Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
Posts: 1
Joined: Sun Feb 20, 2011 8:48 pm


Post by rassul »

AStyle.exe does not work using options: -A3 and -b, I have to run the program two times with each of these two options. Is it a bug or what?
Thanks in advance. :(
Site Admin
Posts: 2476
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Just for your information the astyle.exe is nothing more than stock standard exe found on the Astyle official web page found here:
AStyle.exe does not work using options: -A3 and -b
Now to the issue at hand. Inside Zeus I used the Tools, DOS Command Line menu and ran this command to bring up the AStyle help page:
astyle -?
In the resulting help information I found these two entries:
--style=k&r OR --style=k/r OR -A3
Kernighan & Ritchie style formatting/indenting.
Linux brackets.
--brackets=break OR -b
Break brackets from pre-block code (i.e. ANSI C/C++ style).
So I think the issue you are seeing is the -b is part of the ANSI style and not the K&R style and hence the reason for the need to run the tool twice.

In which case I think there are at least two possible options:

Option 1: Using the AStyle help details from above try tweaking the Zeus Astyle.lua macro options to suit.

Option 2: Edit the Zeus Astyle.lua macro and just run the AStyle.exe a second time using the -b option.

I think the second option is probably the simplest.

The version of the Zeus Astyle.lua macro that I run is shown below (note your version might be different).

I have indicated in the code below where I would be making changes for the Option 1:[/1] or Option 2:[/1] changes.

Cheers Jussi

Code: Select all

--        Name: Astyle Code Reformating Macro
--    Language: Lua Macro
-- Description: This macro will excute the astyle.exe utility to reformat
--              the current file. For more details on how to use astyle.exe
--              visit the following web page:

function key_macro()
  -- dialog box caption
  local caption = "Astyle Utility"

  -- macro only works for documents
  local document = is_document()

  -- macro only works for read/write documents.
  local locked = is_read_only()

  -- macro only works for named documents.
  local named = is_named()

  if (locked == 1) or (document == 0) or (named == 0) then
    -- can't run astyle.exe on current document
    message("This macro can only be run with a named, writable document file.")

  -- the directory of the current document
  local dir = macro_tag("$fdd")

  -- the name of the current document
  local file_name = macro_tag("$f")

  -- the name of the backup document
  local file_backup = file_name .. ".orig"

  local message1 = "Astyle is ready to re-style the current file, while the following backup\nfile will also be created:\n\n         '" .. file_backup .."'\n"
  local message2 = "NOTE: Astyle is specifically designed to work with C, C++ and Java\nfiles, so if the styling does not work as expected use backup file to\nundo the changes made.\n\nDo you want to continue with the styling?"

  local message_text = message1 .. "\n" .. message2

  -- run astyle.exe on current document
  local result = 6; --message_box(4, message_text, caption)

  -- check for the IDYES return value
  if (result == 6) then
      message("Astyle is formatting the code....")
      message("Operation canceled by user.")

  -- ===================================================================
  -- Predefined Styling options:
  -- ===================================================================
  --     --style=ansi
  --     ANSI style formatting/indenting.
  --     --style=kr
  --     Kernighan&Ritchie style formatting/indenting.
  --     --style=gnu
  --     GNU style formatting/indenting.
  --     --style=java
  --     Java mode, with standard java style formatting/indenting.
  --     --style=linux
  --     Linux mode (i.e. 8 spaces per indent, break definition-block
  --     brackets but attach command-block brackets.
  --     --break-blocks  OR  -f
  --     Insert empty lines around unrelated blocks, labels, classes, ...
  --     --break-blocks=all  OR  -F
  --     Like --break-blocks, except also insert empty lines
  --     around closing headers (e.g. 'else', 'catch', ...).
  --     --break-closing-brackets  OR  -y
  --     Break brackets before closing headers (e.g. 'else', 'catch', ...).
  --     --pad-oper  OR  -p
  --     Insert space paddings around operators.
  --     --pad-paren  OR  -P
  --     Insert space padding around parenthesis on both the outside
  --     and the inside.
  --     --pad-paren-out  OR  -d
  --     Insert space padding around parenthesis on the outside only.
  --     --pad-paren-in  OR  -D
  --     Insert space padding around parenthesis on the inside only.
  --     --pad-header  OR  -H
  --     Insert space padding after paren headers (e.g. 'if', 'for'...).
  --     --indent-namespaces  OR  -N
  --     Indent the contents of namespace blocks.
  --     --indent-switches  OR  -S
  --     Indent 'switch' blocks, so that the inner 'case XXX:'
  --     headers are indented in relation to the switch block.
  --     --indent-cases  OR  -K
  --     Indent case blocks from the 'case XXX:' headers.
  --     Case statements not enclosed in blocks are NOT indented.
  --     --unpad-paren  OR  -U
  --     Remove unnecessary space padding around parenthesis.  This
  --     can be used in combination with the 'pad' options above.
  --     --keep-one-line-blocks  OR  -O
  --     Don't break blocks residing completely on one line.
  --     --keep-one-line-statements  OR  -o
  --     Don't break lines containing multiple statements into
  --     multiple single-statement lines.
  --     --align-pointer=type    OR  -k1
  --     --align-pointer=middle  OR  -k2
  --     --align-pointer=name    OR  -k3
  --     Attach a pointer or reference operator (* or &) to either
  --     the operator type (left), middle, or operator name (right).
  --     --convert-tabs  OR  -c
  --     Convert tabs to the appropriate number of spaces.
  -- ===================================================================

  -- ***** Option 1 Modify these options to suit *****

  --local cmd_padding = "--pad-oper --pad-paren-out --unpad-paren "
  local cmd_padding = "--pad-oper " --pad-paren-out "

  -- indent command line options (see above)
  local cmd_indent  = "--indent-namespaces --indent-switches --indent-col1-comments --indent-preprocessor "

  -- break command line options (see above)
  local cmd_break = "--break-blocks --break-closing-brackets "

  -- other command line options (see above)
  local cmd_other  = "--align-pointer=name --keep-one-line-blocks --keep-one-line-statements --max-instatement-indent=79 "

  -- build up the full command line option (see above)
  local cmd_options = "--style=ansi " .. cmd_padding .. cmd_indent .. cmd_other .. cmd_break

  -- get the tab size for the current document
  local tab_size = macro_tag("$TabSize")

  -- see if real tabs are to be used
  local use_tabs = macro_tag("$UseTabs")

  if (use_tabs == "true") then
    -- add the tabs option
    cmd_options = cmd_options .. " " .. "--indent=tab=" .. tab_size
    -- add the spaces option
    cmd_options = cmd_options .. " " .. "--indent=spaces=" .. tab_size .. "--convert-tabs"

  -- build up the final styling command line
  local cmd = "astyle.exe" .. " " ..  cmd_options  .. " \"" .. file_name .. "\""

  -- for debugging only
  --message_box(1, cmd, "Command Line", caption)

  -- System control values
  --  1 - save the document before running the program
  --  2 - capture any standard output generated by the program
  --  4 - capture any standard error generated by the program
  --  8 - ask for additional arguments
  -- 16 - the program will use the MS-DOS command interpreter (ie. dir *.* etc)
  -- 32 - wait for the program to complete (the ESC key will cancel the wait)
  -- 64 - run the program in a visible DOS session (otherwise runs hidden)

  -- run command using the 'save' and 'wait for complete' options
  local flags = 1+32

  -- run the astyle.exe command
  if (system(cmd, dir, flags) == 0) then
    -- ***** Option 2 Uncomment these lines (untested) *****
    -- build up the final styling command line
    -- local cmd = "astyle.exe -b \"" .. file_name .. "\""
    -- for debugging only
    -- message_box(1, cmd, "Option 2 Command Line", caption)
    -- system(cmd, dir, flags)

    -- reload the newly styled docuemnt

    -- get the current window id
    local id = get_window_id()

    -- build the name of the backup file
    local backup_file = dir .. file_backup

    -- load the backup file as well
    if file_open(backup_file) == 1 then
      -- re-activate the reformated file

    -- some feedback
    message("The styling of the document is now complete.")
    -- had problems running the command
    local error_msg = cmd .. "\n\n" .. "Error executing the 'astyle.exe' command!"
    message_box(1, error_msg, caption)

key_macro() -- run the macro
Posts: 3
Joined: Sat Apr 30, 2011 11:45 pm

Post by autocart »

Sorry for my dumb question, but where is the astyle.exe file located that the script is using? I can't find it anywhere. Thx.

Regards, Stephan
Site Admin
Posts: 2476
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

JFYI this is where the command line is built to run the astyle.exe executable.

Code: Select all

  -- build up the final styling command line 
  local cmd = "astyle.exe" .. " " ..  cmd_options  .. " \"" .. file_name .. "\"" 
and you can view the command line by un-commenting this line:

Code: Select all

  -- for debugging only 
  --message_box(1, cmd, "Command Line", caption)
Now back to your question:
where is the astyle.exe file located that the script is using?
As you can see from above there is no location specified in the command line.

The actual location of the executable is here: C:\Program Files\zeus\zGNU

The reason this works is Zeus will ensure the above folder is always defined in it's private version of the PATH environment variable.

Cheers Jussi
Post Reply