/*
***************************************************************************
*
* Datei:
*    RSysHelp.c
*
* Inhalt:
*    void Help(void);
*
* Bemerkungen:
*    Prozeduren zur Verwaltung der Hilfefunktion von RSys.
*
* Erstellungsdatum:
*    07-Jul-93    Rolf Böhme
*
* Änderungen:
*    07-Jul-93    Rolf Böhme    Erstellung
*
***************************************************************************
*/

#include "RSysDebug.h"
#include "RSysFunc.h"

   /*
    * Help() liest eine Datei aus, deren Name in der ENV-Variablen
    * SYSHELP enthalten ist. Diese Datei wird dann im
    * Hauptfenster-Listview angezeigt
    */
void
Help(void)
{
   BPTR  helpfile;
   UBYTE line[HELPLINESIZE + 1];
   int   i = 0,
         len;
   UBYTE helpfilename[MAXFULLNAME+1],
        *buf;
   int   SaveID = LastID;

   DPOS;

   if (GetVar((UBYTE *) "RSYSHELP", helpfilename, MAXFULLNAME, GVF_GLOBAL_ONLY) > 0)
      if (helpfile = Open(helpfilename, MODE_OLDFILE))
      {
         PrintHeader(HELP, NULL);

         EmptyListView();

         LastID = SaveID;

         FGets(helpfile, line, HELPLINESIZE);
         countentries = atoi((char *)line);

         if (!NoEntries())
         {
            Entries = AllocScrollEntries(countentries);

            FGets(helpfile, line, HELPLINESIZE);

            do
            {
               len = strlen((char *)line) - 1;
               line[len] = STRINGEND;

               if (len > 0)
                  strncpy(Entries[i].se_Entry, (char *)line, len);
               else
                  strcpy(Entries[i].se_Entry, field[BLANK_FIELD]);

               i++;

               buf = FGets(helpfile, line, HELPLINESIZE);
            }
            while (buf && (i < countentries));

            CreateEntryList(NO_SORT);

            PrintStatistics();
         }

         Close(helpfile);
      }
      else
         ErrorHandle(FILE_ERR, FIND_FAIL, NO_KILL);
   else
      ErrorHandle(ENV_ERR, FIND_FAIL, NO_KILL);

   return;
}
