. validator/install 100666 241 0 3445 11523215343 11747 0 ustar 00IUSR0001 Validator Service Program Installation
This service program sources come as IFS files (not database file sources) and
with that has all the pros and cons of it.
The installation of this service program is really easy as it is accomplished
with the tool "make". The make tool is very much used in the Unix/Linux world.
To use it just type make in a QShell session.
Requirements: You need a folder in the IFS for your global copy books.
You need the copy books from http://www.rpgnextgen.com/downloads/includes-1.0.0.tar.
Put those copy books in your global copy book folder, f. e. /usr/local/include.
You need to install the message service program (see http://www.rpgnextgen.com).
1. Download sources
2. FTP to IBM i server
3. It is a good idea to create a common source folder for IFS sources (mkdir src)
4. Extract sources (tar -xf validator.tar)
5. Check the CCSID of the Makefile script with ls -S message
(it should have 437, 819, 850 or something like that. 37 won't work.
You can convert the file with the conversion script,
see http://www.rpgnextgen.com/index.php?content=resources)
6. edit the Makefile to match your environment (mostly the BIN_LIB and INCLUDE variable),
use edtf or RDP or RPG Next Gen Editor
7. make
8. make install
9. make clean (removes the rpg module and the binder source file)
FINISHED!
Now you got your VALIDATOR service program installed.
Note: Depending on your system configuration you may have to manually set the
CCSID of the copied copy book at the INCLUDE folder. Set it to the CCSID
of the original file (in your message folder).
F. e.: setccsid 37 /usr/local/include/rng/validator/checkdigit_h.rpgle
If you got any questions just drop me a mail ( mihael at rpgnextgen.com ).
Mihael
validator/example 42777 241 0 0 11523215353 11632 5 ustar 00IUSR0001 validator/example/valid01.rpgle 100666 241 0 3533 11523215403 14277 0 ustar 00IUSR0001 /**
* \brief Validator Example : Check Digit
*
* This program takes a code as parameter (alphanumeric) and checks if the
* check digit is ok (modulus 10). If it ain't a valid code then the
* check digit will be calculated.
*
*
*
* Example: CALL VALID01 PARM('1234565')
*
* \author Mihael Schmidt
* \date 05.02.2011
*/
H dftactgrp(*no) actgrp(*caller)
*-------------------------------------------------------------------------
* PEP
*-------------------------------------------------------------------------
D VALID01 PR extpgm('VALID01')
D ean 13A
D VALID01 PI
D ean 13A
D
*-------------------------------------------------------------------------
* Prototypes
*-------------------------------------------------------------------------
D main PR
D ean 13A
*
/include 'rng/validator/checkdigit_h.rpgle'
/free
if (%parms() = 1);
main(ean);
else;
dsply %trimr('Syntax: CALL VALID01 PARM(''my_ean'')');
endif;
*inlr = *on;
/end-free
P main B
D PI
D ean 13A
*
D dsp S 50A
/free
if (rng_validator_modulus_isValid(ean));
dsply 'Check digit is ok.';
else;
dsply 'Code is invalid. Wrong check digit.';
dsp = 'The check digit should be ' +
%char(rng_validator_modulus_calculate(
%subst(%trim(ean) : 1 : %len(%trim(ean)) -1)));
dsply dsp;
endif;
/end-free
P E
validator/validator.bnd 100666 241 0 254 11523215344 13004 0 ustar 00IUSR0001 STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('Validator 1.0.0')
EXPORT SYMBOL('rng_validator_modulus_isValid')
EXPORT SYMBOL('rng_validator_modulus_calculate')
ENDPGMEXP
validator/Makefile 100666 241 0 2551 11523217434 12016 0 ustar 00IUSR0001 #
# Build script for Validator service program
#
# BIN_LIB is the destination library for the service program.
# the rpg modules and the binder source file are also created in BIN_LIB.
# binder source file and rpg module can be remove with the clean step (make clean)
BIN_LIB=QGPL
# to this library the prototype source file (copy book) is copied in the install step
INCLUDE=/usr/local/include
CFLAGS=DBGVIEW(*LIST) INCDIR('$(INCLUDE)')
LFLAGS=BNDDIR(QC2LE) BNDSRVPGM(MESSAGE)
OBJECTS = checkdigit
.SUFFIXES: .rpgle .c .cpp
# suffix rules
.rpgle:
system "CRTRPGMOD $(BIN_LIB)/$@ SRCSTMF('$<') $(CFLAGS)"
all: clean compile install
compile: $(OBJECTS)
checkdigit.rpgle:
validator.bnd: .PHONY
-system "CRTSRCPF $(BIN_LIB)/VALIDSRV RCDLEN(112)"
-system "CPYFRMIMPF FROMSTMF('$@') TOFILE($(BIN_LIB)/VALIDSRV VALIDATOR) RCDDLM(*ALL) STRDLM(*NONE) RPLNULLVAL(*FLDDFT)
install: compile validator.bnd
system "CRTSRVPGM $(BIN_LIB)/VALIDATOR MODULE(CHECKDIGIT) $(LFLAGS) EXPORT(*SRCFILE) SRCFILE($(BIN_LIB)/VALIDSRV) TEXT('Validator utilities')"
-mkdir $(INCLUDE)/rng
-mkdir $(INCLUDE)/rng/validator
cp checkdigit_h.rpgle $(INCLUDE)/rng/validator/
setccsid 37 $(INCLUDE)/rng/validator/checkdigit_h.rpgle
clean:
-system "DLTMOD $(BIN_LIB)/CHECKDIGIT"
-system "DLTF $(BIN_LIB)/VALIDSRV"
dist-clean: clean
-system "DLTSRVPGM $(BIN_LIB)/VALIDATOR"
.PHONY: validator/checkdigit.rpgle 100666 241 0 16043 11523215341 13523 0 ustar 00IUSR0001 /**
* \brief Check Digit Routines
*
* This service program will cover various check digit algorithms (f. e.
* EAN-8, EAN-13, etc.).
*
* \author Mihael Schmidt
* \date 01.01.2011
*
* \link http://commons.apache.org/validator/ Apache Commons Validator Framework
*/
*-------------------------------------------------------------------------
*
* (C) Copyleft 2011 Mihael Schmidt
*
* This file is part of the VALIDATOR service program.
*
* VALIDATOR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* VALIDATOR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VALIDATOR. If not, see .
*
*-------------------------------------------------------------------------
H nomain
*-------------------------------------------------------------------------
* Prototypes
*-------------------------------------------------------------------------
D calculateModulus...
D PR 10I 0
D code 128A const varying
D includesCheckDigit...
D N const
D modulus 10I 0 const
*
D weightedValue...
D PR 10I 0
D charValue 10I 0 const
D leftPos 10I 0 const
D rightPos 10I 0 const
/include 'message_h.rpgle'
/include 'checkdigit_h.rpgle'
/**
* \brief Validate code
*
* Validate a modulus check digit for a code.
*
* \param Code
* \param Modulus (default: 10)
*
* \return *on = code is valid
* *off = no code passed or code invalid
*/
P rng_validator_modulus_isValid...
P B export
D PI N
D code 128A const varying
D pModulus 10I 0 const options(*nopass)
*
D modulusResult S 10I 0
D modulus S 10I 0 inz(10)
/free
if (code = *blank);
return *off;
endif;
if (%parms() = 2);
modulus = pModulus;
endif;
monitor;
modulusResult = calculateModulus(code : *on : modulus);
return (modulusResult = 0);
on-error *all;
return *off;
endmon;
/end-free
P E
/**
* \param Calculate check digit
*
* Calculates the check digit for the passed code.
*
* \param Code (without check digit)
*
* \return calculated check digit
*
* \throws CPF9898 Invalid check digit
*/
P rng_validator_modulus_calculate...
P B export
D PI 1P 0
D code 128A const varying
D pModulus 10I 0 const options(*nopass)
*
D modulus S 10I 0 inz(10)
D modulusResult S 10I 0
D checkDigit S 10I 0
/free
if (%parms() = 2);
modulus = pModulus;
endif;
modulusResult = calculateModulus(code : *off : modulus);
checkDigit = modulus - modulusResult;
if (checkDigit = modulus);
checkDigit = 0;
endif;
if (checkDigit >= 0 and checkDigit <= 9);
return checkDigit;
else;
msg_sendEscapeMessage('Invalid check digit value '+ %char(checkDigit));
return 0;
endif;
/end-free
P E
/**
* \brief Calculate the modulus for a code.
*
* \param The code to calculate the modulus for.
* \param Whether the code includes the Check Digit or not.
*
* \return The modulus value
*
* \throws if an error occurs calculating the modulus for the specified code
*/
P calculateModulus...
P B
D PI 10I 0
D pCode 128A const varying
D includesCheckDigit...
D N const
D modulus 10I 0 const
*
D code S 128A varying
D codePtr S *
D total S 10I 0
D i S 10I 0
D length S 10I 0
D leftPos S 10I 0
D rightPos S 10I 0
D charValue S 10I 0
D char S 1A based(ptr)
D offset S 3I 0
/free
code = pCode;
codePtr = %addr(code : *DATA);
length = %len(%trim(code));
if (not includesCheckDigit);
offset = 1;
endif;
for i = 0 to length-1;
ptr = codePtr + i;
leftPos = i + 1;
rightPos = length - i + offset;
charValue = %int(char);
total += weightedValue(charValue : leftPos : rightPos);
endfor;
if (total = 0);
msg_sendEscapeMessage('Invalid code, sum is zero');
endif;
return %rem(total : modulus);
/end-free
P E
/**
* \brief Calculate weight of number
*
* Calculates the weighted value of a character in the
* code at a specified position.
*
* For EAN-13 (from right to left) odd digits are weighted
* with a factor of one and even digits with a factor
* of three.
*
* \param The numeric value of the character.
* \param The position of the character in the code, counting from left to right (1-based)
* \param The position of the character in the code, counting from right to left (1-based)
*
* \return The weighted value of the character.
*/
P weightedValue B
D PI 10I 0
D charValue 10I 0 const
D leftPos 10I 0 const
D rightPos 10I 0 const
*
D weight S 10I 0
D weights DS
D pos_weight_1 10I 0 inz(3)
D pos_weight_2 10I 0 inz(1)
D pos_weights 10I 0 dim(2) overlay(weights)
/free
weight = pos_weights(%rem(rightPos : 2) + 1);
return charValue * weight;
/end-free
P E
validator/checkdigit_h.rpgle 100666 241 0 4533 11523215516 14017 0 ustar 00IUSR0001 /if not defined (CHECKDIGIT_H)
/define CHECKDIGIT_H
*-------------------------------------------------------------------------
*
* (C) Copyleft 2011 Mihael Schmidt
*
* This file is part of the CHECKDIGIT service program).
*
* CHECKDIGIT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* CHECKDIGIT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CHECKDIGIT. If not, see .
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
* Prototypes
*-------------------------------------------------------------------------
/**
* \brief Validate code
*
* Validate a modulus check digit for a code.
*
* \param Code
* \param Modulus (default: 10)
*
* \return *on = code is valid
* *off = no code passed or code invalid
*/
D rng_validator_modulus_isValid...
D PR N extproc('rng_validator_modulus_-
D isValid')
D code 128A const varying
D modulus 10I 0 const options(*nopass)
/**
* \param Calculate check digit
*
* Calculates the check digit for the passed code.
*
* \param Code (without check digit)
*
* \return calculated check digit
*
* \throws CPF9898 Invalid check digit
*/
D rng_validator_modulus_calculate...
D PR 1P 0 extproc('rng_validator_modulus_-
D calculate')
D code 128A const varying
D modulus 10I 0 const options(*nopass)
/endif