LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Ini_Sort / sort section name ?

hello,

 

can somebody told me how i can sort an ini-file?
if I use Ini_Sort it sorted to me section name and tag name, but I would like only sort by section name.

thanks 

0 Kudos
Message 1 of 5
(3,912 Views)

What is so bad about having a sorted tag list in a section?

 

If it is really critical, I think you need to sort it yourself: 

- Create 2 ini file objects

- Use one of them to read from the unsorted file and the second one to build your section-sorted file.

- First, read all sections into an array, sort them (you can use strcmp function to compare strings)

- Write to the second file by reading each section's tags using their index (therefore without sorting)

- Save your ini file to the disk, it is ready to use for your purposes.

 

Maybe there is an easier way I do not know of, but that's all I can come up with right now.

Hope this helps, 

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 5
(3,885 Views)

the problem is solved by myself.

 

ebalci, the problem with the tag list was. that the ini-file should have the tags in a fixed order

0 Kudos
Message 3 of 5
(3,868 Views)

Well, a possible alternative solution is to modify the IniFile instrument driver, which is distributed in source code. Ini_Sort function is this one:

 

void    CVIFUNC Ini_Sort(IniText theIniText)
{
    int index;
    int numSections;

    if( !theIniText )
        return;

    numSections = ListNumItems(theIniText->sectionList);

    for (index = 1; index <= numSections; index++)
        {
        IniSection  currentSection;

        ListGetItem(theIniText->sectionList, &currentSection, index);
        ListQuickSort(currentSection->entryList, Ini_CompareEntryNames);
        currentSection->sorted = TRUE;
        }

    ListQuickSort(theIniText->sectionList, Ini_CompareSectionNames);
    theIniText->sorted = TRUE;
}

Commenting out the part in red should do the trick (sort only the section list and not the item list of every section).

If you want to try this way, I suggest you make a copy of the instrument driver files and try loading it as an instrument, next attaching the source code and executing it in the IDE to test it before generating the obj again for the modified version. It's not a way that I'd happy to follow since this modification must be 1. Well documented, and 2. Replicated on every update that reinstalls the instrument. Nevertheless you may want to consider it in your development activity.

 

As a side note, do not rely heavily on the order of entries in a ini file: the instrument does not guarantee that this is maintained over time. In particular, new items are always appended to the end of the section regardless the position in which you have placed the corresponding Ini_Put function in your code.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 5
(3,863 Views)

When you create an ini-file object and read an ini file into it, the file is extracted into the memory and the sorting is again performed in memory.

 

Your file does not get modified just becuase you selected to sort the file.

It loads the section and tags into memory in alphabetical order, that is it... 

 

You can still preserve the specific order you want.

However, in order to access them correctly you should use the tag names instead of their index.

Because the tag indices are modified once they are sorted.

 

Hope this helps, 

S. Eren BALCI
IMESTEK
0 Kudos
Message 5 of 5
(3,844 Views)