/*----------------------------------------------------------
*
*     b_source.c
*
*     Prints source code from DisplayMenu in AmigaBasic
*     (Not terribly useful, but the code isn't too long...
*
*     For Lattice/SAS Version 5.10a:
*
*     Compile:    lc -cfist -v -y -b1 b_source.c
*
*     Link:       blink FROM
*                 c.o
*                 main.o
*                 a_source.o
*                 b_source.o
*                 c_source.o
*                 TO ms
*                 LIB lc.lib
*
*
*  MenuScript b_source.c
*  Copyright (c) 1991 David T. Ossorio.
*  All Rights reserved.
*
*------------------------------------------------------------*/
#include <stdio.h>
#include <exec/types.h>
#include <intuition/intuition.h>

#ifdef LATTICE
#include <proto/all.h>
#endif

extern ULONG version,revision;


/*-----------------------------------------------------------------
*
*     pcl() [print comment line] 
*
*     prints a comment line:
*
*     '*--------------------------------------------------------*
*
* or: /*--------------------------------------------------------
*
* or: ;*--------------------------------------------------------*
*
* depending on the type of source
*
*
*-------------------------------------------------------------------*/

UBYTE *Dash = "------------------------------------------------------------";

VOID pcl(char type)
{
   switch (type) {
      
      case 'c' :
      printf("/*%s*/\n",Dash);
      break;
      
      case 'a' :
      printf(";*%s*\n",Dash);
      break;
      
      case 'b' :
      printf("'*%s*\n",Dash);
      break;
   }
   return;
}

/*--------------------------------------------------------------------
*
*     print_header()
*
*     This header goes on all source code.
*
*----------------------------------------------------------------------*/

VOID print_header(char type)
{
   REGISTER UBYTE *start_comment = "/*";
   REGISTER UBYTE *end_comment = "*/";
   
   switch (type) {
      case 'c' : start_comment = (UBYTE *)"/*"; 
                 end_comment = (UBYTE *)"*/";
                 break;
      case 'a' : start_comment = (UBYTE *)";";
                 end_comment = (UBYTE *)"";
                 break;
      case 'b' : start_comment = (UBYTE *)"'";
                 end_comment = (UBYTE *)"";
                 break;
                                         
   }
        
   pcl(type);
   pcl(type);
   
   printf("%s                                                     %s\n",
   start_comment,end_comment);
   printf("%s                                                     %s\n",
   start_comment,end_comment);
   printf("%s  This source code was created with MenuScript       %s\n",
   start_comment,end_comment);
   printf("%s  Version %d.%d and may be used without restriction. %s\n",
   start_comment,version,revision,end_comment);
   printf("%s                                                     %s\n",
   start_comment,end_comment);
   printf("%s                                                     %s\n",
   start_comment,end_comment);
   
   pcl(type);
   pcl(type);
   return;
}
   
/*---------------------------------------------------------------------*
*
*     print_b_source()
*
*     prints basic source code from DisplayMenu()
*
*-----------------------------------------------------------------------*/

VOID print_b_source(struct Menu *fm)
{
   REGISTER struct Menu *menu = fm;
   REGISTER struct MenuItem *item;
   ULONG menu_id = 0,item_id,state;
   
   fprintf(stderr,"\nWriting AmigaBasic Source Code...\n");
   
   print_header('b');
    
      
   while (menu) {
      
      ++menu_id;
      printf("\n\n\tMENU %d,0,%d,\"%s\"\n\n",
            menu_id,menu->Flags & MENUENABLED == MENUENABLED ? 1 : 0,menu->MenuName);
            item = menu->FirstItem;
            item_id = 0;
            
      while (item) {
         if( (item->Flags & CHECKED == CHECKED) && (item->Flags & ITEMENABLED == ITEMENABLED) ) state = 2;
         else if (item->Flags & ITEMENABLED == ITEMENABLED) state = 1;
         else state = 0;
         
         printf("\t\tMENU %d,%d,%d,\"%s\"\n",
                  menu_id,item_id++,state,
                  ((struct IntuiText *)item->ItemFill)->IText);          
         item = item->NextItem;
      
      }     /* end while */   
            
      menu = menu->NextMenu;
  
   }      /* end while */
         
     
   return;
}


   
