Esempio n. 1
0
int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* Puts PLANET barcodes into the pattern matrix */
	char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 +  1 ~ 256 */
	unsigned int loopey, h;
	int writer;
	int error_number;

	error_number = 0;

	error_number = planet(symbol, source, height_pattern, length);
	if(error_number != 0) {
		return error_number;
	}

	writer = 0;
	h = strlen(height_pattern);
	for(loopey = 0; loopey < h; loopey++)
	{
		if(height_pattern[loopey] == 'L')
		{
			set_module(symbol, 0, writer);
		}
		set_module(symbol, 1, writer);
		writer += 3;
	}
	symbol->row_height[0] = 6;
	symbol->row_height[1] = 6;
	symbol->rows = 2;
	symbol->width = writer - 1;
	return error_number;
}
Esempio n. 2
0
int kix_code(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* Handles Dutch Post TNT KIX symbols */
	/* The same as RM4SCC but without check digit */
	/* Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */
	char height_pattern[50], localstr[20];
	unsigned int loopey;
	int writer, i, h;
	int error_number; /* zeroes; */
	strcpy(height_pattern, "");

	error_number = 0;

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

	/* Add leading zeroes */
	/* zeroes = 11 - length;
	memset(localstr, '0', zeroes);
	strcpy(localstr + zeroes, (char *)source);*/
	strcpy(localstr, (char *)source);

	/* Encode data */
	for (i = 0; i < 18; i++) {
		lookup(KRSET, RoyalTable, localstr[i], height_pattern);
	}

	writer = 0;
	h = strlen(height_pattern);
	for(loopey = 0; loopey < h; loopey++)
	{
		if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
		{
			set_module(symbol, 0, writer);
		}
		set_module(symbol, 1, writer);
		if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0'))
		{
			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;
}
Esempio n. 3
0
int daft_code(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* Handles DAFT Code symbols */
	/* Presumably 'daft' doesn't mean the same thing in Germany as it does in the UK! */
	char height_pattern[100];
	unsigned int loopey, h;
	int writer, i, error_number;
	strcpy(height_pattern, "");

	error_number = 0;
	if(length > 50) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	to_upper((unsigned char*)source);
	error_number = is_sane(DAFTSET, (unsigned char*)source, length);

	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	for (i = 0; i < length; i++) {
		if(source[i] == 'D') { concat(height_pattern, "2"); }
		if(source[i] == 'A') { concat(height_pattern, "1"); }
		if(source[i] == 'F') { concat(height_pattern, "0"); }
		if(source[i] == 'T') { concat(height_pattern, "3"); }
	}

	writer = 0;
	h = strlen(height_pattern);
	for(loopey = 0; loopey < h; loopey++)
	{
		if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
		{
			set_module(symbol, 0, writer);
		}
		set_module(symbol, 1, writer);
		if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0'))
		{
			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;
}
Esempio n. 4
0
void horiz(struct zint_symbol *symbol, int row_no, int full)
{
	int i;
	
	if(full) {
		for(i = 0; i < symbol->width; i++) {
			set_module(symbol, row_no, i);
		}
	} else {
		for(i = 1; i < symbol->width - 1; i++) {
			set_module(symbol, row_no, i);
		}
	}
}
Esempio n. 5
0
void vert(struct zint_symbol *symbol, int column, int height, int top)
{
	int i;
	
	if(top) {
		for (i = 0; i < height; i++) {
			set_module(symbol, i, column);
		}
	} else {
		for (i = 0; i < height; i++) {
			set_module(symbol, symbol->rows - i - 1, column);
		}
	}
}
Esempio n. 6
0
void central_finder(struct zint_symbol *symbol, int start_row, int row_count, int full_rows)
{
	int i;
	
	for(i = 0; i < row_count; i++) {
		if(i < full_rows) {
			horiz(symbol, start_row + (i * 2), 1);
		} else {
			horiz(symbol, start_row + (i * 2), 0);
			if(i != row_count - 1) {
				set_module(symbol, start_row + (i * 2) + 1, 1);
				set_module(symbol, start_row + (i * 2) + 1, symbol->width - 2);
			}
		}
	}
}
Esempio n. 7
0
void expand(struct zint_symbol *symbol, char data[])
{   /* Expands from a width pattern to a bit pattern */

    unsigned int reader, n = strlen(data);
    int writer;
    char latch;

    writer = 0;
    latch = '1';

    for(reader = 0; reader < n; reader++) {
        for(int i = 0; i < ctoi(data[reader]); i++) {
            if(latch == '1') {
                set_module(symbol, symbol->rows, writer);
            }
            writer++;
        }

        latch = (latch == '1' ? '0' : '1');
    }

    if(symbol->symbology != BARCODE_PHARMA) {
        if(writer > symbol->width) {
            symbol->width = writer;
        }
    } else {
        /* Pharmacode One ends with a space - adjust for this */
        if(writer > symbol->width + 2) {
            symbol->width = writer - 2;
        }
    }
    symbol->rows = symbol->rows + 1;
}
Esempio n. 8
0
int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* Puts RM4SCC into the data matrix */
	char height_pattern[200];
	unsigned int loopey, h;
	int writer;
	int error_number;
	strcpy(height_pattern, "");

	error_number = 0;

	if(length > 120) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	to_upper(source);
	error_number = is_sane(KRSET, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	/*check = */rm4scc((char*)source, (unsigned char*)height_pattern, length);
	
	writer = 0;
	h = strlen(height_pattern);
	for(loopey = 0; loopey < h; loopey++)
	{
		if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
		{
			set_module(symbol, 0, writer);
		}
		set_module(symbol, 1, writer);
		if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0'))
		{
			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;
}
Esempio n. 9
0
static int
VMS_get_member_info (struct dsc$descriptor_s *module, unsigned long *rfa)
{
  int status, i;
  long int fnval;

  time_t val;

  static struct dsc$descriptor_s bufdesc =
    { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL };

  struct mhddef *mhd;
  char filename[128];

  bufdesc.dsc$a_pointer = filename;
  bufdesc.dsc$w_length = sizeof (filename);

  status = lbr$set_module (&VMS_lib_idx, rfa, &bufdesc,
			   &bufdesc.dsc$w_length, 0);
  if (! (status & 1))
    {
      error (NILF, _("lbr$set_module failed to extract module info, status = %d"),
	     status);

      lbr$close (&VMS_lib_idx);

      return 0;
    }

  mhd = (struct mhddef *) filename;

#ifdef __DECC
  /* John Fowler <*****@*****.**> writes this is needed in his environment,
   * but that decc$fix_time() isn't documented to work this way.  Let me
   * know if this causes problems in other VMS environments.
   */
  val = decc$fix_time (&mhd->mhd$l_datim) + timezone - daylight*3600;
#endif

  for (i = 0; i < module->dsc$w_length; i++)
    filename[i] = _tolower ((unsigned char)module->dsc$a_pointer[i]);

  filename[i] = '\0';

  VMS_member_date = (time_t) -1;

  fnval =
    (*VMS_function) (-1, filename, 0, 0, 0, 0, val, 0, 0, 0,
		     VMS_saved_memname);

  if (fnval)
    {
      VMS_member_date = fnval;
      return 0;
    }
  else
    return 1;
}
Esempio n. 10
0
void spigot(struct zint_symbol *symbol, int row_no)
{
	int i;
	
	for(i = symbol->width - 1; i > 0; i--) {
		if(module_is_set(symbol, row_no, i - 1)) {
			set_module(symbol, row_no, i);
		}
	}
}
int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length)
{
    /* Draws the patterns for two track pharmacode */
    char height_pattern[200];
    unsigned int loopey, h;
    int writer;
    int error_number = 0;
    strcpy(height_pattern, "");

    if(length > 8) {
        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;
    }
    error_number = pharma_two_calc(symbol, source, height_pattern);
    if(error_number != 0) {
        return error_number;
    }

    writer = 0;
    h = strlen(height_pattern);
    for(loopey = 0; loopey < h; loopey++)
    {
        if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3'))
        {
            set_module(symbol, 0, writer);
        }
        if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '3'))
        {
            set_module(symbol, 1, writer);
        }
        writer += 2;
    }
    symbol->rows = 2;
    symbol->width = writer - 1;


    return error_number;
}
Esempio n. 12
0
void block_copy(struct zint_symbol *symbol, char grid[][120], int start_row, int start_col, int height, int width, int row_offset, int col_offset) {
	int i, j;
	
	for(i = start_row; i < (start_row + height); i++) {
		for(j = start_col; j < (start_col + width); j++) {
			if(grid[i][j] == '1') {
				set_module(symbol, i + row_offset, j + col_offset);
			}
		}
	}
}
Esempio n. 13
0
static int
file_archmember( 
    struct dsc$descriptor_s *module,
    unsigned long *rfa )
{
    static struct dsc$descriptor_s bufdsc =
		  {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL};

    struct mhddef *mhd;
    char filename[128];
    char buf[ MAXJPATH ];

    int status;
    time_t library_date;

    register int i;
    register char *p;

    bufdsc.dsc$a_pointer = filename;
    bufdsc.dsc$w_length = sizeof( filename );
    status = lbr$set_module( &context, rfa, &bufdsc,
			     &bufdsc.dsc$w_length, NULL );

    if ( !(status & 1) )
	return ( 1 );

    mhd = (struct mhddef *)filename;

    file_cvttime( &mhd->mhd$l_datim, &library_date );

    for ( i = 0, p = module->dsc$a_pointer; i < module->dsc$w_length; i++, p++ )
	filename[i] = *p;

    filename[i] = '\0';

    sprintf( buf, "%s(%s.obj)", VMS_archive, filename );

    (*VMS_func)( VMS_closure, buf, 1 /* time valid */, (time_t)library_date );

    return ( 1 );
}
Esempio n. 14
0
	void set_options(const wchar_t* url)
	{
		TraceFunc();
		auto urlCopy = cstr::dup(url);

		TraceFunc();
		URL_COMPONENTSW info;
		bool res = url::crack(urlCopy, &info);
		if (res && cstr::compare_ci(L"logger", info.lpszScheme, info.dwSchemeLength) == 0) {
			if (cstr::compare_ci(L"/default", info.lpszUrlPath, info.dwUrlPathLength) == 0) {
				set_defaults(info.lpszExtraInfo, info.dwExtraInfoLength);
			} else if (cstr::compare_ci(L"/global", info.lpszUrlPath, info.dwUrlPathLength) == 0) {
				set_globals(info.lpszExtraInfo, info.dwExtraInfoLength);
			} else if (cstr::compare_ci(L"/module", info.lpszUrlPath, info.dwUrlPathLength) == 0) {
				set_module(info.lpszExtraInfo, info.dwExtraInfoLength);
			}
		}

		HostFree(memory::heap::DefaultStat, urlCopy);
		TraceFunc();
	}
Esempio n. 15
0
int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Handle EAN-128 (Now known as GS1-128) */
	int i, j,values[170], bar_characters, read, total_sum;
	int error_number, indexchaine, indexliste;
	char set[170], mode, last_set;
	float glyph_count;
	char dest[1000];
	int separator_row, linkage_flag, c_count;
#ifndef _MSC_VER
        char reduced[length + 1];
#else
        char* reduced = (char*)_alloca(length + 1);
#endif
	error_number = 0;
	strcpy(dest, "");
	linkage_flag = 0;

	j = 0;
	bar_characters = 0;
	separator_row = 0;

	memset(values, 0, sizeof(values));
	memset(set, ' ', sizeof(set));

	if(length > 160) {
		/* This only blocks rediculously long input - the actual length of the
		resulting barcode depends on the type of data, so this is trapped later */
		strcpy(symbol->errtxt, "Input too long");
		return ZINT_ERROR_TOO_LONG;
	}
	for(i = 0; i < length; i++) {
		if(source[i] == '\0') {
			/* Null characters not allowed! */
			strcpy(symbol->errtxt, "NULL character in input data");
			return ZINT_ERROR_INVALID_DATA;
		}
	}

	/* if part of a composite symbol make room for the separator pattern */
	if(symbol->symbology == BARCODE_EAN128_CC) {
		separator_row = symbol->rows;
		symbol->row_height[symbol->rows] = 1;
		symbol->rows += 1;
	}

	if(symbol->input_mode != GS1_MODE) {
		/* GS1 data has not been checked yet */
		error_number = gs1_verify(symbol, source, length, reduced);
		if(error_number != 0) { return error_number; }
	}

	/* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */
	indexliste = 0;
	indexchaine = 0;

	mode = parunmodd(reduced[indexchaine]);
	if(reduced[indexchaine] == '[') {
		mode = ABORC;
	}
	
	for(i = 0; i < 170; i++) {
		list[0][i] = 0;
	}
	
	do {
		list[1][indexliste] = mode;
		while ((list[1][indexliste] == mode) && (indexchaine < strlen(reduced))) {
			list[0][indexliste]++;
			indexchaine++;
			mode = parunmodd(reduced[indexchaine]);
			if(reduced[indexchaine] == '[') { mode = ABORC; }
		}
		indexliste++;
	} while (indexchaine < strlen(reduced));

	dxsmooth(&indexliste);

	/* Put set data into set[] */
	read = 0;
	for(i = 0; i < indexliste; i++) {
		for(j = 0; j < list[0][i]; j++) {
			switch(list[1][i]) {
				case SHIFTA: set[read] = 'a'; break;
				case LATCHA: set[read] = 'A'; break;
				case SHIFTB: set[read] = 'b'; break;
				case LATCHB: set[read] = 'B'; break;
				case LATCHC: set[read] = 'C'; break;
			}
			read++;
		}
	}

	/* Watch out for odd-length Mode C blocks */
	c_count = 0;
	for(i = 0; i < read; i++) {
		if(set[i] == 'C') {
			if(reduced[i] == '[') {
				if(c_count & 1) {
					if((i - c_count) != 0) {
						set[i - c_count] = 'B';
					} else {
						set[i - 1] = 'B';
					}
				}
				c_count = 0;
			} else {
				c_count++;
			}
		} else {
			if(c_count & 1) {
				if((i - c_count) != 0) {
					set[i - c_count] = 'B';
				} else {
					set[i - 1] = 'B';
				}
			}
			c_count = 0;
		}
	}
	if(c_count & 1) {
		if((i - c_count) != 0) {
			set[i - c_count] = 'B';
		} else {
			set[i - 1] = 'B';
		}
	}
	for(i = 1; i < read - 1; i++) {
		if((set[i] == 'C') && ((set[i - 1] == 'B') && (set[i + 1] == 'B'))) {
			set[i] = 'B';
		}
	}

	/* for(i = 0; i < read; i++) {
		printf("char %c  mode %c\n", reduced[i], set[i]);
	} */
	
	/* Now we can calculate how long the barcode is going to be - and stop it from
	being too long */
	last_set = ' ';
	glyph_count = 0.0;
	for(i = 0; i < strlen(reduced); i++) {
		if((set[i] == 'a') || (set[i] == 'b')) {
			glyph_count = glyph_count + 1.0;
		}
		if(((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C')) {
			if(set[i] != last_set) {
				last_set = set[i];
				glyph_count = glyph_count + 1.0;
			}
		}

		if((set[i] == 'C') && (reduced[i] != '[')) {
			glyph_count = glyph_count + 0.5;
		} else {
			glyph_count = glyph_count + 1.0;
		}
	}
	if(glyph_count > 80.0) {
		strcpy(symbol->errtxt, "Input too long");
		return ZINT_ERROR_TOO_LONG;
	}

	/* So now we know what start character to use - we can get on with it! */
	switch(set[0])
	{
		case 'A': /* Start A */
			concat(dest, C128Table[103]);
			values[0] = 103;
			break;
		case 'B': /* Start B */
			concat(dest, C128Table[104]);
			values[0] = 104;
			break;
		case 'C': /* Start C */
			concat(dest, C128Table[105]);
			values[0] = 105;
			break;
	}
	bar_characters++;

	concat(dest, C128Table[102]);
	values[1] = 102;
	bar_characters++;

	/* Encode the data */
	read = 0;
	do {

		if((read != 0) && (set[read] != set[read - 1]))
		{ /* Latch different code set */
			switch(set[read])
			{
				case 'A': concat(dest, C128Table[101]);
				values[bar_characters] = 101;
				bar_characters++;
				break;
				case 'B': concat(dest, C128Table[100]);
				values[bar_characters] = 100;
				bar_characters++;
				break;
				case 'C': concat(dest, C128Table[99]);
				values[bar_characters] = 99;
				bar_characters++;
				break;
			}
		}

		if((set[read] == 'a') || (set[read] == 'b')) {
			/* Insert shift character */
			concat(dest, C128Table[98]);
			values[bar_characters] = 98;
			bar_characters++;
		}

		if(reduced[read] != '[') {
			switch(set[read])
			{ /* Encode data characters */
				case 'A':
				case 'a':
					c128_set_a(reduced[read], dest, values, &bar_characters);
					read++;
					break;
				case 'B':
				case 'b':
					c128_set_b(reduced[read], dest, values, &bar_characters);
					read++;
					break;
				case 'C':
					c128_set_c(reduced[read], reduced[read + 1], dest, values, &bar_characters);
					read += 2;
					break;
			}
		} else {
			concat(dest, C128Table[102]);
			values[bar_characters] = 102;
			bar_characters++;
			read++;
		}
	} while (read < strlen(reduced));

	/* "...note that the linkage flag is an extra code set character between
	the last data character and the Symbol Check Character" (GS1 Specification) */
	
	/* Linkage flags in GS1-128 are determined by ISO/IEC 24723 section 7.4 */

	switch(symbol->option_1) {
		case 1:
		case 2:
			/* CC-A or CC-B 2D component */
			switch(set[strlen(reduced) - 1]) {
				case 'A': linkage_flag = 100; break;
				case 'B': linkage_flag = 99; break;
				case 'C': linkage_flag = 101; break;
			}
			break;
		case 3:
			/* CC-C 2D component */
			switch(set[strlen(reduced) - 1]) {
				case 'A': linkage_flag = 99; break;
				case 'B': linkage_flag = 101; break;
				case 'C': linkage_flag = 100; break;
			}
			break;
	}

	if(linkage_flag != 0) {
		concat(dest, C128Table[linkage_flag]);
		values[bar_characters] = linkage_flag;
		bar_characters++;
	}
	
	/*for(i = 0; i < bar_characters; i++) {
		printf("[%d] ", values[i]);
	}
	printf("\n");*/
	
	/* check digit calculation */
	total_sum = 0;
	for(i = 0; i < bar_characters; i++)
	{
		if(i > 0)
		{
			values[i] *= i;

		}
		total_sum += values[i];
	}
	concat(dest, C128Table[total_sum%103]);
	values[bar_characters] = total_sum % 103;
	bar_characters++;

	/* Stop character */
	concat(dest, C128Table[106]);
	values[bar_characters] = 106;
	bar_characters++;
	expand(symbol, dest);

	/* Add the separator pattern for composite symbols */
	if(symbol->symbology == BARCODE_EAN128_CC) {
		for(i = 0; i < symbol->width; i++) {
			if(!(module_is_set(symbol, separator_row + 1, i))) {
				set_module(symbol, separator_row, i);
			}
		}
	}

	for(i = 0; i < length; i++) {
		if((source[i] != '[') && (source[i] != ']')) {
			symbol->text[i] = source[i];
		}
		if(source[i] == '[') {
			symbol->text[i] = '(';
		}
		if(source[i] == ']') {
			symbol->text[i] = ')';
		}
	}

	return error_number;
}
Esempio n. 16
0
/*
**++
**  ROUTINE:	lbr_get_rdt
**
**  FUNCTIONAL DESCRIPTION:
**
**  	Gets the RDT of a library module.
**
**  RETURNS:	cond_value, longword (unsigned), write only, by value
**
**  PROTOTYPE:
**
**  	lbr_get_rdt(char *libfile, char *module, TIME *rdt);
**
**  libfile:	ASCIZ_string, read only, by reference
**  module: 	ASCIZ_string, read only, by reference
**  rdt:    	date_time, quadword (signed), write only, by reference
**
**  IMPLICIT INPUTS:	None.
**
**  IMPLICIT OUTPUTS:	None.
**
**  COMPLETION CODES:	Any from the LBR$ routines.
**
**  SIDE EFFECTS:   	lbrque modified.
**
**--
*/
unsigned int lbr_get_rdt (char *lib, char *mod, TIME *rdt) {

    unsigned int lbrfunc=LBR$C_READ, lbr$c_knf = 0x08680F2, libidx = 1;
    char real_name[256];
    unsigned char fid[28];
    struct dsc$descriptor libdsc, moddsc;
    struct LBR *lbr;
    unsigned int status, len;
    unsigned short rfa[3];
    struct mhddef mhd;

/*
** First look up the library file
*/
    status = file_find(lib, 0, real_name, fid);
    if (!OK(status)) return status;

/*
** Already open?
*/
    for (lbr = (struct LBR *)lbrque.head; lbr != (struct LBR *)&lbrque;
    	    	    lbr = lbr->flink) {
    	if (memcmp(fid, &lbr->nam.nam$t_dvi, 28) == 0) break;
    }

/*
** If not open yet, construct a context block and open it.
*/
    if (lbr == (struct LBR *) &lbrque) {
/*
**  Already have max number of libraries open?  If so, close one.
*/
    	if (lbrcount >= LBR$C_MAXCTL) {
    	    queue_remove(lbrque.head, &lbr);
    	    lbr$close(&lbr->lbrctx);
    	    lbrcount -= 1;
    	} else {
    	    lbr = malloc(sizeof(struct LBR));
    	}
    	queue_insert(lbr, lbrque.tail);
    	lbr->lbrctx = 0;
    	lbr->nam = cc$rms_nam;
    	lbr->nam.nam$b_rss = sizeof(lbr->rspec)-1;
    	lbr->nam.nam$b_ess = sizeof(lbr->espec)-1;
    	lbr->nam.nam$l_esa = lbr->espec;
    	lbr->nam.nam$l_rsa = lbr->rspec;
    	status = lbr$ini_control(&lbr->lbrctx, &lbrfunc, 0, &lbr->nam);
    	if (!OK(status)) lib$signal(status);
    	INIT_SDESC(libdsc, strlen(real_name), real_name);
    	status = lbr$open(&lbr->lbrctx, &libdsc);
    	if (!OK(status)) return status;
    	lbrcount += 1;
    }

/*
** Look up the module in question...
*/
    INIT_SDESC(moddsc, strlen(mod), mod);
/*    status = lbr$lookup_key(&lbr->lbrctx, &moddsc, rfa); */
    mod2search4 = &moddsc;
    return_rfa_here = rfa;
    status = lbr$get_index(&lbr->lbrctx, &libidx, &caseblindsearch);
    if (status != 2) return lbr$c_knf;		/* caseblindsearch returns 2 on success, 1 on failure */

/*
**  ... and get the RDT from the module header
*/
    INIT_SDESC(moddsc, sizeof(mhd), &mhd);
    status = lbr$set_module(&lbr->lbrctx, rfa, &moddsc, &len);
    if (!OK(status) && (status != LBR$_HDRTRUNC)) lib$signal(status);
    memcpy(rdt, &mhd.mhd$l_datim, 8);
    return SS$_NORMAL;

}
Esempio n. 17
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;
}
Esempio n. 18
0
int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
{
	int size = 1, i, j, data_blocks;

	char datagrid[136][120];
	int row, col;
	int sub_version = 0;
	
	if((symbol->option_2 < 0) || (symbol->option_2 > 10)) {
		strcpy(symbol->errtxt, "Invalid symbol size");
		return ERROR_INVALID_OPTION;
	}
	
	if(symbol->option_2 == 9) {
		/* Version S */
		int codewords;
		short int elreg[112];
		unsigned int data[15], ecc[15];
		int stream[30];
		int block_width;
		
		if(length > 18) {
			strcpy(symbol->errtxt, "Input data too long");
			return ERROR_TOO_LONG;
		}
		if(is_sane(NEON, source, length) == ERROR_INVALID_DATA) {
			strcpy(symbol->errtxt, "Invalid input data (Version S encodes numeric input only)");
			return ERROR_INVALID_DATA;
		}
		
		sub_version = 3; codewords = 12; block_width = 6; /* Version S-30 */
		if(length <= 12) { sub_version = 2; codewords = 8; block_width = 4; } /* Version S-20 */
		if(length <= 6) { sub_version = 1; codewords = 4; block_width = 2; } /* Version S-10 */
		
		binary_load(elreg, (char *)source, length);
		hex_dump(elreg);
		
		for(i = 0; i < 15; i++) {
			data[i] = 0;
			ecc[i] = 0;
		}
		
		for(i = 0; i < codewords; i++) {
			data[codewords - i - 1] += 1 * elreg[(i * 5)];
			data[codewords - i - 1] += 2 * elreg[(i * 5) + 1];
			data[codewords - i - 1] += 4 * elreg[(i * 5) + 2];
			data[codewords - i - 1] += 8 * elreg[(i * 5) + 3];
			data[codewords - i - 1] += 16 * elreg[(i * 5) + 4];
		}
		
		rs_init_gf(0x25);
		rs_init_code(codewords, 1);
		rs_encode_long(codewords, data, ecc);
		rs_free();
		
		for(i = 0; i < codewords; i++) {
			stream[i] = data[i];
			stream[i + codewords] = ecc[codewords - i - 1];
		}
		
		for(i = 0; i < 136; i++) {
			for(j = 0; j < 120; j++) {
				datagrid[i][j] = '0';
			}
		}
		
		i = 0;
		for(row = 0; row < 2; row++) {
			for(col = 0; col < block_width; col++) {
				if(stream[i] & 0x10) { datagrid[row * 2][col * 5] = '1'; }
				if(stream[i] & 0x08) { datagrid[row * 2][(col * 5) + 1] = '1'; }
				if(stream[i] & 0x04) { datagrid[row * 2][(col * 5) + 2] = '1'; }
				if(stream[i] & 0x02) { datagrid[(row * 2) + 1][col * 5] = '1'; }
				if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 5) + 1] = '1'; }
				if(stream[i + 1] & 0x10) { datagrid[row * 2][(col * 5) + 3] = '1'; }
				if(stream[i + 1] & 0x08) { datagrid[row * 2][(col * 5) + 4] = '1'; }
				if(stream[i + 1] & 0x04) { datagrid[(row * 2) + 1][(col * 5) + 2] = '1'; }
				if(stream[i + 1] & 0x02) { datagrid[(row * 2) + 1][(col * 5) + 3] = '1'; }
				if(stream[i + 1] & 0x01) { datagrid[(row * 2) + 1][(col * 5) + 4] = '1'; }
				i += 2;
			}
		}
		
		size = 9;	
		symbol->rows = 8;
		symbol->width = 10 * sub_version + 1;
	}
	
	if(symbol->option_2 == 10) {
		/* Version T */
		unsigned int data[40], ecc[25];
		unsigned int stream[65];
		int data_length;
		int data_cw, ecc_cw, block_width;
		
		for(i = 0; i < 40; i++) { data[i] = 0; }
		data_length = c1_encode(symbol, source, data, length);
		
		if(data_length == 0) {
			return ERROR_TOO_LONG;
		}
		
		if(data_length > 38) {
			strcpy(symbol->errtxt, "Input data too long");
			return ERROR_TOO_LONG;
		}
		
		size = 10;
		sub_version = 3; data_cw = 38; ecc_cw = 22; block_width = 12;
		if(data_length <= 24) { sub_version = 2; data_cw = 24; ecc_cw = 16; block_width = 8; }
		if(data_length <= 10) { sub_version = 1; data_cw = 10; ecc_cw = 10; block_width = 4; }
		
		for(i = data_length; i < data_cw; i++) {
			data[i] = 129; /* Pad */
		}
		
		/* Calculate error correction data */
		rs_init_gf(0x12d);
		rs_init_code(ecc_cw, 1);	
		rs_encode_long(data_cw, data, ecc);
		rs_free();
		
		/* "Stream" combines data and error correction data */
		for(i = 0; i < data_cw; i++) {
			stream[i] = data[i];
		}
		for(i = 0; i < ecc_cw; i++) {
			stream[data_cw + i] = ecc[ecc_cw - i - 1];
		}
	
		for(i = 0; i < 136; i++) {
			for(j = 0; j < 120; j++) {
				datagrid[i][j] = '0';
			}
		}
		
		i = 0;
		for(row = 0; row < 5; row++) {
			for(col = 0; col < block_width; col++) {
				if(stream[i] & 0x80) { datagrid[row * 2][col * 4] = '1'; }
				if(stream[i] & 0x40) { datagrid[row * 2][(col * 4) + 1] = '1'; }
				if(stream[i] & 0x20) { datagrid[row * 2][(col * 4) + 2] = '1'; }
				if(stream[i] & 0x10) { datagrid[row * 2][(col * 4) + 3] = '1'; }
				if(stream[i] & 0x08) { datagrid[(row * 2) + 1][col * 4] = '1'; }
				if(stream[i] & 0x04) { datagrid[(row * 2) + 1][(col * 4) + 1] = '1'; }
				if(stream[i] & 0x02) { datagrid[(row * 2) + 1][(col * 4) + 2] = '1'; }
				if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 4) + 3] = '1'; }
				i++;
			}
		}
		
		symbol->rows = 16;
		symbol->width = (sub_version * 16) + 1;
	}
		
	if((symbol->option_2 != 9) && (symbol->option_2 != 10)) {
		/* Version A to H */
		unsigned int data[1500], ecc[600];
		unsigned int sub_data[190], sub_ecc[75];
		unsigned int stream[2100];
		int data_length;
				
		for(i = 0; i < 1500; i++) { data[i] = 0; }
		data_length = c1_encode(symbol, source, data, length);
		
		if(data_length == 0) {
			return ERROR_TOO_LONG;
		}
		
		for(i = 7; i >= 0; i--) {
			if(c1_data_length[i] >= data_length) {
				size = i + 1;
			}
		}
		
		if(symbol->option_2 > size) {
			size = symbol->option_2;
		}
		
		for(i = data_length; i < c1_data_length[size - 1]; i++) {
			data[i] = 129; /* Pad */
		}
		
		/* Calculate error correction data */
		data_length = c1_data_length[size - 1];
		for(i = 0; i < 190; i++) { sub_data[i] = 0; }
		for(i = 0; i < 75; i++) { sub_ecc[i] = 0; }
		
		data_blocks = c1_blocks[size - 1];
		
		rs_init_gf(0x12d);
		rs_init_code(c1_ecc_blocks[size - 1], 0);	
		for(i = 0; i < data_blocks; i++) {
			for(j = 0; j < c1_data_blocks[size - 1]; j++) {
				
				sub_data[j] = data[j * data_blocks + i];
			}
			rs_encode_long(c1_data_blocks[size - 1], sub_data, sub_ecc);
			for(j = 0; j < c1_ecc_blocks[size - 1]; j++) {
				ecc[c1_ecc_length[size - 1] - (j * data_blocks + i) - 1] = sub_ecc[j];
			}
		}
		rs_free();
		
		/* "Stream" combines data and error correction data */
		for(i = 0; i < data_length; i++) {
			stream[i] = data[i];
		}
		for(i = 0; i < c1_ecc_length[size - 1]; i++) {
			stream[data_length + i] = ecc[i];
		}
	
		for(i = 0; i < 136; i++) {
			for(j = 0; j < 120; j++) {
				datagrid[i][j] = '0';
			}
		}
		
		i = 0;
		for(row = 0; row < c1_grid_height[size - 1]; row++) {
			for(col = 0; col < c1_grid_width[size - 1]; col++) {
				if(stream[i] & 0x80) { datagrid[row * 2][col * 4] = '1'; }
				if(stream[i] & 0x40) { datagrid[row * 2][(col * 4) + 1] = '1'; }
				if(stream[i] & 0x20) { datagrid[row * 2][(col * 4) + 2] = '1'; }
				if(stream[i] & 0x10) { datagrid[row * 2][(col * 4) + 3] = '1'; }
				if(stream[i] & 0x08) { datagrid[(row * 2) + 1][col * 4] = '1'; }
				if(stream[i] & 0x04) { datagrid[(row * 2) + 1][(col * 4) + 1] = '1'; }
				if(stream[i] & 0x02) { datagrid[(row * 2) + 1][(col * 4) + 2] = '1'; }
				if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 4) + 3] = '1'; }
				i++;
			}
		}
		
		/* for(i = 0; i < (c1_grid_height[size - 1] * 2); i++) {
			for(j = 0; j < (c1_grid_width[size - 1] * 4); j++) {
				printf("%c", datagrid[i][j]);
			}
			printf("\n");
		} */
		
		symbol->rows = c1_height[size - 1];
		symbol->width = c1_width[size - 1];
	}
	
	switch(size) {
		case 1: /* Version A */
			central_finder(symbol, 6, 3, 1);
			vert(symbol, 4, 6, 1);
			vert(symbol, 12, 5, 0); 
			set_module(symbol, 5, 12);
			spigot(symbol, 0);
			spigot(symbol, 15);
			block_copy(symbol, datagrid, 0, 0, 5, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 5, 12, 0, 2);
			block_copy(symbol, datagrid, 5, 0, 5, 12, 6, 0);
			block_copy(symbol, datagrid, 5, 12, 5, 4, 6, 2);
			break;
		case 2: /* Version B */
			central_finder(symbol, 8, 4, 1);
			vert(symbol, 4, 8, 1);
			vert(symbol, 16, 7, 0); 
			set_module(symbol, 7, 16);
			spigot(symbol, 0);
			spigot(symbol, 21);
			block_copy(symbol, datagrid, 0, 0, 7, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 7, 16, 0, 2);
			block_copy(symbol, datagrid, 7, 0, 7, 16, 8, 0);
			block_copy(symbol, datagrid, 7, 16, 7, 4, 8, 2);
			break;
		case 3: /* Version C */
			central_finder(symbol, 11, 4, 2);
			vert(symbol, 4, 11, 1);
			vert(symbol, 26, 13, 1);
			vert(symbol, 4, 10, 0);
			vert(symbol, 26, 10, 0); 
			spigot(symbol, 0);
			spigot(symbol, 27);
			block_copy(symbol, datagrid, 0, 0, 10, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 10, 20, 0, 2);
			block_copy(symbol, datagrid, 0, 24, 10, 4, 0, 4);
			block_copy(symbol, datagrid, 10, 0, 10, 4, 8, 0);
			block_copy(symbol, datagrid, 10, 4, 10, 20, 8, 2);
			block_copy(symbol, datagrid, 10, 24, 10, 4, 8, 4);
			break;
		case 4: /* Version D */
			central_finder(symbol, 16, 5, 1); 
			vert(symbol, 4, 16, 1);
			vert(symbol, 20, 16, 1);
			vert(symbol, 36, 16, 1);
			vert(symbol, 4, 15, 0);
			vert(symbol, 20, 15, 0);
			vert(symbol, 36, 15, 0);
			spigot(symbol, 0);
			spigot(symbol, 12);
			spigot(symbol, 27);
			spigot(symbol, 39);
			block_copy(symbol, datagrid, 0, 0, 15, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 15, 14, 0, 2);
			block_copy(symbol, datagrid, 0, 18, 15, 14, 0, 4);
			block_copy(symbol, datagrid, 0, 32, 15, 4, 0, 6);
			block_copy(symbol, datagrid, 15, 0, 15, 4, 10, 0);
			block_copy(symbol, datagrid, 15, 4, 15, 14, 10, 2);
			block_copy(symbol, datagrid, 15, 18, 15, 14, 10, 4);
			block_copy(symbol, datagrid, 15, 32, 15, 4, 10, 6);
			break;
		case 5: /* Version E */
			central_finder(symbol, 22, 5, 2); 
			vert(symbol, 4, 22, 1);
			vert(symbol, 26, 24, 1);
			vert(symbol, 48, 22, 1);
			vert(symbol, 4, 21, 0);
			vert(symbol, 26, 21, 0);
			vert(symbol, 48, 21, 0);
			spigot(symbol, 0);
			spigot(symbol, 12);
			spigot(symbol, 39);
			spigot(symbol, 51);
			block_copy(symbol, datagrid, 0, 0, 21, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 21, 20, 0, 2);
			block_copy(symbol, datagrid, 0, 24, 21, 20, 0, 4);
			block_copy(symbol, datagrid, 0, 44, 21, 4, 0, 6);
			block_copy(symbol, datagrid, 21, 0, 21, 4, 10, 0);
			block_copy(symbol, datagrid, 21, 4, 21, 20, 10, 2);
			block_copy(symbol, datagrid, 21, 24, 21, 20, 10, 4);
			block_copy(symbol, datagrid, 21, 44, 21, 4, 10, 6);
			break;
		case 6: /* Version F */
			central_finder(symbol, 31, 5, 3); 
			vert(symbol, 4, 31, 1);
			vert(symbol, 26, 35, 1);
			vert(symbol, 48, 31, 1);
			vert(symbol, 70, 35, 1);
			vert(symbol, 4, 30, 0);
			vert(symbol, 26, 30, 0);
			vert(symbol, 48, 30, 0);
			vert(symbol, 70, 30, 0);
			spigot(symbol, 0);
			spigot(symbol, 12);
			spigot(symbol, 24);
			spigot(symbol, 45);
			spigot(symbol, 57);
			spigot(symbol, 69);
			block_copy(symbol, datagrid, 0, 0, 30, 4, 0, 0);
			block_copy(symbol, datagrid, 0, 4, 30, 20, 0, 2);
			block_copy(symbol, datagrid, 0, 24, 30, 20, 0, 4);
			block_copy(symbol, datagrid, 0, 44, 30, 20, 0, 6);
			block_copy(symbol, datagrid, 0, 64, 30, 4, 0, 8);
			block_copy(symbol, datagrid, 30, 0, 30, 4, 10, 0);
			block_copy(symbol, datagrid, 30, 4, 30, 20, 10, 2);
			block_copy(symbol, datagrid, 30, 24, 30, 20, 10, 4);
			block_copy(symbol, datagrid, 30, 44, 30, 20, 10, 6);
			block_copy(symbol, datagrid, 30, 64, 30, 4, 10, 8);
			break;
		case 7: /* Version G */
			central_finder(symbol, 47, 6, 2); 
			vert(symbol, 6, 47, 1);
			vert(symbol, 27, 49, 1);
			vert(symbol, 48, 47, 1);
			vert(symbol, 69, 49, 1);
			vert(symbol, 90, 47, 1);
			vert(symbol, 6, 46, 0);
			vert(symbol, 27, 46, 0);
			vert(symbol, 48, 46, 0);
			vert(symbol, 69, 46, 0);
			vert(symbol, 90, 46, 0);
			spigot(symbol, 0);
			spigot(symbol, 12);
			spigot(symbol, 24);
			spigot(symbol, 36);
			spigot(symbol, 67);
			spigot(symbol, 79);
			spigot(symbol, 91);
			spigot(symbol, 103);
			block_copy(symbol, datagrid, 0, 0, 46, 6, 0, 0);
			block_copy(symbol, datagrid, 0, 6, 46, 19, 0, 2);
			block_copy(symbol, datagrid, 0, 25, 46, 19, 0, 4);
			block_copy(symbol, datagrid, 0, 44, 46, 19, 0, 6);
			block_copy(symbol, datagrid, 0, 63, 46, 19, 0, 8);
			block_copy(symbol, datagrid, 0, 82, 46, 6, 0, 10);
			block_copy(symbol, datagrid, 46, 0, 46, 6, 12, 0);
			block_copy(symbol, datagrid, 46, 6, 46, 19, 12, 2);
			block_copy(symbol, datagrid, 46, 25, 46, 19, 12, 4);
			block_copy(symbol, datagrid, 46, 44, 46, 19, 12, 6);
			block_copy(symbol, datagrid, 46, 63, 46, 19, 12, 8);
			block_copy(symbol, datagrid, 46, 82, 46, 6, 12, 10);
			break;
		case 8: /* Version H */
			central_finder(symbol, 69, 6, 3);
			vert(symbol, 6, 69, 1);
			vert(symbol, 26, 73, 1);
			vert(symbol, 46, 69, 1);
			vert(symbol, 66, 73, 1);
			vert(symbol, 86, 69, 1);
			vert(symbol, 106, 73, 1);
			vert(symbol, 126, 69, 1);
			vert(symbol, 6, 68, 0);
			vert(symbol, 26, 68, 0);
			vert(symbol, 46, 68, 0);
			vert(symbol, 66, 68, 0);
			vert(symbol, 86, 68, 0);
			vert(symbol, 106, 68, 0);
			vert(symbol, 126, 68, 0); 
			spigot(symbol, 0);
			spigot(symbol, 12);
			spigot(symbol, 24);
			spigot(symbol, 36);
			spigot(symbol, 48);
			spigot(symbol, 60);
			spigot(symbol, 87);
			spigot(symbol, 99);
			spigot(symbol, 111);
			spigot(symbol, 123);
			spigot(symbol, 135);
			spigot(symbol, 147);
			block_copy(symbol, datagrid, 0, 0, 68, 6, 0, 0);
			block_copy(symbol, datagrid, 0, 6, 68, 18, 0, 2);
			block_copy(symbol, datagrid, 0, 24, 68, 18, 0, 4);
			block_copy(symbol, datagrid, 0, 42, 68, 18, 0, 6);
			block_copy(symbol, datagrid, 0, 60, 68, 18, 0, 8);
			block_copy(symbol, datagrid, 0, 78, 68, 18, 0, 10);
			block_copy(symbol, datagrid, 0, 96, 68, 18, 0, 12);
			block_copy(symbol, datagrid, 0, 114, 68, 6, 0, 14);
			block_copy(symbol, datagrid, 68, 0, 68, 6, 12, 0);
			block_copy(symbol, datagrid, 68, 6, 68, 18, 12, 2);
			block_copy(symbol, datagrid, 68, 24, 68, 18, 12, 4);
			block_copy(symbol, datagrid, 68, 42, 68, 18, 12, 6);
			block_copy(symbol, datagrid, 68, 60, 68, 18, 12, 8);
			block_copy(symbol, datagrid, 68, 78, 68, 18, 12, 10);
			block_copy(symbol, datagrid, 68, 96, 68, 18, 12, 12);
			block_copy(symbol, datagrid, 68, 114, 68, 6, 12, 14);
			break;
		case 9: /* Version S */
			horiz(symbol, 5, 1);
			horiz(symbol, 7, 1);
			set_module(symbol, 6, 0);
			set_module(symbol, 6, symbol->width - 1);
			unset_module(symbol, 7, 1);
			unset_module(symbol, 7, symbol->width - 2);
			switch(sub_version) {
				case 1: /* Version S-10 */
					set_module(symbol, 0, 5);
					block_copy(symbol, datagrid, 0, 0, 4, 5, 0, 0);
					block_copy(symbol, datagrid, 0, 5, 4, 5, 0, 1);
					break;
				case 2: /* Version S-20 */
					set_module(symbol, 0, 10);
					set_module(symbol, 4, 10);
					block_copy(symbol, datagrid, 0, 0, 4, 10, 0, 0);
					block_copy(symbol, datagrid, 0, 10, 4, 10, 0, 1);
					break;
				case 3: /* Version S-30 */
					set_module(symbol, 0, 15);
					set_module(symbol, 4, 15);
					set_module(symbol, 6, 15);
					block_copy(symbol, datagrid, 0, 0, 4, 15, 0, 0);
					block_copy(symbol, datagrid, 0, 15, 4, 15, 0, 1);
					break;
			}
			break;
		case 10: /* Version T */
			horiz(symbol, 11, 1);
			horiz(symbol, 13, 1);
			horiz(symbol, 15, 1);
			set_module(symbol, 12, 0);
			set_module(symbol, 12, symbol->width - 1);
			set_module(symbol, 14, 0);
			set_module(symbol, 14, symbol->width - 1);
			unset_module(symbol, 13, 1);
			unset_module(symbol, 13, symbol->width - 2);
			unset_module(symbol, 15, 1);
			unset_module(symbol, 15, symbol->width - 2);
			switch(sub_version) {
				case 1: /* Version T-16 */
					set_module(symbol, 0, 8);
					set_module(symbol, 10, 8);
					block_copy(symbol, datagrid, 0, 0, 10, 8, 0, 0);
					block_copy(symbol, datagrid, 0, 8, 10, 8, 0, 1);
					break;
				case 2: /* Version T-32 */
					set_module(symbol, 0, 16);
					set_module(symbol, 10, 16);
					set_module(symbol, 12, 16);
					block_copy(symbol, datagrid, 0, 0, 10, 16, 0, 0);
					block_copy(symbol, datagrid, 0, 16, 10, 16, 0, 1);
					break;
				case 3: /* Verion T-48 */
					set_module(symbol, 0, 24);
					set_module(symbol, 10, 24);
					set_module(symbol, 12, 24);
					set_module(symbol, 14, 24);
					block_copy(symbol, datagrid, 0, 0, 10, 24, 0, 0);
					block_copy(symbol, datagrid, 0, 24, 10, 24, 0, 1);
					break;
			}
			break;
	}
	
	for(i = 0; i < symbol->rows; i++) {
		symbol->row_height[i] = 1;
	}
	
	return 0;
}
Esempio n. 19
0
int handle_sec_auth_init(int cfd, sec_mod_st *sec, const SecAuthInitMsg *req, pid_t pid)
{
	int ret = -1;
	client_entry_st *e;
	unsigned need_continue = 0;

	e = new_client_entry(sec, req->ip, pid);
	if (e == NULL) {
		seclog(sec, LOG_ERR, "cannot initialize memory");
		return -1;
	}

	ret = set_module(sec, e, req->auth_type);
	if (ret < 0) {
		seclog(sec, LOG_ERR, "no module found for auth type %u", (unsigned)req->auth_type);
		goto cleanup;
	}

	if (req->hostname != NULL) {
		strlcpy(e->hostname, req->hostname, sizeof(e->hostname));
	}

	if (e->module) {
		ret =
		    e->module->auth_init(&e->auth_ctx, e, req->user_name, req->ip, req->our_ip, pid);
		if (ret == ERR_AUTH_CONTINUE) {
			need_continue = 1;
		} else if (ret < 0) {
			goto cleanup;
		}

		ret =
		    e->module->auth_group(e->auth_ctx, req->group_name, e->auth_info.groupname,
				       sizeof(e->auth_info.groupname));
		if (ret != 0) {
			ret = -1;
			goto cleanup;
		}
		e->auth_info.groupname[sizeof(e->auth_info.groupname) - 1] = 0;

	}

	if (req->user_name != NULL) {
		strlcpy(e->auth_info.username, req->user_name, sizeof(e->auth_info.username));
	}

	if (req->our_ip != NULL) {
		strlcpy(e->auth_info.our_ip, req->our_ip, sizeof(e->auth_info.our_ip));
	}

	if (e->auth_type & AUTH_TYPE_CERTIFICATE) {
		if (e->auth_info.groupname[0] == 0 && req->group_name != NULL && sec->config->cert_group_oid != NULL) {
			unsigned i, found = 0;

			for (i=0;i<req->n_cert_group_names;i++) {
				if (strcmp(req->group_name, req->cert_group_names[i]) == 0) {
					strlcpy(e->auth_info.groupname, req->cert_group_names[i], sizeof(e->auth_info.groupname));
					found = 1;
					break;
				}
			}

			if (found == 0) {
				seclog(sec, LOG_AUTH, "user '%s' requested group '%s' but is not included on his certificate groups",
					req->user_name, req->group_name);
				ret = -1;
				goto cleanup;
			}
		}
	}

	ret =
	    check_user_group_status(sec, e, req->tls_auth_ok,
				    req->cert_user_name, req->cert_group_names,
				    req->n_cert_group_names);
	if (ret < 0) {
		goto cleanup;
	}

	e->status = PS_AUTH_INIT;
	seclog(sec, LOG_DEBUG, "auth init %sfor user '%s' "SESSION_STR" of group: '%s' from '%s'", 
	       req->tls_auth_ok?"(with cert) ":"",
	       e->auth_info.username, e->auth_info.psid, e->auth_info.groupname, req->ip);

	if (need_continue != 0) {
		ret = ERR_AUTH_CONTINUE;
		goto cleanup;
	}

	ret = 0;
 cleanup:
	return handle_sec_auth_res(cfd, sec, e, ret);
}
Esempio n. 20
0
int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
{
	/* splits string to parts before and after '+' parts */
	unsigned char first_part[20] = { 0 }, second_part[20] = { 0 }, dest[1000] = { 0 };
	unsigned char local_source[20] = { 0 };
	unsigned int latch, reader, writer, with_addon;
	int error_number, i;
	

	with_addon = FALSE;
	latch = FALSE;
	writer = 0;

	if(src_len > 19) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	if(symbol->symbology != BARCODE_ISBNX) {
		/* ISBN has it's own checking routine */
		error_number = is_sane("0123456789+", source, src_len);
		if(error_number == ERROR_INVALID_DATA) {
			strcpy(symbol->errtxt, "Invalid characters in data");
			return error_number;
		}
	} else {
		error_number = is_sane("0123456789Xx", source, src_len);
		if(error_number == ERROR_INVALID_DATA) {
			strcpy(symbol->errtxt, "Invalid characters in input");
			return error_number;
		}
	}


	/* Add leading zeroes */
	ustrcpy(local_source, (unsigned char *)"");
	if(symbol->symbology == BARCODE_ISBNX) {
		to_upper(local_source);
	}
	
	ean_leading_zeroes(symbol, source, local_source);
	
	for(reader = 0; reader <= ustrlen(local_source); reader++)
	{
		if(source[reader] == '+') { with_addon = TRUE; }
	}

	reader = 0;
	if(with_addon) {
		do {
			if(local_source[reader] == '+') {
				first_part[writer] = '\0';
				latch = TRUE;
				reader++;
				writer = 0;
			}

			if(latch) {
				second_part[writer] = local_source[reader];
				reader++;
				writer++;
			} else {
				first_part[writer] = local_source[reader];
				reader++;
				writer++;
			}
		} while (reader <= ustrlen(local_source));
	} else {
		strcpy((char*)first_part, (char*)local_source);
	}


	switch(symbol->symbology)
	{
		case BARCODE_EANX:
			switch(ustrlen(first_part))
			{
				case 2: add_on(first_part, (char*)dest, 0); ustrcpy(symbol->text, first_part); break;
				case 5: add_on(first_part, (char*)dest, 0); ustrcpy(symbol->text, first_part); break;
				case 7: ean8(symbol, first_part, (char*)dest); break;
				case 12: ean13(symbol, first_part, (char*)dest); break;
				default: strcpy(symbol->errtxt, "Invalid length input"); return ERROR_TOO_LONG; break;
			}
			break;
		case BARCODE_EANX_CC:
			switch(ustrlen(first_part))
			{ /* Adds vertical separator bars according to ISO/IEC 24723 section 11.4 */
				case 7: set_module(symbol, symbol->rows, 1);
					set_module(symbol, symbol->rows, 67);
					set_module(symbol, symbol->rows + 1, 0);
					set_module(symbol, symbol->rows + 1, 68);
					set_module(symbol, symbol->rows + 2, 1);
					set_module(symbol, symbol->rows + 1, 67);
					symbol->row_height[symbol->rows] = 2;
					symbol->row_height[symbol->rows + 1] = 2;
					symbol->row_height[symbol->rows + 2] = 2;
					symbol->rows += 3;
					ean8(symbol, first_part, (char*)dest); break;
				case 12:set_module(symbol, symbol->rows, 1);
					set_module(symbol, symbol->rows, 95);
					set_module(symbol, symbol->rows + 1, 0);
					set_module(symbol, symbol->rows + 1, 96);
					set_module(symbol, symbol->rows + 2, 1);
					set_module(symbol, symbol->rows + 2, 95);
					symbol->row_height[symbol->rows] = 2;
					symbol->row_height[symbol->rows + 1] = 2;
					symbol->row_height[symbol->rows + 2] = 2;
					symbol->rows += 3;
					ean13(symbol, first_part, (char*)dest); break;
					default: strcpy(symbol->errtxt, "Invalid length EAN input"); return ERROR_TOO_LONG; break;
			}
			break;
		case BARCODE_UPCA:
			if(ustrlen(first_part) == 11) {
				upca(symbol, first_part, (char*)dest);
			} else {
				strcpy(symbol->errtxt, "Input wrong length");
				return ERROR_TOO_LONG;
			}
			break;
		case BARCODE_UPCA_CC:
			if(ustrlen(first_part) == 11) {
				set_module(symbol, symbol->rows, 1);
				set_module(symbol, symbol->rows, 95);
				set_module(symbol, symbol->rows + 1, 0);
				set_module(symbol, symbol->rows + 1, 96);
				set_module(symbol, symbol->rows + 2, 1);
				set_module(symbol, symbol->rows + 2, 95);
				symbol->row_height[symbol->rows] = 2;
				symbol->row_height[symbol->rows + 1] = 2;
				symbol->row_height[symbol->rows + 2] = 2;
				symbol->rows += 3;
				upca(symbol, first_part, (char*)dest);
			} else {
				strcpy(symbol->errtxt, "UPCA input wrong length");
				return ERROR_TOO_LONG;
			}
			break;
		case BARCODE_UPCE:
			if((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= 7)) {
				upce(symbol, first_part, (char*)dest);
			} else {
				strcpy(symbol->errtxt, "Input wrong length");
				return ERROR_TOO_LONG;
			}
			break;
		case BARCODE_UPCE_CC:
			if((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= 7)) {
				set_module(symbol, symbol->rows, 1);
				set_module(symbol, symbol->rows, 51);
				set_module(symbol, symbol->rows + 1, 0);
				set_module(symbol, symbol->rows + 1, 52);
				set_module(symbol, symbol->rows + 2, 1);
				set_module(symbol, symbol->rows + 2, 51);
				symbol->row_height[symbol->rows] = 2;
				symbol->row_height[symbol->rows + 1] = 2;
				symbol->row_height[symbol->rows + 2] = 2;
				symbol->rows += 3;
				upce(symbol, first_part, (char*)dest);
			} else {
				strcpy(symbol->errtxt, "UPCE input wrong length");
				return ERROR_TOO_LONG;
			}
			break;
		case BARCODE_ISBNX:
			error_number = isbn(symbol, first_part, ustrlen(first_part), (char*)dest);
			if(error_number > 4) {
				return error_number;
			}
			break;
	}
	switch(ustrlen(second_part))
	{
		case 0: break;
		case 2:
			add_on(second_part, (char*)dest, 1);
			uconcat(symbol->text, (unsigned char*)"+");
			uconcat(symbol->text, second_part);
			break;
		case 5:
			add_on(second_part, (char*)dest, 1);
			uconcat(symbol->text, (unsigned char*)"+");
			uconcat(symbol->text, second_part);
			break;
		default:
			strcpy(symbol->errtxt, "Invalid length input");
			return ERROR_TOO_LONG;
			break;
	}
	
	expand(symbol, (char*)dest);

	switch(symbol->symbology) {
		case BARCODE_EANX_CC:
		case BARCODE_UPCA_CC:
		case BARCODE_UPCE_CC:
			/* shift the symbol to the right one space to allow for separator bars */
			for(i = (symbol->width + 1); i >= 1; i--) {
				if(module_is_set(symbol, symbol->rows - 1, i - 1)) {
					set_module(symbol, symbol->rows - 1, i);
				} else {
					unset_module(symbol, symbol->rows - 1, i);
				}
			}
			unset_module(symbol, symbol->rows - 1, 0);
			symbol->width += 2;
			break;
	}

	
	if((symbol->errtxt[0] == 'w') && (error_number == 0)) {
		error_number = 1; /* flag UPC-E warnings */
	}
	return error_number;
}
Esempio n. 21
0
File: imail.c Progetto: DroiDev/zint
int imail(struct zint_symbol *symbol, unsigned char source[], int length)
{
	char data_pattern[200];
	int error_number;
        int i, j, read;
        char zip[35], tracker[35], zip_adder[11], temp[2];
        short int accum[112], x_reg[112], y_reg[112];
        unsigned char byte_array[13];
        unsigned short usps_crc;
        int codeword[10];
        unsigned short characters[10];
        short int bit_pattern[13], bar_map[130];

	error_number = 0;

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

        /* separate the tracking code from the routing code */
	
	read = 0;
	j = 0;
	for(i = 0; i < length; i++) {
		if(source[i] == '-') {
			tracker[read] = '\0';
			j = 1;
			read = 0;
		} else {
			if(j == 0) {
				/* reading tracker */
				tracker[read] = source[i];
				read++;
			} else {
				/* reading zip code */
				zip[read] = source[i];
				read++;
			}
		}
	}
	if(j == 0) {
		tracker[read] = '\0';
	} else {
		zip[read] = '\0';
	}
	
	if(strlen(tracker) != 20) {
		strcpy(symbol->errtxt, "Invalid length tracking code");
		return ERROR_INVALID_DATA;
	}
	if(strlen(zip) > 11) {
		strcpy(symbol->errtxt, "Invalid ZIP code");
		return ERROR_INVALID_DATA;
	}
	
	/* *** Step 1 - Conversion of Data Fields into Binary Data *** */
	
	/* Routing code first */
	
	for(i = 0; i < 112; i++) {
		accum[i] = 0;
	}
	
	for(read = 0; read < strlen(zip); read++) {

		for(i = 0; i < 112; i++) {
			x_reg[i] = accum[i];
		}
		
		for(i = 0; i < 9; i++) {
			binary_add(accum, x_reg);
		}
		
		x_reg[0] = BCD[ctoi(zip[read]) * 4];
		x_reg[1] = BCD[(ctoi(zip[read]) * 4) + 1];
		x_reg[2] = BCD[(ctoi(zip[read]) * 4) + 2];
		x_reg[3] = BCD[(ctoi(zip[read]) * 4) + 3];
		for(i = 4; i < 112; i++) {
			x_reg[i] = 0;
		}
		
		binary_add(accum, x_reg);
	}
	
	/* add weight to routing code */
	
	for(i = 0; i < 112; i++) {
		x_reg[i] = accum[i];
	}
	
	if(strlen(zip) > 9) {
		strcpy(zip_adder, "1000100001");
	} else {
		if(strlen(zip) > 5) {
			strcpy(zip_adder, "100001");
		} else {
			if(strlen(zip) > 0) {
				strcpy(zip_adder, "1");
			} else {
				strcpy(zip_adder, "0");
			}
		}
	}
	
	for(i = 0; i < 112; i++) {
		accum[i] = 0;
	}
	
	for(read = 0; read < strlen(zip_adder); read++) {

		for(i = 0; i < 112; i++) {
			y_reg[i] = accum[i];
		}
		
		for(i = 0; i < 9; i++) {
			binary_add(accum, y_reg);
		}
		
		y_reg[0] = BCD[ctoi(zip_adder[read]) * 4];
		y_reg[1] = BCD[(ctoi(zip_adder[read]) * 4) + 1];
		y_reg[2] = BCD[(ctoi(zip_adder[read]) * 4) + 2];
		y_reg[3] = BCD[(ctoi(zip_adder[read]) * 4) + 3];
		for(i = 4; i < 112; i++) {
			y_reg[i] = 0;
		}
		
		binary_add(accum, y_reg);
	}

	binary_add(accum, x_reg);
	
	/* tracking code */

	/* multiply by 10 */
	for(i = 0; i < 112; i++) {
		y_reg[i] = accum[i];
	}
		
	for(i = 0; i < 9; i++) {
		binary_add(accum, y_reg);
	}
	
	/* add first digit of tracker */
	y_reg[0] = BCD[ctoi(tracker[0]) * 4];
	y_reg[1] = BCD[(ctoi(tracker[0]) * 4) + 1];
	y_reg[2] = BCD[(ctoi(tracker[0]) * 4) + 2];
	y_reg[3] = BCD[(ctoi(tracker[0]) * 4) + 3];
	for(i = 4; i < 112; i++) {
		y_reg[i] = 0;
	}
		
	binary_add(accum, y_reg);
	
	/* multiply by 5 */
	for(i = 0; i < 112; i++) {
		y_reg[i] = accum[i];
	}
		
	for(i = 0; i < 4; i++) {
		binary_add(accum, y_reg);
	}
	
	/* add second digit */
	y_reg[0] = BCD[ctoi(tracker[1]) * 4];
	y_reg[1] = BCD[(ctoi(tracker[1]) * 4) + 1];
	y_reg[2] = BCD[(ctoi(tracker[1]) * 4) + 2];
	y_reg[3] = BCD[(ctoi(tracker[1]) * 4) + 3];
	for(i = 4; i < 112; i++) {
		y_reg[i] = 0;
	}
	
	binary_add(accum, y_reg);
	
	/* and then the rest */

	for(read = 2; read < strlen(tracker); read++) {

		for(i = 0; i < 112; i++) {
			y_reg[i] = accum[i];
		}
		
		for(i = 0; i < 9; i++) {
			binary_add(accum, y_reg);
		}
		
		y_reg[0] = BCD[ctoi(tracker[read]) * 4];
		y_reg[1] = BCD[(ctoi(tracker[read]) * 4) + 1];
		y_reg[2] = BCD[(ctoi(tracker[read]) * 4) + 2];
		y_reg[3] = BCD[(ctoi(tracker[read]) * 4) + 3];
		for(i = 4; i < 112; i++) {
			y_reg[i] = 0;
		}
		
		binary_add(accum, y_reg);
	}

	/* printf("Binary data 1: ");
	hex_dump(accum); */
	
	/* *** Step 2 - Generation of 11-bit CRC on Binary Data *** */

	accum[103] = 0;
	accum[102] = 0;
	
	memset(byte_array, 0, 13);
	for(j = 0; j < 13; j++) {
		i = 96 - (8 * j);
		byte_array[j] = 0;
		byte_array[j] += accum[i];
		byte_array[j] += 2 * accum[i + 1];
		byte_array[j] += 4 * accum[i + 2];
		byte_array[j] += 8 * accum[i + 3];
		byte_array[j] += 16 * accum[i + 4];
		byte_array[j] += 32 * accum[i + 5];
		byte_array[j] += 64 * accum[i + 6];
		byte_array[j] += 128 * accum[i + 7];
	}
	
	usps_crc = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(byte_array);
	/* printf("FCS 2: %4.4X\n", usps_crc); */
	
	/* *** Step 3 - Conversion from Binary Data to Codewords *** */
	
	/* start with codeword J which is base 636 */
	for(i = 0; i < 112; i++) {
		x_reg[i] = 0;
		y_reg[i] = 0;
	}
	
	x_reg[101] = 1;
	x_reg[98] = 1;
	x_reg[97] = 1;
	x_reg[96] = 1;
	x_reg[95] = 1;
	x_reg[94] = 1;
	
	for(i = 92; i >= 0; i--) {
		y_reg[i] = islarger(accum, x_reg);
		if(y_reg[i] == 1) {
			binary_subtract(accum, x_reg);
		}
		shiftdown(x_reg);
	}
	
	codeword[9] = (accum[9] * 512) + (accum[8] * 256) + (accum[7] * 128) + (accum[6] * 64) +
			(accum[5] * 32) + (accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) +
			(accum[1] * 2) + accum[0];
	
	/* then codewords I to B with base 1365 */
	
	for(j = 8; j > 0; j--) {
		for(i = 0; i < 112; i++) {
			accum[i] = y_reg[i];
			y_reg[i] = 0;
			x_reg[i] = 0;
		}
		x_reg[101] = 1;
		x_reg[99] = 1;
		x_reg[97] = 1;
		x_reg[95] = 1;
		x_reg[93] = 1;
		x_reg[91] = 1;
		for(i = 91; i >= 0; i--) {
			y_reg[i] = islarger(accum, x_reg);
			if(y_reg[i] == 1) {
				binary_subtract(accum, x_reg);
			}
			shiftdown(x_reg);
		}
	
		codeword[j] = (accum[10] * 1024) + (accum[9] * 512) + (accum[8] * 256) +
				(accum[7] * 128) + (accum[6] * 64) + (accum[5] * 32) +
				(accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) +
				(accum[1] * 2) + accum[0];
	}
	
	codeword[0] = (y_reg[10] * 1024) + (y_reg[9] * 512) + (y_reg[8] * 256) +
			(y_reg[7] * 128) + (y_reg[6] * 64) + (y_reg[5] * 32) +
			(y_reg[4] * 16) + (y_reg[3] * 8) + (y_reg[2] * 4) +
			(y_reg[1] * 2) + y_reg[0];
	
	for(i = 0; i < 8; i++) {
		if(codeword[i] == 1365) {
			codeword[i] = 0;
			codeword[i + 1]++;
		}
	}

	/* printf("Codewords  3: ");
	for(i = 0; i < 10; i++) {
		printf("%d ", codeword[i]);
	}
	printf("\n"); */
	
	/* *** Step 4 - Inserting Additional Information into Codewords *** */
	
	codeword[9] = codeword[9] * 2;
	
	if(usps_crc >= 1024) {
		codeword[0] += 659;
	}
	
	/* printf("Codewords 4b: ");
	for(i = 0; i < 10; i++) {
		printf("%d ", codeword[i]);
	}
	printf("\n"); */
	
	/* *** Step 5 - Conversion from Codewords to Characters *** */
	
	for(i = 0; i < 10; i++) {
		if(codeword[i] < 1287) {
			characters[i] = AppxD_I[codeword[i]];
		} else {
			characters[i] = AppxD_II[codeword[i] - 1287];
		}
	}
	
	/* printf("Characters 5a: ");
	for(i = 0; i < 10; i++) {
		printf("%4.4X ", characters[i]);
	}
	printf("\n"); */

	breakup(bit_pattern, usps_crc);

	for(i = 0; i < 10; i++) {
		if(bit_pattern[i] == 1) {
			characters[i] = 0x1FFF - characters[i];
		}
	}
	
	/* printf("Characters 5b: ");
	for(i = 0; i < 10; i++) {
		printf("%4.4X ", characters[i]);
	}
	printf("\n"); */

	/* *** Step 6 - Conversion from Characters to the Intelligent Mail Barcode *** */
	
	for(i = 0; i < 10; i++) {
		breakup(bit_pattern, characters[i]);
		for(j = 0; j < 13; j++) {
			bar_map[AppxD_IV[(13 * i) + j] - 1] = bit_pattern[j];
		}
	}
	
	strcpy(data_pattern, "");
	temp[1] = '\0';
	for(i = 0; i < 65; i++) {
		j = 0;
		if(bar_map[i] == 0)
			j += 1;
		if(bar_map[i + 65] == 0)
			j += 2;
		temp[0] = itoc(j);
		concat(data_pattern, temp);
	}
	
	/* Translate 4-state data pattern to symbol */
	read = 0;
	for(i = 0; i < strlen(data_pattern); i++)
	{
		if((data_pattern[i] == '1') || (data_pattern[i] == '0'))
		{
			set_module(symbol, 0, read);
		}
		set_module(symbol, 1, read);
		if((data_pattern[i] == '2') || (data_pattern[i] == '0'))
		{
			set_module(symbol, 2, read);
		}
		read += 2;
	}

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

	symbol->rows = 3;
	symbol->width = read - 1;
	return error_number;
}
Esempio n. 22
0
int australia_post(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* Handles Australia Posts's 4 State Codes */
	/* Customer Standard Barcode, Barcode 2 or Barcode 3 system determined automatically
	   (i.e. the FCC doesn't need to be specified by the user) dependent
	   on the length of the input string */

	/* The contents of data_pattern conform to the following standard:
	   0 = Tracker, Ascender and Descender
	   1 = Tracker and Ascender
	   2 = Tracker and Descender
	   3 = Tracker only */
	int error_number, zeroes;
	int writer;
	unsigned int loopey, reader, h;

	char data_pattern[200];
	char fcc[3], dpid[10];
	char localstr[30];

	error_number = 0;
        strcpy(localstr, "");
	
	/* Do all of the length checking first to avoid stack smashing */
	if(symbol->symbology == BARCODE_AUSPOST) {
		/* Format control code (FCC) */
		switch(length)
		{
			case 8:
				strcpy(fcc, "11");
				break;
			case 13:
				strcpy(fcc, "59");
				break;
			case 16:
				strcpy(fcc, "59");
				error_number = is_sane(NEON, source, length);
				break;
			case 18:
				strcpy(fcc, "62");
				break;
			case 23:
				strcpy(fcc, "62");
				error_number = is_sane(NEON, source, length);
				break;
			default:
				strcpy(symbol->errtxt, "Auspost input is wrong length");
				return ERROR_TOO_LONG;
				break;
		}
        if(error_number == ERROR_INVALID_DATA1) {
			strcpy(symbol->errtxt, "Invalid characters in data");
			return error_number;
		}
	} else {
		if(length > 8) {
			strcpy(symbol->errtxt, "Auspost input is too long");
			return ERROR_TOO_LONG;
		}
		switch(symbol->symbology) {
			case BARCODE_AUSREPLY: strcpy(fcc, "45"); break;
			case BARCODE_AUSROUTE: strcpy(fcc, "87"); break;
			case BARCODE_AUSREDIRECT: strcpy(fcc, "92"); break;
		}
		
		/* Add leading zeros as required */
		zeroes = 8 - length;
		memset(localstr, '0', zeroes);
		localstr[8] = '\0';
	}

	concat(localstr, (char*)source);
	h = strlen(localstr);
	error_number = is_sane(GDSET, (unsigned char *)localstr, h);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	
	/* Verifiy that the first 8 characters are numbers */
	memcpy(dpid, localstr, 8);
	dpid[8] = '\0';
	error_number = is_sane(NEON, (unsigned char *)dpid, strlen(dpid));
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in DPID");
		return error_number;
	}

	/* Start character */
	strcpy(data_pattern, "13");

	/* Encode the FCC */
	for(reader = 0; reader < 2; reader++)
	{
		lookup(NEON, AusNTable, fcc[reader], data_pattern);
	}

	/* printf("AUSPOST FCC: %s  ", fcc); */

	/* Delivery Point Identifier (DPID) */
	for(reader = 0; reader < 8; reader++)
	{
		lookup(NEON, AusNTable, dpid[reader], data_pattern);
	}

	/* Customer Information */
	if(h > 8)
	{
		if((h == 13) || (h == 18)) {
			for(reader = 8; reader < h; reader++) {
				lookup(GDSET, AusCTable, localstr[reader], data_pattern);
			}
		}
		else if((h == 16) || (h == 23)) {
			for(reader = 8; reader < h; reader++) {
				lookup(NEON, AusNTable, localstr[reader], data_pattern);
			}
		}
	}

	/* Filler bar */
	h = strlen(data_pattern);
	if(h == 22) {
		concat(data_pattern, "3");
	}
	else if(h == 37) {
		concat(data_pattern, "3");
	}
	else if(h == 52) {
		concat(data_pattern, "3");
	}

	/* Reed Solomon error correction */
	rs_error(data_pattern);

	/* Stop character */
	concat(data_pattern, "13");
	
	/* Turn the symbol into a bar pattern ready for plotting */
	writer = 0;
	h = strlen(data_pattern);
	for(loopey = 0; loopey < h; loopey++)
	{
		if((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0'))
		{
			set_module(symbol, 0, writer);
		}
		set_module(symbol, 1, writer);
		if((data_pattern[loopey] == '2') || (data_pattern[loopey] == '0'))
		{
			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;
}
Esempio n. 23
0
int code16k(struct zint_symbol *symbol, uint8_t source[], int length)
{
	char width_pattern[100];
	int current_row, rows_needed, flip_flop, looper, first_check, second_check;
	int indexliste, indexchaine, pads_needed, f_state;
	char set[160] = { ' ' }, fset[160] = { ' ' }, mode, last_set, current_set;
	unsigned int i, j, k, m, read, mx_reader, writer;
	unsigned int values[160] = { 0 };
	unsigned int bar_characters;
	float glyph_count;
	int errornum, first_sum, second_sum;
	int input_length;
	int gs1, c_count;

	errornum = 0;
        strcpy(width_pattern, "");
        input_length = length;

	if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; }

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

	bar_characters = 0;

	/* Detect extended ASCII characters */
	for(i = 0; i <  input_length; i++) {
		if(source[i] >=128) {
			fset[i] = 'f';
		}
	}
	fset[i] = '\0';

	/* Decide when to latch to extended mode */
	for(i = 0; i < input_length; i++) {
		j = 0;
		if(fset[i] == 'f') {
			do {
				j++;
			} while(fset[i + j] == 'f');
			if((j >= 5) || ((j >= 3) && ((i + j) == (input_length - 1)))) {
				for(k = 0; k <= j; k++) {
					fset[i + k] = 'F';
				}
			}
		}
	}

	/* Decide if it is worth reverting to 646 encodation for a few characters */
	if(input_length > 1) {
		for(i = 1; i < input_length; i++) {
			if((fset[i - 1] == 'F') && (fset[i] == ' ')) {
				/* Detected a change from 8859-1 to 646 - count how long for */
				for(j = 0; (fset[i + j] == ' ') && ((i + j) < input_length); j++);
				if((j < 5) || ((j < 3) && ((i + j) == (input_length - 1)))) {
					/* Change to shifting back rather than latching back */
					for(k = 0; k < j; k++) {
						fset[i + k] = 'n';
					}
				}
			}
		}
	}
	/* Detect mode A, B and C characters */
	indexliste = 0;
	indexchaine = 0;

	mode = parunmodd(source[indexchaine]);
	if((gs1) && (source[indexchaine] == '[')) { mode = ABORC; } /* FNC1 */

	for(i = 0; i < 160; i++) {
		list[0][i] = 0;
	}

	do {
		list[1][indexliste] = mode;
		while ((list[1][indexliste] == mode) && (indexchaine < input_length)) {
			list[0][indexliste]++;
			indexchaine++;
			mode = parunmodd(source[indexchaine]);
			if((gs1) && (source[indexchaine] == '[')) { mode = ABORC; } /* FNC1 */
		}
		indexliste++;
	} while (indexchaine < input_length);

	dxsmooth16(&indexliste);

	/* Put set data into set[] */
	read = 0;
	for(i = 0; i < indexliste; i++) {
		for(j = 0; j < list[0][i]; j++) {
			switch(list[1][i]) {
				case SHIFTA: set[read] = 'a'; break;
				case LATCHA: set[read] = 'A'; break;
				case SHIFTB: set[read] = 'b'; break;
				case LATCHB: set[read] = 'B'; break;
				case LATCHC: set[read] = 'C'; break;
			}
			read++;
		}
	}

	/* Adjust for strings which start with shift characters - make them latch instead */
	if(set[0] == 'a') {
		i = 0;
		do {
			set[i] = 'A';
			i++;
		} while (set[i] == 'a');
	}

	if(set[0] == 'b') {
		i = 0;
		do {
			set[i] = 'B';
			i++;
		} while (set[i] == 'b');
	}

	/* Watch out for odd-length Mode C blocks */
	c_count = 0;
	for(i = 0; i < read; i++) {
		if(set[i] == 'C') {
			if(source[i] == '[') {
				if(c_count & 1) {
					if((i - c_count) != 0) {
						set[i - c_count] = 'B';
					} else {
						set[i - 1] = 'B';
					}
				}
				c_count = 0;
			} else {
				c_count++;
			}
		} else {
			if(c_count & 1) {
				if((i - c_count) != 0) {
					set[i - c_count] = 'B';
				} else {
					set[i - 1] = 'B';
				}
			}
			c_count = 0;
		}
	}
	if(c_count & 1) {
		if((i - c_count) != 0) {
			set[i - c_count] = 'B';
		} else {
			set[i - 1] = 'B';
		}
	}
	for(i = 1; i < read - 1; i++) {
		if((set[i] == 'C') && ((set[i - 1] == 'B') && (set[i + 1] == 'B'))) {
			set[i] = 'B';
		}
	}

	/* Make sure the data will fit in the symbol */
	last_set = ' ';
	glyph_count = 0.0;
	for(i = 0; i < input_length; i++) {
		if((set[i] == 'a') || (set[i] == 'b')) {
			glyph_count = glyph_count + 1.0;
		}
		if((fset[i] == 'f') || (fset[i] == 'n')) {
			glyph_count = glyph_count + 1.0;
		}
		if(((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C')) {
			if(set[i] != last_set) {
				last_set = set[i];
				glyph_count = glyph_count + 1.0;
			}
		}
		if(i == 0) {
			if((set[i] == 'B') && (set[1] == 'C')) {
				glyph_count = glyph_count - 1.0;
			}
			if((set[i] == 'B') && (set[1] == 'B')) {
				if(set[2] == 'C') {
					glyph_count = glyph_count - 1.0;
				}
			}
			if(fset[i] == 'F') {
				glyph_count = glyph_count + 2.0;
			}
		} else {
			if((fset[i] == 'F') && (fset[i - 1] != 'F')) {
				glyph_count = glyph_count + 2.0;
			}
			if((fset[i] != 'F') && (fset[i - 1] == 'F')) {
				glyph_count = glyph_count + 2.0;
			}
		}

		if((set[i] == 'C') && (!((gs1) && (source[i] == '[')))) {
			glyph_count = glyph_count + 0.5;
		} else {
			glyph_count = glyph_count + 1.0;
		}
	}

	if((gs1) && (set[0] != 'A')) {
		/* FNC1 can be integrated with mode character */
		glyph_count--;
	}

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

	/* Calculate how tall the symbol will be */
	glyph_count = glyph_count + 2.0;
	i = glyph_count;
	rows_needed = (i/5);
	if(i%5 > 0) { rows_needed++; }

	if(rows_needed == 1) {
		rows_needed = 2;
	}

	/* start with the mode character - Table 2 */
	m = 0;
	switch(set[0]) {
		case 'A': m = 0; break;
		case 'B': m = 1; break;
		case 'C': m = 2; break;
	}

	if(symbol->output_options & READER_INIT) {
		if(m == 2) { m = 5; }
		if(gs1) {
			strcpy(symbol->errtxt, "Cannot use both GS1 mode and Reader Initialisation");
			return ZERROR_INVALID_OPTION;
		} else {
			if((set[0] == 'B') && (set[1] == 'C')) { m = 6; }
		}
		values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */
		values[bar_characters + 1] = 96; /* FNC3 */
		bar_characters += 2;
	} else {
		if(gs1) {
			/* Integrate FNC1 */
			switch(set[0]) {
				case 'B': m = 3; break;
				case 'C': m = 4; break;
			}
		} else {
			if((set[0] == 'B') && (set[1] == 'C')) { m = 5; }
			if(((set[0] == 'B') && (set[1] == 'B')) && (set[2] == 'C')) { m = 6; }
		}
		values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */
		bar_characters++;
	}

	current_set = set[0];
	f_state = 0; /* f_state remembers if we are in Extended ASCII mode (value 1) or
	in ISO/IEC 646 mode (value 0) */
	if(fset[0] == 'F') {
		switch(current_set) {
			case 'A':
				values[bar_characters] = 101;
				values[bar_characters + 1] = 101;
				break;
			case 'B':
				values[bar_characters] = 100;
				values[bar_characters + 1] = 100;
				break;
		}
		bar_characters += 2;
		f_state = 1;
	}

	read = 0;

	/* Encode the data */
	do {

		if((read != 0) && (set[read] != set[read - 1]))
		{ /* Latch different code set */
			switch(set[read])
			{
				case 'A':
					values[bar_characters] = 101;
					bar_characters++;
					current_set = 'A';
					break;
				case 'B':
					values[bar_characters] = 100;
					bar_characters++;
					current_set = 'B';
					break;
				case 'C':
					if(!((read == 1) && (set[0] == 'B'))) { /* Not Mode C/Shift B */
						if(!((read == 2) && ((set[0] == 'B') && (set[1] == 'B')))) {
							/* Not Mode C/Double Shift B */
							values[bar_characters] = 99;
							bar_characters++;
						}
					}
					current_set = 'C';
					break;
			}
		}
		/* printf("tp8\n"); */
		if(read != 0) {
			if((fset[read] == 'F') && (f_state == 0)) {
				/* Latch beginning of extended mode */
				switch(current_set) {
					case 'A':
						values[bar_characters] = 101;
						values[bar_characters + 1] = 101;
						break;
					case 'B':
						values[bar_characters] = 100;
						values[bar_characters + 1] = 100;
						break;
				}
				bar_characters += 2;
				f_state = 1;
			}
			if((fset[read] == ' ') && (f_state == 1)) {
				/* Latch end of extended mode */
				switch(current_set) {
					case 'A':
						values[bar_characters] = 101;
						values[bar_characters + 1] = 101;
						break;
					case 'B':
						values[bar_characters] = 100;
						values[bar_characters + 1] = 100;
						break;
				}
				bar_characters += 2;
				f_state = 0;
			}
		}

		if((fset[i] == 'f') || (fset[i] == 'n')) {
			/* Shift extended mode */
			switch(current_set) {
				case 'A':
					values[bar_characters] = 101; /* FNC 4 */
					break;
				case 'B':
					values[bar_characters] = 100; /* FNC 4 */
					break;
			}
			bar_characters++;
		}

		if((set[i] == 'a') || (set[i] == 'b')) {
			/* Insert shift character */
			values[bar_characters] = 98;
			bar_characters++;
		}

		if(!((gs1) && (source[read] == '['))) {
			switch(set[read])
			{ /* Encode data characters */
				case 'A':
				case 'a':
					c16k_set_a(source[read], values, &bar_characters);
					read++;
					break;
				case 'B':
				case 'b':
					c16k_set_b(source[read], values, &bar_characters);
					read++;
					break;
				case 'C': c16k_set_c(source[read], source[read + 1], values, &bar_characters);
					read += 2;
					break;
			}
		} else {
			values[bar_characters] = 102;
			bar_characters++;
			read++;
		}
		/* printf("tp9 read=%d surrent set=%c\n", read, set[read]); */
	} while (read < ustrlen(source));

	pads_needed = 5 - ((bar_characters + 2) % 5);
	if(pads_needed == 5) {
		pads_needed = 0;
	}
	if((bar_characters + pads_needed) < 8) {
		pads_needed += 8 - (bar_characters + pads_needed);
	}
	for(i = 0; i < pads_needed; i++) {
		values[bar_characters] = 106;
		bar_characters++;
	}

	/* Calculate check digits */
	first_sum = 0;
	second_sum = 0;
	for(i = 0; i < bar_characters; i++)
	{
		first_sum += (i+2) * values[i];
		second_sum += (i+1) * values[i];
	}
	first_check = first_sum % 107;
	second_sum += first_check * (bar_characters + 1);
	second_check = second_sum % 107;
	values[bar_characters] = first_check;
	values[bar_characters + 1] =  second_check;
	bar_characters += 2;

	for(current_row = 0; current_row < rows_needed; current_row++) {

		strcpy(width_pattern, "");
		concat(width_pattern, C16KStartStop[C16KStartValues[current_row]]);
		concat(width_pattern, "1");
		for(i = 0; i < 5; i++) {
			concat(width_pattern, C16KTable[values[(current_row * 5) + i]]);
			/* printf("[%d] ", values[(current_row * 5) + i]); */

		}
		concat(width_pattern, C16KStartStop[C16KStopValues[current_row]]);
		/* printf("\n"); */

		/* Write the information into the symbol */
		writer = 0;
		flip_flop = 1;
		for (mx_reader = 0; mx_reader < strlen(width_pattern); mx_reader++) {
			for(looper = 0; looper < ctoi(width_pattern[mx_reader]); looper++) {
				if(flip_flop == 1) {
					set_module(symbol, current_row, writer);
					writer++; }
				else {
					writer++; }
			}
			if(flip_flop == 0) { flip_flop = 1; } else { flip_flop = 0; }
		}
		symbol->row_height[current_row] = 10;
	}

	symbol->rows = rows_needed;
	symbol->width = 70;
	return errornum;
}
Esempio n. 24
0
/* This is a callback procedure for lib$get_index */
static int
VMS_get_member_info(struct dsc$descriptor_s *module, unsigned long *rfa)
{
  int status, i;
  const int truncated = 0; /* Member name may be truncated */
  time_t member_date; /* Member date */
  char *filename;
  unsigned int buffer_length; /* Actual buffer length */

  /* Unused constants - Make does not actually use most of these */
  const int file_desc = -1; /* archive file descriptor for reading the data */
  const int header_position = 0; /* Header position */
  const int data_position = 0; /* Data position in file */
  const int data_size = 0; /* Data size */
  const int uid = 0; /* member gid */
  const int gid = 0; /* member gid */
  const int mode = 0; /* member protection mode */
  /* End of unused constants */

  static struct dsc$descriptor_s bufdesc =
    { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL };

  /* Only need the module definition */
  struct mhddef *mhd;

  /* If a previous callback is non-zero, just return that status */
  if (VMS_function_ret)
    {
      return SS$_NORMAL;
    }

  /* lbr_set_module returns more than just the module header. So allocate
     a buffer which is big enough: the maximum LBR$C_MAXHDRSIZ. That's at
     least bigger than the size of struct mhddef.
     If the request is too small, a buffer truncated warning is issued so
     it can be reissued with a larger buffer.
     We do not care if the buffer is truncated, so that is still a success. */
  mhd = xmalloc(LBR$C_MAXHDRSIZ);
  bufdesc.dsc$a_pointer = (char *) mhd;
  bufdesc.dsc$w_length = LBR$C_MAXHDRSIZ;

  status = lbr$set_module(&VMS_lib_idx, rfa, &bufdesc, &buffer_length, 0);

  if ((status != LBR$_HDRTRUNC) && !$VMS_STATUS_SUCCESS(status))
    {
      ON(error, NILF,
          _("lbr$set_module() failed to extract module info, status = %d"),
          status);

      lbr$close(&VMS_lib_idx);

      return status;
    }

#ifdef TEST
  /* When testing this code, it is useful to know the length returned */
  printf("Input length = %d, actual = %d\n",
      bufdesc.dsc$w_length, buffer_length);
#endif

  /* Conversion from VMS time to C time.
     VMS defectlet - mhddef is sub-optimal, for the time, it has a 32 bit
     longword, mhd$l_datim, and a 32 bit fill instead of two longwords, or
     equivalent. */
  member_date = vms_time_to_unix(&mhd->mhd$l_datim);
  free(mhd);

  /* Here we have a problem.  The module name on VMS does not have
     a file type, but the filename pattern in the "VMS_saved_arg"
     may have one.
     But only the method being called knows how to interpret the
     filename pattern.
     There are currently two different formats being used.
     This means that we need a VMS specific code in those methods
     to handle it. */
  filename = xmalloc(module->dsc$w_length + 1);

  /* TODO: We may need an option to preserve the case of the module
     For now force the module name to lower case */
  for (i = 0; i < module->dsc$w_length; i++)
    filename[i] = _tolower((unsigned char )module->dsc$a_pointer[i]);

  filename[i] = '\0';

  VMS_function_ret = (*VMS_function)(file_desc, filename, truncated,
      header_position, data_position, data_size, member_date, uid, gid, mode,
      VMS_saved_arg);

  free(filename);
  return SS$_NORMAL;
}
Esempio n. 25
0
int main(int arg, char *args[])
{
    set_folder_template();
    if(args[1]!=NULL)
    {
        printf("Projeto: %s \n",args[1]);
        if(args[2]!=NULL && verified_folder(args[1]))
        {
            path = args[1];
            printf("Namespace: %s\n",args[2]);
            int verified = verified_namespace(args[2]);
            if(verified==1)
            {
                name_space = args[2];
                printf("criando pasta do modulo \n");
                if(create_folder(args[3]))
                {
                    module = args[3];
                    printf("pasta criada \n");
                    char* option;
                    scanf("tipo do modulo %s\n",&option);
                    printf("%s\n",option);
                }
                else
                {
                    printf("erro ao criar o folder \n");
                }
            }
            else
            {
                printf("não existe namespace com esse nome \n ");
                if(args[2]!=NULL && verified == 0)
                {
                    printf("criando o namespace \n");
                    if(create_folder(args[2]))
                    {
                        name_space = args[2];
                        chdir(args[2]);
                        printf("criando pasta do modulo \n");
                        if(create_folder(args[3]))
                        {
                            printf("pasta criada \n");
                            chdir(args[3]);
                            set_module(args[3]);
                            printf("selecione a opção de módulo que você deseja\n");
                            printf("1. simples(etc/config.xml, diretório controller e Block ).\n2. básico (todos os diretórios e também o arquivo de configuração). \n");
                            int option;
                            printf("escolha o tipo do módulo:\n");
                            scanf("%d",&option);
                            printf("opção escolhida %d\n",option);
                            printf("criando template");
                            create_template(option);
                        }
                        else
                        {
                            printf("erro ao criar o folder \n");
                        }
                    }else{
                        printf("erro ao criar o namespace \n");
                    }
                }else{
                    printf("verifique a estrutura de seu projeto \n");
                }

            }
        }
        else
            printf("Nenhum namespace foi  especificado \n");
    }
    else
    {
        printf("Nenhum Projeto foi especificado \n");
    }
    return 0;
}
Esempio n. 26
0
static int
VMS_get_member_info (struct dsc$descriptor_s *module, unsigned long *rfa)
{
  int status, i;
  long int fnval;

  time_t val;

  static struct dsc$descriptor_s bufdesc =
    { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL };

  struct mhddef *mhd;
  char filename[128];

  bufdesc.dsc$a_pointer = filename;
  bufdesc.dsc$w_length = sizeof (filename);

  status = lbr$set_module (&VMS_lib_idx, rfa, &bufdesc,
                           &bufdesc.dsc$w_length, 0);
  if (! (status & 1))
    {
      ON (error, NILF,
          _("lbr$set_module() failed to extract module info, status = %d"),
          status);

      lbr$close (&VMS_lib_idx);

      return 0;
    }

  mhd = (struct mhddef *) filename;

#ifdef __DECC
  /* John Fowler <*****@*****.**> writes this is needed in his environment,
   * but that decc$fix_time() isn't documented to work this way.  Let me
   * know if this causes problems in other VMS environments.
   */
  {
    /* Modified by M. Gehre at 11-JAN-2008 because old formula is wrong:
     * val = decc$fix_time (&mhd->mhd$l_datim) + timezone - daylight*3600;
     * a) daylight specifies, if the timezone has daylight saving enabled, not
     *    if it is active
     * b) what we need is the information, if daylight saving was active, if
     *    the library module was replaced. This information we get using the
     *    localtime function
     */

    struct tm *tmp;

    /* Conversion from VMS time to C time */
    val = decc$fix_time (&mhd->mhd$l_datim);

    /*
     * Conversion from local time (stored in library) to GMT (needed for gmake)
     * Note: The tm_gmtoff element is a VMS extension to the ANSI standard.
     */
    tmp = localtime (&val);
    val -= tmp->tm_gmtoff;
  }
#endif

  for (i = 0; i < module->dsc$w_length; i++)
    filename[i] = _tolower ((unsigned char)module->dsc$a_pointer[i]);

  filename[i] = '\0';

  VMS_member_date = (time_t) -1;

  fnval =
    (*VMS_function) (-1, filename, 0, 0, 0, 0, val, 0, 0, 0,
                     VMS_saved_memname);

  if (fnval)
    {
      VMS_member_date = fnval;
      return 0;
    }
  else
    return 1;
}