1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
|
For installation instructions and usage, see README.1st and INSTALL
This document is a not very well structured story about findent.
You can skip this and use findent after reading the output of
findent -h.
Findent: what?
==============
Findent is an indenter for Fortran programs, fixed and free format.
Findent can also translate fixed format to free format and vice versa.
Since version 3.0.0, findent can generate dependencies based on USE,
MODULE, SUBMODULE, INCLUDE, #include, ??include and emit a sh script
that, using findent, creates a dependency file to be used in a Makefile.
Since version 4.1.0, findent can relabel Fortran sources.
Findent indents more than 100K lines per second, so usage as a
standard indenter in an editor works very well, see 'findent and vim',
'findent and gedit' and 'findent and emacs' below.
Findent will take care of:
continuation lines
multi-statement lines
labelled and unlabelled do-loops
IF
IF ... THEN ... ENDIF
where
FORALL
WHERE constructs
FORALL constructs
etc. see findentclass.cpp for details
Findent will remove trailing spaces and tabs, and convert
tabs at the start of a line into spaces. By default, statement
labels are placed at the start of a line. Apart from this and
indenting, findent will not alter the input, trying to
preserve alignment. For example, the alignment in:
X = 3.0*A + 4*B + &
& 2 *C + Y
will remain intact.
Optionally, findent will refactor lines that end a subroutine etc.:
SUBROUTINE SUB
...
END FUNCTION MYFUN
will become:
SUBROUTINE SUB
...
END SUBROUTINE SUB
Findent is space-insensitive, for example a line like:
REALFUN CTIONFUN(X)
is recognized as the start of a function definition.
Usage:
findent -h
Findent: why?
=============
There are a number of public domain Fortran indenting tools, for example:
- vim is shipped with an simple Fortran indenter
- emacs has a Fortran indenter
- floppy, only for fixed format: http://www.netlib.org/floppy/
- convert.f90: converts from fixed to free format, and indents:
ftp://ftp.numerical.rl.ac.uk/pub/MandR/convert.f90
- f2f90: based on convert.f90: http://www.fortran.com/f2f90.tar.gz
- f90ppr: an impressive piece of software that beautifies
Fortran code and contains a macro processor.
http://fortranwiki.org/fortran/show/f90ppr
- fprettify: an indenter and beautifier, written in Python.
IMHO not mature at the time of this writing (august 2018).
https://github.com/pseewald/fprettify
For me, the problem with these tools is, that
- they are too simple (for example, do not recognize labelled
do-loops)
- or do too much (destroying neatly aligned pieces of code)
- or are for me too complicated to adapt and extend.
Furthermore, I want that indenting does not make irreversible changes
to the source: I want always be able to get back to the version after
the first indenting. (Exceptions: converting from fixed to free format
or vice-versa; adding 'subroutine foo' after 'end'; relabeling).
Therefore I decided, having some spare time after my retirement,
to try to build a Fortran indenter, based on flex and bison for
readability.
As programming language I chose C++, because of the availability
of string, deque, set and map.
After more or less finishing the indenting part, I realized that
findent should be able to play a role in determining the dependencies
based on (sub)modules and various kinds of includes. So I added some
lines to accomplish this. Together with an simple script
dependencies are easily created. See 'man findent' under '--deps' for
details.
There are some tools that can generate dependencies for Fortran
projects:
- makedepf90: see https://github.com/outpaddling/makedepf90, also
in debian and ubuntu. It seems that there is no support for
submodules, but apart from that it seems to work well.
- f90_mod_deps.py: see
http://lagrange.mechse.illinois.edu/f90_mod_deps/f90_mod_deps.py
does not seem to work properly.
- fortdepend: see https://github.com/ZedThree/fort_depend.py
Does not work with submodules and is picky about END statements.
I did not investigate if these tools can cope with split MODULE and
USE lines and fixed-format space-independent source code.
Findent: how?
=============
So, here it is, a Fortran indenter to my taste, based on flex,
bison and g++.
The program performs the following major tasks:
- determine the input format: free or fixed
- glue together continuation lines removing comments
- pre-process the assembled input line, to make it better processable
by flex: remove white space, substitute strings, hollerith's,
statement label and operators like .EQ. by special tokens
- perform a two-stage parsing:
- try if the line is an assignment
- if it is not an assignment, parse the line using as tokens the
Fortran keywords (SUBROUTINE, DO, ...)
- based on the outcome of the parse, determine the indentation
- output the lines that were read in to compose the full line,
trying to preserve the lay-out after the original leading white
space, optionally converting from fixed-form to free-form.
Also optionally, lines that end a subroutine, program etc.,
are completed (or even modified) as in:
END subroutine mysub
Preprocessor statements are accounted for to prevent that code like:
#ifdef one
SUBROUTINE ONE
#else
SUBROUTINE TWO
#endif
would result in a double SUBROUTINE indentation.
Moreover, track is kept of do-labels, in order to correctly indent
constructs like:
DO 10 I=1,20
DO 10 J=1,10
X(I) = Y(I)+J
10 CONTINUE
Findent: structure
==================
In version 2.8.4, a major reorganizing has been done, trying to
make the source more readable and more object-oriented.
These are the classes (all starting with a capital):
- Debugostream
This class contains code for debugging.
- Docs
This class contains code (often generated) to output help-
texts (includeing this text) etcetera.
- Findentclass
Findentclass contains basic functions and variables that
are used throughout the program, such as:
int determine_fix_or_free()
if the input format is not given (parameter -ifixed
or -ifree), this function tries to find a proof that
the program is free-format. If so, FREE is returned,
else FIXED.
Fortranline mygetline()
Reads a line from STDIN.
Optionally, the function builds a buffer to store the
line just read, this option is used by determine_fixed_or_free().
Fortranline Getline()
Uses the buffer from mygetline() or mygetline() to return
a Fortranline. Optionally, maintains a buffer (wizardbuffer)
to enable a look-ahead for the wizard functions.
- Fortranline
This class contains a line of fortran code, and has many
frequently used functions operating on that line.
- Fortran
This is an abstract class with functions and variables needed
to construct a 'full_statement': a string that is composed
of pure fortran code (stripped from comments, preprocessor
directives, ..) and a deque of lines that constructed the
full_statement, including comments and preprocessor statements.
The pure virtual functions are filled in by class Fixed or
class Free, depending on the format of the input.
The indentation required is computed from full_statement
and the current indentation.
Special provisions are made for storing labelled do statements,
preprocessor statements and more.
- Free
This class is a child of Fortran, and contains functions to
indent and output the deque containing the continuation lines
of a free format fortran source.
Also, when conversion from free to fixed format is required,
there is code to store the continuation lines in a fixed
(not properly indented) deque, and present this to Fixed to
output this in a properly indented format.
- Fixed
Basically the same as Free, but vice-versa.
There is a special issue: to determine if there are continuation
lines, a wizard has been created that can look ahead, see
getnext() in Findentclass.
- Flags
This class implements a container for the flags (-ifree, -i4 ...)
and contains code to interpret the flags.
- Globals
This class implements a container for a few global variables.
Maybe, one would be tempted to make these static, but I tried
not to use static variables in order to able to run more than
one Findent in one program, one reading from STDIN, the other
from a file for example.
- Line_prep
This class contains code to pre-analyze a full_statement to
make the work easier for the lexer and parser.
- Pre_analyzer
This class contains code to see if a line is a preprocessor
statement or a findentfix: line.
- Simpleostream
This class implements a simple filter to std::cout.
The program starts in findent.cpp, and goes on in fortranrun.cpp.
The whole thing is somewhat more hairy than I would like to see.
I did not succeed to make the whole thing strictly hierarchical,
and solved this by giving classes access to the internals of
other classes using pointers. But, like in biology, in creating
a program, there is no law to keep it simple.
Btw, when adding the relabel option, I had to revise class-related
things a bit, so maybe the information above is not entirely correct.
Findent: relabel
================
Since version 4.1.0, findent optionally relabels, see the man page.
Relevant flags (see the man page):
--relabel
--relabel=<startlabel>,<increment>
--relabel=shuffle
--relabel-restart
--query-relabel
I strongly advise to check your Fortran program after relabeling,
please let me know if there are problems.
Relabeling is done on a subroutine/function/program basis:
the input is read until a start of a subroutine etc. is found,
and stored in a buffer until the corresponding end is found,
creating a list of defined and used labels.
If something goes wrong (for example: usage of an undefined
label), relabeling is abandoned for the current subroutine etc,
and for the rest of the input.
If everything seems ok, a second pass is started to perform
the actual relabeling.
The complete input, relabeled or not, is presented to the
indenter/converter, so all flags are honoured.
The following constructs are candidates for relabeling:
- 100,110,120,130: label
- X: integer or real or logical expression
- I: identifier
- [,]: optional comma
- ...: not parsed by findent, can be almost anything except '=...'
- [IF]: optional IF(...)
100 ... ! statement or format label
IF(...) 110,120,130
IF(...) 110,120
DO 100[,] I=X,...
DO 100[,] WHILE(...)
DO 100[,] CONCURRENT(...)
DO 100
[IF] ACCEPT 100...
[IF] ASSIGN 100 TO I
[IF] BACKSPACE(...,ERR=100,...)
[IF] CALL I(...,*100,...,&110,...,$120,...)
[IF] CLOSE(...,ERR=100,...)
[IF] DECODE(...,100,...,ERR=110,...)
[IF] DELETE(...,ERR=110,...)
[IF] ENCODE(...,100,...,ERR=110,...)
[IF] ENDFILE(...,ERR=100,...)
[IF] FIND(...,ERR=110,...)
[IF] FLUSH(...,ERR=100,...)
[IF] GOTO 100
[IF] GOTO I[,](100,110,120)
[IF] GOTO(100,110,120)...
[IF] INQUIRE(...,ERR=100,...)
[IF] OPEN(...,ERR=100,...)
[IF] PRINT 100...
[IF] READ 100...
[IF] READ(...,100,...)
[IF] READ(...,ERR=100,...,END=110,EOR=120,...,FMT=130)...
[IF] REREAD 100...
[IF] REREAD(...,100,...)
[IF] REREAD(...,ERR=100,...,END=110,EOR=120,...,FMT=130)...
[IF] REWIND(...,ERR=100,...)
[IF] REWRITE(...,100) ...
[IF] REWRITE(...,ERR=100,...,FMT=110,...,EOR=120)...
[IF] TYPE 100...
[IF] WAIT(...,ERR=100,...,END=110,...,EOR=120,...)
[IF] WRITE(...,100) ...
[IF] WRITE(...,ERR=100,...,FMT=110,...,EOR=120)...
relabel=shuffle
===============
In stead of neatly renumbering your labels, you can also choose to randomly
shuffle them, thereby keeping the semantics of your program the same, of course.
This option is added for demo purposes and for debugging, and will not be used
in a typical development environment.
Findent: usage
==============
Findent reads from standard input and writes to standard output:
findent < prog.f90 > prog1.f90
See also 'wfindent' below.
The command
findent -h
gives an overview of the possible flags and there effect. Most
interesting are:
-i<n>
example: -i5
which determines the amount of indent to be used by every
item that calls for indenting
-Ia
The starting indent is determined from the first line (more
or less), useful when using findent within vim, for example
to intent a selected region:
'<,'>:!findent -Ia
-ofree
converts from fixed format to free format.
-L<n>
example: -L72
limit input line length to 72 characters.
NOTE 1: Findent knows about tabbed input: for fixed-format input,
the following transformations are made:
10<tab>I= -> 10<sp><sp><sp><sp>I=
<tab>1K*J -> <sp><sp><sp><sp><sp>1K*J
<tab>X=Y -> <sp><sp><sp><sp><sp><sp>X=Y
So, a tab followed by 1-9 is transformed to a continuation line,
otherwise to a normal line, starting in column 7.
NOTE 2: Findent silently ignores errors in the flags
NOTE 3: Handling of continuation lines
Example:
a = &
(/ 3, 10, 12, 4, &
5, 9, 1, 0, &
13, 2, 25, 6 /)
After running findent, with standard parameters, you get this:
a = &
(/ 3, 10, 12, 4, &
5, 9, 1, 0, &
13, 2, 25, 6 /)
That is probably not what you really want.
The recommended solution is: add '&' at the start of the
continuation lines:
a = &
& (/ 3, 10, 12, 4, &
& 5, 9, 1, 0, &
& 13, 2, 25, 6 /)
Findent will indent this as:
a = &
& (/ 3, 10, 12, 4, &
& 5, 9, 1, 0, &
& 13, 2, 25, 6 /)
Not recommended solution: You can use the '-k-' flag, like:
findent -k- < prog.f90 > prog1.f90
Findent will in this case not touch continuation lines without
a starting '&', but leave them as they are.
NOTE 4:
Findent does not check the length of an output line, so it could
be that the length will be larger than 72 or 132 for fixed and
free format respectively. In fact, indenting old fixed format
sources will very likely result in lines longer than 72 columns.
If you are lucky, the compiler will generate an error message,
but too long lines can result in changing the semantics of a
program without notice.
Advice: use a compiler flag that allows long lines:
gfortran, free format: -ffree-line-length-none # unlimited
gfortran, fixed formtat: -ffixed-line-length-none # unlimited
ifort, free format: # no flag needed, default is unlimited
ifort, fixed format: -132 # max line length is 132
pgf90, free format: # max line length is 264,
# error if longer
pgf90, fixed format: -Mextend # max line length is 132,
# no error if longer
NOTE 4.1:
Here a script to check for line length:
>>>> snip ---------- checklength ---------------------------------------
#!/bin/sh
# checks file line lengths
# Usage:
# checklength <length> [file ...]
# outputs "filename:line number:line length:line" for lines longer than length
# tabs are converted to spaces using expand
# if no file is given, read from stdin
usage()
{
echo "Usage:"
echo "$0 <length> [file ...]"
}
if [ -z "$1" ] ; then
usage
exit 1
fi
l="$1"
doit()
{
expand | awk -v l="$1" -v f="$2" '{
if (length($0) > l)
printf "%s:%d:%d:%s\n",f,FNR,length($0),$0
}'
}
if [ -z "$2" ] ; then
doit "$l" "-"
exit 0
fi
shift
while [ "$1" ] ; do
cat "$1" | doit "$l" "$1"
shift
done
<<<< snip ---------- checklength --------------------------------------
Example of usage:
checklength 72 *.f
NOTE 5: handling of comment lines
Findent indents comment lines, but does not touch comment lines
with the '!' in column one.
NOTE 5.1: handling of comment lines converting fixed to free format
As said above, findent does not touch comments starting
in column 1. Since all vintage comments start in column 1,
this has the effect that these comments will not be indented
when converting from fixed to free format (using -ofree).
If you want the comments indented, convert to free format,
add a space before every line and use findent again.
Example if the stream editor 'sed' is available:
findent -ofree < prog.f | sed 's/^/ /' | findent > prog.f90
If 'sed' is not available (on Windows for example), you
can create the program 'addspace' or, on Windows, 'addspace.exe'
by compiling this program:
>>>> snip -------- addspace.f ------------------------------------------
program addspace
implicit none
character(1000) :: line
integer :: io
do
read(*,'(a)',iostat=io) line
if (io .ne. 0) exit
write(*,'(1x,a)') trim(line)
enddo
end program addspace
<<<< snip -------- addspace.f ------------------------------------------
Or, if you have a vintage Fortran-4 compiler, by compiling
this program:
>>>> snip -------- ADDSPACE.F ------------------------------------------
DIMENSION L(1000)
DATA LB/1H /
10 DO 15 I=1,1000
15 L(I)=LB
READ(5,100,END=30) L
DO 20 I=1000,1,-1
IF (L(I)-LB) 25,20,25
20 CONTINUE
WRITE(6,110)
GOTO 10
25 WRITE(6,110) (L(J),J=1,I)
GOTO 10
30 CONTINUE
100 FORMAT(1000A1)
110 FORMAT(1H ,1000A1)
END
<<<< snip -------- ADDSPACE.F ------------------------------------------
Use the generated program 'addspace' in stead of 'sed':
findent -ofree < prog.f | addspace | findent > prog.f90
Findent: failure, findentfix:
=============================
One thing is certain: findent contains errors. I appreciate it
if you bring errors to my attention. If possible I will fix them.
On the other hand, it is possible to fool findent, for example
by using #ifdef, #else, #endif in a way that confuses findent.
Both cases can be solved using ! findentfix: , read on:
The next program will not be indented correctly:
>>>> snip -------- fixdemo.f90 -----------------------------------------
! compile with: gfortran -cpp fixdemo.f90
! or
! gfortran -cpp -DLOOPJ fixdemo.f90
program fixdemo
implicit none
integer i,j
j=4
do i=1,3
#ifdef LOOPJ
do j=1,2
#endif
print *,i*j
enddo
#ifdef LOOPJ
enddo
print *,'with j-loop'
#else
print *,'without j-loop'
#endif
continue
end program fixdemo
<<<< snip -------- fixdemo.f90 -----------------------------------------
That is because findent takes the indentation from:
#ifdef LOOPJ
do j=1,2
#endif
and
#else
print *,'without j-loop'
#endif
So, findent is missing an enddo for the j-loop.
In this case, the solution would be to insert #else just before the
first #endif.
If, however, in a real-world example this is not possible, or
when findent really makes an error, you can use findentfix.
In the example above, insert directly after the last #endif:
! findentfix: enddo
and findent will indent correctly. In general, the text after
! findentfix:
will be used by findent as a normal source line, so the following
could also be useful:
! FINDENTfix: subroutine dummy
! findentFIX: do;do;do
! FINDENTFIX: end;end
! findentfix: where ()
But the following would do nothing:
! findentfix: continue
Findent: creating a dependency file for use in an Makefile.
===========================================================
findent --deps < prog.f90
prints the dependencies found in prog.f90, based on USE,
MODULE, SUBMODULE, INCLUDE, #include and ??include.
This is used by the sh script makefdeps to create a dependency
file for use in an Makefile.
Creation of the makefdeps script:
findent --makefdeps > makefdeps
chmod +x makefdeps
The command:
./makefdeps *.f90
will output a dependency file, to be used in an Makefile.
The dependencies are based on .o files, for example:
main.o: sub1.o sub2.o
sub1.o: sub1.inc
Example Makefile and fortran sources to create 'program' from
main.f90 sub1.f90 sub2.f90 sub.inc:
>>>> snip ---------- Makefile ---------------------------------------
SRCS = main.f90 sub1.f90 sub2.f90
OBJS = $(SRCS:.f90=.o)
%.o: %.f90
gfortran -c -o $@ $<
program: $(OBJS)
gfortran -o $@ $(OBJS)
include deps
dep deps:
findent --makefdeps < /dev/null > makefdeps.sh
@if [ "`head -n 1 makefdeps.sh`" != "#!/bin/sh" ] ; then \
findent -v 1>&2; \
echo "Use findent version >= 3.0.0" 1>&2 ; exit 1 ; fi
chmod +x makefdeps.sh
./makefdeps.sh $(SRCS) > deps
clean:
rm -f *.o *.mod *.smod program deps
<<<< snip ---------- Makefile ---------------------------------------
>>>> snip ---------- main.f90 ---------------------------------------
program main
use mymod1
use mymod
call sub1
call sub
end
<<<< snip ---------- main.f90 ---------------------------------------
>>>> snip ---------- sub1.f90 ---------------------------------------
module mymod1
contains
subroutine sub1
print *,'this is sub1'
end
end
module mymod
interface
module subroutine sub
end subroutine
end interface
end module
<<<< snip ---------- sub1.f90 ---------------------------------------
>>>> snip ---------- sub2.f90 ---------------------------------------
submodule (mymod) mymod2
contains
module procedure sub
include 'sub.inc'
end procedure
end submodule
<<<< snip ---------- sub2.f90 ---------------------------------------
>>>> snip ---------- sub.inc ---------------------------------------
print *,'this is sub'
<<<< snip ---------- sub.inc ---------------------------------------
The fortran sources will be compiled in correct order, you can even
use parallel make (make -j). BTW: this example uses the SUBMODULE
statement: you need to have gfortran >= 6 to compile.
Findent: installation:
======================
(For a more comprehensive text, see README.1st and INSTALL)
Linux:
$ ./configure --prefix=/usr/local
$ make
On systems with sudo (Debian, Ubuntu, Mint, ...):
$ sudo make install
On systems without sudo (Redhat, Scientific Linux, ...):
$ su -c 'make install'
Windows:
copy findent.exe C:\WINDOWS
wfindent
========
wfindent, a sh shell script, indents Fortran source in-place,
performing a sanity check.
It accepts all flags that findent accepts.
Usage:
wfindent [ findent flags ] files
example
wfindent -I4 *.f90
Installation:
If you installed findent with the ./configure, make, make install
method, wfindent is installed as well.
Otherwise:
On systems with sudo (Debian, Ubuntu, Mint, ...):
$ sudo install scripts/wfindent /usr/local/bin
On systems without sudo (Redhat, Scientific Linux, ...):
$ su -c 'make install'
wfindent.bat
============
wfindent.bat is for usage in the cmd shell of Windows and has the same
functionality as wfindent, described just above.
Installation:
copy wfindent.bat C:\WINDOWS
Findent and vim
===============
Findent is since version 2.7 very vim-aware. When using the vim scripts
(look at findent --vim-help), findent is used as equalprg
( :help equalprg )
and indentexpr ( :help indentexpr )
Findent can emit configuration files, look at the output of:
findent --vim_help
Findent and gedit
=================
To enable findent in gedit, look at the output of:
findent --gedit_help
Findent and emacs
=================
To enable findent in emacs, look at the output of:
findent --emacs_help
Issues
======
Since findent parses line-by-line, there are situations that are
ambiguous:
F(X) = X**2 An assignment or a statement function?
ELSE WHERE Is this an ELSEWHERE as in
WHERE(X .EQ. 0)
Y=10
ELSE WHERE
Y=1
END WHERE
or is it part of an IF construct with name WHERE:
WHERE: IF (X .EQ. 0) THEN
Y=10
ELSE WHERE
Y=1
ENDIF WHERE
Findent chooses the first possibility.
And there must be more ...
Luckily, it seems that these ambiguities do not affect indentation.
I tried to make findent Fortran-2008 compatible. This raised another
ambiguity, because findent is space-insensitive:
MODULE PROCEDURE MYPROC Is this an module PROCEDUREMYPROC or
an moduleprocedure MYPROC?
Findent assumes the last.
Thanks to
=========
It would not be possible for me to create findent if I could not stand
of the shoulders of other free software projects. In alphabetical order
(and probably forgetting some):
autoconf: https://www.gnu.org/software/autoconf/autoconf.html
bash: https://www.gnu.org/software/bash/
bison: https://www.gnu.org/software/bison/
debian: https://www.debian.org/
flex: https://github.com/westes/flex
g++: https://gcc.gnu.org/
gcc: https://gcc.gnu.org/
gfortran: https://gcc.gnu.org/wiki/GFortran
gnu software: https://www.gnu.org/
kcachegrind: https://kcachegrind.github.io/html/Home.html
linux: https://en.wikipedia.org/wiki/Linux
make: https://www.gnu.org/software/make/
ubuntu: https://www.ubuntu.com/
valgrind: http://valgrind.org/
vim: https://www.vim.org/
The website http://www.cplusplus.com/ helped me to find a way through C++.
I like to thank the people who gave suggestions to improve the functionality
of findent.
=============================================================================
I am happy to receive comments, error reports and suggestions for
improvements.
June 2022, Willem Vermin, wvermin@gmail.com
|