Validation bFile::findFirst/Next/Close

This commit is contained in:
Jérôme Henry-Barnaudière - GeeHB 2023-12-27 17:02:07 +01:00
parent 4ae410aec6
commit 02cec3d042
7 changed files with 184 additions and 83 deletions

View File

@ -7,6 +7,7 @@ find_package(Gint 2.9 REQUIRED)
set(SOURCES
src/sudoSolv.cpp
#src/main.cpp
src/shared/bFile.cpp
src/shared/keyboard.cpp
src/shared/menuBar.cpp
@ -34,5 +35,5 @@ target_link_libraries(sudoSolver Gint::Gint)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
generate_g3a(TARGET sudoSolver OUTPUT "sudoSolv.g3a"
NAME "sudoSolv" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)
NAME "sudoSolver" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)
endif()

View File

@ -25,6 +25,10 @@ grids::grids(){
count_ = 0;
capacity_ = 0;
// this folder
strcpy(folder_, GRIDS_FOLDER);
strcat(folder_, PATH_SEPARATOR);
_browse();
}
@ -40,7 +44,12 @@ bool grids::nextFile(FONTCHARACTER& fName){
}
// Copy the file name
bFile::FC_cpy(fName, files_[++index_]->fileName);
#ifdef DEST_CASIO_CALC
bFile::FC_str2FC(folder_, fName);
bFile::FC_cpy(fName + bFile::FC_len(fName), files_[++index_]->fileName);
#else
#endif // DEST_CASIO_CALC
//bFile::FC_cpy(fName, files_[++index_]->fileName);
return true;
}
@ -56,7 +65,14 @@ bool grids::prevFile(FONTCHARACTER& fName){
}
// Copy the file name
bFile::FC_cpy(fName, files_[--index_]->fileName);
#ifdef DEST_CASIO_CALC
bFile::FC_str2FC(folder_, fName);
bFile::FC_cpy(fName + bFile::FC_len(fName), files_[--index_]->fileName);
#else
#endif // DEST_CASIO_CALC
//bFile::FC_cpy(fName, files_[++index_]->fileName);
//bFile::FC_cpy(fName, files_[--index_]->fileName);
return true;
}
@ -80,8 +96,8 @@ void grids::_browse(){
char szPattern[BFILE_MAX_PATH + 1];
#ifdef DEST_CASIO_CALC
uint16_t fName[255];
uint16_t FCPattern[255];
uint16_t fName[BFILE_MAX_PATH + 1];
uint16_t FCPattern[BFILE_MAX_PATH + 1];
#else
char fName[BFILE_MAX_PATH + 1];
char FCPattern[BFILE_MAX_PATH + 1];
@ -245,34 +261,17 @@ void grids::__vector_clear(){
// @return : numeric value or -1 on error
//
int grids::__fileName2i(FONTCHARACTER src){
size_t len;
if (0 == (len = bFile::FC_len(src))){
return -1;
}
char* buffer = (char*)src;
int num(0);
uint8_t index(0);
char car;
uint8_t sCar(1);
#ifdef DEST_CASIO_CALC
sCar = sizeof(uint16_t);
#endif // DEST_CASIO_CALC
// remove path
if (len > 1){
int index = len - sCar;
while (index && buffer[index] != CHAR_PATH_SEPARATOR){
index-=sCar;
}
buffer=(index?buffer+(index+sCar):buffer);
}
// convert the file name
index = 0;
while (num >= 0 && (car = buffer[index]) && car != '.'){
while (num >= 0 && (car = buffer[index + 1]) && car != '.'){
if (car >= '0' && car <= '9'){
num = num * 10 + (car - '0');
}

View File

@ -1,41 +1,41 @@
//---------------------------------------------------------------------------
//--
//-- grids.h
//--
//-- Definition of grids object - List of grid files stored on "disk"
//---------------------------------------------------------------------------
//--
//-- grids.h
//--
//-- Definition of grids object - List of grid files stored on "disk"
//--
//-- The object works as a rudimentary DB
//-- where each file has a numeric ID
//--
//---------------------------------------------------------------------------
#ifndef __S_SOLVER_GRIDS_h__
#define __S_SOLVER_GRIDS_h__ 1
#include "consts.h"
#include "shared/bFile.h"
//--
//---------------------------------------------------------------------------
#ifndef __S_SOLVER_GRIDS_h__
#define __S_SOLVER_GRIDS_h__ 1
#include "consts.h"
#include "shared/bFile.h"
/*
#include <vector>
#include <vector>
using namespace std;
*/
#ifdef __cplusplus
extern "C" {
#endif // #ifdef __cplusplus
class grids{
public:
// Construction
grids();
// Destruction
#ifdef __cplusplus
extern "C" {
#endif // #ifdef __cplusplus
class grids{
public:
// Construction
grids();
// Destruction
~grids(){
__vector_clear();
}
// # files in folder
}
// # files in folder
int size(){
//return files_.size();
return count_;
@ -47,15 +47,15 @@ public:
//
int pos(){
return index_;
}
}
// nextFile() : Get next file name
//
// @fName : fullname of the next file
//
// @return : true if the next file name is valid
//
bool nextFile(FONTCHARACTER& fName);
//
bool nextFile(FONTCHARACTER& fName);
// prevFile() : Get previous file name
//
@ -63,13 +63,13 @@ public:
//
// @return : true if the previous file name is valid
//
bool prevFile(FONTCHARACTER& fName);
// File management
bool newFileName(FONTCHARACTER fName);
bool prevFile(FONTCHARACTER& fName);
// File management
bool newFileName(FONTCHARACTER fName);
bool deleteFile(); // current
bool deleteFile(); // current
// Internal methods
private:
@ -141,22 +141,23 @@ private:
//
void __strrev(char *str);
// Members
// Members
private:
char folder_[BFILE_MAX_PATH + 1];
int index_; // Index of current file in list (-1 if none)
// We can't use vectors, so let's use my own "vector" like table
// vector<PFNAME> files_; // List of "file names"
PFNAME* files_; // List of files
int capacity_; // max. size of buffer
int count_; // Item count
};
#ifdef __cplusplus
}
#endif // #ifdef __cplusplus
#endif // __S_SOLVER_GRIDS_h__
// EOF
int count_; // Item count
};
#ifdef __cplusplus
}
#endif // #ifdef __cplusplus
#endif // __S_SOLVER_GRIDS_h__
// EOF

View File

@ -447,7 +447,7 @@ bool bFile::findClose(SEARCHHANDLE sHandle){
// FC_str2FC() : Convert a string to FC format
//
// @src : string to copy
// @src : string to convert
// @dest : destination buffer
//
// @return : pointer to a FONTCHARACTER
@ -461,8 +461,8 @@ bool bFile::FC_str2FC(const char* src, FONTCHARACTER dest){
// Copy string content
char* buffer = (char*)dest;
for (size_t index = 0; index <= len; index++){
buffer[2*index] = src[index];
buffer[2*index + 1] = 0;
buffer[2*index] = 0;
buffer[2*index + 1] = src[index];
}
return true;
@ -471,6 +471,30 @@ bool bFile::FC_str2FC(const char* src, FONTCHARACTER dest){
#endif // #ifdef DEST_CASIO_CALC
}
// FC_FC2str() : Convert a string from FC format to char*
//
// @src : FC to convert
// @dest : destination buffer
//
// @return : pointer to a FONTCHARACTER
//
bool bFile::FC_FC2str(const FONTCHARACTER src, char* dest){
#ifdef DEST_CASIO_CALC
size_t len;
if (!src || 0 == (len = FC_len(src)) || !dest){
return false;
}
// Copy string content
char* buffer = (char*)src;
for (size_t index = 0; index <= len; index++){
dest[index] = buffer[2*index + 1];
}
return true;
#endif // #ifdef DEST_CASIO_CALC
}
// FC_cpy() : Copy a FONTCHARACTER to another FONTCHARACTER
//
// @dest : pointer to a destination string (already allocated)
@ -531,7 +555,7 @@ size_t bFile::FC_len(const FONTCHARACTER fName){
#ifdef DEST_CASIO_CALC
size_t len(0);
char* buffer = (char*)fName;
while(buffer[len*sizeof(uint16_t)]){
while(buffer[1+ len*sizeof(uint16_t)]){
len++;
}

View File

@ -221,13 +221,22 @@ public:
// FC_str2FC() : Convert a string to FC format
//
// @src : string to copy
// @src : string to convert
// @dest : destination buffer
//
// @return : pointer to a FONTCHARACTER
//
static bool FC_str2FC(const char* src, FONTCHARACTER dest);
// FC_FC2str() : Convert a string from FC format to char*
//
// @src : FC to convert
// @dest : destination buffer
//
// @return : pointer to a FONTCHARACTER
//
static bool FC_FC2str(const FONTCHARACTER src, char* dest);
// FC_cpy() : Copy a FONTCHARACTER to another FONTCHARACTER
//
// @dest : pointer to a destination string (already allocated)

68
src/shared/trace.h Normal file
View File

@ -0,0 +1,68 @@
//---------------------------------------------------------------------------
//--
//-- File : trace.h
//--
//-- Author : Jérôme Henry-Barnaudière - GeeHB
//--
//-- Project : geeTetris - cpp version
//--
//---------------------------------------------------------------------------
//--
//-- Description:
//--
//-- Shared types, objects and constants
//--
//---------------------------------------------------------------------------
#ifndef __GEE_TETRIS_TRACE_h__
#define __GEE_TETRIS_TRACE_h__ 1
#ifdef DEST_CASIO_CALC
#include "scrCapture.h" // capture only on TRACE mode
#define TRACE_MODE 1 // Only for tests
#else
#ifdef TRACE_MODE // ???
#undef TRACE_MODE
#endif // TRACE_MODE
#endif // DEST_CASIO_CALC
#ifdef __cplusplus
extern "C" {
#endif // #ifdef __cplusplus
#ifdef TRACE_MODE
#ifdef FX9860G
#define TRACE_POS_X (CASIO_WIDTH - 40)
#define TRACE_POS_Y 5 // (CASIO_HEIGHT - 20)
#define TRACE_WIDTH 100
#define TRACE_HEIGHT 12
#else
#define TRACE_POS_X (CASIO_WIDTH - 140)
#define TRACE_POS_Y (CASIO_HEIGHT - 60)
#define TRACE_WIDTH 100
#define TRACE_HEIGHT 15
#endif // #ifdef FX9860G
// TRACE : add a line a text in the screen
//
// @val : text to display
// @tCol : text colour
// @bkCol : Background colour
//
#define TRACE(val, tCol, bkCol) { if (NO_COLOR != bkCol) drect(TRACE_POS_X, TRACE_POS_Y, TRACE_POS_X + TRACE_WIDTH - 1, TRACE_POS_Y + TRACE_HEIGHT -1, bkCol);::dtext(TRACE_POS_X, TRACE_POS_Y, tCol, val);dupdate();}
#define TRACE_DEF(val) TRACE(val, COLOUR_BLACK, NO_COLOR);
#define TRACE_WAIT(val, tCol, bkCol) {TRACE(val, tCol, bkCol); key_event_t evt; do { evt = pollevent();} while(evt.type != KEYEV_DOWN && evt.key != KEY_EXE);}
#else
#define TRACE(val, tCol, tbk) {}
#define TRACE_WAIT(val, tCol, tbk) {}
#define TRACE_DEF(val) {}
#endif // #ifdef TRACE_WIDTH
#ifdef __cplusplus
}
#endif // #ifdef __cplusplus
#endif // __GEE_TETRIS_TRACE_h__
// EOF

View File

@ -12,9 +12,8 @@
#include "sudoku.h"
#include "menu.h"
#include "shared/scrCapture.h"
#ifdef DEST_CASIO_CALC
#include "shared/scrCapture.h"
extern bopti_image_t g_homeScreen; // Background image
scrCapture g_Capture; // Screen capture object
#endif // #ifdef DEST_CASIO_CALC