1

Is there a way of using the -wrap option for all functions defined in a source file, without listing them by hand?

I thought about some wildcard for that option, but my research resulted in nothing. I also considered investigating a way for extraction of source file functions with make, also without success.

Is there any other way to do it?

jalooc
  • 1,169
  • 13
  • 23

1 Answers1

1

You may use ctags as suggested here, sed to add -wrap in front of each and inject the result on the command line.

--- Edit ---

For example, something like:

a=`ctags -o- --fields=-fkst --c-kinds=f myprint.c | cut -f1 | sed -e 's/^\(.*\)/-wrap \1/g'`
echo $a

would give you:

-wrap main -wrap myprint

You can also combine everything in one line:

ld ... `ctags -o- --fields=-fkst --c-kinds=f myprint.c | cut -f1 | sed -e 's/^/-wrap /'`
Community
  • 1
  • 1
Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
  • Okay, with this command: `ctags -o- --fields=-fkst --c-kinds=f ../file.c`I managed to print to standard output a list of lines, each containing the following, `tab`-separated values: tag name, path and EX command. This is said to be the standard _ctags_ format. However I need a list of sole tag names, comma-separated. I couldn't find anything in the docs, nor other sources. Is there a way to achieve this through _ctags_ options or I have to use external tools? (btw we're working on windows, so `sed` is not an option). – jalooc Nov 18 '15 at 09:49
  • use `cut` (to extract the first field, `sed` to add commas, `xargs` to obtain a list, etc. Any other tool like `awk` could be your friend to parse a list and transform it. – Jean-Baptiste Yunès Nov 18 '15 at 11:56
  • I had to add just: | tr '\n' ' ' at the end to make it display in one line and works like a charm :) Now my final _makefile_ instruction looks like this: `CTAGS_WRAP = ./ctags.exe -o- --fields=-fkst --c-kinds=f myFile.c | cut -f1 | sed -e 's/^/-wrap /' | tr '\n' ' '` which prints `-wall f1 -wall f2 -wall f3 ...` – jalooc Nov 19 '15 at 18:19
  • 1
    Sorry, to be precise it's `CTAGS_WRAP = ./ctags.exe -o- --fields=-fkst --c-kinds=f myFile.c | cut -f1 | sed -e 's/^/-Wl,-wrap,/' | tr '\n' ' ' ` to get the output in form: `-Wl,-wrap,f1 -Wl,-wrap,f2 -Wl,-wrap,f3 ...` for use with `ld`. (I couldn't edit the previous comment). – jalooc Nov 19 '15 at 19:35