home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- // Object Scripting
- // Copyright (c) 1996, 1997 by Borland International, All Rights Reserved
- //
- // FINDTABS.SPP: Find Tabs. Searches all .C, .H, .CPP, .HPP, and .SPP
- // files in the specified directory and reports all lines that have
- // at least one tab character to the message database. Double-click a
- // message to edit the referenced file. Useful for coding styles
- // that don't use tab characters.
- //
- // USE: Run script, and enter 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");
-
- findtabs()
- {
- declare msg = new TMsg();
-
- // 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 (CheckForTabs(dir + "\\" + file)) {
- gotOne = TRUE;
- }
- }
- file = FindNextFile();
- }
- IDE.EndWaitCursor();
-
- // Show the Tabs page of the message MPD if something to report.
- //
- if (gotOne) {
- IDE.ViewMessage("Tabs");
- }
- else {
- msg.Info("No tabs 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 with tabs, and reports them to the
- // message database. Returns TRUE if at least one is found.
- //
- CheckForTabs(file)
- {
- declare checkFile = new TFlatFile(file);
- declare sLine = new String();
- declare gotOne = FALSE;
- declare col;
- for (declare i = 0; i < checkFile.EdPos.LastRow; i++) {
- checkFile.EdPos.Move(i + 1, 1);
- sLine.Text = checkFile.EdPos.Read();
- col = sLine.Index("\t");
- if (col) {
- IDE.MessageCreate("Tabs", "", INFORMATION, 0, file, i + 1, col,
- "", NULL, NULL);
- gotOne = TRUE;
- }
- }
- checkFile.Close();
- return gotOne;
- }
-
-
-
-
-