Codebase list lua-ldoc / adcd9c5
better soln for issue #73: partial sorting for all processed files Steve Donovan 10 years ago
2 changed file(s) with 32 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
418418
419419 function M.process_file_list (list, mask, operation, ...)
420420 local exclude_list = list.exclude and M.files_from_list(list.exclude, mask)
421 local files = List()
421422 local function process (f,...)
422423 f = M.abspath(f)
423424 if not exclude_list or exclude_list and exclude_list:index(f) == nil then
424 operation(f, ...)
425 files:append(f)
425426 end
426427 end
427428 for _,f in ipairs(list) do
428429 if path.isdir(f) then
429430 local files = List(dir.getallfiles(f,mask))
430431 for f in files:iter() do
431 process(f,...)
432 files:append(f)
432433 end
433434 elseif path.isfile(f) then
434 process(f,...)
435 files:append(f)
435436 else
436437 quit("file or directory does not exist: "..M.quote(f))
437438 end
439 end
440 if list.sortfn then
441 files:sort(list.sortfn)
442 end
443 for f in files:iter() do
444 operation(f,...)
438445 end
439446 end
440447
260260 end
261261 end
262262
263 local function fixup_module_file (file, fullpath)
264 if args.module_file then
265 for mname, f in pairs(args.module_file) do
266 if f == file then
267 args.module_file[mname] = fullpath
268 args.module_file[fullpath] = true
269 return "master for "..mname
270 end
271 end
272 end
273 return ''
274 end
275
276 -- partial sort of file list, where anything in module_file is now upfront!
277 local function reorder_module_file (files)
278 if args.module_file then
279 local mf = args.module_file
280 table.sort(files,function(x,y) return mf[x] and not mf[y] end)
281 end
282 end
283
284263 local abspath = tools.abspath
285264
286265 -- a special case: 'ldoc .' can get all its parameters from config.ld
294273 lfs.chdir(config_path)
295274 end
296275 config_is_read = true
297 override 'module_file'
298276 args.file = ldoc.file or '.'
299277 if args.file == '.' then
300278 args.file = lfs.currentdir()
301279 elseif type(args.file) == 'table' then
302280 for i,f in ipairs(args.file) do
303281 args.file[i] = abspath(f)
304 fixup_module_file(f,args.file[i])
305 end
306 reorder_module_file(args.file)
282 end
307283 else
308284 args.file = abspath(args.file)
309285 end
386362 override 'colon'
387363 override 'merge'
388364 override 'not_luadoc'
365 override 'module_file'
366
367 -- ldoc.module_file establishes a partial ordering where the
368 -- master module files are processed first.
369 local function reorder_module_file ()
370 if args.module_file then
371 local mf = {}
372 for mname, f in pairs(args.module_file) do
373 local fullpath = abspath(f)
374 mf[fullpath] = true
375 end
376 return function(x,y)
377 return mf[x] and not mf[y]
378 end
379 end
380 end
389381
390382 if type(args.file) == 'table' then
391383 -- this can only be set from config file so we can assume it's already read
384 args.file.sortfn = reorder_module_file()
392385 process_file_list(args.file,'*.*',process_file, file_list)
393386 if #file_list == 0 then quit "no source files specified" end
394387 elseif path.isdir(args.file) then
405398 end
406399 end
407400 end
401 -- process files, optionally in order that respects master module files
402 local sortfn = reorder_module_file()
403 if sortfn then files:sort(sortfn) end
408404 for f in files:iter() do
409405 process_file(f, file_list)
410406 end
407
411408 if #file_list == 0 then
412409 quit(quote(args.file).." contained no source files")
413410 end