Is it possible to get --exclude-ext work only for some specific directories? - cloc

I need to exclude *.c files only from some specific directory/sub_directory. Is this possible?

cloc does not have a built-in way to do that. You can exclude all *.c, or exclude a specific dir/subdir, but not exclude *.c only within a dir/subdir.
A two-step solution comes to mind: you can make a list of files you want to exclude then pass that list file in to cloc with --exclude-list-file, for example,
find dir/subdir -type f -name "*.c" > dont_want_these.txt
cloc --exclude-list-file dont_want_these.txt dir

Related

Remove specific suffix from all files containing it

Long story short, OneDrive has taken all my files and renamed them to include the string "-DESKTOP-9EI0FN7" at the end of the file name, resulting in files such as:
myTextFile-DESKTOP-9EI0FN7.txt
myVideo-DESKTOP-9EI0FN7.mp4
So I'd like to write a batch script that finds all the files with that string in them, and renames them to remove the string, so:
myTextFile-DESKTOP-9EI0FN7.txt becomes myTextFile.txt
The problem is, I know nothing about writing batch files. Any advice?
Test out with this bad boy:
find . -type f -exec rename -n -e 's/(.*)\-DESKTOP\-9EI0FN7(.*)/$1$2/' {} \;
If the output satisfies you, remove the -n portion and it does actually apply the changes.
Good luck, sir!

CLOC --diff and --exclude-dir don't seem to work together

I am trying to compare two directories with multiple subfolders. This is my CLOC script:
cloc-1.76.exe --diff test_initial test_latest --timeout 60 --exclude-dir=ZC_DATA --out=results.txt
Both folders have a ZC_DATA directory. In test_initial it is empty, in test_latest has several C and XML files, therefore lots of code to count.
What I am experiencing is that with or without the switch exclude-dir=ZC_DATA I am getting exactly the same results, no difference at all.
I need a way to include or exclude this folder in order to get different results.
Please advise.
Regards,
M.R.
If you do a straight count of one of the input directories, for example,
cloc-1.76.exe --timeout 60 --exclude-dir=ZC_DATA --out=results.txt test_latest
with and without --exclude-dir=ZC_DATA do the counts change? Repeat the two invocations with the second directory, test_initial, and report if there are differences there as well.
I'm trying to execute a cloc command with --diff AND --exclude-list-file and the files including in .clocignore are not ignored in the result.
Here the cmd:
os.system{'cloc --diff {} {} --exclude-list-file=.clocignore --by-file --out={} --csv'.format (directory1, directory2, output.loc)}
.clocignore file content:
/tmp/workspace/directory2/myfile.cpp
NOTE: this particular file (myfile.cpp) appears in directory2 but it does not exist in directory1.
If diff directory1 - directory2 is not successfully because some files in directory1 do not exist, the result are: the lines counted in directory2, which it is fine!
BUT,
it does not exclude the files contained in ..clocignore
why the --exclude-list-file=.clocignore is not working in this scenario?
Thanks,

How to add multiple include file names under NAMES while using FIND_PATH in CMAKE?

I am trying to include several header files under NAMES while using FIND_PATH, was wondering if there was a way to include them without specifying each one of them.
Currently i use below format for this purpose.
FIND_PATH(FILE_INCLUDE
NAMES "xyz/x.h"
"xy/y.h"
......
......
PATHS "${CMAKE_CURRENT_SOURCE_DIR}"
PATH_SUFFIXES xy/yx/xyz
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
I was wondering if there was a easier way to specify the list of NAMES as there are lot to be added.
CMake provides the following command for recursive files globing:
file(GLOB_RECURSE variable [RELATIVE path] [FOLLOW_SYMLINKS]
[globbing expressions]...) Command documentation:
http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:file

CLOC- count lines of code, exclude everything in a dir except for certain files

I am using cloc to count our code. We need to exclude everything in a directory, except for files with a specific form like *instru.c. Is it possible to use the exclude and include files to do this?

CMake: Managing a list of source files

The problem I'm having at the moment is that I simply wish to manage my list of source files by grabbing everything and removing the few odds and ends that I do not need. I was hoping that Cmake provided nice built-in tools for this.
So I might start with:
file(GLOB A "Application/*.cpp")
I feel like I want to create another list of files to be removed and I want to tell CMake: Remove from list A items that are in list B.
If this were Python I might do something like:
C = [f for f in A if f not in B]
I may have screwed that syntax up but I'm wondering if there is built-in support for managing these lists of files in a more elegant way?
Even if I could do something like my Python example, A is list of absolute paths so constructing B is clunky.
And why absolute paths anyway? It seems like this will break your build as soon as you relocate the source.
You can do that by using the list command with the REMOVE_ITEM option:
list(REMOVE_ITEM <list> <value> [<value> ...])
Have a look:
file(GLOB FOO *)
set (ITEMS_TO_REMOVE "item;item2;item3")
message(STATUS "FOO is ${FOO}")
list(REMOVE_ITEM FOO ${ITEMS_TO_REMOVE})
message(STATUS "FOO is now ${FOO}")
Keep in mind that the paths returned by file(GLOB) are absolute, you might want to build your list of items to remove by prepending ${CMAKE_CURRENT_LIST_DIR} to each one of them:
set (ITEMS_TO_REMOVE "${CMAKE_CURRENT_LIST_DIR}/item;
${CMAKE_CURRENT_LIST_DIR}/item2;
${CMAKE_CURRENT_LIST_DIR}/item3")
If you like Python, you can generate your list of source files with execute_process. There is also possiblity to work with lists.
But I would recommend you to "hardcode" your list of source files.
File command documentation states:
We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate.