/***********************************************************************
* 
*               *****   ***    ***
*                  *   *   *  *   *
*                 *     ***    ***
*                *     *   *  *   *
*               *****   ***    ***
*
* A FREE Finite Elements Analysis Program in ANSI C for the UNIX OS.
*
* Composed and edited and copyright by 
* Professor Dr.-Ing. Frank Rieg, University of Bayreuth, Germany
*
* eMail: 
* frank.rieg@uni-bayreuth.de
* dr.frank.rieg@t-online.de
* 
* V10.0  December 12, 2001
*
* Z88 should compile and run under any UNIX OS and Motif 2.0.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING.  If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
***********************************************************************/ 
/***********************************************************************
* RCOL88 fuer UNIX: Farben einlesen
* 23.3.2002 Rieg
***********************************************************************/

/***********************************************************************
* UNIX
***********************************************************************/
#ifdef FR_UNIX
#include <z88p.h>
#include <stdio.h>   /* fopen,fclose,fgets */
#include <string.h>  /* strstr */
#endif

/***********************************************************************
* Functions
***********************************************************************/
int wlog88p(FR_INT4,int);

/***********************************************************************
* Start rcol88
***********************************************************************/
int rcol88(void)
{

FILE *fcol;

extern int IBELL;
extern int IX_WINDOW,IY_WINDOW,IW_WINDOW,IH_WINDOW;

extern int IX_UPBROW,IY_UPBROW,IW_UPBROW,IH_UPBROW;
extern int IX_LPBROW,IY_LPBROW,IW_LPBROW,IH_LPBROW;

extern int IX_RBSTRUC,IY_RBSTRUC,IW_RBSTRUC,IH_RBSTRUC;
extern int IX_RBVIEW,IY_RBVIEW,IW_RBVIEW,IH_RBVIEW;
extern int IX_RBLABEL,IY_RBLABEL,IW_RBLABEL,IH_RBLABEL;

extern int IX_RCSPLOT,IY_RCSPLOT,IW_RCSPLOT,IH_RCSPLOT,NC_RCSPLOT;

extern int IX_RCFXYZ,IY_RCFXYZ,IW_RCFXYZ,IH_RCFXYZ,NC_RCFXYZ;

extern int IX_RCFXCOR,IY_RCFXCOR,IW_RCFXCOR,IH_RCFXCOR,NC_RCFXCOR;

extern int IX_DRAWAR,IY_DRAWAR,IW_DRAWAR,IH_DRAWAR;  

extern char CF_BUTTONS[],CF_ENTRIES[],CF_GRAFICS[];

extern char CO_FOREGR[],CO_BACKGR[],CO_ENTRIES[];

extern char CO_DRAWAR[];

extern char CO_NORMAL[],CO_DEFLECTED[],CO_ELEMENTS[],CO_NODES[];

extern char CO_STRESS0[],CO_STRESS1[],CO_STRESS2[],CO_STRESS3[];
extern char CO_STRESS4[],CO_STRESS5[],CO_STRESS6[],CO_STRESS7[];
extern char CO_STRESS8[],CO_STRESS9[];

char cline[256], cdummy[80];

/*----------------------------------------------------------------------
* Color- datei z88.fcd oeffnen
*---------------------------------------------------------------------*/
fcol= fopen("z88.fcd","rb"); /* fcd = fonts, colors, dimensions       */

if(fcol == NULL)
  {
  wlog88p(0,LOG_NOCOL);
  return(AL_NOCOL);
  }
rewind(fcol);

/*----------------------------------------------------------------------
* Color- datei z88p.col lesen
*---------------------------------------------------------------------*/
do
  if(fgets(cline,256,fcol)== NULL) break;
while( (strstr(cline,"Z88P START"))== NULL);

if( (strstr(cline,"Z88P START"))!= NULL)              /* File */
  {
  do
    {
    fgets(cline,80,fcol);

    if( (strstr(cline,"WINDOW START"))!= NULL) 
      {
      do
        {
        fgets(cline,80,fcol);

        if( (strstr(cline,"IBELL"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IBELL);

        if( (strstr(cline,"CF_BUTTONS"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CF_BUTTONS);
        if( (strstr(cline,"CF_ENTRIES"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CF_ENTRIES);

        if( (strstr(cline,"CO_FOREGR"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_FOREGR);
        if( (strstr(cline,"CO_BACKGR"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_BACKGR);
        if( (strstr(cline,"CO_ENTRIES"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_ENTRIES);

        if( (strstr(cline,"IX_WINDOW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IX_WINDOW);
        if( (strstr(cline,"IY_WINDOW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IY_WINDOW);
        if( (strstr(cline,"IW_WINDOW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IW_WINDOW);
        if( (strstr(cline,"IH_WINDOW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IH_WINDOW);

        if( (strstr(cline,"IX_UPBROW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IX_UPBROW);
        if( (strstr(cline,"IY_UPBROW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IY_UPBROW);
        if( (strstr(cline,"IW_UPBROW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IW_UPBROW);
        if( (strstr(cline,"IH_UPBROW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IH_UPBROW);

        if( (strstr(cline,"IX_LPBROW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IX_LPBROW);
        if( (strstr(cline,"IY_LPBROW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IY_LPBROW);
        if( (strstr(cline,"IW_LPBROW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IW_LPBROW);
        if( (strstr(cline,"IH_LPBROW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IH_LPBROW);

        if( (strstr(cline,"IX_RBSTRUC"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IX_RBSTRUC);
        if( (strstr(cline,"IY_RBSTRUC"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IY_RBSTRUC);
        if( (strstr(cline,"IW_RBSTRUC"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IW_RBSTRUC);
        if( (strstr(cline,"IH_RBSTRUC"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IH_RBSTRUC);

        if( (strstr(cline,"IX_RBVIEW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IX_RBVIEW);
        if( (strstr(cline,"IY_RBVIEW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IY_RBVIEW);
        if( (strstr(cline,"IW_RBVIEW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IW_RBVIEW);
        if( (strstr(cline,"IH_RBVIEW"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IH_RBVIEW);

        if( (strstr(cline,"IX_RBLABEL"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IX_RBLABEL);
        if( (strstr(cline,"IY_RBLABEL"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IY_RBLABEL);
        if( (strstr(cline,"IW_RBLABEL"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IW_RBLABEL);
        if( (strstr(cline,"IH_RBLABEL"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IH_RBLABEL);

        if( (strstr(cline,"IX_RCSPLOT"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IX_RCSPLOT);
        if( (strstr(cline,"IY_RCSPLOT"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IY_RCSPLOT);
        if( (strstr(cline,"IW_RCSPLOT"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IW_RCSPLOT);
        if( (strstr(cline,"IH_RCSPLOT"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IH_RCSPLOT);
        if( (strstr(cline,"NC_RCSPLOT"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&NC_RCSPLOT);

        if( (strstr(cline,"IX_RCFXYZ"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IX_RCFXYZ);
        if( (strstr(cline,"IY_RCFXYZ"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IY_RCFXYZ);
        if( (strstr(cline,"IW_RCFXYZ"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IW_RCFXYZ);
        if( (strstr(cline,"IH_RCFXYZ"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IH_RCFXYZ);
        if( (strstr(cline,"NC_RCFXYZ"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&NC_RCFXYZ);

        if( (strstr(cline,"IX_RCFXCOR"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IX_RCFXCOR);
        if( (strstr(cline,"IY_RCFXCOR"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IY_RCFXCOR);
        if( (strstr(cline,"IW_RCFXCOR"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IW_RCFXCOR);
        if( (strstr(cline,"IH_RCFXCOR"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IH_RCFXCOR);
        if( (strstr(cline,"NC_RCFXCOR"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&NC_RCFXCOR);

        if( (strstr(cline,"IX_DRAWAR"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IX_DRAWAR);
        if( (strstr(cline,"IY_DRAWAR"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IY_DRAWAR);
        if( (strstr(cline,"IW_DRAWAR"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IW_DRAWAR);
        if( (strstr(cline,"IH_DRAWAR"))!= NULL) 
          sscanf(cline,"%s %d",cdummy,&IH_DRAWAR);
        }
      while( (strstr(cline,"WINDOW END"))== NULL);
      }         

    if( (strstr(cline,"GRAFIC START"))!= NULL) 
      {
      do
        {
        fgets(cline,80,fcol);

        if( (strstr(cline,"CF_GRAFICS"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CF_GRAFICS);

        if( (strstr(cline,"CO_DRAWAR"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_DRAWAR);

        if( (strstr(cline,"CO_NORMAL"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_NORMAL);
        if( (strstr(cline,"CO_DEFLECTED"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_DEFLECTED);
        if( (strstr(cline,"CO_ELEMENTS"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_ELEMENTS);
        if( (strstr(cline,"CO_NODES"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_NODES);

        if( (strstr(cline,"CO_STRESS0"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_STRESS0);
        if( (strstr(cline,"CO_STRESS1"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_STRESS1);
        if( (strstr(cline,"CO_STRESS2"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_STRESS2);
        if( (strstr(cline,"CO_STRESS3"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_STRESS3);
        if( (strstr(cline,"CO_STRESS4"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_STRESS4);
        if( (strstr(cline,"CO_STRESS5"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_STRESS5);
        if( (strstr(cline,"CO_STRESS6"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_STRESS6);
        if( (strstr(cline,"CO_STRESS7"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_STRESS7);
        if( (strstr(cline,"CO_STRESS8"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_STRESS8);
        if( (strstr(cline,"CO_STRESS9"))!= NULL) 
          sscanf(cline,"%s %s",cdummy,CO_STRESS9);

        }
      while( (strstr(cline,"GRAFIC END"))== NULL);
      }         

    }
  while( (strstr(cline,"Z88P END"))== NULL);     
    
  }             
  else
  {
  wlog88p(0,LOG_WRONGCOL);
  return(AL_WRONGCOL);
  }  

/*----------------------------------------------------------------------
* korrekt gelesen, file fcol schliessen
*---------------------------------------------------------------------*/
fclose(fcol);
return (0);
}
