I've spent a little time (spread over a few days) trying to figure this out.  
I have some theories and related questions, but I decided to bite the bullet 
and just ask:

From where is the initialize function in text.c called?

After some further attempts at trying to figure this out, my best guess is 
that it has something to do with this (from text.c):

static TextClassRec textClassRec = {
...
(XtInitProc)initialize, /* initialize */

And that that is hinting (to me) that initialize is sort of a callback 
function, invoked from the X toolkit (? Xt), and, just to keep guessing, 
probably via a function pointer type of call.

If it is the case that initialize is some sort of callback function, I guess 
it doesn't have to be declared in text.h to allow such use?

Or wait, maybe the fact that struct _TextClassRec is defined in text.h allows 
initialize to be called from other files?

Aside: I've described some of my (attempts at) thinking process below--if 
someone wants to suffer through trying to read this and straightening me out, 
it may help me resolve some future similar questions myself (teaching me to 
fish).

(I have read books on C, I'm keeping "C: A Reference Manual" nearby (it's 
currently my bathroom reading material) as I try to work my way through this 
code, but C just frustrates me.  (And maybe some of the frustration is not 
directly C, but things like X, Motif/lestif, and similar.))

   * as an experiment, I indexed the nedit code with recoll (but not (so far), 
for example, the motif/lestif code).  It seems to work reasonably well.  (I 
experimented with ctags, but it doesn't help me find, for example, a function 
call, only a function definition, so I'm looking for something else--I 
recognize (based on a comment someone on this list made to me quite some time 
ago) that if a function is called as (by?) a function pointer, neither 
recoll, ctags, or anything similar is likely to help me.)  

Recoll shows only two instances of "initialize(" (both in text.c) (unless I've 
overlooked something)--I have to do a few tricks in recoll to search for 
"initialize("--that is, disable stemming (by capitalizing the search term), 
and, then, after letting recoll find a file containing hits, doing a search 
within that file (a built in recoll function, but I suspect based on grep or 
something similar instead of the index) to search for the trailing "(".

   * the first occurrence of "intialize(" in text.c is early in the file:
"static void initialize(TextWidget request, TextWidget new);"
... and is a declaration of the function, and in fact, (what in pascal would 
be called, iirc) a forward declaration, needed so that some other part of the 
code (in this file--see next point) can call (or reference) the function 
before it is defined

   * because the forward declaration occurs in text.c instead of text.h, the 
function cannot be called "externally" (that is, from any file other than 
text.c)?? Ohh, wait, I guess if text.c is "include"d in some other file, the 
function could be called from there--let me go see which other files include 
text.c.  Gone to look for (nedit source) files which include text.c--I'm 
back, there are none--there is a comment which refers to text.c in help.c.

   * so, can C functions be called without a () for parameters?  Not as far as 
I know.  Oh, wait, I guess there could be whitespace between "initialize" and 
the leading "("?  Let me search for something like that--

      * well, there is this in text.c:
static TextClassRec textClassRec = {
...
(XtInitProc)initialize, /* initialize */

I wanted to ask about things like this anyway--I guess this is a cast of 
"initialize" to be of type XtInitProc, which, I'm guessing, is a function 
(Proc), from Xt (which, iiuc, is part of the X toolkit library)--am I getting 
close--is this "initialize" what I'm looking for?  

And is it, indeed, a sort of callback function?  Is that still just a 
guess/hunch, or is there something here that (explicitly) tells me that?  I 
should (attempt) to read a little further...well, it still seems like (to me) 
a good guess, but I don't see how I can determine that from the code.  

Also, I'm still not sure how Xt can invoke that function even as a callback if 
it is not declared in text.h.  (I don't know a whole lot about callbacks, 
even if I did use them at least once, in some (turbo) Pascal (iirc) code (oh, 
wait, maybe that was in VisualBasic--or maybe both--I am remembering more 
clearly that I did use callbacks in the VisualBasic thingie I wrote to talk 
to an A-B PLC almost 10 years ago).

   * I was getting to the point of having a guess/hunch that the initialize 
function is something required by X, motif/lesstif, or similar as sort of a 
callback function, but I would think that it would have to be declared in 
text.h to allow something like motif/lesstif to call it, even by a function 
pointer?

Randy Kramer
-- 
"I didn't have time to write a short letter, so I created a video 
instead."--with apologies to Cicero, et.al.
--
NEdit Develop mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/develop

Reply via email to