aboutsummaryrefslogtreecommitdiffstats
path: root/sercp.c
diff options
context:
space:
mode:
authorPavel Vymetálek <pavel@vym.cz>2019-02-18 15:43:11 +0100
committerPavel Vymetálek <pavel@vym.cz>2019-02-18 15:43:11 +0100
commit763b0e4a17aad661705ed333f57cb989b5ac31c3 (patch)
tree2cbd04cd147ac301a6dd51909cc40f9d300e1edc /sercp.c
parentfb473ed61d28c2de73bcb729168ad9427fc4c631 (diff)
downloadsercp-pc-763b0e4a17aad661705ed333f57cb989b5ac31c3.tar.gz
Přidáno zkrácení názvu souboru když je delší než 8.3
- berou se první 4 znaky a posledních 8 znaků - .ext + 4 poslední znaky názvu
Diffstat (limited to 'sercp.c')
-rw-r--r--sercp.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/sercp.c b/sercp.c
index 4d5b2b7..545f725 100644
--- a/sercp.c
+++ b/sercp.c
@@ -11,6 +11,7 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/signal.h>
+#include <signal.h>
#include <fcntl.h>
#include <poll.h>
@@ -28,7 +29,7 @@ int baud_rate = 0;
int wait_us = 200;
int wait_ms = 800;
char *path;
-char tap_file[FILENAME_MAX];
+char sercp_file[FILENAME_MAX];
unsigned char buff[32768];
unsigned char *p_buff;
unsigned int is_continue = 1;
@@ -127,7 +128,7 @@ void TestArgs (int argc, char *argv[])
}
if (optind < argc) {
while (optind < argc){
- strncpy (&tap_file[0], argv[optind++], 63); // input tap file name - without option switch
+ strncpy (&sercp_file[0], argv[optind++], 63); // input file name or path - without option switch
}
}
}
@@ -367,6 +368,8 @@ void RecvSCP(void) {
void SendSCP(void) {
FILE *tap_fd;
char *bname, *basec; // pinter na kopii nazvu souboru - basename
+ char *shortfilename;
+ size_t fn_len;
unsigned int err, no, len;
struct stat st;
FILEINFO *p_fileinfo = &fileinfo;
@@ -379,13 +382,13 @@ void SendSCP(void) {
uint32_t overall_sent;
- no = stat(tap_file, &st);
+ no = stat(sercp_file, &st);
if (no != 0) {
err = errno;
error(1, err, "can't stat input file");
}
- tap_fd = fopen(tap_file, "r");
+ tap_fd = fopen(sercp_file, "r");
if (tap_fd == NULL) {
err = errno;
error(1, err, "can't open input file");
@@ -394,11 +397,20 @@ void SendSCP(void) {
printf ("Zero length of file. End\n");
return;
}
- printf ("File %s, length: %ld\n", tap_file, st.st_size);
+ printf ("File %s, length: %ld\n", sercp_file, st.st_size);
memset (p_fileinfo, 0, sizeof(fileinfo)); // smazat fileinfo
- basec = strdup (tap_file);
+ basec = strdup (sercp_file);
bname = basename (basec);
+ if (strlen(bname) > 12) {
+ printf ("Short filename: ");
+ shortfilename = strdup(bname);
+ fn_len = strlen(shortfilename);
+ memcpy(shortfilename+4, shortfilename+fn_len-8, 8);
+ *(shortfilename+12) = 0;
+ printf ("%s\n", shortfilename);
+ bname = shortfilename;
+ }
memcpy(p_fileinfo->fi_name, bname, strlen(bname));
file_len = (uint32_t) st.st_size;
@@ -472,30 +484,30 @@ int main(int argc, char** argv, char** env)
tcgetattr(serial_fd, &oldtio); /* save current port settings */
switch (baud_rate){
case 115200:
- newtio.c_cflag = B115200 | CS8 | CLOCAL | CREAD | CRTSCTS;
+ newtio.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
break;
case 57600:
- newtio.c_cflag = B57600 | CS8 | CLOCAL | CREAD | CRTSCTS;
+ newtio.c_cflag = B57600 | CS8 | CLOCAL | CREAD;
break;
default:
baud_rate = 38400;
case 38400:
- newtio.c_cflag = B38400 | CS8 | CLOCAL | CREAD | CRTSCTS; // dva stopbity jsou nastaveny vsude, ale tady ne
+ newtio.c_cflag = B38400 | CS8 | CLOCAL | CREAD; // dva stopbity jsou nastaveny vsude, ale tady ne
break;
case 19200:
- newtio.c_cflag = B19200 | CS8 | CLOCAL | CREAD | CRTSCTS;
+ newtio.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
break;
case 9600:
- newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD | CRTSCTS;
+ newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
break;
case 4800:
- newtio.c_cflag = B4800 | CS8 | CLOCAL | CREAD | CRTSCTS;
+ newtio.c_cflag = B4800 | CS8 | CLOCAL | CREAD;
break;
case 2400:
- newtio.c_cflag = B2400 | CS8 | CLOCAL | CREAD | CRTSCTS;
+ newtio.c_cflag = B2400 | CS8 | CLOCAL | CREAD;
break;
case 1200:
- newtio.c_cflag = B1200 | CS8 | CLOCAL | CREAD | CRTSCTS;
+ newtio.c_cflag = B1200 | CS8 | CLOCAL | CREAD;
break;
}
newtio.c_cflag |= CRTSCTS; // CSTOPB - dva stop bity NEE