static int pls_reader(playlist* pl) { int ret; static playlist_entry entry; buffer* inbuf = pl->ptr; stralloc line; stralloc_init(&line); if(( ret = buffer_getline_sa(inbuf, &line))) { size_t index2, index; index2 = index = 0; while(line.len > 1 && (line.s[line.len - 1] == '\r' || line.s[line.len - 1] == '\n')) line.len--; stralloc_0(&line); if(!str_diffn(&line.s[index], "Number", 6)) { } else if(line.s[index] == '[') { } else if((index2 = str_chr(&line.s[index], '=')) > 0) { unsigned long trackno = 0; index = index2; index2++; do { index--; } while(isdigit(line.s[index]) && index > 0); scan_ulong(&line.s[index], &trackno); if(!str_diffn(&line.s[index], "File", 4)) { stralloc_copys(&entry.path, &line.s[index2]); stralloc_0(&entry.path); } else if(!str_diffn(&line.s[index], "Title", 5)) { stralloc_copys(&entry.title, &line.s[index2]); stralloc_0(&entry.title); } else if(!str_diffn(&line.s[index], "Length", 6)) { unsigned long len; scan_ulong(&line.s[index2], &len); entry.length = len; } /* uint32 index = 8; index += scan_ulong(&line.s[index], &len); entry.length = len; index++; stralloc_copys(&entry.title, &line.s[index]); stralloc_0(&entry.title); */ } else { /* stralloc_copy(&entry.path, &line); stralloc_0(&entry.path); if(pl->callback) { pl->callback(pl, &entry.title, &entry.path, entry.length); }*/ } } return ret; }
int main() { stralloc sa; buffer b; stralloc line; stralloc_init(&sa); stralloc_init(&line); stralloc_copys(&sa,"this is a test\nline 2\n"); buffer_fromsa(&b,&sa); while (buffer_getline_sa(&b,&line)==0) { buffer_puts(buffer_1,"got line: \""); if (stralloc_chop(&line)!='\n') break; buffer_putsa(buffer_1,&line); buffer_putsflush(buffer_1,"\"\n"); stralloc_copys(&line,""); } return 0; }