logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

libttyrec - a library for handling ttyrec files

Description

Helperstreamfunction:intopen_stream(intfd,constchar*url,intmode,constchar**error);
           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:

           SM_READ
           SM_WRITE
           SM_REPREAD
           SM_APPEND

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

   Formatencoders:constchar*ttyrec_w_find_format(constchar*format,constchar*filename,constchar*fallback);
           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.

       recorderttyrec_w_open(intfd,constchar*format,constchar*filename,conststructtimeval*ts);
           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.

       intttyrec_w_write(recorderr,conststructtimeval*tm,constchar*data,intlen);
           A chunk of data of length len is written to recorder r, with timestamp tm.  Returns 1 if some sort of
           write error happened.

       intttyrec_w_close(recorderr);
           All pending data is flushed, recorder closed and its memory freed.  Returns 1 if there's some kind of
           failure.

       constchar*ttyrec_w_get_format_name(inti);
           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.

       constchar*ttyrec_w_get_format_ext(constchar*format);
           If the given write format is associated with a file extension, it is returned.

   Formatdecoders:constchar*ttyrec_r_find_format(constchar*format,constchar*filename,constchar*fallback);
           See the _w_ function, except that read formats are searched instead.

       constchar*ttyrec_r_get_format_name(inti);
           ditto

       constchar*ttyrec_r_get_format_ext(constchar*format);
           ditto

       intttyrec_r_play(intfd,constchar*format,constchar*filename,void(*synch_init_wait)(conststructtimeval*ts,void*arg),void(*synch_wait)(conststructtimeval*delay,void*arg),void(*synch_print)(constchar*data,intlen,void*arg),void*arg);
           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.

   Thefollowingfunctionsdealwithin-memoryttyrecs:ttyrecttyrec_init(ttyvt);
           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.

       ttyrecttyrec_load(intfd,constchar*format,constchar*filename,ttyvt);
           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.

       voidttyrec_free(ttyrectr);
           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;

       ttyrec_framettyrec_seek(ttyrectr,conststructtimeval*t,tty*vt);
           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.

       ttyrec_framettyrec_next_frame(ttyrectr,ttyrec_frametfv);
           Returns the next frame after frame tfv, or null if tfv was the last.

       voidttyrec_add_frame(ttyrectr,conststructtimeval*delay,constchar*data,intlen);
           Creates a new frame and appends it to ttyrec tr.

       intttyrec_save(ttyrectr,intfd,constchar*format,constchar*filename,conststructtimeval*selstart,conststructtimeval*selend);
           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.

   structtimevalarithmetics:
       A handful of macros for operating on timeval values:

       tadd(t,d)
           t+=d;

       tsub(t,d)
           t-=d;

       tmul1000(t,m)
           t*=m/1000;

       tdiv1000(t,m)
           t/=m/1000;

       tcmp(t1,t2)
           If t1<t2, -1.  If t1>t2, +1.  0 otherwise.

Name

       libttyrec - a library for handling ttyrec files

See Also

libtty(3)

0.19                                               2024-04-01                                       LIBTTYREC(3)

Synopsis

#include<ttyrec.h>

       Link with -ltty.

See Also