Beispiel #1
0
void log_init(void)
{
/*
	MGET_LOGGER *logger = mget_get_logger(MGET_LOGGER_DEBUG);
	if (config.debug) {
		if (!config.logfile)
			mget_logger_set_file(logger, stderr); // direct debug output to STDERR
		else if (*config.logfile == '-' && config.logfile[1] == 0)
			mget_logger_set_file(logger, stdout); // direct debug output to STDIN
		else
			mget_logger_set_filename(logger, config.logfile);  // direct debug output to logfile

		mget_logger_set_timestamp(logger, 1); // switch timestamps on
	} else
		mget_logger_set_file(logger, NULL); // stop logging (if already started)
*/

	// set debug logging
	mget_logger_set_func(mget_get_logger(MGET_LOGGER_DEBUG), config.debug ? _write_debug : NULL);

	// set error logging
	mget_logger_set_stream(mget_get_logger(MGET_LOGGER_ERROR), config.quiet ? NULL : stderr);

	// set info logging
	mget_logger_set_stream(mget_get_logger(MGET_LOGGER_INFO), config.verbose && !config.quiet ? stdout : NULL);
}
Beispiel #2
0
int main(int argc, const char *const *argv)
{
    // Base URI for converting relative to absolute URIs
    const char *
    base = "http://www.example.com";

    // We assume that base is encoded in the local charset.
    const char *
    local_encoding = mget_local_charset_encoding();

    // parsed 'base'
    mget_iri_t
    *base_uri;

    // Character encoding of CSS file content
    // An HTTP response may contain the encoding in the Content-Type header,
    // but if
    // see http://stackoverflow.com/questions/2526033/why-specify-charset-utf-8-in-your-css-file
    const char *
    css_encoding = NULL;

    int
    argpos;

    // We want the libmget error messages be printed to STDERR.
    // From here on, we can call mget_error_printf, etc.
    mget_logger_set_stream(mget_get_logger(MGET_LOGGER_ERROR), stderr);

    // We want the libmget info messages be printed to STDOUT.
    // From here on, we can call mget_info_printf, etc.
    mget_logger_set_stream(mget_get_logger(MGET_LOGGER_INFO), stdout);

    // parse options
    for (argpos = 1; argpos < argc; argpos++) {
        if (!strcmp(argv[argpos], "--base") && argc - argpos > 1) {
            base = argv[++argpos];
            info_printf("Base URL encoding = '%s'\n", local_encoding);
        } else if (!strcmp(argv[argpos], "--encoding") && argc - argpos > 1) {
            css_encoding = argv[++argpos];
        } else if (!strcmp(argv[argpos], "--")) {
            argpos++;
            break;
        } else if (argv[argpos][0] == '-') {
            usage(argv[0]);
        } else
            break;
    }

    // All URIs are converted into UTF-8 charset.
    // That's why we need the local encoding (aka 'encoding of base URI') here.
    base_uri = mget_iri_parse(base, local_encoding);

    for (; argpos < argc; argpos++) {
        // use '-' as filename for STDIN
        css_parse_localfile(argv[argpos], base_uri, css_encoding);
    }

    mget_iri_free(&base_uri);

    return 0;
}