#!/usr/bin/python
import string, sys, os
if not sys.argv[1:]:
  print ""
  print 'lyinclude writes includes into file.  Syntax: lyinclude file   (redirect output)'
  print 'One argument only: What file to process?  In the file, % on the line stops the read.'
  print '(c)2003 David Raleigh Arnold under GNU.  Purpose is to prepare files to send to others.'
  print ""
else:
  file = open(sys.argv[1], "r")
  for line in file.readlines():
    pos = string.find(line, "\\include")
    if pos >= 0:  
      posnt = string.find(line, "%")  
      if posnt < 0:
        ins = string.strip(line[pos+9:])[1:-1]
        insfile = open(ins, "r")
        for lin in insfile.readlines():
          print lin[:-1]
      else:
        print line[:-1]     
    else:
      print line[:-1] 
