10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-06-02 11:25:19 +02:00
irpf90/src/create_man.py

175 lines
5.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2009-09-23 12:51:27 +02:00
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
# the Implicit Reference to Parameters (IRP) method.
# Copyright (C) 2009 Anthony SCEMAMA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Anthony Scemama
# LCPQ - IRSAMC - CNRS
# Universite Paul Sabatier
# 118, route de Narbonne
# 31062 Toulouse Cedex 4
# scemama@irsamc.ups-tlse.fr
2009-09-23 12:51:27 +02:00
2009-09-06 00:47:20 +02:00
from variable import Variable
from variables import variables
from subroutine import Sub
2014-03-11 15:43:02 +01:00
from subroutines import subroutines
2009-09-06 00:47:20 +02:00
from irpf90_t import *
2009-09-08 16:00:46 +02:00
from util import *
2009-09-06 00:47:20 +02:00
def do_print_short(file,var):
2010-10-02 23:42:55 +02:00
assert type(var) == Variable
2009-09-06 00:47:20 +02:00
print >>file, "%s : %s :: %s %s"%( \
var.line.filename[0].ljust(25),
var.type.ljust(25),
var.name.ljust(25),
2009-09-08 16:00:46 +02:00
build_dim(var.dim) )
2009-09-06 00:47:20 +02:00
######################################################################
def process_doc(file,line):
2010-10-02 23:42:55 +02:00
assert type(line) == str
2009-09-06 00:47:20 +02:00
line = line.strip()
if line == "":
line = ".br"
print >>file, line
######################################################################
def process_deps(file,l):
2010-10-02 23:42:55 +02:00
assert type(l) == list
2009-09-06 00:47:20 +02:00
for v in l:
print >>file, "%s\n.br"%(v,)
######################################################################
def process_types(file,var):
2010-10-02 23:42:55 +02:00
assert type(var) == Variable
2009-09-07 18:02:06 +02:00
vars = [var.name] + var.others
2009-09-06 00:47:20 +02:00
for var in vars:
name = var
var = variables[var]
2010-10-02 23:42:55 +02:00
Type = var.type
2009-09-08 16:00:46 +02:00
dim = build_dim(var.dim)
2010-10-02 23:42:55 +02:00
print >>file, "%s\t:: %s\t%s"%(Type,name,dim)
2009-09-06 00:47:20 +02:00
######################################################################
def do_print(var):
2010-10-02 23:42:55 +02:00
assert type(var) == Variable
2009-09-16 15:59:13 +02:00
filename = var.line.filename[0]
2009-09-06 00:47:20 +02:00
name = var.name
file = open("%s%s.l"%(mandir,var.name), "w")
print >>file, '.TH "IRPF90 entities" l %s "IRPF90 entities" %s'%(name,name)
2009-09-07 18:02:06 +02:00
if var.same_as != var.name:
2009-09-06 00:47:20 +02:00
var = variables[var.same_as]
print >>file, ".SH Declaration"
print >>file, ".nf"
process_types(file,var)
print >>file, ".ni"
if var.doc != []:
print >>file, ".SH Description"
for l in var.doc:
process_doc(file,l)
print >>file, ".SH File\n.P"
print >>file, filename
if var.needs != []:
2009-09-16 15:59:13 +02:00
var.needs.sort()
2009-09-06 00:47:20 +02:00
print >>file, ".SH Needs"
process_deps(file,var.needs)
if var.needed_by != []:
2009-09-16 15:59:13 +02:00
var.needed_by.sort()
2009-09-06 00:47:20 +02:00
print >>file, ".SH Needed by"
process_deps(file,var.needed_by)
file.close()
######################################################################
def process_declaration_subroutine(file, sub):
print >>file, sub.line.text.split('!')[0].strip()
# for line in sub.text:
######################################################################
def do_print_subroutines(sub):
assert type(sub) == Sub
filename = sub.line.filename
name = sub.name
file = open("%s%s.l"%(mandir,sub.name), "w")
print >>file, '.TH "IRPF90 entities" l %s "IRPF90 entities" %s'%(name,name)
print >>file, ".SH Declaration"
print >>file, ".nf"
process_declaration_subroutine(file,sub)
print >>file, ".ni"
if sub.doc != []:
print >>file, ".SH Description"
for l in sub.doc:
process_doc(file,l)
print >>file, ".SH File\n.P"
print >>file, filename
if sub.needs != []:
sub.needs.sort()
print >>file, ".SH Needs"
process_deps(file,sub.needs)
if sub.called_by != []:
sub.called_by.sort()
print >>file, ".SH Called by"
process_deps(file,sub.called_by)
if sub.calls != []:
sub.calls.sort()
print >>file, ".SH Calls"
process_deps(file,sub.calls)
if sub.touches != []:
sub.touches.sort()
print >>file, ".SH Touches"
process_deps(file,sub.touches)
file.close()
2009-09-06 00:47:20 +02:00
######################################################################
def run():
2009-09-07 18:02:06 +02:00
import parsed_text
import os,sys
if os.fork() == 0:
2011-04-09 23:45:50 +02:00
for v in variables.values():
do_print(v)
for s in subroutines.values():
do_print_subroutines(s)
sys.exit(0)
if os.fork() == 0:
2014-03-11 15:43:02 +01:00
tags = []
2011-04-09 23:45:50 +02:00
l = variables.keys()
file = open("irpf90_entities","w")
l.sort()
for v in l:
do_print_short(file,variables[v])
2014-03-11 15:43:02 +01:00
line = variables[v].line
2014-04-25 17:21:04 +02:00
# tags.append( '%s\t%s\t/%s/;"\n'%(v,line.filename[0],line.text.split('!')[0].strip()) )
tags.append( '%s\t%s\t%d\n'%(v,line.filename[0],line.i) )
2014-03-11 15:43:02 +01:00
file.close()
l = subroutines.keys()
for v in l:
line = subroutines[v].line
2014-04-25 17:21:04 +02:00
# tags.append('%s\t%s\t/%s/;"\n'%(v,line.filename,line.text.split('!')[0].strip()))
tags.append('%s\t%s\t%d\n'%(v,line.filename,line.i))
2014-03-11 15:43:02 +01:00
tags.sort()
file = open("tags","w")
for line in tags:
file.write(line)
file.close()
sys.exit(0)
2009-09-06 00:47:20 +02:00
######################################################################
if __name__ == '__main__':
run()