home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- // Object Scripting
- // Copyright (c) 1996, 1997 by Borland International, All Rights Reserved
- //
- // LONGLINE.SPP: Long Line Finder. Searches all .C, .H, .CPP, .HPP, and .SPP
- // files in the specified directory and reports all lines that are longer
- // than a given threshold value to the message database. Double-click a
- // message to edit the referenced file.
- //
- // USE: Run script, and enter the line length threshold and search directory.
- //
- // FILES: FILE.SPP, MSG.SPP
- //--------------------------------------------------------------------------
- print typeid(module());
-
- //
- // IDE import(s).
- //
- import scriptEngine;
- import IDE;
-
- //
- // Load support module(s).
- //
- if (!scriptEngine.IsLoaded("file")) scriptEngine.Load("file");
- if (!scriptEngine.IsLoaded("msg")) scriptEngine.Load("msg");
-
- //
- // Constant for the default line length threshold.
- //
- #define DEFAULT_THRESHOLD "78"
-
- longline()
- {
- declare msg = new TMsg();
-
- // Get the threshold line length.
- //
- declare limit;
- limit = IDE.SimpleDialog("Enter the threshold line length.", DEFAULT_THRESHOLD);
- if (limit == "") return;
-
- // Get the search directory.
- //
- declare dir;
- dir = IDE.SimpleDialog("Enter the search directory.", IDE.CurrentDirectory);
- if (dir == "") return;
-
- // Walk the directory, searching files that are source.
- //
- IDE.StartWaitCursor();
- declare gotOne = FALSE;
- declare file = FindFirstFile(dir + "\\*.*");
- while (file != "") {
- if (IsSource(file)) {
- if (CheckLongLines(dir + "\\" + file, limit)) {
- gotOne = TRUE;
- }
- }
- file = FindNextFile();
- }
- IDE.EndWaitCursor();
-
- // Show the Longline page of the message MPD if something to report.
- //
- if (gotOne) {
- IDE.ViewMessage("Longline");
- }
- else {
- msg.Info("No lines exceeding threshold found.");
- }
- }
-
- //
- // Returns TRUE if the filename passed is .C, .H, .CPP, .HPP, or .SPP;
- // FALSE otherwise.
- //
- IsSource(file)
- {
- declare sTmp = new String(file);
- sTmp = sTmp.Lower();
-
- // Look for extension as last characters of the string.
- //
- if (sTmp.Index(".c") + 1 == sTmp.Length ||
- sTmp.Index(".h") + 1 == sTmp.Length ||
- sTmp.Index(".cpp") + 3 == sTmp.Length ||
- sTmp.Index(".hpp") + 3 == sTmp.Length ||
- sTmp.Index(".spp") + 3 == sTmp.Length) {
- return TRUE;
- }
- return FALSE;
- }
-
- //
- // Searches the file for lines exceeding the threshold length, and
- // reports them to the message database. Returns TRUE if at least one
- // violation is found.
- //
- CheckLongLines(file, threshold)
- {
- declare checkFile = new TFlatFile(file);
- declare sLine = new String();
- declare gotOne = FALSE;
- declare length;
- for (declare i = 0; i < checkFile.EdPos.LastRow; i++) {
- checkFile.EdPos.Move(i + 1, 1);
- sLine.Text = checkFile.EdPos.Read();
- length = sLine.Length;
- if (sLine.Index("\r\n")) length -= 2; // Account for new line characters.
- if (length > threshold) {
- IDE.MessageCreate("Longline", "", INFORMATION, 0, file, i + 1, 1,
- " " + length, NULL, NULL);
- gotOne = TRUE;
- }
- }
- checkFile.Close();
- return gotOne;
- }
-
-
-
-
-