From 298c3400f75efbc7fe934923684177b84221bfd0 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Sun, 9 Mar 2025 16:40:45 +0100 Subject: [PATCH 01/31] Completed .gitignore. --- .gitignore | 70 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index c23cd852..872dd938 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,68 @@ -config.cache +# generic files to ignore +# backup files (*~) and vim swap file (.swp), MacOS dir file (.DS_Store) +*~ +*.lock +*.DS_Store +.*.swp +*.out +*.bak +*.zip +*.patch + +# except this file +!.gitignore + +# from autoreconf -i +compile config.guess -config.h -config.h.in -config.log -config.status config.sub -configure install-sh +missing +depcomp +ylwrap +test-driver +autom4te.cache +m4 +aclocal.m4 +config.cache +config.h.in configure -libtool ltconfig ltmain.sh -.deps -.libs -stamp-h* -aclocal.m4 -Makefile Makefile.in + +# from configure +config.h +config.status +config.log +Makefile +Makefile.PL +stamp-h* +libtool +.deps pilot-link.m4 pilot-link.pc pilot-link-pp.pc tags -autom4te.cache +include/pi-md5.h +include/pi-version.h +doc/xml/catalog.xml +doc/xml/docbook.xsl +doc/doxygen.cfg +bindings/Python/setup*.py + +# from make / cc / gcc +*.o +*.la +*.lo +*.so +.libs +src/pilot-* +!src/*.c +!src/*.h +!src/*.pl +src/parsedate.c +tests/*-test + +# from make install +dist From b65bca51a7f34715858520a3791dc5d32765014a Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Sun, 9 Mar 2025 16:43:18 +0100 Subject: [PATCH 02/31] Applied patches from https://github.com/NixOS/nixpkgs/tree/master/pkgs/by-name/pi/pilot-link. --- configure.ac | 11 ++++------- src/pilot-dlpsh.c | 2 +- src/pilot-hinotes.c | 4 +--- src/pilot-read-notepad.c | 8 ++------ src/pilot-read-palmpix.c | 8 ++------ src/pilot-read-screenshot.c | 8 ++------ src/pilot-read-veo.c | 8 ++------ src/pilot-xfer.c | 9 +++------ 8 files changed, 17 insertions(+), 41 deletions(-) diff --git a/configure.ac b/configure.ac index 71459d08..6a6584ad 100644 --- a/configure.ac +++ b/configure.ac @@ -63,8 +63,8 @@ AC_SUBST(PISYNC_AGE) dnl Eat -Werror so configure will run properly, if the user provided it enable_werror=no save_CFLAGS="$CFLAGS" -CFLAGS=$(echo $save_CFLAGS | sed -e s/-Werror//g) -CXXFLAGS=$(echo $save_CXXFLAGS | sed -e s/-Werror//g) +CFLAGS=$(echo "$save_CFLAGS" | sed -e 's/-Werror[^=]//g') +CXXFLAGS=$(echo "$save_CXXFLAGS" | sed -e 's/-Werror[^=]//g') if test "x$CFLAGS" != "x$save_CFLAGS"; then dnl -Werror was set; treat it as implicit --enable-werror below enable_werror="yes" @@ -392,11 +392,8 @@ if test "x$enable_conduits" != "xno"; then dnl Determine if system popt is good enough save_LIBS="$LIBS" AC_CHECK_HEADER(popt.h, - AC_CHECK_DECL(POPT_BIT_SET, - AC_CHECK_LIB(popt, poptStrippedArgv,, - [with_included_popt="yes"]), - [with_included_popt="yes"], - [#include ]), + AC_CHECK_LIB(popt, poptStrippedArgv,, + [with_included_popt="yes"]), [with_included_popt="yes"] ) LIBS="$save_LIBS" diff --git a/src/pilot-dlpsh.c b/src/pilot-dlpsh.c index afbe5da4..24982059 100644 --- a/src/pilot-dlpsh.c +++ b/src/pilot-dlpsh.c @@ -389,7 +389,7 @@ int time_fn(int sd, int argc, const char *argv[]) strftime(timebuf, 80, "Now setting Palm time from desktop to: " "%a %b %d %H:%M:%S %Z %Y\n", tm_ptr); - printf(timebuf); + printf("%s", timebuf); gettimeofday(&tv, 0); ltime = tv.tv_sec + 1; usleep(1000000 - tv.tv_usec); diff --git a/src/pilot-hinotes.c b/src/pilot-hinotes.c index a0336dc6..40ccf204 100644 --- a/src/pilot-hinotes.c +++ b/src/pilot-hinotes.c @@ -79,9 +79,7 @@ void write_memo_mbox(struct PilotUser User, struct HiNoteNote m, printf("...\n"); else printf("\n"); - printf("\n"); - printf(m.text); - printf("\n"); + printf("\n%s\n", m.text); } void write_memo_in_directory(char *dirname, struct HiNoteNote m, diff --git a/src/pilot-read-notepad.c b/src/pilot-read-notepad.c index 06ee26f2..e33025ab 100644 --- a/src/pilot-read-notepad.c +++ b/src/pilot-read-notepad.c @@ -39,10 +39,6 @@ #ifdef HAVE_PNG #include "png.h" -#if (PNG_LIBPNG_VER < 10201) - #define png_voidp_NULL (png_voidp)NULL - #define png_error_ptr_NULL (png_error_ptr)NULL -#endif #endif const char *progname; @@ -166,8 +162,8 @@ void write_png( FILE *f, struct NotePad *n ) width = n->body.width + 8; png_ptr = png_create_write_struct - ( PNG_LIBPNG_VER_STRING, png_voidp_NULL, - png_error_ptr_NULL, png_error_ptr_NULL); + ( PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL); if(!png_ptr) return; diff --git a/src/pilot-read-palmpix.c b/src/pilot-read-palmpix.c index 2c005517..5799ab3a 100644 --- a/src/pilot-read-palmpix.c +++ b/src/pilot-read-palmpix.c @@ -42,10 +42,6 @@ #ifdef HAVE_PNG #include "png.h" -#if (PNG_LIBPNG_VER < 10201) - #define png_voidp_NULL (png_voidp)NULL - #define png_error_ptr_NULL (png_error_ptr)NULL -#endif #endif const char *progname; @@ -223,8 +219,8 @@ void write_png( FILE *f, const struct PalmPixState *state, png_infop info_ptr; png_ptr = png_create_write_struct - ( PNG_LIBPNG_VER_STRING, png_voidp_NULL, - png_error_ptr_NULL, png_error_ptr_NULL); + ( PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL); if(!png_ptr) return; diff --git a/src/pilot-read-screenshot.c b/src/pilot-read-screenshot.c index a3106a30..18de0222 100644 --- a/src/pilot-read-screenshot.c +++ b/src/pilot-read-screenshot.c @@ -40,10 +40,6 @@ #ifdef HAVE_PNG # include "png.h" -# if (PNG_LIBPNG_VER < 10201) -# define png_voidp_NULL (png_voidp)NULL -# define png_error_ptr_NULL (png_error_ptr)NULL -# endif #endif #define pi_mktag(c1,c2,c3,c4) (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4)) @@ -87,8 +83,8 @@ void write_png ( char *fname, struct ss_state *state ) gray_buf = malloc( state->w ); png_ptr = png_create_write_struct - (PNG_LIBPNG_VER_STRING, png_voidp_NULL, - png_error_ptr_NULL, png_error_ptr_NULL); + (PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL); if (!png_ptr) return; diff --git a/src/pilot-read-veo.c b/src/pilot-read-veo.c index 73aa53b7..6ecc79f9 100644 --- a/src/pilot-read-veo.c +++ b/src/pilot-read-veo.c @@ -41,10 +41,6 @@ #ifdef HAVE_PNG # include "png.h" -# if (PNG_LIBPNG_VER < 10201) -# define png_voidp_NULL (png_voidp)NULL -# define png_error_ptr_NULL (png_error_ptr)NULL -# endif #endif #define pi_mktag(c1,c2,c3,c4) (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4)) @@ -856,8 +852,8 @@ void write_png (FILE * f, struct Veo *v, long flags) png_infop info_ptr; png_ptr = png_create_write_struct - (PNG_LIBPNG_VER_STRING, png_voidp_NULL, - png_error_ptr_NULL, png_error_ptr_NULL); + (PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL); if (!png_ptr) return; diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 25aa05e4..096a93c7 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -2477,8 +2477,7 @@ main(int argc, const char *argv[]) { fprintf(stderr, " ERROR: '%s' is not a directory or does not exist.\n" " Please supply a directory name when performing a " - "backup or restore and try again.\n\n", dirname); - fprintf(stderr,gracias); + "backup or restore and try again.\n\n%s", dirname, gracias); return 1; } } @@ -2487,14 +2486,12 @@ main(int argc, const char *argv[]) case palm_op_list: if (rargc > 0) { - fprintf(stderr," ERROR: Do not pass additional arguments to -busrlLC.\n"); - fprintf(stderr,gracias); + fprintf(stderr," ERROR: Do not pass additional arguments to -busrlLC.\n%s", gracias); return 1; } break; case palm_op_noop: - fprintf(stderr," ERROR: Must specify one of -bursimfdlC.\n"); - fprintf(stderr,gracias); + fprintf(stderr," ERROR: Must specify one of -bursimfdlC.\n%s", gracias); return 1; break; case palm_op_merge: From 458607c003d91d1171e5fa53ae9dcad9d9d741ca Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Sun, 9 Mar 2025 16:46:19 +0100 Subject: [PATCH 03/31] Updated configure.ac with autoupdate and autoreconf -i -s. --- configure.ac | 71 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index 6a6584ad..4be6ea8b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,8 @@ # This is free software, licensed under the GNU Public License V2. # See the file COPYING for details. -AC_INIT(include/pi-version.h.in) +AC_INIT +AC_CONFIG_SRCDIR([include/pi-version.h.in]) AC_CONFIG_MACRO_DIR([m4]) dnl Initialize maintainer mode @@ -15,7 +16,7 @@ AC_PREFIX_DEFAULT(/usr/local) dnl ****************************** dnl Limit to a specific ac version dnl ****************************** -AC_PREREQ(2.53) +AC_PREREQ([2.71]) AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(include/pi-md5.h) @@ -73,7 +74,7 @@ fi dnl Check host type AC_CANONICAL_HOST -AC_CANONICAL_SYSTEM +AC_CANONICAL_TARGET AC_DEFINE_UNQUOTED(HOST_OS, "$host", [Host type]) AM_INIT_AUTOMAKE(pilot-link, [$VERSION]) @@ -155,12 +156,45 @@ AM_CONDITIONAL(GIT_BUILD,[test -d "${srcdir}/.git"]) dnl ****************************** dnl Pilot Link Checks dnl ****************************** -AC_HEADER_STDC +m4_warn([obsolete], +[The preprocessor macro `STDC_HEADERS' is obsolete. + Except in unusual embedded environments, you can safely include all + ISO C90 headers unconditionally.])dnl +# Autoupdate added the next two lines to ensure that your configure +# script's behavior did not change. They are probably safe to remove. +AC_CHECK_INCLUDES_DEFAULT +AC_PROG_EGREP + AC_C_CONST -AC_HEADER_TIME +m4_warn([obsolete], +[Update your code to rely only on HAVE_SYS_TIME_H, +then remove this warning and the obsolete code below it. +All current systems provide time.h; it need not be checked for. +Not all systems provide sys/time.h, but those that do, all allow +you to include it and time.h simultaneously.])dnl +AC_CHECK_HEADERS_ONCE([sys/time.h]) +# Obsolete code to be removed. +if test $ac_cv_header_sys_time_h = yes; then + AC_DEFINE([TIME_WITH_SYS_TIME],[1],[Define to 1 if you can safely include both + and . This macro is obsolete.]) +fi +# End of obsolete code. + AC_STRUCT_TM AC_PROG_GCC_TRADITIONAL -AC_TYPE_SIGNAL +m4_warn([obsolete], +[your code may safely assume C89 semantics that RETSIGTYPE is void. +Remove this warning and the `AC_CACHE_CHECK' when you adjust the code.])dnl +AC_CACHE_CHECK([return type of signal handlers],[ac_cv_type_signal],[AC_COMPILE_IFELSE( +[AC_LANG_PROGRAM([#include +#include +], + [return *(signal (0, 0)) (0) == 1;])], + [ac_cv_type_signal=int], + [ac_cv_type_signal=void])]) +AC_DEFINE_UNQUOTED([RETSIGTYPE],[$ac_cv_type_signal],[Define as the return type of signal handlers + (`int' or `void').]) + AC_CHECK_HEADERS( dirent.h errno.h fcntl.h inttypes.h memory.h netdb.h \ @@ -195,10 +229,8 @@ AC_CHECK_LIB(inet, main, [LIBS="$LIBS -linet"]) AC_CACHE_CHECK([for cispeed and cospeed members of struct termios], ac_cv_termios_cspeed, - [AC_TRY_COMPILE( - [#include ], [int main(void) { - struct termios t;t.c_ispeed=t.c_ospeed=0;}], - ac_cv_termios_cspeed=yes,ac_cv_termios_cspeed=no)]) + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[int main(void) { + struct termios t;t.c_ispeed=t.c_ospeed=0;}]])],[ac_cv_termios_cspeed=yes],[ac_cv_termios_cspeed=no])]) if test $ac_cv_termios_cspeed = yes; then AC_DEFINE(TERMIOS_CSPEED, 1, [Define if we have termios(3) support]) @@ -293,7 +325,7 @@ usb_type= usb_libs= AC_ARG_ENABLE(libusb, - AC_HELP_STRING([--enable-libusb Enable usage of libusb]), + AS_HELP_STRING([--enable-libusb Enable usage of libusb]), if test "x$enableval" != "xno" ; then AC_CHECK_LIB(usb, usb_open, [have_libusb=yes;],[have_libusb=no]) fi @@ -348,8 +380,7 @@ have_bluez=no use_bluez=auto AC_ARG_WITH(bluez, - AC_HELP_STRING([--with-bluez], - [Enable use of BlueZ]), + AS_HELP_STRING([--with-bluez],[Enable use of BlueZ]), [use_bluez="$withval"]) if test "$use_bluez" != "no" ; then PKG_CHECK_MODULES([BLUEZ],[bluez],[ @@ -445,7 +476,7 @@ AC_CHECK_LIB( AC_CHECK_FUNC(iconv, [ AC_CHECK_FUNCS(gnu_get_libc_version) AC_MSG_CHECKING(if system iconv handles CP1252) - AC_TRY_RUN([ + AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include #include #include @@ -471,11 +502,11 @@ int main (int argc, char **argv) exit (1); exit (0); -}], AC_MSG_RESULT(yes); have_iconv=yes, [AC_MSG_RESULT(no);], AC_MSG_RESULT(not cross compiling);)])]) +}]])],[AC_MSG_RESULT(yes); have_iconv=yes],[AC_MSG_RESULT(no);],[AC_MSG_RESULT(not cross compiling);])])]) -dnl ## Fixed AC_TRY_RUN warning, missing third argument. -DD 22/01/2002 +dnl ## Fixed AC_RUN_IFELSE([AC_LANG_SOURCE([[]])],[],[],[]) warning, missing third argument. -DD 22/01/2002 dnl -dnl AC_TRY_RUN is a macro that's basically like an if-then-else structure. If +dnl AC_RUN_IFELSE([AC_LANG_SOURCE([[]])],[],[],[]) is a macro that's basically like an if-then-else structure. If dnl the test program (whose text is the first argument) succeeds, the second dnl argument is executed; if the test fails, the third argument is executed; and dnl if autoconf knows it is cross-compiling for another machine and therefore @@ -702,8 +733,7 @@ dnl ************************************* AM_CONDITIONAL(BUILD_XML,[test ! -d "{$srcdir}/.git"]) # if test -d "${srcdir}/.git" ; then -AC_ARG_ENABLE([xsltproc], [AC_HELP_STRING([--enable-xsltproc], - [Use xsltproc to build documentation [default=no]])], +AC_ARG_ENABLE([xsltproc], [AS_HELP_STRING([--enable-xsltproc],[Use xsltproc to build documentation [default=no]])], [enable_xsltproc="$enableval"], [enable_xsltproc=no]) if test x"$enable_xsltproc" = x"yes"; then @@ -767,7 +797,7 @@ if test "x$GCC" = "xyes" -a "x$enable_werror" = "xyes"; then CFLAGS="$CFLAGS -Werror" fi -AC_OUTPUT([ +AC_CONFIG_FILES([ Makefile pilot-link.m4 pilot-link.pc @@ -796,6 +826,7 @@ AC_OUTPUT([ tests/Makefile darwin/Makefile ]) +AC_OUTPUT AC_MSG_RESULT([ Options detected/selected From 42ac6a9698f20dc1f547a6abc7f225d6967c9a3c Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Sun, 9 Mar 2025 16:56:06 +0100 Subject: [PATCH 04/31] Updated and completed the build instructions in README. --- README | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/README b/README index f5d90a68..cd640bde 100644 --- a/README +++ b/README @@ -120,6 +120,24 @@ Building pilot-link on Linux/Unix systems options. Please make sure you use the --help option to "./configure" to make sure you're enabling all of the options you wish to use. + You will also need to have your development environment set up, which + will require such tools as automake, autoconf, libtool, some system + headers, and others to be properly installed and configured on your + machine first. If you are running a current Linux or Unix system, + these common tools are probably packaged for you. + You also need to satisfy the dependencies of these libraries: + libusb, libbluetooth, libpopt and byacc + On Debian systems you can therefore execute: + $ sudo apt install build-essential automake libtool-bin + $ sudo apt install libusb-dev libbluetooth-dev libpopt-dev byacc + + If you are using a GIT version of pilot-link, e.g. from + https://github.com/desrod/pilot-link/, you will have to run + 'sh ./autogen.sh' first, from the top-level directory, which will + create and bootstrap the "./configure" script for you. On modern systems + you may alternatively use 'autoupdate' and 'autoreconf -i -s' to + create the "./configure" script. + If you have downloaded this code from the website, or as a tarball, simply unpack the tarball and run "./configure" in the top-level directory with your specific arguments. "./configure --help" will @@ -136,8 +154,8 @@ Building pilot-link on Linux/Unix systems $ make After the source builds, feel free to play around in the 'src' - subdirectory, CAREFULLY. 'dlpsh' and 'pilot-xfer' are probably the - most useful programs for you, and also the safest to use + subdirectory, CAREFULLY. 'pilot-dlpsh' and 'pilot-xfer' are probably + the most useful programs for you, and also the safest to use non-destructively. Once you have determined that pilot-link works and suits your needs @@ -157,16 +175,6 @@ Building pilot-link on Linux/Unix systems # make install - If you are using a CVS version of pilot-link, you will have to run - 'sh ./autogen.sh' instead, from the top-level directory, which will - create and bootstrap the "./configure" script for you. - - You will also need to have your development environment set up, which - will require such tools as automake, autoconf, libtool, some system - headers, and others to be properly installed and configured on your - machine first. If you are running a current Linux or Unix system, - these common tools are probably packaged for you. - Building pilot-link on OS/2 --------------------------- From abc616a63bf713ad94d0f6efbe1f2964940562d2 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Sun, 9 Mar 2025 16:59:33 +0100 Subject: [PATCH 05/31] Updated version to 0.13.1. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4be6ea8b..863a0a9e 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,7 @@ dnl Pilot Link Version dnl ****************************** PILOT_LINK_VERS=0 PILOT_LINK_MAJOR=13 -PILOT_LINK_MINOR=0 +PILOT_LINK_MINOR=1 PILOT_LINK_PATCH= AC_SUBST(PILOT_LINK_VERS) From d895072fd079aad5a6710bd0e8da43f2a624ed94 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Tue, 11 Mar 2025 16:13:26 +0100 Subject: [PATCH 06/31] Stripped white space at line end, corrected indentations. --- libpisock/dlp.c | 1914 +++++++++++++++++++++-------------------------- 1 file changed, 869 insertions(+), 1045 deletions(-) diff --git a/libpisock/dlp.c b/libpisock/dlp.c index d37bfd56..3132d8cc 100644 --- a/libpisock/dlp.c +++ b/libpisock/dlp.c @@ -1,4 +1,4 @@ -/* +/* * $Id$ * * dlp.c: Palm DLP protocol @@ -11,7 +11,7 @@ * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. - * + * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library @@ -45,7 +45,7 @@ #define DLP_RESPONSE_DATA(res, arg, offset) &res->argv[arg]->data[offset] #define get_date(ptr) (dlp_ptohdate((ptr))) -#define set_date(ptr,val) (dlp_htopdate((val),(ptr))) +#define set_date(ptr, val) (dlp_htopdate((val), (ptr))) #define RequireDLPVersion(sd,major,minor) \ if (pi_version(sd) < (((major)<<8) | (minor))) \ @@ -61,7 +61,7 @@ /* Define prototypes */ #ifdef PI_DEBUG static void record_dump (unsigned long recID, unsigned int recIndex, - int flags, int catID, const char *data, int data_len); + int flags, int catID, const char *data, int data_len); #endif char *dlp_errorlist[] = { @@ -89,8 +89,7 @@ char *dlp_errorlist[] = { "Bad argument size" }; -/* Look at "Error codes" in VFSMgr.h in the Palm SDK for their - implementation */ +/* Look at "Error codes" in VFSMgr.h in the Palm SDK for their implementation */ char * vfs_errorlist[] = { "No error", "Buffer Overflow", @@ -115,8 +114,7 @@ char * vfs_errorlist[] = { "Name truncated" }; -/* Look at "Error codes" in ExpansionMgr.h in the Palm SDK for their - implementation */ +/* Look at "Error codes" in ExpansionMgr.h in the Palm SDK for their implementation */ char * exp_errorlist[] = { "No error", "Unsupported Operation", @@ -143,17 +141,17 @@ static int dlp_version_minor = PI_DLP_VERSION_MINOR; #ifdef PI_DEBUG #define Trace(name) \ - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s\n", sd, #name)); - #ifdef __GNUC__ - #define TraceX(name,format,...) \ - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s " #format "\n", sd, #name, __VA_ARGS__)); - #else - #define TraceX(name,format,...) \ - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s\n", sd, #name)); - #endif + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s\n", sd, #name)); + #ifdef __GNUC__ + #define TraceX(name, format, ...) \ + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s " #format "\n", sd, #name, __VA_ARGS__)); + #else + #define TraceX(name, format, ...) \ + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s\n", sd, #name)); + #endif #else #define Trace(name) - #define TraceX(name,format,...) + #define TraceX(name, format, ...) #endif #ifdef PI_DEBUG @@ -161,18 +159,18 @@ static void record_dump (unsigned long recID, unsigned int recIndex, int flags, int catID, const char *data, int data_len) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " ID: 0x%8.8lX, Index: %u, Category: %d\n" - " Flags:%s%s%s%s%s%s (0x%2.2X), and %d bytes:\n", - (unsigned long) recID, - recIndex, - catID, - (flags & dlpRecAttrDeleted) ? " Deleted" : "", - (flags & dlpRecAttrDirty) ? " Dirty" : "", - (flags & dlpRecAttrBusy) ? " Busy" : "", - (flags & dlpRecAttrSecret) ? " Secret" : "", - (flags & dlpRecAttrArchived) ? " Archive" : "", - (!flags) ? " None" : "", - flags, data_len)); + " ID: 0x%8.8lX, Index: %u, Category: %d\n" + " Flags:%s%s%s%s%s%s (0x%2.2X), and %d bytes:\n", + (unsigned long) recID, + recIndex, + catID, + (flags & dlpRecAttrDeleted) ? " Deleted" : "", + (flags & dlpRecAttrDirty) ? " Dirty" : "", + (flags & dlpRecAttrBusy) ? " Busy" : "", + (flags & dlpRecAttrSecret) ? " Secret" : "", + (flags & dlpRecAttrArchived) ? " Archive" : "", + (!flags) ? " None" : "", + flags, data_len)); pi_dumpdata(data, (size_t)data_len); } #endif @@ -195,15 +193,15 @@ dlp_set_protocol_version(int major, int minor) * Returns: char* to error text string * ***************************************************************************/ -char +char *dlp_strerror(int error) { if (error < 0) error = -error; - - if ((unsigned int) error >= (sizeof(dlp_errorlist)/(sizeof(char *)))) + + if ((unsigned int) error >= (sizeof(dlp_errorlist) / (sizeof(char *)))) return "Unknown error"; - + return dlp_errorlist[error]; } @@ -220,10 +218,10 @@ char * ***************************************************************************/ struct dlpArg -*dlp_arg_new (int argID, size_t len) +*dlp_arg_new (int argID, size_t len) { struct dlpArg *arg; - + arg = (struct dlpArg *)malloc(sizeof (struct dlpArg)); if (arg != NULL) { @@ -237,8 +235,8 @@ struct dlpArg arg = NULL; } } - } - + } + return arg; } @@ -284,13 +282,13 @@ dlp_arg_len (int argc, struct dlpArg **argv) for (i = 0; i < argc; i++) { struct dlpArg *arg = argv[i]; - + /* FIXME: shapiro: should these be < or <= ??? */ if (arg->len < PI_DLP_ARG_TINY_LEN && - (arg->id_ & (PI_DLP_ARG_FLAG_SHORT | PI_DLP_ARG_FLAG_LONG)) == 0) + (arg->id_ & (PI_DLP_ARG_FLAG_SHORT | PI_DLP_ARG_FLAG_LONG)) == 0) len += 2; else if (arg->len < PI_DLP_ARG_SHORT_LEN && - (arg->id_ & PI_DLP_ARG_FLAG_LONG) == 0) + (arg->id_ & PI_DLP_ARG_FLAG_LONG) == 0) len += 4; else len += 6; @@ -306,7 +304,7 @@ dlp_arg_len (int argc, struct dlpArg **argv) * * Function: dlp_request_new * - * Summary: creates a new dlpRequest instance + * Summary: creates a new dlpRequest instance * * Parameters: dlpFunction command, number of dlpArgs, lengths of dlpArgs * data member @@ -315,13 +313,12 @@ dlp_arg_len (int argc, struct dlpArg **argv) * ***************************************************************************/ struct dlpRequest* -dlp_request_new (enum dlpFunctions cmd, int argc, ...) +dlp_request_new (enum dlpFunctions cmd, int argc, ...) { struct dlpRequest *req; va_list ap; - int i, - j; - + int i, j; + req = (struct dlpRequest *)malloc (sizeof (struct dlpRequest)); if (req != NULL) { @@ -336,7 +333,7 @@ dlp_request_new (enum dlpFunctions cmd, int argc, ...) return NULL; } } - + va_start (ap, argc); for (i = 0; i < argc; i++) { size_t len; @@ -355,8 +352,8 @@ dlp_request_new (enum dlpFunctions cmd, int argc, ...) } va_end (ap); } - - return req; + + return req; } @@ -377,9 +374,8 @@ dlp_request_new_with_argid (enum dlpFunctions cmd, int argid, int argc, ...) { struct dlpRequest *req; va_list ap; - int i, - j; - + int i, j; + req = (struct dlpRequest *) malloc (sizeof (struct dlpRequest)); if (req != NULL) { @@ -400,7 +396,7 @@ dlp_request_new_with_argid (enum dlpFunctions cmd, int argid, int argc, ...) size_t len; len = va_arg (ap, size_t); - req->argv[i] = dlp_arg_new (argid + i, len); + req->argv[i] = dlp_arg_new(argid + i, len); if (req->argv[i] == NULL) { for (j = 0; j < i; j++) dlp_arg_free(req->argv[j]); @@ -421,7 +417,7 @@ dlp_request_new_with_argid (enum dlpFunctions cmd, int argid, int argc, ...) * * Function: dlp_response_new * - * Summary: creates a new dlpResponse instance + * Summary: creates a new dlpResponse instance * * Parameters: dlpFunction command, number of dlpArg instances * @@ -429,10 +425,10 @@ dlp_request_new_with_argid (enum dlpFunctions cmd, int argid, int argc, ...) * ***************************************************************************/ struct dlpResponse -*dlp_response_new (enum dlpFunctions cmd, int argc) +*dlp_response_new (enum dlpFunctions cmd, int argc) { struct dlpResponse *res; - + res = (struct dlpResponse *) malloc (sizeof (struct dlpResponse)); if (res != NULL) { @@ -454,7 +450,7 @@ struct dlpResponse memset(res->argv, 0, sizeof (struct dlpArg *) * argc); } } - + return res; } @@ -480,7 +476,7 @@ dlp_response_read (struct dlpResponse **res, int sd) ssize_t bytes; size_t len; pi_buffer_t *dlp_buf; - + dlp_buf = pi_buffer_new (DLP_BUF_SIZE); if (dlp_buf == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -494,21 +490,21 @@ dlp_response_read (struct dlpResponse **res, int sd) /* packet is probably incomplete */ #ifdef DEBUG LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "dlp_response_read: response too short (%d bytes)\n", - bytes)); + "dlp_response_read: response too short (%d bytes)\n", + bytes)); if (bytes) pi_dumpdata(dlp_buf->data, (size_t)dlp_buf->used); #endif return pi_set_error(sd, PI_ERR_DLP_COMMAND); } - response = dlp_response_new ((enum dlpFunctions)(dlp_buf->data[0] & 0x7f), dlp_buf->data[1]); + response = dlp_response_new((enum dlpFunctions)(dlp_buf->data[0] & 0x7f), dlp_buf->data[1]); *res = response; /* note that in case an error occurs, we do not deallocate the response since callers already do it under all circumstances */ if (response == NULL) { - pi_buffer_free (dlp_buf); + pi_buffer_free(dlp_buf); return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); } @@ -530,20 +526,20 @@ dlp_response_read (struct dlpResponse **res, int sd) contents. We need to report that the data is too large to be transferred. */ - pi_buffer_free (dlp_buf); + pi_buffer_free(dlp_buf); return pi_set_error(sd, PI_ERR_DLP_DATASIZE); } - len = get_long (&buf[2]); + len = get_long(&buf[2]); buf += 6; } else if (get_byte(buf) & PI_DLP_ARG_FLAG_SHORT) { - len = get_short (&buf[2]); + len = get_short(&buf[2]); buf += 4; } else { argid = get_byte(buf); len = get_byte(&buf[1]); buf += 2; } - + response->argv[i] = dlp_arg_new (argid, len); if (response->argv[i] == NULL) { pi_buffer_free (dlp_buf); @@ -553,7 +549,7 @@ dlp_response_read (struct dlpResponse **res, int sd) buf += len; } - pi_buffer_free (dlp_buf); + pi_buffer_free(dlp_buf); return response->argc ? response->argv[0]->len : 0; } @@ -576,35 +572,35 @@ dlp_request_write (struct dlpRequest *req, int sd) unsigned char *exec_buf, *buf; int i; size_t len; - - len = dlp_arg_len (req->argc, req->argv) + 2; + + len = dlp_arg_len(req->argc, req->argv) + 2; exec_buf = (unsigned char *) malloc (sizeof (unsigned char) * len); if (exec_buf == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_byte (&exec_buf[PI_DLP_OFFSET_CMD], req->cmd); - set_byte (&exec_buf[PI_DLP_OFFSET_ARGC], req->argc); + set_byte(&exec_buf[PI_DLP_OFFSET_CMD], req->cmd); + set_byte(&exec_buf[PI_DLP_OFFSET_ARGC], req->argc); - buf = &exec_buf[PI_DLP_OFFSET_ARGV]; + buf = &exec_buf[PI_DLP_OFFSET_ARGV]; for (i = 0; i < req->argc; i++) { struct dlpArg *arg = req->argv[i]; short argid = arg->id_; - + if (arg->len < PI_DLP_ARG_TINY_LEN && - (argid & (PI_DLP_ARG_FLAG_SHORT | PI_DLP_ARG_FLAG_LONG)) == 0) { + (argid & (PI_DLP_ARG_FLAG_SHORT | PI_DLP_ARG_FLAG_LONG)) == 0) { set_byte(&buf[0], argid | PI_DLP_ARG_FLAG_TINY); set_byte(&buf[1], arg->len); memcpy(&buf[2], arg->data, arg->len); - buf += arg->len + 2; + buf += arg->len + 2; } else if (arg->len < PI_DLP_ARG_SHORT_LEN && - (argid & PI_DLP_ARG_FLAG_LONG) == 0) { + (argid & PI_DLP_ARG_FLAG_LONG) == 0) { set_byte(&buf[0], argid | PI_DLP_ARG_FLAG_SHORT); set_byte(&buf[1], 0); set_short(&buf[2], arg->len); memcpy (&buf[4], arg->data, arg->len); - buf += arg->len + 4; + buf += arg->len + 4; } else { set_byte (&buf[0], argid | PI_DLP_ARG_FLAG_LONG); set_byte(&buf[1], 0); @@ -672,13 +668,13 @@ dlp_request_free (struct dlpRequest *req) * ***************************************************************************/ void -dlp_response_free (struct dlpResponse *res) +dlp_response_free (struct dlpResponse *res) { int i; if (res == NULL) return; - + if (res->argv != NULL) { for (i = 0; i < res->argc; i++) { if (res->argv[i] != NULL) @@ -687,7 +683,7 @@ dlp_response_free (struct dlpResponse *res) free (res->argv); } - free (res); + free (res); } @@ -710,16 +706,16 @@ dlp_exec(int sd, struct dlpRequest *req, struct dlpResponse **res) if ((result = dlp_request_write (req, sd)) < req->argc) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP sd:%i dlp_request_write returned %i\n", - sd, result)); + "DLP sd:%i dlp_request_write returned %i\n", + sd, result)); errno = -EIO; return result; } if ((bytes = dlp_response_read (res, sd)) < 0) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP sd:%i dlp_response_read returned %i\n", - sd, bytes)); + "DLP sd:%i dlp_response_read returned %i\n", + sd, bytes)); errno = -EIO; return bytes; } @@ -737,8 +733,8 @@ dlp_exec(int sd, struct dlpRequest *req, struct dlpResponse **res) errno = -ENOMSG; LOG((PI_DBG_DLP, PI_DBG_LVL_DEBUG, - "dlp_exec: result CMD 0x%02x doesn't match requested cmd 0x%02x\n", - (unsigned)((*res)->cmd), (unsigned)req->cmd)); + "dlp_exec: result CMD 0x%02x doesn't match requested cmd 0x%02x\n", + (unsigned)((*res)->cmd), (unsigned)req->cmd)); return pi_set_error(sd, PI_ERR_DLP_COMMAND); } @@ -754,11 +750,11 @@ dlp_exec(int sd, struct dlpRequest *req, struct dlpResponse **res) return bytes; } -/* These conversion functions are strictly for use within the DLP layer. +/* These conversion functions are strictly for use within the DLP layer. This particular date/time format does not occur anywhere else within the Palm or its communications. */ -/* Notice: +/* Notice: The dates in the DLP protocol are expressed as absolute dates/times, without any time zone information. For example if a file was created on the device at 19:32:48, the time members will be 19, 32 and 48. @@ -773,11 +769,11 @@ dlp_ptohdate(const unsigned char *data) struct tm t; /* Seems like year comes back as all zeros if the date is "empty" - (but other fields can vary). And mktime() chokes on 1900 B.C. + (but other fields can vary). And mktime() chokes on 1900 B.C. (result of 0 minus 1900), returning -1, which the higher level code can't deal with (passes it straight on to utime(), which simply leaves the file's timestamp "as-is"). - + So, since year 0 appears to mean "no date", we'll return an odd number that works out to precisely one day before the start of the Palm's clock (thus little chance of being run into by any @@ -789,18 +785,17 @@ dlp_ptohdate(const unsigned char *data) earlier than it was supposed to report. You can verify this with the following: - perl -e '$date=localtime(0x83D8FE00); print $date,"\n"' + perl -e '$date=localtime(0x83D8FE00); print $date,"\n"' - return (time_t) 0x83D8FE00; // Wed Dec 30 16:00:00 1903 GMT + return (time_t) 0x83D8FE00; // Wed Dec 30 16:00:00 1903 GMT - Here are others, depending on what your system requirements are: + Here are others, depending on what your system requirements are: - return (time_t) 0x83D96E80; // Thu Dec 31 00:00:00 1903 GMT - return (time_t) 0x00007080; // Thu Jan 1 00:00:00 1970 GMT + return (time_t) 0x83D96E80; // Thu Dec 31 00:00:00 1903 GMT + return (time_t) 0x00007080; // Thu Jan 1 00:00:00 1970 GMT - Palm's own Conduit Development Kit references using 1/1/1904, - so that's what we'll use here until something else breaks - it. + Palm's own Conduit Development Kit references using 1/1/1904, + so that's what we'll use here until something else breaks it. */ return (time_t) 0x83DAC000; /* Fri Jan 1 00:00:00 1904 GMT */ @@ -821,18 +816,18 @@ dlp_ptohdate(const unsigned char *data) void dlp_htopdate(time_t time_interval, unsigned char *data) { /* @+ptrnegate@ */ - int year; + int year; const struct tm *t; /* Fri Jan 1 00:00:00 1904 GMT */ - time_t palm_epoch = 0x83DAC000; + time_t palm_epoch = 0x83DAC000; if (time_interval == palm_epoch) { memset(data, 0, 8); return; } - t = localtime(&time_interval); + t = localtime(&time_interval); ASSERT(t != NULL); year = t->tm_year + 1900; @@ -850,7 +845,7 @@ dlp_htopdate(time_t time_interval, unsigned char *data) int dlp_GetSysDateTime(int sd, time_t *t) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -860,37 +855,37 @@ dlp_GetSysDateTime(int sd, time_t *t) req = dlp_request_new(dlpFuncGetSysDateTime, 0); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { *t = dlp_ptohdate((const unsigned char *)DLP_RESPONSE_DATA (res, 0, 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP GetSysDateTime %s", ctime(t))); + "DLP GetSysDateTime %s", ctime(t))); } dlp_response_free(res); - + return result; } int dlp_SetSysDateTime(int sd, time_t t) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_SetSysDateTime,"time=0x%08lx",t); + TraceX(dlp_SetSysDateTime, "time=0x%08lx", t); pi_reset_errors(sd); req = dlp_request_new(dlpFuncSetSysDateTime, 1, 8); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + dlp_htopdate(t, (unsigned char *)DLP_REQUEST_DATA(req, 0, 0)); result = dlp_exec(sd, req, &res); @@ -904,12 +899,12 @@ dlp_SetSysDateTime(int sd, time_t t) int dlp_ReadStorageInfo(int sd, int cardno, struct CardInfo *c) { - int result; + int result; size_t len1, len2; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadStorageInfo,"cardno=%d",cardno); + TraceX(dlp_ReadStorageInfo, "cardno=%d", cardno); pi_reset_errors(sd); req = dlp_request_new(dlpFuncReadStorageInfo, 1, 2); @@ -924,11 +919,11 @@ dlp_ReadStorageInfo(int sd, int cardno, struct CardInfo *c) dlp_request_free(req); if (result > 0) { - c->more = get_byte(DLP_RESPONSE_DATA(res, 0, 0)) - || (get_byte(DLP_RESPONSE_DATA(res, 0, 3)) > 1); + c->more = get_byte(DLP_RESPONSE_DATA(res, 0, 0)) + || (get_byte(DLP_RESPONSE_DATA(res, 0, 3)) > 1); c->card = get_byte(DLP_RESPONSE_DATA(res, 0, 5)); c->version = get_byte(DLP_RESPONSE_DATA(res, 0, 6)); - c->creation = get_date((const unsigned char *)DLP_RESPONSE_DATA(res, 0, 8)); + c->creation = get_date((const unsigned char *)DLP_RESPONSE_DATA(res, 0, 8)); c->romSize = get_long(DLP_RESPONSE_DATA(res, 0, 16)); c->ramSize = get_long(DLP_RESPONSE_DATA(res, 0, 20)); c->ramFree = get_long(DLP_RESPONSE_DATA(res, 0, 24)); @@ -938,36 +933,35 @@ dlp_ReadStorageInfo(int sd, int cardno, struct CardInfo *c) c->name[len1] = '\0'; len2 = get_byte(DLP_RESPONSE_DATA(res, 0, 29)); - memcpy(c->manufacturer, DLP_RESPONSE_DATA(res, 0, 30 + len1), - len2); + memcpy(c->manufacturer, DLP_RESPONSE_DATA(res, 0, 30 + len1), len2); c->manufacturer[len2] = '\0'; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP Read Cardno: %d, Card Version: %d, Creation time: %s", - c->card, c->version, ctime(&c->creation))); + "DLP Read Cardno: %d, Card Version: %d, Creation time: %s", + c->card, c->version, ctime(&c->creation))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Total ROM: %lu, Total RAM: %lu, Free RAM: %lu\n", - c->romSize, c->ramSize, c->ramFree)); + " Total ROM: %lu, Total RAM: %lu, Free RAM: %lu\n", + c->romSize, c->ramSize, c->ramFree)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Card name: '%s'\n", c->name)); + " Card name: '%s'\n", c->name)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Manufacturer name: '%s'\n", c->manufacturer)); + " Manufacturer name: '%s'\n", c->manufacturer)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " More: %s\n", c->more ? "Yes" : "No")); + " More: %s\n", c->more ? "Yes" : "No")); } dlp_response_free (res); - + return result; } int dlp_ReadSysInfo(int sd, struct SysInfo *s) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + Trace(dlp_ReadSysInfo); pi_reset_errors(sd); @@ -977,7 +971,7 @@ dlp_ReadSysInfo(int sd, struct SysInfo *s) set_short (DLP_REQUEST_DATA (req, 0, 0), dlp_version_major); set_short (DLP_REQUEST_DATA (req, 0, 2), dlp_version_minor); - + result = dlp_exec(sd, req, &res); dlp_request_free (req); @@ -987,23 +981,22 @@ dlp_ReadSysInfo(int sd, struct SysInfo *s) s->locale = get_long (DLP_RESPONSE_DATA (res, 0, 4)); /* The 8th byte is a filler byte */ s->prodIDLength = get_byte (DLP_RESPONSE_DATA (res, 0, 9)); - memcpy(s->prodID, DLP_RESPONSE_DATA(res, 0, 10), - s->prodIDLength); + memcpy(s->prodID, DLP_RESPONSE_DATA(res, 0, 10), s->prodIDLength); if (res->argc > 1) { /* response added in DLP 1.2 */ pi_socket_t *ps = find_pi_socket(sd); s->dlpMajorVersion = - get_short (DLP_RESPONSE_DATA (res, 1, 0)); + get_short (DLP_RESPONSE_DATA (res, 1, 0)); s->dlpMinorVersion = - get_short (DLP_RESPONSE_DATA (res, 1, 2)); + get_short (DLP_RESPONSE_DATA (res, 1, 2)); s->compatMajorVersion = - get_short (DLP_RESPONSE_DATA (res, 1, 4)); + get_short (DLP_RESPONSE_DATA (res, 1, 4)); s->compatMinorVersion = - get_short (DLP_RESPONSE_DATA (res, 1, 6)); + get_short (DLP_RESPONSE_DATA (res, 1, 6)); s->maxRecSize = - get_long (DLP_RESPONSE_DATA (res, 1, 8)); + get_long (DLP_RESPONSE_DATA (res, 1, 8)); /* update socket information */ ps->dlpversion = (s->dlpMajorVersion << 8) | s->dlpMinorVersion; @@ -1017,37 +1010,35 @@ dlp_ReadSysInfo(int sd, struct SysInfo *s) } LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadSysInfo ROM Ver=0x%8.8lX Locale=0x%8.8lX\n", - s->romVersion, s->locale)); + "DLP ReadSysInfo ROM Ver=0x%8.8lX Locale=0x%8.8lX\n", + s->romVersion, s->locale)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Product ID=0x%8.8lX\n", s->prodID)); + " Product ID=0x%8.8lX\n", s->prodID)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " DLP Major Ver=0x%4.4lX DLP Minor Ver=0x%4.4lX\n", - s->dlpMajorVersion, s->dlpMinorVersion)); + " DLP Major Ver=0x%4.4lX DLP Minor Ver=0x%4.4lX\n", + s->dlpMajorVersion, s->dlpMinorVersion)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Compat Major Ver=0x%4.4lX Compat Minor Vers=0x%4.4lX\n", - s->compatMajorVersion, s->compatMinorVersion)); + " Compat Major Ver=0x%4.4lX Compat Minor Vers=0x%4.4lX\n", + s->compatMajorVersion, s->compatMinorVersion)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Max Rec Size=%ld\n", s->maxRecSize)); + " Max Rec Size=%ld\n", s->maxRecSize)); } dlp_response_free (res); - + return result; } int dlp_ReadDBList(int sd, int cardno, int flags, int start, pi_buffer_t *info) { - int result, - i, - count; + int result, i, count; struct dlpRequest *req; struct dlpResponse *res; unsigned char *p; struct DBInfo db; - TraceX(dlp_ReadDBList,"cardno=%d flags=0x%04x start=%d",cardno,flags,start); + TraceX(dlp_ReadDBList, "cardno=%d flags=0x%04x start=%d", cardno, flags, start); pi_reset_errors(sd); req = dlp_request_new (dlpFuncReadDBList, 1, 4); @@ -1055,7 +1046,7 @@ dlp_ReadDBList(int sd, int cardno, int flags, int start, pi_buffer_t *info) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); pi_buffer_clear (info); - + /* 'multiple' only supported in DLP 1.2 and above */ if (pi_version(sd) < 0x0102) flags &= ~dlpDBListMultiple; @@ -1067,7 +1058,7 @@ dlp_ReadDBList(int sd, int cardno, int flags, int start, pi_buffer_t *info) result = dlp_exec (sd, req, &res); dlp_request_free(req); - + if (result > 0) { p = (unsigned char *)DLP_RESPONSE_DATA(res, 0, 0); db.more = get_byte(p + 2); @@ -1080,47 +1071,45 @@ dlp_ReadDBList(int sd, int cardno, int flags, int start, pi_buffer_t *info) else db.miscFlags = 0; - db.flags = get_short(p + 6); - db.type = get_long(p + 8); + db.flags = get_short(p + 6); + db.type = get_long(p + 8); db.creator = get_long(p + 12); db.version = get_short(p + 16); db.modnum = get_long(p + 18); db.createDate = get_date(p + 22); db.modifyDate = get_date(p + 30); db.backupDate = get_date(p + 38); - db.index = get_short(p + 46); + db.index = get_short(p + 46); memset(db.name, 0, sizeof(db.name)); strncpy(db.name, (char *)(p + 48), 32); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadDBList Name: '%s', Version: %d, More: %s\n", - db.name, db.version, db.more ? "Yes" : "No")); + "DLP ReadDBList Name: '%s', Version: %d, More: %s\n", + db.name, db.version, db.more ? "Yes" : "No")); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Creator: '%s'", printlong(db.creator))); + " Creator: '%s'", printlong(db.creator))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Type: '%s' Flags: %s%s%s%s%s%s%s%s%s%s", - printlong(db.type), - (db.flags & dlpDBFlagResource) ? "Resource " : "", - (db.flags & dlpDBFlagReadOnly) ? "ReadOnly " : "", - (db.flags & dlpDBFlagAppInfoDirty) ? - "AppInfoDirty " : "", - (db.flags & dlpDBFlagBackup) ? "Backup " : "", - (db.flags & dlpDBFlagReset) ? "Reset " : "", - (db.flags & dlpDBFlagNewer) ? "Newer " : "", - (db.flags & dlpDBFlagCopyPrevention) ? - "CopyPrevention " : "", - (db.flags & dlpDBFlagStream) ? "Stream " : "", - (db.flags & dlpDBFlagOpen) ? "Open " : "", - (!db.flags) ? "None" : "")); + " Type: '%s' Flags: %s%s%s%s%s%s%s%s%s%s", + printlong(db.type), + (db.flags & dlpDBFlagResource) ? "Resource " : "", + (db.flags & dlpDBFlagReadOnly) ? "ReadOnly " : "", + (db.flags & dlpDBFlagAppInfoDirty) ? "AppInfoDirty " : "", + (db.flags & dlpDBFlagBackup) ? "Backup " : "", + (db.flags & dlpDBFlagReset) ? "Reset " : "", + (db.flags & dlpDBFlagNewer) ? "Newer " : "", + (db.flags & dlpDBFlagCopyPrevention) ? "CopyPrevention " : "", + (db.flags & dlpDBFlagStream) ? "Stream " : "", + (db.flags & dlpDBFlagOpen) ? "Open " : "", + (!db.flags) ? "None" : "")); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, " (0x%2.2X)\n", db.flags)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Modnum: %ld, Index: %d, Creation date: 0x%08lx, %s", - db.modnum, db.index, db.createDate, ctime(&db.createDate))); + " Modnum: %ld, Index: %d, Creation date: 0x%08lx, %s", + db.modnum, db.index, db.createDate, ctime(&db.createDate))); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, + " Modification date: 0x%08lx, %s", db.modifyDate, ctime(&db.modifyDate))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Modification date: 0x%08lx, %s", db.modifyDate, ctime(&db.modifyDate))); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Backup date: 0x%08lx, %s", db.backupDate, ctime(&db.backupDate))); + " Backup date: 0x%08lx, %s", db.backupDate, ctime(&db.backupDate))); if (pi_buffer_append(info, &db, sizeof(db)) == NULL) { result = pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -1141,14 +1130,12 @@ dlp_ReadDBList(int sd, int cardno, int flags, int start, pi_buffer_t *info) int dlp_FindDBInfo(int sd, int cardno, int start, const char *dbname, - unsigned long type, unsigned long creator, - struct DBInfo *info) + unsigned long type, unsigned long creator, struct DBInfo *info) { - int i, - j; + int i, j; pi_buffer_t *buf; - TraceX(dlp_FindDBInfo,"cardno=%d start=%d",cardno,start); + TraceX(dlp_FindDBInfo, "cardno=%d start=%d", cardno, start); pi_reset_errors(sd); buf = pi_buffer_new (sizeof (struct DBInfo)); @@ -1161,8 +1148,8 @@ dlp_FindDBInfo(int sd, int cardno, int start, const char *dbname, for (j=0; j < (int)(buf->used / sizeof(struct DBInfo)); j++) { memcpy (info, buf->data + j * sizeof(struct DBInfo), sizeof(struct DBInfo)); if ((!dbname || strcmp(info->name, dbname) == 0) - && (!type || info->type == type) - && (!creator || info->creator == creator)) + && (!type || info->type == type) + && (!creator || info->creator == creator)) goto found; i = info->index + 1; } @@ -1175,8 +1162,8 @@ dlp_FindDBInfo(int sd, int cardno, int start, const char *dbname, for (j=0; j < (int)(buf->used / sizeof(struct DBInfo)); j++) { memcpy (info, buf->data + j * sizeof(struct DBInfo), sizeof(struct DBInfo)); if ((!dbname || strcmp(info->name, dbname) == 0) - && (!type || info->type == type) - && (!creator || info->creator == creator)) + && (!type || info->type == type) + && (!creator || info->creator == creator)) { info->index |= 0x1000; goto found; @@ -1206,7 +1193,7 @@ dlp_FindDBInfo(int sd, int cardno, int start, const char *dbname, ***************************************************************************/ static void dlp_decode_finddb_response(struct dlpResponse *res, int *cardno, unsigned long *localid, - int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) + int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) { int arg, argid; for (arg = 0; arg < res->argc; arg++) { @@ -1221,88 +1208,62 @@ dlp_decode_finddb_response(struct dlpResponse *res, int *cardno, unsigned long * if (info) { info->more = 0; - info->miscFlags = - get_byte(DLP_RESPONSE_DATA(res, arg, 11)); - info->flags = - get_short(DLP_RESPONSE_DATA(res, arg, 12)); - info->type = - get_long(DLP_RESPONSE_DATA(res, arg, 14)); - info->creator = - get_long(DLP_RESPONSE_DATA(res, arg, 18)); - info->version = - get_short(DLP_RESPONSE_DATA(res, arg, 22)); - info->modnum = - get_long(DLP_RESPONSE_DATA(res, arg, 24)); + info->miscFlags = get_byte(DLP_RESPONSE_DATA(res, arg, 11)); + info->flags = get_short(DLP_RESPONSE_DATA(res, arg, 12)); + info->type = get_long(DLP_RESPONSE_DATA(res, arg, 14)); + info->creator = get_long(DLP_RESPONSE_DATA(res, arg, 18)); + info->version = get_short(DLP_RESPONSE_DATA(res, arg, 22)); + info->modnum = get_long(DLP_RESPONSE_DATA(res, arg, 24)); info->createDate = - get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 28)); + get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 28)); info->modifyDate = - get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 36)); + get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 36)); info->backupDate = - get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 44)); - info->index = - get_short(DLP_RESPONSE_DATA(res, arg, 52)); + get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 44)); + info->index = get_short(DLP_RESPONSE_DATA(res, arg, 52)); strncpy(info->name, DLP_RESPONSE_DATA(res, arg, 54), 32); info->name[32] = '\0'; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP FindDB Name: '%s', " - "Version: %d, More: %s\n", - info->name, info->version, - info->more ? "Yes" : "No")); + "DLP FindDB Name: '%s', " + "Version: %d, More: %s\n", + info->name, info->version, + info->more ? "Yes" : "No")); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Creator: '%s'", printlong(info->creator))); + " Creator: '%s'", printlong(info->creator))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Type: '%s' Flags: %s%s%s%s%s%s%s%s%s%s", - printlong(info->type), - (info->flags & dlpDBFlagResource) ? - "Resource " : "", - (info->flags & dlpDBFlagReadOnly) ? - "ReadOnly " : "", - (info->flags & dlpDBFlagAppInfoDirty) ? - "AppInfoDirty " : "", - (info->flags & dlpDBFlagBackup) ? - "Backup " : "", - (info->flags & dlpDBFlagReset) ? - "Reset " : "", - (info->flags & dlpDBFlagNewer) ? - "Newer " : "", - (info->flags & dlpDBFlagCopyPrevention) ? - "CopyPrevention " : "", - (info->flags & dlpDBFlagStream) ? - "Stream " : "", - (info->flags & dlpDBFlagOpen) ? - "Open " : "", - (!info->flags) ? "None" : "")); + " Type: '%s' Flags: %s%s%s%s%s%s%s%s%s%s", + printlong(info->type), + (info->flags & dlpDBFlagResource) ? "Resource " : "", + (info->flags & dlpDBFlagReadOnly) ? "ReadOnly " : "", + (info->flags & dlpDBFlagAppInfoDirty) ? "AppInfoDirty " : "", + (info->flags & dlpDBFlagBackup) ? "Backup " : "", + (info->flags & dlpDBFlagReset) ? "Reset " : "", + (info->flags & dlpDBFlagNewer) ? "Newer " : "", + (info->flags & dlpDBFlagCopyPrevention) ? "CopyPrevention " : "", + (info->flags & dlpDBFlagStream) ? "Stream " : "", + (info->flags & dlpDBFlagOpen) ? "Open " : "", + (!info->flags) ? "None" : "")); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " (0x%2.2X)\n", info->flags)); + " (0x%2.2X)\n", info->flags)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Modnum: %ld, Index: %d, " - "Creation date: %s", - info->modnum, info->index, - ctime(&info->createDate))); + " Modnum: %ld, Index: %d, Creation date: %s", + info->modnum, info->index, ctime(&info->createDate))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Modification date: %s", - ctime(&info->modifyDate))); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Backup date: %s", - ctime(&info->backupDate))); + " Modification date: %s", ctime(&info->modifyDate))); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, + " Backup date: %s", ctime(&info->backupDate))); } } else if (argid == 1) { if (size) { - size->numRecords = - get_long(DLP_RESPONSE_DATA(res, arg, 0)); - size->totalBytes = - get_long(DLP_RESPONSE_DATA(res, arg, 4)); - size->dataBytes = - get_long(DLP_RESPONSE_DATA(res, arg, 8)); - size->appBlockSize = - get_long(DLP_RESPONSE_DATA(res, arg, 12)); - size->sortBlockSize = - get_long(DLP_RESPONSE_DATA(res, arg, 16)); - size->maxRecSize = - get_long(DLP_RESPONSE_DATA(res, arg, 20)); + size->numRecords = get_long(DLP_RESPONSE_DATA(res, arg, 0)); + size->totalBytes = get_long(DLP_RESPONSE_DATA(res, arg, 4)); + size->dataBytes = get_long(DLP_RESPONSE_DATA(res, arg, 8)); + size->appBlockSize = get_long(DLP_RESPONSE_DATA(res, arg, 12)); + size->sortBlockSize = get_long(DLP_RESPONSE_DATA(res, arg, 16)); + size->maxRecSize = get_long(DLP_RESPONSE_DATA(res, arg, 20)); } } } @@ -1310,14 +1271,14 @@ dlp_decode_finddb_response(struct dlpResponse *res, int *cardno, unsigned long * int dlp_FindDBByName (int sd, int cardno, PI_CONST char *name, unsigned long *localid, - int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) + int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; int flags = 0; - - TraceX(dlp_FindDBByName,"cardno=%d name='%s'",cardno,name); + + TraceX(dlp_FindDBByName, "cardno=%d name='%s'", cardno, name); pi_reset_errors(sd); if (pi_version(sd) < 0x0102) @@ -1337,26 +1298,26 @@ dlp_FindDBByName (int sd, int cardno, PI_CONST char *name, unsigned long *locali strcpy(DLP_REQUEST_DATA(req, 0, 2), name); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); if (result > 0) dlp_decode_finddb_response(res, NULL, localid, dbhandle, info, size); - + dlp_response_free(res); - - return result; + + return result; } int dlp_FindDBByOpenHandle (int sd, int dbhandle, int *cardno, - unsigned long *localid, struct DBInfo *info, struct DBSizeInfo *size) + unsigned long *localid, struct DBInfo *info, struct DBSizeInfo *size) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; int flags = 0; - + Trace(dlp_FindDBByOpenHandle); pi_reset_errors(sd); @@ -1382,27 +1343,27 @@ dlp_FindDBByOpenHandle (int sd, int dbhandle, int *cardno, result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) dlp_decode_finddb_response(res, cardno, localid, NULL, info, size); - + dlp_response_free(res); - - return result; + + return result; } int dlp_FindDBByTypeCreator (int sd, unsigned long type, unsigned long creator, - int start, int latest, int *cardno, unsigned long *localid, - int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) + int start, int latest, int *cardno, unsigned long *localid, + int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; int flags = 0, search_flags = 0; - - TraceX(dlp_FindDBByTypeCreator,"type='%4.4s' creator='%4.4s' start=%d latest=%d", - (const char *)&type,(const char *)&creator,start,latest); + + TraceX(dlp_FindDBByTypeCreator, "type='%4.4s' creator='%4.4s' start=%d latest=%d", + (const char *)&type, (const char *)&creator, start, latest); pi_reset_errors(sd); if (pi_version(sd) < 0x0102) @@ -1415,40 +1376,38 @@ dlp_FindDBByTypeCreator (int sd, unsigned long type, unsigned long creator, if (cardno || localid || dbhandle || info) flags |= dlpFindDBOptFlagGetAttributes; if (size) - flags |= (dlpFindDBOptFlagGetSize | - dlpFindDBOptFlagMaxRecSize); - + flags |= (dlpFindDBOptFlagGetSize | dlpFindDBOptFlagMaxRecSize); if (start) search_flags |= dlpFindDBSrchFlagNewSearch; if (latest) search_flags |= dlpFindDBSrchFlagOnlyLatest; - + set_byte(DLP_REQUEST_DATA(req, 0, 0), flags); set_byte(DLP_REQUEST_DATA(req, 0, 1), search_flags); set_long(DLP_REQUEST_DATA(req, 0, 2), type); set_long(DLP_REQUEST_DATA(req, 0, 6), creator); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); - + if (result > 0) dlp_decode_finddb_response(res, cardno, localid, dbhandle, info, size); - + dlp_response_free(res); - - return result; + + return result; } int dlp_OpenDB(int sd, int cardno, int mode, PI_CONST char *name, int *dbhandle) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_OpenDB,"'%s'",name); + TraceX(dlp_ OpenDB, "'%s'", name); pi_reset_errors(sd); req = dlp_request_new(dlpFuncOpenDB, 1, 2 + strlen(name) + 1); @@ -1460,29 +1419,28 @@ dlp_OpenDB(int sd, int cardno, int mode, PI_CONST char *name, int *dbhandle) strcpy(DLP_REQUEST_DATA(req, 0, 2), name); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); - + if (result > 0) { *dbhandle = get_byte(DLP_RESPONSE_DATA(res, 0, 0)); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "-> dlp_OpenDB dbhandle=%d\n", *dbhandle)); + "-> dlp_OpenDB dbhandle=%d\n", *dbhandle)); } - + dlp_response_free(res); - + return result; } int dlp_DeleteDB(int sd, int card, const char *name) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_DeleteDB,"%s",name); + TraceX(dlp_DeleteDB, "%s", name); pi_reset_errors(sd); req = dlp_request_new(dlpFuncDeleteDB, 1, 2 + (strlen(name) + 1)); @@ -1494,23 +1452,23 @@ dlp_DeleteDB(int sd, int card, const char *name) strcpy(DLP_REQUEST_DATA(req, 0, 2), name); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_CreateDB(int sd, unsigned long creator, unsigned long type, int cardno, - int flags, unsigned int version, const char *name, int *dbhandle) + int flags, unsigned int version, const char *name, int *dbhandle) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_CreateDB,"'%s' type='%4.4s' creator='%4.4s' flags=0x%04x version=%d", - name,(const char *)&type,(const char *)&creator,flags,version); + TraceX(dlp_CreateDB, "'%s' type='%4.4s' creator='%4.4s' flags=0x%04x version=%d", + name, (const char *)&type, (const char *)&creator, flags, version); pi_reset_errors(sd); req = dlp_request_new(dlpFuncCreateDB, 1, 14 + (strlen(name) + 1)); @@ -1526,16 +1484,15 @@ dlp_CreateDB(int sd, unsigned long creator, unsigned long type, int cardno, strcpy(DLP_REQUEST_DATA(req, 0, 14), name); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); - + if (result > 0 && dbhandle) { *dbhandle = get_byte(DLP_RESPONSE_DATA(res, 0, 0)); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP CreateDB Handle=%d\n", *dbhandle)); + "DLP CreateDB Handle=%d\n", *dbhandle)); } - + dlp_response_free(res); return result; @@ -1544,7 +1501,7 @@ dlp_CreateDB(int sd, unsigned long creator, unsigned long type, int cardno, int dlp_CloseDB(int sd, int dbhandle) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -1558,17 +1515,17 @@ dlp_CloseDB(int sd, int dbhandle) set_byte(DLP_REQUEST_DATA(req, 0, 0), (unsigned char) dbhandle); result = dlp_exec(sd, req, &res); - - dlp_request_free(req); + + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_CloseDB_All(int sd) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -1580,28 +1537,28 @@ dlp_CloseDB_All(int sd) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); result = dlp_exec(sd, req, &res); - - dlp_request_free(req); + + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_CallApplication(int sd, unsigned long creator, unsigned long type, - int action, size_t length, const void *data, - unsigned long *retcode, pi_buffer_t *retbuf) + int action, size_t length, const void *data, + unsigned long *retcode, pi_buffer_t *retbuf) { - int result, - version = pi_version(sd), - previous_honor_rx_timeout, - no_rx_timeout = 0; + int result; + int version = pi_version(sd); + int previous_honor_rx_timeout; + int no_rx_timeout = 0; size_t data_len; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_CallApplication,"type='%4.4s' creator='%4.4s' action=0x%04x dataLength=%d", - (const char *)&type,(const char *)&creator,action,(int)length); + TraceX(dlp_CallApplication, "type='%4.4s' creator='%4.4s' action=0x%04x dataLength=%d", + (const char *)&type, (const char *)&creator, action, (int)length); pi_reset_errors(sd); if (retbuf) pi_buffer_clear(retbuf); @@ -1618,7 +1575,7 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, if (length + 22 > DLP_BUF_SIZE) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP CallApplication: data too large (>64k)")); + "DLP CallApplication: data too large (>64k)")); pi_set_error(sd, PI_ERR_DLP_DATASIZE); return -131; } @@ -1639,31 +1596,31 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, data_len = sizeof(no_rx_timeout); pi_setsockopt(sd, PI_LEVEL_SOCK, PI_SOCK_HONOR_RX_TIMEOUT, - &no_rx_timeout, &data_len); + &no_rx_timeout, &data_len); result = dlp_exec(sd, req, &res); pi_setsockopt(sd, PI_LEVEL_SOCK, PI_SOCK_HONOR_RX_TIMEOUT, - &previous_honor_rx_timeout, &data_len); + &previous_honor_rx_timeout, &data_len); dlp_request_free(req); if (result > 0) { data_len = res->argv[0]->len - 16; - + if (retcode) *retcode = get_long(DLP_RESPONSE_DATA(res, 0, 0)); if (retbuf) pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 16), data_len); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP CallApplication Result: %lu (0x%08lx), " - "and %d bytes:\n", - get_long(DLP_RESPONSE_DATA(res, 0, 0)), - get_long(DLP_RESPONSE_DATA(res, 0, 0)), - data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 16), + "DLP CallApplication Result: %lu (0x%08lx), " + "and %d bytes:\n", + get_long(DLP_RESPONSE_DATA(res, 0, 0)), + get_long(DLP_RESPONSE_DATA(res, 0, 0)), + data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 16), (size_t)data_len)); } @@ -1671,7 +1628,7 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, if (length + 8 > DLP_BUF_SIZE) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP CallApplication: data too large (>64k)")); + "DLP CallApplication: data too large (>64k)")); pi_set_error(sd, PI_ERR_DLP_DATASIZE); return -131; } @@ -1687,12 +1644,12 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, data_len = sizeof(no_rx_timeout); pi_setsockopt(sd, PI_LEVEL_SOCK, PI_SOCK_HONOR_RX_TIMEOUT, - &no_rx_timeout, &data_len); + &no_rx_timeout, &data_len); result = dlp_exec(sd, req, &res); pi_setsockopt(sd, PI_LEVEL_SOCK, PI_SOCK_HONOR_RX_TIMEOUT, - &previous_honor_rx_timeout, &data_len); + &previous_honor_rx_timeout, &data_len); dlp_request_free(req); @@ -1702,17 +1659,17 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, *retcode = get_short(DLP_RESPONSE_DATA(res, 0, 2)); if (retbuf) pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 6), data_len); - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP CallApplication Action: %d Result:" - " %u (0x%04x), and %d bytes:\n", - (int)get_short(DLP_RESPONSE_DATA(res, 0, 0)), - (unsigned int)get_short(DLP_RESPONSE_DATA(res, 0, 2)), - (unsigned int)get_short(DLP_RESPONSE_DATA(res, 0, 2)), - data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 6), - (size_t)data_len)); + "DLP CallApplication Action: %d Result:" + " %u (0x%04x), and %d bytes:\n", + (int)get_short(DLP_RESPONSE_DATA(res, 0, 0)), + (unsigned int)get_short(DLP_RESPONSE_DATA(res, 0, 2)), + (unsigned int)get_short(DLP_RESPONSE_DATA(res, 0, 2)), + data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 6), + (size_t)data_len)); } } @@ -1723,7 +1680,7 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, int dlp_ResetSystem(int sd) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -1736,20 +1693,20 @@ dlp_ResetSystem(int sd) if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_AddSyncLogEntry(int sd, char *entry) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_AddSyncLogEntry,"%s",entry); + TraceX(dlp_AddSyncLogEntry, "%s", entry); pi_reset_errors(sd); req = dlp_request_new(dlpFuncAddSyncLogEntry, 1, strlen(entry) + 1); @@ -1757,15 +1714,15 @@ dlp_AddSyncLogEntry(int sd, char *entry) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); strcpy(DLP_REQUEST_DATA(req, 0, 0), entry); - + result = dlp_exec(sd, req, &res); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); if (result > 0) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP AddSyncLogEntry Entry: \n %s\n", entry)); + "DLP AddSyncLogEntry Entry: \n %s\n", entry)); } return result; @@ -1774,7 +1731,7 @@ dlp_AddSyncLogEntry(int sd, char *entry) int dlp_ReadOpenDBInfo(int sd, int dbhandle, int *records) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -1786,7 +1743,7 @@ dlp_ReadOpenDBInfo(int sd, int dbhandle, int *records) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); - + result = dlp_exec(sd, req, &res); dlp_request_free(req); @@ -1794,26 +1751,26 @@ dlp_ReadOpenDBInfo(int sd, int dbhandle, int *records) if (result > 0) { if (records) *records = get_short(DLP_RESPONSE_DATA(res, 0, 0)); - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadOpenDBInfo %d records\n", - get_short(DLP_RESPONSE_DATA(res, 0, 0)))); + "DLP ReadOpenDBInfo %d records\n", + get_short(DLP_RESPONSE_DATA(res, 0, 0)))); } - + dlp_response_free(res); - + return result; } int -dlp_SetDBInfo (int sd, int dbhandle, int flags, int clearFlags, - unsigned int version, time_t createDate, time_t modifyDate, - time_t backupDate, unsigned long type, unsigned long creator) +dlp_SetDBInfo(int sd, int dbhandle, int flags, int clearFlags, + unsigned int version, time_t createDate, time_t modifyDate, + time_t backupDate, unsigned long type, unsigned long creator) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + Trace(dlp_SetDBInfo); pi_reset_errors(sd); @@ -1834,23 +1791,23 @@ dlp_SetDBInfo (int sd, int dbhandle, int flags, int clearFlags, set_date((unsigned char *)DLP_REQUEST_DATA(req, 0, 24), backupDate); set_long(DLP_REQUEST_DATA(req, 0, 32), type); set_long(DLP_REQUEST_DATA(req, 0, 36), creator); - + result = dlp_exec(sd, req, &res); dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_MoveCategory(int sd, int handle, int fromcat, int tocat) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_MoveCategory,"from %d to %d",fromcat,tocat); + TraceX(dlp_MoveCategory, "from %d to %d", fromcat, tocat); pi_reset_errors(sd); req = dlp_request_new(dlpFuncMoveCategory, 1, 4); @@ -1864,13 +1821,13 @@ dlp_MoveCategory(int sd, int handle, int fromcat, int tocat) result = dlp_exec(sd, req, &res); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); if (result >= 0) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP MoveCategory Handle: %d, From: %d, To: %d\n", - handle, fromcat, tocat)); + "DLP MoveCategory Handle: %d, From: %d, To: %d\n", + handle, fromcat, tocat)); } return result; @@ -1879,22 +1836,22 @@ dlp_MoveCategory(int sd, int handle, int fromcat, int tocat) int dlp_OpenConduit(int sd) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; Trace(dlp_OpenConduit); pi_reset_errors(sd); - + req = dlp_request_new(dlpFuncOpenConduit, 0); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); result = dlp_exec(sd, req, &res); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); - + /* if this was not done yet, this will read and cache the DLP version that the Palm is running. We need this when reading responses during record/resource transfers */ @@ -1907,7 +1864,7 @@ dlp_OpenConduit(int sd) int dlp_EndOfSync(int sd, int status) { - int result; + int result; pi_socket_t *ps; struct dlpRequest *req; struct dlpResponse *res; @@ -1929,10 +1886,10 @@ dlp_EndOfSync(int sd, int status) result = dlp_exec(sd, req, &res); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); - /* Messy code to set end-of-sync flag on socket + /* Messy code to set end-of-sync flag on socket so pi_close won't do it for us */ if (result == 0) ps->state = PI_SOCK_CONN_END; @@ -1962,16 +1919,16 @@ dlp_AbortSync(int sd) int dlp_WriteUserInfo(int sd, const struct PilotUser *User) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; int len; - + Trace(dlp_WriteUserInfo); pi_reset_errors(sd); len = strlen (User->username) + 1; - + req = dlp_request_new (dlpFuncWriteUserInfo, 1, 22 + len); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -1988,50 +1945,43 @@ dlp_WriteUserInfo(int sd, const struct PilotUser *User) dlp_request_free (req); dlp_response_free (res); - + return result; } int dlp_ReadUserInfo(int sd, struct PilotUser *User) { - int result; + int result; size_t userlen; struct dlpRequest *req; struct dlpResponse *res; - + Trace(dlp_ReadUserInfo); pi_reset_errors(sd); req = dlp_request_new (dlpFuncReadUserInfo, 0); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + result = dlp_exec (sd, req, &res); dlp_request_free (req); if (result > 0) { - User->userID = - get_long(DLP_RESPONSE_DATA (res, 0, 0)); - User->viewerID = - get_long(DLP_RESPONSE_DATA (res, 0, 4)); - User->lastSyncPC = - get_long(DLP_RESPONSE_DATA (res, 0, 8)); + User->userID = get_long(DLP_RESPONSE_DATA (res, 0, 0)); + User->viewerID = get_long(DLP_RESPONSE_DATA (res, 0, 4)); + User->lastSyncPC = get_long(DLP_RESPONSE_DATA (res, 0, 8)); User->successfulSyncDate = - get_date((const unsigned char *)DLP_RESPONSE_DATA (res, 0, 12)); + get_date((const unsigned char *)DLP_RESPONSE_DATA (res, 0, 12)); User->lastSyncDate = - get_date((const unsigned char *)DLP_RESPONSE_DATA (res, 0, 20)); - userlen = - get_byte(DLP_RESPONSE_DATA (res, 0, 28)); - User->passwordLength = - get_byte(DLP_RESPONSE_DATA (res, 0, 29)); - - memcpy(User->username, - DLP_RESPONSE_DATA (res, 0, 30), userlen); + get_date((const unsigned char *)DLP_RESPONSE_DATA (res, 0, 20)); + userlen = get_byte(DLP_RESPONSE_DATA (res, 0, 28)); + User->passwordLength = get_byte(DLP_RESPONSE_DATA (res, 0, 29)); + + memcpy(User->username, DLP_RESPONSE_DATA (res, 0, 30), userlen); memcpy(User->password, - DLP_RESPONSE_DATA (res, 0, 30 + userlen), - User->passwordLength); + DLP_RESPONSE_DATA (res, 0, 30 + userlen), User->passwordLength); if (userlen < sizeof(User->username)) User->username[userlen] = '\0'; @@ -2039,26 +1989,25 @@ dlp_ReadUserInfo(int sd, struct PilotUser *User) User->password[User->passwordLength] = '\0'; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadUserInfo UID=0x%8.8lX VID=0x%8.8lX " - "PCID=0x%8.8lX\n", - User->userID, User->viewerID, User->lastSyncPC)); + "DLP ReadUserInfo UID=0x%8.8lX VID=0x%8.8lX PCID=0x%8.8lX\n", + User->userID, User->viewerID, User->lastSyncPC)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Last Sync=%s Last Successful Sync=%s", - ctime (&User->lastSyncDate), - ctime (&User->successfulSyncDate))); + " Last Sync=%s Last Successful Sync=%s", + ctime (&User->lastSyncDate), + ctime (&User->successfulSyncDate))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Username=%s\n", User->username)); + " Username=%s\n", User->username)); } - + dlp_response_free (res); - + return result; } int dlp_ReadNetSyncInfo(int sd, struct NetSyncInfo *i) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -2078,40 +2027,40 @@ dlp_ReadNetSyncInfo(int sd, struct NetSyncInfo *i) if (result >= 0) { size_t str_offset = 24; - + i->lanSync = get_byte(DLP_RESPONSE_DATA(res, 0, 0)); - + i->hostName[0] = '\0'; - memcpy(i->hostName, DLP_RESPONSE_DATA(res, 0, str_offset), - get_short(DLP_RESPONSE_DATA(res, 0, 18))); + memcpy(i->hostName, DLP_RESPONSE_DATA(res, 0, str_offset), + get_short(DLP_RESPONSE_DATA(res, 0, 18))); str_offset += get_short(DLP_RESPONSE_DATA(res, 0, 18)); i->hostAddress[0] = '\0'; - memcpy(i->hostAddress, DLP_RESPONSE_DATA(res, 0, str_offset), - get_short(DLP_RESPONSE_DATA(res, 0, 20))); + memcpy(i->hostAddress, DLP_RESPONSE_DATA(res, 0, str_offset), + get_short(DLP_RESPONSE_DATA(res, 0, 20))); str_offset += get_short(DLP_RESPONSE_DATA(res, 0, 20)); i->hostSubnetMask[0] = '\0'; - memcpy(i->hostSubnetMask, DLP_RESPONSE_DATA(res, 0, str_offset), - get_short(DLP_RESPONSE_DATA(res, 0, 22))); + memcpy(i->hostSubnetMask, DLP_RESPONSE_DATA(res, 0, str_offset), + get_short(DLP_RESPONSE_DATA(res, 0, 22))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadNetSyncInfo Active: %d\n", i->lanSync ? 1 : 0)); + "DLP ReadNetSyncInfo Active: %d\n", i->lanSync ? 1 : 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " PC hostname: '%s', address '%s', mask '%s'\n", - i->hostName, i->hostAddress, i->hostSubnetMask)); + " PC hostname: '%s', address '%s', mask '%s'\n", + i->hostName, i->hostAddress, i->hostSubnetMask)); } dlp_response_free(res); - + return result; } int dlp_WriteNetSyncInfo(int sd, const struct NetSyncInfo *i) { - int result, - str_offset = 24; + int result; + int str_offset = 24; struct dlpRequest *req; struct dlpResponse *res; @@ -2122,14 +2071,13 @@ dlp_WriteNetSyncInfo(int sd, const struct NetSyncInfo *i) return pi_set_error(sd, PI_ERR_DLP_UNSUPPORTED); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadNetSyncInfo Active: %d\n", i->lanSync ? 1 : 0)); + "DLP ReadNetSyncInfo Active: %d\n", i->lanSync ? 1 : 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " PC hostname: '%s', address '%s', mask '%s'\n", - i->hostName, i->hostAddress, i->hostSubnetMask)); + " PC hostname: '%s', address '%s', mask '%s'\n", + i->hostName, i->hostAddress, i->hostSubnetMask)); - req = dlp_request_new(dlpFuncWriteNetSyncInfo, 1, - 24 + strlen(i->hostName) + - strlen(i->hostAddress) + strlen(i->hostSubnetMask) + 3); + req = dlp_request_new(dlpFuncWriteNetSyncInfo, 1, 24 + strlen(i->hostName) + + strlen(i->hostAddress) + strlen(i->hostSubnetMask) + 3); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -2155,7 +2103,7 @@ dlp_WriteNetSyncInfo(int sd, const struct NetSyncInfo *i) dlp_request_free(req); dlp_response_free(res); - + return result; } @@ -2163,10 +2111,8 @@ dlp_WriteNetSyncInfo(int sd, const struct NetSyncInfo *i) int dlp_RPC(int sd, struct RPC_params *p, unsigned long *result) { - int i, - err = 0; - long D0 = 0, - A0 = 0; + int i, err = 0; + long D0 = 0, A0 = 0; unsigned char *c; pi_buffer_t *dlp_buf; @@ -2224,10 +2170,8 @@ dlp_RPC(int sd, struct RPC_params *p, unsigned long *result) c = dlp_buf->data + 18; for (i = p->args - 1; i >= 0; i--) { if (p->param[i].byRef && p->param[i].data) - memcpy(p->param[i].data, c + 2, - p->param[i].size); - c += 2 + ((p->param[i].size + 1) & - (unsigned)~1); + memcpy(p->param[i].data, c + 2, p->param[i].size); + c += 2 + ((p->param[i].size + 1) & (unsigned)~1); } } } @@ -2250,18 +2194,17 @@ dlp_RPC(int sd, struct RPC_params *p, unsigned long *result) int -dlp_ReadFeature(int sd, unsigned long creator, int num, - unsigned long *feature) +dlp_ReadFeature(int sd, unsigned long creator, int num, unsigned long *feature) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadFeature,"creator='%4.4s' num=%d",(const char *)&creator,num); + TraceX(dlp_ReadFeature, "creator='%4.4s' num=%d", (const char *)&creator, num); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { - struct RPC_params p; + struct RPC_params p; int val; unsigned long errCode; @@ -2276,24 +2219,19 @@ dlp_ReadFeature(int sd, unsigned long creator, int num, if (val < 0) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadFeature Error: %s (%d)\n", - dlp_errorlist[-val], val)); - + "DLP ReadFeature Error: %s (%d)\n", dlp_errorlist[-val], val)); return val; } - + if (errCode) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadFeature FtrGet error 0x%8.8lX\n", - res)); + "DLP ReadFeature FtrGet error 0x%8.8lX\n", res)); pi_set_palmos_error(sd, (int)errCode); return pi_set_error(sd, PI_ERR_DLP_PALMOS); } LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " DLP ReadFeature Feature: 0x%8.8lX\n", - (unsigned long) *feature)); - + " DLP ReadFeature Feature: 0x%8.8lX\n", (unsigned long) *feature)); return 0; } @@ -2309,16 +2247,13 @@ dlp_ReadFeature(int sd, unsigned long creator, int num, result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { if (feature) - *feature = (unsigned long) - get_long(DLP_RESPONSE_DATA(res, 0, 0)); - + *feature = (unsigned long)get_long(DLP_RESPONSE_DATA(res, 0, 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadFeature Feature: 0x%8.8lX\n", - (unsigned long) - get_long(DLP_RESPONSE_DATA(res, 0, 0)))); + "DLP ReadFeature Feature: 0x%8.8lX\n", + (unsigned long)get_long(DLP_RESPONSE_DATA(res, 0, 0)))); } dlp_response_free(res); @@ -2331,21 +2266,16 @@ int dlp_GetROMToken(int sd, unsigned long token, void *buffer, size_t *size) { unsigned long result; - struct RPC_params p; - int val; unsigned long buffer_ptr; Trace(dlp_GetROMToken); pi_reset_errors(sd); - + #ifdef DLP_TRACE - if (dlp_trace) { - fprintf(stderr, - " Wrote: Token: '%s'\n", - printlong(token)); - } + if (dlp_trace) + fprintf(stderr, " Wrote: Token: '%s'\n", printlong(token)); #endif PackRPC(&p, 0xa340, RPC_IntReply, /* sysTrapHwrGetROMToken */ @@ -2353,57 +2283,49 @@ dlp_GetROMToken(int sd, unsigned long token, void *buffer, size_t *size) RPC_Long(token), RPC_LongPtr(&buffer_ptr), RPC_ShortPtr(size), RPC_End); - + val = dlp_RPC(sd, &p, &result); #ifdef DLP_TRACE if (dlp_trace) { - if (val < 0) - fprintf(stderr, - "Result: Error: %s (%d)\n", - dlp_errorlist[-val], val); - else if (result) - fprintf(stderr, - "FtrGet error 0x%8.8lX\n", - (unsigned long) result); - else - fprintf(stderr, - " Read: Buffer Ptr: 0x%8.8lX Size: %d\n", - (unsigned long) buffer_ptr, *size); + if (val < 0) + fprintf(stderr, "Result: Error: %s (%d)\n", + dlp_errorlist[-val], val); + else if (result) + fprintf(stderr, "FtrGet error 0x%8.8lX\n", + (unsigned long) result); + else + fprintf(stderr, " Read: Buffer Ptr: 0x%8.8lX Size: %d\n", + (unsigned long) buffer_ptr, *size); } -#endif +#endif if (buffer) { ((unsigned char *)buffer)[*size] = 0; PackRPC(&p, 0xa026, RPC_IntReply, /* sysTrapMemMove */ - RPC_Ptr(buffer, *size), - RPC_Long(buffer_ptr), - RPC_Long((unsigned long) *size), - RPC_End); + RPC_Ptr(buffer, *size), + RPC_Long(buffer_ptr), + RPC_Long((unsigned long) *size), + RPC_End); val = dlp_RPC(sd, &p, &result); } #ifdef DLP_TRACE if (dlp_trace) { - if (val < 0) - fprintf(stderr, - "Result: Error: %s (%d)\n", - dlp_errorlist[-val], val); - else if (result) - fprintf(stderr, - "FtrGet error 0x%8.8lX\n", - (unsigned long) result); - else - fprintf(stderr, - " Read: Buffer: %s\n", buffer); + if (val < 0) + fprintf(stderr, "Result: Error: %s (%d)\n", dlp_errorlist[-val], val); + else if (result) + fprintf(stderr, "FtrGet error 0x%8.8lX\n", (unsigned long) result); + else + fprintf(stderr, " Read: Buffer: %s\n", buffer); } -#endif +#endif if (val < 0) return val; - + if (result) return -((int)result); @@ -2413,8 +2335,8 @@ dlp_GetROMToken(int sd, unsigned long token, void *buffer, size_t *size) int dlp_ResetLastSyncPC(int sd) { - int err; - struct PilotUser User; + int err; + struct PilotUser User; Trace(dlp_ResetLastSyncPC); @@ -2429,7 +2351,7 @@ dlp_ResetLastSyncPC(int sd) int dlp_ResetDBIndex(int sd, int dbhandle) { - int result; + int result; pi_socket_t *ps; struct dlpRequest *req; struct dlpResponse *res; @@ -2449,25 +2371,24 @@ dlp_ResetDBIndex(int sd, int dbhandle) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); - + result = dlp_exec(sd, req, &res); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_ReadRecordIDList(int sd, int dbhandle, int sort, int start, int max, - recordid_t * IDs, int *count) + recordid_t * IDs, int *count) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadRecordIDList,"sort=%d start=%d max=%d", - sort,start,max); + TraceX(dlp_ReadRecordIDList, "sort=%d start=%d max=%d", sort, start, max); pi_reset_errors(sd); req = dlp_request_new(dlpFuncReadRecordIDList, 1, 6); @@ -2485,24 +2406,22 @@ dlp_ReadRecordIDList(int sd, int dbhandle, int sort, int start, int max, if (result > 0) { int ret, i; - + ret = get_short(DLP_RESPONSE_DATA(res, 0, 0)); for (i = 0; i < ret; i++) - IDs[i] = - get_long(DLP_RESPONSE_DATA(res, 0, 2 + (i * 4))); + IDs[i] = get_long(DLP_RESPONSE_DATA(res, 0, 2 + (i * 4))); if (count) *count = ret; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadRecordIDList %d IDs:\n", ret)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), - (size_t)(ret * 4))); + "DLP ReadRecordIDList %d IDs:\n", ret)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), (size_t)(ret * 4))); } dlp_response_free(res); - + return result; } @@ -2510,7 +2429,7 @@ int dlp_WriteRecord(int sd, int dbhandle, int flags, recordid_t recID, int catID, const void *data, size_t length, recordid_t *pNewRecID) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -2536,7 +2455,7 @@ dlp_WriteRecord(int sd, int dbhandle, int flags, recordid_t recID, } else { if ((length + 8) > DLP_BUF_SIZE) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP WriteRecord: data too large (>64k)")); + "DLP WriteRecord: data too large (>64k)")); return PI_ERR_DLP_DATASIZE; } @@ -2562,28 +2481,27 @@ dlp_WriteRecord(int sd, int dbhandle, int flags, recordid_t recID, *pNewRecID = get_long(DLP_RESPONSE_DATA(res, 0, 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP WriteRecord Record ID: 0x%8.8lX\n", - get_long(DLP_RESPONSE_DATA(res, 0, 0)))); + "DLP WriteRecord Record ID: 0x%8.8lX\n", + get_long(DLP_RESPONSE_DATA(res, 0, 0)))); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - record_dump( + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, record_dump( get_long(DLP_RESPONSE_DATA(res, 0, 0)), /* recID */ 0xffff, /* index */ flags, catID, (const char *)data, (int)length)); } - + dlp_response_free(res); - + return result; } int dlp_DeleteRecord(int sd, int dbhandle, int all, recordid_t recID) { - int result, - flags = all ? 0x80 : 0; + int result; + int flags = all ? 0x80 : 0; struct dlpRequest *req; struct dlpResponse *res; @@ -2599,21 +2517,21 @@ dlp_DeleteRecord(int sd, int dbhandle, int all, recordid_t recID) set_long(DLP_REQUEST_DATA(req, 0, 2), recID); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_DeleteCategory(int sd, int dbhandle, int category) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_DeleteCategory,"category=%d",category); + TraceX(dlp_DeleteCategory, "category=%d", category); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { @@ -2622,16 +2540,15 @@ dlp_DeleteCategory(int sd, int dbhandle, int category) recordid_t id_; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP DeleteCategory Emulating with: Handle: %d, " - "Category: %d\n", - dbhandle, category & 0xff)); + "DLP DeleteCategory Emulating with: Handle: %d, Category: %d\n", + dbhandle, category & 0xff)); for (i = 0; - (result = dlp_ReadRecordByIndex(sd, dbhandle, i, NULL, &id_, - &attr, &cat)) >= 0; i++) { + (result = dlp_ReadRecordByIndex(sd, dbhandle, i, NULL, &id_, &attr, &cat)) >= 0; + i++) { if (cat != category - || (attr & dlpRecAttrDeleted) - || (attr & dlpRecAttrArchived)) + || (attr & dlpRecAttrDeleted) + || (attr & dlpRecAttrArchived)) continue; result = dlp_DeleteRecord(sd, dbhandle, 0, id_); if (result < 0) @@ -2642,15 +2559,15 @@ dlp_DeleteCategory(int sd, int dbhandle, int category) return result; } else { int flags = 0x40; - + req = dlp_request_new(dlpFuncDeleteRecord, 1, 6); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); set_byte(DLP_REQUEST_DATA(req, 0, 1), flags); set_long(DLP_REQUEST_DATA(req, 0, 2), category & 0xff); - + result = dlp_exec(sd, req, &res); dlp_request_free(req); @@ -2662,15 +2579,15 @@ dlp_DeleteCategory(int sd, int dbhandle, int category) int dlp_ReadResourceByType(int sd, int dbhandle, unsigned long type, int resID, - pi_buffer_t *buffer, int *resindex) + pi_buffer_t *buffer, int *resindex) { - int result, - data_len; + int result; + int data_len; struct dlpRequest *req; struct dlpResponse *res; int maxBufferSize = pi_maxrecsize(sd) - RECORD_READ_SAFEGUARD_SIZE; - TraceX(dlp_ReadResourceByType,"type='%4.4s' resID=%d",(const char *)&type,resID); + TraceX(dlp_ReadResourceByType, "type='%4.4s' resID=%d", (const char *)&type, resID); pi_reset_errors(sd); req = dlp_request_new_with_argid(dlpFuncReadResource, 0x21, 1, 12); @@ -2687,15 +2604,14 @@ dlp_ReadResourceByType(int sd, int dbhandle, unsigned long type, int resID, result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { data_len = res->argv[0]->len - 10; if (resindex) *resindex = get_short(DLP_RESPONSE_DATA(res, 0, 6)); if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len); /* Some devices such as the Tungsten TX, Treo 650 and Treo 700p lock up if you try to read the entire record if the ** record is almost at the maximum record size. The following mitigates this and allows the record @@ -2713,9 +2629,9 @@ dlp_ReadResourceByType(int sd, int dbhandle, unsigned long type, int resID, set_short(DLP_REQUEST_DATA(req, 0, 10), RECORD_READ_SAFEGUARD_SIZE); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); - + if (result > 0) { data_len = res->argv[0]->len - 10; /* number of bytes returned by the second read... */ pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len); @@ -2724,35 +2640,33 @@ dlp_ReadResourceByType(int sd, int dbhandle, unsigned long type, int resID, } } } - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadResourceByType Type: '%s', ID: %d, " - "Index: %d, and %d bytes:\n", - printlong(type), resID, - get_short(DLP_RESPONSE_DATA(res, 0, 6)),(size_t)data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 10),(size_t)data_len)); + "DLP ReadResourceByType Type: '%s', ID: %d, " + "Index: %d, and %d bytes:\n", + printlong(type), resID, + get_short(DLP_RESPONSE_DATA(res, 0, 6)), (size_t)data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len)); } else { data_len = result; } dlp_response_free(res); - + return data_len; } int dlp_ReadResourceByIndex(int sd, int dbhandle, unsigned int resindex, pi_buffer_t *buffer, - unsigned long *type, int *resID) + unsigned long *type, int *resID) { - int result, - data_len, - large = 0; + int result, data_len, large = 0; struct dlpRequest *req; struct dlpResponse *res; int maxBufferSize = pi_maxrecsize(sd) - RECORD_READ_SAFEGUARD_SIZE; - TraceX(dlp_ReadResourceByIndex,"resindex=%d",resindex); + TraceX(dlp_ReadResourceByIndex, "resindex=%d", resindex); pi_reset_errors(sd); /* TapWave (DLP 1.4) implements a 'large' version of dlpFuncReadResource, @@ -2783,7 +2697,7 @@ dlp_ReadResourceByIndex(int sd, int dbhandle, unsigned int resindex, pi_buffer_t result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { data_len = res->argv[0]->len - (large ? 12 : 10); if (type) @@ -2792,8 +2706,7 @@ dlp_ReadResourceByIndex(int sd, int dbhandle, unsigned int resindex, pi_buffer_t *resID = get_short(DLP_RESPONSE_DATA(res, 0, 4)); if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 12 : 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 12 : 10), (size_t)data_len); /* Some devices such as the Tungsten TX, Treo 650 and Treo 700p lock up if you try to read the entire record if the ** record is almost at the maximum record size. The following mitigates this and allows the record @@ -2808,49 +2721,47 @@ dlp_ReadResourceByIndex(int sd, int dbhandle, unsigned int resindex, pi_buffer_t set_short(DLP_REQUEST_DATA(req, 0, 2), resindex); set_short(DLP_REQUEST_DATA(req, 0, 4), maxBufferSize); /* Offset in record */ set_short(DLP_REQUEST_DATA(req, 0, 6), RECORD_READ_SAFEGUARD_SIZE); - + result = dlp_exec(sd, req, &res); - + dlp_request_free(req); - + if (result > 0) { data_len = res->argv[0]->len - (large ? 12 : 10); /* number of bytes returned by the second read... */ - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 12 : 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 12 : 10), (size_t)data_len); data_len += maxBufferSize; /* ...that add up to the bytes received in the first read */ } } - } + } } LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadResourceByIndex Type: '%s', ID: %d, " - "Index: %d, and %d bytes:\n", - printlong(get_long(DLP_RESPONSE_DATA(res, 0, 0))), - get_short(DLP_RESPONSE_DATA(res, 0, 4)), - resindex, data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, (large ? 12 : 10)), - (size_t)data_len)); + "DLP ReadResourceByIndex Type: '%s', ID: %d, " + "Index: %d, and %d bytes:\n", + printlong(get_long(DLP_RESPONSE_DATA(res, 0, 0))), + get_short(DLP_RESPONSE_DATA(res, 0, 4)), + resindex, data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, (large ? 12 : 10)), + (size_t)data_len)); } else { data_len = result; } dlp_response_free(res); - + return data_len; } int dlp_WriteResource(int sd, int dbhandle, unsigned long type, int resID, - const void *data, size_t length) + const void *data, size_t length) { - int result, - large = 0; + int result, large = 0; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_WriteResource,"'%4.4s' #%d",(const char *)&type,resID); + TraceX(dlp_WriteResource, "'%4.4s' #%d", (const char *)&type, resID); pi_reset_errors(sd); /* TapWave (DLP 1.4) implements a 'large' version of dlpFuncWriteResource, @@ -2858,7 +2769,7 @@ dlp_WriteResource(int sd, int dbhandle, unsigned long type, int resID, */ if (pi_version(sd) >= 0x0104) { req = dlp_request_new_with_argid(dlpFuncWriteResourceEx, - PI_DLP_ARG_FIRST_ID | PI_DLP_ARG_FLAG_LONG, 1, 12 + length); + PI_DLP_ARG_FIRST_ID | PI_DLP_ARG_FLAG_LONG, 1, 12 + length); large = 1; } else { if (length > 0xffff) @@ -2867,8 +2778,7 @@ dlp_WriteResource(int sd, int dbhandle, unsigned long type, int resID, } if (req == NULL) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP sd:%i large:%i dlp_request_new failed\n", - sd, large)); + "DLP sd:%i large:%i dlp_request_new failed\n", sd, large)); return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); } @@ -2893,16 +2803,14 @@ dlp_WriteResource(int sd, int dbhandle, unsigned long type, int resID, int -dlp_DeleteResource(int sd, int dbhandle, int all, unsigned long restype, - int resID) +dlp_DeleteResource(int sd, int dbhandle, int all, unsigned long restype, int resID) { - int result, - flags = all ? 0x80 : 0; + int result, flags = all ? 0x80 : 0; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_DeleteResource,"restype='%4.4s' resID=%d all=%d", - (const char *)&restype,resID,all); + TraceX(dlp_DeleteResource, "restype='%4.4s' resID=%d all=%d", + (const char *)&restype, resID, all); pi_reset_errors(sd); req = dlp_request_new(dlpFuncDeleteResource, 1, 8); @@ -2915,22 +2823,21 @@ dlp_DeleteResource(int sd, int dbhandle, int all, unsigned long restype, set_short(DLP_REQUEST_DATA(req, 0, 6), resID); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_ReadAppBlock(int sd, int dbhandle, int offset, int reqbytes, pi_buffer_t *retbuf) { - int result, - data_len; + int result, data_len; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadAppBlock,"offset=%d reqbytes=%ld",offset,reqbytes); + TraceX(dlp_ReadAppBlock, "offset=%d reqbytes=%ld", offset, reqbytes); pi_reset_errors(sd); if (retbuf) @@ -2948,53 +2855,49 @@ dlp_ReadAppBlock(int sd, int dbhandle, int offset, int reqbytes, pi_buffer_t *re result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result >= 0) { if (result < 2) data_len = PI_ERR_DLP_COMMAND; else { data_len = res->argv[0]->len - 2; if (retbuf && data_len) - pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 2), - (size_t)data_len); - + pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 2), (size_t)data_len); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP ReadAppBlock %d bytes\n", data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), - (size_t)data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), (size_t)data_len)); } } else { data_len = result; } dlp_response_free(res); - + return data_len; } int -dlp_WriteAppBlock(int sd, int dbhandle, const /* @unique@ */ void *data, - size_t length) +dlp_WriteAppBlock(int sd, int dbhandle, const /* @unique@ */ void *data, size_t length) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_WriteAppBlock,"length=%ld",length); + TraceX(dlp_WriteAppBlock, "length=%ld", length); pi_reset_errors(sd); req = dlp_request_new(dlpFuncWriteAppBlock, 1, 4 + length); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); set_byte(DLP_REQUEST_DATA(req, 0, 1), 0); set_short(DLP_REQUEST_DATA(req, 0, 2), length); if (length + 10 > DLP_BUF_SIZE) { - LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP WriteAppBlock: data too large (>64k)")); + LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, "DLP WriteAppBlock: data too large (>64k)")); pi_set_error(sd, PI_ERR_DLP_DATASIZE); return -131; } @@ -3012,12 +2915,11 @@ dlp_WriteAppBlock(int sd, int dbhandle, const /* @unique@ */ void *data, int dlp_ReadSortBlock(int sd, int dbhandle, int offset, int reqbytes, pi_buffer_t *retbuf) { - int result, - data_len; + int result, data_len; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadSortBlock,"offset=%d reqbytes=%d",offset,reqbytes); + TraceX(dlp_ReadSortBlock, "offset=%d reqbytes=%d", offset, reqbytes); pi_reset_errors(sd); if (retbuf) @@ -3035,40 +2937,37 @@ dlp_ReadSortBlock(int sd, int dbhandle, int offset, int reqbytes, pi_buffer_t *r result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result >= 0) { if (result < 2) data_len = PI_ERR_DLP_COMMAND; else { data_len = res->argv[0]->len - 2; if (retbuf) - pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 2), - (size_t)data_len); - + pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 2), (size_t)data_len); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadSortBlock %d bytes\n", data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), - (size_t)data_len)); + "DLP ReadSortBlock %d bytes\n", data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), (size_t)data_len)); } } else { data_len = result; } dlp_response_free(res); - + return data_len; } int -dlp_WriteSortBlock(int sd, int dbhandle, const /* @unique@ */ void *data, - size_t length) +dlp_WriteSortBlock(int sd, int dbhandle, const /* @unique@ */ void *data, size_t length) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_WriteSortBlock,"length=%ld",length); + TraceX(dlp_WriteSortBlock, "length=%ld", length); pi_reset_errors(sd); req = dlp_request_new(dlpFuncWriteSortBlock, 1, 4 + length); @@ -3080,8 +2979,8 @@ dlp_WriteSortBlock(int sd, int dbhandle, const /* @unique@ */ void *data, set_short(DLP_REQUEST_DATA(req, 0, 2), length); if (length + 10 > DLP_BUF_SIZE) { - LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP WriteSortBlock: data too large (>64k)")); + LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, + "DLP WriteSortBlock: data too large (>64k)")); pi_set_error(sd, PI_ERR_DLP_DATASIZE); return -131; } @@ -3098,7 +2997,7 @@ dlp_WriteSortBlock(int sd, int dbhandle, const /* @unique@ */ void *data, int dlp_CleanUpDatabase(int sd, int dbhandle) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -3112,17 +3011,17 @@ dlp_CleanUpDatabase(int sd, int dbhandle) set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_ResetSyncFlags(int sd, int dbhandle) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -3136,37 +3035,32 @@ dlp_ResetSyncFlags(int sd, int dbhandle) set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, - pi_buffer_t *buffer, recordid_t *recuid, int *recindex, - int *attr) + pi_buffer_t *buffer, recordid_t *recuid, int *recindex, int *attr) { - int result, - data_len, - flags; + int result, data_len, flags; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadNextRecInCategory,"category=%d",category); + TraceX(dlp_ReadNextRecInCategory, "category=%d", category); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { /* Emulate for PalmOS 1.0 */ - int cat, - rec; + int cat, rec; pi_socket_t *ps; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadNextRecInCategory Emulating with: Handle: %d, " - "Category: %d\n", - dbhandle, category)); + "DLP ReadNextRecInCategory Emulating with: Handle: %d, Category: %d\n", + dbhandle, category)); if ((ps = find_pi_socket(sd)) == 0) { errno = ESRCH; @@ -3176,8 +3070,7 @@ dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, for (;;) { /* Fetch next modified record (in any category) */ rec = dlp_ReadRecordByIndex(sd, dbhandle, - ps->dlprecord, 0, 0, - 0, &cat); + ps->dlprecord, 0, 0, 0, &cat); if (rec < 0) break; @@ -3188,8 +3081,7 @@ dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, } rec = dlp_ReadRecordByIndex(sd, dbhandle, - ps->dlprecord, buffer, - recuid, attr, &cat); + ps->dlprecord, buffer, recuid, attr, &cat); if (rec >= 0) { if (recindex) @@ -3211,7 +3103,7 @@ dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, return rec; } - + req = dlp_request_new(dlpFuncReadNextRecInCategory, 1, 2); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -3233,17 +3125,14 @@ dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, *attr = get_byte(DLP_RESPONSE_DATA(res, 0, 8)); if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len); } flags = get_byte(DLP_RESPONSE_DATA(res, 0, 8)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadNextRecInCategory ID: 0x%8.8lX, " - "Index: %d, Category: %d\n" + "DLP ReadNextRecInCategory ID: 0x%8.8lX, Index: %d, Category: %d\n" " Flags: %s%s%s%s%s%s (0x%2.2X) and %d bytes:\n", - (unsigned long) get_long(DLP_RESPONSE_DATA(res, - 0, 0)), + (unsigned long) get_long(DLP_RESPONSE_DATA(res, 0, 0)), get_short(DLP_RESPONSE_DATA(res, 0, 4)), (int) get_byte(DLP_RESPONSE_DATA(res, 0, 9)), (flags & dlpRecAttrDeleted) ? " Deleted" : "", @@ -3253,48 +3142,45 @@ dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, (flags & dlpRecAttrArchived) ? " Archive" : "", (!flags) ? " None" : "", flags, data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 10), - (size_t)data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len)); } else { data_len = result; } dlp_response_free(res); - + return data_len; } int dlp_ReadAppPreference(int sd, unsigned long creator, int prefID, int backup, - int maxsize, void *buffer, size_t *size, int *version) + int maxsize, void *buffer, size_t *size, int *version) { - int result, - data_len; + int result, data_len; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadAppPreference,"creator='%4.4s' prefID=%d backup=%d maxsize=%d", - (const char *)creator,prefID,backup,maxsize); + TraceX(dlp_ReadAppPreference, "creator='%4.4s' prefID=%d backup=%d maxsize=%d", + (const char *)creator, prefID, backup, maxsize); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { /* Emulate on PalmOS 1.0 */ - int db; + int db; pi_buffer_t *buf; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadAppPreference Emulating with: Creator: '%s', " - "Id: %d, Size: %d, Backup: %d\n", - printlong(creator), prefID, - buffer ? maxsize : 0, backup ? 0x80 : 0)); + "DLP ReadAppPreference Emulating with: Creator: '%s', " + "Id: %d, Size: %d, Backup: %d\n", + printlong(creator), prefID, buffer ? maxsize : 0, backup ? 0x80 : 0)); result = dlp_OpenDB(sd, 0, dlpOpenRead, "System Preferences", &db); if (result < 0) return result; buf = pi_buffer_new (1024); - + result = dlp_ReadResourceByType(sd, db, creator, prefID, buf,NULL); if (result < 0) { @@ -3328,7 +3214,7 @@ dlp_ReadAppPreference(int sd, unsigned long creator, int prefID, int backup, dlp_CloseDB(sd, db); return result; } - + req = dlp_request_new(dlpFuncReadAppPreference, 1, 10); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -3342,7 +3228,7 @@ dlp_ReadAppPreference(int sd, unsigned long creator, int prefID, int backup, result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { data_len = get_short(DLP_RESPONSE_DATA(res, 0, 4)); if (version) @@ -3352,18 +3238,16 @@ dlp_ReadAppPreference(int sd, unsigned long creator, int prefID, int backup, if (size && buffer) *size = data_len; /* Size returned */ if (buffer) - memcpy(buffer, DLP_RESPONSE_DATA(res, 0, 6), - (size_t)data_len); + memcpy(buffer, DLP_RESPONSE_DATA(res, 0, 6), (size_t)data_len); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadAppPref Version: %d, " - "Total size: %d, Read %d bytes:\n", - get_short(DLP_RESPONSE_DATA(res, 0, 0)), - get_short(DLP_RESPONSE_DATA(res, 0, 2)), - get_short(DLP_RESPONSE_DATA(res, 0, 4)))); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 6), - (size_t)data_len)); + "DLP ReadAppPref Version: %d, " + "Total size: %d, Read %d bytes:\n", + get_short(DLP_RESPONSE_DATA(res, 0, 0)), + get_short(DLP_RESPONSE_DATA(res, 0, 2)), + get_short(DLP_RESPONSE_DATA(res, 0, 4)))); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 6), (size_t)data_len)); } else { data_len = result; } @@ -3375,35 +3259,30 @@ dlp_ReadAppPreference(int sd, unsigned long creator, int prefID, int backup, int dlp_WriteAppPreference(int sd, unsigned long creator, int prefID, int backup, - int version, const void *buffer, size_t size) + int version, const void *buffer, size_t size) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_WriteAppPreference,"creator='%4.4s' prefID=%d backup=%d version=%d size=%ld", - (const char *)&creator,prefID,backup,version,size); + TraceX(dlp_WriteAppPreference, "creator='%4.4s' prefID=%d backup=%d version=%d size=%ld", + (const char *)&creator, prefID, backup, version, size); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { /* Emulate on PalmOS 1.0 */ - int db, - err1, - err2; + int db, err1, err2; - if ((result = dlp_OpenDB(sd, 0, dlpOpenWrite, "System Preferences", - &db)) < 0) + if ((result = dlp_OpenDB(sd, 0, dlpOpenWrite, "System Preferences", &db)) < 0) return result; if (buffer && size) { unsigned char dlp_buf[DLP_BUF_SIZE]; memcpy(dlp_buf + 2, buffer, size); set_short(dlp_buf, version); - result = dlp_WriteResource(sd, db, creator, prefID, dlp_buf, - size); + result = dlp_WriteResource(sd, db, creator, prefID, dlp_buf, size); } else { - result = dlp_WriteResource(sd, db, creator, prefID, NULL, - 0); + result = dlp_WriteResource(sd, db, creator, prefID, NULL, 0); } err1 = pi_error(sd); err2 = pi_palmos_error(sd); @@ -3432,7 +3311,7 @@ dlp_WriteAppPreference(int sd, unsigned long creator, int prefID, int backup, if ((size + 12) > DLP_BUF_SIZE) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP WriteAppPreferenceV2: data too large (>64k)")); + "DLP WriteAppPreferenceV2: data too large (>64k)")); return PI_ERR_DLP_DATASIZE; } memcpy(DLP_REQUEST_DATA(req, 0, 12), buffer, size); @@ -3447,46 +3326,44 @@ dlp_WriteAppPreference(int sd, unsigned long creator, int prefID, int backup, int dlp_ReadNextModifiedRecInCategory(int sd, int dbhandle, int category, - pi_buffer_t *buffer, recordid_t *recID, - int *recindex, int *attr) + pi_buffer_t *buffer, recordid_t *recID, int *recindex, int *attr) { - int result, - data_len; + int result, data_len; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadNextModifiedRecInCategory,"category=%d",category); + TraceX(dlp_ReadNextModifiedRecInCategory, "category=%d", category); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { /* Emulate for PalmOS 1.0 */ - int cat; + int cat; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadNextModifiedRecInCategory" - " Emulating with: Handle: %d, Category: %d\n", - dbhandle, category)); + "DLP ReadNextModifiedRecInCategory" + " Emulating with: Handle: %d, Category: %d\n", + dbhandle, category)); do { /* Fetch next modified record (in any category) */ result = dlp_ReadNextModifiedRec(sd, dbhandle, buffer, - recID, recindex, attr, &cat); + recID, recindex, attr, &cat); /* If none found, reset modified pointer so that - another search on a different (or the same!) category - will start from the beginning */ + another search on a different (or the same!) category + will start from the beginning */ /* Working on same assumption as ReadNextRecInCat, - elide this: - if (r < 0) - dlp_ResetDBIndex(sd, fHandle); + elide this: + if (r < 0) + dlp_ResetDBIndex(sd, fHandle); */ /* Loop until we fail to get a record or a record - is found in the proper category */ + is found in the proper category */ } while (result >= 0 && cat != category); - + return result; } @@ -3513,12 +3390,10 @@ dlp_ReadNextModifiedRecInCategory(int sd, int dbhandle, int category, if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len); } - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - record_dump( + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, record_dump( get_long(DLP_RESPONSE_DATA(res, 0, 0)), /* recID */ get_short(DLP_RESPONSE_DATA(res, 0, 4)), /* index */ get_byte(DLP_RESPONSE_DATA(res, 0, 8)), /* flags */ @@ -3535,26 +3410,25 @@ dlp_ReadNextModifiedRecInCategory(int sd, int dbhandle, int category, int dlp_ReadNextModifiedRec(int sd, int dbhandle, pi_buffer_t *buffer, recordid_t * recID, - int *recindex, int *attr, int *category) + int *recindex, int *attr, int *category) { - int result, - data_len; + int result, data_len; struct dlpRequest *req; struct dlpResponse *res; Trace(dlp_ReadNextModifiedRec); pi_reset_errors(sd); - + req = dlp_request_new (dlpFuncReadNextModifiedRec, 1, 1); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); - + result = dlp_exec (sd, req, &res); dlp_request_free(req); - + if (result >= 0) { data_len = res->argv[0]->len -10; if (recID) @@ -3568,12 +3442,10 @@ dlp_ReadNextModifiedRec(int sd, int dbhandle, pi_buffer_t *buffer, recordid_t * if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len); } - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - record_dump( + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, record_dump( get_long(DLP_RESPONSE_DATA(res, 0, 0)), /* recID */ get_short(DLP_RESPONSE_DATA(res, 0, 4)), /* index */ get_byte(DLP_RESPONSE_DATA(res, 0, 8)), /* flags */ @@ -3584,20 +3456,20 @@ dlp_ReadNextModifiedRec(int sd, int dbhandle, pi_buffer_t *buffer, recordid_t * } dlp_response_free(res); - + return data_len; } int dlp_ReadRecordById(int sd, int dbhandle, recordid_t recuid, pi_buffer_t *buffer, - int *recindex, int *attr, int *category) + int *recindex, int *attr, int *category) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; int maxBufferSize = pi_maxrecsize(sd) - RECORD_READ_SAFEGUARD_SIZE; - TraceX(dlp_ReadRecordById,"recuid=0x%08lx",recuid); + TraceX(dlp_ReadRecordById, "recuid=0x%08lx", recuid); pi_reset_errors(sd); req = dlp_request_new(dlpFuncReadRecord, 1, 10); @@ -3606,14 +3478,14 @@ dlp_ReadRecordById(int sd, int dbhandle, recordid_t recuid, pi_buffer_t *buffer, set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); set_byte(DLP_REQUEST_DATA(req, 0, 1), 0); - set_long(DLP_REQUEST_DATA(req, 0, 2), recuid); + set_long(DLP_REQUEST_DATA(req, 0, 2), recuid); set_short(DLP_REQUEST_DATA(req, 0, 6), 0); /* Offset into record */ set_short(DLP_REQUEST_DATA(req, 0, 8), buffer ? maxBufferSize : 0); /* length to return */ result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { result = res->argv[0]->len - 10; if (recindex) @@ -3624,8 +3496,7 @@ dlp_ReadRecordById(int sd, int dbhandle, recordid_t recuid, pi_buffer_t *buffer, *category = get_byte(DLP_RESPONSE_DATA(res, 0, 9)); if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)result); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)result); /* Some devices such as the Tungsten TX, Treo 650 and Treo 700p lock up if you try to read the entire record if the ** record is almost at the maximum record size. The following mitigates this and allows the record @@ -3637,7 +3508,7 @@ dlp_ReadRecordById(int sd, int dbhandle, recordid_t recuid, pi_buffer_t *buffer, if (req != NULL) { set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); set_byte(DLP_REQUEST_DATA(req, 0, 1), 0); - set_long(DLP_REQUEST_DATA(req, 0, 2), recuid); + set_long(DLP_REQUEST_DATA(req, 0, 2), recuid); set_short(DLP_REQUEST_DATA(req, 0, 6), maxBufferSize); /* Offset into record */ set_short(DLP_REQUEST_DATA(req, 0, 8), buffer ? RECORD_READ_SAFEGUARD_SIZE : 0); /* length to return */ @@ -3646,39 +3517,36 @@ dlp_ReadRecordById(int sd, int dbhandle, recordid_t recuid, pi_buffer_t *buffer, if (result > 0) { result = res->argv[0]->len - 10; - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)result); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)result); result += maxBufferSize; } } } } - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - record_dump( + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, record_dump( get_long(DLP_RESPONSE_DATA(res, 0, 0)), /* recID */ get_short(DLP_RESPONSE_DATA(res, 0, 4)), /* index */ get_byte(DLP_RESPONSE_DATA(res, 0, 8)), /* flags */ get_byte(DLP_RESPONSE_DATA(res, 0, 9)), /* catID */ DLP_RESPONSE_DATA(res, 0, 10), result)); } - + dlp_response_free(res); - + return result; } int dlp_ReadRecordByIndex(int sd, int dbhandle, int recindex, pi_buffer_t *buffer, - recordid_t * recuid, int *attr, int *category) + recordid_t * recuid, int *attr, int *category) { - int result, - large = 0; + int result, large = 0; struct dlpRequest *req; struct dlpResponse *res; int maxBufferSize = pi_maxrecsize(sd) - RECORD_READ_SAFEGUARD_SIZE; - TraceX(dlp_ReadRecordByIndex,"recindex=%d",recindex); + TraceX(dlp_ReadRecordByIndex, "recindex=%d", recindex); pi_reset_errors(sd); /* TapWave (DLP 1.4) implements a 'large' version of dlpFuncReadRecord, @@ -3708,7 +3576,7 @@ dlp_ReadRecordByIndex(int sd, int dbhandle, int recindex, pi_buffer_t *buffer, } result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { result = res->argv[0]->len - (large ? 14 : 10); if (recuid) @@ -3719,8 +3587,7 @@ dlp_ReadRecordByIndex(int sd, int dbhandle, int recindex, pi_buffer_t *buffer, *category = get_byte(DLP_RESPONSE_DATA(res, 0, large ? 13 : 9)); if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 14 : 10), - (size_t)result); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 14 : 10), (size_t)result); /* Some devices such as the Tungsten TX, Treo 650 and Treo 700p lock up if you try to read the entire record if the ** record is almost at the maximum record size. The following mitigates this and allows the record @@ -3741,17 +3608,15 @@ dlp_ReadRecordByIndex(int sd, int dbhandle, int recindex, pi_buffer_t *buffer, if (result > 0) { result = res->argv[0]->len - (large ? 14 : 10); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 14 : 10), - (size_t)result); - + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 14 : 10), (size_t)result); + result += maxBufferSize; } } } } - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - record_dump( + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, record_dump( get_long(DLP_RESPONSE_DATA(res, 0, 0)), /* recUID */ get_short(DLP_RESPONSE_DATA(res, 0, 4)), /* index */ get_byte(DLP_RESPONSE_DATA(res, 0, large ? 12 : 8)), /* flags */ @@ -3760,17 +3625,17 @@ dlp_ReadRecordByIndex(int sd, int dbhandle, int recindex, pi_buffer_t *buffer, } dlp_response_free(res); - + return result; } int dlp_ExpSlotEnumerate(int sd, int *numSlots, int *slotRefs) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); Trace(dlp_ExpSlotEnumerate); pi_reset_errors(sd); @@ -3782,29 +3647,24 @@ dlp_ExpSlotEnumerate(int sd, int *numSlots, int *slotRefs) result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { int slots, i; slots = get_short(DLP_RESPONSE_DATA (res, 0, 0)); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ExpSlotEnumerate %d\n", slots)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP ExpSlotEnumerate %d\n", slots)); if (slots) { for (i = 0; i < slots && i < *numSlots; i++) { - slotRefs[i] = - get_short(DLP_RESPONSE_DATA (res, 0, - 2 + (2 * i))); - - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " %d Slot-Refnum %d\n", i, slotRefs[i])); + slotRefs[i] = get_short(DLP_RESPONSE_DATA (res, 0, 2 + (2 * i))); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, " %d Slot-Refnum %d\n", i, slotRefs[i])); } } *numSlots = slots; } - + dlp_response_free(res); return result; @@ -3813,12 +3673,12 @@ dlp_ExpSlotEnumerate(int sd, int *numSlots, int *slotRefs) int dlp_ExpCardPresent(int sd, int slotRef) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); - TraceX(dlp_ExpCardPresent,"slotRef=%d",slotRef); + TraceX(dlp_ExpCardPresent, "slotRef=%d", slotRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncExpCardPresent, 1, 2); @@ -3836,15 +3696,14 @@ dlp_ExpCardPresent(int sd, int slotRef) } int -dlp_ExpCardInfo(int sd, int slotRef, unsigned long *flags, int *numStrings, - char **strings) +dlp_ExpCardInfo(int sd, int slotRef, unsigned long *flags, int *numStrings, char **strings) { int result; struct dlpRequest* req; struct dlpResponse* res; RequireDLPVersion(sd,1,2); - TraceX(dlp_ExpCardInfo,"slotRef=%d",slotRef); + TraceX(dlp_ExpCardInfo, "slotRef=%d", slotRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncExpCardInfo, 1, 2); @@ -3856,7 +3715,7 @@ dlp_ExpCardInfo(int sd, int slotRef, unsigned long *flags, int *numStrings, result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { *flags = get_long(DLP_RESPONSE_DATA (res, 0, 0)); *numStrings = get_byte(DLP_RESPONSE_DATA (res, 0, 4)); @@ -3876,8 +3735,8 @@ dlp_ExpCardInfo(int sd, int slotRef, unsigned long *flags, int *numStrings, } LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ExpCardInfo flags: 0x%08lx numStrings: %d\n", - *flags, *numStrings)); + "DLP ExpCardInfo flags: 0x%08lx numStrings: %d\n", + *flags, *numStrings)); } dlp_response_free(res); @@ -3886,70 +3745,64 @@ dlp_ExpCardInfo(int sd, int slotRef, unsigned long *flags, int *numStrings, } int -dlp_VFSGetDefaultDir(int sd, int volRefNum, const char *type, char *dir, - int *len) +dlp_VFSGetDefaultDir(int sd, int volRefNum, const char *type, char *dir, int *len) { int result, buflen; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSGetDefaultDir,"volRefNum=%d",volRefNum); + TraceX(dlp_VFSGetDefaultDir, "volRefNum=%d", volRefNum); pi_reset_errors(sd); - - req = dlp_request_new(dlpFuncVFSGetDefaultDir, - 1, 2 + (strlen(type) + 1)); + + req = dlp_request_new(dlpFuncVFSGetDefaultDir, 1, 2 + (strlen(type) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); set_short(DLP_REQUEST_DATA(req, 0, 0), volRefNum); strcpy(DLP_REQUEST_DATA(req, 0, 2), type); - + result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { buflen = get_short(DLP_RESPONSE_DATA (res, 0, 0)); - + if (*len < buflen + 1) result = pi_set_error(sd, PI_ERR_DLP_BUFSIZE); else { if (buflen) - strncpy(dir, DLP_RESPONSE_DATA (res, 0, 2), - (size_t)buflen); + strncpy(dir, DLP_RESPONSE_DATA (res, 0, 2), (size_t)buflen); else dir[0] = '\0'; - + *len = buflen; - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Default dir is %s\n", dir)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "Default dir is %s\n", dir)); } } - + dlp_response_free(res); - + return result; } int dlp_VFSImportDatabaseFromFile(int sd, int volRefNum, const char *path, - int *cardno, unsigned long *localid) + int *cardno, unsigned long *localid) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSImportDatabaseFromFile,"volRefNum=%d path='%s'",volRefNum,path); + TraceX(dlp_VFSImportDatabaseFromFile, "volRefNum=%d path='%s'", volRefNum,path); pi_reset_errors(sd); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Import file <%s>%d\n", path)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "Import file <%s>%d\n", path)); - req = dlp_request_new(dlpFuncVFSImportDatabaseFromFile, - 1, 2 + (strlen(path) + 1)); + req = dlp_request_new(dlpFuncVFSImportDatabaseFromFile, 1, 2 + (strlen(path) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -3964,34 +3817,33 @@ dlp_VFSImportDatabaseFromFile(int sd, int volRefNum, const char *path, if (cardno) *cardno = get_short(DLP_RESPONSE_DATA (res, 0, 0)); if (localid) - *localid = get_short(DLP_RESPONSE_DATA (res, 0, 2)); + *localid = get_short(DLP_RESPONSE_DATA (res, 0, 2)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Database imported as: cardNo:%d dbID:%d\n", - get_short(DLP_RESPONSE_DATA (res, 0, 0)), - get_short(DLP_RESPONSE_DATA (res, 0, 2)))); + "Database imported as: cardNo:%d dbID:%d\n", + get_short(DLP_RESPONSE_DATA (res, 0, 0)), + get_short(DLP_RESPONSE_DATA (res, 0, 2)))); } - + dlp_response_free(res); return result; } int -dlp_VFSExportDatabaseToFile(int sd, int volRefNum, const char *path, - int cardno, unsigned int localid) +dlp_VFSExportDatabaseToFile(int sd, int volRefNum, const char *path, + int cardno, unsigned int localid) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); TraceX(dlp_VFSExportDatabaseToFile,"cardno=%d localid=0x%08lx volRefNum=%d path='%s'", - cardno,(long)localid,volRefNum,path); + cardno, (long)localid, volRefNum, path); pi_reset_errors(sd); - req = dlp_request_new(dlpFuncVFSExportDatabaseToFile, - 1, 8 + (strlen(path) + 1)); + req = dlp_request_new(dlpFuncVFSExportDatabaseToFile, 1, 8 + (strlen(path) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -4011,12 +3863,12 @@ dlp_VFSExportDatabaseToFile(int sd, int volRefNum, const char *path, int dlp_VFSFileCreate(int sd, int volRefNum, const char *name) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileCreate,"volRefNum=%d name='%s'",volRefNum,name); + TraceX(dlp_VFSFileCreate, "volRefNum=%d name='%s'", volRefNum,name); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileCreate, 1, 2 + (strlen(name) + 1)); @@ -4035,16 +3887,14 @@ dlp_VFSFileCreate(int sd, int volRefNum, const char *name) } int -dlp_VFSFileOpen(int sd, int volRefNum, const char *path, int openMode, - FileRef *fileRef) +dlp_VFSFileOpen(int sd, int volRefNum, const char *path, int openMode, FileRef *fileRef) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileOpen,"volRefNum=%d mode=0x%04x path='%s'", - volRefNum,openMode,path); + TraceX(dlp_VFSFileOpen,"volRefNum=%d mode=0x%04x path='%s'", volRefNum, openMode, path); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileOpen, 1, 4 + (strlen (path) + 1)); @@ -4058,14 +3908,12 @@ dlp_VFSFileOpen(int sd, int volRefNum, const char *path, int openMode, result = dlp_exec (sd, req, &res); dlp_request_free (req); - + if (result > 0) { *fileRef = get_long(DLP_RESPONSE_DATA (res, 0, 0)); - - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "OpenFileRef: 0x%x\n", *fileRef)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "OpenFileRef: 0x%x\n", *fileRef)); } - + dlp_response_free(res); return result; @@ -4074,12 +3922,12 @@ dlp_VFSFileOpen(int sd, int volRefNum, const char *path, int openMode, int dlp_VFSFileClose(int sd, FileRef fileRef) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileClose,"fileRef=%ld",fileRef); + TraceX(dlp_VFSFileClose, "fileRef=%ld", fileRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileClose, 1, 4); @@ -4092,9 +3940,8 @@ dlp_VFSFileClose(int sd, FileRef fileRef) dlp_request_free (req); dlp_response_free (res); - - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Closed FileRef: %x\n", fileRef)); + + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "Closed FileRef: %x\n", fileRef)); return result; } @@ -4102,17 +3949,16 @@ dlp_VFSFileClose(int sd, FileRef fileRef) int dlp_VFSFileWrite(int sd, FileRef fileRef, const void *data, size_t len) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res = NULL; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileWrite,"fileRef=%ld len=%ld",(long)fileRef,(long)len); + TraceX(dlp_VFSFileWrite, "fileRef=%ld len=%ld", (long)fileRef, (long)len); pi_reset_errors(sd); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Write to FileRef: %x bytes %d\n", fileRef, len)); - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "Write to FileRef: %x bytes %d\n", fileRef, len)); + req = dlp_request_new (dlpFuncVFSFileWrite, 1, 8); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -4128,8 +3974,7 @@ dlp_VFSFileWrite(int sd, FileRef fileRef, const void *data, size_t len) int bytes = pi_write (sd, data, len); result = bytes; if (result < (int)len) { - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "send failed %d\n", result)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "send failed %d\n", result)); } else { dlp_response_free (res); res = NULL; @@ -4139,10 +3984,10 @@ dlp_VFSFileWrite(int sd, FileRef fileRef, const void *data, size_t len) if (result > 0) { pi_set_palmos_error(sd, get_short(DLP_RESPONSE_DATA (res, 0, 2))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "send success (%d) res 0x%04x!\n", len, pi_palmos_error(sd))); + "send success (%d) res 0x%04x!\n", len, pi_palmos_error(sd))); result = bytes; } - } + } } dlp_response_free (res); @@ -4153,7 +3998,7 @@ dlp_VFSFileWrite(int sd, FileRef fileRef, const void *data, size_t len) int dlp_VFSFileRead(int sd, FileRef fileRef, pi_buffer_t *data, size_t len) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; size_t bytes = 0; @@ -4161,7 +4006,7 @@ dlp_VFSFileRead(int sd, FileRef fileRef, pi_buffer_t *data, size_t len) size_t opt_size = sizeof(int); RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileRead,"fileRef=%ld len=%ld",(long)fileRef,(long)len); + TraceX(dlp_VFSFileRead, "fileRef=%ld len=%ld", (long)fileRef, (long)len); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileRead, 1, 8); @@ -4176,7 +4021,7 @@ dlp_VFSFileRead(int sd, FileRef fileRef, pi_buffer_t *data, size_t len) */ pi_setsockopt(sd, PI_LEVEL_PADP, PI_PADP_FREEZE_TXID, &freeze_txid, &opt_size); - result = dlp_exec (sd, req, &res); + result = dlp_exec (sd, req, &res); dlp_request_free (req); @@ -4193,8 +4038,8 @@ dlp_VFSFileRead(int sd, FileRef fileRef, pi_buffer_t *data, size_t len) } while (result > 0 && len > 0); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "dlp_VFSFileRead: read %u bytes (last pi_read was %d)\n", - (unsigned)bytes, result)); + "dlp_VFSFileRead: read %u bytes (last pi_read was %d)\n", + (unsigned)bytes, result)); if (result >= 0) result = bytes; @@ -4211,21 +4056,21 @@ dlp_VFSFileRead(int sd, FileRef fileRef, pi_buffer_t *data, size_t len) int dlp_VFSFileDelete(int sd, int volRefNum, const char *path) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileDelete,"volRefNum=%d path='%s'",volRefNum,path); + TraceX(dlp_VFSFileDelete, "volRefNum=%d path='%s'", volRefNum,path); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileDelete, 1, 2 + (strlen (path) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + set_short (DLP_REQUEST_DATA (req, 0, 0), volRefNum); strcpy (DLP_REQUEST_DATA (req, 0, 2), path); - + result = dlp_exec (sd, req, &res); dlp_request_free (req); @@ -4235,20 +4080,18 @@ dlp_VFSFileDelete(int sd, int volRefNum, const char *path) } int -dlp_VFSFileRename(int sd, int volRefNum, const char *path, - const char *newname) +dlp_VFSFileRename(int sd, int volRefNum, const char *path, const char *newname) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileRename,"volRefNum=%d file '%s' renamed '%s'", - volRefNum,path,rename); + TraceX(dlp_VFSFileRename, "volRefNum=%d file '%s' renamed '%s'", volRefNum, path, rename); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileRename, - 1, 4 + (strlen (path) + 1) + (strlen (newname) + 1)); + 1, 4 + (strlen (path) + 1) + (strlen (newname) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -4256,7 +4099,7 @@ dlp_VFSFileRename(int sd, int volRefNum, const char *path, set_short (DLP_REQUEST_DATA (req, 0, 2), 2); strcpy (DLP_REQUEST_DATA (req, 0, 4), path); strcpy (DLP_REQUEST_DATA (req, 0, 4 + (strlen(path) + 1)), newname); - + result = dlp_exec (sd, req, &res); dlp_request_free (req); @@ -4268,22 +4111,22 @@ dlp_VFSFileRename(int sd, int volRefNum, const char *path, int dlp_VFSFileEOF(int sd, FileRef fileRef) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileEOF,"fileRef=%ld",fileRef); + TraceX(dlp_VFSFileEOF, "fileRef=%ld", fileRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileEOF, 1, 4); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); - + result = dlp_exec (sd, req, &res); - + dlp_request_free (req); dlp_response_free (res); @@ -4293,12 +4136,12 @@ dlp_VFSFileEOF(int sd, FileRef fileRef) int dlp_VFSFileTell(int sd, FileRef fileRef,int *position) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileTell,"fileRef=%ld",fileRef); + TraceX(dlp_VFSFileTell, "fileRef=%ld", fileRef); pi_reset_errors(sd); req = dlp_request_new(dlpFuncVFSFileTell, 1, 4); @@ -4308,13 +4151,13 @@ dlp_VFSFileTell(int sd, FileRef fileRef,int *position) set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); result = dlp_exec (sd, req, &res); - + dlp_request_free (req); if (result > 0) { *position = get_long (DLP_RESPONSE_DATA (res, 0, 0)); } - + dlp_response_free (res); return result; @@ -4324,28 +4167,28 @@ int dlp_VFSFileGetAttributes (int sd, FileRef fileRef, unsigned long *attributes) { int result; - struct dlpRequest *req; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileGetAttributes,"fileRef=%ld",fileRef); + TraceX(dlp_VFSFileGetAttributes, "fileRef=%ld", fileRef); pi_reset_errors(sd); - + req = dlp_request_new (dlpFuncVFSFileGetAttributes, 1, 4); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); - + result = dlp_exec (sd, req, &res); - + dlp_request_free (req); if (result > 0) { *attributes = get_long (DLP_RESPONSE_DATA (res, 0, 0)); } - dlp_response_free(res); + dlp_response_free(res); return result; } @@ -4354,12 +4197,11 @@ int dlp_VFSFileSetAttributes(int sd, FileRef fileRef, unsigned long attributes) { int result; - struct dlpRequest *req; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileSetAttributes,"fileRef=%ld attributes=0x%08lx", - fileRef,attributes); + TraceX(dlp_VFSFileSetAttributes, "fileRef=%ld attributes=0x%08lx", fileRef, attributes); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileSetAttributes, 1, 8); @@ -4368,7 +4210,7 @@ dlp_VFSFileSetAttributes(int sd, FileRef fileRef, unsigned long attributes) set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); set_long (DLP_REQUEST_DATA (req, 0, 4), attributes); - + result = dlp_exec (sd, req, &res); dlp_request_free (req); @@ -4381,11 +4223,11 @@ int dlp_VFSFileGetDate(int sd, FileRef fileRef, int which, time_t *date) { int result; - struct dlpRequest *req; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileGetDate,"fileRef=%ld which=%d",fileRef,which); + TraceX(dlp_VFSFileGetDate, "fileRef=%ld which=%d", fileRef, which); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileGetDate, 1, 6); @@ -4398,17 +4240,16 @@ dlp_VFSFileGetDate(int sd, FileRef fileRef, int which, time_t *date) result = dlp_exec (sd, req, &res); dlp_request_free (req); - + if (result > 0) { *date = get_long (DLP_RESPONSE_DATA (res, 0, 0)) - 2082852000; - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Requested date(%d): %d / %x calc %d / %x\n",which, - get_long(DLP_RESPONSE_DATA (res, 0, 0)), - get_long(DLP_RESPONSE_DATA (res, 0, 0)), - *date,*date)); + "Requested date(%d): %d / %x calc %d / %x\n", which, + get_long(DLP_RESPONSE_DATA (res, 0, 0)), + get_long(DLP_RESPONSE_DATA (res, 0, 0)), *date, *date)); } - + dlp_response_free (res); return result; @@ -4420,10 +4261,10 @@ dlp_VFSFileSetDate(int sd, FileRef fileRef, int which, time_t date) int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileSetDate,"fileRef=%ld which=%d date=0x%08lx", - (long)fileRef,which,(long)date); + TraceX(dlp_VFSFileSetDate, "fileRef=%ld which=%d date=0x%08lx", + (long)fileRef, which, (long)date); pi_reset_errors(sd); req = dlp_request_new(dlpFuncVFSFileSetDate, 1, 10); @@ -4437,7 +4278,7 @@ dlp_VFSFileSetDate(int sd, FileRef fileRef, int which, time_t date) result = dlp_exec (sd, req, &res); dlp_request_free (req); - dlp_response_free (res); + dlp_response_free (res); return result; } @@ -4445,12 +4286,12 @@ dlp_VFSFileSetDate(int sd, FileRef fileRef, int which, time_t date) int dlp_VFSDirCreate(int sd, int volRefNum, const char *path) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSDirCreate,"volRefNum=%d path='%s'",volRefNum,path); + TraceX(dlp_VFSDirCreate, "volRefNum=%d path='%s'", volRefNum, path); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSDirCreate, 1, 2 + (strlen(path) + 1)); @@ -4459,7 +4300,7 @@ dlp_VFSDirCreate(int sd, int volRefNum, const char *path) set_short (DLP_REQUEST_DATA (req, 0, 0), volRefNum); strcpy (DLP_REQUEST_DATA (req, 0, 2), path); - + result = dlp_exec (sd, req, &res); dlp_request_free (req); @@ -4469,20 +4310,20 @@ dlp_VFSDirCreate(int sd, int volRefNum, const char *path) } int -dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, - unsigned long *dirIterator, int *maxDirItems, struct VFSDirInfo *data) +dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, + unsigned long *dirIterator, int *maxDirItems, struct VFSDirInfo *data) { unsigned int result, - entries, - from, - at, - slen, - count; + entries, + from, + at, + slen, + count; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSDirEntryEnumerate,"dirRef=%ld",dirRefNum); + TraceX(dlp_VFSDirEntryEnumerate, "dirRef=%ld", dirRefNum); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSDirEntryEnumerate, 1, 12); @@ -4494,9 +4335,9 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, set_long (DLP_REQUEST_DATA (req, 0, 8), 8 + *maxDirItems * (4 + vfsMAXFILENAME)); result = dlp_exec (sd, req, &res); - + dlp_request_free (req); - + if (result > 0) { if (result) { *dirIterator = get_long (DLP_RESPONSE_DATA (res, 0, 0)); @@ -4507,15 +4348,14 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, } LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "%d results returnd (ilterator: %d)\n", entries, - *dirIterator)); - + "%d results returnd (ilterator: %d)\n", entries, *dirIterator)); + from = 8; count = 0; - + for (at = 0; at < entries; at++) { if (*maxDirItems > at) { - data[at].attr = + data[at].attr = get_long(DLP_RESPONSE_DATA (res, 0, from)); /* fix for Sony sims (and probably devices too): they return @@ -4527,38 +4367,36 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, data[at].attr >>= 16; strncpy (data[at].name, - DLP_RESPONSE_DATA(res, 0, from + 4), - vfsMAXFILENAME); + DLP_RESPONSE_DATA(res, 0, from + 4), vfsMAXFILENAME); data[at].name[vfsMAXFILENAME-1] = 0; count++; } - + /* Zero terminated string. Strings that have an even length will be null terminated and have a pad byte. */ slen = strlen (DLP_RESPONSE_DATA(res, 0, from + 4)) + 1; if (slen & 1) slen++; /* make even stringlen + NULL */ - + /* 6 = 4 (attr) + 1 (NULL) -+ 1 (PADDING) */ from += slen + 4; } *maxDirItems = count; } - + dlp_response_free (res); - return result; + return result; } int -dlp_VFSVolumeFormat(int sd, unsigned char flags, - int fsLibRef, struct VFSSlotMountParam *param) +dlp_VFSVolumeFormat(int sd, unsigned char flags, int fsLibRef, struct VFSSlotMountParam *param) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); Trace(dlp_VFSVolumeFormat); pi_reset_errors(sd); @@ -4569,17 +4407,16 @@ dlp_VFSVolumeFormat(int sd, unsigned char flags, /* FIXME check sizes, list the mount params properly */ set_short(DLP_REQUEST_DATA(req, 0, 0), fsLibRef); - set_short(DLP_REQUEST_DATA(req, 0, 2), - sizeof(struct VFSSlotMountParam)); + set_short(DLP_REQUEST_DATA(req, 0, 2), sizeof(struct VFSSlotMountParam)); set_byte(DLP_REQUEST_DATA(req, 0, 4), flags); set_byte(DLP_REQUEST_DATA(req, 0, 4), 0); /* unused */ set_short(DLP_REQUEST_DATA(req, 0, 6), param->vfsMountParam.volRefNum); - set_short(DLP_REQUEST_DATA(req, 0, 8), param->vfsMountParam.reserved); + set_short(DLP_REQUEST_DATA(req, 0, 8), param->vfsMountParam.reserved); set_long(DLP_REQUEST_DATA(req, 0, 10), param->vfsMountParam.mountClass); set_short(DLP_REQUEST_DATA(req, 0, 14), param->slotLibRefNum); - set_short(DLP_REQUEST_DATA(req, 0, 16), param->slotRefNum); - + set_short(DLP_REQUEST_DATA(req, 0, 16), param->slotRefNum); + result = dlp_exec(sd, req, &res); dlp_request_free(req); @@ -4594,7 +4431,7 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); Trace(dlp_VFSVolumeEnumerate); pi_reset_errors(sd); @@ -4603,26 +4440,21 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - result = dlp_exec (sd, req, &res); - - dlp_request_free (req); + result = dlp_exec(sd, req, &res); + + dlp_request_free(req); if (result > 0) { int vols, i; - vols = get_short (DLP_RESPONSE_DATA (res, 0, 0)); + vols = get_short(DLP_RESPONSE_DATA (res, 0, 0)); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP VFSVolumeEnumerate %d\n", vols)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP VFSVolumeEnumerate %d\n", vols)); if (vols) { for (i = 0; i < vols && i < *numVols; i++) { - volRefs[i] = - get_short (DLP_RESPONSE_DATA (res, - 0, 2 + (2 * i))); - - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " %d Volume-Refnum %d\n", i, volRefs[i])); + volRefs[i] = get_short(DLP_RESPONSE_DATA (res, 0, 2 + (2 * i))); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, " %d Volume-Refnum %d\n", i, volRefs[i])); } } *numVols = vols; @@ -4630,7 +4462,7 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) else *numVols = 0; - dlp_response_free (res); + dlp_response_free(res); return result; } @@ -4638,12 +4470,12 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) int dlp_VFSVolumeInfo(int sd, int volRefNum, struct VFSInfo *volInfo) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSVolumeInfo,"volRefNum=%d",volRefNum); + TraceX(dlp_VFSVolumeInfo, "volRefNum=%d", volRefNum); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSVolumeInfo, 1, 2); @@ -4652,68 +4484,66 @@ dlp_VFSVolumeInfo(int sd, int volRefNum, struct VFSInfo *volInfo) set_short (DLP_REQUEST_DATA(req, 0, 0), volRefNum); - result = dlp_exec (sd, req, &res); + result = dlp_exec(sd, req, &res); + + dlp_request_free(req); - dlp_request_free (req); - if (result > 0) { volInfo->attributes = get_long (DLP_RESPONSE_DATA (res, 0, 0)); - volInfo->fsType = get_long (DLP_RESPONSE_DATA (res, 0, 4)); + volInfo->fsType = get_long (DLP_RESPONSE_DATA (res, 0, 4)); volInfo->fsCreator = get_long (DLP_RESPONSE_DATA (res, 0, 8)); volInfo->mountClass = get_long (DLP_RESPONSE_DATA (res, 0, 12)); volInfo->slotLibRefNum = get_short (DLP_RESPONSE_DATA (res, 0, 16)); volInfo->slotRefNum = get_short (DLP_RESPONSE_DATA (res, 0, 18)); volInfo->mediaType = get_long (DLP_RESPONSE_DATA (res, 0, 20)); - volInfo->reserved = get_long (DLP_RESPONSE_DATA (res, 0, 24)); + volInfo->reserved = get_long (DLP_RESPONSE_DATA (res, 0, 24)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "VFSVolumeInfo: fstype '%s' ", printlong(volInfo->fsType))); - + "VFSVolumeInfo: fstype '%s' ", printlong(volInfo->fsType))); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "fscreator: '%s'\nSlotlibref %d Slotref %d\n", - printlong(volInfo->fsCreator), - volInfo->slotLibRefNum, - volInfo->slotRefNum)); - + "fscreator: '%s'\nSlotlibref %d Slotref %d\n", + printlong(volInfo->fsCreator), + volInfo->slotLibRefNum, + volInfo->slotRefNum)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Media: '%s'\n", printlong(volInfo->mediaType))); + "Media: '%s'\n", printlong(volInfo->mediaType))); } - + dlp_response_free(res); - + return result; } int dlp_VFSVolumeGetLabel(int sd, int volRefNum, int *len, char *name) { - int result; - struct dlpRequest *req; + int result; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSVolumeGetLabel,"volRefNum=%d",volRefNum); + TraceX(dlp_VFSVolumeGetLabel, "volRefNum=%d", volRefNum); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSVolumeGetLabel, 1, 2); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_short (DLP_REQUEST_DATA (req, 0, 0), volRefNum); - - result = dlp_exec (sd, req, &res); - - dlp_request_free (req); + set_short(DLP_REQUEST_DATA (req, 0, 0), volRefNum); + + result = dlp_exec(sd, req, &res); + + dlp_request_free(req); if (result > 0) { - strncpy(name, DLP_RESPONSE_DATA(res, 0, 0), - (size_t)(*len - 1)); + strncpy(name, DLP_RESPONSE_DATA(res, 0, 0), (size_t)(*len - 1)); *len = strlen(name); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP VFSVolumeGetLabel %s\n", name)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP VFSVolumeGetLabel %s\n", name)); } - + dlp_response_free(res); return result; @@ -4722,62 +4552,60 @@ dlp_VFSVolumeGetLabel(int sd, int volRefNum, int *len, char *name) int dlp_VFSVolumeSetLabel(int sd, int volRefNum, const char *name) { - int result; - struct dlpRequest *req; + int result; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSVolumeSetLabel,"volRefNum=%d name='%s'",volRefNum,name); + TraceX(dlp_VFSVolumeSetLabel, "volRefNum=%d name='%s'", volRefNum,name); pi_reset_errors(sd); - req = dlp_request_new (dlpFuncVFSVolumeSetLabel, 1, - 2 + (strlen(name) + 1)); + req = dlp_request_new (dlpFuncVFSVolumeSetLabel, 1, 2 + (strlen(name) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_short (DLP_REQUEST_DATA (req, 0, 0), volRefNum); - strcpy (DLP_REQUEST_DATA (req, 0, 2), name); + set_short(DLP_REQUEST_DATA (req, 0, 0), volRefNum); + strcpy(DLP_REQUEST_DATA (req, 0, 2), name); - result = dlp_exec (sd, req, &res); + result = dlp_exec(sd, req, &res); - dlp_response_free (res); - dlp_request_free (req); + dlp_response_free(res); + dlp_request_free(req); return result; } int -dlp_VFSVolumeSize(int sd, int volRefNum, long *volSizeUsed, - long *volSizeTotal) +dlp_VFSVolumeSize(int sd, int volRefNum, long *volSizeUsed, long *volSizeTotal) { - int result; - struct dlpRequest *req; + int result; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSVolumeSize,"volRefNum=%d",volRefNum); + TraceX(dlp_VFSVolumeSize, "volRefNum=%d", volRefNum); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSVolumeSize, 1, 2); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_short (DLP_REQUEST_DATA (req, 0, 0), volRefNum); + set_short(DLP_REQUEST_DATA (req, 0, 0), volRefNum); - result = dlp_exec (sd, req, &res); + result = dlp_exec(sd, req, &res); + + dlp_request_free(req); - dlp_request_free (req); - if (result > 0) { *volSizeUsed = get_long (DLP_RESPONSE_DATA (res, 0, 0)); *volSizeTotal = get_long (DLP_RESPONSE_DATA (res, 0, 4)); - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP VFS Volume Size total: %d used: %d\n", - *volSizeTotal, *volSizeUsed)); + "DLP VFS Volume Size total: %d used: %d\n", + *volSizeTotal, *volSizeUsed)); } - dlp_response_free (res); + dlp_response_free(res); return result; } @@ -4785,27 +4613,26 @@ dlp_VFSVolumeSize(int sd, int volRefNum, long *volSizeUsed, int dlp_VFSFileSeek(int sd, FileRef fileRef, int origin, int offset) { - int result; - struct dlpRequest *req; + int result; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileSeek,"fileRef=%ld origin=%d offset=%d", - fileRef,origin,offset); + TraceX(dlp_VFSFileSeek, "fileRef=%ld origin=%d offset=%d", fileRef, origin, offset); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileSeek, 1, 10); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); - set_short (DLP_REQUEST_DATA (req, 0, 4), origin); - set_long (DLP_REQUEST_DATA (req, 0, 6), offset); + set_long(DLP_REQUEST_DATA (req, 0, 0), fileRef); + set_short(DLP_REQUEST_DATA (req, 0, 4), origin); + set_long(DLP_REQUEST_DATA (req, 0, 6), offset); - result = dlp_exec (sd, req, &res); + result = dlp_exec(sd, req, &res); - dlp_request_free (req); - dlp_response_free (res); + dlp_request_free(req); + dlp_response_free(res); return result; } @@ -4813,12 +4640,12 @@ dlp_VFSFileSeek(int sd, FileRef fileRef, int origin, int offset) int dlp_VFSFileResize(int sd, FileRef fileRef, int newSize) { - int result; - struct dlpRequest *req; + int result; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileResize,"fileRef=%ld newSize=%d",fileRef,newSize); + TraceX(dlp_VFSFileResize, "fileRef=%ld newSize=%d", fileRef, newSize); pi_reset_errors(sd); req = dlp_request_new(dlpFuncVFSFileResize, 1, 8); @@ -4827,44 +4654,42 @@ dlp_VFSFileResize(int sd, FileRef fileRef, int newSize) set_long(DLP_REQUEST_DATA(req, 0, 0), fileRef); set_long(DLP_REQUEST_DATA(req, 0, 4), newSize); - + result = dlp_exec(sd, req, &res); - dlp_request_free (req); - dlp_response_free (res); - + dlp_request_free(req); + dlp_response_free(res); + return result; } int dlp_VFSFileSize(int sd, FileRef fileRef, int *size) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileSize,"fileRef=%ld",fileRef); + TraceX(dlp_VFSFileSize, "fileRef=%ld", fileRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileSize, 1, 4); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); - - result = dlp_exec (sd, req, &res); - - dlp_request_free (req); - - if (result > 0) { - *size = get_long (DLP_RESPONSE_DATA (res, 0, 0)); + set_long(DLP_REQUEST_DATA (req, 0, 0), fileRef); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP VFS File Size: %d\n", *size)); + result = dlp_exec(sd, req, &res); + + dlp_request_free(req); + + if (result > 0) { + *size = get_long(DLP_RESPONSE_DATA (res, 0, 0)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP VFS File Size: %d\n", *size)); } - - dlp_response_free (res); + + dlp_response_free(res); return result; } @@ -4872,33 +4697,32 @@ dlp_VFSFileSize(int sd, FileRef fileRef, int *size) int dlp_ExpSlotMediaType(int sd, int slotNum, unsigned long *mediaType) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1, 4); - TraceX(dlp_ExpSlotMediaType,"slotNum=%d",slotNum); + TraceX(dlp_ExpSlotMediaType, "slotNum=%d", slotNum); pi_reset_errors(sd); - req = dlp_request_new (dlpFuncExpSlotMediaType, 1, 2); + req = dlp_request_new(dlpFuncExpSlotMediaType, 1, 2); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_short (DLP_REQUEST_DATA (req, 0, 0), slotNum); + set_short(DLP_REQUEST_DATA (req, 0, 0), slotNum); - result = dlp_exec (sd, req, &res); + result = dlp_exec(sd, req, &res); - dlp_request_free (req); + dlp_request_free(req); if (result > 0) { - *mediaType = get_long (DLP_RESPONSE_DATA (res, 0, 0)); + *mediaType = get_long(DLP_RESPONSE_DATA (res, 0, 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP Media Type for slot %d: %4.4s\n", - slotNum, mediaType)); + "DLP Media Type for slot %d: %4.4s\n", slotNum, mediaType)); } - dlp_response_free (res); + dlp_response_free(res); return result; } From f3acfa1858c55f83cb895538475c50e6926048f9 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Fri, 14 Mar 2025 14:29:37 +0100 Subject: [PATCH 07/31] Fixed issue #9 in https://github.com/desrod/pilot-link/. --- libpisock/dlp.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/libpisock/dlp.c b/libpisock/dlp.c index 3132d8cc..f839f7b1 100644 --- a/libpisock/dlp.c +++ b/libpisock/dlp.c @@ -4313,12 +4313,8 @@ int dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, unsigned long *dirIterator, int *maxDirItems, struct VFSDirInfo *data) { - unsigned int result, - entries, - from, - at, - slen, - count; + int result; + unsigned int entries, from, at, slen, count; struct dlpRequest *req; struct dlpResponse *res; @@ -4339,13 +4335,8 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, dlp_request_free (req); if (result > 0) { - if (result) { - *dirIterator = get_long (DLP_RESPONSE_DATA (res, 0, 0)); - entries = get_long (DLP_RESPONSE_DATA (res, 0, 4)); - } else { - *dirIterator = vfsIteratorStop; - entries = 0; - } + *dirIterator = get_long (DLP_RESPONSE_DATA (res, 0, 0)); + entries = get_long (DLP_RESPONSE_DATA (res, 0, 4)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "%d results returnd (ilterator: %d)\n", entries, *dirIterator)); @@ -4383,6 +4374,9 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, from += slen + 4; } *maxDirItems = count; + } else { + *dirIterator = (unsigned long)vfsIteratorStop; + entries = 0; } dlp_response_free (res); From 029803368763ce3f7b38fcc38d29df798a623b89 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Fri, 14 Mar 2025 20:50:45 +0100 Subject: [PATCH 08/31] Stripped trailing white space in README. --- README | 64 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/README b/README index cd640bde..41a42a5e 100644 --- a/README +++ b/README @@ -43,7 +43,7 @@ List archive........: https://web.archive.org/web/2015/http://lists.pilot-link.o The architecture of pilot-link ------------------------------ -There are several core parts of pilot-link: +There are several core parts of pilot-link: The libraries ------------- @@ -79,7 +79,7 @@ There are several core parts of pilot-link: your favorite language of choice. Currently, pilot-link includes language "bindings" in Perl, Python, Java, and Tcl. This means you can use those languages, instead of C directly, to talk to your Palm - handheld device and communicate with it. + handheld device and communicate with it. Want to write a Java application that uses pilot-link's libraries? Simple! Just use the Java bindings. @@ -152,12 +152,12 @@ Building pilot-link on Linux/Unix systems software. $ make - + After the source builds, feel free to play around in the 'src' subdirectory, CAREFULLY. 'pilot-dlpsh' and 'pilot-xfer' are probably the most useful programs for you, and also the safest to use non-destructively. - + Once you have determined that pilot-link works and suits your needs by testing with these programs, switch to the super user, typically "root", to install the conduits, libraries, docs, and headers @@ -175,7 +175,7 @@ Building pilot-link on Linux/Unix systems # make install -Building pilot-link on OS/2 +Building pilot-link on OS/2 --------------------------- pilot-link on OS/2 only supports serial devices. USB is unsupported @@ -187,17 +187,17 @@ Building pilot-link on OS/2 The steps are fairly straightforward. - Run the os2configure.cmd script in the top-level directory. - + Run the os2configure.cmd script in the top-level directory. + Run make -f Makefile.os2 - + Play around, CAREFULLY. pilot-xfer is probably the most useful program for you, and also the safest of all to use non-destructively. Also dlpsh is a good app to use to poke around in your Palm device. - + Run 'make install' if you you have tested thoroughly and are sure pilot-link works well for you. - + Note on pilot-debug: This program is a work-in-progress, and requires Tcl 7.5 (or greater) and optionally Tk 4.1 (or greater) and/or Readline 2.0. You'll need to modify Makefile to to use Readline 2.0, @@ -269,15 +269,15 @@ Building pilot-link on Apple OSX/Darwin first. The syntax to test pilot-link on OSX for USB devices is as follows: - -p usb: [arguments..] + -p usb: [arguments..] - One example of this is as follows: + One example of this is as follows: pilot-xfer --port usb: --list This should list the record and resource databases found on your Palm handheld device. - + Building pilot-link on Cygwin under Windows ------------------------------------------- @@ -287,10 +287,10 @@ Building pilot-link on Cygwin under Windows Some usage notes about pilot-link --------------------------------- - + read-ical and sync-ical will only run if you have ical-2.x installed and in the path. - + sync-plan is a full syncronization program, though it has some interesting quirks and requirements. You must run netplan from plan-1.6.1 (probably available at @@ -301,16 +301,16 @@ Some usage notes about pilot-link moment. Sync-plan leaves a file, that has a name starting with "pilothash", in the current directory. This file must be present for all future syncs between that plan database and that Palm. - + As sync-plan is a work in progress, please contact me with any problems. - + The default connection rate is 9600 baud. You are welcome to try higher baud rates (19200, 38400, or 57600) by setting the PILOTRATE environment variable, but various machines have various limitations. (Be careful about 38400 on a Linux box if you've been using setserial to change the multiplier.) - + pilot-mail (which requires a Palm with the new Mail application, as well as sendmail and/or a POP3 server) is still in the experimental stage. Run with an argument of '-H' for help. While I don't expect @@ -322,7 +322,7 @@ Some usage notes about pilot-link If you wish, you may easily change the default settings (pop host, password, etc.) for pilot-mail by editing the top of pilot-mail.c, as well as by setting the environment variables indicated in its help. - + Scott Grosch's "validate" program is included, and can be made via 'make validate', but it may not be of use to anyone but Scott. @@ -338,18 +338,18 @@ Debugging notes USB Notes --------- - + Please see doc/README.usb for more detailed information on configuring your system to use USB-enabled Palm handheld devices using the standard Linux "visor" kernel module. If you would like to try the new libusb code, please see doc/README.libusb for details on how to get that working properly. - + FreeBSD Notes ------------- - + Please see doc/README.freebsd for more detailed information on setting up pilot-link to work with FreeBSD systems. In FreeBSD, you may have to set your ACLOCAL_FLAGS="-I /usr/local/share/aclocal/" @@ -368,32 +368,32 @@ FreeBSD Notes Embedding information --------------------- - + As of 0.5.0, the headers in pilot-link have been rearranged slightly so that it should be easier and more reliable to use the libpisock.a library in external applications. - + If you want to use the pilot-link portability layer (configured via autoconf), then include pi-source.h. Otherwise, do not touch this file, as it sets up a mildly complex environment. - + For all normal operations, simply include the obvious files (pi-file - for pdb and .prc file access, pi-dlp for DLP sync functions, etc.). + for pdb and .prc file access, pi-dlp for DLP sync functions, etc.). pi-macros contains the portable byte-access routines. Reporting Bugs -------------- - + Please visit https://github.com/desrod/pilot-link/issues to report any bugs you find with pilot-link. From there, any issue reported can be - updated, audited, commented on, and resolved. You can also attach + updated, audited, commented on, and resolved. You can also attach other relevant items to each bug report, to help the team solve the issues or add the features you have requested. - - PLEASE NOTE + + PLEASE NOTE ----------- - + Please check the existing issues in the system FIRST before reporting your bug. There may be an identical report from another user that matches your issue. If @@ -423,7 +423,7 @@ License notes language bindings (Perl, Python, Java, and Tcl) are licensed for use under the LGPL. For more information, please see COPYING.LIB included in this source tree. - + All contained source is the copyright of its author(s). Please see the copyright notices in the individual files for more information on their individual copyrights. From 69c00f36d08797c125efad305712b185f58e1278 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Fri, 14 Mar 2025 21:55:55 +0100 Subject: [PATCH 09/31] Added chapter 'Basic use of pilot-link conduits' to README. --- README | 63 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/README b/README index 41a42a5e..eee373c8 100644 --- a/README +++ b/README @@ -14,7 +14,7 @@ Bugs and requests...: https://github.com/desrod/pilot-link/issues Code contributions..: https://github.com/desrod/pilot-link/pulls?q=is:pr If you are unwilling to use GitHub, you may instead contact me, David A. -Desrosiers, project maintainer, via email at . +Desrosiers, project maintainer, via email at . We used to be reachable on Internet Relay Chat, "irc", at irc.pilot-link.org in the channel #pilot-link. I used the name "setuid" there, and there were a @@ -285,6 +285,38 @@ Building pilot-link on Cygwin under Windows COM1 through the Cygwin virtual serial port bridging. +Basic use of pilot-link conduits +-------------------------------- + + On modern systems you probably use a USB connection to your Palm device. + For this it is recommended to use the standard Linux kernel modules + "usbserial" and "visor", which usually must be loaded first. On Debian + systems i.e. this looks as follows: + + $ sudo modprobe -a usbserial visor + + Then you can use all pilot-link commands, always with specifying a port. + Note that you must press the HotSync button on your device, before + invoking the command within few seconds at maximum. + On Debian systems i.e. type: + + $ -p /dev/ttyUSB1 [options..] [arguments..] + + Some rare devices may prefer `ttyUSB0`. + For special cases and details see the chapter below. + + +USB Notes +--------- + + Please see doc/README.usb for more detailed information on + configuring your system to use USB-enabled Palm handheld devices + using the standard Linux "visor" kernel module. + + If you would like to try the new libusb code, please see + doc/README.libusb for details on how to get that working properly. + + Some usage notes about pilot-link --------------------------------- @@ -327,26 +359,6 @@ Some usage notes about pilot-link 'make validate', but it may not be of use to anyone but Scott. -Debugging notes ---------------- - - Please see doc/README.debugging for more detailed information - describing how to debug pilot-link's core protocols and interfaces. - Debugging pilot-link will allow us to make pilot-link work better on - new devices and with new applications. - - -USB Notes ---------- - - Please see doc/README.usb for more detailed information on - configuring your system to use USB-enabled Palm handheld devices - using the standard Linux "visor" kernel module. - - If you would like to try the new libusb code, please see - doc/README.libusb for details on how to get that working properly. - - FreeBSD Notes ------------- @@ -382,6 +394,15 @@ Embedding information pi-macros contains the portable byte-access routines. +Debugging notes +--------------- + + Please see doc/README.debugging for more detailed information + describing how to debug pilot-link's core protocols and interfaces. + Debugging pilot-link will allow us to make pilot-link work better on + new devices and with new applications. + + Reporting Bugs -------------- From 0d5139031ee234952690bf946712e31253f84fe7 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Sat, 15 Mar 2025 20:00:54 +0100 Subject: [PATCH 10/31] Fixed issue #7 in https://github.com/desrod/pilot-link/. --- include/pi-dlp.h | 6 ++++-- libpisock/dlp.c | 6 ++++-- src/pilot-foto-treo650.c | 2 +- src/pilot-xfer.c | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/pi-dlp.h b/include/pi-dlp.h index 2c588edc..32f82558 100644 --- a/include/pi-dlp.h +++ b/include/pi-dlp.h @@ -1594,8 +1594,10 @@ struct dlpResponse { * @return A negative value if an error occured (see pi-error.h) */ extern PI_ERR dlp_VFSDirEntryEnumerate - PI_ARGS((int sd, FileRef dirref, unsigned long *diriterator, - int *maxitems, struct VFSDirInfo *diritems)); + PI_ARGS((int sd, FileRef dirref, + int *diriterator, int *maxitems, struct VFSDirInfo *diritems)); + // for older compilers where int is 16 bit: + // long *diriterator, int *maxitems, struct VFSDirInfo *diritems)); /** @brief Create a new directory on a VFS volume * diff --git a/libpisock/dlp.c b/libpisock/dlp.c index f839f7b1..e47dbc65 100644 --- a/libpisock/dlp.c +++ b/libpisock/dlp.c @@ -4311,7 +4311,9 @@ dlp_VFSDirCreate(int sd, int volRefNum, const char *path) int dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, - unsigned long *dirIterator, int *maxDirItems, struct VFSDirInfo *data) + int *dirIterator, int *maxDirItems, struct VFSDirInfo *data) + // for older compilers where int is 16 bit: + // long *dirIterator, int *maxDirItems, struct VFSDirInfo *data) { int result; unsigned int entries, from, at, slen, count; @@ -4375,7 +4377,7 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, } *maxDirItems = count; } else { - *dirIterator = (unsigned long)vfsIteratorStop; + *dirIterator = vfsIteratorStop; entries = 0; } diff --git a/src/pilot-foto-treo650.c b/src/pilot-foto-treo650.c index 8c54eadd..8848cc56 100644 --- a/src/pilot-foto-treo650.c +++ b/src/pilot-foto-treo650.c @@ -180,7 +180,7 @@ static void static void dump_dir(int sd, long volume, const char *path, FileRef dir) { - unsigned long it = 0; + int it = vfsIteratorStart; int max = 64; struct VFSDirInfo infos[64]; int i; diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 096a93c7..ccd243a8 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -1709,7 +1709,7 @@ print_fileinfo(const char *path, FileRef file) static void print_dir(long volume, const char *path, FileRef dir) { - unsigned long it = 0; + int it = vfsIteratorStart; int max = 64; struct VFSDirInfo infos[64]; int i; From 09bf83098d13f1974eb6fb958a4809d388ead9df Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Mon, 17 Mar 2025 13:32:24 +0100 Subject: [PATCH 11/31] Added run and debug instructions to README. --- README | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README b/README index eee373c8..6a746e59 100644 --- a/README +++ b/README @@ -143,11 +143,21 @@ Building pilot-link on Linux/Unix systems directory with your specific arguments. "./configure --help" will describe all of them. + If you want to run some of the command line programs, e.g. `pilot-xfer`, + pass autogen.sh or configure the argument: + + $ ./configure --enable-conduits + If you want to install in some place other than the default location of - /usr/local, pass configure an argument such as: + /usr/local, pass autogen.sh or configure an argument such as: $ ./configure --prefix=/home/fred/pilot + If you want you want to debug the program with Linux gdb debugger, + pass autogen.sh or configure an argument such as: + + $ ./configure CFLAGS="-ggdb -Wall" ... + If configure ran successfully, you should run 'make' to build the software. @@ -175,6 +185,10 @@ Building pilot-link on Linux/Unix systems # make install + For the smallest footprint of the final distribution you may consider: + + $ ./configure -g0 + Building pilot-link on OS/2 --------------------------- From 9fdc59f16a96b8714536f4a233346d1c5b4a4a50 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Mon, 17 Mar 2025 20:31:28 +0100 Subject: [PATCH 12/31] Include hidden built-in volume with dlp_VFSVolumeEnumerate(...). --- README | 2 +- libpisock/dlp.c | 35 +++++++++++++++++++++++------------ src/pilot-xfer.c | 2 +- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/README b/README index 6a746e59..0fe4018e 100644 --- a/README +++ b/README @@ -187,7 +187,7 @@ Building pilot-link on Linux/Unix systems For the smallest footprint of the final distribution you may consider: - $ ./configure -g0 + $ ./configure CFLAGS=-g0 Building pilot-link on OS/2 --------------------------- diff --git a/libpisock/dlp.c b/libpisock/dlp.c index e47dbc65..baa0e042 100644 --- a/libpisock/dlp.c +++ b/libpisock/dlp.c @@ -4424,14 +4424,29 @@ dlp_VFSVolumeFormat(int sd, unsigned char flags, int fsLibRef, struct VFSSlotMou int dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) { - int result; + int result, found = 0; + struct VFSInfo volInfo; struct dlpRequest *req; struct dlpResponse *res; + if (*numVols <= 0) + return -1; RequireDLPVersion(sd,1,2); Trace(dlp_VFSVolumeEnumerate); pi_reset_errors(sd); + // On the Palm Centro, Treo 650 and maybe more, there is a regular + // file system on the built-in memory. It appears it is hidden from the + // dlpFuncVFSVolumeEnumerate request and the first non-hidden volRef is 2. + // So first check the existence of it with volRef 1. + if ((result = dlp_VFSVolumeInfo(sd, 1, &volInfo)) < 0) { + LOG ((PI_DBG_DLP, PI_DBG_LVL_ERR, + "palm_cardinfo: dlp_VFSVolumeInfo[1] returned %i\n", result)); + volRefs[found] = -1; + } else { + volRefs[found++] = 1; + } + req = dlp_request_new (dlpFuncVFSVolumeEnumerate, 0); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -4441,22 +4456,18 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) dlp_request_free(req); if (result > 0) { - int vols, i; - - vols = get_short(DLP_RESPONSE_DATA (res, 0, 0)); + int vols = get_short(DLP_RESPONSE_DATA (res, 0, 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP VFSVolumeEnumerate %d\n", vols)); - if (vols) { - for (i = 0; i < vols && i < *numVols; i++) { - volRefs[i] = get_short(DLP_RESPONSE_DATA (res, 0, 2 + (2 * i))); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, " %d Volume-Refnum %d\n", i, volRefs[i])); - } + for (int i = 0; i < vols && found < *numVols; i++) { + int volRef = get_short(DLP_RESPONSE_DATA (res, 0, 2 + (2 * i))); + if (volRef == 1 && volRefs[0] == 1) continue; + volRefs[found++] = volRef; + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, " %d Volume-Refnum %d\n", i, volRefs[i])); } - *numVols = vols; } - else - *numVols = 0; + *numVols = found; dlp_response_free(res); diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index ccd243a8..52c89085 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -2327,7 +2327,7 @@ main(int argc, const char *argv[]) /* action indicators that take no arguments. */ {"list", 'l', POPT_ARG_NONE, NULL, palm_op_list, "List all application and 3rd party Palm data/apps", NULL}, - {"cardinfo", 'C', POPT_ARG_NONE, NULL, palm_op_cardinfo, "Show information on available cards", NULL}, + {"cardinfo", 'C', POPT_ARG_NONE, NULL, palm_op_cardinfo, "Show information on available card and built-in volumes", NULL}, /* action indicators that may be mixed in with the others */ {"Purge", 'P', POPT_BIT_SET, &sync_flags, PURGE, "Purge any deleted data that hasn't been cleaned up", NULL}, From f68fca3f5a4f2831b9d5395c31ee646f893b6c11 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Mon, 17 Mar 2025 20:53:00 +0100 Subject: [PATCH 13/31] Lifted version of libpisock. --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 863a0a9e..62eda0df 100644 --- a/configure.ac +++ b/configure.ac @@ -41,8 +41,8 @@ dnl Please see the following URL for details: dnl http://sources.redhat.com/autobook/autobook/autobook_91.html dnl ****************************** PISOCK_CURRENT=10 -PISOCK_REVISION=0 -PISOCK_AGE=1 +PISOCK_REVISION=1 +PISOCK_AGE=0 AC_SUBST(PISOCK_CURRENT) AC_SUBST(PISOCK_REVISION) From 10b730532fda4e3043a09d0648357c0ae72fd436 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Mon, 17 Mar 2025 21:19:40 +0100 Subject: [PATCH 14/31] Added warning, if not all existing volumes were enumerated. --- libpisock/dlp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libpisock/dlp.c b/libpisock/dlp.c index baa0e042..c8a24624 100644 --- a/libpisock/dlp.c +++ b/libpisock/dlp.c @@ -4460,12 +4460,15 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP VFSVolumeEnumerate %d\n", vols)); - for (int i = 0; i < vols && found < *numVols; i++) { + int i = 0; + for ( ; i < vols && found < *numVols; i++) { int volRef = get_short(DLP_RESPONSE_DATA (res, 0, 2 + (2 * i))); if (volRef == 1 && volRefs[0] == 1) continue; volRefs[found++] = volRef; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, " %d Volume-Refnum %d\n", i, volRefs[i])); } + if (i < vols) + LOG((PI_DBG_USER, PI_DBG_LVL_WARN, " emumerated only %d of %d existing volumes\n", found, found + vols - i)); } *numVols = found; From 49777c626459a356dfe0eb9312bea4c77171eb1e Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Tue, 18 Mar 2025 14:03:53 +0100 Subject: [PATCH 15/31] Fixed desrod issue #30; Added flag "Hidden" to Card/Volume info. --- src/pilot-xfer.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 52c89085..71668613 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -1839,6 +1839,7 @@ mediatype (struct VFSInfo *info) typedef struct cardreport_s { char *type; + char *hidden; long size_total; long size_used; long size_free; @@ -1856,8 +1857,7 @@ palm_cardinfo () volume_count = 16, volumes[16]; cardreport_t *cards = NULL, - *t, - *t2; + *t; struct VFSInfo info; char buf[vfsMAXFILENAME], fmt[64]; @@ -1865,7 +1865,9 @@ palm_cardinfo () size_total; int len; /* should be size_t in dlp.c? */ + const size_t CONDENSE = 3; size_t digits_type = 10, + digits_hidden = 6 - CONDENSE, digits_total = 4, digits_used = 4, digits_free = 4, @@ -1899,10 +1901,12 @@ palm_cardinfo () dlp_VFSVolumeGetLabel (sd, volumes[i], &len, buf); t = malloc (sizeof (cardreport_t)); - t->size_used = size_used; + t->type = mediatype(&info); + t->hidden = (info.attributes & vfsVolAttrHidden) ? "x" : " "; + // alternative: t->hidden = (info.attributes & vfsVolAttrHidden) ? "y" : "n"; t->size_total = size_total; + t->size_used = size_used; t->size_free = size_total - size_used; - t->type = mediatype(&info); t->cardnum = info.slotRefNum; t->name = malloc (strlen(buf) + 1); strcpy (&t->name[1], buf); @@ -1913,11 +1917,11 @@ palm_cardinfo () t->next = cards; cards = t; } else { - t2 = cards; - while (t2->next != NULL && t2->next->cardnum < t->cardnum) - t2 = t2->next; - t->next = t2->next; - t2->next = t; + cardreport_t *tmp = cards; + while (tmp->next != NULL && tmp->next->cardnum < t->cardnum) + tmp = tmp->next; + t->next = tmp->next; + tmp->next = t; } /* Determine field widths */ @@ -1926,28 +1930,29 @@ palm_cardinfo () if (j > NAME) \ NAME = j FIELDWIDTH (digits_type, (t->type==NULL ? sizeof(unknown_type) : strlen(t->type))); - FIELDWIDTH (digits_used, numdigits(t->size_used)); + FIELDWIDTH (digits_hidden, strlen(t->hidden)); FIELDWIDTH (digits_total, numdigits(t->size_total)); + FIELDWIDTH (digits_used, numdigits(t->size_used)); FIELDWIDTH (digits_free, numdigits(t->size_free)); FIELDWIDTH (digits_cardnum, numdigits(t->cardnum)); #undef FIELDWIDTH } memset(fmt,0,sizeof(fmt)); - snprintf (fmt, sizeof(fmt)-1, "%%-%zus %%%zus %%%zus %%%zus %%-%zus %%s\n", - digits_type, digits_used, digits_total, digits_free, + snprintf (fmt, sizeof(fmt)-1, "%%-%zus %%-%zus %%%zus %%%zus %%%zus %%-%zus %%s\n", + digits_type, digits_hidden, digits_total - CONDENSE, digits_used, digits_free, digits_cardnum); - printf (fmt, "Filesystem", "Size", "Used", "Free", "#", "Card name"); + printf (fmt, "Filesystem", "Hidden", "Size", "Used", "Free", "#", "Card name"); memset(fmt,0,sizeof(fmt)); - snprintf (fmt, sizeof(fmt)-1, "%%-%zus %%%zuli %%%zuli %%%zuli %%%zui %%s\n", - digits_type, digits_used, digits_total, digits_free, + snprintf (fmt, sizeof(fmt)-1, "%%-%zus %%-%zus %%%zuli %%%zuli %%%zuli %%%zui %%s\n", + digits_type, digits_hidden, digits_total, digits_used, digits_free, digits_cardnum); for (t = cards; t != NULL; t = t->next) { - printf (fmt, t->type==NULL ? unknown_type : t->type, t->size_used, t->size_total, - t->size_free, t->cardnum, t->name); + printf (fmt, t->type==NULL ? unknown_type : t->type, t->hidden, + t->size_total, t->size_used, t->size_free, t->cardnum, t->name); } cleanup: From 8bc57ff75ecb344c56bf8df551e6013bddefa337 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Tue, 18 Mar 2025 14:09:15 +0100 Subject: [PATCH 16/31] Renamed variable for better understanding. --- src/pilot-xfer.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 71668613..5dfa1235 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -1866,12 +1866,12 @@ palm_cardinfo () int len; /* should be size_t in dlp.c? */ const size_t CONDENSE = 3; - size_t digits_type = 10, - digits_hidden = 6 - CONDENSE, - digits_total = 4, - digits_used = 4, - digits_free = 4, - digits_cardnum = 1; + size_t width_type = 10, + width_hidden = 6 - CONDENSE, + width_total = 4, + width_used = 4, + width_free = 4, + width_cardnum = 1; static const char unknown_type[] = ""; /* VFS info */ @@ -1929,26 +1929,26 @@ palm_cardinfo () j = FUNC; \ if (j > NAME) \ NAME = j - FIELDWIDTH (digits_type, (t->type==NULL ? sizeof(unknown_type) : strlen(t->type))); - FIELDWIDTH (digits_hidden, strlen(t->hidden)); - FIELDWIDTH (digits_total, numdigits(t->size_total)); - FIELDWIDTH (digits_used, numdigits(t->size_used)); - FIELDWIDTH (digits_free, numdigits(t->size_free)); - FIELDWIDTH (digits_cardnum, numdigits(t->cardnum)); + FIELDWIDTH (width_type, (t->type==NULL ? sizeof(unknown_type) : strlen(t->type))); + FIELDWIDTH (width_hidden, strlen(t->hidden)); + FIELDWIDTH (width_total, numdigits(t->size_total)); + FIELDWIDTH (width_used, numdigits(t->size_used)); + FIELDWIDTH (width_free, numdigits(t->size_free)); + FIELDWIDTH (width_cardnum, numdigits(t->cardnum)); #undef FIELDWIDTH } memset(fmt,0,sizeof(fmt)); snprintf (fmt, sizeof(fmt)-1, "%%-%zus %%-%zus %%%zus %%%zus %%%zus %%-%zus %%s\n", - digits_type, digits_hidden, digits_total - CONDENSE, digits_used, digits_free, - digits_cardnum); + width_type, width_hidden, width_total - CONDENSE, width_used, width_free, + width_cardnum); printf (fmt, "Filesystem", "Hidden", "Size", "Used", "Free", "#", "Card name"); memset(fmt,0,sizeof(fmt)); snprintf (fmt, sizeof(fmt)-1, "%%-%zus %%-%zus %%%zuli %%%zuli %%%zuli %%%zui %%s\n", - digits_type, digits_hidden, digits_total, digits_used, digits_free, - digits_cardnum); + width_type, width_hidden, width_total, width_used, width_free, + width_cardnum); for (t = cards; t != NULL; t = t->next) { printf (fmt, t->type==NULL ? unknown_type : t->type, t->hidden, From 2a8bc484fce3bd3bd8b2af7166481cc7b10bad64 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Tue, 18 Mar 2025 14:21:35 +0100 Subject: [PATCH 17/31] Lifted version of pilot-link and libpisock. --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 62eda0df..985ac9fc 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,7 @@ dnl Pilot Link Version dnl ****************************** PILOT_LINK_VERS=0 PILOT_LINK_MAJOR=13 -PILOT_LINK_MINOR=1 +PILOT_LINK_MINOR=2 PILOT_LINK_PATCH= AC_SUBST(PILOT_LINK_VERS) @@ -42,7 +42,7 @@ dnl http://sources.redhat.com/autobook/autobook/autobook_91.html dnl ****************************** PISOCK_CURRENT=10 PISOCK_REVISION=1 -PISOCK_AGE=0 +PISOCK_AGE=1 AC_SUBST(PISOCK_CURRENT) AC_SUBST(PISOCK_REVISION) From fddd68cc62b018ef40ebd4e80040983324773d81 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Sat, 22 Mar 2025 01:36:32 +0100 Subject: [PATCH 18/31] Corrected return value of dlp_VFSVolumeEnumerate(...) when no card exists. --- libpisock/dlp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libpisock/dlp.c b/libpisock/dlp.c index baa0e042..e12e55cc 100644 --- a/libpisock/dlp.c +++ b/libpisock/dlp.c @@ -4452,6 +4452,8 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); result = dlp_exec(sd, req, &res); + // -301 : PalmOS Error. Probably no volume (SDCard) found, but hidden volume 1 may exist + // 4 : At least one volume found, but additional hidden volume 1 may exist dlp_request_free(req); @@ -4471,7 +4473,7 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) dlp_response_free(res); - return result; + return (result < 0 && found > 0) ? 4 : result; } int From d89b57b0145ad0b9bc14f1a6d30fbf38283cbfd3 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Sat, 22 Mar 2025 02:02:20 +0100 Subject: [PATCH 19/31] Adapted `pilot-xfer -D --list` to new enhanced functionality of dlp_VFSVolumeEnumerate(...). --- src/pilot-xfer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 52c89085..393bcf37 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -2030,9 +2030,9 @@ findVFSRoot_clumsy(const char *root_component, long *match) return 0; } - if ((matched_volume < 0) && (1 == volume_count)) { - /* Assume that with one card, just go look there. */ - *match = volumes[0]; + if ((matched_volume < 0) && (volume_count > 0)) { + /* Assume that with at least one card, just go look in the last one. */ + *match = volumes[volume_count - 1]; return 1; } return -1; From ef091ce13ec7272dff35d973be7965d073cc8305 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Sat, 22 Mar 2025 15:16:53 +0100 Subject: [PATCH 20/31] In findVFSRoot_clumsy(...) at least match one volume if feasible. --- src/pilot-xfer.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 393bcf37..b98676e5 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -713,7 +713,6 @@ pi_file_retrieve_VFS(const int fd, const char *basename, const int socket, const pi_buffer_t *buffer; ssize_t readsize,writesize; int filesize; - int original_filesize; int written_so_far; pi_progress_t progress; @@ -762,7 +761,6 @@ pi_file_retrieve_VFS(const int fd, const char *basename, const int socket, const } dlp_VFSFileSize(socket,file,&filesize); - original_filesize = filesize; memset(&progress, 0, sizeof(progress)); progress.type = PI_PROGRESS_RECEIVE_VFS; @@ -1986,10 +1984,7 @@ findVFSRoot_clumsy(const char *root_component, long *match) { int volume_count = 16; int volumes[16]; - struct VFSInfo info; - int i; - int buflen; - char buf[vfsMAXFILENAME]; + char labels[16][vfsMAXFILENAME]; long matched_volume = -1; if (dlp_VFSVolumeEnumerate(sd,&volume_count,volumes) < 0) @@ -2002,23 +1997,25 @@ findVFSRoot_clumsy(const char *root_component, long *match) device. If we're listing, print everything out, otherwise remain silent and just set matched_volume if there's a match in the first filename component. */ - for (i = 0; i= 0) { *match = matched_volume; return 0; - } - - if ((matched_volume < 0) && (volume_count > 0)) { - /* Assume that with at least one card, just go look in the last one. */ - *match = volumes[volume_count - 1]; + } else if (volume_count > 0) { // Assume at least one card and match. + *match = volumes[0]; + for (int i=0; i Date: Sat, 22 Mar 2025 18:15:42 +0100 Subject: [PATCH 21/31] Corrected order for definition of library version no digits. --- configure.ac | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 4be6ea8b..85a369af 100644 --- a/configure.ac +++ b/configure.ac @@ -41,12 +41,12 @@ dnl Please see the following URL for details: dnl http://sources.redhat.com/autobook/autobook/autobook_91.html dnl ****************************** PISOCK_CURRENT=10 -PISOCK_REVISION=0 PISOCK_AGE=1 +PISOCK_REVISION=0 AC_SUBST(PISOCK_CURRENT) -AC_SUBST(PISOCK_REVISION) AC_SUBST(PISOCK_AGE) +AC_SUBST(PISOCK_REVISION) dnl ****************************** @@ -54,12 +54,12 @@ dnl Pilot Link Sync Library Version dnl libpisync.so dnl ****************************** PISYNC_CURRENT=1 -PISYNC_REVISION=3 PISYNC_AGE=0 +PISYNC_REVISION=3 AC_SUBST(PISYNC_CURRENT) -AC_SUBST(PISYNC_REVISION) AC_SUBST(PISYNC_AGE) +AC_SUBST(PISYNC_REVISION) dnl Eat -Werror so configure will run properly, if the user provided it enable_werror=no From e0efb372da968fa0a000aa17c56dbde3bd35226b Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Wed, 19 Mar 2025 18:12:13 +0100 Subject: [PATCH 22/31] Show file attributes with dir listing. --- src/pilot-xfer.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 5dfa1235..9c3b605d 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -1678,7 +1678,7 @@ palm_list_internal(unsigned long int flags) * ***********************************************************************/ static void -print_fileinfo(const char *path, FileRef file) +print_fileinfo(const char *path, FileRef file, unsigned long attributes) { int size; time_t date; @@ -1688,7 +1688,7 @@ print_fileinfo(const char *path, FileRef file) (void) dlp_VFSFileGetDate(sd,file,vfsFileDateModified,&date); s = ctime(&date); s[24]=0; - printf(" %8d %s %s\n",size,s,path); + printf(" %02X %8d %s %s\n",attributes,size,s,path); } /*********************************************************************** @@ -1743,6 +1743,7 @@ print_dir(long volume, const char *path, FileRef dir) while (dlp_VFSDirEntryEnumerate(sd,dir,&it,&max,infos) >= 0) { if (max<1) break; + printf(" %d files in %s...\n",max,vfsdir); for (i = 0; i Date: Sat, 22 Mar 2025 22:02:42 +0100 Subject: [PATCH 23/31] Corrected order for definition of library version no digits in Makefile.am. --- libpisock/Makefile.am | 2 +- libpisync/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libpisock/Makefile.am b/libpisock/Makefile.am index e5b11162..5a0cf6f6 100644 --- a/libpisock/Makefile.am +++ b/libpisock/Makefile.am @@ -85,7 +85,7 @@ libpisock_la_LIBADD = \ @usb_libs@ @PTHREAD_LIBS@ @PTHREAD_CFLAGS@ @BLUEZ_LIBS@ libpisock_la_LDFLAGS = \ - -export-dynamic -version-info $(PISOCK_CURRENT):$(PISOCK_REVISION):$(PISOCK_AGE) + -export-dynamic -version-info $(PISOCK_CURRENT):$(PISOCK_AGE):$(PISOCK_REVISION) libpisock_la_CFLAGS = $(PIC_LIBS) @PTHREAD_CFLAGS@ @BLUEZ_CFLAGS@ EXTRA_DIST = $(bluetooth_FILES) $(serial_FILES) $(usb_FILES) diff --git a/libpisync/Makefile.am b/libpisync/Makefile.am index 0f93e9cd..dc4e18e9 100644 --- a/libpisync/Makefile.am +++ b/libpisync/Makefile.am @@ -14,4 +14,4 @@ libpisync_la_LIBADD = \ $(ICONV_LIBS) libpisync_la_LDFLAGS = \ - -export-dynamic -version-info $(PISYNC_CURRENT):$(PISYNC_REVISION):$(PISYNC_AGE) + -export-dynamic -version-info $(PISYNC_CURRENT):$(PISYNC_AGE):$(PISYNC_REVISION) From ca614d7606c579e7f963b73471141d549001658d Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Sun, 23 Mar 2025 02:06:39 +0100 Subject: [PATCH 24/31] =?UTF-8?q?In=20understanding=20the=20libtool?= =?UTF-8?q?=E2=80=99s=20versioning=20system,=20corrected=20the=20library?= =?UTF-8?q?=20version=20nunbers.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configure.ac | 18 +++++++++--------- libpisock/Makefile.am | 2 +- libpisync/Makefile.am | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 1c9592d6..67dc0e2c 100644 --- a/configure.ac +++ b/configure.ac @@ -36,30 +36,30 @@ VERSION="$PILOT_LINK_VERS.$PILOT_LINK_MAJOR.$PILOT_LINK_MINOR$PILOT_LINK_PATCH" dnl ****************************** dnl Pilot Link Library Version -dnl libpisock.so.CURRENT.AGE.REVISION +dnl libpisock.so.CURRENT-AGE.AGE.REVISION dnl Please see the following URL for details: dnl http://sources.redhat.com/autobook/autobook/autobook_91.html dnl ****************************** PISOCK_CURRENT=10 -PISOCK_AGE=2 -PISOCK_REVISION=0 +PISOCK_REVISION=2 +PISOCK_AGE=1 AC_SUBST(PISOCK_CURRENT) -AC_SUBST(PISOCK_AGE) AC_SUBST(PISOCK_REVISION) +AC_SUBST(PISOCK_AGE) dnl ****************************** dnl Pilot Link Sync Library Version -dnl libpisync.so +dnl libpisync.so.CURRENT-AGE.AGE.REVISION dnl ****************************** PISYNC_CURRENT=1 -PISYNC_AGE=0 PISYNC_REVISION=3 +PISYNC_AGE=0 AC_SUBST(PISYNC_CURRENT) -AC_SUBST(PISYNC_AGE) AC_SUBST(PISYNC_REVISION) +AC_SUBST(PISYNC_AGE) dnl Eat -Werror so configure will run properly, if the user provided it enable_werror=no @@ -832,8 +832,8 @@ AC_MSG_RESULT([ Options detected/selected -------------------------. pilot-link version...... : $VERSION - libpisock version....... : $PISOCK_CURRENT.$PISOCK_AGE.$PISOCK_REVISION - libpisync version....... : $PISYNC_CURRENT.$PISYNC_AGE.$PISYNC_REVISION + libpisock version....... : $(($PISOCK_CURRENT-$PISOCK_AGE)).$PISOCK_AGE.$PISOCK_REVISION + libpisync version....... : $(($PISYNC_CURRENT-$PISYNC_AGE)).$PISYNC_AGE.$PISYNC_REVISION Build for host.......... : $host Extra Warnings.......... : $set_compile_warnings Direct USB support...... : $msg_usb diff --git a/libpisock/Makefile.am b/libpisock/Makefile.am index 5a0cf6f6..e5b11162 100644 --- a/libpisock/Makefile.am +++ b/libpisock/Makefile.am @@ -85,7 +85,7 @@ libpisock_la_LIBADD = \ @usb_libs@ @PTHREAD_LIBS@ @PTHREAD_CFLAGS@ @BLUEZ_LIBS@ libpisock_la_LDFLAGS = \ - -export-dynamic -version-info $(PISOCK_CURRENT):$(PISOCK_AGE):$(PISOCK_REVISION) + -export-dynamic -version-info $(PISOCK_CURRENT):$(PISOCK_REVISION):$(PISOCK_AGE) libpisock_la_CFLAGS = $(PIC_LIBS) @PTHREAD_CFLAGS@ @BLUEZ_CFLAGS@ EXTRA_DIST = $(bluetooth_FILES) $(serial_FILES) $(usb_FILES) diff --git a/libpisync/Makefile.am b/libpisync/Makefile.am index dc4e18e9..0f93e9cd 100644 --- a/libpisync/Makefile.am +++ b/libpisync/Makefile.am @@ -14,4 +14,4 @@ libpisync_la_LIBADD = \ $(ICONV_LIBS) libpisync_la_LDFLAGS = \ - -export-dynamic -version-info $(PISYNC_CURRENT):$(PISYNC_AGE):$(PISYNC_REVISION) + -export-dynamic -version-info $(PISYNC_CURRENT):$(PISYNC_REVISION):$(PISYNC_AGE) From dc9a89872fe753cccdfb43c637c995f85b0e4930 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Mon, 12 May 2025 13:29:51 +0200 Subject: [PATCH 25/31] Fix of desrod issue #26 - `pilot-xfer --list -D` does not list all directory entries, if there are more than 64. --- include/pi-dlp.h | 23 +++----- libpisock/dlp.c | 107 ++++++++++++++++-------------------- src/pilot-foto-treo650.c | 115 ++++++++++++++++----------------------- src/pilot-xfer.c | 64 +++++++++------------- tests/vfs-test.c | 22 +++----- 5 files changed, 136 insertions(+), 195 deletions(-) diff --git a/include/pi-dlp.h b/include/pi-dlp.h index 32f82558..81c988f4 100644 --- a/include/pi-dlp.h +++ b/include/pi-dlp.h @@ -118,8 +118,8 @@ typedef unsigned long FileRef; /**< Type for file references when working with /** @brief Information retrieved by dlp_VFSDirEntryEnumerate() */ struct VFSDirInfo { - unsigned long attr; /**< File or directory attributes (see VSF File attribute definitions) */ - char name[vfsMAXFILENAME]; /**< File or directory name */ + unsigned long attr; /**< File or directory attributes (see #dlpVFSFileAttributeConstants enum) */ + char *name; /**< File or directory name (should be freed after use) */ }; /** @brief Information used to format a volume with dlp_VFSVolumeFormat() */ @@ -1576,10 +1576,8 @@ struct dlpResponse { /** @brief Iterate through the entries in a directory * - * Supported on Palm OS 4.0 and later. At the beginning you set - * @p dirIterator to #vfsIteratorStart, then call this function - * repeatedly until it returns an error code or the iterator becomes - * #vfsIteratorStop. + * Supported on Palm OS 4.0 and later. At the beginning you set @p dirItems + * to an empty #VFSDirInfo pointer variable, and then call this function. * * @bug On some early OS 5 devices like Tungsten T and Sony NX70, NX73 this * call crashes the device. This has been confirmed to be a bug in HotSync on @@ -1587,17 +1585,12 @@ struct dlpResponse { * device with this call too. * * @param sd Socket number - * @param dirref Directory reference obtained from dlp_VFSFileOpen() - * @param diriterator Ptr to an iterator. Start with #vfsIteratorStart - * @param maxitems On input, the max number of VFSDirInfo structures stored in @p dirItems. On output, the actual number of items. - * @param diritems Preallocated array that contains a number of VFSDirInfo structures on return. - * @return A negative value if an error occured (see pi-error.h) + * @param dirRef Directory reference obtained from dlp_VFSFileOpen() + * @param dirItems On input, NULL pointer to #VFSDirInfo structure. On output, a pointer to the array of retrieved #VFSDirInfo structures. You are too responsible for free()'ing it, once you're done with it. Additionally for each @p VFSDirInfo.name fields a char buffer is allocated, which must be free()'ed too after use, before free()'ing the whole array of retrieved #VFSDirInfo structures. + * @return The number of #VFSDirInfo structures stored in @p dirItems. A negative value, if an error occured (see pi-error.h) */ extern PI_ERR dlp_VFSDirEntryEnumerate - PI_ARGS((int sd, FileRef dirref, - int *diriterator, int *maxitems, struct VFSDirInfo *diritems)); - // for older compilers where int is 16 bit: - // long *diriterator, int *maxitems, struct VFSDirInfo *diritems)); + PI_ARGS((int sd, FileRef dirRef, struct VFSDirInfo **dirItems)); /** @brief Create a new directory on a VFS volume * diff --git a/libpisock/dlp.c b/libpisock/dlp.c index 38413290..2af8b3cd 100644 --- a/libpisock/dlp.c +++ b/libpisock/dlp.c @@ -4310,80 +4310,65 @@ dlp_VFSDirCreate(int sd, int volRefNum, const char *path) } int -dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, - int *dirIterator, int *maxDirItems, struct VFSDirInfo *data) - // for older compilers where int is 16 bit: - // long *dirIterator, int *maxDirItems, struct VFSDirInfo *data) +dlp_VFSDirEntryEnumerate(int sd, FileRef dirRef, struct VFSDirInfo **dirItems) { int result; - unsigned int entries, from, at, slen, count; struct dlpRequest *req; struct dlpResponse *res; - RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSDirEntryEnumerate, "dirRef=%ld", dirRefNum); + RequireDLPVersion(sd, 1, 2); + TraceX(dlp_VFSDirEntryEnumerate, "dirRef=%ld", dirRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSDirEntryEnumerate, 1, 12); - if (req == NULL) - return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - - set_long (DLP_REQUEST_DATA (req, 0, 0), dirRefNum); - set_long (DLP_REQUEST_DATA (req, 0, 4), *dirIterator); - set_long (DLP_REQUEST_DATA (req, 0, 8), 8 + *maxDirItems * (4 + vfsMAXFILENAME)); - - result = dlp_exec (sd, req, &res); + if (!req) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); + set_long(DLP_REQUEST_DATA(req, 0, 0), dirRef); + set_long(DLP_REQUEST_DATA(req, 0, 4), vfsIteratorStart); + + for (int buflen=256, dirIterator, last=0; ; buflen*=2, last=result) + { + set_long(DLP_REQUEST_DATA(req, 0, 8), buflen); + result = dlp_exec (sd, req, &res); // returns length of response buffer or error if negative - dlp_request_free (req); - - if (result > 0) { - *dirIterator = get_long (DLP_RESPONSE_DATA (res, 0, 0)); - entries = get_long (DLP_RESPONSE_DATA (res, 0, 4)); + if (result > 0) { + dirIterator = get_long(DLP_RESPONSE_DATA(res, 0, 0)); + result = get_long(DLP_RESPONSE_DATA(res, 0, 4)); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "%d results returnd (ilterator: %d)\n", entries, *dirIterator)); - - from = 8; - count = 0; - - for (at = 0; at < entries; at++) { - if (*maxDirItems > at) { - data[at].attr = - get_long(DLP_RESPONSE_DATA (res, 0, from)); - - /* fix for Sony sims (and probably devices too): they return - the attributes in the high word of attr instead of the low - word. We can safely shift it since the high 16 bits are not - used for VFS flags */ - if ((data[at].attr & 0x0000FFFF) == 0 && - (data[at].attr & 0xFFFF0000) != 0) - data[at].attr >>= 16; - - strncpy (data[at].name, - DLP_RESPONSE_DATA(res, 0, from + 4), vfsMAXFILENAME); - data[at].name[vfsMAXFILENAME-1] = 0; - count++; + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, + "%d entries returned (iterator: %d)\n", result, dirIterator)); + // loop further if iteration not complete and too increase of entries: + if (dirIterator != vfsIteratorStop && result > last) { + dlp_response_free (res); + continue; } - - /* Zero terminated string. Strings that have an - even length will be null terminated and have a - pad byte. */ - slen = strlen (DLP_RESPONSE_DATA(res, 0, from + 4)) + 1; - if (slen & 1) - slen++; /* make even stringlen + NULL */ - - /* 6 = 4 (attr) + 1 (NULL) -+ 1 (PADDING) */ - from += slen + 4; + dlp_request_free (req); + struct VFSDirInfo *infos = malloc(sizeof(*infos) * result); + if (!infos) result = pi_set_error(sd, PI_ERR_GENERIC_MEMORY); + + for (int i=0, offset=8, slen; i>= 16; + + char *name = DLP_RESPONSE_DATA(res, 0, offset += 4); + if (!(infos[i].name = malloc(slen = strlen(name) + 1))) { + result = pi_set_error(sd, PI_ERR_GENERIC_MEMORY); + for (; --i>=0; ) free(infos[i].name); + break; + } + strcpy(infos[i].name, name); + // Strings with an odd length including the terminating zero + // are followed by a pad byte. + if (slen & 1) slen++; + } + *dirItems = infos; } - *maxDirItems = count; - } else { - *dirIterator = vfsIteratorStop; - entries = 0; + dlp_response_free (res); + return result; } - - dlp_response_free (res); - - return result; } int diff --git a/src/pilot-foto-treo650.c b/src/pilot-foto-treo650.c index 8848cc56..31ad5741 100644 --- a/src/pilot-foto-treo650.c +++ b/src/pilot-foto-treo650.c @@ -178,74 +178,55 @@ static void * ***********************************************************************/ static void - dump_dir(int sd, long volume, const char *path, FileRef dir) + dump_dir(int sd, long volume, const char *dirPath, FileRef dirRef) { - int it = vfsIteratorStart; - int max = 64; - struct VFSDirInfo infos[64]; - int i; - FileRef file; - char buf[vfsMAXFILENAME]; - int pathlen = strlen(path); - int fd; - char *index; - - /* Set up buf so it contains path with trailing / and - buflen points to the terminating NUL. */ - if (pathlen<1) - { - printf(" NULL path.\n"); - return; - } - - memset(buf,0,vfsMAXFILENAME); - strncpy(buf,path,vfsMAXFILENAME-1); - - if (buf[pathlen-1] != '/') - { - buf[pathlen]='/'; - pathlen++; - } - - if (pathlen>vfsMAXFILENAME-2) - { - printf(" Path too long.\n"); - return; - } - - while (dlp_VFSDirEntryEnumerate(sd,dir,&it,&max,infos) >= 0) - { - if (max<1) break; - for (i = 0; i vfsMAXFILENAME-2) { + printf(" Dir path too long.\n"); + return; + } + + int entries = dlp_VFSDirEntryEnumerate(sd, dirRef, &infos); + + for (int i = 0; ivfsMAXFILENAME-2) - { - printf(" Path too long.\n"); + if (pathlen > vfsMAXFILENAME-2) { + printf(" Dir path too long.\n"); return; } - while (dlp_VFSDirEntryEnumerate(sd,dir,&it,&max,infos) >= 0) - { - if (max<1) break; - for (i = 0; i= 0) { - unsigned long dirIterator = vfsIteratorStart; - do { - struct VFSDirInfo dirItems[16]; - int dirCount; - - memset (dirItems, 0, sizeof(dirItems)); - dirCount = 16; - result = dlp_VFSDirEntryEnumerate (sd, fileRef, &dirIterator, &dirCount, dirItems); - CHECK_RESULT(dlp_VFSDirEntryEnumerate); + struct VFSDirInfo *dirItems = NULL; - if (result >= 0) { - for (j = 0; j < dirCount; j++) { - LOG((PI_DBG_USER, PI_DBG_LVL_INFO, "\t'%s' attrs = 0x%08lx\n", dirItems[j].name, dirItems[j].attr)); - } + result = dlp_VFSDirEntryEnumerate (sd, fileRef, &dirItems); + CHECK_RESULT(dlp_VFSDirEntryEnumerate); + + if (result >= 0) { + for (j = 0; j < result; j++) { + LOG((PI_DBG_USER, PI_DBG_LVL_INFO, "\t'%s' attrs = 0x%08lx\n", dirItems[j].name, dirItems[j].attr)); } - } while (dirIterator != vfsIteratorStop && result >= 0); + } result = dlp_VFSFileClose (sd, fileRef); CHECK_RESULT(dlp_VFSFileClose); From 4f1fb026b6a25a4d61bd297916716822fba37231 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Fri, 16 May 2025 00:28:21 +0200 Subject: [PATCH 26/31] Fix of desrod issue #32 -Text messages for PalmOS errors are corrupted. --- bindings/Java/libjpisock.c | 6 +- bindings/Python/src/pisock_wrap.c | 4 +- bindings/Tcl/pitcl.c | 6 +- exp.csv | 1 + include/pi-dlp.h | 330 +++++++++++++++++------------- include/pi-error.h | 52 +++-- libpisock/dlp.c | 254 ++++++++++++++++------- src/pilot-xfer.c | 49 +++-- 8 files changed, 441 insertions(+), 261 deletions(-) create mode 100644 exp.csv diff --git a/bindings/Java/libjpisock.c b/bindings/Java/libjpisock.c index 81d99926..1758812c 100644 --- a/bindings/Java/libjpisock.c +++ b/bindings/Java/libjpisock.c @@ -1241,13 +1241,13 @@ static void postPilotLinkException(JNIEnv * env, const char * sTexto, int iResul // Attempt to describe underlying errno for exception sMessage = (char *)malloc(strlen(sTemplate) + strlen(sTexto) + - strlen(dlp_strerror(iResult)) + strlen(strerror(save_errno)) + 1); + strlen(dlp_err_message(iResult)) + strlen(strerror(save_errno)) + 1); if (sMessage != NULL) { - sprintf(sMessage, sTemplate, sTexto, dlp_strerror(iResult), strerror(save_errno)); + sprintf(sMessage, sTemplate, sTexto, dlp_err_message(iResult), strerror(save_errno)); postJavaException(env, sExceptionClass, sMessage); free(sMessage); } else { - postJavaException(env, sExceptionClass, dlp_strerror(iResult)); + postJavaException(env, sExceptionClass, dlp_err_message(iResult)); } } diff --git a/bindings/Python/src/pisock_wrap.c b/bindings/Python/src/pisock_wrap.c index 794ee109..03b022f1 100644 --- a/bindings/Python/src/pisock_wrap.c +++ b/bindings/Python/src/pisock_wrap.c @@ -1753,7 +1753,7 @@ static int pythonWrapper_handlePiErr(int sd, int err) return 0; if (palmerr > dlpErrNoError && palmerr <= dlpErrUnknown) { PyErr_SetObject(PIError, - Py_BuildValue("(is)", palmerr, dlp_strerror(palmerr))); + Py_BuildValue("(is)", palmerr, dlp_err_message(palmerr))); return err; } } @@ -1803,7 +1803,7 @@ static PyObject *_wrap_dlp_ReadRecordIDList (PyObject *self, PyObject *args) { } if (ret < 0) { - PyErr_SetObject(PIError, Py_BuildValue("(is)", ret, dlp_strerror(ret))); + PyErr_SetObject(PIError, Py_BuildValue("(is)", ret, dlp_err_message(ret))); PyMem_Free(buf); return NULL; } diff --git a/bindings/Tcl/pitcl.c b/bindings/Tcl/pitcl.c index 02f0da6e..d834c44c 100644 --- a/bindings/Tcl/pitcl.c +++ b/bindings/Tcl/pitcl.c @@ -1054,7 +1054,7 @@ OpenDBCmd(ClientData clientData, Tcl_Interp * interp, int argc, char*argv[]) result, name, mode, cardno, handle); if (result<0) { - Tcl_SetResult(interp, dlp_strerror(result), TCL_STATIC); + Tcl_SetResult(interp, dlp_err_message(result), TCL_STATIC); return TCL_ERROR; } @@ -1126,7 +1126,7 @@ GetRecordCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[]) result = dlp_ReadRecordByIndex(tcl_socket(interp, argv[1]), handle, index, buf, &id_, &attr, &cat); if (result<0) { - Tcl_SetResult(interp, dlp_strerror(result), TCL_STATIC); + Tcl_SetResult(interp, dlp_err_message(result), TCL_STATIC); return TCL_ERROR; } @@ -1175,7 +1175,7 @@ SetRecordCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[]) free(buf); if (result<0) { - Tcl_SetResult(interp, dlp_strerror(result), TCL_STATIC); + Tcl_SetResult(interp, dlp_err_message(result), TCL_STATIC); return TCL_ERROR; } diff --git a/exp.csv b/exp.csv new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/exp.csv @@ -0,0 +1 @@ + diff --git a/include/pi-dlp.h b/include/pi-dlp.h index 32f82558..1861cc3c 100644 --- a/include/pi-dlp.h +++ b/include/pi-dlp.h @@ -109,9 +109,9 @@ extern "C" { /** @name VFS definitions */ /*@{*/ #define vfsMountFlagsUseThisFileSystem 0x01 /**< Mount/Format the volume with the filesystem specified */ -#define vfsMAXFILENAME 256 /**< The maximum size of a filename in a VFS volume */ -#define vfsInvalidVolRef 0 /**< constant for an invalid volume reference, guaranteed not to represent a valid one. Use it like you would use NULL for a FILE*. */ -#define vfsInvalidFileRef 0L /**< constant for an invalid file reference, guaranteed not to represent a valid one. Use it like you would use NULL for a FILE*. */ +#define vfsMAXFILENAME 256 /**< The maximum size of a filename in a VFS volume */ +#define vfsInvalidVolRef 0 /**< constant for an invalid volume reference, guaranteed not to represent a valid one. Use it like you would use NULL for a FILE*. */ +#define vfsInvalidFileRef 0L /**< constant for an invalid file reference, guaranteed not to represent a valid one. Use it like you would use NULL for a FILE*. */ /*@}*/ typedef unsigned long FileRef; /**< Type for file references when working with VFS files and directories. */ @@ -139,7 +139,7 @@ struct VFSSlotMountParam { /** @brief Information about a VFS volume, returned by dlp_VFSVolumeInfo() */ struct VFSInfo { /* 0: read-only etc. */ - unsigned long attributes; /**< Volume attributes (see #dlpVFSVolumeAttributes enum) */ + unsigned long attributes; /**< Volume attributes (see #dlpVFSVolumeAttributes enum) */ /* 4: Filesystem type for this volume (defined below). These you can expect to see in devices: @@ -161,14 +161,14 @@ struct VFSInfo { 'novl' (Novell filesystem) 'ntfs' (Windows NT filesystem) */ - unsigned long fsType; /**< File system time (four-char code, see above) */ + unsigned long fsType; /**< File system time (four-char code, see above) */ /* 8: Creator code of filesystem driver for this volume. */ - unsigned long fsCreator; /**< File system creator (four-char code) */ + unsigned long fsCreator; /**< File system creator (four-char code) */ /* For slot based filesystems: (mountClass = VFSMountClass_SlotDriver) 12: mount class that mounted this volume */ - unsigned long mountClass; /**< Mount class */ + unsigned long mountClass; /**< Mount class */ /* 16: Library on which the volume is mounted */ int slotLibRefNum; /**< Slot library reference number */ @@ -193,10 +193,10 @@ struct VFSInfo { 'ramd' (RAM disk) 'smed' (SmartMedia) */ - unsigned long mediaType; /**< Media type (see above) */ + unsigned long mediaType; /**< Media type (see above) */ /* 24: reserved for future use (other mountclasses may need more space) */ - unsigned long reserved; /**< Reserved, set to 0 */ + unsigned long reserved; /**< Reserved, set to 0 */ }; /** @brief Information about the handheld user @@ -204,9 +204,9 @@ struct VFSInfo { * This structure is used in dlp_ReadUserInfo() and dlp_WriteUserInfo() */ struct PilotUser { - size_t passwordLength; - char username[128]; - char password[128]; + size_t passwordLength; + char username[128]; + char password[128]; unsigned long userID; unsigned long viewerID; unsigned long lastSyncPC; @@ -219,15 +219,15 @@ struct PilotUser { * This structure is filled by dlp_ReadSysInfo() */ struct SysInfo { - unsigned long romVersion; /**< Version of the device ROM, of the form 0xMMmmffssbb where MM=Major, mm=minor, ff=fix, ss=stage, bb=build */ - unsigned long locale; /**< Locale for this device */ - unsigned char prodIDLength; /**< Length of the prodID string */ - char prodID[128]; /**< Product ID */ + unsigned long romVersion; /**< Version of the device ROM, of the form 0xMMmmffssbb where MM=Major, mm=minor, ff=fix, ss=stage, bb=build */ + unsigned long locale; /**< Locale for this device */ + unsigned char prodIDLength; /**< Length of the prodID string */ + char prodID[128]; /**< Product ID */ unsigned short dlpMajorVersion; /**< Major version of the DLP protocol on this device */ unsigned short dlpMinorVersion; /**< Minor version of the DLP protocol on this device */ unsigned short compatMajorVersion; /**< Minimum major version of DLP this device is compatible with */ unsigned short compatMinorVersion; /**< Minimum minor version of DLP this device is compatible with */ - unsigned long maxRecSize; /**< Maximum record size. Usually <=0xFFFF or ==0 for older devices (means records are limited to 64k), can be much larger for devices with DLP >= 1.4 (i.e. 0x00FFFFFE) */ + unsigned long maxRecSize; /**< Maximum record size. Usually <=0xFFFF or ==0 for older devices (means records are limited to 64k), can be much larger for devices with DLP >= 1.4 (i.e. 0x00FFFFFE) */ }; /** @brief Database information. @@ -236,14 +236,14 @@ struct SysInfo { * and dlp_FindDBByTypeCreator(). */ struct DBInfo { - int more; /**< When reading database list using dlp_ReadDBList(), this flag is set if there are more databases to come */ + int more; /**< When reading database list using dlp_ReadDBList(), this flag is set if there are more databases to come */ char name[34]; /**< Database name, 32 characters max. */ unsigned int flags; /**< Database flags (@see dlpDBFlags enum) */ - unsigned int miscFlags; /**< Additional database flags filled by pilot-link (@see dlpDBMiscFlags enum) */ - unsigned int version; /**< Database version number */ + unsigned int miscFlags; /**< Additional database flags filled by pilot-link (@see dlpDBMiscFlags enum) */ + unsigned int version; /**< Database version number */ unsigned long type; /**< Database type (four-char code, i.e. 'appl') */ - unsigned long creator; /**< Database creator (four-char code, i.e. 'DATA') */ - unsigned long modnum; /**< Modification count */ + unsigned long creator; /**< Database creator (four-char code, i.e. 'DATA') */ + unsigned long modnum; /**< Modification count */ unsigned int index; /**< Database index in database list */ time_t createDate; /**< Database creation date (using the machine's local time zone) */ time_t modifyDate; /**< Last time this database was modified (using the machine's local time zone). If the database was never modified, this field is set to 0x83DAC000 (Fri Jan 1 00:00:00 1904 GMT) */ @@ -259,7 +259,7 @@ struct DBSizeInfo { unsigned long totalBytes; /**< Total number of bytes occupied by the database, including header and records list */ unsigned long dataBytes; /**< Total number of data bytes contained in the database's records or resources */ unsigned long appBlockSize; /**< Size of the appInfo block */ - unsigned long sortBlockSize; /**< Size of the sortInfo block */ + unsigned long sortBlockSize; /**< Size of the sortInfo block */ unsigned long maxRecSize; /**< note: this field is always set to 0 on return from dlp_FindDBxxx */ }; @@ -269,15 +269,15 @@ struct DBSizeInfo { * It is returned by dlp_ReadStorageInfo(). */ struct CardInfo { - int card; /**< Memory card index (most devices only have one). */ - int version; /**< Version of the card */ - int more; /**< Set if there is another card after this one */ - time_t creation; /**< Creation date (using the computer's local time zone) */ - unsigned long romSize; /**< Size of the ROM block on this card (in bytes) */ - unsigned long ramSize; /**< Size of the RAM block on this card (in bytes) */ - unsigned long ramFree; /**< Total free RAM bytes */ - char name[128]; /**< Card name */ - char manufacturer[128]; /**< Card manufacturer name */ + int card; /**< Memory card index (most devices only have one). */ + int version; /**< Version of the card */ + int more; /**< Set if there is another card after this one */ + time_t creation; /**< Creation date (using the computer's local time zone) */ + unsigned long romSize; /**< Size of the ROM block on this card (in bytes) */ + unsigned long ramSize; /**< Size of the RAM block on this card (in bytes) */ + unsigned long ramFree; /**< Total free RAM bytes */ + char name[128]; /**< Card name */ + char manufacturer[128]; /**< Card manufacturer name */ }; /** @brief Network HotSync information. @@ -285,10 +285,10 @@ struct CardInfo { * Returned by dlp_ReadNetSyncInfo(). Gives the network location of a remote handheld. */ struct NetSyncInfo { - int lanSync; /**< Non-zero if LanSync is turned on on the device */ - char hostName[256]; /**< Device hostname if any. Null terminated string. */ - char hostAddress[40]; /**< Device host address. Null terminated string. */ - char hostSubnetMask[40]; /**< Device subnet mask. Null terminated string */ + int lanSync; /**< Non-zero if LanSync is turned on on the device */ + char hostName[256]; /**< Device hostname if any. Null terminated string. */ + char hostAddress[40]; /**< Device host address. Null terminated string. */ + char hostSubnetMask[40]; /**< Device subnet mask. Null terminated string */ }; #ifndef SWIG /* no need to clutter the bindings with this */ @@ -299,22 +299,22 @@ enum dlpFunctions { /* DLP 1.0 FUNCTIONS START HERE (PalmOS v1.0) */ dlpFuncReadUserInfo, /* 0x10 */ dlpFuncWriteUserInfo, /* 0x11 */ - dlpFuncReadSysInfo, /* 0x12 */ + dlpFuncReadSysInfo, /* 0x12 */ dlpFuncGetSysDateTime, /* 0x13 */ dlpFuncSetSysDateTime, /* 0x14 */ dlpFuncReadStorageInfo, /* 0x15 */ - dlpFuncReadDBList, /* 0x16 */ - dlpFuncOpenDB, /* 0x17 */ - dlpFuncCreateDB, /* 0x18 */ - dlpFuncCloseDB, /* 0x19 */ - dlpFuncDeleteDB, /* 0x1a */ + dlpFuncReadDBList, /* 0x16 */ + dlpFuncOpenDB, /* 0x17 */ + dlpFuncCreateDB, /* 0x18 */ + dlpFuncCloseDB, /* 0x19 */ + dlpFuncDeleteDB, /* 0x1a */ dlpFuncReadAppBlock, /* 0x1b */ dlpFuncWriteAppBlock, /* 0x1c */ dlpFuncReadSortBlock, /* 0x1d */ dlpFuncWriteSortBlock, /* 0x1e */ dlpFuncReadNextModifiedRec, /* 0x1f */ - dlpFuncReadRecord, /* 0x20 */ - dlpFuncWriteRecord, /* 0x21 */ + dlpFuncReadRecord, /* 0x20 */ + dlpFuncWriteRecord, /* 0x21 */ dlpFuncDeleteRecord, /* 0x22 */ dlpFuncReadResource, /* 0x23 */ dlpFuncWriteResource, /* 0x24 */ @@ -322,74 +322,74 @@ enum dlpFunctions { dlpFuncCleanUpDatabase, /* 0x26 */ dlpFuncResetSyncFlags, /* 0x27 */ dlpFuncCallApplication, /* 0x28 */ - dlpFuncResetSystem, /* 0x29 */ + dlpFuncResetSystem, /* 0x29 */ dlpFuncAddSyncLogEntry, /* 0x2a */ dlpFuncReadOpenDBInfo, /* 0x2b */ dlpFuncMoveCategory, /* 0x2c */ - dlpProcessRPC, /* 0x2d */ - dlpFuncOpenConduit, /* 0x2e */ - dlpFuncEndOfSync, /* 0x2f */ + dlpProcessRPC, /* 0x2d */ + dlpFuncOpenConduit, /* 0x2e */ + dlpFuncEndOfSync, /* 0x2f */ dlpFuncResetRecordIndex, /* 0x30 */ dlpFuncReadRecordIDList, /* 0x31 */ /* DLP 1.1 FUNCTIONS ADDED HERE (PalmOS v2.0 Personal, and Professional) */ - dlpFuncReadNextRecInCategory, /* 0x32 */ - dlpFuncReadNextModifiedRecInCategory, /* 0x33 */ - dlpFuncReadAppPreference, /* 0x34 */ - dlpFuncWriteAppPreference, /* 0x35 */ - dlpFuncReadNetSyncInfo, /* 0x36 */ - dlpFuncWriteNetSyncInfo, /* 0x37 */ - dlpFuncReadFeature, /* 0x38 */ + dlpFuncReadNextRecInCategory, /* 0x32 */ + dlpFuncReadNextModifiedRecInCategory, /* 0x33 */ + dlpFuncReadAppPreference, /* 0x34 */ + dlpFuncWriteAppPreference, /* 0x35 */ + dlpFuncReadNetSyncInfo, /* 0x36 */ + dlpFuncWriteNetSyncInfo, /* 0x37 */ + dlpFuncReadFeature, /* 0x38 */ /* DLP 1.2 FUNCTIONS ADDED HERE (PalmOS v3.0) */ dlpFuncFindDB, /* 0x39 */ dlpFuncSetDBInfo, /* 0x3a */ /* DLP 1.3 FUNCTIONS ADDED HERE (PalmOS v4.0) */ - dlpLoopBackTest, /* 0x3b */ - dlpFuncExpSlotEnumerate, /* 0x3c */ - dlpFuncExpCardPresent, /* 0x3d */ - dlpFuncExpCardInfo, /* 0x3e */ - dlpFuncVFSCustomControl, /* 0x3f */ - dlpFuncVFSGetDefaultDir, /* 0x40 */ + dlpLoopBackTest, /* 0x3b */ + dlpFuncExpSlotEnumerate, /* 0x3c */ + dlpFuncExpCardPresent, /* 0x3d */ + dlpFuncExpCardInfo, /* 0x3e */ + dlpFuncVFSCustomControl, /* 0x3f */ + dlpFuncVFSGetDefaultDir, /* 0x40 */ dlpFuncVFSImportDatabaseFromFile, /* 0x41 */ - dlpFuncVFSExportDatabaseToFile, /* 0x42 */ - dlpFuncVFSFileCreate, /* 0x43 */ - dlpFuncVFSFileOpen, /* 0x44 */ - dlpFuncVFSFileClose, /* 0x45 */ - dlpFuncVFSFileWrite, /* 0x46 */ - dlpFuncVFSFileRead, /* 0x47 */ - dlpFuncVFSFileDelete, /* 0x48 */ - dlpFuncVFSFileRename, /* 0x49 */ - dlpFuncVFSFileEOF, /* 0x4a */ - dlpFuncVFSFileTell, /* 0x4b */ + dlpFuncVFSExportDatabaseToFile, /* 0x42 */ + dlpFuncVFSFileCreate, /* 0x43 */ + dlpFuncVFSFileOpen, /* 0x44 */ + dlpFuncVFSFileClose, /* 0x45 */ + dlpFuncVFSFileWrite, /* 0x46 */ + dlpFuncVFSFileRead, /* 0x47 */ + dlpFuncVFSFileDelete, /* 0x48 */ + dlpFuncVFSFileRename, /* 0x49 */ + dlpFuncVFSFileEOF, /* 0x4a */ + dlpFuncVFSFileTell, /* 0x4b */ dlpFuncVFSFileGetAttributes, /* 0x4c */ dlpFuncVFSFileSetAttributes, /* 0x4d */ - dlpFuncVFSFileGetDate, /* 0x4e */ - dlpFuncVFSFileSetDate, /* 0x4f */ - dlpFuncVFSDirCreate, /* 0x50 */ + dlpFuncVFSFileGetDate, /* 0x4e */ + dlpFuncVFSFileSetDate, /* 0x4f */ + dlpFuncVFSDirCreate, /* 0x50 */ dlpFuncVFSDirEntryEnumerate, /* 0x51 */ - dlpFuncVFSGetFile, /* 0x52 */ - dlpFuncVFSPutFile, /* 0x53 */ - dlpFuncVFSVolumeFormat, /* 0x54 */ - dlpFuncVFSVolumeEnumerate, /* 0x55 */ - dlpFuncVFSVolumeInfo, /* 0x56 */ - dlpFuncVFSVolumeGetLabel, /* 0x57 */ - dlpFuncVFSVolumeSetLabel, /* 0x58 */ - dlpFuncVFSVolumeSize, /* 0x59 */ - dlpFuncVFSFileSeek, /* 0x5a */ - dlpFuncVFSFileResize, /* 0x5b */ - dlpFuncVFSFileSize, /* 0x5c */ + dlpFuncVFSGetFile, /* 0x52 */ + dlpFuncVFSPutFile, /* 0x53 */ + dlpFuncVFSVolumeFormat, /* 0x54 */ + dlpFuncVFSVolumeEnumerate, /* 0x55 */ + dlpFuncVFSVolumeInfo, /* 0x56 */ + dlpFuncVFSVolumeGetLabel, /* 0x57 */ + dlpFuncVFSVolumeSetLabel, /* 0x58 */ + dlpFuncVFSVolumeSize, /* 0x59 */ + dlpFuncVFSFileSeek, /* 0x5a */ + dlpFuncVFSFileResize, /* 0x5b */ + dlpFuncVFSFileSize, /* 0x5c */ /* DLP 1.4 functions added here (Palm OS 5.2+, ie Tapwave Zodiac) */ - dlpFuncExpSlotMediaType, /* 0x5d */ - dlpFuncWriteRecordEx, /* 0x5e - function to write >64k records in Tapwave */ - dlpFuncWriteResourceEx, /* 0x5f - function to write >64k resources in Tapwave */ - dlpFuncReadRecordEx, /* 0x60 - function to read >64k records by index in Tapwave */ + dlpFuncExpSlotMediaType, /* 0x5d */ + dlpFuncWriteRecordEx, /* 0x5e - function to write >64k records in Tapwave */ + dlpFuncWriteResourceEx, /* 0x5f - function to write >64k resources in Tapwave */ + dlpFuncReadRecordEx, /* 0x60 - function to read >64k records by index in Tapwave */ dlpFuncUnknown1, /* 0x61 (may be bogus definition in tapwave headers, is listed as dlpFuncReadRecordStream)*/ dlpFuncUnknown3, /* 0x62 */ dlpFuncUnknown4, /* 0x63 */ - dlpFuncReadResourceEx, /* 0x64 - function to read resources >64k by index in Tapwave */ + dlpFuncReadResourceEx, /* 0x64 - function to read resources >64k by index in Tapwave */ dlpLastFunc }; @@ -399,35 +399,35 @@ enum dlpFunctions { /*@{*/ /** @brief Database flags in DBInfo structure and also for dlp_CreateDB() */ enum dlpDBFlags { - dlpDBFlagResource = 0x0001, /**< Resource database */ - dlpDBFlagReadOnly = 0x0002, /**< Database is read only */ - dlpDBFlagAppInfoDirty = 0x0004, /**< AppInfo data has been modified */ - dlpDBFlagBackup = 0x0008, /**< Database should be backed up during HotSync */ - dlpDBFlagHidden = 0x0100, /**< Database is hidden */ - dlpDBFlagLaunchable = 0x0200, /**< Database is launchable data (show in Launcher, launch app by Creator) */ - dlpDBFlagRecyclable = 0x0400, /**< Database will be deleted shortly */ - dlpDBFlagBundle = 0x0800, /**< Database is bundled with others having same creator (i.e. for Beam) */ - dlpDBFlagOpen = 0x8000, /**< Database is currently open */ + dlpDBFlagResource = 0x0001, /**< Resource database */ + dlpDBFlagReadOnly = 0x0002, /**< Database is read only */ + dlpDBFlagAppInfoDirty = 0x0004, /**< AppInfo data has been modified */ + dlpDBFlagBackup = 0x0008, /**< Database should be backed up during HotSync */ + dlpDBFlagHidden = 0x0100, /**< Database is hidden */ + dlpDBFlagLaunchable = 0x0200, /**< Database is launchable data (show in Launcher, launch app by Creator) */ + dlpDBFlagRecyclable = 0x0400, /**< Database will be deleted shortly */ + dlpDBFlagBundle = 0x0800, /**< Database is bundled with others having same creator (i.e. for Beam) */ + dlpDBFlagOpen = 0x8000, /**< Database is currently open */ /* v2.0 specific */ - dlpDBFlagNewer = 0x0010, /**< Newer version may be installed over open DB (Palm OS 2.0 and later) */ - dlpDBFlagReset = 0x0020, /**< Reset after installation (Palm OS 2.0 and later) */ + dlpDBFlagNewer = 0x0010, /**< Newer version may be installed over open DB (Palm OS 2.0 and later) */ + dlpDBFlagReset = 0x0020, /**< Reset after installation (Palm OS 2.0 and later) */ /* v3.0 specific */ dlpDBFlagCopyPrevention = 0x0040, /**< Database should not be beamed or sent (Palm OS 3.0 and later) */ - dlpDBFlagStream = 0x0080, /**< Database is a file stream (Palm OS 3.0 and later) */ + dlpDBFlagStream = 0x0080, /**< Database is a file stream (Palm OS 3.0 and later) */ /* OS 6+ */ - dlpDBFlagSchema = 0x1000, /**< Schema database (Palm OS 6.0 and later) */ - dlpDBFlagSecure = 0x2000, /**< Secure database (Palm OS 6.0 and later) */ + dlpDBFlagSchema = 0x1000, /**< Schema database (Palm OS 6.0 and later) */ + dlpDBFlagSecure = 0x2000, /**< Secure database (Palm OS 6.0 and later) */ dlpDBFlagExtended = dlpDBFlagSecure, /**< Set if Schema not set and DB is Extended (Palm OS 6.0 and later) */ - dlpDBFlagFixedUp = 0x4000 /**< Temp flag used to clear DB on write (Palm OS 6.0 and later) */ + dlpDBFlagFixedUp = 0x4000 /**< Temp flag used to clear DB on write (Palm OS 6.0 and later) */ }; /** @brief Misc. flags in DBInfo structure */ enum dlpDBMiscFlags { dlpDBMiscFlagExcludeFromSync = 0x80, /**< DLP 1.1 and later: exclude this database from sync */ - dlpDBMiscFlagRamBased = 0x40 /**< DLP 1.2 and later: this database is in RAM */ + dlpDBMiscFlagRamBased = 0x40 /**< DLP 1.2 and later: this database is in RAM */ }; /** @brief Database record attributes */ @@ -457,8 +457,8 @@ enum dlpFunctions { enum dlpFindDBOptFlags { dlpFindDBOptFlagGetAttributes = 0x80, - dlpFindDBOptFlagGetSize = 0x40, - dlpFindDBOptFlagMaxRecSize = 0x20 + dlpFindDBOptFlagGetSize = 0x40, + dlpFindDBOptFlagMaxRecSize = 0x20 }; enum dlpFindDBSrchFlags { @@ -470,10 +470,10 @@ enum dlpFunctions { /** @brief End status values for dlp_EndOfSync() */ enum dlpEndStatus { - dlpEndCodeNormal = 0, /**< Normal termination */ - dlpEndCodeOutOfMemory, /**< End due to low memory on device */ - dlpEndCodeUserCan, /**< Cancelled by user */ - dlpEndCodeOther /**< dlpEndCodeOther and higher == "Anything else" */ + dlpEndCodeNormal = 0, /**< Normal termination */ + dlpEndCodeOutOfMemory, /**< End due to low memory on device */ + dlpEndCodeUserCan, /**< Cancelled by user */ + dlpEndCodeOther /**< dlpEndCodeOther and higher == "Anything else" */ }; /** @name Expansion manager and VFS manager constants */ @@ -494,50 +494,50 @@ enum dlpEndStatus { /** @brief Constants for dlp_VFSFileSeek() */ enum dlpVFSSeekConstants { - vfsOriginBeginning = 0, /**< From the beginning (first data byte of file) */ - vfsOriginCurrent = 1, /**< from the current position */ + vfsOriginBeginning = 0, /**< From the beginning (first data byte of file) */ + vfsOriginCurrent = 1, /**< from the current position */ vfsOriginEnd = 2 /**< From the end of file (one position beyond last data byte, only negative offsets are legally allowed) */ }; /** @brief Flags for dlp_VFSFileOpen() */ enum dlpVFSOpenFlags { - dlpVFSOpenExclusive = 0x01, /**< For dlp_VFSFileOpen(). Exclusive access */ + dlpVFSOpenExclusive = 0x01, /**< For dlp_VFSFileOpen(). Exclusive access */ dlpVFSOpenRead = 0x02, /**< For dlp_VFSFileOpen(). Read only */ dlpVFSOpenWrite = 0x05, /**< For dlp_VFSFileOpen(). Write only. Implies exclusive */ - dlpVFSOpenReadWrite = 0x07, /**< For dlp_VFSFileOpen(). Read | write */ + dlpVFSOpenReadWrite = 0x07, /**< For dlp_VFSFileOpen(). Read | write */ /* Remainder are aliases and special cases not for VFSFileOpen */ vfsModeExclusive = dlpVFSOpenExclusive, /**< Alias to #dlpVFSOpenExclusive */ - vfsModeRead = dlpVFSOpenRead, /**< Alias to #dlpVFSOpenRead */ - vfsModeWrite = dlpVFSOpenWrite, /**< Alias to #dlpVFSOpenWrite */ + vfsModeRead = dlpVFSOpenRead, /**< Alias to #dlpVFSOpenRead */ + vfsModeWrite = dlpVFSOpenWrite, /**< Alias to #dlpVFSOpenWrite */ vfsModeReadWrite = vfsModeRead | vfsModeWrite, /**< Alias to #dlpVFSOpenReadWrite */ - vfsModeCreate = 0x08 /**< Not for dlp_VFSFileOpen(). Create file if it doesn't exist. */, - vfsModeTruncate = 0x10 /**< Not for dlp_VFSFileOpen(). Truncate to 0 bytes on open. */, - vfsModeLeaveOpen = 0x20 /**< Not for dlp_VFSFileOpen(). Leave file open even if foreground task closes. */ + vfsModeCreate = 0x08, /**< Not for dlp_VFSFileOpen(). Create file if it doesn't exist. */ + vfsModeTruncate = 0x10, /**< Not for dlp_VFSFileOpen(). Truncate to 0 bytes on open. */ + vfsModeLeaveOpen = 0x20 /**< Not for dlp_VFSFileOpen(). Leave file open even if foreground task closes. */ } ; /** @brief VFS file attribute constants */ enum dlpVFSFileAttributeConstants { - vfsFileAttrReadOnly = 0x00000001, /**< File is read only */ - vfsFileAttrHidden = 0x00000002, /**< File is hidden */ - vfsFileAttrSystem = 0x00000004, /**< File is a system file */ + vfsFileAttrReadOnly = 0x00000001, /**< File is read only */ + vfsFileAttrHidden = 0x00000002, /**< File is hidden */ + vfsFileAttrSystem = 0x00000004, /**< File is a system file */ vfsFileAttrVolumeLabel = 0x00000008, /**< File is the volume label */ vfsFileAttrDirectory = 0x00000010, /**< File is a directory */ - vfsFileAttrArchive = 0x00000020, /**< File is archived */ - vfsFileAttrLink = 0x00000040 /**< File is a link to another file */ + vfsFileAttrArchive = 0x00000020, /**< File is archived */ + vfsFileAttrLink = 0x00000040 /**< File is a link to another file */ }; /** @brief Constants for dlp_VFSFileGetDate() and dlp_VFSFileSetDate() */ enum dlpVFSDateConstants { - vfsFileDateCreated = 1, /**< The date the file was created. */ - vfsFileDateModified = 2, /**< The date the file was last modified. */ + vfsFileDateCreated = 1, /**< The date the file was created. */ + vfsFileDateModified = 2, /**< The date the file was last modified. */ vfsFileDateAccessed = 3 /**< The date the file was last accessed. */ }; /** @brief VFS file iterator constants */ enum dlpVFSFileIteratorConstants { - vfsIteratorStart = 0, /** < Indicates that iterator is beginning */ - vfsIteratorStop = -1 /**< Indicate that iterator has gone through all items */ + vfsIteratorStart = 0, /** < Indicates that iterator is beginning */ + vfsIteratorStop = -1 /**< Indicate that iterator has gone through all items */ }; /*@}*/ @@ -552,7 +552,7 @@ enum dlpEndStatus { * definitions, in relation with each DLP call) */ enum dlpErrors { - dlpErrNoError = 0, /**< No error */ + dlpErrNoError = 0, /**< No error (0x0000) */ dlpErrSystem, /**< System error (0x0001) */ dlpErrIllegalReq, /**< Illegal request, not supported by this version of DLP (0x0002) */ dlpErrMemory, /**< Not enough memory (0x0003) */ @@ -562,22 +562,69 @@ enum dlpErrors { dlpErrAlreadyOpen, /**< File already open (0x0007) */ dlpErrTooManyOpen, /**< Too many open files (0x0008) */ dlpErrExists, /**< File already exists (0x0009) */ - dlpErrOpen, /**< Can't open file (0x000a) */ + dlpErrOpen, /**< Can't open file (0x000a) */ dlpErrDeleted, /**< File deleted (0x000b) */ - dlpErrBusy, /**< Record busy (0x000c) */ + dlpErrBusy, /**< Record busy (0x000c) */ dlpErrNotSupp, /**< Call not supported (0x000d) */ dlpErrUnused1, /**< @e Unused (0x000e) */ dlpErrReadOnly, /**< File is read-only (0x000f) */ dlpErrSpace, /**< Not enough space left on device (0x0010) */ dlpErrLimit, /**< Limit reached (0x0011) */ - dlpErrSync, /**< Sync error (0x0012) */ + dlpErrSync, /**< Sync error (0x0012) */ dlpErrWrapper, /**< Wrapper error (0x0013) */ dlpErrArgument, /**< Invalid argument (0x0014) */ - dlpErrSize, /**< Invalid size (0x0015) */ + dlpErrSize, /**< Invalid size (0x0015) */ dlpErrUnknown = 127 /**< Unknown error (0x007F) */ }; +/** @brief Error codes returned by PalmOS + * + * Reference: https://www.nsbasic.com/palm/info/technotes/TN23.htm + */ +enum palmOSErrors { + errNone = 0x0000, /**< No error */ + + dmErrAlreadyExists = 0x0219, /**< Another database with the same name already exists in RAM store */ + + sysErrParamErr = 0x0502, /**< Wrong input parameter */ + + expErrUnsupportedOperation = 0x2901, /**< Unsupported or undefined opcode and/or creator */ + expErrNotEnoughPower = 0x2902, /**< The required power is not available */ + expErrCardNotPresent = 0x2903, /**< No card is present */ + expErrInvalidSlotRefNum = 0x2904, /**< Slot reference number is bad */ + expErrSlotDeallocated = 0x2905, /**< Slot reference number is within valid range, but has been deallocated */ + expErrCardNoSectorReadWrite = 0x2906, /**< The card does not support the SlotDriver block read/write API */ + expErrCardReadOnly = 0x2907, /**< The card does support R/W API but the card is read only */ + expErrCardBadSector = 0x2908, /**< The card does support R/W API but the sector is bad */ + expErrCardProtectedSector = 0x2909, /**< The card does support R/W API but the sector is protected */ + expErrNotOpen = 0x290a, /**< Slot driver library has not been opened */ + expErrStillOpen = 0x290b, /**< Slot driver library is still open - maybe it was opened > once */ + expErrUnimplemented = 0x290c, /**< Call is unimplemented */ + expErrEnumerationEmpty = 0x290d, /**< No values remaining to enumerate */ + expErrIncompatibleAPIVer = 0x290e, /**< The API version of this slot driver is not supported by this version of ExpansionMgr. */ + + vfsErrBufferOverflow = 0x2a01, /**< Passed in buffer is too small */ + vfsErrFileGeneric = 0x2a02, /**< Generic file error. */ + vfsErrFileBadRef = 0x2a03, /**< The fileref is invalid (has been closed, or was not obtained from VFS.Open() ) */ + vfsErrFileStillOpen = 0x2a04, /**< Returned from VFS.Delete if the file is still open */ + vfsErrFilePermissionDenied = 0x2a05, /**< The file is read only */ + vfsErrFileAlreadyExists = 0x2a06, /**< A file of this name exists already in this location */ + vfsErrFileEOF = 0x2a07, /**< File pointer is at end of file */ + vfsErrFileNotFound = 0x2a08, /**< File was not found at the path specified */ + vfsErrVolumeBadRef = 0x2a09, /**< The volume refnum is invalid */ + vfsErrVolumeStillMounted = 0x2a0a, /**< Returned if the volume is still mounted */ + vfsErrNoFileSystem = 0x2a0b, /**< No installed filesystem supports this operation */ + vfsErrBadData = 0x2a0c, /**< Operation could not be completed because of invalid data (i.e., import DB from .PRC file) */ + vfsErrDirNotEmpty = 0x2a0d, /**< Can't delete a non-empty directory */ + vfsErrBadName = 0x2a0e, /**< Invalid filename, or path, or volume label or something... */ + vfsErrVolumeFull = 0x2a0f, /**< Not enough space left on volume */ + vfsErrUnimplemented = 0x2a10, /**< This call is not implemented */ + vfsErrNotADirectory = 0x2a11, /**< This operation requires a directory */ + vfsErrIsADirectory = 0x2a12, /**< This operation requires a regular file, not a directory */ + vfsErrDirectoryNotFound = 0x2a13, /**< Returned from VFS.FileCreate when the path leading up to the new file does not exist */ + vfsErrNameShortened = 0x2a14 /**< A volume name or filename was automatically shortened to conform to filesystem spec */ +}; #ifndef SWIG /* no need to clutter the bindings with this */ @@ -585,21 +632,21 @@ enum dlpErrors { struct dlpArg { int id_; /**< Argument ID (start at #PI_DLP_ARG_FIRST_ID) */ size_t len; /**< Argument length */ - char *data; /**< Argument data */ + char *data; /**< Argument data */ }; /** @brief Internal DLP command request structure */ struct dlpRequest { enum dlpFunctions cmd; /**< Command ID */ - int argc; /**< Number of arguments */ + int argc; /**< Number of arguments */ struct dlpArg **argv; /**< Ptr to arguments */ }; /** @brief Internal DLP command response structure */ struct dlpResponse { enum dlpFunctions cmd; /**< Command ID as returned by device. If not the same than requested command, this is an error */ - enum dlpErrors err; /**< DLP error (see #dlpErrors enum) */ - int argc; /**< Number of response arguments */ + enum dlpErrors err; /**< DLP error (see #dlpErrors enum) */ + int argc; /**< Number of response arguments */ struct dlpArg **argv; /**< Response arguments */ }; @@ -629,8 +676,9 @@ struct dlpResponse { extern int dlp_exec PI_ARGS((int sd, struct dlpRequest *req, struct dlpResponse **res)); - extern char *dlp_errorlist[]; - extern char *dlp_strerror(int error); + extern char *pi_err_message(int error); + extern char *dlp_errorList[]; + extern char *dlp_err_message(int error); struct RPC_params; extern int dlp_RPC diff --git a/include/pi-error.h b/include/pi-error.h index 5425e77b..4c614baf 100644 --- a/include/pi-error.h +++ b/include/pi-error.h @@ -50,30 +50,30 @@ typedef int PI_ERR; /** @brief Definition of errors returned by various libpisock functions */ enum dlpErrorDefinitions { /* PROTOCOL level errors */ - PI_ERR_PROT_ABORTED = -100, /**< aborted by other end */ + PI_ERR_PROT_ABORTED = -100, /**< aborted by other end */ PI_ERR_PROT_INCOMPATIBLE = -101, /**< can't talk with other end */ PI_ERR_PROT_BADPACKET = -102, /**< bad packet (used with serial protocols) */ /* SOCKET level errors */ PI_ERR_SOCK_DISCONNECTED = -200, /**< connection has been broken */ - PI_ERR_SOCK_INVALID = -201, /**< invalid protocol stack */ - PI_ERR_SOCK_TIMEOUT = -202, /**< communications timeout (but link not known as broken) */ + PI_ERR_SOCK_INVALID = -201, /**< invalid protocol stack */ + PI_ERR_SOCK_TIMEOUT = -202, /**< communications timeout (but link not known as broken) */ PI_ERR_SOCK_CANCELED = -203, /**< last data transfer was canceled */ - PI_ERR_SOCK_IO = -204, /**< generic I/O error */ + PI_ERR_SOCK_IO = -204, /**< generic I/O error */ PI_ERR_SOCK_LISTENER = -205, /**< socket can't listen/accept */ /* DLP level errors */ - PI_ERR_DLP_BUFSIZE = -300, /**< provided buffer is not big enough to store data */ - PI_ERR_DLP_PALMOS = -301, /**< a non-zero error was returned by the device */ + PI_ERR_DLP_BUFSIZE = -300, /**< provided buffer is not big enough to store data */ + PI_ERR_DLP_PALMOS = -301, /**< a non-zero error was returned by the device */ PI_ERR_DLP_UNSUPPORTED = -302, /**< this DLP call is not supported by the connected handheld */ - PI_ERR_DLP_SOCKET = -303, /**< invalid socket */ - PI_ERR_DLP_DATASIZE = -304, /**< requested transfer with data block too large (>64k) */ - PI_ERR_DLP_COMMAND = -305, /**< command error (the device returned an invalid response) */ + PI_ERR_DLP_SOCKET = -303, /**< invalid socket */ + PI_ERR_DLP_DATASIZE = -304, /**< requested transfer with data block too large (>64k) */ + PI_ERR_DLP_COMMAND = -305, /**< command error (the device returned an invalid response) */ /* FILE level error */ - PI_ERR_FILE_INVALID = -400, /**< invalid prc/pdb/pqa/pi_file file */ - PI_ERR_FILE_ERROR = -401, /**< generic error when reading/writing file */ - PI_ERR_FILE_ABORTED = -402, /**< file transfer was aborted by progress callback, see pi_file_retrieve(), pi_file_install(), pi_file_merge() */ + PI_ERR_FILE_INVALID = -400, /**< invalid prc/pdb/pqa/pi_file file */ + PI_ERR_FILE_ERROR = -401, /**< generic error when reading/writing file */ + PI_ERR_FILE_ABORTED = -402, /**< file transfer was aborted by progress callback, see pi_file_retrieve(), pi_file_install(), pi_file_merge() */ PI_ERR_FILE_NOT_FOUND = -403, /**< record or resource not found */ PI_ERR_FILE_ALREADY_EXISTS = -404, /**< a record with same UID or resource with same type/ID already exists */ @@ -85,11 +85,29 @@ enum dlpErrorDefinitions { /** @name libpisock error management macros */ /*@{*/ - #define IS_PROT_ERR(error) ((error)<=-100 && (error)>-200) /**< Check whether the error code is at protocol level */ - #define IS_SOCK_ERR(error) ((error)<=-200 && (error)>-300) /**< Check whether the error code is at socket level */ - #define IS_DLP_ERR(error) ((error)<=-300 && (error)>-400) /**< Check whether the error code is at DLP level */ - #define IS_FILE_ERR(error) ((error)<=-400 && (error)>-500) /**< Check whether the error code os a file error */ - #define IS_GENERIC_ERR(error) ((error)<=-500 && (error)>-600) /**< Check whether the error code is a generic error */ + #define IS_PROT_ERR(error) ((error)<=-100 && (error)>-200) /**< Check whether the error code is at protocol level */ + #define IS_SOCK_ERR(error) ((error)<=-200 && (error)>-300) /**< Check whether the error code is at socket level */ + #define IS_DLP_ERR(error) ((error)<=-300 && (error)>-400) /**< Check whether the error code is at DLP level */ + #define IS_FILE_ERR(error) ((error)<=-400 && (error)>-500) /**< Check whether the error code is a file error */ + #define IS_GENERIC_ERR(error) ((error)<=-500 && (error)>-600) /**< Check whether the error code is a generic error */ +/*@}*/ + +/** @name libpisock error management macros */ +/*@{*/ + #define PI_PROT_ERR -100 /**< Offset for protocol level error */ + #define PI_SOCK_ERR -200 /**< Offset for socket level error */ + #define PI_DLP_ERR -300 /**< Offset for DLP level error */ + #define PI_FILE_ERR -400 /**< Offset for file error */ + #define PI_GENERIC_ERR -500 /**< Offset for generic error */ +/*@}*/ + +/** @name DLP PalmOS error masks */ +/*@{*/ + #define DLP_ERR 0x0000 /**< Mask for DLP level error */ + #define POS_DM_ERR 0x0200 /**< Mask for PalmOS data manager level error */ + #define POS_SYS_ERR 0x0500 /**< Mask for PalmOS system level error */ + #define POS_EXP_ERR 0x2900 /**< Mask for PalmOS expansion level error */ + #define POS_VFS_ERR 0x2A00 /**< Mask for PalmOS VFS level error */ /*@}*/ #endif diff --git a/libpisock/dlp.c b/libpisock/dlp.c index 38413290..3c7391d5 100644 --- a/libpisock/dlp.c +++ b/libpisock/dlp.c @@ -64,73 +64,126 @@ static void record_dump (unsigned long recID, unsigned int recIndex, int flags, int catID, const char *data, int data_len); #endif -char *dlp_errorlist[] = { - "No error", - "General System error", - "Illegal Function", - "Out of memory", - "Invalid parameter", - "Not found", - "None Open", - "Already Open", - "Too many Open", - "Already Exists", - "Cannot Open", - "Record deleted", - "Record busy", - "Operation not supported", - "-Unused-", - "Read only", - "Not enough space", - "Limit exceeded", - "Sync cancelled", - "Bad arg wrapper", - "Argument missing", - "Bad argument size" +char *pi_prot_errorList[] = { + "aborted by other end", /**< aborted by other end (-100) */ + "can't talk with other end", /**< can't talk with other end (-101) */ + "bad packet" /**< bad packet (used with serial protocols) (-102) */ }; -/* Look at "Error codes" in VFSMgr.h in the Palm SDK for their implementation */ -char * vfs_errorlist[] = { - "No error", - "Buffer Overflow", - "Generic file error", - "File reference is invalid", - "File still open", - "Permission denied", - "File or folder already exists", - "FileEOF", - "File not found", - "volumereference is invalid", - "Volume still mounted", - "No filesystem", - "Bad data", - "Non-empty directory", - "Invalid path or filename", - "Volume full - not enough space", - "Unimplemented", - "Not a directory", - "Is a directory", - "Directory not found", - "Name truncated" +char *pi_sock_errorList[] = { + "disconnected", /**< connection has been broken (-200) */ + "invalid protocol stack", /**< invalid protocol stack (-201) */ + "communications timeout", /**< communications timeout (but link not known as broken) (-202) */ + "transfer was canceled", /**< last data transfer was canceled (-203) */ + "generic I/O error", /**< generic I/O error (-204) */ + "socket can't listen/accept" /**< socket can't listen/accept (-205) */ +}; + +char *pi_dlp_errorList[] = { + "insufficient buffer size", /**< provided buffer is not big enough to store data (-300) */ + "PalmOS error", /**< a non-zero error was returned by the device (-301) */ + "unsupported DLP call", /**< this DLP call is not supported by the connected handheld (-302) */ + "invalid socket", /**< invalid socket (-303) */ + "data block too large", /**< requested transfer with data block too large (>64k) (-304) */ + "command error" /**< command error (the device returned an invalid response) (-305) */ +}; + +char *pi_file_errorList[] = { + "invalid file", /**< invalid prc/pdb/pqa/pi_file file (-400) */ + "generic error", /**< generic error when reading/writing file (-401) */ + "file transfer aborted by progress callback", /**< file transfer was aborted by progress callback, see pi_file_retrieve(), pi_file_install(), pi_file_merge() (-402) */ + "record or resource not found", /**< record or resource not found (-403) */ + "record or resource ID/type already exists" /**< a record with same UID or resource with same type/ID already exists (-404) */ +}; + +char *pi_generic_errorList[] = { + "out of memory", /**< not enough memory (-500) */ + "invalid argument(s)", /**< invalid argument(s) (-501) */ + "generic system error" /**< generic system error (-502) */ +}; + +char *dlp_errorList[] = { + "No error", /**< No error (0x0000) */ + "General system error", /**< System error (0x0001) */ + "Illegal function", /**< Illegal request, not supported by this version of DLP (0x0002) */ + "Out of memory", /**< Not enough memory (0x0003) */ + "Invalid parameter", /**< Invalid parameter (0x0004) */ + "Not found", /**< File, database or record not found (0x0005) */ + "None open", /**< No file opened (0x0006) */ + "Already open", /**< File already open (0x0007) */ + "Too many open", /**< Too many open files (0x0008) */ + "Already exists", /**< File already exists (0x0009) */ + "Cannot open", /**< Can't open file (0x000a) */ + "Record deleted", /**< File deleted (0x000b) */ + "Record busy", /**< Record busy (0x000c) */ + "Operation not supported", /**< Call not supported (0x000d) */ + "-Unused-", /**< @e Unused (0x000e) */ + "Read only", /**< File is read-only (0x000f) */ + "Not enough space", /**< Not enough space left on device (0x0010) */ + "Limit exceeded", /**< Limit reached (0x0011) */ + "Sync cancelled", /**< Sync error (0x0012) */ + "Bad arg wrapper", /**< Wrapper error (0x0013) */ + "Argument missing", /**< Invalid argument (0x0014) */ + "Bad argument size" /**< Invalid size (0x0015) */ +}; + +/* Look at "Error codes" in the Palm SDK for their implementation + * Reference: https://www.nsbasic.com/palm/info/technotes/TN23.htm */ +char *dm_errorList[] = { // needs offset of -0x18 + "Unknown", /**< Unknown PalmOS data manager error (0x0218) */ + "Database with same name already exists" /**< Another database with the same name already exists in RAM store (0x0219) */ +}; + +/* Look at "Error codes" in the Palm SDK for their implementation + * Reference: https://www.nsbasic.com/palm/info/technotes/TN23.htm */ +char *sys_errorList[] = { + "No error", /**< No error (0x0500) */ + "Unknown", /**< Unknown PalmOS system error (0x0501) */ + "Wrong input parameter" /**< Wrong input parameter (0x0502) */ }; /* Look at "Error codes" in ExpansionMgr.h in the Palm SDK for their implementation */ -char * exp_errorlist[] = { - "No error", - "Unsupported Operation", - "Not enough Power", - "Card not present", - "Invalid slotreference number", - "Slot deallocated", - "Card no sector read/write", - "Card read only", - "Card bad sector", - "Protected sector", - "Not open (slot driver)", - "still open (slot driver)", - "Unimplemented", - "Enumeration empty", - "Incompatible API version" +char *exp_errorList[] = { + "No error", /**< No error (0x2900) */ + "Unsupported Operation", /**< Unsupported or undefined opcode and/or creator (0x2901) */ + "Not enough Power", /**< The required power is not available (0x2902) */ + "Card not present", /**< No card is present (0x2903) */ + "Invalid slot reference number", /**< Slot reference number is bad (0x2904) */ + "Slot deallocated", /**< Slot reference number is within valid range, but has been deallocated (0x2905) */ + "Card no sector read/write", /**< The card does not support the SlotDriver block read/write API (0x2906) */ + "Card read only", /**< The card does support R/W API but the card is read only (0x2907) */ + "Card bad sector", /**< The card does support R/W API but the sector is bad (0x2908) */ + "Protected sector", /**< The card does support R/W API but the sector is protected (0x2909) */ + "Not open (slot driver)", /**< Slot driver library has not been opened (0x290a) */ + "still open (slot driver)", /**< Slot driver library is still open - maybe it was opened > once (0x290b) */ + "Unimplemented", /**< Call is unimplemented (0x290c) */ + "Enumeration empty", /**< No values remaining to enumerate (0x290d) */ + "Incompatible API version" /**< The API version of this slot driver is not supported by this version of ExpansionMgr. (0x290e) */ +}; + +/* Look at "Error codes" in VFSMgr.h in the Palm SDK for their implementation */ +char *vfs_errorList[] = { + "No error", /**< No error (0x2a00) */ + "Buffer overflow", /**< Passed in buffer is too small (0x2a01) */ + "Generic file error", /**< Generic file error (0x2a02) */ + "File reference is invalid", /**< The fileref is invalid (has been closed, or was not obtained from VFS.Open() ) (0x2a03) */ + "File still open", /**< Returned from VFS.Delete if the file is still open (0x2a04) */ + "Permission denied", /**< The file is read only (0x2a05) */ + "File or folder already exists", /**< A file of this name exists already in this location (0x2a06) */ + "FileEOF", /**< File pointer is at end of file (0x2a07) */ + "File not found", /**< File was not found at the path specified (0x2a08) */ + "volume reference is invalid", /**< The volume refnum is invalid (0x2a09) */ + "Volume still mounted", /**< Returned if the volume is still mounted (0x2a0a) */ + "No filesystem", /**< No installed filesystem supports this operation (0x2a0b) */ + "Bad data", /**< Operation could not be completed because of invalid data (i.e., import DB from .PRC file) (0x2a0c) */ + "Non-empty directory", /**< Can't delete a non-empty directory (0x2a0d) */ + "Invalid path or file name", /**< Invalid file name, or path, or volume label or something... (0x2a0e) */ + "Volume full - not enough space", /**< Not enough space left on volume (0x2a0f) */ + "Unimplemented", /**< This call is not implemented (0x2a10) */ + "Not a directory", /**< This operation requires a directory (0x2a11) */ + "Is a directory", /**< This operation requires a regular file, not a directory (0x2a12) */ + "Directory not found", /**< Returned from VFS.FileCreate when the path leading up to the new file does not exist (0x2a13) */ + "Name truncated" /**< A volume name or filename was automatically shortened to conform to filesystem spec (0x2a14) */ }; #ifdef DLP_TRACE @@ -182,11 +235,12 @@ dlp_set_protocol_version(int major, int minor) dlp_version_minor = minor; } + /*************************************************************************** * - * Function: dlp_strerror + * Function: pi_err_message * - * Summary: lookup text for dlp error + * Summary: lookup text for Pilot-Link error * * Parameters: error number * @@ -194,15 +248,69 @@ dlp_set_protocol_version(int major, int minor) * ***************************************************************************/ char -*dlp_strerror(int error) +*pi_err_message(int error) { - if (error < 0) - error = -error; + char **list; + int size; + char *prefix; + + switch (error / 100) { + case PI_PROT_ERR/100 : list = pi_prot_errorList; size = sizeof(pi_prot_errorList); + prefix = "Pilot-Link protokol error: "; break; + case PI_SOCK_ERR/100 : list = pi_sock_errorList; size = sizeof(pi_sock_errorList); + prefix = "Pilot-Link socket error: "; break; + case PI_DLP_ERR/100 : list = pi_dlp_errorList; size = sizeof(pi_dlp_errorList); + prefix = "Pilot-Link DLP error: "; break; + case PI_FILE_ERR/100 : list = pi_file_errorList; size = sizeof(pi_file_errorList); + prefix = "Pilot-Link file error: "; break; + case PI_GENERIC_ERR/100 : list = pi_generic_errorList; size = sizeof(pi_generic_errorList); + prefix = "Pilot-Link generic error: "; break; + default : return "Unknown Pilot-Link error"; + } + static char message[128]; // !!! With this static buffer this function is not thread-safe !!! + sprintf(message, "%s%s", prefix, (-error % 100) < size / sizeof(char *) + ? list[-error % 100] : "Unknown"); + return message; +} - if ((unsigned int) error >= (sizeof(dlp_errorlist) / (sizeof(char *)))) - return "Unknown error"; - return dlp_errorlist[error]; +/*************************************************************************** + * + * Function: dlp_err_message + * + * Summary: lookup text for DLP error + * + * Parameters: error number + * + * Returns: char* to error text string + * + ***************************************************************************/ +char +*dlp_err_message(int error) +{ + char **list; + int size; + char *prefix; + + if (error < 0) error = -error; + + switch (error >> 8) { + case DLP_ERR>>8 : list = dlp_errorList; size = sizeof(dlp_errorList); + prefix = "DLP error: "; break; + case POS_DM_ERR>>8 : list = dm_errorList; size = sizeof(dm_errorList); error -= 0x18; + prefix = "PalmOS data manager error: "; break; + case POS_SYS_ERR>>8 : list = sys_errorList; size = sizeof(sys_errorList); + prefix = "PalmOS system error: "; break; + case POS_EXP_ERR>>8 : list = exp_errorList; size = sizeof(exp_errorList); + prefix = "PalmOS expansion error: "; break; + case POS_VFS_ERR>>8 : list = vfs_errorList; size = sizeof(vfs_errorList); + prefix = "PalmOS VFS error: "; break; + default : return "Unknown PalmOS error"; + } + static char message[128]; // !!! With this static buffer this function is not thread-safe !!! + sprintf(message, "%s%s", prefix, (error & 0xFF) < size / sizeof(char *) + ? list[error & 0xFF] : "Unknown"); + return message; } @@ -2219,7 +2327,7 @@ dlp_ReadFeature(int sd, unsigned long creator, int num, unsigned long *feature) if (val < 0) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadFeature Error: %s (%d)\n", dlp_errorlist[-val], val)); + "DLP ReadFeature Error: %s (%d)\n", dlp_errorList[-val], val)); return val; } @@ -2290,7 +2398,7 @@ dlp_GetROMToken(int sd, unsigned long token, void *buffer, size_t *size) if (dlp_trace) { if (val < 0) fprintf(stderr, "Result: Error: %s (%d)\n", - dlp_errorlist[-val], val); + dlp_errorList[-val], val); else if (result) fprintf(stderr, "FtrGet error 0x%8.8lX\n", (unsigned long) result); @@ -2315,7 +2423,7 @@ dlp_GetROMToken(int sd, unsigned long token, void *buffer, size_t *size) #ifdef DLP_TRACE if (dlp_trace) { if (val < 0) - fprintf(stderr, "Result: Error: %s (%d)\n", dlp_errorlist[-val], val); + fprintf(stderr, "Result: Error: %s (%d)\n", dlp_errorList[-val], val); else if (result) fprintf(stderr, "FtrGet error 0x%8.8lX\n", (unsigned long) result); else diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 5720333b..c78c27f2 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -1709,7 +1709,7 @@ print_dir(long volume, const char *path, FileRef dir) { int it = vfsIteratorStart; int max = 64; - struct VFSDirInfo infos[64]; + struct VFSDirInfo infos[max]; int i; FileRef file; char buf[vfsMAXFILENAME]; @@ -1717,40 +1717,45 @@ print_dir(long volume, const char *path, FileRef dir) /* Set up buf so it contains path with trailing / and buflen points to the terminating NUL. */ - if (pathlen<1) - { + if (pathlen < 1) { printf(" NULL path.\n"); return; } - memset(buf,0,vfsMAXFILENAME); - strncpy(buf,path,vfsMAXFILENAME-1); + memset(buf, 0, vfsMAXFILENAME); + strncpy(buf, path, vfsMAXFILENAME-1); - if (buf[pathlen-1] != '/') - { - buf[pathlen]='/'; - pathlen++; + if (buf[pathlen-1] != '/') { + buf[pathlen++]='/'; } - if (pathlen>vfsMAXFILENAME-2) - { + if (pathlen > vfsMAXFILENAME-2) { printf(" Path too long.\n"); return; } - while (dlp_VFSDirEntryEnumerate(sd,dir,&it,&max,infos) >= 0) - { - if (max<1) break; - for (i = 0; i Date: Fri, 16 May 2025 16:05:32 +0200 Subject: [PATCH 27/31] Re-use dirIterator in loop and on error report it. --- libpisock/dlp.c | 5 ++-- src/pilot-xfer.c | 52 +++++++++++++++++++------------------- tests/pilot-xfer_list_D.sh | 36 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 29 deletions(-) create mode 100644 tests/pilot-xfer_list_D.sh diff --git a/libpisock/dlp.c b/libpisock/dlp.c index 3c7391d5..1761760e 100644 --- a/libpisock/dlp.c +++ b/libpisock/dlp.c @@ -4427,6 +4427,7 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, unsigned int entries, from, at, slen, count; struct dlpRequest *req; struct dlpResponse *res; +// printf("dlp_VFSDirEntryEnumerate: dirIterator=%d, maxDirItems=%d)\n", *dirIterator, *maxDirItems); RequireDLPVersion(sd,1,2); TraceX(dlp_VFSDirEntryEnumerate, "dirRef=%ld", dirRefNum); @@ -4450,6 +4451,7 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "%d results returnd (ilterator: %d)\n", entries, *dirIterator)); +// printf("dlp_exec returned %d (dirIterator=%d, entries=%d)\n", result, *dirIterator, entries); from = 8; count = 0; @@ -4484,9 +4486,6 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, from += slen + 4; } *maxDirItems = count; - } else { - *dirIterator = vfsIteratorStop; - entries = 0; } dlp_response_free (res); diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index c78c27f2..e2088c17 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -1705,53 +1705,53 @@ print_fileinfo(const char *path, FileRef file) * ***********************************************************************/ static void -print_dir(long volume, const char *path, FileRef dir) +print_dir(long volume, const char *dirPath, FileRef dir) { - int it = vfsIteratorStart; - int max = 64; - struct VFSDirInfo infos[max]; - int i; + static const int BUFFSIZE = 4; + struct VFSDirInfo infos[BUFFSIZE]; FileRef file; - char buf[vfsMAXFILENAME]; - int pathlen = strlen(path); + char filePath[vfsMAXFILENAME]; + int pathlen = strlen(dirPath); - /* Set up buf so it contains path with trailing / and + /* Set up filePath so it contains dirPath with trailing / and buflen points to the terminating NUL. */ if (pathlen < 1) { - printf(" NULL path.\n"); + printf(" NULL dirPath.\n"); return; } - memset(buf, 0, vfsMAXFILENAME); - strncpy(buf, path, vfsMAXFILENAME-1); + filePath[vfsMAXFILENAME-1] = 0; + strncpy(filePath, dirPath, vfsMAXFILENAME-1); - if (buf[pathlen-1] != '/') { - buf[pathlen++]='/'; + if (filePath[pathlen-1] != '/') { + filePath[pathlen++]='/'; } if (pathlen > vfsMAXFILENAME-2) { - printf(" Path too long.\n"); + printf(" dirPath too long.\n"); return; } - for (int entries; ; ) { - if ((entries = dlp_VFSDirEntryEnumerate(sd, dir, &it, &max, infos)) < 0) { - fprintf(stderr, "print_dir: %s\n", pi_err_message(entries)); + for (int it=vfsIteratorStart, max=BUFFSIZE, result; ; max=BUFFSIZE) { + if ((result = dlp_VFSDirEntryEnumerate(sd, dir, &it, &max, infos)) < 0) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, - "print_dir: dlp_VFSDirEntryEnumerate returned %s\n", pi_err_message(entries))); - if (entries == PI_ERR_DLP_PALMOS) { - fprintf(stderr, "print_dir: %s\n", dlp_err_message(pi_palmos_error(sd))); + "print_dir: dlp_VFSDirEntryEnumerate returned %s\n", pi_err_message(result))); + if (result == PI_ERR_DLP_PALMOS) { + result = pi_palmos_error(sd); LOG((PI_DBG_USER, PI_DBG_LVL_ERR, - "print_dir: dlp_VFSDirEntryEnumerate returned %s\n", dlp_err_message(pi_palmos_error(sd)))); - } + "print_dir: dlp_VFSDirEntryEnumerate returned %s\n", dlp_err_message(result))); + if (result != expErrEnumerationEmpty) + fprintf(stderr, " dlp_VFSDirEntryEnumerate returned %s\n", dlp_err_message(result)); + } else + fprintf(stderr, " dlp_VFSDirEntryEnumerate returned %s\n", pi_err_message(result)); break; } if (max < 1) break; - for (i = 0; i Date: Wed, 21 May 2025 13:55:15 +0200 Subject: [PATCH 28/31] Beautified `pilot-xfer -l -D` output and enhanced error messages. --- include/pi-dlp.h | 24 ++-- src/pilot-xfer.c | 259 +++++++++++++++++-------------------- tests/pilot-xfer_list_D.sh | 36 +++++- 3 files changed, 165 insertions(+), 154 deletions(-) diff --git a/include/pi-dlp.h b/include/pi-dlp.h index 9b97627f..ab687f78 100644 --- a/include/pi-dlp.h +++ b/include/pi-dlp.h @@ -923,7 +923,7 @@ struct dlpResponse { * @param version If not NULL * @return A negative value if an error occured (see pi-error.h), otherwise the size of the preference block */ - extern PI_ERR dlp_ReadAppPreference + extern int dlp_ReadAppPreference PI_ARGS((int sd, unsigned long creator, int prefid, int backup, int maxsize, void *databuf, size_t *datasize, int *version)); @@ -1494,7 +1494,7 @@ struct dlpResponse { * @param slotref The slot reference as returned by dlp_ExpSlotEnumerate(). * @return A negative value if an error occured (see pi-error.h), >=0 if a card is inserted */ - extern PI_ERR dlp_ExpCardPresent + extern int dlp_ExpCardPresent PI_ARGS((int sd, int slotref)); /** @brief Get information about a removable card inserted in an expansion slot @@ -1635,7 +1635,7 @@ struct dlpResponse { * @param sd Socket number * @param dirRef Directory reference obtained from dlp_VFSFileOpen() * @param dirItems On input, NULL pointer to #VFSDirInfo structure. On output, a pointer to the array of retrieved #VFSDirInfo structures. You are too responsible for free()'ing it, once you're done with it. Additionally for each @p VFSDirInfo.name fields a char buffer is allocated, which must be free()'ed too after use, before free()'ing the whole array of retrieved #VFSDirInfo structures. - * @return The number of #VFSDirInfo structures stored in @p dirItems. A negative value, if an error occured (see pi-error.h) + * @return A negative value if an error occured (see pi-error.h), the number of found dirItems otherwise. */ extern int dlp_VFSDirEntryEnumerate PI_ARGS((int sd, FileRef dirRef, struct VFSDirInfo **dirItems)); @@ -1698,9 +1698,9 @@ struct dlpResponse { /** @brief Open an existing file on a VFS volume * - * Supported on Palm OS 4.0 and later. On some devices, it is required to open the - * file using the #dlpOpenReadWrite mode to be able to write to it (using - * #dlpOpenWrite is not enough). + * Supported on Palm OS 4.0 and later. On some devices, it is required to open + * the file using the #dlpOpenReadWrite mode to be able to write to it (using + * #dlpOpenWrite is not enough, see: https://github.com/desrod/pilot-link/issues/10). * * @param sd Socket number * @param volref Volume reference number (obtained from dlp_VFSVolumeEnumerate()) @@ -1726,8 +1726,10 @@ struct dlpResponse { /** @brief Write data to an open file * - * Supported on Palm OS 4.0 and later. Will return the number of bytes - * written if successful. + * Supported on Palm OS 4.0 and later. Will return the number of bytes written + * if successful. On some devices, it is required to open the file using + * the #dlpOpenReadWrite mode to be able to write to it (using #dlpOpenWrite + * is not enough, see: https://github.com/desrod/pilot-link/issues/10). * * @param sd Socket number * @param fileref File reference obtained from dlp_VFSFileOpen() @@ -1735,7 +1737,7 @@ struct dlpResponse { * @param datasize Length of the data to write * @return A negative value if an error occured (see pi-error.h), the number of bytes written otherwise. */ - extern PI_ERR dlp_VFSFileWrite + extern int dlp_VFSFileWrite PI_ARGS((int sd, FileRef fileref, PI_CONST void *databuf, size_t datasize)); /** @brief Read data from an open file @@ -1749,7 +1751,7 @@ struct dlpResponse { * @param reqbytes Number of bytes to read from the file. * @return A negative value if an error occured (see pi-error.h), or the total number of bytes read */ - extern PI_ERR dlp_VFSFileRead + extern int dlp_VFSFileRead PI_ARGS((int sd, FileRef fileref, pi_buffer_t *retbuf, size_t reqbytes)); /** @brief Delete an existing file from a VFS volume @@ -1790,7 +1792,7 @@ struct dlpResponse { * @param fileref File reference obtained from dlp_VFSFileOpen() * @return A negative value if an error occured (see pi-error.h). 0 if not at EOF, >0 if at EOF. */ - extern PI_ERR dlp_VFSFileEOF + extern int dlp_VFSFileEOF PI_ARGS((int sd, FileRef fileref)); /** @brief Return the current seek position in an open file diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index aacffbb9..c51dacd3 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -111,8 +111,7 @@ char *vfsdir = NULL; char *exclude[MAXEXCLUDE]; int numexclude = 0; -static int findVFSPath(const char *path, long *volume, char *rpath, - int *rpathlen); +static int findVFSPath(const char *path, long *volume, char *rpath, int *rpathlen); const char *media_name(int m) @@ -1666,27 +1665,35 @@ palm_list_internal(unsigned long int flags) * * Function: print_fileinfo * - * Summary: Show information about the given @p file (which is + * Summary: Show information about the given @p fileRef (which is * assumed to have VFS path @p path). * - * Parameters: path --> path to file in VFS volume. - * file --> FileRef for already opened file. + * Parameters: err --> possible PI_ERR. + * fileRef --> FileRef for already opened file. + * path --> path to file in VFS volume. * * Returns: Nothing * ***********************************************************************/ static void -print_fileinfo(const char *path, FileRef file) +print_fileinfo(PI_ERR err, FileRef fileRef, const char *path) { int size; - time_t date; - char *s; - - (void) dlp_VFSFileSize(sd,file,&size); - (void) dlp_VFSFileGetDate(sd,file,vfsFileDateModified,&date); - s = ctime(&date); - s[24]=0; - printf(" %8d %s %s\n",size,s,path); + time_t epoch; + + err = err < 0 ? err : dlp_VFSFileSize(sd, fileRef, &size); + err = err < 0 ? err : dlp_VFSFileGetDate(sd, fileRef, vfsFileDateModified, &epoch); + if (err < 0) { + if (err != PI_ERR_DLP_PALMOS) + printf(" %s", pi_err_message(err)); + else + printf(" %s", dlp_err_message(pi_palmos_error(sd))); + printf(": %s\n", path); + } else { + char *date = ctime(&epoch); + date[24] = 0; + printf(" %8d %s %s\n", size, date, path); + } } /*********************************************************************** @@ -1698,8 +1705,8 @@ print_fileinfo(const char *path, FileRef file) * path @p path on that volume. * * Parameters: volume --> volume ref number. - * path --> path to directory. - * dir --> file ref to already opened dir. + * dirPath --> path to directory. + * dirRef --> file ref to already opened dir. * * Returns: Nothing * @@ -1707,27 +1714,23 @@ print_fileinfo(const char *path, FileRef file) static void print_dir(long volume, const char *dirPath, FileRef dirRef) { - int pathlen = strlen(dirPath); char filePath[vfsMAXFILENAME]; + int pathlen; struct VFSDirInfo *infos = NULL; - FileRef file; + FileRef fileRef; // Set up filePath so it contains dirPath with trailing / and // pathlen points to the terminating NUL. - if (pathlen == 0) { - printf(" NULL dirPath.\n"); - return; - } - filePath[vfsMAXFILENAME-1] = 0; strncpy(filePath, dirPath, vfsMAXFILENAME-1); + pathlen = strlen(filePath); - if (filePath[pathlen-1] != '/') { + if (pathlen == 0 || filePath[pathlen-1] != '/') { filePath[pathlen++]='/'; } if (pathlen > vfsMAXFILENAME-2) { - printf(" dirPath too long.\n"); + fprintf(stderr, " dirPath too long.\n"); return; } @@ -1739,21 +1742,22 @@ print_dir(long volume, const char *dirPath, FileRef dirRef) entries = pi_palmos_error(sd); LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "print_dir: dlp_VFSDirEntryEnumerate returned %s\n", dlp_err_message(entries))); - if (entries != expErrEnumerationEmpty) - fprintf(stderr, " dlp_VFSDirEntryEnumerate returned %s\n", dlp_err_message(entries)); + if (entries == expErrEnumerationEmpty) + printf(" No files in this directory.\n"); + else + fprintf(stderr, " dlp_VFSDirEntryEnumerate returned %s\n", dlp_err_message(entries)); } else - fprintf(stderr, " dlp_VFSDirEntryEnumerate returned %s\n", pi_err_message(entries)); + fprintf(stderr, " dlp_VFSDirEntryEnumerate returned %s\n", pi_err_message(entries)); return; } for (int i = 0; i= 0) { + dlp_VFSFileClose(sd, fileRef); } free(infos[i].name); } @@ -1983,9 +1987,11 @@ palm_cardinfo () * * Returns: -2 on VFSVolumeEnumerate error, * -1 if no match was found, - * 0 if a match was found and @p match is set, - * 1 if no match but only one VFS volume exists and - * match is set. + * 0 if a match was found; @p match is set, + * 1 if no match but at least one VFS volume exists; match is set + * to the first, or if found, the first unlabeled volume, + * 2 if invalid cardID but at least one VFS volume exists; match is set + * to the first, or if found, the first unlabeled volume. * ***********************************************************************/ static int @@ -1996,7 +2002,7 @@ findVFSRoot_clumsy(const char *root_component, long *match) char labels[16][vfsMAXFILENAME]; long matched_volume = -1; - if (dlp_VFSVolumeEnumerate(sd,&volume_count,volumes) < 0) + if (dlp_VFSVolumeEnumerate(sd, &volume_count, volumes) < 0) { return -2; } @@ -2008,41 +2014,46 @@ findVFSRoot_clumsy(const char *root_component, long *match) first filename component. */ for (int i=0; i= 0) { *match = matched_volume; return 0; - } else if (volume_count > 0) { // Assume at least one card and match. + } else if (volume_count > 0) { // assume at least one card and match *match = volumes[0]; for (int i=0; i volume ref number. - * path --> path to file or directory. - * - * Returns: Nothing - * - ***********************************************************************/ -static void palm_list_VFSDir(long volume, const char *path) -{ - FileRef file; - unsigned long attributes; - - if (dlp_VFSFileOpen(sd,volume,path,dlpVFSOpenRead,&file) < 0) - { - printf(" %s: No such file or directory.\n",path); - return; - } - - if (dlp_VFSFileGetAttributes(sd,file,&attributes) < 0) - { - printf(" %s: Cannot get attributes.\n",path); - return; - } - - if (vfsFileAttrDirectory == (attributes & vfsFileAttrDirectory)) - { - /* directory */ - print_dir(volume,path,file); - } else { - /* file */ - print_fileinfo(path,file); - } - - (void) dlp_VFSFileClose(sd,file); + return r; } /*********************************************************************** @@ -2168,10 +2140,10 @@ static void palm_list_VFSDir(long volume, const char *path) * Function: palm_list_VFS * * Summary: Show information about the directory or file specified - * in global vfsdir. Listing / will always tell you the - * physical VFS cards present; other paths should specify - * either a card as /cardX/ in the path of a volume label. - * As a special case, /dir/ is mapped to /card1/dir/ if + * in global vfsdir. Listing / or nothing will tell you the + * physical VFS cards present; other paths should prepend either + * /BUILTIN or a card as /cardX in the path of a volume label. + * As a special case, / or nothing is mapped to /card1 if * there is only one card. * * Parameters: None @@ -2182,35 +2154,48 @@ static void palm_list_VFSDir(long volume, const char *path) static void palm_list_VFS() { - char root_component[vfsMAXFILENAME]; - int rootlen = vfsMAXFILENAME; - long matched_volume = -1; + char path[vfsMAXFILENAME]; + int pathlen = vfsMAXFILENAME; + long volume = -1; int r; + FileRef fileRef; + unsigned long attributes = 0; - /* Listing the root directory / has special handling. Detect that - here. */ - if (NULL == vfsdir) - vfsdir="/"; + // Listing the root directory / has special handling. Detect that here. + if (NULL == vfsdir || strlen(vfsdir) == 0) + vfsdir = "/"; - /* Find the given directory. Will list the VFS root dir if the - requested dir is "/" */ - printf(" Directory of %s...\n",vfsdir); + // Find the given directory. Will list the VFS root dir if the requested dir is "/" - r = findVFSPath(vfsdir,&matched_volume,root_component,&rootlen); + r = findVFSPath(vfsdir, &volume, path, &pathlen); - if (-2 == r) - { + if (-2 == r) { fprintf(stderr," Not ready reading drive C:\n"); return; } - if (r < 0) - { - fprintf(stderr," No such directory, use pilot-xfer -C to list volumes.\n"); - return; + +// printf(" With %s, r=%d check path %s on volume %ld\n", vfsdir, r, path, volume); + PI_ERR err = r >= 0 ? dlp_VFSFileOpen(sd, volume, path, dlpVFSOpenRead, &fileRef) : -1; + + if (err < 0 && r == 2) + printf(" Invalid cardID (use pilot-xfer -C to list cards / volumes) and ...\n"); + +// printf(" On volume: %ld read path: %s, err: %d, fileRef: %ld\n", volume, path, err, fileRef); + char *defVol = r > 0 ? " default" : ""; + if (err >= 0 && (err = dlp_VFSFileGetAttributes(sd, fileRef, &attributes)) >= 0 + && attributes & vfsFileAttrDirectory) { + // directory + printf(" Directory on%s volume %ld of %s...\n", defVol, volume, path); + print_dir(volume, path, fileRef); + } else { + // file + if (err >= 0 && !(attributes & vfsFileAttrDirectory) && path[pathlen-1] == '/') + path[pathlen-1] = 0; + printf(" File on%s volume %ld:\n", defVol, volume); + print_fileinfo(err, fileRef, path); } - /* printf(" Reading card dir %s on volume %ld\n",root_component,matched_volume); */ - palm_list_VFSDir(matched_volume,root_component); + (void) dlp_VFSFileClose(sd, fileRef); } /*********************************************************************** diff --git a/tests/pilot-xfer_list_D.sh b/tests/pilot-xfer_list_D.sh index 64bc5f96..176f5a82 100644 --- a/tests/pilot-xfer_list_D.sh +++ b/tests/pilot-xfer_list_D.sh @@ -1,36 +1,60 @@ echo '****** pilot-xfer -p /dev/ttyUSB1 -C ******' +echo '************ Hit HotSync button ! ************' sleep 3 dist/bin/pilot-xfer -p /dev/ttyUSB1 -C -echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN" ******' +echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "BUILTIN" ******' +echo '************ Hit HotSync button ! ************' sleep 8 -dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN" +dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "BUILTIN" echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/BLAZER" ******' +echo '************ Hit HotSync button ! ************' sleep 8 dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/BLAZER" -echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/PALM_DM" ******' +echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/PALM_DM/" ******' +echo '************ Hit HotSync button ! ************' sleep 8 -dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/PALM_DM" +dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/PALM_DM/" echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/PALM_DM/ReserveFile" ******' +echo '************ Hit HotSync button ! ************' sleep 8 dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/PALM_DM/ReserveFile" -echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/SpaceHolderFile" ******' +echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/SpaceHolderFile/" ******' +echo '************ Hit HotSync button ! ************' sleep 8 -dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/SpaceHolderFile" +dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/SpaceHolderFile/" echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/Photos & Videos" ******' +echo '************ Hit HotSync button ! ************' sleep 8 dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/BUILTIN/Photos & Videos" echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/" ******' +echo '************ Hit HotSync button ! ************' sleep 8 dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/" echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/PALM" ******' +echo '************ Hit HotSync button ! ************' sleep 8 dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/PALM" echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/PALM/Launcher" ******' +echo '************ Hit HotSync button ! ************' sleep 8 dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/PALM/Launcher" echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/DCIM" ******' +echo '************ Hit HotSync button ! ************' sleep 8 dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/DCIM" echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/DCIM/137DSCIM" ******' +echo '************ Hit HotSync button ! ************' sleep 8 dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/DCIM/137DSCIM" +echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "card1/not_existing" ******' +echo '************ Hit HotSync button ! ************' +sleep 8 +dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "card1/not_existing" +echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "card9/test" ******' +echo '************ Hit HotSync button ! ************' +sleep 8 +dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "card9/test" +echo '****** pilot-xfer -p /dev/ttyUSB1 -l -D "/non/sense" ******' +echo '************ Hit HotSync button ! ************' +sleep 8 +dist/bin/pilot-xfer -p /dev/ttyUSB1 -l -D "/non/sense" From 1448a6fbffda1440e0819293ca7f3caec702ede9 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Wed, 21 May 2025 16:37:19 +0200 Subject: [PATCH 29/31] Updated versions of libpisock and Pilot-Link, as API was changed. --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 67dc0e2c..11044b91 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,7 @@ dnl Pilot Link Version dnl ****************************** PILOT_LINK_VERS=0 PILOT_LINK_MAJOR=13 -PILOT_LINK_MINOR=3 +PILOT_LINK_MINOR=4 PILOT_LINK_PATCH= AC_SUBST(PILOT_LINK_VERS) @@ -41,8 +41,8 @@ dnl Please see the following URL for details: dnl http://sources.redhat.com/autobook/autobook/autobook_91.html dnl ****************************** PISOCK_CURRENT=10 -PISOCK_REVISION=2 -PISOCK_AGE=1 +PISOCK_REVISION=0 +PISOCK_AGE=0 AC_SUBST(PISOCK_CURRENT) AC_SUBST(PISOCK_REVISION) From 80e7a99a9a6a996d469ba5cca878318b4314595b Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Thu, 22 May 2025 21:34:25 +0200 Subject: [PATCH 30/31] Fixed bug in `print_file_info()`, so now, if a directory, instead size the number of entries is shown. --- src/pilot-xfer.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 61c0648b..bbf0dd88 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -1676,23 +1676,27 @@ palm_list_internal(unsigned long int flags) * ***********************************************************************/ static void -print_fileinfo(PI_ERR err, FileRef fileRef, const char *path) +print_fileinfo(PI_ERR err, FileRef fileRef, const char *path, unsigned long attributes) { int size; time_t epoch; - err = err < 0 ? err : dlp_VFSFileSize(sd, fileRef, &size); - err = err < 0 ? err : dlp_VFSFileGetDate(sd, fileRef, vfsFileDateModified, &epoch); - if (err < 0) { + if (err >= 0) + if (attributes & vfsFileAttrDirectory) + err = size = dlp_VFSDirEntryEnumerate(sd, fileRef, NULL); + else + err = dlp_VFSFileSize(sd, fileRef, &size); + err = (err >= 0) ? dlp_VFSFileGetDate(sd, fileRef, vfsFileDateModified, &epoch) : err; + if (err >= 0) { + char *date = ctime(&epoch); + date[24] = 0; + printf(" %8d %s %s\n", size, date, path); + } else { if (err != PI_ERR_DLP_PALMOS) printf(" %s", pi_err_message(err)); else printf(" %s", dlp_err_message(pi_palmos_error(sd))); printf(": %s\n", path); - } else { - char *date = ctime(&epoch); - date[24] = 0; - printf(" %8d %s %s\n", size, date, path); } } @@ -1754,7 +1758,7 @@ print_dir(long volume, const char *dirPath, FileRef dirRef) memset(filePath+pathlen, 0, vfsMAXFILENAME-pathlen); strncpy(filePath+pathlen, infos[i].name, vfsMAXFILENAME-pathlen); PI_ERR err = dlp_VFSFileOpen(sd, volume, filePath, dlpVFSOpenRead, &fileRef); - print_fileinfo(err, fileRef, infos[i].name); + print_fileinfo(err, fileRef, infos[i].name, infos[i].attr); if (err >= 0) { dlp_VFSFileClose(sd, fileRef); } @@ -2191,7 +2195,7 @@ palm_list_VFS() if (err >= 0 && !(attributes & vfsFileAttrDirectory) && path[pathlen-1] == '/') path[pathlen-1] = 0; printf(" File on%s volume %ld:\n", defVol, volume); - print_fileinfo(err, fileRef, path); + print_fileinfo(err, fileRef, path, attributes); } (void) dlp_VFSFileClose(sd, fileRef); From 7c1d67b6895e698ab416428ffed51e8ed1bbb443 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: Fri, 23 May 2025 00:33:16 +0200 Subject: [PATCH 31/31] Output file attributes as characters. --- src/pilot-xfer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 69ccfda8..d82e464a 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -1689,9 +1689,14 @@ print_fileinfo(PI_ERR err, FileRef fileRef, const char *path, unsigned long attr err = dlp_VFSFileSize(sd, fileRef, &size); err = (err >= 0) ? dlp_VFSFileGetDate(sd, fileRef, vfsFileDateModified, &epoch) : err; if (err >= 0) { + char attr_chars[] = "ladvshr"; + for (int i=0; i> i))) + attr_chars[i] = '-'; + } char *date = ctime(&epoch); date[24] = 0; - printf(" %02X %8d %s %s\n", attributes, size, date, path); + printf(" %s %8d %s %s\n", attr_chars, size, date, path); } else { if (err != PI_ERR_DLP_PALMOS) printf(" %s", pi_err_message(err));