#include "../pistorm-dev-enums.h"
#include "pistorm_dev.h"
+//#define SHUTUP_VSCODE
+
+#ifdef SHUTUP_VSCODE
+#define __stdargs
+#else
#include <exec/resident.h>
#include <exec/errors.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <proto/disk.h>
#include <proto/expansion.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#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);
}
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;
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;
}