home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / SCRPTEXM.PAK / FINDTABS.SPP < prev    next >
Encoding:
Text File  |  1997-05-06  |  2.8 KB  |  113 lines

  1. //--------------------------------------------------------------------------
  2. // Object Scripting
  3. // Copyright (c) 1996, 1997 by Borland International, All Rights Reserved
  4. //
  5. // FINDTABS.SPP: Find Tabs. Searches all .C, .H, .CPP, .HPP, and .SPP
  6. //   files in the specified directory and reports all lines that have
  7. //   at least one tab character to the message database. Double-click a
  8. //   message to edit the referenced file. Useful for coding styles
  9. //   that don't use tab characters.
  10. //
  11. // USE: Run script, and enter search directory.
  12. //
  13. // FILES: FILE.SPP, MSG.SPP
  14. //--------------------------------------------------------------------------
  15. print typeid(module());
  16.  
  17. //
  18. // IDE import(s).
  19. //
  20. import scriptEngine;
  21. import IDE;
  22.  
  23. //
  24. // Load support module(s).
  25. //
  26. if (!scriptEngine.IsLoaded("file")) scriptEngine.Load("file");
  27. if (!scriptEngine.IsLoaded("msg")) scriptEngine.Load("msg");
  28.  
  29. findtabs()
  30. {
  31.   declare msg = new TMsg();
  32.  
  33.   // Get the search directory.
  34.   //
  35.   declare dir;
  36.   dir = IDE.SimpleDialog("Enter the search directory.", IDE.CurrentDirectory);
  37.   if (dir == "") return;
  38.  
  39.   // Walk the directory, searching files that are source.
  40.   //
  41.   IDE.StartWaitCursor();
  42.   declare gotOne = FALSE;
  43.   declare file = FindFirstFile(dir + "\\*.*");
  44.   while (file != "") {
  45.     if (IsSource(file)) {
  46.       if (CheckForTabs(dir + "\\" + file)) {
  47.         gotOne = TRUE;
  48.       }
  49.     }
  50.     file = FindNextFile();
  51.   }
  52.   IDE.EndWaitCursor();
  53.  
  54.   // Show the Tabs page of the message MPD if something to report.
  55.   //
  56.   if (gotOne) {
  57.     IDE.ViewMessage("Tabs");
  58.   }
  59.   else {
  60.     msg.Info("No tabs found.");
  61.   }
  62. }
  63.  
  64. //
  65. // Returns TRUE if the filename passed is .C, .H, .CPP, .HPP, or .SPP;
  66. // FALSE otherwise.
  67. //
  68. IsSource(file)
  69. {
  70.   declare sTmp = new String(file);
  71.   sTmp = sTmp.Lower();
  72.  
  73.   // Look for extension as last characters of the string.
  74.   //
  75.   if (sTmp.Index(".c") + 1 == sTmp.Length ||
  76.       sTmp.Index(".h") + 1 == sTmp.Length ||
  77.       sTmp.Index(".cpp") + 3 == sTmp.Length ||
  78.       sTmp.Index(".hpp") + 3 == sTmp.Length ||
  79.       sTmp.Index(".spp") + 3 == sTmp.Length) {
  80.     return TRUE;
  81.   }
  82.   return FALSE;
  83. }
  84.  
  85. //
  86. // Searches the file for lines with tabs, and reports them to the
  87. // message database. Returns TRUE if at least one is found.
  88. //
  89. CheckForTabs(file)
  90. {
  91.   declare checkFile = new TFlatFile(file);
  92.   declare sLine = new String();
  93.   declare gotOne = FALSE;
  94.   declare col;
  95.   for (declare i = 0; i < checkFile.EdPos.LastRow; i++) {
  96.     checkFile.EdPos.Move(i + 1, 1);
  97.     sLine.Text = checkFile.EdPos.Read();
  98.     col = sLine.Index("\t");
  99.     if (col) {
  100.       IDE.MessageCreate("Tabs", "", INFORMATION, 0, file, i + 1, col,
  101.                         "", NULL, NULL);
  102.       gotOne = TRUE;
  103.     }
  104.   }
  105.   checkFile.Close();
  106.   return gotOne;
  107. }
  108.  
  109.  
  110.  
  111.  
  112.  
  113.