Ejemplo n.º 1
0
int					ft_opera_handler(char *str)
{
	int			k;
	char		**tb;

	INIT(int, i, ft_is_opera(str));
	if (i >= 0)
		return (ft_truc2(str, i));
	i = red_is(str);
	IF_(i >= 0);
	tb = malloc(sizeof(char *) * (COUNTC(str, '>') + COUNTC(str, '<') + 2));
	INIT(int, j, ft_getcharpos(str, g_rc[i], 0));
	DBA(k, 0, tb[k++], ft_strsub(str, 0, j));
	str = str + j;
	WHILE(i >= 0 && j >= 0);
	j = ft_getcharpos(str + ((str[1] == g_rc[i]) ? 2 : 1), g_rc[i], 0);
	IF_(j >= 0);
	tb[k++] = ft_strsub(str, 0, j + ((str[1] == g_rc[i]) ? 2 : 1));
	str = str + ((j > 0) ? j : 1) + ((str[1] == g_rc[i]) ? 2 : 1);
	i = red_is(str);
	ELSE(tb[k++] = ft_strdup(str));
	ENDWHILE;
	tb[k] = NULL;
	return (ft_truc(tb));
	ENDIF;
	return (-2);
}
Ejemplo n.º 2
0
static bool write_range(
    char **string, size_t *length,
    unsigned int start, unsigned int end, bool first)
{
    return
        IF_(!first, write_string(string, length, ","))  &&
        write_uint(string, length, start)  &&
        IF_(end > start,
            write_string(string, length, "-")  &&
            write_uint(string, length, end));
}
Ejemplo n.º 3
0
static bool load_fa_ids_file(const char *filename)
{
    FILE *input;
    bool ok = TEST_NULL_(input = fopen(filename, "r"),
        "Unable to open IDs file \"%s\"", filename);
    if (ok)
    {
        bool seen[id_list_length];
        memset(seen, 0, id_list_length * sizeof(bool));

        char line[1024];
        while (ok  &&  fgets(line, sizeof(line), input))
        {
            /* Check the line hasn't been truncated.  This also complains if the
             * file ends without a newline, but that's too bad. */
            char *eol;
            ok =
                TEST_NULL_(eol = strchr(line, '\n'),
                    "Line truncated or missing newline at end of file")  &&
                DO_(*eol = '\0')  &&
                /* Fixed format: blank lines or lines beginning with # are
                 * ignored, all other lines must be a number followed by
                 * optional whitespace followed by an optional description. */
                IF_(line[0] != '\0'  &&  line[0] != '#',
                    DO_PARSE("FA ID file", parse_fa_id_line, line, seen));
        }
        fclose(input);
    }
    return ok;
}
Ejemplo n.º 4
0
/* Parses time in hh:mm:ss[Y] format representing time today or yesterday. */
static bool parse_today(const char **string, struct timespec *ts)
{
    return
        parse_time(string, ts)  &&
        DO_(ts->tv_sec += midnight_today())  &&
        IF_(read_char(string, 'Y'),
            DO_(ts->tv_sec -= 24 * 3600));
}
Ejemplo n.º 5
0
/* Captures open data stream to configured output file. */
static bool capture_and_save(FILE *stream)
{
    return
        IF_(!continuous_capture,
            TEST_OK(READ_ITEM(stream, sample_count)))  &&
        IF_ELSE(matlab_format,
            capture_matlab_data(stream),
            capture_raw_data(stream));
}
Ejemplo n.º 6
0
/* Parses one or two timestamps of the same format possibly separated by ~. */
static bool parse_interval(
    const char **string,
    bool (*parser)(const char **string, struct timespec *ts))
{
    return
        parser(string, &start)  &&
        DO_(start_specified = true)  &&
        IF_(read_char(string, '~'),
            parser(string, &end)  &&
            DO_(end_specified = true));
}
Ejemplo n.º 7
0
/* Parses all command line arguments. */
static bool parse_args(int argc, char **argv)
{
    return
        parse_opts(&argc, &argv)  &&
        TEST_OK_(argc == 1  ||  argc == 2,
            "Wrong number of arguments.  Try `capture -h` for help.")  &&
        /* Note that we have to interrogate the archive parameters after parsing
         * the server settings, but before we parse the sample count or capture
         * mask, because these use the settings we read. */
        read_archive_parameters()  &&
        DO_PARSE("capture mask",
            parse_mask, argv[0], fa_entry_count, &capture_mask)  &&
        IF_(argc == 2,
            DO_PARSE("sample count", parse_samples, argv[1], &sample_count));
}
Ejemplo n.º 8
0
/* Coordination of matlab data capture. */
static bool capture_matlab_data(FILE *stream)
{
    uint64_t frames_written;
    time_t local_offset = offset_matlab_times ? local_time_offset() : 0;
    return
        TEST_OK(READ_ITEM(stream, timestamp_header))  &&
        TEST_OK_(timestamp_header.offset < timestamp_header.block_size,
            "Invalid response from server")  &&

        write_header((uint32_t) sample_count)  &&
        capture_data(stream, &frames_written)  &&
        write_footer((uint32_t) frames_written, local_offset)  &&

        IF_(frames_written != sample_count,
            /* For an incomplete capture, probably an interrupted continuous
             * capture, we need to rewrite the header with the correct
             * capture count. */
            TEST_IO_(fseek(output_file, 0, SEEK_SET),
                "Cannot update matlab file, file not seekable")  &&
            write_header((uint32_t) frames_written));
}
Ejemplo n.º 9
0
/* Captures requested data from archiver and saves to file. */
int main(int argc, char **argv)
{
    char *server = getenv("FA_ARCHIVE_SERVER");
    if (server != NULL)
        server_name = server;

    output_file = stdout;
    FILE *stream;
    bool ok =
        parse_args(argc, argv)  &&
        validate_args()  &&

        connect_server(&stream)  &&
        IF_(output_filename != NULL,
            TEST_NULL_(
                output_file = fopen(output_filename, "w"),
                "Unable to open output file \"%s\"", output_filename))  &&
        request_data(stream)  &&
        check_response(stream)  &&

        initialise_signal()  &&
        capture_and_save(stream);
    return ok ? 0 : 1;
}
Ejemplo n.º 10
0
bool load_fa_ids(const char *filename, uint32_t fa_entry_count)
{
    fa_id_list = calloc(fa_entry_count, sizeof(struct fa_id_list));
    id_list_length = fa_entry_count;
    return IF_(filename, load_fa_ids_file(filename));
}
Ejemplo n.º 11
0
/* The matlab footer includes the timestamp information and optionally the id0
 * information, both derived from the timestamps blocks captured during data
 * transfer. */
static bool write_footer(unsigned int frames_written, time_t local_offset)
{
    return
        write_timestamps(frames_written, local_offset)  &&
        IF_(save_id0, write_id0(frames_written));
}