X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=platforms%2Famiga%2Fpistorm-dev%2Fpistorm_dev_amiga%2Fsimple_interact.c;h=b9ea1a919180dade02f67285b53f3cc24f9e65da;hb=852bfb6e64da97b3481c3e6f77799522f358e4a8;hp=eaf2903be818e550e59e43bc68f327e0f49dc70c;hpb=840e75be868f82a3974371b16aa1d0ca7b90fd44;p=pistorm diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/simple_interact.c b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/simple_interact.c index eaf2903..b9ea1a9 100644 --- a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/simple_interact.c +++ b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/simple_interact.c @@ -3,6 +3,11 @@ #include "../pistorm-dev-enums.h" #include "pistorm_dev.h" +//#define SHUTUP_VSCODE + +#ifdef SHUTUP_VSCODE +#define __stdargs +#else #include #include #include @@ -23,6 +28,7 @@ #include #include #include +#endif #include #include @@ -31,7 +37,7 @@ #define LOADLIB(a, b) if ((a = (struct a*)OpenLibrary(b,0L))==NULL) { \ printf("Failed to load %s.\n", b); \ return 1; \ - } \ + } void print_usage(char *exe); int get_command(char *cmd); @@ -89,6 +95,37 @@ int __stdargs main (int argc, char *argv[]) { } pi_handle_config(cmd_arg, argv[2]); break; + case PI_CMD_TRANSFERFILE: + if (argc < 4) { + printf ("Please specify a source and destination filename in addition to the command.\n"); + printf ("Example: %s --transfer platforms/platform.h snakes.h\n", argv[0]); + } + if (pi_get_filesize(argv[2], &tmpvalue) == PI_RES_FILENOTFOUND) { + printf ("File %s not found on the Pi side.\n", argv[2]); + } else { + unsigned int filesize = tmpvalue; + unsigned char *dest = malloc(filesize); + + if (dest == NULL) { + printf ("Failed to allocate memory buffer for file. Aborting file transfer.\n"); + } else { + printf ("Found a %d byte file on the Pi side. Eating it.\n", filesize); + if (pi_transfer_file(argv[2], dest) != PI_RES_OK) { + printf ("Something went horribly wrong during the file transfer.\n"); + } else { + FILE *out = fopen(argv[3], "wb+"); + if (out == NULL) { + printf ("Failed to open output file %s for writing.\n", argv[3]); + } else { + fwrite(dest, filesize, 1, out); + fclose(out); + printf ("%d bytes transferred to file %s.\n", filesize, argv[3]); + } + } + free(dest); + } + } + break; default: printf ("Unhandled command %s.\n", argv[1]); return 1; @@ -117,6 +154,9 @@ int get_command(char *cmd) { cmd_arg = PICFG_DEFAULT; return PI_CMD_SWITCHCONFIG; } + if (strcmp(cmd, "--transfer-file") == 0 || strcmp(cmd, "--transfer") == 0 || strcmp(cmd, "--getfile") == 0) { + return PI_CMD_TRANSFERFILE; + } return -1; }