Is there anyway that we can count the number of lines & comments in an Xcode Project? - xcode8

I need to know the total number of lines and comments of Xcode project.
I have tried CLOC .
CLOC failed to give the result i was looking for.
Please respond!

I would do this in Bash...
Go to the directory your files are in and do something like this.
Assuming the files you want are .swift files.
find YOUR_DIR_HERE -name '*.swift' | xargs wc -l

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!

How to copy and rename multiple files in CMake with wildcards?

I have a CMake project and I need to copy files from one folder to another and do some additional renaming with the following pattern:
"xy-1" will be "abcd1",
"xy-2" will be "abcd2",
...,
"xy-123" will be "abcd123"
Currently I´m trying this with add_custom_command() and in general it works for a simpler pattern like
"xy-1" will be "abc1",
"xy-2" will be "abc2",
...,
"xy-123" will be "abc123",
I´m doing it with
COMMAND copy "${path_to_source_folder}xy-*.txt" "${path_to_destination_folder}abc*.txt"
In the working pattern the number of characters before the asterisk are the same for the source- and the destination-name.
But in the not working pattern, there are 3 characters in the source-name and four characters in the destination-name before the asterisk:
COMMAND copy "${path_to_source_folder}xy-*.txt" "${path_to_destination_folder}abcd*.txt"
This not working. There is no error coming from cmake, but it will not copy all files (only the first 99) and the names are not created properly.
A quick fix would be to list all (400+) files explicitly, but I´d like to avoid this ;-)
How to do this with add_custom_command() or if this is not possible, how to do it in another way?
Many thanks for your help!
Cheers Daniel
Upate:
Thanks for the hints in the comments! I´m running on Windows 10 and using powershell for running cmake.

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 rename photo files using awk, such that they are named (and hence ordered) by "date taken"?

I have 3 groups of photos, from 3 different cameras (with time sychronised onboard all cameras) but with different naming schemes (e.g.: IMG_3142.jpg, DCM_022.jpg). I would like to rename every photo file with the following naming convention:
1_yyyy_mm_dd_hh_mm_ss.jpg for earliest
2_yyyy_mm_dd_hh_mm_ss.jpg for next earliest, and so on,
until we reach around 5000_yyyy_mm_dd_hh_mm_ss.jpg for the last one (i.e. the most recent)
I would like the yyyy_mm_dd_hh_mm_ss field to be replaced by the “date and time taken” value for when this photo was taken. Which is saved in the metadata/properties of each file.
I have seen awk used to carry out similar operations but I'm not familiar enough to know how to access the “time taken” metadata, etc.
Also, not that this should make a difference: my computer is a mac.
You can use jhead for this. The command is:
jhead -n%Y_%m_%d_%H_%M_%S *.jpg
Make a COPY of your files first before running it! You can install jhead with homebrew using:
brew install jhead
Or, if you don't have homebrew, download here for OS X.
That will get you the date in the filename as you wish. The sequence number is a little more difficult. Try what I am suggesting above and, if you are happy with that, we can work on the sequence number maybe. Basically, you would run jhead again to set the file modification times of your files to match the time they were shot - then the files can be made to show up in the listing in date order and we can put your sequence number on the front.
So, to get the file's date set on the computer to match the time it was taken, do:
jhead -ft *.jpg
Now all the files will be dated on your computer to match the time the photos were taken. Then we need to whizz through them in a loop with our script adding in the sequence number:
#!/bin/bash
seq=1
# List files in order, oldest first
for f in $(ls -rt *jpg)
do
# Work out new name
new="$seq_$f"
echo Rename $f as $new
# Remove "#" from start of following command if things look good so the renaming is actually done
# mv "$f" $new"
((seq++))
done
You would save that in your HOME directory as renamer, then you would go into Terminal and make the script executable like this:
chmod +x renamer
Then you need to go to where your photos are, say Desktop\Photos
cd "$HOME/Desktop/Photos"
and run the script
$HOME/renamer
That should do it.
By the way, I wonder how wise it is to use a simple sequence number at the start of your filenames because that will not make them come up in order when you look at them in Finder.
Think of file 20 i.e. 20_2015_02_03_11:45:52.jpg. Now imagine that files starting with 100-199 will be listed BEFORE file 2o, also files 1000-1999 will also be listed before file 20 - because their leading 1s come before file 20's leading 2. So, you may want to name your files:
0001_...
0002_...
0003_...
...
0019_...
0020_...
then they will come up in sequential order in Finder. If you want that, use this script instead:
#!/bin/bash
seq=1
for f in $(ls -rt *jpg)
do
# Generate new name with zero-padded sequence number
new=$(printf "%04d_$f" $seq)
echo Rename $f as $new
# Remove "#" from start of following command if things look good so the renaming is actually done
# mv "$f" $new"
((seq++))
done

Script for Testing with Input files and Output Solutions

I have a set of *.in files and a set of *.soln files with matching files names. I would like to run my program with the *.in file as input and compare the output to the ones found in the *.soln files. What would be the best way to go about this? I can think of 3 options.
Write some driver in Java to list files in the folder, run the program, and compare. This would be hard and difficult.
Write a bash script to do this. How?
Write a python script to do this?
I would go for a the bash solution. Also given that what you are doing is a test, I would always save the output of the myprogram so that if there are failures, that you always have the output to compare it to.
#!/bin/bash
for infile in *.in; do
basename=${infile%.*}
myprogram $infile > $basename.output
diff $basename.output $basename.soln
done
Adding the checking or exit statuses etc. as required by your report.
If the program exists, I suspect the bash script is the best bet.
If your soln files are named right, some kind of loop like
for file in base*.soln
do
myprogram > new_$file
diff $file new_$file
done
Of course, you can check the exit code of diff and
do various other things to create a test report . . .
That looks simplest to me . . .
Karl
This is primarily a problem that requires the use of the file-system with minimal logic. Bash isn't a bad choice for such problems. If it turns out you want to do something more complicated than just comparing for equality Python becomes a more attractive choice. Java doesn't seem like a good choice for a throwaway script such as this.
Basic bash implementation might look something like this:
cd dir_with_files
program=your_program
input_ext=".in"
compare_to_ext=".soIn"
for file in *$from_extension; do
diff <("$program" "$i") "${file:0:$((${#file}-3))}$compare_to_ext"
done
Untested.