In article <Pine.SOL.3.91.950111111010.6577A-100000@chroma> Russ Welti <rwelti@chroma.mbt.washington.edu> writes:
> If your editor supports a matching function for characters
> such as '(' '{' '[' etc. (e.g. the % key in vi) then you
> might like this little technique I started using one day
> when I could not find the matching END for an IDL construct.
...
Personally I would rather have a program to diagram them for me.
I assume you have a Fortran compiler (-:
----------------------------CUT HERE---------------------------------
program diagrami
c Diagrams IDL if-else-elseif-endif and do-enddo constructs.
c Program by Mitchell R Grunes, ATSC/NRL.
c Note--this is a quick and dirty attempt--may not always work quite right.
c It is assumed that no fortran carriage control exists.
c Versions: To diagram Fortran: diagram.for
c IDL: diagrami.for
c C: diagramc.for
implicit integer*2 (i-n)
character*160 a,b
character*16 aa
character*5 form
character*1 c
logical find
external find
common icol
print*,'IDL source filename?'
a=' '
read(*,1)a(1:132)
1 format(a132)
open(1,file=a,status='old')
print*,'output file?'
b=' '
read(*,1)b(1:132)
open(2,file=b)
c last minute change to reduce spaces in diagram block:
c print*,'column for line #(60 for screen,91 for laser,112 for print,0 for none)?'
print*,'column for line #(68 for screen,99 for laser,'
print*,' 120 for print,0 for none)?'
iline=0
read*,iline
cwrite(2,*)a
cwrite(2,*)'************************************************ **************'
aa='| | | | | | | | | | | | | | | | | | | | | | | | |'
i1=0 !# of nest levels before current line
i2=0 !# of nest levels on current line
i3=0 !# of nest levels after current line
i4=0 !1 to flag start or end of block
InSub=0 !Inside a procedure or function?
nline=0
iunit=1
10 read(iunit,11,end=99)a
11 format(a160)
nline=nline+1
if(nline/100*100.eq.nline)print*,'Line ',nline
b=' ' !turn tabs to spaces
j=1
do i=1,160
if(a(i:i).eq.char(9))then
j=(j-1)/8*8+8+1
elseif(j.le.160)then
b(j:j)=a(i:i)
j=j+1
endif
enddo
a=b
b=' '
i=1
j=1
dowhile(i.le.160.and.j.le.160) !handle upper case
c=a(i:i)
b(j:j)=c
j=j+1
i=i+1
enddo
a=' '
iquote=0 !no ' yet
idquote=0 !no " yet
do i=1,160
c=b(i:i)
if(c.ge.'A'.and.c.le.'Z')c=char(ichar(c)+32)
if(c.eq.";")goto 15
if(c.eq."'".and.i.ne.6)iquote=1-iquote
if(c.eq.'"'.and.i.ne.6)idquote=1-idquote
if(iquote.eq.1)then
if(find(a,'include ',1))then
iquote=0
idquote=0
endif
endif
if(iquote.ne.0.or.idquote.ne.0)c=' '
a(i:i)=c
enddo
15 i2=i1
i3=i1
i4=0
iflag=0 !no goto on line
if(find(a,'goto',0))iflag=1
if(find(a,'include ',1))then
a=a(icol:160)
if(.not.find(a,"'",0))goto 16
a=a(icol:160)
if(.not.find(a,"'",0))goto 16
a(icol-1:160)=' '
close(3)
open(3,file=a,status='old')
iunit=3
nlinesave=nline
i2=i2+1
i3=i3+1
i4=i4+1
16 continue
elseif(find(a,'begin ',0))then
i4=i4+1
if(.not.find(a,'else',0))then
i2=i2+1
i3=i3+1
endif
elseif(find(a,'endif ',1).or.find(a,'endfor ',1)
& .or.find(a,'endelse ',1).or.find(a,'endwhile ',1))then
i3=i3-1
i4=i4+1
elseif(find(a,'function ',1).or.find(a,'pro ',1))then
i2=i2+1
i3=i3+1
i4=i4+1
InSub=1
if(i3.ne.1)then
PRINT*,'*******ERROR--INVALID DIAGRAMMING INDEX!*******'
WRITE(2,*)'*******ERROR--INVALID DIAGRAMMING INDEX!******'
print*,char(7)
endif
i3=1
elseif(find(a,'end ',1))then
if(InSub.ne.0)then
i3=i3-1
i4=i4+1
InSub=0
endif
if(i3.ne.0)then
PRINT*,'*******ERROR--INVALID DIAGRAMMING INDEX!*******'
WRITE(2,*)'*******ERROR--INVALID DIAGRAMMING INDEX!******'
print*,char(7)
endif
i3=0
endif
20 a=' '
if(i1.lt.0.or.i2.lt.0.or.i3.lt.0.or.i4.lt.0)then
PRINT*,
& '*********ERROR--INVALID DIAGRAMMING INDEX!*********'
WRITE(2,*)
& '*********ERROR--INVALID DIAGRAMMING INDEX!*********'
print*,char(7)
i1=max(i1,0)
i2=max(i2,0)
i3=max(i3,0)
i4=max(i4,0)
endif
jj=max(1,min(16,2*i2-1))
if(i2.gt.0)a=aa(1:jj)
if(i4.ne.0)then
jjj=1
dowhile(jjj.lt.160.and.b(jjj:jjj).eq.' ')
jjj=jjj+1
enddo
if(jjj.gt.1)b(1:jjj-1)=
& '---------------------------------------------------'
a(jj:16)='-------------------------------'
endif
do i=0,i4-1
a(max(1,min(15,jj-i*2)):max(1,min(15,jj+1-i*2)))='+-'
enddo
if(iline.ne.0.and.b(max(1,iline):160).eq.' ')then
write(form,'(i5)')nline !line #
if(nline.eq.0)write(form,'(i5)')nlinesave
if(form(1:1).eq.' ')form(1:1)='|'
b(iline:iline+4)=form
endif
n=160
dowhile(n.gt.1.and.b(n:n).eq.' ')
n=n-1
enddo
if(iflag.ne.0)a(1:1)='*'
c last minute change to reduce spaces in diagram block:
write(2,2)(a(i:i),i=1,15,2),(b(i:i),i=1,n)
2 format(132a1)
i1=i3
goto 10
99 if(iunit.eq.3)then
iunit=1
nline=nlinesave
i1=i1-1
close(3)
goto 10
endif
end
ccccccccccccccccccc
logical function find(a,b,iflag) !find b in a.
! if iflag.ne.0, must be first
! non-blank in a.
implicit integer*2 (i-n)
integer iflag
character*(*) a,b
common icol
ii=len(a)
jj=len(b)
do i=1,ii-jj+1
if(a(i:i+jj-1).eq.b)then
icol=i+jj ! icol=colomn after item found
if(i.gt.1.and.iflag.ne.0)then
if(a(1:i-1).eq.' ')goto 10
else
goto 10
endif
endif
enddo
find=.false.
return
10 find=.true.
return
end
----------------------------CUT HERE---------------------------------
|