/*******************************************************************
* profile.c : reads profile and changes its commands into command  *
*	      line parameters					   *
*								   *
* created: 01-Mar-91 Mtwx					   *
*******************************************************************/

/* --------------------- source code revisions, tracked by RCS ---------- */

/* $Header: Hard0:C-Compiler/src/wfile/rcs/profile.c,v 1.0 91/08/12 20:25:32 Mtwx Exp $ */
/* $Log:	profile.c,v $
 * Revision 1.0  91/08/12  20:25:32  Mtwx
 * Initial revision
 *  */

/* ----------------------- Includes ----------------------------- */

#include <stdio.h>
#include <stdlib.h>

/* ----------------------- external references ------------------ */

extern char *templ_argv[];

/* -------------------------------------------------------------- */

int parse_profile(filename)
char *filename;
{
  int t_argc=0;
  char inputline[80];
  FILE *file;

/* check presence of file (filename) and open */

  if((file=fopen(filename,"r"))==NULL)
  {
    perror(filename);
    return 0;
  }
  while(fgets(inputline,79,file) != NULL)
  {
    if(inputline[0]!='#') /* only if line is not a comment */
    {
#ifdef AMIGA
      inputline[strlen(inputline)-1]='\0';  /* discard newline */
#endif
#ifdef UNIX
      inputline[strlen(inputline)-1]='\0';  /* discard newline */
#endif
#ifdef MSDOS
      inputline[strlen(inputline)-2]='\0';  /* discard newline */
#endif
      templ_argv[t_argc]=(char *)malloc(strlen(inputline)+1);
      if(templ_argv[t_argc]==NULL)
      {
	puts("Couldn't get memory for building template from profile");
	printf("\'%s\' will not be processed!\n",inputline);
      }
      else
      {
	puts(inputline);
	strcpy(templ_argv[t_argc],inputline);
      }
      t_argc++;
    }
  }
  fclose(file);
  return t_argc;
}
