changed reading hint
[gromacs/adressmacs.git] / src / local / copyrgt.c
blob55c561e5d46c31c469d2307da63fdb19ef745b2d
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 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_copyrgt_c = "$Id$";
31 #include "stdio.h"
32 #include "stdlib.h"
33 #include "macros.h"
34 #include "string2.h"
35 #include "futil.h"
36 #include "copyrite.h"
38 static char *head1[]= {
39 "",
40 " This source code is part of",
41 "",
42 " G R O M A C S",
43 "",
44 "GROningen MAchine for Chemical Simulations",
47 static char *head2[] = {
48 "Please refer to:",
49 "GROMACS: A message-passing parallel molecular dynamics implementation",
50 "H.J.C. Berendsen, D. van der Spoel and R. van Drunen",
51 "Comp. Phys. Comm. 91, 43-56 (1995)",
52 "",
53 "Also check out our WWW page:",
54 "http://md.chem.rug.nl/~gmx",
55 "or e-mail to:",
56 "gromacs@chem.rug.nl",
57 "",
58 "And Hey:"
60 #define NH1 asize(head1)
61 #define NCR asize(CopyrightText)
62 #define NH2 asize(head2)
63 #define MAXS 10240
65 void head(FILE *out, char *fn_, bool bH, bool bSRCID,
66 char *cstart, char *ccont, char *cend)
68 int i;
70 fprintf(out,"%s\n",cstart);
71 /* NOTE: the "" are to mislead CVS so it will not replace by version info */
72 fprintf(out,"%s $""Id""$\n",ccont);
73 for(i=0; (i<NH1); i++)
74 fprintf(out,"%s %s\n",ccont,head1[i]);
75 fprintf(out,"%s %s\n",ccont,GromacsVersion());
76 for(i=0; (i<NCR); i++)
77 fprintf(out,"%s %s\n",ccont,CopyrightText[i]);
78 for(i=0; (i<NH2); i++)
79 fprintf(out,"%s %s\n",ccont,head2[i]);
81 fprintf(out,"%s %s\n",ccont,bromacs());
82 fprintf(out,"%s\n",cend);
83 if (bH) {
84 fprintf(out,"\n");
85 fprintf(out,"#ifndef _%s\n",fn_);
86 fprintf(out,"#define _%s\n",fn_);
87 fprintf(out,"\n");
89 if (bSRCID)
90 fprintf(out,"static char *SRCID_%s = \"$""Id""$\";\n",fn_);
91 /* NOTE: the "" are to mislead CVS so it will not replace by version info */
92 fprintf(out,"\n");
95 void cr_c(char *fn)
97 FILE *in,*out;
98 char ofn[1024],line[MAXS+1],cwd[1024];
99 char *p,*fn_;
100 bool bH,bSRCID;
102 sprintf(ofn,"%s.bak",fn);
104 fprintf(stderr,"Processing %s (backed up to %s)\n",
105 fn,ofn);
107 if (rename(fn,ofn) != 0) {
108 perror(ofn);
109 exit(1);
111 in=ffopen(ofn,"r");
112 out=ffopen(fn,"w");
114 /* Skip over empty lines in the beginning only */
115 do {
116 if (fgets2(line,MAXS,in))
117 rtrim(line);
118 } while ((strlen(line) == 0) && (!feof(in)));
120 /* Now we are at end of file, or we have a non-empty string */
121 if (strlen(line) != 0) {
122 if (strstr(line,"/*") != NULL) {
123 /* File does start with comment, so delete it and add new */
124 while ((strstr(line,"*/") == NULL) && (!feof(in)))
125 fgets2(line,MAXS,in);
127 fn_=strdup(fn);
128 p=strchr(fn_,'.');
129 if (p)
130 p[0]='_';
131 bH=FALSE;
132 do {
133 fgets2(line,MAXS,in);
134 if ( (strstr(line,fn_) != NULL) &&
135 (strstr(line,"#define") != NULL) )
136 bH=TRUE;
137 } while ( ( (strstr(line,fn_) != NULL) ||
138 (strstr(line,"static char *SRCID") != NULL) ||
139 (strlen(line)==0) ) && (!feof(in) ) );
140 getcwd(cwd,STRLEN);
141 bSRCID = TRUE;
142 /* Do not put source id's in include/types since some filenames are
143 * be equal to those in include */
144 if ((strlen(cwd)>strlen("types")) &&
145 (strcmp(cwd+strlen(cwd)-strlen("types"),"types") == NULL))
146 bSRCID = FALSE;
147 head(out,fn_,bH,bSRCID,"/*"," *"," */");
148 do {
149 fprintf(out,"%s\n",line);
150 } while (!feof(in) && fgets2(line,MAXS,in));
152 fclose(in);
153 fclose(out);
156 void cr_tex(char *fn)
158 FILE *in,*out;
159 char ofn[1024],line[MAXS+1];
160 char *p;
162 sprintf(ofn,"%s.bak",fn);
164 fprintf(stderr,"Processing (as Tex) %s (backed up to %s)\n",
165 fn,ofn);
167 if (rename(fn,ofn) != 0) {
168 perror(ofn);
169 exit(1);
171 in=ffopen(ofn,"r");
172 out=ffopen(fn,"w");
174 /* Skip over empty lines in the beginning only */
176 if (fgets2(line,MAXS,in))
177 rtrim(line);
178 while ((strlen(line) == 0) && (!feof(in)));
180 /* Now we are at end of file, or we have a non-empty string */
181 if (strlen(line) != 0) {
182 while ((strstr(line,"%") != NULL) && (!feof(in)))
183 /* File does start with comment, so delete it and add new */
184 fgets2(line,MAXS,in);
185 head(out,"",FALSE,FALSE,"%","%","%");
186 /* Skip over empty lines */
187 while ( (strlen(line) == 0) && !feof(in) )
188 if (fgets2(line,MAXS,in))
189 rtrim(line);
191 fprintf(out,"%s\n",line);
192 while (!feof(in) && fgets2(line,MAXS,in));
194 fclose(in);
195 fclose(out);
198 int main(int argc,char *argv[])
200 int i;
201 char *fn,*p;
203 for(i=1; (i<argc); i++) {
204 fn=argv[i];
205 p=strrchr(fn,'.');
206 if ( strcmp(p,".tex")==0 )
207 cr_tex(fn);
208 else
209 cr_c(fn);
211 return 0;