#! /bin/nawk -f
#
#             convert SGKS PS file into idraw EPSF
#
#				ver. 0.3           swamp 92/02/12
#
#                      usage : sgks2idraw <file>
#
BEGIN	{ print "%I Idraw 9"; print
	  print "%%Page: 1 1"; print
	  print "Begin"
	  print	"%I b u"
	  print "%I cfg Black"
	  print "0 0 0 SetCFg"
	  print "%I cbg White"
	  print "1 1 1 SetCBg"
	  print "%I f u" 
	  print "%I k u"
	  print "%I p u"
	  print "%I t"
	  print "[ 0.2 0 0 0.2 0 0 ] concat"
	  print "/originalCTM matrix currentmatrix def"; print
	  p = -1
	  linew = 1
	}

/^N/	{ p = 0 ;  next	}

	{ if ( p>=0 ) 
	  {
		 if      ( $NF == "S" || $NF == "M" )
		 {  if ( p != 0 ) 
			{ print "Begin %I MLine"
		          print "%I b 65535"
			  print linew " 0 0 [] 0 SetB"
			  print "%I cfg u"
			  print "%I cbg u"
			  print "% % %I p n"
			  print "%I t"
			  print "[ 0.5 0 0 0.5 0 0 ] concat"
			  print "%I " p
			  for ( i=0; i<p; i++ )
				print x[i] " " y[i]
			  print p " MLine"
			  print "End"; print
			}
                	p = 0
		 }

		 if ( $NF == "W" )  
	         {  linew = int($1/2)   }
  		 else if ( NF == 3 && ( $NF == "M" || $NF == "L" ) )
		 {  x[p] = $1; y[p] = $2; p++ }
		 else if ( $NF == "G" )
		 {  print "% < hard tone neglected >" }
		 else if ( NF >= 2 )
		 {  print "% < invalid command >" $0 }
	 }
	}

END	{ print "End %I eop"; print
	  print "showpage"
	}

