Debian Codegraph @

plugins/wdx/scripts/descriptionwdx.lua

raw
1 -- This script reads file descriptions from descript.ion
2
3 function ContentGetSupportedField(Index)
4 if (Index > 0) then
5 return '','', 0; -- ft_nomorefields
6 end
7
8 return 'Description','', 8; -- FieldName,Units,ft_string
9 end
10
11 function ContentGetDefaultSortOrder(FieldIndex)
12 return 1; --or -1
13 end
14
15 function ContentGetDetectString()
16 return 'EXT="*"'; -- return detect string
17 end
18
19 function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
20 if FieldIndex==0 then
21 --Linux paths only
22 local pat="/.*/"
23 i,j=string.find(FileName,pat);
24 if i~=nil then
25 local path=string.sub(FileName,i,j);
26 fn=string.sub(FileName,string.len(path)+1,-1);
27 if fn~=".." then
28 return GetDesc(path,fn);
29 else
30 return "";
31 end
32 end
33 end
34 return nil;
35 end
36
37 function GetDesc(Path,Name)
38 local f=io.open(Path..'descript.ion',"r");
39 if not f then
40 return nil;
41 end
42
43 for line in f:lines() do
44 if string.find(line,Name..' ') then
45 f:close();
46 return string.sub(line,string.len(Name..' ')+1,-1);
47 end
48 end
49
50 f:close();
51
52 return nil;
53 end