コード例 #1
0
ファイル: config.c プロジェクト: gammu/gammu
int main(int argc, char **argv)
{
	GSM_Error error;
	GSM_Config cfg = { "", "", NULL, NULL, FALSE, FALSE, NULL, FALSE, FALSE, "", "", "", "", "", {0}, {0} };
	INI_Section *ini = NULL;

	/* Check parameters */
	if (argc != 2) {
		printf("Not enough parameters!\nUsage: config config_file\n");
		return 1;
	}

	error = GSM_FindGammuRC(&ini, argv[1]);
	gammu_test_result(error, "GSM_FindGammuRC");

	error = GSM_ReadConfig(ini, &cfg, 0);
	gammu_test_result(error, "GSM_ReadConfig");

	/* Free config file structures */
	INI_Free(ini);

	printf("DEBUG_LEVEL: '%s'\n", cfg.DebugLevel);

	free(cfg.Device);
	free(cfg.Connection);
	free(cfg.DebugFile);

	return 0;
}
コード例 #2
0
ファイル: gammu-json.c プロジェクト: hack-alex/gammu-json
/**
 * @name gammu_create:
 */
gammu_state_t *gammu_create(const char *config_path) {

  gammu_state_t *s = allocate(sizeof(*s));

  INI_Section *ini;
  GSM_InitLocales(NULL);

  if ((s->err = GSM_FindGammuRC(&ini, config_path)) != ERR_NONE) {
    goto cleanup;
  }

  s->sm = GSM_AllocStateMachine();
  GSM_Config *cfg = GSM_GetConfig(s->sm, 0);

  if ((s->err = GSM_ReadConfig(ini, cfg, 0)) != ERR_NONE) {
    goto cleanup_state;
  }

  INI_Free(ini);
  GSM_SetConfigNum(s->sm, 1);

  if ((s->err = GSM_InitConnection(s->sm, 1)) != ERR_NONE) {
    goto cleanup_state;
  }

  /* Success */
  return s;

  cleanup_state:
    GSM_FreeStateMachine(s->sm);
  
  cleanup:
    free(s);
    return NULL;
}
コード例 #3
0
ファイル: main.c プロジェクト: gammu/gammu
int main(int argc, char *argv[])
{
	GError *error = NULL;
	GSM_Error gerror;
	INI_Section *cfg = NULL;
	char *locales_path = NULL;

	GOptionContext *context;

	gerror = GSM_FindGammuRC(&cfg, NULL);
	if (gerror == ERR_NONE) {
		locales_path = INI_GetValue(cfg, "gammu", "gammuloc", FALSE);
	} else {
		locales_path = NULL;
	}
	GSM_InitLocales(locales_path);
#ifdef LIBINTL_LIB_FOUND
	if (locales_path != NULL) {
		bindtextdomain("gammu", locales_path);
	} else {
#if defined(LOCALE_PATH)
		bindtextdomain("gammu", LOCALE_PATH);
#else
		bindtextdomain("gammu", ".");
#endif
	}
	textdomain("gammu");
#endif

	if (cfg != NULL) {
		INI_Free(cfg);
	}

	g_type_init();

	context = g_option_context_new("");
	g_option_context_add_main_entries(context, entries, "gammu");
	if (!g_option_context_parse(context, &argc, &argv, &error)) {
		g_printerr(_("option parsing failed: %s\n"), error->message);
		exit(1);
	}

	if (show_version) {
		print_version();
		return 0;
	}

#ifdef GUDEV_FOUND
	if (!no_udev) {
		udev_detect();
	}
#endif
#ifdef BLUEZ_FOUND
	if (!no_bluez) {
		bluez_detect();
	}
#endif
#ifdef WIN32
	if (!no_win32_serial) {
		win32_serial_detect();
	}
#endif

	return 0;
}