/* *******************************************************************
 *                                                                   *
 * Copyright (c) L-DGO/MIT/JGOFS                                     *
 *                                                                   *
 *                                                                   *
 * File             : ch.c                                           *
 *                                                                   *
 * Purpose          :                                                *         
 *                                                                   *
 * Version Number   : 1.1a                                           *
 *                                                                   *
 * Revision History :                                                *
 *                                                                   *
 * Date                              Developer                       *
 * ----                              ---------                       *
 *                                                                   *
 * 27 Jul 05			    WJS				     *
 *	Explicitly exit with 0 under normal conditions		     *
 *	Type main to avoid diagnostic				     *
 *      include stdlib.h for exit defn				     *
 * 		[begin 1.1a]					     *
 * Sat Oct 17  1992 10.00           Glenn Flierl                     *
 *                                                                   *   
 *                                                                   *
 ******************************************************************* */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(argc,argv)
int argc;
char *argv[];
{
int i,j,j1,ok;
char lines[2025];
char *s,*t;
char nam[255];
FILE *fil;

if((fil=fopen(argv[1],"r+")) == NULL)exit(1);
s=lines;
while (fgets(s,81,fil) != NULL) s += strlen(s)+1;
t=lines;
fclose(fil);
fil=fopen(argv[1],"w");
/* rewind(fil); */
while(t != s)
  {ok=1;
   strcpy(nam,t);
   j=strcspn(nam,"=")+1;
   if ( j < (int)strlen(nam)){
   for(i=2;i<argc && ok;i++)
     {
     if(strncmp(argv[i],nam,j) == 0)
        {
	j=strcspn(nam,"#");
	j1=strlen(argv[i]);
	fputs(argv[i],fil);   
	if (j==strlen(nam))
	  fputc('\n',fil);
        else if (j1<=j) 
	   {
	   while(j1<j){fputc(' ',fil);j1++;};
	   fputs(nam+j,fil);
	   }
        else
           fputs(nam+j,fil);
	ok=0;};
     };
   };
   if(ok)fputs(t,fil);
   t +=strlen(t)+1;
   };
fclose(fil);
exit(0);
}

  
