summaryrefslogtreecommitdiff
path: root/experimental/doligez/checkheaders
blob: 779c8c88623f0a9c967e1004a4b57ec818a88ed8 (plain)
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
#!/bin/sh

#######################################################################
#                                                                     #
#                                OCaml                                #
#                                                                     #
#          Damien Doligez, projet Gallium, INRIA Rocquencourt         #
#                                                                     #
#  Copyright 2011 Institut National de Recherche en Informatique et   #
#  en Automatique.  All rights reserved.  This file is distributed    #
#  under the terms of the Q Public License version 1.0.               #
#                                                                     #
#######################################################################

(
case $# in
  0) find . -type f -print;;
  *) echo $1;;
esac
) | \
while read f; do
awk -f - "$f" <<\EOF

function checkline (x) {
  return ( $0 ~ ("^.{0,4}" x) );
}

function hrule () {
  return (checkline("[*#]{69}"));
}

function blank () {
  return (checkline(" {69}"));
}

function ocaml () {
  return (checkline(" {32}OCaml {32}") \
       || checkline(" {35}OCaml {32}") \
       || checkline("                 MLTk, Tcl/Tk interface of OCaml                     ") \
       || checkline("                         OCaml LablTk library                          ") \
       || checkline("                             ocamlbuild                              ") \
       || checkline("                             OCamldoc                                ") \
  );
}

function any () {
  return (checkline(".{69}"));
}

function copy1 () {
  return (checkline("  Copyright +[-0-9]+ +Institut +National +de +Recherche +en +Informatique +et   "));
}

function copy2 () {
  return (checkline("  en Automatique"));
}

function err () {
  printf ("File \"%s\", line %d:\n", FILENAME, FNR);
  printf ("  Error: line %d of header is wrong.\n", FNR + offset);
  print $0;
}

function add_ignore_re (x) {
    ignore_re[++ignore_re_index] = x;
}

function add_exception (x) {
    exception[++exception_index] = x;
}

FNR == 1 {
  offset = 0;
  add_ignore_re("/\\.svn/");
  add_ignore_re("/\\.depend(\\.nt)?$");
  add_ignore_re("/\\.ignore$");
  add_ignore_re("\\.gif$");
  add_ignore_re("/[A-Z]*$");
  add_ignore_re("/README\\.[^/]*$");
  add_ignore_re("/Changes$");
  add_ignore_re("\\.mlpack$");
  add_ignore_re("\\.mllib$");
  add_ignore_re("\\.mltop$");
  add_ignore_re("\\.clib$");
  add_ignore_re("\\.odocl$");
  add_ignore_re("\\.itarget$");
  add_ignore_re("^\\./boot/");
  add_ignore_re("^\\./camlp4/test/");
  add_ignore_re("^\\./camlp4/unmaintained/");
  add_ignore_re("^\\./config/gnu/");
  add_ignore_re("^\\./experimental/");
  add_ignore_re("^\\./ocamlbuild/examples/");
  add_ignore_re("^\\./ocamlbuild/test/");
  add_ignore_re("^\\./otherlibs/labltk/builtin/");
  add_ignore_re("^\\./otherlibs/labltk/examples_");
  add_ignore_re("^\\./testsuite/");
  for (i in ignore_re){
      if (FILENAME ~ ignore_re[i]) { nextfile; }
  }
  add_exception("./asmrun/m68k.S");                     # obsolete
  add_exception("./build/camlp4-bootstrap-recipe.txt");
  add_exception("./build/new-build-system");
  add_exception("./ocamlbuild/ChangeLog");
  add_exception("./ocamlbuild/manual/myocamlbuild.ml"); # TeX input file ?
  add_exception("./ocamlbuild/manual/trace.out");       # TeX input file
  add_exception("./ocamldoc/Changes.txt");
  add_exception("./ocamldoc/ocamldoc.sty");             # public domain
  add_exception("./otherlibs/labltk/browser/help.txt");
  add_exception("./otherlibs/labltk/camltk/modules");   # generated
  add_exception("./otherlibs/labltk/labltk/modules");   # generated
  add_exception("./tools/objinfo_helper.c");            # non-INRIA
  add_exception("./tools/magic");                       # public domain ?
  add_exception("./Upgrading");
  add_exception("./win32caml/inriares.h");              # generated
  add_exception("./win32caml/ocaml.rc");                # generated
  add_exception("./win32caml/resource.h");              # generated
  for (i in exception){
      if (FILENAME == exception[i]) { nextfile; }
  }
}

# 1 [!hrule]     #!
# 2 [!hrule]     empty
# 3 hrule
# 4 [blank]
# 5 ocaml        title
# 6 blank
# 7 any          author
# 8 [!blank]     author
# 9 [!blank]     author
#10 blank
#11 copy1        copyright
#12 copy2        copyright
#13 any          copyright
#14 [!blank]     copyright
#15 [!blank]     copyright
#16 blank
#17 hrule

FNR + offset == 1 && hrule() { ++offset; }
FNR + offset == 2 && hrule() { ++offset; }
FNR + offset == 3 && ! hrule() { err(); nextfile; }
FNR + offset == 4 && ! blank() { ++offset; }
FNR + offset == 5 && ! ocaml() { err(); nextfile; }
FNR + offset == 6 && ! blank() { err(); nextfile; }
FNR + offset == 7 && ! any() { err(); nextfile; }
FNR + offset == 8 && blank() { ++offset; }
FNR + offset == 9 && blank() { ++offset; }
FNR + offset ==10 && ! blank() { err(); nextfile; }
FNR + offset ==11 && ! copy1() { err(); nextfile; }
FNR + offset ==12 && ! copy2() { err(); nextfile; }
FNR + offset ==13 && ! any() { err(); nextfile; }
FNR + offset ==14 && blank() { ++offset; }
FNR + offset ==15 && blank() { ++offset; }
FNR + offset ==16 && ! blank() { err(); nextfile; }
FNR + offset ==17 && ! hrule() { err(); nextfile; }

EOF
done