Ejemplo n.º 1
0
int
any2eucjp (unsigned char *dest, unsigned char *src, unsigned int dest_max)
{
  static unsigned char tmp_dest[BUFSIZ];
  int ret;

  if (strlen ((const char *) src) >= BUFSIZ)
    {
      error ("input string too large");
      return -1;
    }
  if (dest_max > BUFSIZ)
    {
      error
	("invalid maximum size of destination\nit should be less than %d.",
	 BUFSIZ);
      return -1;
    }
  ret = do_check_and_conv (tmp_dest, src);
  if (strlen ((const char *) tmp_dest) >= dest_max)
    {
      error ("output buffer overflow");
      ustrcpy (dest, src);
      return -1;
    }
  ustrcpy (dest, tmp_dest);
  return ret;
}
Ejemplo n.º 2
0
Archivo: 2of5.c Proyecto: ahippo/zint
int interleaved_two_of_five(struct zint_symbol *symbol, uint8_t source[], int length)
{ /* Code 2 of 5 Interleaved */

	int error_number;
	char bars[7], spaces[7], mixed[14], dest[1000];
	uint8_t temp[length + 2];

	error_number = 0;

	if(length > 89) {
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if (error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	ustrcpy(temp, (uint8_t *) "");
	/* Input must be an even number of characters for Interlaced 2 of 5 to work:
	   if an odd number of characters has been entered then add a leading zero */
	if (length & 1) {
		ustrcpy(temp, (uint8_t *) "0");
		length++;
	}
	uconcat(temp, source);

	/* start character */
	strcpy(dest, "1111");

	for(int i = 0; i < length; i+=2) {
		/* look up the bars and the spaces and put them in two strings */
		strcpy(bars, "");
		lookup(NEON, C25InterTable, temp[i], bars);
		strcpy(spaces, "");
		lookup(NEON, C25InterTable, temp[i + 1], spaces);

		/* then merge (interlace) the strings together */
		int k = 0;
		for(int j = 0; j <= 4; j++)
		{
			mixed[k] = bars[j]; k++;
			mixed[k] = spaces[j]; k++;
		}
		mixed[k] = '\0';
		concat (dest, mixed);
	}

	/* Stop character */
	concat (dest, "311");

	expand(symbol, dest);
	ustrcpy(symbol->text, temp);
	return error_number;

}
Ejemplo n.º 3
0
EOF_TEXT_EVENT * eof_song_add_text_event(EOF_SONG * sp, unsigned long beat, char * text, unsigned long track, unsigned long flags, char is_temporary)
{
// 	eof_log("eof_song_add_text_event() entered");

	if(sp && text && (sp->text_events < EOF_MAX_TEXT_EVENTS) && (beat < sp->beats))
	{	//If the maximum number of text events hasn't already been defined, and the specified beat number is valid
		sp->text_event[sp->text_events] = malloc(sizeof(EOF_TEXT_EVENT));
		if(sp->text_event[sp->text_events])
		{
			sp->text_event[sp->text_events]->text[0] = '\0';	//Eliminate false positive in Splint
			(void) ustrcpy(sp->text_event[sp->text_events]->text, text);
			sp->text_event[sp->text_events]->beat = beat;
			if(track >= sp->tracks)
			{	//If this is an invalid track
				track = 0;	//Make this a global text event
			}
			sp->text_event[sp->text_events]->track = track;
			sp->text_event[sp->text_events]->flags = flags;
			sp->text_event[sp->text_events]->is_temporary = is_temporary;
			sp->beat[beat]->flags |= EOF_BEAT_FLAG_EVENTS;	//Set the events flag for the beat
			sp->text_event[sp->text_events]->index = 0;
			sp->text_events++;
			return sp->text_event[sp->text_events-1];	//Return successfully created text event
		}
	}
	return NULL;	//Return failure
}
Ejemplo n.º 4
0
int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Code 2 of 5 Industrial */

	int i, error_number;
	char dest[512]; /* 6 + 40 * 10 + 6 + 1 */

	error_number = 0;

	if(length > 45) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid character in data");
		return error_number;
	}

	/* start character */
	strcpy(dest, "313111");

	for(i = 0; i < length; i++) {
		lookup(NEON, C25IndustTable, source[i], dest);
	}

	/* Stop character */
	concat (dest, "31113");

	expand(symbol, dest);
	ustrcpy(symbol->text, source);
	return error_number;
}
Ejemplo n.º 5
0
void eof_controller_read_button_names(EOF_CONTROLLER * cp)
{
	int i;

	eof_log("eof_controller_read_button_names() entered", 1);

	if(!cp)
	{
		return;
	}
	for(i = 0; i < EOF_CONTROLLER_MAX_BUTTONS; i++)
	{
		switch(cp->button[i].type)
		{
			case EOF_CONTROLLER_BUTTON_TYPE_KEY:
			{
				(void) ustrcpy(cp->button[i].name, scancode_to_name(cp->button[i].key));
				break;
			}
			case EOF_CONTROLLER_BUTTON_TYPE_JOYBUTTON:
			{
				(void) snprintf(cp->button[i].name, sizeof(cp->button[i].name) - 1, "Joy %d %s", cp->button[i].joy, joy[cp->button[i].joy].button[cp->button[i].key].name);
				break;
			}
			case EOF_CONTROLLER_BUTTON_TYPE_JOYAXIS:
			{
				(void) snprintf(cp->button[i].name, sizeof(cp->button[i].name) - 1, "Joy %d %s Axis (%s)", cp->button[i].joy, joy[cp->button[i].joy].stick[cp->button[i].index].axis[cp->button[i].key].name, cp->button[i].d == 0 ? "-" : "+");
				break;
			}
		}
	}
}
Ejemplo n.º 6
0
/*
 * Add a string structure to the symbol.
 * Coordinates assumed to be from top-center.
 */
int render_plot_add_string(struct zint_symbol *symbol,
		unsigned char *text, float x, float y, float fsize, float width,
		struct zint_render_string **last_string)
{
	struct zint_render_string *string;

#ifndef _MSC_VER
	string = malloc(sizeof(struct zint_render_string));
#else
	string = (struct zint_render_string *)_alloca(sizeof(struct zint_render_string));
#endif
	string->next = NULL;
	string->x = x;
	string->y = y;
	string->width = width; 
	string->fsize = fsize;
	string->length = ustrlen(text);
#ifndef _MSC_VER
	string->text = malloc(sizeof(unsigned char) * (ustrlen(text) + 1));
#else
	string->text = (unsigned char *)_alloca((ustrlen(text) + 1) * sizeof(unsigned char));
#endif
	ustrcpy(string->text, text);

	if (*last_string)
		(*last_string)->next = string;
	else
		symbol->rendered->strings = string; // First character
	*last_string = string;

	return 1;
}
Ejemplo n.º 7
0
Archivo: 2of5.c Proyecto: ahippo/zint
int logic_two_of_five(struct zint_symbol *symbol, uint8_t source[], int length)
{ /* Code 2 of 5 Data Logic */

	int error_number;
	char dest[512]; /* 4 + 80 * 6 + 3 + 1 */

	error_number = 0;

	if(length > 80) {
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	/* start character */
	strcpy(dest, "1111");

	for(int i = 0; i < length; i++) {
		lookup(NEON, C25MatrixTable, source[i], dest);
	}

	/* Stop character */
	concat (dest, "311");

	expand(symbol, dest);
	ustrcpy(symbol->text, source);
	return error_number;
}
Ejemplo n.º 8
0
void Accelerator::addKeysFromString(const char* string)
{
  char *s, *begin, buf[256];
  int backup;

  ustrcpy(buf, string);

  for (s=buf; *s; ) {
    if (*s == '<') {
      begin = ++s;

      while ((*s) && (*s != '>')) s++;

      backup = *s;
      *s = 0;

      process_one_word(this, begin);

      *s = backup;
    }
    else {
      s++;
    }
  }
}
Ejemplo n.º 9
0
int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
	
	int i, error_number;
	char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/

	error_number = 0;

	if(length > 80) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	/* start character */
	strcpy(dest, "411111");

	for(i = 0; i < length; i++) {
		lookup(NEON, C25MatrixTable, source[i], dest);
	}

	/* Stop character */
	concat (dest, "41111");

	expand(symbol, dest);
	ustrcpy(symbol->text, source);
	return error_number;
}
Ejemplo n.º 10
0
void XlateTableWriteBase::DoItem(XlateEntryData *p, unsigned lvl){
	RecString tmp;
	tmp.lv = lvl;
	tmp.ch = p->c;
	tmp.ln = p->l + 1; /* "+ 1" is in MAKEBASE j.b. */
	ustrcpy(tmp.sq, p->s);
	WriteData((void *)&tmp, 4+ustrlen(tmp.sq));  //4 = 3 char data, + 0 for sq term
};
Ejemplo n.º 11
0
void XlateTable::AddIfAbsent(UNCH cin, UNCH * cout){
	XlateTableRec *xp2 = md[0];
	if (xp2->dat[cin] == 0) xp2->dat[cin] = new XlateEntryData(cin);
	XlateEntryData *p = xp2->dat[cin];
	if (p->s[0] != '\0') return;
	ustrcpy(p->s, cout);
	p->l = ustrlen(cout);
	p->m = '0';
}
Ejemplo n.º 12
0
int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) {
	/* Channel Code - According to ANSI/AIM BC12-1998 */
	
	int channels, i;
	int error_number = 0, range = 0, zeroes;
	char hrt[9];

	target_value = 0;
	
	if(length > 7) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	
	if((symbol->option_2 < 3) || (symbol->option_2 > 8)) { channels = 0; } else { channels = symbol->option_2; }
	if(channels == 0) { channels = length + 1; }
	if(channels == 2) { channels = 3; }
	
	for(i = 0; i < length; i++) {
		target_value *= 10;
		target_value += ctoi((char) source[i]);
	}
	
	switch(channels) {
		case 3: if(target_value > 26) { range = 1; } break;
		case 4: if(target_value > 292) { range = 1; } break;
		case 5: if(target_value > 3493) { range = 1; } break;
		case 6: if(target_value > 44072) { range = 1; } break;
		case 7: if(target_value > 576688) { range = 1; } break;
		case 8: if(target_value > 7742862) { range = 1; } break;
	}
	if(range) {
		strcpy(symbol->errtxt, "Value out of range");
        return ERROR_INVALID_DATA1;
	}
	
	for(i = 0; i < 11; i++) { B[i] = 0; S[i] = 0; }
	
	B[0] = S[1] = B[1] = S[2] = B[2] = 1;
	value = 0;
	NextS(channels,3,channels,channels);
	
	zeroes = channels - 1 - length;
	memset(hrt, '0', zeroes);
	strcpy(hrt + zeroes, (char *)source);
	ustrcpy(symbol->text, (unsigned char *)hrt);
	
	expand(symbol, pattern);
	
	return error_number;
}
Ejemplo n.º 13
0
void upca(struct zint_symbol *symbol, unsigned char source[], char dest[])
{ /* Make a UPC A barcode when we haven't been given the check digit */
	int length;
	char gtin[15];

	strcpy(gtin, (char*)source);
	length = strlen(gtin);
	gtin[length] = upc_check(gtin);
	gtin[length + 1] = '\0';
	upca_draw(gtin, dest);
	ustrcpy(symbol->text, (unsigned char*)gtin);
}
Ejemplo n.º 14
0
void ean8(struct zint_symbol *symbol, unsigned char source[], char dest[])
{ /* Make an EAN-8 barcode when we haven't been given the check digit */
  /* EAN-8 is basically the same as UPC-A but with fewer digits */
	int length;
	char gtin[10];

	strcpy(gtin, (char*)source);
	length = strlen(gtin);
	gtin[length] = upc_check(gtin);
	gtin[length + 1] = '\0';
	upca_draw(gtin, dest);
	ustrcpy(symbol->text, (unsigned char*)gtin);
}
Ejemplo n.º 15
0
int ustrcat(wchar *dest, char *src)
{
	int dest_len, src_len;
	wchar *uni;

	dest_len=ustrlen(dest);
	src_len=(int)strlen(src);

	uni=new wchar[src_len+1];
	ustrcpy(uni,src);
	ustrcat(dest,uni);
	delete[] uni;
	return dest_len+src_len;
}
Ejemplo n.º 16
0
UNCH LookupIntName(UNCH * n){
	int u = NumberChars - 1,i,l = 0,c;
	if (!n[0]) return '\0';
	UNCH n1[50];
	ustrcpy(n1,n);
	capstr(n1+1);
	do {
		if (u < l) return '\0';
		i = (l+u)/2;
		c = ustrcmp(n1,SortedCharNames[i].cname);
		if (c < 0) u = i-1; else l = i+1;}
	while (c != 0);
	return SortedCharNames[i].codept;
}
Ejemplo n.º 17
0
BOOLEAN XlateTable::InsertXlateMode(UNCH mdin, UNCH mdout,
												UNCH * seqin,
												DupHanType DupWhat,
												ostream & s){
	XlateTableRec* trc = FindMode(mdin);
	XlateEntryData* p = trc->InsertEntry(seqin);
	if ((p->s[0] == '\0') || (DupWhat == UpdateEntry)) {
		p->t = MODE;
		ustrcpy(p->s, seqin);
		p->m = mdout;}
	else if (((p->t == MODE)||(p->s[0] != '\0')) && (DupWhat == GiveError)) {
		ResFile->ResMessage(CONFLICTMSGRESOURCE, s);
		return FALSE;
		}
	return TRUE;
}
Ejemplo n.º 18
0
int ugs1_verify(struct zint_symbol *symbol, uint8_t source[], const unsigned int src_len, uint8_t reduced[])
{
	/* Only to keep the compiler happy */
	char temp[src_len + 5];
	int error_number;

	error_number = gs1_verify(symbol, source, src_len, temp);
	if(error_number != 0) { return error_number; }

	if (strlen(temp) < src_len + 5) {
		ustrcpy(reduced, (uint8_t*)temp);
		return 0;
	}
	strcpy(symbol->errtxt, "ugs1_verify overflow");
	return ZERROR_INVALID_DATA;
}
Ejemplo n.º 19
0
void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[])
{
	unsigned int length, i, half_way;
	char parity[6];
	char gtin[15];

	strcpy(parity, "");
	strcpy(gtin, (char*)source);
	
	/* Add the appropriate check digit */
	length = strlen(gtin);
	gtin[length] = ean_check(gtin);
	gtin[length + 1] = '\0';

	/* Get parity for first half of the symbol */
	lookup(SODIUM, EAN13Parity, gtin[0], parity);

	/* Now get on with the cipher */
	half_way = 7;

	/* start character */
	concat (dest, "111");
	length = strlen(gtin);
	for(i = 1; i <= length; i++)
	{
		if (i == half_way)
		{
			/* middle character - separates manufacturer no. from product no. */
			/* also inverses right hand characters */
			concat (dest, "11111");
		}

		if(((i > 1) && (i < 7)) && (parity[i - 2] == 'B'))
		{
			lookup(NEON, EANsetB, gtin[i], dest);
		}
		else
		{
			lookup(NEON, EANsetA, gtin[i], dest);
		}
	}

	/* stop character */
	concat (dest, "111");
	
	ustrcpy(symbol->text, (unsigned char*)gtin);
}
Ejemplo n.º 20
0
static uint8_t m2i_delete(path_t *path, cbmdirent_t *dent) {
  uint16_t offset;

  offset = dent->pvt.m2i.offset;// find_entry
  if (load_entry(path->part, offset))
    return 255;

  /* Ignore the result, we'll have to delete the entry anyway */
  ustrcpy(dent->name, ops_scratch + M2I_FATNAME_OFFSET);
  fat_delete(path, dent);

  ops_scratch[0] = '-';
  if (image_write(path->part, offset, ops_scratch, 1, 1))
    return 0;
  else
    return 1;
}
Ejemplo n.º 21
0
void Widget::setTextf(const char *format, ...)
{
  char buf[4096];

  // formatted string
  if (format) {
    va_list ap;
    va_start(ap, format);
    vsprintf(buf, format, ap);
    va_end(ap);
  }
  // empty string
  else {
    ustrcpy(buf, empty_string);
  }

  setText(buf);
}
Ejemplo n.º 22
0
/**
 * open_existing - open an existing file
 * @path      : path handle
 * @dent      : pointer to cbmdirent struct with name of the file
 * @type      : type of the file (not checked)
 * @buf       : buffer to be used
 * @appendflag: Flags if the file should be opened for appending
 *
 * This function searches the file name in an M2I file and opens it
 * either in read or append mode according to appendflag by calling
 * the appropiate fat_* functions.
 */
static void open_existing(path_t *path, cbmdirent_t *dent, uint8_t type, buffer_t *buf, uint8_t appendflag) {
  if (load_entry(path->part, dent->pvt.m2i.offset)) {
    set_error(ERROR_FILE_NOT_FOUND);
    return;
  }

  if (parsetype()) {
    set_error(ERROR_FILE_NOT_FOUND);
    return;
  }

  ustrcpy(dent->pvt.fat.realname, ops_scratch + M2I_FATNAME_OFFSET);

  if (appendflag)
    fat_open_write(path, dent, type, buf, 1);
  else
    fat_open_read(path, dent, buf);
}
Ejemplo n.º 23
0
Archivo: 2of5.c Proyecto: ahippo/zint
int itf14(struct zint_symbol *symbol, uint8_t source[], int length)
{
	int error_number, zeroes;
	unsigned int count;
	char localstr[16];

	error_number = 0;

	count = 0;

	if(length > 13) {
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}

	error_number = is_sane(NEON, source, length);
	if(error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid character in data");
		return error_number;
	}

	/* Add leading zeros as required */
	zeroes = 13 - length;
	for(int i = 0; i < zeroes; i++) {
		localstr[i] = '0';
	}
	strcpy(localstr + zeroes, (char *)source);

	/* Calculate the check digit - the same method used for EAN-13 */

	for (int i = 12; i >= 0; i--) {
		count += ctoi(localstr[i]);

		if (!(i & 1)) {
			count += 2 * ctoi(localstr[i]);
		}
	}

	localstr[13] = check_digit(count);
	localstr[14] = '\0';
	error_number = interleaved_two_of_five(symbol, (uint8_t *)localstr, strlen(localstr));
	ustrcpy(symbol->text, (uint8_t*)localstr);
	return error_number;
}
Ejemplo n.º 24
0
int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Pharmazentral Nummer (PZN) */
	
	int i, error_number, zeroes;
	unsigned int count, check_digit;
	char localstr[10];
	
	error_number = 0;

	count = 0;
	if(length > 6) {
		strcpy(symbol->errtxt, "Input wrong length");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	
	localstr[0] = '-';
	zeroes = 6 - length + 1;
	for(i = 1; i < zeroes; i++)
		localstr[i] = '0';
	strcpy(localstr + zeroes, (char *)source);
	
	for (i = 1; i < 7; i++) {
		count += (i + 1) * ctoi(localstr[i]);
	}
	
	check_digit = count%11;
	if (check_digit == 11) { check_digit = 0; }
	localstr[7] = itoc(check_digit);
	localstr[8] = '\0';
	if(localstr[7] == 'A') { 
		strcpy(symbol->errtxt, "Invalid PZN Data");
        return ERROR_INVALID_DATA1;
	}
	error_number = c39(symbol, (unsigned char *)localstr, strlen(localstr));
	ustrcpy(symbol->text, (unsigned char *)"PZN");
	uconcat(symbol->text, (unsigned char *)localstr);
	return error_number;
}
Ejemplo n.º 25
0
int codabar(struct zint_symbol *symbol, unsigned char source[], int length)
{   /* The Codabar system consisting of simple substitution */

    int i, error_number;
    char dest[512];

    error_number = 0;
    strcpy(dest, "");

    if(length > 60) { /* No stack smashing please */
        strcpy(symbol->errtxt, "Input too long");
        return ERROR_TOO_LONG;
    }
    to_upper(source);
    error_number = is_sane(CALCIUM, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return error_number;
    }
    /* Codabar must begin and end with the characters A, B, C or D */
    if((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C') && (source[0] != 'D'))
    {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return ERROR_INVALID_DATA1;
    }

    if((source[length - 1] != 'A') && (source[length - 1] != 'B') &&
            (source[length - 1] != 'C') && (source[length - 1] != 'D'))
    {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return ERROR_INVALID_DATA1;
    }

    for(i = 0; i < length; i++)
    {
        lookup(CALCIUM, CodaTable, source[i], dest);
    }

    expand(symbol, dest);
    ustrcpy(symbol->text, source);
    return error_number;
}
Ejemplo n.º 26
0
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[])
{
	/* Only to keep the compiler happy */
#ifndef _MSC_VER
	char temp[src_len + 5];
#else
        char* temp = (char*)_alloca(src_len + 5);
#endif
	int error_number;

	error_number = gs1_verify(symbol, source, src_len, temp);
	if(error_number != 0) { return error_number; }

	if (strlen(temp) < src_len + 5) {
		ustrcpy(reduced, (unsigned char*)temp);
		return 0;
	}
	strcpy(symbol->errtxt, "ugs1_verify overflow");
	return ERROR_INVALID_DATA;
}
Ejemplo n.º 27
0
TileType::TileType(BITMAP *tileBitmap, const char *tileName)
{
	bitmap = tileBitmap;
	name = (char*)malloc(ustrsizez(tileName));
	ustrcpy(name, tileName);
	int x, y;
	unsigned long r = 0, g = 0, b = 0;
	unsigned long pixels = tileBitmap->w * tileBitmap->h;

	// Calculate average color
	for (x = 0; x < tileBitmap->w; x++) {
		for (y = 0; y < tileBitmap->h; y++) {
			int c = getpixel(tileBitmap, x, y);
			r += getr(c);
			g += getg(c);
			b += getb(c);
		}
	}

	color = makecol(r / pixels, g / pixels, b / pixels);
}
Ejemplo n.º 28
0
int ean_14(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* EAN-14 - A version of EAN-128 */
	int i, count, check_digit;
	int error_number, zeroes;
	unsigned char ean128_equiv[20];

	if(length > 13) {
		strcpy(symbol->errtxt, "Input wrong length");
		return ZINT_ERROR_TOO_LONG;
	}

	error_number = is_sane(NEON, source, length);
	if(error_number == ZINT_ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid character in data");
		return error_number;
	}

	zeroes = 13 - length;
	strcpy((char*)ean128_equiv, "[01]");
	memset(ean128_equiv + 4, '0', zeroes);
	ustrcpy(ean128_equiv + 4 + zeroes, source);

	count = 0;
	for (i = length - 1; i >= 0; i--) {
		count += ctoi(source[i]);

		if (!(i & 1)) {
			count += 2 * ctoi(source[i]);
		}
	}
	check_digit = 10 - (count % 10);
	if (check_digit == 10) { check_digit = 0; }
	ean128_equiv[17] = itoc(check_digit);
	ean128_equiv[18] = '\0';

	error_number = ean_128(symbol, ean128_equiv, ustrlen(ean128_equiv));

	return error_number;
}
Ejemplo n.º 29
0
int main(int argc, char *argv[])
{
    initialize();

    // Handle a map file passed as argument
    if (argc == 2 && exists(argv[1]))
    {
        PACKFILE *file = pack_fopen(argv[1], F_READ_PACKED);
        if (file) {
            currentMap->loadFrom(file, tileRepository);
            pack_fclose(file);
            ustrcpy(map_filename, argv[1]);
            update_window_title();
        } else {
            alert("Invalid map file:", argv[1], NULL, "OK", NULL, 13, 0);
        }
    }

    do_dialog(main_dlg, -1);
    clean_up();
    return 0;
}
Ejemplo n.º 30
0
Archivo: 2of5.c Proyecto: ahippo/zint
int dpleit(struct zint_symbol *symbol, uint8_t source[], int length)
{ /* Deutshe Post Leitcode */
	int error_number;
	unsigned int count;
	char localstr[16];
	int zeroes;

	error_number = 0;
	count = 0;
	if(length > 13) {
		strcpy(symbol->errtxt, "Input wrong length");
		return ZERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	zeroes = 13 - length;
	for(int i = 0; i < zeroes; i++)
		localstr[i] = '0';
	strcpy(localstr + zeroes, (char *)source);

	for (int i = 12; i >= 0; i--)
	{
		count += 4 * ctoi(localstr[i]);

		if (i & 1) {
			count += 5 * ctoi(localstr[i]);
		}
	}

	localstr[13] = check_digit(count);
	localstr[14] = '\0';
	error_number = interleaved_two_of_five(symbol, (uint8_t *)localstr, strlen(localstr));
	ustrcpy(symbol->text, (uint8_t*)localstr);
	return error_number;
}