58#include "ignore-value.h"
59#include "string-buffer.h"
61#include "xvasprintf.h"
68#if defined(HAVE_READLINE_READLINE_H)
69# include <readline/readline.h>
70#elif defined(HAVE_READLINE_H)
75#ifdef HAVE_READLINE_HISTORY
76# if defined(HAVE_READLINE_HISTORY_H)
77# include <readline/history.h>
78# elif defined(HAVE_HISTORY_H)
90#define CLIPFILE "C:/System/Data/Clpboard.cbd"
107 cout <<
_(
"FTP commands:") << endl << endl;
108 cout <<
" pwd" << endl;
109 cout <<
" ren <oldname> <newname>" << endl;
110 cout <<
" touch <psionfile>" << endl;
111 cout <<
" gtime <psionfile>" << endl;
112 cout <<
" test <psionfile>" << endl;
113 cout <<
" gattr <psionfile>" << endl;
114 cout <<
" sattr [[-|+]rwhsa] <psionfile>" << endl;
115 cout <<
" devs" << endl;
116 cout <<
" dir|ls" << endl;
117 cout <<
" dircnt" << endl;
118 cout <<
" cd <dir>" << endl;
119 cout <<
" lcd <dir>" << endl;
120 cout <<
" !<system command>" << endl;
121 cout <<
" get <psionfile>" << endl;
122 cout <<
" put <unixfile>" << endl;
123 cout <<
" mget <shellpattern>" << endl;
124 cout <<
" mput <shellpattern>" << endl;
125 cout <<
" cp <psionfile> <psionfile>" << endl;
126 cout <<
" del|rm <psionfile>" << endl;
127 cout <<
" mkdir <psiondir>" << endl;
128 cout <<
" rmdir <psiondir>" << endl;
129 cout <<
" volname <drive> <name>" << endl;
130 cout <<
" prompt" << endl;
131 cout <<
" hash" << endl;
132 cout <<
" bye" << endl;
133 cout << endl <<
_(
"RPC commands:") << endl << endl;
134 cout <<
" ps" << endl;
135 cout <<
" kill <pid|'all'>" << endl;
136 cout <<
" getclip <unixfile>" << endl;
137 cout <<
" putclip <unixfile>" << endl;
138 cout <<
" run <psionfile> [args]" << endl;
139 cout <<
" killsave <unixfile>" << endl;
140 cout <<
" runrestore <unixfile>" << endl;
141 cout <<
" machinfo" << endl;
142 cout <<
" ownerinfo" << endl;
143 cout <<
" settime" << endl;
144 cout <<
" setupinfo" << endl;
145 cout << endl <<
_(
"Device commands:") << endl << endl;
146 cout <<
" deviceid - get the device id used for backup and sync" << endl;
147 cout <<
" devicename - get the device name used for backup and sync" << endl;
148 cout <<
" setdevicename <name> - set the device name and persist the id used for backup and sync" << endl;
153 struct string_buffer sb;
155 int argc = argv.size();
156 for (
int i = 0; i < argc; i++) {
157 sb_append(&sb, argv[i]);
162 return sb_dupfree(&sb);
171 printf(
"#"); fflush(stdout);
190 FILE *fp = fopen(file,
"w");
193 cerr <<
_(
"Could not open command list file ") << file << endl;
196 fputs(
"#plpftp processlist\n", fp);
198 cerr <<
_(
"Could not get process list, Error: ") << res << endl;
201 for (processList::iterator i = tmp.begin(); i != tmp.end(); i++) {
202 fputs(i->getArgs(), fp);
206 time_t tstart = time(
nullptr) + 5;
207 while (!tmp.empty()) {
208 for (processList::iterator i = tmp.begin(); i != tmp.end(); i++) {
212 if (time(
nullptr) > tstart) {
213 cerr <<
_(
"Could not stop all processes. Please stop running\n"
214 "programs manually on the Psion, then hit return.") << flush;
215 cin.getline((
char *)&tstart, 1);
216 tstart = time(
nullptr) + 5;
219 cerr <<
_(
"Could not get process list, Error: ") << res << endl;
226static char *
get_upto(FILE *fp,
const char *term,
size_t *final_len) {
229 char *l = (
char *)malloc(len), *s = l;
232 for (c = getc(fp); c != EOF && strchr(term, c) == NULL; c = getc(fp)) {
234 l = (
char *)realloc(l, len * 2);
241 l = (
char *)realloc(l, len + 1);
249 l = (
char *)realloc(l, s - l);
260 FILE *fp = fopen(file,
"r");
264 cerr <<
_(
"Could not open command list file ") << file << endl;
267 cmd = string(
getln(fp));
268 if (strcmp(cmd.c_str(),
"#plpftp processlist")) {
270 cerr <<
_(
"Error: ") << file <<
271 _(
" is not a process list saved with killsave") << endl;
274 for (cmd =
string(
getln(fp)); cmd.length() > 0; cmd = string(
getln(fp))) {
275 int firstBlank = cmd.find(
' ');
276 string prog = string(cmd, 0, firstBlank);
277 string arg = string(cmd, firstBlank + 1);
283 if ((arg.size() > 2) && (arg[1] ==
':') && (arg[0] >=
'A') &&
294 if (prog.find(
'\\') == prog.npos) {
298 for (i = 0; i < 26; i++) {
299 if (devbits & (1 << i)) {
300 string tmp = string();
302 tmp +=
":\\System\\Apps\\" + prog +
"\\" + prog +
".app";
312 cerr <<
_(
"Could not start ") << cmd << endl;
313 cerr <<
_(
"Error: ") << res << endl;
322 cerr <<
_(
"Clipboard protocol not supported by Psion Series 3.") << endl;
330 cerr <<
_(
"Your Psion does not support the clipboard protocol.\n\
331 The reason for that is usually a missing server library.\n\
332 Make sure that C:\\System\\Libs\\clipsvr.rsy exists.\n\
333 This file is part of PsiWin and usually gets copied to\n\
334 your Psion when you enable CopyAnywhere in PsiWin.\n\
335 You can also get it from a PsiWin installation directory\n\
336 and copy it to your Psion manually.") << endl;
344 for (p = buf; len; len--, p++)
370 for (p = buf; len; len--, p++)
386static char *
slurp(FILE *fp,
size_t *final_len) {
394 const unsigned char *p;
403 if ((fp = fopen(file,
"r")) == NULL) {
408 data =
slurp(fp, &len);
431 p = (
const unsigned char *)b.
getString(0);
454 char *buf = (
char *)malloc(len);
457 cerr <<
"Out of memory in getClipData" << endl;
464 res =
a.
fread(fh, (
unsigned char *)buf, len, tmp);
470 uint32_t *ti = (uint32_t*)buf;
473 if (*ti++ != 0x10000037) {
477 if (*ti++ != 0x1000003b) {
485 if (*ti++ != 0x4739d53b) {
495 uint32_t *td = (uint32_t*)p;
497 uint32_t sType = *td++;
498 if (sType == 0x10000033) {
501 len = *((uint32_t*)p);
504 clipText += (
char *)p;
506 if (sType == 0x1000003d) {
519 FILE *fp = fopen(file,
"w");
523 fwrite(clipText.c_str(), 1, clipText.length(), fp);
536 if ((f1[strlen(f1) - 1] !=
'/') && (f1[strlen(f1) - 1] !=
'\\')) {
537 char *f2 = xasprintf(
"%s%s", f1,
"\\");
552 unsigned argc = argv.size();
559 auto nameError = deviceEndpoint.
getName(name);
566 cout <<
_(
"Connected to a ") << machType <<
_(
", at ") << speed <<
_(
" baud.") << endl;
568 cout <<
_(
"Connected to '") << name <<
_(
"', a ") << machType <<
_(
", at ")
569 << speed <<
_(
" baud.") << endl;
575 if (!strcmp(DDRIVE,
"AUTO")) {
585 cout <<
_(
"Psion dir is: \"") <<
psionDir <<
"\"" << endl;
599 if ((!strcmp(argv[0],
"help")) || (!strcmp(argv[0],
"?"))) {
603 if (!strcmp(argv[0],
"prompt")) {
605 cout <<
_(
"Prompting now ") << (prompt?
_(
"on") :
_(
"off")) << endl;
608 if (!strcmp(argv[0],
"hash")) {
610 cout <<
_(
"Hash printing now ") << (hash?
_(
"on") :
_(
"off")) << endl;
614 if (!strcmp(argv[0],
"pwd")) {
615 cout <<
_(
"Local dir: \"") <<
localDir <<
"\"" << endl;
616 cout <<
_(
"Psion dir: \"") <<
psionDir <<
"\"" << endl;
619 if (!strcmp(argv[0],
"volname") && (argc == 3) && (strlen(argv[1]) == 1)) {
621 cerr <<
_(
"Error: ") << res << endl;
625 if (!strcmp(argv[0],
"ren") && (argc == 3)) {
626 char *f1 = xasprintf(
"%s%s",
psionDir, argv[1]);
627 char *f2 = xasprintf(
"%s%s",
psionDir, argv[2]);
629 cerr <<
_(
"Error: ") << res << endl;
635 if (!strcmp(argv[0],
"cp") && (argc == 3)) {
636 char *f1 = xasprintf(
"%s%s",
psionDir, argv[1]);
637 char *f2 = xasprintf(
"%s%s",
psionDir, argv[2]);
639 cerr <<
_(
"Error: ") << res << endl;
645 if (!strcmp(argv[0],
"touch") && (argc == 2)) {
646 char *f1 = xasprintf(
"%s%s",
psionDir, argv[1]);
649 cerr <<
_(
"Error: ") << res << endl;
654 if (!strcmp(argv[0],
"test") && (argc == 2)) {
656 char *f1 = xasprintf(
"%s%s",
psionDir, argv[1]);
658 cerr <<
_(
"Error: ") << res << endl;
665 if (!strcmp(argv[0],
"gattr") && (argc == 2)) {
667 char *f1 = xasprintf(
"%s%s",
psionDir, argv[1]);
669 cerr <<
_(
"Error: ") << res << endl;
671 cout << hex << setw(4) << setfill(
'0') << attr;
672 cout <<
" (" << rfsv.
attr2String(attr) <<
")" << endl;
677 if (!strcmp(argv[0],
"gtime") && (argc == 2)) {
679 char *f1 = xasprintf(
"%s%s",
psionDir, argv[1]);
681 cerr <<
_(
"Error: ") << res << endl;
683 cout << mtime <<
"(" << hex
692 if (!strcmp(argv[0],
"sattr") && (argc == 3)) {
697 char *f1 = xasprintf(
"%s%s",
psionDir, argv[2]);
699 attr[0] = attr[1] = 0;
732 cerr <<
_(
"Error: ") << res << endl;
737 if (!strcmp(argv[0],
"deviceid") && (argc == 1)) {
738 cout << deviceEndpoint.
id() << endl;
740 cout <<
_(
"Warning: ") <<
_(
"not persistent; use setdevicename to set a name and persist the device id") << endl;
744 if (!strcmp(argv[0],
"devicename") && (argc == 1)) {
748 cout << name << endl;
750 cout <<
_(
"Error: ") <<
"not set; use setdevicename to set a name and persist the device id" << endl;
752 cerr <<
_(
"Error: ") <<
error << endl;
756 if (!strcmp(argv[0],
"setdevicename") && (argc == 2)) {
757 std::string name = argv[1];
760 cerr <<
_(
"Error: ") <<
error << endl;
765 if (!strcmp(argv[0],
"dircnt")) {
768 cerr <<
_(
"Error: ") << res << endl;
770 cout << cnt <<
_(
" Entries") << endl;
774 if (!strcmp(argv[0],
"devs")) {
777 cout <<
_(
"Drive Type Volname Total Free UniqueID") << endl;
778 for (
int i = 0; i < 26; i++) {
781 if ((devbits & 1) != 0) {
783 cout << (char) (
'A' + i) <<
" " << hex
784 << setw(4) << setfill(
'0')
785 <<
static_cast<uint32_t
>(drive.
getMediaType()) <<
" " << setw(12)
786 << setfill(
' ') << setiosflags(ios::left)
788 << resetiosflags(ios::left) << dec << setw(9)
790 << drive.
getSpace() <<
" " << setw(8)
791 << setfill(
'0') << hex << drive.
getUID()
798 cerr <<
_(
"Error: ") << res << endl;
802 if (!strcmp(argv[0],
"ls") || !strcmp(argv[0],
"dir")) {
806 cerr <<
_(
"Error: ") << res << endl;
808 while (!files.empty()) {
809 cout << files[0] << endl;
816 if (!strcmp(argv[0],
"lcd")) {
820 if (chdir(argv[1]) == 0) {
823 cerr <<
_(
"No such directory") << endl
824 <<
_(
"Keeping original directory \"") <<
localDir <<
"\"" << endl;
829 if (!strcmp(argv[0],
"cd")) {
837 cerr <<
_(
"Error: ") << res << endl;
838 cerr <<
_(
"Keeping original directory \"") <<
psionDir <<
"\"" << endl;
847 if ((!strcmp(argv[0],
"get")) && (argc > 1)) {
848 struct timeval stime;
849 struct timeval etime;
854 char *f2 = xasprintf(
"%s%s%s",
localDir,
"/", argc == 2 ? basename.c_str() : argv[2]);
856 gettimeofday(&stime,
nullptr);
862 cerr <<
_(
"Error: ") << res << endl;
866 gettimeofday(&etime,
nullptr);
867 long dsec = etime.tv_sec - stime.tv_sec;
868 long dhse = (etime.tv_usec / 10000) -
869 (stime.tv_usec /10000);
878 float cps = (float)(stbuf.st_size) / dt;
879 cout <<
_(
"Transfer complete, (") << dec << stbuf.st_size
880 <<
_(
" bytes in ") << dsec <<
"."
881 << dhse <<
_(
" secs = ") << cps <<
" cps)\n";
886 }
else if ((!strcmp(argv[0],
"mget")) && (argc == 2)) {
887 char *pattern = argv[1];
890 cerr <<
_(
"Error: ") << res << endl;
893 for (
size_t i = 0; i < files.size(); i++) {
900 if (fnmatch(pattern, e.
getName(), FNM_NOESCAPE) == FNM_NOMATCH) {
903 cout <<
_(
"Get \"") << e.
getName() <<
"\" (y,n): ";
921 cerr <<
_(
"Error: ") << res << endl;
927 cout <<
_(
"Transfer complete\n");
935 if (!strcmp(argv[0],
"put") && (argc >= 2)) {
936 struct timeval stime;
937 struct timeval etime;
940 char *f1 = xasprintf(
"%s%s%s",
localDir,
"/", argv[1]);
941 char *f2 = xasprintf(
"%s%s",
psionDir, argc == 2 ? argv[1] : argv[2]);
942 gettimeofday(&stime,
nullptr);
948 cerr <<
_(
"Error: ") << res << endl;
952 gettimeofday(&etime,
nullptr);
953 long dsec = etime.tv_sec - stime.tv_sec;
954 long dhse = (etime.tv_usec / 10000) -
955 (stime.tv_usec /10000);
964 float cps = (float)(stbuf.st_size) / dt;
965 cout <<
_(
"Transfer complete, (") << dec << stbuf.st_size
966 <<
_(
" bytes in ") << dsec <<
"."
967 << dhse <<
_(
" secs = ") << cps <<
" cps)\n";
973 if ((!strcmp(argv[0],
"mput")) && (argc == 2)) {
974 char *pattern = argv[1];
983 if (fnmatch(pattern, de->d_name, FNM_NOESCAPE) == FNM_NOMATCH) {
986 char *f1 = xasprintf(
"%s%s%s",
localDir,
"/", de->d_name);
987 if (stat(f1, &st) == 0 && S_ISREG(st.st_mode)) {
988 cout <<
_(
"Put \"") << de->d_name <<
"\" y,n: ";
998 char *f2 = xasprintf(
"%s%s",
psionDir, de->d_name);
1004 cerr <<
_(
"Error: ") << res << endl;
1013 cout <<
_(
"Transfer complete\n");
1022 cerr <<
_(
"Error in directory name \"") <<
localDir <<
"\"\n";
1026 if ((!strcmp(argv[0],
"del") ||
1027 !strcmp(argv[0],
"rm")) && (argc == 2)) {
1028 char *f1 = xasprintf(
"%s%s",
psionDir, argv[1]);
1030 cerr <<
_(
"Error: ") << res << endl;
1035 if (!strcmp(argv[0],
"mkdir") && (argc == 2)) {
1036 char *f1 = xasprintf(
"%s%s",
psionDir, argv[1]);
1038 cerr <<
_(
"Error: ") << res << endl;
1043 if (!strcmp(argv[0],
"rmdir") && (argc == 2)) {
1044 char *f1 = xasprintf(
"%s%s",
psionDir, argv[1]);
1046 cerr <<
_(
"Error: ") << res << endl;
1051 if (argv[0][0] ==
'!') {
1054 ignore_value(system(cmd));
1057 cout <<
_(
"Starting subshell ...\n");
1058 sh = getenv(
"SHELL");
1062 ignore_value(system(sh));
1068 if (!strcmp(argv[0],
"settime")) {
1070 cerr <<
_(
"Error: ") << res << endl;
1074 if (!strcmp(argv[0],
"setupinfo")) {
1079 cerr <<
_(
"Error: ") << res << endl;
1082 if (db.
getLen() < 1152) {
1083 cerr <<
_(
"Unknown setup info received") << endl;
1086 cout <<
_(
"Setup information:") << endl;
1087 cout <<
_(
" Screen contrast: ") << dec
1089 cout <<
_(
" Keyboard click: ")
1091 (db.
getDWord(0x204) ?
_(
"high") :
_(
"low")) :
_(
"off")) << endl;
1092 cout <<
_(
" Screen click: ")
1094 (db.
getDWord(0x210) ?
_(
"high") :
_(
"low")) :
_(
"off")) << endl;
1095 cout <<
_(
" Error sound: ")
1097 (db.
getDWord(0x218) ?
_(
"high") :
_(
"low")) :
_(
"off")) << endl;
1098 cout <<
_(
" Auto-switch off: ");
1104 cout <<
_(
"if running on battery power");
1107 cout <<
_(
"always");
1112 cout <<
_(
" Switch off after: ") << dec
1113 << db.
getDWord(0x22c) <<
_(
" seconds") << endl;
1114 cout <<
_(
" Backlight off after: ") << dec
1115 << db.
getDWord(0x234) <<
_(
" seconds") << endl;
1116 cout <<
_(
" Switch on when tapping on screen: ")
1117 << (db.
getDWord(0x238) ?
_(
"yes") :
_(
"no")) << endl;
1118 cout <<
_(
" Switch on when opening: ")
1119 << (db.
getDWord(0x23c) ?
_(
"yes") :
_(
"no")) << endl;
1120 cout <<
_(
" Switch off when closing: ")
1121 << (db.
getDWord(0x23c) ?
_(
"yes") :
_(
"no")) << endl;
1122 cout <<
_(
" Ask for password on startup: ")
1123 << (db.
getDWord(0x29c) ?
_(
"yes") :
_(
"no")) << endl;
1124 cout <<
_(
" Show Owner info on startup: ");
1130 cout <<
_(
"once a day");
1133 cout <<
_(
"always");
1139 if (!strcmp(argv[0],
"run") && (argc >= 2)) {
1140 vector<char *> args = {argv.begin() + 1, argv.end()};
1143 if (!strchr(argv[1],
':')) {
1144 cmd = xasprintf(
"%s%s",
psionDir, argv[1]);
1146 cmd = xstrdup(argv[1]);
1153 if (!strcmp(argv[0],
"ownerinfo")) {
1156 cerr <<
_(
"Error: ") << res << endl;
1159 while (!b.
empty()) {
1164 if (!strcmp(argv[0],
"machinfo")) {
1167 cerr <<
_(
"Error: ") << res << endl;
1171 cout <<
_(
"General:") << endl;
1172 cout <<
_(
" Machine Type: ") << mi.
machineType << endl;
1173 cout <<
_(
" Machine Name: ") << mi.
machineName << endl;
1174 cout <<
_(
" Machine UID: ") << hex << mi.
machineUID << dec << endl;
1175 cout <<
_(
" UI Language: ") << mi.
uiLanguage << endl;
1176 cout <<
_(
"ROM:") << endl;
1177 cout <<
_(
" Version: ") << mi.
romMajor <<
"." << setw(2) << setfill(
'0') <<
1179 cout <<
_(
" Size: ") << mi.
romSize / 1024 <<
"k" << endl;
1180 cout <<
_(
" Programmable: ") <<
1182 cout <<
_(
"RAM:") << endl;
1183 cout <<
_(
" Size: ") << mi.
ramSize / 1024 <<
"k" << endl;
1184 cout <<
_(
" Free: ") << mi.
ramFree / 1024 <<
"k" << endl;
1185 cout <<
_(
" Free max: ") << mi.
ramMaxFree / 1024 <<
"k" << endl;
1186 cout <<
_(
"RAM disk size: ") << mi.
ramDiskSize / 1024 <<
"k" << endl;
1190 cout <<
_(
"Time:") << endl;
1192 cout <<
_(
" Current time: ") << pt << endl;
1193 cout <<
_(
" UTC offset: ") << mi.
tz.
utc_offset <<
_(
" seconds") << endl;
1194 cout <<
_(
" DST: ") <<
1197 cout <<
_(
" Country Code: ") << mi.
countryCode << endl;
1198 cout <<
_(
"Main battery:") << endl;
1200 cout <<
_(
" Changed at: ") << pt << endl;
1207 cout <<
_(
"Backup battery:") << endl;
1211 cout <<
_(
"External power:") << endl;
1212 cout <<
_(
" Supplied: ")
1217 if (!strcmp(argv[0],
"runrestore") && (argc == 2)) {
1221 if (!strcmp(argv[0],
"killsave") && (argc == 2)) {
1225 if (!strcmp(argv[0],
"putclip") && (argc == 2)) {
1227 cerr <<
_(
"Error setting clipboard") << endl;
1231 if (!strcmp(argv[0],
"getclip") && (argc == 2)) {
1233 cerr <<
_(
"Error getting clipboard") << endl;
1237 if (!strcmp(argv[0],
"kill") && (argc >= 2)) {
1239 bool anykilled =
false;
1241 cerr <<
_(
"Error: ") << res << endl;
1243 for (
unsigned int i = 1; i < argc; i++) {
1245 if (!strcmp(argv[i],
"all")) {
1248 sscanf(argv[i],
"%d", &kpid);
1250 processList::iterator j;
1251 for (j = tmp.begin(); j != tmp.end(); j++) {
1252 if (kpid == -1 || kpid == j->getPID()) {
1262 cerr <<
_(
"no such process") << endl;
1267 if (!strcmp(argv[0],
"ps")) {
1270 cerr <<
_(
"Error: ") << res << endl;
1272 cout <<
"PID CMD ARGS" << endl;
1273 for (processList::iterator i = tmp.begin(); i != tmp.end(); i++) {
1279 if (strcmp(argv[0],
"bye") == 0 || strcmp(argv[0],
"quit") == 0) {
1282 cerr <<
_(
"syntax error. Try \"help\"") << endl;
1288#define MATCHFUNCTION rl_completion_matches
1291 "pwd",
"ren",
"touch",
"gtime",
"test",
"gattr",
"sattr",
"devs",
1292 "dir",
"ls",
"dircnt",
"cd",
"lcd",
"get",
"put",
"mget",
"mput",
1293 "del",
"rm",
"mkdir",
"rmdir",
"prompt",
"bye",
"cp",
"volname",
1294 "ps",
"kill",
"killsave",
"runrestore",
"run",
"machinfo",
1295 "ownerinfo",
"help",
"settime",
"setupinfo",
"deviceid",
"devicename",
1296 "setdevicename", NULL
1300 "lcd ",
"put ",
"mput ",
"killsave ",
"runrestore ", NULL
1304 "cd ",
"rmdir ", NULL
1324 cerr <<
_(
"Error: ") << res << endl;
1338 if (!(strncmp(tmp.c_str(), text, len))) {
1340 rl_completion_append_character =
'\0';
1343 return (strdup(tmp.c_str()));
1350 static int idx, len;
1359 if (!strncmp(name, text, len)) {
1360 return (strdup(name));
1369 static char null[1] =
"";
1374 char **matches = NULL;
1377 rl_completion_append_character =
' ';
1378 rl_attempted_completion_over = 1;
1386 rl_filename_quoting_desired = 1;
1389 if (!strncmp(name, rl_line_buffer, strlen(name))) {
1390 rl_completion_entry_function = NULL;
1406 if (!strncmp(name, rl_line_buffer, strlen(name))) {
1419 rl_readline_name =
"plpftp";
1422 rl_basic_word_break_characters =
" \t\n\"\\'`@><=;|&{(";
1423 rl_completer_quote_characters =
"\"";
1429 vector<char *> argv;
1443 for (
char *p = buf; *p; p++)
1465 cout <<
"bye" << endl;
1466 buf = strdup(
"bye");
1467 argv.push_back(buf);
An array of BufferStores.
bool empty() const
Checks if this BufferArray is empty.
BufferStore pop(void)
Removes the first BufferStore.
A generic container for an array of bytes.
const char * getString(long pos=0) const
Retrieves the characters at index pos.
uint32_t getDWord(long pos=0) const
Retrieves the dword at index pos.
void addByte(unsigned char c)
Appends a byte to the content of this instance.
void addStringT(const char *s)
Appends a string to the content of this instance.
void addDWord(long dw)
Appends a dword to the content of this instance.
unsigned long getLen() const
Retrieves the length of a BufferStore.
unsigned char getByte(long pos=0) const
Retrieves the byte at index pos.
std::string id() const
Device identifier.
bool hasPersistentId() const
Enum< RFSV::errs > setName(const std::string &name)
Set the device name.
Enum< RFSV::errs > getName(std::string &name) const
Get the device name.
A class representing information about a Disk drive on the psion.
uint32_t getUID() const
Retrieve the UID of the drive.
MediaType getMediaType() const
Retrieve the media type of the drive.
uint64_t getSpace() const
Retrieve the free capacity on the drive.
uint64_t getSize() const
Retrieve the total capacity of the drive.
std::string getName() const
Retrieve the volume name of the drive.
Wrapper class featuring range-checking and string representation of enumerated values.
std::vector< char * > getCommand()
int session(DeviceEndpoint &deviceEndpoint, RFSV &rfsv, RPCS &rpcs, rclip &clipboard, std::vector< char * > argv)
int putClipText(RFSV &a, rclip &rc, const char *data)
bool checkClipConnection(RFSV &a, rclip &rc)
int getClipData(RFSV &a, rclip &rc, const char *file)
A class, representing a directory entry of the Psion.
uint32_t getAttr() const
Retrieves the file attributes of a directory entry.
const char * getName() const
Retrieve the file name of a directory entry.
uint32_t getSize() const
Retrieves the file size of a directory entry.
Psion time related utility class.
uint32_t getPsiTimeHi(void)
Retrieves the instance's current value in Psion time format, low 32 bits.
uint32_t getPsiTimeLo(void)
Retrieves the instance's current value in Psion time format, high 32 bits.
void setPsiTime(psi_timeval *_ptv)
Modifies the value of this instance.
Access remote file services of a Psion.
virtual Enum< errs > copyOnPsion(const char *const from, const char *const to, void *, cpCallback_t func)=0
Copies a file from the Psion to the Psion.
virtual Enum< errs > fwrite(const uint32_t handle, const unsigned char *const buffer, const uint32_t len, uint32_t &count)=0
Write to a file on the Psion.
virtual Enum< errs > fgetmtime(const char *const name, PsiTime &mtime)=0
Retrieves the modification time of a file on the Psion.
virtual uint32_t opMode(const uint32_t mode)=0
Converts an open-mode (A combination of the PSI_O_ constants.) from generic representation to the mac...
virtual Enum< errs > remove(const char *const name)=0
Removes a file on the Psion.
virtual Enum< errs > fopen(const uint32_t attr, const char *const name, uint32_t &handle)=0
Opens a file.
std::string attr2String(const uint32_t attr)
Converts a file attribute RFSV::file_attribs to human readable format, usable for showing them in dir...
virtual Enum< errs > setVolumeName(const char drive, const char *const name)=0
Set the name of a Psion Volume (Drive).
virtual Enum< errs > fread(const uint32_t handle, unsigned char *const buffer, const uint32_t len, uint32_t &count)=0
Reads from a file on the Psion.
virtual Enum< errs > fsetattr(const char *const name, const uint32_t seta, const uint32_t unseta)=0
virtual Enum< errs > copyToPsion(const char *const from, const char *const to, void *, cpCallback_t func)=0
Copies a file from local machine to the Psion.
virtual Enum< errs > fgeteattr(const char *const name, PlpDirent &e)=0
Retrieves attributes, size and modification time of a file on the Psion.
virtual Enum< errs > fsetmtime(const char *const name, const PsiTime mtime)=0
Sets the modification time of a file on the Psion.
virtual Enum< errs > mkdir(const char *const name)=0
Creates a directory on the Psion.
virtual char defaultInternalDriveLetter()=0
virtual Enum< errs > fclose(const uint32_t handle)=0
Close a file on the Psion whih was previously opened/created by using fopen , fcreatefile ,...
Enum< errs > getStatus()
Retrieves the current connection status.
virtual Enum< errs > fgetattr(const char *const name, uint32_t &attr)=0
Retrieves attributes of a file on the Psion.
virtual Enum< errs > dir(const char *const name, PlpDir &ret)=0
Reads a directory on the Psion.
virtual Enum< errs > dircount(const char *const name, uint32_t &count)=0
Counts number of entries in a directory.
virtual Enum< errs > freplacefile(const uint32_t attr, const char *const name, uint32_t &handle)=0
Creates an named file, overwriting an existing file.
virtual int getProtocolVersion()=0
Retrieves the protocol version.
virtual Enum< errs > rmdir(const char *const name)=0
Removes a directory on the Psion.
virtual Enum< errs > devlist(uint32_t &devbits)=0
Retrieves available drives on the Psion.
virtual Enum< errs > devinfo(const char drive, Drive &dinfo)=0
Retrieves details about a drive.
static std::string convertSlash(const std::string &name)
Utility method, converts '/' to '\'.
virtual Enum< errs > rename(const char *const oldname, const char *const newname)=0
Renames a file on the Psion.
int getSpeed()
Retrieve speed of serial link.
virtual Enum< errs > copyFromPsion(const char *from, const char *to, void *context, cpCallback_t func)=0
Copies a file from the Psion to the local machine.
@ PSI_A_READ
Attributes, valid on SIBO only.
@ PSI_A_RDONLY
Attributes, valid on both EPOC and SIBO.
Remote procedure call services via PLP.
virtual Enum< RFSV::errs > getOwnerInfo(BufferArray &owner)=0
Retrieve owner information of the remote machine.
Enum< RFSV::errs > queryPrograms(processList &ret)
Retrieves a list of all running Programs.
virtual Enum< RFSV::errs > getMachineInfo(machineInfo &machineInfo)
Retrieve general Information about the connected machine.
virtual Enum< RFSV::errs > configRead(uint32_t size, BufferStore &data)
Read from Series 5 scratch RAM.
Enum< RFSV::errs > stopProgram(const char *program)
Requests termination of a program running on the remote machine.
Enum< RFSV::errs > getMachineType(Enum< machs > &type)
Retrieves the type of machine on the remote side as defined in machs.
Enum< RFSV::errs > execProgram(const char *program, const char *args)
Starts execution of a program on the remote machine.
virtual Enum< RFSV::errs > setTime(time_t time)
Remote ClipBoard services via PLP.
Enum< RFSV::errs > initClipbd()
Send initialization frame.
static char ** do_completion(const char *text, int start, int)
static char * join_string_vector(vector< char * > argv, const char *sep)
static int checkAbortHash(void *, uint32_t)
static int checkAbortNoHash(void *, uint32_t)
static void ascii2PsiText(char *buf, int len)
static void psiText2ascii(char *buf, int len)
static char * null_completion(const char *, int)
static char * epoc_dir_from(const char *path)
Compute new directory from path, which may be absolute or relative, and cwd.
static char * command_generator(const char *text, int state)
static const char * remote_dir_commands[]
static int startPrograms(RPCS &r, RFSV &a, const char *file)
static char * getln(FILE *fp)
static const char * all_commands[]
static const char * localfile_commands[]
static void sigint_handler2(int)
static int continueRunning
static char * filename_generator(const char *text, int state)
static char * slurp(FILE *fp, size_t *final_len)
static char * get_upto(FILE *fp, const char *term, size_t *final_len)
static int stopPrograms(RPCS &rpcs, const char *file)
static void sigint_handler(int)
char * resolve_epoc_path(const char *path, const char *initialPath)
Returns a new absolute EPOC path, determined by resolving path relative to initialPath.
std::string epoc_basename(std::string path)
Returns the last path component of an EPOC path.
int(* cpCallback_t)(void *, uint32_t)
Defines the callback procedure for progress indication of copy operations.
std::deque< class PlpDirent > PlpDir
std::vector< PsiProcess > processList
static void error(int line)
This struct holds the data returned by RPCS::getMachineInfo.
unsigned long mainBatteryUsedPower
Enum< languages > uiLanguage
unsigned long displayHeight
unsigned long mainBatteryVoltage
psi_timeval externalPowerUsedTime
Enum< batterystates > backupBatteryStatus
psi_timeval mainBatteryInsertionTime
Enum< machs > machineType
unsigned long ramDiskSize
unsigned long mainBatteryCurrent
psi_timeval mainBatteryUsedTime
Enum< batterystates > mainBatteryStatus
unsigned long countryCode
unsigned long long machineUID
unsigned long backupBatteryMaxVoltage
unsigned long registrySize
unsigned long displayWidth
unsigned long mainBatteryMaxVoltage
unsigned long backupBatteryVoltage