aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Vymetálek <pavel@vym.cz>2025-06-06 17:27:55 +0200
committerPavel Vymetálek <pavel@vym.cz>2025-06-06 17:27:55 +0200
commit0a4fc433732a9bfcb443ae35944272d7d0f5b70e (patch)
tree1d43798c89d74a99363185587983af1f2e557152
parent57c87cbbde7e04ca00ef3f2caaee76b3db022c86 (diff)
downloadsercp-pc-0a4fc433732a9bfcb443ae35944272d7d0f5b70e.tar.gz
sercp-zx use configuration file .sercprc in your home directory. Thanks to Dusky/UB880DHEADv0.8.1master
-rw-r--r--.gitignore3
-rw-r--r--CHANGELOG2
-rw-r--r--sercp.c102
3 files changed, 86 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..604c28a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*~
+sercp
+sercp.d
diff --git a/CHANGELOG b/CHANGELOG
index 834fa8f..fbc21fd 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+2025-06-06 v0.8.1 sercp-zx use configuration file .sercprc in your home directory. Thanks to Dusky/UB880D
+2024-03-10 v0.8.0 unified version number to sercp at speccy side
2024-01-11 v0.4.0 use new ACK messages instead hw-flow control
2020-05-01 v0.3.5 use gnu99 instead of gnu11, add O_NDELAY to serial port initialization
2020-04-08 v0.3.4 removed hw flow control for mac and bsd
diff --git a/sercp.c b/sercp.c
index d9c4f9b..8d9d0a0 100644
--- a/sercp.c
+++ b/sercp.c
@@ -68,7 +68,7 @@
#define FALSE 0
#define true 1
#define TRUE 1
-const char* _version = "v0.8.0";
+const char* _version = "v0.8.1";
// SERIAL
FILE *tapout_fd = NULL;
int is_outfile = 0;
@@ -80,9 +80,6 @@ unsigned char buff[32768];
unsigned char *p_buff;
unsigned int is_binary = 0;
-static int inp_indx = 0;
-
-size_t out_indx;
float width; // width of terminal
long pos = 0;
int scp = 0;
@@ -161,23 +158,24 @@ void usage(void) {
// fileinfo 1109bytes
/************************************************************************/
+static struct option long_options[] = {
+ {"device", required_argument, NULL, 'd'},
+ {"baud", required_argument, NULL, 'b'},
+ {"wait", required_argument, NULL, 'w'},
+ {"hwflow", no_argument, NULL, 'l'},
+ {"oldprot", no_argument, NULL, 'o'},
+ {"read", no_argument, NULL, 'r'},
+ {"turbo", no_argument, NULL, 't'},
+ {"version", no_argument, NULL, 'v'},
+ {"help", no_argument, NULL, 'h'},
+ {0, 0, 0, 0}
+};
+
void TestArgs (int argc, char *argv[])
{
int c;
while (1) {
int option_index = 0;
- static struct option long_options[] = {
- {"device", required_argument, NULL, 'd'},
- {"baud", required_argument, NULL, 'b'},
- {"wait", required_argument, NULL, 'w'},
- {"hwflow", no_argument, NULL, 'l'},
- {"oldprot", no_argument, NULL, 'o'},
- {"read", no_argument, NULL, 'r'},
- {"turbo", no_argument, NULL, 't'},
- {"version", no_argument, NULL, 'v'},
- {"help", no_argument, NULL, 'h'},
- {0, 0, 0, 0}
- };
c = getopt_long (argc, argv, "d:b:w:lortvh", long_options, &option_index);
if (c == -1) {
// end of arguments
@@ -222,10 +220,74 @@ void TestArgs (int argc, char *argv[])
}
}
if (optind < argc) {
- while (optind < argc){
- strncpy (&sercp_file[0], argv[optind++], 63); // input file name or path - without option switch
+ strncpy (&sercp_file[0], argv[argc-1], FILENAME_MAX); // input file name or path - without option switch
+ sercp_file[FILENAME_MAX-1] = '\0';
+ }
+}
+
+#define CFG_NAME ".sercprc"
+
+void ParseCfg() {
+ char *home, *val;
+ char cfg_path[256];
+ char opt[1024];
+ int optidx;
+ FILE *fp;
+
+#ifdef _WIN32
+ home = getenv( "USERPROFILE" );
+ if (!home) return;
+ snprintf(cfg_path, sizeof(cfg_path), "%s\\%s", home, CFG_NAME);
+#else
+ home = getenv( "HOME" );
+ if (!home) return;
+ snprintf(cfg_path, sizeof(cfg_path), "%s/%s", home, CFG_NAME);
+#endif
+ if (!(fp = fopen(cfg_path, "rb"))) return;
+
+ fgets(opt, sizeof(opt), fp);
+ while (!feof(fp)) {
+ if ((val=strchr(opt, '\r'))) *val = '\0';
+ if ((val=strchr(opt, '\n'))) *val = '\0';
+
+ val = strchr(opt, ' ');
+ if (val) *val++ = '\0';
+
+ for (optidx = 0; long_options[optidx].name; optidx++) {
+ if (!strcmp(opt, long_options[optidx].name)) {
+ switch (long_options[optidx].val) {
+ case 'd':
+ if (val) {
+#ifdef _WIN32
+ sprintf(SERIALDEVICE, "\\\\.\\%s", val);
+#else
+ sprintf(SERIALDEVICE, "%s", val);
+#endif
+ }
+ break;
+ case 'b':
+ if (val) baud_rate = atoi(val);
+ break;
+ case 't':
+ baud_rate = 115200;
+ break;
+ case 'w':
+ if (val) wait_ms = atoi(val);
+ break;
+ case 'l':
+ is_flow_control_hw = 1;
+ break;
+ case 'o':
+ is_old_protocol = 1;
+ break;
+ default:
+ break;
+ }
+ }
}
+ fgets(opt, sizeof(opt), fp);
}
+ fclose(fp);
}
@@ -962,14 +1024,12 @@ int OpenUart() {
#endif
}
-
-
/************************************************************************/
/************************************************************************/
int main(int argc, char** argv, char** env)
{
width = GetTerminalWidth();
- inp_indx = 0;
+ ParseCfg();
if (argc < 2) {
// printf("You must specify the Serial device and file\n");
usage();