⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maxicode.c

📁 This is program with source code to convert ascii text files to the maxicode barcode standard.
💻 C
📖 第 1 页 / 共 5 页
字号:
 #include <stdio.h> #include <stdlib.h> //#include <unistd.h> #include <string.h> #include <sys/stat.h> #include <fcntl.h> #include <getopt.h> #include <errno.h> #include <fcntl.h>#define	CLEAR(a,n) {\int ci;\for(ci=(n)-1;ci >=0;ci--)\(a)[ci] = 0;\}#define	COPY(a,b,n) {\int ci;\for(ci=(n)-1;ci >=0;ci--)\(a)[ci] = (b)[ci];\}#define	COPYDOWN(a,b,n) {\int ci;\for(ci=(n)-1;ci >=0;ci--)\(a)[ci] = (b)[ci];\} #define min(a,b)        ((a) < (b) ? (a) : (b)) /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; */ /* The maxicode_encode program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library  Public License for more details.  */ /* usage:      maxi_encode infile outfile */ /* the infile and outfile args are required and specify the input and */ /* output files respectively.  The optional rows and cols arguments */ /*                                        */ /* Authors: John Lien (jtlien@charter.net) */ /*          /* Revisions:  1.0    1/31/02     Initial release */ #include <ctype.h> typedef int Int32; typedef unsigned int UInt32; typedef unsigned long long UInt64; typedef short Int16; #include "iso.h"   // iso country codes data base #define NULLCHAR 0 #define TC 0 #define NC 1 #define BC 2 #define PC 3 #define CC 4 #define SC 5 #define MO 6 #define PM 7 #define SM 8 #define PS 9  #define CR 13 #define HT 9 #define LF 10 #define FS 28 #define GS 29 #define RS 30 #define BACKSLASH 92 #define MM 6 #define B0 1/* Primitive polynomials - see Lin & Costello, Appendix A, * and  Lee & Messerschmitt, p. 453. */#if(MM == 2)/* Admittedly silly */int Pp[MM+1] = { 1, 1, 1 };#elif(MM == 3)/* 1 + x + x^3 */int Pp[MM+1] = { 1, 1, 0, 1 };#elif(MM == 4)/* 1 + x + x^4 */int Pp[MM+1] = { 1, 1, 0, 0, 1 };#elif(MM == 5)/* 1 + x^2 + x^5 */int Pp[MM+1] = { 1, 0, 1, 0, 0, 1 };#elif(MM == 6)/* 1 + x + x^6 */int Pp[MM+1] = { 1, 1, 0, 0, 0, 0, 1 };#elif(MM == 7)/* 1 + x^3 + x^7 */int Pp[MM+1] = { 1, 0, 0, 1, 0, 0, 0, 1 };#elif(MM == 8)/* 1+x^2+x^3+x^4+x^8 */int Pp[MM+1] = { 1, 0, 1, 1, 1, 0, 0, 0, 1 };#elif(MM == 9)/* 1+x^4+x^9 */int Pp[MM+1] = { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 };#elif(MM == 10)/* 1+x^3+x^10 */int Pp[MM+1] = { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 };#elif(MM == 11)/* 1+x^2+x^11 */int Pp[MM+1] = { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };#elif(MM == 12)/* 1+x+x^4+x^6+x^12 */int Pp[MM+1] = { 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 };#elif(MM == 13)/* 1+x+x^3+x^4+x^13 */int Pp[MM+1] = { 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };#elif(MM == 14)/* 1+x+x^6+x^10+x^14 */int Pp[MM+1] = { 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 };#elif(MM == 15)/* 1+x+x^15 */int Pp[MM+1] = { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };#elif(MM == 16)/* 1+x+x^3+x^12+x^16 */int Pp[MM+1] = { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 };#else#error " MM must be set in range 2-16"#endif #define	NN ((1 << MM) - 1) #define PRIM 1 #define GPRIME 64 #define KK 32 #define A0 63 #define Ldec 1 #define SHIFTA_B  59 #define SHIFTA_C  60 #define SHIFTA_D  61 #define SHIFTA_E  62 #define SHIFTB_A  59 #define SHIFTB_C  60 #define SHIFTB_D  61 #define SHIFTB_E  62 #define LATCHA_B  63 #define LATCHB_A  63 #define LATCHC_B  63 #define LATCHD_B  63 #define LATCHC_A  58 #define LATCHD_A  58 #define LATCHE_A  58 #define LOCKIN_C  60 #define LOCKIN_D  61 #define LOCKIN_E  62 #define SHIFTC_D  61 #define SHIFTC_E  62 #define SHIFTD_C  60 #define SHIFTD_E  62 #define SHIFTE_C  60 #define SHIFTE_D  61 #define NUMERIC_SH 31 #define ECI_SH     27 #define SHIFT_TWO_BA 56 #define SHIFT_THREE_BA 57// galois group for error correctionstatic int Gg[NN-KK+1]; // // Galois field 2^6 generated by 1 + x +  x^6 // //  binary value at index = log of index // static int bin_expgood[] = // binary_to polynomial power ( log) {     63,    // infinity      0,    // 1      1,    // 2      6,    // 3      2,    // 4      12,   // 5      7,    // 6      26,   // 7      3,    // 8      32,   // 9      13,   // 10      35,   // 11      8,    // 12      48,   // 13      27,   // 14      18,   // 15      4,    // 16      24,   // 17      33,   // 18      16,   // 19      14,   // 20      52,   // 21      36,   // 22      54,   // 23      9,    // 24      45,   // 25      49,   // 26      38,   // 27      28,   // 28      41,   // 29      19,   // 30      56,   // 31      5,    // 32      62,   // 33      25,   // 34      11,   // 35      34,   // 36      31,   // 37      17,   // 38      47,   // 39      15,   // 40      23,   // 41      53,   // 42      51,   // 43      37,   // 44      44,   // 45      55,   // 46      40,   // 47      10,   // 48      61,   // 49      46,   // 50      30,   // 51      50,   // 52      22,   // 53      39,   // 54      43,   // 55      29,   // 56      60,   // 57      42,   // 58      21,   // 59      20,   // 60      59,   // 61      57,   // 62      58    // 63    }; // // Galois field 2^6 generated by 1 + x +  x^6 // // x^ (index) = binary value at index // static int exp_bingood[] = // polynomial power to binary ( antilog) {          1,      2,      4,      8,      16,      32,      3,      6,      12,      24,      48,      35,      5,      10,      20,      40,      19,      38,      15,      30,      60,      59,      53,      41,      17,      34,      7,      14,      28,      56,      51,      37,      9,      18,      36,      11,      22,      44,      27,      54,      47,      29,      58,      55,      45,      25,      50,      39,      13,      26,      52,      43,      21,      42,      23,      46,      31,      62,      63,      61,      57,      49,      33,       0};int code_array[150];   // array to keep the raw codes each < 64int out_code_array[150];   // array to keep the codes to put into hexagonsint sec_code_array[150];   // code array for the secondary messagedouble shape_0_width;double shape_0_hwidth;double shape_1_width;double shape_2_width;double shape_0_height;double shape_1_height;double shape_2_height;double shape_0h_width;double row_height;char service_class_str[10];int Alpha_to[1024];int Index_of[1024];int mode;int postal_code;int postal_code_flag;int country_code_flag;int service_class_flag;static int RS_init;int country_code;int special;        // indicate a special message, no secondary neededchar mode_str[64];char postal_code_str[32];char country_code_str[256];char primary_message_str[256];  // primary message, if not mode 2,3char primary_smessage_str[256];  // special primary message                                 // this has form year space// postal code space country code space service class space rest of messagechar secondary_message_str[512];  //secondary message strint digit_table_valid;char opstring[256];int row;char quotchar;int digit_vals[50][16];   /* base 900 values for 1, 10, 100, 1000 .. 10^45 */int end_of_file;int linenum;  /* line of input file */int linechar;  /* index to char in input line */char inline_str[120];int eras_pos[128];       /* erasure positions, for ecc testing */int no_eras;FILE *infile1, *outfile1;// FILE *outfile1;#define TRUE 1#define FALSE 0#define PDF417_START 0x1fea8#define PDF417_STOP  0x1fd14Int32 *out;int ecclen;int mods_10[32];int mods_28[64];int mods_20[64];// int powers_of_2[1024];int log_of_2[1024];int ecc_results[124];int  erase_posit[2048];    /* used to indicate erasures */int  synd_array[2048];int global;int non_append;         // not a structured appendint append_count;       // number of appended symbolsint code_length;UInt32 data[3000];      /* this is the array of data, ecc will be added */                          /* this will be x rows of y columns where */                          /* y = number_of_columns - 2; */  UInt32 rows_columns[90][32];  /* rectangle of rows, columns */				/* max 90 rows, max 32 columns */          int number_of_rows;  int number_of_columns;    /* number of total columns = left, data, right */  int ec_level;      int eclen;       /* number of bytes in ecc */  int prim_codeindex;   int sec_codeindex;  int secondary_msg;  int codeindex;  int codes[3000];    /* put_back array */ int set_debug;  void put_back(int inval )  {  int debug;  debug = 0;    if (debug)      { printf("Code = %d prim_codeindex = %d \n",inval,prim_codeindex); }    if (debug)       { printf("Code = %d sec_codeindex = %d \n",inval,sec_codeindex); }       if ( secondary_msg == FALSE)        {         if ( prim_codeindex < 11)          {           code_array[prim_codeindex] = inval;                  prim_codeindex += 1;          }         else	   {	     printf("Primary message too long \n");           }        }    else      {       if ( sec_codeindex < 104)        {         sec_code_array[sec_codeindex] = inval;                sec_codeindex += 1;        }       else	 {	   printf("Secondary message too long \n");         }      }  }  /* put back */#define BITMASK 0x3F  void generateEC( UInt32 *data, UInt32 len, UInt32 EClen)  {      UInt32 base_reg[80];       UInt32 coeff_reg[80];      int i,j;      int tint;      UInt32 temp;      UInt32 wrap;      UInt32 t1;      int debug;          debug = 0;      if (debug)        {          printf("In generateEC - len = %d EClen = %d \n", len, EClen);        }      for(i=0; i < len; i += 1)	{	  if (debug) { printf("Data in = %d %d \n",i, data[i]); }        }      if (debug)	{         printf(" In generateEC - data length = %d \n",len);         printf(" In generateEC - ECC length = %d \n",EClen);        }      /* get the coefficients */      if ( EClen == 20)       {        for (i = 0; i < EClen; i +=1)	 {	  coeff_reg[i] = mods_20[i+1];          if (debug) { printf("Set coeff_reg %d to %d \n", i, coeff_reg[i]); }	 }       }      if ( EClen == 28)       {        for (i = 0; i < EClen; i +=1)	 {	  coeff_reg[i] = mods_28[i+1];          if (debug) { printf("Set coeff_reg %d to %d \n", i, coeff_reg[i]); }	 }       }      if ( EClen == 10)       {        for (i = 0; i < EClen; i +=1)	 {	  coeff_reg[i] = mods_10[i+1];          if (debug) { printf("Set coeff_reg %d to %d \n", i, coeff_reg[i]); }	 }       }          /* initialize b regs */      for (i = 0; i < EClen; i +=1)	{	  base_reg[i]=0;	}      /* Initialize ecc result data */      for (i=len; i < len + EClen; i += 1)	{	 data[i] = 0;	}      /* Load up with data */      for(i=0;i<len;++i) {           	wrap = (base_reg[EClen-1] ^ data[i]) & BITMASK;	  for (j=EClen-1; j > 0; j = j-1)	    {             temp = poly_mult(coeff_reg[EClen-1-j], wrap) & BITMASK;	     base_reg[j] = (base_reg[j-1] ^ temp) & BITMASK;	    }          temp = poly_mult(coeff_reg[EClen-1], wrap) & BITMASK;	  // temp = (temp ^ BITMASK) & BITMASK;	  base_reg[0]= temp;      }      /* Read off the info */      for (j = 0; j < EClen; j += 1)	{          if (debug) {            printf("Adding ECC byte %d = %d \n",j,base_reg[EClen-1-j]); }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -