There is a hpmud C API (hpmud_get_model()) that takes a device-id string as input, parses out the MODEL: field, then generalizes the returned model string (see hpmud.h).
Then with the generalized model string you can use a simple strcasecmp() on PPD file name (or *NickName with the above fix) for auto-discovery.
If you want to extract the code into your own utility that is not hplip or hpmud specific here is the code from hpmud.c.
int generalize_serial(const char *sz, char *buf, int bufSize)
{
const char *pMd=sz;
int i, j;
for (i=0; pMd[i] == ' ' && i < bufSize; i++); /* eat leading white space */
for (j=0; (pMd[i] != 0) && (i < bufSize); i++)
{
buf[j++] = pMd[i];
}
for (i--; buf[i] == '_' && i > 0; i--); /* eat trailing white space */
buf[++i] = 0;
return i; /* length does not include zero termination */
}
/* Parse the model from the IEEE 1284 device id string and generalize the model name */
int hpmud_get_model(const char *id, char *buf, int buf_size)
{
char *pMd;
buf[0] = 0;
if ((pMd = strstr(id, "MDL:")) != NULL)
pMd+=4;
else if ((pMd = strstr(id, "MODEL:")) != NULL)
pMd+=6;
else
return 0;
There is a hpmud C API (hpmud_get_model()) that takes a device-id string as input, parses out the MODEL: field, then generalizes the returned model string (see hpmud.h).
Then with the generalized model string you can use a simple strcasecmp() on PPD file name (or *NickName with the above fix) for auto-discovery.
If you want to extract the code into your own utility that is not hplip or hpmud specific here is the code from hpmud.c.
int generalize_ serial( const char *sz, char *buf, int bufSize)
{
const char *pMd=sz;
int i, j;
for (i=0; pMd[i] == ' ' && i < bufSize; i++); /* eat leading white space */
for (j=0; (pMd[i] != 0) && (i < bufSize); i++)
{
buf[j++] = pMd[i];
}
for (i--; buf[i] == '_' && i > 0; i--); /* eat trailing white space */
buf[++i] = 0;
return i; /* length does not include zero termination */
}
/* Parse the model from the IEEE 1284 device id string and generalize the model name */ model(const char *id, char *buf, int buf_size)
int hpmud_get_
{
char *pMd;
buf[0] = 0;
if ((pMd = strstr(id, "MDL:")) != NULL)
pMd+=4;
else if ((pMd = strstr(id, "MODEL:")) != NULL)
pMd+=6;
else
return 0;
return generalize_ model(pMd, buf, buf_size);
}
-dave