Skip to content

Commit 3f73702

Browse files
committed
Move helper functions out of Magic.gi
1 parent 3993c8b commit 3f73702

2 files changed

Lines changed: 68 additions & 68 deletions

File tree

gap/Magic.gi

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,74 +5,6 @@
55
#
66
# SPDX-License-Identifier: GPL-2.0-or-later
77

8-
# Given a string containing a ".", , return its suffix,
9-
# i.e. the bit after the last ".". For example, given "test.txt",
10-
# it returns "txt".
11-
BindGlobal( "AUTODOC_GetSuffix",
12-
function(str)
13-
local i;
14-
i := Length(str);
15-
while i > 0 and str[i] <> '.' do i := i - 1; od;
16-
if i = 0 then return ""; fi;
17-
return str{[i+1..Length(str)]};
18-
end );
19-
20-
# Scan the given (by name) subdirs of a package dir for
21-
# files with one of the given extensions, and return the corresponding
22-
# filenames, as relative paths (relative to the package dir).
23-
#
24-
# For example, the invocation
25-
# AUTODOC_FindMatchingFiles(pkgdir, [ "gap/" ], [ "gi", "gd" ]);
26-
# might return a list looking like
27-
# [ "gap/AutoDocMainFunction.gd", "gap/AutoDocMainFunction.gi", ... ]
28-
BindGlobal( "AUTODOC_FindMatchingFiles",
29-
function (pkgdir, subdirs, extensions)
30-
local result, JoinRelativePath, AddMatchingFiles, d_rel;
31-
32-
result := [];
33-
34-
JoinRelativePath := function( dir, entry )
35-
if dir = "" then
36-
return entry;
37-
fi;
38-
return Concatenation( dir, "/", entry );
39-
end;
40-
41-
AddMatchingFiles := function( abs_dir, rel_dir, recursive )
42-
local abs_dir_obj, entries, entry, abs_entry, rel_entry;
43-
44-
abs_dir_obj := Directory( abs_dir );
45-
entries := DirectoryContents( abs_dir_obj );
46-
Sort( entries );
47-
for entry in entries do
48-
if entry = "." or entry = ".." then
49-
continue;
50-
fi;
51-
abs_entry := Filename( abs_dir_obj, entry );
52-
rel_entry := JoinRelativePath( rel_dir, entry );
53-
if IsDirectoryPath( abs_entry ) then
54-
if recursive then
55-
AddMatchingFiles( abs_entry, rel_entry, true );
56-
fi;
57-
elif AUTODOC_GetSuffix( entry ) in extensions and
58-
IsReadableFile( abs_entry ) then
59-
Add( result, rel_entry );
60-
fi;
61-
od;
62-
end;
63-
64-
for d_rel in subdirs do
65-
if d_rel = "" or d_rel = "." then
66-
AddMatchingFiles( Filename( pkgdir, "" ), "", false );
67-
elif not IsDirectoryPath( Filename( pkgdir, d_rel ) ) then
68-
continue;
69-
else
70-
AddMatchingFiles( Filename( pkgdir, d_rel ), d_rel, true );
71-
fi;
72-
od;
73-
return result;
74-
end );
75-
768
#
779
InstallGlobalFunction( AutoDoc,
7810
function( arg )

gap/ToolFunctions.gi

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,74 @@
55
#
66
# SPDX-License-Identifier: GPL-2.0-or-later
77

8+
# Given a string containing a ".", , return its suffix,
9+
# i.e. the bit after the last ".". For example, given "test.txt",
10+
# it returns "txt".
11+
BindGlobal( "AUTODOC_GetSuffix",
12+
function(str)
13+
local i;
14+
i := Length(str);
15+
while i > 0 and str[i] <> '.' do i := i - 1; od;
16+
if i = 0 then return ""; fi;
17+
return str{[i+1..Length(str)]};
18+
end );
19+
20+
# Scan the given (by name) subdirs of a package dir for
21+
# files with one of the given extensions, and return the corresponding
22+
# filenames, as relative paths (relative to the package dir).
23+
#
24+
# For example, the invocation
25+
# AUTODOC_FindMatchingFiles(pkgdir, [ "gap/" ], [ "gi", "gd" ]);
26+
# might return a list looking like
27+
# [ "gap/AutoDocMainFunction.gd", "gap/AutoDocMainFunction.gi", ... ]
28+
BindGlobal( "AUTODOC_FindMatchingFiles",
29+
function (pkgdir, subdirs, extensions)
30+
local result, JoinRelativePath, AddMatchingFiles, d_rel;
31+
32+
result := [];
33+
34+
JoinRelativePath := function( dir, entry )
35+
if dir = "" then
36+
return entry;
37+
fi;
38+
return Concatenation( dir, "/", entry );
39+
end;
40+
41+
AddMatchingFiles := function( abs_dir, rel_dir, recursive )
42+
local abs_dir_obj, entries, entry, abs_entry, rel_entry;
43+
44+
abs_dir_obj := Directory( abs_dir );
45+
entries := DirectoryContents( abs_dir_obj );
46+
Sort( entries );
47+
for entry in entries do
48+
if entry = "." or entry = ".." then
49+
continue;
50+
fi;
51+
abs_entry := Filename( abs_dir_obj, entry );
52+
rel_entry := JoinRelativePath( rel_dir, entry );
53+
if IsDirectoryPath( abs_entry ) then
54+
if recursive then
55+
AddMatchingFiles( abs_entry, rel_entry, true );
56+
fi;
57+
elif AUTODOC_GetSuffix( entry ) in extensions and
58+
IsReadableFile( abs_entry ) then
59+
Add( result, rel_entry );
60+
fi;
61+
od;
62+
end;
63+
64+
for d_rel in subdirs do
65+
if d_rel = "" or d_rel = "." then
66+
AddMatchingFiles( Filename( pkgdir, "" ), "", false );
67+
elif not IsDirectoryPath( Filename( pkgdir, d_rel ) ) then
68+
continue;
69+
else
70+
AddMatchingFiles( Filename( pkgdir, d_rel ), d_rel, true );
71+
fi;
72+
od;
73+
return result;
74+
end );
75+
876
# Ensure that the directory named by the given path string exists, creating any
977
# missing parent directories on the way. Relative paths are accepted and `.` /
1078
# `..` components are normalized before creating directories.

0 commit comments

Comments
 (0)