示例#1
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;
}
示例#2
0
int
cmd_update(int argc, char **argv)
{
	struct child_config	*cc;
	int			ch,
				ret;
	const char		*b;
	int			sock;

	if (argc < 2)
		help_update();

	cc = child_config_new();

	while ((ch = getopt_long(argc, argv, update_opts, update_longopts, NULL)) != -1) {
		switch (ch) {
		case 'a':
			cc->cc_age = strtol(optarg, NULL, 10);
			break;
		case 'd':
			cc->cc_dir = optarg;
			break;
		case 'e':
			cc->cc_stderr = optarg;
			break;
		case 'f':
			cc->cc_fatal_cb = optarg;
			break;
		case 'h':
			help_update();
			break;
		case 'H':
			cc->cc_heartbeat = optarg;
			break;
		case 'i':
			cc->cc_instances = strtol(optarg, NULL, 10);
			break;
		case 'k':
			cc->cc_killsig = strtol(optarg, NULL, 10);
			break;
		case 'o':
			cc->cc_stdout = optarg;
			break;
		case 's':
			cc->cc_status = child_config_status_from_string(optarg);
			if (cc->cc_status == -1) {
				fprintf(stderr, "Illegal status code\n");
				exit(1);
			}
			break;
		default:
			help_update();
			break;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 1)
		help_update();

	cc->cc_name = argv[0];

	b = child_config_serialize(cc);

	if ((sock = sock_connect()) == -1) {
		fprintf(stderr, "server running?\n");
		return 1;
	}

	if (sock_send_command(sock, "UPDT", b) == -1) {
		fprintf(stderr, "failed to send command.\n");
		return 1;
	}

	ret = get_status_reply(sock);
	close(sock);
	return ret;
}