How to count the number of lines of code and the number of lines of code

Source: Internet
Author: User

How to count the number of lines of code and the number of lines of code
How to count the number of lines of code

  • Linux provides many practical tools, even on Android, which are included in the transplanted busybox.
  • According to the KISS concept, these tools have a single function. However, by combining these tools, we can calculate the amount of code.
Count the number of lines of code
  • The process is as follows: first use the find command to find all source code files with the correct suffix names, and then use the wc command to count the number of lines. The number of files may be too large. To prevent errors, use the xargs command to split the parameter list. You can use sort to sort the final result.
  • Command for counting the number of lines in all c source code:find -name *.c | xargs wc -l |sort -r. Results are arranged in reverse order.
  • find -name *.c | xargs wc -l |sort -k2Results are arranged by file name
  • To calculate the c ++ code, Set*.cChange*.ccYou can. If c ++ uses the cpp extension name, change it*.cpp
Detailed description of the commands used
  • The find command recursively searches for directories. If any file makes the expression true, it is placed in the result.
  • Usagefind [path...] [expression]
  • Path specifies the directory range to be searched. The default value is the current directory.
  • Expression is usually a test condition. true or false is returned.
  • -name patternThe file name conforms to the shell regular expression.
  • -path patternThe file path name conforms to the shell regular expression.
  • -exec order {}Execute the command. If the return value is 0, it is true.
  • Example:find -name *.cSearch for files suffixed with c
  • Example:find . -exec sleep {1}Display an object every 1 s
Wc command
  • Wc stands for wordcount and is used for statistics files.
  • Usagewc [-lwc] filename
  • L, w, and c indicate the number of rows, words, and characters respectively. All three are counted by default.
  • Example:wc -l file1 file2Count the number of rows in two files
Xargs command
  • Xargs is used to capture the output of the previous command in the pipeline, create a segmentation parameter table, and execute another command.
  • If the parameter column generated by the find command is too long, you can use the xargs command to pass only some parameters at a time to prevent overflow errors in some systems.
  • Xargs usually uses spaces or line breaks to separate parameters,-0Option to ensure that the parameter column contains spaces, line breaks, and so on.
  • Example:find /tmp -name core | xargs -0 /bin/rm -f. Set/tmpAll files named core in the folder are passed to the rm command and deleted forcibly.-0Option to ensure that the file name contains line breaks or spaces.
Sort command
  • Sort is used to sort different texts in behavior units.
  • The default sorting method is ascending,-rOption can be changed to descending order
  • -nThe options are sorted by the value of the number, as shown in figure1 2 10 20If this option is not enabled, the sorting result is1 10 2 20
  • -fCase Insensitive
  • -tSet the delimiter between columns,-kSort by Column
  • Example:sort -n -f -k 2 test.txt. Sort the rows in test.txt by the second column, case insensitive
Redirection
  • The statistical result of the number of rows can be saved to a text file.> count.txtYou can.
  • Standard input, output, and error output are represented by 0, 1, and 2, respectively.
  • Input redirection use the input redirection Operator<, You can use the content in the file as the input of the program. For example:./a.out < test.inThe test. in file contains the test input of the program.
  • Output redirection can write the output of a program to a file and use the output redirection operator.>.
    • Example:ls 1>/dev/null 2>/dev/nullOutput and error output are not displayed. No space is allowed between 1, 2, and>.
    • Example:ls 2> &1> t.txtThe error output is redirected to the standard output, while the standard output is not redirected. Because the standard output content is written to t.txt, the error output remains on the screen.
    • Example:ls 1> t.txt 2> &1Write both standard output and error output to t.txt.
MPs queue
  • MPs queue usage|Indicates
  • The function is to convert the standard output of the previous command to the standard input of the second command.
  • The second command must be read from the standard input, as shown in figurelsCommand does not meet the requirements

 
 

Reprinted by: Focustc. The blog address is http://blog.csdn.net/caozhk. The original link is opened by clicking
 
 
How to Use the C # language to count the number of lines of code in a file and provide code

Using (StreamReader sr = new StreamReader (@ "c: \ a. cs "))
{
Int cnt = 0;
While (sr. ReadLine ()! = Null)
{
Cnt ++;
}
// This cnt is the number of rows
}

How does one calculate the number of lines of code at the function layer in the file?

What is SDK? -[]

What is SDK?
[Posting 23:49:09] poster: Don't let me go

I often see such posts in technical forums: "What is SDK ?", "Could you tell me what the SDK is ?"......

In fact, the SDK is short for Software Development Kit, which means "Software Development Kit" in Chinese ". This is a widely used term. It can be said that the collection of documents, examples, and tools used to assist in the development of a certain type of software can be called "sdks ". In this series of tutorials, we will only discuss a subset of the general SDK-the SDK used to develop applications on the Windows platform.

In fact, the above is just a general concept of the SDK. Is it so easy to understand what the SDK is? I'm afraid it's not that easy! In order to explain what the SDK is, we have to introduce the concepts of API, dynamic link library, and import/export library. ^ _ ^, Don't be afraid, that is, just a few new terms. I realized that learning new terms is actually learning new terms, new concepts, and new terms at the end of the University.

The first thing to contact is the "API", that is, the Application Programming Interface, which is actually a call Interface left by the operating system for the Application, by calling the API of the operating system, an application enables the operating system to execute commands (Actions) of the application ). In fact, as early as the DOS era, there was an API concept, but at that time the API was provided in the form of Interrupt calls (INT 21 h, all applications running under DOS use the operating system functions directly or indirectly through interrupt calls, for example, if you set AH to 30 h and call INT 21 h, you can get the dos OS version number. In Windows, system APIs are provided through function calls. In Windows, you need to call the GetVersionEx () function. In this case, the dos api is "Thinking in assembly language", while the Windows API is "Thinking in advanced language. DOS APIs are part of system programs. They are loaded into the memory together with the system and can be found through the interrupt vector table. What about Windows APIs? To understand this problem, we have to introduce this concept-DLL.

DLL (also an abbreviation, I feel that there are many acronyms in the IT industry), that is, Dynamic Link Library (Dynamic Link Library ). We often see files in. dll format. These files are dynamic link library files, but they are also executable files. Unlike. exe files,. dll files cannot be executed directly. They are usually imported by. exe during execution, which contains some resources and executable code. In fact, the three modules of Windows are provided in the form of DLL (Kernel32.dll, User32.dll, GDI32.dll), which contains the Execution Code of API functions. To use the API functions in DLL, we must have an API function declaration (. h) and its import to the database (. LIB), the function prototype declaration is not difficult to understand, so what is the purpose of importing data into the database? For the moment, we first understand that import and export are used to find the API entry point in the DLL.

Therefore, in order to use API functions, we need to have corresponding APIs. H and. the SDK provides a complete set of related files, examples, and tools required to develop Windows applications ". So far, we have explained the meaning of the SDK.

Because the SDK contains the required information for using APIs, it is also often used to compile Windows ...... the remaining full text>
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.