File: seeks.c

package info (click to toggle)
termrec 0.19-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,148 kB
  • sloc: ansic: 8,430; makefile: 181; perl: 16; sh: 15
file content (64 lines) | stat: -rw-r--r-- 1,300 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <string.h>
#include <ttyrec.h>
#include "sys/error.h"

ttyrec tr;

#define BUFFER_SIZE 64

static void sub(int t1, int t2, const char *exp)
{
    char buf[BUFFER_SIZE], *bptr;
    ttyrec_frame fr;
    struct timeval tv;

    printf("Exp: [%s]\n", exp);

    tv.tv_sec=t1;
    tv.tv_usec=0;
    fr=ttyrec_seek(tr, (t1!=-1)?&tv:0, 0);
    bptr=buf;
    while (fr && (t2==-1 || fr->t.tv_sec<=t2))
    {
        if (bptr+10>buf+BUFFER_SIZE)
            die("Buffer overflow!\n");
        if (bptr!=buf)
            *bptr++=' ';
        bptr+=snprintf(bptr, 8, "%.*s", fr->len, fr->data);
        fr=ttyrec_next_frame(tr, fr);
    }
    printf("Got: [%s]\n", buf);
    if (strcmp(buf, exp))
        die(" `-- mismatch!\n");
}

int main(void)
{
    struct timeval tv;
    int i;
    char word[2]="x";

    tr=ttyrec_init(0);
    if (!tr)
        die("ttyrec_init() failed");
    tv.tv_sec=1;
    tv.tv_usec=0;

    for (i=1;i<=10;i++)
    {
        word[0]=i+'A'-1;
        ttyrec_add_frame(tr, &tv, word, 1);
    }

    sub( 1,10, "A B C D E F G H I J");
    sub(-1,10, "A B C D E F G H I J");
    sub( 1,-1, "A B C D E F G H I J");
    sub(-1,-1, "A B C D E F G H I J");
    sub( 2, 3, "B C");
    sub( 9,-1, "I J");
    sub( 0, 1, "A");

    ttyrec_free(tr);
    return 0;
}