Program: 58354
Project: 58354
Buggy source:
private int encodeAsCode1Data(){
  Mode current_mode, next_mode;
  boolean latch;
  boolean done;
  int sourcePoint, targetPoint, i, j;
  int c40_p;
  int text_p;
  int edi_p;
  int byte_start=0;
  int[] c40_buffer=new int[6];
  int[] text_buffer=new int[6];
  int[] edi_buffer=new int[6];
  String decimal_binary="String_Node_Str";
  int length=content.length();
  int shift_set, value;
  int data_left, decimal_count;
  int sub_value;
  int bits_left_in_byte, target_count;
  boolean isTwoDigits;
  source=content.getBytes(StandardCharsets.ISO_8859_1);
  sourcePoint=0;
  targetPoint=0;
  c40_p=0;
  text_p=0;
  edi_p=0;
  if (inputDataType == DataType.GS1) {
    data[targetPoint]=232;
    targetPoint++;
  }
  current_mode=Mode.C1_ASCII;
  next_mode=Mode.C1_ASCII;
  do {
    if (current_mode != next_mode) {
switch (next_mode) {
case C1_C40:
        data[targetPoint]=230;
      targetPoint++;
    break;
case C1_TEXT:
  data[targetPoint]=239;
targetPoint++;
break;
case C1_EDI:
data[targetPoint]=238;
targetPoint++;
break;
case C1_BYTE:
data[targetPoint]=231;
targetPoint++;
break;
}
}
if ((current_mode != Mode.C1_BYTE) && (next_mode == Mode.C1_BYTE)) {
byte_start=targetPoint;
}
current_mode=next_mode;
if (current_mode == Mode.C1_ASCII) {
next_mode=Mode.C1_ASCII;
if ((length - sourcePoint) >= 21) {
j=0;
for (i=0; i < 21; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 21) {
next_mode=Mode.C1_DECIMAL;
decimal_binary+="String_Node_Str";
}
}
if ((next_mode == Mode.C1_ASCII) && ((length - sourcePoint) >= 13)) {
j=0;
for (i=0; i < 13; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 13) {
latch=false;
for (i=sourcePoint + 13; i < length; i++) {
if (!((source[i] >= '0') && (source[i] <= '9'))) {
latch=true;
}
}
if (!(latch)) {
next_mode=Mode.C1_DECIMAL;
decimal_binary+="String_Node_Str";
}
}
}
if (next_mode == Mode.C1_ASCII) {
isTwoDigits=false;
if ((sourcePoint + 1) != length) {
if ((source[sourcePoint] >= '0') && (source[sourcePoint] <= '9')) {
if ((source[sourcePoint + 1] >= '0') && (source[sourcePoint + 1] <= '9')) {
data[targetPoint]=(10 * (source[sourcePoint] - '0')) + (source[sourcePoint + 1] - '0') + 130;
targetPoint++;
sourcePoint+=2;
isTwoDigits=true;
}
}
}
if (!(isTwoDigits)) {
if ((inputDataType == DataType.GS1) && (source[sourcePoint] == '[')) {
if ((length - sourcePoint) >= 15) {
j=0;
for (i=0; i < 15; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 15) {
data[targetPoint]=236;
targetPoint++;
sourcePoint++;
next_mode=Mode.C1_DECIMAL;
}
}
if ((length - sourcePoint) >= 7) {
j=0;
for (i=0; i < 7; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 7) {
latch=false;
for (i=sourcePoint + 7; i < length; i++) {
if (!((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9'))) {
latch=true;
}
}
if (!(latch)) {
data[targetPoint]=236;
targetPoint++;
sourcePoint++;
next_mode=Mode.C1_DECIMAL;
}
}
}
}
if (next_mode == Mode.C1_ASCII) {
next_mode=lookAheadTest(length,sourcePoint,current_mode);
if (next_mode == Mode.C1_ASCII) {
if (source[sourcePoint] > 127) {
data[targetPoint]=235;
targetPoint++;
data[targetPoint]=(source[sourcePoint] - 128) + 1;
targetPoint++;
sourcePoint++;
}
 else {
if ((inputDataType == DataType.GS1) && (source[sourcePoint] == '[')) {
data[targetPoint]=232;
targetPoint++;
sourcePoint++;
}
 else {
data[targetPoint]=source[sourcePoint] + 1;
targetPoint++;
sourcePoint++;
}
}
}
}
}
}
}
if (current_mode == Mode.C1_C40) {
done=false;
next_mode=Mode.C1_C40;
if (c40_p == 0) {
if ((length - sourcePoint) >= 12) {
j=0;
for (i=0; i < 12; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 12) {
next_mode=Mode.C1_ASCII;
done=true;
}
}
if ((length - sourcePoint) >= 8) {
j=0;
for (i=0; i < 8; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if ((length - sourcePoint) == 8) {
latch=true;
}
 else {
latch=true;
for (j=sourcePoint + 8; j < length; j++) {
if ((source[j] <= '0') || (source[j] >= '9')) {
latch=false;
}
}
}
if ((j == 8) && latch) {
next_mode=Mode.C1_ASCII;
done=true;
}
}
if (!(done)) {
next_mode=lookAheadTest(length,sourcePoint,current_mode);
}
}
if (next_mode != Mode.C1_C40) {
data[targetPoint]=255;
targetPoint++;
}
 else {
if (source[sourcePoint] > 127) {
c40_buffer[c40_p]=1;
c40_p++;
c40_buffer[c40_p]=30;
c40_p++;
shift_set=C40_SHIFT[source[sourcePoint] - 128];
value=C40_VALUE[source[sourcePoint] - 128];
}
 else {
shift_set=C40_SHIFT[source[sourcePoint]];
value=C40_VALUE[source[sourcePoint]];
}
if ((inputDataType == DataType.GS1) && (source[sourcePoint] == '[')) {
shift_set=2;
value=27;
}
if (shift_set != 0) {
c40_buffer[c40_p]=shift_set - 1;
c40_p++;
}
c40_buffer[c40_p]=value;
c40_p++;
if (c40_p >= 3) {
int iv;
iv=(1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
c40_buffer[0]=c40_buffer[3];
c40_buffer[1]=c40_buffer[4];
c40_buffer[2]=c40_buffer[5];
c40_buffer[3]=0;
c40_buffer[4]=0;
c40_buffer[5]=0;
c40_p-=3;
}
sourcePoint++;
}
}
if (current_mode == Mode.C1_TEXT) {
done=false;
next_mode=Mode.C1_TEXT;
if (text_p == 0) {
if ((length - sourcePoint) >= 12) {
j=0;
for (i=0; i < 12; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 12) {
next_mode=Mode.C1_ASCII;
done=true;
}
}
if ((length - sourcePoint) >= 8) {
j=0;
for (i=0; i < 8; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if ((length - sourcePoint) == 8) {
latch=true;
}
 else {
latch=true;
for (j=sourcePoint + 8; j < length; j++) {
if ((source[j] <= '0') || (source[j] >= '9')) {
latch=false;
}
}
}
if ((j == 8) && latch) {
next_mode=Mode.C1_ASCII;
done=true;
}
}
if (!(done)) {
next_mode=lookAheadTest(length,sourcePoint,current_mode);
}
}
if (next_mode != Mode.C1_TEXT) {
data[targetPoint]=255;
targetPoint++;
}
 else {
if (source[sourcePoint] > 127) {
text_buffer[text_p]=1;
text_p++;
text_buffer[text_p]=30;
text_p++;
shift_set=TEXT_SHIFT[source[sourcePoint] - 128];
value=TEXT_VALUE[source[sourcePoint] - 128];
}
 else {
shift_set=TEXT_SHIFT[source[sourcePoint]];
value=TEXT_VALUE[source[sourcePoint]];
}
if ((inputDataType == DataType.GS1) && (source[sourcePoint] == '[')) {
shift_set=2;
value=27;
}
if (shift_set != 0) {
text_buffer[text_p]=shift_set - 1;
text_p++;
}
text_buffer[text_p]=value;
text_p++;
if (text_p >= 3) {
int iv;
iv=(1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
text_buffer[0]=text_buffer[3];
text_buffer[1]=text_buffer[4];
text_buffer[2]=text_buffer[5];
text_buffer[3]=0;
text_buffer[4]=0;
text_buffer[5]=0;
text_p-=3;
}
sourcePoint++;
}
}
if (current_mode == Mode.C1_EDI) {
value=0;
next_mode=Mode.C1_EDI;
if (edi_p == 0) {
if ((length - sourcePoint) >= 12) {
j=0;
for (i=0; i < 12; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 12) {
next_mode=Mode.C1_ASCII;
}
}
if ((length - sourcePoint) >= 8) {
j=0;
for (i=0; i < 8; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if ((length - sourcePoint) == 8) {
latch=true;
}
 else {
latch=true;
for (j=sourcePoint + 8; j < length; j++) {
if ((source[j] <= '0') || (source[j] >= '9')) {
latch=false;
}
}
}
if ((j == 8) && latch) {
next_mode=Mode.C1_ASCII;
}
}
if (!((isEdiEncodable(source[sourcePoint]) && isEdiEncodable(source[sourcePoint + 1])) && isEdiEncodable(source[sourcePoint + 2]))) {
next_mode=Mode.C1_ASCII;
}
}
if (next_mode != Mode.C1_EDI) {
data[targetPoint]=255;
targetPoint++;
}
 else {
if (source[sourcePoint] == 13) {
value=0;
}
if (source[sourcePoint] == '*') {
value=1;
}
if (source[sourcePoint] == '>') {
value=2;
}
if (source[sourcePoint] == ' ') {
value=3;
}
if ((source[sourcePoint] >= '0') && (source[sourcePoint] <= '9')) {
value=source[sourcePoint] - '0' + 4;
}
if ((source[sourcePoint] >= 'A') && (source[sourcePoint] <= 'Z')) {
value=source[sourcePoint] - 'A' + 14;
}
edi_buffer[edi_p]=value;
edi_p++;
if (edi_p >= 3) {
int iv;
iv=(1600 * edi_buffer[0]) + (40 * edi_buffer[1]) + (edi_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
edi_buffer[0]=edi_buffer[3];
edi_buffer[1]=edi_buffer[4];
edi_buffer[2]=edi_buffer[5];
edi_buffer[3]=0;
edi_buffer[4]=0;
edi_buffer[5]=0;
edi_p-=3;
}
sourcePoint++;
}
}
if (current_mode == Mode.C1_DECIMAL) {
next_mode=Mode.C1_DECIMAL;
data_left=length - sourcePoint;
decimal_count=0;
if (data_left >= 1) {
if ((source[sourcePoint] >= '0') && (source[sourcePoint] <= '9')) {
decimal_count=1;
}
}
if (data_left >= 2) {
if ((decimal_count == 1) && ((source[sourcePoint + 1] >= '0') && (source[sourcePoint + 1] <= '9'))) {
decimal_count=2;
}
}
if (data_left >= 3) {
if ((decimal_count == 2) && ((source[sourcePoint + 2] >= '0') && (source[sourcePoint + 2] <= '9'))) {
decimal_count=3;
}
}
if (decimal_count != 3) {
decimal_binary+="String_Node_Str";
target_count=3;
if (decimal_binary.length() <= 16) {
target_count=2;
}
if (decimal_binary.length() <= 8) {
target_count=1;
}
bits_left_in_byte=(8 * target_count) - decimal_binary.length();
if (bits_left_in_byte == 8) {
bits_left_in_byte=0;
}
if (bits_left_in_byte == 2) {
decimal_binary+="String_Node_Str";
}
if ((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) {
if (decimal_count >= 1) {
sub_value=source[sourcePoint] - '0' + 1;
for (i=0x08; i > 0; i=i >> 1) {
if ((sub_value & i) != 0) {
decimal_binary+="String_Node_Str";
}
 else {
decimal_binary+="String_Node_Str";
}
}
sourcePoint++;
}
 else {
decimal_binary+="String_Node_Str";
}
}
if (bits_left_in_byte == 6) {
decimal_binary+="String_Node_Str";
}
if (target_count >= 1) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
if (target_count >= 2) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(8 + i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
if (target_count == 3) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(16 + i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
next_mode=Mode.C1_ASCII;
}
 else {
value=(100 * (source[sourcePoint] - '0')) + (10 * (source[sourcePoint + 1] - '0')) + (source[sourcePoint + 2] - '0')+ 1;
for (i=0x200; i > 0; i=i >> 1) {
if ((value & i) != 0) {
decimal_binary+="String_Node_Str";
}
 else {
decimal_binary+="String_Node_Str";
}
}
sourcePoint+=3;
}
if (decimal_binary.length() >= 24) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(i) == '1') {
data[targetPoint]+=128 >> i;
}
if (decimal_binary.charAt(8 + i) == '1') {
data[targetPoint + 1]+=128 >> i;
}
if (decimal_binary.charAt(16 + i) == '1') {
data[targetPoint + 2]+=128 >> i;
}
}
targetPoint+=3;
if (decimal_binary.length() > 24) {
decimal_binary=decimal_binary.substring(24);
}
}
}
if (current_mode == Mode.C1_BYTE) {
next_mode=Mode.C1_BYTE;
if ((inputDataType == DataType.GS1) && (source[sourcePoint] == '[')) {
next_mode=Mode.C1_ASCII;
}
 else {
if (source[sourcePoint] <= 127) {
next_mode=lookAheadTest(length,sourcePoint,current_mode);
}
}
if (next_mode != Mode.C1_BYTE) {
if ((targetPoint - byte_start) <= 249) {
for (i=targetPoint; i >= byte_start; i--) {
data[i + 1]=data[i];
}
data[byte_start]=(targetPoint - byte_start);
targetPoint++;
}
 else {
for (i=targetPoint; i >= byte_start; i--) {
data[i + 2]=data[i];
}
data[byte_start]=249 + ((targetPoint - byte_start) / 250);
data[byte_start + 1]=((targetPoint - byte_start) % 250);
targetPoint+=2;
}
}
 else {
data[targetPoint]=source[sourcePoint];
targetPoint++;
sourcePoint++;
}
}
if (targetPoint > 1480) {
throw new OkapiException("String_Node_Str");
}
}
 while (sourcePoint < length);
if (c40_p == 2) {
int iv;
c40_buffer[2]=1;
iv=(1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
data[targetPoint]=255;
targetPoint++;
}
if (c40_p == 1) {
int iv;
c40_buffer[1]=1;
c40_buffer[2]=31;
iv=(1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
data[targetPoint]=255;
targetPoint++;
}
if (text_p == 2) {
int iv;
text_buffer[2]=1;
iv=(1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
data[targetPoint]=255;
targetPoint++;
}
if (text_p == 1) {
int iv;
text_buffer[1]=1;
text_buffer[2]=31;
iv=(1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
data[targetPoint]=255;
targetPoint++;
}
if (current_mode == Mode.C1_DECIMAL) {
decimal_binary+="String_Node_Str";
target_count=3;
if (decimal_binary.length() <= 16) {
target_count=2;
}
if (decimal_binary.length() <= 8) {
target_count=1;
}
bits_left_in_byte=(8 * target_count) - decimal_binary.length();
if (bits_left_in_byte == 8) {
bits_left_in_byte=0;
}
if (bits_left_in_byte == 2) {
decimal_binary+="String_Node_Str";
}
if ((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) {
decimal_binary+="String_Node_Str";
}
if (bits_left_in_byte == 6) {
decimal_binary+="String_Node_Str";
}
if (target_count >= 1) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
if (target_count >= 2) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(8 + i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
if (target_count == 3) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(16 + i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
}
if (current_mode == Mode.C1_BYTE) {
if ((targetPoint - byte_start) <= 249) {
for (i=targetPoint; i >= byte_start; i--) {
data[i + 1]=data[i];
}
data[byte_start]=(targetPoint - byte_start);
targetPoint++;
}
 else {
for (i=targetPoint; i >= byte_start; i--) {
data[i + 2]=data[i];
}
data[byte_start]=249 + ((targetPoint - byte_start) / 250);
data[byte_start + 1]=((targetPoint - byte_start) % 250);
targetPoint+=2;
}
}
if (targetPoint > 1480) {
throw new OkapiException("String_Node_Str");
}
return targetPoint;
}

Fixed version (ground truth):
private int encodeAsCode1Data(){
  Mode current_mode, next_mode;
  boolean latch;
  boolean done;
  int sourcePoint, targetPoint, i, j;
  int c40_p;
  int text_p;
  int edi_p;
  int byte_start=0;
  int[] c40_buffer=new int[6];
  int[] text_buffer=new int[6];
  int[] edi_buffer=new int[6];
  String decimal_binary="String_Node_Str";
  int length=content.length();
  int shift_set, value;
  int data_left, decimal_count;
  int sub_value;
  int bits_left_in_byte, target_count;
  boolean isTwoDigits;
  byte[] bytes=content.getBytes(StandardCharsets.ISO_8859_1);
  source=new int[bytes.length];
  for (i=0; i < source.length; i++) {
    source[i]=bytes[i] & 0xff;
  }
  sourcePoint=0;
  targetPoint=0;
  c40_p=0;
  text_p=0;
  edi_p=0;
  if (inputDataType == DataType.GS1) {
    data[targetPoint]=232;
    targetPoint++;
  }
  current_mode=Mode.C1_ASCII;
  next_mode=Mode.C1_ASCII;
  do {
    if (current_mode != next_mode) {
switch (next_mode) {
case C1_C40:
        data[targetPoint]=230;
      targetPoint++;
    break;
case C1_TEXT:
  data[targetPoint]=239;
targetPoint++;
break;
case C1_EDI:
data[targetPoint]=238;
targetPoint++;
break;
case C1_BYTE:
data[targetPoint]=231;
targetPoint++;
break;
}
}
if ((current_mode != Mode.C1_BYTE) && (next_mode == Mode.C1_BYTE)) {
byte_start=targetPoint;
}
current_mode=next_mode;
if (current_mode == Mode.C1_ASCII) {
next_mode=Mode.C1_ASCII;
if ((length - sourcePoint) >= 21) {
j=0;
for (i=0; i < 21; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 21) {
next_mode=Mode.C1_DECIMAL;
decimal_binary+="String_Node_Str";
}
}
if ((next_mode == Mode.C1_ASCII) && ((length - sourcePoint) >= 13)) {
j=0;
for (i=0; i < 13; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 13) {
latch=false;
for (i=sourcePoint + 13; i < length; i++) {
if (!((source[i] >= '0') && (source[i] <= '9'))) {
latch=true;
}
}
if (!(latch)) {
next_mode=Mode.C1_DECIMAL;
decimal_binary+="String_Node_Str";
}
}
}
if (next_mode == Mode.C1_ASCII) {
isTwoDigits=false;
if ((sourcePoint + 1) != length) {
if ((source[sourcePoint] >= '0') && (source[sourcePoint] <= '9')) {
if ((source[sourcePoint + 1] >= '0') && (source[sourcePoint + 1] <= '9')) {
data[targetPoint]=(10 * (source[sourcePoint] - '0')) + (source[sourcePoint + 1] - '0') + 130;
targetPoint++;
sourcePoint+=2;
isTwoDigits=true;
}
}
}
if (!(isTwoDigits)) {
if ((inputDataType == DataType.GS1) && (source[sourcePoint] == '[')) {
if ((length - sourcePoint) >= 15) {
j=0;
for (i=0; i < 15; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 15) {
data[targetPoint]=236;
targetPoint++;
sourcePoint++;
next_mode=Mode.C1_DECIMAL;
}
}
if ((length - sourcePoint) >= 7) {
j=0;
for (i=0; i < 7; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 7) {
latch=false;
for (i=sourcePoint + 7; i < length; i++) {
if (!((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9'))) {
latch=true;
}
}
if (!(latch)) {
data[targetPoint]=236;
targetPoint++;
sourcePoint++;
next_mode=Mode.C1_DECIMAL;
}
}
}
}
if (next_mode == Mode.C1_ASCII) {
next_mode=lookAheadTest(length,sourcePoint,current_mode);
if (next_mode == Mode.C1_ASCII) {
if (source[sourcePoint] > 127) {
data[targetPoint]=235;
targetPoint++;
data[targetPoint]=(source[sourcePoint] - 128) + 1;
targetPoint++;
sourcePoint++;
}
 else {
if ((inputDataType == DataType.GS1) && (source[sourcePoint] == '[')) {
data[targetPoint]=232;
targetPoint++;
sourcePoint++;
}
 else {
data[targetPoint]=source[sourcePoint] + 1;
targetPoint++;
sourcePoint++;
}
}
}
}
}
}
}
if (current_mode == Mode.C1_C40) {
done=false;
next_mode=Mode.C1_C40;
if (c40_p == 0) {
if ((length - sourcePoint) >= 12) {
j=0;
for (i=0; i < 12; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 12) {
next_mode=Mode.C1_ASCII;
done=true;
}
}
if ((length - sourcePoint) >= 8) {
j=0;
for (i=0; i < 8; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if ((length - sourcePoint) == 8) {
latch=true;
}
 else {
latch=true;
for (j=sourcePoint + 8; j < length; j++) {
if ((source[j] <= '0') || (source[j] >= '9')) {
latch=false;
}
}
}
if ((j == 8) && latch) {
next_mode=Mode.C1_ASCII;
done=true;
}
}
if (!(done)) {
next_mode=lookAheadTest(length,sourcePoint,current_mode);
}
}
if (next_mode != Mode.C1_C40) {
data[targetPoint]=255;
targetPoint++;
}
 else {
if (source[sourcePoint] > 127) {
c40_buffer[c40_p]=1;
c40_p++;
c40_buffer[c40_p]=30;
c40_p++;
shift_set=C40_SHIFT[source[sourcePoint] - 128];
value=C40_VALUE[source[sourcePoint] - 128];
}
 else {
shift_set=C40_SHIFT[source[sourcePoint]];
value=C40_VALUE[source[sourcePoint]];
}
if ((inputDataType == DataType.GS1) && (source[sourcePoint] == '[')) {
shift_set=2;
value=27;
}
if (shift_set != 0) {
c40_buffer[c40_p]=shift_set - 1;
c40_p++;
}
c40_buffer[c40_p]=value;
c40_p++;
if (c40_p >= 3) {
int iv;
iv=(1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
c40_buffer[0]=c40_buffer[3];
c40_buffer[1]=c40_buffer[4];
c40_buffer[2]=c40_buffer[5];
c40_buffer[3]=0;
c40_buffer[4]=0;
c40_buffer[5]=0;
c40_p-=3;
}
sourcePoint++;
}
}
if (current_mode == Mode.C1_TEXT) {
done=false;
next_mode=Mode.C1_TEXT;
if (text_p == 0) {
if ((length - sourcePoint) >= 12) {
j=0;
for (i=0; i < 12; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 12) {
next_mode=Mode.C1_ASCII;
done=true;
}
}
if ((length - sourcePoint) >= 8) {
j=0;
for (i=0; i < 8; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if ((length - sourcePoint) == 8) {
latch=true;
}
 else {
latch=true;
for (j=sourcePoint + 8; j < length; j++) {
if ((source[j] <= '0') || (source[j] >= '9')) {
latch=false;
}
}
}
if ((j == 8) && latch) {
next_mode=Mode.C1_ASCII;
done=true;
}
}
if (!(done)) {
next_mode=lookAheadTest(length,sourcePoint,current_mode);
}
}
if (next_mode != Mode.C1_TEXT) {
data[targetPoint]=255;
targetPoint++;
}
 else {
if (source[sourcePoint] > 127) {
text_buffer[text_p]=1;
text_p++;
text_buffer[text_p]=30;
text_p++;
shift_set=TEXT_SHIFT[source[sourcePoint] - 128];
value=TEXT_VALUE[source[sourcePoint] - 128];
}
 else {
shift_set=TEXT_SHIFT[source[sourcePoint]];
value=TEXT_VALUE[source[sourcePoint]];
}
if ((inputDataType == DataType.GS1) && (source[sourcePoint] == '[')) {
shift_set=2;
value=27;
}
if (shift_set != 0) {
text_buffer[text_p]=shift_set - 1;
text_p++;
}
text_buffer[text_p]=value;
text_p++;
if (text_p >= 3) {
int iv;
iv=(1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
text_buffer[0]=text_buffer[3];
text_buffer[1]=text_buffer[4];
text_buffer[2]=text_buffer[5];
text_buffer[3]=0;
text_buffer[4]=0;
text_buffer[5]=0;
text_p-=3;
}
sourcePoint++;
}
}
if (current_mode == Mode.C1_EDI) {
value=0;
next_mode=Mode.C1_EDI;
if (edi_p == 0) {
if ((length - sourcePoint) >= 12) {
j=0;
for (i=0; i < 12; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if (j == 12) {
next_mode=Mode.C1_ASCII;
}
}
if ((length - sourcePoint) >= 8) {
j=0;
for (i=0; i < 8; i++) {
if ((source[sourcePoint + i] >= '0') && (source[sourcePoint + i] <= '9')) {
j++;
}
}
if ((length - sourcePoint) == 8) {
latch=true;
}
 else {
latch=true;
for (j=sourcePoint + 8; j < length; j++) {
if ((source[j] <= '0') || (source[j] >= '9')) {
latch=false;
}
}
}
if ((j == 8) && latch) {
next_mode=Mode.C1_ASCII;
}
}
if (!((isEdiEncodable(source[sourcePoint]) && isEdiEncodable(source[sourcePoint + 1])) && isEdiEncodable(source[sourcePoint + 2]))) {
next_mode=Mode.C1_ASCII;
}
}
if (next_mode != Mode.C1_EDI) {
data[targetPoint]=255;
targetPoint++;
}
 else {
if (source[sourcePoint] == 13) {
value=0;
}
if (source[sourcePoint] == '*') {
value=1;
}
if (source[sourcePoint] == '>') {
value=2;
}
if (source[sourcePoint] == ' ') {
value=3;
}
if ((source[sourcePoint] >= '0') && (source[sourcePoint] <= '9')) {
value=source[sourcePoint] - '0' + 4;
}
if ((source[sourcePoint] >= 'A') && (source[sourcePoint] <= 'Z')) {
value=source[sourcePoint] - 'A' + 14;
}
edi_buffer[edi_p]=value;
edi_p++;
if (edi_p >= 3) {
int iv;
iv=(1600 * edi_buffer[0]) + (40 * edi_buffer[1]) + (edi_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
edi_buffer[0]=edi_buffer[3];
edi_buffer[1]=edi_buffer[4];
edi_buffer[2]=edi_buffer[5];
edi_buffer[3]=0;
edi_buffer[4]=0;
edi_buffer[5]=0;
edi_p-=3;
}
sourcePoint++;
}
}
if (current_mode == Mode.C1_DECIMAL) {
next_mode=Mode.C1_DECIMAL;
data_left=length - sourcePoint;
decimal_count=0;
if (data_left >= 1) {
if ((source[sourcePoint] >= '0') && (source[sourcePoint] <= '9')) {
decimal_count=1;
}
}
if (data_left >= 2) {
if ((decimal_count == 1) && ((source[sourcePoint + 1] >= '0') && (source[sourcePoint + 1] <= '9'))) {
decimal_count=2;
}
}
if (data_left >= 3) {
if ((decimal_count == 2) && ((source[sourcePoint + 2] >= '0') && (source[sourcePoint + 2] <= '9'))) {
decimal_count=3;
}
}
if (decimal_count != 3) {
decimal_binary+="String_Node_Str";
target_count=3;
if (decimal_binary.length() <= 16) {
target_count=2;
}
if (decimal_binary.length() <= 8) {
target_count=1;
}
bits_left_in_byte=(8 * target_count) - decimal_binary.length();
if (bits_left_in_byte == 8) {
bits_left_in_byte=0;
}
if (bits_left_in_byte == 2) {
decimal_binary+="String_Node_Str";
}
if ((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) {
if (decimal_count >= 1) {
sub_value=source[sourcePoint] - '0' + 1;
for (i=0x08; i > 0; i=i >> 1) {
if ((sub_value & i) != 0) {
decimal_binary+="String_Node_Str";
}
 else {
decimal_binary+="String_Node_Str";
}
}
sourcePoint++;
}
 else {
decimal_binary+="String_Node_Str";
}
}
if (bits_left_in_byte == 6) {
decimal_binary+="String_Node_Str";
}
if (target_count >= 1) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
if (target_count >= 2) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(8 + i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
if (target_count == 3) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(16 + i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
next_mode=Mode.C1_ASCII;
}
 else {
value=(100 * (source[sourcePoint] - '0')) + (10 * (source[sourcePoint + 1] - '0')) + (source[sourcePoint + 2] - '0')+ 1;
for (i=0x200; i > 0; i=i >> 1) {
if ((value & i) != 0) {
decimal_binary+="String_Node_Str";
}
 else {
decimal_binary+="String_Node_Str";
}
}
sourcePoint+=3;
}
if (decimal_binary.length() >= 24) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(i) == '1') {
data[targetPoint]+=128 >> i;
}
if (decimal_binary.charAt(8 + i) == '1') {
data[targetPoint + 1]+=128 >> i;
}
if (decimal_binary.charAt(16 + i) == '1') {
data[targetPoint + 2]+=128 >> i;
}
}
targetPoint+=3;
if (decimal_binary.length() > 24) {
decimal_binary=decimal_binary.substring(24);
}
}
}
if (current_mode == Mode.C1_BYTE) {
next_mode=Mode.C1_BYTE;
if ((inputDataType == DataType.GS1) && (source[sourcePoint] == '[')) {
next_mode=Mode.C1_ASCII;
}
 else {
if (source[sourcePoint] <= 127) {
next_mode=lookAheadTest(length,sourcePoint,current_mode);
}
}
if (next_mode != Mode.C1_BYTE) {
if ((targetPoint - byte_start) <= 249) {
for (i=targetPoint; i >= byte_start; i--) {
data[i + 1]=data[i];
}
data[byte_start]=(targetPoint - byte_start);
targetPoint++;
}
 else {
for (i=targetPoint; i >= byte_start; i--) {
data[i + 2]=data[i];
}
data[byte_start]=249 + ((targetPoint - byte_start) / 250);
data[byte_start + 1]=((targetPoint - byte_start) % 250);
targetPoint+=2;
}
}
 else {
data[targetPoint]=source[sourcePoint];
targetPoint++;
sourcePoint++;
}
}
if (targetPoint > 1480) {
throw new OkapiException("String_Node_Str");
}
}
 while (sourcePoint < length);
if (c40_p == 2) {
int iv;
c40_buffer[2]=1;
iv=(1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
data[targetPoint]=255;
targetPoint++;
}
if (c40_p == 1) {
int iv;
c40_buffer[1]=1;
c40_buffer[2]=31;
iv=(1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
data[targetPoint]=255;
targetPoint++;
}
if (text_p == 2) {
int iv;
text_buffer[2]=1;
iv=(1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
data[targetPoint]=255;
targetPoint++;
}
if (text_p == 1) {
int iv;
text_buffer[1]=1;
text_buffer[2]=31;
iv=(1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2])+ 1;
data[targetPoint]=iv / 256;
targetPoint++;
data[targetPoint]=iv % 256;
targetPoint++;
data[targetPoint]=255;
targetPoint++;
}
if (current_mode == Mode.C1_DECIMAL) {
decimal_binary+="String_Node_Str";
target_count=3;
if (decimal_binary.length() <= 16) {
target_count=2;
}
if (decimal_binary.length() <= 8) {
target_count=1;
}
bits_left_in_byte=(8 * target_count) - decimal_binary.length();
if (bits_left_in_byte == 8) {
bits_left_in_byte=0;
}
if (bits_left_in_byte == 2) {
decimal_binary+="String_Node_Str";
}
if ((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) {
decimal_binary+="String_Node_Str";
}
if (bits_left_in_byte == 6) {
decimal_binary+="String_Node_Str";
}
if (target_count >= 1) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
if (target_count >= 2) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(8 + i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
if (target_count == 3) {
for (i=0; i < 8; i++) {
if (decimal_binary.charAt(16 + i) == '1') {
data[targetPoint]+=128 >> i;
}
}
targetPoint++;
}
}
if (current_mode == Mode.C1_BYTE) {
if ((targetPoint - byte_start) <= 249) {
for (i=targetPoint; i >= byte_start; i--) {
data[i + 1]=data[i];
}
data[byte_start]=(targetPoint - byte_start);
targetPoint++;
}
 else {
for (i=targetPoint; i >= byte_start; i--) {
data[i + 2]=data[i];
}
data[byte_start]=249 + ((targetPoint - byte_start) / 250);
data[byte_start + 1]=((targetPoint - byte_start) % 250);
targetPoint+=2;
}
}
if (targetPoint > 1480) {
throw new OkapiException("String_Node_Str");
}
return targetPoint;
}