Zeus IDE Forum Index Zeus IDE
Use this forum to ask for help, submit a bug report or make a suggestion.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

BCPP C/C++ Code Beautifier V1.9

 
Post new topic   Reply to topic    Zeus IDE Forum Index -> Tutorials, Tips and Tricks
View previous topic :: View next topic  
Author Message
jussij
Site Admin


Joined: 13 Aug 2004
Posts: 2216

PostPosted: Wed Feb 28, 2007 10:43 pm    Post subject: BCPP C/C++ Code Beautifier V1.9 Reply with quote

I found this C/C++ code beautifier:

Quote:
C/C++ Code Beautifier V1.9

Written by Steven De Toni December 1995
Updated by Thomas Dickey January 1997

http://dickey.his.com/bcpp/bcpp.html

The above link only contains the source code, so I created a Windows build of this code which can be found here:

http://www.zeusedit.com/z300/bcpp_exe.zip

A typical command line to format example.cpp and write the beautified code to result.cpp would be:

Quote:
c:\bcpp\bcpp.exe -fnc c:\bcpp\bcpp.cfg -fi example.cpp -fo result.cpp

If you add the c:\bcpp\ instalation directory to the PATH environment variable the following command line can be used instead:
Quote:
bcpp.exe -fi example.cpp -fo result.cpp

In this case the bcpp.exe will go looking for the bcpp.cfg by searching the PATH environment variable.

Dispite the fact the number of configuration options provided seem fairly limited (i.e. just the bare minimum), IMHO it does a very good job of cleaning up the code Wink

Cheers Jussi
Back to top
View user's profile Send private message Send e-mail
jussij
Site Admin


Joined: 13 Aug 2004
Posts: 2216

PostPosted: Thu Mar 01, 2007 1:40 am    Post subject: Reply with quote

It is possible to integrate BCPP directly into Zeus as follows:

Step 1:
Create a bcpp.cmd batch file to first backup then format the file supplied:
Code:
@echo off

if %1 == "" goto BadInputData
if %2 == "" goto BadInputData

REM Make a backup copy of the file
if not exist %1 goto Failed
copy %1 %2

REM Make sure we have the backup copy
if not exist %2 goto Failed

REM Reformat the file by formating the backup copy
echo bcpp.exe -fi %2 -fo %1
bcpp.exe -fi %2 -fo %1

REM Success
goto End

REM BadInputData
:BadInputData
Echo Bad input data provided.
Echo USAGE: bcpp.cmd "$fn" "$zdzBackup\$f"
exit -1

REM Failed
:Failed
Echo Unexpected error with input files!
exit -1

:End
exit 0


Step 2:
Put the bcpp.cmd batch file in the Zeus install directory and run the batch file using the following bcpp.lua Lua macro:
Code:
--
--        Name: BCPP Lua Macro
--
--      Author: Jussi Jumppanen
--
--    Language: Lua Macro
--
-- Description: This simple Lua macro will run the bcpp.cmd
--              which will formats the currently active file.
--

function key_macro()
  -- macro only works for documents
  if is_document() == 0 then
    message("This macro only works for document files!")
    beep()
    return
  end

  -- macro only works for read/write documents
  if is_read_only() == 1 then
    message("The current document is marked as read only!")
    beep()
    return
  end

  -- build up the file names
  local file_source = macro_tag("$fn")
  local file_backup = macro_tag("$zdzBackup\\") .. macro_tag("$f")

  -- build up the command line
  local cmd = "bcpp.cmd \"" .. file_source .. "\" \"" .. file_backup .. "\""

  message("BCPP Comand:" .. cmd)

  -- help with debugging
  -- message_box(1, cmd)

  -- setup command control falgs (see Zeus Macro help for more details)
  --  1 : save the document before running the program
  -- 16 : the program uses MS-DOS command interpreter (ie. dir *.* etc)
  -- 32 : wait for the program to complete (the ESC key will cancel the wait)
  local flags = 1+16+32

  -- run command
  system(cmd, "", flags)

  -- relaod teh formated file
  FileReloadCurrent()

  message("Formating complete")
end

key_macro() -- run the macro

Cheers Jussi
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Zeus IDE Forum Index -> Tutorials, Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group