Strip'em Add-in for Visual Studio 6.0

This article was contributed by Itay Szekely - etay@writeme.com.

Environment: Windows NT/9x, Visual C++ 6

This Add-in converts the text format of a file when it is saved in Visual Studio.
This can be very useful when working in a mixed Windows-Unix environment. In Unix, end of lines in text files are identified by line feed characters. In Windows - they are identified by a combination of carriage return and line feed.
This add-in makes sure that files will be saved the way you. want. When invoked, it opens a dialog box in which you can select the text mode you need.

Strip'em Dialog


Setup

Copy Stripem.dll to any place you want. A good place would be under the Microsoft Visual Studio folder at Common\MSDev98\AddIns

Open Visual Studio and select: Tools | Customize...

Go to the Add-ins and Macro files tab and click on the Browse button.

Go to the folder to which you copied Stripem.dll and select it. Make sure the Files of type listbox is on Add-ins (.dll).

When closing the dialog, a toolbar will appear with the Strip'em button. Using the customize dialog you can move this button to any other toolbar (if you want to).

Pressing the button will open a dialog box in which you can select the text mode you want to use.


Possible problems

After saving a file, the add-in kicks in and start replacing carriage returns and line feeds. If the file is opened in Visual Studio, it will open a dialog box saying that the file has changed, and will ask if you want to reload it. This is quite annoying so you can set up Visual Studio to automatically reload changed files. To do this, select: Tools | Options | Editor, and check "Automatic reload of externally modified files".
This add-in was built with Visual C++ 6.0 with service pack 3. I haven't tested it with other versions, so you can take your chance. I heard from a friend that it didn't work with DevStudio/Visual C++ 5, so he downloaded the source, compiled it and then it worked.

If the add-in doesn't "remember" its previous settings between Visual Studio sessions, check the registry for the following key:

HKEY_CURRENT_USER\Software\Microsoft\DevStudio\6.0

This is where Visual Studio saves its data and where the add-in creates its sub-keys. If it doesn't exist you may have a Visual Studio setup problems. If the key exists, it should have the following sub-key:

AddIns\Stripem.DSAddIn.1

This is where the add-in saves its data. If the key doesn't exist, create it manually and see if it works.

Version History

  • Version 1.01.0

  • Added a new option: save in Windows mode. Until now you could either remove CR characters or do nothing. Now you can convert single LF characters to CR+LF pairs - convert from Unix to Windows format.

  • Version 1.00.2

  • First release outside my small beta tester comunity.

    Downloads

    Download Strip'em Add-in - 18 Kb
    Download source - 21 Kb


    Comments

    • Clear of undo history

      Posted by Legacy on 09/11/2002 12:00am

      Originally posted by: Adi Goldberg

      Although this code is great and do its job, I have 2 comments regarding:

      1. As mentioned already, it is very slow on big files.
      2. When used it clears the undo history buffer.

      Is there any solution for the 2nd problem ?

      Best Regards,
      adi

      Reply
    • Useful, but very slowly ...

      Posted by Legacy on 07/19/2002 12:00am

      Originally posted by: Yuriy

      This add-in is very useful, but main algorithm is slowly, I rewrote it. (you can check it, please try work with network file with size => 100 kb)
      
      

      I can put another approach here and also resolve problem
      with bytes like 0xD 0xD 0xA = 0xA (unix) or
      = 0xD 0xA (windows)

      void crlf_lf(const char* src_path, bool to_unix)
      {
      char* src_buff = 0, *tmp_name = 0;
      long buf_size = 0;
      int src_file = -1;

      try
      {
      // 1. Copy file to buffer.
      ...

      // 2. Remove CR from buffer, main algorithm
      long iw = 0;
      for(long ir = 0; ir < buf_size; ++ir)
      {
      if ( src_buff[ir] ^ 0xD ) src_buff[iw++] = src_buff[ir];
      }

      // 3. Open file, deny write access.
      int oflag = _O_TEXT; if ( to_unix ) oflag = _O_BINARY;
      src_file = _sopen(src_path, oflag | _O_WRONLY, _SH_DENYWR );
      if( src_file == -1 ) throw GetLastError();

      // 4. Write buffer to file.
      if ( _write(src_file, src_buff, iw) == -1 ) throw GetLastError();
      else if ( to_unix )
      {
      // 5. Change size of the file.
      if ( _chsize(src_file, iw) == -1 ) throw GetLastError();
      }
      }
      catch( ... )
      {
      _close( src_file ); delete [] src_buff;
      throw;
      }

      _close( src_file ); delete [] src_buff;
      }

      PS. If to_unix == true file will be saved in Unix format another in Windows.

      Good luck!

      Reply
    • problems with w2k

      Posted by Legacy on 04/18/2002 12:00am

      Originally posted by: Yann

      I can't have it work as a simple user on w2k
      It works as an administrator, who I am not...

      any hint ?

      Reply
    • Fix SaveAll

      Posted by Legacy on 02/07/2001 12:00am

      Originally posted by: urcin

      use the Document,Not get_ActiveDocument:
      
      ((IGenericDocument*) theDocument)->get_FullName(&filenamew);

      Reply
    • problem with stripem and Save All

      Posted by Legacy on 12/13/2000 12:00am

      Originally posted by: Rob van Berkel

      When I use Save All in VC++ 6.0, stripem doesn't stripe all the files it saves. I must save every file individually. Is there a solution?

      Reply
    • Fix for DevStudio 5.0

      Posted by Legacy on 02/05/2000 12:00am

      Originally posted by: George

      In the file Commands.cpp replace
      
      

      CComBSTR filenamew(MAX_PATH, NULL);

      with:
      CComBSTR filenamew(MAX_PATH, (LPCOLESTR)NULL);

      Full:

      HRESULT CCommands::XApplicationEvents::DocumentSave(IDispatch* theDocument)
      {
      AFX_MANAGE_STATE(AfxGetStaticModuleState());

      // Save the files (if enabled)
      if (gStripM != SM_NONE)
      {
      IGenericDocument *pDocument;
      m_pCommands->GetApplicationObject()->get_ActiveDocument((IDispatch **)&pDocument);
      if (pDocument)
      {
      // Get the document file name
      #if _MSC_VER >= 1200
      // VS 6.0 or more
      CComBSTR filenamew(MAX_PATH);
      #else
      CComBSTR filenamew(MAX_PATH, (LPCOLESTR)NULL);
      #endif
      pDocument->get_FullName(&filenamew);

      Reply
    Leave a Comment
    • Your email address will not be published. All fields are required.

    Top White Papers and Webcasts

    • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

    • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today makes data protection a must-have, as we live in a data-driven society -- the digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join Seagate Cloud …

    Most Popular Programming Stories

    More for Developers

    Latest Developer Headlines

    RSS Feeds