how to listdir in gint ?
Posté le 12/12/2023 17:34
In the beginning, I thank
Lephenixnoir for introducing
Gint and
FxSDK. It made it very easy for me. So far, I have no problems dealing with it. I want to know how I can access the file names located in the current path. We will assume that the current path is registered inside (PATH).
uint16_t PATH = u"////fls0//";
How can I write a function to do this?
I tried asking ChatGPT and it gave me this function
void listdir(uint16_t const *path , list_t* scr, int x_scrl ,int y_scrl) {
void listdir(uint16_t const *path) {
int shandle;
uint16_t foundfile[FILENAME_MAX];
struct BFile_FileInfo fileinfo;
// Open a search handle
int result = BFile_FindFirst(path, &shandle, foundfile, &fileinfo);
if (result < 0) {
print_txt(scr,"Error opening directory", x_scrl, y_scrl);
return;
}
// Iterate through the directory entries
while (result == 0 || result == BFile_EnumerateEnd) {
print_txt(scr, "F", x_scrl, y_scrl);
// Continue the search
result = BFile_FindNext(shandle, foundfile, &fileinfo);
if (result < 0) {
print_txt(scr, "Error during enumeration", x_scrl, y_scrl);
break;
}
}
// Close the search handle
BFile_FindClose(shandle);
scroll(scr,x_scrl,y_scrl);
}
}
But it always prints me
"Error opening directory", and that
print_txt(scr, ... , x_scrl, y_scrl)
is just something I wrote previously to print a line on the terminal program for the addin.
Citer : Posté le 12/12/2023 20:48 | #
If you're targeting the fx-CG or the G-III series of black-and-white calcs, you can use the standard functions opendir() and readdir() as they are currently supported by gint and forget about BFile's atrocities.
Otherwise, you can use gint's implementation of opendir(), which lists a directory pretty much as you're trying to do here, as a reference. I'll just go through the code you have currently to try and help a bit more.
First of all, and most importantly, the path is called \\fls0\*. The prefix \\fls0 indicates the storage memory. \ is the folder separator (like in Windows), and you have to specify * to indicate that you want to match all files. Also because this is C, all backslashes need to be doubled because it's the escape character. Finally, note that PATH is a pointer to a sequence of uint16_t, not one of them.
Then:
Looks good to me.
You should certainly stop the loop at BFile_EnumerateEnd.
Finally, while the find functions have generally been shown to work while using gint, you should world switch out of gint to use them.
Nitpick: no idea where that nested function is coming from but it probably shouldn't be there.
Citer : Posté le 12/12/2023 21:12 | #
If you're targeting the fx-CG or the G-III series of black-and-white calcs, you can use the standard functions opendir() and readdir() as they are currently supported by gint and forget about BFile's atrocities.
Otherwise, you can use gint's implementation of opendir(), which lists a directory pretty much as you're trying to do here, as a reference. I'll just go through the code you have currently to try and help a bit more.
First of all, and most importantly, the path is called \\fls0\*. The prefix \\fls0 indicates the storage memory. \ is the folder separator (like in Windows), and you have to specify * to indicate that you want to match all files. Also because this is C, all backslashes need to be doubled because it's the escape character. Finally, note that PATH is a pointer to a sequence of uint16_t, not one of them.
Then:
Looks good to me.
You should certainly stop the loop at BFile_EnumerateEnd.
Finally, while the find functions have generally been shown to work while using gint, you should world switch out of gint to use them.
Nitpick: no idea where that nested function is coming from but it probably shouldn't be there.
Thanks buddy, but how i should include them? (dir_t , fugue_dir_explore) , something like ?
Citer : Posté le 12/12/2023 21:17 | #
You can't use fugue_dir_explore directly because it's an internal function, unfortunately... you can get opendir(), readdir() etc. with #include <dirent.h> if that's what you're targeting, otherwise you should copy the code I linked you over to your project and adjust it to fit your needs.
Citer : Posté le 12/12/2023 21:50 | #
You can't use fugue_dir_explore directly because it's an internal function, unfortunately... you can get opendir(), readdir() etc. with #include <dirent.h> if that's what you're targeting, otherwise you should copy the code I linked you over to your project and adjust it to fit your needs.
I apologize for bothering you with my many questions, but this is my first time writing a project in C. I am trying to make a Linux simulator.
All of these functions do not give me output, even though I set the path to
I think tired Python programmers like me have big problems with this
When I am free, I will develop a program to write addin in Python, based on FxSDK
Citer : Posté le 12/12/2023 22:08 | #
If you could make it possible to program addins in Python, that would be really incredible !
The syntax is so much simpler than that of C
Citer : Posté le 12/12/2023 22:09 | #
You can't use fugue_dir_explore directly because it's an internal function, unfortunately... you can get opendir(), readdir() etc. with #include <dirent.h> if that's what you're targeting, otherwise you should copy the code I linked you over to your project and adjust it to fit your needs.
Until now, I have problems with everything related to files and dirs. I don’t know what to do. Do you have documents, courses, or anything in which these things are explained?
Citer : Posté le 12/12/2023 22:11 | #
If you could make it possible to program addins in Python, that would be really incredible !
The syntax is so much simpler than that of C
You can already try to scrap something together with a Python -> C compiler if you think it's that great
As for myself i think the benefits wouldn't really be there, and it would dissuade people from trying to pick up C (Unless it's really unpratical )
Caltos : G35+EII, G90+E (briquée )
Citer : Posté le 12/12/2023 22:12 | #
If you could make it possible to program addins in Python, that would be really incredible !
The syntax is so much simpler than that of C
It's very easy, just to rewrite the gint function in a simple way for Python (C Function). Then I will create a library in pip that deals with FxSDK and writes Python code inside a C file and runs it with Python.h (Python C API) with some additions that you do automatically.
Citer : Posté le 12/12/2023 22:14 | #
You can already try to scrap something together with a Python -> C compiler if you think it's that great
As for myself i think the benefits wouldn't really be there, and it would dissuade people from trying to pick up C (Unless it's really unpratical )
It would actually be impractical because it is simple. I'm tormented now to write a simple program in C
Citer : Posté le 12/12/2023 22:15 | #
Until now, I have problems with everything related to files and dirs. I don’t know what to do. Do you have documents, courses, or anything in which these things are explained?
For those kinds of things you would be better off starting on PC, as - especially on Unix systems - it is much more documented and explained
It's very easy, just to rewrite the gint function in a simple way for Python (C Function). Then I will create a library in pip that deals with FxSDK and writes Python code inside a C file and runs it with Python.h (Python C API) with some additions that you do automatically.
I didn't look that much into it, but it seems like the better (and more realistic) approach would be doing a tool that wraps something like Cython with the FxSDK
Edit : To explain more, running python inside of C would be much more complex as the cypthon project shows...
Caltos : G35+EII, G90+E (briquée )
Citer : Posté le 12/12/2023 22:15 | #
If t
If you could make it possible to program addins in Python, that would be really incredible !
The syntax is so much simpler than that of C
It's very easy, just to rewrite the gint function in a simple way for Python (C Function). Then I will create a library in pip that deals with FxSDK and writes Python code inside a C file and runs it with Python.h (Python C API) with some additions that you do automatically.
If that's what you call simple
Citer : Posté le 12/12/2023 22:21 | #
Wait people don't go on tangents about binding Python and C... it's harder than it looks. One thing at a time.
I apologize for bothering you with my many questions, but this is my first time writing a project in C. I am trying to make a Linux simulator.
All of these functions do not give me output, even though I set the path to
Don't worry, do ask! Your path is not correct yet. Paths in the calculator filesystem use backslash (\) as the separator, not slash (/). The path should be u"\\\\fls0\\*" for the search.
Citer : Posté le 12/12/2023 22:21 | #
If t
If you could make it possible to program addins in Python, that would be really incredible !
The syntax is so much simpler than that of C
It's very easy, just to rewrite the gint function in a simple way for Python (C Function). Then I will create a library in pip that deals with FxSDK and writes Python code inside a C file and runs it with Python.h (Python C API) with some additions that you do automatically.
If that's what you call simple
Most of the program will be based on Python, so I am proficient in that. I will look for someone to help me in C only
Citer : Posté le 12/12/2023 22:23 | #
Most of the program will be based on Python, so I am proficient in that. I will look for someone to help me in C only
Please clean up those quotes
Caltos : G35+EII, G90+E (briquée )
Citer : Posté le 12/12/2023 22:25 | #
Wait people don't go on tangents about binding Python and C... it's harder than it looks. One thing at a time.
I apologize for bothering you with my many questions, but this is my first time writing a project in C. I am trying to make a Linux simulator.
All of these functions do not give me output, even though I set the path to
Don't worry, do ask! Your path is not correct yet. Paths in the calculator filesystem use backslash (\) as the separator, not slash (/). The path should be u"\\\\fls0\\*" for the search.
I tried all of this
char PWD[] = "\\\\fls0\\*";
void listdir(const char* path, list_t* scr, int x_scrl ,int y_scrl) {
// Explore the directory
void* dir_data = fugue_dir_explore(path);
if (!dir_data) {
print_txt(scr,"Error exploring directory",x_scrl,y_scrl);
return;
}
// Cast the directory data to dir_t
dir_t* dp = (dir_t*)dir_data;
// Print the list of files
for (int i = 0; i < dp->count; i++) {
print_txt(scr, dp->entries[i]->d_name, x_scrl,y_scrl);
}
// Close the directory
fugue_dir_close(dir_data);
}
else if (strcmp(last_line,"ls") == 0) {
listdir(PWD,scr,x_scrl,y_scrl);
}
also
listdir("\\\\fls0",scr,x_scrl,y_scrl);
listdir("\\\\fls0\\",scr,x_scrl,y_scrl);
listdir("\\\\fls0\\*",scr,x_scrl,y_scrl);
Citer : Posté le 12/12/2023 22:28 | #
Most of the program will be based on Python, so I am proficient in that. I will look for someone to help me in C only
Please clean up those quotes
Citer : Posté le 12/12/2023 23:07 | #
It's very easy, just to rewrite the gint function in a simple way for Python (C Function). Then I will create a library in pip that deals with FxSDK and writes Python code inside a C file and runs it with Python.h (Python C API) with some additions that you do automatically.
welll i don't think it's that simple... python.h is not officially supported in gint, maybe you will have to deal with some parts of the Python C API (recode some parts of it, adapte it) and, tbh, i don't think this is really easy x)
But if you're really motivated that would be an amazing project ! I personally think that C>Python for, well, a bunch of reasons, but yeah it would be a very nice-engineered system, and maybe it could bring a lot of people that would'nt usually create add-ins to do so... so, good luck !
Citer : Posté le 13/12/2023 04:33 | #
welll i don't think it's that simple... python.h is not officially supported in gint, maybe you will have to deal with some parts of the Python C API (recode some parts of it, adapte it) and, tbh, i don't think this is really easy x)
But if you're really motivated that would be an amazing project ! I personally think that C>Python for, well, a bunch of reasons, but yeah it would be a very nice-engineered system, and maybe it could bring a lot of people that would'nt usually create add-ins to do so... so, good luck !
Dude, I won't need that. gint is a standalone library. I think the topic depends on my skill in building C (that i don't have now) . I think I can attach it by adding some code to the CMakeLists.txt file. I don't know. I'll try it later.
Citer : Posté le 13/12/2023 11:32 | #
Yeah but you'll have to recompile Python for the casio calculator... for now Python is just a bunch of code built into a library and compiled for your personal processor - you have to compile it for the casio calculator, which I think , is not really simple.
But anyways, we’re doing kind of off-topic x)
Citer : Posté le 13/12/2023 12:32 | #
Yeah but you'll have to recompile Python for the casio calculator... for now Python is just a bunch of code built into a library and compiled for your personal processor - you have to compile it for the casio calculator, which I think , is not really simple.
But anyways, we’re doing kind of off-topic x)
I will use the same method for normal FxSDK Addin and link it to the source files on my system and convert it to an extension with ease. I do not know if this will work.