/** * loads a config file * @return <0 if load failed, 0 otherwise */ static int olsrmain_load_config(char *file) { struct stat statbuf; if (stat(file, &statbuf) < 0) { fprintf(stderr, "Could not find specified config file %s!\n%s\n\n", file, strerror(errno)); return -1; } if (olsrd_parse_cnf(file) < 0) { fprintf(stderr, "Error while reading config file %s!\n", file); return -1; } return 0; }
/* Build as standalone binary */ int main(int argc, char *argv[]) { struct olsrd_config *cnf; if (argc == 1) { fprintf(stderr, "Usage: olsrd_cfgparser [filename] -print\n\n"); exit(EXIT_FAILURE); } if ((cnf = olsrd_parse_cnf(argv[1])) != NULL) { if ((argc > 2) && (!strcmp(argv[2], "-print"))) { olsrd_print_cnf(cnf); olsrd_write_cnf(cnf, "./out.conf"); } else printf("Use -print to view parsed values\n"); printf("Configfile parsed OK\n"); } else { printf("Failed parsing \"%s\"\n", argv[1]); } return 0; }
int MyDialog2::OpenConfigFile(CString PathName) { struct ip_prefix_list *Hna; struct olsr_if *Int, *PrevInt; struct olsr_msg_params *MsgPar; int NumInt = m_InterfaceList.GetItemCount(); int i; CString IntName; CString Conv; if (Conf != NULL) olsrd_free_cnf(Conf); if (olsrd_parse_cnf(PathName) < 0) return -1; Conf = olsr_cnf; for (i = 0; i < NumInt; i++) m_InterfaceList.SetCheck(i, FALSE); for (Int = Conf->interfaces; Int != NULL; Int = Int->next) { IntName = Int->name; IntName.MakeUpper(); for (i = 0; i < NumInt; i++) { if (m_InterfaceList.GetItemText(i, 0).Mid(0, 4) == IntName) m_InterfaceList.SetCheck(i, TRUE); } } Int = Conf->interfaces; MsgPar = &Int->cnf->hello_params; Conv.Format("%.2f", MsgPar->emission_interval); m_HelloInt.SetWindowText(Conv); Conv.Format("%.2f", MsgPar->validity_time); m_HelloHold.SetWindowText(Conv); MsgPar = &Int->cnf->tc_params; Conv.Format("%.2f", MsgPar->emission_interval); m_TcInt.SetWindowText(Conv); Conv.Format("%.2f", MsgPar->validity_time); m_TcHold.SetWindowText(Conv); MsgPar = &Int->cnf->mid_params; Conv.Format("%.2f", MsgPar->emission_interval); m_MidInt.SetWindowText(Conv); Conv.Format("%.2f", MsgPar->validity_time); m_MidHold.SetWindowText(Conv); MsgPar = &Int->cnf->hna_params; Conv.Format("%.2f", MsgPar->emission_interval); m_HnaInt.SetWindowText(Conv); Conv.Format("%.2f", MsgPar->validity_time); m_HnaHold.SetWindowText(Conv); SetDebugLevel(Conf->debug_level); Conv.Format("%.2f", Conf->pollrate); m_PollInt.SetWindowText(Conv); Conv.Format("%d", Conf->mpr_coverage); m_MprCov.SetWindowText(Conv); m_TcRed.SetCurSel(Conf->tc_redundancy); m_LqAlgo.SetCurSel(m_LqAlgo.FindStringExact(-1, Conf->lq_algorithm)); m_HystCheck.SetCheck(Conf->use_hysteresis); Conv.Format("%.2f", Conf->hysteresis_param.scaling); m_HystScaling.SetWindowText(Conv); Conv.Format("%.2f", Conf->hysteresis_param.thr_high); m_HystThresholdHigh.SetWindowText(Conv); Conv.Format("%.2f", Conf->hysteresis_param.thr_low); m_HystThresholdLow.SetWindowText(Conv); OnHystCheck(); m_FishEyeCheck.SetCheck(Conf->lq_fish > 0); m_EtxCheck.SetCheck(Conf->lq_level > 0); #if 0 Conv.Format("%d", Conf->lq_wsize); m_EtxWindowSize.SetWindowText(Conv); #endif m_EtxRadio1.SetCheck(Conf->lq_level == 1); m_EtxRadio2.SetCheck(Conf->lq_level == 0 || Conf->lq_level == 2); OnEtxCheckWorker(); m_InternetCheck.SetCheck(FALSE); for (Hna = Conf->hna_entries; Hna != NULL; Hna = Hna->next) if (0 == Hna->net.prefix_len && m_InternetCheck.IsWindowEnabled()) m_InternetCheck.SetCheck(TRUE); PrevInt = NULL; for (Int = Conf->interfaces; Int != NULL; Int = Int->next) { IntName = Int->name; if (IntName.CompareNoCase("GUI") == 0) break; PrevInt = Int; } if (Int != NULL) { if (PrevInt == NULL) Conf->interfaces = Int->next; else PrevInt->next = Int->next; win32_olsrd_free(Int); } return 0; }