Highley Recommended, Inc.
[ Home |
News |
Services |
Links ]
Split FrameMaker MIF File
#! /bin/sh
SRC_ID='@(#) $Header: split_file,v 1.0 93/11/10 14:56:15
uid=135(dhighley) gid=10(staff) groups=10(staff) Exp $'
# Author: David Highley
# Copyright (c) 1993 Highley Recommended, Inc.
# All Rights Reserved. This copyright and the "SRC_ID" string(s)
# included in the source must not be removed. Permission is granted
# for licensed systems.
#
# $Log$
# Initial Edit: 93/11/10 14:56:15
#
Rev='$Revision: 1.0 $'
nawk '
{
################################################################
# This section extracts the Catalog at the start of the file #
################################################################
# print "Catalog Clause"
True = "True"
print $0 >"catalog"
while ( True == "True" ) {
getline
if ( $0 == "> # End of Catalog" ) {
print $0 >>"catalog"
break}
print $0 >> "catalog"
}
close ("catalog")
#########################################################################
# This section extracts each drawing and puts it into a separate file #
#########################################################################
# print "Frame Clause"
FileName = ""
TempFile = "tmp.mif"
True = "True"
while ( True == "True" ) {
getline
if ( $0 == "<TextFlow" )
break
if ( $1 == "<Frame" ) { # New Frame
print $0 >>TempFile
getline # <ID #>
FileName = substr($2,1,length($2) - 1)
# print "ID is " FileName
}
print $0 >>TempFile
if ( $0 == " > # End of Frame" ) { # End of Frame
close (TempFile)
system ("mv " TempFile " " FileName".ID")
FileName = ""
# print "End Frame"
}
}
#############################################
# This section extracts chapter paragraph #
#############################################
# print "Chapter Paragraph Clause"
close (TempFile)
LineIndex = 0
while ( getline Line[LineIndex] <TempFile > 0 ) {
LineIndex = LineIndex + 1
}
close (TempFile)
system ("rm " TempFile)
Line[LineIndex] = $0
while ( Line[LineIndex] != " <PgfTag DpsSubSec>" ) { # Read in
# rest of paragraph
LineIndex = LineIndex + 1
getline Line[LineIndex]
}
Loop = 0
while ( Loop < (LineIndex - 2) ) { # Write paragraph to file
print Line[Loop] >>"ChapTitlePar"
Loop = Loop + 1
}
close ("ChapTitlePar")
Line[0] = Line[LineIndex - 2] # Shuffle up 3 lines from next paragraph
Line[1] = Line[LineIndex - 1]
Line[2] = Line[LineIndex]
LineIndex = 2
###########################################################################
# This section extracts each text paragraph and adds it to drawing file #
###########################################################################
# print "Subsection Clause"
AFrame = 1000000
while ( True == "True" ) {
LineIndex = LineIndex + 1
getline Line[LineIndex]
if ( match(Line[LineIndex],"<PgfTag DpsSubSec>") >0 ) {
# Found next
# level 2 section
# print "Found new Subsection"
if ( FileName == "" ) { # No diagram for para
FileName = AFrame".AFrame"
AFrame = AFrame + 1
}
Loop = 0
while ( Loop < (LineIndex - 2) ) { # Write paragraph
# to file
print Line[Loop] >>FileName
Loop = Loop + 1
}
close (FileName)
FileName = ""
Line[0] = Line[LineIndex - 2] # Shuffle up 3 lines
Line[1] = Line[LineIndex - 1] # from next paragraph
Line[2] = Line[LineIndex]
LineIndex = 2
continue
}
if ( match(Line[LineIndex],"<AFrame") >0 ) {
# May not be one
# in Subsection
# if drawing was
# to large
Start = 12
End = index(Line[LineIndex],">")
Len = End - Start
FileName = substr(Line[LineIndex],Start,Len)".AFrame"
# print "AFrame is " FileName
continue }
if ( match(Line[LineIndex],"> # TextFlow") >0 ) {
# Get trailer to add
# to end of files
# print "Trailer Clause"
Loop = 0
while ( Loop < LineIndex ) { # Write paragraph
# to file
print Line[Loop] >>FileName
Loop = Loop + 1
}
close (FileName)
print Line[LineIndex] >"trailer"
while ( (getline > 0) && \
($0 != "# End of MIFFile") ) {
print $0 >>"trailer" }
print $0 >>"trailer"
close("trailer")
exit
} # End of loop for trailer file
} # End of loop for extraction of Subsection paragraph
} '