Example #1
0
/*
 **************************************************************************************************
 * main
 **************************************************************************************************
 *   Main function
 **************************************************************************************************
 * Params:
 *   std main params
 **************************************************************************************************
 */
int main(int argc, char **argv)
{
  int res;
  srand((unsigned long)time(NULL));

  /* if (fork()) exit(0); */

  atexit(quit_do_cleanup);
  signal(SIGINT, quit_got_signal);
  signal(SIGTERM, quit_got_signal);
  signal(SIGHUP, sighup_rehash);

  if ((res = conf_load())) quit_service(res);
  if ((res = log_open())) quit_service(res);

  log_command(LOG_SERVICES, NULL, "", "Services startup");
  log_write("#############################################################################\n");
  
  if ((res = dbase_load_persistant())) quit_service(res);
  if ((res = queue_init())) quit_service(res);
  help_load();
  

  nickserv_dbase_checkold(NULL);
  chanserv_dbase_check_expire(NULL);
  
  pthread_mutex_init(&sock_mutex, NULL);

  irc = com_sock_create(SOCK_SERVER);
  if (!com_connect(irc)) quit_service(ERROR_SERVER_COULD_NOT_CONNECT);

  irc->buffer[0] = '\0';
  
  res = com_mainloop();

  pthread_mutex_destroy(&sock_mutex);
  
  quit_service(res);

  return res;
}
Example #2
0
int main(int argc, char **argv)
{
	int nmenu;
	int imenu;

	GError *error = NULL;
	GOptionContext *context;

	gebr_libinit("libgebr");
	gebr_geoxml_init();

	/* Summary */
	context = g_option_context_new(NULL);
	g_option_context_set_summary(context,
				     "Edit tags of menu files for GeBR. Many menu files can\n"
				     "be edited at once, but using the same tag values to all menus.");
	/* Description */
	g_option_context_set_description(context,
					 "Parameter --created set menu's creation date. It accepts \"now\" or\n"
					 "a full qualified UTC date, like \"2008-09-23 21:12\".\n\n"
					 "If iprog is 0, then title and description options refers to menu's\n"
					 "title and description. If iprog > 0, then ith program is edited.\n"
					 "Copyright (C) 2008-2010 Ricardo Biloti <*****@*****.**>");
	g_option_context_add_main_entries(context, entries, NULL);
	/* Complain about unknown options */
	g_option_context_set_ignore_unknown_options(context, FALSE);

	/* Parse command line */
	if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
		fprintf(stderr, "%s: syntax error\n", argv[0]);
		fprintf(stderr, "Try %s --help\n", argv[0]);
		return EXIT_FAILURE;
	}
	g_option_context_free(context);

	/* End of command line parse */
	if (menu == NULL)
		return 0;
	nmenu = 0;
	while (menu[++nmenu] != NULL) ;

	for (imenu = 0; imenu < nmenu; imenu++) {
		GebrGeoXmlDocument *doc;
		GebrGeoXmlFlow *flow;
		GebrGeoXmlSequence *seq;
		GebrGeoXmlProgram *prog;
		gint nprog;

		if (gebr_geoxml_document_load((GebrGeoXmlDocument **) (&flow), menu[imenu], TRUE, NULL) !=
		    GEBR_GEOXML_RETV_SUCCESS) {
			fprintf(stderr, "Unable to load %s\n", menu[imenu]);
			break;
		}
		doc = GEBR_GEOXML_DOC(flow);
		nprog = gebr_geoxml_flow_get_programs_number(flow);
		if (author != NULL)
			gebr_geoxml_document_set_author(doc, author);
		if (email != NULL)
			gebr_geoxml_document_set_email(doc, email);
		if (date != NULL) {
			if (strcmp(date, "now") == 0) {
				gebr_geoxml_document_set_date_created(doc, gebr_iso_date());
			} else {
				static gchar datestr[100];
				struct tm tm;
				if (strptime(date, "%Y-%m-%d%H:%M", &tm) == NULL) {
					printf("Date parse error. See help for accepted formats.\n");
					break;
				}
				strftime(datestr, 100, "%Y-%m-%dT%H:%M:00Z", &tm);
				gebr_geoxml_document_set_date_created(doc, datestr);
			}
		}

		if (iprog == 0) {
			if (title != NULL)
				gebr_geoxml_document_set_title(doc, title);
			if (desc != NULL)
				gebr_geoxml_document_set_description(doc, desc);
			if (url || binary || version)
				printf("To set URL, binary, or binary's version you must specify iprog\n");
			if (helpdel)
				gebr_geoxml_document_set_help(doc, "");

			gchar *help;
			if (fnhelp) {
				help = help_load (GEBR_GEOXML_OBJECT (doc), fnhelp);
				gebr_geoxml_document_set_help (doc, help);
			} else if (!helpdel) {
				help = help_update (GEBR_GEOXML_OBJECT (doc));
				gebr_geoxml_document_set_help (doc, help);
			}
		} else {
			if (iprog > nprog) {
				printf("Invalid program index for menu %s\n", menu[imenu]);
				goto out;
			}

			gebr_geoxml_flow_get_program(flow, &seq, iprog - 1);
			prog = GEBR_GEOXML_PROGRAM(seq);

			if (title != NULL)
				gebr_geoxml_program_set_title(prog, title);
			if (desc != NULL)
				gebr_geoxml_program_set_description(prog, desc);
			if (binary != NULL)
				gebr_geoxml_program_set_binary(prog, binary);
                        if (version != NULL)
				gebr_geoxml_program_set_version(prog, version);
			if (url != NULL)
				gebr_geoxml_program_set_url(prog, url);
			if (helpdel)
				gebr_geoxml_program_set_help(prog, "");

			gchar *help;
			if (fnhelp) {
				help = help_load (GEBR_GEOXML_OBJECT (prog), fnhelp);
				gebr_geoxml_program_set_help (prog, help);
			} else if (!helpdel) {
				help = help_update (GEBR_GEOXML_OBJECT (prog));
				gebr_geoxml_program_set_help (prog, help);
			}
		}

 out:		gebr_geoxml_document_set_date_modified(doc, gebr_iso_date());
		if (gebr_geoxml_document_save(doc, menu[imenu], FALSE) != GEBR_GEOXML_RETV_SUCCESS)
			fprintf(stderr, "Unable to save %s\n", menu[imenu]);
		gebr_geoxml_document_free(doc);
	}

	gebr_geoxml_finalize();

	return 0;
}