π
<-
Chat plein-écran
[^]

Loosing my nerves on the folder/file listing function

C, C++, ASM...

Loosing my nerves on the folder/file listing function

Message non lude SlyVTT » 05 Mai 2021, 22:13

Hello everybody,

I am experiencing a bug in my GUI Tollkit when trying to list files and folders in a given folder.

My code is the following :

Code: Tout sélectionner
int FileDialogBoxWidget::listdir(const char *path)
{
    char name[255];
    struct dirent *ent;
    DIR *dir = opendir(path);
    while((ent = readdir(dir)))
    {
        strcpy(name, path);
        strcat(name,"/");
        strcat(name, ent->d_name);
        DIR *test = opendir( name );
        if(test)
        {
            closedir(test);
            folderlist->additem( (char *) ent->d_name );
        }
        else
        {
            filelist->additem( (char *) ent->d_name );
        }
    }
    closedir(dir);
  return 0;
}



It loops the correct number of times but ent->d_name always return the name of the first item (in my case the name of the first folder) in the considered folder to scrutinize.

I made the same routine on my linux distribution and it works perfectly well. The code is as follows :

Code: Tout sélectionner
int listdir(const char *path)
{
    char name[255];
    struct dirent *ent;
    DIR *dir = opendir(path);
    while((ent = readdir(dir)))
    {
        //Test whether it's a directory
        strcpy(name, path);
        strcat(name,"/");
        strcat(name, ent->d_name);
        DIR *test = opendir( name );
        if(test)    // This is a directory and we add to the folder list widget
        {
            closedir(test);
            printf( "[ %s ] \n", ent->d_name );
        }
        else    // this is a file and we add to the folder list widget
        {
                printf( " %s  \n", ent->d_name );
        }
    }
    closedir(dir);
  return 0;
}


No need to say that I checked many thing to try to identify if the folderlist and filelist works fine, and they do.
I do not understand what's happening, does anyone also met that bug/issue ?
The bug is in the following file : https://github.com/SlyVTT/Widget-for-TI-NSpire/blob/main/Toolkit/FileDialogBoxWidget.cpp

Ciao

Sly
Some works in progress :
The GUI Toolkit NF for nSpireMyShmup for fxCG-50Magic Light for Casio Graph 90+E
and
Magic Light for nSpire CX/CX-II
Simple Text Editor for nSpireOutRun for Casio Graph 90+E
95%
50%
100%
75%
100%
And more to come ... stay tuned
Avatar de l’utilisateur
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 42.9%
 
Messages: 481
Images: 31
Inscription: 19 Jan 2021, 09:41
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
GitHub: SlyVTT

Re: Loosing my nerves on the folder/file listing function

Message non lude Adriweb » 05 Mai 2021, 22:24

I suppose that if it's an ndless-related issue, it's good that you opened a github issue, Vogtinator will likely reply soon :)
Image

MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)
Avatar de l’utilisateur
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 80%
 
Messages: 14599
Images: 1216
Inscription: 01 Juin 2007, 00:00
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
Twitter/X: adriweb
GitHub: adriweb

Re: Loosing my nerves on the folder/file listing function

Message non lude jean-baptiste boric » 05 Mai 2021, 22:25

Looking at your code, you try to open a directory entry to see if that's a directory or a file. You should probably instead use lstat() if that's available on your system.
Avatar de l’utilisateur
jean-baptiste boricPremium
Niveau 10: GR (Guide de Référence)
Niveau 10: GR (Guide de Référence)
Prochain niv.: 4.5%
 
Messages: 374
Inscription: 21 Déc 2015, 22:22
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile
GitHub: boricj

Re: Loosing my nerves on the folder/file listing function

Message non lude SlyVTT » 05 Mai 2021, 22:33

Adriweb a écrit:I suppose that if it's an ndless-related issue, it's good that you opened a github issue, Vogtinator will likely reply soon :)


I did it concurrently. I don't know where Vogtinator will navigate first :-)

Thanks Adriweb
Some works in progress :
The GUI Toolkit NF for nSpireMyShmup for fxCG-50Magic Light for Casio Graph 90+E
and
Magic Light for nSpire CX/CX-II
Simple Text Editor for nSpireOutRun for Casio Graph 90+E
95%
50%
100%
75%
100%
And more to come ... stay tuned
Avatar de l’utilisateur
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 42.9%
 
Messages: 481
Images: 31
Inscription: 19 Jan 2021, 09:41
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
GitHub: SlyVTT

Re: Loosing my nerves on the folder/file listing function

Message non lude SlyVTT » 05 Mai 2021, 22:39

jean-baptiste boric a écrit:Looking at your code, you try to open a directory entry to see if that's a directory or a file. You should probably instead use lstat() if that's available on your system.


I tried to stay 'as basic as possible' to keep the size of the toolkit as low as possible.
For sure this is not the best way.

I don't know if the stat include is available. The dirent structure is hence very limited and does not offer all the info. In particular the d_type is missing. So this is why a need a trick to check if it is a file or a folder.

Thanks

Sly
Some works in progress :
The GUI Toolkit NF for nSpireMyShmup for fxCG-50Magic Light for Casio Graph 90+E
and
Magic Light for nSpire CX/CX-II
Simple Text Editor for nSpireOutRun for Casio Graph 90+E
95%
50%
100%
75%
100%
And more to come ... stay tuned
Avatar de l’utilisateur
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 42.9%
 
Messages: 481
Images: 31
Inscription: 19 Jan 2021, 09:41
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
GitHub: SlyVTT

Re: Loosing my nerves on the folder/file listing function

Message non lude Bisam » 06 Mai 2021, 08:22

I really don't know anything about it but it SEEMS that the struct dirent is badly implemented...
Avatar de l’utilisateur
BisamAdmin
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Prochain niv.: 69.5%
 
Messages: 5665
Inscription: 11 Mar 2008, 00:00
Localisation: Lyon
Genre: Homme
Calculatrice(s):
MyCalcs profile

Re: Loosing my nerves on the folder/file listing function

Message non lude SlyVTT » 06 Mai 2021, 09:27

Bisam,

Also looks like this to me.
Right now it is a copy of the "nucleus" struct nuc_dirent, which only contains a "char d_name[1];" member.
Looks a bit strange.

And I cannot find direct useage of nuc_dirent in other programs sources.
Vogtinator's pyWrite uses the dirent.h functions and it seems to work earlier, but I was not able to compile the sources with current revision of Ndless to check if it is still working or is now broken.
Hope he (or another skilled guy of the Ndless team) will be able to give feedbacks on that issue.

Ciao

Sly
Some works in progress :
The GUI Toolkit NF for nSpireMyShmup for fxCG-50Magic Light for Casio Graph 90+E
and
Magic Light for nSpire CX/CX-II
Simple Text Editor for nSpireOutRun for Casio Graph 90+E
95%
50%
100%
75%
100%
And more to come ... stay tuned
Avatar de l’utilisateur
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 42.9%
 
Messages: 481
Images: 31
Inscription: 19 Jan 2021, 09:41
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
GitHub: SlyVTT

Re: Loosing my nerves on the folder/file listing function

Message non lude SlyVTT » 06 Mai 2021, 11:51

Ok Guys,

Spending a lot of time on this, we can conclude I am a bit brainless ... :bang:

Now this is working. The problem was coming from the use of the ent->d_name as an allocated (char *) while it is just a pointer. Now I allocate memory on the fly for each iteration of the loop and copy the ent->d_name to the right place.
This avoids pointing (and adding in the lists) always the first item.

below is the working code, note the malloc part that saves my life ;-)

Code: Tout sélectionner
int FileDialogBoxWidget::listdir(const char *path)
{
char name[255];
    struct dirent *ent;
    DIR *dir = opendir(path);
    while((ent = readdir(dir)))
    {
        //Test whether it's a directory
        strcpy(name, path);
        strcat(name,"/");
        strcat(name, ent->d_name);
        DIR *test = opendir( name );
        if(test)    // This is a directory and we add to the folder list widget
        {
            closedir(test);
            char *temp = (char*) malloc( strlen(ent->d_name) +1 );
            strcpy(temp, ent->d_name );
            folderlist->additem( (char *) temp );
        }
        else    // this is a file and we add to the file list widget
        {
            char *temp = (char*) malloc( strlen(ent->d_name) +1 );
            strcpy(temp, ent->d_name );
            filelist->additem( (char *) temp );
        }
    }
    closedir(dir);
  return 0;
}


and to celebrate that important moment :p , this is the picture of the working file picking dialog box (still needing some works of mine to make it fully functional).

Image

Ciao

Sly


PS: the Ndless repository PR has been closed with the working code posted
Dernière édition par SlyVTT le 07 Mai 2021, 13:24, édité 1 fois.
Some works in progress :
The GUI Toolkit NF for nSpireMyShmup for fxCG-50Magic Light for Casio Graph 90+E
and
Magic Light for nSpire CX/CX-II
Simple Text Editor for nSpireOutRun for Casio Graph 90+E
95%
50%
100%
75%
100%
And more to come ... stay tuned
Avatar de l’utilisateur
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 42.9%
 
Messages: 481
Images: 31
Inscription: 19 Jan 2021, 09:41
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
GitHub: SlyVTT

Re: Loosing my nerves on the folder/file listing function

Message non lude Bisam » 06 Mai 2021, 13:30

Nice work !
Hopefully, you'll change the color of the selected files... I really dislike this pink.
Avatar de l’utilisateur
BisamAdmin
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Prochain niv.: 69.5%
 
Messages: 5665
Inscription: 11 Mar 2008, 00:00
Localisation: Lyon
Genre: Homme
Calculatrice(s):
MyCalcs profile

Re: Loosing my nerves on the folder/file listing function

Message non lude SlyVTT » 06 Mai 2021, 13:58

Bisam,

this is to highlight the "Girly" part of mine :#langue#: . Don't worry, the application is fully themable.

but for visibility reason, I keep this "bright" theme, cause it helps a lot the development (I know very well the color scheme and can see in one single eyeshot is something is wrong or not).

-- Advertisement mode : ON --

I am looking for contributors to create THEMES and LOGO ... Still :#gni#:

-- Advertisement mode : OFF --

Ciao

Sly
Some works in progress :
The GUI Toolkit NF for nSpireMyShmup for fxCG-50Magic Light for Casio Graph 90+E
and
Magic Light for nSpire CX/CX-II
Simple Text Editor for nSpireOutRun for Casio Graph 90+E
95%
50%
100%
75%
100%
And more to come ... stay tuned
Avatar de l’utilisateur
SlyVTTPremium
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 42.9%
 
Messages: 481
Images: 31
Inscription: 19 Jan 2021, 09:41
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
GitHub: SlyVTT


Retourner vers Native: Ndless, Linux, ...

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 9 invités

-
Rechercher
-
Social TI-Planet
-
Sujets à la une
Comparaisons des meilleurs prix pour acheter sa calculatrice !
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
Phi NumWorks jailbreak
123
-
Faire un don / Premium
Pour plus de concours, de lots, de tests, nous aider à payer le serveur et les domaines...
Faire un don
Découvrez les avantages d'un compte donateur !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partenaires et pub
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
716 utilisateurs:
>698 invités
>13 membres
>5 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Autres sites intéressants
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)