Package: picocom
Version: 1.7-1
Tags: patch
Severity: wishlist
this patch adds support for a minimal configuration file:
$ cat ~/.picocomrc
port = /dev/ttyUSB0
baud = 115200
--
Matteo Croce
OpenWrt Developer
--- picocom.c
+++ picocom.c
@@ -965,6 +965,48 @@
/**********************************************************************/
+char * key_value(char *line, char *key)
+{
+ int llen = strlen(line);
+ int klen = strlen(key);
+ if(strstr(line, key) == line &&
+ (line[klen] == ' ' || line[klen] == '=')) {
+ int i;
+ for(i = klen; i < llen; i++)
+ if(line[i] != ' ' && line[i] != '=') {
+ line[llen - 1] = 0;
+ return line + i;
+ }
+ }
+ return NULL;
+}
+
+void parse_conf()
+{
+ char buf[_POSIX_PATH_MAX];
+ FILE *cfg;
+ char *line;
+
+ snprintf(buf, _POSIX_PATH_MAX, "%s/.picocomrc", getenv("HOME"));
+ cfg = fopen(buf, "r");
+ if(!cfg)
+ return;
+
+ while((line = fgets(buf, _POSIX_PATH_MAX, cfg))) {
+ char *val;
+
+ val = key_value(line, "port");
+ if(val)
+ strcpy(opts.port, val);
+
+ val = key_value(line, "baud");
+ if(val)
+ opts.baud = atoi(val);
+ }
+
+ fclose(cfg);
+}
+
void
parse_args(int argc, char *argv[])
{
@@ -1120,12 +1162,14 @@
}
} /* while */
- if ( (argc - optind) < 1) {
- fprintf(stderr, "No port given\n");
- exit(EXIT_FAILURE);
+ if(!opts.port[0]) {
+ if ( (argc - optind) < 1) {
+ fprintf(stderr, "No port given\n");
+ exit(EXIT_FAILURE);
+ }
+ strncpy(opts.port, argv[optind], sizeof(opts.port) - 1);
+ opts.port[sizeof(opts.port) - 1] = '\0';
}
- strncpy(opts.port, argv[optind], sizeof(opts.port) - 1);
- opts.port[sizeof(opts.port) - 1] = '\0';
printf("picocom v%s\n", VERSION_STR);
printf("\n");
@@ -1157,6 +1201,7 @@
{
int r;
+ parse_conf();
parse_args(argc, argv);
establish_signal_handlers();