# TODO : do not correct indentation for & within an regular line
elif"ELSE"ini:
# To improve : the indentation correction is weird (strict) if the indentation before
indent_score=indent_score+1
# the MNH EXPAND comments is not respected (over-indentation)
textwrite=check_indent(ncurrline,indent_score,i)
fin=open(f,'r')
indent_score=indent_score-1
fout=open(f+'_CORRECT_INDENT','w')
elif"THEN"ini:
contentbyline=fin.readlines()
textwrite=check_indent(ncurrline,indent_score,i)
indent_score=indent_score+1
ncurrline=0
elif"DO J"ini:
indent_score=0
textwrite=check_indent(ncurrline,indent_score,i)
expand_score=0
indent_score=indent_score+1
passNextLine={'Pass':False,'Reason':""}
elif ("ENDDO"ini)or("END DO"ini):
foriincontentbyline:
indent_score=indent_score-1
i7=first7char(i)
textwrite=check_indent(ncurrline,indent_score,i)
ifpassNextLine['Pass']:#Second line with & for if or #if(n)def
elif ("END IF"ini)or("ENDIF"ini):
textwrite=i
indent_score=indent_score-1
passNextLine['Pass']=False
textwrite=check_indent(ncurrline,indent_score,i)
ifpassNextLine['Reason']=="IF":
else:
indent_score=indent_score+1
textwrite=i
elifpassNextLine['Reason']=="#ifdef":
else:# not EXPAND lines nor within mnh_expand
textwrite=check_indent(ncurrline,indent_score,i)
if"THEN"ini:
elifpassNextLine['Reason']=="#else":
indent_score=indent_score+1
textwrite=check_indent(ncurrline,indent_score,i)
elif"DO J"ini:
# ONLY IF present in between #ifdef is handled
indent_score=indent_score+1
# If more test is needed (present in the fortran code), duplicate test here
elif ("ENDDO"ini)or("END DO"ini):
if"IF"ini7and"THEN"ini:
indent_score=indent_score-1
indent_score=indent_score+1
elif ("END IF"ini)or("ENDIF"ini):
else:
indent_score=indent_score-1
sys.exit("Reason for passing the line not defined")
textwrite=i
elif"! $MNH EXPAND$ !"ini:
ncurrline=ncurrline+1
expand_score=expand_score+1
fout.writelines(textwrite)
textwrite=""
elif"! $MNH END EXPAND$ !"ini:
fout.close()
expand_score=expand_score-1
fin.close()
textwrite=""
# Ignore comment lines
if__name__=="__main__":
eliffirstchar(i)=="!":
importargparse
textwrite=i
importsys
# Correct indentation only in between $MNH EXPAND$ and $MNH END EXPAND$
parser=argparse.ArgumentParser(description='Detecte les balises !$mnh_expand et !$mnh_end_expand et ajoute un commentaire avant et après pour corriger l\'indentation par la suite avec correct_indentation.py')
elif"IF"ini7and"THEN"ini:#exclude IF in one line (without THEN)
indent_score=indent_score+1
elif"DO J"ini7:
indent_score=indent_score+1
elif ("ENDDO"ini7)or("END DO"ini7):
indent_score=indent_score-1
elif ("END IF"ini7)or("ENDIF"ini7):
indent_score=indent_score-1
textwrite=i
ncurrline=ncurrline+1
fout.writelines(textwrite)
fout.close()
fin.close()
if__name__=="__main__":
importargparse
importsys
parser=argparse.ArgumentParser(description='Detecte les balises !$mnh_expand et !$mnh_end_expand et ajoute un commentaire avant et après pour corriger l\'indentation par la suite avec correct_indentation.py')
value=argparse.ArgumentParser()
parser.add_argument('file1',metavar='file1',type=str,help="file to check")
parser.add_argument('action',metavar='action',type=str,help="action (indent or detect")
args=parser.parse_args()
if"indent"inargs.action:
sys.exit(correct_indent(args.file1))
elif"detect"inargs.action:
sys.exit(detectMNH_expand(args.file1))
else:
sys.exit("Error : action should be indent or detect. Nothing has been done")