/*ProfiPacket - packet radio terminal program
  Copyright (C) 1999  Alexander Feigl

  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 of the License, 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; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

  Author:

  Alexander Feigl
  Burachstraße 51

  D-88250 Weingarten

  Mail : Alexander.Feigl@gmx.de
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "GUIProtos.h"
#include "global.h"

#include <libraries/mui.h>

#include <exec/lists.h>
#include <exec/memory.h>

#include <dos/exall.h>
#include <dos/dos.h>

#include <graphics/text.h>
#include <graphics/scale.h>

#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/locale_protos.h>

#ifdef __GNUC__


extern void *SysBase;
extern void *LocaleBase;
extern struct Catalog *Catalog;

#include <inline/exec.h>
#include <inline/locale.h>
#endif

extern const char ProfiPacketCatalog[];

int GUI_InitStringSpeedup(void)
 {
  const unsigned char *catsource;
  char **sst;
  int strings=0,i;
  unsigned char **ssu;
  
   
  catsource=(const unsigned char *) ProfiPacketCatalog;
  while (1)
   {
    long int strn;
    strn=((*(catsource++))<<8);
    strn|=(*(catsource++));
    if (strn==0xffff) break;
    if (strn>strings) strings=strn;
    while (*(catsource++)!=0);
    if ( ((long int) catsource)&1) ++catsource;    
   }
  ++strings;
  StringSpeedupSize=strings;
  sst=AllocVec(StringSpeedupSize*sizeof(char *),1);
  if (sst==NULL)
   {
    return(-1); 
   }
  ssu=((unsigned char **)sst);  
  for (i=0;i<StringSpeedupSize;++i)
   {
    *(ssu++)=GUI_String(i); 
   }
  StringSpeedup=sst;   
  return(0);
 }
 
 
extern const unsigned char Ver2_Export[];
extern const unsigned char ProgramVersion[];
 
 
 
 unsigned char *GUI_String(signed long strnum)
  {
   if (strnum==-2)
    {
     return((unsigned char *) Ver2_Export);       
    }
   if (strnum==-1)
    {
     return(NULL);
    }
   if (strnum==0)
    {
     return((unsigned char *) ProgramVersion);
    }
   if (StringSpeedup!=NULL)
    {
     if (strnum>=StringSpeedupSize)
      {
       return("<<<<Stringnotdefined>>>>");  
      }
     return(StringSpeedup[strnum]);
     
    }
    else
    {
     const unsigned char *ppct;
     
     ppct=(const unsigned char *) ProfiPacketCatalog;
     while (1)
      {
       int stn;
       stn=(*(ppct++))<<8;
       stn|=*(ppct++);
       if (stn==strnum) break;
       if (stn==0xffff)
        {
         return("<<<<Stringnotdefined>>>>");
        }
       while (*(ppct++)!=0);
       if ( ((unsigned long) ppct) & 1) ++ppct;
      }
     if (Catalog!=NULL)
      {
       ppct=((const char *) GetCatalogStr(Catalog,strnum,(char *)ppct));
      } 
     return((unsigned char *)ppct);
    }
  }