The
Writes a rough C-language code line statistic script, and there are still some bugs, and the efficiency is not high. The script is mainly to remove most of the annotation after the number of lines, equivalent to doing a part of preprocessing work. Here's the code:
#!/bin/bash filename=$1 echo "' WhoAmI '" if [$#-lt 1];then echo "usage:./scripts filename" exit-1 fi if [!-F
$filename];then echo "$filename is not a file" exit 0;
Fi user= "' WhoAmI '" If ["$user"!= "root"];then echo "Use scripts with Root" exit 0; Fi #删除空行, empty rows include: Tables + space sed '/^[[:blank:]]*$/d ' $filename > "${filename}_backup" #删除//The line Sed-i '/^[[:blank: ]]*\/\//d ' "${filename}_backup" #/*xxxxx*/#打印/* All start lines grep-n ' [[: blank:]]*/[*] ' "${filename}_backup" | awk ' begin{fs= ': "}{print" > "Start.txt" #打印 * * all end lines grep-n ' [*]/[[:blank:]]* ' ${filename}_backup '] | awk ' begin{fs= ': "}{print" > "End.txt" #合并两个文件, final.txt each line is/*xx....\n....xx*/the start and start line numbers for this type of comment paste " Start.txt "End.txt" > "final.txt" while read line do #得到起始行 start= ' echo ' $line | awk ' begin{fs= ' \ t '}{print $} ' #得到结束行 end= ' echo ' $line | awk ' begin{fs= ' \ T "}{print $}" #这里有一个bug, AS/* and/* in/*xxxx*/, in the same line, and there is code in the same line # printf ("Hello world\n"); /* Print String */#/* Print string/#上Face two kinds of situation can not judge, hope everybody optimizes if [$START-eq $END];then continue fi #删除/* to all Sed-i "${start},${end}d" "${filename}_backu" P "Done <" final.txt "Wc-l" ${filename}_backup "rm-f" Final.txt "" Start.txt "" End.txt "
Scripts can only achieve the approximate number of lines of code statistics, can not do accurate statistics!
Because there are not many tests to do, and I do not rule out some of the more rare comments I did not consider the efficiency of the script is also relatively poor, with a lot of TMP files.
So I hope you can make a lot of comments!