?? main.c
字號:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <fcntl.h>#ifdef WIN32#include "getopt.h"#else#ifdef __FreeBSD__#include <unistd.h>#else#include <getopt.h>#endif#endif#include <errno.h>#include "globs.h"#include "pdf417_enc.h"#include "main.h"void Usage (void){ fprintf (stderr, "Usage: pdf417_enc [-t type] [-r nrows] [-c ncols] [-e ec_level]\n"); fprintf (stderr, " [-xX] [-yY] [-qQ] infile outfile\n");#ifdef DO_GIFS fprintf (stderr, "\tValid types are: gif, pbm, ps, eps, raw\n");#else fprintf (stderr, "\tValid types are: pbm, ps, eps, raw\n");#endif /* DO_GIFS */ fprintf (stderr, "\tDefault type is eps\n\n"); fprintf (stderr, "\tDefault nrows = auto (999)\n"); fprintf (stderr, "\tDefault ncols = 8\n"); fprintf (stderr, "\tDefault ec_level 5\n\n"); fprintf (stderr, "\t-x, -y -q options are only applicable to PS/EPS otuput:\n"); fprintf (stderr, "\tX is integer module width in mils, default 10.\n"); fprintf (stderr, "\tY is integer multiplier of X as row height, default 3.\n"); fprintf (stderr, "\tQ is integer multiplier of X for quiet zone width, default 2.\n\n"); fprintf (stderr,"\tinfile is stdin if omitted or given as a - (dash).\n"); fprintf (stderr,"\toutfile is stdout if omitted or given as a - (dash).\n\n");}intmain (int argc, char **argv){ int test_mode; int test_ecc_mode; char rowstring[128]; char colstring[128]; char ec_string[128]; int debug; int use_def; int rval; int cval; int output_type = 0; int option_args = 0; int ch; /* these are PS/EPS only */ int Xwid = 10; // default module wid, 10 mils. int Ydim = 3; // default row height, multiple of Xwid int qz = 2; // default quiet zone, multiple of Xwid debug = 0; digit_table_valid = FALSE; /* base 900 table for numeric_compress */ if (debug) { printf ("In main \n"); } quotchar = 34; codeindex = 0; test_mode = 0; test_ecc_mode = 0; /* default cols, rows, and ec_level */ cval = 8; rval = 999 /*24*/; ec_level = 5; pdf417_init_arrays (); /* default stdin, stdout */ input_filename = output_filename = NULL; /* process getopt commandline arguments */ while ((ch = getopt (argc, argv, "c:r:e:t:x:y:q:h")) != -1) { switch (ch) { case 'c': cval = atoi (optarg); break; case 'r': rval = atoi (optarg); break; case 'e': ec_level = atoi(optarg); if (ec_level > 8 || ec_level < 1) { fprintf (stderr,"Error Correction level shouldbe be from 1 to 8\n"); fprintf (stderr,"using Error Correction level 5.\n"); ec_level = 5; } break; case 't': if (strcasecmp ("pbm", optarg) == 0) output_type = OUTPUT_PBM; else if (strcasecmp ("ps", optarg) == 0) output_type = OUTPUT_PS; else if (strcasecmp ("psbits", optarg) == 0) output_type = OUTPUT_PS_BITS; else if (strcasecmp ("raw", optarg) == 0) output_type = OUTPUT_RAW; else if (strcasecmp ("eps", optarg) == 0) output_type = OUTPUT_EPS;#ifdef DO_GIFS else if (strcasecmp ("gif", optarg) == 0) output_type = OUTPUT_GIF;#endif /* DO_GIFS */ else { Usage (); exit (1); } break; case 'x': Xwid = atoi(optarg); if (Xwid <= 0) Xwid = 10; if (Xwid < 10) fprintf (stderr, "Warning: module width %d mils may be too small\n", Xwid); break; case 'y': Ydim = atoi(optarg); if (Ydim <= 0) Ydim = 3; break; case 'q': qz = atoi(optarg); if (qz <= 0) qz = 2; break; default: Usage (); exit (0); } } /* optional input file name */ if ((argc - optind) > 0) { if ( strncmp("_", argv[optind], 1) != 0) input_filename = strdup (argv[optind]); optind++; } /* optional output file name */ if ((argc - optind) > 0) { if ( strncmp("_", argv[optind], 1) != 0) output_filename = strdup (argv[optind]); optind++; } use_def = TRUE; if (debug) { printf ("Argc = %d \n", argc); } /* validate row/col numbers */ if ((rval > 2) && (rval < 91)) { if ((cval > 0) && (cval < 31)) { use_def = FALSE; number_of_rows = rval; number_of_columns = cval; } else { printf (" Columns must be between 1 and 30, inclusive.\n"); exit (1); } } else { if (rval != 999) { printf ("Rows must be between 3 and 90, inclusive.\n"); exit (1); } else // rval = 999 { if ((cval > 0) && (cval < 31)) { use_def = FALSE; // number of rows to calculated later number_of_columns = cval; } else { printf (" Columns must be between 1 and 30, inclusive.\n"); exit (1); } } }#if 0 if (argc - option_args > 3) { if (argc - option_args < 6) { strcpy (rowstring, argv[option_args + 3]); strcpy (colstring, argv[option_args + 4]); rval = atoi (rowstring); cval = atoi (colstring); if (debug) { printf ("Col = %d row = %d \n", rval, cval); } if ((rval > 0) && (rval < 90)) { if ((cval > 0) && (cval < 30)) { use_def = FALSE; number_of_rows = rval; number_of_columns = cval; } else { printf (" Columns must be less than 30 \n"); exit (0); } } else { if (rval != 999) { printf ("Rows must be less that 90 \n"); exit (0); } else // rval = 999 { if ((cval > 0) && (cval < 30)) { use_def = FALSE; // number of rows to calculated later number_of_columns = cval; } else { printf (" Columns must be less than 30 \n"); exit (0); } } } } if (argc - option_args == 6) { strcpy (rowstring, argv[option_args + 3]); strcpy (colstring, argv[option_args + 4]); strcpy (ec_string, argv[option_args + 5]); if (debug) { printf ("rowstring = %s colstring = %s ec_string = %s \n", rowstring, colstring, ec_string); } rval = atoi (rowstring); cval = atoi (colstring); ec_level = atoi (ec_string); if (debug) { printf ("ec_level = %d \n", ec_level); } if (ec_level > 8) { printf ("Error: Error correction level > 8 not supported \n"); printf ("Error correction level defaulting to 5 \n"); ec_level = 5; } if (ec_level < 1) { printf ("Error: Error correction level should be from 1 to 8 \n"); printf ("Error correction defaulted to 5 \n"); ec_level = 5; } if (debug) { printf ("Col = %d row = %d \n", rval, cval); } if ((rval > 0) && (rval < 90)) { if ((cval > 0) && (cval < 30)) { use_def = FALSE; number_of_rows = rval; number_of_columns = cval; } else { printf (" Columns must be less than 30 \n"); exit (0); } } else { if (rval != 999) { printf ("Rows must be less thatn 90 \n"); exit (0); } else { if ((cval > 0) && (cval < 30)) { use_def = FALSE; // number of rows to calculated later number_of_columns = cval; } else { printf (" Columns must be less than 30 \n"); exit (0); } } } } }#endif // test_ecc(); if (test_mode) { test_text_comp (); test_byte_compact (); test_nc (); test_ecc (); } if (test_ecc_mode) { test_ecc (); exit (0); }// do the code to generate barcode pdf417_en_new (rval, cval, ec_level, output_type, use_def, FALSE, Xwid, Ydim, qz);} /* end main */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -