home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / dev / misc / flexcat / c_c_v20.sd < prev    next >
Text File  |  1993-12-21  |  6KB  |  227 lines

  1. ##stringtype C
  2. ##shortstrings
  3. /****************************************************************
  4.    This file was created automatically by `FlexCat V1.0'
  5.    Do NOT edit by hand!
  6. ****************************************************************/
  7.  
  8. #ifndef %b_CAT_H
  9. #include "%b_CAT.h"
  10. #endif    /*  !%b_CAT_H         */
  11.  
  12. #include <string.h>
  13.  
  14. #ifndef EXEC_MEMORY_H
  15. #include <exec/memory.h>
  16. #endif    /*  !EXEC_MEMORY_H        */
  17. #ifndef LIBRARIES_IFFPARSE_H
  18. #include <libraries/iffparse.h>
  19. #endif    /*  !LIBRARIES_IFFPARSE_H   */
  20.  
  21. #ifndef CLIB_IFFPARSE_PROTOS_H
  22. #include <clib/iffparse_protos.h>
  23. #endif    /*  !CLIB_IFFPARSE_PROTOS_H */
  24. #ifndef CLIB_LOCALE_PROTOS_H
  25. #include <clib/locale_protos.h>
  26. #endif    /*  !CLIB_LOCALE_PROTOS_H   */
  27. #ifndef CLIB_DOS_PROTOS_H
  28. #include <clib/dos_protos.h>
  29. #endif    /*  !DOS_PROTOS_H        */
  30. #ifndef CLIB_EXEC_PROTOS_H
  31. #include <clib/exec_protos.h>
  32. #endif    /*  !EXEC_PROTOS_H        */
  33. #ifndef CLIB_UTILITY_PROTOS_H
  34. #include <clib/utility_protos.h>
  35. #endif    /*  !CLIB_UTILITY_PROTOS_H  */
  36.  
  37. #ifdef AZTEC_C
  38. #ifndef __PRAGMAS_LOCALE_LIB_H
  39. #include <pragmas/locale_lib.h>
  40. #endif    /*  !PRAGMAS_LOCALE_LIB_H   */
  41. #ifndef __PRAGMAS_IFFPARSE_LIB_H
  42. #include <pragmas/iffparse_lib.h>
  43. #endif    /*  !PRAGMAS_IFFPARSE_LIB_H */
  44. #ifndef __PRAGMAS_DOS_LIB_H
  45. #include <pragmas/dos_lib.h>
  46. #endif    /*  !PRAGMAS_DOS_LIB_H        */
  47. #ifndef __PRAGMAS_EXEC_LIB_H
  48. #include <pragmas/exec_lib.h>
  49. #endif    /*  !PRAGMAS_EXEC_LIB_H     */
  50. #ifndef __PRAGMAS_UTILITY_LIB_H
  51. #include <pragmas/utility_lib.h>
  52. #endif    /*  !PRAGMAS_UTILITY_LIB_H  */
  53. #endif    /*  AZTEC_C            */
  54.  
  55. static LONG %b_Version = %v;
  56. static const STRPTR %b_BuiltInLanguage = (STRPTR) %l;
  57.  
  58. struct FC_Type
  59. {   LONG    ID;
  60.     STRPTR  Str;
  61. };
  62.  
  63. static const struct FC_Type %b_Array [] =
  64. {
  65.     %i, (STRPTR) %s%,
  66. };
  67.  
  68. static struct Catalog *%b_Catalog = NULL;
  69. static struct FC_Type *%b_OwnCatalog = NULL;
  70. static LONG %b_OwnStrings;
  71. static LONG %b_OwnBytes;
  72.  
  73. void Open%bCatalog(struct Locale *loc, STRPTR language)
  74. { LONG tag, tagarg;
  75.   extern struct Library *LocaleBase;
  76.   extern struct Library *IFFParseBase;
  77.  
  78.   Close%bCatalog();  /*  Not needed if the programmer pairs Open-()
  79.              and CloseCatalog() right, but does no harm. */
  80.   if (language == NULL)
  81.   { tag = TAG_IGNORE;
  82.   }
  83.   else
  84.   { tag = OC_Language;
  85.     tagarg = (LONG) language;
  86.   }
  87.   if (LocaleBase != NULL  &&  %b_Catalog == NULL)
  88.   { %b_Catalog = OpenCatalog(loc, (STRPTR) "%b.catalog",
  89.                  OC_BuiltInLanguage, %b_BuiltInLanguage,
  90.                  tag, tagarg,
  91.                  OC_Version, %b_Version,
  92.                  TAG_DONE);
  93.   }
  94.   if (LocaleBase == NULL  &&  IFFParseBase != NULL  &&  language != NULL  &&
  95.       Stricmp(language, %b_BuiltInLanguage) != 0)
  96.   { struct IFFHandle *iffhandle;
  97.     char path[128]; /*    Enough to hold 4 path items (dos.library 3.0)  */
  98.  
  99.     if ((iffhandle = AllocIFF())  !=  NULL)
  100.     { /*  Trying to open the catalog  */
  101.       strcpy(path, "Catalogs");
  102.       AddPart((STRPTR) path, language, sizeof(path));
  103.       AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
  104.       if ((iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))
  105.                  ==  NULL)
  106.       { strcpy(path, "Locale:Catalogs");
  107.     AddPart((STRPTR) path, language, sizeof(path));
  108.     AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
  109.     iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE);
  110.       }
  111.  
  112.       if (iffhandle->iff_Stream)
  113.       { InitIFFasDOS(iffhandle);
  114.     if (!OpenIFF(iffhandle, IFFF_READ))
  115.     { if (!PropChunk(iffhandle, MAKE_ID('C','T','L','G'),
  116.              MAKE_ID('S','T','R','S')))
  117.       { struct StoredProperty *sp;
  118.         int error;
  119.  
  120.         for (;;)
  121.         { if ((error = ParseIFF(iffhandle, IFFPARSE_STEP))
  122.              ==  IFFERR_EOC)
  123.           { continue;
  124.           }
  125.           if (error != 0)
  126.           { break;
  127.           }
  128.  
  129.           if (sp = FindProp(iffhandle, MAKE_ID('C','T','L','G'),
  130.                 MAKE_ID('S','T','R','S')))
  131.           { LONG *ptr;
  132.         LONG BytesToScan, StrLength;
  133.  
  134.         /*  First scan: Check the number of strings        */
  135.         /*  Note that this assumes that the strings are padded    */
  136.         /*  to a longword boundary!                */
  137.         %b_OwnBytes = 0;
  138.         %b_OwnStrings = 0;
  139.         BytesToScan = sp->sp_Size;
  140.         ptr = sp->sp_Data;
  141.         while (BytesToScan > 0)
  142.         { ++%b_OwnStrings;
  143.           ++ptr;              /*  Skip ID        */
  144.           StrLength = *ptr+1;          /*  NUL-Byte!        */
  145.           %b_OwnBytes += StrLength;
  146.           ptr += 1+(StrLength+3)/4;   /*  Skip Length and String*/
  147.           BytesToScan -= 8+((StrLength+3)/4)*4;
  148.         }
  149.  
  150.         /*  Marginal check: BytesToScan has to be 0!        */
  151.         if (BytesToScan == 0)
  152.         { char *cptr;
  153.           LONG i;
  154.  
  155.           if (%b_OwnCatalog = (struct FC_Type *)
  156.               AllocMem(%b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes,
  157.                    MEMF_ANY))
  158.           { /*    Second scan: Copy the strings and their ID's    */
  159.             cptr = (char *) &%b_OwnCatalog[%b_OwnStrings];
  160.             BytesToScan = sp->sp_Size;
  161.             ptr = sp->sp_Data;
  162.             i = 0;
  163.             while (BytesToScan > 0)
  164.             { %b_OwnCatalog[i].ID = *(ptr++);
  165.               %b_OwnCatalog[i].Str = (STRPTR) cptr;
  166.               StrLength = *ptr+1;     /*  NUL-Byte!        */
  167.               ptr++;
  168.               strncpy(cptr, (char *) ptr, StrLength);
  169.                     /*  Not more, not less bytes!    */
  170.               cptr+=StrLength;
  171.               ptr += (StrLength+3)/4;
  172.               BytesToScan -= 8+((StrLength+3)/4)*4;
  173.               ++i;
  174.             }
  175.             break;
  176.           }
  177.         }
  178.           }
  179.         }
  180.       }
  181.       CloseIFF(iffhandle);
  182.     }
  183.     Close(iffhandle->iff_Stream);
  184.       }
  185.  
  186.       FreeIFF(iffhandle);
  187.     }
  188.   }
  189. }
  190.  
  191.  
  192. void Close%bCatalog(void)
  193. { if (LocaleBase != NULL)
  194.   { CloseCatalog(%b_Catalog);
  195.   }
  196.   %b_Catalog = NULL;
  197.   if (%b_OwnCatalog != NULL)
  198.   { FreeMem(%b_OwnCatalog,
  199.         %b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes);
  200.     %b_OwnCatalog = NULL;
  201.   }
  202. }
  203.  
  204.  
  205. STRPTR Get%bString(LONG strnum)
  206. { STRPTR defaultstr = NULL;
  207.   LONG i;
  208.  
  209.   for (i = 0;  i < sizeof(%b_Array)/sizeof(struct FC_Type);  i++)
  210.     { if (%b_Array[i].ID == strnum)
  211.       { defaultstr = %b_Array[i].Str;
  212.     break;
  213.       }
  214.     }
  215.   if (%b_Catalog == NULL)
  216.   { if (%b_OwnCatalog != NULL)
  217.     { for (i = 0;  i < %b_OwnStrings;  i++)
  218.        { if (%b_OwnCatalog[i].ID == strnum)
  219.      { return(%b_OwnCatalog[i].Str);
  220.      }
  221.        }
  222.     }
  223.     return(defaultstr);
  224.   }
  225.   return(GetCatalogStr(%b_Catalog, strnum, defaultstr));
  226. }
  227.