Exemple #1
0
bool StarbookDriver::updateLocation(double latitude, double longitude, double elevation) {
    INDI_UNUSED(elevation);
    if (last_known_state != starbook::INIT) {
        LOGF_WARN("Can't update location in %s state", starbook::STATE_TO_STR.at(last_known_state).c_str());
        return false;
    }
    if (TimeT[1].text == nullptr) {
        LOG_WARN("Can't update location before time");
        return false;
    }

    auto utc_offset = static_cast<short>(std::floor(std::strtof(TimeT[1].text, nullptr)));
    LOGF_WARN("UTC offset for location: %i", utc_offset);
    starbook::LnLat posn(latitude, longitude);
    starbook::ResponseCode rc = cmd_interface->SetPlace(posn, utc_offset);
    LogResponse("Updating location", rc);
    return rc == starbook::OK;
}
Exemple #2
0
int best_option(char* Maze, int start)
{
    int* U_$;
    int* Add_$; 
    int U_R = sdistance(Maze, start, 2650), min;   
    U_$ = (int*)malloc(sizeof(int)*100);
    Add_$ = (int*)malloc(sizeof(int)*100);
    int i =0,j=0;
    while(i<2704)
    {
        if(Maze[i] == '$')
        {
            U_$[j] = sdistance(Maze, start, i);
            Add_$[j] = i;
            j++;
        }
        i++;
    }
    U_$[j] = -10;  //termination constant
    j = 0;
    min = U_$[j];
    int minadd = Add_$[j];
    for(j=0; U_$[j] != -10; j++)
    {
        if(min > U_$[j])
            {min = U_$[j]; minadd = Add_$[j];} 
    }
    int E = posn(Maze, 'E');
    int E_R = sdistance(Maze, E, 2650);
    int* E_$;
    E_$ = (int*)malloc(sizeof(int)*100);
    i =0,j=0;
    while(i<2704)
    {
        if(Maze[i] == '$')
        {
            E_$[j] = sdistance(Maze, E, i);
            j++;
        }
        i++;
    }
    E_$[j] = -10;  //termination constant

    
    
/*
 * Now here, starts the bot algorithm The decisive part of the bot which decides
 * which point towards should the move be intended for
 */
 
/*
 * If distance between U and R is less than that between E and R
 * and provided E cant take 5 $ before U reaches R, go straight for R
 */ 
    if(U_R < dist_calc(E_$,5) && U_R < E_R)
        return 2650;

/*
 * If distance between U and R is less than that between E and R
 * and provided E can reach 5 $ before U reaches R.
 */
    else if(U_R < E_R && U_R > dist_calc(E_$,5))
    {
    // If U can reach a $ and still be close to R than E go take that $
        if(min + sdistance(Maze,minadd,2650) < E_R)
            return minadd;
    // Going towards R while collecting random $ near it (radius 4)               
//        else
//            return standard(Maze,start);
    }
    else if(U_R == E_R)
        return standard(Maze, start);
    else if(U_R > E_R)
    {
            return minadd;          
    }    
    return 2650;
}
Exemple #3
0
int hibc(struct zint_symbol *symbol, uint8_t source[], int length)
{
	int counter, error_number, i;
	char to_process[40], temp[2], check_digit;

	if(length > 36) {
		strcpy(symbol->errtxt, "Data too long for HIBC LIC");
		return ZERROR_TOO_LONG;
	}
	to_upper(source);
	error_number = is_sane(TECHNETIUM , source, length);
	if(error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	strcpy(to_process, "+");
	counter = 41;
	for(i = 0; i < length; i++) {
		counter += posn(TECHNETIUM, source[i]);
	}
	counter = counter % 43;

	if(counter < 10) {
		check_digit = itoc(counter);
	} else {
		if(counter < 36) {
			check_digit = (counter - 10) + 'A';
		} else {
			switch(counter) {
				case 36: check_digit = '-'; break;
				case 37: check_digit = '.'; break;
				case 38: check_digit = ' '; break;
				case 39: check_digit = '$'; break;
				case 40: check_digit = '/'; break;
				case 41: check_digit = '+'; break;
				case 42: check_digit = '%'; break;
				default: check_digit = ' '; break; /* Keep compiler happy */
			}
		}
	}

	temp[0] = check_digit;
	temp[1] = '\0';

	concat(to_process, (char *)source);
	concat(to_process, temp);
	length = strlen(to_process);

	switch(symbol->symbology) {
		case BARCODE_HIBC_QR:
			error_number = qr_code(symbol, (uint8_t *)to_process, length);
			break;
		case BARCODE_HIBC_PDF:
			error_number = pdf417enc(symbol, (uint8_t *)to_process, length);
			break;
		case BARCODE_HIBC_MICPDF:
			error_number = micro_pdf417(symbol, (uint8_t *)to_process, length);
			break;
	}

	return error_number;
}
int c93(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Code 93 is an advancement on Code 39 and the definition is a lot tighter */

  /* SILVER includes the extra characters a, b, c and d to represent Code 93 specific
     shift characters 1, 2, 3 and 4 respectively. These characters are never used by
     c39() and ec39() */

	int i;
	int h, weight, c, k, values[128], error_number;
	char buffer[220];
	char dest[670];
	char set_copy[] = SILVER;
	
	error_number = 0;
    strcpy(buffer, "");
	
	if(length > 107) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	
	/* Message Content */
	for (i = 0; i < length; i++) {
		if (source[i] > 127) {
			/* Cannot encode extended ASCII */
			strcpy(symbol->errtxt, "Invalid characters in input data");
            return ERROR_INVALID_DATA1;
		}
		concat(buffer, C93Ctrl[source[i]]);
		symbol->text[i] = source[i] ? source[i] : ' ';
	}
	
	/* Now we can check the true length of the barcode */
	h = strlen(buffer);
	if (h > 107) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	
	for (i = 0; i < h; i++) {
		values[i] = posn(SILVER, buffer[i]);
	}

	/* Putting the data into dest[] is not done until after check digits are calculated */

	/* Check digit C */
	c = 0;
	weight = 1;
	for (i = h - 1; i >= 0; i--) {
		c += values[i] * weight;
		weight++;
		if (weight == 21)
			weight = 1;
	}
	c = c % 47;
	values[h] = c;
	buffer[h] = set_copy[c];

	/* Check digit K */
	k = 0;
	weight = 1;
	for (i = h; i >= 0; i--) {
		k += values[i] * weight;
		weight++;
		if(weight == 16)
			weight = 1;
	}
	k = k % 47;
	buffer[++h] = set_copy[k];
	buffer[++h] = '\0';

	/* Start character */
	strcpy(dest, "111141");

	for(i = 0; i < h; i++) {
		lookup(SILVER, C93Table, buffer[i], dest);
	}

	/* Stop character */
	concat(dest, "1111411");
	expand(symbol, dest);

	symbol->text[length] = set_copy[c];
	symbol->text[length + 1] = set_copy[k];
	symbol->text[length + 2] = '\0';

	return error_number;
}
int c39(struct zint_symbol *symbol, unsigned char source[], unsigned int length)
{ /* Code 39 */
    unsigned int i;
    unsigned int counter = 0;
	char check_digit;
    int error_number = 0;
	char dest[775];
	char localstr[2] = { 0 };
	
	if((symbol->option_2 < 0) || (symbol->option_2 > 1)) {
		symbol->option_2 = 0;
	}
	
	if((symbol->symbology == BARCODE_LOGMARS) && (length > 59)) {
			strcpy(symbol->errtxt, "Input too long");
			return ERROR_TOO_LONG;
	} else if(length > 74) {
			strcpy(symbol->errtxt, "Input too long");
			return ERROR_TOO_LONG;
	}
	to_upper(source);
	error_number = is_sane(SILVER , source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	/* Start character */
	strcpy(dest, "1211212111");

	for(i = 0; i < length; i++) {
		lookup(SILVER, C39Table, source[i], dest);
		counter += posn(SILVER, source[i]);
	}
	
	if((symbol->symbology == BARCODE_LOGMARS) || (symbol->option_2 == 1)) {
		
		counter = counter % 43;
		if(counter < 10) {
			check_digit = itoc(counter);
		} else {
			if(counter < 36) {
				check_digit = (counter - 10) + 'A';
			} else {
				switch(counter) {
					case 36: check_digit = '-'; break;
					case 37: check_digit = '.'; break;
					case 38: check_digit = ' '; break;
					case 39: check_digit = '$'; break;
					case 40: check_digit = '/'; break;
					case 41: check_digit = '+'; break;
					case 42: check_digit = 37; break;
					default: check_digit = ' '; break; /* Keep compiler happy */
				}
			}
		}
		lookup(SILVER, C39Table, check_digit, dest);
	
		/* Display a space check digit as _, otherwise it looks like an error */
		if(check_digit == ' ') {
			check_digit = '_';
		}
		
		localstr[0] = check_digit;
		localstr[1] = '\0';
	}
	
	/* Stop character */
	concat (dest, "121121211");
	
	if((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) {
		/* LOGMARS uses wider 'wide' bars than normal Code 39 */
		counter = strlen(dest);
		for(i = 0; i < counter; i++) {
			if(dest[i] == '2') {
				dest[i] = '3';
			}
		}
	}
	
	expand(symbol, dest);
	
	if(symbol->symbology == BARCODE_CODE39) {
		ustrcpy(symbol->text, (unsigned char*)"*");
		uconcat(symbol->text, source);
		uconcat(symbol->text, (unsigned char*)localstr);
		uconcat(symbol->text, (unsigned char*)"*");
	} else {
		ustrcpy(symbol->text, source);
		uconcat(symbol->text, (unsigned char*)localstr);
	}
	return error_number;
}
Exemple #6
0
int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
{
	int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value, h;
	char intermediate[170];
	int codewords[170], codeword_count;
	int c_grid[8][8]; /* Refers to table 3 */
	int w_grid[8][4]; /* Refets to table 2 */
	int pad_count = 0;
	char pattern[40];
	int gs1;

	if(length > 81) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; }

	strcpy(intermediate, gs1 ? "*" : ""); /* FNC1 */
	for(i = 0; i < length; i++) {
		if(source[i] > 127) {
			strcpy(symbol->errtxt, "Invalid characters in input data");
			return ERROR_INVALID_DATA;
		}
		if(gs1 && (source[i] == '['))
			concat(intermediate, "*"); /* FNC1 */
		else
			concat(intermediate, c49_table7[source[i]]);
	}

	codeword_count = 0;
	i = 0;
	h = strlen(intermediate);
	do {
		if((intermediate[i] >= '0') && (intermediate[i] <= '9')) {
			/* Numeric data */
			for(j = 0; (intermediate[i + j] >= '0') && (intermediate[i + j] <= '9'); j++);
			if(j >= 5) {
				/* Use Numeric Encodation Method */
				int block_count, c;
				int block_remain;
				int block_value;
				
				codewords[codeword_count] = 48; /* Numeric Shift */
				codeword_count++;
				
				block_count = j / 5;
				block_remain = j % 5;
				
				for(c = 0; c < block_count; c++) {
					if((c == block_count - 1) && (block_remain == 2)) {
						/* Rule (d) */
						block_value = 100000;
						block_value += ctoi(intermediate[i]) * 1000;
						block_value += ctoi(intermediate[i + 1]) * 100;
						block_value += ctoi(intermediate[i + 2]) * 10;
						block_value += ctoi(intermediate[i + 3]);
					
						codewords[codeword_count] = block_value / (48 * 48);
						block_value = block_value - (48 * 48) * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value / 48;
						block_value = block_value - 48 * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value;
						codeword_count++;
						i += 4;
						block_value = ctoi(intermediate[i]) * 100;
						block_value += ctoi(intermediate[i + 1]) * 10;
						block_value += ctoi(intermediate[i + 2]);
						
						codewords[codeword_count] = block_value / 48;
						block_value = block_value - 48 * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value;
						codeword_count++;
						i += 3;
					} else {	
						block_value = ctoi(intermediate[i]) * 10000;
						block_value += ctoi(intermediate[i + 1]) * 1000;
						block_value += ctoi(intermediate[i + 2]) * 100;
						block_value += ctoi(intermediate[i + 3]) * 10;
						block_value += ctoi(intermediate[i + 4]);
						
						codewords[codeword_count] = block_value / (48 * 48);
						block_value = block_value - (48 * 48) * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value / 48;
						block_value = block_value - 48 * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value;
						codeword_count++;
						i += 5;
					}
				}
				
				switch(block_remain) {
					case 1:
						/* Rule (a) */
						codewords[codeword_count] = posn(INSET, intermediate[i]);
						codeword_count++;
						i++;
						break;
					case 3:
						/* Rule (b) */
						block_value = ctoi(intermediate[i]) * 100;
						block_value += ctoi(intermediate[i + 1]) * 10;
						block_value += ctoi(intermediate[i + 2]);
						
						codewords[codeword_count] = block_value / 48;
						block_value = block_value - 48 * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value;
						codeword_count++;
						i += 3;
						break;
					case 4:
						/* Rule (c) */
						block_value = 100000;
						block_value += ctoi(intermediate[i]) * 1000;
						block_value += ctoi(intermediate[i + 1]) * 100;
						block_value += ctoi(intermediate[i + 2]) * 10;
						block_value += ctoi(intermediate[i + 3]);
					
						codewords[codeword_count] = block_value / (48 * 48);
						block_value = block_value - (48 * 48) * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value / 48;
						block_value = block_value - 48 * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value;
						codeword_count++;
						i += 4;
						break;
				}
				if(i < h) {
					/* There is more to add */
					codewords[codeword_count] = 48; /* Numeric Shift */
					codeword_count++;
				}
			} else {
				codewords[codeword_count] = posn(INSET, intermediate[i]);
				codeword_count++;
				i++;
			}
		} else {
			codewords[codeword_count] = posn(INSET, intermediate[i]);
			codeword_count++;
			i++;
		}
	} while(i < h);
	
	switch(codewords[0]) { /* Set starting mode value */
		case 48: M = 2;
		case 43: M = 4;
		case 44: M = 5;
		default: M = 0;
	}
	
	if(M != 0) {
		for(i = 0; i < codeword_count; i++) {
			codewords[i] = codewords[i + 1];
		}
		codeword_count--;
	}
	
	if(codeword_count > 49) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	
	/* Place codewords in code character array (c grid) */
	rows = 0;
	do{
		for(i = 0; i < 7; i++) {
			if(((rows * 7) + i) < codeword_count) {
				c_grid[rows][i] = codewords[(rows * 7) + i];
			} else {
				c_grid[rows][i] = 48; /* Pad */
				pad_count++;
			}
		}
		rows++;
	} while ((rows * 7) < codeword_count);
	
	if((((rows <= 6) && (pad_count < 5))) || (rows > 6) || (rows == 1)) {
		/* Add a row */
		for(i = 0; i < 7; i++) {
			c_grid[rows][i] = 48; /* Pad */
		}
		rows++;
	}
	
	/* Add row count and mode character */
	c_grid[rows - 1][6] = (7 * (rows - 2)) + M;
	
	/* Add row check character */
	for(i = 0; i < rows - 1; i++) {
		int row_sum = 0;
		
		for(j = 0; j < 7; j++) {
			row_sum += c_grid[i][j];
		}
		c_grid[i][7] = row_sum % 49;
	}
	
	/* Calculate Symbol Check Characters */
	posn_val = 0;
	x_count = c_grid[rows - 1][6] * 20;
	y_count = c_grid[rows - 1][6] * 16;
	z_count = c_grid[rows - 1][6] * 38;
	for(i = 0; i < rows - 1; i++) {
		for(j = 0; j < 4; j++) {
			local_value = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1];
			x_count += c49_x_weight[posn_val] * local_value;
			y_count += c49_y_weight[posn_val] * local_value;
			z_count += c49_z_weight[posn_val] * local_value;
			posn_val++;
		}
	}
	
	if(rows > 6) {
		/* Add Z Symbol Check */
		c_grid[rows - 1][0] = (z_count % 2401) / 49;
		c_grid[rows - 1][1] = (z_count % 2401) % 49;
	}
	
	local_value = (c_grid[rows - 1][0] * 49) + c_grid[rows - 1][1];
	x_count += c49_x_weight[posn_val] * local_value;
	y_count += c49_y_weight[posn_val] * local_value;
	posn_val++;
	
	/* Add Y Symbol Check */
	c_grid[rows - 1][2] = (y_count % 2401) / 49;
	c_grid[rows - 1][3] = (y_count % 2401) % 49;
	
	local_value = (c_grid[rows - 1][2] * 49) + c_grid[rows - 1][3];
	x_count += c49_x_weight[posn_val] * local_value;
	
	/* Add X Symbol Check */
	c_grid[rows - 1][4] = (x_count % 2401) / 49;
	c_grid[rows - 1][5] = (x_count % 2401) % 49;
	
	/* Add last row check character */
	j = 0;
	for(i = 0; i < 7; i++) {
		j += c_grid[rows - 1][i];
	}
	c_grid[rows - 1][7] = j % 49;
	
	/* Transfer data to symbol character array (w grid) */
	for(i = 0; i < rows; i++) {
		for(j = 0; j < 4; j ++) {
			w_grid[i][j] = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1];
		}
	}
	
	for(i = 0; i < rows; i++) {
		strcpy(pattern, "11"); /* Start character */
		for(j = 0; j < 4; j++) {
			if(i != (rows - 1)) {
				if(c49_table4[i][j] == 'E') {
					/* Even Parity */
					concat(pattern, c49_appxe_even[w_grid[i][j]]);
				} else {
					/* Odd Parity */
					concat(pattern, c49_appxe_odd[w_grid[i][j]]);
				}
			} else {
				/* Last row uses all even parity */
				concat(pattern, c49_appxe_even[w_grid[i][j]]);
			}
		}
		concat(pattern, "4"); /* Stop character */
		
		/* Expand into symbol */
		symbol->row_height[i] = 10;
		expand(symbol, pattern);
	}
	
	symbol->whitespace_width = 10;
	symbol->output_options = BARCODE_BIND;
	symbol->border_width = 2;

	return 0;
}
Exemple #7
0
int gm_encode(int gbdata[], int length, char binary[], int reader)
{
	/* Create a binary stream representation of the input data.
	   7 sets are defined - Chinese characters, Numerals, Lower case letters, Upper case letters,
	   Mixed numerals and latters, Control characters and 8-bit binary data */
	int sp, current_mode, next_mode, last_mode, glyph = 0;
	int c1, c2, done;
	int p = 0, ppos;
	int numbuf[3], punt = 0;
	int number_pad_posn, debug = 0;
	int byte_count_posn = 0, byte_count = 0;
	int shift, i;
	
	strcpy(binary, "");
	
	sp = 0;
	current_mode = 0;
	last_mode = 0;
	number_pad_posn = 0;
	
	if(reader) {
		concat(binary, "1010"); /* FNC3 - Reader Initialisation */
	}
	
	do {
		next_mode = seek_forward(gbdata, length, sp, current_mode);
		
		if(next_mode != current_mode) {
			switch(current_mode) {
				case 0:
					switch(next_mode) {
						case GM_CHINESE: concat(binary, "0001"); break;
						case GM_NUMBER: concat(binary, "0010"); break;
						case GM_LOWER: concat(binary, "0011"); break;
						case GM_UPPER: concat(binary, "0100"); break;
						case GM_MIXED: concat(binary, "0101"); break;
						case GM_BYTE: concat(binary, "0111"); break;
					}
					break;
				case GM_CHINESE:
					switch(next_mode) {
						case GM_NUMBER: concat(binary, "1111111100001"); break; // 8161
						case GM_LOWER: concat(binary, "1111111100010"); break; // 8162
						case GM_UPPER: concat(binary, "1111111100011"); break; // 8163
						case GM_MIXED: concat(binary, "1111111100100"); break; // 8164
						case GM_BYTE: concat(binary, "1111111100101"); break; // 8165
					}
					break;
				case GM_NUMBER:
					/* add numeric block padding value */
					switch(p) {
						case 1: binary[number_pad_posn] = '1'; binary[number_pad_posn + 1] = '0'; break; // 2 pad digits
						case 2: binary[number_pad_posn] = '0'; binary[number_pad_posn + 1] = '1'; break; // 1 pad digit
						case 3: binary[number_pad_posn] = '0'; binary[number_pad_posn + 1] = '0'; break; // 0 pad digits
					}
					switch(next_mode) {
						case GM_CHINESE: concat(binary, "1111111011"); break; // 1019
						case GM_LOWER: concat(binary, "1111111100"); break; // 1020
						case GM_UPPER: concat(binary, "1111111101"); break; // 1021
						case GM_MIXED: concat(binary, "1111111110"); break; // 1022
						case GM_BYTE: concat(binary, "1111111111"); break; // 1023
					}
					break;
				case GM_LOWER:
				case GM_UPPER:
					switch(next_mode) {
						case GM_CHINESE: concat(binary, "11100"); break; // 28
						case GM_NUMBER: concat(binary, "11101"); break; // 29
						case GM_LOWER:
						case GM_UPPER: concat(binary, "11110"); break; // 30
						case GM_MIXED: concat(binary, "1111100"); break; // 124
						case GM_BYTE: concat(binary, "1111110"); break; // 126
					}
					break;
				case GM_MIXED:
					switch(next_mode) {
						case GM_CHINESE: concat(binary, "1111110001"); break; // 1009
						case GM_NUMBER: concat(binary, "1111110010"); break; // 1010
						case GM_LOWER: concat(binary, "1111110011"); break; // 1011
						case GM_UPPER: concat(binary, "1111110100"); break; // 1012
						case GM_BYTE: concat(binary, "1111110111"); break; // 1015
					}
					break;
				case GM_BYTE:
					/* add byte block length indicator */
					add_byte_count(binary, byte_count_posn, byte_count);
					byte_count = 0;
					switch(next_mode) {
						case GM_CHINESE: concat(binary, "0001"); break; // 1
						case GM_NUMBER: concat(binary, "0010"); break; // 2
						case GM_LOWER: concat(binary, "0011"); break; // 3
						case GM_UPPER: concat(binary, "0100"); break; // 4
						case GM_MIXED: concat(binary, "0101"); break; // 5
					}
					break;
			}
			if(debug) {
				switch(next_mode) {
					case GM_CHINESE: printf("CHIN "); break;
					case GM_NUMBER: printf("NUMB "); break;
					case GM_LOWER: printf("LOWR "); break;
					case GM_UPPER: printf("UPPR "); break;
					case GM_MIXED: printf("MIXD "); break;
					case GM_BYTE: printf("BYTE "); break;
				}
			}
		}
		last_mode = current_mode;
		current_mode = next_mode;
		
		switch(current_mode) {
			case GM_CHINESE: 
				done = 0;
				if(gbdata[sp] > 0xff) {
					/* GB2312 character */
					c1 = (gbdata[sp] & 0xff00) >> 8;
					c2 = gbdata[sp] & 0xff;
					
					if((c1 >= 0xa0) && (c1 <= 0xa9)) {
						glyph = (0x60 * (c1 - 0xa1)) + (c2 - 0xa0);
					}
					if((c1 >= 0xb0) && (c1 <= 0xf7)) {
						glyph = (0x60 * (c1 - 0xb0 + 9)) + (c2  - 0xa0);
					}
					done = 1;
				}
				if(!(done)) {
					if(sp != (length - 1)) {
						if((gbdata[sp] == 0x13) && (gbdata[sp + 1] == 0x10)) {
							/* End of Line */
							glyph = 7776;
							sp++;
						}
						done = 1;
					}
				}
				if(!(done)) {
					if(sp != (length - 1)) {
						if(((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) &&
							((gbdata[sp + 1] >= '0') && (gbdata[sp + 1] <= '9'))) {
							/* Two digits */
							glyph = 8033 + (10 * (gbdata[sp] - '0')) + (gbdata[sp + 1] - '0');
							sp++;
						}
					}
				}
				if(!(done)) {
					/* Byte value */
					glyph = 7777 + gbdata[sp];
				}
				
				if(debug) { printf("[%d] ", glyph); }
				
				if(glyph & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
				sp++;
				break;
				
			case GM_NUMBER:
				if(last_mode != current_mode) {
					/* Reserve a space for numeric digit padding value (2 bits) */
					number_pad_posn = strlen(binary);
					concat(binary, "XX");
				}
				p = 0;
				ppos = -1;
				
				/* Numeric compression can also include certain combinations of
				   non-numeric character */
				
				numbuf[0] = '0';
				numbuf[1] = '0';
				numbuf[2] = '0';
				do {
					if((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) {
						numbuf[p] = gbdata[sp];
						sp++;
						p++;
					}
					switch(gbdata[sp]) {
						case ' ':
						case '+':
						case '-':
						case '.':
						case ',':
							punt = gbdata[sp];
							sp++;
							ppos = p;
							break;
					}
					if(sp < (length - 1)) {
						if((gbdata[sp] == 0x13) && (gbdata[sp + 1] == 0x10)) {
							/* <end of line> */
							punt = gbdata[sp];
							sp += 2;
							ppos = p;
						}
					}
				} while ((p < 3) && (sp < length));
				
				if(ppos != -1) {
					switch(punt) {
						case ' ': glyph = 0; break;
						case '+': glyph = 3; break;
						case '-': glyph = 6; break;
						case '.': glyph = 9; break;
						case ',': glyph = 12; break;
						case 0x13: glyph = 15; break;
					}
					glyph += ppos;
					glyph += 1000;
					
					if(debug) { printf("[%d] ", glyph); }
					
					if(glyph & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
				}
				
				glyph = (100 * (numbuf[0] - '0')) + (10 * (numbuf[1] - '0')) + (numbuf[2] - '0');
				if(debug) { printf("[%d] ", glyph); }
				
				if(glyph & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
				break;
				
			case GM_BYTE:
				if(last_mode != current_mode) {
					/* Reserve space for byte block length indicator (9 bits) */
					byte_count_posn = strlen(binary);
					concat(binary, "LLLLLLLLL");
				}
				if(byte_count == 512) {
					/* Maximum byte block size is 512 bytes. If longer is needed then start a new block */
					add_byte_count(binary, byte_count_posn, byte_count);
					concat(binary, "0111");
					byte_count_posn = strlen(binary);
					concat(binary, "LLLLLLLLL");
					byte_count = 0;
				}
				
				glyph = gbdata[sp];
				if(debug) { printf("[%d] ", glyph); }
				if(glyph & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
				if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
				sp++;
				byte_count++;
				break;
				
			case GM_MIXED:
				shift = 1;
				if((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) { shift = 0; }
				if((gbdata[sp] >= 'A') && (gbdata[sp] <= 'Z')) { shift = 0; }
				if((gbdata[sp] >= 'a') && (gbdata[sp] <= 'z')) { shift = 0; }
				if(gbdata[sp] == ' ') { shift = 0; }
				
				if(shift == 0) {
					/* Mixed Mode character */
					glyph = posn(EUROPIUM, gbdata[sp]);
					if(debug) { printf("[%d] ", glyph); }
					
					if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
				} else {
					/* Shift Mode character */
					concat(binary, "1111110110"); /* 1014 - shift indicator */
					add_shift_char(binary, gbdata[sp]);
				}
				
				sp++;
				break;
				
			case GM_UPPER:
				shift = 1;
				if((gbdata[sp] >= 'A') && (gbdata[sp] <= 'Z')) { shift = 0; }
				if(gbdata[sp] == ' ') { shift = 0; }
				
				if(shift == 0) {
					/* Upper Case character */
					glyph = posn("ABCDEFGHIJKLMNOPQRSTUVWXYZ ", gbdata[sp]);
					if(debug) { printf("[%d] ", glyph); }
					
					if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
				} else {
					/* Shift Mode character */
					concat(binary, "1111101"); /* 127 - shift indicator */
					add_shift_char(binary, gbdata[sp]);
				}
				
				sp++;
				break;
				
			case GM_LOWER: 
				shift = 1;
				if((gbdata[sp] >= 'a') && (gbdata[sp] <= 'z')) { shift = 0; }
				if(gbdata[sp] == ' ') { shift = 0; }
				
				if(shift == 0) {
					/* Lower Case character */
					glyph = posn("abcdefghijklmnopqrstuvwxyz ", gbdata[sp]);
					if(debug) { printf("[%d] ", glyph); }
					
					if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
					if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
				} else {
					/* Shift Mode character */
					concat(binary, "1111101"); /* 127 - shift indicator */
					add_shift_char(binary, gbdata[sp]);
				}
				
				sp++;
				break;
		}
		if(strlen(binary) > 9191) {
			return ERROR_TOO_LONG;
		}
		
	} while(sp < length);
Exemple #8
0
 //Function to erase the given value if it is in the list
 inline void erase(const int val)
 {
   int position = posn(val);
   if( elements[position] == val )
     elements.erase(elements.begin() + position );
 }
Exemple #9
0
int japan_post(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Japanese Postal Code (Kasutama Barcode) */
	int error_number, h;
	char pattern[69];
	int writer, loopey, inter_posn, i, sum, check;
	char check_char;
	char inter[23];

#ifndef _MSC_VER
        char local_source[length + 1];
#else
        char* local_source = (char*)_alloca(length + 1);
#endif
	
	inter_posn = 0;
	error_number = 0;

	strcpy(local_source, (char*)source);
	for(i = 0; i < length; i++) {
		local_source[i] = source[i];
	}
	to_upper((unsigned char*)local_source);
	error_number = is_sane(SHKASUTSET, (unsigned char*)local_source, length);

	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	memset(inter, 'd', 20);/* Pad character CC4 */
	inter[20] = '\0';

	i = 0;
	inter_posn = 0;
	do {
		if(((local_source[i] >= '0') && (local_source[i] <= '9')) || (local_source[i] == '-')) {
			inter[inter_posn] = local_source[i];
			inter_posn++;
		} else {
			if((local_source[i] >= 'A') && (local_source[i] <= 'J')) {
				inter[inter_posn] = 'a';
				inter[inter_posn + 1] = local_source[i] - 'A' + '0';
				inter_posn += 2;
			}
			if((local_source[i] >= 'K') && (local_source[i] <= 'T')) {
				inter[inter_posn] = 'b';
				inter[inter_posn + 1] = local_source[i] - 'K' + '0';
				inter_posn += 2;
			}
			if((local_source[i] >= 'U') && (local_source[i] <= 'Z')) {
				inter[inter_posn] = 'c';
				inter[inter_posn + 1] = local_source[i] - 'U' + '0';
				inter_posn += 2;
			}
		}
		i++;
	}while((i < length) && (inter_posn < 20));
	inter[20] = '\0';

	strcpy(pattern, "13"); /* Start */

	sum = 0;
	for(i = 0; i < 20; i++) {
		concat(pattern, JapanTable[posn(KASUTSET, inter[i])]);
		sum += posn(CHKASUTSET, inter[i]);
		/* printf("%c (%d)\n", inter[i], posn(CHKASUTSET, inter[i])); */
	}

	/* Calculate check digit */
	check = 19 - (sum % 19);
	if(check == 19) { check = 0; }
	if(check <= 9) { check_char = check + '0'; }
	if(check == 10) { check_char = '-'; }
	if(check >= 11) { check_char = (check - 11) + 'a'; }
	concat(pattern, JapanTable[posn(KASUTSET, check_char)]);
	/* printf("check %c (%d)\n", check_char, check); */

	concat(pattern, "31"); /* Stop */

	/* Resolve pattern to 4-state symbols */
	writer = 0;
	h = strlen(pattern);
	for(loopey = 0; loopey < h; loopey++)
	{
		if((pattern[loopey] == '2') || (pattern[loopey] == '1'))
		{
			set_module(symbol, 0, writer);
		}
		set_module(symbol, 1, writer);
		if((pattern[loopey] == '3') || (pattern[loopey] == '1'))
		{
			set_module(symbol, 2, writer);
		}
		writer += 2;
	}

	symbol->row_height[0] = 3;
	symbol->row_height[1] = 2;
	symbol->row_height[2] = 3;
	symbol->rows = 3;
	symbol->width = writer - 1;

	return error_number;
}
Exemple #10
0
Graph * 
geo(long seed, geo_parms *pp)
{
double p,d,L,radius,r;
u_char *occ;
register int scale;
unsigned nbytes, index, x, y;
u_long units,pertrange;
int mallocd;
register i,j;
Graph *G;
Vertex *up,*vp;
char namestr[128];

    gb_trouble_code = 0;

    if (seed)			/* zero seed means "already init'd */
	gb_init_rand(seed);

    scale = pp->scale;

    L = sqrt(2.0) * scale;

    gb_trouble_code = 0;
    if ((pp->alpha <= 0.0) || (pp->alpha > 1.0)) gb_trouble_code=bad_specs+1;
    if (pp->gamma < 0.0) 		gb_trouble_code=bad_specs+GEO_TRBL;
    if (pp->beta < 0.0)			gb_trouble_code=bad_specs+GEO_TRBL;
    if (pp->n > (scale * scale))	gb_trouble_code=bad_specs+GEO_TRBL;
    if (gb_trouble_code)
	return NULL;

    radius = pp->gamma * L;	/* comes in as a fraction of diagonal */

#define posn(x,y)	((x)*scale)+(y)
#define bitset(v,i)	(v[(i)/NBBY]&(1<<((i)%NBBY)))
#define setbit(v,i)	v[(i)/NBBY] |= (1<<((i)%NBBY))

/* create a new graph structure */
   
    if ((G=gb_new_graph(pp->n)) == NULL)
	return NULL;

    nbytes = ((scale*scale)%NBBY ? (scale*scale/NBBY)+1 : (scale*scale)/NBBY);

    if (nbytes < STACKMAX) {	/* small amount - just do it in the stack */
        occ = (u_char *) alloca(nbytes);
        mallocd = 0;
    } else {
        occ = (u_char *) malloc(nbytes);
        mallocd = 1;
    }

    for (i=0; i<nbytes; i++) occ[i] = 0;


/* place each of n points in the plane */

    for (i=0,vp = G->vertices; i<pp->n; i++,vp++) {
	sprintf(namestr,"%d",i);	/* name is just node number */
	vp->name = gb_save_string(namestr);
        do {
            vp->xpos = gb_next_rand()%scale;         /* position: 0..scale-1 */
            vp->ypos = gb_next_rand()%scale;         /* position: 0..scale-1 */
	    index = posn(vp->xpos,vp->ypos);
        } while (bitset(occ,index));
        setbit(occ,index);
    }

/* Now go back and add the edges */
	
    for (i=0,up = G->vertices; i<(pp->n)-1; i++,up++)
	for (j=i+1, vp = &G->vertices[i+1]; j<pp->n; j++,vp++) { 
	    d = distance(up,vp);
            switch (pp->method) {
	    case RG2:		/* Waxman's */
		d = randfrac()*L;
		/* fall through */
            case RG1:		/* Waxman's */
		p = pp->alpha * exp(-d/(L*pp->beta));
		break;
	    case RANDOM:	/* the classic */
		p = pp->alpha;
		break;
	    case EXP:	
		p = pp->alpha * exp(-d/(L-d));
		break;
            case DL:		/* Doar-Leslie */
		p = pp->alpha * (pp->gamma/pp->n) * exp(-d/(L*pp->beta));
		break;
	    case LOC:		/* Locality model, two probabilities */
		if (d <= radius) p = pp->alpha;
		else p = pp->beta;	
		break;
	    default:
		die("Bad edge method in geo()!");
	    }
	    if (randfrac() < p) 
		gb_new_edge(up,vp,(int)rint(d));
		
	}

/* Fill in the "id" string to say how the graph was created */

    G->Gscale = scale;
    sprintf(G->id,"geo(%ld,", seed);
    i = strlen(G->id);
    i += printparms(G->id+i,pp);
    G->id[i] = ')';
    G->id[i+1] = (char) 0;
    strcpy(G->util_types,GEO_UTIL);

/* clean up */
    if (mallocd) free(occ);

    return G;
}