Changeset 17584 in niluje


Ignore:
Timestamp:
Jul 28, 2020, 9:04:58 PM (11 days ago)
Author:
NiLuJe
Message:

MobiCover:

  • Make it build
Location:
Configs/trunk/Kindle/Touch_Hacks/MobiCover/LibMobi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Configs/trunk/Kindle/Touch_Hacks/MobiCover/LibMobi/Makefile

    r17583 r17584  
    4545EXTRA_CFLAGS+=-Wconversion
    4646
    47 # Detect the K3 TC to disable CLOEXEC...
    48 ifdef CROSS_TC
    49         ifeq "$(CROSS_TC)" "arm-kindle-linux-gnueabi"
    50                 EXTRA_CPPFLAGS+=-DKINDLE_LEGACY
    51         endif
    52 endif
    53 
    5447all: mobicover
    5548
  • Configs/trunk/Kindle/Touch_Hacks/MobiCover/LibMobi/mobicover.c

    r17583 r17584  
    2020#include <stdio.h>
    2121#include <stdlib.h>
     22#include <string.h>
    2223#include <unistd.h>
    2324
     
    2829// Return negative values on failure
    2930#define ERRCODE(e) (-(e))
     31
     32// Helper functions from libmobi's tools/common.c
     33#define ARRAYSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
     34
     35/**
     36  @brief Messages for libmobi return codes
     37  For reference see enum MOBI_RET in mobi.h
     38 */
     39static const char* libmobi_messages[] = {
     40        "Success",
     41        "Generic error",
     42        "Wrong function parameter",
     43        "Corrupted data",
     44        "File not found",
     45        "Document is encrypted",
     46        "Unsupported document format",
     47        "Memory allocation error",
     48        "Initialization error",
     49        "Buffer error",
     50        "XML error",
     51        "Invalid DRM pid",
     52        "DRM key not found",
     53        "DRM support not included",
     54};
     55
     56#define LIBMOBI_MSG_COUNT ARRAYSIZE(libmobi_messages)
     57
     58/**
     59 @brief Return message for given libmobi return code
     60 @param[in] ret Libmobi return code
     61 */
     62static const char*
     63    libmobi_msg(const MOBI_RET ret)
     64{
     65        size_t index = ret;
     66        if (index < LIBMOBI_MSG_COUNT) {
     67                return libmobi_messages[index];
     68        } else {
     69                return "Unknown error";
     70        }
     71}
     72
     73static const char separator = '/';
     74/**
     75 @brief Parse file name into file path and base name.
     76        Dirname or basename can be skipped by setting to null.
     77        All buffers must have FILENAME_MAX size.
     78 @param[in] fullpath Full file path
     79 @param[in,out] dirname Will be set to full dirname
     80 @param[in,out] basename Will be set to file basename
     81 */
     82static void
     83    split_fullpath(const char* fullpath, char* dirname, char* basename)
     84{
     85        char* p = strrchr(fullpath, separator);
     86        if (p) {
     87                p += 1;
     88                if (dirname) {
     89                        strncpy(dirname, fullpath, (unsigned long) (p - fullpath));
     90                        dirname[p - fullpath] = '\0';
     91                }
     92                if (basename) {
     93                        strcpy(basename, p);
     94                }
     95        } else {
     96                if (dirname) {
     97                        dirname[0] = '\0';
     98                }
     99                if (basename) {
     100                        strcpy(basename, fullpath);
     101                }
     102        }
     103        if (basename) {
     104                p = strrchr(basename, '.');
     105                if (p) {
     106                        *p = '\0';
     107                }
     108        }
     109}
     110
     111// Actual tools/mobitool.c stuff
    30112
    31113/**
Note: See TracChangeset for help on using the changeset viewer.