diff --git a/code/inventory/upc.h b/code/inventory/upc.h new file mode 100644 index 0000000..c215276 --- /dev/null +++ b/code/inventory/upc.h @@ -0,0 +1,24 @@ +/* + * upc.h - UPC-A barcode validation. + * + * Pure C, no SIBO/PLIB dependencies, so it can be unit-tested on any host + * compiler as well as built for the Workabout. + */ +#ifndef UPC_H +#define UPC_H + +#define UPC_A_LEN 12 + +/* + * Returns 1 if s is a valid 12-digit UPC-A (all digits and a correct + * check digit), 0 otherwise. s must be NUL-terminated. + */ +int upcIsValid(const char *s); + +/* + * Returns the UPC-A check digit (0-9) computed from the first 11 digits + * of s, or -1 if those 11 characters are not all digits. + */ +int upcCheckDigit(const char *s); + +#endif /* UPC_H */