Scroll to navigation

LIBTTYREC(3) termrec LIBTTYREC(3)

NAME

libttyrec - a library for handling ttyrec files

SYNOPSIS

#include <ttyrec.h>

Link with -ltty.

DESCRIPTION

Helper stream function:

This function opens a stream designated by the url. If the given url ends in ".gz", ".xz", ".bz2" or ".zst"), the stream is assumed to be compressed and gets passed through the appropriate [un]packer. If the fd is not -1, it is the descriptor you already opened; if it is -1, the file is opened. The mode can be:

On error, -1 is returned. If you want the message, pass a non-null pointer error, it will be filled in.

Format encoders:

This function searches for a format that would fit the filename provided -- that is, abc.ttyrec.gz returns "ttyrec". If no known extension is found, the function returns whatever you gave as fallback. You can force a format yourself, in this case, it is only validated and if invalid, 0 is returned regardless of the other two arguments.
A recorder is opened, writing to the file fd; if it's not given (=-1), the function calls open_stream(). Recording is done in the given format, if not provided, the format is guessed based on the filename. If you provide a timestamp ts, it becomes date of the recording.
A chunk of data of length len is written to recorder r, with timestamp tm. Returns 1 if some sort of write error happened.
All pending data is flushed, recorder closed and its memory freed. Returns 1 if there's some kind of failure.
You can use this function to enumerate known write formats by calling it with i being subsequent numbers starting at 0. An invalid i will return a null pointer.
If the given write format is associated with a file extension, it is returned.

Format decoders:

See the _w_ function, except that read formats are searched instead.
ditto
ditto
This function decodes the file fd (opening filename if fd=-1). If its contents contain the date of the recording, you'll receive it through the callback synch_init_wait. Between frames, the delay is passed through synch_wait. The actual frame data goes through synch_print. Note that in some formats, two or more consecutive delays or two consecutive frames can happen one after another. If you provide an arbitrary arg, it will be passed to all callbacks.

The function doesn't return until the end of input data. Returns 1 on success, 0 on failure.

The following functions deal with in-memory ttyrecs:

An empty one is allocated. If a vt is provided, it becomes the screen that the ttyrec is internally played on; otherwise, a blank 80x25 one is allocated. The vt is consumed.
This function will load a ttyrec from the file designated with fd. If it's not open yet (fd=-1), it will be opened with open_stream. The ttyrec is played on the vt you provide -- or on a new 80x25 one.
Destroys the in-memory ttyrec, freeing its memory.

You can read the ttyrec's data while it's being read; all functions are thread-safe with regard to reading. The frames are stored in structures like this:

typedef struct {
struct timeval t;
int len;
char *data; } *ttyrec_frame;

Finds the frame that should be shown at time *t, or the first frame if t is null. If vt is not-null, it will receive a terminal containing the screen at that frame.
Returns the next frame after frame tfv, or null if tfv was the last.
Creates a new frame and appends it to ttyrec tr.
Exports the ttyrec to a new file. If selstart and/or selend are given, they designate the part that should be exported -- if not, the whole is.

struct timeval arithmetics:

A handful of macros for operating on timeval values:

t+=d;
t-=d;
t*=m/1000;
t/=m/1000;
If t1<t2, -1. If t1>t2, +1. 0 otherwise.

SEE ALSO

libtty(3)

2020-04-19 0.19