Sha256: 41ef7a9587e90e03a45c26ca791e89d85b4d60c54fa5d248fa7587b617008ec7
Contents?: true
Size: 732 Bytes
Versions: 1
Compression:
Stored size: 732 Bytes
Contents
#include "ccsv.h" static VALUE rb_cC; static VALUE foreach(VALUE self, VALUE filename) { FILE *file = fopen(StringValueCStr(filename), "r"); if (file == NULL) rb_raise(rb_eRuntimeError, "File not found"); char line[MAX_LENGTH]; char *token; VALUE ary = rb_ary_new(); int idx; while (fgets(line, sizeof(line), file) != NULL) { token = strtok(line, DELIMITERS); idx = 0; while (token != NULL) { rb_ary_store(ary, idx, rb_str_new(token, strlen(token))); idx ++; token = strtok(NULL, DELIMITERS); } rb_yield(ary); } return Qnil; } void Init_ccsv() { rb_cC = rb_define_class("Ccsv", rb_cObject); rb_define_singleton_method(rb_cC, "foreach", foreach, 1); }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ccsv-0.0.2 | ext/ccsv.c |