From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 12-MAR-1993 09:29:18.60
To:	Info-VAX@KL.SRI.COM
CC:	
Subj:	re: problem with callback? (vax/vms+motif+fortran)

In article <11159902@MVB.SAIC.COM>, "Brian A McMillan (44) 5057 5388" <MCMILLAN@COLLOQUIUM.CO.UK> writes:
> Like you I started off linking I would do it all in Fortran (better still
> RAMBOTRAN), but after discovering:
> 
> 1. Almost all of the examples are in C
> 2. Almost everyone else does it in C
> 3. All the bindings are C oriented
> 4. I could not find a Motif manual in a language other than C (there must be an
>    ADA version I guess)
> 
> I bought a copy of kernihan and ritchie, swallowed my pride and did in in
> lowercase. Suggest you do the same, but good luck otherwise.

You don't *have* to use C to program for X if you are willing to do a little
extra work.  One day I received yet another book-club mailing that listed four
Unix books and four X books under the heading "Unix", decided I wasn't going to
take it any more, and wrote my first X app.  Here it is:

*+
* PROGRAM : HELLO-WORLD
* 
* PROGRAM DESCRIPTION:
* 
*       Trivial X-window application, to show the world that X doesn't imply
*	C, let alone Unix!
* 
* AUTHORS:
* 
*       Mark H. Wood
*	Indiana University - Purdue University at Indianapolis
*	Computing Services
* 
* CREATION DATE: 13-Aug-1991
* 
* 
* DESIGN ISSUES:
* 
*       COBOL won't dereference pointers, so we have to do it the sneaky way
*	by passing them by value to subroutines.
* 
* MODIFICATION HISTORY:
* 
*       [chg-date-author-desc]
* 
*-

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.



DATA DIVISION.

WORKING-STORAGE SECTION.

77  DISPLAY-P	    USAGE IS POINTER.
77  ROOT-WINDOW	    USAGE IS POINTER.
77  WINDOW	    USAGE IS POINTER.
77  GC		    USAGE IS POINTER.
77  SCREEN-N	    USAGE IS POINTER.
77  BLACK	    USAGE IS POINTER.
77  WHITE	    USAGE IS POINTER.
77  JUNK	    USAGE IS POINTER.
77  ROOT-CHILDREN-P USAGE IS POINTER.
77  ROOT-N-CHILDREN USAGE IS COMP   PICTURE IS 9(9).
77  PSEUDO-ROOT	    USAGE IS POINTER.
77  DELAY-TIME	    USAGE IS COMP-1 VALUE IS 10.0.

PROCEDURE DIVISION.
MAINLINE SECTION.
MAIN-LINE.
    CALL "XOpenDisplay"
	USING BY REFERENCE X"00"
	GIVING DISPLAY-P.
    IF DISPLAY-P IS ZERO THEN STOP RUN.

    CALL "XDefaultScreen"
	USING BY VALUE DISPLAY-P
	GIVING SCREEN-N.
    CALL "XDefaultGC"
	USING BY VALUE DISPLAY-P,
	    BY VALUE SCREEN-N
	GIVING GC.
    CALL "XBlackPixel"
	USING BY VALUE DISPLAY-P,
	    BY VALUE SCREEN-N
	GIVING BLACK.
    CALL "XWhitePixel"
	USING BY VALUE DISPLAY-P,
	    BY VALUE SCREEN-N
	GIVING WHITE.

    CALL "XDefaultRootWindow"
	USING BY VALUE DISPLAY-P
	GIVING ROOT-WINDOW.
    CALL "XQueryTree"
	USING BY VALUE DISPLAY-P,
	    BY VALUE ROOT-WINDOW,
	    BY REFERENCE JUNK, JUNK,
	    BY REFERENCE ROOT-CHILDREN-P,
	    BY REFERENCE ROOT-N-CHILDREN.
    CALL "FIND-PSEUDO-ROOT"
	USING BY REFERENCE DISPLAY-P,
	    BY VALUE ROOT-CHILDREN-P,
	    BY REFERENCE ROOT-N-CHILDREN
	GIVING PSEUDO-ROOT.

    CALL "XCreateSimpleWindow"
	USING BY VALUE DISPLAY-P,
	    BY VALUE PSEUDO-ROOT,
	    BY VALUE 100, 100,
	    BY VALUE 160, 100,
	    BY VALUE 3,
	    BY VALUE BLACK,
	    BY VALUE WHITE
	GIVING WINDOW.
    IF WINDOW IS ZERO THEN STOP RUN.
    CALL "XMapRaised"
	USING BY VALUE DISPLAY-P,
	    BY VALUE WINDOW.

    CALL "XDrawString"
	USING BY VALUE DISPLAY-P,
	    BY VALUE WINDOW,
	    BY VALUE GC,
	    BY VALUE 40, 55,
	    BY REFERENCE "Hello, world!",
	    BY VALUE 13.

    CALL "XFlush" USING BY VALUE DISPLAY-P.
    CALL "LIB$WAIT" USING BY REFERENCE DELAY-TIME.

    CALL "XCloseDisplay" USING BY VALUE DISPLAY-P.

    STOP RUN.

IDENTIFICATION DIVISION.
PROGRAM-ID. FIND-PSEUDO-ROOT.

DATA DIVISION.

WORKING-STORAGE SECTION.
77  PSEUDO-ROOT	    USAGE IS COMP   PICTURE IS 9(9).
77  PARENT-WINDOW   USAGE IS COMP   PICTURE IS 9(9).
77  ROOT-WINDOW	    USAGE IS COMP   PICTURE IS 9(9).
77  CHILD-INDEX	    USAGE IS COMP   PICTURE IS 9(9).
77  JUNK	    USAGE IS INDEX.

LINKAGE SECTION.
01  DISPLAY-P	USAGE IS POINTER.
01  CHILDREN	USAGE IS COMP.
    02	CHILD	PICTURE IS 9(9)
	OCCURS 1 TO 10000 TIMES DEPENDING ON N-CHILDREN.
01  N-CHILDREN	USAGE IS COMP	PICTURE IS 9(9).

PROCEDURE DIVISION
    USING DISPLAY-P, CHILDREN, N-CHILDREN
    GIVING PSEUDO-ROOT.

DOIT.
    PERFORM WITH TEST AFTER
	    VARYING CHILD-INDEX FROM 1 BY 1
		UNTIL (CHILD-INDEX > N-CHILDREN) OR
		    (PARENT-WINDOW = ROOT-WINDOW)
	    CALL "XQUERYTREE"
		USING BY VALUE DISPLAY-P,
		    BY VALUE CHILD(CHILD-INDEX),
		    BY REFERENCE ROOT-WINDOW,
		    BY REFERENCE PARENT-WINDOW,
		    BY REFERENCE JUNK, JUNK;
	    END-PERFORM.
    IF PARENT-WINDOW IS EQUAL TO ROOT-WINDOW
	THEN MOVE CHILD(CHILD-INDEX) TO PSEUDO-ROOT
	ELSE MOVE ZERO TO PSEUDO-ROOT.
END PROGRAM FIND-PSEUDO-ROOT.

END PROGRAM HELLO-WORLD.

-- 
Mark H. Wood, Lead Systems Programmer    +1 317 274 0749   [@disclaimer@]
Internet:  IMHW400@INDYVAX.IUPUI.EDU     BITNET:  IMHW400@INDYVAX
Celebrate freedom:  read a banned newsgroup.

