/* Function: al_ustr_find_set */ int al_ustr_find_set(const ALLEGRO_USTR *us, int start_pos, const ALLEGRO_USTR *accept) { int rc; int32_t c, d; int pos; int set_pos; /* Fast path for ASCII characters. */ if (all_ascii(accept)) { rc = _al_binchr(us, start_pos, accept); return (rc == _AL_BSTR_ERR) ? -1 : rc; } /* Non-ASCII. */ pos = 0; while ((c = al_ustr_get(us, pos)) != -1) { if (c == -2) { /* Invalid byte sequence. */ pos++; continue; } set_pos = 0; while ((d = al_ustr_get_next(accept, &set_pos)) != -1) { if (c == d) return pos; } pos += al_utf8_width(c); } return -1; }
void build_comment_frame(const char *lang, const wchar_t *desc, const wchar_t *value, std::vector<uint8_t> *res) { std::vector<uint8_t> vec(10), buf; std::memcpy(&vec[0], "COMM", 4); bool ascii = all_ascii(desc) && all_ascii(value); build_text_frame_value(desc, &buf, ascii); vec.push_back(buf[0]); std::copy(lang, lang + std::strlen(lang), std::back_inserter(vec)); std::copy(buf.begin() + 1, buf.end(), std::back_inserter(vec)); buf.clear(); build_text_frame_value(value, &buf, ascii); std::copy(buf.begin() + 1, buf.end(), std::back_inserter(vec)); uint32_t size = util::h2big32(vec.size() - 10); std::memcpy(&vec[4], &size, 4); res->swap(vec); }
void build_text_frame(const char *key, const wchar_t *value, std::vector<uint8_t> *result) { std::vector<uint8_t> vec(10), buf; const char *name = get_id3name(key); if (!name) return; std::memcpy(&vec[0], name, 4); build_text_frame_value(value, &buf, all_ascii(value)); uint32_t size = util::h2big32(buf.size()); std::memcpy(&vec[4], &size, 4); std::copy(buf.begin(), buf.end(), std::back_inserter(vec)); result->swap(vec); }
int main(int argc, char *argv[]) { char* data_buf; LimeReader *reader; FILE *fp; int status; n_uint64_t nbytes, read_bytes; int msg,rec,first; char *lime_type; size_t bytes_pad; int MB_flag, ME_flag; if( argc != 2 ) { fprintf(stderr, "Usage: %s <lime_file>\n", argv[0]); return EXIT_FAILURE; } fp = DCAPL(fopen)(argv[1], "r"); if(fp == (FILE *)NULL) { fprintf(stderr,"Unable to open file %s for reading\n", argv[1]); return EXIT_FAILURE; } reader = limeCreateReader(fp); if( reader == (LimeReader *)NULL ) { fprintf(stderr, "Unable to open LimeReader\n"); return EXIT_FAILURE; } msg = 0; first = 1; rec = 0; while( (status = limeReaderNextRecord(reader)) != LIME_EOF ){ if( status != LIME_SUCCESS ) { fprintf(stderr, "limeReaderNextRecord returned status = %d\n", status); return EXIT_FAILURE; } nbytes = limeReaderBytes(reader); lime_type = limeReaderType(reader); bytes_pad = limeReaderPadBytes(reader); MB_flag = limeReaderMBFlag(reader); ME_flag = limeReaderMEFlag(reader); if (MB_flag == 1 || first) { first = 0; rec = 0; msg++; } rec++; printf("\n\n"); printf("Message: %d\n", msg); printf("Record: %d\n", rec); printf("Type: %s\n", lime_type); printf("Data Length: %llu\n", (unsigned long long)nbytes); printf("Padding Length: %lu\n", (unsigned long)bytes_pad); printf("MB flag: %d\n", MB_flag); printf("ME flag: %d\n", ME_flag); /* TO DO: Buffer the input */ if(nbytes < MAX_BYTES){ data_buf = (char *)malloc((size_t)nbytes+1); if( data_buf == (char *)NULL) { fprintf(stderr, "Couldn't malloc data buf\n"); return EXIT_FAILURE; } read_bytes = nbytes; status = limeReaderReadData((void *)data_buf, &read_bytes, reader); if( status < 0 ) { if( status != LIME_EOR ) { fprintf(stderr, "LIME read error occurred: status= %d %llu bytes wanted, %llu read\n", status, (unsigned long long)nbytes, (unsigned long long)read_bytes); return EXIT_FAILURE; } } data_buf[nbytes]='\0'; if(!all_ascii(data_buf, nbytes)) printf("Data: [Binary data]\n"); else printf("Data: \"%s\" \n", data_buf); free(data_buf); } else{ printf("Data: [Long record skipped]\n"); } } limeDestroyReader(reader); DCAP(fclose)(fp); return EXIT_SUCCESS; }