CatComp array

3 posts / 0 new
Last post
mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
CatComp array

I never liked CatComp's source output files. On OS4 I am trying to use it "as is". But I can't get it to compile quite right.

In my protos_globals.h file:

  1. extern struct CatCompArrayType
  2. {
  3. LONG cca_ID;
  4. CONST_STRPTR cca_Str;
  5. } CatCompArray[];

so my Locale code can "see" the array for string look up.

GCC gives me a redefinition error of 'struct CatCompArrayType' because CatComp puts this in the created CFILE:

  1. struct CatCompArrayType
  2. {
  3. LONG cca_ID;
  4. CONST_STRPTR cca_Str;
  5. };
  6.  
  7. STATIC CONST struct CatCompArrayType CatCompArray[] =
  8. ......

I have tried every combination I can think of to get this to work. What am I doing wrong?

salass00
salass00's picture
Offline
Last seen: 1 year 2 months ago
Joined: 2011-02-03 11:27
@mritter0 You shouldn't need

@mritter0

You shouldn't need the CatCompArray to be externally visible. Just make sure that it is included in the file where you implement your GetBuiltInString() function:

  1. CONST_STRPTR GetBuiltInString(int32 str_id) {
  2. const int32 num_str = sizeof(CatCompArray) / sizeof(CatCompArray[0]);
  3. int32 i;
  4.  
  5. for (i = 0; i < num_str; i++) {
  6. if (CatCompArray[i].cca_ID == str_id)
  7. return CatCompArray[i].cca_Str;
  8. }
  9.  
  10. return NULL;
  11. }

This can then be used in your GetString() function like so:

  1. CONST_STRPTR GetString(struct Catalog *catalog, int32 str_id) {
  2. CONST_STRPTR built_in;
  3.  
  4. built_in = GetBuiltInString(str_id);
  5.  
  6. if (catalog != NULL)
  7. return ILocale->GetCatalogStr(catalog, str_id, built_in);
  8.  
  9. return built_in;
  10. }
mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
Oh duh me! Moving the one

Oh duh me! Moving the one function fixed it. Arg! So simple.

Thanks.

Log in or register to post comments