ParsePatternNoCase() and ObtainDirContextTags()

10 posts / 0 new
Last post
jabirulo
jabirulo's picture
Offline
Last seen: 4 weeks 1 day ago
Joined: 2013-05-30 00:53
ParsePatternNoCase() and ObtainDirContextTags()

Hi just noticed that using ParsePatternNoCase() and ObtainDirContextTags() I get something like this:
[gui_resources.c:487 ] searching "STRIDER.gs[0-9]":
[gui_resources.c:511 ] 'STRIDER.gs1'
[gui_resources.c:514 ] slot #1
[gui_resources.c:511 ] 'STRIDER.gs5'
[gui_resources.c:514 ] slot #5
[gui_resources.c:511 ] 'STRIDER.gs3'
[gui_resources.c:514 ] slot #3
[gui_resources.c:511 ] 'STRIDER.gs0'
[gui_resources.c:514 ] slot #0

Just wandering why .gs0 is the last one, shouldn't it be the first match?
Snipped of my code:

  1. ...
  2. IUtility->Strlcpy(filestate, fn, MAX_DOS_FILENAME);
  3. IUtility->Strlcat(filestate, ".gs[0-9]", MAX_DOS_FILENAME);
  4. DBUG(" searching \"%s\":\n",filestate);
  5.  
  6. // Detach chooser list
  7. [...]
  8. // Search selected/active rom savestates
  9. IDOS->ParsePatternNoCase(filestate, pattern_ms, 2+MAX_DOS_FILENAME*2);
  10. context = IDOS->ObtainDirContextTags(EX_StringNameInput, SAVES,
  11. EX_DataFields, (EXF_NAME|EXF_TYPE),
  12. EX_MatchString, pattern_ms,
  13. TAG_END);
  14. if(context) {
  15. struct ExamineData *dat;
  16.  
  17. while( (dat=IDOS->ExamineDir(context)) )
  18. {
  19. if( EXD_IS_FILE(dat) )
  20. {
  21. char slot[2] = "";
  22. DBUG(" '%s'\n",dat->Name);
  23. ...

TiA

EDIT1: seems it takes into account the date of files ¿:-/ so if .gs0 is newer it shows last.
EDIT2: tried to get "initial" behaviour,but now always is sorted correctly ¿:-/

thomas
thomas's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2011-05-16 14:23
Re: ParsePatternNoCase() and ObtainDirContextTags()

Directory entries are returned in no specific order. The order might even change between program executions. It depends on file system implementation and internal structures and maybe caching.

If you want the entries to be ordered, for example names ascending alphabetically, you have to sort them yourself.

jabirulo
jabirulo's picture
Offline
Last seen: 4 weeks 1 day ago
Joined: 2013-05-30 00:53
Re: ParsePatternNoCase() and ObtainDirContextTags()

ok, so if they are sorted it's by pure luck (maybe). thanks

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

cwenzel
cwenzel's picture
Offline
Last seen: 5 months 2 weeks ago
Joined: 2021-01-12 07:05
Re: ParsePatternNoCase() and ObtainDirContextTags()

Example #2 in the latest dos.doc for ExamineDir() has sorting example code.

File attachments: 

AttachmentSize
Plain text icon examinedir_sort_example.txt1.69 KB
OldFart
OldFart's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2010-11-30 14:09
Re: ParsePatternNoCase() and ObtainDirContextTags()

@cwenzel

Example #2 in the latest dos.doc for ExamineDir() has sorting example code.

This example makes mention of function 'SortList' in utility.library, but when looking at the the only documentation on that library, there is no such function to be found. The list jumps from 'SNPrintf' straight to 'Stricmp' and in alphabetical order 'SortList' should be right in between these two. Just an observation.

OldFart

msteed
msteed's picture
Offline
Last seen: 4 months 5 days ago
Joined: 2022-01-18 08:34
Re: ParsePatternNoCase() and ObtainDirContextTags()

@OldFart

Do you have an older version of the SDK, perhaps? I see both SortList() and SortMinList(). They were added in utility.library v. 54.2, which I believe is OS 4.1 FE.

Those functions are missing from the OS4 documentation wiki, which apparently hasn't been updated.

OldFart
OldFart's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2010-11-30 14:09
Re: ParsePatternNoCase() and ObtainDirContextTags()

@msteed

Do you have an older version of the SDK, perhaps?

I was looking at the online documentation on the library. A typo with a pretty high level of severity:

... but when looking at the the only documentation on that library...

, which was meant to read: "...but when looking at the online documentation on the library..." should have clarified my source.
But does this indicate that online documentation is no longer maintained?

OldFart

jabirulo
jabirulo's picture
Offline
Last seen: 4 weeks 1 day ago
Joined: 2013-05-30 00:53
Re: ParsePatternNoCase() and ObtainDirContextTags()

THX didn't know such example.

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

jabirulo
jabirulo's picture
Offline
Last seen: 4 weeks 1 day ago
Joined: 2013-05-30 00:53
Re: ParsePatternNoCase() and ObtainDirContextTags()

Hi, "reopening" this thread, just a doubt:

  1. /* Sort list if utility function available. */
  2. if( LIB_IS_AT_LEAST(UtilityBase, 54, 2) )
  3. {
  4. struct Hook HK =
  5. {
  6. .h_Entry = (HOOKFUNC)compare_name_hookfunc,
  7. .h_Data = (APTR)IUtility
  8. };
  9. IUtility->SortList(&LS, &HK);
  10. }

Why do you "pass" .h_Data = (APTR)IUtility? I have it already open as global.

BTW works great (with my changes to use in a chooser_gd list).

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

cwenzel
cwenzel's picture
Offline
Last seen: 5 months 2 weeks ago
Joined: 2021-01-12 07:05
Re: ParsePatternNoCase() and ObtainDirContextTags()

Why do you "pass" .h_Data = (APTR)IUtility? I have it already open as global.

Out of habit I guess, I usually write re-entrant library type code and rarely use global variables.
I grabbed that example code from an actual piece of working code I tested and just used a
local 'iutil' passd in the hook as h_Data. Just ignore it in the hook() and use IUtility->
I have modified the example in the autodoc to use a global interface everywhere now.
Thanks for being observant.

Log in or register to post comments