maxlen in content plugins

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

maxlen in content plugins

Post by *tbeu »

It would be useful if a WDX plugin developer could determine the maximum length of the ft_string field type. Currently the maxlen parameter is a parameter to functions ContentGetValue() and ContentEditValue(). It is also a hidden limitation of ContentSetValue().

I noticed that maxlen is always 2^10. However JPG comment supports a maximum length of 2^16. So there is a limitation that only 2^10 characters can be set by the content plugin.

Additionally, I noticed that "Load from file under cursor" will display only 258 = MAX_PATH - 2 characters although maxlen characters are retrieved from the plugin by ContentGetValue(). If the >> button is clicked afterwards with flags=editflags_initialize then the FieldValue in ContentEditValue() is only 258 characters long and not maxlen as expected.
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50479
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

I noticed that maxlen is always 2^10. However JPG comment supports a maximum length of 2^16. So there is a limitation that only 2^10 characters can be set by the content plugin.
Just copy only as many characters to the buffer as TC tells you. In Delphi, there is a function strlcopy for that. Here is the equivalent in C/C++:

Code: Select all

char* strlcpy(char* p,const char* p2,int maxlen)
{
	if ((int)strlen(p2)>=maxlen) {
		strncpy(p,p2,maxlen);
		p[maxlen]=0;
	} else
		strcpy(p,p2);
	return p;
}
Additionally, I noticed that "Load from file under cursor" will display only 258 = MAX_PATH - 2 characters although maxlen characters are retrieved from the plugin by ContentGetValue(). If the >> button is clicked afterwards with flags=editflags_initialize then the FieldValue in ContentEditValue() is only 258 characters long and not maxlen as expected.
This is due to limitations of the operating system (MAXLEN-1 is the maximum path length supported by Ansi file system functions).
Author of Total Commander
https://www.ghisler.com
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

ghisler(Author) wrote:Just copy only as many characters to the buffer as TC tells you.
This is of course what is done. But buffer size of TC is too short. There is no chance to specify the buffer size. Buffer size maxlen = 2^10 might be suitable for custom columns view, however larger maxlen is possible for the field edit window of ContentEditField(). Do you think a user-specified maxlen is possible?
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50479
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

No, that's not possible. But I could use a larger buffer for the field edit, where it really would make sense...
Author of Total Commander
https://www.ghisler.com
User avatar
Lefteous
Power Member
Power Member
Posts: 9536
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2ghisler(Author)
But I could use a larger buffer for the field edit, where it really would make sense...
I'm not sure if a larger buffer for writing fields would make sense if it's not used in the read functions. In other words: A string would be written which cannot be displayed.

Support for fields of type fulltext would be also nice :-)
Post Reply