Browse Source

Moved Borland porting functions/defines to portlib, fixed, tested, included

master
surkeh 3 years ago
parent
commit
e82dd82150
5 changed files with 18 additions and 141 deletions
  1. 2
    3
      Makefile
  2. 1
    129
      include/paperbak.h
  3. 1
    1
      lib/PortLibC
  4. 14
    6
      src/Fileproc.cpp
  5. 0
    2
      src/Printer.cpp

+ 2
- 3
Makefile View File

@@ -3,12 +3,11 @@ SDIR=src
BZDIR=lib/BZLIB
AESDIR=lib/AES
CC=g++
PORTDIR=lib/PortLibC/src
CFLAGS=-std=c++11 -I"include" -I"$(PORTDIR)" -I"lib/cxxopts/include" -I"lib/AES" -I"lib/BZLIB"
CFLAGS=-std=c++11 -I"include" -I"lib/PortLibC/include" -I"lib/cxxopts/include" -I"lib/AES" -I"lib/BZLIB"

all: main

main: $(SDIR)/main.cpp $(SDIR)/Printer.cpp $(SDIR)/Scanner.cpp $(SDIR)/Fileproc.cpp $(SDIR)/Decoder.cpp $(SDIR)/Fileproc.cpp $(SDIR)/Crc16.cpp $(SDIR)/Ecc.cpp $(BZDIR)/bz_lib.cpp $(BZDIR)/bz_blocksort.cpp $(BZDIR)/bz_compress.cpp $(BZDIR)/bz_crctable.cpp $(BZDIR)/bz_decompress.cpp $(BZDIR)/bz_huffman.cpp $(BZDIR)/bz_randtable.cpp $(AESDIR)/ae_aes.cpp $(PORTDIR)/FileAttributes.c
main: $(SDIR)/main.cpp $(SDIR)/Printer.cpp $(SDIR)/Scanner.cpp $(SDIR)/Fileproc.cpp $(SDIR)/Decoder.cpp $(SDIR)/Fileproc.cpp $(SDIR)/Crc16.cpp $(SDIR)/Ecc.cpp $(BZDIR)/bz_lib.cpp $(BZDIR)/bz_blocksort.cpp $(BZDIR)/bz_compress.cpp $(BZDIR)/bz_crctable.cpp $(BZDIR)/bz_decompress.cpp $(BZDIR)/bz_huffman.cpp $(BZDIR)/bz_randtable.cpp $(AESDIR)/ae_aes.cpp
$(CC) $^ $(CFLAGS) -o $(EX)



+ 1
- 129
include/paperbak.h View File

@@ -24,6 +24,7 @@
#include "bzlib.h"
#include "Bitmap.h"
#include "FileAttributes.h"
#include "Borland.h"



@@ -31,32 +32,12 @@
////////////////////////////////////////////////////////////////////////////////
///////////////////////////// GENERAL DEFINITIONS //////////////////////////////

// Values set by Borland compiler
#define MAXDRIVE 3
// For 16-bit cpu
//#define MAXPATH 80
//#define MAXDIR 66
//#define MAXFILE 9
//#define MAXEXT 5
// For 32-bit cpu (#if defined(__FLAT__))
#define MAXPATH 260
#define MAXDIR 256
#define MAXFILE 256
#define MAXEXT 256
// For Borlands fnsplit function
#define WILDCARDS 0x01
#define EXTENSION 0x02
#define FILENAME 0x04
#define DIRECTORY 0x08
#define DRIVE 0x10

// Size required by Reed-Solomon ECC
#define ECC_SIZE 32

// Oleh's magic numbers
#define FILENAME_SIZE 64


#define VERSIONHI 1 // Major version
#define VERSIONLO 2 // Minor version

@@ -392,115 +373,6 @@ inline int strnicmp (const char *str1, const char *str2, size_t len)
}


// Portable version of Borlands fnsplit
// RETURNS: bitvector of what components were found in path, regardless of
// which arguments were NULL
// NOTE: Does not handle wildcard *
// NOTE: Like the original, assumes argument cstrings of specific defined lengths
inline int fnsplit(const char *path,
char *drive,
char *dir,
char *name,
char *ext)
{
int i = 0; // for loop iterator set after drive letter, if needed
int flags = 0;
if (path != NULL) {
if (path[1] == ':') {
flags |= DRIVE;
if (drive != NULL) {
strncat (drive, path, 2);
drive[2] = '\0';
}
i = 2;
}

// path not necessarily terminated by \0
// parse char by char
char token[MAXPATH];
int iToken = 0;
if (dir != NULL)
dir[0] = '\0';

for ( ; i < MAXPATH; i++) {
// if delimiter, act accordingly
// token is part of the directory
if (path[i] == '/' || path[i] == '\\') {
flags |= DIRECTORY;
token[iToken++] = path[i];
token[iToken++] = '\0';
if (dir != NULL)
strcat (dir, token);
iToken = 0;
continue;
}
// token is name
else if (path[i] == '.') {
flags |= FILENAME;
flags |= EXTENSION;
token[iToken] = '\0';
if (name != NULL)
strcpy (name, token);
token[0] = '.';
iToken = 1;
continue;
}
// token is name or extension
else if (path[i] == '\0'
|| i >= MAXPATH - 1 ) {
//|| extCount >= MAXEXT - 1) {
if (flags & FILENAME) {
// is extension
token[iToken] = '\0';
if (ext != NULL)
strcpy (ext, token);
// all parts gathered, exit function
break;
}
else {
// is name
flags |= FILENAME;
token[iToken] = '\0';
if (name != NULL)
strcpy (name, token);
// all parts gathered, exit
break;
}
}
else {
//if not delimiter, build string
token[iToken++] = path[i];
}
}
}

return flags;
}



// Portable version of Borlands fnmerge
inline void fnmerge (char *path,
const char *drive,
const char *dir,
const char *name,
const char *ext)
{
if (path == NULL)
return;

path[0] = '\0';

if (drive != NULL)
strcat (path, drive);
if (dir != NULL)
strcat (path, dir);
if (name != NULL)
strcat (path, name);
if (ext != NULL)
strcat (path, ext);
}


// returns 0 on success, -1 on failure
inline int Getpassword()

+ 1
- 1
lib/PortLibC

@@ -1 +1 @@
Subproject commit 8196bd4c38a255020ad53f1cca305fafe49dc1d6
Subproject commit a7749edff4e4155b4c6e986f8959fc3e17dd3099

+ 14
- 6
src/Fileproc.cpp View File

@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <algorithm>
#include <stdint.h>
#include <utime.h>
#include "bzlib.h"
#include "aes.h"

@@ -202,10 +203,10 @@ int Finishpage(int slot,int ngood,int nbad,uint32_t nrestored) {
pf->badblocks+=nbad;
pf->restoredbytes+=nrestored;

printf("ngood: %d", pb_procdata.ngood);
printf("nbad: %d", pb_procdata.nbad);
printf("nsuper: %d", pb_procdata.nsuper);
printf("nrestored: %d", pb_procdata.nrestored);
printf("\nngood: %d\n", pb_procdata.ngood);
printf("nbad: %d\n", pb_procdata.nbad);
printf("nsuper: %d\n", pb_procdata.nsuper);
printf("nrestored: %d\n\n", pb_procdata.nrestored);

// Restore bad blocks if corresponding recovery blocks are available (max. 1
// per group).
@@ -404,8 +405,16 @@ int Saverestoredfile(int slot,int force) {
};
#elif __linux__
// Set file time
// FIXME left off here
struct stat bmpStat;
struct utimbuf newTime;
stat(::pb_outfile, &bmpStat);
newTime.actime = bmpStat.st_atime;
newTime.modtime = convertToPosixTime(pf->modified);
utime(::pb_outfile, &newTime);

// Restore mode
mode_t mode = convertToPosixAttributes(pf->attributes);
chmod (::pb_outfile, convertToPosixAttributes(pf->attributes));

#endif
// Close file descriptor and report success.
@@ -414,4 +423,3 @@ int Saverestoredfile(int slot,int force) {
return 0;
};



+ 0
- 2
src/Printer.cpp View File

@@ -445,13 +445,11 @@ static void Initializeprinting(t_printdata *print) {
print->superdata.mode|=PBM_COMPRESSED;
if (print->encryption)
print->superdata.mode|=PBM_ENCRYPTED;
#if defined(_WIN32) || defined(__CYGWIN__)
//mask windows values, otherwise leave *nix mode data alone
print->superdata.attributes=(uchar)(print->attributes &
(FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|
FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_ARCHIVE|
FILE_ATTRIBUTE_NORMAL));
#endif
print->superdata.modified=print->modified;
print->superdata.filecrc=(ushort)print->bufcrc;
int flags = fnsplit(print->infile,NULL,NULL,nam,ext);

Loading…
Cancel
Save