From 9f79156be648e0564f6c9ea60c7300e60f211ad1 Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Wed, 25 Apr 2018 02:52:34 +0200 Subject: [PATCH] Integrated p7utils into this repository. --- .gitignore | 2 + AUTHORS.rst | 4 + CONTRIBUTING.md => CONTRIBUTING.rst | 6 +- GPL2.md | 336 ++++++++++++ LICENSE.md => LGPL3.md | 0 LICENSE.rst | 10 + Makefile | 230 ++++++--- Makefile.vars | 295 +++++++---- README.md | 76 --- README.rst | 80 +++ configure | 129 +++-- include/libcasio/fs.h | 25 +- include/libcasio/mcsfile.h | 2 +- {src => lib}/bcd/cas.c | 0 {src => lib}/bcd/double.c | 0 {src => lib}/bcd/mcs.c | 0 {src => lib}/bcd/str.c | 0 {src => lib}/char/utf32_to_fontchar16.c.draft | 0 {src => lib}/comlist/builtin/linux.c | 0 {src => lib}/comlist/builtin/macos.c | 0 {src => lib}/comlist/builtin/windows.c | 0 {src => lib}/comlist/comlist.c | 0 {src => lib}/date/decode.c | 0 {src => lib}/date/encode.c | 0 {src => lib}/errors.c | 0 {src => lib}/file/corresp/standard.c | 0 {src => lib}/file/corresp/standard.h | 0 {src => lib}/file/corresp/standard_sub.c | 0 {src => lib}/file/decode.c | 0 {src => lib}/file/decode/cafix.c.draft | 0 {src => lib}/file/decode/cas.c | 0 {src => lib}/file/decode/casemul.c | 0 {src => lib}/file/decode/decode.h | 0 {src => lib}/file/decode/fxi.c.draft | 0 {src => lib}/file/decode/newcat.c.draft | 0 {src => lib}/file/decode/std.c | 0 {src => lib}/file/decode/std/addin.c | 0 {src => lib}/file/decode/std/dict.c | 0 {src => lib}/file/decode/std/dict.h | 0 {src => lib}/file/decode/std/eact.c.draft | 0 {src => lib}/file/decode/std/fkey.c | 0 {src => lib}/file/decode/std/lang.c | 0 {src => lib}/file/decode/std/mcs.c | 0 {src => lib}/file/decode/std/picture.c | 0 {src => lib}/file/file.h | 0 {src => lib}/file/manage.c | 0 {src => lib}/file/open.c | 0 {src => lib}/fontchar/fontchar.h | 0 {src => lib}/fontchar/lead.c.draft | 0 {src => lib}/fontchar/open.c.draft | 0 {src => lib}/fontchar/reference.h | 0 {src => lib}/fs/builtin/posix/del.c | 0 {src => lib}/fs/builtin/posix/frompath.c | 0 {src => lib}/fs/builtin/posix/make.c | 0 {src => lib}/fs/builtin/posix/open_fs.c | 2 +- {src => lib}/fs/builtin/posix/posix.h | 0 {src => lib}/fs/builtin/posix/stat.c | 0 {src => lib}/fs/builtin/posix/topath.c | 0 {src => lib}/fs/builtin/windows/make.c | 0 {src => lib}/fs/builtin/windows/topath.c | 0 {src => lib}/fs/builtin/windows/windows.h | 0 {src => lib}/fs/delete.c | 0 {src => lib}/fs/fs.h | 0 {src => lib}/fs/makedir.c | 0 {src => lib}/fs/open.c | 32 +- {src => lib}/fs/open_file.c | 0 lib/fs/optimize.c | 45 ++ {src => lib}/fs/path.c | 0 {src => lib}/fs/pathnode.c | 0 {src => lib}/internals.h | 0 {src => lib}/link/info.c | 0 {src => lib}/link/link.h | 0 {src => lib}/link/lock.c | 0 {src => lib}/link/open.c | 0 {src => lib}/link/open/com.c | 0 {src => lib}/link/open/usb.c | 0 {src => lib}/link/seven/command.c | 0 {src => lib}/link/seven/data.c | 8 +- {src => lib}/link/seven/data.h | 0 {src => lib}/link/seven/dataflow.c | 0 {src => lib}/link/seven/datastream.c | 0 {src => lib}/link/seven/devices.c | 0 {src => lib}/link/seven/eack.c | 0 {src => lib}/link/seven/encoderaw.c | 0 {src => lib}/link/seven/init.c | 0 {src => lib}/link/seven/receive.c | 0 {src => lib}/link/seven/send.c | 0 {src => lib}/link/seven_fs/delete.c | 0 {src => lib}/link/seven_fs/open.c | 3 +- lib/link/seven_fs/optimize.c | 42 ++ {src => lib}/link/seven_fs/seven_fs.h | 5 + {src => lib}/link/seven_fs/topath.c | 0 {src => lib}/link/seven_mcs/delete.c | 0 {src => lib}/link/seven_mcs/get.c | 0 {src => lib}/link/seven_mcs/list.c | 0 {src => lib}/link/seven_mcs/open.c | 0 {src => lib}/link/seven_mcs/put.c.draft | 0 {src => lib}/link/seven_mcs/seven_mcs.h | 0 {src => lib}/link/usage/backup_rom.c | 0 {src => lib}/link/usage/getscreen.c | 0 {src => lib}/link/usage/server/seven.c | 0 {src => lib}/link/usage/setlink.c | 0 {src => lib}/link/usage/upload_and_run.c | 2 + {src => lib}/link/usage/usage.h | 0 {src => lib}/log/conv.c | 0 {src => lib}/log/log.h | 0 {src => lib}/log/manage.c | 0 {src => lib}/log/mem.c | 0 {src => lib}/log/msg.c | 0 {src => lib}/mcs/delete.c | 0 {src => lib}/mcs/get.c | 0 {src => lib}/mcs/list.c | 0 {src => lib}/mcs/local/delete.c | 0 {src => lib}/mcs/local/find.c | 0 {src => lib}/mcs/local/get.c | 0 {src => lib}/mcs/local/list.c | 0 {src => lib}/mcs/local/local.h | 0 {src => lib}/mcs/local/open.c | 0 {src => lib}/mcs/local/put.c | 0 {src => lib}/mcs/mcs.h | 0 {src => lib}/mcs/open.c | 0 {src => lib}/mcs/put.c | 0 {src => lib}/mcs/transfer.c | 0 {src => lib}/mcsfile/copy.c | 0 {src => lib}/mcsfile/decode/cas.c | 0 {src => lib}/mcsfile/decode/cas/cell.c | 0 {src => lib}/mcsfile/decode/cas/program.c | 0 {src => lib}/mcsfile/decode/cas/sshot.c | 0 {src => lib}/mcsfile/decode/decode.h | 0 {src => lib}/mcsfile/decode/mcs.c | 0 {src => lib}/mcsfile/decode/mcs/cells.c | 0 {src => lib}/mcsfile/decode/mcs/picture.c | 0 {src => lib}/mcsfile/decode/mcs/program.c | 0 {src => lib}/mcsfile/decode/mcs/setup.c | 0 {src => lib}/mcsfile/decode/mcs/ssheet.c | 0 {src => lib}/mcsfile/decode/mcs/string.c | 0 {src => lib}/mcsfile/decode/mcs/var.c | 0 {src => lib}/mcsfile/dup.c | 0 {src => lib}/mcsfile/free.c | 0 {src => lib}/mcsfile/head.c | 0 {src => lib}/mcsfile/make.c | 0 {src => lib}/mcsfile/match.c | 0 {src => lib}/mcsfile/mcsfile.h | 0 {src => lib}/mcsfile/prepare.c | 0 {src => lib}/mcsfile/ref/cas_app.c | 0 {src => lib}/mcsfile/ref/cas_data.c | 0 {src => lib}/mcsfile/ref/mcs.c | 0 {src => lib}/mcsfile/ref/ref.h | 0 {src => lib}/picture/decode.c | 0 {src => lib}/picture/encode.c | 0 {src => lib}/picture/picture.h | 0 {src => lib}/picture/size.c | 0 {src => lib}/setup/export.c.draft | 0 {src => lib}/setup/feed_mcs.c | 0 {src => lib}/setup/feed_seven.c | 0 {src => lib}/setup/init.c | 0 {src => lib}/setup/setup.h | 0 {src => lib}/stream/attrs.c | 0 {src => lib}/stream/builtin/csum32.c | 13 +- {src => lib}/stream/builtin/file.c | 80 ++- {src => lib}/stream/builtin/libusb/close.c | 6 +- {src => lib}/stream/builtin/libusb/libusb.h | 7 +- {src => lib}/stream/builtin/libusb/open.c | 83 +-- {src => lib}/stream/builtin/libusb/read.c | 23 +- {src => lib}/stream/builtin/libusb/settm.c | 4 +- {src => lib}/stream/builtin/libusb/write.c | 3 +- {src => lib}/stream/builtin/limited.c | 12 +- {src => lib}/stream/builtin/memory.c | 42 +- {src => lib}/stream/builtin/streams/close.c | 6 +- {src => lib}/stream/builtin/streams/open.c | 48 +- {src => lib}/stream/builtin/streams/read.c | 27 +- {src => lib}/stream/builtin/streams/scsi.c | 0 .../stream/builtin/streams/setattrs.c | 36 +- {src => lib}/stream/builtin/streams/settm.c | 18 +- {src => lib}/stream/builtin/streams/streams.h | 7 +- {src => lib}/stream/builtin/streams/write.c | 7 +- {src => lib}/stream/builtin/windows/close.c | 0 {src => lib}/stream/builtin/windows/find.c | 44 +- {src => lib}/stream/builtin/windows/open.c | 18 +- {src => lib}/stream/builtin/windows/read.c | 22 +- {src => lib}/stream/builtin/windows/seek.c | 19 +- .../stream/builtin/windows/setattrs.c | 28 +- {src => lib}/stream/builtin/windows/settm.c | 5 +- {src => lib}/stream/builtin/windows/windows.h | 3 +- {src => lib}/stream/builtin/windows/write.c | 14 +- {src => lib}/stream/get.c | 0 {src => lib}/stream/open.c | 0 {src => lib}/stream/open/com.c | 0 {src => lib}/stream/open/usb.c | 0 {src => lib}/stream/read.c | 0 {src => lib}/stream/seek.c | 0 {src => lib}/stream/size.c | 0 {src => lib}/stream/skip.c | 0 {src => lib}/stream/stream.h | 0 {src => lib}/stream/timeouts.c | 0 {src => lib}/stream/write.c | 0 {src => lib}/utils/alloc.c | 0 {src => lib}/utils/ascii.c | 0 {src => lib}/utils/checksum.c | 0 {src => lib}/utils/endian.c | 0 {src => lib}/utils/endian.h | 0 {src => lib}/utils/ext.c | 0 {src => lib}/utils/mutex.c | 0 {src => lib}/utils/sleep.c | 0 {src => lib}/version.c | 0 {src => lib}/version/check.c | 0 {src => lib}/version/decode.c | 0 {src => lib}/version/encode.c | 0 src/g1a-wrapper/args.c | 194 +++++++ src/g1a-wrapper/icon.c | 94 ++++ src/g1a-wrapper/main.c | 100 ++++ src/g1a-wrapper/main.h | 50 ++ src/g1a-wrapper/vars.mk | 4 + src/mcsfile/args.c | 175 +++++++ src/mcsfile/main.c | 72 +++ src/mcsfile/main.h | 36 ++ src/mcsfile/print.c | 120 +++++ src/mcsfile/vars.mk | 4 + src/p7/args.c | 488 ++++++++++++++++++ src/p7/dump.c | 94 ++++ src/p7/list_devices.c | 53 ++ src/p7/main.c | 354 +++++++++++++ src/p7/main.h | 63 +++ src/p7/vars.mk | 3 + src/p7os/args.c | 311 +++++++++++ src/p7os/main.c | 101 ++++ src/p7os/main.h | 79 +++ src/p7os/procs/std_backup.c | 50 ++ src/p7os/procs/std_prepare.c | 65 +++ src/p7os/utils/open_link.c | 44 ++ src/p7os/utils/osdisp.c | 120 +++++ src/p7os/vars.mk | 4 + src/p7screen/args.c | 178 +++++++ src/p7screen/main.c | 164 ++++++ src/p7screen/main.h | 32 ++ src/p7screen/vars.mk | 3 + src/p7servtest/args.c | 97 ++++ src/p7servtest/client.c | 51 ++ src/p7servtest/main.c | 82 +++ src/p7servtest/main.h | 29 ++ src/p7servtest/server.c | 121 +++++ src/p7servtest/vars.mk | 4 + 242 files changed, 4856 insertions(+), 492 deletions(-) create mode 100644 AUTHORS.rst rename CONTRIBUTING.md => CONTRIBUTING.rst (53%) create mode 100644 GPL2.md rename LICENSE.md => LGPL3.md (100%) create mode 100644 LICENSE.rst delete mode 100644 README.md create mode 100644 README.rst rename {src => lib}/bcd/cas.c (100%) rename {src => lib}/bcd/double.c (100%) rename {src => lib}/bcd/mcs.c (100%) rename {src => lib}/bcd/str.c (100%) rename {src => lib}/char/utf32_to_fontchar16.c.draft (100%) rename {src => lib}/comlist/builtin/linux.c (100%) rename {src => lib}/comlist/builtin/macos.c (100%) rename {src => lib}/comlist/builtin/windows.c (100%) rename {src => lib}/comlist/comlist.c (100%) rename {src => lib}/date/decode.c (100%) rename {src => lib}/date/encode.c (100%) rename {src => lib}/errors.c (100%) rename {src => lib}/file/corresp/standard.c (100%) rename {src => lib}/file/corresp/standard.h (100%) rename {src => lib}/file/corresp/standard_sub.c (100%) rename {src => lib}/file/decode.c (100%) rename {src => lib}/file/decode/cafix.c.draft (100%) rename {src => lib}/file/decode/cas.c (100%) rename {src => lib}/file/decode/casemul.c (100%) rename {src => lib}/file/decode/decode.h (100%) rename {src => lib}/file/decode/fxi.c.draft (100%) rename {src => lib}/file/decode/newcat.c.draft (100%) rename {src => lib}/file/decode/std.c (100%) rename {src => lib}/file/decode/std/addin.c (100%) rename {src => lib}/file/decode/std/dict.c (100%) rename {src => lib}/file/decode/std/dict.h (100%) rename {src => lib}/file/decode/std/eact.c.draft (100%) rename {src => lib}/file/decode/std/fkey.c (100%) rename {src => lib}/file/decode/std/lang.c (100%) rename {src => lib}/file/decode/std/mcs.c (100%) rename {src => lib}/file/decode/std/picture.c (100%) rename {src => lib}/file/file.h (100%) rename {src => lib}/file/manage.c (100%) rename {src => lib}/file/open.c (100%) rename {src => lib}/fontchar/fontchar.h (100%) rename {src => lib}/fontchar/lead.c.draft (100%) rename {src => lib}/fontchar/open.c.draft (100%) rename {src => lib}/fontchar/reference.h (100%) rename {src => lib}/fs/builtin/posix/del.c (100%) rename {src => lib}/fs/builtin/posix/frompath.c (100%) rename {src => lib}/fs/builtin/posix/make.c (100%) rename {src => lib}/fs/builtin/posix/open_fs.c (98%) rename {src => lib}/fs/builtin/posix/posix.h (100%) rename {src => lib}/fs/builtin/posix/stat.c (100%) rename {src => lib}/fs/builtin/posix/topath.c (100%) rename {src => lib}/fs/builtin/windows/make.c (100%) rename {src => lib}/fs/builtin/windows/topath.c (100%) rename {src => lib}/fs/builtin/windows/windows.h (100%) rename {src => lib}/fs/delete.c (100%) rename {src => lib}/fs/fs.h (100%) rename {src => lib}/fs/makedir.c (100%) rename {src => lib}/fs/open.c (78%) rename {src => lib}/fs/open_file.c (100%) create mode 100644 lib/fs/optimize.c rename {src => lib}/fs/path.c (100%) rename {src => lib}/fs/pathnode.c (100%) rename {src => lib}/internals.h (100%) rename {src => lib}/link/info.c (100%) rename {src => lib}/link/link.h (100%) rename {src => lib}/link/lock.c (100%) rename {src => lib}/link/open.c (100%) rename {src => lib}/link/open/com.c (100%) rename {src => lib}/link/open/usb.c (100%) rename {src => lib}/link/seven/command.c (100%) rename {src => lib}/link/seven/data.c (96%) rename {src => lib}/link/seven/data.h (100%) rename {src => lib}/link/seven/dataflow.c (100%) rename {src => lib}/link/seven/datastream.c (100%) rename {src => lib}/link/seven/devices.c (100%) rename {src => lib}/link/seven/eack.c (100%) rename {src => lib}/link/seven/encoderaw.c (100%) rename {src => lib}/link/seven/init.c (100%) rename {src => lib}/link/seven/receive.c (100%) rename {src => lib}/link/seven/send.c (100%) rename {src => lib}/link/seven_fs/delete.c (100%) rename {src => lib}/link/seven_fs/open.c (96%) create mode 100644 lib/link/seven_fs/optimize.c rename {src => lib}/link/seven_fs/seven_fs.h (92%) rename {src => lib}/link/seven_fs/topath.c (100%) rename {src => lib}/link/seven_mcs/delete.c (100%) rename {src => lib}/link/seven_mcs/get.c (100%) rename {src => lib}/link/seven_mcs/list.c (100%) rename {src => lib}/link/seven_mcs/open.c (100%) rename {src => lib}/link/seven_mcs/put.c.draft (100%) rename {src => lib}/link/seven_mcs/seven_mcs.h (100%) rename {src => lib}/link/usage/backup_rom.c (100%) rename {src => lib}/link/usage/getscreen.c (100%) rename {src => lib}/link/usage/server/seven.c (100%) rename {src => lib}/link/usage/setlink.c (100%) rename {src => lib}/link/usage/upload_and_run.c (99%) rename {src => lib}/link/usage/usage.h (100%) rename {src => lib}/log/conv.c (100%) rename {src => lib}/log/log.h (100%) rename {src => lib}/log/manage.c (100%) rename {src => lib}/log/mem.c (100%) rename {src => lib}/log/msg.c (100%) rename {src => lib}/mcs/delete.c (100%) rename {src => lib}/mcs/get.c (100%) rename {src => lib}/mcs/list.c (100%) rename {src => lib}/mcs/local/delete.c (100%) rename {src => lib}/mcs/local/find.c (100%) rename {src => lib}/mcs/local/get.c (100%) rename {src => lib}/mcs/local/list.c (100%) rename {src => lib}/mcs/local/local.h (100%) rename {src => lib}/mcs/local/open.c (100%) rename {src => lib}/mcs/local/put.c (100%) rename {src => lib}/mcs/mcs.h (100%) rename {src => lib}/mcs/open.c (100%) rename {src => lib}/mcs/put.c (100%) rename {src => lib}/mcs/transfer.c (100%) rename {src => lib}/mcsfile/copy.c (100%) rename {src => lib}/mcsfile/decode/cas.c (100%) rename {src => lib}/mcsfile/decode/cas/cell.c (100%) rename {src => lib}/mcsfile/decode/cas/program.c (100%) rename {src => lib}/mcsfile/decode/cas/sshot.c (100%) rename {src => lib}/mcsfile/decode/decode.h (100%) rename {src => lib}/mcsfile/decode/mcs.c (100%) rename {src => lib}/mcsfile/decode/mcs/cells.c (100%) rename {src => lib}/mcsfile/decode/mcs/picture.c (100%) rename {src => lib}/mcsfile/decode/mcs/program.c (100%) rename {src => lib}/mcsfile/decode/mcs/setup.c (100%) rename {src => lib}/mcsfile/decode/mcs/ssheet.c (100%) rename {src => lib}/mcsfile/decode/mcs/string.c (100%) rename {src => lib}/mcsfile/decode/mcs/var.c (100%) rename {src => lib}/mcsfile/dup.c (100%) rename {src => lib}/mcsfile/free.c (100%) rename {src => lib}/mcsfile/head.c (100%) rename {src => lib}/mcsfile/make.c (100%) rename {src => lib}/mcsfile/match.c (100%) rename {src => lib}/mcsfile/mcsfile.h (100%) rename {src => lib}/mcsfile/prepare.c (100%) rename {src => lib}/mcsfile/ref/cas_app.c (100%) rename {src => lib}/mcsfile/ref/cas_data.c (100%) rename {src => lib}/mcsfile/ref/mcs.c (100%) rename {src => lib}/mcsfile/ref/ref.h (100%) rename {src => lib}/picture/decode.c (100%) rename {src => lib}/picture/encode.c (100%) rename {src => lib}/picture/picture.h (100%) rename {src => lib}/picture/size.c (100%) rename {src => lib}/setup/export.c.draft (100%) rename {src => lib}/setup/feed_mcs.c (100%) rename {src => lib}/setup/feed_seven.c (100%) rename {src => lib}/setup/init.c (100%) rename {src => lib}/setup/setup.h (100%) rename {src => lib}/stream/attrs.c (100%) rename {src => lib}/stream/builtin/csum32.c (96%) rename {src => lib}/stream/builtin/file.c (87%) rename {src => lib}/stream/builtin/libusb/close.c (91%) rename {src => lib}/stream/builtin/libusb/libusb.h (97%) rename {src => lib}/stream/builtin/libusb/open.c (81%) rename {src => lib}/stream/builtin/libusb/read.c (91%) rename {src => lib}/stream/builtin/libusb/settm.c (97%) rename {src => lib}/stream/builtin/libusb/write.c (99%) rename {src => lib}/stream/builtin/limited.c (96%) rename {src => lib}/stream/builtin/memory.c (90%) rename {src => lib}/stream/builtin/streams/close.c (95%) rename {src => lib}/stream/builtin/streams/open.c (89%) rename {src => lib}/stream/builtin/streams/read.c (89%) rename {src => lib}/stream/builtin/streams/scsi.c (100%) rename {src => lib}/stream/builtin/streams/setattrs.c (92%) rename {src => lib}/stream/builtin/streams/settm.c (92%) rename {src => lib}/stream/builtin/streams/streams.h (97%) rename {src => lib}/stream/builtin/streams/write.c (95%) rename {src => lib}/stream/builtin/windows/close.c (100%) rename {src => lib}/stream/builtin/windows/find.c (87%) rename {src => lib}/stream/builtin/windows/open.c (93%) rename {src => lib}/stream/builtin/windows/read.c (90%) rename {src => lib}/stream/builtin/windows/seek.c (86%) rename {src => lib}/stream/builtin/windows/setattrs.c (91%) rename {src => lib}/stream/builtin/windows/settm.c (97%) rename {src => lib}/stream/builtin/windows/windows.h (95%) rename {src => lib}/stream/builtin/windows/write.c (95%) rename {src => lib}/stream/get.c (100%) rename {src => lib}/stream/open.c (100%) rename {src => lib}/stream/open/com.c (100%) rename {src => lib}/stream/open/usb.c (100%) rename {src => lib}/stream/read.c (100%) rename {src => lib}/stream/seek.c (100%) rename {src => lib}/stream/size.c (100%) rename {src => lib}/stream/skip.c (100%) rename {src => lib}/stream/stream.h (100%) rename {src => lib}/stream/timeouts.c (100%) rename {src => lib}/stream/write.c (100%) rename {src => lib}/utils/alloc.c (100%) rename {src => lib}/utils/ascii.c (100%) rename {src => lib}/utils/checksum.c (100%) rename {src => lib}/utils/endian.c (100%) rename {src => lib}/utils/endian.h (100%) rename {src => lib}/utils/ext.c (100%) rename {src => lib}/utils/mutex.c (100%) rename {src => lib}/utils/sleep.c (100%) rename {src => lib}/version.c (100%) rename {src => lib}/version/check.c (100%) rename {src => lib}/version/decode.c (100%) rename {src => lib}/version/encode.c (100%) create mode 100644 src/g1a-wrapper/args.c create mode 100644 src/g1a-wrapper/icon.c create mode 100644 src/g1a-wrapper/main.c create mode 100644 src/g1a-wrapper/main.h create mode 100644 src/g1a-wrapper/vars.mk create mode 100644 src/mcsfile/args.c create mode 100644 src/mcsfile/main.c create mode 100644 src/mcsfile/main.h create mode 100644 src/mcsfile/print.c create mode 100755 src/mcsfile/vars.mk create mode 100644 src/p7/args.c create mode 100644 src/p7/dump.c create mode 100644 src/p7/list_devices.c create mode 100644 src/p7/main.c create mode 100644 src/p7/main.h create mode 100755 src/p7/vars.mk create mode 100644 src/p7os/args.c create mode 100644 src/p7os/main.c create mode 100644 src/p7os/main.h create mode 100644 src/p7os/procs/std_backup.c create mode 100644 src/p7os/procs/std_prepare.c create mode 100644 src/p7os/utils/open_link.c create mode 100644 src/p7os/utils/osdisp.c create mode 100755 src/p7os/vars.mk create mode 100644 src/p7screen/args.c create mode 100644 src/p7screen/main.c create mode 100644 src/p7screen/main.h create mode 100755 src/p7screen/vars.mk create mode 100644 src/p7servtest/args.c create mode 100644 src/p7servtest/client.c create mode 100644 src/p7servtest/main.c create mode 100644 src/p7servtest/main.h create mode 100644 src/p7servtest/server.c create mode 100644 src/p7servtest/vars.mk diff --git a/.gitignore b/.gitignore index 64a08e6..290c37d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,7 @@ /man /docs/_build +build .*.swp +vgcore* diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 0000000..f51c772 --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,4 @@ +libcasio authors +================ + +Copyright (C) 2016-2018 Thomas Touhey diff --git a/CONTRIBUTING.md b/CONTRIBUTING.rst similarity index 53% rename from CONTRIBUTING.md rename to CONTRIBUTING.rst index dd2906c..922f640 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.rst @@ -1,4 +1,6 @@ -# Contributing to libcasio +Contributing to libcasio +======================== + For now, this is a personal project from Thomas "Cakeisalie5" Touhey. No contributions are allowed while it is. An announce will be put on the -[P7 website](https://p7.planet-casio.com/en.html) when they will be. +`P7 website `_ when they will be. diff --git a/GPL2.md b/GPL2.md new file mode 100644 index 0000000..0daa041 --- /dev/null +++ b/GPL2.md @@ -0,0 +1,336 @@ +GNU General Public License +========================== + +_Version 2, June 1991_ +_Copyright © 1989, 1991 Free Software Foundation, Inc.,_ +_51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA_ + +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +### Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: **(1)** copyright the software, and +**(2)** offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +**0.** This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The “Program”, below, +refers to any such program or work, and a “work based on the Program” +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term “modification”.) Each licensee is addressed as “you”. + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +**1.** You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +**2.** You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +* **a)** You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. +* **b)** You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. +* **c)** If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +**3.** You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +* **a)** Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, +* **b)** Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, +* **c)** Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +**4.** You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +**5.** You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +**6.** Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +**7.** If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +**8.** If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +**9.** The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and “any +later version”, you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +**10.** If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + +### NO WARRANTY + +**11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +**12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS + +### How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the “copyright” line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w` and `show c` should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w` and `show c`; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a “copyright disclaimer” for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/LICENSE.md b/LGPL3.md similarity index 100% rename from LICENSE.md rename to LGPL3.md diff --git a/LICENSE.rst b/LICENSE.rst new file mode 100644 index 0000000..0a239ff --- /dev/null +++ b/LICENSE.rst @@ -0,0 +1,10 @@ +libcasio license +================ + +This repository has content from several sources which had several licenses +applied. This means: + +- the utilities (``src/`` folder) are under GPL version 2 (see ``GPL2.md``). +- the library (``lib/`` and ``include/`` folder) are under LGPL version 3 + (see ``LGPL3.md``). +- the rest is under LGPL version 3 (see ``LGPL3.md``). diff --git a/Makefile b/Makefile index 7db2377..aa48d01 100755 --- a/Makefile +++ b/Makefile @@ -1,24 +1,31 @@ #!/usr/bin/make -f -#*****************************************************************************# -# Include variables and message subsystem # -#*****************************************************************************# include Makefile.vars Makefile.msg -#*****************************************************************************# -# General targets # -#*****************************************************************************# +# --- +# General targets. +# --- + # Build everything. -all: all-lib + +all: all-lib all-utils # Mostly clean everything (remove everything but the end results). -mostlyclean: mostlyclean-lib + +mostlyclean: + mclean: mostlyclean # Clean everything. -clean: clean-lib + +clean: + $(call rmsg,Removing the build folder.) + $(call qcmd,$(RM) -r build obj) + $(call qcmd,$(RM) $(SONAMES) $(ANAMES)) + fclean: clean # To original state. + mrproper: clean $(call rmsg,Removing configuration.) $(call qcmd,$(RM) Makefile.cfg) @@ -31,12 +38,6 @@ re: clean all # Install everything. install: install-lib -# Uninstall everything. (experimental) -uninstall: uninstall-lib - -# Reinstall everything. (experimental) -reinstall: uninstall install - # Make a distribution tarball dist: mrproper $(call bcmd,mkdir,lib$(NAME)-$(VERSION),\ @@ -51,16 +52,20 @@ dist: mrproper $(call qcmd,$(RM) -r lib$(NAME)-$(VERSION)) .PHONY: all mostlyclean mclean clean fclean mrproper re -.PHONY: dist install uninstall reinstall -#*****************************************************************************# -# Configuration (version) checking dependencies # -#*****************************************************************************# +.PHONY: dist install + +# --- +# Configuration (version) checking dependencies. +# --- + # Define the dependencies. + CHECKCFG := $(if $(shell test -f Makefile.cfg || echo y),check-config, \ $(if $(shell [ "$(VERSION)" = "$(CONFIG_VERSION)" ] || echo y), \ check-config-version)) # Define the rules. + check-config: @echo -e "\033[1;31mNo configuration file found!" @echo -e "You should configure before re-running this target.\033[0m" @@ -71,75 +76,80 @@ dist: mrproper @false .PHONY: check-config check-config-version -#*****************************************************************************# -# Information getting from the Makefile variables # -#*****************************************************************************# + +# --- +# Targets for gathering information from the Makefile variables. +# --- + # Get the project name. + getname: - @echo lib$(NAME) + @echo $(NAME) # Get the project version. + getversion: @echo $(VERSION) # Check if is indev. + isindev: @$(if $(INDEV),echo $(INDEV),true) # Get the maintainer. + getmaintainer: @echo "$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>" -.PHONY: getname getversion getmaintainer -#*****************************************************************************# -# Library-specific targets # -#*****************************************************************************# -# Make the library. - all-lib: $(CHECKCFG) $(if $(STATIC),$(ANAME),$(SONAME)) +.PHONY: getname getversion isindev getmaintainer -# Make a module object directory. - $(OBJDIR)/ $(DIRS:%=$(OBJDIR)/%): +# --- +# Make directories. +# --- + + ./build/ $(L_OBJDIRS) $(U_OBJDIRS) $(M_SECTIONS:%=$(M_MANDIR)/man%/): $(call bcmd,mkdir,$@,$(MD) $@) +# --- +# Library specific targets. +# --- + +# Make the library. + + all-lib: $(CHECKCFG) $(if $(STATIC),./build/$(L_ANAME),./build/$(L_SONAME)) + +# Make the shared or static library. + +ifeq ($(FOR_WINDOWS),) + ./build/lib$(LIB).so: ./build/$(L_SONAME) + $(call bcmd,ln,$@,$(LN) $(L_SONAME) $@) +endif + + ./build/$(L_SONAME): $(L_SRC:%=$(L_OBJDIR)/%.o) + $(call bcmd,ld,$(L_SONAME),$(LD) -o $@ $^ $(L_LDFLAGS)) + ./build/lib$(L_ANAME).a: $(L_SRC:%=$(L_OBJDIR)/%.o) + $(call bcmd,ar rc,lib$(L_ANAME).a,$(AR) rcs $@ $^) + # Make an object out of a source file. + define make-obj-rule - $(OBJDIR)/$1.c.o: $(SRCDIR)/$1.c $(INC) $(INCI) | $(dir $(OBJDIR)/$1) - $(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS)) + $(L_OBJDIR)/$1.c.o: $(L_SRCDIR)/$1.c $(L_INC) | $(dir $(L_OBJDIR)/$1) + $(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(L_CFLAGS)) endef -$(foreach src,$(basename $(SRC)),\ +$(foreach src,$(basename $(L_SRC)),\ $(eval $(call make-obj-rule,$(src)))) -# Make the shared library. - $(SONAME): $(SRC:%=$(OBJDIR)/%.o) - $(call bcmd,ld,$@,$(LD) -o $@ $^ $(LDFLAGS)) - -# Make the static library. - lib$(NAME).a: $(SRC:%=$(OBJDIR)/%.o) - $(call bcmd,ar rc,$@,$(AR) rcs $@ $^) - -# Remove the objects directory. - mostlyclean-lib: - $(call rmsg,Removing object directory.) - $(call qcmd,$(RM) -r $(OBJDIR)) - mclean-lib: mostlyclean-lib - -# Clean and remove the built library. - clean-lib: mclean-lib - $(call rmsg,Removing the library.) - $(call qcmd,$(RM) $(SONAMES) $(ANAMES)) - -# Remake the library. - re-lib: clean-lib all-lib - # Install the library and development files. + LINK_TO_MAJOR := $(if $(INSTALL_DEVEL),$(if $(STATIC),,\ $(if $(FOR_WINDOWS),,y))) IWINDLL := $(if $(FOR_WINDOWS),$(if $(STATIC),,y)) + install-lib: all-lib $(if $(INSTALL_DEVEL),install-cfgtool) $(call imsg,Installing the library.) $(call qcmd,$(INST) -m 755 -d "$(ILIBDIR)") $(call qcmd,$(INST) -m 755 -t "$(ILIBDIR)" $(if $(STATIC),\ - $(if $(FOR_WINDOWS),lib$(NAME).lib,lib$(NAME).a),\ + $(if $(FOR_WINDOWS),lib$(L_NAME).lib,lib$(L_NAME).a),\ $(if $(FOR_WINDOWS),lib$(NAME).dll.a,$(SONAME)))) $(if $(IWINDLL),$(call qcmd,$(INST) -m 755 -d "$(IBINDIR)")) @@ -160,26 +170,12 @@ $(eval $(call make-obj-rule,$(src)))) $(call qcmd,$(INST) -m 644 $(INCDIR)/$(i) \ "$(IINCDIR)/lib$(NAME)-$(VERSION)/$(i)"$(\n)))) -# Uninstall the library and development files. (experimental) - uninstall-lib: $(CHECKCFG) uninstall-cfgtool - $(call rmsg,Uninstalling the library.) - $(call qcmd,$(RM) "$(IBINDIR)/lib$(NAME).dll") - $(call qcmd,$(RM) "$(ILIBDIR)/lib$(NAME).so"* \ - "$(ILIBDIR)/lib$(NAME).a" "$(ILIBDIR)/lib$(NAME).dll"*) - $(call rmsg,Uninstalling development files.) - $(call qcmd,$(RM) -r "$(IINCDIR)/lib$(NAME)-$(VERSION)") - $(call qcmd,$(RM) "$(IINCDIR)/lib$(NAME).h") - $(call qcmd,$(RM) -r "$(IINCDIR)/lib$(NAME)") +.PHONY: all-lib install-lib -# Reinstall the library and development files. - reinstall-lib: uninstall-lib install-lib +# --- +# Configuration tools related. +# --- -.PHONY: all-lib mostlyclean-lib mclean-lib clean-lib re-lib -.PHONY: install-lib uninstall-lib reinstall-lib -#*****************************************************************************# -# Configuration tools-related # -#*****************************************************************************# -# Install it. install-cfgtool: $(CHECKCFG) $(call imsg,Installing the configuration tool.) $(call qcmd,$(INST) -m 755 -d "$(IBINDIR)") @@ -203,20 +199,82 @@ $(eval $(call make-obj-rule,$(src)))) >"$(IPKGDIR)/lib$(NAME).pc" \ && chmod 644 "$(IPKGDIR)/lib$(NAME).pc") -# Uninstall it - uninstall-cfgtool: $(CHECKCFG) - $(call rmsg,Uninstalling configuration tool and package.) - $(call qcmd,$(RM) "$(IPKGDIR)/lib$(NAME).pc" \ - "$(IBINDIR)/lib$(NAME)-config" "$(IBINDIR)/"*"-lib$(NAME)-config" \ - $(if $(TARGET),"$(HBINDIR)/$(TARGET)lib$(NAME)-config")) +.PHONY: install-cfgtool + +# --- +# Utilities related. +# --- + +# Make the utilities. + + all-utils: $(CHECKCFG) $(DEFAULT_UTILS:%=all-%) + +# Make a utility. + +define make-util-rules + ./build/$1$(if $(FOR_WINDOWS),.exe): $(U_OBJ_$1) \ + $(if $(filter libcasio,$(U_DEPS_$1)),./build/lib$(LIB).so) | ./build/ + $(call bcmd,ld,$$@,$(LD) -o $$@ $(U_OBJ_$1) $(U_LDFLAGS_$1)) + + all-$1: ./build/$1$(if $(FOR_WINDOWS),.exe) +endef +$(foreach util,$(UTILS),\ +$(eval $(call make-util-rules,$(util)))) + +# Make an object out of a file. + +define make-util-obj-rules +ifeq ($(suffix $(U_OBJDIR)/$1/$2),.c) + $(U_OBJDIR)/$1/$2.o: $(U_SRCDIR)/$1/$2 $(U_INC_$1) \ + | $(dir $(U_OBJDIR)/$1/$2) + $(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(U_CFLAGS_$1)) +endif +endef +$(foreach util,$(UTILS),\ +$(foreach src,$(U_SRC_$(util)),\ +$(eval $(call make-util-obj-rules,$(util),$(src))))) + +# Install a utility. + +define make-util-install-rule + install-$1 install-$1.exe: $(CHECKCFG) + $(call imsg,Installing $1$(if $(FOR_WINDOWS),.exe).) + $(call qcmd,$(INSTALL) -m 755 -d "$(IBINDIR)") + $(call qcmd,$(INSTALL) -m 755 -t "$(IBINDIR)" $1$(if $(FOR_WINDOWS),.exe)) +endef + +.PHONY: all-utils $(foreach util,$(UTILS),all-$(util) install-$(util) \ + install-$(util).exe) + +# --- +# Manpages related. +# --- + +# Produce the manpages. + + all-man: $(foreach sec,$(M_SECTIONS),\ + $(M_PAGES_$(sec):%=$(M_MANDIR)/man$(sec)/%.$(sec).gz)) + +# Produce one page. + +define make-manpage-rules + $(M_MANDIR)/man$1/$2.$1.gz: $(M_MANDIR)/man$1/$2.$1 + $(call bcmd,gzip,$$<,$(GZIP) $$<) + + $(M_MANDIR)/man$1/$2.$1: $(M_SRCDIR)/$2.$1.txt | $(M_MANDIR)/man$1/ + $(call bcmd,a2x,$$<,$(A2X) -f manpage -D $$| $$< 2>/dev/null) +endef +$(foreach sec,$(M_SECTIONS),\ +$(foreach pg,$(M_PAGES_$(sec)),\ +$(eval $(call make-manpage-rules,$(sec),$(pg))))) + +# --- +# Documentation-related targets. +# --- -.PHONY: install-cfgtool uninstall-cfgtool -#*****************************************************************************# -# Documentation-related targets # -#*****************************************************************************# -# Make the HTML documentation. html: make -C docs .PHONY: html + # End of file diff --git a/Makefile.vars b/Makefile.vars index 31a003b..4d34fbe 100755 --- a/Makefile.vars +++ b/Makefile.vars @@ -1,71 +1,49 @@ #!/usr/bin/make -f -#*****************************************************************************# -# Include configuration # -#*****************************************************************************# -# Do it -include Makefile.cfg -# Correct target +# Correct the target. TARGET := $(if $(TARGET),$(TARGET)-) -#*****************************************************************************# -# Project main information # -#*****************************************************************************# -# Project name and description - NAME := casio - DESCRIPTION := Library for manipulating CASIO protocols and file formats. -# Maintainer information - MAINTAINER_NAME := Thomas \"Cakeisalie5\" Touhey +# --- +# Main information about the project. +# --- + +# Name and description. + + NAME := libcasio + DESCRIPTION := Library and utils for using CASIO protocols and file formats. + +# Maintainer information. + + MAINTAINER_NAME := Thomas « Cakeisalie5 » Touhey MAINTAINER_MAIL := thomas@touhey.fr -# Project version + MAINTAINER := $(MAINTAINER_NAME) <$(MAINTAINER_MAIL)> + +# Project version. + MAJOR := 0 MINOR := 1 INDEV := yes -# Project version string VERSION := $(MAJOR).$(MINOR)$(if $(INDEV),-indev) -#*****************************************************************************# -# Project directories # -#*****************************************************************************# -# Headers directory - where all the headers are. - INCDIR := ./include -# Sources directory - where all the sources are. - SRCDIR := ./src +# Name of some components. -# Objects directory - where the objects will be put. - OBJDIR := ./obj + LIB := casio -# Documentation directory - where the asciidoc sources for the manpages are. - DOCDIR := ./doc +# --- +# Utilities. +# --- -# Manpages directory - where the manpages will be put. - MANDIR := ./man -#*****************************************************************************# -# Object names # -#*****************************************************************************# -# Dynamic library name - SONAME := $(if $(FOR_WINDOWS),lib$(NAME).dll,lib$(NAME).so.$(MAJOR)) - SONAMES := $(if $(FOR_WINDOWS),lib$(NAME).dll,lib$(NAME).so.*) +# Package configuration. -# Static library name - ANAME := $(if $(FOR_WINDOWS),lib$(NAME).lib,lib$(NAME).a) - ANAMES := lib$(NAME).lib lib$(NAME).a lib$(NAME).dll.a - -# Libs - DEPS := libfontcharacter - DEPS_PRIV := zlib $(if $(NO_LIBUSB),,libusb-1.0) - ALLDEPS := $(DEPS) $(DEPS_PRIV) -#*****************************************************************************# -# Binary utilities # -#*****************************************************************************# -# Package configuration PKGCONFIG := $(TARGET)pkg-config -# Compiler +# Compiler. + CC := $(TARGET)gcc -# - Check flags (warnings) + CWERROR := all extra no-attributes no-unused-macros no-vla no-multichar ifneq ($(MORE_WARNINGS),) CWERROR += shadow write-strings redundant-decls format format-nonliteral \ @@ -74,18 +52,18 @@ ifneq ($(MORE_WARNINGS),) stack-protector no-unused-parameter endif CWARN := $(CWERROR:%=-W%) -# - For random manipulations (profiling, ...) #CMOREFLAGS := -# - All C compiling flags + CFLAGS := -I $(INCDIR) $(CWARN) -std=c99 -pedantic \ $(if $(STATIC),-DLIBCASIO_STATIC,-fPIC) $(if $(OPTIMIZE_SIZE),-Os,-O2) \ -D LOGLEVEL="casio_loglevel_$(LOG_LEVEL)" \ $(shell $(PKGCONFIG) --cflags $(ALLDEPS) 2>/dev/null) \ $(CMOREFLAGS) -# Linker +# Linker. + LD := $(TARGET)gcc -# - Specific linker flags + LDFLAGS := $(if $(STATIC),,-shared) \ $(shell $(PKGCONFIG) --libs $(ALLDEPS) 2>/dev/null) -lm ifneq ($(FOR_WINDOWS),) @@ -96,62 +74,203 @@ else -e lib$(NAME)__version \ -Wl,-z,relro -Wl,-z,combreloc -Wl,-z,defs) endif +#LDMOREFLAGS := + LDFLAGS += $(LDMOREFLAGS) -# Archive manager +# Archive manager, directory maker, file copier, file mover, +# symbolic link maker, file/folder remover, documentation creator, +# installer, gzipper. + AR := $(TARGET)ar - -# Directory maker MD := mkdir -p -# Copier CP := cp -# Mover MV := mv -# Symbolic link maker LN := ln -sf -# File remover RM := rm -f -# Documentation creator A2X := a2x -# Installer INST := install -# GZipper - GZIP := gzip -f -#*****************************************************************************# -# Look up the sources and includes # -#*****************************************************************************# -# Look up the sources. - SRC := $(patsubst $(SRCDIR)/%,%,$(shell find $(SRCDIR) -name "*.c")) - DIRS := $(sort $(dir $(SRC))) + GZIP := gzip -k -f -# Look up the includes. - INC := $(shell find $(INCDIR) -name "*.h") - INCp := $(INC:$(INCDIR)/%=%) +# --- +# Dependencies definitions. +# --- -# Look up the source includes. - INCI := $(shell find $(SRCDIR) -name "*.h") -#*****************************************************************************# -# Look for manpages # -#*****************************************************************************# -# Get the manpages sections and contents - MAN_SECTIONS := -define check-man - MAN_SECTIONS += $1 - MAN_$1 += $2 +# libcasio, defined here. + + DEP_libcasio_CFLAGS := -I include + DEP_libcasio_LIBS := -L build -lcasio + +# zlib, compression library. + + DEP_zlib_CFLAGS := $(shell $(PKGCONFIG) zlib --cflags) + DEP_zlib_LIBS := $(shell $(PKGCONFIG) zlib --libs) + +# libusb, communication library. + + DEP_libusb_CFLAGS := $(shell $(PKGCONFIG) libusb-1.0 --cflags) + DEP_libusb_LIBS := $(shell $(PKGCONFIG) libusb-1.0 --libs) + +# imagemagick, for image manipulation. + + DEP_magick_CFLAGS := $(shell $(PKGCONFIG) MagickCore --cflags) + DEP_magick_LIBS := $(shell $(PKGCONFIG) MagickCore --libs) + +# SDL, for simple graphical utilities. + + DEP_sdl_CFLAGS := $(shell $(PKGCONFIG) sdl --cflags) + DEP_sdl_LIBS := $(shell $(PKGCONFIG) sdl --libs) + +# --- +# Informations about the library. +# --- + +# Dependencies. + + L_DEPS := + L_DEPS_PRIV := zlib $(if $(NO_LIBUSB),,libusb) + +# Folders. + + L_INCDIR := ./include + L_SRCDIR := ./lib + L_OBJDIR := ./build/lib + +# Destination (dynamic and static library name). + + L_SONAME := $(if $(FOR_WINDOWS),lib$(LIB).dll,lib$(LIB).so.$(MAJOR)) + L_SONAMES := ./build/$(if $(FOR_WINDOWS),lib$(LIB).dll,lib$(LIB).so.*) + + L_ANAME := lib$(LIB)$(if $(FOR_WINDOWS),.lib,.a) + L_ANAMES := ./build/lib$(LIB).lib ./build/lib$(LIB).a \ + ./build/lib$(LIB).dll.a + +# Files. + + L_SRC := $(patsubst $(L_SRCDIR)/%,%,$(wildcard $(L_SRCDIR)/*.c \ + $(L_SRCDIR)/**/*.c $(L_SRCDIR)/**/**/*.c $(L_SRCDIR)/**/**/**/*.c)) + L_OBJ := $(L_SRC:%=$(L_OBJDIR)/%.o) + L_OBJDIRS := $(sort $(dir $(L_OBJ))) + + L_INCp := $(patsubst $(L_INCDIR)/%,%,$(wildcard $(L_INCDIR)/*.h \ + $(L_INCDIR)/**/*.h)) + L_INC := $(L_INCp:%=$(L_INCDIR)/%) \ + $(wildcard $(L_SRCDIR)/*.h $(L_SRCDIR)/**/*.h) + +# Flags. + + L_CFLAGS := $(CFLAGS) $(foreach dep,$(L_DEPS) $(L_DEPS_PRIV),\ + $(DEP_$(dep)_CFLAGS)) -I $(L_INCDIR) + L_LIBS := $(foreach dep,$(L_DEPS) $(L_DEPS_PRIV),$(DEP_$(dep)_LIBS)) + + L_LDFLAGS := $(if $(STATIC),,-shared) $(L_LIBS) +ifneq ($(FOR_WINDOWS),) + L_LDFLAGS += -Wl,--out-implib,lib$(NAME).dll.a -lws2_32 -lsetupapi -luuid +else + L_LDFLAGS += $(if $(STATIC),,"-Wl,-soname,$(L_SONAME)" \ + -e lib$(LIB)__version "-Wl,-z,relro" "-Wl,-z,combreloc" \ + -Wl,-z,defs) +endif + +# --- +# Informations about the utilities. +# --- + +# Folders. + + U_SRCDIR := ./src + U_OBJDIR := ./build/utils + +# Look for utilities. + + UTILS := $(patsubst $(U_SRCDIR)/%,%,$(wildcard $(U_SRCDIR)/*)) + +# Get the dependencies. +# `U_DEPS_`: dependencies for util . +# `U_DIS_`: if the util is disabled or not. + +define get-util-info + U_DEPS_$1 := $(shell make -f $(U_SRCDIR)/$1/vars.mk libs 2>/dev/null) + U_DIS_$1 := $(shell make -f $(U_SRCDIR)/$1/vars.mk disable 2>/dev/null \ + && echo y) endef -$(foreach doc,$(wildcard $(DOCDIR)/*.*.txt),\ -$(eval $(call check-man,$(patsubst .%,%,$(suffix $(doc))),$(basename $(doc))))) +$(foreach util,$(UTILS),\ +$(eval $(call get-util-info,$(util)))) + +# Get the default utilities. + + DEFAULT_UTILS := $(foreach util,$(UTILS),\ + $(if $(U_DIS_$(util)),,$(util))) + +# Look for the utilities source files and flags. +# It is important to not merge this function with the `get-util-info` as +# you cannot use a variable defined earlier in such a function, you have +# to do a second one. + +define get-util-source + U_SRC_$1 := $(patsubst $(U_SRCDIR)/$1/%,%,$(wildcard $(U_SRCDIR)/$1/*.c \ + $(U_SRCDIR)/$1/**/*.c)) + U_INC_$1 := $(patsubst $(U_INCDIR)/$1/%,%,$(wildcard $(U_SRCDIR)/$1/*.h \ + $(U_SRCDIR)/$1/**/*.h)) + + U_CFLAGS_$1 := $(CFLAGS) $(foreach dep,$(U_DEPS_$1),$(DEP_$(dep)_CFLAGS)) \ + -D BIN="$1$(if $(FOR_WINDOWS),.exe)" \ + -D MAINTAINER="$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>" \ + -D DEFAULT_STORAGE="$(DEFAULT_STORAGE)" \ + -D DEFAULT_ZOOM="$(DEFAULT_ZOOM)" + U_LIBS_$1 := $(foreach dep,$(U_DEPS_$1),$(DEP_$(dep)_LIBS)) + + U_LDFLAGS_$1 := $(foreach dep,$(U_DEPS_$1),$(DEP_$(dep)_LIBS)) +endef +define get-util-objects + U_OBJ_$1 := $(U_SRC_$1:%=$(U_OBJDIR)/$1/%.o) +endef + +$(foreach util,$(UTILS),\ +$(eval $(call get-util-source,$(util)))) +$(foreach util,$(UTILS),\ +$(eval $(call get-util-objects,$(util)))) + +# Get the object directories. + + U_OBJDIRS := $(sort $(dir $(foreach util,$(UTILS),\ + $(U_SRC_$(util):%=$(U_OBJDIR)/$(util)/%)))) + +# --- +# Manpages. +# --- + +# Manpages folder. + + M_SRCDIR := ./man + M_MANDIR := ./build/man + +# Get the manpages sections and contents. + + M_SECTIONS := +define check-man + M_SECTIONS += $1 + M_PAGES_$1 += $2 +endef +$(foreach doc,$(wildcard $(M_SRCDIR)/*.*.txt),\ +$(eval $(call check-man,$(patsubst .%,%,$(suffix $(basename $(doc)))),\ +$(notdir $(basename $(basename $(doc))))))) # Remove duplicate sections. - MAN_SECTIONS := $(sort $(MAN_SECTIONS)) -#*****************************************************************************# -# Check for DESTDIR (add as prefix to installation root) # -#*****************************************************************************# + + M_SECTIONS := $(sort $(M_SECTIONS)) + +# --- +# Check for DESTDIR (add as prefix to installation root). +# --- + # Save original library and include dir. + OIINCDIR := $(IINCDIR) OILIBDIR := $(ILIBDIR) # Make it. + define add-dest-dir $1 = $(DESTDIR)$($1) endef diff --git a/README.md b/README.md deleted file mode 100644 index 2d74f16..0000000 --- a/README.md +++ /dev/null @@ -1,76 +0,0 @@ -# libcasio - Utilities for manipulating CASIO's protocols and file formats -## Introduction -This is the central library in the P7 project, a project to free software -surrounding CASIO calculators. It aims at being able to manage CASIO's -proprietary protocols and file formats. It is basically a merge of two -libraries of the P7 project: the libp7, which managed protocols, and the -libg1m, which managed file formats. - -## Prerequisites -Side note : the library might work with older versions of these dependencies, -I took these as a reference because these are the ones I work with. - -Because of libusb, the library compiles in C99. Without it, it compiles -using C89. - -### Build-only dependencies -| Name | Version | -| ------------------------------------------------------------------- | -------- | -| [make](https://www.gnu.org/software/make/) | >= 4.0 | -| [gcc](https://gcc.gnu.org/) | >= 4.9 | -| [binutils](https://www.gnu.org/software/binutils/) | >= 2.25 | -| [asciidoc](http://asciidoc.org/) | >= 8.6.9 | -| [gzip](https://www.gnu.org/software/gzip/) | >= 1.6 | -| [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) | any | - -### Build and runtime dependencies -| Name | Version | -| -------------------------------------------------------------------- | -------- | -| [libfontcharacter](https://github.com/PlaneteCasio/libfontcharacter) | >= 1.0 | -| [libusb](http://libusb.info/) | >= 1.0 | -| [zlib](http://zlib.net/) | >= 1.2.8 | - -## Configuring -First of all, the configure script has a help message where all of the -options are listed. The defaults should be appropriate for a native build, -just `./configure` if that's what you want to do, but you should read at -least the next paragraph. - -If you're installing on or packaging for a GNU/Linux distribution, you might -want to install the `udev` rule to let the access to the direct calculator -connexions to normal users. As calculators can be connected as serial devices, -which are attributed to the `uucp` group (on Manjaro GNU/Linux), I chose to -attribute the `uucp` group to calculators plugged directly as USB. If you -agree with that, just add the `--udev` option to the configuration command -line; otherwise, make your own, or make nothing, I don't really care. - -Building for the MS-Windows platform is supported, just use a `-mingw32` -target. - -Also, building a static library, for both PC and embedded systems, is -supported : just use the `--static` option. If you want to build a static -library so that a cross-compiler that uses Microsoft Windows static library -formats, add the `--windows` option (notice that for a `-mingw32` target and -a dynamic library generation, this option is automatically added). - -## Building and installing -Once configuring is done (necessary step), just `make`. -To install, use `make install`. - -To build and install only the lib, use `all-lib` then `install-lib`. -To build and install only the docs, use `all-doc` and `install-doc`. - -If you ought to package this library, use the `DESTDIR` Makefile variable, -e.g. `make install DESTDIR=./package-root`. Do **not** use the `--root` -configure options for this, as configure tools (`libp7-config` and the -`pkg-config` configuration file) will add what's in the `--root` option value -but not in the `DESTDIR` option. - -Other useful targets: - -- `uninstall`, `uninstall-lib`, `uninstall-bin`, `uninstall-doc`: - will try to uninstall using the current configuration (experimental); -- `mostlyclean`, `clean`, `clean-doc`, `mostlyclean-lib`, `clean-lib`: - remove built files at different levels; -- `re`, `re-lib`, `re-doc`: regenerate built files at different levels - (clean and build) -- useful when configuration is changed. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..5dd979b --- /dev/null +++ b/README.rst @@ -0,0 +1,80 @@ +libcasio - Library and utilitiess for using CASIO's protocols and file formats +============================================================================== + +This is the main repository for the P7 project, a project to free software +surrounding CASIO calculators. It aims at being able to manage CASIO's +proprietary protocols and file formats. It is basically a merge of three +subprojects of the P7 project: the libp7, which managed protocols, the +libg1m, which managed file formats, and the p7utils, which had the utilities +now put in this repository. + +Prerequisites +------------- + +Side note : the library might work with older versions of these dependencies, +I took these as a reference because these are the ones I work with. + +Because of libusb, the library requires C99. Without it, it should compile +using C89. + +Build-only dependencies +----------------------- + +- `make `_ (>= 4.0). +- `gcc `_ (>= 4.9). +- `binutils `_ (>= 2.25). +- `asciidoc `_ (>= 8.6.9). +- `gzip `_ (1.6). +- `pkg-config `_. + +Runtime dependencies +-------------------- + +- `libusb `_ (>= 1.0). +- `zlib `_ (>= 1.2.8). + +Configuring +----------- + +First of all, the configure script has a help message where all of the +options are listed. The defaults should be appropriate for a native build, +just ``./configure`` if that's what you want to do, but you should read at +least the next paragraph. + +If you're installing on or packaging for a GNU/Linux distribution, you might +want to install the ``udev`` rule to let the access to the direct calculator +connexions to normal users. As calculators can be connected as serial devices, +which are attributed to the ``uucp`` group (on Manjaro GNU/Linux), I chose to +attribute the ``uucp`` group to calculators plugged directly as USB. If you +agree with that, just add the ``--udev`` option to the configuration command +line; otherwise, make your own, or make nothing, I don't really care. + +Building for the MS-Windows platform is supported, just use a ``-mingw32`` +BFD target. + +Also, building a static library, for both PC and embedded systems, is +supported : just use the ``--static`` option. If you want to build a static +library so that a cross-compiler that uses Microsoft Windows static library +formats, add the ``--windows`` option (notice that for a ``-mingw32`` target +and a dynamic library generation, this option is automatically added). + +Building and installing +----------------------- + +Once configuring is done (necessary step), just ``make``. +To install, use ``make install``. + +To build and install only the lib, use ``all-lib`` then ``install-lib``. +To build and install only the docs, use ``all-doc`` and ``install-doc``. + +If you ought to package this library, use the ``DESTDIR`` Makefile variable, +e.g. ``make install DESTDIR=./package-root``. Do **not** use the ``--root`` +configure options for this, as configure tools (``libcasio-config`` and the +``pkg-config`` configuration file) will add what's in the `--root` option +value but not in the ``DESTDIR`` option. + +Other useful targets: + +- ``clean``: remove built files; +- ``re``: regenerate built files (clean and build) -- useful when + configuration is changed. diff --git a/configure b/configure index 4ad65f2..34d7a81 100755 --- a/configure +++ b/configure @@ -1,9 +1,12 @@ #!/bin/sh cd "$(dirname $0)" -#*****************************************************************************# -# Defaults # -#*****************************************************************************# -# Project variables + +# --- +# Defaults. +# --- + +# Project variables. + [ -f Makefile.cfg ] && mv Makefile.cfg Makefile.cfg.tmp name="$(make -s getname)" version="$(make -s getversion)" @@ -11,15 +14,18 @@ indev="$(make -s isindev)" maintainer="$(make -s getmaintainer)" [ -f Makefile.cfg.tmp ] && mv Makefile.cfg.tmp Makefile.cfg -# Platform +# Platform. + platform="$(command -v gcc 1>/dev/null && gcc --print-multiarch)" platform="$([ "$platform" ] && echo "/$platform")" -# Make options +# Make options. + make_full_log= more_warnings= -# Build options +# Build options. + target= no_file= no_libusb= @@ -29,7 +35,11 @@ optimize_size= no_log= loglevel=none # none, info, warn, error, fatal -# Installation directories +default_zoom=8 +default_storage=fls0 + +# Installation directories. + root='' [ x"$indev" != x ] && prefix='${root}/opt/p7-project' \ || prefix='${root}/usr' @@ -42,15 +52,19 @@ libdir='${prefix}/lib'"$platform" includedir='${prefix}/include'"$platform" pkgdir='${libdir}/pkgconfig' -# Installation options +# Installation options. + install_devel=yes -# Tweaks +# Tweaks. + cflags= ldflags= -#*****************************************************************************# -# Help message # -#*****************************************************************************# + +# --- +# Help message. +# --- + usage() { cat </dev/null ]; then + echo "--default-zoom: a number is expected (got \"$zoom\")" >&2 + elif [ $zoom -lt 1 ]; then + echo "--default-zoom: should be 1 or more (got $zoom)" >&2 + elif [ $zoom -gt 16 ]; then + echo "--default-zoom: should be 16 or less (got $zoom)" >&2 + else default_zoom=$zoom; fi ;; +--default-storage=*) + storage="${arg#*=}" + # check if 4 chars long + if [ ! $(echo "$storage" | wc -c ) -eq 5 ]; then + echo "$0: --default-storage: must be 4 characters long" + continue + fi + # then set + default_storage="$storage" ;; --no-devel) install_devel= ;; --root=*) root="${arg#*=}" ;; --hprefix=*) hprefix="${arg#*=}" ;; @@ -161,27 +203,33 @@ CFLAGS=*) cflags="${arg#*=}" ;; LDFLAGS=*) ldflags="${arg#*=}" ;; *) echo "$arg: didn't read" ;; esac; done -#*****************************************************************************# -# Little things # -#*****************************************************************************# -# Cross-compilation things + +# --- +# Checks and tweaks. +# --- + +# Cross-compilation things. + if [ ! $prefix_set ] && [ $target ]; then prefix="$prefix"/"$target" fi -# Check MS-Windows targets +# Check MS-Windows targets. + win_target= case "$target" in *-mingw32) if [ ! "$static" ]; then windows=y; win_target=y fi;; esac -# Evaluate variables +# Evaluate variables. + vars="prefix bindir libdir pkgdir includedir hprefix hbindir" for var in $vars; do eval $var'='$(eval 'echo $'$var) done # Check that static and MS-Windows are not asked. + if [ "$static" ] && [ "$windows" ]; then cat >&2 <&2 <&2 </dev/null 2>/dev/null -# Create the configuration header +# Create the configuration header. + tools/write-header-config --version=${version} \ --maintainer="$(echo ${maintainer} | sed 's/"/\\"/g')" \ $([ "$no_file" ] && echo --no-file) \ $([ "$no_libusb" ] && echo --no-libusb) \ $([ "$no_log" ] && echo --no-log) \ - >include/${name}/config.h + >include/libcasio/config.h # Do it! + exec 3>&1 1>Makefile.cfg cat <&3 3>&- chmod +x Makefile.cfg # Print the end message. + echo "Configuration loaded, you can make now." # End of file. diff --git a/include/libcasio/fs.h b/include/libcasio/fs.h index 8b00331..0f8b0eb 100644 --- a/include/libcasio/fs.h +++ b/include/libcasio/fs.h @@ -227,6 +227,20 @@ typedef int casio_fs_list_t OF((void *casio__cookie, casio_path_t *casio__path, casio_fs_list_func_t *casio__callback, void *casio__cbcookie)); +/* The `casio_fs_optim` callback is used to optimize the filesystem + * (run a defragmentation, …). + * + * FIXME: we need a `casio_path_t` equivalent to express devices. + * On CASIOWIN, the device is expressed as a path node/string (e.g. + * "fls0" in \fls0\file.txt), on WINDOWS, it can be expressed as a + * letter (e.g. C:), a path from the Local Device \\.\ or + * Root Local Device \\?\, or a mount point, and on Linux/Mac, as a + * mount point. This is a mess we need to clean up sometime, for now + * we're only considering this operation for CASIOWIN. */ + +typedef int casio_fs_optim_t + OF((void *casio__cookie, const char *device)); + /* And here is the structure with all of the functions. * It is the one used when you want to open a libcasio filesystem interface * abstraction. */ @@ -243,17 +257,21 @@ struct casio_fsfuncs_s { casio_fs_list_t *casio_fsfuncs_list; casio_fs_open_t *casio_fsfuncs_open; + + casio_fs_optim_t *casio_fsfuncs_optim; }; /* ************************************************************************* */ /* Filesystem public functions */ /* ************************************************************************* */ CASIO_BEGIN_DECLS -/* Open a custom filesystem. */ +/* Open a custom filesystem, and close any filesystem. */ CASIO_EXTERN int CASIO_EXPORT casio_open_fs OF((casio_fs_t **casio__filesystem, void *casio__cookie, const casio_fsfuncs_t *casio__funcs)); +CASIO_EXTERN int CASIO_EXPORT casio_close_fs + OF((casio_fs_t *casio__filesystem)); /* Manipulate native paths. */ @@ -289,6 +307,11 @@ CASIO_EXTERN int CASIO_EXPORT casio_open_nat void *casio__path, casio_off_t casio__size, casio_openmode_t casio__mode)); +/* Optimize the filesystem. */ + +CASIO_EXTERN int CASIO_EXPORT casio_optimize + OF((casio_fs_t *casio__fs, const char *casio__device)); + CASIO_END_DECLS CASIO_END_NAMESPACE #endif /* LIBCASIO_FS_H */ diff --git a/include/libcasio/mcsfile.h b/include/libcasio/mcsfile.h index 5554e2a..b992878 100644 --- a/include/libcasio/mcsfile.h +++ b/include/libcasio/mcsfile.h @@ -45,7 +45,7 @@ CASIO_BEGIN_NAMESPACE typedef unsigned long casio_mcsfile_type_t; typedef unsigned long casio_mcstype_t; -# define casio_mcstype_unknown 0x00000000, +# define casio_mcstype_unknown 0x00000000 /* A program. */ diff --git a/src/bcd/cas.c b/lib/bcd/cas.c similarity index 100% rename from src/bcd/cas.c rename to lib/bcd/cas.c diff --git a/src/bcd/double.c b/lib/bcd/double.c similarity index 100% rename from src/bcd/double.c rename to lib/bcd/double.c diff --git a/src/bcd/mcs.c b/lib/bcd/mcs.c similarity index 100% rename from src/bcd/mcs.c rename to lib/bcd/mcs.c diff --git a/src/bcd/str.c b/lib/bcd/str.c similarity index 100% rename from src/bcd/str.c rename to lib/bcd/str.c diff --git a/src/char/utf32_to_fontchar16.c.draft b/lib/char/utf32_to_fontchar16.c.draft similarity index 100% rename from src/char/utf32_to_fontchar16.c.draft rename to lib/char/utf32_to_fontchar16.c.draft diff --git a/src/comlist/builtin/linux.c b/lib/comlist/builtin/linux.c similarity index 100% rename from src/comlist/builtin/linux.c rename to lib/comlist/builtin/linux.c diff --git a/src/comlist/builtin/macos.c b/lib/comlist/builtin/macos.c similarity index 100% rename from src/comlist/builtin/macos.c rename to lib/comlist/builtin/macos.c diff --git a/src/comlist/builtin/windows.c b/lib/comlist/builtin/windows.c similarity index 100% rename from src/comlist/builtin/windows.c rename to lib/comlist/builtin/windows.c diff --git a/src/comlist/comlist.c b/lib/comlist/comlist.c similarity index 100% rename from src/comlist/comlist.c rename to lib/comlist/comlist.c diff --git a/src/date/decode.c b/lib/date/decode.c similarity index 100% rename from src/date/decode.c rename to lib/date/decode.c diff --git a/src/date/encode.c b/lib/date/encode.c similarity index 100% rename from src/date/encode.c rename to lib/date/encode.c diff --git a/src/errors.c b/lib/errors.c similarity index 100% rename from src/errors.c rename to lib/errors.c diff --git a/src/file/corresp/standard.c b/lib/file/corresp/standard.c similarity index 100% rename from src/file/corresp/standard.c rename to lib/file/corresp/standard.c diff --git a/src/file/corresp/standard.h b/lib/file/corresp/standard.h similarity index 100% rename from src/file/corresp/standard.h rename to lib/file/corresp/standard.h diff --git a/src/file/corresp/standard_sub.c b/lib/file/corresp/standard_sub.c similarity index 100% rename from src/file/corresp/standard_sub.c rename to lib/file/corresp/standard_sub.c diff --git a/src/file/decode.c b/lib/file/decode.c similarity index 100% rename from src/file/decode.c rename to lib/file/decode.c diff --git a/src/file/decode/cafix.c.draft b/lib/file/decode/cafix.c.draft similarity index 100% rename from src/file/decode/cafix.c.draft rename to lib/file/decode/cafix.c.draft diff --git a/src/file/decode/cas.c b/lib/file/decode/cas.c similarity index 100% rename from src/file/decode/cas.c rename to lib/file/decode/cas.c diff --git a/src/file/decode/casemul.c b/lib/file/decode/casemul.c similarity index 100% rename from src/file/decode/casemul.c rename to lib/file/decode/casemul.c diff --git a/src/file/decode/decode.h b/lib/file/decode/decode.h similarity index 100% rename from src/file/decode/decode.h rename to lib/file/decode/decode.h diff --git a/src/file/decode/fxi.c.draft b/lib/file/decode/fxi.c.draft similarity index 100% rename from src/file/decode/fxi.c.draft rename to lib/file/decode/fxi.c.draft diff --git a/src/file/decode/newcat.c.draft b/lib/file/decode/newcat.c.draft similarity index 100% rename from src/file/decode/newcat.c.draft rename to lib/file/decode/newcat.c.draft diff --git a/src/file/decode/std.c b/lib/file/decode/std.c similarity index 100% rename from src/file/decode/std.c rename to lib/file/decode/std.c diff --git a/src/file/decode/std/addin.c b/lib/file/decode/std/addin.c similarity index 100% rename from src/file/decode/std/addin.c rename to lib/file/decode/std/addin.c diff --git a/src/file/decode/std/dict.c b/lib/file/decode/std/dict.c similarity index 100% rename from src/file/decode/std/dict.c rename to lib/file/decode/std/dict.c diff --git a/src/file/decode/std/dict.h b/lib/file/decode/std/dict.h similarity index 100% rename from src/file/decode/std/dict.h rename to lib/file/decode/std/dict.h diff --git a/src/file/decode/std/eact.c.draft b/lib/file/decode/std/eact.c.draft similarity index 100% rename from src/file/decode/std/eact.c.draft rename to lib/file/decode/std/eact.c.draft diff --git a/src/file/decode/std/fkey.c b/lib/file/decode/std/fkey.c similarity index 100% rename from src/file/decode/std/fkey.c rename to lib/file/decode/std/fkey.c diff --git a/src/file/decode/std/lang.c b/lib/file/decode/std/lang.c similarity index 100% rename from src/file/decode/std/lang.c rename to lib/file/decode/std/lang.c diff --git a/src/file/decode/std/mcs.c b/lib/file/decode/std/mcs.c similarity index 100% rename from src/file/decode/std/mcs.c rename to lib/file/decode/std/mcs.c diff --git a/src/file/decode/std/picture.c b/lib/file/decode/std/picture.c similarity index 100% rename from src/file/decode/std/picture.c rename to lib/file/decode/std/picture.c diff --git a/src/file/file.h b/lib/file/file.h similarity index 100% rename from src/file/file.h rename to lib/file/file.h diff --git a/src/file/manage.c b/lib/file/manage.c similarity index 100% rename from src/file/manage.c rename to lib/file/manage.c diff --git a/src/file/open.c b/lib/file/open.c similarity index 100% rename from src/file/open.c rename to lib/file/open.c diff --git a/src/fontchar/fontchar.h b/lib/fontchar/fontchar.h similarity index 100% rename from src/fontchar/fontchar.h rename to lib/fontchar/fontchar.h diff --git a/src/fontchar/lead.c.draft b/lib/fontchar/lead.c.draft similarity index 100% rename from src/fontchar/lead.c.draft rename to lib/fontchar/lead.c.draft diff --git a/src/fontchar/open.c.draft b/lib/fontchar/open.c.draft similarity index 100% rename from src/fontchar/open.c.draft rename to lib/fontchar/open.c.draft diff --git a/src/fontchar/reference.h b/lib/fontchar/reference.h similarity index 100% rename from src/fontchar/reference.h rename to lib/fontchar/reference.h diff --git a/src/fs/builtin/posix/del.c b/lib/fs/builtin/posix/del.c similarity index 100% rename from src/fs/builtin/posix/del.c rename to lib/fs/builtin/posix/del.c diff --git a/src/fs/builtin/posix/frompath.c b/lib/fs/builtin/posix/frompath.c similarity index 100% rename from src/fs/builtin/posix/frompath.c rename to lib/fs/builtin/posix/frompath.c diff --git a/src/fs/builtin/posix/make.c b/lib/fs/builtin/posix/make.c similarity index 100% rename from src/fs/builtin/posix/make.c rename to lib/fs/builtin/posix/make.c diff --git a/src/fs/builtin/posix/open_fs.c b/lib/fs/builtin/posix/open_fs.c similarity index 98% rename from src/fs/builtin/posix/open_fs.c rename to lib/fs/builtin/posix/open_fs.c index c575dff..e8b0877 100644 --- a/src/fs/builtin/posix/open_fs.c +++ b/lib/fs/builtin/posix/open_fs.c @@ -24,7 +24,7 @@ CASIO_LOCAL casio_fsfuncs_t posix_fs_funcs = { NULL, &casio_make_posix_path, &casio_free_posix_path, &casio_posix_stat, NULL, NULL, NULL, - NULL, NULL + NULL, NULL, NULL }; /** diff --git a/src/fs/builtin/posix/posix.h b/lib/fs/builtin/posix/posix.h similarity index 100% rename from src/fs/builtin/posix/posix.h rename to lib/fs/builtin/posix/posix.h diff --git a/src/fs/builtin/posix/stat.c b/lib/fs/builtin/posix/stat.c similarity index 100% rename from src/fs/builtin/posix/stat.c rename to lib/fs/builtin/posix/stat.c diff --git a/src/fs/builtin/posix/topath.c b/lib/fs/builtin/posix/topath.c similarity index 100% rename from src/fs/builtin/posix/topath.c rename to lib/fs/builtin/posix/topath.c diff --git a/src/fs/builtin/windows/make.c b/lib/fs/builtin/windows/make.c similarity index 100% rename from src/fs/builtin/windows/make.c rename to lib/fs/builtin/windows/make.c diff --git a/src/fs/builtin/windows/topath.c b/lib/fs/builtin/windows/topath.c similarity index 100% rename from src/fs/builtin/windows/topath.c rename to lib/fs/builtin/windows/topath.c diff --git a/src/fs/builtin/windows/windows.h b/lib/fs/builtin/windows/windows.h similarity index 100% rename from src/fs/builtin/windows/windows.h rename to lib/fs/builtin/windows/windows.h diff --git a/src/fs/delete.c b/lib/fs/delete.c similarity index 100% rename from src/fs/delete.c rename to lib/fs/delete.c diff --git a/src/fs/fs.h b/lib/fs/fs.h similarity index 100% rename from src/fs/fs.h rename to lib/fs/fs.h diff --git a/src/fs/makedir.c b/lib/fs/makedir.c similarity index 100% rename from src/fs/makedir.c rename to lib/fs/makedir.c diff --git a/src/fs/open.c b/lib/fs/open.c similarity index 78% rename from src/fs/open.c rename to lib/fs/open.c index 3ec0936..499e89e 100644 --- a/src/fs/open.c +++ b/lib/fs/open.c @@ -34,10 +34,15 @@ int CASIO_EXPORT casio_open_fs(casio_fs_t **pfs, int err; casio_fs_t *fs; /* Allocate the filesystem. */ + *pfs = malloc(sizeof(casio_fs_t)); fs = *pfs; - if (!fs) { err = casio_error_alloc; goto fail; } + if (!fs) { + err = casio_error_alloc; + goto fail; + } /* Copy the data into it. */ + fs->casio_fs_cookie = cookie; memcpy(&fs->casio_fs_funcs, funcs, sizeof(casio_fsfuncs_t)); return (0); @@ -47,3 +52,28 @@ fail: (*funcs->casio_fsfuncs_close)(cookie); return (err); } + +/** + * casio_close_fs: + * Close a filesystem. + */ + +int CASIO_EXPORT casio_close_fs(casio_fs_t *fs) +{ + casio_fs_close_t *cl; + int err = 0; + + if (!fs) + return (0); + + /* Call the custom free function for the filesystem content. */ + + cl = fs->casio_fs_funcs.casio_fsfuncs_close; + if (cl) + err = (*cl)(fs->casio_fs_cookie); + + /* Free the element and go! */ + + free(fs); + return (err); +} diff --git a/src/fs/open_file.c b/lib/fs/open_file.c similarity index 100% rename from src/fs/open_file.c rename to lib/fs/open_file.c diff --git a/lib/fs/optimize.c b/lib/fs/optimize.c new file mode 100644 index 0000000..7883ada --- /dev/null +++ b/lib/fs/optimize.c @@ -0,0 +1,45 @@ +/* **************************************************************************** + * fs/open.c -- open a libcasio filesystem. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of libcasio. + * libcasio is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcasio 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libcasio; if not, see . + * ************************************************************************* */ +#include "fs.h" + +/** + * casio_optimize: + * Optimize a filesystem. + * + * @arg fs the filesystem. + * @arg device the device name. + * @return the error code (0 if ok). + */ + +int CASIO_EXPORT casio_optimize(casio_fs_t *fs, const char *device) +{ + int err; + casio_fs_optim_t *optim; + + /* Get the callback. */ + + optim = fs->casio_fs_funcs.casio_fsfuncs_optim; + if (!optim) + return (casio_error_op); + + /* Just do it. */ + + err = (*optim)(fs->casio_fs_cookie, device); + return (err); +} diff --git a/src/fs/path.c b/lib/fs/path.c similarity index 100% rename from src/fs/path.c rename to lib/fs/path.c diff --git a/src/fs/pathnode.c b/lib/fs/pathnode.c similarity index 100% rename from src/fs/pathnode.c rename to lib/fs/pathnode.c diff --git a/src/internals.h b/lib/internals.h similarity index 100% rename from src/internals.h rename to lib/internals.h diff --git a/src/link/info.c b/lib/link/info.c similarity index 100% rename from src/link/info.c rename to lib/link/info.c diff --git a/src/link/link.h b/lib/link/link.h similarity index 100% rename from src/link/link.h rename to lib/link/link.h diff --git a/src/link/lock.c b/lib/link/lock.c similarity index 100% rename from src/link/lock.c rename to lib/link/lock.c diff --git a/src/link/open.c b/lib/link/open.c similarity index 100% rename from src/link/open.c rename to lib/link/open.c diff --git a/src/link/open/com.c b/lib/link/open/com.c similarity index 100% rename from src/link/open/com.c rename to lib/link/open/com.c diff --git a/src/link/open/usb.c b/lib/link/open/usb.c similarity index 100% rename from src/link/open/usb.c rename to lib/link/open/usb.c diff --git a/src/link/seven/command.c b/lib/link/seven/command.c similarity index 100% rename from src/link/seven/command.c rename to lib/link/seven/command.c diff --git a/src/link/seven/data.c b/lib/link/seven/data.c similarity index 96% rename from src/link/seven/data.c rename to lib/link/seven/data.c index f935f86..b6a6093 100644 --- a/src/link/seven/data.c +++ b/lib/link/seven/data.c @@ -28,7 +28,7 @@ * Send data packet. * * Carries 'raw' data in the context of a command. E.g. file data. - * Maximum data size is 256 octets. + * Maximum data size is CASIO_SEVEN_MAX_RAWDATA_SIZE (256) octets. * * @arg handle the link handle * @arg total the total number of data packets in trans @@ -43,8 +43,12 @@ int CASIO_EXPORT casio_seven_send_data_packet(casio_link_t *handle, unsigned int total, unsigned int id, const void *data, unsigned int datasize, int resp) { + unsigned char buf[8 + CASIO_SEVEN_MAX_RAWDATA_SIZE]; + + if (datasize > CASIO_SEVEN_MAX_RAWDATA_SIZE) + return (casio_error_op); + /* make new buffer */ - unsigned char buf[8 + datasize]; casio_putascii(buf, total, 4); casio_putascii(&buf[4], id, 4); memcpy(&buf[8], data, datasize); diff --git a/src/link/seven/data.h b/lib/link/seven/data.h similarity index 100% rename from src/link/seven/data.h rename to lib/link/seven/data.h diff --git a/src/link/seven/dataflow.c b/lib/link/seven/dataflow.c similarity index 100% rename from src/link/seven/dataflow.c rename to lib/link/seven/dataflow.c diff --git a/src/link/seven/datastream.c b/lib/link/seven/datastream.c similarity index 100% rename from src/link/seven/datastream.c rename to lib/link/seven/datastream.c diff --git a/src/link/seven/devices.c b/lib/link/seven/devices.c similarity index 100% rename from src/link/seven/devices.c rename to lib/link/seven/devices.c diff --git a/src/link/seven/eack.c b/lib/link/seven/eack.c similarity index 100% rename from src/link/seven/eack.c rename to lib/link/seven/eack.c diff --git a/src/link/seven/encoderaw.c b/lib/link/seven/encoderaw.c similarity index 100% rename from src/link/seven/encoderaw.c rename to lib/link/seven/encoderaw.c diff --git a/src/link/seven/init.c b/lib/link/seven/init.c similarity index 100% rename from src/link/seven/init.c rename to lib/link/seven/init.c diff --git a/src/link/seven/receive.c b/lib/link/seven/receive.c similarity index 100% rename from src/link/seven/receive.c rename to lib/link/seven/receive.c diff --git a/src/link/seven/send.c b/lib/link/seven/send.c similarity index 100% rename from src/link/seven/send.c rename to lib/link/seven/send.c diff --git a/src/link/seven_fs/delete.c b/lib/link/seven_fs/delete.c similarity index 100% rename from src/link/seven_fs/delete.c rename to lib/link/seven_fs/delete.c diff --git a/src/link/seven_fs/open.c b/lib/link/seven_fs/open.c similarity index 96% rename from src/link/seven_fs/open.c rename to lib/link/seven_fs/open.c index e3882f6..fcc0a2c 100644 --- a/src/link/seven_fs/open.c +++ b/lib/link/seven_fs/open.c @@ -26,7 +26,8 @@ CASIO_LOCAL casio_fsfuncs_t sevenfs_callbacks = { (casio_fs_freepath_t*)&casio_free_sevenfs_path, NULL, NULL, (casio_fs_del_t*)&casio_sevenfs_delete, - NULL, NULL, NULL + NULL, NULL, NULL, + (casio_fs_optim_t*)&casio_sevenfs_optimize }; /** diff --git a/lib/link/seven_fs/optimize.c b/lib/link/seven_fs/optimize.c new file mode 100644 index 0000000..dcab59e --- /dev/null +++ b/lib/link/seven_fs/optimize.c @@ -0,0 +1,42 @@ +/* **************************************************************************** + * link/seven_fs/optimize.c -- optimize a Protocol 7.00 filesystem. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of libcasio. + * libcasio is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcasio 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libcasio; if not, see . + * ************************************************************************* */ +#include "seven_fs.h" + +/** + * casio_sevenfs_optimize: + * Optimize a Protocol 7.00 filesystem. + * + * @arg cookie the cookie. + * @return the error code (0 if ok). + */ + +int CASIO_EXPORT casio_sevenfs_optimize(sevenfs_cookie_t *cookie, + const char *device) +{ + int err; casio_link_t *handle = cookie; + + msg((ll_info, "Sending the optimize command.")); + err = casio_seven_send_cmdfls_opt(handle, device); + if (err) + return (err); + if (response.casio_seven_packet_type != casio_seven_type_ack) + return (casio_error_unknown); + + return (0); +} diff --git a/src/link/seven_fs/seven_fs.h b/lib/link/seven_fs/seven_fs.h similarity index 92% rename from src/link/seven_fs/seven_fs.h rename to lib/link/seven_fs/seven_fs.h index a5c60e0..8ae6660 100644 --- a/src/link/seven_fs/seven_fs.h +++ b/lib/link/seven_fs/seven_fs.h @@ -46,4 +46,9 @@ CASIO_EXTERN void CASIO_EXPORT casio_free_sevenfs_path CASIO_EXTERN int CASIO_EXPORT casio_sevenfs_delete OF((sevenfs_cookie_t *casio__cookie, sevenfs_path_t *casio__path)); +/* Optimize the filesystem. */ + +CASIO_EXTERN int CASIO_EXPORT casio_sevenfs_optimize + OF((sevenfs_cookie_t *casio__cookie, const char *casio__device)); + #endif /* LOCAL_LINK_SEVEN_FS_H */ diff --git a/src/link/seven_fs/topath.c b/lib/link/seven_fs/topath.c similarity index 100% rename from src/link/seven_fs/topath.c rename to lib/link/seven_fs/topath.c diff --git a/src/link/seven_mcs/delete.c b/lib/link/seven_mcs/delete.c similarity index 100% rename from src/link/seven_mcs/delete.c rename to lib/link/seven_mcs/delete.c diff --git a/src/link/seven_mcs/get.c b/lib/link/seven_mcs/get.c similarity index 100% rename from src/link/seven_mcs/get.c rename to lib/link/seven_mcs/get.c diff --git a/src/link/seven_mcs/list.c b/lib/link/seven_mcs/list.c similarity index 100% rename from src/link/seven_mcs/list.c rename to lib/link/seven_mcs/list.c diff --git a/src/link/seven_mcs/open.c b/lib/link/seven_mcs/open.c similarity index 100% rename from src/link/seven_mcs/open.c rename to lib/link/seven_mcs/open.c diff --git a/src/link/seven_mcs/put.c.draft b/lib/link/seven_mcs/put.c.draft similarity index 100% rename from src/link/seven_mcs/put.c.draft rename to lib/link/seven_mcs/put.c.draft diff --git a/src/link/seven_mcs/seven_mcs.h b/lib/link/seven_mcs/seven_mcs.h similarity index 100% rename from src/link/seven_mcs/seven_mcs.h rename to lib/link/seven_mcs/seven_mcs.h diff --git a/src/link/usage/backup_rom.c b/lib/link/usage/backup_rom.c similarity index 100% rename from src/link/usage/backup_rom.c rename to lib/link/usage/backup_rom.c diff --git a/src/link/usage/getscreen.c b/lib/link/usage/getscreen.c similarity index 100% rename from src/link/usage/getscreen.c rename to lib/link/usage/getscreen.c diff --git a/src/link/usage/server/seven.c b/lib/link/usage/server/seven.c similarity index 100% rename from src/link/usage/server/seven.c rename to lib/link/usage/server/seven.c diff --git a/src/link/usage/setlink.c b/lib/link/usage/setlink.c similarity index 100% rename from src/link/usage/setlink.c rename to lib/link/usage/setlink.c diff --git a/src/link/usage/upload_and_run.c b/lib/link/usage/upload_and_run.c similarity index 99% rename from src/link/usage/upload_and_run.c rename to lib/link/usage/upload_and_run.c index 53892af..300f13a 100644 --- a/src/link/usage/upload_and_run.c +++ b/lib/link/usage/upload_and_run.c @@ -74,6 +74,7 @@ int CASIO_EXPORT casio_upload_and_run(casio_link_t *handle, } #ifndef LIBCASIO_DISABLED_FILE + /** * casio_upload_and_run_file: * Upload and run, FILE version. @@ -103,4 +104,5 @@ int CASIO_EXPORT casio_upload_and_run_file(casio_link_t *handle, FILE *file, buf_err = casio_close(buffer); return (err ? err : buf_err); } + #endif diff --git a/src/link/usage/usage.h b/lib/link/usage/usage.h similarity index 100% rename from src/link/usage/usage.h rename to lib/link/usage/usage.h diff --git a/src/log/conv.c b/lib/log/conv.c similarity index 100% rename from src/log/conv.c rename to lib/log/conv.c diff --git a/src/log/log.h b/lib/log/log.h similarity index 100% rename from src/log/log.h rename to lib/log/log.h diff --git a/src/log/manage.c b/lib/log/manage.c similarity index 100% rename from src/log/manage.c rename to lib/log/manage.c diff --git a/src/log/mem.c b/lib/log/mem.c similarity index 100% rename from src/log/mem.c rename to lib/log/mem.c diff --git a/src/log/msg.c b/lib/log/msg.c similarity index 100% rename from src/log/msg.c rename to lib/log/msg.c diff --git a/src/mcs/delete.c b/lib/mcs/delete.c similarity index 100% rename from src/mcs/delete.c rename to lib/mcs/delete.c diff --git a/src/mcs/get.c b/lib/mcs/get.c similarity index 100% rename from src/mcs/get.c rename to lib/mcs/get.c diff --git a/src/mcs/list.c b/lib/mcs/list.c similarity index 100% rename from src/mcs/list.c rename to lib/mcs/list.c diff --git a/src/mcs/local/delete.c b/lib/mcs/local/delete.c similarity index 100% rename from src/mcs/local/delete.c rename to lib/mcs/local/delete.c diff --git a/src/mcs/local/find.c b/lib/mcs/local/find.c similarity index 100% rename from src/mcs/local/find.c rename to lib/mcs/local/find.c diff --git a/src/mcs/local/get.c b/lib/mcs/local/get.c similarity index 100% rename from src/mcs/local/get.c rename to lib/mcs/local/get.c diff --git a/src/mcs/local/list.c b/lib/mcs/local/list.c similarity index 100% rename from src/mcs/local/list.c rename to lib/mcs/local/list.c diff --git a/src/mcs/local/local.h b/lib/mcs/local/local.h similarity index 100% rename from src/mcs/local/local.h rename to lib/mcs/local/local.h diff --git a/src/mcs/local/open.c b/lib/mcs/local/open.c similarity index 100% rename from src/mcs/local/open.c rename to lib/mcs/local/open.c diff --git a/src/mcs/local/put.c b/lib/mcs/local/put.c similarity index 100% rename from src/mcs/local/put.c rename to lib/mcs/local/put.c diff --git a/src/mcs/mcs.h b/lib/mcs/mcs.h similarity index 100% rename from src/mcs/mcs.h rename to lib/mcs/mcs.h diff --git a/src/mcs/open.c b/lib/mcs/open.c similarity index 100% rename from src/mcs/open.c rename to lib/mcs/open.c diff --git a/src/mcs/put.c b/lib/mcs/put.c similarity index 100% rename from src/mcs/put.c rename to lib/mcs/put.c diff --git a/src/mcs/transfer.c b/lib/mcs/transfer.c similarity index 100% rename from src/mcs/transfer.c rename to lib/mcs/transfer.c diff --git a/src/mcsfile/copy.c b/lib/mcsfile/copy.c similarity index 100% rename from src/mcsfile/copy.c rename to lib/mcsfile/copy.c diff --git a/src/mcsfile/decode/cas.c b/lib/mcsfile/decode/cas.c similarity index 100% rename from src/mcsfile/decode/cas.c rename to lib/mcsfile/decode/cas.c diff --git a/src/mcsfile/decode/cas/cell.c b/lib/mcsfile/decode/cas/cell.c similarity index 100% rename from src/mcsfile/decode/cas/cell.c rename to lib/mcsfile/decode/cas/cell.c diff --git a/src/mcsfile/decode/cas/program.c b/lib/mcsfile/decode/cas/program.c similarity index 100% rename from src/mcsfile/decode/cas/program.c rename to lib/mcsfile/decode/cas/program.c diff --git a/src/mcsfile/decode/cas/sshot.c b/lib/mcsfile/decode/cas/sshot.c similarity index 100% rename from src/mcsfile/decode/cas/sshot.c rename to lib/mcsfile/decode/cas/sshot.c diff --git a/src/mcsfile/decode/decode.h b/lib/mcsfile/decode/decode.h similarity index 100% rename from src/mcsfile/decode/decode.h rename to lib/mcsfile/decode/decode.h diff --git a/src/mcsfile/decode/mcs.c b/lib/mcsfile/decode/mcs.c similarity index 100% rename from src/mcsfile/decode/mcs.c rename to lib/mcsfile/decode/mcs.c diff --git a/src/mcsfile/decode/mcs/cells.c b/lib/mcsfile/decode/mcs/cells.c similarity index 100% rename from src/mcsfile/decode/mcs/cells.c rename to lib/mcsfile/decode/mcs/cells.c diff --git a/src/mcsfile/decode/mcs/picture.c b/lib/mcsfile/decode/mcs/picture.c similarity index 100% rename from src/mcsfile/decode/mcs/picture.c rename to lib/mcsfile/decode/mcs/picture.c diff --git a/src/mcsfile/decode/mcs/program.c b/lib/mcsfile/decode/mcs/program.c similarity index 100% rename from src/mcsfile/decode/mcs/program.c rename to lib/mcsfile/decode/mcs/program.c diff --git a/src/mcsfile/decode/mcs/setup.c b/lib/mcsfile/decode/mcs/setup.c similarity index 100% rename from src/mcsfile/decode/mcs/setup.c rename to lib/mcsfile/decode/mcs/setup.c diff --git a/src/mcsfile/decode/mcs/ssheet.c b/lib/mcsfile/decode/mcs/ssheet.c similarity index 100% rename from src/mcsfile/decode/mcs/ssheet.c rename to lib/mcsfile/decode/mcs/ssheet.c diff --git a/src/mcsfile/decode/mcs/string.c b/lib/mcsfile/decode/mcs/string.c similarity index 100% rename from src/mcsfile/decode/mcs/string.c rename to lib/mcsfile/decode/mcs/string.c diff --git a/src/mcsfile/decode/mcs/var.c b/lib/mcsfile/decode/mcs/var.c similarity index 100% rename from src/mcsfile/decode/mcs/var.c rename to lib/mcsfile/decode/mcs/var.c diff --git a/src/mcsfile/dup.c b/lib/mcsfile/dup.c similarity index 100% rename from src/mcsfile/dup.c rename to lib/mcsfile/dup.c diff --git a/src/mcsfile/free.c b/lib/mcsfile/free.c similarity index 100% rename from src/mcsfile/free.c rename to lib/mcsfile/free.c diff --git a/src/mcsfile/head.c b/lib/mcsfile/head.c similarity index 100% rename from src/mcsfile/head.c rename to lib/mcsfile/head.c diff --git a/src/mcsfile/make.c b/lib/mcsfile/make.c similarity index 100% rename from src/mcsfile/make.c rename to lib/mcsfile/make.c diff --git a/src/mcsfile/match.c b/lib/mcsfile/match.c similarity index 100% rename from src/mcsfile/match.c rename to lib/mcsfile/match.c diff --git a/src/mcsfile/mcsfile.h b/lib/mcsfile/mcsfile.h similarity index 100% rename from src/mcsfile/mcsfile.h rename to lib/mcsfile/mcsfile.h diff --git a/src/mcsfile/prepare.c b/lib/mcsfile/prepare.c similarity index 100% rename from src/mcsfile/prepare.c rename to lib/mcsfile/prepare.c diff --git a/src/mcsfile/ref/cas_app.c b/lib/mcsfile/ref/cas_app.c similarity index 100% rename from src/mcsfile/ref/cas_app.c rename to lib/mcsfile/ref/cas_app.c diff --git a/src/mcsfile/ref/cas_data.c b/lib/mcsfile/ref/cas_data.c similarity index 100% rename from src/mcsfile/ref/cas_data.c rename to lib/mcsfile/ref/cas_data.c diff --git a/src/mcsfile/ref/mcs.c b/lib/mcsfile/ref/mcs.c similarity index 100% rename from src/mcsfile/ref/mcs.c rename to lib/mcsfile/ref/mcs.c diff --git a/src/mcsfile/ref/ref.h b/lib/mcsfile/ref/ref.h similarity index 100% rename from src/mcsfile/ref/ref.h rename to lib/mcsfile/ref/ref.h diff --git a/src/picture/decode.c b/lib/picture/decode.c similarity index 100% rename from src/picture/decode.c rename to lib/picture/decode.c diff --git a/src/picture/encode.c b/lib/picture/encode.c similarity index 100% rename from src/picture/encode.c rename to lib/picture/encode.c diff --git a/src/picture/picture.h b/lib/picture/picture.h similarity index 100% rename from src/picture/picture.h rename to lib/picture/picture.h diff --git a/src/picture/size.c b/lib/picture/size.c similarity index 100% rename from src/picture/size.c rename to lib/picture/size.c diff --git a/src/setup/export.c.draft b/lib/setup/export.c.draft similarity index 100% rename from src/setup/export.c.draft rename to lib/setup/export.c.draft diff --git a/src/setup/feed_mcs.c b/lib/setup/feed_mcs.c similarity index 100% rename from src/setup/feed_mcs.c rename to lib/setup/feed_mcs.c diff --git a/src/setup/feed_seven.c b/lib/setup/feed_seven.c similarity index 100% rename from src/setup/feed_seven.c rename to lib/setup/feed_seven.c diff --git a/src/setup/init.c b/lib/setup/init.c similarity index 100% rename from src/setup/init.c rename to lib/setup/init.c diff --git a/src/setup/setup.h b/lib/setup/setup.h similarity index 100% rename from src/setup/setup.h rename to lib/setup/setup.h diff --git a/src/stream/attrs.c b/lib/stream/attrs.c similarity index 100% rename from src/stream/attrs.c rename to lib/stream/attrs.c diff --git a/src/stream/builtin/csum32.c b/lib/stream/builtin/csum32.c similarity index 96% rename from src/stream/builtin/csum32.c rename to lib/stream/builtin/csum32.c index 53759df..529214f 100644 --- a/src/stream/builtin/csum32.c +++ b/lib/stream/builtin/csum32.c @@ -23,6 +23,7 @@ struct thecookie { casio_stream_t *_stream; casio_uint32_t *_checksum; }; + /* ************************************************************************* */ /* Callbacks */ /* ************************************************************************* */ @@ -42,10 +43,12 @@ CASIO_LOCAL int csum32_read(struct thecookie *cookie, int err; /* Make the call. */ + err = casio_read(cookie->_stream, dest, size); if (err) return (err); /* Make the checksum. */ + *cookie->_checksum = casio_checksum32(dest, size, *cookie->_checksum); return (0); } @@ -68,6 +71,7 @@ CASIO_LOCAL int csum32_close(struct thecookie *cookie) CASIO_LOCAL const casio_streamfuncs_t csum32_callbacks = casio_stream_callbacks_for_virtual(csum32_close, csum32_read, NULL, NULL); + /* ************************************************************************* */ /* Main functions */ /* ************************************************************************* */ @@ -88,15 +92,18 @@ int CASIO_EXPORT casio_open_csum32(casio_stream_t **stream, casio_openmode_t openmode; /* FIXME: check original stream */ - /* allocate the cookie */ + /* Allocate the cookie. */ + cookie = casio_alloc(1, sizeof(struct thecookie)); if (!cookie) return (casio_error_alloc); - /* fill the cookie */ + /* Fill the cookie. */ + cookie->_stream = original; cookie->_checksum = csum; - /* Initialize da stream. */ + /* Initialize and return da stream. */ + openmode = casio_get_openmode(original) & CASIO_OPENMODE_READ; return (casio_open_stream(stream, openmode, cookie, &csum32_callbacks, 0)); } diff --git a/src/stream/builtin/file.c b/lib/stream/builtin/file.c similarity index 87% rename from src/stream/builtin/file.c rename to lib/stream/builtin/file.c index 19ccf6b..2b8ab90 100644 --- a/src/stream/builtin/file.c +++ b/lib/stream/builtin/file.c @@ -33,6 +33,7 @@ typedef struct { int _rstream_cl, _wstream_cl; FILE *_rstream, *_wstream; } file_cookie_t; + /* ************************************************************************* */ /* Callbacks */ /* ************************************************************************* */ @@ -51,23 +52,29 @@ CASIO_LOCAL int casio_file_read(file_cookie_t *cookie, { size_t recv; - /* main receiving loop */ + /* Main receiving loop. */ + recv = 0; do { - /* read */ + /* Read. */ + recv = fread(dest, 1, size, cookie->_rstream); - /* iterate */ + /* Iterate. */ + dest = (void*)((char*)dest + recv); size -= recv; - /* check error */ + /* Check the error. */ + if (!recv) { - /* approximation */ + /* Approximation. */ + if (errno != EAGAIN) break; - /* i'm absolutely unsure about this... */ + /* I'm absolutely unsure about this... */ + msg((ll_info, "received EAGAIN, sleep and retry")); errno = 0; casio_sleep(3000); @@ -75,25 +82,28 @@ CASIO_LOCAL int casio_file_read(file_cookie_t *cookie, } } while (size); - /* check error */ + /* Check the error. */ if (!recv) switch (errno) { - /* end of file */ case 0: + /* End of file. */ + msg((ll_error, "encountered an end of file")); return (casio_error_eof); - /* - timeout - */ case EINTR: /* alarm */ case ETIMEDOUT: # ifdef ETIME case ETIME: # endif + /* A timeout has occurred. */ + msg((ll_error, "timeout received")); return (casio_error_timeout); - /* - device error - */ case ENODEV: case EPIPE: case ESPIPE: + /* A device error has occured. */ + msg((ll_error, "calculator was disconnected")); return (casio_error_nocalc); @@ -120,37 +130,40 @@ CASIO_LOCAL int casio_file_write(file_cookie_t *cookie, { size_t sent; - /* main sending */ + /* Main sending. */ + sent = fwrite(data, size, 1, cookie->_wstream); - /* check the error */ + /* Check the error. */ + if (!sent) switch (errno) { - /* end of file */ case 0: + /* End of file (EOF). */ + msg((ll_error, "encountered an end of file")); return (casio_error_eof); - /* - timeout error - */ case EINTR: /* alarm */ case ETIMEDOUT: # ifdef ETIME case ETIME: # endif + /* Timeout error. */ + msg((ll_error, "timeout received")); return (casio_error_timeout); - /* - device disconnected - */ case ENODEV: + /* Device disconnected. */ + msg((ll_fatal, "calculator was disconnected")); return (casio_error_nocalc); - /* - unknown error - */ default: msg((ll_fatal, "errno was %d: %s", errno, strerror(errno))); return (casio_error_unknown); } - /* no error */ return (0); } @@ -170,6 +183,7 @@ CASIO_LOCAL int casio_file_seek(file_cookie_t *cookie, casio_off_t *offset, int wh; /* Seek. */ + wh = whence == CASIO_SEEK_SET ? SEEK_SET : whence == CASIO_SEEK_CUR ? SEEK_CUR : SEEK_END; @@ -177,6 +191,7 @@ CASIO_LOCAL int casio_file_seek(file_cookie_t *cookie, casio_off_t *offset, return (casio_error_op); /* TODO: check errno? */ /* Hide. */ + *offset = (casio_off_t)ftell(cookie->_rstream); return (0); } @@ -224,30 +239,41 @@ int CASIO_EXPORT casio_open_stream_file(casio_stream_t **stream, file_cookie_t *cookie = NULL; int err; casio_openmode_t mode = 0; - /* setup the mode. */ - if (rstream && __freadable(rstream)) mode |= CASIO_OPENMODE_READ; - if (wstream && __fwritable(wstream)) mode |= CASIO_OPENMODE_WRITE; + /* Setup the mode. */ + + if (rstream && __freadable(rstream)) + mode |= CASIO_OPENMODE_READ; + if (wstream && __fwritable(wstream)) + mode |= CASIO_OPENMODE_WRITE; if (!mode) { msg((ll_error, "Neither readable or writable...")); err = casio_error_nostream; goto fail; } - /* allocate the cookie */ - cookie = casio_alloc(1, sizeof(file_cookie_t)); - if (!cookie) { err = casio_error_alloc; goto fail; } + /* Allocate the cookie. */ + + cookie = casio_alloc(1, sizeof(file_cookie_t)); + if (!cookie) { + err = casio_error_alloc; + goto fail; + } + + /* Fill the cookie. */ - /* fill the cookie */ cookie->_rstream_cl = rstream_cl; cookie->_wstream_cl = wstream_cl; cookie->_rstream = rstream; cookie->_wstream = wstream; - /* initialize the stream */ + /* Initialize the stream. */ + return (casio_open_stream(stream, mode, cookie, &casio_file_callbacks, 0)); fail: - if (rstream && rstream_cl) fclose(rstream); - if (wstream != rstream && wstream_cl) fclose(wstream); + if (rstream && rstream_cl) + fclose(rstream); + if (wstream != rstream && wstream_cl) + fclose(wstream); return (err); } diff --git a/src/stream/builtin/libusb/close.c b/lib/stream/builtin/libusb/close.c similarity index 91% rename from src/stream/builtin/libusb/close.c rename to lib/stream/builtin/libusb/close.c index d70983b..afe007c 100644 --- a/src/stream/builtin/libusb/close.c +++ b/lib/stream/builtin/libusb/close.c @@ -29,8 +29,10 @@ int CASIO_EXPORT casio_libusb_close(cookie_libusb_t *cookie) { - if (cookie->_handle) libusb_close(cookie->_handle); - if (cookie->_context) libusb_exit(cookie->_context); + if (cookie->_handle) + libusb_close(cookie->_handle); + if (cookie->_context) + libusb_exit(cookie->_context); casio_free(cookie); return (0); } diff --git a/src/stream/builtin/libusb/libusb.h b/lib/stream/builtin/libusb/libusb.h similarity index 97% rename from src/stream/builtin/libusb/libusb.h rename to lib/stream/builtin/libusb/libusb.h index 25d14f4..fdc75ea 100644 --- a/src/stream/builtin/libusb/libusb.h +++ b/lib/stream/builtin/libusb/libusb.h @@ -23,14 +23,17 @@ # include # define BUFSIZE 2048 + typedef struct { libusb_context *_context; libusb_device_handle *_handle; - /* timeouts */ + /* Timeouts. */ + unsigned int tmread, tmwrite; - /* buffer control */ + /* Buffer control. */ + ssize_t _start, _end; unsigned char _buffer[BUFSIZE]; } cookie_libusb_t; diff --git a/src/stream/builtin/libusb/open.c b/lib/stream/builtin/libusb/open.c similarity index 81% rename from src/stream/builtin/libusb/open.c rename to lib/stream/builtin/libusb/open.c index bb48c57..c9b05d4 100644 --- a/src/stream/builtin/libusb/open.c +++ b/lib/stream/builtin/libusb/open.c @@ -20,6 +20,7 @@ #ifndef LIBCASIO_DISABLED_LIBUSB /* Stream callbacks. */ + CASIO_LOCAL const casio_streamfuncs_t casio_libusb_callbacks = { (casio_stream_close_t*)&casio_libusb_close, (casio_stream_settm_t*)&casio_libusb_settm, @@ -46,13 +47,15 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream) cookie_libusb_t *cookie = NULL; casio_openmode_t openmode = CASIO_OPENMODE_USB; - /* open up context */ + /* Open up context. */ + if (libusb_init(&context)) { msg((ll_fatal, "Couldn't create libusb context.")); return (casio_error_nocalc); } - /* get device list */ + /* Get device list. */ + device_count = libusb_get_device_list(context, &device_list); if (device_count < 0) { msg((ll_fatal, "couldn't get device list.")); @@ -60,15 +63,18 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream) goto fail; } - /* look for the calculator */ + /* Look for the calculator. */ + for (id = 0; id < device_count; id++) { struct libusb_device_descriptor descriptor; - /* get the device descriptor */ + /* Get the device descriptor. */ + if (libusb_get_device_descriptor(device_list[id], &descriptor)) continue; - /* check if is a CASIO Protocol 7.00 device */ + /* Check if is a CASIO Protocol 7.00 device. */ + if (descriptor.idVendor == 0x07cf && descriptor.idProduct == 0x6101) { openmode |= CASIO_OPENMODE_READ | CASIO_OPENMODE_WRITE; @@ -76,7 +82,8 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream) break; } - /* check if is a CASIO SCSI device */ + /* Check if is a CASIO SCSI device. */ + if (descriptor.idVendor == 0x07cf && descriptor.idProduct == 0x6102) { openmode |= CASIO_OPENMODE_SCSI; @@ -85,43 +92,53 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream) } } - /* the calculator wasn't found */ + /* The calculator wasn't found. */ + if (!calc) { libusb_free_device_list(device_list, 1); err = casio_error_nocalc; goto fail; } - /* get calculator handle */ + /* Get calculator handle. */ + msg((ll_info, "getting the device handle")); uerr = libusb_open(calc, &dhandle); libusb_free_device_list(device_list, 1); - /* check if we have the handle */ + /* Check if we have the handle. */ + switch (uerr) { - /* couldn't get access to the device */ + case 0: + /* No error! */ + break; + case LIBUSB_ERROR_ACCESS: + /* Couldn't get access to the device. */ + err = casio_error_noaccess; goto fail; - /* default cases */ - case 0: break; default: + /* Default cases. */ + msg((ll_fatal, "libusb_open returned %d: %s", uerr, libusb_error_name(uerr))); err = casio_error_noaccess; goto fail; } - /* disconnect any kernel driver */ + /* Disconnect any kernel driver. */ + msg((ll_info, "Detaching kernel driver, if any.")); uerr = libusb_detach_kernel_driver(dhandle, 0); switch (uerr) { - /* cases where it's okay */ - case 0: case LIBUSB_ERROR_NOT_SUPPORTED: - case LIBUSB_ERROR_NOT_FOUND: break; + case 0: + case LIBUSB_ERROR_NOT_SUPPORTED: + case LIBUSB_ERROR_NOT_FOUND: + /* Cases where it's okay. */ + break; - /* cases where it's not okay */ case LIBUSB_ERROR_INVALID_PARAM: msg((ll_fatal, "Interface 0 doesn't exist...?")); err = casio_error_nocalc; @@ -135,17 +152,20 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream) goto fail; } - /* check if the interface is active */ + /* Check if the interface is active. */ + libusb_kernel_driver_active(dhandle, 0); - /* claim the interface */ + /* Claim the interface. */ + msg((ll_info, "Claiming the interface.")); uerr = libusb_claim_interface(dhandle, 0); switch (uerr) { - /* cases where it's okay (not a lot) */ - case 0: break; + case 0: + /* Cases where it's okay (not a lot). */ + break; - /* cases where it's not okay */ + /* Cases where it's not okay. */ case LIBUSB_ERROR_NO_DEVICE: case LIBUSB_ERROR_NOT_FOUND: err = casio_error_nocalc; @@ -161,22 +181,27 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream) goto fail; } - /* make the cookie */ + /* Make the cookie. */ + cookie = casio_alloc(1, sizeof(cookie_libusb_t)); err = casio_error_alloc; - if (!cookie) goto fail; + if (!cookie) + goto fail; cookie->_context = context; cookie->_handle = dhandle; cookie->_start = 0; cookie->_end = -1; /* final call. */ - return (casio_open_stream(stream, openmode, - cookie, &casio_libusb_callbacks, 0)); + return (casio_open_stream(stream, openmode, cookie, + &casio_libusb_callbacks, 0)); fail: - if (cookie) casio_free(cookie); - if (dhandle) libusb_close(dhandle); - if (context) libusb_exit(context); + if (cookie) + casio_free(cookie); + if (dhandle) + libusb_close(dhandle); + if (context) + libusb_exit(context); return (err); } diff --git a/src/stream/builtin/libusb/read.c b/lib/stream/builtin/libusb/read.c similarity index 91% rename from src/stream/builtin/libusb/read.c rename to lib/stream/builtin/libusb/read.c index c4eea8f..1441f77 100644 --- a/src/stream/builtin/libusb/read.c +++ b/lib/stream/builtin/libusb/read.c @@ -30,13 +30,15 @@ */ # define ENDPOINT_IN (LIBUSB_ENDPOINT_IN | LIBUSB_TRANSFER_TYPE_BULK) + int CASIO_EXPORT casio_libusb_read(cookie_libusb_t *cookie, unsigned char *dest, size_t size) { int libusberr; size_t tocopy; - /* transmit what's already in the buffer */ + /* Transmit what's already in the buffer. */ + if (cookie->_start <= cookie->_end) { tocopy = cookie->_end - cookie->_start + 1; if (tocopy > size) tocopy = size; @@ -47,15 +49,18 @@ int CASIO_EXPORT casio_libusb_read(cookie_libusb_t *cookie, size -= tocopy; } - /* main receiving loop */ + /* Main receiving loop. */ + while (size) { int recv; - /* make the transfer. */ + /* Make the transfer. */ + libusberr = libusb_bulk_transfer(cookie->_handle, ENDPOINT_IN, cookie->_buffer, BUFSIZE, &recv, cookie->tmread); switch (libusberr) { - case 0: break; + case 0: + break; case LIBUSB_ERROR_PIPE: case LIBUSB_ERROR_NO_DEVICE: @@ -72,21 +77,23 @@ int CASIO_EXPORT casio_libusb_read(cookie_libusb_t *cookie, return (casio_error_unknown); } - /* get the current size to copy */ + /* Get the current size to copy. */ + tocopy = (size_t)recv; if (tocopy > size) tocopy = size; - /* copy to destination */ + /* Copy to destination. */ + memcpy(dest, cookie->_buffer, tocopy); dest += tocopy; size -= tocopy; - /* correct start and end points */ + /* Correct start and end points. */ + cookie->_start = tocopy; cookie->_end = (size_t)recv - 1; } - /* no error */ return (0); } diff --git a/src/stream/builtin/libusb/settm.c b/lib/stream/builtin/libusb/settm.c similarity index 97% rename from src/stream/builtin/libusb/settm.c rename to lib/stream/builtin/libusb/settm.c index 3e1faba..517ad4d 100644 --- a/src/stream/builtin/libusb/settm.c +++ b/lib/stream/builtin/libusb/settm.c @@ -31,11 +31,11 @@ int CASIO_EXPORT casio_libusb_settm(cookie_libusb_t *cookie, const casio_timeouts_t *timeouts) { - /* set the timeouts */ + /* Set the timeouts. */ + cookie->tmread = timeouts->casio_timeouts_read; cookie->tmwrite = timeouts->casio_timeouts_write; - /* no error! */ return (0); } diff --git a/src/stream/builtin/libusb/write.c b/lib/stream/builtin/libusb/write.c similarity index 99% rename from src/stream/builtin/libusb/write.c rename to lib/stream/builtin/libusb/write.c index 1c95c19..42a4e18 100644 --- a/src/stream/builtin/libusb/write.c +++ b/lib/stream/builtin/libusb/write.c @@ -30,12 +30,14 @@ */ # define ENDPOINT_OUT (LIBUSB_ENDPOINT_OUT | LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) + int CASIO_EXPORT casio_libusb_write(cookie_libusb_t *cookie, const unsigned char *data, size_t size) { int sent, libusberr; /* Make the transfer. */ + libusberr = libusb_bulk_transfer(cookie->_handle, ENDPOINT_OUT, (unsigned char*)data, size, &sent, cookie->tmwrite); switch (libusberr) { @@ -52,7 +54,6 @@ int CASIO_EXPORT casio_libusb_write(cookie_libusb_t *cookie, return (casio_error_unknown); } - /* no error! */ return (0); } diff --git a/src/stream/builtin/limited.c b/lib/stream/builtin/limited.c similarity index 96% rename from src/stream/builtin/limited.c rename to lib/stream/builtin/limited.c index 1b3a868..4d37628 100644 --- a/src/stream/builtin/limited.c +++ b/lib/stream/builtin/limited.c @@ -18,12 +18,14 @@ * ************************************************************************* */ #include "../../internals.h" -/* cookie structure */ +/* Cookie structure. */ + typedef struct { char _magic[8]; casio_stream_t *_stream; size_t _left; } limited_cookie_t; + /* ************************************************************************* */ /* Callbacks */ /* ************************************************************************* */ @@ -57,8 +59,7 @@ CASIO_LOCAL int casio_limited_read(void *vcookie, unsigned char *dest, return (casio_error_eof); } - err = casio_read(cookie->_stream, dest, size); - if (err) { + if ((err = casio_read(cookie->_stream, dest, size))) { cookie->_left = 0; /* XXX: depends on the error? */ return (err); } @@ -81,9 +82,11 @@ CASIO_LOCAL int casio_limited_close(void *vcookie) } /* Callbacks. */ + CASIO_LOCAL const casio_streamfuncs_t casio_limited_callbacks = casio_stream_callbacks_for_virtual(casio_limited_close, casio_limited_read, NULL, NULL); + /* ************************************************************************* */ /* Main functions */ /* ************************************************************************* */ @@ -106,7 +109,8 @@ int CASIO_EXPORT casio_open_limited(casio_stream_t **stream, /* allocate the cookie */ cookie = casio_alloc(1, sizeof(limited_cookie_t)); - if (!cookie) return (casio_error_alloc); + if (!cookie) + return (casio_error_alloc); /* Fill the cookie. */ diff --git a/src/stream/builtin/memory.c b/lib/stream/builtin/memory.c similarity index 90% rename from src/stream/builtin/memory.c rename to lib/stream/builtin/memory.c index 58100e4..8b32e56 100644 --- a/src/stream/builtin/memory.c +++ b/lib/stream/builtin/memory.c @@ -23,6 +23,7 @@ typedef struct { unsigned char *_memory; casio_off_t _size, _offset; } memory_cookie_t; + /* ************************************************************************* */ /* Callbacks */ /* ************************************************************************* */ @@ -97,17 +98,29 @@ CASIO_LOCAL int casio_memory_seek(void *vcookie, casio_off_t *offset, memory_cookie_t *cookie = (void*)vcookie; casio_off_t off; - /* get the offset */ + /* Get the offset. */ + switch (whence) { - case CASIO_SEEK_CUR: off = cookie->_offset + *offset; break; - case CASIO_SEEK_END: off = cookie->_size - *offset; break; - default /* CASIO_SEEK_SET */: off = *offset; break; } + case CASIO_SEEK_CUR: + off = cookie->_offset + *offset; + break; + case CASIO_SEEK_END: + off = cookie->_size - *offset; + break; + default /* CASIO_SEEK_SET */: + off = *offset; + break; + } - /* check the bounds */ - if (off < 0) off = 0; - else if (off >= cookie->_size) off = cookie->_size - 1; + /* Check the bounds. */ + + if (off < 0) + off = 0; + else if (off >= cookie->_size) + off = cookie->_size - 1; + + /* Set the offset, return. */ - /* set the offset, return */ *offset = off; cookie->_offset = off; return (0); @@ -131,6 +144,7 @@ CASIO_LOCAL int casio_memory_close(void *vcookie) CASIO_LOCAL const casio_streamfuncs_t casio_memory_callbacks = casio_stream_callbacks_for_virtual(casio_memory_close, casio_memory_read, casio_memory_write, casio_memory_seek); + /* ************************************************************************* */ /* Opening functions */ /* ************************************************************************* */ @@ -149,20 +163,24 @@ int CASIO_EXPORT casio_open_memory(casio_stream_t **stream, { memory_cookie_t *cookie = NULL; - /* check things */ + /* Check things. */ + if (!memory || !size) return (casio_error_nostream); - /* allocate the cookie */ + /* Allocate the cookie. */ + cookie = casio_alloc(1, sizeof(memory_cookie_t)); if (!cookie) return (casio_error_alloc); - /* fill the cookie */ + /* Fill the cookie. */ + cookie->_memory = (void*)memory; cookie->_size = size; cookie->_offset = 0; - /* initialize da stream */ + /* Initialize and return da stream. */ + return (casio_open_stream(stream, CASIO_OPENMODE_READ, cookie, &casio_memory_callbacks, 0)); } diff --git a/src/stream/builtin/streams/close.c b/lib/stream/builtin/streams/close.c similarity index 95% rename from src/stream/builtin/streams/close.c rename to lib/stream/builtin/streams/close.c index bfc8e40..a22726f 100644 --- a/src/stream/builtin/streams/close.c +++ b/lib/stream/builtin/streams/close.c @@ -29,14 +29,16 @@ int CASIO_EXPORT casio_streams_close(streams_cookie_t *cookie) { - /* close the file descriptors. */ + /* Close the file descriptors. */ + if (cookie->_readfd >= 0 && cookie->_closeread) close(cookie->_readfd); if (cookie->_writefd >= 0 && cookie->_readfd != cookie->_writefd && cookie->_closewrite) close(cookie->_writefd); - /* free the cookie. */ + /* Free the cookie and exit. */ + casio_free(cookie); return (0); } diff --git a/src/stream/builtin/streams/open.c b/lib/stream/builtin/streams/open.c similarity index 89% rename from src/stream/builtin/streams/open.c rename to lib/stream/builtin/streams/open.c index 86f271b..91950f1 100644 --- a/src/stream/builtin/streams/open.c +++ b/lib/stream/builtin/streams/open.c @@ -20,6 +20,7 @@ #ifndef LIBCASIO_DISABLED_STREAMS /* Callbacks. */ + CASIO_LOCAL const casio_streamfuncs_t casio_streams_callbacks = casio_stream_callbacks_for_serial(casio_streams_close, casio_streams_setattrs, casio_streams_settm, @@ -56,7 +57,8 @@ int CASIO_EXPORT casio_open_stream_streams(casio_stream_t **stream, { int openfd, readfd, writefd, flags; - /* make up the flags */ + /* Make up the flags. */ + flags = O_NOCTTY; if ((mode & CASIO_OPENMODE_READ) && (mode & CASIO_OPENMODE_WRITE)) flags |= O_RDWR; @@ -66,33 +68,39 @@ int CASIO_EXPORT casio_open_stream_streams(casio_stream_t **stream, flags |= O_WRONLY; else return (casio_error_invalid); - /* open the stream */ + /* Open the stream. */ + openfd = open(path, flags); if (openfd < 0) switch (errno) { - /* no such device */ case ENODEV: case ENOENT: case ENXIO: case EPIPE: case ESPIPE: + /* No such device. */ + msg((ll_error, "couldn't open calculator: %s", strerror(errno))); return (casio_error_nocalc); - /* no access */ case EACCES: + /* No access. */ + msg((ll_error, "permission denied")); return (casio_error_noaccess); - /* default */ default: + /* Default case. */ + msg((ll_error, "unknown error: %s (0x%X)", strerror(errno), errno)); return (casio_error_unknown); } - /* make the file descriptors */ + /* Make the file descriptors. */ + readfd = mode & CASIO_OPENMODE_READ ? openfd : -1; writefd = mode & CASIO_OPENMODE_WRITE ? openfd : -1; - /* make the final stream */ + /* Make the final stream. */ + return (casio_open_stream_fd(stream, readfd, writefd, 1, 1)); } @@ -115,18 +123,28 @@ int CASIO_EXPORT casio_open_stream_fd(casio_stream_t **stream, casio_openmode_t mode = CASIO_OPENMODE_READ | CASIO_OPENMODE_WRITE | CASIO_OPENMODE_SERIAL; - /* check if the devices are valid. */ + /* Check if the devices are valid. */ + if ( readfd < 0 || read(readfd, NULL, 0) < 0) mode &= ~CASIO_OPENMODE_READ; if (writefd < 0 || write(writefd, NULL, 0) < 0) mode &= ~CASIO_OPENMODE_WRITE; - /* check if we have at least read/write file descriptors. */ - if (!mode) { err = casio_error_invalid; goto fail; } + /* Check if we have at least read/write file descriptors. */ + + if (!mode) { + err = casio_error_invalid; + goto fail; + } + + /* Allocate cookie. */ - /* allocate cookie */ cookie = casio_alloc(1, sizeof(streams_cookie_t)); - if (!cookie) { err = casio_error_alloc; goto fail; } + if (!cookie) { + err = casio_error_alloc; + goto fail; + } + cookie->_readfd = readfd; cookie->_writefd = writefd; cookie->_closeread = closeread; @@ -134,11 +152,13 @@ int CASIO_EXPORT casio_open_stream_fd(casio_stream_t **stream, cookie->_start = 0; cookie->_end = -1; - /* init for real */ + /* Init for real. */ + msg((ll_info, "Initializing STREAMS stream with fds: (%d, %d)", readfd, writefd)); - /* final call */ + /* Final call. */ + return (casio_open_stream(stream, mode, cookie, &casio_streams_callbacks, 0)); fail: diff --git a/src/stream/builtin/streams/read.c b/lib/stream/builtin/streams/read.c similarity index 89% rename from src/stream/builtin/streams/read.c rename to lib/stream/builtin/streams/read.c index 7bfcd7b..74e86e0 100644 --- a/src/stream/builtin/streams/read.c +++ b/lib/stream/builtin/streams/read.c @@ -34,7 +34,8 @@ int CASIO_EXPORT casio_streams_read(streams_cookie_t *cookie, { int fd = cookie->_readfd; - /* transmit what's already in the buffer */ + /* Transmit what's already in the buffer. */ + if (cookie->_start <= cookie->_end) { size_t tocopy = cookie->_end - cookie->_start + 1; if (tocopy > size) tocopy = size; @@ -45,16 +46,20 @@ int CASIO_EXPORT casio_streams_read(streams_cookie_t *cookie, size -= tocopy; } - /* main receiving loop */ + /* Main receiving loop. */ + while (size) { ssize_t recv; size_t tocopy; - /* receive */ - recv = read(fd, cookie->_buffer, BUFSIZE); - if (!recv) continue; + /* Receive. */ + + recv = read(fd, cookie->_buffer, BUFSIZE); + if (!recv) + continue; + + /* Check error. */ - /* check error */ if (recv < 0) switch (errno) { case 0: continue; case ENODEV: case EIO: @@ -65,21 +70,23 @@ int CASIO_EXPORT casio_streams_read(streams_cookie_t *cookie, return (casio_error_unknown); } - /* get the current size to copy */ + /* Get the current size to copy. */ + tocopy = (size_t)recv; if (tocopy > size) tocopy = size; - /* copy to destination */ + /* Copy to destination. */ + memcpy(dest, cookie->_buffer, tocopy); dest += tocopy; size -= tocopy; - /* correct start and end points */ + /* Correct start and end points. */ + cookie->_start = tocopy; cookie->_end = (size_t)recv - 1; } - /* no error */ return (0); } diff --git a/src/stream/builtin/streams/scsi.c b/lib/stream/builtin/streams/scsi.c similarity index 100% rename from src/stream/builtin/streams/scsi.c rename to lib/stream/builtin/streams/scsi.c diff --git a/src/stream/builtin/streams/setattrs.c b/lib/stream/builtin/streams/setattrs.c similarity index 92% rename from src/stream/builtin/streams/setattrs.c rename to lib/stream/builtin/streams/setattrs.c index 2fbcffe..4840099 100644 --- a/src/stream/builtin/streams/setattrs.c +++ b/lib/stream/builtin/streams/setattrs.c @@ -38,7 +38,8 @@ CASIO_LOCAL int set_attrs_for_fd(const int fd, speed_t speed; unsigned int status, dtrflags, rtsflags; - /* get the speed */ + /* Get the speed. */ + switch (settings->casio_streamattrs_speed) { case CASIO_B1200: speed = B1200; break; case CASIO_B2400: speed = B2400; break; @@ -54,15 +55,18 @@ CASIO_LOCAL int set_attrs_for_fd(const int fd, return (casio_error_op); } - /* get the current configuration */ + /* Get the current configuration. */ + if (tcgetattr(fd, &term) < 0) return (casio_error_unknown); - /* set the speed */ + /* Set the speed. */ + cfsetispeed(&term, speed); cfsetospeed(&term, speed); - /* input flags */ + /* Input flags. */ + term.c_iflag &= ~(IGNBRK | IGNCR | BRKINT | PARMRK | ISTRIP | INLCR | ICRNL | IGNPAR | IXON | IXOFF); if (settings->casio_streamattrs_flags & CASIO_XONMASK) @@ -70,11 +74,13 @@ CASIO_LOCAL int set_attrs_for_fd(const int fd, if (settings->casio_streamattrs_flags & CASIO_XOFFMASK) term.c_iflag |= IXOFF; - /* output flags, local modes */ + /* Output flags, local modes. */ + term.c_oflag = 0; term.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - /* control flags */ + /* Control flags. */ + term.c_cflag &= ~(PARENB | PARODD | CREAD | CSTOPB | CSIZE); term.c_cflag |= CREAD | CS8; if (settings->casio_streamattrs_flags & CASIO_TWOSTOPBITS) @@ -84,20 +90,25 @@ CASIO_LOCAL int set_attrs_for_fd(const int fd, if (settings->casio_streamattrs_flags & CASIO_PARODD) term.c_cflag |= PARODD; - /* control characters */ + /* Control characters. */ + term.c_cc[VSTART] = settings->casio_streamattrs_cc[CASIO_XON]; term.c_cc[VSTOP] = settings->casio_streamattrs_cc[CASIO_XOFF]; term.c_cc[VMIN] = 0; /* ? */ - /* update the termios settings! */ + /* Update the termios settings! */ + if (tcsetattr(fd, TCSANOW, &term)) return (casio_error_unknown); - /* get line status */ + /* Get line status. */ + if (ioctl(fd, TIOCMGET, &status) >= 0) status = 0; status &= ~(TIOCM_DTR | TIOCM_RTS); - /* activate DTR and RTS */ + /* Activate DTR and RTS. + * TODO: use the 'X' versions if available? */ + dtrflags = settings->casio_streamattrs_flags & CASIO_DTRMASK; rtsflags = settings->casio_streamattrs_flags & CASIO_RTSMASK; if (dtrflags == CASIO_DTRCTL_ENABLE || dtrflags == CASIO_DTRCTL_HANDSHAKE) @@ -107,7 +118,6 @@ CASIO_LOCAL int set_attrs_for_fd(const int fd, if (ioctl(fd, TIOCMSET, &status) < 0) return (casio_error_unknown); - /* no error! */ return (0); } @@ -125,7 +135,8 @@ int CASIO_EXPORT casio_streams_setattrs(streams_cookie_t *cookie, { int err; - /* set attributes */ + /* Set attributes. */ + if (cookie->_readfd >= 0) { err = set_attrs_for_fd(cookie->_readfd, settings); if (err) return (err); @@ -135,7 +146,6 @@ int CASIO_EXPORT casio_streams_setattrs(streams_cookie_t *cookie, if (err) return (err); } - /* no error */ return (0); } diff --git a/src/stream/builtin/streams/settm.c b/lib/stream/builtin/streams/settm.c similarity index 92% rename from src/stream/builtin/streams/settm.c rename to lib/stream/builtin/streams/settm.c index 4b7a21d..15574bd 100644 --- a/src/stream/builtin/streams/settm.c +++ b/lib/stream/builtin/streams/settm.c @@ -33,27 +33,27 @@ int CASIO_EXPORT casio_streams_settm(streams_cookie_t *cookie, { struct termios term; - /* set on the read thing */ - if (!tcgetattr(cookie->_readfd, &term)) { - /* set the timeout */ - term.c_cc[VTIME] = timeouts->casio_timeouts_read / 100; + /* Set on the read thing. */ - /* update */ + if (!tcgetattr(cookie->_readfd, &term)) { + /* Set the timeout and update. */ + + term.c_cc[VTIME] = timeouts->casio_timeouts_read / 100; if (tcsetattr(cookie->_readfd, TCSANOW, &term)) return (0); } - /* set on the write thing */ + /* Set on the write thing. */ + if (cookie->_readfd != cookie->_writefd && !tcgetattr(cookie->_writefd, &term)) { - term.c_cc[VTIME] = timeouts->casio_timeouts_write / 100; + /* Set the timeout and update. */ - /* update */ + term.c_cc[VTIME] = timeouts->casio_timeouts_write / 100; if (tcsetattr(cookie->_writefd, TCSANOW, &term)) return (0); } - /* no error! */ return (0); } diff --git a/src/stream/builtin/streams/streams.h b/lib/stream/builtin/streams/streams.h similarity index 97% rename from src/stream/builtin/streams/streams.h rename to lib/stream/builtin/streams/streams.h index 443b205..d04b078 100644 --- a/src/stream/builtin/streams/streams.h +++ b/lib/stream/builtin/streams/streams.h @@ -27,13 +27,16 @@ # include # include -/* the cookie type */ +/* The cookie type. */ + # define BUFSIZE 2048 + typedef struct { int _readfd, _writefd; int _closeread, _closewrite; - /* buffer [control] */ + /* Buffer [control] */ + ssize_t _start, _end; unsigned char _buffer[BUFSIZE]; } streams_cookie_t; diff --git a/src/stream/builtin/streams/write.c b/lib/stream/builtin/streams/write.c similarity index 95% rename from src/stream/builtin/streams/write.c rename to lib/stream/builtin/streams/write.c index 55c1282..2388826 100644 --- a/src/stream/builtin/streams/write.c +++ b/lib/stream/builtin/streams/write.c @@ -34,14 +34,16 @@ int CASIO_EXPORT casio_streams_write(streams_cookie_t *cookie, { int fd = cookie->_writefd; - /* send */ + /* Send. */ + while (size) { ssize_t wr = write(fd, data, size); if (wr < 0) break; size -= (size_t)wr; } - /* be sure it's written, or check the error */ + /* Be sure it's written, or check the error. */ + if (size) switch (errno) { case ENODEV: return (casio_error_nocalc); @@ -50,7 +52,6 @@ int CASIO_EXPORT casio_streams_write(streams_cookie_t *cookie, return (casio_error_unknown); } - /* no error! */ return (0); } diff --git a/src/stream/builtin/windows/close.c b/lib/stream/builtin/windows/close.c similarity index 100% rename from src/stream/builtin/windows/close.c rename to lib/stream/builtin/windows/close.c diff --git a/src/stream/builtin/windows/find.c b/lib/stream/builtin/windows/find.c similarity index 87% rename from src/stream/builtin/windows/find.c rename to lib/stream/builtin/windows/find.c index 06d769d..6feae4e 100644 --- a/src/stream/builtin/windows/find.c +++ b/lib/stream/builtin/windows/find.c @@ -37,10 +37,12 @@ int CASIO_EXPORT casio_windows_find_usb(char **path, HDEVINFO DeviceInfoSet; SP_DEVICE_INTERFACE_DATA DeviceInterfaceData; - /* make the vid/pid string */ + /* Make the vid/pid string. */ + sprintf(vidpid, "#vid_%04x&pid_%04x", vid, pid); - /* get the device information set (chained list) */ + /* Get the device information set (chained list). */ + msg((ll_info, "Getting the device info set")); DeviceInfoSet = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); @@ -50,16 +52,17 @@ int CASIO_EXPORT casio_windows_find_usb(char **path, return (casio_error_notfound); } - /* browse this set, setup */ + /* Browse this set, setup. */ + DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); msg((ll_info, "Enumerating interfaces")); for (i = 0; SetupDiEnumDeviceInterfaces(DeviceInfoSet, NULL, &GUID_DEVINTERFACE_USB_DEVICE, i, &DeviceInterfaceData); i++) { - /* make the local variables */ DWORD RequiredSize = 0; const char *Path; PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData; - /* get the detail size */ + /* Get the detail size. */ + msg((ll_info, "Getting interface information detail size")); if (!SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, &DeviceInterfaceData, NULL, 0, &RequiredSize, NULL) && @@ -68,19 +71,20 @@ int CASIO_EXPORT casio_windows_find_usb(char **path, continue; } - /* allocate detail space */ - msg((ll_info, - "Allocating space for interface information detail (%luo)", - RequiredSize)); + /* Allocate detail space. */ + + msg((ll_info, "Allocating space for interface " + "information detail (%luo)", RequiredSize)); DeviceInterfaceDetailData = casio_alloc(RequiredSize, 1); if (!DeviceInterfaceDetailData) { msg((ll_error, "Memory allocation failed. Oh well.")); - break ; + break; } DeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); - /* get the detail */ + /* Get the detail. */ + msg((ll_info, "Getting interface information detail")); if (!SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, &DeviceInterfaceData, DeviceInterfaceDetailData, RequiredSize, @@ -91,24 +95,30 @@ int CASIO_EXPORT casio_windows_find_usb(char **path, continue; } - /* check if it corresponds */ + /* Check if it corresponds. */ + Path = DeviceInterfaceDetailData->DevicePath; msg((ll_info, "Stumbled across: %s", Path)); if (strstr(Path, vidpid)) { devpath = casio_alloc(strlen(Path) + 1, 1); - if (!devpath) break; + if (!devpath) + break; strcpy(devpath, Path); } - /* free the allocated detail */ + /* Free the allocated detail. */ + casio_free(DeviceInterfaceDetailData); - if (devpath) break ; + if (devpath) + break ; } - /* destroy the device information set */ + /* Destroy the device information set. */ + msg((ll_info, "Destroying the device information set")); SetupDiDestroyDeviceInfoList(DeviceInfoSet); - if (!devpath) return (casio_error_notfound); + if (!devpath) + return (casio_error_notfound); *path = devpath; return (0); } diff --git a/src/stream/builtin/windows/open.c b/lib/stream/builtin/windows/open.c similarity index 93% rename from src/stream/builtin/windows/open.c rename to lib/stream/builtin/windows/open.c index 794b006..c55a3a0 100644 --- a/src/stream/builtin/windows/open.c +++ b/lib/stream/builtin/windows/open.c @@ -19,7 +19,8 @@ #include "windows.h" #ifndef LIBCASIO_DISABLED_WINDOWS -/* Callbacks */ +/* Callbacks. */ + CASIO_LOCAL const casio_streamfuncs_t casio_windows_callbacks = { (casio_stream_close_t*)&casio_windows_close, (casio_stream_settm_t*)&casio_windows_settm, @@ -66,7 +67,8 @@ int CASIO_EXPORT casio_opencom_windows(casio_stream_t **stream, win_cookie_t *cookie = NULL; casio_openmode_t mode; - /* open the file handle - my god, this function is so complex. */ + /* Open the file handle - my god, this function is so complex. */ + msg((ll_info, "Opening the stream")); fhandle = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); @@ -81,11 +83,13 @@ int CASIO_EXPORT casio_opencom_windows(casio_stream_t **stream, err = casio_error_noaccess; goto fail; } - /* make cookie */ + /* Make the cookie. */ + msg((ll_info, "Making the cookie")); cookie = casio_alloc(1, sizeof(win_cookie_t)); err = casio_error_alloc; - if (!cookie) goto fail; + if (!cookie) + goto fail; /* fill cookie */ cookie->_handle = fhandle; @@ -97,8 +101,10 @@ int CASIO_EXPORT casio_opencom_windows(casio_stream_t **stream, return (casio_open_stream(stream, mode, cookie, &casio_windows_callbacks, 0)); fail: - if (fhandle != INVALID_HANDLE_VALUE) CloseHandle(fhandle); - if (cookie) casio_free(cookie); + if (fhandle != INVALID_HANDLE_VALUE) + CloseHandle(fhandle); + if (cookie) + casio_free(cookie); return (err); } diff --git a/src/stream/builtin/windows/read.c b/lib/stream/builtin/windows/read.c similarity index 90% rename from src/stream/builtin/windows/read.c rename to lib/stream/builtin/windows/read.c index 3ea6311..af56a3e 100644 --- a/src/stream/builtin/windows/read.c +++ b/lib/stream/builtin/windows/read.c @@ -32,7 +32,8 @@ int CASIO_EXPORT casio_windows_read(win_cookie_t *cookie, { DWORD werr, wsuccess, recv; size_t tocopy; - /* transmit what's already in the buffer */ + /* Transmit what's already in the buffer. */ + if (cookie->_start <= cookie->_end) { tocopy = cookie->_end - cookie->_start + 1; if (tocopy > size) tocopy = size; @@ -43,13 +44,16 @@ int CASIO_EXPORT casio_windows_read(win_cookie_t *cookie, size -= tocopy; } - /* main receiving loop */ + /* Main receiving loop. */ + while (size) { - /* receive */ + /* Receive. */ + wsuccess = ReadFile(cookie->_handle, cookie->_buf, size, &recv, NULL); - /* check error */ + /* Check error. */ + if (!wsuccess) switch ((werr = GetLastError())) { case ERROR_DEV_NOT_EXIST: msg((ll_error, "Device has been disconnected!")); @@ -60,21 +64,23 @@ int CASIO_EXPORT casio_windows_read(win_cookie_t *cookie, return (casio_error_unknown); } - /* get the current size to copy */ + /* Get the current size to copy. */ + tocopy = (size_t)recv; if (tocopy > size) tocopy = size; - /* copy to destination */ + /* Copy to destination. */ + memcpy(dest, cookie->_buf, tocopy); dest += tocopy; size -= tocopy; - /* correct start and end points */ + /* Correct start and end points. */ + cookie->_start = tocopy; cookie->_end = (size_t)recv - 1; } - /* no error */ return (0); } diff --git a/src/stream/builtin/windows/seek.c b/lib/stream/builtin/windows/seek.c similarity index 86% rename from src/stream/builtin/windows/seek.c rename to lib/stream/builtin/windows/seek.c index 7535bf1..b402cc7 100644 --- a/src/stream/builtin/windows/seek.c +++ b/lib/stream/builtin/windows/seek.c @@ -32,14 +32,21 @@ int CASIO_EXPORT casio_windows_seek(win_cookie_t *cookie, casio_off_t *offset, casio_whence_t whence) { - DWORD ret; + DWORD ret, MoveMethod; + + /* Get the move method. */ - /* get the move method */ - DWORD MoveMethod; switch (whence) { - case CASIO_SEEK_CUR: MoveMethod = FILE_CURRENT; break; - case CASIO_SEEK_END: MoveMethod = FILE_END; break; - default /* CASIO_SEEK_SET */: MoveMethod = FILE_BEGIN; break; } + case CASIO_SEEK_CUR: + MoveMethod = FILE_CURRENT; + break; + case CASIO_SEEK_END: + MoveMethod = FILE_END; + break; + default /* CASIO_SEEK_SET */: + MoveMethod = FILE_BEGIN; + break; + } ret = SetFilePointer(cookie->_handle, (LONG)*offset, NULL, MoveMethod); if (ret == INVALID_SET_FILE_POINTER) diff --git a/src/stream/builtin/windows/setattrs.c b/lib/stream/builtin/windows/setattrs.c similarity index 91% rename from src/stream/builtin/windows/setattrs.c rename to lib/stream/builtin/windows/setattrs.c index 7809ada..3b2e5e1 100644 --- a/src/stream/builtin/windows/setattrs.c +++ b/lib/stream/builtin/windows/setattrs.c @@ -36,7 +36,8 @@ int CASIO_EXPORT casio_windows_setattrs(win_cookie_t *cookie, { DWORD wsuccess, spd; DCB dcb; - /* get speed */ + /* Get the speed. */ + switch (settings->casio_streamattrs_speed) { case CASIO_B1200: spd = CBR_1200; break; case CASIO_B2400: spd = CBR_2400; break; @@ -52,7 +53,8 @@ int CASIO_EXPORT casio_windows_setattrs(win_cookie_t *cookie, return (casio_error_op); } - /* gather stream properties */ + /* Gather stream properties. */ + SecureZeroMemory(&dcb, sizeof(DCB)); dcb.DCBlength = sizeof(DCB); if (!GetCommState(cookie->_handle, &dcb)) { @@ -61,7 +63,8 @@ int CASIO_EXPORT casio_windows_setattrs(win_cookie_t *cookie, return (0); } - /* set normal things */ + /* Set normal things. */ + dcb.BaudRate = spd; dcb.ByteSize = 8; dcb.fParity = !!(settings->casio_streamattrs_flags & CASIO_PARENB); @@ -71,7 +74,8 @@ int CASIO_EXPORT casio_windows_setattrs(win_cookie_t *cookie, dcb.StopBits = (settings->casio_streamattrs_flags & CASIO_TWOSTOPBITS) ? TWOSTOPBITS : ONESTOPBIT; - /* set the DTR control mode */ + /* Set the DTR control mode. */ + switch (settings->casio_streamattrs_flags & CASIO_DTRMASK) { case CASIO_DTRCTL_ENABLE: dcb.fDtrControl = DTR_CONTROL_ENABLE; @@ -84,7 +88,8 @@ int CASIO_EXPORT casio_windows_setattrs(win_cookie_t *cookie, break; } - /* set the RTS control mode */ + /* Set the RTS control mode. */ + switch (settings->casio_streamattrs_flags & CASIO_RTSMASK) { case CASIO_RTSCTL_ENABLE: dcb.fRtsControl = RTS_CONTROL_ENABLE; @@ -97,20 +102,24 @@ int CASIO_EXPORT casio_windows_setattrs(win_cookie_t *cookie, break; } - /* set the XON/XOFF control mode on input */ + /* Set the XON/XOFF control mode on input. */ + dcb.fInX = !!(settings->casio_streamattrs_flags & CASIO_XONCTL_ENABLE); dcb.XonChar = settings->casio_streamattrs_cc[CASIO_XON]; - /* set the XON/XOFF control mode on output */ + /* Set the XON/XOFF control mode on output. */ + dcb.fOutX = !!(settings->casio_streamattrs_flags & CASIO_XOFFCTL_ENABLE); dcb.XoffChar = settings->casio_streamattrs_cc[CASIO_XOFF]; - /* set buffer limits (TODO: find out why non-zero values cause + /* Set buffer limits (TODO: find out why non-zero values cause * ERROR_INVALID_PARAMETER when using `SetCommState`) */ + dcb.XonLim = 0x0000; dcb.XoffLim = 0x0000; - /* save new state */ + /* Save new state. */ + msg((ll_info, "Updating the DCB.")); wsuccess = SetCommState(cookie->_handle, &dcb); if (!wsuccess) { @@ -118,7 +127,6 @@ int CASIO_EXPORT casio_windows_setattrs(win_cookie_t *cookie, return (casio_error_unknown); } - /* no error! */ return (0); } diff --git a/src/stream/builtin/windows/settm.c b/lib/stream/builtin/windows/settm.c similarity index 97% rename from src/stream/builtin/windows/settm.c rename to lib/stream/builtin/windows/settm.c index 0b88b53..3af1ce3 100644 --- a/src/stream/builtin/windows/settm.c +++ b/lib/stream/builtin/windows/settm.c @@ -31,14 +31,15 @@ int CASIO_EXPORT casio_windows_settm(win_cookie_t *cookie, const casio_timeouts_t *timeouts) { - /* set the timeouts */ COMMTIMEOUTS tm; + + /* Set the timeouts. */ + tm.ReadIntervalTimeout = timeouts->casio_timeouts_read_bw; tm.ReadTotalTimeoutConstant = timeouts->casio_timeouts_read; tm.WriteTotalTimeoutConstant = timeouts->casio_timeouts_write; SetCommTimeouts(cookie->_handle, &tm); - /* no error */ return (0); } diff --git a/src/stream/builtin/windows/windows.h b/lib/stream/builtin/windows/windows.h similarity index 95% rename from src/stream/builtin/windows/windows.h rename to lib/stream/builtin/windows/windows.h index b19422b..34402a9 100644 --- a/src/stream/builtin/windows/windows.h +++ b/lib/stream/builtin/windows/windows.h @@ -27,7 +27,8 @@ # define BUFSIZE 2048 /* Here is the structure of a cookie, used by the stream callbacks. - * PSP_COOKIE is just there to take the piss out of Microsoft :p */ + * PSP_COOKIE is just there to take the piss out of Microsoft, it isn't + * actually used in the source code. */ typedef struct { HANDLE _handle; diff --git a/src/stream/builtin/windows/write.c b/lib/stream/builtin/windows/write.c similarity index 95% rename from src/stream/builtin/windows/write.c rename to lib/stream/builtin/windows/write.c index 4689721..6092959 100644 --- a/src/stream/builtin/windows/write.c +++ b/lib/stream/builtin/windows/write.c @@ -34,20 +34,25 @@ int CASIO_EXPORT casio_windows_write(win_cookie_t *cookie, { BOOL wsuccess, werr; - /* make the I/O request */ + /* Make the I/O request. */ + wsuccess = TRUE; do { - /* write */ DWORD wrt; + + /* Write. */ + wsuccess = WriteFile(cookie->_handle, data, size, &wrt, NULL); if (!wsuccess) break; - /* go forward */ + /* Go forward. */ + data += wrt; size -= wrt; } while (size); - /* check error */ + /* Check the error. */ + if (!wsuccess) switch ((werr = GetLastError())) { case ERROR_DEV_NOT_EXIST: msg((ll_error, "Device has been disconnected!")); @@ -58,7 +63,6 @@ int CASIO_EXPORT casio_windows_write(win_cookie_t *cookie, return (casio_error_unknown); } - /* success! */ return (0); } diff --git a/src/stream/get.c b/lib/stream/get.c similarity index 100% rename from src/stream/get.c rename to lib/stream/get.c diff --git a/src/stream/open.c b/lib/stream/open.c similarity index 100% rename from src/stream/open.c rename to lib/stream/open.c diff --git a/src/stream/open/com.c b/lib/stream/open/com.c similarity index 100% rename from src/stream/open/com.c rename to lib/stream/open/com.c diff --git a/src/stream/open/usb.c b/lib/stream/open/usb.c similarity index 100% rename from src/stream/open/usb.c rename to lib/stream/open/usb.c diff --git a/src/stream/read.c b/lib/stream/read.c similarity index 100% rename from src/stream/read.c rename to lib/stream/read.c diff --git a/src/stream/seek.c b/lib/stream/seek.c similarity index 100% rename from src/stream/seek.c rename to lib/stream/seek.c diff --git a/src/stream/size.c b/lib/stream/size.c similarity index 100% rename from src/stream/size.c rename to lib/stream/size.c diff --git a/src/stream/skip.c b/lib/stream/skip.c similarity index 100% rename from src/stream/skip.c rename to lib/stream/skip.c diff --git a/src/stream/stream.h b/lib/stream/stream.h similarity index 100% rename from src/stream/stream.h rename to lib/stream/stream.h diff --git a/src/stream/timeouts.c b/lib/stream/timeouts.c similarity index 100% rename from src/stream/timeouts.c rename to lib/stream/timeouts.c diff --git a/src/stream/write.c b/lib/stream/write.c similarity index 100% rename from src/stream/write.c rename to lib/stream/write.c diff --git a/src/utils/alloc.c b/lib/utils/alloc.c similarity index 100% rename from src/utils/alloc.c rename to lib/utils/alloc.c diff --git a/src/utils/ascii.c b/lib/utils/ascii.c similarity index 100% rename from src/utils/ascii.c rename to lib/utils/ascii.c diff --git a/src/utils/checksum.c b/lib/utils/checksum.c similarity index 100% rename from src/utils/checksum.c rename to lib/utils/checksum.c diff --git a/src/utils/endian.c b/lib/utils/endian.c similarity index 100% rename from src/utils/endian.c rename to lib/utils/endian.c diff --git a/src/utils/endian.h b/lib/utils/endian.h similarity index 100% rename from src/utils/endian.h rename to lib/utils/endian.h diff --git a/src/utils/ext.c b/lib/utils/ext.c similarity index 100% rename from src/utils/ext.c rename to lib/utils/ext.c diff --git a/src/utils/mutex.c b/lib/utils/mutex.c similarity index 100% rename from src/utils/mutex.c rename to lib/utils/mutex.c diff --git a/src/utils/sleep.c b/lib/utils/sleep.c similarity index 100% rename from src/utils/sleep.c rename to lib/utils/sleep.c diff --git a/src/version.c b/lib/version.c similarity index 100% rename from src/version.c rename to lib/version.c diff --git a/src/version/check.c b/lib/version/check.c similarity index 100% rename from src/version/check.c rename to lib/version/check.c diff --git a/src/version/decode.c b/lib/version/decode.c similarity index 100% rename from src/version/decode.c rename to lib/version/decode.c diff --git a/src/version/encode.c b/lib/version/encode.c similarity index 100% rename from src/version/encode.c rename to lib/version/encode.c diff --git a/src/g1a-wrapper/args.c b/src/g1a-wrapper/args.c new file mode 100644 index 0000000..12e2d4c --- /dev/null +++ b/src/g1a-wrapper/args.c @@ -0,0 +1,194 @@ +/* ***************************************************************************** + * g1a-wrapper/args.c -- g1a-wrapper command-line argument parsing. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#include +#include +#include +#include + +/* ************************************************************************** */ +/* Help and version messages */ +/* ************************************************************************** */ +/* Version message */ +static const char version_message[] = +QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) + " (licensed under GPLv2)\n" +"Maintained by " QUOTE(MAINTAINER) ".\n" +"\n" +"This is free software; see the source for copying conditions.\n" +"There is NO warranty; not even for MERCHANTABILITY or\n" +"FITNESS FOR A PARTICULAR PURPOSE."; + +/* Main help message */ +static const char help_message[] = +"Usage: " QUOTE(BIN) " [-v] [--help|-h] \n" +" [-o ] [-i ] [-n ]\n" +" [--version ] [--internal <@ADDIN>]\n" +" [--date Output file name, default is 'addin.g1a'.\n" +" -i The application icon, must be 30x19.\n" +" Default is blank.\n" +" -n The application name. '[A-Z]{,8}' formatted.\n" +" Default name is the truncated output filename.\n" +" --version The application version, 'MM.mm.pppp' formatted.\n" +" Default is '00.00.0000'.\n" +" --internal The application internal name. '@[A-Z]{,7}' formatted.\n" +" Default is '@ADDIN'.\n" +" --date The application build date. 'yyyy.MMdd.hhmm' formatted.\n" +" Default is the current time.\n" +"\n" +"Report bugs to " QUOTE(MAINTAINER) "."; + +/* ************************************************************************** */ +/* Main function */ +/* ************************************************************************** */ +/** + * parse_args: + * Args parsing main function. + * + * Was my very first experiment with getopt. + * Then I took an arrow in the knee. + * + * @arg ac the arguments count + * @arg av the arguments values + * @arg args the parsed args pointer + * @return if it was successfully parsed + */ + +int parse_args(int ac, char **av, args_t *args) +{ + /* initialize args */ + static char name[9]; + *args = (args_t){ + .outfile = "addin.g1a", .iconfile = NULL, + .name = name, .intname = "@ADDIN", + .version = {0, 0, 0}, .date = time(NULL)}; + + /* define options */ + const char *short_options = "hvo:i:n:"; + struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"version", required_argument, NULL, 'V'}, + {"internal", required_argument, NULL, 'I'}, + {"date", required_argument, NULL, 'D'}, + {NULL, 0, NULL, 0}, + }; + + /* get all options */ + int c; opterr = 0; + int help = 0; + const char *s_ver = NULL, *s_date = NULL; + while ((c = getopt_long(ac, av, short_options, long_options, NULL)) != -1) + switch (c) { + /* help, version */ + case 'h': help = 1; break; + case 'v': puts(version_message); return (0); break; + + /* general options */ + case 'o': args->outfile = optarg; break; + case 'i': args->iconfile = optarg; break; + + /* build options */ + case 'n': args->name = optarg; break; + case 'V': s_ver = optarg; break; + case 'I': args->intname = optarg; break; + case 'D': s_date = optarg; break; + + /* in case of error */ + case '?': switch (optopt) { + case 'o': err("-o: expected an argument"); break; + case 'i': err("-i: expected an argument"); break; + case 'n': err("-n: expected an argument"); break; + case 'V': err("--version: expected an argument"); break; + case 'I': err("--internal: expected an argument"); break; + case 'D': err("--date: expected an argument"); break; + } break; + } + + /* get non-option arguments (subcommand and parameters) */ + int pc = ac - optind; char **pv = &av[optind]; + if (pc != 1) help = 1; + args->infile = pv[0]; + + /* put help */ + if (help) { puts(help_message); return (0); } + + /* get name */ + const char *p = strrchr(pv[0], '/'); + if (!p) p = pv[0]; + /* TODO: MS-Windows */ + const char *e = strrchr(p, '.'); + name[0] = 0; + for (int i = 0; p < e && i < 8; p++) { + if (isupper(*p)) { + name[i++] = *p; + name[i] = 0; + } + } if (!name[0]) + strcpy(name, "ADDIN"); + + /* check internal name */ + if (args->intname[0] != '@') { + err("internal name should start with an '@'"); + return (0); + } for (int i = 1; args->intname[i]; i++) { + if (i >= 8) { + err("internal name should be up to 8 characters only!"); + return (0); + } + + if (!isupper(args->intname[i])) { + err("internal name should be an '@' then up to seven uppercase " + "letters!"); + return (0); + } + } + + /* get version */ + if (s_ver) { + if (g1m_check_version(s_ver)) { + err("version string '%s' does not have " + "expected format 'MM.mm.ffff'", s_ver); + return (0); + } + + /* decode! */ + g1m_decode_version(s_ver, &args->version); + } + + /* get date */ + if (s_date) { + if (g1m_check_date(s_date)) { + err("date string '%s' does not have " + "expected format 'yyyy.MMdd.hhmm'", s_date); + return (0); + } + + /* decode! */ + g1m_decode_date(s_date, &args->date); + } + + /* everything went well */ + return (1); +} diff --git a/src/g1a-wrapper/icon.c b/src/g1a-wrapper/icon.c new file mode 100644 index 0000000..0b7dc60 --- /dev/null +++ b/src/g1a-wrapper/icon.c @@ -0,0 +1,94 @@ +/* ***************************************************************************** + * g1a-wrapper/icon.c -- g1a-wrapper icon decoding function. + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#include + +/** + * open_icon: + * Open the icon. + * + * @arg path the image path. + * @arg icon the image. + */ + +int open_icon(const char *path, uint32_t **icon) +{ + int ret = 1; + Image *images = NULL, *image = NULL; + ImageInfo *info = NULL; + ExceptionInfo *exception = NULL; + + /* initialize */ + MagickCoreGenesis("g1a-wrapper", MagickTrue); + + /* read source image and image info */ + exception = AcquireExceptionInfo(); + info = CloneImageInfo((ImageInfo*)NULL); + strcpy(info->filename, path); + images = ReadImage(info, exception); + if (!images) { + err("unable to open the icon: %s", exception->reason); + goto fail; + } + + /* get the first frame */ + image = RemoveFirstImageFromList(&images); + if (!image) goto fail; + + /* check the dimensions */ + unsigned int width = image->columns, height = image->rows; + if (width != 30 || height < 17 || height > 19) { + err("icon must be between 30x17 and 30x19 pixels, is %ux%u", + width, height); + goto fail; + } + + /* get the pixels */ + const Quantum *pixels = GetVirtualPixels(image, 0, 0, width, height, + exception); + if (!pixels) { + err("unable to access icon pixels."); + goto fail; + } + + /* skip the first line */ + if (height == 19) pixels += width * 4; + + /* get the pixels */ + for (size_t y = 0; y < 17; y++) for (size_t x = 0; x < 30; x++) { + /* get the total */ + float r = *pixels++; + float g = *pixels++; + float b = *pixels++; + pixels++; + + /* check the total */ + icon[y][x] = (r + g + b > 0x198) ? 0xFFFFFF : 0x000000; + } + + ret = 0; +fail: + if (info) DestroyImageInfo(info); + if (exception) DestroyExceptionInfo(exception); + if (image) DestroyImage(image); + if (images) DestroyImage(images); + MagickCoreTerminus(); + return (ret); +} diff --git a/src/g1a-wrapper/main.c b/src/g1a-wrapper/main.c new file mode 100644 index 0000000..db5a07e --- /dev/null +++ b/src/g1a-wrapper/main.c @@ -0,0 +1,100 @@ +/* ***************************************************************************** + * g1a-wrapper/main.c -- g1a-wrapper main source. + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#include +#include +#include + +/* ************************************************************************** */ +/* Main function */ +/* ************************************************************************** */ +/** + * main: + * User entry point of the program. + * + * @arg ac arguments count. + * @arg av arguments values. + * @return return code (0 if ok) + */ + +int main(int ac, char **av) +{ + int ret = 1; FILE *in = NULL; + g1m_handle_t *handle = NULL; + + /* Parse args */ + args_t args; + if (!parse_args(ac, av, &args)) + return (0); + + /* get file length */ + in = fopen(args.infile, "r"); + if (!in) { + err("couldn't open input file: %s", strerror(errno)); + goto fail; + } + if (fseek(in, 0L, SEEK_END) < 0) { + err("couldn't seek in file."); + goto fail; + } + long off = ftell(in); + if (off < 0L) + goto fail; + size_t sz = (off < 0) ? SIZE_MAX : (size_t)off; + if (fseek(in, 0L, SEEK_SET)) + goto fail; + + /* make the handle */ + int err = g1m_make_addin(&handle, g1m_platform_fx, sz, + args.name, args.intname, &args.version, &args.date); + if (err) { + err("couldn't make libg1m handle: %s", g1m_strerror(err)); + goto fail; + } + + /* decode the icon */ + open_icon(args.iconfile, handle->icon_unsel); + + /* copy the file content */ + unsigned char *p = handle->content; + while (sz) { + size_t rd = fread(p, 1, sz, in); + if (!rd) { + err("couldn't read binary data: %s", strerror(errno)); + goto fail; + } + sz -= rd; p += rd; + } + + /* encode */ + err = g1m_write(handle, args.outfile); + if (err) { + err("couldn't write to output file: %s", + err == g1m_error_nostream ? strerror(errno) : g1m_strerror(err)); + goto fail; + } + + /* we're good */ + ret = 0; +fail: + if (in) fclose(in); + if (handle) g1m_free(handle); + return (ret); +} diff --git a/src/g1a-wrapper/main.h b/src/g1a-wrapper/main.h new file mode 100644 index 0000000..9593736 --- /dev/null +++ b/src/g1a-wrapper/main.h @@ -0,0 +1,50 @@ +/* ***************************************************************************** + * g1a-wrapper/main.h -- g1a-wrapper main header. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#ifndef MAIN_H +# define MAIN_H +# define Q(x) #x +# define QUOTE(x) Q(x) +# include +# include +# define warn(M, ...) \ + fprintf(stderr, "g1a-wrapper: warning: " M "\n", ##__VA_ARGS__) +# define err(M, ...) \ + fprintf(stderr, "g1a-wrapper: error: " M "\n", ##__VA_ARGS__) + +/* Arguments */ +typedef struct { + /* general options */ + const char *infile; /* path to the input file */ + const char *outfile; /* default: addin.g1a */ + const char *iconfile; /* icon file, default is blank */ + + /* build options */ + const char *name; /* default: truncated output filename */ + const char *intname; /* default: @ADDIN */ + g1m_version_t version; /* default: 00.00.0000 */ + time_t date; /* default: current time */ +} args_t; + +/* Command-line arguments parsing function */ +extern int parse_args(int ac, char **av, args_t *args); + +/* Icon decoding function */ +extern int open_icon(const char *path, uint32_t **icon); + +#endif /* MAIN_H */ diff --git a/src/g1a-wrapper/vars.mk b/src/g1a-wrapper/vars.mk new file mode 100644 index 0000000..a4cdc31 --- /dev/null +++ b/src/g1a-wrapper/vars.mk @@ -0,0 +1,4 @@ +#!/usr/bin/make -f +disable: +libs: + @echo libcasio magick diff --git a/src/mcsfile/args.c b/src/mcsfile/args.c new file mode 100644 index 0000000..73cbd16 --- /dev/null +++ b/src/mcsfile/args.c @@ -0,0 +1,175 @@ +/* ***************************************************************************** + * mcsfile/args.c -- mcsfile command-line arguments parsing utility. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#define Q(x) #x +#define QUOTE(x) Q(x) + +/* --- + * Help and version messages. + * --- */ + +/* Help message. */ + +static const char *help_start = +"Usage: mcsfile [--version|-v] [--help|-h] \n" +"\n" +"Reads mcs files in a g1m file.\n" +"\n" +"Options are:\n" +" -h, --help Display this help message.\n" +" -v, --version Display the version message.\n"; + +static const char *help_loglevel_init = +" --log The library log level (default: %s).\n" +" One of: %s"; + +static const char *help_end = +"\n" +"Report bugs to " QUOTE(MAINTAINER) ".\n"; + +/* Version message. */ + +static const char *version_message = +"mcsfile - from p7utils v" QUOTE(VERSION) " (licensed under GPLv2)\n" +"Maintained by " QUOTE(MAINTAINER) ".\n" +"\n" +"This is free software; see the source for copying conditions.\n" +"There is NO warranty; not even for MERCHANTABILITY or\n" +"FITNESS FOR A PARTICULAR PURPOSE.\n"; + +/* --- + * Main argument parsing functions. + * --- */ + +/** + * put_loglevel: + * Put a loglevel (for listing). + * + * @arg initialized if the list was initialized. + * @arg level the level string. + */ + +static void put_loglevel(char **first, const char *level) +{ + if (!*first) { + *first = malloc(strlen(level) + 2); + if (!*first) return ; + strcpy(*first + 1, level); + **first = 'F'; + return ; + } + + if (**first == 'F') { + printf(help_loglevel_init, casio_getlog(), *first + 1); + **first = 'N'; + } + + printf(", %s", level); +} + +/** + * put_help: + * Put the help message on standard output. + */ + +static void put_help(void) +{ + char *first; + + /* First big part. */ + + fputs(help_start, stdout); + + /* Loglevels. */ + + first = NULL; + casio_listlog((casio_log_list_t*)&put_loglevel, (void*)&first); + if (first && *first == 'N') fputc('\n', stdout); + free(first); + + /* Second big part. */ + + fputs(help_end, stdout); +} + +/** + * put_version: + * Put the version message on standard output. + */ + +static void put_version(void) +{ + fputs(version_message, stdout); +} + +/** + * parse_args: + * Args parsing main function. + * + * @arg ac the arguments count. + * @arg av the arguments values. + * @arg files pointer to the file paths tab to allocate. + * @return if execution should stop. + */ + +int parse_args(int ac, char **av, const char **path) +{ + /* getopt elements */ + const char *optstring = "hv"; + const struct option longopts[] = { + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {} + }; + + /* get options */ + int c; opterr = 0; + int help = 0, version = 0; + while ((c = getopt_long(ac, av, optstring, longopts, NULL)) != -1) + switch (c) { + case 'h': help = 1; break; + case 'v': version = 1; break; + default: switch (optopt) { + default: + fprintf(stderr, "-%c: unknown option.\n", optopt); + } + return (1); + } + + /* check parameters */ + int pc = ac - optind; + char **pv = &av[optind]; + if (pc != 1) + help = 1; + else + *path = *pv; + + /* display version or help message */ + if (version) { + put_version(); + return (1); + } else if (help) { + put_help(); + return (1); + } + + /* no error */ + return (0); +} diff --git a/src/mcsfile/main.c b/src/mcsfile/main.c new file mode 100644 index 0000000..0978fd5 --- /dev/null +++ b/src/mcsfile/main.c @@ -0,0 +1,72 @@ +/* ***************************************************************************** + * mcsfile/main.c -- mcsfile main source. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#include +#include +#define cry(S, ...) fprintf(stderr, S "\n", ##__VA_ARGS__) + +/** + * main: + * Entry point of the program. + * + * @arg ac the arguments count. + * @arg av the arguments values. + * @return the status code (0 if ok). + */ + +int main(int ac, char **av) +{ + const char *path; + casio_file_t *handle; + int err; + + /* Set the locale and parse arguments. */ + + setlocale(LC_ALL, ""); + if (parse_args(ac, av, &path)) + return (0); + + /* parse */ + if ((err = casio_open_file(&handle, path, casio_filetype_mcs))) + switch (err) { + case casio_error_wrong: + cry("An MCS file was expected (g1m/g1r, g1m/g2r, g3m)"); + return (1); + case casio_error_nostream: + cry("Could not open file: %s", strerror(errno)); + return (1); + case casio_error_magic: + cry("Magic error: file might be corrupted"); + return (1); + case casio_error_eof: + cry("Unexpected end of file"); + return (1); + default: + cry("Unknown error: %s", casio_strerror(err)); + return (1); + } + + /* Read the files, free the handle and exit. */ + + print_files(handle->casio_file_mcs); + casio_free_file(handle); + + return (0); +} diff --git a/src/mcsfile/main.h b/src/mcsfile/main.h new file mode 100644 index 0000000..d810700 --- /dev/null +++ b/src/mcsfile/main.h @@ -0,0 +1,36 @@ +/* ***************************************************************************** + * mcsfile/main.h -- mcsfile main header. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#ifndef MAIN_H +# define MAIN_H +# include + +/* Some printf types */ +# ifdef _WIN64 +# define PRIuSIZE "l64u" +# elif _WIN32 +# define PRIuSIZE "u" +# else +# define PRIuSIZE "zu" +# endif + +/* Prototypes */ +int parse_args(int ac, char **av, const char **paths); +void print_files(casio_mcs_t *handle); + +#endif /* MAIN_H */ diff --git a/src/mcsfile/print.c b/src/mcsfile/print.c new file mode 100644 index 0000000..1835603 --- /dev/null +++ b/src/mcsfile/print.c @@ -0,0 +1,120 @@ +/* ***************************************************************************** + * mcsfile/print.c -- mcsfile directory printing utilities. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#include + +/** + * print_file: + * Put the description (with the newline). + * + * @arg file the MCS file. + */ + +static void print_file(void *cookie, const casio_mcshead_t *head) +{ + const char *password; + + (void)cookie; + + if (head->casio_mcshead_dirname[0]) + printf("%s/", head->casio_mcshead_dirname); + printf("%s: ", head->casio_mcshead_name); + + switch (head->casio_mcshead_type) { + case casio_mcstype_unknown: + printf("unknown content (%" PRIuSIZE " octets)\n", + head->casio_mcshead_size); + break; + + case casio_mcstype_program: + password = head->casio_mcshead_password; + + printf("program ("); + if (password && password[0]) + printf("password: '%s')\n", password); + else + printf("no password)\n"); + break; + + case casio_mcstype_list: + printf("list %d (", casio_get_id_minor(head->casio_mcshead_id)); + if (casio_get_id_major(head->casio_mcshead_id)) + printf("from listfile %d, ", + casio_get_id_major(head->casio_mcshead_id)); + printf("%d columns)\n", head->casio_mcshead_width); + break; + + case casio_mcstype_mat: + printf("matrix %c (%d columns, %d rows)\n", + 'A' + casio_get_id_minor(head->casio_mcshead_id) - 1, + head->casio_mcshead_width, head->casio_mcshead_height); + break; + + case casio_mcstype_vct: + printf("vector %c (%d rows)\n", + 'A' + casio_get_id_minor(head->casio_mcshead_id) - 1, + head->casio_mcshead_height); + break; + + case casio_mcstype_pict: + printf("picture %d (double %dx%d image)\n", + casio_get_id_minor(head->casio_mcshead_id), + head->casio_mcshead_width, head->casio_mcshead_height); + break; + + case casio_mcstype_capt: + printf("capture %d (%dx%d)\n", + casio_get_id_minor(head->casio_mcshead_id), + head->casio_mcshead_width, head->casio_mcshead_height); + break; + + case casio_mcstype_ssheet: + printf("spreadsheet (%d columns, %d rows)\n", + head->casio_mcshead_width, head->casio_mcshead_height); + break; + + case casio_mcstype_string: + printf("string %d\n", casio_get_id_minor(head->casio_mcshead_id)); + break; + + case casio_mcstype_setup: + printf("setup\n"); + break; + + case casio_mcstype_alphamem: + printf("alpha memory\n"); + break; + + default: + break; + } +} + +/** + * print_files: + * Put the files. + * + * @arg handle the handle. + */ + +void print_files(casio_mcs_t *handle) +{ + casio_list_mcsfiles(handle, &print_file, NULL); +} diff --git a/src/mcsfile/vars.mk b/src/mcsfile/vars.mk new file mode 100755 index 0000000..ce38114 --- /dev/null +++ b/src/mcsfile/vars.mk @@ -0,0 +1,4 @@ +#!/usr/bin/make -f +disable: +libs: + @echo libcasio diff --git a/src/p7/args.c b/src/p7/args.c new file mode 100644 index 0000000..f655861 --- /dev/null +++ b/src/p7/args.c @@ -0,0 +1,488 @@ +/* ***************************************************************************** + * p7/args.c -- p7 command-line argument parsing. + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#include +#include +#include +#include + +/* ************************************************************************** */ +/* Help and version messages */ +/* ************************************************************************** */ +/* Version message */ +static const char version_message[] = +QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) + " (licensed under GPLv2)\n" +"Maintained by " QUOTE(MAINTAINER) ".\n" +"\n" +"This is free software; see the source for copying conditions.\n" +"There is NO warranty; not even for MERCHANTABILITY or\n" +"FITNESS FOR A PARTICULAR PURPOSE."; + +/* Parts */ +#define FOOT \ + "\nType \"" QUOTE(BIN) " --help\" for other subcommands and general options." + +/* Sending help message */ +static const char help_send[] = +"Usage: " QUOTE(BIN) " send [-f] [-o ]\n" +" [-d ] [-#] \n" +"Send a file to the calculator.\n" +"\n" +"Options are:\n" +" -f, --force Overwrite without asking\n" +" -o The output filename on the calculator (by default, the same\n" +" as the local file)\n" +" -d The directory on-calc in which the file will be stored (by\n" +" default, the root directory)\n" +" -# Display a nice little loading bar\n" +FOOT; + +/* Getting help message */ +static const char help_get[] = +"Usage: " QUOTE(BIN) " get [-o ]\n" +" [-d ] \n" +"Request a file from the calculator.\n" +"\n" +"Options are:\n" +" -o The output filename (by default, the same as the on-calc file)\n" +" -d The directory on-calc in which to get the file (by default,\n" +" the root directory)\n" +" -# Display a nice little loading bar (if output isn't stdout)\n" +FOOT; + +/* Copying help message */ +static const char help_copy[] = +"Usage: " QUOTE(BIN) " copy [-d ] \n" +"Copies a file into the other on the calculator.\n" +"\n" +"Options are:\n" +" -d The source directory (by default, the root directory)\n" +" -t The dest. directory (by default, the root directory)\n" +FOOT; + +/* Deleting help message */ +static const char help_del[] = +"Usage: " QUOTE(BIN) " delete [-d \n" +"Delete a file on the calculator.\n" +"\n" +"Options are:\n" +" -d The directory on-calc in which to remove the file (by default,\n" +" the root directory)\n" +FOOT; + +/* Listing help message */ +static const char help_list[] = +"Usage: " QUOTE(BIN) " list\n" +"List files on the distant filesystem.\n" +FOOT; + +/* Resetting help message */ +static const char help_reset[] = +"Usage: " QUOTE(BIN) " reset\n" +"Reset the distant filesystem.\n" +FOOT; + +/* Optimizing help message */ +static const char help_optimize[] = +"Usage: " QUOTE(BIN) " optimize\n" +"Optimize the distant filesystem.\n" +FOOT; + +/* Dumping help message */ +static const char help_info[] = +"Usage: " QUOTE(BIN) " info\n" +"Dump information about the calculator.\n" +FOOT; + +/* List serial devices */ +static const char help_listcom[] = +"Usage: " QUOTE(BIN) " list-devices\n" +"List serial devices.\n" +FOOT; + +/* Idle */ +static const char help_idle[] = +"Usage: " QUOTE(BIN) " idle|laze\n" +"Only initialize or end the communication.\n" +"\n" +"This subcommand is useful when used with `--no-init` and/or `--no-exit`.\n" +"It allows you to prepare the communication state for the next calls, or to\n" +"end a series of calls, without any side effects.\n" +FOOT; + +/* Unlock */ +static const char help_unlock[] = +"Usage: " QUOTE(BIN) " unlock\n" +"Unlock examination mode.\n" +FOOT; +/* ************************************************************************** */ +/* Help helpers */ +/* ************************************************************************** */ +/* Main help message parts */ +static const char help_main_part0[] = +"Usage: " QUOTE(BIN) " [--version|-v] [--help|-h] [--no-init] [--no-exit]\n" +" [--storage ] [--com ]\n" +" [options...]\n" +"\n" +"Subcommands you can use are:\n" +" send Send a file to the calculator.\n" +" get Get a file from the calculator.\n" +" copy Copy a file into another on the calculator.\n" +" delete Delete a file on the calculator.\n" +" reset Reset the flash memory.\n" +" optimize Optimize the distant filesystem.\n" +" list List files on the distant filesystem.\n" +" info Dump info about the calculator.\n" +" idle Do nothing. (only start or end the communication)\n" +" unlock Unlock examination mode.\n" +"\n" +"General options:\n" +" -h, --help Display the help page of the (sub)command and quit.\n" +" -v, --version Display the version message and quit.\n" +" --com The serial device, if you want to communicate with a\n" +" calculator connected using a USB-to-serial cable.\n" +" If this option isn't used, the program will look for a\n" +" calculator connected using direct USB.\n" +" --storage The storage device with which to interact (fls0, crd0).\n" +" Default storage device is '" QUOTE(DEFAULT_STORAGE) "'.\n" +" --no-exit Does not terminate connection when action is completed.\n" +" --no-init Does not initialize connection (should only be used\n" +" when --no-exit was used last time p7 was called).\n" +" --use Use the following serial settings (when used with `--com`).\n" +" For example, \"9600N2\" represents 9600 bauds, no parity,\n" +" and two stop bits. (E for even parity, O for odd parity)\n" +" --set Set the following serial settings (when used with `--com`).\n" +" The string has the same format than for `--use`.\n"; + +static const char help_main_loglevel_init[] = +" --log The library log level (default: %s).\n" +" One of: %s"; + +static const char help_main_part1[] = +" --reset Reset the default communication settings (9600N2).\n" +"\n" +"Type \"" QUOTE(BIN) " --help\" for some help about the subcommand.\n" +"Report bugs to " QUOTE(MAINTAINER) ".\n"; + +/** + * put_loglevel: + * Put a loglevel (for listing). + * + * @arg initialized if the list was initialized. + * @arg level the level string. + */ + +static void put_loglevel(char **first, const char *level) +{ + if (!*first) { + *first = malloc(strlen(level) + 2); + if (!*first) return ; + strcpy(*first + 1, level); + **first = 'F'; + return ; + } + + if (**first == 'F') { + printf(help_main_loglevel_init, casio_getlog(), *first + 1); + **first = 'N'; + } + + printf(", %s", level); +} + +/** + * put_main_help: + * Put the main help on standard output. + */ + +static void put_main_help(void) +{ + char *first; + + /* First big part. */ + + fputs(help_main_part0, stdout); + + /* Loglevels. */ + + first = NULL; + casio_listlog((casio_log_list_t*)&put_loglevel, (void*)&first); + if (first && *first == 'N') fputc('\n', stdout); + free(first); + + /* Second big part. */ + + fputs(help_main_part1, stdout); +} +/* ************************************************************************** */ +/* Main function */ +/* ************************************************************************** */ +/* useful macros */ +#define sub_init(CMD, NARGS) \ + args->menu = mn_##CMD; \ + if (help || aac != 1 + (NARGS)) { \ + puts(help_##CMD); \ + return (0); \ + } + +/** + * parse_args: + * Args parsing main function. + * + * Was my very first experiment with getopt. + * Then I took an arrow in the knee. + * + * @arg ac the arguments count + * @arg av the arguments values + * @arg args the parsed args pointer + * @return if it was successfully parsed + */ + +int parse_args(int ac, char **av, args_t *args) +{ + int c, help = 0, rst = 0; + const char *s_out = NULL, *s_dir = NULL, *s_todir = NULL; + const char *s_use = NULL, *s_set = NULL, *s_log = NULL; + char short_options[] = "hvfo:d:t:#"; + struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {"com", required_argument, NULL, 'c'}, + {"storage", required_argument, NULL, 's'}, + {"force", no_argument, NULL, 'f'}, + {"output", required_argument, NULL, 'o'}, + {"directory", required_argument, NULL, 'd'}, + {"to", required_argument, NULL, 't'}, + {"no-init", no_argument, NULL, 'i'}, + {"no-start", no_argument, NULL, 'i'}, + {"no-exit", no_argument, NULL, 'e'}, + {"no-term", no_argument, NULL, 'e'}, + {"set", required_argument, NULL, 'S'}, + {"reset", no_argument, NULL, 'R'}, + {"use", required_argument, NULL, 'U'}, + {"log", required_argument, NULL, 'L'}, + + /* sentinel */ + {NULL, 0, NULL, 0} + }; + + /* initialize args */ + args->menu = 0; + args->nicedisp = 0; + args->dirname = NULL; + args->filename = NULL; + args->newdir = NULL; + args->newname = NULL; + args->local = NULL; + args->force = 0; + args->com = 0; + args->storage = QUOTE(DEFAULT_STORAGE); + args->initflags = CASIO_LINKFLAG_ACTIVE | CASIO_LINKFLAG_CHECK + | CASIO_LINKFLAG_TERM; + args->use = NULL; + args->set = NULL; + args->do_the_set = 0; + + /* get all options */ + opterr = 0; + while ((c = getopt_long(ac, av, short_options, long_options, NULL)) != -1) { + switch (c) { + /* help */ + case 'h': help = 1; break; + /* version */ + case 'v': puts(version_message); return (0); break; + /* force */ + case 'f': args->force = 1; break; + /* nice display */ + case '#': args->nicedisp = 1; break; + /* logging */ + case 'L': s_log = optarg; break; + + /* output file (on calc or local) */ + case 'o': s_out = optarg; break; + /* directory name */ + case 'd': s_dir = optarg; break; + /* destination directory name */ + case 't': s_todir = optarg; break; + + /* com port */ + case 'c': args->com = optarg; break; + /* storage */ + case 's': args->storage = optarg; break; + /* force no initialization */ + case 'i': args->initflags &= ~CASIO_LINKFLAG_CHECK; break; + /* force no exit */ + case 'e': args->initflags &= ~CASIO_LINKFLAG_TERM; break; + + /* use and set settings */ + case 'U': s_use = optarg; break; + case 'S': s_set = optarg; break; + case 'R': rst = 1; break; + + /* in case of error */ + case '?': + if (optopt == 'o') + log("-o, --output: expected an argument\n"); + else if (optopt == 'd') + log("-d, --directory: expected an argument\n"); + else if (optopt == 't') + log("-t, --to: expected an argument\n"); + else if (optopt == 'c') + log("--com: expected an argument\n"); + else if (optopt == 's') + log("--storage: expected an argument\n"); + else + break; + return (0); + break; + } + } + + /* get non-option arguments (subcommand and parameters) */ + int aac = ac - optind; + char **aav = &av[optind]; + + /* get subcommand and things to check */ + char fpmode[2] = " "; + args->localpath = NULL; + /* - all subcommands - */ + if (!aac || !strcmp(aav[0], "help")) { + put_main_help(); + return (0); + } else if (!strcmp(aav[0], "version")) { + puts(version_message); + return (0); + } else if (!strcmp(aav[0], "list-devices")) { + if (help || aac > 1) puts(help_listcom); + else list_devices(); + return (0); + } else if (!strcmp(aav[0], "info")) { + sub_init(info, 0) + } else if (!strcmp(aav[0], "list") || !strcmp(aav[0], "ls")) { + sub_init(list, 0) + } else if (!strcmp(aav[0], "reset")) { + sub_init(reset, 0) + } else if (!strcmp(aav[0], "optimize")) { + sub_init(optimize, 0) + } else if (!strcmp(aav[0], "send")) { + sub_init(send, 1) + + /* put arguments to check */ + fpmode[0] = 'r'; + args->localpath = aav[1]; + args->dirname = s_dir ? s_dir : NULL; + if (s_out) args->filename = s_out; + else { + char *rs = strrchr(args->localpath, '/'); + args->filename = rs ? rs + 1 : args->localpath; + } + } else if (!strcmp(aav[0], "get")) { + sub_init(get, 1) + + /* put arguments to check */ + fpmode[0] = 'w'; + args->filename = aav[1]; + args->dirname = s_dir; + args->localpath = s_out ? s_out : args->filename; + } else if (!strcmp(aav[0], "copy")) { + sub_init(copy, 2) + + /* get filename */ + args->filename = aav[1]; + args->dirname = s_dir; + args->newname = aav[2]; + args->newdir = s_todir; + } else if (!strcmp(aav[0], "del") || !strcmp(aav[0], "delete")) { + sub_init(del, 1) + + /* get filename */ + args->filename = aav[1]; + args->dirname = s_dir; + } else if (!strcmp(aav[0], "idle") || !strcmp(aav[0], "laze")) { + sub_init(idle, 0) + } else if (!strcmp(aav[0], "unlock")) { + sub_init(unlock, 0) + } else { + /* unknown subcommand ! */ + log("Unknown subcommand '%s'.\n", aav[0]); + return (0); + } + + /* check string lengths */ + int noerror = 0; + if (args->filename && strnlen(args->filename, 13) == 13) + log("On-calc filename must have 12 chars or less!\n"); + else if (args->newname && strnlen(args->newname, 13) == 13) + log("Destination filename must have 12 chars or less!\n"); + else if (args->dirname && strnlen(args->dirname, 9) == 9) + log("On-calc directory name must have 8 chars or less!\n"); + else if (args->newdir && strnlen(args->newdir, 9) == 9) + log("Destination directory name must have 8 chars or less!\n"); + else if (strnlen(args->storage, 5) != 4) + log("Storage device (%s) should be 4 chars long!\n", args->storage); + else + noerror = 1; + if (!noerror) return (0); + + /* use serial settings */ + if (s_use) { + if (args->com) args->use = &args->_use; + if (casio_make_attrs(&args->_use, s_use)) { + log("--use: invalid format!\n"); + log("--use: expected , " + "e.g. 9600N2 or 115200E1!\n"); + return (0); + } + } + + /* set serial settings */ + if (rst) + args->do_the_set = 1; + else if (s_set) { + args->do_the_set = 1; + if (args->com) args->set = &args->_set; + if (casio_make_attrs(&args->_set, s_set)) { + log("--set: invalid format!\n"); + log("--set: expected , " + "e.g. 9600N2 or 115200E1!\n"); + return (0); + } + } + + /* check local path */ + if (args->localpath) { + if (fpmode[0] == 'w' && !strcmp(args->localpath, "-")) + args->local = stdout; + else if (!(args->local = fopen(args->localpath, fpmode))) { + log("Could not open local file : %s\n", strerror(errno)); + if (fpmode[0] == 'w') + remove(args->localpath); + return (0); + } + } + + /* set the log level */ + if (s_log) casio_setlog(s_log); + + /* everything went well */ + return (1); +} diff --git a/src/p7/dump.c b/src/p7/dump.c new file mode 100644 index 0000000..7345108 --- /dev/null +++ b/src/p7/dump.c @@ -0,0 +1,94 @@ +/* ***************************************************************************** + * p7/dump.c -- p7 information dumping utility. + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#define numformat "%lu" +#define addrformat "0x%08lX" + +/** + * dump: + * Dump calculator information. + * + * @arg handle the libp7 handle + * @return the error code (0 if ok). + */ + +int dump(casio_link_t *handle) +{ + /* get server info */ + const casio_link_info_t *info = casio_get_link_info(handle); + + /* Wiped out things */ + if (info->casio_link_info_wiped & casio_link_info_wiped_preprog) + log("Warning: Preprogrammed ROM information looks wiped out!\n"); + if (info->casio_link_info_wiped & casio_link_info_wiped_bootcode) + log("Warning: Bootcode information looks wiped out!\n"); + if (info->casio_link_info_wiped & casio_link_info_wiped_os) + log("Warning: OS information looks wiped out!\n"); + if (!info->casio_link_info_username[0]) + log("Warning: Username is not set.\n"); + + /* main information */ + printf("CPU ID (probably out of date): %s\n", info->casio_link_info_cpuid); + printf("Environnement ID: %s\n", info->casio_link_info_hwid); + printf("Product ID: %s\n", info->casio_link_info_product_id); + + /* Preprogrammed ROM */ + if (~info->casio_link_info_wiped & casio_link_info_wiped_preprog) { + printf("Preprogrammed ROM version: %02u.%02u", + info->casio_link_info_rom_version.casio_version_major, + info->casio_link_info_rom_version.casio_version_minor); + printf("\nPreprogrammed ROM capacity: " numformat "o\n", + info->casio_link_info_rom_capacity); + } + + /* ROM and RAM */ + printf("ROM capacity: " numformat "KiB\n", + info->casio_link_info_flash_rom_capacity / 1024); + printf("RAM capacity: " numformat "KiB\n", + info->casio_link_info_ram_capacity / 1024); + + /* Bootcode */ + if (~info->casio_link_info_wiped & casio_link_info_wiped_bootcode) { + printf("Bootcode version: %02u.%02u", + info->casio_link_info_bootcode_version.casio_version_major, + info->casio_link_info_bootcode_version.casio_version_minor); + printf("\nBootcode offset: " addrformat "\n", + info->casio_link_info_bootcode_offset); + printf("Bootcode size: " numformat "KiB\n", + info->casio_link_info_bootcode_size / 1024); + } + + /* OS */ + if (~info->casio_link_info_wiped & casio_link_info_wiped_os) { + printf("OS version: %02u.%02u", + info->casio_link_info_os_version.casio_version_major, + info->casio_link_info_os_version.casio_version_minor); + printf("\nOS offset: " addrformat "\n", + info->casio_link_info_os_offset); + printf("OS size: " numformat "KiB\n", + info->casio_link_info_os_size / 1024); + } + + /* Miscallenous information */ + if (info->casio_link_info_username[0]) + printf("Username: %s\n", info->casio_link_info_username); + + return (0); +} diff --git a/src/p7/list_devices.c b/src/p7/list_devices.c new file mode 100644 index 0000000..fa6adbc --- /dev/null +++ b/src/p7/list_devices.c @@ -0,0 +1,53 @@ +/* ***************************************************************************** + * p7/list_devices.c -- p7 device listing functions. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" + +/** + * list_a_device: + * List one serial device. + * + * @arg cookie the cookie (unused) + * @arg path the path. + */ + +static int initialized = 0; +static void list_a_device(void *cookie, const char *path) +{ + (void)cookie; + if (!initialized) { + printf("Available devices:\n"); + initialized = 1; + } + printf("- %s\n", path); +} + +/** + * list_devices: + * List serial devices. + * + * @return the program return code. + */ + +int list_devices(void) +{ + casio_comlist(list_a_device, NULL); + if (!initialized) + fprintf(stderr, "Could not find any devices.\n"); + return (0); +} diff --git a/src/p7/main.c b/src/p7/main.c new file mode 100644 index 0000000..e9aedfd --- /dev/null +++ b/src/p7/main.c @@ -0,0 +1,354 @@ +/* ***************************************************************************** + * p7/main.c -- p7 main source. + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#include + +/* ************************************************************************** */ +/* Error messages */ +/* ************************************************************************** */ +/* Couldn't initialize connexion with the calculator. */ +static const char error_noconnexion[] = +"Could not connect to the calculator.\n" +"- Is it plugged in and in receive mode?\n" +"- Have you tried changing the cable?\n"; + +/* Calculator was disconnected. */ +static const char error_disconnected[] = +"Lost connexion to the calculator!\n" +"Please reconnect the calculator, rerun receive mode and try again.\n"; + +/* Calculator was found but program wasn't allowed to communicate with it. */ +static const char error_noaccess[] = +"Could not get access to the calculator.\n" +"Install the appropriate udev rule, or run as root.\n"; + +/* Command was unsupported. */ +static const char error_unsupported[] = +"The command is unsupported by the calculator.\n" +"- Does the calculator have mass storage?\n" +"- Does its OS allow the use of it?\n" +"- Is it in Receive Mode (and not in OS Update)?\n"; + +/* The device didn't exist. */ +static const char error_unsupported_device[] = +"Device '%s' is not supported by the device.\n"; + +/* The calculator acted in an unplanned way. */ +static const char error_unplanned[] = +"The calculator didn't act as planned.\n" +"Stop receive mode on calculator and start it again before re-running " \ + QUOTE(BIN) ".\n" +"Error was: %s\n"; + +/* Requested file didn't exist. */ +static const char error_noexists[] = +"Requested file didn't exist.\n"; + +/* Sent file cannot be empty. */ +static const char error_empty[] = +"Can't send an empty file!\n"; + +/* Not enough space left on the calculator. */ +static const char error_nospace[] = +"Not enough space on the calculator for the file you're trying to send.\n" +"If you believe there should be, try optimizing (OPT) on the calculator\n" +"(in MEMORY menu) and try again.\n"; + +/* ************************************************************************** */ +/* Auxiliary functions */ +/* ************************************************************************** */ +/** + * sendfile_confirm: + * Confirm file sending. + * + * @return if the file overwriting is confirmed + */ + +static int sendfile_confirm(void) +{ + char line[10]; + + /* Print stuff */ + printf("It looks like the file already exists on the calculator.\n"); + printf("Overwrite ? ([n]/y) "); + + /* Get the line */ + if (!fgets(line, 10, stdin)) + return (0); + + /* Check if should overwrite */ + return (*line == 'y'); +} + +/** + * sendfile_display: + * File sending nice display. + * + * "Initialization" is when id > total (called in main). + * + * @arg id data packet ID + * @arg total total number of data packets + */ + +static int sendfile_display_initialized = 0; +static void sendfile_display(unsigned int id, unsigned int total) +{ + /* here's the buffer */ + static char buf[50] = + "\r|---------------------------------------| 00.00%"; + static char *bar = &buf[2]; + + /* initialize */ + static int pos; + + /* if is initialize, fill */ + if (id > total) { + pos = 0; + /* indicate that is has been initialized */ + sendfile_display_initialized = 1; + /* put initial buffer */ + fputs(buf, stdout); + /* we're done */ + return ; + } + + /* modify buffer */ + /* - # - */ + int current = 38 * id / total; + while (pos <= current) bar[pos++] = '#'; + /* - % - */ + unsigned int percent = 10000 * id / total; + sprintf(&buf[43], "%02u.%02u", (percent / 100) % 100, percent % 100); + + /* put it */ + fputs(buf, stdout); + fflush(stdout); +} + +/** + * print_file_info: + * File listing callback. + * + * @arg cookie (unused) + * @arg dir the directory in which the file is stored (NULL if root) + * @arg name the filename + * @arg size the filesize + */ + +static void print_file_info(void *cookie, const char *dir, const char *name, + unsigned long size) +{ + (void)cookie; + /* initialize buffer */ + static char buf[45]; + + /* clean buffer */ + memset(buf, ' ', 28); + /* put path in buffer */ + char *b = buf; + if (dir) b += sprintf(b, "%s/", dir); + if (name) b[sprintf(b, "%s", name)] = ' '; + /* put size */ + sprintf(&buf[28], "%10uo", (unsigned)size); + + /* put the string */ + puts(buf); +} +/* ************************************************************************** */ +/* Main function */ +/* ************************************************************************** */ +/** + * main: + * User entry point of the program. + * + * @arg ac arguments count + * @arg av arguments values + * @return return code (0 if ok) + */ + +int main(int ac, char **av) +{ + int err = 0; args_t args; + casio_link_t *handle = NULL; + casio_fs_t *fs = NULL; + + /* Parse args */ + if (!parse_args(ac, av, &args)) + return (0); + + /* Initialize the link */ + if (args.com) + err = casio_open_com(&handle, args.initflags, args.com, args.use); + else + err = casio_open_usb(&handle, args.initflags); + if (err) { + /* display error */ + switch (err) { + case casio_error_nocalc: + log(error_noconnexion); + break; + case casio_error_noaccess: + log(error_noaccess); + break; + default: + log(error_unplanned, casio_strerror(err)); + break; + } + + /* closing, removing if necessary */ + if (args.menu == mn_send) + fclose(args.local); + if (args.menu == mn_get && args.local != stdout) { + fclose(args.local); + remove(args.localpath); + } + return (1); + } + + /* Change speed, and things */ + if (args.do_the_set) { + err = casio_setlink(handle, args.set); + if (err) + goto fail; + } + + /* Check according to menu */ + switch (args.menu) { +#if 0 + case mn_send: + /* get file size */ + fseek(args.local, 0, SEEK_END); + casio_off_t filesize = (casio_off_t)ftell(args.local); + rewind(args.local); + + /* get capacity */ + unsigned long capacity; + err = casio_getfreemem(handle, args.storage, &capacity); + if (err) break; + + /* optimize if required */ + if (filesize > (casio_off_t)capacity) { + printf("Not enough space on the device. Let's optimize!\n"); + err = casio_optimize(handle, args.storage); + if (err) break; + } + + /* send the file */ + err = casio_sendfile(handle, args.local, + args.dirname, args.filename, + args.storage, 1, args.force ? NULL : &sendfile_confirm, + args.nicedisp ? &sendfile_display : NULL); + break; + case mn_get: + err = casio_reqfile(handle, args.local, + args.dirname, args.filename, + args.storage, args.nicedisp && args.local != stdout + ? &sendfile_display : NULL); + break; + case mn_copy: + err = casio_copy(handle, args.dirname, args.filename, + args.newdir, args.newname, args.storage); + break; + case mn_del: + err = casio_delete(handle, args.dirname, args.filename, + args.storage); + break; + case mn_list: + err = casio_list(handle, args.storage, &print_file_info, NULL); + break; + case mn_reset: + err = casio_reset(handle, args.storage); + break; +#endif + case mn_optimize: + if ((err = casio_open_seven_fs(&fs, handle)) + || (err = casio_optimize(fs, args.storage))) + break; + + casio_close_fs(fs); + fs = NULL; + break; + + case mn_info: + err = dump(handle); + break; + + case mn_idle: + break; /* time! */ + + case mn_unlock: + break; /* dance! */ + + default: + fprintf(stderr, "Unhandled yet.\n"); + break; + } + + /* put error */ + if (err && err != casio_error_noow) + goto fail; + + if (sendfile_display_initialized) + puts("\b\b\b\b\b\bTransfer complete."); + if (args.local && args.local != stdout) fclose(args.local); + + /* terminate communication and de-initialize link handle */ + casio_close_fs(fs); + casio_close_link(handle); + handle = NULL; + + /* Then we're good */ + return (0); +fail: + if (sendfile_display_initialized) + puts("\b\b\b\b\b\bError !"); + + /* close the file */ + if (args.local && args.local != stdout) fclose(args.local); + if (args.menu == mn_get && args.local != stdout) + remove(args.localpath); + + /* put the error string */ + switch (err) { + case casio_error_fullmem: + log(error_nospace); break; + case casio_error_empty: + log(error_empty); break; + case casio_error_notfound: + log(error_noexists); break; + case casio_error_nocalc: + log(error_disconnected); break; +#if 0 + case casio_error_unsupported: + log(error_unsupported); break; + case casio_error_unsupported_device: + log(error_unsupported_device, args.storage); break; +#endif + default: log(error_unplanned, casio_strerror(err)); + } + + /* that doesn't mean you shouldn't exit, heh. */ + casio_close_fs(fs); + casio_close_link(handle); + handle = NULL; + + /* then go away */ + return (1); +} diff --git a/src/p7/main.h b/src/p7/main.h new file mode 100644 index 0000000..3ab4d24 --- /dev/null +++ b/src/p7/main.h @@ -0,0 +1,63 @@ +/* ***************************************************************************** + * p7/main.h -- p7 main header. + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#ifndef MAIN_H +# define MAIN_H +# define Q(x) #x +# define QUOTE(x) Q(x) +# include +# include +# define log(S, ...) fprintf(stderr, S, ##__VA_ARGS__) + +/* Menus */ +typedef enum { + mn_send, mn_get, mn_copy, mn_del, mn_list, mn_reset, + mn_optimize, mn_info, mn_idle, mn_unlock +} menu_t; + +/* Arguments */ +typedef struct { + /* basic things */ + menu_t menu; int nicedisp; + + /* libp7 settings */ + unsigned int initflags; + casio_streamattrs_t *use, _use; + casio_streamattrs_t *set, _set; + int do_the_set; + + /* for file transferring menus */ + const char *dirname, *filename; + const char *newdir, *newname; + FILE *local; const char *localpath; + int force; + + /* other options */ + const char *com, *storage; +} args_t; + +/* Parsing function */ +int parse_args(int ac, char **av, args_t *args); + +/* List devices function */ +int list_devices(void); + +/* Dumping function */ +int dump(casio_link_t *handle); + +#endif /* MAIN_H */ diff --git a/src/p7/vars.mk b/src/p7/vars.mk new file mode 100755 index 0000000..372e49b --- /dev/null +++ b/src/p7/vars.mk @@ -0,0 +1,3 @@ +#!/usr/bin/make -f +libs: + @echo libcasio diff --git a/src/p7os/args.c b/src/p7os/args.c new file mode 100644 index 0000000..9c6f50c --- /dev/null +++ b/src/p7os/args.c @@ -0,0 +1,311 @@ +/* **************************************************************************** + * p7os/args.c -- p7os command-line arguments parsing utility. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************* */ +#include "main.h" +#include +#include +#include +#include +#include + +/* ************************************************************************* */ +/* Help and version messages */ +/* ************************************************************************* */ +/* The version message - that's when the President comes in */ +static const char version_message[] = +QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n" +"Maintained by " QUOTE(MAINTAINER) ".\n" +"\n" +"This is free software; see the source for copying conditions.\n" +"There is NO warranty; not even for MERCHANTABILITY or\n" +"FITNESS FOR A PARTICULAR PURPOSE."; + +/* Main help message */ +static const char help_main0[] = +"Usage: " QUOTE(BIN) " [--version|-v] [--help|-h] [--com ]\n" +" [--no-prepare] [--uexe ]\n" +" [options...]\n" +"\n" +"Subcommands you can use are :\n" +" prepare-only Set-up the update program, but leave it for other programs\n" +" to interact with it.\n" +" get Get the OS image.\n" +" flash Flash the OS image.\n" +"\n" +"General options:\n" +" -h, --help Display the help page of the (sub)command and quit.\n" +" -v, --version Display the version message and quit.\n"; + +static const char help_log[] = +" --log The library log level (default: %s).\n" +" One of: %s"; + +static const char help_main1[] = +" --com The serial device, if you want to communicate with a\n" +" calculator connected using a USB-to-serial cable.\n" +" If this option isn't used, the program will look for a\n" +" calculator connected using direct USB.\n" +" --no-prepare Use the current environment, instead of uploading one.\n" +" -u, --uexe Use a custom update program.\n" +" If `--no-prepare` is not given, this option is required.\n" +"\n" +"Type \"" QUOTE(BIN) " --help\" for some help about a subcommand.\n" +"Report bugs to " QUOTE(MAINTAINER) "."; + +/* Subcommands help messages footer */ +#define FOOT \ + "\nType \"" QUOTE(BIN) " --help\" for other subcommands and general options." + +/* Help message for prepare subcommand */ +static const char help_prepare_only[] = +"Usage: " QUOTE(BIN) " prepare-only\n" +"Send the P7 server on the calculator for further operations.\n" +"This must be used before any other p7os operation.\n" +FOOT; + +/* Help message for get subcommand */ +static const char help_get[] = +"Usage: " QUOTE(BIN) " get [-o ]\n" +"Get the calculator OS image.\n" +"\n" +"Options are :\n" +" -o Where to store the image (default is \"os.bin\")\n" +FOOT; + +/* Help message for flash subcommand. */ +static const char help_flash[] = +"Usage: " QUOTE(BIN) " flash \n" +"Flash the calculator's OS image.\n" +FOOT; +/* ************************************************************************* */ +/* Main help message. */ +/* ************************************************************************* */ +/** + * put_loglevel: + * Put a loglevel (for listing). + * + * @arg first the first log level. + * @arg level the level string. + */ + +static void put_loglevel(char **first, const char *level) +{ + if (!*first) { + *first = malloc(strlen(level) + 2); + if (!*first) return ; + strcpy(*first + 1, level); + **first = 'F'; + return ; + } + + if (**first == 'F') { + printf(help_log, casio_getlog(), *first + 1); + **first = 'N'; + } + + printf(", %s", level); +} + +/** + * put_help: + * Put the main help message. + */ + +static void put_help(void) +{ + char *first; + + /* first big part */ + fputs(help_main0, stdout); + + /* loglevels */ + first = NULL; + casio_listlog((casio_log_list_t*)&put_loglevel, (void*)&first); + if (first && *first == 'N') fputc('\n', stdout); + free(first); + + /* second big part */ + puts(help_main1); +} +/* ************************************************************************* */ +/* Main function */ +/* ************************************************************************* */ +/* Help macro */ +#define sub_init(CMD, NARGS) { \ + args->menu = mn_##CMD; \ + if (help || pc != (NARGS)) { \ + puts(help_##CMD); \ + return (1); \ + }} + +/* Options. */ +static const char shopts[] = "hvu:o:#"; +static const struct option longopts[] = { + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {"com", required_argument, NULL, 'c'}, + {"no-prepare", no_argument, NULL, 'n'}, + {"uexe", required_argument, NULL, 'u'}, + {"output", required_argument, NULL, 'o'}, + {"log", required_argument, NULL, 'l'}, + {NULL, 0, NULL, 0} +}; + +/** + * parse_args: + * Args parsing main function. + * + * Based on my very first experiment with getopt. + * + * @arg ac the arguments count + * @arg av the arguments values + * @arg args the parsed args pointer + * @return if has been parsed successfully + */ + +int parse_args(int ac, char **av, args_t *args) +{ + int c, help = 0, version = 0; + const char *s_out = "os.bin", *s_uexe = NULL, *s_log = NULL; + + /* Initialize the arguments. */ + memset(args, 0, sizeof(*args)); + + /* get all options */ + opterr = 0; + while (1) { + c = getopt_long(ac, av, shopts, longopts, NULL); + if (c < 0) break; + + switch (c) { + case 'h': help = 1; break; + case 'v': version = 1; break; + + /* COM port, should prepare or not */ + case 'c': args->com = optarg; break; + case 'n': args->noprepare = 1; break; + + /* log level, Update.Exe, output path */ + case 'l': s_log = optarg; break; + case 'u': s_uexe = optarg; break; + case 'o': s_out = optarg; break; + + /* error */ + case '?': + if (optopt == 'o') + log("-o, --output: expected an argument\n"); + else if (optopt == 'c') + log("--com: expected an argument\n"); + else if (optopt == 'u') + log("-u, --uexe: expected an argument\n"); + else + break; + return (1); + } + } + + /* check for version */ + if (version) { + puts(version_message); + return (1); + } + + /* get non-option arguments (subcommand and parameters) */ + int pc = ac - optind; + char **pv = &av[optind]; + char *sub = pc ? pv[0] : NULL; + pc--; pv++; + + /* subcommand. */ + char fpmode[3] = "r\0"; + if (!sub || !strcmp(sub, "help")) { + put_help(); + return (1); + } else if (!strcmp(sub, "version")) { + puts(version_message); + return (1); + + } else if (!strcmp(sub, "prepare-only")) { + sub_init(prepare_only, 0) + + if (args->noprepare) { + log("So we should prepare but we should not prepare? Duh!\n"); + return (1); + } + } else if (!strcmp(sub, "get")) { + sub_init(get, 0) + args->localpath = s_out; + fpmode[0] = 'w'; + } else if (!strcmp(sub, "flash")) { + sub_init(flash, 1) + args->localpath = pv[0]; + } else { + log("Unknown subcommand '%s'.\n", sub); + return (1); + } + + /* open destination file */ + if (args->localpath) { + FILE *localfile = fopen(args->localpath, fpmode); + if (!localfile) { + log("Could not open local file: %s\n", strerror(errno)); + return (1); + } + + int err = casio_open_stream_file(&args->local, + fpmode[0] == 'r' ? localfile : NULL, + fpmode[0] == 'w' || fpmode[1] == '+' ? localfile : NULL, + 1, 1); + if (err) { + log("Could not make a stream out of local file: %s\n", + casio_strerror(err)); + return (1); + } + } + + /* open update.exe file */ + if (!args->noprepare) { + if (!s_uexe) { + log("One of `-u ` or `--no-prepare` is expected!\n"); + if (args->local) casio_close(args->local); + return (1); + } + + FILE *uexe = fopen(s_uexe, "r"); + if (!uexe) { + log("Could not open update program: %s\n", strerror(errno)); + if (args->local) casio_close(args->local); + return (1); + } + + int err = casio_open_stream_file(&args->uexe, + uexe, NULL, 1, 0); + if (err) { + log("Could not make a stream out of the update.exe: %s\n", + casio_strerror(err)); + if (args->local) casio_close(args->local); + return (1); + } + } + + /* set the log level */ + if (s_log) casio_setlog(s_log); + + /* everything went well :) */ + return (0); +} diff --git a/src/p7os/main.c b/src/p7os/main.c new file mode 100644 index 0000000..be65889 --- /dev/null +++ b/src/p7os/main.c @@ -0,0 +1,101 @@ +/* **************************************************************************** + * p7os/main.c -- p7os main source. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************* */ +#include "main.h" + +/* Couldn't initialize connexion to calculator. */ +static const char error_noconnexion[] = +"Could not connect to the calculator.\n" +"- Is it plugged in and in Receive mode/OS Update?\n" +"- Have you tried changing the cable ?\n"; + +/* Calculator was found but program wasn't allowed to communicate with it. */ +static const char error_noaccess[] = +"Could not get access to the calculator.\n" +"Install the appropriate udev rule, or run as root.\n"; + +/* The calculator acted in a weird way. */ +static const char error_unplanned[] = +"The calculator didn't act as planned: %s.\n" +"Stop receive mode on calculator and start it again before re-running " \ + QUOTE(BIN) ".\n"; + +/* Unsupported operation -> OS Update, not receive mode! */ +static const char error_unsupported[] = +"Required operation was unsupported by the calculator.\n" +"If you did not prepare, perhaps you should prepare?\n"; + +/** + * main: + * User entry point of the program. + * + * @arg ac arguments count + * @arg av arguments values + * @return return code (0 if OK) + */ + +int main(int ac, char **av) +{ + int err; args_t args; + + /* parse args */ + if (parse_args(ac, av, &args)) + return (0); + + /* prepare */ + if (!args.noprepare) { + err = prepare(&args); + if (err) goto fail; + } + + /* check according to menu */ + switch (args.menu) { + case mn_prepare_only: break; + case mn_get: + err = backup_rom(&args); break; + case mn_flash: +#if 0 + err = fxremote_flash(&args); break; +#endif + fprintf(stderr, + "fxRemote-like flashing has been removed.\n" + "Sorry for the inconvenience.\n"); + err = 0; break; + } + +fail: + /* close the file, remove if necessary */ + if (args.localpath) { + casio_close(args.local); + if (err && casio_iswritable(args.local)) + remove(args.localpath); + } + + /* displaying error */ + if (err) switch (err) { + case casio_error_nocalc: + log(error_noconnexion); break; + case casio_error_noaccess: + log(error_noaccess); break; + case casio_error_command: + log(error_unsupported); break; + default: log(error_unplanned, casio_strerror(err)); + } + + return (1); +} diff --git a/src/p7os/main.h b/src/p7os/main.h new file mode 100644 index 0000000..f0f25dc --- /dev/null +++ b/src/p7os/main.h @@ -0,0 +1,79 @@ +/* ***************************************************************************** + * p7os/main.h -- p7os main header. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#ifndef MAIN_H +# define MAIN_H +# include +# include +# define Q(x) #x +# define QUOTE(x) Q(x) +# define log(S, ...) fprintf(stderr, S, ##__VA_ARGS__) + +/* ************************************************************************** */ +/* CLI options */ +/* ************************************************************************** */ +/* Menu */ +enum menu_e { + mn_prepare_only = 1, + mn_get = 2, + mn_flash = 3 +}; + +/* Arguments */ +typedef struct { + enum menu_e menu; + int noprepare; + + /* communication and tweaks */ + const char *com; + + /* others */ + casio_stream_t *local; + const char *localpath; + casio_stream_t *uexe; +} args_t; +/* ************************************************************************* */ +/* Progress displayer */ +/* ************************************************************************* */ +typedef struct { + const char *msg, *success; + + char buf[50], *bar; + int init, pos; +} osdisp_t; + +extern void osdisp_init(osdisp_t *cookie, const char *init, + const char *success); +extern void osdisp(void *cookie, unsigned int id, unsigned int total); + +extern void osdisp_interrupt(osdisp_t *cookie); +extern void osdisp_success(osdisp_t *cookie); +/* ************************************************************************* */ +/* Central functions */ +/* ************************************************************************* */ +/* Utilities. */ +extern int parse_args(int ac, char **av, args_t *args); +extern int open_link(casio_link_t **link, args_t *args, + unsigned long flags, casio_streamattrs_t *attrs); + +/* Main functions. */ +extern int prepare(args_t *args); +extern int backup_rom(args_t *args); +extern int fxremote_flash(args_t *args); + +#endif /* MAIN_H */ diff --git a/src/p7os/procs/std_backup.c b/src/p7os/procs/std_backup.c new file mode 100644 index 0000000..4be913d --- /dev/null +++ b/src/p7os/procs/std_backup.c @@ -0,0 +1,50 @@ +/* **************************************************************************** + * p7os/procs/std_backup.c -- backup the ROM. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************* */ +#include "../main.h" + +/** + * backup_rom: + * Backup the ROM. + * + * @arg args the CLI args. + * @return the error code (0 if ok). + */ + +int backup_rom(args_t *args) +{ + int err; casio_link_t *link = NULL; + osdisp_t osdisp_cookie; + + /* Open the link. */ + err = open_link(&link, args, + CASIO_LINKFLAG_ACTIVE | CASIO_LINKFLAG_CHECK | CASIO_LINKFLAG_TERM, + NULL); + if (err) return (err); + + /* Use the "standard" way. */ + osdisp_init(&osdisp_cookie, "Gathering the OS...", "Backed up!"); + err = casio_backup_rom(link, args->local, osdisp, &osdisp_cookie); + if (err) { osdisp_interrupt(&osdisp_cookie); goto fail; } + osdisp_success(&osdisp_cookie); + + err = 0; +fail: + casio_close_link(link); + return (err); +} diff --git a/src/p7os/procs/std_prepare.c b/src/p7os/procs/std_prepare.c new file mode 100644 index 0000000..6663169 --- /dev/null +++ b/src/p7os/procs/std_prepare.c @@ -0,0 +1,65 @@ +/* **************************************************************************** + * p7os/procs/std_prepare.c -- upload and run the update.exe. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************* */ +#include "../main.h" + +/** + * prepare: + * Upload and run the given update.exe. + * + * @arg args the command-line arguments. + * @return the error code (0 if ok). + */ + +int prepare(args_t *args) +{ + int err; casio_link_t *link = NULL; + osdisp_t osdisp_cookie; + casio_off_t usize; + + /* Get the update.exe size. */ + err = casio_getsize(args->uexe, &usize); + if (err) return (err); + + /* Open the link. */ + err = open_link(&link, args, + CASIO_LINKFLAG_ACTIVE | CASIO_LINKFLAG_CHECK, NULL); + if (err) goto fail; + + /* Upload and run. */ + osdisp_init(&osdisp_cookie, "Uploading the Update.Exe...", "Uploaded!"); + err = casio_upload_and_run(link, args->uexe, usize, + 0x88024000, 0x88024000, osdisp, &osdisp_cookie); + if (err) { + /* interrupt loading bar */ + osdisp_interrupt(&osdisp_cookie); + goto fail; + } + osdisp_success(&osdisp_cookie); + + /* Sleep while the software on the calculator sets up the + * communication interface. */ + printf("Waiting for the Update.Exe to set up the communication...\n"); + casio_sleep(1000); + + err = 0; +fail: + if (link) casio_close_link(link); + casio_close(args->uexe); + return (err); +} diff --git a/src/p7os/utils/open_link.c b/src/p7os/utils/open_link.c new file mode 100644 index 0000000..4002adb --- /dev/null +++ b/src/p7os/utils/open_link.c @@ -0,0 +1,44 @@ +/* **************************************************************************** + * p7os/utils/open_link.c -- open the link based on cli arguments and other stuff. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************* */ +#include "../main.h" + +/** + * open_link: + * Open the link using the arguments. + * + * @arg link the link to open. + * @arg args the command-line arguments. + * @arg flags the required flags. + * @arg attrs the serial attributes. + * @return the error code (0 if ok). + */ + +int open_link(casio_link_t **link, args_t *args, + unsigned long flags, casio_streamattrs_t *attrs) +{ + int err; + + /* Open the link. */ + if (args->com) err = casio_open_com(link, flags, args->com, attrs); + else err = casio_open_usb(link, flags); + if (err) return (err); + + /* XXX: `--set`, `--use`? */ + return (0); +} diff --git a/src/p7os/utils/osdisp.c b/src/p7os/utils/osdisp.c new file mode 100644 index 0000000..ee13f7d --- /dev/null +++ b/src/p7os/utils/osdisp.c @@ -0,0 +1,120 @@ +/* **************************************************************************** + * p7os/utils/osdisp.c -- progress displayer. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************* */ +#include "../main.h" +#include + +/* ************************************************************************* */ +/* Main function */ +/* ************************************************************************* */ +/** + * osdisp: + * Nice little loading bar. + * + * Taken from `src/p7/main.c`. + * "Initialization" is when id > total (called in main). + * + * @arg id data packet ID. + * @arg total total number of packets. + */ + +void osdisp(void *vcookie, unsigned int id, unsigned int total) +{ + osdisp_t *cookie = (void*)vcookie; + int current; unsigned int percent; + + /* if is initialize, fill */ + if (id > total) { + /* initialize */ + strcpy(cookie->buf, + "\r|---------------------------------------| 00.00%"); + cookie->bar = &cookie->buf[2]; + cookie->pos = 0; + cookie->init = 1; + + /* put message and initial buffer. */ + printf("%s\n%s", cookie->msg, cookie->buf); + + /* save cursor position and we're done */ + fputs("\x1B[s", stdout); + return ; + } + + /* id and total start from 1, let them start from zero */ + id--; total--; + + /* modify buffer */ + /* - # - */ + current = 38 * id / total; + while (cookie->pos <= current) cookie->bar[cookie->pos++] = '#'; + /* - % - */ + percent = 10000 * id / total; + sprintf(&cookie->buf[43], "%02u.%02u", + percent / 100 % 100, percent % 100); + + /* put it */ + printf("%s", cookie->buf); + /* force cursor position */ + fputs("\x1B""8", stdout); + fflush(stdout); +} +/* ************************************************************************* */ +/* Initialization, miscallaneous actions */ +/* ************************************************************************* */ +/** + * osdisp_init: + * Initialize a display cookie. + * + * @arg cookie the display cookie to initialize. + * @arg init the initial message. + * @arg success the success message. + */ + +void osdisp_init(osdisp_t *cookie, const char *init, const char *success) +{ + cookie->msg = init; + cookie->success = success; + cookie->init = 0; + cookie->pos = 0; +} + +/** + * osdisp_interrupt: + * End with an error. + * + * @arg cookie the display cookie. + */ + +void osdisp_interrupt(osdisp_t *cookie) +{ + /* interrupt loading bar */ + if (cookie->init) + printf("\b\b\b\b\b\bError!\n"); +} + +/** + * osdisp_success: + * End with a success. + * + * @arg cookie the display cookie. + */ + +void osdisp_success(osdisp_t *cookie) +{ + printf("\b\b\b\b\b\b%s\n", cookie->success); +} diff --git a/src/p7os/vars.mk b/src/p7os/vars.mk new file mode 100755 index 0000000..ce38114 --- /dev/null +++ b/src/p7os/vars.mk @@ -0,0 +1,4 @@ +#!/usr/bin/make -f +disable: +libs: + @echo libcasio diff --git a/src/p7screen/args.c b/src/p7screen/args.c new file mode 100644 index 0000000..d1fa30a --- /dev/null +++ b/src/p7screen/args.c @@ -0,0 +1,178 @@ +/* **************************************************************************** + * p7screen/args.c -- p7screen argument parsing. + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************* */ +#include "main.h" +#include +#include +#include + +/* ************************************************************************* */ +/* Help and version messages */ +/* ************************************************************************* */ +/* Version message */ +static const char version_message[] = +QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n" +"Maintained by " QUOTE(MAINTAINER) ".\n" +"\n" +"This is free software; see the source for copying conditions.\n" +"There is NO warranty; not even for MERCHANTABILITY or\n" +"FITNESS FOR A PARTICULAR PURPOSE."; + +/* Help message */ +static const char help_main0[] = +"Usage: " QUOTE(BIN) " [--help|-h] [--version|-v]\n" +"\n" +"Displays the streamed screen from a CASIO fx calculator.\n" +"\n" +"Options are:\n" +" -h, --help Display this help page\n" +" -v, --version Displays the version\n"; + +static const char help_log[] = +" --log The library log level (default: %s).\n" +" One of: %s"; + +static const char help_main1[] = +" -z ZOOM Change the zoom (1 to 16)\n" +" By default, the zoom will be " QUOTE(DEFAULT_ZOOM) ".\n" +"\n" +"Report bugs to " QUOTE(MAINTAINER) ".\n"; +/* ************************************************************************* */ +/* Main function */ +/* ************************************************************************* */ +/** + * put_loglevel: + * Put a loglevel (for listing). + * + * @arg first the first log level. + * @arg level the level string. + */ + +static void put_loglevel(char **first, const char *level) +{ + if (!*first) { + *first = malloc(strlen(level) + 2); + if (!*first) return ; + strcpy(*first + 1, level); + **first = 'F'; + return ; + } + + if (**first == 'F') { + printf(help_log, casio_getlog(), *first + 1); + **first = 'N'; + } + + printf(", %s", level); +} + +/** + * put_help: + * Put the help message. + */ + +static void put_help(void) +{ + char *first; + + /* first big part */ + fputs(help_main0, stdout); + + /* loglevels */ + first = NULL; + casio_listlog((casio_log_list_t*)&put_loglevel, (void*)&first); + if (first && *first == 'N') fputc('\n', stdout); + free(first); + + /* second big part */ + fputs(help_main1, stdout); +} + +/** + * parse_args: + * Args parsing main function. + * + * Inspired of the edits of my first experiment with getopt. + * Interesting, huh? + * + * @arg ac the arguments count + * @arg av the arguments values + * @arg zoom pointer the zoom + * @return 0 if ok, other if not. + */ + +int parse_args(int ac, char **av, int *zoom) +{ + /* initialize args */ + *zoom = DEFAULT_ZOOM; + + /* define options */ + const char short_options[] = "hvz:"; + const struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {"zoom", required_argument, NULL, 'z'}, + {"log", required_argument, NULL, 'l'}, + {NULL, 0, NULL, 0} + }; + + /* get all options */ + int c; opterr = 0; + int help = 0, version = 0; + const char *s_log = NULL; + while ((c = getopt_long(ac, av, short_options, long_options, NULL)) != -1) + switch (c) { + /* help */ + case 'h': help = 1; break; + /* version */ + case 'v': version = 1; break; + /* zoom */ + case 'z': + *zoom = atoi(optarg); + if (*zoom <= 0 || *zoom > 16) { + log("-z, --zoom: should be between 1 and 16"); + return (1); + } + break; + + case 'l': + s_log = optarg; + break; + + /* error (ignore) */ + case '?': + if (optopt == 'z') + log("-z, --zoom: expected an argument\n"); + else + break; + return (1); + } + + /* check if there is any parameter */ + if (ac - optind) help = 1; + + /* set the log level */ + if (s_log) + casio_setlog(s_log); + + /* print help or version if required, and return */ + if (version) puts(version_message); + else if (help) put_help(); + else return (0); + return (1); +} diff --git a/src/p7screen/main.c b/src/p7screen/main.c new file mode 100644 index 0000000..71be816 --- /dev/null +++ b/src/p7screen/main.c @@ -0,0 +1,164 @@ +/* ***************************************************************************** + * p7screen/main.c -- p7screen main source. + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#include + +/* ************************************************************************** */ +/* Error messages */ +/* ************************************************************************** */ +/* Couldn't initialize connexion to calculator. */ +static const char error_noconnexion[] = +"Could not connect to the calculator.\n" +"- Is it plugged in and in PROJ mode?\n" +"- Have you tried unplugging, plugging and selecting Projector on pop-up?\n" +"- Have you tried changing the cable?\n"; + +/* Calculator was found but program wasn't allowed to communicate with it. */ +static const char error_noaccess[] = +"Could not get access to the calculator.\n" +"Install the appropriate udev rule, or run as root.\n"; + +/* The calculator acted in a weird way. */ +static const char error_unplanned[] = +"The calculator didn't act as planned.\n" +"Stop receive mode on calculator and start it again before re-running " \ + QUOTE(BIN) ".\n" +"Error was: %s\n"; + +/* ************************************************************************** */ +/* Globals */ +/* ************************************************************************** */ +/* The z00m (omG) */ +static int zoom; + +/* ************************************************************************** */ +/* Auxiliary functions */ +/* ************************************************************************** */ +/** + * display_callback: + * The main callback for screen streaming. + * + * @arg vcookie the cookie (unused). + * @arg w the width of the received image + * @arg h the height of the received image + * @arg pixels the image data + */ + +static void display_callback(void *vcookie, + int w, int h, casio_uint32_t **pixels) +{ + static SDL_Surface *screen = NULL; + static int saved_w = 0, saved_h = 0; + + (void)vcookie; + /* Create screen if there isn't one. */ + if (!screen || saved_w != w || saved_h != h) { + /* Create the window. */ + if (!(screen = SDL_SetVideoMode(w * zoom, h * zoom, 32, + SDL_SWSURFACE | SDL_DOUBLEBUF))) { + log("Couldn't set video mode: %s\n", SDL_GetError()); + return ; + } + SDL_WM_SetCaption("P7screen", NULL); + + /* Save data and display message. */ + saved_w = w; saved_h = h; + puts("Turn off your calculator (SHIFT+AC) when you have finished."); + } + + /* Lock the screen. */ + SDL_LockSurface(screen); + + /* Copy the data. */ + uint32_t *px = (uint32_t*)screen->pixels; + int linesize = w * zoom; + for (int y = 0; y < h; y++) { + uint32_t *refline = px; + for (int x = 0; x < w; x++) { + uint32_t pixel = pixels[y][x]; + for (int zx = 0; zx < zoom; zx++) + *px++ = pixel; + } + for (int zy = 1; zy < zoom; zy++) { + memcpy(px, refline, linesize * sizeof(uint32_t)); + px += linesize; + } + } + + /* Unlock the screen, and flippin' flip it. */ + SDL_UnlockSurface(screen); + SDL_Flip(screen); +} +/* ************************************************************************** */ +/* Main function */ +/* ************************************************************************** */ +/** + * main: + * Entry point of the program. + * + * @arg ac arguments count + * @arg av arguments values + * @return if it worked (0 if OK) + */ + +int main(int ac, char **av) +{ + int err; casio_link_t *handle = NULL; + + /* parse args */ + if (parse_args(ac, av, &zoom)) + return (0); + + /* Make the libcasio link handle. */ + if ((err = casio_open_usb(&handle, 0))) { + /* display error */ + switch (err) { + case casio_error_nocalc: log(error_noconnexion); break; + case casio_error_noaccess: log(error_noaccess); break; + default: log(error_unplanned, casio_strerror(err)); break; + } + + /* return */ + return (1); + } + + /* Initialize SDL */ + if (SDL_Init(SDL_INIT_VIDEO)) { + log("Failed to initialize SDL: %s\n", SDL_GetError()); + return (3); + } + atexit(SDL_Quit); + + /* receive screen */ + if ((err = casio_getscreen(handle, &display_callback, NULL)) + && err != casio_error_nocalc) { + switch (err) { + case casio_error_timeout: log(error_noconnexion); break; + default: log(error_unplanned, casio_strerror(err)); break; + } + return (1); + } + + /* close */ + casio_close_link(handle); + + /* everything went well */ + return (0); +} diff --git a/src/p7screen/main.h b/src/p7screen/main.h new file mode 100644 index 0000000..539d498 --- /dev/null +++ b/src/p7screen/main.h @@ -0,0 +1,32 @@ +/* ***************************************************************************** + * p7screen/main.h -- p7screen main header. + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#ifndef MAIN_H +# define MAIN_H +# include +# include +# include +# include +# define Q(x) #x +# define QUOTE(x) Q(x) +# define log(S, ...) fprintf(stderr, S, ##__VA_ARGS__) + +/* all functions */ +int parse_args(int ac, char **av, int *zoom); + +#endif /* MAIN_H */ diff --git a/src/p7screen/vars.mk b/src/p7screen/vars.mk new file mode 100755 index 0000000..c030138 --- /dev/null +++ b/src/p7screen/vars.mk @@ -0,0 +1,3 @@ +#!/usr/bin/make -f +libs: + @echo libcasio sdl diff --git a/src/p7servtest/args.c b/src/p7servtest/args.c new file mode 100644 index 0000000..e866dce --- /dev/null +++ b/src/p7servtest/args.c @@ -0,0 +1,97 @@ +/* ***************************************************************************** + * p7servtest/args.c -- p7servtest command-line argument parsing utility. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include +#define Q(x) #x +#define QUOTE(x) Q(x) + +/* ************************************************************************** */ +/* Help and version messages */ +/* ************************************************************************** */ +/* Version message */ +static const char version_message[] = +QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) + " (licensed under GPLv2)\n" +"Maintained by " QUOTE(MAINTAINER) ".\n" +"\n" +"This is free software; see the source for copying conditions.\n" +"There is NO warranty; not even for MERCHANTABILITY or\n" +"FITNESS FOR A PARTICULAR PURPOSE."; + +/* Main help message */ +static const char help_main[] = +"Usage: " QUOTE(BIN) " [--help] [--version]\n" +"\n" +"This utility is only there to test the libcasio server feature.\n" +"It should not be used in production for anything else.\n" +"\n" +"General options:\n" +" -h, --help Display the help page of the (sub)command and quit.\n" +" -v, --version Display the version message and quit.\n" +"\n" +"Report bugs to " QUOTE(MAINTAINER) "."; + +/* ************************************************************************** */ +/* Main args parsing function */ +/* ************************************************************************** */ +/** + * parse_args: + * Args parsing main function. + * + * @arg ac the arguments count. + * @arg av the arguments values. + * @return if execution should stop after this call. + */ + +int parse_args(int ac, char **av) +{ + /* define options */ + const char shopts[] = "hv"; + const struct option longopts[] = { + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {NULL, 0, NULL, 0} + }; + + /* get all options */ + int c; opterr = 0; + int help = 0, version = 0; + while ((c = getopt_long(ac, av, shopts, longopts, NULL)) >= 0) switch (c) { + case 'h': help = 1; break; + case 'v': version = 1; break; + + case '?': break; + } + + /* get parameters */ + int pc = ac - optind; + if (pc) help = 1; + + /* print help or version */ + if (help) { + puts(help_main); + return (1); + } else if (version) { + puts(version_message); + return (1); + } + + /* no problem */ + return (0); +} diff --git a/src/p7servtest/client.c b/src/p7servtest/client.c new file mode 100644 index 0000000..8d8cd80 --- /dev/null +++ b/src/p7servtest/client.c @@ -0,0 +1,51 @@ +/* ***************************************************************************** + * p7servtest/client.c -- p7servtest virtual client. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" + +int run_client(int in, int out) +{ + int err; casio_link_t *link = NULL; + casio_stream_t *stream = NULL; + + /* make the stream */ + err = casio_open_stream_fd(&stream, in, out, 1, 1); + if (err) { + fprintf(stderr, "Client stream initialization has encountered " + "an error: %s\n", casio_strerror(err)); + return (1); + } + + /* make the handle */ + err = casio_open_link(&link, + CASIO_LINKFLAG_ACTIVE | CASIO_LINKFLAG_CHECK | CASIO_LINKFLAG_TERM, + stream, NULL); + if (err) { + fprintf(stderr, "Client initialization has encountered an error: %s\n", + casio_strerror(err)); + return (1); + } + + /* change working directory. */ + casio_seven_send_cmdfls_cwd(link, "oui", "fls0"); + casio_seven_send_cmdfls_cwd(link, "non", "fls0"); + + /* we're done. */ + casio_close_link(link); + return (0); +} diff --git a/src/p7servtest/main.c b/src/p7servtest/main.c new file mode 100644 index 0000000..f0ab2bf --- /dev/null +++ b/src/p7servtest/main.c @@ -0,0 +1,82 @@ +/* ***************************************************************************** + * p7servtest/main.c -- p7servtest main source. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include + +/** + * init: + * Let's go baby. + * + * @arg sin the server input. + * @arg sout the server output. + * @arg cin the client input. + * @arg cout the client output. + */ + +static void init(int sin, int sout, int cin, int cout) +{ + /* everybody do the fork */ + pid_t pid = fork(); + if (pid == (pid_t)-1) + return ; + + /* yay */ + if (!pid) run_server(sin, sout); + else { + sleep(1); + run_client(cin, cout); + } +} + +/** + * main: + * A handful of feet. + * + * @arg ac the arguments count. + * @arg av the arguments values. + * @return the error code (0 if ok). + */ + +int main(int ac, char **av) +{ + /* parse the arguments */ + if (parse_args(ac, av)) + return (0); + + /* create the pipes */ + int fds1[2], fds2[2]; + if (pipe(fds1)) { + fprintf(stderr, + "Unable to make the first set of pipes (server to client)\n"); + return (1); + } + if (pipe(fds2)) { + fprintf(stderr, + "Unable to make the second set of pipes (client to server)\n"); + close(fds1[0]); + close(fds1[1]); + return (1); + } + + /* initialize. */ + init(fds1[0], fds2[1], fds2[0], fds1[1]); + + /* everything went well. */ + return (0); +} diff --git a/src/p7servtest/main.h b/src/p7servtest/main.h new file mode 100644 index 0000000..9196d57 --- /dev/null +++ b/src/p7servtest/main.h @@ -0,0 +1,29 @@ +/* ***************************************************************************** + * p7servtest/main.h -- p7servtest main header. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#ifndef MAIN_H +# define MAIN_H +# include +# include + +int parse_args(int ac, char **av); + +int run_server(int in, int out); +int run_client(int in, int out); + +#endif /* MAIN_H */ diff --git a/src/p7servtest/server.c b/src/p7servtest/server.c new file mode 100644 index 0000000..efa237a --- /dev/null +++ b/src/p7servtest/server.c @@ -0,0 +1,121 @@ +/* ***************************************************************************** + * p7servtest/server.c -- p7servtest virtual server. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of p7utils. + * p7utils is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2.0 of the License, + * or (at your option) any later version. + * + * p7utils 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with p7utils; if not, see . + * ************************************************************************** */ +#include "main.h" +#include + +/* ************************************************************************** */ +/* Server callbacks */ +/* ************************************************************************** */ +/** + * directory_exists: + * Check if a directory exists. + * + * @arg cookie the cookie. + * @arg dirname the directory. + * @arg devname the devname. + * @return the error (0 if ok). + */ + +static int directory_exists(void *cookie, const char *dirname) +{ + (void)cookie; + + /* check directory name */ + if (!strcmp(dirname, "oui")) + return (0); + else return (casio_error_notfound); +} +/* ************************************************************************** */ +/* Server configuration */ +/* ************************************************************************** */ +/* the server information */ +static casio_link_info_t server_information = { + /* main calculator information */ + .casio_link_info_cpuid = "The CPU ID, wow!", + .casio_link_info_hwid = "TESTSERV", + .casio_link_info_product_id = "OMGOMGOMGOMGOMGO", + + /* system configuration */ + .casio_link_info_username = "Cow", + + /* wiped things */ + .casio_link_info_wiped = + casio_link_info_wiped_preprog | casio_link_info_wiped_bootcode, + + /* flash ROM and RAM information */ + .casio_link_info_flash_rom_capacity = 8 * 1024 * 1024, + .casio_link_info_ram_capacity = 256 * 1024, + + /* OS information */ + .casio_link_info_os_offset = 0x80000000, + .casio_link_info_os_size = 0x100000, + .casio_link_info_os_version = { + .casio_version_major = 2, .casio_version_minor = 9, + .casio_version_zone = casio_version_zone_fr, + .casio_version_math = casio_version_math_all, + .casio_version_status = casio_version_status_standard, + .casio_version_platform = casio_version_platform_special + }, +}; + +/* the server filesystems */ +static casio_filesystem_t server_filesystems[] = { + /* main filesystem: the flash */ { + .casio_filesystem_name = "fls0", + .casio_filesystem_directory_exists = directory_exists + }, + {NULL} +}; +/* ************************************************************************** */ +/* Server functions */ +/* ************************************************************************** */ +/** + * run_server: + * Run the server! + * + * @arg in the input. + * @arg out the output. + */ + +int run_server(int in, int out) +{ + int err; casio_link_t *handle = NULL; + casio_stream_t *stream = NULL; + + /* make the stream */ + err = casio_open_stream_fd(stream, in, out, 1, 1); + if (err) { + fprintf(stderr, "Server stream initialization has encountered " + "an error: %s\n", p7_strerror(err)); + return (1); + } + + /* make the handle */ + err = casio_open_link(&handle, 0, stream, NULL); + if (err) { + fprintf(stderr, "Server initialization has encountered an error: %s\n", + p7_strerror(err)); + return (1); + } + + /* protect and serve */ + casio_serve(handle, &server_information, server_filesystems); + casio_close_link(handle); + return (0); +} diff --git a/src/p7servtest/vars.mk b/src/p7servtest/vars.mk new file mode 100644 index 0000000..ce38114 --- /dev/null +++ b/src/p7servtest/vars.mk @@ -0,0 +1,4 @@ +#!/usr/bin/make -f +disable: +libs: + @echo libcasio