2008-08-30 4 views

Antwort

0

Um eine grobe Schätzung erhalten Sie immer find . -type f -exec cat {} \; | wc -l im Projektverzeichnis laufen könnte, wenn Sie Mac OS X.

1

Oder

find . -name '*.as' -or -name '*.mxml' | xargs wc -l 

Oder wenn Sie verwenden zsh

wc -l **/*.{as,mxml} 
verwenden

Es wird Ihnen nicht geben, welcher Teil dieser Zeilen Kommentare oder Leerzeilen sind, aber wenn Sie nur daran interessiert sind, wie sich ein Projekt von einem anderen unterscheidet und Sie beide geschrieben haben, s eine nützliche Metrik.

+0

^Wo verwenden Sie diesen Befehl? Ist dieser FLEX-Compilerbefehl? DOS-Befehl? PERL-Befehle? Python? Ich bin hier verloren. – D3vtr0n

+0

Das ist ein Shell-Befehl. Geben Sie es in ein Terminal in einer Linux- oder OS X-Box ein. – Theo

1

Hier ist ein kleines Skript, das ich geschrieben habe, um die Gesamtanzahl der Vorkommen für verschiedene Quellcodeelemente in ActionScript 3 Code zu finden (dies ist in Python geschrieben, weil ich damit vertraut bin, während Perl wahrscheinlich besser für eine regex lastige Skript wie folgt):

#!/usr/bin/python 

import sys, os, re 

# might want to improve on the regexes used here 
codeElements = { 
'package':{ 
    'regex':re.compile('^\s*[(private|public|static)\s]*package\s+([A-Za-z0-9_.]+)\s*', re.MULTILINE), 
    'numFound':0 
    }, 
'class':{ 
    'regex':re.compile('^\s*[(private|public|static|dynamic|final|internal|(\[Bindable\]))\s]*class\s', re.MULTILINE), 
    'numFound':0 
    }, 
'interface':{ 
    'regex':re.compile('^\s*[(private|public|static|dynamic|final|internal)\s]*interface\s', re.MULTILINE), 
    'numFound':0 
    }, 
'function':{ 
    'regex':re.compile('^\s*[(private|public|static|protected|internal|final|override)\s]*function\s', re.MULTILINE), 
    'numFound':0 
    }, 
'member variable':{ 
    'regex':re.compile('^\s*[(private|public|static|protected|internal|(\[Bindable\]))\s]*var\s+([A-Za-z0-9_]+)(\s*\\:\s*([A-Za-z0-9_]+))*\s*', re.MULTILINE), 
    'numFound':0 
    }, 
'todo note':{ 
    'regex':re.compile('[*\s/][Tt][Oo]\s?[Dd][Oo][\s\-:_/]', re.MULTILINE), 
    'numFound':0 
    } 
} 
totalLinesOfCode = 0 

filePaths = [] 
for i in range(1,len(sys.argv)): 
    if os.path.exists(sys.argv[i]): 
     filePaths.append(sys.argv[i]) 

for filePath in filePaths: 
    thisFile = open(filePath,'r') 
    thisFileContents = thisFile.read() 
    thisFile.close() 
    totalLinesOfCode = totalLinesOfCode + len(thisFileContents.splitlines()) 
    for codeElementName in codeElements: 
     matchSubStrList = codeElements[codeElementName]['regex'].findall(thisFileContents) 
     codeElements[codeElementName]['numFound'] = codeElements[codeElementName]['numFound'] + len(matchSubStrList) 

for codeElementName in codeElements: 
    print str(codeElements[codeElementName]['numFound']) + ' instances of element "'+codeElementName+'" found' 
print '---' 
print str(totalLinesOfCode) + ' total lines of code' 
print '' 

Pass Wege, um alle der Quellcodedateien in Ihrem Projekt als Argument für dieses Skript, um es alle von ihnen zu verarbeiten und die Summen melden.

Ein Befehl wie folgt aus:

find /path/to/project/root/ -name "*.as" -or -name "*.mxml" | xargs /path/to/script 

Will Ausgang dieses so etwas wie:

1589 instances of element "function" found 
147 instances of element "package" found 
58 instances of element "todo note" found 
13 instances of element "interface" found 
2033 instances of element "member variable" found 
156 instances of element "class" found 
--- 
40822 total lines of code 
2

Einfaches Tool namens LocMetrics kann für .as arbeiten Dateien auch ...

+0

Danke! So einfach zu bedienen und ich liebe es, wie es die Daten präsentiert. – khailcs

1

CLOC - http://cloc.sourceforge.net/. Obwohl es auf Windows-Kommandozeilen basiert, funktioniert es mit AS3.0, hat alle Funktionen, die Sie wollen und ist gut dokumentiert. Hier ist das BAT-Datei-Setup, das ich verwende:

REM ===================== 

echo off 

cls 

REM set variables 

set ASDir=C:\root\directory\of\your\AS3\code\ 

REM run the program 

REM See docs for different output formats. 

cloc-1.09.exe --by-file-by-lang --force-lang="ActionScript",as --exclude_dir=.svn --ignored=ignoredFiles.txt --report-file=totalLOC.txt %ASDir% 

REM show the output 

totalLOC.txt 

REM end 

pause 

REM =====================