Re: get full prototype of a function

Shigio YAMAGUCHI <[email protected]> Thu, 18 Feb 2016 13:22:42 +0900
Newsgroups gmane.comp.gnu.global.general
Message-ID <CADJmJYpWzHAbzioV7rZvAYu3N6Woo0gQceYeLMXZVksu7NyK7Q@mail.gmail.com>
--===============8371920480211085363==
Content-Type: multipart/alternative; boundary=001a11c344f0ba48d0052c03b746

--001a11c344f0ba48d0052c03b746
Content-Type: text/plain; charset=UTF-8

Hi,
Though it cannot said an easy way, you can do it using the ctags plug-in
parser.
You need to modify both Exuberant Ctags and the ctags plug-in parser like
follows:

1. Exuberant Ctags (version 5.8): writeXrefEntry() in entry.c

[BEFORE]
    length += writeCompactSourceLine (TagFile.fp, line);

[AFTER]
    if (Option.extensionFields.signature && tag->extensionFields.signature
!= NULL)
        length += fprintf (TagFile.fp, "signature:%s",
tag->extensionFields.signature);
    else
        length += writeCompactSourceLine (TagFile.fp, line);

2. Ctags plug-in parser (GLOBAL_6.5.2): plugin-factory/exuberant-c

[BEFORE]
#if defined(USE_EXTRA_FIELDS)
        "--_xformat=%R %-16N %4n %-16F %C",
        "--extra=+r",
#else
        "--format=1",
#endif

[AFTER]
#if defined(USE_EXTRA_FIELDS)
        "--_xformat=%R %-16N %4n %-16F %C",
        "--extra=+r",
        "--fields=+rS",
#else
        "--format=1",
        "--fields=+S",
#endif

3. The result

$ global -x main
main                2 main.c           signature:( int argc, char *argv[] )

Regards,
Shigio


2016-02-18 7:45 GMT+09:00 john smith <[email protected]>:

> Is this possible to get a full prototype of a given function in a
> standardized, easily parsable form?  The point is I need to get a
> number of parameters for a number of functions as I am writing a
> custom REPL-like tool that will call functions from an external API.
> I need to know how many parameters every function takes in order to
> inform user that he gave too few parameters. What I do now is this:
>
> $ gtags -v -f LIST
> $ global -f diff.h
> foo                 5 diff.h           foo(
>
> But it doesn't show any arguments that foo() takes.  It's written like
> this in a source file:
>
> void
> foo(
> int a,
>          int b, int c, char
> *f)
> {
> }
>
> It's possible to do this in ctags:
>
> $ ctags  --fields=+S diff.h
> $ less tags
> (...)
> foo     diff.h  /^foo($/;"      f       signature:( int a, int b, int
> c, char *f)
>
> Now I can easily parse `signature:part' and get a number of
> parameters.  I could use ctags but I got used to global, is this
> possible here?
>
> --
> <[email protected]>
>
> _______________________________________________
> Help-global mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/help-global
>



-- 
Shigio YAMAGUCHI <[email protected]>
PGP fingerprint: D1CB 0B89 B346 4AB6 5663  C4B6 3CA5 BBB3 57BE DDA3

--001a11c344f0ba48d0052c03b746
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div>Hi,</div><div>Though it cannot said an easy way,=
 you can do it using the ctags plug-in parser.</div><div>You need to modify=
 both Exuberant Ctags and the ctags plug-in parser like follows:</div><div>=
<br></div><div>1. Exuberant Ctags (version 5.8): writeXrefEntry() in entry.=
c</div><div><br></div><div>[BEFORE]</div><div>=C2=A0 =C2=A0 length +=3D wri=
teCompactSourceLine (TagFile.fp, line);</div><div><br></div><div>[AFTER]</d=
iv><div>=C2=A0 =C2=A0 if (Option.extensionFields.signature &amp;&amp; tag-&=
gt;extensionFields.signature !=3D NULL)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 length +=3D fprintf (TagFile.fp, &quot;signature:%s&quot;, tag-&gt;exte=
nsionFields.signature);</div><div>=C2=A0 =C2=A0 else</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 length +=3D writeCompactSourceLine (TagFile.fp, line);</d=
iv><div><br></div><div>2. Ctags plug-in parser (GLOBAL_6.5.2): plugin-facto=
ry/exuberant-c</div></div><div><br></div><div><div>[BEFORE]</div><div>#if d=
efined(USE_EXTRA_FIELDS)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 &quot;--_xfo=
rmat=3D%R %-16N %4n %-16F %C&quot;,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 &=
quot;--extra=3D+r&quot;,</div><div>#else</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 &quot;--format=3D1&quot;,</div><div>#endif</div><div><br></div><div>[AF=
TER]</div><div>#if defined(USE_EXTRA_FIELDS)</div><div>=C2=A0 =C2=A0 =C2=A0=
 =C2=A0 &quot;--_xformat=3D%R %-16N %4n %-16F %C&quot;,</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 &quot;--extra=3D+r&quot;,</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 &quot;--fields=3D+rS&quot;,</div><div>#else</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 &quot;--format=3D1&quot;,</div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 &quot;--fields=3D+S&quot;,</div><div>#endif</div><div><br></div><div=
>3. The result</div><div><br></div><div>$ global -x main</div><div>main =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A02 main.c =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 signature:( int argc, char *argv[] )</div><div><br></d=
iv><div>Regards,<br></div><div>Shigio</div></div><div><br></div></div><div =
class=3D"gmail_extra"><br><div class=3D"gmail_quote">2016-02-18 7:45 GMT+09=
:00 john smith <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" t=
arget=3D"_blank">[email protected]</a>&gt;</span>:<br><blockquote class=3D"=
gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-=
left:1ex">Is this possible to get a full prototype of a given function in a=
<br>
standardized, easily parsable form?=C2=A0 The point is I need to get a<br>
number of parameters for a number of functions as I am writing a<br>
custom REPL-like tool that will call functions from an external API.<br>
I need to know how many parameters every function takes in order to<br>
inform user that he gave too few parameters. What I do now is this:<br>
<br>
$ gtags -v -f LIST<br>
$ global -f diff.h<br>
foo=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A05 diff.h=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0foo(<br>
<br>
But it doesn&#39;t show any arguments that foo() takes.=C2=A0 It&#39;s writ=
ten like<br>
this in a source file:<br>
<br>
void<br>
foo(<br>
int a,<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int b, int c, char<br>
*f)<br>
{<br>
}<br>
<br>
It&#39;s possible to do this in ctags:<br>
<br>
$ ctags=C2=A0 --fields=3D+S diff.h<br>
$ less tags<br>
(...)<br>
foo=C2=A0 =C2=A0 =C2=A0diff.h=C2=A0 /^foo($/;&quot;=C2=A0 =C2=A0 =C2=A0 f=
=C2=A0 =C2=A0 =C2=A0 =C2=A0signature:( int a, int b, int<br>
c, char *f)<br>
<br>
Now I can easily parse `signature:part&#39; and get a number of<br>
parameters.=C2=A0 I could use ctags but I got used to global, is this<br>
possible here?<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br>
--<br>
&lt;<a href=3D"mailto:[email protected]">[email protected]</a>&gt;<br>
<br>
_______________________________________________<br>
Help-global mailing list<br>
<a href=3D"mailto:[email protected]">[email protected]</a><br>
<a href=3D"https://lists.gnu.org/mailman/listinfo/help-global" rel=3D"noref=
errer" target=3D"_blank">https://lists.gnu.org/mailman/listinfo/help-global=
</a><br>
</font></span></blockquote></div><br><br clear=3D"all"><div><br></div>-- <b=
r><div class=3D"gmail_signature"><div dir=3D"ltr">Shigio YAMAGUCHI &lt;<a h=
ref=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a>&gt;<div>=
PGP fingerprint: D1CB 0B89 B346 4AB6 5663 =C2=A0C4B6 3CA5 BBB3 57BE DDA3<br=
></div></div></div>
</div>

--001a11c344f0ba48d0052c03b746--


--===============8371920480211085363==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Help-global mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-global

--===============8371920480211085363==--