new patch which lets command line override configuration file for device path
Index: Makefile
===================================================================
--- Makefile (revisione 31)
+++ Makefile (copia locale)
@@ -7,7 +7,7 @@
CPPFLAGS=-DVERSION_STR=\"$(VERSION)\" \
-DUUCP_LOCK_DIR=\"$(UUCP_LOCK_DIR)\" \
-DHIGH_BAUD
-CFLAGS = -Wall -g
+CFLAGS = -Wall -g3
# LD = gcc
LDFLAGS = -g
Index: picocom.c
===================================================================
--- picocom.c (revisione 31)
+++ picocom.c (copia locale)
@@ -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) {
+ if(argc - optind > 0) {
+ strncpy(opts.port, argv[optind], sizeof(opts.port) - 1);
+ opts.port[sizeof(opts.port) - 1] = '\0';
+ }
+ if (!opts.port[0]) {
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';
printf("picocom v%s\n", VERSION_STR);
printf("\n");
@@ -1157,6 +1201,7 @@
{
int r;
+ parse_conf();
parse_args(argc, argv);
establish_signal_handlers();