4 int drop_comment( char *);
5 int change_to_lower( char *, int );
8 main( int argc
, char *argv
[] )
13 char wrf_error_fatal_str
[256] ;
14 char surface_driver_str
[256] ;
15 char radiation_driver_str
[256] ;
16 char cumulus_driver_str
[256] ;
17 char pbl_driver_str
[256] ;
26 fprintf(stderr
,"usage: %s file\n",argv
[0]) ;
28 if ((fp
= fopen(argv
[1],"r"))==NULL
) {
29 fprintf(stderr
,"cannot open %s for reading\n",argv
[1]) ;
32 while ( fgets( linei
, 2048, fp
) != NULL
) {
34 if ( linei
[0] != '#' ) drop_comment( linei
) ;
36 for ( p
= linei
, q
= lineo
, firstp
= *p
; *p
; p
++ ) {
37 if ( !inacall
&& (*(p
+0) == 'c' || *(p
+0) == 'C' ) &&
38 (*(p
+1) == 'a' || *(p
+1) == 'A' ) &&
39 (*(p
+2) == 'l' || *(p
+2) == 'L' ) &&
40 (*(p
+3) == 'l' || *(p
+3) == 'L' ) && firstp
!= '#' )
43 strncpy(q
,p
,4) ; q
+=4 ;
44 ns
= 1 ; while ( *(p
+3+ns
) && *(p
+3+ns
) != '\n' &&
46 *(p
+3+ns
) == '\t' )) { *q
++ = *(p
+3+ns
) ; ns
++ ; }
48 strncpy(wrf_error_fatal_str
, p
+3+ns
,15+1) ; change_to_lower(wrf_error_fatal_str
,15+1 ) ; /* 15, but add one to check for '3' */
49 strncpy(surface_driver_str
, p
+3+ns
,14) ; change_to_lower(surface_driver_str
,14) ;
50 strncpy(radiation_driver_str
, p
+3+ns
,16) ; change_to_lower(radiation_driver_str
,16) ;
51 strncpy(cumulus_driver_str
, p
+3+ns
,14) ; change_to_lower(cumulus_driver_str
,14) ;
52 strncpy(pbl_driver_str
, p
+3+ns
,10) ; change_to_lower(pbl_driver_str
,10) ;
54 if ( !strncmp( wrf_error_fatal_str
, "wrf_error_fatal", 15 ) && wrf_error_fatal_str
[15] != '3' )
56 ns2
= 1 ; while ( *(p
+3+ns
+14+ns2
) && *(p
+3+ns
+14+ns2
) != '\n' &&
57 (*(p
+3+ns
+14+ns2
) == ' ' ) ) ns2
++ ;
58 if ( *(p
+3+ns
+14+ns2
) == '(' ) {
61 printf("wrf_error_fatal3(__FILE__,__LINE__,&\n") ;
62 ns2
= 1 ; while ( *(p
+3+ns
+14+ns2
) && *(p
+3+ns
+14+ns2
) != '\n' &&
63 (*(p
+3+ns
+14+ns2
) == ' ' ||
64 *(p
+3+ns
+14+ns2
) == '(' ||
65 *(p
+3+ns
+14+ns2
) == '\t' ||
66 *(p
+3+ns
+14+ns2
) == '&' )) ns2
++ ;
67 if( *(p
+3+ns
+14+ns2
) != '\n') printf("%s",(p
+3+ns
+14+ns2
)) ;
73 } else if ( !strncmp ( surface_driver_str
, "surface_driver", 14 ) ||
74 !strncmp ( radiation_driver_str
, "radiation_driver", 16) ||
75 !strncmp ( cumulus_driver_str
, "cumulus_driver", 14) ||
76 !strncmp ( pbl_driver_str
, "pbl_driver", 10)
78 strcpy(lineo
,p
+3+ns
) ;
80 while ( fgets( linei
, 2048, fp
) != NULL
) {
81 for ( q
= linei
; *q
; q
++ ) {
82 if (*q
=='!') { *q
= '\n' ; *(q
+1) = '\0' ; break ; }
84 for ( q
= linei
; *q
; q
++ ) {
85 if ( *q
== '(' ) inparen
++ ;
86 else if ( *q
== ')' ) inparen
-- ;
93 for(q
=lineo
,r
=lineo
;*q
;q
++) {
94 if (*q
== '#' && *(q
-1) == '\n') { /* CPP def. copy as is*/
99 if ( *q
== '\n' ) break ;
102 if ( *q
== ' ' || *q
== '\n' || *q
== '&' ) continue ;
107 for(q
=lineo
,col
=130-5;*q
;q
++) {
109 if ( *q
== '\n' ) { if (*(q
+1) != '#') { putchar('&') ; } ; col
= 131 ; }
113 if (*q
!=')' || *(q
+1) ) { putchar('&') ; putchar('\n') ; putchar('&') ; }
136 drop_comment( char * linei
)
139 char inquote
= '\0' ;
141 for ( p
= linei
; *p
; p
++ )
143 if ( *p
== '\'' ) { if ( inquote
== *p
) { inquote
= '\0' ; } else { inquote
= *p
; } }
144 if ( *p
== '"' ) { if ( inquote
== *p
) { inquote
= '\0' ; } else { inquote
= *p
; } }
145 if ( !inquote
&& *p
== '!' ) {
146 /* let us make sure this is not an OMP directive shall we? */
147 for ( q
= p
; *q
; q
++ ) {
149 (*(q
+1) == 'o' || *(q
+1) == 'O') &&
150 (*(q
+2) == 'm' || *(q
+2) == 'M') &&
151 (*(q
+3) == 'p' || *(q
+3) == 'P') ) return(0) ;
152 /* nor an intel compiler directive, what? */
153 if ((*(q
+3) == '$') &&
154 (*(q
) == 'd' || *(q
) == 'D') &&
155 (*(q
+1) == 'e' || *(q
+1) == 'E') &&
156 (*(q
+2) == 'c' || *(q
+2) == 'C') ) return(0) ;
158 *p
= '\n' ; *(p
+1) = '\0' ; return(0) ;
164 change_to_lower( char * s
, int n
)
167 for ( i
= 0 ; i
< n
; i
++ )
169 if ( s
[i
] >= 'A' && s
[i
] <= 'Z' ) s
[i
] = s
[i
] - 'A' + 'a' ;