Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #128031
| Subject | Re: Dropping C |
|---|---|
| Newsgroups | comp.lang.c |
| References | (10 earlier) <0OQrC.13909$qM7.8865@fx29.iad> <n1SrC.158620$_91.29492@fx02.am4> <1bk1u8x78k.fsf@pfeifferfamily.net> <o%TrC.159938$a15.75205@fx22.am4> <fhagsnF5omlU2@mid.individual.net> |
| From | bartc <bc@freeuk.com> |
| Message-ID | <MlVrC.26148$qo7.8063@fx04.am4> (permalink) |
| Organization | virginmedia.com |
| Date | 2018-03-19 20:47 +0000 |
On 19/03/2018 19:20, Ian Collins wrote:
> On 03/20/2018 08:15 AM, bartc wrote:
>> On 19/03/2018 18:14, Joe Pfeiffer wrote:
>>> bartc <bc@freeuk.com> writes:
>>>
>>>> On 19/03/2018 15:36, Scott Lurndal wrote:
>>>>> bartc <bc@freeuk.com> writes:
>>>>>
>>>>>> BTW I've been meaning to ask this for a while: given an ordinary text
>>>>>> editor, and given the name of a function, how do you find that
>>>>>> function
>>>>>> definition in a source file? I mean, going straight there rather then
>>>>>> scanning a hundred other occurrences of the name before you get to
>>>>>> the
>>>>>> definition.
>>>>>
>>>>> With vim, you have the choice of ctags or cscope databases
>>>>> to allow direct access to the definition (e.g. with cscope or
>>>>> ctags, <CTRL>-}
>>>>> over an identifier will
>>>>> go directly to the definition, even if it is in a different source
>>>>> file.
>>>>> <CTRL>-T will return to the prior file/line. The tag stack can be
>>>>> arbitrarily
>>>>> deep.
>>>>>
>>>>
>>>> That'll work from a general editor? Like Notepad?
>>>
>>> Vim is, of course, a general editor. If you meant to ask specifically
>>> about Notepad, you should have said Notepad in the question.
>>
>> I obviously mean any editor that just edits text and knows nothing about
>> ctags or cscopes or databases or identifiers.
>>
>> (How would a function definition get into such a database anyway. You
>> download a C project; does it come with such databases, or do you have
>> to run some utilities first?)
>>
>> What I'm getting at is that there is no simple syntax form that can help
>> ANY editor to trivially find any specific function. Or to not find it,
>> if it exists outside of this source file.
>
> ctags and vi are almost as old as C...
OK, that's what I thought. A general editor won't do it, not unless you
rope in the services of a separate program (a complicated one by the
sound of it) to do all the work, which also sounds like it has to
thoroughly understand and half-compile C source code.
But an Editor plus Special Add-on doesn't equal General Purpose Editor.
It's just another illustration of how C source syntax isn't really fit
for purpose, because of all these numerous add-on programs you have to
use to be able to work with it.
OK, let's throw down a challenge: how short a program can you write in
pure C, to take any C source file, and produce a list of the function
definitions and what line numbers they are on.
You're not allowed to just use system("ctags"), as we're trying to
establish exactly how big a job the design of the language makes this task.
To make it a bit easier, you don't need to bother with dealing with
#includes, #ifs, macros (which can change the results if fully
expanded), comments, and string constants (both of which can contain
what look like definitions).
It that is still too hard, you can rope in the help of another language.
I can tell you I can do this for my language with the following C code.
(And using a dynamic language, it's trivial.) This version lazily just
prints the whole line (so 'extractname' is a misnomer).
-----------------------------------------------------------
#include <stdio.h>
#include <string.h>
char* extractname(char* line) {
int length=strlen(line);
char* prefixes[] = {
"global proc ",
"global function ",
"proc ",
"function "};
int i,plen;
for (i=0; i<4; ++i) {
plen=strlen(prefixes[i]);
if (plen<length && memcmp(prefixes[i],line,plen)==0) {
return line;
}
}
return NULL;
}
int main(void) {
char linebuffer[16384];
FILE* fh;
char *fnname;
int lineno=0;
fh=fopen("/pcl/pc_handlers.m","r");
if (fh) {
while (fgets(linebuffer,sizeof(linebuffer),fh)) {
++lineno;
fnname=extractname(linebuffer);
if (fnname)
printf("%5d: %s",lineno,fnname);
}
fclose(fh);
}
}
--
bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Dropping C bartc <bc@freeuk.com> - 2018-03-17 16:07 +0000
Re: Dropping C "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2018-03-18 00:41 +0800
Re: Dropping C Richard Damon <Richard@Damon-Family.org> - 2018-03-17 19:54 -0400
Re: Dropping C Ian Collins <ian-news@hotmail.com> - 2018-03-18 13:19 +1300
Re: Dropping C Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-18 02:42 -0700
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-18 01:28 +0000
Re: Dropping C Richard Damon <Richard@Damon-Family.org> - 2018-03-17 21:41 -0400
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-18 11:25 +0000
Re: Dropping C Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-18 04:33 -0700
Re: Dropping C jacobnavia <jacob@jacob.remcomp.fr> - 2018-03-19 00:05 +0100
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-19 00:24 +0000
Re: Dropping C Richard Damon <Richard@Damon-Family.org> - 2018-03-18 21:15 -0400
Re: Dropping C Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-18 19:00 -0700
Re: Dropping C David Brown <david.brown@hesbynett.no> - 2018-03-19 14:04 +0100
Re: Dropping C Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-19 06:08 -0700
Re: Dropping C supercat@casperkitty.com - 2018-03-19 14:29 -0700
Re: Dropping C Noob <root@127.0.0.1> - 2018-03-19 14:34 +0100
Re: Dropping C Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-19 06:39 -0700
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-19 15:17 +0100
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-19 15:03 +0000
Re: Dropping C scott@slp53.sl.home (Scott Lurndal) - 2018-03-19 15:36 +0000
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-19 17:01 +0000
Re: Dropping C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-03-19 12:14 -0600
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-19 19:15 +0000
Re: Dropping C Ian Collins <ian-news@hotmail.com> - 2018-03-20 08:20 +1300
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-19 20:47 +0000
Re: Dropping C Lowell Gilbert <lgusenet@be-well.ilk.org> - 2018-03-19 18:00 -0400
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-19 22:17 +0000
Re: Dropping C Reinhardt Behm <rbehm@hushmail.com> - 2018-03-20 09:34 +0800
Re: Dropping C jacobnavia <jacob@jacob.remcomp.fr> - 2018-03-21 07:54 +0100
Re: Dropping C Robert Wessel <robertwessel2@yahoo.com> - 2018-03-21 04:10 -0500
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-21 11:08 +0000
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-21 11:18 +0000
Re: Dropping C Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-21 05:28 -0700
Re: Dropping C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-21 12:13 +0000
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-21 12:26 +0000
Re: Dropping C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-21 15:55 +0000
Re: Dropping C jacobnavia <jacob@jacob.remcomp.fr> - 2018-03-21 20:15 +0100
Re: Dropping C Keith Thompson <kst-u@mib.org> - 2018-03-21 12:45 -0700
Re: Dropping C supercat@casperkitty.com - 2018-03-21 13:46 -0700
Killfiles (Was: Dropping C) gazelle@shell.xmission.com (Kenny McCormack) - 2018-03-21 21:42 +0000
Re: Killfiles (Was: Dropping C) Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-22 04:22 -0700
Re: Dropping C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-21 20:21 +0000
Re: Dropping C Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-21 22:21 -0700
Re: Dropping C Reinhardt Behm <rbehm@hushmail.com> - 2018-03-20 09:32 +0800
Re: Dropping C Ian Collins <ian-news@hotmail.com> - 2018-03-21 10:01 +1300
Re: Dropping C luser droog <luser.droog@gmail.com> - 2018-03-20 16:01 -0700
Re: Dropping C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-03-19 13:41 -0600
Re: Dropping C luser droog <luser.droog@gmail.com> - 2018-03-19 12:52 -0700
Re: Dropping C Spiros Bousbouras <spibou@gmail.com> - 2018-03-19 20:15 +0000
Re: Dropping C scott@slp53.sl.home (Scott Lurndal) - 2018-03-19 20:38 +0000
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-19 22:00 +0100
Re: Dropping C Spiros Bousbouras <spibou@gmail.com> - 2018-03-20 01:45 +0000
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-20 03:05 +0100
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-19 21:09 +0000
Re: Dropping C Ian Collins <ian-news@hotmail.com> - 2018-03-20 18:26 +1300
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-20 10:58 +0000
Re: Dropping C David Brown <david.brown@hesbynett.no> - 2018-03-20 14:22 +0100
Re: Dropping C scott@slp53.sl.home (Scott Lurndal) - 2018-03-20 13:58 +0000
Re: Dropping C David Brown <david.brown@hesbynett.no> - 2018-03-20 17:14 +0100
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-20 16:31 +0000
Re: Dropping C scott@slp53.sl.home (Scott Lurndal) - 2018-03-20 17:14 +0000
Re: Dropping C Ian Collins <ian-news@hotmail.com> - 2018-03-21 07:31 +1300
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-20 18:51 +0000
Re: Dropping C Ian Collins <ian-news@hotmail.com> - 2018-03-21 08:01 +1300
Re: Dropping C scott@slp53.sl.home (Scott Lurndal) - 2018-03-20 19:03 +0000
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-20 19:22 +0000
Re: Dropping C Ian Collins <ian-news@hotmail.com> - 2018-03-21 08:25 +1300
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-20 19:33 +0000
Re: Dropping C Ian Collins <ian-news@hotmail.com> - 2018-03-21 09:34 +1300
Re: Dropping C scott@slp53.sl.home (Scott Lurndal) - 2018-03-20 19:49 +0000
Re: Dropping C David Brown <david.brown@hesbynett.no> - 2018-03-21 11:27 +0100
Re: Dropping C Spiros Bousbouras <spibou@gmail.com> - 2018-03-20 01:27 +0000
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-19 17:03 +0100
Re: Dropping C David Brown <david.brown@hesbynett.no> - 2018-03-19 23:13 +0100
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-20 00:23 +0100
Re: Dropping C Spiros Bousbouras <spibou@gmail.com> - 2018-03-20 00:55 +0000
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-20 02:29 +0100
Re: Dropping C Spiros Bousbouras <spibou@gmail.com> - 2018-03-20 02:04 +0000
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-20 03:31 +0100
Re: Dropping C jacobnavia <jacob@jacob.remcomp.fr> - 2018-03-21 20:18 +0100
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-21 21:32 +0100
Re: Dropping C scott@slp53.sl.home (Scott Lurndal) - 2018-03-21 20:52 +0000
Re: Dropping C supercat@casperkitty.com - 2018-03-21 14:38 -0700
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-21 23:08 +0100
Re: Dropping C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-22 13:37 +0000
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-22 15:41 +0100
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-22 14:58 +0000
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-22 17:37 +0100
Re: Dropping C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-22 17:09 +0000
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-22 18:27 +0100
Re: Dropping C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-22 17:35 +0000
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-22 18:46 +0100
Re: Dropping C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-22 18:22 +0000
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-22 19:38 +0100
Re: Dropping C jameskuyper@verizon.net - 2018-03-22 12:19 -0700
Re: Dropping C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-22 20:23 +0000
Re: Dropping C Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-03-23 06:10 -0700
Re: Dropping C David Brown <david.brown@hesbynett.no> - 2018-03-23 14:54 +0100
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-23 16:55 +0100
Re: Dropping C David Brown <david.brown@hesbynett.no> - 2018-03-23 17:46 +0100
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-24 02:50 +0100
Re: Dropping C GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-03-24 02:54 +0100
Re: Dropping C scott@slp53.sl.home (Scott Lurndal) - 2018-03-22 16:43 +0000
Re: Dropping C Keith Thompson <kst-u@mib.org> - 2018-03-22 10:39 -0700
Re: Dropping C Robert Wessel <robertwessel2@yahoo.com> - 2018-03-22 11:47 -0500
Re: Dropping C Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-24 00:59 -0700
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-19 15:07 +0000
Re: Dropping C scott@slp53.sl.home (Scott Lurndal) - 2018-03-19 15:37 +0000
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-19 17:16 +0000
Re: Dropping C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-19 20:30 +0000
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-19 21:24 +0000
Re: Dropping C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-19 23:06 +0000
Re: Dropping C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-20 14:04 +0000
Re: Dropping C supercat@casperkitty.com - 2018-03-19 15:32 -0700
Re: Dropping C Robert Wessel <robertwessel2@yahoo.com> - 2018-03-19 19:03 -0500
Re: Dropping C Spiros Bousbouras <spibou@gmail.com> - 2018-03-20 02:13 +0000
Re: Dropping C David Brown <david.brown@hesbynett.no> - 2018-03-20 14:25 +0100
Re: Dropping C jacobnavia <jacob@jacob.remcomp.fr> - 2018-03-21 18:36 +0100
Re: Dropping C David Brown <david.brown@hesbynett.no> - 2018-03-19 23:33 +0100
Re: Dropping C supercat@casperkitty.com - 2018-03-19 16:34 -0700
Re: Dropping C asetofsymbols@gmail.com - 2018-03-20 00:58 -0700
Re: Dropping C Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-20 01:10 -0700
Re: Dropping C Ian Collins <ian-news@hotmail.com> - 2018-03-19 14:25 +1300
Re: Dropping C bartc <bc@freeuk.com> - 2018-03-21 12:19 +0000
csiph-web