/****************************************************************** * void linecount() * * Created by: Wesley Wilk, SlickEdit * Created on: June 1, 2003 * * * Linecount will scroll thru every file of every project in your workspace, * and will provide a total count of all lines of code, meaning minus all * comments and blank lines. * * Output can be one of two ways: * 1) Output buffer listing the total count plus the number of lines * per file * 2) Message box stating the total lines only. * This can be toggled by changing the displayResultsInBuffer value below. * * * You have the ability to toggle between a detailed displayed in an edit * window, or or a simple message box stating the total number of lines. * To change, simply toggle the displayResultsInBuffer value at the * beginning of this macro. * * Note that the output will be created in a new file called * LineCountResults.txt. If this buffer is open and you run this macro * again, the text will be appended at the location of the cursor, * so make sure to place the cursor at the bottom. * * ******************************************************************* * * VARIATIONS: * * Since you have full control of this code, you can modify this as you * please. Here is one suggestion that you may want to consider * * * Remove message box alert if a file is missing * --------------------------------------------- * * If a file included in the project is missing in the actual file * system, the default action is to display a message box alerting the * user. In some scenarios, this may be 'as designed' and the user may * not want to be alerted, if so, simply comment out the following line in * the first for loop: * * _message_box( "Error accessing file: "ProjectFileList[pLength][i][1] ); * * * * *******************************************************************/ #include "slick.sh" _command void linecount() { // Toggle this flag to set the results to a new buffer, or just get a dialog box. boolean displayResultsInBuffer = true; // Create a three-dimensional array to store file information for the final report. // ProjectFileList[i][0][0] - Project Name // ProjectFileList[i][0][1] - Number of files in project // ProjectFileList[i][0][2] - Number of lines in project // ProjectFileList[i][j][1] - File Name (j>0) // ProjectFileList[i][j][2] - Number of Lines _str ProjectFileList[][][]; _str WorkspaceProjectList[]; int fileCount = 0; int orig_view_id = p_view_id; int temp_view_id; numLines=0; // Validate that a project is open (If a project is open, a workspace is open) if (_project_name == '') { _message_box('This macro requires a project to be open.'); return; } /*********************************************************************** * * Gather Workspace, Project, and File Information * ************************************************************************/ status = _GetWorkspaceFiles( _workspace_filename,WorkspaceProjectList); /*********************************************************************** * Save the list of Project names. ************************************************************************/ for ( wLength=0; wLength < WorkspaceProjectList._length(); ++wLength) { ProjectFileList[wLength][0][0] = _AbsoluteToWorkspace(WorkspaceProjectList[wLength]); } // Now loop thru each Project to access the files in each Project for ( pLength = 0; pLength < WorkspaceProjectList._length(); ++pLength ) { int numberFilesInProject = 0; int numberLinesInProject = 0; /********************************************************************* * Save the list of filenames per project. **********************************************************************/ // GetProjectFiles will get all files in the given project and will add them // to a temporary buffer (temp_view_id), one filename per line status = GetProjectFiles(ProjectFileList[pLength][0][0], temp_view_id); if (!status) { // Status of 0 = success p_view_id = temp_view_id; top();up(); // scroll down temp buffer and create an array of strings for (i = 1; !down(); i++) { get_line(line); ProjectFileList[pLength][i][1] = _parse_project_command(maybe_quote_filename(line), "", ProjectFileList[pLength][0][0],""); } p_view_id = orig_view_id; _delete_temp_view(temp_view_id); } else { // Error. This shouldn't happen. _message_box("Status = "status". GetProjectFiles() failed."); p_view_id = orig_view_id; _delete_temp_view(temp_view_id); } //p_view_id = orig_view_id; /********************************************************************* * Loop down one file at a time and count the lines of code, * (non-comment and non-blank lines) **********************************************************************/ for (i=1; i