eancheck_1.0.orig/0000755000175000017500000000000010550300452013502 5ustar joejoe00000000000000eancheck_1.0.orig/README0000644000175000017500000000303510550223355014371 0ustar joejoe00000000000000RUBRIC ------ This is just a little program I hacked up in a few minutes. It takes in an EAN code as a command line argument and prints to STDOUT whether it is valid or not. It does this by performing a checksum on the supplied EAN. It can also check: - UPC codes (12 digits), just preface them with a zero - Four digit codes (PLUs) which some supermarkets with older tills use on their till systems to ring up products like bread, fruit, veg... basically any loose product. Eancheck can validate them, no prefixing needed. If you want to use the eancheck functions in a program, I invite you to use eancheck.h in your programs. It provides two functions, one to check check digits and another to generate them for a given EAN. COMPATIBILITY ------------- So far I have tested the main program on Windows and Linux, both times with the G++ compiler. I have only tested the header file on Linux, but I assume it works on Windows too. USING EANCHECK.H ---------------- eancheck.h provides two functions you can use. * int ec_checkean(char inputean[]) This function takes an input EAN as a character array (string) and returns 0 if the check digit is correct, 1 if it is incorrect and 3 if invalid characters were found in the string. * int ec_gencd(char inputean[]) This function takes an EAN without the check digit and returns either the check digit (from 0-9) or 10 if an invalid character was found. LICENSING INFORMATION --------------------- I don't care what you do with this code, it's a pissy little program. Do what thou wilt.eancheck_1.0.orig/eancheck.cpp0000644000175000017500000000567210550300613015760 0ustar joejoe00000000000000/* LICENSE INFORMATION: I don't give a flying f*ck what you do with this program or its code. Really. I don't care. Not one bit. Use it in a program, change the code, redistribute the code (changed or not changed...whatever). You're allowed to do anything and everything with it. Maybe Windows Vista will include a "Check EAN check digit" function, based on this. I very much doubt it. This is just a little program I hacked up in a few minutes. It takes in an EAN code as a command line argument and prints to STDOUT whether it is valid or not. It does this by performing a checksum on the supplied EAN. It can also check: - UPC codes (12 digits), just preface them with a zero - Four digit codes (PLUs) which some supermarkets with older tills use on their till systems to ring up products like bread, fruit, veg... basically any loose product. Eancheck can validate them, no prefixing needed. If you want to use the eancheck functions in a program, I invite you to use eancheck.h in your programs. It provides two functions, one to check check digits and another to generate them for a given EAN. */ #include #include #include int main(int argc, char *argv[]) { if (argc == 1) { cout << "Eancheck by Joe Baldwin" << endl; cout << "A simple program to check whether an EAN code (barcode number)" << " is acceptable by validating its check digit." << endl; cout << "Usage: eancheck 0123456789012" << endl; cout << "To check a UPC (12 digit) code, prefix it with a zero" << endl; cout << "4 digit till codes work without prefixing." << endl << endl; } else { int trip = 0; for (int c = 0; c < strlen(argv[1]); c++) { if ((argv[1][c] < 48) || (argv[1][c] > 57)) trip++; } if (trip == 0) { // the variable for the numbers input via the command line. int digits[strlen(argv[1])]; for (int i=0; i < strlen(argv[1]); i++) { // this makes each digit of the EAN a string (with terminating // character) so that atoi can work its magic on it. char convert[2]; convert[0] = argv[1][i]; convert[1] = '\0'; // converts the char (as input on the command line) into a number. digits[i] = atoi(convert); } // the total of all the "odd" numbers. int oaccumulator = 0; // the total of all the "even" numbers. int eaccumulator = 0; for (int o=0; o eancheck.1.gz install: eancheck eancheck.1.gz install -c -D -o root -g root -m 755 eancheck $(PREFIX)/bin/eancheck install -c -D -o root -g root -m 644 eancheck.h $(PREFIX)/include/eancheck.h install -c -D -o root -g root -m 644 README $(PREFIX)/share/doc/eancheck/README install -c -D -o root -g root -m 644 eancheck.1.gz $(PREFIX)/share/man/man1/eancheck.1.gz uninstall: rm $(PREFIX)/bin/eancheck rm $(PREFIX)/include/eancheck.h rm -rf $(PREFIX)/share/doc/eancheck rm $(PREFIX)/share/man/man1/eancheck.1.gz clean: -rm eancheck -rm eancheck.o -rm eancheck.1.gz eancheck_1.0.orig/eancheck.h0000644000175000017500000000466310550223240015424 0ustar joejoe00000000000000#include #include #include int ec_checkean(char inputean[]) { int trip = 0; for (int c = 0; c < strlen(inputean); c++) { if ((inputean[c] < 48) || (inputean[c] > 57)) trip++; } if (trip == 0) { // the variable for the numbers passed to the function int digits[strlen(inputean)]; for (int i=0; i < strlen(inputean); i++) { // this makes each digit of the EAN a string (with terminating // character) so that atoi can work its magic on it. char convert[2]; convert[0] = inputean[i]; convert[1] = '\0'; // converts the char (as sent as argument) into a number. digits[i] = atoi(convert); } // the total of all the "odd" numbers. int oaccumulator = 0; // the total of all the "even" numbers. int eaccumulator = 0; for (int o=0; o 57)) trip++; } if (trip == 0) { // the variable for the numbers passed to the function int digits[strlen(inputean)]; for (int i=0; i < strlen(inputean); i++) { // this makes each digit of the EAN a string (with terminating // character) so that atoi can work its magic on it. char convert[2]; convert[0] = inputean[i]; convert[1] = '\0'; // converts the char (as sent as argument) into a number. digits[i] = atoi(convert); } // the total of all the "odd" numbers. int oaccumulator = 0; // the total of all the "even" numbers. int eaccumulator = 0; for (int o=0; o