File: rec_args.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 (120 lines) | stat: -rw-r--r-- 3,375 bytes parent folder | download | duplicates (3)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "config.h"
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include "error.h"
#include "compat.h"
#include "ttyrec.h"
#include "rec_args.h"
#include "gettext.h"
#include "common.h"

const char *command, *format, *format_ext;
int lport,rport;
char *record_name;
int raw;
int append;

#ifdef HAVE_GETOPT_LONG
static struct option rec_opts[]={
{"format",      1, 0, 'f'},
{"exec",        1, 0, 'e'},
{"raw",         0, 0, 'r'},
{"append",      0, 0, 'a'},
{"help",        0, 0, 'h'},
{0,             0, 0, 0},
};
#endif

static const char *comp_ext;

void get_rec_parms(int argc, char **argv)
{
    format=0;
    command=0;
    record_name=0;
    raw=0;
    append=0;
#if (defined HAVE_LIBBZ2) || (defined SHIPPED_LIBBZ2)
    comp_ext=".bz2";
#elif (defined HAVE_LIBZ) || (defined SHIPPED_LIBZ)
    comp_ext=".gz";
#elif (defined HAVE_LIBLZMA) || (defined SHIPPED_LIBLZMA)
    comp_ext=".xz";
#elif (defined HAVE_LIBZSTD) || (defined SHIPPED_LIBZSTD)
    comp_ext=".zst";
#else
    comp_ext="";
#endif

    while (1)
    {
#ifdef HAVE_GETOPT_LONG
        switch (getopt_long(argc, argv, "f:e:rah", rec_opts, 0))
#else
        switch (getopt(argc, argv, "f:e:rah"))
#endif
        {
        case -1:
            goto finish_args;
        case ':':
        case '?':
            exit(1);
        case 'f':
            get_w_format(&format);
            break;
        case 'e':
            if (command)
                die(_("You can specify -e only once.\n"));
            command=optarg;
            break;
        case 'r':
            raw=1;
            break;
        case 'a':
            append=1;
            break;
        case 'h':
            printf(
                "%stermrec [-f format] [-e command] [file]\n"
                "    %s"
                "-f, --format X        %s\n"
                "-e, --exec X          %s\n"
                "-r, --raw             %s\n"
                "-a, --append          %s\n"
                "-h, --help            %s\n"
                "%s%s%s",
                _("Usage: "),
                _("Records the output of a console session to a file, including timing data.\n"),
                _("set output format to X (-f whatever for the list)"),
                _("execute command X instead of spawning a shell"),
                _("don't record UTFness or terminal size"),
                _("append to an existing file"),
                _("show this usage message"),
                _("If no filename is given, a name will be generated using the current date\n"
                  "    and the given format.\n"),
                _("If no format is given, it will be set according to the extension of the\n"
                  "    filename, or default to ttyrec if nothing is given.\n"),
                _("You can specify compression by appending .gz, .xz or .bz2 to the file name.\n"));
            exit(0);
        }
    }
finish_args:
    if (optind<argc)
        record_name=argv[optind++];
    if (optind<argc)
        die(_("You can specify at most one file to record to.\n"));

    if (!format)
        format=ttyrec_w_find_format(0, record_name, "ttyrec");
    if (!(format_ext=ttyrec_w_get_format_ext(format)))
        format_ext="";
}