int loc_counter(FILE *fp) { int i = 0, count = 0, ret = 0; char buff[BUFF_SIZE] = {'\0', }; char trim_buff[BUFF_SIZE] = {'\0', }; if (fp == NULL) return -1; while (!feof(fp)) { // Initialization memset(buff, '\0', BUFF_SIZE); memset(trim_buff, '\0', BUFF_SIZE); // Read one line ret = fscanf(fp, "%[^\n]", buff); fgetc(fp); // Trim rtrim(trim_buff, buff) == NULL; printf("= %s", trim_buff); // Check LOC if (0 <= (ret = check_loc(trim_buff, BUFF_SIZE))) count++; } return count; }
static inline int check_symbol (const zbar::Image &img, const zbar::Symbol &sym) { zbar::zbar_symbol_type_t type(sym.get_type()); std::string data(sym.get_data()); bool pass = expect_type && type == expect_type && data == expect_data && sym.get_data_length() == expect_data.length() && sym.get_quality() > 4; if(pass) pass = !check_loc(img, sym); if(verbose || !pass) std::cerr << "decode Symbol: " << sym << std::endl; if(!expect_type) error("unexpected"); else if(!pass) error(std::string("expected: ") + zbar::zbar_get_symbol_name(expect_type) + " " + expect_data); expect_type = zbar::ZBAR_NONE; expect_data = ""; return(!pass); }
/* * print_all_info(): Print out all the locales and * charmaps supported by the system */ static void print_all_info(int flag) { struct dirent *direntp; DIR *dirp; char *filename; /* filename[PATH_MAX] */ char *p; if ((filename = malloc(PATH_MAX)) == NULL) { (void) fprintf(stderr, gettext("locale: cannot allocate buffer")); exit(1); } (void) memset(filename, 0, PATH_MAX); if (flag == GET_LOCALE) { /* save the current locale */ save_loc = setlocale(LC_ALL, NULL); (void) strcpy(filename, LOCALE_DIR); add_loc_entry("POSIX"); } else { /* CHARMAP */ (void) strcpy(filename, CHARMAP_DIR); } if ((dirp = opendir(filename)) == NULL) { if (flag == GET_LOCALE) exit(0); else { /* CHARMAP */ (void) fprintf(stderr, gettext( "locale: charmap information not available.\n")); exit(2); } } p = filename + strlen(filename); while ((direntp = readdir(dirp)) != NULL) { struct stat stbuf; (void) strcpy(p, direntp->d_name); if (stat(filename, &stbuf) < 0) { continue; } if (flag == GET_LOCALE) { if (S_ISDIR(stbuf.st_mode) && (direntp->d_name[0] != '.') && /* "POSIX" has already been printed out */ strcmp(direntp->d_name, "POSIX") != 0) { check_loc(direntp->d_name); } } else { /* CHARMAP */ if (S_ISDIR(stbuf.st_mode) && direntp->d_name[0] != '.') { struct dirent *direntc; DIR *dirc; char *charmap; char *c; if ((charmap = malloc(PATH_MAX)) == NULL) { (void) fprintf(stderr, gettext("locale: cannot allocate buffer")); exit(1); } (void) memset(charmap, 0, PATH_MAX); (void) strcpy(charmap, filename); if ((dirc = opendir(charmap)) == NULL) { exit(0); } c = charmap + strlen(charmap); *c++ = '/'; while ((direntc = readdir(dirc)) != NULL) { struct stat stbuf; (void) strcpy(c, direntc->d_name); if (stat(charmap, &stbuf) < 0) { continue; } if (S_ISREG(stbuf.st_mode) && (strcmp(direntc->d_name, CHARMAP_NAME) == 0) && (direntc->d_name[0] != '.')) { (void) printf("%s/%s\n", p, direntc->d_name); } } (void) closedir(dirc); free(charmap); } } } if (flag == GET_LOCALE) { /* restore the saved loc */ (void) setlocale(LC_ALL, save_loc); show_loc_entry(); } (void) closedir(dirp); free(filename); exit(0); }