q-lang-cvs Mailing List for Q - Equational Programming Language (Page 7)
Brought to you by:
agraef
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(106) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(219) |
Feb
(152) |
Mar
|
Apr
(92) |
May
(45) |
Jun
(3) |
Jul
|
Aug
(3) |
Sep
(111) |
Oct
(52) |
Nov
|
Dec
|
2005 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
(2) |
May
(23) |
Jun
(46) |
Jul
(158) |
Aug
(22) |
Sep
|
Oct
(26) |
Nov
(11) |
Dec
(49) |
2006 |
Jan
(57) |
Feb
(196) |
Mar
(10) |
Apr
(41) |
May
(149) |
Jun
(308) |
Jul
(11) |
Aug
(25) |
Sep
(15) |
Oct
|
Nov
|
Dec
(15) |
2007 |
Jan
|
Feb
|
Mar
|
Apr
(15) |
May
(204) |
Jun
(112) |
Jul
(7) |
Aug
(16) |
Sep
(134) |
Oct
(313) |
Nov
(262) |
Dec
(83) |
2008 |
Jan
(81) |
Feb
(83) |
Mar
(21) |
Apr
|
May
|
Jun
(1) |
Jul
(2) |
Aug
(6) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: RER <ed...@us...> - 2008-01-22 16:45:39
|
Update of /cvsroot/q-lang/q-csv In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv8598 Modified Files: csv.c csv.q Log Message: Changed module to be loosely compatible with Python's CSV module Index: csv.c =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** csv.c 18 Jan 2008 21:34:13 -0000 1.11 --- csv.c 22 Jan 2008 16:45:16 -0000 1.12 *************** *** 28,31 **** --- 28,32 ---- #define FORCEQUOTE 0 #define AUTOQUOTE 1 + #define NOQUOTE 2 /* fread_block reads embbeded '\n's. *************** *** 36,44 **** { FILE *fp; ! char *bf, *tb, *s_dl, *s; ! int n_q = 0, n_s_dl; long sz = BSIZE, n = 0; ! if (argc != 2 || !isfile(argv[0], &fp) || !isstr(argv[1], &s_dl)) return __FAIL; --- 37,47 ---- { FILE *fp; ! char *bf, *tb, *qt_s, *s; ! int qt_cnt = 0, n_qt_s; long sz = BSIZE, n = 0; ! if (argc != 2 ! || !isfile(argv[0], &fp) ! || !isstr(argv[1], &qt_s)) return __FAIL; *************** *** 46,50 **** return __ERROR; ! n_s_dl = strlen(s_dl); while (1) { s = bf + n; --- 49,53 ---- return __ERROR; ! n_qt_s = strlen(qt_s); while (1) { s = bf + n; *************** *** 64,77 **** goto fini; n += strlen(s); ! if (!*(bf+n-1) == '\n') continue; while (*s) { ! if (!strncmp(s, s_dl, n_s_dl)) { ! ++n_q; ! s += n_s_dl; } else ++s; } ! if (!(n_q & 1)) { fini: s = to_utf8(bf, NULL); --- 67,80 ---- goto fini; n += strlen(s); ! if (*(bf+n-1) != '\n') continue; while (*s) { ! if (!strncmp(s, qt_s, n_qt_s)) { ! ++qt_cnt; ! s += n_qt_s; } else ++s; } ! if (!(qt_cnt & 1)) { fini: s = to_utf8(bf, NULL); *************** *** 141,147 **** FUNCTION(csv, csvstr_to_tuple, argc, argv) { ! int n, cvt_f, fld_sz = 256, n_fld, rec_sz = 64, n_ws = 0, ! n_rec = 0, n_s_dl, n_fld_dl, st = 0; ! char *fld, *tfld, *fldp, *s, *fld_dl, *s_dl, errmsg[80]; expr *xs, *rec, *trec; char *sp; --- 144,153 ---- FUNCTION(csv, csvstr_to_tuple, argc, argv) { ! int n, st = 0, fld_sz = 256, n_fld, rec_sz = 64, n_ws = 0, n_rec = 0, ! n_delimiter, n_escape, n_quote, n_lineterm, skipspace_f, ! esc_eq_quote; ! char *fld, *tfld, *fldp, *s, errmsg[80], ! *delimiter, *escape, *quote, *lineterm; ! long quoting; expr *xs, *rec, *trec; char *sp; *************** *** 149,156 **** if (argc != 2 || !istuple(argv[0], &n, &xs) ! || n != 3 ! || !isbool(xs[0], &cvt_f) ! || !isstr(xs[1], &fld_dl) ! || !isstr(xs[2], &s_dl) || !isstr(argv[1], &s)) return __FAIL; --- 155,165 ---- if (argc != 2 || !istuple(argv[0], &n, &xs) ! || n != 6 ! || !isstr(xs[0], &delimiter) ! || !isstr(xs[1], &escape) ! || !isstr(xs[2], "e) ! || !isint(xs[3], "ing) ! || !isstr(xs[4], &lineterm) ! || !isbool(xs[5], &skipspace_f) || !isstr(argv[1], &s)) return __FAIL; *************** *** 164,169 **** } ! n_s_dl = strlen(s_dl); ! n_fld_dl = strlen(fld_dl); fldp = fld; while (st < 10) { --- 173,181 ---- } ! n_delimiter = strlen(delimiter); ! n_escape = strlen(escape); ! n_quote = strlen(quote); ! esc_eq_quote = !strcmp(escape, quote); ! n_lineterm = strlen(lineterm); fldp = fld; while (st < 10) { *************** *** 172,187 **** fldp = fld; n_fld = 0; ! if (!strncmp(s, fld_dl, n_fld_dl)) { *fldp = 0; putrec(FORCEQUOTE); ! s += n_fld_dl; ! } else if (!strncmp(s, s_dl, n_s_dl)) { ! s += n_s_dl; st = 1; ! } else if (!*s || *s == '\n' || *s == EOF) { ! putrec(FORCEQUOTE); st = 10; ! } else if (isspace(*s)) { ++s; } else { putfld(1); --- 184,201 ---- fldp = fld; n_fld = 0; ! if (!strncmp(s, delimiter, n_delimiter)) { *fldp = 0; putrec(FORCEQUOTE); ! s += n_delimiter; ! } else if (!strncmp(s, quote, n_quote)) { ! s += n_quote; st = 1; ! } else if (!*s || *s == EOF || !strncmp(s, lineterm, n_lineterm)) { st = 10; ! } else if (isspace(*s) && skipspace_f) { ++s; + } else if (!strncmp(s, escape, n_escape)) { + sprintf(errmsg, "Column %d: Unexpected escape.", n_fld+1); + st = 20; } else { putfld(1); *************** *** 191,200 **** break; case 1: ! if (!strncmp(s, s_dl, n_s_dl)) { ! s += n_s_dl; st = 2; } else if (!*s || *s == EOF) { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, s_dl); st = 20; } else { putfld(1); --- 205,218 ---- break; case 1: ! if (!strncmp(s, quote, n_quote)) { ! s += n_quote; st = 2; } else if (!*s || *s == EOF) { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, quote); st = 20; + } else if (!strncmp(s, escape, n_escape)) { + s += n_escape; + putfld(1); + ++s; } else { putfld(1); *************** *** 203,215 **** break; case 2: ! if (!strncmp(s, s_dl, n_s_dl)) { ! putfld(n_s_dl); ! s += n_s_dl; st = 1; ! } else if (!strncmp(s, fld_dl, n_fld_dl)) { putrec(FORCEQUOTE); ! s += n_fld_dl; st = 0; ! } else if (!*s || *s == '\n' || *s == EOF) { putrec(FORCEQUOTE); st = 10; --- 221,233 ---- break; case 2: ! if (!strncmp(s, quote, n_quote) && esc_eq_quote) { ! putfld(n_quote); ! s += n_quote; st = 1; ! } else if (!strncmp(s, delimiter, n_delimiter)) { putrec(FORCEQUOTE); ! s += n_delimiter; st = 0; ! } else if (!*s || *s == EOF || !strncmp(s, lineterm, n_lineterm)) { putrec(FORCEQUOTE); st = 10; *************** *** 218,229 **** st = 3; } else { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, fld_dl); st = 20; } break; case 3: ! if (!strncmp(s, fld_dl, n_fld_dl)) { putrec(FORCEQUOTE); ! s += n_fld_dl; st = 0; } else if (!*s || *s == '\n' || *s == EOF) { --- 236,247 ---- st = 3; } else { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, delimiter); st = 20; } break; case 3: ! if (!strncmp(s, delimiter, n_delimiter)) { putrec(FORCEQUOTE); ! s += n_delimiter; st = 0; } else if (!*s || *s == '\n' || *s == EOF) { *************** *** 233,252 **** ++s; } else { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, fld_dl); st = 20; } break; case 4: ! if (!strncmp(s, s_dl, n_s_dl)) { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, fld_dl); st = 20; ! } else if (!strncmp(s, fld_dl, n_fld_dl)) { fldp -= n_ws; n_fld -= n_ws; ! putrec(cvt_f); ! s += n_fld_dl; st = 0; ! } else if (!*s || *s == '\n' || *s == EOF) { ! putrec(cvt_f); st = 10; } else if (isspace(*s)) { --- 251,270 ---- ++s; } else { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, delimiter); st = 20; } break; case 4: ! if (!strncmp(s, quote, n_quote) || !strncmp(s, escape, n_escape)) { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, delimiter); st = 20; ! } else if (!strncmp(s, delimiter, n_delimiter)) { fldp -= n_ws; n_fld -= n_ws; ! putrec(quoting); ! s += n_delimiter; st = 0; ! } else if (!*s || *s == EOF || !strncmp(s, lineterm, n_lineterm)) { ! putrec(quoting); st = 10; } else if (isspace(*s)) { *************** *** 288,296 **** ! #define insert_num \ mrk = len; \ len += strlen(tb); \ resize_str; \ ! strncpy(t, tb, len - mrk) /* convert tuple to csv string --- 306,314 ---- ! #define insert \ mrk = len; \ len += strlen(tb); \ resize_str; \ ! strncpy(t, tb, len - mrk) /* convert tuple to csv string *************** *** 310,316 **** FUNCTION (csv, tuple_to_csvstr, argc, argv) { ! int i, n, sz = 256, mrk, n_q, len = 0, cvt_f, n_s_dl, n_fld_dl; ! char *s, *ts, *p, *sval, *s_dl, *fld_dl, tb[48], errmsg[80]; ! long ival; double dval; expr *xs, *ys; --- 328,336 ---- FUNCTION (csv, tuple_to_csvstr, argc, argv) { ! int i, n, k, sz = 256, mrk, quote_cnt, delim_cnt, lineterm_cnt, ! len = 0, skipspace_f, n_escape, n_quote, n_delimiter, n_lineterm; ! char *s, *ts, *p, *sval, tb[48], errmsg[80], ! *escape, *quote, *delimiter, *lineterm; ! long ival, quoting; double dval; expr *xs, *ys; *************** *** 319,376 **** if (argc != 2 || !istuple(argv[0], &i, &ys) ! || i != 3 ! || !isbool(ys[0], &cvt_f) /* unquote flag */ ! || !isstr(ys[1], &fld_dl) ! || !isstr(ys[2], &s_dl) ! || !istuple(argv[1], &n, &xs)) return __FAIL; if (!(s = (char *)malloc(sz))) return __ERROR; ! n_s_dl = strlen(s_dl); ! n_fld_dl = strlen(fld_dl); for (i = 0; i < n; ++i) { if (isint(xs[i], &ival)) { ! if (cvt_f) ! sprintf(tb, "%d%s", ival, fld_dl); else ! sprintf(tb, "%s%d%s%s", s_dl, ival, s_dl, fld_dl); ! insert_num; } else if (isfloat(xs[i], &dval)) { ! if (cvt_f) ! sprintf(tb, "%.16g%s", dval, fld_dl); else ! sprintf(tb, "%s%.16g%s%s", s_dl, dval, s_dl, fld_dl); ! insert_num; } else if (isstr(xs[i], &sval)) { ! n_q = 0; p = sval; ! while (*p) { ! if (!strncmp(p, s_dl, n_s_dl)) ! ++n_q; ! ++p; ! } mrk = len; - /* strlen + double s_dls + dquotes + fld_dl */ - len += (p - sval + 1) + n_s_dl*(1 + n_q) + n_fld_dl; - resize_str; - p = sval; - strncpy(t, s_dl, n_s_dl); - t += n_s_dl; while (*p) { ! if (!strncmp(p, s_dl, n_s_dl)) { ! strncpy(t, s_dl, n_s_dl); ! t += n_s_dl; ! strncpy(t, s_dl, n_s_dl); ! t += n_s_dl; ! p += n_s_dl; ! } else ! *t++ = *p++; } ! strncpy(t, s_dl, n_s_dl); ! t += n_s_dl; ! strncpy(t, fld_dl, n_fld_dl); ! t += n_fld_dl; } else { sprintf(errmsg, "Field %d: Invalid conversion type.", i+1); --- 339,433 ---- if (argc != 2 || !istuple(argv[0], &i, &ys) ! || i != 6 ! || !isstr(ys[0], &delimiter) ! || !isstr(ys[1], &escape) ! || !isstr(ys[2], "e) ! || !isint(ys[3], "ing) ! || !isstr(ys[4], &lineterm) ! || !isbool(ys[5], &skipspace_f) ! || !istuple(argv[1], &n, &xs)) { return __FAIL; + } if (!(s = (char *)malloc(sz))) return __ERROR; ! n_escape = strlen(escape); ! n_quote = strlen(quote); ! n_delimiter = strlen(delimiter); ! n_lineterm = strlen(lineterm); for (i = 0; i < n; ++i) { if (isint(xs[i], &ival)) { ! if (!quoting) ! sprintf(tb, "%s%d%s%s", quote, ival, quote, delimiter); else ! sprintf(tb, "%d%s", ival, delimiter); ! insert; } else if (isfloat(xs[i], &dval)) { ! if (!quoting) ! sprintf(tb, "%s%.16g%s%s", quote, dval, quote, delimiter); else ! sprintf(tb, "%.16g%s", dval, delimiter); ! insert; } else if (isstr(xs[i], &sval)) { ! quote_cnt = 0; ! delim_cnt = 0; ! lineterm_cnt = 0; p = sval; ! if (skipspace_f && quoting == NOQUOTE) ! while (isspace(*p) ! && strncmp(p, quote, n_delimiter) ! && strncmp(p, delimiter, n_delimiter) ! && strncmp(p, lineterm, n_lineterm)) { ! ++p; ! } ! k = p - sval; mrk = len; while (*p) { ! if (!strncmp(p, quote, n_quote)) { ! ++quote_cnt; ! p += n_quote; ! len += n_escape + n_quote; ! } else if (!strncmp(p, delimiter, n_delimiter)) { ! ++delim_cnt; ! p += n_delimiter; ! len += n_delimiter; ! } else if (!strncmp(p, lineterm, n_lineterm)) { ! ++lineterm_cnt; ! p += n_lineterm; ! len += n_lineterm; ! } else { ! ++len; ! ++p; ! } } ! len += n_delimiter; ! p = sval + k; ! if (quoting==NOQUOTE && !(quote_cnt + delim_cnt + lineterm_cnt)) { ! resize_str; ! k = len-mrk-1; ! strncpy(t, p, k); ! t += k; ! } else { ! /* Add space for surrounding quotes */ ! len += n_quote << 1; ! resize_str; ! strncpy(t, quote, n_quote); ! t += n_quote; ! while (*p) { ! if (!strncmp(p, quote, n_quote)) { ! strncpy(t, escape, n_escape); ! t += n_escape; ! strncpy(t, quote, n_quote); ! t += n_quote; ! p += n_quote; ! } else ! *t++ = *p++; ! } ! strncpy(t, quote, n_quote); ! t += n_quote; ! } ! strncpy(t, delimiter, n_delimiter); ! t += n_delimiter; } else { sprintf(errmsg, "Field %d: Invalid conversion type.", i+1); *************** *** 378,392 **** } } ! mrk = (len -= n_fld_dl - 2); /* write over last fld_dl */ ! #if defined (_WIN32) ! resize_str; ! #else /* Unix and Linux */ ! ++len; /* guarantee enough space for for \r\n */ resize_str; ! *(t-2) = '\r'; ! #endif ! *(t-1) = '\n'; ! *t = 0; ! s = realloc(s, len); ! return mkstr(s); } --- 435,444 ---- } } ! mrk = (len -= n_delimiter); /* write over last delimiter */ ! len += n_lineterm; resize_str; ! strcpy(t, lineterm); ! if (!(t = strdup(s))) ! return __ERROR; ! return mkstr(t); } Index: csv.q =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.q,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** csv.q 18 Jan 2008 21:34:13 -0000 1.11 --- csv.q 22 Jan 2008 16:45:16 -0000 1.12 *************** *** 19,206 **** /* The CSV library provides an interface to read and write comma separated ! value files. The reading and writing functions abide by RFC 4180 ! (http://www.ietf.org/rfc/rfc4180.txt) except for additional parameters ! that allow field delimiters and quote delimiters to be changed. */ ! ! public extern fread_csvstr FILE STRDELIM; ! /* Read a CSV record from a file (including embedded new lines). ! FILE: file to be read from ! STRDELIM: string delimiter used in the CSV format ! ! NOTE: fread_csvstr does not take into account badly formatted records. ! csvstr_to_tuple is necessary for error checking. ! */ ! ! public extern tuple_to_csvstr ARGS REC; ! /* Convert a tuple (record) to a CSV string ! ARGS: tuple (auto conversion flag, field delimiter, string delimiter) ! REC: tuple of fields to be converted to CSV format ! ! NOTES ! (1) REC must contain ONLY strings, integers, and floating point numbers. ! If a field is some other type, the 'csv_error MSG' rule is invoked. ! (2) When the auto conversion flag is false, ALL fields are strings. ! */ ! ! public extern csvstr_to_tuple ARGS STR; ! /* Convert CSV string to a tuple (record). ! ARGS: tuple (auto conversion flag, field delimiter, string delimiter) ! STR: CSV string to be converted to a tuple ! NOTES ! (1) When the auto conversion flag is false, all fields are strings. ! (2) The 'csv_error MSG' rule is invoked on improperly formatted strings. ! */ public csv_error MSG; /* User may define csv_error for custom error handling. */ ! /* String functions */ ! public sreadcsv_data ARGS; ! sreadcsv_data S:String ! = csvstr_to_tuple (true, ",", "\"") S; ! sreadcsv_data (S:String, FieldDelim:String) ! = csvstr_to_tuple (true, FieldDelim, "\"") S; ! sreadcsv_data (S:String, FieldDelim:String, StrDelim:String) ! = csvstr_to_tuple (true, FieldDelim, StrDelim) S; ! ! public sreadcsv_string ARGS; ! sreadcsv_string S:String ! = csvstr_to_tuple (false, ",", "\"") S; ! sreadcsv_string (S:String, FieldDelim:String) ! = csvstr_to_tuple (false, FieldDelim, "\"") S; ! sreadcsv_string (S:String, FieldDelim:String, StrDelim:String) ! = csvstr_to_tuple (false, FieldDelim, StrDelim) S; ! ! public sreadcsvlist_data ARGS; ! sreadcsvlist_data L:List ! = map (csvstr_to_tuple (true, ",", "\"")) L; ! sreadcsvlist_data (S:String, FieldDelim:String) ! = map (csvstr_to_tuple (true, FieldDelim, "\"")) L; ! sreadcsvlist_data (S:String, FieldDelim:String, StrDelim:String) ! = map (csvstr_to_tuple (true, FieldDelim, StrDelim)) L; ! ! public sreadcsvlist_string ARGS; ! sreadcsvlist_string L:List ! = map (csvstr_to_tuple (false, ",", "\"")) L; ! sreadcsvlist_string (S:String, FieldDelim:String) ! = map (csvstr_to_tuple (false, FieldDelim, "\"")) L; ! sreadcsvlist_string (S:String, FieldDelim:String, StrDelim:String) ! = map (csvstr_to_tuple (false, FieldDelim, StrDelim)) L; ! ! public swritecsv_data ARGS; ! swritecsv_data (Rec:Tuple, FieldDelim:String, StrDelim:String) ! = tuple_to_csvstr (true, FieldDelim, StrDelim) Tec; ! swritecsv_data (Rec:Tuple, FieldDelim:String) ! = tuple_to_csvstr (true, FieldDelim, "\"") Rec; ! swritecsv_data Rec:Tuple ! = tuple_to_csvstr (true, ",", "\"") Rec; ! ! public swritecsv_string ARGS; ! swritecsv_string (Rec:Tuple, FieldDelim:String, StrDelim:String) ! = tuple_to_csvstr (false, FieldDelim, StrDelim) Rec; ! swritecsv_string (Rec:Tuple, FieldDelim:String) ! = tuple_to_csvstr (false, FieldDelim, "\"") Rec; ! swritecsv_string Rec:Tuple ! = tuple_to_csvstr (false, ",", "\"") Rec; ! ! public swritecsvlist_data ARGS; ! swritecsvlist_data L:List ! = map (tuple_to_csvstr (true, ",", "\"")) L; ! swritecsvlist_data (L:List, FieldDelim:String) ! = map (tuple_to_csvstr (true, FieldDelim, "\"")) L; ! swritecsvlist_data (L:List, FieldDelim:String, StrDelim:String) ! = map (tuple_to_csvstr (true, FieldDelim, StrDelim)) L; ! public swritecsvlist_string ARGS; ! swritecsvlist_string L:List ! = map (tuple_to_csvstr (false, ",", "\"")) L; ! swritecsvlist_string (L:List, FieldDelim:String) ! = map (tuple_to_csvstr (false, FieldDelim, "\"")) L; ! swritecsvlist_string (L:List, FieldDelim:String, StrDelim:String) ! = map (tuple_to_csvstr (false, FieldDelim, StrDelim)) L; ! public freadcsv_data ARGS; ! /* Read one CSV record from the file with number conversion. */ ! freadcsv_data F:File ! = csvstr_to_tuple (true, ",", "\"") (fread_csvstr F "\""); ! freadcsv_data (F:File, FieldDelim:String) ! = csvstr_to_tuple (true, FieldDelim, "\"") (fread_csvstr F "\""); ! freadcsv_data (F:File, FieldDelim:String, StrDelim:String) ! = csvstr_to_tuple (true, FieldDelim, StrDelim) (fread_csvstr F StrDelim); ! public freadcsv_string ARGS; ! /* Read one CSV record from the file without number conversion. */ ! freadcsv_string F:File ! = csvstr_to_tuple (false, ",", "\"") (fread_csvstr F "\""); ! freadcsv_string (F:File, FieldDelim:String) ! = csvstr_to_tuple (false, FieldDelim, "\"") (fread_csvstr F "\""); ! freadcsv_string (F:File, FieldDelim:String, StrDelim:String) ! = csvstr_to_tuple (false, ",", "\"") (fread_csvstr F StrDelim); ! public freadcsvlist_data ARGS, freadcsvlist_string ARGS; ! /* Read an entire file of records into a list of tuples. */ ! freadcsvlist_data F:File ! = [] if feof F; ! = [freadcsv_data F | freadcsvlist_data F]; ! freadcsvlist_data (F:File, FieldDelim:String) ! = [] if feof F; ! = [freadcsv_data (F, FieldDelim) ! | freadcsvlist_data (F, FieldDelim)]; ! freadcsvlist_data (F:File, FieldDelim:String, StrDelim:String) ! = [] if feof F; ! = [freadcsv_data (F, FieldDelim, StrDelim) ! | freadcsvlist_data (F, FieldDelim, StrDelim)]; ! freadcsvlist_string F:File ! = [] if feof F; ! = [freadcsv_string F | freadcsvlist_data F]; ! freadcsvlist_string (F:File, FieldDelim:String) ! = [] if feof F; ! = [freadcsv_string (F, FieldDelim) ! | freadcsvlist_string (F, FieldDelim)]; ! freadcsvlist_string (F:File, FieldDelim:String, StrDelim:String) ! = [] if feof F; ! = [freadcsv_string (F, FieldDelim, StrDelim) ! | freadcsvlist_string (F, FieldDelim, StrDelim)]; ! public fwritecsv_data FILE REC; ! /* Write one CSV record to a file with number conversion. */ ! fwritecsv_data F:File Rec:Tuple ! = fwrites F (tuple_to_csvstr (true, ",", "\"") Rec); ! fwritecsv_data (F:File, FieldDelim:String) Rec:Tuple ! = fwrites F (tuple_to_csvstr (true, FieldDelim, "\"") Rec); ! fwritecsv_data (F:File, FieldDelim:String, StrDelim:String) Rec:Tuple ! = fwrites F (tuple_to_csvstr (true, FieldDelim, StrDelim) Rec); ! public fwritecsv_string FILE REC; ! /* Write one CSV record to a file without number conversion. */ ! fwritecsv_string F:File Rec:Tuple ! = fwrites F (tuple_to_csvstr (false, ",", "\"") Rec); ! fwritecsv_string (F:File, FieldDelim:String) Rec:Tuple ! = fwrites F (tuple_to_csvstr (false, FieldDelim, "\"") Rec); ! fwritecsv_string (F:File, FieldDelim:String, StrDelim:String) Rec:Tuple ! = fwrites F (tuple_to_csvstr (false, FieldDelim, StrDelim) Rec); ! public fwritecsvlist_data FILE LIST, fwritecsvlist_string ARGS; ! /* Write a list of tuples to a CSV formatted file. */ ! fwritecsvlist_data F:File L:List ! = do (fwritecsv_data F) L; ! fwritecsvlist_data (F:File, FieldDelim:String) L:List ! = do (fwritecsv_data (F, FieldDelim)) L; ! fwritecsvlist_data (F:File, FieldDelim:String, StrDelim:String) L:List ! = do (fwritecsv_data (F, FieldDelim, StrDelim)) L; ! fwritecsvlist_string F:File L:List ! = do (fwritecsv_string F) L; ! fwritecsvlist_string (F:File, FieldDelim:String) L:List ! = do (fwritecsv_string (F, FieldDelim)) L; ! fwritecsvlist_string (F:File, FieldDelim:String, StrDelim:String) L:List ! = do (fwritecsv_string (F, FieldDelim, StrDelim)) L; \ No newline at end of file --- 19,157 ---- /* The CSV library provides an interface to read and write comma separated ! value files. The reading and writing functions are loosely based on ! Python's csv module (http://docs.python.org/lib/module-csv.html) */ ! private extern fread_csvstr FILE QUOTE; ! private extern tuple_to_csvstr ARGS REC; ! private extern csvstr_to_tuple ARGS STR; public csv_error MSG; /* User may define csv_error for custom error handling. */ ! from dict import dict, insert, vals, member; ! /* Dialect Options */ ! public const var ! csv_delimiter = 0, /* Field delimiter. Defaults to ",". */ ! csv_escape = 1, /* Embedded escape character. Defaults to "\"". ! Reading: The escape character is dropped and ! the next char is inserted into the field. ! Writing: The escape character is written into the ! output stream. */ ! csv_quote = 2, /* Quote character. Defaults to "\"". ! Note: If embedded quotes are doubled, csv_escape ! must equal csv_quote. */ ! csv_quoting = 3, /* Quoting options: Defaults to quote_strings. ! If csv_quote_all, ! Reading: all fields are read as strings. ! Writing: all fields are quoted. ! If csv_quote_strings, ! Reading: integers and floats are converted. ! Writing: integers and floats are unquoted. ! If csv_quote_none, ! Reading: ntegers and floats are converted. ! Writing: all fields are unquoted except for ! those containing embedded quotes or ! newlines. */ ! csv_lineterminator = 4, /* Record terminator. Defaults to "\r\n" */ ! csv_skipspace = 5, /* Skip white space flag. Defaults to true. ! Reading/Writing: If true, white spaces before ! fields are removed. Quoted fields retain white ! space. */ + /* Constants used by csv quoting */ + csv_quote_all = 0, /* Quote every field */ + csv_quote_strings = 1, /* Quote only strings */ + csv_quote_none = 2; /* Quote only fields with embedded field delimeters, + line terminators, or escaped quotes. */ ! /* Defaults to RFC 4180 (http://www.ietf.org/rfc/rfc4180.txt) */ ! def DEFAULTS ! = dict [csv_delimiter, ","; ! csv_escape, "\""; ! csv_quote, "\""; ! csv_quoting, csv_quote_strings; ! csv_lineterminator, "\r\n"; ! csv_skipspace, true]; ! /* Create a dialect base on the list of dialect options given above */ ! public csv_dialect OPTS; ! csv_dialect Opts:List ! = tuple $ vals ! $ foldl insert (insert DEFAULTS (csv_escape, D!csv_quote)) $ Opts ! if (member D csv_quote) and then (not member D csv_escape) ! where D = dict Opts; ! = tuple $ vals $ foldl insert DEFAULTS $ Opts; ! /* Standard CSV format */ ! public rfc4180_dialect; ! rfc4180_dialect = csv_dialect []; ! public unix_dialect; ! unix_dialect = csv_dialect [csv_lineterminator,"\n";]; ! /* Convert a tuple (record) to a CSV string ! Dialect: CSV format specification. If none is given, defaults to ! rfc4180_dialect. ! Rec: Tuple of fields to be converted to CSV format. ! NOTE: REC must contain ONLY strings, integers, and floating point numbers. ! If a field is some other type, the 'csv_error MSG' rule is invoked. ! */ ! public swritecsv ARGS; ! swritecsv (Dialect:Tuple, Rec:Tuple) ! = tuple_to_csvstr Dialect Rec; ! swritecsv Rec:Tuple ! = tuple_to_csvstr rfc4180_dialect Rec; ! /* Convert a list of tuples to a list of CSV formated strings. */ ! public swritecsvlist ARGS; ! swritecsvlist (Dialect:Tuple, L:List) ! = map (tuple_to_csvstr Dialect) L; ! swritecsvlist L:List ! = map (tuple_to_csvstr rfc4180_dialect) L; ! /* Convert a tuple (record) to a CSV string ! Dialect: CSV format specification. If none is given, defaults to ! rfc4180_dialect. ! Rec: Tuple of fields to be converted to CSV format. ! NOTE: The 'csv_error MSG' rule is invoked on improperly formatted strings. ! */ ! public sreadcsv ARGS; ! sreadcsv (Rec:Tuple, Dialect:Tuple) ! = csvstr_to_tuple Dialect Rec; ! sreadcsv Rec:Tuple ! = csvstr_to_tuple rfc4180_dialect Rec; ! /* Convert a list of CSV formated strings to a list of tuples */ ! public sreadcsvlist ARGS; ! sreadcsvlist (L:List, Dialect:Tuple) ! = map (csvstr_to_tuple Dialect) L; ! sreadcsvlist L:List ! = map (csvstr_to_tuple rfc4180_dialect) L; ! /* File handling functions */ ! public freadcsv ARGS; ! freadcsv (F:File, Dialect:Tuple) ! = csvstr_to_tuple Dialect $ fread_csvstr F (Dialect!csv_quote); ! freadcsv F:File ! = csvstr_to_tuple rfc4180_dialect $ fread_csvstr F "\""; ! public fwritecsv ARGS REC; ! fwritecsv (F:File, Dialect:Tuple) Rec:Tuple ! = fwrites F $ tuple_to_csvstr Dialect Rec; ! fwritecsv F:File Rec:Tuple ! = fwrites F $ tuple_to_csvstr rfc4180_dialect Rec; ! public freadcsvlist ARGS; ! freadcsvlist (F:File, Dialect:Tuple) ! = [freadcsv (F, Dialect) | freadcsvlist (F, Dialect)]; ! freadcsvlist F:File ! = [freadcsv F | freadcsvlist F]; ! public fwritecsvlist ARGS REC; ! fwritecsvlist (F:File, Dialect:Tuple) L:List ! = do (fwritecsv F Dialect) L; ! fwritecsvlist F:File L:List ! = do (fwritecsv F) L; \ No newline at end of file |
From: Albert G. <ag...@us...> - 2008-01-22 12:41:41
|
Update of /cvsroot/q-lang/q/doc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv7378 Modified Files: qdoc.texi version.texi Log Message: update documentation Index: qdoc.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/qdoc.texi,v retrieving revision 1.142 retrieving revision 1.143 diff -C2 -d -r1.142 -r1.143 *** qdoc.texi 18 Jan 2008 11:34:58 -0000 1.142 --- qdoc.texi 22 Jan 2008 12:41:38 -0000 1.143 *************** *** 11148,11160 **** which allow you to treat byte strings as mutable C vectors of signed/unsigned 8/16/32 bit integers or single/double precision floating ! point numbers. The following functions provide read/write access to the ! elements of such C vectors. Note that the given index argument @code{I} ! is interpreted relative to the corresponding element type. Thus, e.g., ! @code{get_int32 B I} returns the @code{I}th 32 bit integer rather than ! the integer at byte offset @code{I}. ! ! NOTE: Integer arguments must fit into machine integers, otherwise these ! operations will fail. Integers passed for floating point arguments will be ! coerced to floating point values automatically. @smallexample --- 11148,11153 ---- which allow you to treat byte strings as mutable C vectors of signed/unsigned 8/16/32 bit integers or single/double precision floating ! point numbers. The following functions provide read/write access to ! elements and slices of such C vectors: @smallexample *************** *** 11168,11171 **** --- 11161,11184 ---- @end smallexample + Note that the given index argument @code{I} is interpreted relative to + the corresponding element type. Thus, e.g., @code{get_int32 B I} returns + the @code{I}th 32 bit integer rather than the integer at byte offset + @code{I}. Also note that integer arguments must fit into machine + integers, otherwise these operations will fail. Integers passed for + floating point arguments will be coerced to floating point values + automatically. + + For the @code{get_xxx} functions, the index parameter may also be a pair + @code{(I,J)} to return a slice of the given byte string instead of a + single element (this works like @code{sub}/@code{bsub}, but interprets + indices relative to the element type). The @code{put_xxx} functions also + accept a byte string instead of an element as input, and will then + overwrite the corresponding slice of the target byte string @code{B} + with the given source byte string @code{X}. Similar to + @code{sub}/@code{bsub}, these variations of + @code{get_xxx}/@code{put_xxx} are ``safe'' in that they automatically + adjust the given indices to fit within the bounds of the target byte + string. + Moreover, the following convenience functions are provided to convert between byte strings and lists of integer/floating point elements. *************** *** 11323,11333 **** In order to facilitate the handling of C vectors of integers and floating point values, as of Q 7.11 @code{clib} offers a number of ! specialized operations which provide direct read/write access to the ! elements of numeric vectors, and allow you to convert between C vectors ! and Q lists of integer or floating point values. These operations are ! all implemented directly in C and will usually be much more efficient ! for manipulating numeric C vectors than the basic byte-oriented ! functions. Moreover, they allow you to modify the elements of a C vector ! in a direct fashion, turning byte strings into a mutable data structure. Different operations are provided to handle vectors of signed or --- 11336,11347 ---- In order to facilitate the handling of C vectors of integers and floating point values, as of Q 7.11 @code{clib} offers a number of ! specialized operations which provide direct read/write access to ! elements and slices of numeric vectors, and allow you to convert between ! C vectors and Q lists of integer or floating point values. These ! operations are all implemented directly in C and will usually be much ! more efficient for manipulating numeric C vectors than the basic ! byte-oriented functions. Moreover, they allow you to modify the elements ! of a C vector in a direct fashion, turning byte strings into a mutable ! data structure. Different operations are provided to handle vectors of signed or *************** *** 11360,11363 **** --- 11374,11395 ---- @end smallexample + Entire slices of byte strings can be retrieved and overwritten as + well. Note that, as with @code{sub}, the indices are adjusted + automatically to stay within the bounds of the target vector. + + @smallexample + ==> put_uint32 B (-2) (uint32_vect [90..94]) + () + + ==> uint32_list B + [92,93,94,103,104,105,106,107,108,109,110] + + ==> uint32_list $ get_uint32 B (-2,3) + [92,93,94,103] + + ==> uint32_list $ get_uint32 B (8,100) + [108,109,110] + @end smallexample + @node Extended File Functions, C-Style Formatted I/O, Byte Strings, Clib @section Extended File Functions Index: version.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/version.texi,v retrieving revision 1.96 retrieving revision 1.97 diff -C2 -d -r1.96 -r1.97 *** version.texi 18 Jan 2008 11:18:45 -0000 1.96 --- version.texi 22 Jan 2008 12:41:38 -0000 1.97 *************** *** 1,3 **** ! @set UPDATED 18 January 2008 @set UPDATED-MONTH January 2008 @set EDITION 7.11 --- 1,3 ---- ! @set UPDATED 22 January 2008 @set UPDATED-MONTH January 2008 @set EDITION 7.11 |
From: Albert G. <ag...@us...> - 2008-01-22 12:05:09
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24633 Modified Files: ChangeLog Log Message: update ChangeLog Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.316 retrieving revision 1.317 diff -C2 -d -r1.316 -r1.317 *** ChangeLog 18 Jan 2008 10:09:38 -0000 1.316 --- ChangeLog 22 Jan 2008 12:05:02 -0000 1.317 *************** *** 1,2 **** --- 1,15 ---- + 2008-01-22 Albert Graef <Dr....@t-...> + + * modules/clib/clib.q, modules/clib/clib.c: add support for + reading and writing slices of byte strings in addition to single + elements + + More specifically, the get_xxx operations can now be invoked with + a pair of indices (I,J) to get a slice from a byte string. This + works like sub/bsub, but uses indices relative to the element + type. Likewise, the put_xxx operations can now be invoked with a + byte string argument rather than a single element, to replace an + entire slice of a byte string with a single operation. + 2008-01-18 Albert Graef <Dr....@t-...> |
From: Albert G. <ag...@us...> - 2008-01-22 12:00:52
|
Update of /cvsroot/q-lang/q/modules/clib In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv22789 Modified Files: clib.c clib.q Log Message: add support for reading and writing slices of byte strings Index: clib.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/clib/clib.q,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** clib.q 18 Jan 2008 11:20:42 -0000 1.34 --- clib.q 22 Jan 2008 12:00:46 -0000 1.35 *************** *** 260,267 **** you to treat byte strings as mutable C vectors of signed/unsigned 8/16/32 bit integers or single/double precision floating point numbers. The ! following functions provide read/write access to the elements of such C ! vectors. Note that the given index argument I is interpreted relative to ! the corresponding element type. Thus, e.g., get_int32 B I returns the Ith ! 32 bit integer rather than the integer at byte offset I. */ /* NOTE: Integer arguments must fit into machine integers, otherwise these --- 260,276 ---- you to treat byte strings as mutable C vectors of signed/unsigned 8/16/32 bit integers or single/double precision floating point numbers. The ! following functions provide read/write access to elements and slices of ! such C vectors. Note that the given index argument I is interpreted ! relative to the corresponding element type. Thus, e.g., get_int32 B I ! returns the Ith 32 bit integer rather than the integer at byte offset I. ! ! For the get_xxx functions, the index parameter may also be a pair (I,J) to ! return a slice of the given byte string instead of a single element ! (similar to sub/bsub, but interpreting indices relative to the element ! type). The put_xxx functions also accept a byte string instead of an ! element as input, and will then overwrite the corresponding slice of the ! target byte string with the given source. Similar to sub/bsub, these ! variations of get_xxx/put_xxx are "safe" in that they automatically adjust ! the given indices to fit within the bounds of the target byte string. */ /* NOTE: Integer arguments must fit into machine integers, otherwise these Index: clib.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/clib/clib.c,v retrieving revision 1.83 retrieving revision 1.84 diff -C2 -d -r1.83 -r1.84 *** clib.c 18 Jan 2008 10:06:04 -0000 1.83 --- clib.c 22 Jan 2008 12:00:46 -0000 1.84 *************** *** 4040,4051 **** } FUNCTION(clib,get_int8,argc,argv) { bstr_t *m; ! long i; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && i >= 0 && i < m->size) ! return mkint((signed char)m->v[i]); ! else return __FAIL; } --- 4040,4092 ---- } + static inline long get_clamp(long *i, long *j, long m) + { + if (*i < 0) *i = 0; + if (*j < *i) *j = *i-1; + if (*j >= m) { + *j = m-1; + if (*i > *j) *i = *j+1; + } + return *j-*i+1; + } + + static inline long put_clamp(long *i, long *j, long k, long m) + { + long l = k; + if (k < 0) l = k = 0; + if (*i < 0) { k += *i; *j -= *i; *i = 0; } + if (*i > m) *i = m; + if (k > m-*i) k = m-*i; + if (k < 0) k = 0; + if (*j < 0) *j = 0; + if (*j > l) *j = l; + return k; + } + FUNCTION(clib,get_int8,argc,argv) { bstr_t *m; ! expr *xv; ! int n; ! long i, j; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m)) { ! signed char *u = m->v; ! if (isint(argv[1], &i) && i >= 0 && i < m->size) ! return mkint(u[i]); ! else if (istuple(argv[1], &n, &xv) && n==2 && ! isint(xv[0], &i) && isint(xv[1], &j)) { ! long k = get_clamp(&i, &j, m->size); ! if (k > INT_MAX) ! return __ERROR; ! else if (k > 0) { ! signed char *v = (signed char*)malloc(k); ! if (!v) return __ERROR; ! memcpy(v, u+i, k); ! return mkbstr(k, v); ! } else ! return mkbstr(0, NULL); ! } else ! return __FAIL; ! } else return __FAIL; } *************** *** 4053,4062 **** FUNCTION(clib,put_int8,argc,argv) { ! bstr_t *m; long i, x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && isint(argv[2], &x) && i >= 0 && i < m->size) { ! m->v[i] = (signed char)x; ! return mkvoid; } else return __FAIL; --- 4094,4112 ---- FUNCTION(clib,put_int8,argc,argv) { ! bstr_t *m, *m1; long i, x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i)) { ! signed char *u = m->v; ! if (isint(argv[2], &x) && i >= 0 && i < m->size) { ! u[i] = (signed char)x; ! return mkvoid; ! } else if (isobj(argv[2], type(ByteStr), (void**)&m1)) { ! signed char *v = m1->v; ! long j = 0, k = put_clamp(&i, &j, m1->size, m->size); ! if (k > 0) memcpy(u+i, v+j, k); ! return mkvoid; ! } else ! return __FAIL; } else return __FAIL; *************** *** 4066,4074 **** { bstr_t *m; ! long i; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && i >= 0 && i < (m->size >> 1)) { ! short *v = (short*)m->v; ! return mkint(v[i]); } else return __FAIL; --- 4116,4141 ---- { bstr_t *m; ! expr *xv; ! int n; ! long i, j; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m)) { ! long N = m->size/sizeof(short); ! short *u = (short*)m->v; ! if (isint(argv[1], &i) && i >= 0 && i < N) ! return mkint(u[i]); ! else if (istuple(argv[1], &n, &xv) && n==2 && ! isint(xv[0], &i) && isint(xv[1], &j)) { ! long k = get_clamp(&i, &j, N); ! if (k > INT_MAX) ! return __ERROR; ! else if (k > 0) { ! short *v = (short*)malloc(k*sizeof(short)); ! if (!v) return __ERROR; ! memcpy(v, u+i, k*sizeof(short)); ! return mkbstr(k*sizeof(short), v); ! } else ! return mkbstr(0, NULL); ! } else ! return __FAIL; } else return __FAIL; *************** *** 4077,4088 **** FUNCTION(clib,put_int16,argc,argv) { ! bstr_t *m; long i, x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && isint(argv[2], &x) && ! i >= 0 && i < (m->size >> 1)) { ! short *v = (short*)m->v; ! v[i] = (short)x; ! return mkvoid; } else return __FAIL; --- 4144,4164 ---- FUNCTION(clib,put_int16,argc,argv) { ! bstr_t *m, *m1; long i, x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i)) { ! long N = m->size/sizeof(short); ! short *u = (short*)m->v; ! if (isint(argv[2], &x) && i >= 0 && i < N) { ! u[i] = (short)x; ! return mkvoid; ! } else if (isobj(argv[2], type(ByteStr), (void**)&m1)) { ! long M = m1->size/sizeof(short); ! short *v = (short*)m1->v; ! long j = 0, k = put_clamp(&i, &j, M, N); ! if (k > 0) memcpy(u+i, v+j, k*sizeof(short)); ! return mkvoid; ! } else ! return __FAIL; } else return __FAIL; *************** *** 4092,4100 **** { bstr_t *m; ! long i; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && i >= 0 && i < (m->size >> 2)) { ! long *v = (long*)m->v; ! return mkint(v[i]); } else return __FAIL; --- 4168,4193 ---- { bstr_t *m; ! expr *xv; ! int n; ! long i, j; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m)) { ! long N = m->size/sizeof(long); ! long *u = (long*)m->v; ! if (isint(argv[1], &i) && i >= 0 && i < N) ! return mkint(u[i]); ! else if (istuple(argv[1], &n, &xv) && n==2 && ! isint(xv[0], &i) && isint(xv[1], &j)) { ! long k = get_clamp(&i, &j, N); ! if (k > INT_MAX) ! return __ERROR; ! else if (k > 0) { ! long *v = (long*)malloc(k*sizeof(long)); ! if (!v) return __ERROR; ! memcpy(v, u+i, k*sizeof(long)); ! return mkbstr(k*sizeof(long), v); ! } else ! return mkbstr(0, NULL); ! } else ! return __FAIL; } else return __FAIL; *************** *** 4103,4114 **** FUNCTION(clib,put_int32,argc,argv) { ! bstr_t *m; long i, x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && isint(argv[2], &x) && ! i >= 0 && i < (m->size >> 2)) { ! long *v = (long*)m->v; ! v[i] = (long)x; ! return mkvoid; } else return __FAIL; --- 4196,4216 ---- FUNCTION(clib,put_int32,argc,argv) { ! bstr_t *m, *m1; long i, x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i)) { ! long N = m->size/sizeof(long); ! long *u = (long*)m->v; ! if (isint(argv[2], &x) && i >= 0 && i < N) { ! u[i] = (long)x; ! return mkvoid; ! } else if (isobj(argv[2], type(ByteStr), (void**)&m1)) { ! long M = m1->size/sizeof(long); ! long *v = (long*)m1->v; ! long j = 0, k = put_clamp(&i, &j, M, N); ! if (k > 0) memcpy(u+i, v+j, k*sizeof(long)); ! return mkvoid; ! } else ! return __FAIL; } else return __FAIL; *************** *** 4118,4126 **** { bstr_t *m; ! long i; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && i >= 0 && i < m->size) ! return mkuint((unsigned char)m->v[i]); ! else return __FAIL; } --- 4220,4245 ---- { bstr_t *m; ! expr *xv; ! int n; ! long i, j; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m)) { ! unsigned char *u = m->v; ! if (isint(argv[1], &i) && i >= 0 && i < m->size) ! return mkuint(u[i]); ! else if (istuple(argv[1], &n, &xv) && n==2 && ! isint(xv[0], &i) && isint(xv[1], &j)) { ! long k = get_clamp(&i, &j, m->size); ! if (k > INT_MAX) ! return __ERROR; ! else if (k > 0) { ! unsigned char *v = (unsigned char*)malloc(k); ! if (!v) return __ERROR; ! memcpy(v, u+i, k); ! return mkbstr(k, v); ! } else ! return mkbstr(0, NULL); ! } else ! return __FAIL; ! } else return __FAIL; } *************** *** 4128,4138 **** FUNCTION(clib,put_uint8,argc,argv) { ! bstr_t *m; long i; unsigned long x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && isuint(argv[2], &x) && i >= 0 && i < m->size) { ! m->v[i] = (unsigned char)x; ! return mkvoid; } else return __FAIL; --- 4247,4266 ---- FUNCTION(clib,put_uint8,argc,argv) { ! bstr_t *m, *m1; long i; unsigned long x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i)) { ! unsigned char *u = m->v; ! if (isuint(argv[2], &x) && i >= 0 && i < m->size) { ! u[i] = (unsigned char)x; ! return mkvoid; ! } else if (isobj(argv[2], type(ByteStr), (void**)&m1)) { ! unsigned char *v = m1->v; ! long j = 0, k = put_clamp(&i, &j, m1->size, m->size); ! if (k > 0) memcpy(u+i, v+j, k); ! return mkvoid; ! } else ! return __FAIL; } else return __FAIL; *************** *** 4142,4150 **** { bstr_t *m; ! long i; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && i >= 0 && i < (m->size >> 1)) { ! unsigned short *v = (unsigned short*)m->v; ! return mkuint(v[i]); } else return __FAIL; --- 4270,4295 ---- { bstr_t *m; ! expr *xv; ! int n; ! long i, j; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m)) { ! long N = m->size/sizeof(unsigned short); ! unsigned short *u = (unsigned short*)m->v; ! if (isint(argv[1], &i) && i >= 0 && i < N) ! return mkuint(u[i]); ! else if (istuple(argv[1], &n, &xv) && n==2 && ! isint(xv[0], &i) && isint(xv[1], &j)) { ! long k = get_clamp(&i, &j, N); ! if (k > INT_MAX) ! return __ERROR; ! else if (k > 0) { ! unsigned short *v = (unsigned short*)malloc(k*sizeof(unsigned short)); ! if (!v) return __ERROR; ! memcpy(v, u+i, k*sizeof(unsigned short)); ! return mkbstr(k*sizeof(unsigned short), v); ! } else ! return mkbstr(0, NULL); ! } else ! return __FAIL; } else return __FAIL; *************** *** 4153,4165 **** FUNCTION(clib,put_uint16,argc,argv) { ! bstr_t *m; long i; unsigned long x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && isuint(argv[2], &x) && ! i >= 0 && i < (m->size >> 1)) { ! short *v = (short*)m->v; ! v[i] = (short)x; ! return mkvoid; } else return __FAIL; --- 4298,4319 ---- FUNCTION(clib,put_uint16,argc,argv) { ! bstr_t *m, *m1; long i; unsigned long x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i)) { ! long N = m->size/sizeof(unsigned short); ! unsigned short *u = (unsigned short*)m->v; ! if (isuint(argv[2], &x) && i >= 0 && i < N) { ! u[i] = (unsigned short)x; ! return mkvoid; ! } else if (isobj(argv[2], type(ByteStr), (void**)&m1)) { ! long M = m1->size/sizeof(unsigned short); ! unsigned short *v = (unsigned short*)m1->v; ! long j = 0, k = put_clamp(&i, &j, M, N); ! if (k > 0) memcpy(u+i, v+j, k*sizeof(unsigned short)); ! return mkvoid; ! } else ! return __FAIL; } else return __FAIL; *************** *** 4169,4177 **** { bstr_t *m; ! long i; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && i >= 0 && i < (m->size >> 2)) { ! unsigned long *v = (unsigned long*)m->v; ! return mkuint(v[i]); } else return __FAIL; --- 4323,4348 ---- { bstr_t *m; ! expr *xv; ! int n; ! long i, j; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m)) { ! long N = m->size/sizeof(unsigned long); ! unsigned long *u = (unsigned long*)m->v; ! if (isint(argv[1], &i) && i >= 0 && i < N) ! return mkuint(u[i]); ! else if (istuple(argv[1], &n, &xv) && n==2 && ! isint(xv[0], &i) && isint(xv[1], &j)) { ! long k = get_clamp(&i, &j, N); ! if (k > INT_MAX) ! return __ERROR; ! else if (k > 0) { ! unsigned long *v = (unsigned long*)malloc(k*sizeof(unsigned long)); ! if (!v) return __ERROR; ! memcpy(v, u+i, k*sizeof(unsigned long)); ! return mkbstr(k*sizeof(unsigned long), v); ! } else ! return mkbstr(0, NULL); ! } else ! return __FAIL; } else return __FAIL; *************** *** 4180,4192 **** FUNCTION(clib,put_uint32,argc,argv) { ! bstr_t *m; long i; unsigned long x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && isuint(argv[2], &x) && ! i >= 0 && i < (m->size >> 2)) { ! unsigned long *v = (unsigned long*)m->v; ! v[i] = (unsigned long)x; ! return mkvoid; } else return __FAIL; --- 4351,4372 ---- FUNCTION(clib,put_uint32,argc,argv) { ! bstr_t *m, *m1; long i; unsigned long x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i)) { ! long N = m->size/sizeof(unsigned long); ! unsigned long *u = (unsigned long*)m->v; ! if (isuint(argv[2], &x) && i >= 0 && i < N) { ! u[i] = (unsigned long)x; ! return mkvoid; ! } else if (isobj(argv[2], type(ByteStr), (void**)&m1)) { ! long M = m1->size/sizeof(unsigned long); ! unsigned long *v = (unsigned long*)m1->v; ! long j = 0, k = put_clamp(&i, &j, M, N); ! if (k > 0) memcpy(u+i, v+j, k*sizeof(unsigned long)); ! return mkvoid; ! } else ! return __FAIL; } else return __FAIL; *************** *** 4196,4204 **** { bstr_t *m; ! long i; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && i >= 0 && i < (m->size / sizeof(float))) { ! float *v = (float*)m->v; ! return mkfloat(v[i]); } else return __FAIL; --- 4376,4401 ---- { bstr_t *m; ! expr *xv; ! int n; ! long i, j; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m)) { ! long N = m->size/sizeof(float); ! float *u = (float*)m->v; ! if (isint(argv[1], &i) && i >= 0 && i < N) ! return mkfloat(u[i]); ! else if (istuple(argv[1], &n, &xv) && n==2 && ! isint(xv[0], &i) && isint(xv[1], &j)) { ! long k = get_clamp(&i, &j, N); ! if (k > INT_MAX) ! return __ERROR; ! else if (k > 0) { ! float *v = (float*)malloc(k*sizeof(float)); ! if (!v) return __ERROR; ! memcpy(v, u+i, k*sizeof(float)); ! return mkbstr(k*sizeof(float), v); ! } else ! return mkbstr(0, NULL); ! } else ! return __FAIL; } else return __FAIL; *************** *** 4207,4220 **** FUNCTION(clib,put_float,argc,argv) { ! bstr_t *m; long i; double x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && ! (isfloat(argv[2], &x) || ismpz_float(argv[2], &x)) && ! i >= 0 && i < (m->size / sizeof(float))) { ! float *v = (float*)m->v; ! v[i] = (float)x; ! return mkvoid; } else return __FAIL; --- 4404,4426 ---- FUNCTION(clib,put_float,argc,argv) { ! bstr_t *m, *m1; long i; double x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i)) { ! long N = m->size/sizeof(float); ! float *u = (float*)m->v; ! if ((isfloat(argv[2], &x) || ismpz_float(argv[2], &x)) && ! i >= 0 && i < N) { ! u[i] = (float)x; ! return mkvoid; ! } else if (isobj(argv[2], type(ByteStr), (void**)&m1)) { ! long M = m1->size/sizeof(float); ! float *v = (float*)m1->v; ! long j = 0, k = put_clamp(&i, &j, M, N); ! if (k > 0) memcpy(u+i, v+j, k*sizeof(float)); ! return mkvoid; ! } else ! return __FAIL; } else return __FAIL; *************** *** 4224,4232 **** { bstr_t *m; ! long i; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && i >= 0 && i < (m->size / sizeof(double))) { ! double *v = (double*)m->v; ! return mkfloat(v[i]); } else return __FAIL; --- 4430,4455 ---- { bstr_t *m; ! expr *xv; ! int n; ! long i, j; ! if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m)) { ! long N = m->size/sizeof(double); ! double *u = (double*)m->v; ! if (isint(argv[1], &i) && i >= 0 && i < N) ! return mkfloat(u[i]); ! else if (istuple(argv[1], &n, &xv) && n==2 && ! isint(xv[0], &i) && isint(xv[1], &j)) { ! long k = get_clamp(&i, &j, N); ! if (k > INT_MAX) ! return __ERROR; ! else if (k > 0) { ! double *v = (double*)malloc(k*sizeof(double)); ! if (!v) return __ERROR; ! memcpy(v, u+i, k*sizeof(double)); ! return mkbstr(k*sizeof(double), v); ! } else ! return mkbstr(0, NULL); ! } else ! return __FAIL; } else return __FAIL; *************** *** 4235,4248 **** FUNCTION(clib,put_double,argc,argv) { ! bstr_t *m; long i; double x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i) && ! (isfloat(argv[2], &x) || ismpz_float(argv[2], &x)) && ! i >= 0 && i < (m->size / sizeof(double))) { ! double *v = (double*)m->v; ! v[i] = x; ! return mkvoid; } else return __FAIL; --- 4458,4480 ---- FUNCTION(clib,put_double,argc,argv) { ! bstr_t *m, *m1; long i; double x; if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && ! isint(argv[1], &i)) { ! long N = m->size/sizeof(double); ! double *u = (double*)m->v; ! if ((isfloat(argv[2], &x) || ismpz_float(argv[2], &x)) && ! i >= 0 && i < N) { ! u[i] = (double)x; ! return mkvoid; ! } else if (isobj(argv[2], type(ByteStr), (void**)&m1)) { ! long M = m1->size/sizeof(double); ! double *v = (double*)m1->v; ! long j = 0, k = put_clamp(&i, &j, M, N); ! if (k > 0) memcpy(u+i, v+j, k*sizeof(double)); ! return mkvoid; ! } else ! return __FAIL; } else return __FAIL; |
From: RER <ed...@us...> - 2008-01-18 21:34:23
|
Update of /cvsroot/q-lang/q-csv/examples In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16832/examples Modified Files: readsamples.q writesamples.q Log Message: Bugfix in tuple_to_csvstr and fixed comments in readsamples.q and writesamples.q Index: writesamples.q =================================================================== RCS file: /cvsroot/q-lang/q-csv/examples/writesamples.q,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** writesamples.q 13 Jan 2008 17:27:14 -0000 1.3 --- writesamples.q 18 Jan 2008 21:34:13 -0000 1.4 *************** *** 2,6 **** To run: ! At the command line> Q writesamples.q At the prompt ==> main Using your favorite editor open the write samples to see what was wrought. --- 2,6 ---- To run: ! At the command line> q writesamples.q At the prompt ==> main Using your favorite editor open the write samples to see what was wrought. *************** *** 45,58 **** ("a, b", "", 0, 0.0, "00")]; ! main = writes "Writing 'write-sample1.csv: (standard CSV)" || writefile (fopen "write-sample1.csv" "w") Sample1 || writes "\ndone.\n\n-----" ! || writes "Writing 'write-sample2.csv: (standard CSV, quoted)" || writefile_string (fopen "write-sample2.csv" "w") Sample1 || writes "\ndone.\n\n-----" ! || writes "Writing 'write-sample3.csv: (tab delimited)" || writefile_tab (fopen "write-sample3.csv" "w") Sample2 || writes "\ndone.\n\n-----" ! || writes "Writing 'write-sample4.csv: (tab delimited, single quoted)" || writefile_tab_quote (fopen "write-sample4.csv" "w") Sample3 || writes "\ndone.\n\n-----"; \ No newline at end of file --- 45,58 ---- ("a, b", "", 0, 0.0, "00")]; ! main = writes "Writing 'write-sample1.csv:' (standard CSV)" || writefile (fopen "write-sample1.csv" "w") Sample1 || writes "\ndone.\n\n-----" ! || writes "Writing 'write-sample2.csv:' (standard CSV, quoted)" || writefile_string (fopen "write-sample2.csv" "w") Sample1 || writes "\ndone.\n\n-----" ! || writes "Writing 'write-sample3.csv:' (tab delimited)" || writefile_tab (fopen "write-sample3.csv" "w") Sample2 || writes "\ndone.\n\n-----" ! || writes "Writing 'write-sample4.csv:' (tab delimited, single quoted)" || writefile_tab_quote (fopen "write-sample4.csv" "w") Sample3 || writes "\ndone.\n\n-----"; \ No newline at end of file Index: readsamples.q =================================================================== RCS file: /cvsroot/q-lang/q-csv/examples/readsamples.q,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** readsamples.q 13 Jan 2008 17:27:14 -0000 1.3 --- readsamples.q 18 Jan 2008 21:34:13 -0000 1.4 *************** *** 2,6 **** To run: ! at the command line> Q readsamples.q at the prompt ==> main */ --- 2,6 ---- To run: ! at the command line> q readsamples.q at the prompt ==> main */ *************** *** 30,47 **** /* Illustration of freadcsv with tab and quote delimeters */ readfile_tab_quote F = [] if feof F; ! = [freadcsv_data (F, "\t", ",") | readfile_tab_quote F]; ! main = writes "Reading 'read-sample1.csv: (standard CSV)" || write (readfile (fopen "read-sample1.csv" "r")) || writes "\n\n-----" ! || writes "Reading 'read-sample1.csv: (standard CSV, no convertions)" || write (readfile_string (fopen "read-sample1.csv" "r")) || writes "\n\n-----" ! || writes "Reading 'read-sample2.csv: (tab delimited)" || write (readfile_tab (fopen "read-sample2.csv" "r")) || writes "\n\n-----" ! || writes "Reading 'read-sample3.csv: (tab delimited, single quoted)" ! || write (readfile_tab (fopen "read-sample3.csv" "r")) || writes "\n\n-----" ! || writes "Reading 'read-sample4.csv: (Malformed)\n" || write (readfile (fopen "read-sample4.csv" "r")); \ No newline at end of file --- 30,47 ---- /* Illustration of freadcsv with tab and quote delimeters */ readfile_tab_quote F = [] if feof F; ! = [freadcsv_data (F, "\t", "'") | readfile_tab_quote F]; ! main = writes "Reading 'read-sample1.csv:' (standard CSV)\n" || write (readfile (fopen "read-sample1.csv" "r")) || writes "\n\n-----" ! || writes "Reading 'read-sample1.csv:' (standard CSV, no convertions)\n" || write (readfile_string (fopen "read-sample1.csv" "r")) || writes "\n\n-----" ! || writes "Reading 'read-sample2.csv:' (tab delimited)\n" || write (readfile_tab (fopen "read-sample2.csv" "r")) || writes "\n\n-----" ! || writes "Reading 'read-sample3.csv:' (tab delimited, single quoted)\n" ! || write (readfile_tab_quote (fopen "read-sample3.csv" "r")) || writes "\n\n-----" ! || writes "Reading 'read-sample4.csv:' (Malformed)\n" || write (readfile (fopen "read-sample4.csv" "r")); \ No newline at end of file |
From: RER <ed...@us...> - 2008-01-18 21:34:23
|
Update of /cvsroot/q-lang/q-csv In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16832 Modified Files: csv.c csv.q Log Message: Bugfix in tuple_to_csvstr and fixed comments in readsamples.q and writesamples.q Index: csv.c =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** csv.c 17 Jan 2008 20:54:18 -0000 1.10 --- csv.c 18 Jan 2008 21:34:13 -0000 1.11 *************** *** 264,272 **** done: free(fld); ! switch (st) { ! case 10: rec = realloc(rec, sizeof(expr)*n_rec); return mktuplev(n_rec, rec); ! default: for (n = 0; n < n_rec; ++n) dispose(rec[n]); --- 264,271 ---- done: free(fld); ! if (st == 10) { rec = realloc(rec, sizeof(expr)*n_rec); return mktuplev(n_rec, rec); ! } else { for (n = 0; n < n_rec; ++n) dispose(rec[n]); *************** *** 379,393 **** } } ! mrk = (len -= n_fld_dl - 1); /* write over last fld_dl */ #if defined (_WIN32) ++len; /* guarantee enough space for for \r\n */ resize_str; *(t-2) = '\r'; - #else - resize_str; #endif *(t-1) = '\n'; *t = 0; ! s = (char *)realloc(s, len); return mkstr(s); } --- 378,392 ---- } } ! mrk = (len -= n_fld_dl - 2); /* write over last fld_dl */ #if defined (_WIN32) + resize_str; + #else /* Unix and Linux */ ++len; /* guarantee enough space for for \r\n */ resize_str; *(t-2) = '\r'; #endif *(t-1) = '\n'; *t = 0; ! s = realloc(s, len); return mkstr(s); } Index: csv.q =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.q,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** csv.q 17 Jan 2008 20:54:18 -0000 1.10 --- csv.q 18 Jan 2008 21:34:13 -0000 1.11 *************** *** 90,107 **** public swritecsv_data ARGS; - swritecsv_data Rec:Tuple - = tuple_to_csvstr (true, ",", "\"") Rec; - swritecsv_data (Rec:Tuple, FieldDelim:String) - = tuple_to_csvstr (true, FieldDelim, "\"") Rec; swritecsv_data (Rec:Tuple, FieldDelim:String, StrDelim:String) = tuple_to_csvstr (true, FieldDelim, StrDelim) Tec; public swritecsv_string ARGS; - swritecsv_string Rec:Tuple - = tuple_to_csvstr (false, ",", "\"") Rec; - swritecsv_string (Rec:Tuple, FieldDelim:String) - = tuple_to_csvstr (false, FieldDelim, "\"") Rec; swritecsv_string (Rec:Tuple, FieldDelim:String, StrDelim:String) = tuple_to_csvstr (false, FieldDelim, StrDelim) Rec; public swritecsvlist_data ARGS; --- 90,107 ---- public swritecsv_data ARGS; swritecsv_data (Rec:Tuple, FieldDelim:String, StrDelim:String) = tuple_to_csvstr (true, FieldDelim, StrDelim) Tec; + swritecsv_data (Rec:Tuple, FieldDelim:String) + = tuple_to_csvstr (true, FieldDelim, "\"") Rec; + swritecsv_data Rec:Tuple + = tuple_to_csvstr (true, ",", "\"") Rec; public swritecsv_string ARGS; swritecsv_string (Rec:Tuple, FieldDelim:String, StrDelim:String) = tuple_to_csvstr (false, FieldDelim, StrDelim) Rec; + swritecsv_string (Rec:Tuple, FieldDelim:String) + = tuple_to_csvstr (false, FieldDelim, "\"") Rec; + swritecsv_string Rec:Tuple + = tuple_to_csvstr (false, ",", "\"") Rec; public swritecsvlist_data ARGS; |
From: Albert G. <ag...@us...> - 2008-01-18 11:35:02
|
Update of /cvsroot/q-lang/q/doc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12347 Modified Files: qdoc.texi Log Message: update documentation Index: qdoc.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/qdoc.texi,v retrieving revision 1.141 retrieving revision 1.142 diff -C2 -d -r1.141 -r1.142 *** qdoc.texi 18 Jan 2008 11:18:45 -0000 1.141 --- qdoc.texi 18 Jan 2008 11:34:58 -0000 1.142 *************** *** 11324,11337 **** floating point values, as of Q 7.11 @code{clib} offers a number of specialized operations which provide direct read/write access to the ! elements of numeric vectors, and to convert between such C vectors and ! lists of integer or floating point values. These operations are all ! implemented directly in C and will usually be much more efficient for ! manipulating numeric C vectors than the basic byte-oriented functions. Moreover, they allow you to modify the elements of a C vector in a direct fashion, turning byte strings into a mutable data structure. Different operations are provided to handle vectors of signed or ! unsigned 8/16/32 (machine) integers, as well as single and double ! precision floating point numbers. For instance: @smallexample --- 11324,11337 ---- floating point values, as of Q 7.11 @code{clib} offers a number of specialized operations which provide direct read/write access to the ! elements of numeric vectors, and allow you to convert between C vectors ! and Q lists of integer or floating point values. These operations are ! all implemented directly in C and will usually be much more efficient ! for manipulating numeric C vectors than the basic byte-oriented functions. Moreover, they allow you to modify the elements of a C vector in a direct fashion, turning byte strings into a mutable data structure. Different operations are provided to handle vectors of signed or ! unsigned 8/16/32 bit (machine) integers, as well as single (32 bit) and ! double precision (64 bit) floating point numbers. For instance: @smallexample |
From: Albert G. <ag...@us...> - 2008-01-18 11:20:46
|
Update of /cvsroot/q-lang/q/modules/clib In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv5156/modules/clib Modified Files: clib.q Log Message: fix typo in comment Index: clib.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/clib/clib.q,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** clib.q 18 Jan 2008 10:06:05 -0000 1.33 --- clib.q 18 Jan 2008 11:20:42 -0000 1.34 *************** *** 262,266 **** following functions provide read/write access to the elements of such C vectors. Note that the given index argument I is interpreted relative to ! the corresponding element type. Thus, e.g., get_uint32 B I returns the Ith 32 bit integer rather than the integer at byte offset I. */ --- 262,266 ---- following functions provide read/write access to the elements of such C vectors. Note that the given index argument I is interpreted relative to ! the corresponding element type. Thus, e.g., get_int32 B I returns the Ith 32 bit integer rather than the integer at byte offset I. */ |
From: Albert G. <ag...@us...> - 2008-01-18 11:18:53
|
Update of /cvsroot/q-lang/q/doc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3854 Modified Files: qdoc.texi version.texi Log Message: update documentation Index: qdoc.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/qdoc.texi,v retrieving revision 1.140 retrieving revision 1.141 diff -C2 -d -r1.140 -r1.141 *** qdoc.texi 16 Jan 2008 08:30:22 -0000 1.140 --- qdoc.texi 18 Jan 2008 11:18:45 -0000 1.141 *************** *** 11143,11146 **** --- 11143,11184 ---- operations are all implemented in terms of the functions listed above. + @subheading Byte Strings as Mutable C Vectors + + As of Q 7.11, @code{clib} supports a number of additional operations + which allow you to treat byte strings as mutable C vectors of + signed/unsigned 8/16/32 bit integers or single/double precision floating + point numbers. The following functions provide read/write access to the + elements of such C vectors. Note that the given index argument @code{I} + is interpreted relative to the corresponding element type. Thus, e.g., + @code{get_int32 B I} returns the @code{I}th 32 bit integer rather than + the integer at byte offset @code{I}. + + NOTE: Integer arguments must fit into machine integers, otherwise these + operations will fail. Integers passed for floating point arguments will be + coerced to floating point values automatically. + + @smallexample + public extern get_int8 B I, get_int16 B I, get_int32 B I; + public extern get_uint8 B I, get_uint16 B I, get_uint32 B I; + public extern get_float B I, get_double B I; + + public extern put_int8 B I X, put_int16 B I X, put_int32 B I X; + public extern put_uint8 B I X, put_uint16 B I X, put_uint32 B I X; + public extern put_float B I X, put_double B I X; + @end smallexample + + Moreover, the following convenience functions are provided to convert + between byte strings and lists of integer/floating point elements. + + @smallexample + public extern int8_list B, int16_list B, int32_list B; + public extern uint8_list B, uint16_list B, uint32_list B; + public extern float_list B, double_list B; + + public extern int8_vect Xs, int16_vect Xs, int32_vect Xs; + public extern uint8_vect Xs, uint16_vect Xs, uint32_vect Xs; + public extern float_vect Xs, double_vect Xs; + @end smallexample + @subheading Examples *************** *** 11283,11286 **** --- 11321,11363 ---- addresses. + In order to facilitate the handling of C vectors of integers and + floating point values, as of Q 7.11 @code{clib} offers a number of + specialized operations which provide direct read/write access to the + elements of numeric vectors, and to convert between such C vectors and + lists of integer or floating point values. These operations are all + implemented directly in C and will usually be much more efficient for + manipulating numeric C vectors than the basic byte-oriented + functions. Moreover, they allow you to modify the elements of a C vector + in a direct fashion, turning byte strings into a mutable data structure. + + Different operations are provided to handle vectors of signed or + unsigned 8/16/32 (machine) integers, as well as single and double + precision floating point numbers. For instance: + + @smallexample + ==> def B = uint32_vect [100..110] + + ==> uint32_list B + [100,101,102,103,104,105,106,107,108,109,110] + + ==> get_uint32 B 1 + 101 + + ==> put_uint32 B 1 0xffffffff + () + + ==> uint32_list B + [100,4294967295,102,103,104,105,106,107,108,109,110] + @end smallexample + + Note that, because these C vectors are just normal byte strings, you can + freely convert between different representations of the numeric + data. E.g.: + + @smallexample + ==> take 12 $ int8_list B + [100,0,0,0,-1,-1,-1,-1,102,0,0,0] + @end smallexample + @node Extended File Functions, C-Style Formatted I/O, Byte Strings, Clib @section Extended File Functions Index: version.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/version.texi,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** version.texi 16 Jan 2008 09:07:38 -0000 1.95 --- version.texi 18 Jan 2008 11:18:45 -0000 1.96 *************** *** 1,3 **** ! @set UPDATED 16 January 2008 @set UPDATED-MONTH January 2008 @set EDITION 7.11 --- 1,3 ---- ! @set UPDATED 18 January 2008 @set UPDATED-MONTH January 2008 @set EDITION 7.11 |
From: Albert G. <ag...@us...> - 2008-01-18 10:12:45
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9239 Modified Files: NEWS Log Message: update NEWS Index: NEWS =================================================================== RCS file: /cvsroot/q-lang/q/NEWS,v retrieving revision 1.136 retrieving revision 1.137 diff -C2 -d -r1.136 -r1.137 *** NEWS 16 Jan 2008 09:22:17 -0000 1.136 --- NEWS 18 Jan 2008 10:12:41 -0000 1.137 *************** *** 5,12 **** * 7.11 January 2008 (work in progress) ! As suggested by Rob Hubbard and John Cowan, special Unicode characters in ! strings can now be specified using an escape of the form '\&name;', where name ! is any of the XML entity names specified here: ! http://www.w3.org/TR/2007/WD-xml-entity-names-20071214/ --- 5,19 ---- * 7.11 January 2008 (work in progress) ! - As suggested by Rob Hubbard and John Cowan, special Unicode characters in ! strings can now be specified using an escape of the form '\&name;', where ! name is any of the XML entity names specified here: ! http://www.w3.org/TR/2007/WD-xml-entity-names-20071214/ ! ! - clib now provides a set of additional int/float vector operations, as ! suggested by John Cowan on the mailing list a while ago. These allow you to ! treat byte strings as mutable C vectors of signed/unsigned 8/16/32 bit ! integers or float/double values. Operations to convert between such C ! vectors and corresponding lists of integers/floating point values are ! provided as well. |
From: Albert G. <ag...@us...> - 2008-01-18 10:09:41
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv8012 Modified Files: ChangeLog Log Message: update ChangeLog Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.315 retrieving revision 1.316 diff -C2 -d -r1.315 -r1.316 *** ChangeLog 17 Jan 2008 08:25:23 -0000 1.315 --- ChangeLog 18 Jan 2008 10:09:38 -0000 1.316 *************** *** 1,2 **** --- 1,12 ---- + 2008-01-18 Albert Graef <Dr....@t-...> + + * modules/clib/clib.q, modules/clib/clib.c: add int/float vector + operations, as suggested by John Cowan + + These allow you to treat byte strings as mutable C vectors of + signed/unsigned 8/16/32 bit integers or float/double values. + Operations to convert between such C vectors and corresponding + lists of integers/floating point values are provided as well. + 2008-01-17 Albert Graef <Dr....@t-...> |
From: Albert G. <ag...@us...> - 2008-01-18 10:06:09
|
Update of /cvsroot/q-lang/q/modules/clib In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv6345/modules/clib Modified Files: clib.c clib.q Log Message: add int/float vector operations, as suggested by John Cowan Index: clib.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/clib/clib.q,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** clib.q 16 Dec 2007 20:23:21 -0000 1.32 --- clib.q 18 Jan 2008 10:06:05 -0000 1.33 *************** *** 257,260 **** --- 257,291 ---- (B1:ByteStr>=B2:ByteStr) = (bcmp B1 B2>=0); + /* As of Q 7.11, clib supports a number of additional operations which allow + you to treat byte strings as mutable C vectors of signed/unsigned 8/16/32 + bit integers or single/double precision floating point numbers. The + following functions provide read/write access to the elements of such C + vectors. Note that the given index argument I is interpreted relative to + the corresponding element type. Thus, e.g., get_uint32 B I returns the Ith + 32 bit integer rather than the integer at byte offset I. */ + + /* NOTE: Integer arguments must fit into machine integers, otherwise these + operations will fail. Integers passed for floating point arguments will be + coerced to floating point values automatically. */ + + public extern get_int8 B I, get_int16 B I, get_int32 B I; + public extern get_uint8 B I, get_uint16 B I, get_uint32 B I; + public extern get_float B I, get_double B I; + + public extern put_int8 B I X, put_int16 B I X, put_int32 B I X; + public extern put_uint8 B I X, put_uint16 B I X, put_uint32 B I X; + public extern put_float B I X, put_double B I X; + + /* Some convenience functions to convert between byte strings and lists of + integer/floating point elements. */ + + public extern int8_list B, int16_list B, int32_list B; + public extern uint8_list B, uint16_list B, uint32_list B; + public extern float_list B, double_list B; + + public extern int8_vect Xs, int16_vect Xs, int32_vect Xs; + public extern uint8_vect Xs, uint16_vect Xs, uint32_vect Xs; + public extern float_vect Xs, double_vect Xs; + /****************************************************************************/ Index: clib.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/clib/clib.c,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -d -r1.82 -r1.83 *** clib.c 16 Dec 2007 20:23:21 -0000 1.82 --- clib.c 18 Jan 2008 10:06:04 -0000 1.83 *************** *** 4040,4043 **** --- 4040,4564 ---- } + FUNCTION(clib,get_int8,argc,argv) + { + bstr_t *m; + long i; + if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && i >= 0 && i < m->size) + return mkint((signed char)m->v[i]); + else + return __FAIL; + } + + FUNCTION(clib,put_int8,argc,argv) + { + bstr_t *m; + long i, x; + if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && isint(argv[2], &x) && i >= 0 && i < m->size) { + m->v[i] = (signed char)x; + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(clib,get_int16,argc,argv) + { + bstr_t *m; + long i; + if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && i >= 0 && i < (m->size >> 1)) { + short *v = (short*)m->v; + return mkint(v[i]); + } else + return __FAIL; + } + + FUNCTION(clib,put_int16,argc,argv) + { + bstr_t *m; + long i, x; + if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && isint(argv[2], &x) && + i >= 0 && i < (m->size >> 1)) { + short *v = (short*)m->v; + v[i] = (short)x; + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(clib,get_int32,argc,argv) + { + bstr_t *m; + long i; + if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && i >= 0 && i < (m->size >> 2)) { + long *v = (long*)m->v; + return mkint(v[i]); + } else + return __FAIL; + } + + FUNCTION(clib,put_int32,argc,argv) + { + bstr_t *m; + long i, x; + if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && isint(argv[2], &x) && + i >= 0 && i < (m->size >> 2)) { + long *v = (long*)m->v; + v[i] = (long)x; + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(clib,get_uint8,argc,argv) + { + bstr_t *m; + long i; + if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && i >= 0 && i < m->size) + return mkuint((unsigned char)m->v[i]); + else + return __FAIL; + } + + FUNCTION(clib,put_uint8,argc,argv) + { + bstr_t *m; + long i; + unsigned long x; + if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && isuint(argv[2], &x) && i >= 0 && i < m->size) { + m->v[i] = (unsigned char)x; + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(clib,get_uint16,argc,argv) + { + bstr_t *m; + long i; + if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && i >= 0 && i < (m->size >> 1)) { + unsigned short *v = (unsigned short*)m->v; + return mkuint(v[i]); + } else + return __FAIL; + } + + FUNCTION(clib,put_uint16,argc,argv) + { + bstr_t *m; + long i; + unsigned long x; + if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && isuint(argv[2], &x) && + i >= 0 && i < (m->size >> 1)) { + short *v = (short*)m->v; + v[i] = (short)x; + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(clib,get_uint32,argc,argv) + { + bstr_t *m; + long i; + if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && i >= 0 && i < (m->size >> 2)) { + unsigned long *v = (unsigned long*)m->v; + return mkuint(v[i]); + } else + return __FAIL; + } + + FUNCTION(clib,put_uint32,argc,argv) + { + bstr_t *m; + long i; + unsigned long x; + if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && isuint(argv[2], &x) && + i >= 0 && i < (m->size >> 2)) { + unsigned long *v = (unsigned long*)m->v; + v[i] = (unsigned long)x; + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(clib,get_float,argc,argv) + { + bstr_t *m; + long i; + if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && i >= 0 && i < (m->size / sizeof(float))) { + float *v = (float*)m->v; + return mkfloat(v[i]); + } else + return __FAIL; + } + + FUNCTION(clib,put_float,argc,argv) + { + bstr_t *m; + long i; + double x; + if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && + (isfloat(argv[2], &x) || ismpz_float(argv[2], &x)) && + i >= 0 && i < (m->size / sizeof(float))) { + float *v = (float*)m->v; + v[i] = (float)x; + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(clib,get_double,argc,argv) + { + bstr_t *m; + long i; + if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && i >= 0 && i < (m->size / sizeof(double))) { + double *v = (double*)m->v; + return mkfloat(v[i]); + } else + return __FAIL; + } + + FUNCTION(clib,put_double,argc,argv) + { + bstr_t *m; + long i; + double x; + if (argc == 3 && isobj(argv[0], type(ByteStr), (void**)&m) && + isint(argv[1], &i) && + (isfloat(argv[2], &x) || ismpz_float(argv[2], &x)) && + i >= 0 && i < (m->size / sizeof(double))) { + double *v = (double*)m->v; + v[i] = x; + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(clib,int8_list,argc,argv) + { + bstr_t *m; + if (argc == 1 && isobj(argv[0], type(ByteStr), (void**)&m)) { + int i, n = m->size; + signed char *v = (signed char*)m->v; + expr *xv; + if (n <= 0) return mknil; + xv = malloc(n*sizeof(expr)); + if (!xv) return __ERROR; + for (i = 0; i < n; i++) + xv[i] = mkint(v[i]); + return mklistv(n, xv); + } else + return __FAIL; + } + + FUNCTION(clib,uint8_list,argc,argv) + { + bstr_t *m; + if (argc == 1 && isobj(argv[0], type(ByteStr), (void**)&m)) { + int i, n = m->size; + unsigned char *v = (unsigned char*)m->v; + expr *xv; + if (n <= 0) return mknil; + xv = malloc(n*sizeof(expr)); + if (!xv) return __ERROR; + for (i = 0; i < n; i++) + xv[i] = mkuint(v[i]); + return mklistv(n, xv); + } else + return __FAIL; + } + + FUNCTION(clib,int16_list,argc,argv) + { + bstr_t *m; + if (argc == 1 && isobj(argv[0], type(ByteStr), (void**)&m)) { + int i, n = m->size >> 1; + short *v = (short*)m->v; + expr *xv; + if (n <= 0) return mknil; + xv = malloc(n*sizeof(expr)); + if (!xv) return __ERROR; + for (i = 0; i < n; i++) + xv[i] = mkint(v[i]); + return mklistv(n, xv); + } else + return __FAIL; + } + + FUNCTION(clib,uint16_list,argc,argv) + { + bstr_t *m; + if (argc == 1 && isobj(argv[0], type(ByteStr), (void**)&m)) { + int i, n = m->size >> 1; + unsigned short *v = (unsigned short*)m->v; + expr *xv; + if (n <= 0) return mknil; + xv = malloc(n*sizeof(expr)); + if (!xv) return __ERROR; + for (i = 0; i < n; i++) + xv[i] = mkuint(v[i]); + return mklistv(n, xv); + } else + return __FAIL; + } + + FUNCTION(clib,int32_list,argc,argv) + { + bstr_t *m; + if (argc == 1 && isobj(argv[0], type(ByteStr), (void**)&m)) { + int i, n = m->size >> 2; + long *v = (long*)m->v; + expr *xv; + if (n <= 0) return mknil; + xv = malloc(n*sizeof(expr)); + if (!xv) return __ERROR; + for (i = 0; i < n; i++) + xv[i] = mkint(v[i]); + return mklistv(n, xv); + } else + return __FAIL; + } + + FUNCTION(clib,uint32_list,argc,argv) + { + bstr_t *m; + if (argc == 1 && isobj(argv[0], type(ByteStr), (void**)&m)) { + int i, n = m->size >> 2; + unsigned long *v = (unsigned long*)m->v; + expr *xv; + if (n <= 0) return mknil; + xv = malloc(n*sizeof(expr)); + if (!xv) return __ERROR; + for (i = 0; i < n; i++) + xv[i] = mkuint(v[i]); + return mklistv(n, xv); + } else + return __FAIL; + } + + FUNCTION(clib,float_list,argc,argv) + { + bstr_t *m; + if (argc == 1 && isobj(argv[0], type(ByteStr), (void**)&m)) { + int i, n = m->size / sizeof(float); + float *v = (float*)m->v; + expr *xv; + if (n <= 0) return mknil; + xv = malloc(n*sizeof(expr)); + if (!xv) return __ERROR; + for (i = 0; i < n; i++) + xv[i] = mkfloat(v[i]); + return mklistv(n, xv); + } else + return __FAIL; + } + + FUNCTION(clib,double_list,argc,argv) + { + bstr_t *m; + if (argc == 1 && isobj(argv[0], type(ByteStr), (void**)&m)) { + int i, n = m->size / sizeof(double); + double *v = (double*)m->v; + expr *xv; + if (n <= 0) return mknil; + xv = malloc(n*sizeof(expr)); + if (!xv) return __ERROR; + for (i = 0; i < n; i++) + xv[i] = mkfloat(v[i]); + return mklistv(n, xv); + } else + return __FAIL; + } + + FUNCTION(clib,int8_vect,argc,argv) + { + if (argc == 1) { + expr xs = argv[0], hd, tl; + int i, n = 0; + long x; + signed char *v; + while (iscons(xs, &hd, &tl) && isint(hd, &x)) { + xs = tl; n++; + } + if (!isnil(xs)) return __FAIL; + if (n <= 0) return mkbstr(0, NULL); + if (!(v = malloc(n))) return __ERROR; + xs = argv[0]; n = 0; + while (iscons(xs, &hd, &tl) && isint(hd, &x)) { + xs = tl; v[n++] = (signed char)x; + } + return mkbstr(n, v); + } else + return __FAIL; + } + + FUNCTION(clib,int16_vect,argc,argv) + { + if (argc == 1) { + expr xs = argv[0], hd, tl; + int i, n = 0; + long x; + short *v; + while (iscons(xs, &hd, &tl) && isint(hd, &x)) { + xs = tl; n++; + } + if (!isnil(xs)) return __FAIL; + if (n <= 0) return mkbstr(0, NULL); + if (!(v = malloc(n*sizeof(short)))) return __ERROR; + xs = argv[0]; n = 0; + while (iscons(xs, &hd, &tl) && isint(hd, &x)) { + xs = tl; v[n++] = (short)x; + } + return mkbstr(n*sizeof(short), v); + } else + return __FAIL; + } + + FUNCTION(clib,int32_vect,argc,argv) + { + if (argc == 1) { + expr xs = argv[0], hd, tl; + int i, n = 0; + long x; + long *v; + while (iscons(xs, &hd, &tl) && isint(hd, &x)) { + xs = tl; n++; + } + if (!isnil(xs)) return __FAIL; + if (n <= 0) return mkbstr(0, NULL); + if (!(v = malloc(n*sizeof(long)))) return __ERROR; + xs = argv[0]; n = 0; + while (iscons(xs, &hd, &tl) && isint(hd, &x)) { + xs = tl; v[n++] = x; + } + return mkbstr(n*sizeof(long), v); + } else + return __FAIL; + } + + FUNCTION(clib,uint8_vect,argc,argv) + { + if (argc == 1) { + expr xs = argv[0], hd, tl; + int i, n = 0; + unsigned long x; + unsigned char *v; + while (iscons(xs, &hd, &tl) && isuint(hd, &x)) { + xs = tl; n++; + } + if (!isnil(xs)) return __FAIL; + if (n <= 0) return mkbstr(0, NULL); + if (!(v = malloc(n))) return __ERROR; + xs = argv[0]; n = 0; + while (iscons(xs, &hd, &tl) && isuint(hd, &x)) { + xs = tl; v[n++] = (unsigned char)x; + } + return mkbstr(n, v); + } else + return __FAIL; + } + + FUNCTION(clib,uint16_vect,argc,argv) + { + if (argc == 1) { + expr xs = argv[0], hd, tl; + int i, n = 0; + unsigned long x; + unsigned short *v; + while (iscons(xs, &hd, &tl) && isuint(hd, &x)) { + xs = tl; n++; + } + if (!isnil(xs)) return __FAIL; + if (n <= 0) return mkbstr(0, NULL); + if (!(v = malloc(n*sizeof(unsigned short)))) return __ERROR; + xs = argv[0]; n = 0; + while (iscons(xs, &hd, &tl) && isuint(hd, &x)) { + xs = tl; v[n++] = (unsigned short)x; + } + return mkbstr(n*sizeof(unsigned short), v); + } else + return __FAIL; + } + + FUNCTION(clib,uint32_vect,argc,argv) + { + if (argc == 1) { + expr xs = argv[0], hd, tl; + int i, n = 0; + unsigned long x; + unsigned long *v; + while (iscons(xs, &hd, &tl) && isuint(hd, &x)) { + xs = tl; n++; + } + if (!isnil(xs)) return __FAIL; + if (n <= 0) return mkbstr(0, NULL); + if (!(v = malloc(n*sizeof(unsigned long)))) return __ERROR; + xs = argv[0]; n = 0; + while (iscons(xs, &hd, &tl) && isuint(hd, &x)) { + xs = tl; v[n++] = x; + } + return mkbstr(n*sizeof(unsigned long), v); + } else + return __FAIL; + } + + FUNCTION(clib,float_vect,argc,argv) + { + if (argc == 1) { + expr xs = argv[0], hd, tl; + int i, n = 0; + double x; + float *v; + while (iscons(xs, &hd, &tl) && (isfloat(hd, &x) || ismpz_float(hd, &x))) { + xs = tl; n++; + } + if (!isnil(xs)) return __FAIL; + if (n <= 0) return mkbstr(0, NULL); + if (!(v = malloc(n*sizeof(float)))) return __ERROR; + xs = argv[0]; n = 0; + while (iscons(xs, &hd, &tl) && (isfloat(hd, &x) || ismpz_float(hd, &x))) { + xs = tl; v[n++] = (float)x; + } + return mkbstr(n*sizeof(float), v); + } else + return __FAIL; + } + + FUNCTION(clib,double_vect,argc,argv) + { + if (argc == 1) { + expr xs = argv[0], hd, tl; + int i, n = 0; + double x; + double *v; + while (iscons(xs, &hd, &tl) && (isfloat(hd, &x) || ismpz_float(hd, &x))) { + xs = tl; n++; + } + if (!isnil(xs)) return __FAIL; + if (n <= 0) return mkbstr(0, NULL); + if (!(v = malloc(n*sizeof(double)))) return __ERROR; + xs = argv[0]; n = 0; + while (iscons(xs, &hd, &tl) && (isfloat(hd, &x) || ismpz_float(hd, &x))) { + xs = tl; v[n++] = x; + } + return mkbstr(n*sizeof(double), v); + } else + return __FAIL; + } + /* references: ************************************************************/ |
From: Albert G. <ag...@us...> - 2008-01-18 02:31:50
|
Update of /cvsroot/q-lang/q/src In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24143 Modified Files: w3centities.c Log Message: fix some minor glitches in the generated entities table, as pointed out by John Cowan Index: w3centities.c =================================================================== RCS file: /cvsroot/q-lang/q/src/w3centities.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** w3centities.c 16 Jan 2008 09:02:46 -0000 1.1 --- w3centities.c 18 Jan 2008 02:31:46 -0000 1.2 *************** *** 1,3 **** ! /* generated from w3centities.ent Wed Jan 16 08:17:24 2008 */ typedef struct ENTITY { char *name; long c; } Entity; --- 1,3 ---- ! /* generated from w3centities.ent Fri Jan 18 03:24:08 2008 */ typedef struct ENTITY { char *name; long c; } Entity; *************** *** 89,93 **** { "Dopf", 0x1D53B }, { "Dot", 0x000A8 }, - { "DotDot", 0x020DC }, { "DotEqual", 0x02250 }, { "DoubleContourIntegral", 0x0222F }, --- 89,92 ---- *************** *** 107,111 **** { "DownArrowBar", 0x02913 }, { "DownArrowUpArrow", 0x021F5 }, - { "DownBreve", 0x00311 }, { "DownLeftRightVector", 0x02950 }, { "DownLeftTeeVector", 0x0295E }, --- 106,109 ---- *************** *** 500,504 **** { "TildeTilde", 0x02248 }, { "Topf", 0x1D54B }, - { "TripleDot", 0x020DB }, { "Tscr", 0x1D4AF }, { "Tstrok", 0x00166 }, --- 498,501 ---- *************** *** 517,521 **** { "Ugrave", 0x000D9 }, { "Umacr", 0x0016A }, - { "UnderBar", 0x00332 }, { "UnderBrace", 0x0FE38 }, { "UnderBracket", 0x023B5 }, --- 514,517 ---- *************** *** 606,609 **** --- 602,606 ---- { "amacr", 0x00101 }, { "amalg", 0x02A3F }, + { "amp", 0x00026 }, { "and", 0x02227 }, { "andand", 0x02A55 }, *************** *** 1356,1359 **** --- 1353,1357 ---- { "lsquor", 0x0201A }, { "lstrok", 0x00142 }, + { "lt", 0x0003C }, { "ltcc", 0x02AA6 }, { "ltcir", 0x02A79 }, *************** *** 1922,1926 **** { "tcedil", 0x00163 }, { "tcy", 0x00442 }, - { "tdot", 0x020DB }, { "telrec", 0x02315 }, { "tfr", 0x1D531 }, --- 1920,1923 ---- |
From: RER <ed...@us...> - 2008-01-17 20:54:25
|
Update of /cvsroot/q-lang/q-csv In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12881 Modified Files: csv.c csv.q Log Message: added sreadcsv/swritecsv routines, updated routines to have multichar delimiters Index: csv.c =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** csv.c 14 Jan 2008 06:15:17 -0000 1.9 --- csv.c 17 Jan 2008 20:54:18 -0000 1.10 *************** *** 1,3 **** ! /* CSV according to RFC 4180 (http://tools.ietf.rg/html/rfc4180) This is free software; you can redistribute it and/or --- 1,3 ---- ! /* CSV according to RFC 4180 (http://tools.ietf.rg/html/rfc4180.txt) This is free software; you can redistribute it and/or *************** *** 17,21 **** $Id$ ! Written by Eddie Rucker 3-13 Jan, 2008 */ #include <stdio.h> --- 17,21 ---- $Id$ ! Written by Eddie Rucker 3-17 Jan, 2008 */ #include <stdio.h> *************** *** 29,86 **** #define AUTOQUOTE 1 ! /* fread_block reads embbeded '\n's ! Does not account for badly formatted records */ FUNCTION (csv, fread_csvstr, argc, argv) { FILE *fp; ! char *buff, *bp, *tp, *strdl, *s; ! int len = 0, q_cnt = 0, size = BSIZE; ! register int c; ! if (argc != 2 ! || !isfile(argv[0], &fp) ! || !isstr(argv[1], &strdl)) return __FAIL; ! if (!(buff = (char *)malloc(size))) ! return NULL; ! bp = buff; ! while ((c = fgetc(fp)) != EOF) { ! if (len > size) { ! if (!(tp = (char *)realloc(buff, size <<= 1))) { ! free(buff); return __ERROR; } ! buff = tp; ! bp = buff + len; } - if (c == '\n' && !(q_cnt & 1)) - break; - if (c == *strdl) - ++q_cnt; - ++len; - *bp++ = c; } - *bp++ = c; - *bp = 0; - s = to_utf8(buff, NULL); - free(buff); - if (s) - return mkstr(s); - else - return __ERROR; } - /* convience function to convert numbers */ ! expr *convert(char *s, int cvt_flag) { long i; double d; char *p, *t; ! if (cvt_flag) { i = strtol(s, &p, 0); if (*p == 0) --- 29,93 ---- #define AUTOQUOTE 1 ! /* fread_block reads embbeded '\n's. ! Does not account for badly formatted records. ! */ FUNCTION (csv, fread_csvstr, argc, argv) { FILE *fp; ! char *bf, *tb, *s_dl, *s; ! int n_q = 0, n_s_dl; ! long sz = BSIZE, n = 0; ! if (argc != 2 || !isfile(argv[0], &fp) || !isstr(argv[1], &s_dl)) return __FAIL; ! if (!(s = bf = (char *)malloc(sz))) ! return __ERROR; ! n_s_dl = strlen(s_dl); ! while (1) { ! s = bf + n; ! if (n + BSIZE > sz) { ! if (!(tb = realloc(bf, sz <<= 1))) { ! free(bf); return __ERROR; } ! s = (bf = tb) + n; ! } ! fgets(s, BSIZE, fp); ! if (ferror(fp)) { ! free(bf); ! return __ERROR; ! } ! if (feof(fp)) ! goto fini; ! n += strlen(s); ! if (!*(bf+n-1) == '\n') ! continue; ! while (*s) { ! if (!strncmp(s, s_dl, n_s_dl)) { ! ++n_q; ! s += n_s_dl; ! } else ! ++s; ! } ! if (!(n_q & 1)) { ! fini: ! s = to_utf8(bf, NULL); ! free(bf); ! return mkstr(s); } } } /* convience function to convert numbers */ ! expr *convert(char *s, int cvt_f) { long i; double d; char *p, *t; ! if (cvt_f) { i = strtol(s, &p, 0); if (*p == 0) *************** *** 95,120 **** } ! #define putfld \ ! if (fld_len >= fld_size - 1) { \ ! if (!(tfield = (char *)realloc(field, fld_size <<= 1))) \ ! goto st30; \ ! field = tfield; \ ! } \ ! fieldp = field + fld_len++; \ ! *fieldp++ = *sp ! ! ! /* force == 0 forces the field to be quoted */ ! ! #define putrec(force) \ ! *fieldp = 0; \ ! if (rec_len >= rec_size - 1) { \ ! if (!(trec = (expr *)realloc(rec, (rec_size += 16)*sizeof(expr)))) \ ! goto st30; \ rec = trec; \ } \ ! if ((rec[rec_len++] = convert(field, cvt_f&force)) == NULL) \ ! goto st30 --- 102,126 ---- } + #define putfld(len) \ + if (n_fld + len >= fld_sz) { \ + if (!(tfld = (char *)realloc(fld, fld_sz <<= 1))) \ + goto done; \ + fld = tfld; \ + } \ + fldp = fld + n_fld; \ + strncpy(fldp, s, len); \ + n_fld += len \ + + /* qt == 0 forces the field to be quoted */ ! #define putrec(qt) \ ! *(fldp + 1) = 0; \ ! if (n_rec >= rec_sz - 1) { \ ! if (!(trec = (expr *)realloc(rec, (rec_sz += 64)*sizeof(expr)))) \ ! goto done; \ rec = trec; \ } \ ! if ((rec[n_rec++] = convert(fld, qt)) == NULL) \ ! goto done *************** *** 135,143 **** FUNCTION(csv, csvstr_to_tuple, argc, argv) { ! int n, cvt_f, fld_size = 256, fld_len, rec_size = 64, ws_cnt = 0, ! rec_len = 0, exit_type = 0; ! char *field, *tfield, *fieldp, *s, *flddl, *strdl, errmsg[80]; expr *xs, *rec, *trec; ! register char *sp; if (argc != 2 --- 141,149 ---- FUNCTION(csv, csvstr_to_tuple, argc, argv) { ! int n, cvt_f, fld_sz = 256, n_fld, rec_sz = 64, n_ws = 0, ! n_rec = 0, n_s_dl, n_fld_dl, st = 0; ! char *fld, *tfld, *fldp, *s, *fld_dl, *s_dl, errmsg[80]; expr *xs, *rec, *trec; ! char *sp; if (argc != 2 *************** *** 145,290 **** || n != 3 || !isbool(xs[0], &cvt_f) ! || !isstr(xs[1], &flddl) ! || !isstr(xs[2], &strdl) || !isstr(argv[1], &s)) return __FAIL; ! ! if (!(field = (char *)malloc(fld_size))) return __ERROR; ! if (!(rec = (expr *)malloc(rec_size*sizeof(expr)))) { ! free(field); return __ERROR; } ! ! sp = s - 1; ! st0: ++sp; ! fieldp = field; ! fld_len = 0; ! if (!strncmp(sp, flddl, 1)) { ! putrec(FORCEQUOTE); ! goto st0; ! } else if (!strncmp(sp, strdl, 1)) { ! goto st1; ! } else if (*sp == '\n' || *sp == 0) { ! putrec(FORCEQUOTE); ! goto st10; ! } else if (isspace(*sp)) { ! /* fld_dlm might be ws make sure it is after (c == *fld_dlm) */ ! goto st0; ! } else { ! putfld; ! goto st4; ! } ! st1: ++sp; ! if (!strncmp(sp, strdl, 1)) { ! goto st2; ! } else if (*sp == 0) { ! goto st20; ! } else { ! putfld; ! goto st1; ! } ! st2: ++sp; ! if (!strncmp(sp, strdl, 1)) { ! putfld; ! goto st1; ! } else if (!strncmp(sp, flddl, 1)) { ! putrec(FORCEQUOTE); ! goto st0; ! } else if (*sp == '\n' || *sp == 0) { ! putrec(FORCEQUOTE); ! goto st10; ! } else if (isspace(*sp)) { ! /* fld_dlm might be ws make sure it is after (c == *fld_dlm) */ ! goto st3; ! } else { ! goto st20; ! } ! st3: ++sp; ! if (!strncmp(sp, flddl, 1)) { ! putrec(FORCEQUOTE); ! goto st0; ! } else if (*sp == '\n' || *sp == 0) { ! putrec(FORCEQUOTE); ! goto st10; ! } else if (isspace(*sp)) { ! /* fld_dlm might be ws make sure it is after (c == *fld_dlm) */ ! goto st3; ! } else { ! goto st20; ! } ! st4: ++sp; ! if (!strncmp(sp, flddl, 1)) { ! putrec(AUTOQUOTE); ! goto st0; ! } else if (*sp == '\n' || *sp == 0) { ! putrec(AUTOQUOTE); ! goto st10; ! } else if (!strncmp(sp, strdl, 1)) { ! goto st20; ! } else if (isspace(*sp)) { ! /* fld_dlm might be ws make sure it is after (c == *fld_dlm) */ ! ws_cnt = 1; ! putfld; ! goto st5; ! } else { ! putfld; ! goto st4; ! } ! st5: ++sp; ! if (!strncmp(sp, flddl, 1)) { ! fieldp -= ws_cnt; /* get rid of ws at the end of the field */ ! putrec(AUTOQUOTE); ! goto st0; ! } else if (*sp == '\n' || *sp == 0) { ! fieldp -= ws_cnt; /* get rid of ws at the end of the field */ ! putrec(AUTOQUOTE); ! goto st10; ! } else if (isspace(*sp)) { ! /* fld_dlm might be ws make sure it is after (c == *fld_dlm) */ ! ++ws_cnt; ! putfld; ! goto st5; ! } else { ! putfld; ! goto st4; } ! st10: ! free(field); ! rec = realloc(rec, rec_len*sizeof(expr)); ! return mktuplev(rec_len, rec); ! st20: ! exit_type = 1; ! st30: ! free(field); ! for (n = 0; n < rec_len; ++n) ! dispose(rec[n]); ! free(rec); ! if (exit_type == 1) { ! sprintf(errmsg, "Column %d: Unexpected end of file.", (fld_len+1)); ! return mkapp(mksym(sym(csv_error)), mkstr(strdup(errmsg))); } - return __ERROR; } - #define resize_str \ ! if (len > size) { \ ! if (!(tstr = realloc(str, sizeof(char)*(size <<= 1)))) { \ ! free(str); \ return __ERROR; \ } \ ! str = tstr; \ } \ ! t = str + mark #define insert_num \ ! mark = len; \ ! len += strlen(tbuff); \ resize_str; \ ! strncpy(t, tbuff, len - mark) ! /* convert tuple to csv string --- 151,297 ---- || n != 3 || !isbool(xs[0], &cvt_f) ! || !isstr(xs[1], &fld_dl) ! || !isstr(xs[2], &s_dl) || !isstr(argv[1], &s)) return __FAIL; ! ! if (!(fld = (char *)malloc(fld_sz))) return __ERROR; ! if (!(rec = (expr *)malloc(rec_sz*sizeof(expr)))) { ! free(fld); return __ERROR; } ! ! n_s_dl = strlen(s_dl); ! n_fld_dl = strlen(fld_dl); ! fldp = fld; ! while (st < 10) { ! switch (st) { ! case 0: ! fldp = fld; ! n_fld = 0; ! if (!strncmp(s, fld_dl, n_fld_dl)) { ! *fldp = 0; ! putrec(FORCEQUOTE); ! s += n_fld_dl; ! } else if (!strncmp(s, s_dl, n_s_dl)) { ! s += n_s_dl; ! st = 1; ! } else if (!*s || *s == '\n' || *s == EOF) { ! putrec(FORCEQUOTE); ! st = 10; ! } else if (isspace(*s)) { ! ++s; ! } else { ! putfld(1); ! ++s; ! st = 4; ! } ! break; ! case 1: ! if (!strncmp(s, s_dl, n_s_dl)) { ! s += n_s_dl; ! st = 2; ! } else if (!*s || *s == EOF) { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, s_dl); ! st = 20; ! } else { ! putfld(1); ! ++s; ! } ! break; ! case 2: ! if (!strncmp(s, s_dl, n_s_dl)) { ! putfld(n_s_dl); ! s += n_s_dl; ! st = 1; ! } else if (!strncmp(s, fld_dl, n_fld_dl)) { ! putrec(FORCEQUOTE); ! s += n_fld_dl; ! st = 0; ! } else if (!*s || *s == '\n' || *s == EOF) { ! putrec(FORCEQUOTE); ! st = 10; ! } else if (isspace(*s)) { ! ++s; ! st = 3; ! } else { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, fld_dl); ! st = 20; ! } ! break; ! case 3: ! if (!strncmp(s, fld_dl, n_fld_dl)) { ! putrec(FORCEQUOTE); ! s += n_fld_dl; ! st = 0; ! } else if (!*s || *s == '\n' || *s == EOF) { ! putrec(FORCEQUOTE); ! st = 10; ! } else if (isspace(*s)) { ! ++s; ! } else { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, fld_dl); ! st = 20; ! } ! break; ! case 4: ! if (!strncmp(s, s_dl, n_s_dl)) { ! sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, fld_dl); ! st = 20; ! } else if (!strncmp(s, fld_dl, n_fld_dl)) { ! fldp -= n_ws; ! n_fld -= n_ws; ! putrec(cvt_f); ! s += n_fld_dl; ! st = 0; ! } else if (!*s || *s == '\n' || *s == EOF) { ! putrec(cvt_f); ! st = 10; ! } else if (isspace(*s)) { ! n_ws = n_ws ? n_ws+1 : 1; ! putfld(1); ! ++s; ! } else { ! n_ws = 0; ! putfld(1); ! ++s; ! } ! break; ! } } ! done: ! free(fld); ! switch (st) { ! case 10: ! rec = realloc(rec, sizeof(expr)*n_rec); ! return mktuplev(n_rec, rec); ! default: ! for (n = 0; n < n_rec; ++n) ! dispose(rec[n]); ! free(rec); ! if (st == 20) ! return mkapp(mksym(sym(csv_error)), mkstr(strdup(errmsg))); ! return __ERROR; } } #define resize_str \ ! if (len > sz) { \ ! if (!(ts = (char *)realloc(s, sz <<= 1))) { \ ! free(s); \ return __ERROR; \ } \ ! s = ts; \ } \ ! t = s + mrk #define insert_num \ ! mrk = len; \ ! len += strlen(tb); \ resize_str; \ ! strncpy(t, tb, len - mrk) /* convert tuple to csv string *************** *** 304,309 **** FUNCTION (csv, tuple_to_csvstr, argc, argv) { ! int i, n, size = 256, mark, qcnt, len = 0, cvt_f; ! char *str, *tstr, *sval, *strdl, *flddl, *p, tbuff[48], errmsg[80]; long ival; double dval; --- 311,316 ---- FUNCTION (csv, tuple_to_csvstr, argc, argv) { ! int i, n, sz = 256, mrk, n_q, len = 0, cvt_f, n_s_dl, n_fld_dl; ! char *s, *ts, *p, *sval, *s_dl, *fld_dl, tb[48], errmsg[80]; long ival; double dval; *************** *** 315,375 **** || i != 3 || !isbool(ys[0], &cvt_f) /* unquote flag */ ! || !isstr(ys[1], &flddl) ! || !isstr(ys[2], &strdl) || !istuple(argv[1], &n, &xs)) return __FAIL; ! if (!(str = (char *)malloc(size))) return __ERROR; ! for (i = 0; i < n; ++i) { if (isint(xs[i], &ival)) { if (cvt_f) ! sprintf(tbuff, "%d%s", ival, flddl); else ! sprintf(tbuff, "%s%d%s%s", strdl, ival, strdl, flddl); insert_num; } else if (isfloat(xs[i], &dval)) { if (cvt_f) ! sprintf(tbuff, "%.16g%s", dval, flddl); else ! sprintf(tbuff, "%s%.16g%s%s", strdl, dval, strdl, flddl); insert_num; } else if (isstr(xs[i], &sval)) { ! qcnt = 0; p = sval; ! while (*p) ! if (!strncmp(p++, strdl, 1)) ! ++qcnt; ! mark = len; ! len += p - sval + qcnt + 3; /* strlen + double strdls + dquotes */ resize_str; p = sval; ! *t++ = *strdl; ! while (*t++ = *p) { ! if (!strncmp(p, strdl, 1)) ! *t++ = *p; ! ++p; } ! --t; ! *t++ = *strdl; ! *t++ = *flddl; } else { ! sprintf(errmsg, "Field %d: Invalid conversion type.", (i+1)); return mkapp(mksym(sym(csv_error)), mkstr(strdup(errmsg))); } } ! mark = len; #if defined (_WIN32) ! len += 2; resize_str; *(t-2) = '\r'; #else - ++len; resize_str; #endif *(t-1) = '\n'; *t = 0; ! str = (char *)realloc(str, len); ! return mkstr(str); } --- 322,393 ---- || i != 3 || !isbool(ys[0], &cvt_f) /* unquote flag */ ! || !isstr(ys[1], &fld_dl) ! || !isstr(ys[2], &s_dl) || !istuple(argv[1], &n, &xs)) return __FAIL; ! if (!(s = (char *)malloc(sz))) return __ERROR; ! ! n_s_dl = strlen(s_dl); ! n_fld_dl = strlen(fld_dl); for (i = 0; i < n; ++i) { if (isint(xs[i], &ival)) { if (cvt_f) ! sprintf(tb, "%d%s", ival, fld_dl); else ! sprintf(tb, "%s%d%s%s", s_dl, ival, s_dl, fld_dl); insert_num; } else if (isfloat(xs[i], &dval)) { if (cvt_f) ! sprintf(tb, "%.16g%s", dval, fld_dl); else ! sprintf(tb, "%s%.16g%s%s", s_dl, dval, s_dl, fld_dl); insert_num; } else if (isstr(xs[i], &sval)) { ! n_q = 0; p = sval; ! while (*p) { ! if (!strncmp(p, s_dl, n_s_dl)) ! ++n_q; ! ++p; ! } ! mrk = len; ! /* strlen + double s_dls + dquotes + fld_dl */ ! len += (p - sval + 1) + n_s_dl*(1 + n_q) + n_fld_dl; resize_str; p = sval; ! strncpy(t, s_dl, n_s_dl); ! t += n_s_dl; ! while (*p) { ! if (!strncmp(p, s_dl, n_s_dl)) { ! strncpy(t, s_dl, n_s_dl); ! t += n_s_dl; ! strncpy(t, s_dl, n_s_dl); ! t += n_s_dl; ! p += n_s_dl; ! } else ! *t++ = *p++; } ! strncpy(t, s_dl, n_s_dl); ! t += n_s_dl; ! strncpy(t, fld_dl, n_fld_dl); ! t += n_fld_dl; } else { ! sprintf(errmsg, "Field %d: Invalid conversion type.", i+1); return mkapp(mksym(sym(csv_error)), mkstr(strdup(errmsg))); } } ! mrk = (len -= n_fld_dl - 1); /* write over last fld_dl */ #if defined (_WIN32) ! ++len; /* guarantee enough space for for \r\n */ resize_str; *(t-2) = '\r'; #else resize_str; #endif *(t-1) = '\n'; *t = 0; ! s = (char *)realloc(s, len); ! return mkstr(s); } Index: csv.q =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.q,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** csv.q 14 Jan 2008 04:28:03 -0000 1.9 --- csv.q 17 Jan 2008 20:54:18 -0000 1.10 *************** *** 49,55 **** NOTES ! (1) A properly formated CSV string MUST end with a '\n'. ! (2) When the auto conversion flag is false, all fields are strings. ! (3) The 'csv_error MSG' rule is invoked on improperly formatted strings. */ --- 49,54 ---- NOTES ! (1) When the auto conversion flag is false, all fields are strings. ! (2) The 'csv_error MSG' rule is invoked on improperly formatted strings. */ *************** *** 57,60 **** --- 56,125 ---- /* User may define csv_error for custom error handling. */ + /* String functions */ + public sreadcsv_data ARGS; + sreadcsv_data S:String + = csvstr_to_tuple (true, ",", "\"") S; + sreadcsv_data (S:String, FieldDelim:String) + = csvstr_to_tuple (true, FieldDelim, "\"") S; + sreadcsv_data (S:String, FieldDelim:String, StrDelim:String) + = csvstr_to_tuple (true, FieldDelim, StrDelim) S; + + public sreadcsv_string ARGS; + sreadcsv_string S:String + = csvstr_to_tuple (false, ",", "\"") S; + sreadcsv_string (S:String, FieldDelim:String) + = csvstr_to_tuple (false, FieldDelim, "\"") S; + sreadcsv_string (S:String, FieldDelim:String, StrDelim:String) + = csvstr_to_tuple (false, FieldDelim, StrDelim) S; + + public sreadcsvlist_data ARGS; + sreadcsvlist_data L:List + = map (csvstr_to_tuple (true, ",", "\"")) L; + sreadcsvlist_data (S:String, FieldDelim:String) + = map (csvstr_to_tuple (true, FieldDelim, "\"")) L; + sreadcsvlist_data (S:String, FieldDelim:String, StrDelim:String) + = map (csvstr_to_tuple (true, FieldDelim, StrDelim)) L; + + public sreadcsvlist_string ARGS; + sreadcsvlist_string L:List + = map (csvstr_to_tuple (false, ",", "\"")) L; + sreadcsvlist_string (S:String, FieldDelim:String) + = map (csvstr_to_tuple (false, FieldDelim, "\"")) L; + sreadcsvlist_string (S:String, FieldDelim:String, StrDelim:String) + = map (csvstr_to_tuple (false, FieldDelim, StrDelim)) L; + + public swritecsv_data ARGS; + swritecsv_data Rec:Tuple + = tuple_to_csvstr (true, ",", "\"") Rec; + swritecsv_data (Rec:Tuple, FieldDelim:String) + = tuple_to_csvstr (true, FieldDelim, "\"") Rec; + swritecsv_data (Rec:Tuple, FieldDelim:String, StrDelim:String) + = tuple_to_csvstr (true, FieldDelim, StrDelim) Tec; + + public swritecsv_string ARGS; + swritecsv_string Rec:Tuple + = tuple_to_csvstr (false, ",", "\"") Rec; + swritecsv_string (Rec:Tuple, FieldDelim:String) + = tuple_to_csvstr (false, FieldDelim, "\"") Rec; + swritecsv_string (Rec:Tuple, FieldDelim:String, StrDelim:String) + = tuple_to_csvstr (false, FieldDelim, StrDelim) Rec; + + public swritecsvlist_data ARGS; + swritecsvlist_data L:List + = map (tuple_to_csvstr (true, ",", "\"")) L; + swritecsvlist_data (L:List, FieldDelim:String) + = map (tuple_to_csvstr (true, FieldDelim, "\"")) L; + swritecsvlist_data (L:List, FieldDelim:String, StrDelim:String) + = map (tuple_to_csvstr (true, FieldDelim, StrDelim)) L; + + public swritecsvlist_string ARGS; + swritecsvlist_string L:List + = map (tuple_to_csvstr (false, ",", "\"")) L; + swritecsvlist_string (L:List, FieldDelim:String) + = map (tuple_to_csvstr (false, FieldDelim, "\"")) L; + swritecsvlist_string (L:List, FieldDelim:String, StrDelim:String) + = map (tuple_to_csvstr (false, FieldDelim, StrDelim)) L; + + public freadcsv_data ARGS; /* Read one CSV record from the file with number conversion. */ *************** *** 62,65 **** --- 127,132 ---- freadcsv_data F:File = csvstr_to_tuple (true, ",", "\"") (fread_csvstr F "\""); + freadcsv_data (F:File, FieldDelim:String) + = csvstr_to_tuple (true, FieldDelim, "\"") (fread_csvstr F "\""); freadcsv_data (F:File, FieldDelim:String, StrDelim:String) = csvstr_to_tuple (true, FieldDelim, StrDelim) (fread_csvstr F StrDelim); *************** *** 69,75 **** freadcsv_string F:File ! = csvstr_to_tuple (false, "," "\"") (fread_csvstr F "\""); freadcsv_string (F:File, FieldDelim:String, StrDelim:String) ! = csvstr_to_tuple (false, "," "\"") (fread_csvstr F StrDelim); public fwritecsv_data FILE REC; --- 136,171 ---- freadcsv_string F:File ! = csvstr_to_tuple (false, ",", "\"") (fread_csvstr F "\""); ! freadcsv_string (F:File, FieldDelim:String) ! = csvstr_to_tuple (false, FieldDelim, "\"") (fread_csvstr F "\""); freadcsv_string (F:File, FieldDelim:String, StrDelim:String) ! = csvstr_to_tuple (false, ",", "\"") (fread_csvstr F StrDelim); ! ! public freadcsvlist_data ARGS, freadcsvlist_string ARGS; ! /* Read an entire file of records into a list of tuples. */ ! ! freadcsvlist_data F:File ! = [] if feof F; ! = [freadcsv_data F | freadcsvlist_data F]; ! freadcsvlist_data (F:File, FieldDelim:String) ! = [] if feof F; ! = [freadcsv_data (F, FieldDelim) ! | freadcsvlist_data (F, FieldDelim)]; ! freadcsvlist_data (F:File, FieldDelim:String, StrDelim:String) ! = [] if feof F; ! = [freadcsv_data (F, FieldDelim, StrDelim) ! | freadcsvlist_data (F, FieldDelim, StrDelim)]; ! ! freadcsvlist_string F:File ! = [] if feof F; ! = [freadcsv_string F | freadcsvlist_data F]; ! freadcsvlist_string (F:File, FieldDelim:String) ! = [] if feof F; ! = [freadcsv_string (F, FieldDelim) ! | freadcsvlist_string (F, FieldDelim)]; ! freadcsvlist_string (F:File, FieldDelim:String, StrDelim:String) ! = [] if feof F; ! = [freadcsv_string (F, FieldDelim, StrDelim) ! | freadcsvlist_string (F, FieldDelim, StrDelim)]; public fwritecsv_data FILE REC; *************** *** 78,81 **** --- 174,179 ---- fwritecsv_data F:File Rec:Tuple = fwrites F (tuple_to_csvstr (true, ",", "\"") Rec); + fwritecsv_data (F:File, FieldDelim:String) Rec:Tuple + = fwrites F (tuple_to_csvstr (true, FieldDelim, "\"") Rec); fwritecsv_data (F:File, FieldDelim:String, StrDelim:String) Rec:Tuple = fwrites F (tuple_to_csvstr (true, FieldDelim, StrDelim) Rec); *************** *** 86,119 **** fwritecsv_string F:File Rec:Tuple = fwrites F (tuple_to_csvstr (false, ",", "\"") Rec); fwritecsv_string (F:File, FieldDelim:String, StrDelim:String) Rec:Tuple = fwrites F (tuple_to_csvstr (false, FieldDelim, StrDelim) Rec); ! public freadcsvfile_data ARGS, freadcsvfile_string ARGS; ! /* Read an entire file of records into a list of tuples. */ ! ! freadcsvfile_data F:File ! = [] if feof F; ! = [freadcsv_data F | freadcsvfile_data F]; ! freadcsvfile_data (F:File, FieldDelim:String, StrDelim:String) ! = [] if feof F; ! = [freadcsv_data (F, FieldDelim, StrDelim) | freadcsvfile_data F]; ! ! freadcsvfile_string F:File ! = [] if feof F; ! = [freadcsv_string F | freadcsvfile_data F]; ! freadcsvfile_string (F:File, FieldDelim:String, StrDelim:String) ! = [] if feof F; ! = [freadcsv_string (F, FieldDelim, StrDelim) | freadcsvfile_string F]; ! ! public fwritecsvfile_data FILE LIST, fwritecsvfile_string ARGS; /* Write a list of tuples to a CSV formatted file. */ ! fwritecsvfile_data F:File L:List = do (fwritecsv_data F) L; ! fwritecsvfile_data (F:File, FieldDelim:String, StrDelim:String) L:List = do (fwritecsv_data (F, FieldDelim, StrDelim)) L; ! fwritecsvfile_string F:File L:List = do (fwritecsv_string F) L; ! fwritecsvfile_string (F:File, FieldDelim:String, StrDelim:String) L:List = do (fwritecsv_string (F, FieldDelim, StrDelim)) L; \ No newline at end of file --- 184,206 ---- fwritecsv_string F:File Rec:Tuple = fwrites F (tuple_to_csvstr (false, ",", "\"") Rec); + fwritecsv_string (F:File, FieldDelim:String) Rec:Tuple + = fwrites F (tuple_to_csvstr (false, FieldDelim, "\"") Rec); fwritecsv_string (F:File, FieldDelim:String, StrDelim:String) Rec:Tuple = fwrites F (tuple_to_csvstr (false, FieldDelim, StrDelim) Rec); ! public fwritecsvlist_data FILE LIST, fwritecsvlist_string ARGS; /* Write a list of tuples to a CSV formatted file. */ ! fwritecsvlist_data F:File L:List = do (fwritecsv_data F) L; ! fwritecsvlist_data (F:File, FieldDelim:String) L:List ! = do (fwritecsv_data (F, FieldDelim)) L; ! fwritecsvlist_data (F:File, FieldDelim:String, StrDelim:String) L:List = do (fwritecsv_data (F, FieldDelim, StrDelim)) L; ! fwritecsvlist_string F:File L:List = do (fwritecsv_string F) L; ! fwritecsvlist_string (F:File, FieldDelim:String) L:List ! = do (fwritecsv_string (F, FieldDelim)) L; ! fwritecsvlist_string (F:File, FieldDelim:String, StrDelim:String) L:List = do (fwritecsv_string (F, FieldDelim, StrDelim)) L; \ No newline at end of file |
From: Albert G. <ag...@us...> - 2008-01-17 08:25:28
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv29519 Modified Files: ChangeLog Log Message: update ChangeLog Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.314 retrieving revision 1.315 diff -C2 -d -r1.314 -r1.315 *** ChangeLog 16 Jan 2008 09:24:01 -0000 1.314 --- ChangeLog 17 Jan 2008 08:25:23 -0000 1.315 *************** *** 1,2 **** --- 1,6 ---- + 2008-01-17 Albert Graef <Dr....@t-...> + + * src/uchar_props_data.c: updated to latest from ICU 3.8 + 2008-01-16 Albert Graef <Dr....@t-...> |
From: Albert G. <ag...@us...> - 2008-01-17 08:10:46
|
Update of /cvsroot/q-lang/q/src In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23320 Modified Files: uchar_props_data.c Log Message: update uchar_props data to latest from ICU 3.8 Index: uchar_props_data.c =================================================================== RCS file: /cvsroot/q-lang/q/src/uchar_props_data.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** uchar_props_data.c 14 Feb 2006 22:04:23 -0000 1.3 --- uchar_props_data.c 17 Jan 2008 08:10:41 -0000 1.4 *************** *** 1,180 **** /* ! * Copyright (C) 1999-2005, International Business Machines * Corporation and others. All Rights Reserved. * * file name: uchar_props_data.c * ! * machine-generated on: 2005-04-29 */ static const UVersionInfo formatVersion={4,0,5,2}; [...3849 lines suppressed...] ! 0x60,0x412c0593,0x80000000,0,0x412c0602,0x80000000,0,0x412ec880,0x80000000,0x10,0x41308381,0x50020000,0x60,0x413aa200,0x80000000,3, ! 0x413aa391,0xf8400c00,0x18000,0x413aa791,0xf8000c00,0x18001,0x413ac100,0x80000000,0,0x413ec880,0x80000000,0x10,0x4142c880,0x80000000,0x1410,0x414c0a23, ! 0xd0000000,0x15800,0x414c45bb,0xd0000000,0x15800,0x41503300,0x80000080,0x4008000,0x4152c880,0x80000000,0x8010,0x41540602,0x80000000,0,0x41581500,0x80000000, ! 0,0x415c4700,0x80000000,0x4008000,0x416045bb,0x80000000,0,0x416045bb,0xd0000400,0x18000,0x416045bb,0xf8000400,0x18000,0x50080219,0xf8000400,0x10400, ! 0x50080219,0xf8000400,0x28400,0x5008040e,0xf8000400,0x10400,0x50080488,0xf8000400,0x10400,0x50080488,0xf8000400,0x28400,0x5008078a,0xf8000400,0x18400,0x50080b15, ! 0x80000000,0,0x50081600,0x80000000,0,0x50081619,0xf8000400,0x10400,0x50081699,0xf8000400,0x10400,0x50081800,0x80000000,0x4000000,0x50081800,0x80000080, ! 0x4000000,0x50081b80,0x80000000,0x4000000,0x50082e80,0xf8000480,0x10405,0x50082e80,0xf8000480,0x28405,0x50083088,0xf8000400,0x10400,0x50083088,0xf8000400,0x28400, ! 0x50083300,0x80000080,0x4000000,0x50083980,0x80000000,0x4000000,0x50084500,0xf8001400,0x18400,0x50084957,0x80000000,0,0x50084957,0xf8000400,0x18400,0x50084957, ! 0xf8001400,0x18400,0x50084957,0xf8002400,0x18400,0x500849be,0x80000000,0,0x500849be,0xf8000400,0x18400,0x500849be,0xf8000400,0x18401,0x50084a19,0xf8000400, ! 0x10400,0x50084a19,0xf8000400,0x28400,0x50084a80,0x80001000,0,0x50084b5a,0xf8000400,0x18400,0x50084bdb,0x80000000,0,0x50084bdb,0xf8000400,0x18400, ! 0x50084c65,0xf8000400,0x18400,0x50084ce5,0xf8000400,0x18400,0x50084d00,0x80000000,0,0x501049be,0x80000000,0,0x501049be,0x80000040,0,0x501049be, ! 0x80000040,0x1024000,0x50104bdb,0x80000040,0,0x50104ce5,0x80000040,0,0x50144b5a,0x80000000,0,0x50240593,0x50021400,0x60,0x50240b15,0x50020400, ! 0x60,0x50241581,0x50020080,0x60,0x50244181,0x50021000,0x60,0x50244957,0x50021000,0x60,0x502449be,0x50020400,0x60,0x502449be,0x50021000,0x60, ! 0x502449be,0xd0000400,0x18400,0x502449be,0xd0000400,0x18401,0x502449be,0xd0041000,0,0x502c4957,0x80000040,0x1024000,0x502c4b5a,0x80000040,0x1024000,0x50404957, ! 0x80000040,0x1400,0x504c4957,0xd0000000,0x15800,0x504c49be,0xd0000000,0x15800}; ! static const myint32_t countPropsVectors=3384; static const myint32_t propsVectorsColumns=3; ! static const myint32_t indexes[UPROPS_INDEX_COUNT]={0x1a54,0x1a54,0x1a54,0x1a54,0x3b66,3,0x489e,0,0,0,0x8ecd73,0x29d31,0,0,0,0}; |
From: Albert G. <ag...@us...> - 2008-01-16 09:24:04
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18462 Modified Files: ChangeLog Log Message: update ChangeLog Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.313 retrieving revision 1.314 diff -C2 -d -r1.313 -r1.314 *** ChangeLog 16 Jan 2008 08:28:43 -0000 1.313 --- ChangeLog 16 Jan 2008 09:24:01 -0000 1.314 *************** *** 1,4 **** --- 1,6 ---- 2008-01-16 Albert Graef <Dr....@t-...> + * bump version number, update docs + * src/qbase.c: added \&entity; escapes to string syntax, per request by Rob Hubbard |
From: Albert G. <ag...@us...> - 2008-01-16 09:22:22
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17999 Modified Files: NEWS Log Message: update NEWS Index: NEWS =================================================================== RCS file: /cvsroot/q-lang/q/NEWS,v retrieving revision 1.135 retrieving revision 1.136 diff -C2 -d -r1.135 -r1.136 *** NEWS 16 Jan 2008 09:07:37 -0000 1.135 --- NEWS 16 Jan 2008 09:22:17 -0000 1.136 *************** *** 7,13 **** As suggested by Rob Hubbard and John Cowan, special Unicode characters in strings can now be specified using an escape of the form '\&name;', where name ! is any of the XML entity names as specified by the Dec 2007 working draft of ! the W3C "XML Entity definitions for Characters", see: ! http://www.w3.org/TR/xml-entity-names/ --- 7,12 ---- As suggested by Rob Hubbard and John Cowan, special Unicode characters in strings can now be specified using an escape of the form '\&name;', where name ! is any of the XML entity names specified here: ! http://www.w3.org/TR/2007/WD-xml-entity-names-20071214/ |
From: Albert G. <ag...@us...> - 2008-01-16 09:07:48
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv5146 Modified Files: NEWS README configure.in Log Message: bump version number Index: README =================================================================== RCS file: /cvsroot/q-lang/q/README,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** README 17 Dec 2007 22:05:41 -0000 1.63 --- README 16 Jan 2008 09:07:37 -0000 1.64 *************** *** 1,5 **** ! Q eQuational Programming System Version 7.10 ! Copyright (c) 1991-2007 by Albert Graef <ag...@mu..., Dr....@t-...> --- 1,5 ---- ! Q eQuational Programming System Version 7.11 ! Copyright (c) 1991-2008 by Albert Graef <ag...@mu..., Dr....@t-...> Index: NEWS =================================================================== RCS file: /cvsroot/q-lang/q/NEWS,v retrieving revision 1.134 retrieving revision 1.135 diff -C2 -d -r1.134 -r1.135 *** NEWS 17 Dec 2007 22:05:41 -0000 1.134 --- NEWS 16 Jan 2008 09:07:37 -0000 1.135 *************** *** 3,6 **** --- 3,17 ---- ======= + * 7.11 January 2008 (work in progress) + + As suggested by Rob Hubbard and John Cowan, special Unicode characters in + strings can now be specified using an escape of the form '\&name;', where name + is any of the XML entity names as specified by the Dec 2007 working draft of + the W3C "XML Entity definitions for Characters", see: + http://www.w3.org/TR/xml-entity-names/ + + + ------------------------------------------------------------------------------ + * 7.10 17 December 2007 Index: configure.in =================================================================== RCS file: /cvsroot/q-lang/q/configure.in,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** configure.in 17 Dec 2007 22:05:41 -0000 1.57 --- configure.in 16 Jan 2008 09:07:37 -0000 1.58 *************** *** 5,9 **** AC_INIT(src/q.c) AM_CONFIG_HEADER(config.h) ! AM_INIT_AUTOMAKE(q, 7.10) dnl AM_MAINTAINER_MODE --- 5,9 ---- AC_INIT(src/q.c) AM_CONFIG_HEADER(config.h) ! AM_INIT_AUTOMAKE(q, 7.11) dnl AM_MAINTAINER_MODE |
From: Albert G. <ag...@us...> - 2008-01-16 09:07:45
|
Update of /cvsroot/q-lang/q/doc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv5146/doc Modified Files: version.texi Log Message: bump version number Index: version.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/version.texi,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** version.texi 16 Jan 2008 08:30:22 -0000 1.94 --- version.texi 16 Jan 2008 09:07:38 -0000 1.95 *************** *** 1,4 **** @set UPDATED 16 January 2008 @set UPDATED-MONTH January 2008 ! @set EDITION 7.10 ! @set VERSION 7.10 --- 1,4 ---- @set UPDATED 16 January 2008 @set UPDATED-MONTH January 2008 ! @set EDITION 7.11 ! @set VERSION 7.11 |
From: Albert G. <ag...@us...> - 2008-01-16 09:02:52
|
Update of /cvsroot/q-lang/q/src In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2927 Modified Files: Makefile.mingw mingw.h qbase.c Added Files: w3centities.c Removed Files: w3centities.h Log Message: rename w3centities.h -> w3centities.c Index: qbase.c =================================================================== RCS file: /cvsroot/q-lang/q/src/qbase.c,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** qbase.c 16 Jan 2008 08:28:15 -0000 1.26 --- qbase.c 16 Jan 2008 09:02:45 -0000 1.27 *************** *** 1019,1023 **** } ! #include "w3centities.h" static int entcmp(const void *_x, const void *_y) --- 1019,1023 ---- } ! #include "w3centities.c" static int entcmp(const void *_x, const void *_y) Index: mingw.h =================================================================== RCS file: /cvsroot/q-lang/q/src/mingw.h,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** mingw.h 17 Dec 2007 22:05:41 -0000 1.24 --- mingw.h 16 Jan 2008 09:02:45 -0000 1.25 *************** *** 153,156 **** /* Version number of package */ ! #define VERSION "7.10" --- 153,156 ---- /* Version number of package */ ! #define VERSION "7.11" --- NEW FILE: w3centities.c --- /* generated from w3centities.ent Wed Jan 16 08:17:24 2008 */ typedef struct ENTITY { char *name; long c; } Entity; static Entity entities[] = { { "AElig", 0x000C6 }, { "Aacgr", 0x00386 }, { "Aacute", 0x000C1 }, { "Abreve", 0x00102 }, { "Acirc", 0x000C2 }, { "Acy", 0x00410 }, { "Afr", 0x1D504 }, { "Agr", 0x00391 }, { "Agrave", 0x000C0 }, { "Alpha", 0x00391 }, { "Amacr", 0x00100 }, { "And", 0x02A53 }, { "Aogon", 0x00104 }, { "Aopf", 0x1D538 }, [...2081 lines suppressed...] { "yicy", 0x00457 }, { "yopf", 0x1D56A }, { "yscr", 0x1D4CE }, { "yucy", 0x0044E }, { "yuml", 0x000FF }, { "zacute", 0x0017A }, { "zcaron", 0x0017E }, { "zcy", 0x00437 }, { "zdot", 0x0017C }, { "zeetrf", 0x02128 }, { "zeta", 0x003B6 }, { "zfr", 0x1D537 }, { "zgr", 0x003B6 }, { "zhcy", 0x00436 }, { "zigrarr", 0x021DD }, { "zopf", 0x1D56B }, { "zscr", 0x1D4CF }, { "zwj", 0x0200D }, { "zwnj", 0x0200C }, }; Index: Makefile.mingw =================================================================== RCS file: /cvsroot/q-lang/q/src/Makefile.mingw,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Makefile.mingw 17 Dec 2007 22:05:41 -0000 1.35 --- Makefile.mingw 16 Jan 2008 09:02:45 -0000 1.36 *************** *** 17,21 **** # version number ! version = 7.10 # Window'ish installation layout: binaries and libraries in prefix directory, --- 17,21 ---- # version number ! version = 7.11 # Window'ish installation layout: binaries and libraries in prefix directory, --- w3centities.h DELETED --- |
From: Albert G. <ag...@us...> - 2008-01-16 09:02:05
|
Update of /cvsroot/q-lang/q/src In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2474 Modified Files: Makefile.am Log Message: add w3centities.c source to distribution Index: Makefile.am =================================================================== RCS file: /cvsroot/q-lang/q/src/Makefile.am,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Makefile.am 21 May 2007 10:33:37 -0000 1.27 --- Makefile.am 16 Jan 2008 09:02:00 -0000 1.28 *************** *** 79,83 **** libglobs_a_CFLAGS = $(AM_CFLAGS) ! EXTRA_DIST = qld.in Makefile.mingw mingw.h qint.c uchar_props_data.c CLEANFILES = qld --- 79,84 ---- libglobs_a_CFLAGS = $(AM_CFLAGS) ! EXTRA_DIST = qld.in Makefile.mingw mingw.h qint.c uchar_props_data.c \ ! w3centities.c CLEANFILES = qld |
From: Albert G. <ag...@us...> - 2008-01-16 08:30:26
|
Update of /cvsroot/q-lang/q/doc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv28393 Modified Files: qdoc.texi version.texi Log Message: update documentation Index: qdoc.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/qdoc.texi,v retrieving revision 1.139 retrieving revision 1.140 diff -C2 -d -r1.139 -r1.140 *** qdoc.texi 13 Jan 2008 21:02:44 -0000 1.139 --- qdoc.texi 16 Jan 2008 08:30:22 -0000 1.140 *************** *** 1745,1748 **** --- 1745,1761 ---- happens to be a valid digit, as in @code{"\(123)4"}. + As of version 7.11 and later, the interpreter also supports symbolic + character escapes of the form @samp{\&@var{name};}, where @var{name} is + any of the XML single character entity names specified in the ``XML + Entity definitions for Characters'', see + @url{http://www.w3.org/TR/xml-entity-names/}. Note that, at the time of + this writing, this is still a W3C working draft, so the supported entity + names may be subject to change until the final specification comes out; + the currently supported entities are described in the draft from 14 + December 2007, see + @url{http://www.w3.org/TR/2007/WD-xml-entity-names-20071214/}. Also note + that multi-character entities are @emph{not} supported in this + implementation. + A string may also be continued across lines by putting the @code{\} character immediately before the end of the line, which causes the *************** *** 1750,1755 **** As of Q 7.0, it is a syntax error if a character escape is not ! recognized as either a numeric escape or one of the special escapes in ! the list above. Some examples: --- 1763,1768 ---- As of Q 7.0, it is a syntax error if a character escape is not ! recognized as either a numeric escape or one of the special escapes ! listed above. Some examples: *************** *** 1762,1765 **** --- 1775,1779 ---- "\0x1b" @r{same in hexadecimal} "\(0x1b)c" @r{ASCII escape followed by a literal @samp{c} character} + "Gr\äf" @r{German umlaut, using XML entity escape} "a string" @r{multiple character string} "a \"quoted\" string" @r{include double quotes} Index: version.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/version.texi,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** version.texi 13 Jan 2008 21:02:44 -0000 1.93 --- version.texi 16 Jan 2008 08:30:22 -0000 1.94 *************** *** 1,3 **** ! @set UPDATED 13 January 2008 @set UPDATED-MONTH January 2008 @set EDITION 7.10 --- 1,3 ---- ! @set UPDATED 16 January 2008 @set UPDATED-MONTH January 2008 @set EDITION 7.10 |
From: Albert G. <ag...@us...> - 2008-01-16 08:28:46
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv28363 Modified Files: ChangeLog Log Message: update ChangeLog Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.312 retrieving revision 1.313 diff -C2 -d -r1.312 -r1.313 *** ChangeLog 17 Dec 2007 22:05:41 -0000 1.312 --- ChangeLog 16 Jan 2008 08:28:43 -0000 1.313 *************** *** 1,2 **** --- 1,11 ---- + 2008-01-16 Albert Graef <Dr....@t-...> + + * src/qbase.c: added \&entity; escapes to string syntax, per + request by Rob Hubbard + + As suggested by John Cowan, the supported entity names follow the + W3C "XML Entity definitions for Characters", as of W3C Working + Draft 14 December 2007. See: http://www.w3.org/TR/xml-entity-names/ + 2007-12-16 Albert Graef <Dr....@t-...> |
From: Albert G. <ag...@us...> - 2008-01-16 08:28:18
|
Update of /cvsroot/q-lang/q/src In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv28296 Modified Files: qbase.c Added Files: w3centities.h Log Message: add xml entity character escapes, as suggested by Rob Hubbard and John Cowan Index: qbase.c =================================================================== RCS file: /cvsroot/q-lang/q/src/qbase.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** qbase.c 24 Sep 2007 12:20:59 -0000 1.25 --- qbase.c 16 Jan 2008 08:28:15 -0000 1.26 *************** *** 1019,1022 **** --- 1019,1051 ---- } + #include "w3centities.h" + + static int entcmp(const void *_x, const void *_y) + { + const char *x = (const char*)_x; + const Entity *y = (const Entity*)_y; + return strcmp(x, y->name); + } + + static inline long entity(const char *name) + { + Entity *x = bsearch(name, entities, sizeof(entities) / sizeof(Entity), + sizeof(Entity), entcmp); + return x?x->c:-1; + } + + static long parse_entity(char *s, char **t) + { + long c; + char *p = strchr(s, ';'); + if (!p) return -1; + *p = 0; + c = entity(s); + *p = ';'; + if (c < 0) return c; + *t = p+1; + return c; + } + static char * scanchar(char *t, char **s, char **p) *************** *** 1049,1052 **** --- 1078,1099 ---- *t++ = c; break; + case '&': { + char *r; + long c = parse_entity(*s, s); + if (c >= 0) { + #ifdef HAVE_UNICODE + if (c >= 0x110000) + c %= 0x110000; + u8encode(t, c); + t += strlen(t); + #else + *t++ = (char)c; + #endif + } else { + *p = *s-1; + *t++ = c; + } + break; + } case '(': { if ('0' <= **s && **s <= '9') { --- NEW FILE: w3centities.h --- /* generated from w3centities.ent Wed Jan 16 08:17:24 2008 */ typedef struct ENTITY { char *name; long c; } Entity; static Entity entities[] = { { "AElig", 0x000C6 }, { "Aacgr", 0x00386 }, { "Aacute", 0x000C1 }, { "Abreve", 0x00102 }, { "Acirc", 0x000C2 }, { "Acy", 0x00410 }, { "Afr", 0x1D504 }, { "Agr", 0x00391 }, { "Agrave", 0x000C0 }, { "Alpha", 0x00391 }, { "Amacr", 0x00100 }, { "And", 0x02A53 }, { "Aogon", 0x00104 }, { "Aopf", 0x1D538 }, [...2081 lines suppressed...] { "yicy", 0x00457 }, { "yopf", 0x1D56A }, { "yscr", 0x1D4CE }, { "yucy", 0x0044E }, { "yuml", 0x000FF }, { "zacute", 0x0017A }, { "zcaron", 0x0017E }, { "zcy", 0x00437 }, { "zdot", 0x0017C }, { "zeetrf", 0x02128 }, { "zeta", 0x003B6 }, { "zfr", 0x1D537 }, { "zgr", 0x003B6 }, { "zhcy", 0x00436 }, { "zigrarr", 0x021DD }, { "zopf", 0x1D56B }, { "zscr", 0x1D4CF }, { "zwj", 0x0200D }, { "zwnj", 0x0200C }, }; |