Skip to content

Commit

Permalink
irrecord: Add command line used to config file header.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec Leamas authored and Alec Leamas committed Mar 30, 2014
1 parent 8799251 commit 671e819
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
29 changes: 18 additions & 11 deletions daemons/dump_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,26 @@
#include "dump_config.h"
#include "config_file.h"

void fprint_comment(FILE * f, struct ir_remote *rem)
void fprint_comment(FILE * f, struct ir_remote *rem, const char* commandline)
{
time_t timet;
struct tm *tmp;
char buff[128];

if (commandline)
snprintf(buff, sizeof(buff), "# Command line: %s\n", commandline);
else
strncat(buff, "", sizeof(buff));

timet = time(NULL);
tmp = localtime(&timet);
fprintf(f,
"#\n"
"# this config file was automatically generated\n"
"# using lirc-%s(%s) on %s" "#\n" "# contributed by \n" "#\n" "# brand: %s\n"
"# model no. of remote control: \n" "# devices being controlled by this remote:\n" "#\n\n", VERSION,
hw.name, asctime(tmp), rem->name);
fprintf(f,
"#\n"
"# this config file was automatically generated\n"
"# using lirc-%s(%s) on %s" "#\n"
"# contributed by \n" "%s" "#\n" "# brand: %s\n"
"# model no. of remote control: \n" "# devices being controlled by this remote:\n" "#\n\n", VERSION,
hw.name, asctime(tmp), buff, rem->name);
}

void fprint_flags(FILE * f, int flags)
Expand All @@ -63,11 +70,11 @@ void fprint_flags(FILE * f, int flags)
fprintf(f, "\n");
}

void fprint_remotes(FILE * f, struct ir_remote *all)
void fprint_remotes(FILE * f, struct ir_remote *all, const char* commandline)
{

while (all) {
fprint_remote(f, all);
fprint_remote(f, all, commandline);
fprintf(f, "\n\n");
all = all->next;
}
Expand Down Expand Up @@ -250,9 +257,9 @@ void fprint_remote_signals(FILE * f, struct ir_remote *rem)
fprint_remote_signal_foot(f, rem);
}

void fprint_remote(FILE * f, struct ir_remote *rem)
void fprint_remote(FILE * f, struct ir_remote *rem, const char* commandline)
{
fprint_comment(f, rem);
fprint_comment(f, rem, commandline);
fprint_remote_head(f, rem);
fprint_remote_signals(f, rem);
fprint_remote_foot(f, rem);
Expand Down
6 changes: 3 additions & 3 deletions daemons/dump_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

#include "ir_remote.h"

void fprint_comment(FILE * f, struct ir_remote *rem);
void fprint_comment(FILE * f, struct ir_remote *rem, const char* commandline);
void fprint_flags(FILE * f, int flags);
void fprint_remotes(FILE * f, struct ir_remote *all);
void fprint_remotes(FILE * f, struct ir_remote *all, const char* commandline);
void fprint_remote_gap(FILE * f, struct ir_remote *rem);
void fprint_remote_head(FILE * f, struct ir_remote *rem);
void fprint_remote_foot(FILE * f, struct ir_remote *rem);
void fprint_remote_signal_head(FILE * f, struct ir_remote *rem);
void fprint_remote_signal_foot(FILE * f, struct ir_remote *rem);
void fprint_remote_signal(FILE * f, struct ir_remote *rem, struct ir_ncode *codes);
void fprint_remote_signals(FILE * f, struct ir_remote *rem);
void fprint_remote(FILE * f, struct ir_remote *rem);
void fprint_remote(FILE * f, struct ir_remote *rem, const char* commandline);

#endif
31 changes: 27 additions & 4 deletions daemons/irrecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ struct ir_ncode *current_code = NULL;
int current_index = 0;
int current_rep = 0;


static void get_commandline(int argc, char** argv, char* buff, size_t size)
{
int i;
int j;
int dest = 0;
if (size == 0)
return;
for (i = 1; i < argc; i += 1 ) {
for (j=0; argv[i][j] != '\0'; j += 1) {
if (dest + 1 >= size)
break;
buff[dest++] = argv[i][j];
}
if (dest + 1 >= size)
break;
buff[dest++] = ' ';
}
buff[--dest] = '\0';
}

lirc_t emulation_readdata(lirc_t timeout)
{
static lirc_t sum = 0;
Expand Down Expand Up @@ -299,11 +320,13 @@ int main(int argc, char **argv)
char *device = NULL;
int using_template = 0;
int analyse = 0;
char commandline[128];
#ifdef DEBUG
int get_pre = 0, get_post = 0, test = 0, invert = 0, trail = 0;
#endif

progname = argv[0];
get_commandline(argc, argv, commandline, sizeof(commandline));
force = 0;
hw_choose_driver(NULL);
while (1) {
Expand Down Expand Up @@ -443,7 +466,7 @@ int main(int argc, char **argv)
if (invert)
for_each_remote(remotes, invert_data);

fprint_remotes(stdout, remotes);
fprint_remotes(stdout, remotes, commandline);
free_config(remotes);
return (EXIT_SUCCESS);
}
Expand Down Expand Up @@ -605,7 +628,7 @@ int main(int argc, char **argv)
printf("Now enter the names for the buttons.\n");

fprint_copyright(fout);
fprint_comment(fout, &remote);
fprint_comment(fout, &remote, commandline);
fprint_remote_head(fout, &remote);
fprint_remote_signal_head(fout, &remote);
while (1) {
Expand Down Expand Up @@ -853,7 +876,7 @@ int main(int argc, char **argv)
return (EXIT_FAILURE);
}
fprint_copyright(fout);
fprint_remotes(fout, remotes);
fprint_remotes(fout, remotes, commandline);
free_config(remotes);
printf("Successfully written config file.\n");
return (EXIT_SUCCESS);
Expand Down Expand Up @@ -1328,7 +1351,7 @@ void analyse_remote(struct ir_remote *raw_data)
}
new_codes[new_index].name = NULL;
remote.codes = new_codes;
fprint_remotes(stdout, &remote);
fprint_remotes(stdout, &remote, (const char*)NULL);
remote.codes = NULL;
free(new_codes);
}
Expand Down

0 comments on commit 671e819

Please sign in to comment.