home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk22
/
dir02
/
f014710.re_
/
f014710.re
Wrap
Text File
|
1996-04-02
|
10KB
|
290 lines
program externpg
c
c ----------------------------------------------------------------------
c
c Copyright (1995) Bentley Systems, Inc., All rights reserved.
c
c "MicroStation" is a registered trademark and "MDL" and "MicroCSL"
c are trademarks of Bentley Systems, Inc.
c
c Limited permission is hereby granted to reproduce and modify this
c copyrighted material provided that the resulting code is used only
c in conjunction with Bentley Systems products under the terms of the
c license agreement provided therein, and that this notice is retained
c in its entirety in any such reproduction or modification.
c
c ----------------------------------------------------------------------
c
c $Logfile: J:/mdl/examples/externpg/extrnpgf.fov $
c $Workfile: extrnpgf.for $
c $Revision: 1.2 $
c $Date: 20 Jun 1995 10:03:20 $
c
c ----------------------------------------------------------------------
c
c extrnpgf.for --
c This is test Fortran-microstation interface.
c The following C functions from extrnpgi.c file
c are currently referenced (aside of standard
c C interface functions extprg_*)
c
c (call) c_copyToFar(BYTE farhandle(6) , character string*x )
c (call) c_copyFromFar(character string*x, BYTE farhandle(6))
c (call) extint_shmemAttach (BYTE farhandle(6), char* extname)
c (call) testargs
c
c ----------------------------------------------------------------------
c
implicit integer (a-z)
c
parameter (EXTERNPG_UPDATE=1)
parameter (EXTERNPG_TERMINATE=2)
parameter (EXTERNPG_ACKNOWLEDGE=4)
parameter (EXTERNPG_DISPLAY=3)
c
parameter (extqnamesize=100)
parameter (extmnamesize=100)
parameter (maxmsglength=100) ! This MUST be assigned to
c
hcexternal extprg_messageReceive ! This declares external C
integer*4 extprg_messageReceive ! function
hcexternal extprg_messageSend
integer*4 extprg_messageSend
hcexternal extprg_queueAttach ! This declares external C
integer*4 extprg_queueAttach ! function
logical check48bit
c hcexternal c_copyToFar
c hcexternal c_copyFromFar
hcexternal extint_shmemAttach
character string*128
byte farhandle(6) ! shared memory handle
byte extmname(extmnamesize) ! name of shared memory
integer*4 ptr_msmsgqdescr ! Queue descriptor handle
byte extqname(extqnamesize) ! This will be the name of queue
character clstring*128
integer*4 mtype,msglength,sendpid,reqtype
byte mtext(maxmsglength)
byte ptr_externalmessage ! Just a pointer name...
integer*4 retval
common /externalmessage/mtype,msglength,sendpid,reqtype,mtext
equivalence (mtype,ptr_externalmessage)
c
print *,'Here we start !'
call getcl(clstring)
print *,'Command line',clstring
if (getargc().lt.2) then ! Terminate
print *,'No parameters.'
goto 1000
endif
call getargv(extqname,1) ! This gets 1st command line argument
ptr_msmsgqdescr=extprg_queueAttach(carg(pointer(extqname)))
if(ptr_msmsgqdescr.eq.0) then ! ERROR
print *,'Cannot attach queue.'
goto 1000
endif
print *,'Queue Attached !'
call getargv(extmname,2)
call extint_shmemAttach( carg(pointer(farhandle)),
& carg(pointer(extmname)) )
if(check48bit(farhandle)) then ! ERROR
print *,'Cannot attach shared memory...'
goto 1000
endif
print *,'Shared memory is here !'
c call testargs ! C function to test its argv,argc
do
print *,'Waiting for message from Microstation'
retval=extprg_messageReceive(
& carg(pointer(ptr_externalmessage)),
& carg(ptr_msmsgqdescr),carg(0),carg(0))
print *,'Got something...'
if(retval.ne.0) then ! ERROR, must be 0
print *,'Receive returned error...'
goto 1000
endif
print *,'Request:',reqtype
select case (reqtype)
case (EXTERNPG_UPDATE)
print *,'Received update request.'
reqtype=EXTERNPG_ACKNOWLEDGE
msglength=0
retval=extprg_messageSend(
& carg(pointer(ptr_externalmessage)),
& carg(ptr_msmsgqdescr))
if(retval.ne.0) then
print *,'Error returned from SENDER.'
goto 1000
endif
case (EXTERNPG_DISPLAY)
print *,'Received display update'
call c_copyFromFar(string,farhandle)
print *,string
reqtype=EXTERNPG_ACKNOWLEDGE
msglength=0
string='Here it is...'
call c_copyToFar(farhandle,string)
retval=extprg_messageSend(
& carg(pointer(ptr_externalmessage)),
& carg(ptr_msmsgqdescr))
if(retval.ne.0) then
print *,'Error returned from SENDER.'
goto 1000
endif
case (EXTERNPG_TERMINATE)
print *,'Received termination request.'
reqtype=EXTERNPG_ACKNOWLEDGE
msglength=0
string='Here it is...'
call c_copyToFar(farhandle,string)
retval=extprg_messageSend(
& carg(pointer(ptr_externalmessage)),
& carg(ptr_msmsgqdescr))
if(retval.ne.0) then
print *,'Error returned from SENDER.'
goto 1000
endif
print *,'OK: Terminating...'
goto 1000
case default
print *,'Default (terminating).'
goto 1000
end select
end do
1000 print *,'End...'
end
c
c
c Length of C representation of a string
c
c
integer function clen(source)
byte source(0:1000) ! assume sensible length is
integer i ! ve-e-e-ry large
do 1 i=0,1000
if(source(i).eq.0) goto 2
1 continue
2 clen=i
return
end
c
c This functions gets number of arguments in command line
c
integer function getargc()
integer argnum
character clstring*127
integer i,length,inword
argnum=0
call getcl(clstring)
length=len(clstring)
do 100 i=1,length ! scan line first
if(ichar(clstring(i:i)).lt.32) goto 1000
100 continue
inword=0
do 200 i=1,length
if(ichar(clstring(i:i)).ne.32) then
if(inword.eq.0) then
inword=1
argnum=argnum+1
endif
else
inword=0
endif
200 continue
1000 getargc=argnum
return
end
c
c This subroutine gives C-form of i-th(st,nd,rd...) argument
c
subroutine getargv(destination,number)
c
byte destination(0:128) ! assume there is sufficient place
integer*4 number
character clstring*127
character clsubstring*127
integer*4 i,length,num
c
call getcl(clstring) ! get command line
c
length=len(clstring)
num=number
clsubstring=' '(1:0)
do 1 i=1,length ! scan for nongraphical characters
if(ichar(clstring(i:i)).lt.32) goto 1000
1 continue
2 if(length.eq.0) goto 1000 ! check length
i=index(clstring,' ') ! Kill leading space (if any)
if(i.eq.1) then
clstring=clstring(2:length)
length=length-1
goto 2
endif
num=num-1
if (num.gt.0) then ! still not this argument...
if (i.eq.0) goto 1000 ! no more arguments in command line
clstring=clstring(i+1:length)
length=length-i ! truncate line
goto 2
endif
if(i.eq.0) then
clsubstring=clstring
goto 1000
endif
C clstring=clstring(i+1:length)
C i=index(clstring,' ')
C if(i.eq.0) then
C clsubstring=clstring
C else
clsubstring=clstring(1:i-1)
C endif
1000 call fortfw(destination,clsubstring)
return
end
c
c subroutine fortfw converts 1st word of source
c fortran string to C destination
c
subroutine fortfw(dest,source)
byte dest(0:1000) ! assume sufficient space
character source*127
integer*4 length,i
length=len(source)
do 1 i=1,length
if(ichar(source(i:i)).eq.32) goto 1000
1 dest(i-1)=ichar(source(i:i))
1000 dest(i-1)=0
return
end
c
c This function test 1st 6 bytes of its argument to be 0
c
c
logical function check48bit(testval)
byte testval(6)
integer i
logical result
result=.TRUE.
do 1 i=1,6
if(testval(i).ne.0) then
result=.FALSE.
goto 2
endif
1 continue
2 check48bit=result
return
end