Skip to content

Commit 89e33a5

Browse files
committed
Rename Struct Member
1 parent da89e6b commit 89e33a5

4 files changed

Lines changed: 31 additions & 30 deletions

File tree

src/main.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ int main(int argc, char** argv) {
2424
exit(EXIT_FAILURE);
2525
}
2626

27-
struct outargs oa;
28-
memset(&oa, 0, sizeof oa);
27+
struct outargs oa = {0};
2928

3029
unsigned char i = 1;
3130

@@ -49,8 +48,8 @@ int main(int argc, char** argv) {
4948
if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--format") == 0) {
5049
if (i == argc - 1) { printf("No file-format name specified!\n"); exit(EXIT_FAILURE); }
5150
const char* format = argv[i + 1];
52-
if (strcmp(format, "asciinema_v1") == 0) oa.format_version = ASCIINEMA_V1;
53-
else if (strcmp(format, "asciinema_v2") == 0) oa.format_version = ASCIINEMA_V2;
51+
if (strcmp(format, "asciinema_v1") == 0) oa.format = ASCIINEMA_V1;
52+
else if (strcmp(format, "asciinema_v2") == 0) oa.format = ASCIINEMA_V2;
5453
else { printf("Invalid file-format specified!\n"); exit(EXIT_FAILURE); }
5554
}
5655
}

src/record.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ enum control_command {
1010
typedef enum {
1111
TERMREC_PLAY = 1,
1212
TERMREC_RECORD
13-
} trMode_t;
13+
} AppMode;
1414

1515
typedef enum {
1616
ASCIINEMA_V1 = 1,
1717
ASCIINEMA_V2 = 2
18-
} fileformat_t;
18+
} FileFormat;
1919

2020
struct outargs {
2121
int start_paused;
2222
int controlfd;
2323
int masterfd;
24-
int rows;
25-
int cols;
26-
fileformat_t format_version;
27-
trMode_t mode;
24+
25+
// Terminal Rows/Columns
26+
int rows, cols;
27+
28+
AppMode mode;
29+
FileFormat format;
2830

2931
const char* cmd;
3032
const char* env;

src/recorder.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void RecordSession(struct outargs oa) {
4848
oa.env = SerializeEnv();
4949
exec_cmd = NULL;
5050

51-
if (!oa.format_version) oa.format_version = ASCIINEMA_V1;
51+
if (!oa.format) oa.format = ASCIINEMA_V1;
5252
if (!oa.fileName) oa.fileName = "events.cast";
5353

5454
if (pipe(controlfd) != 0) die("pipe");
@@ -278,8 +278,8 @@ static void handle_command(enum control_command cmd) {
278278
}
279279

280280
// This Function Is Responsible For Writing The Data To The File
281-
static inline void handle_input(unsigned char *buf, size_t buflen, fileformat_t format_version) {
282-
assert(format_version >= ASCIINEMA_V1 && format_version <= ASCIINEMA_V2);
281+
static inline void handle_input(unsigned char *buf, size_t buflen, FileFormat format) {
282+
assert(format >= ASCIINEMA_V1 && format <= ASCIINEMA_V2);
283283
static int first = 1;
284284
double delta;
285285

@@ -300,7 +300,7 @@ static inline void handle_input(unsigned char *buf, size_t buflen, fileformat_t
300300

301301
dur += delta;
302302

303-
WriteStdoutStart((format_version == ASCIINEMA_V1 ? delta : dur) / 1000);
303+
WriteStdoutStart((format == ASCIINEMA_V1 ? delta : dur) / 1000);
304304

305305
uint32_t state, cp;
306306
state = 0;
@@ -350,7 +350,7 @@ void StartOutputProcess(struct outargs *oa) {
350350
status = EXIT_SUCCESS;
351351
master = oa->masterfd;
352352

353-
assert(oa->format_version >= ASCIINEMA_V1 && oa->format_version <= ASCIINEMA_V2);
353+
assert(oa->format >= ASCIINEMA_V1 && oa->format <= ASCIINEMA_V2);
354354

355355
start_paused = paused = oa->start_paused;
356356

@@ -428,7 +428,7 @@ void StartOutputProcess(struct outargs *oa) {
428428
}
429429

430430
if (!paused) {
431-
handle_input(obuf, nread, oa->format_version);
431+
handle_input(obuf, nread, oa->format);
432432
}
433433
}
434434
}

src/writer.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int WriteHeader(struct outargs* oa) {
2525
if (oa == NULL || outfile == NULL) return -1;
2626

2727
memcpy(&OA, oa, sizeof(struct outargs));
28-
if (oa->format_version == ASCIINEMA_V1 || oa->format_version == ASCIINEMA_V2) {
28+
if (oa->format == ASCIINEMA_V1 || oa->format == ASCIINEMA_V2) {
2929
/* Write asciicast header and append events. Format defined at
3030
* v1 https://github.com/asciinema/asciinema/blob/master/doc/asciicast-v1.md
3131
* v2 https://github.com/asciinema/asciinema/blob/master/doc/asciicast-v2.md
@@ -37,24 +37,24 @@ int WriteHeader(struct outargs* oa) {
3737
struct timeval tv;
3838
gettimeofday(&tv, NULL);
3939

40-
#define _CONDITION_TAB oa->format_version == ASCIINEMA_V1 ? '\t' : ' '
41-
#define _CONDITION_NEWL oa->format_version == ASCIINEMA_V1 ? '\n' : ' '
40+
#define _CONDITION_TAB oa->format == ASCIINEMA_V1 ? '\t' : ' '
41+
#define _CONDITION_NEWL oa->format == ASCIINEMA_V1 ? '\n' : ' '
4242

4343
WriteStdout_fprintf("{ "); // Have Room For Putting Duration
44-
WriteStdout_fprintf("%c\"version\": %d,%c", _CONDITION_TAB, oa->format_version, _CONDITION_NEWL);
44+
WriteStdout_fprintf("%c\"version\": %d,%c", _CONDITION_TAB, oa->format, _CONDITION_NEWL);
4545
WriteStdout_fprintf("%c\"timestamp\": %ld,%c", _CONDITION_TAB, tv.tv_sec, _CONDITION_NEWL);
4646
WriteStdout_fprintf("%c\"width\": %d,%c", _CONDITION_TAB, oa->cols, _CONDITION_NEWL);
4747
WriteStdout_fprintf("%c\"height\": %d,%c", _CONDITION_TAB, oa->rows, _CONDITION_NEWL);
4848
WriteStdout_fprintf("%c\"command\": %s,%c", _CONDITION_TAB, oa->cmd ? oa->cmd : "\"\"", _CONDITION_NEWL);
4949
WriteStdout_fprintf("%c\"title\": %s,%c", _CONDITION_TAB, oa->title ? oa->title : "\"\"", _CONDITION_NEWL);
50-
WriteStdout_fprintf("%c\"env\": %s%c%c", _CONDITION_TAB, oa->env, oa->format_version == ASCIINEMA_V1 ? ',' : ' ', _CONDITION_NEWL);
50+
WriteStdout_fprintf("%c\"env\": %s%c%c", _CONDITION_TAB, oa->env, oa->format == ASCIINEMA_V1 ? ',' : ' ', _CONDITION_NEWL);
5151

5252
#undef _CONDITION_TAB
5353
#undef _CONDITION_NEWL
5454

55-
if (oa->format_version == ASCIINEMA_V1)
55+
if (oa->format == ASCIINEMA_V1)
5656
WriteStdout_fprintf("\t\"stdout\": [\n\t\t[ 0, \"\" ],\n"); // v1 header finished, console data is appended in structure
57-
else if (oa->format_version == ASCIINEMA_V2)
57+
else if (oa->format == ASCIINEMA_V2)
5858
WriteStdout_fprintf("}\n[ 0, \"o\", \"\" ]\n");
5959
}
6060

@@ -64,12 +64,12 @@ int WriteHeader(struct outargs* oa) {
6464
int WriteDuration(float duration) {
6565
if (outfile == NULL) return -1;
6666

67-
if (OA.format_version == ASCIINEMA_V1 || OA.format_version == ASCIINEMA_V2) {
67+
if (OA.format == ASCIINEMA_V1 || OA.format == ASCIINEMA_V2) {
6868
// seeks to header, overwriting spaces with duration
6969
size_t currPos = ftell(outfile);
7070
fseek(outfile, 2L, SEEK_SET);
7171

72-
#define _CONDITION_NEWL OA.format_version == ASCIINEMA_V1 ? '\n' : ' '
72+
#define _CONDITION_NEWL OA.format == ASCIINEMA_V1 ? '\n' : ' '
7373
fprintf(outfile, "%c\t\"duration\": %.9g,%c", _CONDITION_NEWL, duration, _CONDITION_NEWL);
7474
#undef _CONDITION_NEWL
7575

@@ -81,7 +81,7 @@ int WriteDuration(float duration) {
8181
}
8282

8383
void WriterClose() {
84-
if (OA.format_version == ASCIINEMA_V1) {
84+
if (OA.format == ASCIINEMA_V1) {
8585
// Delete The Comma From Last Entry in "stdout" array
8686
size_t currPos = ftell(outfile);
8787
fseek(outfile, currPos - 2, SEEK_SET);
@@ -99,9 +99,9 @@ void WriterClose() {
9999

100100
void WriteStdoutStart(float duration) {
101101
if (outfile) {
102-
if (OA.format_version == ASCIINEMA_V1) {
102+
if (OA.format == ASCIINEMA_V1) {
103103
WriteStdout_fprintf("\t\t[ %0.4f, \"", duration);
104-
} else if (OA.format_version == ASCIINEMA_V2) {
104+
} else if (OA.format == ASCIINEMA_V2) {
105105
WriteStdout_fprintf("[ %0.4f, \"o\", \"", duration);
106106
}
107107
}
@@ -130,9 +130,9 @@ void WriteStdout_fputc(char character) {
130130

131131
void WriteStdoutEnd() {
132132
if (outfile) {
133-
if (OA.format_version == ASCIINEMA_V1) {
133+
if (OA.format == ASCIINEMA_V1) {
134134
WriteStdout_fputs("\" ],\n");
135-
} else if (OA.format_version == ASCIINEMA_V2) {
135+
} else if (OA.format == ASCIINEMA_V2) {
136136
WriteStdout_fputs("\" ]\n");
137137
}
138138
}

0 commit comments

Comments
 (0)