--- canon.i950.c 2007-07-30 14:28:44.000000000 -0700 +++ canon.no_hardcoded_num_models.c 2007-07-30 14:53:31.000000000 -0700 @@ -59,8 +59,6 @@ static void decodeCIR(char *s, levelTab lt); /* IMPORTANT NOTE: the number of cartridges is to be confirmed for each type */ -/* Must modify MAX_NUMBER_OF_MODELS each time you touch to existingPrinters */ -#define MAX_NUMBER_OF_MODELS 22 struct { char *model; /* The model identifier */ @@ -69,7 +67,7 @@ unsigned char numberOfColors; char cartridgeTypes[10]; } chdTypes[4]; -} existingPrinters [MAX_NUMBER_OF_MODELS] = +} existingPrinters [] = { {"iP1000", {{"BK",1,{CARTRIDGE_BLACK}}, @@ -192,6 +190,8 @@ {NULL,RESPONSE_INVALID,{}}}} }; +const int MAX_NUMBER_OF_MODELS = sizeof(existingPrinters) / sizeof(existingPrinters[0]); + /* Some Canon printers give a binary ink level indicator : LOW (attributed to 20% remaining) or not LOW, 100% remaining. Some other printers give more precise indicator, 40 or 70% remaining. */