diff options
| author | Pavel Vymetálek <pavel@vym.cz> | 2026-10-27 17:44:12 +0100 |
|---|---|---|
| committer | Pavel Vymetálek <pavel@vym.cz> | 2026-10-27 17:44:12 +0100 |
| commit | f98353aa76375f8af48ac5d64f4688ca7ca4b155 (patch) | |
| tree | 00f2fa562b74956aa4f3a7a40335b2f4c599e918 | |
| parent | ebd248bfe4be0b6892e91d451af01894f126cdd2 (diff) | |
| download | sercp-pc-f98353aa76375f8af48ac5d64f4688ca7ca4b155.tar.gz | |
Add LFN support and posibility to switch back to 8.3 filenames
- switch -s disable LFN 64 character filename
| -rw-r--r-- | sercp.c | 45 |
1 files changed, 37 insertions, 8 deletions
@@ -68,7 +68,7 @@ #define FALSE 0 #define true 1 #define TRUE 1 -const char* _version = "v0.8.2"; +const char* _version = "v0.9.0pre1"; // SERIAL FILE *tapout_fd = NULL; int is_outfile = 0; @@ -87,6 +87,7 @@ size_t out_indx; float width; // width of terminal long pos = 0; int scp = 0; +int is_lfn_enable = 1; int is_scp_read = 0; int is_continue = 1; int is_flow_control_hw = 0; // 1 - set flow control to NONE @@ -112,6 +113,17 @@ char SERIALDEVICE[128] = { struct pollfd spolfd_serial[1]; // pole descriptoru pro poll #endif +// filename length +#define MAX_LFN_LEN 64 +#define LEFT_KEEP 4 +#define RIGHT_KEEP (MAX_LFN_LEN - LEFT_KEEP) + +#define MAX_SHORT_LEN 12 +#define LEFT_SHORT_KEEP 4 +#define RIGHT_SHORT_KEEP (MAX_LFN_LEN - LEFT_KEEP) +uint8_t max_lfn_len = MAX_LFN_LEN; +uint8_t left_keep = LEFT_KEEP; +uint8_t right_keep = RIGHT_KEEP; typedef struct { uint16_t block_len; // legth of block @@ -134,11 +146,12 @@ typedef struct { FILEINFO fileinfo; void usage(void) { - printf ("sercp %s (c)2018-2024 Pavel Vymetalek <pavel@vym.cz>\n", _version); + printf ("sercp %s (c)2018-2026 Pavel Vymetalek <pavel@vym.cz>\n", _version); printf ("serial copy for transfering file to/from ZX Spectrum 128 AY's RS232\n"); // printf ("Use 1109-bytes of fileinfo - blocks sums, filename, etc.\n"); printf ("Confirmation of communication using ack messages - no HW flow control\n"); - printf ("Still compatible with old .sercp - with -l switch\n"); + printf ("Still compatible with old .sercp - with -o and -l switch\n"); + printf ("Since v0.9 LFNs are used, filename limited to 64 characters, -s to disable LFN\n"); printf ("More info at https://vym.cz/sercp/\n"); #ifdef _WIN32 printf ("Usage:\nsercp.exe -d com1 [-t] [-r] <filename>\n"); @@ -158,6 +171,7 @@ void usage(void) { printf ("\t-o, --oldprot\tUse the old protocol without AKC messages.\n\t\t\tThis is useful for old .sercp with missing HW flow control\n"); printf ("\t-w, --wait\tWaiting in milliseconds between transmitted blocks.\n\t\t\tIn case of improperly functioning hw flow control\n"); printf ("\t-r, --read\tRead file from serial port\n"); + printf ("\t-s, --short\tShorten file names to 8.3 format\n"); } // fileinfo 1109bytes @@ -169,6 +183,7 @@ static struct option long_options[] = { {"hwflow", no_argument, NULL, 'l'}, {"oldprot", no_argument, NULL, 'o'}, {"read", no_argument, NULL, 'r'}, + {"short", no_argument, NULL, 's'}, {"turbo", no_argument, NULL, 't'}, {"version", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, @@ -180,7 +195,7 @@ void TestArgs (int argc, char *argv[]) int c; while (1) { int option_index = 0; - c = getopt_long (argc, argv, "d:b:w:lortvh", long_options, &option_index); + c = getopt_long (argc, argv, "d:b:w:lorstvh", long_options, &option_index); if (c == -1) { // end of arguments break; @@ -205,6 +220,12 @@ void TestArgs (int argc, char *argv[]) case 'r': is_scp_read = 1; break; + case 's': + is_lfn_enable = 0; + max_lfn_len = MAX_SHORT_LEN; + left_keep = LEFT_SHORT_KEEP; + right_keep = RIGHT_SHORT_KEEP; + break; case 'l': is_flow_control_hw = 1; break; @@ -740,8 +761,8 @@ void sercpRecv(void) { expected_len = p_fileinfo->fi_blocks[block_index].block_len; } if (expected_len == 0 || block_index == 255) { + DoProgress(recv_length, overall_length, PROGRESS_COMPLETTE); printf ("\nTransfer successful\n"); - DoProgress(0, 0, PROGRESS_COMPLETTE); is_continue = 0; recv_phase++; break; @@ -770,6 +791,7 @@ void sercpRecv(void) { } + /************************************************************************/ void sercpSend(void) { FILE *tap_fd; @@ -824,12 +846,19 @@ void sercpSend(void) { p_basec = strdup(sercp_file); p_bname = basename (p_basec); - if (strlen(p_bname) > 12) { + if (strlen(p_bname) > max_lfn_len) { printf ("Short filename: "); p_shortfilename = strdup(p_bname); fn_len = strlen(p_shortfilename); - memcpy(p_shortfilename+4, p_shortfilename+fn_len-8, 8); - *(p_shortfilename+12) = 0; + if (is_lfn_enable) { + memmove(p_shortfilename + left_keep, p_shortfilename + fn_len - right_keep, right_keep); + p_shortfilename[max_lfn_len] = '\0'; + } else { + memcpy(p_shortfilename+4, p_shortfilename+fn_len-8, 8); + *(p_shortfilename+12) = 0; + } + + printf ("%s\n", p_shortfilename); p_bname = p_shortfilename; } |
