/* VIManager_SList_addArc: add arc */ static void VIManager_SList_addArc(VIManager_SList *l, int index_s1, int index_s2, char *isymbol, char *osymbol) { int i, idx; VIManager_State *s1, *s2; VIManager_Arc *a1, *a2; VIManager_AList *arc_list; char itype[MMDAGENT_MAXBUFLEN]; char iargs[MMDAGENT_MAXBUFLEN]; char otype[MMDAGENT_MAXBUFLEN]; char oargs[MMDAGENT_MAXBUFLEN]; s1 = VIManager_SList_searchState(l, index_s1); s2 = VIManager_SList_searchState(l, index_s2); arc_list = &s1->arc_list; /* analysis input symbol */ idx = 0; i = getArgFromString(isymbol, &idx, itype, VIMANAGER_SEPARATOR1); if (i <= 0) return; getTokenFromString(isymbol, &idx, iargs); /* analysis output symbol */ idx = 0; i = getArgFromString(osymbol, &idx, otype, VIMANAGER_SEPARATOR1); if (i <= 0) return; getTokenFromString(osymbol, &idx, oargs); /* create */ a1 = (VIManager_Arc *) malloc(sizeof(VIManager_Arc)); VIManager_Arc_initialize(a1, itype, iargs, otype, oargs, s2); /* set */ if (arc_list->head == NULL) { arc_list->head = a1; } else { for (a2 = arc_list->head; a2->next != NULL; a2 = a2->next); a2->next = a1; } }
/* VIManager_SList_addArc: add arc */ static void VIManager_SList_addArc(VIManager_SList *l, int index_s1, int index_s2, char *isymbol, char *osymbol) { int i, idx; VIManager_State *s1, *s2; VIManager_Arc *a1, *a2; VIManager_AList *arc_list; char type[MMDAGENT_MAXBUFLEN]; char **args = NULL; int argc = 0; char otype[MMDAGENT_MAXBUFLEN]; char oargs[MMDAGENT_MAXBUFLEN]; s1 = VIManager_SList_searchState(l, index_s1); s2 = VIManager_SList_searchState(l, index_s2); arc_list = &s1->arc_list; /* analysis input symbol */ idx = 0; i = getArgFromString(isymbol, &idx, type); if (i <= 0) return; getArgs(&isymbol[idx], &args, &argc); /* analysis output symbol */ idx = 0; i = getArgFromString(osymbol, &idx, otype); if (i <= 0) return; getTokenFromString(osymbol, &idx, oargs); /* create */ a1 = (VIManager_Arc *) calloc(1, sizeof(VIManager_Arc)); VIManager_Arc_initialize(a1, type, args, argc, otype, oargs, s2); /* set */ if (arc_list->head == NULL) { arc_list->head = a1; } else { for (a2 = arc_list->head; a2->next != NULL; a2 = a2->next); a2->next = a1; } /* free buffer */ if (argc > 0) { for (i = 0; i < argc; i++) free(args[i]); free(args); } }
/* VIManager::load: load FST */ int VIManager::load(const char *file) { FILE *fp; char buff[MMDAGENT_MAXBUFLEN]; int len; int idx; char buff_s1[MMDAGENT_MAXBUFLEN]; char buff_s2[MMDAGENT_MAXBUFLEN]; char buff_is[MMDAGENT_MAXBUFLEN]; char buff_os[MMDAGENT_MAXBUFLEN]; char buff_er[MMDAGENT_MAXBUFLEN]; int size_s1; int size_s2; int size_is; int size_os; int size_er; char *err_s1; char *err_s2; unsigned int index_s1; unsigned int index_s2; /* open */ fp = MMDAgent_fopen(file, "r"); if (fp == NULL) return 0; /* unload */ VIManager_SList_clear(&m_stateList); VIManager_SList_initialize(&m_stateList); while (fgets(buff, MMDAGENT_MAXBUFLEN - 3, fp) != NULL) { /* string + \r + \n + \0 */ /* remove final \n and \r */ len = MMDAgent_strlen(buff); while (len > 0 && (buff[len-1] == '\n' || buff[len-1] == '\r')) buff[--len] = '\0'; /* check and load arc */ if (len > 0) { idx = 0; size_s1 = getTokenFromString(buff, &idx, buff_s1); size_s2 = getTokenFromString(buff, &idx, buff_s2); size_is = getTokenFromString(buff, &idx, buff_is); size_os = getTokenFromString(buff, &idx, buff_os); size_er = getTokenFromString(buff, &idx, buff_er); if (size_s1 > 0 && size_s2 > 0 && size_is > 0 && size_os > 0 && size_er == 0 && buff_s1[0] != VIMANAGER_COMMENT) { index_s1 = (unsigned int) strtoul(buff_s1, &err_s1, 10); index_s2 = (unsigned int) strtoul(buff_s2, &err_s2, 10); if (buff_s1 + size_s1 == err_s1 && buff_s2 + size_s2 == err_s2) VIManager_SList_addArc(&m_stateList, index_s1, index_s2, buff_is, buff_os); } } if (feof(fp) || ferror(fp)) break; } fclose(fp); /* set current state to zero */ m_currentState = VIManager_SList_searchState(&m_stateList, VIMANAGER_STARTSTATE); return 1; }