5

I recently hit a usage problem with astyle that I have been unable to figure out. I am not sure if this is a bug, or I am simply using the astyle tool incorrectly. I am attempting to use the "--exclude" option to omit files and directories from processing, but continue to get an "unmatched" exclude error and astyle terminates:

bwallace$ ls -l foo.c
-rw-r--r-- 1 bwallace 1767304860 22 Aug 1 21:36 foo.c

bwallace$ astyle ./foo.c --exclude=./foo.c -v
Artistic Style 2.04 08/03/2014
Exclude (unmatched) ./foo.c
Artistic Style has terminated

When I pass the "-i" (ignore exclude errors) astyle processes the file as expected. Hence, it seems to be a problem with the "exclude" statement.

bwallace$ astyle ./foo.c --exclude=./foo.c -v -i
Artistic Style 2.04 08/03/2014
Exclude (unmatched) ./foo.c
Unchanged ./foo.c
0 formatted 1 unchanged 0.00 seconds 2 lines

Is this a bug? Am I using astyle incorrectly? Any help would be appreciated.

bwallace
  • 131
  • 1
  • 1
  • 4

2 Answers2

2

Excluding a directory is done using simple string contains matching rather than matching actual directories. I've been having the same issue and figured it out by looking at the source here.

Adding a lot of options is a bit tedious. I've found it's easiest to create an options file. There are instructions on the astyle website about where to put it.

To exclude multiple files or directories you need to have multiple "--exclude" options in the file:

--exclude=dir/subdir1
--exclude=dir/subdir2
jrw10293
  • 21
  • 2
2

Try this: astyle "*.c" --exclude=foo.c - that should do the trick.

The . in your exclude statement is one of the issues. Using a wildcard for Astyle's input ("*.c") also seems to be required. This is definitely weird behaviour on Astyle's side.

An unmatched exclude flag results in an "exclude error" and AStyle terminates. When you add --ignore-exclude-errors, AStyle continues despite this error. I usually add this flag to my options files.

For the record - I'm using AStyle 3.1, so it could be that this improved in the meantime.

Sidelobe
  • 433
  • 7
  • 13