Tagged files with gromacs 3.0 header and added some license info
[alexxy/gromacs.git] / src / contrib / copyrgt.c
1 /*
2  * $Id$
3  * 
4  *                This source code is part of
5  * 
6  *                 G   R   O   M   A   C   S
7  * 
8  *          GROningen MAchine for Chemical Simulations
9  * 
10  *                        VERSION 3.0
11  * 
12  * Copyright (c) 1991-2001
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  * 
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  * 
31  * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
32  * 
33  * And Hey:
34  * GROup of MAchos and Cynical Suckers
35  */
36 static char *SRCID_copyrgt_c = "$Id$";
37 #include "stdio.h"
38 #include "stdlib.h"
39 #include "macros.h"
40 #include "string2.h"
41 #include "futil.h"
42 #include "copyrite.h"
43
44 static char *head1[]= {
45   "",
46   "               This source code is part of",
47   "",
48   "                G   R   O   M   A   C   S",
49   "",
50   "         GROningen MAchine for Chemical Simulations",
51   ""
52 };
53
54 static char *head2[]= {
55   "This program is free software; you can redistribute it and/or",
56   "modify it under the terms of the GNU General Public License",
57   "as published by the Free Software Foundation; either version 2",
58   "of the License, or (at your option) any later version.",
59   "",
60   "If you want to redistribute modifications, please consider that",
61   "scientific software is very special. Version control is crucial -",
62   "bugs must be traceable. We will be happy to consider code for",
63   "inclusion in the official distribution, but derived work must not",
64   "be called official GROMACS. Details are found in the README & COPYING",
65   "files - if they are missing, get the official version at www.gromacs.org.",
66   "",
67   "To help us fund GROMACS development, we humbly ask that you cite",
68   "the papers on the package - you can find them in the top README file.",
69   "",
70   "Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .",
71   "",
72   "And Hey:"
73 };
74
75 #define NH1 asize(head1)
76 #define NCR asize(CopyrightText)
77 #define NH2 asize(head2)
78 #define MAXS 10240
79
80 void head(FILE *out, char *fn_, bool bH, bool bSRCID,
81           char *cstart, char *ccont, char *cend)
82 {
83   int i;
84
85   fprintf(out,"%s\n",cstart);
86   /* NOTE: the "" are to mislead CVS so it will not replace by version info */
87   fprintf(out,"%s $""Id""$\n",ccont);
88   for(i=0; (i<NH1); i++)
89     fprintf(out,"%s %s\n",ccont,head1[i]);
90   fprintf(out,"%s                        %s\n",ccont,GromacsVersion());
91   for(i=0; (i<NCR); i++)
92     fprintf(out,"%s %s\n",ccont,CopyrightText[i]);
93   for(i=0; (i<NH2); i++)
94     fprintf(out,"%s %s\n",ccont,head2[i]);
95
96   fprintf(out,"%s %s\n",ccont,bromacs());
97   fprintf(out,"%s\n",cend);
98   if (bH) {
99     fprintf(out,"\n");
100     fprintf(out,"#ifndef _%s\n",fn_);
101     fprintf(out,"#define _%s\n",fn_);
102     fprintf(out,"\n");
103   }
104   if (bSRCID)
105     fprintf(out,"static char *SRCID_%s = \"$""Id""$\";\n",fn_);
106   /* NOTE: the "" are to mislead CVS so it will not replace by version info */
107   /*fprintf(out,"\n");*/
108 }
109
110 void cr_c(char *fn)
111 {
112   FILE *in,*out;
113   char ofn[1024],line[MAXS+1],cwd[1024];
114   char *p,*fn_;
115   bool bH,bSRCID;
116   
117   sprintf(ofn,"%s.bak",fn);
118   
119   fprintf(stderr,"Processing %s (backed up to %s)\n",
120           fn,ofn);
121   
122   if (rename(fn,ofn) != 0) {
123     perror(ofn);
124     exit(1);
125   }
126   in=ffopen(ofn,"r");
127   out=ffopen(fn,"w");
128   
129   /* Skip over empty lines in the beginning only */
130   do { 
131     if (fgets2(line,MAXS,in))
132       rtrim(line); 
133   } while ((strlen(line) == 0) && (!feof(in)));
134   
135   /* Now we are at end of file, or we have a non-empty string */
136   if (strlen(line) != 0) {  
137     if (strstr(line,"/*") != NULL) {
138       /* File does start with comment, so delete it and add new */
139       while ((strstr(line,"*/") == NULL) && (!feof(in)))
140         fgets2(line,MAXS,in);
141     }
142     fn_=strdup(fn);
143     p=strchr(fn_,'.');
144     if (p)
145       p[0]='_';
146     bH=FALSE;
147     do {
148       fgets2(line,MAXS,in);
149       if ( (strstr(line,fn_) != NULL) && 
150            (strstr(line,"#define") != NULL) )
151         bH=TRUE;
152     } while ( ( (strstr(line,fn_) != NULL)  ||
153                 (strstr(line,"static char *SRCID") != NULL) ||
154                 (strlen(line)==0) ) && (!feof(in) ) );
155     getcwd(cwd,STRLEN);
156     bSRCID = TRUE;
157     /* Do not put source id's in include/types since some filenames are
158      * be equal to those in include */
159     if ((strlen(cwd)>strlen("types")) &&
160         (!strcmp(cwd+strlen(cwd)-strlen("types"),"types")))
161       bSRCID = FALSE;
162     head(out,fn_,bH,bSRCID,"/*"," *"," */");
163     do {
164       fprintf(out,"%s\n",line);
165     } while (!feof(in) && fgets2(line,MAXS,in));
166   }
167   fclose(in);
168   fclose(out);
169 }
170
171 void cr_other(char *fn)
172 {
173
174   /* Doesnt work right now, so its commented out */
175   /*  FILE *in,*out;
176   char ofn[1024],line[MAXS+1],line2[MAXS+1],cwd[1024];
177   char *p,*fn_,*ptr;
178   bool bH,bSRCID;
179   
180   sprintf(ofn,"%s.bak",fn);
181   
182   fprintf(stderr,"Processing %s (backed up to %s)\n",
183           fn,ofn);
184   
185   if (rename(fn,ofn) != 0) {
186     perror(ofn);
187     exit(1);
188   }
189   in=ffopen(ofn,"r");
190   out=ffopen(fn,"w");
191   */
192   /* Skip over empty lines in the beginning only */
193   /*
194   do { 
195     if (fgets2(line,MAXS,in))
196       rtrim(line);
197   } while ((strlen(line) == 0) && (!feof(in)));
198   */
199   /* Now we are at end of file, or we have a non-empty string */
200   /*
201   if (strlen(line) != 0) {  
202     strcpy(line2,line);
203     trim(line2);
204     while ((line2[0] == ';') && (!feof(in))) {
205       fgets2(line,MAXS,in);
206       strcpy(line2,line);
207       trim(line2);
208       }
209   */
210     /*
211     fn_=strdup(fn);
212     p=strchr(fn_,'.');
213     if (p)
214       p[0]='_';
215     bH=FALSE;
216     do {
217       fgets2(line,MAXS,in);
218       if ( (strstr(line,fn_) != NULL) && 
219            (strstr(line,"#define") != NULL) )
220         bH=TRUE;
221     } while ( ( (strstr(line,fn_) != NULL)  ||
222                 (strstr(line,"static char *SRCID") != NULL) ||
223                 (strlen(line)==0) ) && (!feof(in) ) );
224     getcwd(cwd,STRLEN);
225     bSRCID = TRUE;
226     */
227     /* Do not put source id's in include/types since some filenames are
228      * be equal to those in include */
229     /*if ((strlen(cwd)>strlen("types")) &&
230         (strcmp(cwd+strlen(cwd)-strlen("types"),"types") == NULL))
231     */
232   /*
233   bSRCID = FALSE;
234     head(out,fn_,bH,bSRCID,";",";",";");
235     do {
236       fprintf(out,"%s\n",line);
237     } while (!feof(in) && fgets2(line,MAXS,in));
238   }
239   fclose(in);
240   fclose(out);
241   */
242 }
243
244 void cr_tex(char *fn)
245 {
246   FILE *in,*out;
247   char ofn[1024],line[MAXS+1];
248   char *p;
249   
250   sprintf(ofn,"%s.bak",fn);
251   
252   fprintf(stderr,"Processing (as Tex) %s (backed up to %s)\n",
253           fn,ofn);
254   
255   if (rename(fn,ofn) != 0) {
256     perror(ofn);
257     exit(1);
258   }
259   in=ffopen(ofn,"r");
260   out=ffopen(fn,"w");
261   
262   /* Skip over empty lines in the beginning only */
263   do
264     if (fgets2(line,MAXS,in))
265       rtrim(line);
266   while ((strlen(line) == 0) && (!feof(in)));
267   
268   /* Now we are at end of file, or we have a non-empty string */
269   if (strlen(line) != 0) {  
270     while ((strstr(line,"%") != NULL) && (!feof(in)))
271       /* File does start with comment, so delete it and add new */
272       fgets2(line,MAXS,in); 
273     head(out,"",FALSE,FALSE,"%","%","%");
274     /* Skip over empty lines */
275     while ( (strlen(line) == 0) && !feof(in) )
276       if (fgets2(line,MAXS,in))
277         rtrim(line);
278     do
279       fprintf(out,"%s\n",line);
280     while (!feof(in) && fgets2(line,MAXS,in));
281   }
282   fclose(in);
283   fclose(out);
284 }
285
286 int main(int argc,char *argv[])
287 {
288   int i;
289   char *fn,*p;
290   
291   for(i=1; (i<argc); i++) {
292     fn=argv[i];
293     p=strrchr(fn,'.');
294     if ( strcmp(p,".tex")==0 )
295       cr_tex(fn);
296     else if ((strcmp(p,".c") == 0) || (strcmp(p,".h") == 0))
297       cr_c(fn);
298     else
299       cr_other(fn);
300   }
301   return 0;
302 }