예제 #1
0
파일: libstdbuf.c 프로젝트: 2asoft/freebsd
static void
change_buf(FILE *s, const char *bufmode)
{
	char *unit;
	size_t bufsize;
	int mode;

	bufsize = 0;
	if (bufmode[0] == '0' && bufmode[1] == '\0')
		mode = _IONBF;
	else if (bufmode[0] == 'L' && bufmode[1] == '\0')
		mode = _IOLBF;
	else if (bufmode[0] == 'B' && bufmode[1] == '\0') {
		mode = _IOFBF;
		bufsize = 0;
	} else {
		/*
		 * This library being preloaded, depending on libutil
		 * would lead to excessive namespace pollution.
		 * Thus we do not use expand_number().
		 */
		errno = 0;
		bufsize = strtol(bufmode, &unit, 0);
		if (errno == EINVAL || errno == ERANGE || unit == bufmode)
			warn("Wrong buffer mode '%s' for %s", bufmode,
			    stream_name(s));
		switch (*unit) {
		case 'G':
			bufsize *= 1024 * 1024 * 1024;
			break;
		case 'M':
			bufsize *= 1024 * 1024;
			break;
		case 'k':
			bufsize *= 1024;
			break;
		case '\0':
			break;
		default:
			warnx("Unknown suffix '%c' for %s", *unit,
			    stream_name(s));
			return;
		}
		mode = _IOFBF;
	}
	if (setvbuf(s, NULL, mode, bufsize) != 0)
		warn("Cannot set buffer mode '%s' for %s", bufmode,
		    stream_name(s));
}
예제 #2
0
파일: lib.c 프로젝트: alexanderkyte/sparse
static void do_warn(const char *type, struct position pos, const char * fmt, va_list args)
{
	static char buffer[512];
	const char *name;

	vsprintf(buffer, fmt, args);	
	name = stream_name(pos.stream);
		
	fprintf(stderr, "%s:%d:%d: %s%s\n",
		name, pos.line, pos.pos, type, buffer);
}
예제 #3
0
static void print_usage(SCTX_ struct token *pos, struct symbol *sym, unsigned mode)
{
	static unsigned curr_stream = -1;

	if (curr_stream != pos->pos.stream) {
		curr_stream = pos->pos.stream;
		printf("\nFILE: %s\n\n", stream_name(sctx_ curr_stream));
	}

	printf("%s%4d:%-3d %c %-5.3s", sctxp reporter->indent ? "\t" : "",
		pos->pos.line, pos->pos.pos, storage(sym), show_mode(mode));
}
예제 #4
0
static void convert_null_to_space(char *cp, const char *fname, const FILE *stream) {
	static const char *fn = NULL;

	/* convert null characters */
	if (*cp == '\0') {
		*cp = ' ';
		if (fname == NULL)
			fname = stream_name(stream);
		if (fn != fname) { /* print only once: */
			pr_warning("converted null-character(s) in `%s' to space", fname);
			fn = fname;
		}
	}
	return;
}
예제 #5
0
파일: util.c 프로젝트: apakian/audacious
void describe_song (const char * name, const Tuple * tuple, char * * _title,
 char * * _artist, char * * _album)
{
    /* Common folder names to skip */
    static const char * const skip[] = {"music"};

    char * title = get_nonblank_field (tuple, FIELD_TITLE);
    char * artist = get_nonblank_field (tuple, FIELD_ARTIST);
    char * album = get_nonblank_field (tuple, FIELD_ALBUM);

    if (title && artist && album)
    {
DONE:
        * _title = title;
        * _artist = artist;
        * _album = album;
        return;
    }

    if (! strncmp (name, "file:///", 8))
    {
        char * filename = uri_to_filename (name);
        if (! filename)
            goto DONE;
        
        char * base, * first, * second;
        split_filename (skip_top_folders (filename), & base, & first, & second);

        if (! title)
            title = str_get (base);

        for (int i = 0; i < G_N_ELEMENTS (skip); i ++)
        {
            if (first && ! g_ascii_strcasecmp (first, skip[i]))
                first = NULL;
            if (second && ! g_ascii_strcasecmp (second, skip[i]))
                second = NULL;
        }

        if (first)
        {
            if (second && ! artist && ! album)
            {
                artist = str_get (second);
                album = str_get (first);
            }
            else if (! artist)
                artist = str_get (first);
            else if (! album)
                album = str_get (first);
        }
        
        free (filename);
    }
    else
    {
        char buf[strlen (name) + 1];
        memcpy (buf, name, sizeof buf);

        if (! title)
        {
            title = str_get_decoded (stream_name (buf));

            if (! title)
                title = str_get_decoded (buf);
        }
        else if (! artist)
            artist = str_get_decoded (stream_name (buf));
        else if (! album)
            album = str_get_decoded (stream_name (buf));
    }

    goto DONE;
}
예제 #6
0
int main(int argc, char ** argv)
{
    // Initialise settings from configuration files.
    dvswitch_read_config(handle_config);

    // Parse arguments.

    int opt;
    while ((opt = getopt_long(argc, argv, "c:v", options, NULL)) != -1)
    {
	switch (opt)
	{
	case 'c':
	    fw_port_name = optarg;
	    break;
	case 'h':
	    listen_host = optarg;
	    break;
	case 'p':
	    listen_port = optarg;
	    break;
	case 'v':
	    verbose = true;
	    break;
	case 'H': // --help
	    usage(argv[0]);
	    return 0;
	default:
	    usage(argv[0]);
	    return 2;
	}
    }

    if (optind != argc)
	fw_port_name = argv[optind++];

    if (optind != argc)
    {
	fprintf(stderr, "%s: excess argument \"%s\"\n",
		argv[0], argv[optind]);
	usage(argv[0]);
	return 2;
    }

    // Catch SIGINT.
    struct sigaction sigint_action;
    sigint_action.sa_handler = handle_sigint;
    sigemptyset(&sigint_action.sa_mask);
    sigint_action.sa_flags = SA_RESTART;
    if (sigaction(SIGINT, &sigint_action, NULL))
    {
	perror("ERROR: sigaction");
	return 1;
    }

    // Set up liveMedia framework
    BasicTaskScheduler * sched = BasicTaskScheduler::createNew();
    BasicUsageEnvironment * env = BasicUsageEnvironment::createNew(*sched);
    RTSPServer * server = RTSPServer::createNew(*env, 8554, NULL);
    if (server == NULL)
    {
	*env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
	return 1;
    }
    OutPacketBuffer::maxSize = DIF_MAX_FRAME_SIZE;

    // Set up session
    std::string stream_name("firewire");
    stream_name.append(fw_port_name);
    std::string stream_desc("DV stream from Firewire port ");
    stream_desc.append(fw_port_name);
    ServerMediaSession * sms =
	ServerMediaSession::createNew(*env, stream_name.c_str(),
				      stream_desc.c_str(), stream_desc.c_str());
    sms->addSubsession(new firewire_subsession(*env, fw_port_name));
    server->addServerMediaSession(sms);

    // Loop until SIGINT received
    if (verbose)
	printf("INFO: Serving at rtsp://*:8554/%s\n", stream_name.c_str());
    sched->doEventLoop(&received_sigint);

    env->reclaim();

    return 0;
}