summaryrefslogtreecommitdiff
path: root/numpy/f2py/doc/collectinput.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-01-04 17:26:31 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-01-04 17:26:31 +0000
commit8e2654541c6eae0f308908f501cccbc86b2f9101 (patch)
treebfcfe3b282c8fb659832bf86a841ce76852094ad /numpy/f2py/doc/collectinput.py
parentddaed649c23bbd0ad36cdafdfe9cd92397ce69e3 (diff)
downloadnumpy-8e2654541c6eae0f308908f501cccbc86b2f9101.tar.gz
Moved scipy directory to numpy
Diffstat (limited to 'numpy/f2py/doc/collectinput.py')
-rwxr-xr-xnumpy/f2py/doc/collectinput.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/numpy/f2py/doc/collectinput.py b/numpy/f2py/doc/collectinput.py
new file mode 100755
index 000000000..c2ce2bf89
--- /dev/null
+++ b/numpy/f2py/doc/collectinput.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+"""
+collectinput - Collects all files that are included to a main Latex document
+ with \input or \include commands. These commands must be
+ in separate lines.
+
+Copyright 1999 Pearu Peterson all rights reserved,
+Pearu Peterson <pearu@ioc.ee>
+Permission to use, modify, and distribute this software is given under the
+terms of the LGPL. See http://www.fsf.org
+
+NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
+
+Pearu Peterson
+
+Usage:
+ collectinput <infile> <outfile>
+ collectinput <infile> # <outfile>=inputless_<infile>
+ collectinput # in and out are stdin and stdout
+"""
+
+__version__ = "0.0"
+
+stdoutflag=0
+import sys,os,string,fileinput,re,commands
+
+try: fn=sys.argv[2]
+except:
+ try: fn='inputless_'+sys.argv[1]
+ except: stdoutflag=1
+try: fi=sys.argv[1]
+except: fi=()
+if not stdoutflag:
+ sys.stdout=open(fn,'w')
+
+nonverb=r'[\w\s\\&=\^\*\.\{\(\)\[\?\+\$/]*(?!\\verb.)'
+input=re.compile(nonverb+r'\\(input|include)\*?\s*\{?.*}?')
+comment=re.compile(r'[^%]*%')
+
+for l in fileinput.input(fi):
+ l=l[:-1]
+ l1=''
+ if comment.match(l):
+ m=comment.match(l)
+ l1=l[m.end()-1:]
+ l=l[:m.end()-1]
+ m=input.match(l)
+ if m:
+ l=string.strip(l)
+ if l[-1]=='}': l=l[:-1]
+ i=m.end()-2
+ sys.stderr.write('>>>>>>')
+ while i>-1 and (l[i] not in [' ','{']): i=i-1
+ if i>-1:
+ fn=l[i+1:]
+ try: f=open(fn,'r'); flag=1; f.close()
+ except:
+ try: f=open(fn+'.tex','r'); flag=1;fn=fn+'.tex'; f.close()
+ except: flag=0
+ if flag==0:
+ sys.stderr.write('Could not open a file: '+fn+'\n')
+ print l+l1
+ continue
+ elif flag==1:
+ sys.stderr.write(fn+'\n')
+ print '%%%%% Begin of '+fn
+ print commands.getoutput(sys.argv[0]+' < '+fn)
+ print '%%%%% End of '+fn
+ else:
+ sys.stderr.write('Could not extract a file name from: '+l)
+ print l+l1
+ else:
+ print l+l1
+sys.stdout.close()
+
+
+