File: format_code.c

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (62 lines) | stat: -rw-r--r-- 1,439 bytes parent folder | download | duplicates (7)
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
/* Formats Mathematica output code after it has been run through the
   sed script to straighten out the continuation lines for free-format
   fortran 90 and "compactify" the code.  Note that 39 continuation
   lines are all that are allowed in the Fortran 95 standard, so more
   are flagged for hand-coding attention.  Lines up to 132 characters
   are allowed, but there is no sense in making the code even less
   readable than this already does. */

#include <stdio.h>

#define MAX_CHAR  65
#define MAX_CONTINUE  39

main()
{
  int c;
  int n_char,n_paren,n_continue;

  n_continue=0;

  printf("\n    ");
  n_char=4;

  while((c = getchar()) != EOF){
    if(c == '#'){
      printf("\n    ");
      n_char = 4;
      n_continue = 0;
      n_paren = 0;
    }
    else if(c == '\\'){
      if((c = getchar()) == '\n'){
        if((c = getchar()) == '#'){
          printf("\n    ");
          n_char = 4;
          n_continue = 0;
          n_paren = 0;
        }
      }
    }

    if(n_char >= MAX_CHAR && c != ')' && n_paren > 0){
      printf("&\n");
      n_continue += 1;
      if(n_continue >= MAX_CONTINUE){
        printf("!***** WARNING: continue lines > MAX_CONTINUE *****\n");
        n_continue = 0;
      }
      printf("&    ");
      n_char = 5;
      n_paren = 0;
    }

    if(c != ' ' && c != '\n' && c != '#'){
      putchar(c);
      n_char += 1;
    }

    if(n_char >= MAX_CHAR && c == ')') n_paren += 1;

  }
}