/**
 * Sub function to Add a dictionary entry line to the word dictionary.
 *
 * @param buf [i/o] buffer to hold the input string, will be modified in this function
 * @param vnum_p [in] current number of words in @a winfo
 * @param linenum [in] current line number of the input
 * @param winfo [out] pointer to word dictionary to append the data.
 * @param hmminfo [in] HTK %HMM definition data.  if NULL, phonemes are ignored.
 * @param do_conv [in] TRUE if performing triphone conversion
 * @param ok_flag [out] will be set to FALSE if an error occured for this input.
 * @param headphone [in] word head silence model name
 * @param tailphone [in] word tail silence model name
 * @param contextphone [in] silence context name to be used at head and tail
 *
 * @return FALSE if buf == "DICEND", else TRUE will be returned.
 */
boolean
voca_load_wordlist_line(char *buf, WORD_ID *vnum_p, int linenum, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, boolean do_conv, boolean *ok_flag, char *headphone, char *tailphone, char *contextphone)
{
    char *ptmp, *lp = NULL, *p;
    static char cbuf[MAX_HMMNAME_LEN];
    static HMM_Logical **tmpwseq = NULL;
    static int tmpmaxlen;
    int i, len;
    HMM_Logical *tmplg;
    boolean pok, first;
    int vnum;

    vnum = *vnum_p;

    if (strmatch(buf, "DICEND")) return FALSE;

    /* allocate temporal work area for the first call */
    if (tmpwseq == NULL) {
        tmpmaxlen = PHONEMELEN_STEP;
        tmpwseq = (HMM_Logical **)mymalloc(sizeof(HMM_Logical *) * tmpmaxlen);
    }

    /* backup whole line for debug output */
    strcpy(bufbak, buf);

    /* Output string */
    if ((ptmp = mystrtok_quote(buf, " \t\n")) == NULL) {
        jlog("Error: voca_load_wordlist: line %d: corrupted data:\n> %s\n", linenum, bufbak);
        winfo->errnum++;
        *ok_flag = FALSE;
        return TRUE;
    }
    winfo->wname[vnum] = strcpy((char *)mybmalloc2(strlen(ptmp)+1, &(winfo->mroot)), ptmp);

    /* reset transparent flag */
    winfo->is_transparent[vnum] = FALSE;

    /* just move pointer to next token */
    if ((ptmp = mystrtok_movetonext(NULL, " \t\n")) == NULL) {
        jlog("Error: voca_load_wordlist: line %d: corrupted data:\n> %s\n", linenum, bufbak);
        winfo->errnum++;
        *ok_flag = FALSE;
        return TRUE;
    }
#ifdef CLASS_NGRAM
    winfo->cprob[vnum] = 0.0;	/* prob = 1.0, logprob = 0.0 */
#endif

    if (ptmp[0] == '@') {		/* class N-gram prob */
#ifdef CLASS_NGRAM
        /* word probability within the class (for class N-gram) */
        /* format: classname @classprob wordname [output] phoneseq */
        /* classname equals to wname, and wordname will be omitted */
        /* format: @%f (log scale) */
        /* if "@" not found or "@0", it means class == word */
        if ((ptmp = mystrtok(NULL, " \t\n")) == NULL) {
            jlog("Error: voca_load_wordlist: line %d: corrupted data:\n> %s\n", linenum, bufbak);
            winfo->errnum++;
            *ok_flag = FALSE;
            return TRUE;
        }
        if (ptmp[1] == '\0') {	/* space between '@' and figures */
            jlog("Error: voca_load_wordlist: line %d: value after '@' missing, maybe wrong space?\n> %s\n", linenum, bufbak);
            winfo->errnum++;
            *ok_flag = FALSE;
            return TRUE;
        }
        winfo->cprob[vnum] = atof(&(ptmp[1]));
        if (winfo->cprob[vnum] != 0.0) winfo->cwnum++;
        /* read next word entry (just skip them) */
        if ((ptmp = mystrtok(NULL, " \t\n")) == NULL) {
            jlog("Error: voca_load_wordlist: line %d: corrupted data:\n> %s\n", linenum,bufbak);
            winfo->errnum++;
            *ok_flag = FALSE;
            return TRUE;
        }
        /* move to the next word entry */
        if ((ptmp = mystrtok_movetonext(NULL, " \t\n")) == NULL) {
            jlog("Error: voca_load_wordlist: line %d: corrupted data:\n> %s\n", linenum, bufbak);
            winfo->errnum++;
            *ok_flag = FALSE;
            return TRUE;
        }
#else  /* ~CLASS_NGRAM */
        jlog("Error: voca_load_wordlist: line %d: cannot handle in-class word probability\n> %s\n", linenum, ptmp, bufbak);
        winfo->errnum++;
        *ok_flag = FALSE;
        return TRUE;
#endif /* CLASS_NGRAM */
    }

    /* OutputString */
    switch(ptmp[0]) {
    case '[':			/* ignore transparency */
        ptmp = mystrtok_quotation(NULL, " \t\n", '[', ']', 0);
        break;
    case '{':			/* ignore transparency */
        ptmp = mystrtok_quotation(NULL, " \t\n", '{', '}', 0);
        break;
    default:
        /* ALLOW no entry for output */
        /* same as wname is used */
        ptmp = winfo->wname[vnum];
    }
    if (ptmp == NULL) {
        jlog("Error: voca_load_wordlist: line %d: corrupted data:\n> %s\n", linenum, bufbak);
        winfo->errnum++;
        *ok_flag = FALSE;
        return TRUE;
    }
    winfo->woutput[vnum] = strcpy((char *)mybmalloc2(strlen(ptmp)+1, &(winfo->mroot)), ptmp);

#ifdef USE_MBR
    /* just move pointer to next token */
    if ((ptmp = mystrtok_movetonext(NULL, " \t\n")) == NULL) {
        jlog("Error: voca_load_wordlist: line %d: corrupted data:\n> %s\n", linenum, bufbak);
        winfo->errnum++;
        *ok_flag = FALSE;
        return TRUE;
    }

    if (ptmp[0] == ':') {        /* Word weight (use minimization WWER on MBR) */

        /* Word weight (use minimization WWER on MBR) */
        /* format: (classname @classprob) wordname [output] :weight phoneseq */
        /* format: :%f (linear scale) */
        /* if ":" not found, it means weight == 1.0 (same minimization WER) */

        if ((ptmp = mystrtok(NULL, " \t\n")) == NULL) {
            jlog("Error: voca_load_wordlist: line %d: corrupted data:\n> %s\n", linenum, bufbak);
            winfo->errnum++;
            *ok_flag = FALSE;
            return TRUE;
        }
        if ((ptmp[1] < '0' || ptmp[1] > '9') && ptmp[1] != '.') {     /* not figure after ':' */
            jlog("Error: voca_load_wordlist: line %d: value after ':' missing, maybe wrong space?\n> %s\n", linenum, bufbak);
            winfo->errnum++;
            *ok_flag = FALSE;
            return TRUE;
        }

        /* allocate if not yet */
        if (winfo->weight == NULL) {
            winfo->weight = (LOGPROB *)mymalloc(sizeof(LOGPROB) * winfo->maxnum);
            for (i = 0; i < vnum; i++) {
                winfo->weight[i] = 1.0;
            }
        }

        winfo->weight[vnum] = atof(&(ptmp[1]));
    }
    else {
        if (winfo->weight)
            winfo->weight[vnum] = 1.0; /* default, same minimization WER */
    }
#endif


    /* phoneme sequence */
    if (hmminfo == NULL) {
        /* don't read */
        winfo->wseq[vnum] = NULL;
        winfo->wlen[vnum] = 0;
    } else {

        len = 0;
        first = TRUE;
        pok = TRUE;

        for (;;) {
            if (do_conv) {
                if (first) {
                    /* init phone cycler */
                    cycle_triphone(NULL);
                    /* insert head phone at beginning of word */
                    if (contextphone) {
                        if (strlen(contextphone) >= MAX_HMMNAME_LEN) {
                            jlog("Error: voca_load_wordlist: line %d: too long phone name: %s\n", linenum, contextphone);
                            winfo->errnum++;
                            *ok_flag = FALSE;
                            return TRUE;
                        }
                        cycle_triphone(contextphone);
                    } else {
                        cycle_triphone("NULL_C");
                    }
                    if ((lp = mystrtok(NULL, " \t\n")) == NULL) {
                        jlog("Error: voca_load_wordlist: line %d: word %s has no phoneme:\n> %s\n", linenum, winfo->wname[vnum], bufbak);
                        winfo->errnum++;
                        *ok_flag = FALSE;
                        return TRUE;
                    }
                    if (strlen(lp) >= MAX_HMMNAME_LEN) {
                        jlog("Error: voca_load_wordlist: line %d: too long phone name: %s\n", linenum, lp);
                        winfo->errnum++;
                        *ok_flag = FALSE;
                        return TRUE;
                    }
                    p = cycle_triphone(lp);
                    first = FALSE;
                } else {		/* do_conv, not first */
                    if (lp != NULL) {	/* some token processed at last loop */
                        lp = mystrtok(NULL, " \t\n");
                        if (lp != NULL) {
                            /* token exist */
                            if (strlen(lp) >= MAX_HMMNAME_LEN) {
                                jlog("Error: voca_load_wordlist: line %d: too long phone name: %s\n", linenum, lp);
                                winfo->errnum++;
                                *ok_flag = FALSE;
                                return TRUE;
                            }
                            p = cycle_triphone(lp);
                        } else {
                            /* no more token, insert tail phone at end of word */
                            if (contextphone) {
                                if (strlen(contextphone) >= MAX_HMMNAME_LEN) {
                                    jlog("Error: voca_load_wordlist: line %d: too long phone name: %s\n", linenum, contextphone);
                                    winfo->errnum++;
                                    *ok_flag = FALSE;
                                    return TRUE;
                                }
                                p = cycle_triphone(contextphone);
                            } else {
                                p = cycle_triphone("NULL_C");
                            }
                        }
                    } else {		/* no more token at last input  */
                        /* flush tone cycler */
                        p = cycle_triphone_flush();
                    }
                }
            } else {			/* not do_conv */
                if (first) {
                    p = lp = headphone;
                    first = FALSE;
                } else {
                    if (lp != NULL) {	/* some token processed at last loop */
                        p = lp = mystrtok(NULL, " \t\n");
                        /* if no more token, use tailphone */
                        if (lp == NULL) p = tailphone;
                    } else {
                        /* no more token at last input, exit loop */
                        p = NULL;
                    }
                }
            }
            if (p == NULL) break;
            /* for headphone and tailphone, their context should not be handled */
            /* and when they appear as context they should be replaced by contextphone */
            if (do_conv) {
                center_name(p, cbuf);
                if (contextphone) {
                    if (strmatch(cbuf, contextphone)) {
                        if (len == 0) {
                            p = headphone;
                        } else if (lp == NULL) {
                            p = tailphone;
                        }
                    }
                } else {
                    if (strmatch(cbuf, "NULL_C")) {
                        if (len == 0) {
                            p = headphone;
                        } else if (lp == NULL) {
                            p = tailphone;
                        }
                    } else {
                        if (strnmatch(p, "NULL_C", 6)) {
                            if (strnmatch(&(p[strlen(p)-6]), "NULL_C", 6)) {
                                p = cbuf;
                            } else {
                                p = rightcenter_name(p, cbuf);
                            }
                        } else if (strnmatch(&(p[strlen(p)-6]), "NULL_C", 6)) {
                            p = leftcenter_name(p, cbuf);
                        }
                    }
                }
            }
            //printf("[[%s]]\n", p);

            /* both defined/pseudo phone is allowed */
            tmplg = htk_hmmdata_lookup_logical(hmminfo, p);
            if (tmplg == NULL) {
                /* not found */
                if (do_conv) {
                    /* logical phone was not found */
                    jlog("Error: voca_load_wordlist: line %d: logical phone \"%s\" not found\n", linenum, p);
                    snprintf(cbuf,MAX_HMMNAME_LEN,"%s", p);
                } else {
                    jlog("Error: voca_load_wordlist: line %d: phone \"%s\" not found\n", linenum, p);
                    snprintf(cbuf, MAX_HMMNAME_LEN, "%s", p);
                }
                add_to_error(winfo, cbuf);
                pok = FALSE;
            } else {
                /* found */
                if (len >= tmpmaxlen) {
                    /* expand wseq area by PHONEMELEN_STEP */
                    tmpmaxlen += PHONEMELEN_STEP;
                    tmpwseq = (HMM_Logical **)myrealloc(tmpwseq, sizeof(HMM_Logical *) * tmpmaxlen);
                }
                /* store to temporal buffer */
                tmpwseq[len] = tmplg;
            }
            len++;
        }
        if (!pok) {			/* error in phoneme */
            jlog("Error: voca_load_wordlist: the line content was: %s\n", bufbak);
            winfo->errnum++;
            *ok_flag = FALSE;
            return TRUE;
        }
        if (len == 0) {
            jlog("Error: voca_load_wordlist: line %d: no phone specified:\n> %s\n", linenum, bufbak);
            winfo->errnum++;
            *ok_flag = FALSE;
            return TRUE;
        }
        /* store to winfo */
        winfo->wseq[vnum] = (HMM_Logical **)mybmalloc2(sizeof(HMM_Logical *) * len, &(winfo->mroot));
        memcpy(winfo->wseq[vnum], tmpwseq, sizeof(HMM_Logical *) * len);
        winfo->wlen[vnum] = len;
        winfo->wton[vnum] = 0;
    }

    vnum++;
    *vnum_p = vnum;

    return(TRUE);
}
Exemple #2
0
struct einit_cron_job *einit_cron_parse_attrs_to_cron_job (char **attributes) {
 if (!attributes) return NULL;

 struct einit_cron_job *cj = emalloc (sizeof (struct einit_cron_job));
 uint32_t i = 0;
 memset (cj, 0, sizeof (struct einit_cron_job));

 for (; attributes[i]; i+=2) {
  if (strmatch (attributes[i], "command")) {
   cj->command = estrdup(attributes[i+1]);
  } else if (strmatch (attributes[i], "id")) {
   cj->id = estrdup(attributes[i+1]);
  } else if (strmatch (attributes[i], "years") || strmatch (attributes[i], "year")) {
   char **x = str2set (':', attributes[i+1]);
   uint32_t j = 0;

   for (; x[j]; j++) {
    uintptr_t num = parse_integer (x[j]);

    if (num) {
     cj->years = (uintptr_t *)setadd ((void **)cj->years, (void *)num, SET_NOALLOC);
	}
   }

   free (x);
  } else if (strmatch (attributes[i], "months") || strmatch (attributes[i], "month")) {
   char **x = str2set (':', attributes[i+1]);
   uint32_t j = 0;

   for (; x[j]; j++) {
    uintptr_t num = parse_integer (x[j]);

    if (num) {
     cj->months = (uintptr_t *)setadd ((void **)cj->months, (void *)num, SET_NOALLOC);
	}
   }

   free (x);
  } else if (strmatch (attributes[i], "days") || strmatch (attributes[i], "day")) {
   char **x = str2set (':', attributes[i+1]);
   uint32_t j = 0;

   for (; x[j]; j++) {
    uintptr_t num = parse_integer (x[j]);

    if (num) {
     cj->days = (uintptr_t *)setadd ((void **)cj->days, (void *)num, SET_NOALLOC);
	}
   }

   free (x);
  } else if (strmatch (attributes[i], "hours") || strmatch (attributes[i], "hour")) {
   char **x = str2set (':', attributes[i+1]);
   uint32_t j = 0;

   for (; x[j]; j++) {
    uintptr_t num = parse_integer (x[j]);

    if (num) {
     cj->hours = (uintptr_t *)setadd ((void **)cj->hours, (void *)num, SET_NOALLOC);
	}
   }

   free (x);
  } else if (strmatch (attributes[i], "minutes") || strmatch (attributes[i], "minute")) {
   char **x = str2set (':', attributes[i+1]);
   uint32_t j = 0;

   for (; x[j]; j++) {
    uintptr_t num = parse_integer (x[j]);

    if (num) {
     cj->minutes = (uintptr_t *)setadd ((void **)cj->minutes, (void *)num, SET_NOALLOC);
	}
   }

   free (x);
  } else if (strmatch (attributes[i], "seconds") || strmatch (attributes[i], "second")) {
   char **x = str2set (':', attributes[i+1]);
   uint32_t j = 0;

   for (; x[j]; j++) {
    uintptr_t num = parse_integer (x[j]);

    if (num) {
     cj->seconds = (uintptr_t *)setadd ((void **)cj->seconds, (void *)num, SET_NOALLOC);
	}
   }

   free (x);
  } else if (strmatch (attributes[i], "weekdays") || strmatch (attributes[i], "weekday")) {
   char **x = str2set (':', attributes[i+1]);
   uint32_t j = 0;

   for (; x[j]; j++) {
    if (strmatch (x[j], "sunday")) {
     cj->weekdays = (uintptr_t *)setadd ((void **)cj->weekdays, (void *)0, SET_NOALLOC);
	} else if (strmatch (x[j], "monday")) {
     cj->weekdays = (uintptr_t *)setadd ((void **)cj->weekdays, (void *)1, SET_NOALLOC);
	} else if (strmatch (x[j], "tuesday")) {
     cj->weekdays = (uintptr_t *)setadd ((void **)cj->weekdays, (void *)2, SET_NOALLOC);
	} else if (strmatch (x[j], "wednesday")) {
     cj->weekdays = (uintptr_t *)setadd ((void **)cj->weekdays, (void *)3, SET_NOALLOC);
	} else if (strmatch (x[j], "thursday")) {
     cj->weekdays = (uintptr_t *)setadd ((void **)cj->weekdays, (void *)4, SET_NOALLOC);
	} else if (strmatch (x[j], "friday")) {
     cj->weekdays = (uintptr_t *)setadd ((void **)cj->weekdays, (void *)5, SET_NOALLOC);
	} else if (strmatch (x[j], "saturday")) {
     cj->weekdays = (uintptr_t *)setadd ((void **)cj->weekdays, (void *)6, SET_NOALLOC);
	}
   }

   free (x);
  }
 }

 return cj;
}
int linux_static_dev_run() {
    char *dm;

    if (!linux_static_dev_enabled && (dm = cfg_getstring("configuration-system-device-manager", NULL)) && strmatch (dm, "static")) {
        linux_static_dev_enabled = 1;

        mount ("proc", "/proc", "proc", 0, NULL);
        mount ("sys", "/sys", "sysfs", 0, NULL);

        mount ("devpts", "/dev/pts", "devpts", 0, NULL);

        mount ("shm", "/dev/shm", "tmpfs", 0, NULL);

        ethread_spawn_detached ((void *(*)(void *))linux_static_dev_hotplug, (void *)NULL);

        FILE *he = fopen ("/proc/sys/kernel/hotplug", "w");
        if (he) {
            char *hotplug_handler = cfg_getstring ("configuration-system-hotplug-handler", NULL);

            if (hotplug_handler) {
                fputs (hotplug_handler, he);
            } else {
                fputs ("", he);
            }

            fputs ("\n", he);
            fclose (he);
        }

        linux_static_dev_load_kernel_extensions();

        mount ("usbfs", "/proc/bus/usb", "usbfs", 0, NULL);

        return status_ok;
    } else
        return status_failed;
}
Exemple #4
0
void writefile(FILE *input, FILE *output, unsigned char *buffer, unsigned buffersize, unsigned char pairtable[128][2])
{
  char str[256];
  int insection, indent, needseparator;
  unsigned char *bufptr;

  bufptr = buffer;
  insection = 0;

  rewind(input);
  while (!feof(input)) {
    while (fgets(str,sizeof str,input)!=NULL) {
      fprintf(output,"%s",str);
      if (check_tablename(str)) {
        write_pairtable(output, pairtable, tablename);
        /* strip an existing pair table from the file */
        if (fgets(str,sizeof str,input)!=NULL) {
          if (strmatch(str,"/*-*SCPACK",NULL)) {
            while (fgets(str,sizeof str,input)!=NULL)
              if (strmatch(str,"/*-*SCPACK",NULL))
                break;
          } else {
            fprintf(output,"%s",str);
          } /* if */
        } /* if */
      } /* if */
      if (strmatch(str,START_TOKEN,NULL))
        insection = 1;
      if (insection && strmatch(str,"#else",NULL))
        break;
    } /* while */
    if (!strmatch(str,"#else",&indent))
      return;           /* no (more) section found, quit */
    insection=0;

    /* dump the buffer as strings, separated with commas */
    needseparator = 0;
    while (*bufptr != '\0') {
      assert((unsigned)(bufptr-buffer) < buffersize);
      if (needseparator)
        fprintf(output, "%s\n",separator);
      fprintf(output, "%*c\"",indent+2,' ');
      /* loop over string */
      while (*bufptr != '\0') {
        if (*bufptr<' ' || *bufptr >= 128 || *bufptr == '"' || *bufptr == '\\')
          fprintf(output, "\\%03o", *bufptr);
        else
          fprintf(output, "%c", *bufptr);
        bufptr++;
      } /* while */
      fprintf(output, "\"");
      needseparator = 1;
      bufptr++;           /* skip '\0' */
    } /* while */
    fprintf(output, "%s\n",terminator);
    bufptr++;

    /* skip the input file until the #endif section */
    while (fgets(str,sizeof str,input)!=NULL) {
      if (strmatch(str,"#endif",NULL)) {
        fprintf(output,"%s",str);
        break;          /* done */
      } /* if */
    } /* while */
  } /* while - !feof(input) */
}
void core_einit_event_handler (struct einit_event *ev) {
 if (ev->type == einit_core_configuration_update) {
  struct cfgnode *node;
  char *str;

  ev->chain_type = einit_core_update_modules;

  if ((node = cfg_getnode ("core-mortality-bad-malloc", NULL)))
   mortality[bitch_emalloc] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-stdio", NULL)))
   mortality[bitch_stdio] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-regex", NULL)))
   mortality[bitch_regex] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-expat", NULL)))
   mortality[bitch_expat] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-dl", NULL)))
   mortality[bitch_dl] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-lookup", NULL)))
   mortality[bitch_lookup] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-pthreads", NULL)))
   mortality[bitch_epthreads] = node->value;

  if ((node = cfg_getnode ("core-settings-allow-code-unloading", NULL)))
   einit_allow_code_unloading = node->flag;

  if ((str = cfg_getstring ("core-scheduler-niceness/core", NULL)))
   einit_core_niceness_increment = parse_integer (str);

  if ((str = cfg_getstring ("core-scheduler-niceness/tasks", NULL)))
   einit_task_niceness_increment = parse_integer (str);
 } else if (ev->type == einit_core_update_modules) {
  struct lmodule *lm;

  repeat:

  lm = mlist;
  einit_new_node = 0;

  while (lm) {
   if (lm->source && strmatch(lm->source, "core")) {
    lm = mod_update (lm);

// tell module to scan for changes if it's a module-loader
    if (lm->module && (lm->module->mode & einit_module_loader) && (lm->scanmodules != NULL)) {
     notice (8, "updating modules (%s)", lm->module->rid ? lm->module->rid : "unknown");

     lm->scanmodules (mlist);

/* if an actual new node has been added to the configuration,
   repeat this step */
     if (einit_new_node) goto repeat;
    }

   }
   lm = lm->next;
  }

/* give the module-logic code and others a chance at processing the current list */
  struct einit_event update_event = evstaticinit(einit_core_module_list_update);
  update_event.para = mlist;
  event_emit (&update_event, einit_event_flag_broadcast);
  evstaticdestroy(update_event);
 } else if (ev->type == einit_core_recover) { // call everyone's recover-function (if defined)
  struct lmodule *lm = mlist;

  while (lm) {
   if (lm->recover) {
    lm->recover (lm);
   }

   lm = lm->next;
  }
 } else if (ev->type == einit_core_suspend_all) { // suspend everyone (if possible)
  struct lmodule *lm = mlist;
  int ok = 0;

  while (lm) {
   ok += (mod (einit_module_suspend, lm, NULL) == status_ok) ? 1 : 0;

   lm = lm->next;
  }

  if (ok)
   notice (4, "%i modules suspended", ok);

  event_snooze_time = event_timer_register_timeout(60);
 } else if (ev->type == einit_core_resume_all) { // resume everyone (if necessary)
  struct lmodule *lm = mlist;
  int ok = 0;

  while (lm) {
   ok += (mod (einit_module_resume, lm, NULL) == status_ok) ? 1 : 0;

   lm = lm->next;
  }

  if (ok)
   notice (4, "%i available", ok);
 }
}
Exemple #6
0
int Imatch (int argc, lvar_t *argv) {
    if (!T_ISSTRING (argv[0].o) || !T_ISSTRING (argv[1].o))
        return L_FAILURE;
    rtno = Tinteger (strmatch (Tgetstring (argv[0].o), Tgetstring (argv[1].o)));
    return L_SUCCESS;
}
Exemple #7
0
char*
pathshell(void)
{
	register char*	sh;
	int		ru;
	int		eu;
	int		rg;
	int		eg;
	struct stat	st;

	static char*	val;

	if ((sh = getenv("SHELL")) && *sh == '/' && strmatch(sh, "*/(sh|*[!cC]sh)*([[:digit:]])?(-+([.[:alnum:]]))?(.exe)"))
	{
		if (!(ru = getuid()) || !eaccess("/bin", W_OK))
		{
			if (stat(sh, &st))
				goto defshell;
			if (ru != st.st_uid && !strmatch(sh, "?(/usr)?(/local)/?([ls])bin/?([[:lower:]])sh?(.exe)"))
				goto defshell;
		}
		else
		{
			eu = geteuid();
			rg = getgid();
			eg = getegid();
			if (ru != eu || rg != eg)
			{
				char*	s;
				char	dir[PATH_MAX];

				s = sh;
				for (;;)
				{
					if (stat(s, &st))
						goto defshell;
					if (ru != eu && st.st_uid == ru)
						goto defshell;
					if (rg != eg && st.st_gid == rg)
						goto defshell;
					if (s != sh)
						break;
					if (strlen(s) >= sizeof(dir))
						goto defshell;
					strcpy(dir, s);
					if (!(s = strrchr(dir, '/')))
						break;
					*s = 0;
					s = dir;
				}
			}
		}
		return sh;
	}
 defshell:
	if (!(sh = val))
	{
		if (!*(sh = astconf("SH", NiL, NiL)) || *sh != '/' || eaccess(sh, X_OK) || !(sh = strdup(sh)))
			sh = "/bin/sh";
		val = sh;
	}
	return sh;
}
Exemple #8
0
GImage *GImageRead(char * filename) {
/* Go read an input image file. Return NULL if cannot guess file type */
    char *mime, *pt;

    if (filename == NULL )
	return( NULL );

    /* Try finding correct routine to use based on GTK mime type */
    if ( GFileExists(filename) ) {
	mime=GIOGetMimeType(filename, true);

	if ( strcasecmp(mime,"image/bmp")==0 )
	    return( GImageReadBmp(filename) );
	else if ( strcasecmp(mime,"image/x-xbitmap")==0 )
	    return( GImageReadXbm(filename) );
	else if ( strcasecmp(mime,"image/x-xpixmap")==0 )
	    return( GImageReadXpm(filename) );
	else if ( strcasecmp(mime,"image/tiff")==0 )
	    return( GImageReadTiff(filename) );
	else if ( strcasecmp(mime,"image/jpeg")==0 )
	    return( GImageReadJpeg(filename) );
	else if ( strcasecmp(mime,"image/png")==0 )
	    return( GImageReadPng(filename) );
	else if ( strcasecmp(mime,"image/gif")==0 )
	    return( GImageReadGif(filename) );
	else if ( strcasecmp(mime,"image/x-cmu-raster")==0 || \
		  strcasecmp(mime,"image/x-sun-raster")==0 )
	    return( GImageReadRas(filename) );		/* Sun raster */
	else if ( strcasecmp(mime,"image/x-rgb")==0 || \
		  strcasecmp(mime,"image/x-sgi")==0 )
	    return( GImageReadRgb(filename) );		/* SGI format */
    }

    /* Try finding correct routine to use based on filename suffix */
    if ( (pt=strrchr(filename,'.'))!=NULL ) {

	if ( strmatch(pt,".bmp")==0 )
	    return( GImageReadBmp(filename) );
	else if ( strmatch(pt,".xbm")==0 )
	    return( GImageReadXbm(filename) );
	else if ( strmatch(pt,".xpm")==0 )
	    return( GImageReadXpm(filename) );
	else if ( strmatch(pt,".tiff")==0 || strmatch(pt,".tif")==0 )
	    return( GImageReadTiff(filename) );
	else if ( strmatch(pt,".jpeg")==0 || strmatch(pt,".jpg")==0 )
	    return( GImageReadJpeg(filename) );
	else if ( strmatch(pt,".png")==0 )
	    return( GImageReadPng(filename) );
	else if ( strmatch(pt,".gif")==0 )
	    return( GImageReadGif(filename) );
	else if ( strmatch(pt,".ras")==0 || strmatch(pt,".im1")==0 || \
		  strmatch(pt,".im8")==0 || strmatch(pt,".im24")==0 || \
		  strmatch(pt,".im32")==0 || strmatch(pt,".rs")==0 || \
		  strmatch(pt,".sun")==0 )
	    return( GImageReadRas(filename) );		/* Sun raster */
	else if ( strmatch(pt,".rgb")==0 || strmatch(pt,".rgba")==0 || \
		  strmatch(pt,".sgi")==0 || strmatch(pt,".bw")==0 )
	    return( GImageReadRgb(filename) );		/* SGI format */
    }

    return( NULL );
}
Exemple #9
0
/* parse DNN config file */
boolean
dnn_config_file_parse(char *filename, JCONF_AM *am, Jconf *jconf)
{
  FILE *fp;
  char buf[BUFLEN];
  char *p, *pp;
  char *v;
  int i, n;
  boolean error_flag;
  char *cdir;

  if (am->dnn.wfile != NULL) {
    jlog("ERROR: dnn_config_file_parse: duplicated loading: %s\n", filename);
    return FALSE;
  }

  if ((fp = fopen(filename, "r")) == NULL) {
    jlog("ERROR: dnn_config_file_parse: failed to open %s\n", filename);
    return FALSE;
  }

  cdir = strcpy((char *)mymalloc(strlen(filename)+1), filename);
  get_dirname(cdir);
  if (cdir[0] == '\0') {
    free(cdir);
    cdir = NULL;
  }

  while (fgets_jconf(buf, BUFLEN, fp) != NULL) {
    if ((p = strchr(buf, '#')) != NULL) {
      *p = '\0';
    }
    pp = &(buf[0]);
    while (*pp == ' ' || *pp == '\t') pp++;
    if (*pp == '\0') continue;
    p = strchr(pp, ' ');
    if (p == NULL) {
      jlog("ERROR: dnn_config_file_parse: wrong file format: %s\n", buf);
      if (cdir) free(cdir);
      fclose(fp);
      return FALSE;
    }
    v = p;
    while (*v == ' ') v++;
    *p = '\0';
    if (strmatch(pp, "feature_type")) {
      am->dnn.paramtype = param_str2code(v);
    } else if (strmatch(pp, "feature_options")) {
      am->dnn.optionstring = strdup(v);
    } else if (strmatch(pp, "feature_len")) am->dnn.veclen = atoi(v);
    else if (strmatch(pp, "context_len")) am->dnn.contextlen = atoi(v);
    else if (strmatch(pp, "input_nodes")) am->dnn.inputnodes = atoi(v);
    else if (strmatch(pp, "output_nodes")) am->dnn.outputnodes = atoi(v);
    else if (strmatch(pp, "hidden_nodes")) am->dnn.hiddennodes = atoi(v);
    else if (strmatch(pp, "hidden_layers")) {
      am->dnn.hiddenlayernum = atoi(v);
      am->dnn.wfile = (char **)mymalloc(sizeof(char *) * am->dnn.hiddenlayernum);
      am->dnn.bfile = (char **)mymalloc(sizeof(char *) * am->dnn.hiddenlayernum);
      for (i = 0; i < am->dnn.hiddenlayernum; i++) {
	am->dnn.wfile[i] = NULL;
	am->dnn.bfile[i] = NULL;
      }
    } else if (pp[0] == 'W') {
      n = atoi(&(pp[1]));
      if (n > am->dnn.hiddenlayernum) {
	jlog("ERROR: dnn_config_file_parse: W%d > # of hidden_layers (%d)\n", n, am->dnn.hiddenlayernum);
	if (cdir) free(cdir);
	fclose(fp);
	return FALSE;
      } else if (n <= 0) {
	jlog("ERROR: dnn_config_file_parse: layer id should begin with 1\n");
	if (cdir) free(cdir);
	fclose(fp);
	return FALSE;
      }
      am->dnn.wfile[n-1] = filepath(v, cdir);
    } else if (pp[0] == 'B') {
      n = atoi(&(pp[1]));
      if (n > am->dnn.hiddenlayernum) {
	jlog("ERROR: dnn_config_file_parse: B%d > # of hidden_layers (%d)\n", n, am->dnn.hiddenlayernum);
	if (cdir) free(cdir);
	fclose(fp);
	return FALSE;
      } else if (n <= 0) {
	jlog("ERROR: dnn_config_file_parse: layer id should begin with 1\n");
	if (cdir) free(cdir);
	fclose(fp);
	return FALSE;
      }
      am->dnn.bfile[n-1] = filepath(v, cdir);
    } else if (strmatch(pp, "output_W")) am->dnn.output_wfile = filepath(v, cdir);
    else if (strmatch(pp, "output_B")) am->dnn.output_bfile = filepath(v, cdir);
    else if (strmatch(pp, "state_prior")) am->dnn.priorfile = filepath(v, cdir);
    else if (strmatch(pp, "state_prior_factor")) am->dnn.prior_factor = atof(v);
    else if (strmatch(pp, "batch_size")) am->dnn.batchsize = atoi(v);
    else if (strmatch(pp, "num_threads")) am->dnn.num_threads = atoi(v);
    else {
      jlog("ERROR: dnn_config_file_parse: unknown spec: %s %s\n", pp, v);
      if (cdir) free(cdir);
      fclose(fp);
      return FALSE;
    }
  }
  if (fclose(fp) == -1) {
    jlog("ERROR: dnn_config_file_parse: failed to close file\n");
    if (cdir) free(cdir);
    return FALSE;
  }

  /* check validity */
  error_flag = FALSE;
  for (i = 0; i < am->dnn.hiddenlayernum; i++) {
    if (am->dnn.wfile[i] == NULL) {
      jlog("ERROR: dnn_config_file_parse: no W file specified for hidden layer #%d\n", i + 1);
      error_flag = TRUE;
    }
    if (am->dnn.bfile[i] == NULL) {
      jlog("ERROR: dnn_config_file_parse: no B file specified for hidden layer #%d\n", i + 1);
      error_flag = TRUE;
    }
  }
  if (error_flag == TRUE) {
    if (cdir) free(cdir);
    return FALSE;
  }

  am->dnn.enabled = TRUE;

  /* load options */
  if (am->dnn.optionstring) {
    if (config_string_parse_basedir(jconf->amnow->dnn.optionstring, jconf, cdir) == FALSE) {
      if (cdir) free(cdir);
      return FALSE;
    }
  }

  if (cdir) free(cdir);

  return TRUE;
}
Exemple #10
0
int main(int argc, char **argv)
{
	int x, y;
	int maskflag=0;
	unsigned char *mask;
	double k;
	double *phase2elevBase,*sinFlat,*cosFlat;
	char datafile[256], basefile[256], outfile[256];
	char maskfile[256];
	int nrows,ncols; 
	float *f_coh;
	float *f_eleverr;
	float percent=0.0;
	double init_err=DEFAULT_ERROR;
	FILE *fdata, *fmask, *fout;
	meta_parameters *meta;
	baseline base;


/* Parse command line arguments */
	logflag=FALSE;
	while (currArg < (argc-NUM_ARGS)) {
	   char *key = argv[currArg++];
	   if (strmatch(key,"-log")) {
	      CHECK_ARG(1);
	      strcpy(logFile,GET_ARG(1));
	      fLog = FOPEN(logFile, "a");
	      logflag=TRUE;
	   }
	   else if (strmatch(key, "-mask")) {
	      CHECK_ARG(1);
	      strcpy(maskfile, GET_ARG(1));
	      maskflag = TRUE;
	   }
	   else if (strmatch(key,"-i")) {
	      CHECK_ARG(1);
	      init_err = atof(GET_ARG(1));
	      init_err *= init_err;
	   }
	   else {
	      printf("\n**Invalid option:  %s\n",argv[currArg-1]);
	      usage(argv[0]);
	   }
	}
	if ((argc-currArg) < NUM_ARGS) {
	   printf("Insufficient arguments.\n");
	   usage(argv[0]);
	}

	create_name(datafile, argv[currArg], ".img");
	strcpy(basefile, argv[currArg+1]);
	strcpy(outfile, argv[currArg+2]);

	asfSplashScreen(argc, argv);

/* Get appropriate metadata */
	meta = meta_read(datafile);
	nrows = meta->general->line_count;
	ncols = meta->general->sample_count;
	meta->general->data_type = REAL32;
	meta_write(meta, outfile);
	k  = meta_get_k(meta);    /* wave number*/
	
/* Allocate space for vectors, matricies, and stuff*/
	mask = (unsigned char *)MALLOC(sizeof(unsigned char)*ncols);
	f_coh = (float *)MALLOC(sizeof(float)*ncols);
	f_eleverr = (float *)MALLOC(sizeof(float)*ncols);
	sinFlat = (double *)MALLOC(sizeof(double)*ncols);
	cosFlat = (double *)MALLOC(sizeof(double)*ncols);
	phase2elevBase = (double *)MALLOC(sizeof(double)*ncols);

/* Open data file & get seed phase*/
	fdata = fopenImage(datafile, "rb");
	fout = fopenImage(outfile,"wb");
	if (maskflag) fmask = fopenImage(maskfile,"rb");
	
/* Read in baseline values*/
	base = read_baseline(basefile);

/* Obtain information from metadata*/
	for (x=0;x<ncols;x++)
	{
		int img_x = x * meta->sar->sample_increment
		            + meta->general->start_sample;
		double incid=meta_incid(meta,0,img_x);
		double flat=meta_flat(meta,0,img_x);
		sinFlat[x]=sin(flat);
		cosFlat[x]=cos(flat);
		phase2elevBase[x]=meta_get_slant(meta,0,img_x)*sin(incid)/(2.0*k);
	}

/* Loop through each row & calculate height*/
	for (y=0;y<nrows;y++) {
		double Bn_y,Bp_y;

		/* Report progress */
		if ((y*100/nrows)>percent) {
		  printf("\r   Completed %3.0f percent", percent);
		  fflush(NULL);
		  percent+=5.0;
		}

		/* read in data */
		if (maskflag)
			ASF_FREAD(mask,sizeof(unsigned char),ncols,fmask);
		get_float_line(fdata, meta, y, f_coh);
		
		/* calculate baseline for this row*/
		meta_interp_baseline(meta, base,
			y*meta->sar->line_increment+meta->general->start_line+1,
			&Bn_y, &Bp_y);
		
		/* step through each pixel in row*/
		for (x=0;x<ncols;x++) {
			if ((mask[x] == 0x10 && maskflag) || (!maskflag)) {
				double tmp,tmp1,sigma_height;
				tmp = phase2elevBase[x]/(-Bp_y*sinFlat[x]-Bn_y*cosFlat[x]);
				tmp1 = (FLOAT_EQUALS_ZERO(f_coh[x])) 
					    ? 0.0 : sqrt((1-f_coh[x])/f_coh[x]);
				sigma_height = tmp*tmp1;
				f_eleverr[x] = (float)sqrt( init_err +
					sigma_height*sigma_height );
			}
			else
				f_eleverr[x] = -1.0;
		}
		put_float_line(fout, meta, y, f_eleverr);
	}
	printf("\r   Completed 100 percent\n\n");
	sprintf(logbuf, "   Wrote %lld bytes of data\n\n",
	        (long long)(nrows*ncols*4));
	printf("%s", logbuf);
	if (logflag) { printLog(logbuf); }
	
	/* free memory & scram*/
	meta_free(meta);
	FREE(mask);
	FREE(f_coh);
	FREE(f_eleverr);
	FREE(sinFlat);
	FREE(cosFlat);
	FREE(phase2elevBase);
	FCLOSE(fdata);
	FCLOSE(fout);
	if (maskflag) FCLOSE(fmask);

	exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
{
  FILE *fp;
  meta_parameters *metaSrc, *metaTrg;
  envi_header *envi;
  extern int currArg;          // Pre-initialized to 1
  radiometry_t radiometry=r_AMP;
  filter_type_t filter_type;
  char srcImage[255], trgImage[255], *inFile, outFile[255], filter_str[25];
  int startX_src, startY_src, startX_trg, startY_trg, lines, samples, size;
  int subset=FALSE, filter=FALSE, geotiff=FALSE, line_count, sample_count;
  double lat_UL, lon_UL, lat_LR, lon_LR, yLine, xSample;
  float mean, scale;
  register float *img, *filtered_img=NULL;
  register int x, y, l;

  /* parse command line */
  logflag=quietflag=FALSE;
  while (currArg < (argc-2)) {
    char *key = argv[currArg++];
    if (strmatch(key,"-startX")) {
      CHECK_ARG(1);
      startX_src = atoi(GET_ARG(1));
      subset = TRUE;
    }
    else if (strmatch(key,"-startY")) {
      CHECK_ARG(1);
      startY_src = atoi(GET_ARG(1));
      subset = TRUE;
    }
    else if (strmatch(key,"-lines")) {
      CHECK_ARG(1);
      lines = atoi(GET_ARG(1));
      subset = TRUE;
    }
    else if (strmatch(key,"-samples")) {
      CHECK_ARG(1);
      samples = atoi(GET_ARG(1));
      subset = TRUE;
    }
    else if (strmatch(key,"-filter")) {
      CHECK_ARG(2);
      strcpy(filter_str, GET_ARG(2));
      size = atoi(GET_ARG(1));
      filter = TRUE;
    }
    else if (strmatch(key,"-geotiff")) {
      geotiff = TRUE;
    }
    else {
      printf( "\n**Invalid option:  %s\n", argv[currArg-1]);
      usage(argv[0]);
    }
  }

  if ((argc-currArg)<2) {printf("Insufficient arguments.\n"); usage(argv[0]);}

  strcpy (srcImage, argv[currArg]);
  strcpy (trgImage, argv[currArg+1]);

  asfSplashScreen(argc, argv);

  // Ingesting CEOS files into ASF internal format
  asfPrintStatus("Ingesting source image: %s ...\n", srcImage);
  asf_import(radiometry, FALSE, FALSE, FALSE, "CEOS", "", "geocoded_image", NULL, NULL,
	     -99.0, -99.0, NULL, NULL, NULL, TRUE, NULL, srcImage, "", srcImage);
  metaSrc = meta_read(srcImage);

  asfPrintStatus("Ingesting target image: %s ...\n", trgImage);
  asf_import(radiometry, FALSE, FALSE, FALSE, "CEOS", "", "geocoded_image", NULL, NULL,
	     -99.0, -99.0, NULL, NULL, NULL, TRUE, NULL, trgImage, "", trgImage);
  metaTrg = meta_read(trgImage);

  // Check subset values for source image
  line_count = metaSrc->general->line_count;
  sample_count = metaSrc->general->sample_count;
  if (subset) {
    if (startX_src < 0 || startX_src > sample_count)
      startX_src = 0;
    if (startY_src < 0 || startY_src > line_count)
      startY_src = 0;
    if (lines < 0 || (lines-startY_src) > line_count)
      lines = line_count - startY_src;
    if (samples < 0 || (samples-startX_src) > sample_count)
      samples = sample_count - startX_src;
  }
  else {
    startX_src = startY_src = 0;
    lines = line_count;
    samples = sample_count;
  }

  // Assign filter
  if (filter) {
    if (strcmp(uc(filter_str), "AVERAGE") == 0)
      filter_type = AVERAGE;
    else if (strcmp(uc(filter_str), "SOBEL") == 0)
      filter_type = SOBEL;
    else if (strcmp(uc(filter_str), "FROST") == 0)
      filter_type = FROST;
    else if (strcmp(uc(filter_str), "LEE") == 0)
      filter_type = LEE;
    else if (strcmp(uc(filter_str), "GAMMA_MAP") == 0)
      filter_type = GAMMA_MAP;
    else {
      asfPrintWarning("Unsupported filter type '%s'- ignoring the filter"
		      " settings\n", filter_str);
      filter = FALSE;
    }
    if (size%2 == 0 && filter_type != AVERAGE) {
      size--;
      asfPrintWarning("Filter kernel must have an odd number of lines and"
		      "samples!\n");
    }
  }

  // Allocate some memory for the subsets
  line_count = metaTrg->general->line_count;
  sample_count = metaTrg->general->sample_count;
  img = (float *) MALLOC(sizeof(float)*lines*samples);
  if (filter)
    filtered_img = (float *) MALLOC(sizeof(float)*lines*samples);

  // Determine geographic location of subset
  meta_get_latLon(metaSrc, startY_src, startX_src, 0.0, &lat_UL, &lon_UL);
  meta_get_latLon(metaSrc, startY_src+lines, startX_src+samples, 0.0,
		  &lat_LR, &lon_LR);
  meta_get_lineSamp(metaTrg, lat_UL, lon_UL, 0.0, &yLine, &xSample);
  startX_trg = (int) (xSample + 0.5);
  startY_trg = (int) (yLine + 0.5);

  // READ IN SUBSETS
  // Read target image subset first to determine average brightness
  asfPrintStatus("\nGenerating subset for target image ...\n");
  asfPrintStatus("start line: %d, start sample: %d, lines: %d, samples: %d\n",
		 startY_trg, startX_trg, lines, samples);
  inFile = appendExt(trgImage, ".img");
  sprintf(outFile, "%s_sub.img", trgImage);
  fp = FOPEN(inFile, "rb");
  read_subset(fp, metaTrg, startX_trg, startY_trg, samples, lines, 0.0,
	      &mean, img);
  FCLOSE(fp);

  // Compute scale factor
  mean *= -1;
  scale = 1.0 / (lines * samples);

  // Subtract this average off of target image
  for (y=0; y<lines; y++) {
    l = samples * y;
    for (x=0; x<samples; x++)
      img[l+x] = (img[l+x] + mean) * scale;
  }

  if (filter) {
    asfPrintStatus("\nFiltering target image subset with %s (%dx%d) ...\n",
		   uc(filter_str), size, size);
    filter_image(img, filtered_img, filter_type, size, lines, samples);
  }

  // Update metadata and write target subset to file
  metaTrg->general->line_count = lines;
  metaTrg->general->sample_count = samples;
  metaTrg->general->start_line = startY_trg;
  metaTrg->general->start_sample = startX_trg;
  meta_write(metaTrg, outFile);
  envi = meta2envi(metaTrg);
  write_envi_header(outFile, outFile, metaTrg, envi);

  fp = FOPEN(outFile, "wb");
  if (filter)
    put_float_lines(fp, metaTrg, 0, lines, filtered_img);
  else
    put_float_lines(fp, metaTrg, 0, lines, img);
  FCLOSE(fp);

  // Read source image subset applying for brightness
  asfPrintStatus("\nGenerating subset for source image ...\n");
  asfPrintStatus("start line: %d, start sample: %d, lines: %d, samples: %d\n",
		 startY_src, startX_src, lines, samples);
  inFile = appendExt(srcImage, ".img");
  sprintf(outFile, "%s_sub.img", srcImage);
  fp = FOPEN(inFile, "rb");
  read_subset(fp, metaSrc, startX_src, startY_src, samples, lines, mean,
	      NULL, img);
  FCLOSE(fp);

  if (filter) {
    asfPrintStatus("\nFiltering source image subset with %s (%dx%d) ...\n",
		   uc(filter_str), size, size);
    filter_image(img, filtered_img, filter_type, size, lines, samples);
  }

  // Update metadata and write source subset to file
  metaSrc->general->line_count = lines;
  metaSrc->general->sample_count = samples;
  metaSrc->general->start_line = startY_src;
  metaSrc->general->start_sample = startX_src;
  meta_write(metaSrc, outFile);
  envi = meta2envi(metaSrc);
  write_envi_header(outFile, outFile, metaSrc, envi);

  fp = FOPEN(outFile, "wb");
  if (filter)
    put_float_lines(fp, metaSrc, 0, lines, filtered_img);
  else
    put_float_lines(fp, metaSrc, 0, lines, img);
  FCLOSE(fp);

  // Clean up
  FREE(img);
  meta_free(metaSrc);
  meta_free(metaTrg);

  // Exporting subsets to GeoTIFF
  if (geotiff) {
    output_format_t output_format=GEOTIFF;
    scale_t sample_mapping=SIGMA;

    asfPrintStatus("\nExporting source image subset to GeoTIFF ...\n");
    sprintf(outFile, "%s_sub", srcImage);
    asf_export(output_format, sample_mapping, outFile, outFile);
    asfPrintStatus("\nExporting target image subset to GeoTIFF ...\n");
    sprintf(outFile, "%s_sub", trgImage);
    asf_export(output_format, sample_mapping, outFile, outFile);
  }

  return (0);
}
Exemple #12
0
/*
 * Process queries - return list of available agent programs
 */
INTERNAL int
agent_query(EVENT_AGENTD_REQ *eagent, DIR *dir, char *dirpath) {
	EVENT_AGENTD_MOD emod;
	struct dirent   *dirent;
	struct stat      statb;
	char             path[PATHLEN];
	char            *bufp;
	int              ntot, nmod, len, bytes;
	int              rc;

	if (Verbose)
	  printf("processing agentd query from %d\n", eagent->head.from);

	ntot  = 0;
	bufp  = &emod.modules[0];
	bytes = AGENTD_LISTBUF-1;
	nmod  = 0;

	while (dirent = readdir(dir)) {
		if (*dirpath) sprintf(path, "%s/%s", dirpath, dirent->d_name);
		else          strcpy(path,  dirent->d_name);
		if (stat(path, &statb) != SYS_OK) {
			if (errno == EACCES) continue;
			fprintf(stderr, "error stating %s\n", path);
			continue;
		}

		if (Debug)
		  printf("agent_query: processing file %s %o\n", path, statb.st_mode);

		if (statb.st_mode&S_IFDIR) {
			DIR *subdir;

			if (dirent->d_name[0] == '.') continue;
			subdir = opendir(path);
			if (!subdir) {
				fprintf(stderr, "error opening subdir %s\n", path);
				continue;
			}
			ntot += agent_query(eagent, subdir, path);
			closedir(subdir);
			continue;
		}
		if (!(statb.st_mode&S_IFREG) ||
		    !strmatch(eagent->module, path) ||
		    access(path, X_OK)
		    ) continue;

		/* Copy module name to query event */
		len = strlen(path)+1;
		if (len >= AGENTD_LISTBUF-1) { /* This would be very, very bad */
			fprintf(stderr,
				"path too long for event buffer!!!\"%s\"\n",
				path);
			continue;
		}
		if (len > bytes) {      /* If no room send and start anew */
			*bufp         = '\0';
			emod.flags    = AGENTD_FLAG_MORE;
			emod.tag      = eagent->tag;
			emod.nmodules = nmod;
			event_clientname(emod.hostname);
			SEND(EventFrom(*eagent), AGENTD_MOD, emod);

			bytes = AGENTD_LISTBUF-1;
			nmod  = 0;
			bufp  = &emod.modules[0];
		}
		strcpy(bufp, path);
		bufp  += len;
		bytes -= len;
		++nmod;
	}
	if (nmod) {
		*bufp         = '\0';
		emod.flags    = 0;
		emod.tag      = eagent->tag;
		emod.nmodules = nmod;
		event_clientname(emod.hostname);
		SEND(EventFrom(*eagent), AGENTD_MOD, emod);
	}
	return(ntot+nmod);
}
Exemple #13
0
main(int argc, char *argv[]) {
	char *pgm, *s;
	int   ok, help;
	char *server;
	int   id, nc;
	int   i;
	char  me[256];
	char  logstr[200];

	pgm = argv[0];

	/* Get and save our original working directory */
	if (!GetWD(SelfWD, sizeof(SelfWD))) {
		fprintf(stderr, "%s: couldn't get working directory\n", pgm);
		perror(pgm);
		exit(4);
	}

	/* Get our own name and any path prefix */
	if (pgm = strrchr(argv[0], '/')) {
		*pgm++ = '\0';
		if (*argv[0] == '/') strcpy(Logdir, argv[0]);
		else                 make_path(Logdir, SelfWD, argv[0]);
		if (Verbose) printf("Logdir search is \"%s\"\n", Logdir);
	}
	else {
		strcpy(Logdir, SelfWD);
		pgm = argv[0];
	}

	++argv; --argc;

	/* See if we are running as the LOGGER */
	sprintf(logstr, "{%s,%s%s}", LOGGEREXEC, LOGGEREXEC, LOGGEREXT);
	if (strmatch(logstr, pgm)) logger(pgm, argc, argv);

	/* Default options */
	ok    = 1;
	help  = 0;

	/* Parse out command line options */
	while (argc && *argv[0] == '-') {
		char *opt;

		opt = argv[0] + 1;
		++argv; --argc;

		if      (substr(opt, "help"))    ++help;
		else if (substr(opt, "debug"))   ++Debug;
		else if (substr(opt, "nodebug")) Debug   = 0;
		else if (substr(opt, "verbose")) Verbose = 1;
		else if (substr(opt, "quiet"))   Verbose = 0;
		else if (streq(opt, "bin") || streq(opt, "dir")) {
			if (argc < 1) {
				fprintf(stderr, "%s: missing argument to -%s\n",
					pgm, opt);
				ok = 0;
				break;
			}
			RootPath = argv[0];
			++argv; --argc;
		}
		else if (streq(opt, "wd") || streq(opt, "cd")) {
			if (argc < 1) {
				fprintf(stderr, "%s: missing argument to -%s\n",
					pgm, opt);
				ok = 0;
				break;
			}
			WorkDir = argv[0];
			++argv; --argc;
		}
		else if (substr(opt, "logger")) {
			if (argc < 1) {
				fprintf(stderr, "%s: missing argument to -%s\n",
					pgm, opt);
				ok = 0;
				break;
			}
			if (argv[0][0] == '/') strcpy(Logger, argv[0]);
			else {
				int  len;
				char *name;

				/* Copy the current working directory */
				strcpy(Logger, SelfWD);
				len = strlen(Logger);
				if (Logger[len-1] != '/') Logger[len++] = '/';

				name = argv[0];
				if (substr("./", name)) name += 2;
				strcpy(Logger+len, name);
			}
			++argv; --argc;
		}
		else {
			fprintf(stderr, "%s: ignoring argument -%s\n", pgm, opt);
			help = 1;
			ok   = 0;
		}
	}
	if (!ok || argc == 0) {
		usage(pgm, help);
		exit(!help);
	}

	server = argv[0];
	++argv; --argc;

	/* Allow directory to be specified as last command line arg */
	if (argc) {
		if (RootPath) {
			if (!streq(RootPath, argv[0])) {
				fprintf(stderr,
					 "%s: can't use -dir (%s) and specify path (%s)\n",
					 pgm, RootPath, argv[0]);
				exit(4);
			}
		}
		else {
			RootPath = argv[0];
			++argv; --argc;
		}
	}

	/* Check for any extraneous args */
	if (argc) {
		fprintf(stderr, "%s: too many arguments starting with \"%s\"\n",
			pgm, argv[0]);
		usage(pgm, help);
		exit(!help);
	}

	/* Now change to our root directory */
	if (RootPath) {
		if (chdir(RootPath) != SYS_OK) {
			fprintf(stderr, "%s: couldn't chdir to \"%s\"\n", pgm, RootPath);
			exit(4);
		}
	}
	else fprintf(stderr, "%s: WARNING! no root directory specified - using .\n", pgm);

	/* Set up path to working directory for lauched agents */
	if (WorkDir)
	   if (*WorkDir == '/') strcpy(WorkPath, WorkDir);
	   else make_path(WorkPath, SelfWD, WorkDir);

	/* Open the executable directory to process queries */
	if (!GetWD(ExecPath, sizeof(ExecPath))) {
		fprintf(stderr, "%s: couldn't get working directory\n", pgm);
		perror(pgm);
		exit(4);
	}

	ExecDir = opendir(ExecPath);
	if (!ExecDir) {
		fprintf(stderr, "%s: couldn't open working directory \"%s\"\n", pgm, ExecPath);
		perror(pgm);
		exit(4);
	}

#ifdef win32
	/*
	 * On windows we need to run the logger as a separate helper app
	 * since the cygwin implementation of fork is not quite right.
	 * Look for it in standard places as well as looking as users $PATH
	 */
	if (!Logger[0] && !find_logger()) {
		fprintf(stderr,
			"%s: couldn't find initiator \"%s\"\n",
			pgm, LOGGEREXEC);
		exit(4);
	}
	if (Verbose) printf("Logger exec is \"%s\"\n", Logger);
#endif

	/* Make sure we found the file and it is executable */
	if (Logger[0] && access(Logger, X_OK) != SYS_OK) {
		fprintf(stderr,
			"%s: initiator \"%s\" not %s\n", pgm, Logger,
			access(Logger, F_OK)?"found":"executable");
		exit(4);
	}

	/* Deal with signals */
	siginit();

	/* local initialization */
	event_verbose(Verbose);
	event_tunnel_enable(0);
	agentd_init();

	/* Connect to our event server */
	id = event_join(server, &nc);
	if (!id) {
		fprintf(stderr, "%s: couldn't join server \"%s\"\n", pgm, server);
		exit(4);
	}
	if (Verbose) printf("%s: joined %s as client id %d (%d clients)\n", pgm, server, id, nc);

	/* Register */
	cuserid(me);

	event_register(AGENTDCLASS, AGENTDSPEC, me);

	/* Subscribe to only AGENTD type events */
	event_select_type(0, ET_MIN, ET_MAX);
	event_select_type(1, ET_AGENTD_MIN, ET_AGENTD_MAX);

	/* Initialize agent control structures */
	for (i = 0; i < MAX_AGENT; ++i) {
		Agent[i].pid    = 0;
		Agent[i].status = AGENTD_AGENT_FREE;
	}

	mp_init();  /*(not strcitly necessary, since done in event land)*/

	/* Allocate our locks and semaphores */
	AgentLock = mp_alloclock();

	Exitlock  = mp_alloclock();
	Exitwait  = mp_allocsema();
	ReadInit  = mp_allocsema();
	AgentInit = mp_allocsema();

	/*
	 * Loop forever processing agentd requests
	 */
	FOREVER {
		EVENT e;

		/* Wait for an event and then dispatch it */
		event_wait();
		if (!event_receive(&e)) continue;

		switch (e.ev_head.type) {
		  case ET_AGENTD_REQ:
			agent_request((EVENT_AGENTD_REQ *)&e);
			break;

		  default:
			if (Verbose)
			   printf("Ignoring event \'%s\'(%d) from %d\n",
				   event_lookup_name(e.ev_head.type),
				   e.ev_head.type, e.ev_head.from);
		}
	}
}
Exemple #14
0
/** 
 * <EN>
 * Fill in system default values to a search parameter structure.
 * 
 * @param j [in] search configuration parameter structure
 * </EN>
 * <JA>
 * 探索(SEARCH)パラメータ構造体に初期値を代入する.
 * 
 * @param j [in] 探索パラメータ構造体
 * </JA>
 * 
 * @callgraph
 * @callergraph
 * 
 */
void
jconf_set_default_values_search(JCONF_SEARCH *j)
{
  j->name[0] = '\0';

  j->amconf = NULL;
  j->lmconf = NULL;
  j->compute_only_1pass			= FALSE;
  j->force_ccd_handling			= FALSE;
  j->ccd_handling			= FALSE;
  /* 
    default values below are assigned later using HMM information:
	j->lmp.*
  */
  j->lmp.lm_penalty_trans		= 0.0;
  j->lmp.penalty1			= 0.0;
  j->lmp.penalty2			= 0.0;
  j->lmp.lmp2_specified			= FALSE;
  j->lmp.lmp_specified			= FALSE;

  j->pass1.specified_trellis_beam_width	= -1;
#ifdef SCORE_PRUNING
  j->pass1.score_pruning_width		= -1.0;
#endif
#if defined(WPAIR) && defined(WPAIR_KEEP_NLIMIT)
  j->pass1.wpair_keep_nlimit		= 3;
#endif
#ifdef HASH_CACHE_IW
  j->pass1.iw_cache_rate		= 10;
#endif
  j->pass1.old_tree_function_flag = FALSE;
#ifdef DETERMINE
  j->pass1.determine_score_thres = 10.0;
  j->pass1.determine_duration_thres = 6;
#endif
  if (strmatch(JULIUS_SETUP, "fast")) {
    j->pass2.nbest		= 1;
    j->pass2.enveloped_bestfirst_width = 30;
  } else {
    j->pass2.nbest		= 10;
    j->pass2.enveloped_bestfirst_width = 100;
  }
#ifdef SCAN_BEAM
  j->pass2.scan_beam_thres	= 80.0;
#endif
  j->pass2.hypo_overflow		= 2000;
  j->pass2.stack_size		= 500;
  j->pass2.lookup_range		= 5;
  j->pass2.looktrellis_flag	= FALSE; /* dfa */

  j->graph.enabled			= FALSE;
  j->graph.lattice			= FALSE;
  j->graph.confnet			= FALSE;
  j->graph.graph_merge_neighbor_range	= 0;
#ifdef   GRAPHOUT_DEPTHCUT
  j->graph.graphout_cut_depth		= 80;
#endif
#ifdef   GRAPHOUT_LIMIT_BOUNDARY_LOOP
  j->graph.graphout_limit_boundary_loop_num = 20;
#endif
#ifdef   GRAPHOUT_SEARCH_DELAY_TERMINATION
  j->graph.graphout_search_delay	= FALSE;
#endif
  j->successive.enabled			= FALSE;
  j->successive.sp_frame_duration	= 10;
  j->successive.pausemodelname		= NULL;
#ifdef SPSEGMENT_NAIST
  j->successive.sp_margin		= DEFAULT_SP_MARGIN;
  j->successive.sp_delay		= DEFAULT_SP_DELAY;
#endif
#ifdef CONFIDENCE_MEASURE
  j->annotate.cm_alpha			= 0.05;
#ifdef   CM_MULTIPLE_ALPHA
  j->annotate.cm_alpha_bgn		= 0.03;
  j->annotate.cm_alpha_end		= 0.15;
  j->annotate.cm_alpha_num		= 5;
  j->annotate.cm_alpha_step		= 0.03;
#endif
#ifdef   CM_SEARCH_LIMIT
  j->annotate.cm_cut_thres		= 0.03;
#endif
#ifdef   CM_SEARCH_LIMIT_POPO
  j->annotate.cm_cut_thres_pop		= 0.1;
#endif
#endif /* CONFIDENCE_MEASURE */
  j->annotate.align_result_word_flag	= FALSE;
  j->annotate.align_result_phoneme_flag	= FALSE;
  j->annotate.align_result_state_flag	= FALSE;

  j->output.output_hypo_maxnum		= 1;
  j->output.progout_flag		= FALSE;
  j->output.progout_interval		= 300;
  j->output.multigramout_flag		= FALSE; /* dfa */
  
  j->sw.trellis_check_flag		= FALSE;
  j->sw.triphone_check_flag		= FALSE;
  j->sw.wchmm_check_flag		= FALSE;
  j->sw.start_inactive			= FALSE;
  j->sw.fallback_pass1_flag		= FALSE;

#ifdef USE_MBR
  j->mbr.use_mbr = FALSE;
  j->mbr.use_word_weight = FALSE;
  j->mbr.score_weight = 0.1;
  j->mbr.loss_weight = 1.0;
#endif
}
Exemple #15
0
static Extype_t
eval(Expr_t* ex, register Exnode_t* expr, void* env)
{
	register Exnode_t*	x;
	register Exnode_t*	a;
	register Extype_t**	t;
	register int		n;
	Extype_t		v;
	Extype_t		r;
	Extype_t		i;
	char*			e;
	Exnode_t		tmp;
	Exassoc_t*		assoc;
	Extype_t		args[FRAME+1];
	Extype_t		save[FRAME];

	if (!expr || ex->loopcount)
	{
		v.integer = 1;
		return v;
	}
	x = expr->data.operand.left;
	switch (expr->op)
	{
	case BREAK:
	case CONTINUE:
		v = eval(ex, x, env);
		ex->loopcount = v.integer;
		ex->loopop = expr->op;
		return v;
	case CONSTANT:
		return expr->data.constant.value;
	case DEC:
		n = -1;
	add:
		if (x->op == DYNAMIC)
			r = getdyn(ex, x, env, &assoc);
		else
		{
			if (x->data.variable.index)
				i = eval(ex, x->data.variable.index, env);
			else
				i.integer = EX_SCALAR;
			r = (*ex->disc->getf)(ex, x, x->data.variable.symbol, x->data.variable.reference, env, (int)i.integer, ex->disc);
		}
		v = r;
		switch (x->type)
		{
		case FLOATING:
			v.floating += n;
			break;
		case INTEGER:
		case UNSIGNED:
			v.integer += n;
			break;
		default:
			goto huh;
		}
	set:
		if (x->op == DYNAMIC)
		{
			if (x->type == STRING)
			{
				v.string = vmstrdup(ex->vm, v.string);
				if (e = assoc ? assoc->value.string : x->data.variable.symbol->value->data.constant.value.string)
					vmfree(ex->vm, e);
			}
			if (assoc)
				assoc->value = v;
			else
				x->data.variable.symbol->value->data.constant.value = v;
		}
		else
		{
			if (x->data.variable.index)
				i = eval(ex, x->data.variable.index, env);
			else
				i.integer = EX_SCALAR;
			if ((*ex->disc->setf)(ex, x, x->data.variable.symbol, x->data.variable.reference, env, (int)i.integer, v, ex->disc) < 0)
				exerror("%s: cannot set value", x->data.variable.symbol->name);
		}
		if (expr->subop == PRE)
			r = v;
		return r;
	case DYNAMIC:
		return getdyn(ex, expr, env, &assoc);
	case EXIT:
		v = eval(ex, x, env);
		exit((int)v.integer);
		/*NOTREACHED*/
		v.integer = -1;
		return v;
	case IF:
		v = eval(ex, x, env);
		if (v.integer)
			eval(ex, expr->data.operand.right->data.operand.left, env);
		else
			eval(ex, expr->data.operand.right->data.operand.right, env);
		v.integer = 1;
		return v;
	case FOR:
	case WHILE:
		expr = expr->data.operand.right;
		for (;;)
		{
			r = eval(ex, x, env);
			if (!r.integer)
			{
				v.integer = 1;
				return v;
			}
			if (expr->data.operand.right)
			{
				eval(ex, expr->data.operand.right, env);
				if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop != CONTINUE))
				{
					v.integer = 0;
					return v;
				}
			}
			if (expr->data.operand.left)
				eval(ex, expr->data.operand.left, env);
		}
		/*NOTREACHED*/
	case SWITCH:
		v = eval(ex, x, env);
		i.integer = x->type;
		r.integer = 0;
		x = expr->data.operand.right;
		a = x->data.select.statement;
		n = 0;
		while (x = x->data.select.next)
		{
			if (!(t = x->data.select.constant))
				n = 1;
			else
				for (; *t; t++)
				{
					switch ((int)i.integer)
					{
					case INTEGER:
					case UNSIGNED:
						if ((*t)->integer == v.integer)
							break;
						continue;
					case STRING:
						if ((ex->disc->version >= 19981111L && ex->disc->matchf) ? (*ex->disc->matchf)(ex, x, (*t)->string, expr->data.operand.left, v.string, env, ex->disc) : strmatch((*t)->string, v.string))
							break;
						continue;
					case FLOATING:
						if ((*t)->floating == v.floating)
							break;
						continue;
					}
					n = 1;
					break;
				}
			if (n)
			{
				if (!x->data.select.statement)
				{
					r.integer = 1;
					break;
				}
				r = eval(ex, x->data.select.statement, env);
				if (ex->loopcount > 0)
				{
					ex->loopcount--;
					break;
				}
			}
		}
		if (!n && a)
		{
			r = eval(ex, a, env);
			if (ex->loopcount > 0)
				ex->loopcount--;
		}
		return r;
	case ITERATE:
		v.integer = 0;
		if (expr->data.generate.array->op == DYNAMIC)
		{
			n = expr->data.generate.index->type == STRING;
			for (assoc = (Exassoc_t*)dtfirst((Dt_t*)expr->data.generate.array->data.variable.symbol->local.pointer); assoc; assoc = (Exassoc_t*)dtnext((Dt_t*)expr->data.generate.array->data.variable.symbol->local.pointer, assoc))
			{
				v.integer++;
				if (n)
					expr->data.generate.index->value->data.constant.value.string = assoc->name;
				else
					expr->data.generate.index->value->data.constant.value.integer = strtol(assoc->name, NiL, 0);
				eval(ex, expr->data.generate.statement, env);
				if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop != CONTINUE))
				{
					v.integer = 0;
					break;
				}
			}
		}
		else
		{
			r = (*ex->disc->getf)(ex, expr, expr->data.generate.array->data.variable.symbol, expr->data.generate.array->data.variable.reference, env, 0, ex->disc);
			for (v.integer = 0; v.integer < r.integer; v.integer++)
			{
				expr->data.generate.index->value->data.constant.value.integer = v.integer;
				eval(ex, expr->data.generate.statement, env);
				if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop != CONTINUE))
				{
					v.integer = 0;
					break;
				}
			}
		}
		return v;
	case CALL:
		x = expr->data.call.args;
		for (n = 0, a = expr->data.call.procedure->value->data.procedure.args; a && x; a = a->data.operand.right)
		{
			if (n < elementsof(args))
			{
				save[n] = a->data.operand.left->data.variable.symbol->value->data.constant.value;
				args[n++] = eval(ex, x->data.operand.left, env);
			}
			else
				a->data.operand.left->data.variable.symbol->value->data.constant.value = eval(ex, x->data.operand.left, env);
			x = x->data.operand.right;
		}
		for (n = 0, a = expr->data.call.procedure->value->data.procedure.args; a && n < elementsof(save); a = a->data.operand.right)
			a->data.operand.left->data.variable.symbol->value->data.constant.value = args[n++];
		if (x)
			exerror("too many actual args");
		else if (a)
			exerror("not enough actual args");
		v = exeval(ex, expr->data.call.procedure->value->data.procedure.body, env);
		for (n = 0, a = expr->data.call.procedure->value->data.procedure.args; a && n < elementsof(save); a = a->data.operand.right)
			a->data.operand.left->data.variable.symbol->value->data.constant.value = save[n++];
		return v;
	case FUNCTION:
		n = 0;
		args[n++].string = (char*)env;
		for (x = expr->data.operand.right; x && n < elementsof(args); x = x->data.operand.right)
			args[n++] = eval(ex, x->data.operand.left, env);
		return (*ex->disc->getf)(ex, expr->data.operand.left, expr->data.operand.left->data.variable.symbol, expr->data.operand.left->data.variable.reference, args+1, EX_CALL, ex->disc);
	case ID:
		if (expr->data.variable.index)
			i = eval(ex, expr->data.variable.index, env);
		else
			i.integer = EX_SCALAR;
		return (*ex->disc->getf)(ex, expr, expr->data.variable.symbol, expr->data.variable.reference, env, (int)i.integer, ex->disc);
	case INC:
		n = 1;
		goto add;
	case PRINTF:
		v.integer = print(ex, expr, env, NiL);
		return v;
	case QUERY:
		print(ex, expr, env, sfstderr);
		v.integer = !astquery(2, "");
		return v;
	case RETURN:
		ex->loopret = eval(ex, x, env);
		ex->loopcount = 32767;
		ex->loopop = expr->op;
		return ex->loopret;
	case SCANF:
	case SSCANF:
		v.integer = scan(ex, expr, env, NiL);
		return v;
	case SPRINTF:
		print(ex, expr, env, ex->tmp);
		v.string = exstash(ex->tmp, ex->ve);
		return v;
	case '=':
		v = eval(ex, expr->data.operand.right, env);
		if (expr->subop != '=')
		{
			r = v;
			if (x->op == DYNAMIC)
				v = getdyn(ex, x, env, &assoc);
			else
			{
				if (x->data.variable.index)
					v = eval(ex, x->data.variable.index, env);
				else
					v.integer = EX_SCALAR;
				v = (*ex->disc->getf)(ex, x, x->data.variable.symbol, x->data.variable.reference, env, (int)v.integer, ex->disc);
			}
			switch (x->type)
			{
			case FLOATING:
				switch (expr->subop)
				{
				case '+':
					v.floating += r.floating;
					break;
				case '-':
					v.floating -= r.floating;
					break;
				case '*':
					v.floating *= r.floating;
					break;
				case '/':
					if (r.floating == 0.0)
						exerror("floating divide by 0");
					else
						v.floating /= r.floating;
					break;
				case '%':
					if ((r.integer = r.floating) == 0)
						exerror("floating 0 modulus");
					else
						v.floating = ((Sflong_t)v.floating) % r.integer;
					break;
				case '&':
					v.floating = ((Sflong_t)v.floating) & ((Sflong_t)r.floating);
					break;
				case '|':
					v.floating = ((Sflong_t)v.floating) | ((Sflong_t)r.floating);
					break;
				case '^':
					v.floating = ((Sflong_t)v.floating) ^ ((Sflong_t)r.floating);
					break;
				case LS:
					v.floating = ((Sflong_t)v.floating) << ((Sflong_t)r.floating);
					break;
				case RS:
#if _WIN32
					v.floating = (Sflong_t)(((Sfulong_t)v.floating) >> ((Sflong_t)r.floating));
#else
					v.floating = ((Sfulong_t)v.floating) >> ((Sflong_t)r.floating);
#endif
					break;
				default:
					goto huh;
				}
				break;
			case INTEGER:
			case UNSIGNED:
				switch (expr->subop)
				{
				case '+':
					v.integer += r.integer;
					break;
				case '-':
					v.integer -= r.integer;
					break;
				case '*':
					v.integer *= r.integer;
					break;
				case '/':
					if (r.integer == 0)
						exerror("integer divide by 0");
					else
						v.integer /= r.integer;
					break;
				case '%':
					if (r.integer == 0)
						exerror("integer 0 modulus");
					else
						v.integer %= r.integer;
					break;
				case '&':
					v.integer &= r.integer;
					break;
				case '|':
					v.integer |= r.integer;
					break;
				case '^':
					v.integer ^= r.integer;
					break;
				case LS:
					v.integer <<= r.integer;
					break;
				case RS:
					v.integer = (Sfulong_t)v.integer >> r.integer;
					break;
				default:
					goto huh;
				}
				break;
			case STRING:
				switch (expr->subop)
				{
				case '+':
					v.string = str_add(ex, v.string, r.string);
					break;
				case '|':
					v.string = str_ior(ex, v.string, r.string);
					break;
				case '&':
					v.string = str_and(ex, v.string, r.string);
					break;
				case '^':
					v.string = str_xor(ex, v.string, r.string);
					break;
				case '%':
					v.string = str_mod(ex, v.string, r.string);
					break;
				case '*':
					v.string = str_mpy(ex, v.string, r.string);
					break;
				default:
					goto huh;
				}
				break;
			default:
				goto huh;
			}
		}
		else if (x->op == DYNAMIC)
Exemple #16
0
Encoding *_FindOrMakeEncoding(const char *name,int make_it) {
    Encoding *enc;
    char buffer[20];
    const char *iconv_name;
    Encoding temp;
    uint8 good[256];
    int i, j, any, all;
    char from[8], ucs[20];
    size_t fromlen, tolen;
    ICONV_CONST char *fpt;
    char *upt;
    /* iconv is not case sensitive */

    if ( strncasecmp(name,"iso8859_",8)==0 || strncasecmp(name,"koi8_",5)==0 ) {
	/* Fixup for old naming conventions */
	strncpy(buffer,name,sizeof(buffer));
	*strchr(buffer,'_') = '-';
	name = buffer;
    } else if ( strcasecmp(name,"iso-8859")==0 ) {
	/* Fixup for old naming conventions */
	strncpy(buffer,name,3);
	strncpy(buffer+3,name+4,sizeof(buffer)-3);
	name = buffer;
    } else if ( strcasecmp(name,"isolatin1")==0 ) {
        name = "iso8859-1";
    } else if ( strcasecmp(name,"isocyrillic")==0 ) {
        name = "iso8859-5";
    } else if ( strcasecmp(name,"isoarabic")==0 ) {
        name = "iso8859-6";
    } else if ( strcasecmp(name,"isogreek")==0 ) {
        name = "iso8859-7";
    } else if ( strcasecmp(name,"isohebrew")==0 ) {
        name = "iso8859-8";
    } else if ( strcasecmp(name,"isothai")==0 ) {
        name = "tis-620";	/* TIS doesn't define non-breaking space in 0xA0 */ 
    } else if ( strcasecmp(name,"latin0")==0 || strcasecmp(name,"latin9")==0 ) {
        name = "iso8859-15";	/* "latin-9" is supported (libiconv bug?) */ 
    } else if ( strcasecmp(name,"koi8r")==0 ) {
        name = "koi8-r";
    } else if ( strncasecmp(name,"jis201",6)==0 || strncasecmp(name,"jisx0201",8)==0 ) {
        name = "jis_x0201";
    } else if ( strcasecmp(name,"AdobeStandardEncoding")==0 || strcasecmp(name,"Adobe")==0 )
	name = "AdobeStandard";
    for ( enc=enclist; enc!=NULL; enc=enc->next )
	if ( strmatch(name,enc->enc_name)==0 ||
		(enc->iconv_name!=NULL && strmatch(name,enc->iconv_name)==0))
return( enc );
    if ( strmatch(name,"unicode")==0 || strmatch(name,"iso10646")==0 || strmatch(name,"iso10646-1")==0 )
return( &unicodebmp );
    if ( strmatch(name,"unicode4")==0 || strmatch(name,"ucs4")==0 )
return( &unicodefull );

    iconv_name = name;
    /* Mac seems to work ok */
    if ( strcasecmp(name,"win")==0 || strcasecmp(name,"ansi")==0 )
	iconv_name = "MS-ANSI";		/* "WINDOWS-1252";*/
    else if ( strcasecmp(name,"gb2312pk")==0 || strcasecmp(name,"gb2312packed")==0 )
    iconv_name = "EUC-CN";
    else if ( strcasecmp(name,"wansung")==0 )
	iconv_name = "EUC-KR";
    else if ( strcasecmp(name,"EUC-CN")==0 ) {
	iconv_name = name;
	name = "gb2312pk";
    } else if ( strcasecmp(name,"EUC-KR")==0 ) {
	iconv_name = name;
	name = "wansung";
    }

/* Escape sequences:					*/
/*	ISO-2022-CN:     \e $ ) A ^N			*/
/*	ISO-2022-KR:     \e $ ) C ^N			*/
/*	ISO-2022-JP:     \e $ B				*/
/*	ISO-2022-JP-2:   \e $ ( D			*/
/*	ISO-2022-JP-3:   \e $ ( O			*/ /* Capital "O", not zero */
/*	ISO-2022-CN-EXT: \e $ ) E ^N			*/ /* Not sure about this, also uses CN escape */

    memset(&temp,0,sizeof(temp));
    temp.builtin = true;
    temp.tounicode = iconv_open(FindUnicharName(),iconv_name);
    if ( temp.tounicode==(iconv_t) -1 || temp.tounicode==NULL )
return( NULL );			/* Iconv doesn't recognize this name */
    temp.fromunicode = iconv_open(iconv_name,FindUnicharName());
    if ( temp.fromunicode==(iconv_t) -1 || temp.fromunicode==NULL ) {
	/* This should never happen, but if it does... */
	iconv_close(temp.tounicode);
return( NULL );
    }

    memset(good,0,sizeof(good));
    any = false; all = true;
    for ( i=1; i<256; ++i ) {
	from[0] = i; from[1] = 0;
	fromlen = 1;
	fpt = from;
	upt = ucs;
	tolen = sizeof(ucs);
	if ( iconv( temp.tounicode , &fpt, &fromlen, &upt, &tolen )!= (size_t) (-1)) {
	    good[i] = true;
	    any = true;
	} else
	    all = false;
    }
    if ( any )
	temp.has_1byte = true;
    if ( all )
	temp.only_1byte = true;

    if ( !all ) {
	if ( strstr(iconv_name,"2022")==NULL ) {
	    for ( i=temp.has_1byte; i<256; ++i ) if ( !good[i] ) {
		for ( j=0; j<256; ++j ) {
		    from[0] = i; from[1] = j; from[2] = 0;
		    fromlen = 2;
		    fpt = from;
		    upt = ucs;
		    tolen = sizeof(ucs);
		    if ( iconv( temp.tounicode , &fpt, &fromlen, &upt, &tolen )!= (size_t) (-1) &&
			    upt-ucs==sizeof(unichar_t) /* Exactly one character */ ) {
			if ( temp.low_page==-1 )
			    temp.low_page = i;
			temp.high_page = i;
			temp.has_2byte = true;
		break;
		    }
		}
	    }
	    if ( temp.low_page==temp.high_page ) {
		temp.has_2byte = false;
		temp.low_page = temp.high_page = -1;
	    }
	}
	if ( !temp.has_2byte && !good[033]/* escape */ ) {
	    if ( strstr(iconv_name,"2022")!=NULL &&
		    strstr(iconv_name,"JP3")!=NULL &&
                      TryEscape( &temp,"\33$(O" )) {
		;
	    }
	    else if ( strstr(iconv_name,"2022")!=NULL &&
		    strstr(iconv_name,"JP2")!=NULL &&
		      TryEscape( &temp,"\33$(D" )) {
		;
	    }
	    else if ( strstr(iconv_name,"2022")!=NULL &&
		    strstr(iconv_name,"JP")!=NULL &&
		      TryEscape( &temp,"\33$B" )) {
		;
	    }
	    else if ( strstr(iconv_name,"2022")!=NULL &&
		    strstr(iconv_name,"KR")!=NULL &&
		      TryEscape( &temp,"\33$)C\16" )) {
		;
	    }
	    else if ( strstr(iconv_name,"2022")!=NULL &&
		    strstr(iconv_name,"CN")!=NULL &&
		      TryEscape( &temp,"\33$)A\16" )) {
		;
	    }
	}
    }
    if ( !temp.has_1byte && !temp.has_2byte )
return( NULL );
    if ( !make_it )
return( NULL );

    enc = chunkalloc(sizeof(Encoding));
    *enc = temp;
    enc->enc_name = copy(name);
    if ( iconv_name!=name )
	enc->iconv_name = copy(iconv_name);
    enc->next = enclist;
    enc->builtin = true;
    enclist = enc;
    if ( enc->has_2byte )
	enc->char_cnt = (enc->high_page<<8) + 256;
    else {
	enc->char_cnt = 256;
	enc->only_1byte = true;
    }
    if ( strstrmatch(iconv_name,"JP")!=NULL ||
	    strstrmatch(iconv_name,"sjis")!=NULL ||
	    strstrmatch(iconv_name,"cp932")!=NULL )
	enc->is_japanese = true;
    else if ( strstrmatch(iconv_name,"KR")!=NULL )
	enc->is_korean = true;
    else if ( strstrmatch(iconv_name,"CN")!=NULL )
	enc->is_simplechinese = true;
    else if ( strstrmatch(iconv_name,"BIG")!=NULL && strstrmatch(iconv_name,"5")!=NULL )
	enc->is_tradchinese = true;

    if ( strstrmatch(name,"ISO8859")!=NULL &&
	    strtol(name+strlen(name)-2,NULL,10)>=16 )
	/* Not in our menu, don't hide */;
    else if ( iconv_name!=name || strmatch(name,"mac")==0 || strstrmatch(name,"ISO8859")!=NULL ||
	    strmatch(name,"koi8-r")==0 || strmatch(name,"sjis")==0 ||
	    strmatch(name,"big5")==0 || strmatch(name,"big5hkscs")==0 )
	enc->hidden = true;

return( enc );
}
Exemple #17
0
/** 
 * Register a physical %HMM as a member of a pseudo phone set.
 * 
 * @param root [i/o] root node of %HMM search index node.
 * @param d [in] a physical defined %HMM to be added.
 * @param cdname [in] name of the pseudo phone set.
 * 
 * @return TRUE if newly registered, FALSE if the specified physical %HMM already exists in the pseudo phone.
 */
boolean
regist_cdset(APATNODE **root, HTK_HMM_Data *d, char *cdname, BMALLOC_BASE **mroot)
{
  boolean need_new;
  CD_State_Set *tmp;
  CD_Set *lset = NULL, *lmatch = NULL;
  int j,n;
  boolean changed = FALSE;

  if (strlen(cdname) >= MAX_HMMNAME_LEN) {
    jlog("Error: cdset: HMM name exceeds limit (%d): %s!\n", MAX_HMMNAME_LEN, cdname);
    jlog("Error: cdset: Please increase the value of MAX_HMMNAME_LEN (current = %d)\n", MAX_HMMNAME_LEN);
    exit(1);
  }
  
  /* check if the cdset already exist */
  need_new = TRUE;
  if (*root != NULL) {
    lmatch = aptree_search_data(cdname, *root);
    if (lmatch != NULL && strmatch(lmatch->name, cdname)) {
      /* exist, add to it later */
      lset = lmatch;
      need_new = FALSE;
      /* if the state num is larger than allocated, expand the lset */
      if (d->state_num > lset->state_num) {
	lset->stateset = (CD_State_Set *)myrealloc(lset->stateset, sizeof(CD_State_Set) * d->state_num);
	/* 0 1 ... (lset->state_num-1) */
	/* N A ... N                   */
	/* 0 1 ...                     ... (d->state_num-1) */
	/* N A ... A ..................... N                */
	/* malloc new area to expanded state (N to A above) */
	for(j = lset->state_num - 1; j < d->state_num - 1; j++) {
	  lset->stateset[j].maxnum = CD_STATE_SET_STEP;
	  lset->stateset[j].s = (HTK_HMM_State **)mymalloc(sizeof(HTK_HMM_State *) * lset->stateset[j].maxnum);
	  lset->stateset[j].num = 0;
	}
	lset->stateset[d->state_num-1].s = NULL;
	lset->stateset[d->state_num-1].num = 0;
	lset->stateset[d->state_num-1].maxnum = 0;
	
	lset->state_num = d->state_num;

	/* update transition table */
	lset->tr = d->tr;

	changed = TRUE;
      }
    }
  }

  if (need_new) {
    /* allocate as new with blank data */
    lset = cdset_new();
    lset->name = strdup(cdname);
    lset->state_num = d->state_num;
    lset->stateset = (CD_State_Set *)mymalloc(sizeof(CD_State_Set) * lset->state_num);
    /* assume first and last state has no outprob */
    lset->stateset[0].s = lset->stateset[lset->state_num-1].s = NULL;
    lset->stateset[0].num = lset->stateset[lset->state_num-1].num = 0;
    lset->stateset[0].maxnum = lset->stateset[lset->state_num-1].maxnum = 0;
    for(j=1;j<lset->state_num-1; j++) {
      /* pre-allocate only the first step */
      lset->stateset[j].maxnum = CD_STATE_SET_STEP;
      lset->stateset[j].s = (HTK_HMM_State **)mymalloc(sizeof(HTK_HMM_State *) * lset->stateset[j].maxnum);
      lset->stateset[j].num = 0;
    }
    /* assign transition table of first found %HMM (ad-hoc?) */
    lset->tr = d->tr;
    /* add to search index tree */
    if (*root == NULL) {
      *root = aptree_make_root_node(lset, mroot);
    } else {
      aptree_add_entry(lset->name, lset, lmatch->name, root, mroot);
    }

    changed = TRUE;
  }
    
  /* register each HMM states to the lcdset */
  for (j=1;j<d->state_num-1;j++) {
    tmp = &(lset->stateset[j]);
    /* check if the state has already registered */
    for(n = 0; n < tmp->num ; n++) {
      if (tmp->s[n] == d->s[j]) { /* compare by pointer */
	/*jlog("\tstate %d has same\n", n);*/
	break;
      }
    }
    if (n < tmp->num ) continue;	/* same state found, cancel regist. */
    
    /* expand storage area if necessary */
    if (tmp->num >= tmp->maxnum) {
      tmp->maxnum += CD_STATE_SET_STEP;
      tmp->s = (HTK_HMM_State **)myrealloc(tmp->s, sizeof(HTK_HMM_State *) * tmp->maxnum);
    }
    
    tmp->s[tmp->num] = d->s[j];
    tmp->num++;

    changed = TRUE;
  }

  return(changed);
}
Exemple #18
0
static void evalPrimary(Parser *p){
    double d, d2=NAN;
    char *next= p->s;
    int i;

    /* number */
    d= strtod(p->s, &next);
    if(next != p->s){
        push(p, d);
        p->s= next;
        return;
    }

    /* named constants */
    for(i=0; p->const_name[i]; i++){
        if(strmatch(p->s, p->const_name[i])){
            push(p, p->const_value[i]);
            p->s+= strlen(p->const_name[i]);
            return;
        }
    }

    p->s= strchr(p->s, '(');
    if(p->s==NULL){
        fprintf(stderr, "Parser: missing ( in \"%s\"\n", next);
        return;
    }
    p->s++; // "("
    evalExpression(p);
    d= pop(p);
    if(p->s[0]== ','){
        p->s++; // ","
        evalExpression(p);
        d2= pop(p);
    }
    if(p->s[0] != ')'){
        fprintf(stderr, "Parser: missing ) in \"%s\"\n", next);
        return;
    }
    p->s++; // ")"

         if( strmatch(next, "sinh"  ) ) d= sinh(d);
    else if( strmatch(next, "cosh"  ) ) d= cosh(d);
    else if( strmatch(next, "tanh"  ) ) d= tanh(d);
    else if( strmatch(next, "sin"   ) ) d= sin(d);
    else if( strmatch(next, "cos"   ) ) d= cos(d);
    else if( strmatch(next, "tan"   ) ) d= tan(d);
    else if( strmatch(next, "exp"   ) ) d= exp(d);
    else if( strmatch(next, "log"   ) ) d= log(d);
    else if( strmatch(next, "squish") ) d= 1/(1+exp(4*d));
    else if( strmatch(next, "gauss" ) ) d= exp(-d*d/2)/sqrt(2*M_PI);
    else if( strmatch(next, "abs"   ) ) d= fabs(d);
    else if( strmatch(next, "max"   ) ) d= d > d2 ? d : d2;
    else if( strmatch(next, "min"   ) ) d= d < d2 ? d : d2;
    else if( strmatch(next, "gt"    ) ) d= d > d2 ? 1.0 : 0.0;
    else if( strmatch(next, "gte"    ) ) d= d >= d2 ? 1.0 : 0.0;
    else if( strmatch(next, "lt"    ) ) d= d > d2 ? 0.0 : 1.0;
    else if( strmatch(next, "lte"    ) ) d= d >= d2 ? 0.0 : 1.0;
    else if( strmatch(next, "eq"    ) ) d= d == d2 ? 1.0 : 0.0;
//    else if( strmatch(next, "l1"    ) ) d= 1 + d2*(d - 1);
//    else if( strmatch(next, "sq01"  ) ) d= (d >= 0.0 && d <=1.0) ? 1.0 : 0.0;
    else{
        int error=1;
        for(i=0; p->func1_name && p->func1_name[i]; i++){
            if(strmatch(next, p->func1_name[i])){
                d= p->func1[i](p->opaque, d);
                error=0;
                break;
            }
        }

        for(i=0; p->func2_name && p->func2_name[i]; i++){
            if(strmatch(next, p->func2_name[i])){
                d= p->func2[i](p->opaque, d, d2);
                error=0;
                break;
            }
        }

        if(error){
            fprintf(stderr, "Parser: unknown function in \"%s\"\n", next);
            return;
        }
    }

    push(p, d);
}
Exemple #19
0
/** 
 * Parse the input line and set grammar information, one by line.
 * 
 * @param line [in] text buffer that holds a line of DFA file
 * @param dinfo [i/o] the read data will be appended to this DFA data
 * @param state_max [i/o] maximum number of state id appeared, will be updated
 * @param arc_num [i/o] number of read arcs, will be updated
 * @param terminal_max [i/o] maximum number of state id appended, will be updated
 * 
 * @return TRUE if the line was successfully parsed, FALSE if failed.
 */
boolean
rddfa_line(char *line, DFA_INFO *dinfo, int *state_max, int *arc_num, int *terminal_max)
{
  DFA_ARC *newarc;
  int state, terminal, next_state;
  unsigned int status;
  char *p;

  if (strmatch(buf, "DFAEND")) return(FALSE);
  /* format: state terminalID nextstate statuscode_of_state */
  if ((p = strtok(line, DELM)) == NULL) {
    jlog("Error: rddfa: failed to parse, corrupted or invalid data?\n");
    return FALSE;
  }
  state = atoi(p);
  if ((p = strtok(NULL, DELM)) == NULL) {
    jlog("Error: rddfa: failed to parse, corrupted or invalid data?\n");
    return FALSE;
  }
  terminal = atoi(p);
  if ((p = strtok(NULL, DELM)) == NULL) {
    jlog("Error: rddfa: failed to parse, corrupted or invalid data?\n");
    return FALSE;
  }
  next_state = atoi(p);
  if ((p = strtok(NULL, DELM)) == NULL) {
    jlog("Error: rddfa: failed to parse, corrupted or invalid data?\n");
    return FALSE;
  }
  sscanf(p, "%x", &status);

  if (state >= dinfo->maxstatenum) {      /* expand */
    dfa_state_expand(dinfo, state+1);
  }
  if (next_state >= dinfo->maxstatenum) { /* expand */
    dfa_state_expand(dinfo, next_state+1);
  }

  /* set state status (accept / initial) */
  if (status & ACCEPT_S) {
    dinfo->st[state].status |= ACCEPT_S;
  }
  /* the state #0 is an initial state */
  if (state == 0) {
    dinfo->st[state].status |= INITIAL_S;
  }
  
  /* skip line with negative terminalID/nextstate */
  if (terminal > 0 || next_state > 0) {
    /* add new arc to the state */
    newarc = (DFA_ARC *)mymalloc(sizeof(DFA_ARC));
    newarc->label    = terminal;
    newarc->to_state = next_state;
    newarc->next     = dinfo->st[state].arc;
    dinfo->st[state].arc = newarc;
    (*arc_num)++;
  }

  if (*state_max < state) *state_max = state;
  if (*terminal_max < terminal) *terminal_max = terminal;

  return(TRUE);
}
char *linux_bootchart_update_ps (char *ps, char *uptime) {
    DIR *d;
    struct dirent *e;
    char **data = NULL;

    d = opendir ("/proc");
    if (d != NULL) {
        while ((e = readdir (d))) {
            char *t, *u, *da = NULL;
            if (strmatch (e->d_name, ".") || strmatch (e->d_name, "..")) {
                continue;
            }

            if ((t = joinpath ("/proc/", e->d_name))) {
                if ((u = joinpath (t, "stat"))) {
                    struct stat st;
                    if (!stat (u, &st)) {
                        da = readfile (u);
                    }

                    free (u);
                }

                /*    if ((u = joinpath (t, "cmdline"))) {
                     struct stat st;
                     if (!stat (u, &st)) {
                      char *ru = readfile (u);

                      if (strstr (ru, )) {
                       linux_bootchart_have_thread = 0;
                      }
                     }

                     free (u);
                    }*/

                free (t);
            }

            if (da) {
                data = (char **)setadd ((void **)data, da, SET_TYPE_STRING);
                free (da);
                da = NULL;
            }
        }

        closedir(d);
    }

    if (data) {
        char *t = set2str ('\n', (const char **)data);

        if (t) {
            size_t len = strlen (uptime) + strlen (t) + 4 + (ps ? strlen (ps) : 0);
            char *tx = emalloc (len);

            if (ps) {
                esprintf (tx, len, "%s\n%s\n%s\n", ps, uptime, t);
                free (ps);
            } else {
                esprintf (tx, len, "%s\n%s\n", uptime, t);
            }

            free (t);

            ps = tx;
        }

        free (data);
    }

    return ps;
}
Exemple #21
0
/* readbuffer
 * Reads in the input file and stores all strings in the
 * section between "#ifdef SCPACK" and "#else" in a buffer.
 * Only text that is between double quotes is added to the
 * buffer; the \" escape code is handled. Multiple strings
 * on one line are handled.
 */
unsigned readbuffer(FILE *input, unsigned char *buffer)
{
  char str[256];
  unsigned buffersize;
  int i,linenr;

  linenr=0;
  buffersize=0;

  rewind(input);
  while (!feof(input)) {
    while (fgets(str,sizeof str,input)!=NULL) {
      linenr++;
      check_tablename(str);
      check_separator(str);
      if (strmatch(str,START_TOKEN,NULL))
        break;
    } /* while */
    if (!strmatch(str,START_TOKEN,NULL))
      return buffersize;  /* no (more) section found, quit */

    while (fgets(str,sizeof str,input)!=NULL) {
      linenr++;
      check_if(str,linenr);
      if (check_tablename(str))
        printf("Error: table name definition should not be in SCPACK section (line %d)\n", linenr);
      check_separator(str);
      if (strmatch(str,"#else",NULL))
        break;          /* done */
      /* add to the buffer only what is between double quotes */
      i=0;
      do {
        while (str[i]!='\0' && str[i]!='"')
          i++;
        if (str[i]=='"') {
          /* we are in a string */
          i++;
          while (str[i]!='\0' && str[i]!='"') {
            /* handle escape sequences */
            if (str[i]=='\\') {
              i++;
              switch (str[i]) {
              case 'a': /* alarm */
                buffer[buffersize++]='\a';
                i++;
                break;
              case 'b': /* backspace */
                buffer[buffersize++]='\b';
                i++;
                break;
              case 'f': /* form feed */
                buffer[buffersize++]='\f';
                i++;
                break;
              case 'n': /* newline */
                buffer[buffersize++]='\n';
                i++;
                break;
              case 'r': /* carriage return */
                buffer[buffersize++]='\n';
                i++;
                break;
              case 't': /* tab */
                buffer[buffersize++]='\t';
                i++;
                break;
              case '\'':
                buffer[buffersize++]='\'';
                i++;
                break;
              case '"':
                buffer[buffersize++]='"';
                i++;
                break;
              default:
                // ??? octal character code escapes and hexadecimal escapes
                //     not supported
                printf("Unknown escape sequence '\\%c' on line %d\n",
                       str[i], linenr);
              } /* switch */
            } else {
              buffer[buffersize++]=str[i++];
            } /* if */
          } /* while */
          if (str[i]=='"') {
            buffer[buffersize++]='\0'; /* terminate each string */
            i++;
          } else {
            printf("Error: unterminated string on line %d\n",linenr);
          } /* if */
        } /* if */
      } while (str[i]!='\0');
    } /* while - in SCPACK section */
    /* put in another '\0' to terminate the section */
    buffer[buffersize++]='\0';
  } /* while - !feof(input) */
  return buffersize;
}
Exemple #22
0
static int
str2code(char *codestr, unsigned int *code)
{
  if (strmatch(codestr, "euc-jp")
      || strmatch(codestr, "euc")
      || strmatch(codestr, "eucjp")) {
    /* input = Shift_jis (codepage 932) */
    *code = CODE_JPN_EUC;
  } else if (strmatch(codestr, "ansi")) {
    /* ANSI codepage (MBCS) ex. shift-jis in Windows XP Japanese edition.*/
    *code = CP_ACP;
  } else if (strmatch(codestr, "mac")) {
    /* Macintosh codepage */
    *code = CP_MACCP;
  } else if (strmatch(codestr, "oem")) {
    /* OEM localized default codepage */
    *code = CP_OEMCP;
  } else if (strmatch(codestr, "utf-7")) {
    /* UTF-7 codepage */
    *code = CP_UTF7;
  } else if (strmatch(codestr, "utf-8")) {
    /* UTF-8 codepage */
    *code = CP_UTF8;
  } else if (strmatch(codestr, "sjis")
	     || strmatch(codestr, "sjis-win")
	     || strmatch(codestr, "shift-jis")
	     || strmatch(codestr, "shift_jis")) {
    /* sjis codepage = 932 */
    *code = 932;
  } else if (codestr[0] >= '0' && codestr[0] <= '9') {
    /* codepage number */
    *code = atoi(codestr);
    if (! IsValidCodePage(*code)) {
      jlog("Error: charconv_win32: codepage \"%d\" not found\n", codestr);
      return -1;
    }
  } else {
    fprintf(stderr, "Error: str2code: unknown source codepage \"%s\"\n", codestr);
    fprintf(stderr, "Error: str2code: valids are \"euc-jp\", \"ansi\", \"mac\", \"oem\", \"utf-7\", \"utf-8\", \"sjis\" and codepage number\n");
    return -1;
  }
  
  return 0;
}
Exemple #23
0
mBOOL DLLINTERNAL MConfig::set(option_t *setp, const char *setstr) {
	char pathbuf[PATH_MAX];
	int *optval = (int *) setp->dest;
	char **optstr = (char **) setp->dest;
	// cvar_t *optcvar = (cvar_t *) setp->dest;
	// SETOPT_FN optcmd = (SETOPT_FN) setp->dest;

	if(!setstr)
		return(mTRUE);

	switch(setp->type) {
		case CF_INT:
			if(!isdigit(setstr[0])) {
				META_WARNING("option '%s' invalid format '%s'", setp->name, setstr);
				RETURN_ERRNO(mFALSE, ME_FORMAT);
			}
			*optval=atoi(setstr);
			META_DEBUG(3, ("set config int: %s = %d", setp->name, *optval));
			break;
		case CF_BOOL:
			if(strcasematch(setstr, "true")
					|| strcasematch(setstr, "yes")
					|| strmatch(setstr, "1"))
			{
				*optval=1;
			}
			else if(strcasematch(setstr, "false")
					|| strcasematch(setstr, "no")
					|| strmatch(setstr, "0"))
			{
				*optval=0;
			}
			else {
				META_WARNING("option '%s' invalid format '%s'", setp->name, setstr);
				RETURN_ERRNO(mFALSE, ME_FORMAT);
			}
			META_DEBUG(3, ("set config bool: %s = %s", setp->name, *optval ? "true" : "false"));
			break;
		case CF_STR:
			if(*optstr)
				free(*optstr);
			*optstr=strdup(setstr);
			META_DEBUG(3, ("set config string: %s = %s", setp->name, *optstr));
			break;
		case CF_PATH:
			if(*optstr)
				free(*optstr);
			full_gamedir_path(setstr, pathbuf);
			*optstr=strdup(pathbuf);
			META_DEBUG(3, ("set config path: %s = %s", setp->name, *optstr));
			break;
#if 0
		case CF_CVAR:
			CVAR_SET_STRING(optcvar->name, setstr);
			META_DEBUG(3, ("set config cvar: %s = %s", optcvar->name, setstr));
			break;
		case CF_CMD:
			optcmd(setp->name, setstr);
			META_DEBUG(3, ("set config command: %s, %s", optcvar->name, setstr));
			break;
#endif
		default:
			META_WARNING("unrecognized config type '%d'", setp->type);
			RETURN_ERRNO(mFALSE, ME_ARGUMENT);
	}
	return(mTRUE);
}
Exemple #24
0
void linux_hotplug_hotplug_event_handler (struct einit_event *ev) {
 if (ev->stringset) {
  char *subsystem = NULL;
  char *firmware = NULL;
  char *devpath = NULL;
  int i = 0;
  struct cfgnode *node = cfg_getnode ("configuration-system-hotplug-support-legacy-hotplug-scripts", NULL);

  for (; ev->stringset[i]; i+=2) {
   if (strmatch (ev->stringset[i], "SUBSYSTEM")) {
    subsystem = ev->stringset[i+1];
   } else if (strmatch (ev->stringset[i], "FIRMWARE")) {
    firmware = ev->stringset[i+1];
   } else if (strmatch (ev->stringset[i], "DEVPATH")) {
    devpath = ev->stringset[i+1];
   }
  }

  if (node && node->flag) {
   char **commands = NULL;

   if (subsystem) {
    char n = 0;

    for (; n < 2; n++) {
     char buffer[BUFFERSIZE];
     char *tbuffer = (n == 1) ? "/etc/einit/hotplug.d/default/" : NULL;

     switch (n) {
      case 0:
       esprintf(buffer, BUFFERSIZE, "/etc/einit/hotplug.d/%s/", subsystem);
       tbuffer = buffer;
       break;
      case 1:
       break;
      default:
       tbuffer = NULL;
       break;
     }

     if (tbuffer) {
      struct stat st;

      if (!stat (tbuffer, &st) && S_ISDIR(st.st_mode)) {
       char **cm = readdirfilter (NULL, tbuffer, "\\.hotplug$", NULL, 0);

       if (cm) {
        commands = (char **)setcombine_nc ((void **)commands, (const void **)cm, SET_TYPE_STRING);
        efree (cm);
       }
      }
     }
    }
   }

   if (commands) {
    char **env = NULL;
    char *command;
    ssize_t blen = strlen (subsystem) + 2;
    char **cd = NULL;

    for (i = 0; ev->stringset[i]; i+=2) {
     env = straddtoenviron (env, ev->stringset[i], ev->stringset[i+1]);
    }

    for (i = 0; commands[i]; i++) {
     int len = blen + strlen (commands[i]);
     char *t = emalloc (len);

     esprintf (t, len, "%s %s", commands[i], subsystem);
     cd = set_str_add (cd, t);
     efree (t);
    }

    if (cd) {
     command = set2str (';', (const char **)cd);

     pexec(command, NULL, 0, 0, NULL, NULL, env, NULL);

     efree (cd);
     efree (command);
    }

    efree (env);
    efree (commands);
   }
  }

  if (firmware && (ev->type == einit_hotplug_add)) {
   char buffer[BUFFERSIZE];
   int tblen = sizeof(SYS_DIR) + strlen (devpath) + 11;
   FILE *f;
   struct stat st;
   char *targetbuffer = emalloc (tblen);

   notice (2, "need firmware: %s", firmware);

   esprintf (buffer, BUFFERSIZE, FIRMWARE_DIR "/%s", firmware);
   if (stat (buffer, &st)) {
    esprintf (targetbuffer, tblen, SYS_DIR "/%s/loading", devpath);
    if ((f = fopen (targetbuffer, "w"))) {
     fputs ("-1\n", f);
     fclose (f);
    }

    notice (3, "can't locate firmware: %s", buffer);
   } else {
    esprintf (targetbuffer, tblen, SYS_DIR "/%s/loading", devpath);
    if ((f = fopen (targetbuffer, "w"))) {
     fputs ("1\n", f);
     fclose (f);
    }

    esprintf (targetbuffer, tblen, SYS_DIR "/%s/data", devpath);

    ssize_t ll = 0;
    char *firmware_data = readfile_l (buffer, &ll);

    if (firmware_data && ll) {
     if ((f = fopen (targetbuffer, "w"))) {
      int rembytes = ll;
      while (rembytes > 0) {
       size_t bw = fwrite (firmware_data +ll -rembytes, rembytes, 1, f);

       if (bw == 1) break;

       if (bw < 0) {
        notice (3, "error writing firmware: %s", buffer);
       }
      }
      fclose (f);
     }

     esprintf (targetbuffer, tblen, SYS_DIR "/%s/loading", devpath);
     if ((f = fopen (targetbuffer, "w"))) {
      fputs ("0\n", f);
      fclose (f);
     }

     notice (3, "firmware loaded okay: %s", buffer);
    } else {
     esprintf (targetbuffer, tblen, SYS_DIR "/%s/loading", devpath);
     if ((f = fopen (targetbuffer, "w"))) {
      fputs ("-1\n", f);
      fclose (f);
     }

     notice (3, "can't load firmware: %s", buffer);
    }
   }

   notice (3, "done loading firmware: %s", buffer);

   efree (targetbuffer);
  }
 }
}
int main(int argc, char **argv, char **environ) {
#else
int main(int argc, char **argv) {
#endif
 int i, ret = EXIT_SUCCESS;
 pid_t pid = getpid(), wpid = 0;
 char **ipccommands = NULL;
 int pthread_errno;
 FILE *commandpipe_in, *commandpipe_out;
 int commandpipe[2];
 int debugsocket[2];
 char need_recovery = 0;
 char debug = 0;
 int debugme_pipe = 0;
 char crash_threshold = 5;
 char *einit_crash_data = NULL;

 boottime = time(NULL);

 uname (&osinfo);
 config_configure();

// initialise subsystems
 ipc_configure(NULL);

// is this the system's init-process?
 isinit = getpid() == 1;

 event_listen (einit_event_subsystem_core, core_einit_event_handler);
 event_listen (einit_event_subsystem_timer, core_timer_event_handler);

 if (argv) einit_argv = (char **)setdup ((const void **)argv, SET_TYPE_STRING);

/* check command line arguments */
 for (i = 1; i < argc; i++) {
  if (argv[i][0] == '-')
   switch (argv[i][1]) {
    case 'c':
     if ((++i) < argc)
      einit_default_startup_configuration_files[0] = argv[i];
     else
      return print_usage_info ();
     break;
    case 'h':
     return print_usage_info ();
     break;
    case 'v':
     eputs("eINIT " EINIT_VERSION_LITERAL "\n", stdout);
     return 0;
    case 'L':
     eputs("eINIT " EINIT_VERSION_LITERAL
          "\nThis Program is Free Software, released under the terms of this (BSD) License:\n"
          "--------------------------------------------------------------------------------\n"
          "Copyright (c) 2006, 2007, Magnus Deininger\n"
          BSDLICENSE "\n", stdout);
     return 0;
    case '-':
     if (strmatch(argv[i], "--check-configuration") || strmatch(argv[i], "--checkup") || strmatch(argv[i], "--wtf")) {
      ipccommands = (char **)setadd ((void **)ipccommands, "examine configuration", SET_TYPE_STRING);
     } else if (strmatch(argv[i], "--help"))
      return print_usage_info ();
     else if (strmatch(argv[i], "--ipc-command") && argv[i+1])
      ipccommands = (char **)setadd ((void **)ipccommands, (void *)argv[i+1], SET_TYPE_STRING);
     else if (strmatch(argv[i], "--override-init-check"))
      initoverride = 1;
     else if (strmatch(argv[i], "--sandbox")) {
      einit_default_startup_configuration_files[0] = "lib/einit/einit.xml";
      coremode = einit_mode_sandbox;
      need_recovery = 1;
     } else if (strmatch(argv[i], "--metadaemon")) {
      coremode = einit_mode_metadaemon;
     } else if (strmatch(argv[i], "--bootstrap-modules")) {
      bootstrapmodulepath = argv[i+1];
     } else if (strmatch(argv[i], "--debugme")) {
      debugme_pipe = parse_integer (argv[i+1]);
      i++;
      initoverride = 1;
     } else if (strmatch(argv[i], "--debug")) {
      debug = 1;
     }

     break;
   }
 }

/* check environment */
 if (environ) {
  uint32_t e = 0;
  for (e = 0; environ[e]; e++) {
   char *ed = estrdup (environ[e]);
   char *lp = strchr (ed, '=');

   *lp = 0;
   lp++;

   if (strmatch (ed, "softlevel")) {
    einit_startup_mode_switches = str2set (':', lp);
   } if (strmatch (ed, "mode")) {
/* override default mode-switches with the ones in the environment variable mode= */
    einit_startup_mode_switches = str2set (':', lp);
   } else if (strmatch (ed, "einit")) {
/* override default configuration files and/or mode-switches with the ones in the variable einit= */
    char **tmpstrset = str2set (',', lp);
    uint32_t rx = 0;

    for (rx = 0; tmpstrset[rx]; rx++) {
     char **atom = str2set (':', tmpstrset[rx]);

     if (strmatch (atom[0], "file")) {
/* specify configuration files */
      einit_startup_configuration_files = (char **)setdup ((const void **)atom, SET_TYPE_STRING);
      einit_startup_configuration_files = (char **)strsetdel (einit_startup_configuration_files, (void *)"file");
     } else if (strmatch (atom[0], "mode")) {
/* specify mode-switches */
      einit_startup_mode_switches = (char **)setdup ((const void **)atom, SET_TYPE_STRING);
      einit_startup_mode_switches = (char **)strsetdel (einit_startup_mode_switches, (void *)"mode");
     } else if (strmatch (atom[0], "stfu")) {
      einit_quietness = 3;
     } else if (strmatch (atom[0], "silent")) {
      einit_quietness = 2;
     } else if (strmatch (atom[0], "quiet")) {
      einit_quietness = 1;
     }

     free (atom);
    }

    free (tmpstrset);
   }

   free (ed);
  }

  einit_initial_environment = (char **)setdup ((const void **)environ, SET_TYPE_STRING);
 }

 if (!einit_startup_mode_switches) einit_startup_mode_switches = einit_default_startup_mode_switches;
 if (!einit_startup_configuration_files) einit_startup_configuration_files = einit_default_startup_configuration_files;

 respawn:

 pipe (commandpipe);

 fcntl (commandpipe[1], F_SETFD, FD_CLOEXEC);

 socketpair (AF_UNIX, SOCK_STREAM, 0, debugsocket);
 fcntl (debugsocket[0], F_SETFD, FD_CLOEXEC);
 fcntl (debugsocket[1], F_SETFD, FD_CLOEXEC);

 if (!debug) {
  fcntl (commandpipe[0], F_SETFD, FD_CLOEXEC);
  commandpipe_in = fdopen (commandpipe[0], "r");
 }
 commandpipe_out = fdopen (commandpipe[1], "w");

 if (!initoverride && ((pid == 1) || ((coremode & einit_mode_sandbox) && !ipccommands))) {
// if (pid == 1) {
  initoverride = 1;
#if 0
#ifdef LINUX
  if ((einit_sub = syscall(__NR_clone, CLONE_PTRACE | SIGCHLD, 0, NULL, NULL, NULL)) < 0) {
   bitch (bitch_stdio, errno, "Could not fork()");
   eputs (" !! Haven't been able to fork a secondary worker process. This is VERY bad, you will get a lot of zombie processes! (provided that things work at all)\n", stderr);
  }
#else
#endif
#endif
  if ((einit_sub = fork()) < 0) {
   bitch (bitch_stdio, errno, "Could not fork()");
   eputs (" !! Haven't been able to fork a secondary worker process. This is VERY bad, you will get a lot of zombie processes! (provided that things work at all)\n", stderr);
  }
 }

 if (einit_sub) {
/* PID==1 part */
  int rstatus;
  struct sigaction action;

/* signal handlers */
  action.sa_sigaction = einit_sigint;
  sigemptyset(&(action.sa_mask));
  action.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
  if ( sigaction (SIGINT, &action, NULL) ) bitch (bitch_stdio, 0, "calling sigaction() failed.");

/* ignore sigpipe */
  action.sa_sigaction = (void (*)(int, siginfo_t *, void *))SIG_IGN;

  if ( sigaction (SIGPIPE, &action, NULL) ) bitch (bitch_stdio, 0, "calling sigaction() failed.");

  close (debugsocket[1]);
  if (einit_crash_data) {
   free (einit_crash_data);
   einit_crash_data = NULL;
  }

  while (1) {
   wpid = waitpid(-1, &rstatus, 0); /* this ought to wait for ANY process */

   if (wpid == einit_sub) {
//    goto respawn; /* try to recover by re-booting */
    if (!debug) if (commandpipe_in) fclose (commandpipe_in);
    if (commandpipe_out) fclose (commandpipe_out);

    if (WIFEXITED(rstatus) && (WEXITSTATUS(rstatus) != einit_exit_status_die_respawn)) {
     fprintf (stderr, "eINIT has quit properly.\n");

     if (!(coremode & einit_mode_sandbox)) {
      if (WEXITSTATUS(rstatus) == einit_exit_status_last_rites_halt) {
       execl (EINIT_LIB_BASE "/bin/last-rites", EINIT_LIB_BASE "/bin/last-rites", "h", NULL);
      } else if (WEXITSTATUS(rstatus) == einit_exit_status_last_rites_reboot) {
       execl (EINIT_LIB_BASE "/bin/last-rites", EINIT_LIB_BASE "/bin/last-rites", "r", NULL);
      } else if (WEXITSTATUS(rstatus) == einit_exit_status_last_rites_kexec) {
       execl (EINIT_LIB_BASE "/bin/last-rites", EINIT_LIB_BASE "/bin/last-rites", "k", NULL);
      }
     }

     exit (EXIT_SUCCESS);
    }

    int n = 5;
    fprintf (stderr, "The secondary eINIT process has died, waiting a while before respawning.\n");
    if ((einit_crash_data = readfd (debugsocket[0]))) {
     fprintf (stderr, " > neat, received crash data\n");
    }
    while ((n = sleep (n)));
    fprintf (stderr, "Respawning secondary eINIT process.\n");

    if (crash_threshold) crash_threshold--;
    else debug = 1;
    need_recovery = 1;
    initoverride = 0;

    close (debugsocket[0]);

    goto respawn;
   } else {
    if (commandpipe_out) {
     if (WIFEXITED(rstatus)) {
      fprintf (commandpipe_out, "pid %i terminated\n\n", wpid);
     } else {
      fprintf (commandpipe_out, "pid %i died\n\n", wpid);
     }
     fflush (commandpipe_out);
    }
   }
  }
 } else {
  enable_core_dumps ();

  close (debugsocket[0]);
  sched_trace_target = debugsocket[1];

  if (debug) {
   char **xargv = (char **)setdup ((const void **)argv, SET_TYPE_STRING);
   char tbuffer[BUFFERSIZE];
   struct stat st;
   char have_valgrind = 0;
   char have_gdb = 0;

   fputs ("eINIT needs to be debugged, starting in debugger mode\n.", stderr);

   xargv = (char **)setadd ((void **)xargv, (void *)"--debugme", SET_TYPE_STRING);
   snprintf (tbuffer, BUFFERSIZE, "%i", commandpipe[0]);
   xargv = (char **)setadd ((void **)xargv, (void *)tbuffer, SET_TYPE_STRING);

   xargv = strsetdel (xargv, "--debug"); // don't keep the --debug flag

   if (!stat ("/usr/bin/valgrind", &st)) have_valgrind = 1;
   if (!stat ("/usr/bin/gdb", &st)) have_gdb = 1;

   if (have_valgrind) {
    char **nargv = NULL;
    uint32_t i = 1;

#ifdef LINUX
    if (!(coremode & einit_mode_sandbox)) {
     mount ("proc", "/proc", "proc", 0, NULL);
     mount ("sys", "/sys", "sysfs", 0, NULL);

     system ("mount / -o remount,rw");
    }
#endif

    nargv = (char **)setadd ((void **)nargv, "/usr/bin/valgrind", SET_TYPE_STRING);
    nargv = (char **)setadd ((void **)nargv, "--log-file=/einit.valgrind", SET_TYPE_STRING);
    nargv = (char **)setadd ((void **)nargv, (coremode & einit_mode_sandbox) ? "sbin/einit" : "/sbin/einit", SET_TYPE_STRING);

    for (; xargv[i]; i++) {
     nargv = (char **)setadd ((void **)nargv, xargv[i], SET_TYPE_STRING);
    }

    execv ("/usr/bin/valgrind", nargv);
   } else {
    execv ((coremode & einit_mode_sandbox) ? "sbin/einit" : "/sbin/einit", xargv);
   }
  }

  if (debugme_pipe) { // commandpipe[0]
   fcntl (commandpipe[0], F_SETFD, FD_CLOEXEC);
   commandpipe_in = fdopen (debugme_pipe, "r");
  }

/* actual system initialisation */
  struct einit_event cev = evstaticinit(einit_core_update_configuration);

  if (ipccommands && (coremode != einit_mode_sandbox)) {
   coremode = einit_mode_ipconly;
  }

  eprintf (stderr, "eINIT " EINIT_VERSION_LITERAL ": Initialising: %s\n", osinfo.sysname);

  if ((pthread_errno = pthread_attr_init (&thread_attribute_detached))) {
   bitch(bitch_epthreads, pthread_errno, "pthread_attr_init() failed.");

   if (einit_initial_environment) free (einit_initial_environment);
   return -1;
  } else {
   if ((pthread_errno = pthread_attr_setdetachstate (&thread_attribute_detached, PTHREAD_CREATE_DETACHED))) {
    bitch(bitch_epthreads, pthread_errno, "pthread_attr_setdetachstate() failed.");
   }
  }

  if ((pthread_errno = pthread_key_create(&einit_function_macro_key, NULL))) {
   bitch(bitch_epthreads, pthread_errno, "pthread_key_create(einit_function_macro_key) failed.");

   if (einit_initial_environment) free (einit_initial_environment);
   return -1;
  }

/* this should be a good place to initialise internal modules */
   if (coremodules) {
    uint32_t cp = 0;

    eputs (" >> initialising in-core modules:", stderr);

    for (; coremodules[cp]; cp++) {
     struct lmodule *lmm;
     eprintf (stderr, " [%s]", (*coremodules[cp])->rid);
     lmm = mod_add(NULL, (*coremodules[cp]));

     lmm->source = estrdup("core");
    }

    eputs (" OK\n", stderr);
   }

/* emit events to read configuration files */
  if (einit_startup_configuration_files) {
   uint32_t rx = 0;
   for (; einit_startup_configuration_files[rx]; rx++) {
    cev.string = einit_startup_configuration_files[rx];
    event_emit (&cev, einit_event_flag_broadcast);
   }

   if (einit_startup_configuration_files != einit_default_startup_configuration_files) {
    free (einit_startup_configuration_files);
   }
  }

  cev.string = NULL;
  cev.type = einit_core_configuration_update;

// make sure we keep updating until everything is sorted out
  while (cev.type == einit_core_configuration_update) {
//   notice (2, "stuff changed, updating configuration.");

   cev.type = einit_core_update_configuration;
   event_emit (&cev, einit_event_flag_broadcast);
  }
  evstaticdestroy(cev);

  if (ipccommands) {
   uint32_t rx = 0;
   for (; ipccommands[rx]; rx++) {
    ret = ipc_process (ipccommands[rx], stdout);
   }

//   if (gmode == EINIT_GMODE_SANDBOX)
//    cleanup ();

   free (ipccommands);
   if (einit_initial_environment) free (einit_initial_environment);
   return ret;
  } else if ((coremode == einit_mode_init) && !isinit && !initoverride) {
   eputs ("WARNING: eINIT is configured to run as init, but is not the init-process (pid=1) and the --override-init-check flag was not specified.\nexiting...\n\n", stderr);
   exit (EXIT_FAILURE);
  } else {
/* actual init code */
   uint32_t e = 0;

   nice (einit_core_niceness_increment);

   if (need_recovery) {
    notice (1, "need to recover from something...");

    struct einit_event eml = evstaticinit(einit_core_recover);
    event_emit (&eml, einit_event_flag_broadcast);
    evstaticdestroy(eml);
   }

   if (einit_crash_data) {
    notice (1, "submitting crash data...");

    struct einit_event eml = evstaticinit(einit_core_crash_data);
    eml.string = einit_crash_data;
    event_emit (&eml, einit_event_flag_broadcast);
    evstaticdestroy(eml);

    free (einit_crash_data);
    einit_crash_data = NULL;
   }

   {
    notice (3, "running early bootup code...");

    struct einit_event eml = evstaticinit(einit_boot_early);
    event_emit (&eml, einit_event_flag_broadcast | einit_event_flag_spawn_thread_multi_wait);
    evstaticdestroy(eml);
   }

   notice (2, "scheduling startup switches.\n");

   for (e = 0; einit_startup_mode_switches[e]; e++) {
    struct einit_event ee = evstaticinit(einit_core_switch_mode);

    ee.string = einit_startup_mode_switches[e];
    event_emit (&ee, einit_event_flag_broadcast | einit_event_flag_spawn_thread | einit_event_flag_duplicate);
    evstaticdestroy(ee);
   }

   struct einit_event eml = evstaticinit(einit_core_main_loop_reached);
   eml.file = commandpipe_in;
   event_emit (&eml, einit_event_flag_broadcast);
   evstaticdestroy(eml);
  }

  if (einit_initial_environment) free (einit_initial_environment);
  return ret;
 }

/* this should never be reached... */
 if (einit_initial_environment) free (einit_initial_environment);
 return 0;
}
Exemple #26
0
		json_object_free(top);
	}

	list_delete(&errlist);
}

DEFUN_NOSH(show_error_code,
	   show_error_code_cmd,
	   "show error <(1-4294967296)|all> [json]",
	   SHOW_STR
	   "Information on errors\n"
	   "Error code to get info about\n"
	   "Information on all errors\n"
	   JSON_STR)
{
	bool json = strmatch(argv[argc-1]->text, "json");
	uint32_t arg = 0;

	if (!strmatch(argv[2]->text, "all"))
		arg = strtoul(argv[2]->arg, NULL, 10);

	log_ref_display(vty, arg, json);
	return CMD_SUCCESS;
}

void log_ref_init(void)
{
	pthread_mutex_lock(&refs_mtx);
	{
		refs = hash_create(ferr_hash_key, ferr_hash_cmp,
				   "Error Reference Texts");
Exemple #27
0
static enum encoding name_to_enc(const char *encname) {
    struct { const char *name; enum encoding enc; } map[] = {
	{ "UCS-2-INTERNAL", e_unicode },
	{ "UCS2", e_unicode },
	{ "UCS-2", e_unicode },
	{ "UCS-2LE", e_unicode },
	{ "UCS-2BE", e_unicode },
	{ "UNICODELITTLE", e_unicode },
	{ "UNICODEBIG", e_unicode },
	{ "ISO-10646/UCS2", e_unicode },
	{ "ISO-10646/USC2", e_unicode },		/* Old typo */
	{ "UCS4", e_ucs4 },
	{ "UCS-4", e_ucs4 },
	{ "UCS-4LE", e_ucs4 },
	{ "UCS-4BE", e_ucs4 },
	{ "UCS-4-INTERNAL", e_ucs4 },
	{ "ISO-10646/UCS4", e_ucs4 },
	{ "iso8859-1", e_iso8859_1 },
	{ "iso8859-2", e_iso8859_2 },
	{ "iso8859-3", e_iso8859_3 },
	{ "iso8859-4", e_iso8859_4 },
	{ "iso8859-5", e_iso8859_5 },
	{ "iso8859-6", e_iso8859_6 },
	{ "iso8859-7", e_iso8859_7 },
	{ "iso8859-8", e_iso8859_8 },
	{ "iso8859-9", e_iso8859_9 },
	{ "iso8859-10", e_iso8859_10 },
	{ "iso8859-11", e_iso8859_11 },
	{ "iso8859-13", e_iso8859_13 },
	{ "iso8859-14", e_iso8859_14 },
	{ "iso8859-15", e_iso8859_15 },
	{ "iso-8859-1", e_iso8859_1 },
	{ "iso-8859-2", e_iso8859_2 },
	{ "iso-8859-3", e_iso8859_3 },
	{ "iso-8859-4", e_iso8859_4 },
	{ "iso-8859-5", e_iso8859_5 },
	{ "iso-8859-6", e_iso8859_6 },
	{ "iso-8859-7", e_iso8859_7 },
	{ "iso-8859-8", e_iso8859_8 },
	{ "iso-8859-9", e_iso8859_9 },
	{ "iso-8859-10", e_iso8859_10 },
	{ "iso-8859-11", e_iso8859_11 },
	{ "iso-8859-13", e_iso8859_13 },
	{ "iso-8859-14", e_iso8859_14 },
	{ "iso-8859-15", e_iso8859_15 },
	{ "koi8-r", e_koi8_r },
	{ "jis201", e_jis201 },
	{ "mac", e_mac },
	{ "Macintosh", e_mac },
	{ "MS-ANSI", e_win },
	{ "EUC-KR", e_wansung },
	{ "johab", e_johab },
	{ "ISO-2022-KR", e_jiskorean },
	{ "ISO-2022-CN", e_jisgb },
	{ "EUC-CN", e_jisgbpk },
	{ "big5", e_big5 },
	{ "big5hkscs", e_big5hkscs },
	{ "ISO-2022-JP", e_jis },
	{ "ISO-2022-JP-2", e_jis2 },
	{ "Sjis", e_sjis },
	{ "UTF-8", e_utf8 },
	{ "UTF8", e_utf8 },
	{ NULL }};
    int i;

    for ( i=0; map[i].name!=NULL; ++i )
	if ( strmatch(map[i].name,encname)==0 )
return( map[i].enc );

return( -1 );
}
int search_next_matches(Search_Context *context, Search_Match *matches, int max_matches)
{
	unsigned chain_data_size = SEARCH_DATA_COUNT;
	int match_count = 0;

	// Restore the state from context to the stack, this should help compilers
	// optimize the variables better.
	const char *data = context->data;
	int length = context->length;

	Search_Chain *chains = context->chains;
	uint16_t *chain_data = context->chain_data;
	unsigned chain_data_head = context->chain_data_head;

	Search_Chain *last_end_chain = context->last_end_chain;
	int last_match_pos = context->last_match_pos;
	int last_match_length = context->last_match_length;
	bool last_match_was_best = context->last_match_was_best;

	// TODO: Free list optimization (less GC)

	int pos = context->position;
	for (; pos < length; pos++) {
		if (match_count >= max_matches)
			break;

		if (pos + SEARCH_TUPLE_SIZE > length) {
			// This algorithm can't find matches that are less than the tuple
			// size in length. But in practice that's not a problem because there
			// is no need for that short matches anyway.
			continue;
		}

		const char *pos_str = &data[pos];

		// Find the chain the beginning tuple of this match belongs to.
		unsigned hash = tuplehash(pos_str) % SEARCH_CHAIN_COUNT;
		Search_Chain *chain = &chains[hash];

		int begin_pos = chain->base;
		int pos_diff = pos - begin_pos;

		// Set as the new base of the chain.
		chain->base = pos;

		if (pos_diff >= SEARCH_MAX_DIST) {
			// Never seen or too far to reference: Orphan the chain.
			chain->capacity = 0;
			chain->data_index = 0;
			continue;
		}

		// If there is not enough space in the chain, its storage needs to be reallocated
		if (chain->capacity == 0) {
			uint16_t *begin = &chain_data[chain->data_index];
			uint16_t *iter = begin;

			int chain_diff = pos_diff;
			do {
				chain_diff += *iter++;
			} while (chain_diff < SEARCH_MAX_DIST);

			unsigned length = (int)(iter - begin);

			// Grow the allocation geometrically to reduce the amount of reallocations needed.
			unsigned alloc_amount = length * 2;

			// If there is no space try to do a garbage collection, if that doesn't help give up.
			if (chain_data_head + alloc_amount > chain_data_size) {

				chain_data_head = chain_data_gc(chains, SEARCH_CHAIN_COUNT,
					chain_data, chain_data_size, pos);

				if (chain_data_head + alloc_amount > chain_data_size) {
					return false;
				}
			}

			unsigned capacity = alloc_amount - length;
			int data_begin = chain_data_head + capacity;

			// Copy the old data.
			memcpy(chain_data + data_begin, begin, length * sizeof(uint16_t));

			chain->data_index = data_begin;
			chain->capacity = capacity;

			chain_data_head += alloc_amount;
		}

		// Add the distance to the previous occurrence to the chain.
		chain->capacity--;
		chain_data[--chain->data_index] = (uint16_t)pos_diff;

		uint16_t *begin_iter = chain_data + chain->data_index + 1;

		// Info about the current match candidate.
		int match_pos = 0;
		int match_length = 0;
		bool best_match = false;

		// The chain and iterator for the tuple that is required for a match
		// that is longer than the previous matches.
		Search_Chain *end_chain = 0;
		int end_pos;
		uint16_t *end_iter;

		int target_match_length = SEARCH_TUPLE_SIZE;

		// Can't match the buffer but don't limit the match lengths since it
		// breaks the buffering of the matches. Let the calling code splice
		// the too long matches into smaller ones (easy)
		int input_left = length - pos;
		int max_match_length = input_left;

		// If this match is a sub-match of the previous one we have already
		// found a match which is one byte shorter than the last one.
		int submatch_length = last_match_length - 1;
		if (submatch_length > SEARCH_TUPLE_SIZE) {
			// Set as new minimum goal
			match_pos = last_match_pos + 1;
			match_length = submatch_length;

			if (last_match_was_best) {
				// If the last match was the best possible match just accept it.
				last_match_was_best = true;
				last_match_pos = match_pos;
				last_match_length = match_length;
				continue;
			}

			// Re-use the previous end tuple, since it must be included in any
			// longer matches than the current submatch of the previous one.
			end_chain = last_end_chain;
			end_pos = end_chain->base;
			end_iter = chain_data + end_chain->data_index;
			target_match_length = last_match_length;
		}

		do {
			// If we have an end chain make sure that we only check places where
			// the begin and end iterators are separated by the target distance
			int target_dist = target_match_length - SEARCH_TUPLE_SIZE;
			if (end_chain && !sync_iterators(&begin_pos, &begin_iter, &end_pos, &end_iter, target_dist, pos)) {
				break;
			}

			// Compare the reference byte-by-byte as far as they match.
			int length = strmatch(pos_str, &data[begin_pos], max_match_length);
			int mpos = begin_pos;

			if (length >= target_match_length) {

				// Found a new longest match!
				match_length = length;
				match_pos = mpos;

				if (match_length == max_match_length) {
					// Accept as the best match.
					best_match = true;
					break;
				}

				// We MUST have additional characters left that could match, create the tuple
				// of the source string that contains one character past of the current best
				// match.

				const int end_offset = match_length - SEARCH_TUPLE_SIZE + 1;
				unsigned end_hash = tuplehash(pos_str + end_offset) % SEARCH_CHAIN_COUNT;

				Search_Chain *chain = &chains[end_hash];

				if (pos - chain->base >= SEARCH_MAX_DIST) {
					// There is no instance of a tuple that is required to continue the match
					// therefore this is the best match.
					best_match = true;
					break;
				}

				end_chain = chain;
				end_pos = end_chain->base;
				end_iter = chain_data + end_chain->data_index;

				target_match_length = match_length + 1;
			}

			// Advance.
			begin_pos -= *begin_iter++;
		} while (pos - begin_pos < SEARCH_MAX_DIST);

		// If there was a match and it's not _completely_ included in the last one
		// write it to the buffer.
		if (match_length >= SEARCH_TUPLE_SIZE && match_length >= last_match_length) {
			Search_Match *match = &matches[match_count++];
			match->position = pos;
			match->offset = pos - match_pos;
			match->length = match_length;
		}

		last_end_chain = end_chain;
		last_match_length = match_length;
		last_match_was_best = best_match;
	}

	// Store the cached data back to the context.
	context->chain_data_head = chain_data_head;
	context->last_end_chain = last_end_chain;
	context->last_match_pos = last_match_pos;
	context->last_match_length = last_match_length;
	context->last_match_was_best = last_match_was_best;
	context->position = pos;

	return match_count;
}
/** 
 * Read word/class entry names and 1-gram data from LR 2-gram file.
 * 
 * @param fp [in] file pointer
 * @param ndata [out] N-gram to set the read data.
 */
static boolean
set_unigram(FILE *fp, NGRAM_INFO *ndata)
{
  WORD_ID nid;
  int resid;
  LOGPROB prob, bo_wt;
  char *name, *p;
  boolean ok_p = TRUE;
  NGRAM_TUPLE_INFO *t;

  t = &(ndata->d[0]);

  /* malloc name area */
  ndata->wname = (char **)mymalloc(sizeof(char *) * ndata->max_word_num);

  /* malloc data area */
  //t->bgn_upper = t->bgn_lower = t->bgn = t->num = NULL;
  t->bgn_upper = NULL;
  t->bgn_lower = NULL;
  t->bgn = NULL;
  t->num = NULL;
  t->bgnlistlen = 0;
  t->nnid2wid = NULL;
  t->prob = (LOGPROB *)mymalloc_big(sizeof(LOGPROB), t->totalnum);
  t->bo_wt = (LOGPROB *)mymalloc_big(sizeof(LOGPROB), t->totalnum);
  t->context_num = t->totalnum;
  t->nnid2ctid_upper = NULL;
  t->nnid2ctid_lower = NULL;

  nid = 0;
  
  while (getl(buf, sizeof(buf), fp) != NULL && buf[0] != '\\') {
    if ((p = strtok(buf, DELM)) == NULL) {
      jlog("Error: ngram_read_arpa: 1-gram: failed to parse, corrupted or invalid data?\n");
      return FALSE;
    }
    prob = (LOGPROB)atof(p);
    if ((p = strtok(NULL, DELM)) == NULL) {
      jlog("Error: ngram_read_arpa: 1-gram: failed to parse, corrupted or invalid data?\n");
      return FALSE;
    }
    name = strcpy((char *)mymalloc(strlen(p)+1), p);
    if ((p = strtok(NULL, DELM)) == NULL) {
      bo_wt = 0.0;
    } else {
      bo_wt = (LOGPROB)atof(p);
    }

    /* register word entry name */
    ndata->wname[nid] = name;

    /* add entry name to index tree */
    if (ndata->root == NULL) {
      ndata->root = ptree_make_root_node(nid, &(ndata->mroot));
    } else {
      resid = ptree_search_data(name, ndata->root);
      if (resid != -1 && strmatch(name, ndata->wname[resid])) { /* already exist */
	jlog("Error: ngram_read_arpa: duplicate word entry \"%s\" at #%d and #%d in 1-gram\n", name, resid, nid);
	ok_p = FALSE;
	continue;
      } else {
	ptree_add_entry(name, nid, ndata->wname[resid], &(ndata->root), &(ndata->mroot));
      }
    }

    if (nid >= ndata->max_word_num) {
      jlog("Error: ngram_read_arpa: num of 1-gram is bigger than header value (%d)\n", ndata->max_word_num);
      return FALSE;
    }

    /* register entry info */
    t->prob[nid] = prob;
    t->bo_wt[nid] = bo_wt;
  
    nid++;
  }

  if (nid != t->totalnum) {
    jlog("Error: ngram_read_arpa: num of 1-gram (%d) not equal to header value (%d)\n", nid, t->totalnum);
    return FALSE;
  }

  if (ok_p == TRUE) {
    jlog("Stat: ngram_read_arpa: read %d 1-gram entries\n", nid);
  }
  
  return ok_p;
}
/** 
 * Sub function to Add a dictionary entry line to the word dictionary.
 * 
 * @param buf [i/o] buffer to hold the input string, will be modified in this function
 * @param vnum_p [in] current number of words in @a winfo
 * @param linenum [in] current line number of the input
 * @param winfo [out] pointer to word dictionary to append the data.
 * @param hmminfo [in] HTK %HMM definition data.  if NULL, phonemes are ignored.
 * @param do_conv [in] TRUE if performing triphone conversion
 * @param ok_flag [out] will be set to FALSE if an error occured for this input.
 * 
 * @return FALSE if buf == "DICEND", else TRUE will be returned.
 */
boolean
voca_load_htkdict_line(char *buf, WORD_ID *vnum_p, int linenum, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, boolean do_conv, boolean *ok_flag)
{
  char *ptmp, *lp = NULL, *p;
  static char cbuf[MAX_HMMNAME_LEN];
  HMM_Logical **tmpwseq;
  int len;
  HMM_Logical *tmplg;
  boolean pok;
  int vnum;

  vnum = *vnum_p;

  if (strmatch(buf, "DICEND")) return FALSE;

  /* allocate temporal work area for the first call */
  if (winfo->work == NULL) {
    winfo->work_num = PHONEMELEN_STEP;
    winfo->work = (void *)mybmalloc2(sizeof(HMM_Logical *) * winfo->work_num, &(winfo->mroot));
  }
  tmpwseq = (HMM_Logical **)winfo->work;

  /* backup whole line for debug output */
  strcpy(bufbak, buf);
  
  /* GrammarEntry */
  if ((ptmp = mystrtok_quote(buf, " \t\n")) == NULL) {
    jlog("Error: voca_load_htkdict: line %d: corrupted data:\n> %s\n", linenum, bufbak);
    winfo->errnum++;
    *ok_flag = FALSE;
    return TRUE;
  }
  winfo->wname[vnum] = strcpy((char *)mybmalloc2(strlen(ptmp)+1, &(winfo->mroot)), ptmp);

  /* just move pointer to next token */
  if ((ptmp = mystrtok_movetonext(NULL, " \t\n")) == NULL) {
    jlog("Error: voca_load_htkdict: line %d: corrupted data:\n> %s\n", linenum, bufbak);
    winfo->errnum++;
    *ok_flag = FALSE;
    return TRUE;
  }
#ifdef CLASS_NGRAM
  winfo->cprob[vnum] = 0.0;	/* prob = 1.0, logprob = 0.0 */
#endif
  
  if (ptmp[0] == '@') {		/* class N-gram prob */
#ifdef CLASS_NGRAM
    /* word probability within the class (for class N-gram) */
    /* format: classname @classprob wordname [output] phoneseq */
    /* classname equals to wname, and wordname will be omitted */
    /* format: @%f (log scale) */
    /* if "@" not found or "@0", it means class == word */
    if ((ptmp = mystrtok(NULL, " \t\n")) == NULL) {
      jlog("Error: voca_load_htkdict: line %d: corrupted data:\n> %s\n", linenum, bufbak);
      winfo->errnum++;
      *ok_flag = FALSE;
      return TRUE;
    }
    if (ptmp[1] == '\0') {	/* space between '@' and figures */
      jlog("Error: voca_load_htkdict: line %d: value after '@' missing, maybe wrong space?\n> %s\n", linenum, bufbak);
      winfo->errnum++;
      *ok_flag = FALSE;
      return TRUE;
    }
    winfo->cprob[vnum] = atof(&(ptmp[1]));
    if (winfo->cprob[vnum] != 0.0) winfo->cwnum++;
    /* read next word entry (just skip them) */
    if ((ptmp = mystrtok(NULL, " \t\n")) == NULL) {
      jlog("Error: voca_load_htkdict: line %d: corrupted data:\n> %s\n", linenum,bufbak);
      winfo->errnum++;
      *ok_flag = FALSE;
      return TRUE;
    }
    /* move to the next word entry */
    if ((ptmp = mystrtok_movetonext(NULL, " \t\n")) == NULL) {
      jlog("Error: voca_load_htkdict: line %d: corrupted data:\n> %s\n", linenum, bufbak);
      winfo->errnum++;
      *ok_flag = FALSE;
      return TRUE;
    }
#else  /* ~CLASS_NGRAM */
    jlog("Error: voca_load_htkdict: line %d: cannot handle in-class word probability\n> %s\n", linenum, ptmp, bufbak);
    winfo->errnum++;
    *ok_flag = FALSE;
    return TRUE;
#endif /* CLASS_NGRAM */
  }

  /* OutputString */
  switch(ptmp[0]) {
  case '[':			/* not transparent word */
    winfo->is_transparent[vnum] = FALSE;
    ptmp = mystrtok_quotation(NULL, " \t\n", '[', ']', 0);
    break;
  case '{':			/* transparent word */
    winfo->is_transparent[vnum] = TRUE;
    ptmp = mystrtok_quotation(NULL, " \t\n", '{', '}', 0);
    break;
  default:
#if 1
    /* ALLOW no entry for output */
    /* same as wname is used */
    winfo->is_transparent[vnum] = FALSE;
    ptmp = winfo->wname[vnum];
#else
    /* error */
    jlog("Error: voca_load_htkdict: line %d: missing output string??\n> %s\n", linenum, bufbak);
    winfo->errnum++;
    *ok_flag = FALSE;
    return TRUE;
#endif
  }
  if (ptmp == NULL) {
    jlog("Error: voca_load_htkdict: line %d: corrupted data:\n> %s\n", linenum, bufbak);
    winfo->errnum++;
    *ok_flag = FALSE;
    return TRUE;
  }
  winfo->woutput[vnum] = strcpy((char *)mybmalloc2(strlen(ptmp)+1, &(winfo->mroot)), ptmp);
    
  /* phoneme sequence */
  if (hmminfo == NULL) {
    /* don't read */
    winfo->wseq[vnum] = NULL;
    winfo->wlen[vnum] = 0;
  } else {

    /* store converted phone sequence to temporal bufffer */
    len = 0;
      
    if (do_conv) {
      /* convert phoneme to triphone expression (word-internal) */
      cycle_triphone(NULL);
      if ((lp = mystrtok(NULL, " \t\n")) == NULL) {
	jlog("Error: voca_load_htkdict: line %d: word %s has no phoneme:\n> %s\n", linenum, winfo->wname[vnum], bufbak);
	winfo->errnum++;
	*ok_flag = FALSE;
	return TRUE;
      }
      if (strlen(lp) >= MAX_HMMNAME_LEN) {
	jlog("Error: voca_load_htkdict: line %d: too long phone name: %s\n", linenum, lp);
	winfo->errnum++;
	*ok_flag = FALSE;
	return TRUE;
      }
      cycle_triphone(lp);
    }

    pok = TRUE;
    for (;;) {
      if (do_conv) {
/*	if (lp != NULL) jlog(" %d%s",len,lp);*/
	if (lp != NULL) lp = mystrtok(NULL, " \t\n");
	if (lp != NULL) {
	  if (strlen(lp) >= MAX_HMMNAME_LEN) {
	    jlog("Error: voca_load_htkdict: line %d: too long phone name: %s\n", linenum, lp);
	    winfo->errnum++;
	    *ok_flag = FALSE;
	    return TRUE;
	  }
	  p = cycle_triphone(lp);
	}
	else p = cycle_triphone_flush();
      } else {
	p = mystrtok(NULL, " \t\n");
      }
      if (p == NULL) break;

      /* both defined/pseudo phone is allowed */
      tmplg = htk_hmmdata_lookup_logical(hmminfo, p);
      if (tmplg == NULL) {
	/* not found */
	if (do_conv) {
	  /* both defined or pseudo phone are not found */
	  if (len == 0 && lp == NULL) {
	    jlog("Error: voca_load_htkdict: line %d: triphone \"*-%s+*\" or monophone \"%s\" not found\n", linenum, p, p);
	    snprintf(cbuf,MAX_HMMNAME_LEN,"*-%s+* or monophone %s", p, p);
	  } else if (len == 0) {
	    jlog("Error: voca_load_htkdict: line %d: triphone \"*-%s\" or biphone \"%s\" not found\n", linenum, p, p);
	    snprintf(cbuf,MAX_HMMNAME_LEN,"*-%s or biphone %s", p, p);
	  } else if (lp == NULL) {
	    jlog("Error: voca_load_htkdict: line %d: triphone \"%s+*\" or biphone \"%s\" not found\n", linenum, p, p);
	    snprintf(cbuf,MAX_HMMNAME_LEN,"%s+* or biphone %s", p, p);
	  } else {
	    jlog("Error: voca_load_htkdict: line %d: triphone \"%s\" not found\n", linenum, p);
	    snprintf(cbuf,MAX_HMMNAME_LEN,"%s", p);
	  }
	} else {
	  jlog("Error: voca_load_htkdict: line %d: phone \"%s\" not found\n", linenum, p);
	  snprintf(cbuf, MAX_HMMNAME_LEN, "%s", p);
	}
	add_to_error(winfo, cbuf);
	pok = FALSE;
      } else {
	/* found */
	if (len >= winfo->work_num) {
	  /* expand wseq area by PHONEMELEN_STEP */
	  winfo->work_num += PHONEMELEN_STEP;
	  winfo->work = (void *)mybmalloc2(sizeof(HMM_Logical *) * winfo->work_num, &(winfo->mroot));
	  memcpy(winfo->work, tmpwseq, sizeof(HMM_Logical *) * (winfo->work_num - PHONEMELEN_STEP));
	  tmpwseq = (HMM_Logical **)winfo->work;
	}
	/* store to temporal buffer */
	tmpwseq[len] = tmplg;
      }
      len++;
    }
    if (!pok) {			/* error in phoneme */
      jlog("Error: voca_load_htkdict: the line content was: %s\n", bufbak);
      winfo->errnum++;
      *ok_flag = FALSE;
      return TRUE;
    }
    if (len == 0) {
      jlog("Error: voca_load_htkdict: line %d: no phone specified:\n> %s\n", linenum, bufbak);
      winfo->errnum++;
      *ok_flag = FALSE;
      return TRUE;
    }
    /* store to winfo */
    winfo->wseq[vnum] = (HMM_Logical **)mybmalloc2(sizeof(HMM_Logical *) * len, &(winfo->mroot));
    memcpy(winfo->wseq[vnum], tmpwseq, sizeof(HMM_Logical *) * len);
    winfo->wlen[vnum] = len;
  }

  vnum++;

  *vnum_p = vnum;
  
  return(TRUE);
}