q-lang-cvs Mailing List for Q - Equational Programming Language (Page 6)
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: Albert G. <ag...@us...> - 2008-01-27 09:42:32
|
Update of /cvsroot/q-lang/q/modules/clib In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3055 Modified Files: Makefile.mingw Log Message: Windows compatibility fixes Index: Makefile.mingw =================================================================== RCS file: /cvsroot/q-lang/q/modules/clib/Makefile.mingw,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.mingw 15 Oct 2007 13:48:26 -0000 1.5 --- Makefile.mingw 27 Jan 2008 09:42:29 -0000 1.6 *************** *** 15,22 **** clib$(SHLEXT): clib.c ! $(QCC) $(QCCFLAGS) -o clib$(SHLEXT) clib.c -- $(CFLAGS) $(DEFS) -I. -I../../../iconv -I../../libq -I../../../pthread -I../../../gmp --link -L. -L../../../iconv -liconv -L../../../pthread -lpthreadGC -L../../../gmp -lgmp -L../../libq system$(SHLEXT): system.c ! $(QCC) $(QCCFLAGS) -o system$(SHLEXT) system.c -- $(CFLAGS) $(DEFS) -I. -I../../../iconv -I../../../intl -I../../libq -I../../../glob -I../../../regex -I../../../pthread -I../../../readline -I../../../gmp --link -L. -L../../../iconv -liconv -L../../../intl -lintl -L../../../glob -lglob -L../../../regex -lregex -lwsock32 -L../../../pthread -lpthreadGC -L../../../readline -lreadline -L../../../gmp -lgmp -L../../libq clean mostlyclean distclean maintainer-clean:: --- 15,22 ---- clib$(SHLEXT): clib.c ! $(QCC) $(QCCFLAGS) -o clib$(SHLEXT) clib.c -- $(CFLAGS) $(DEFS) -I. -I../../../iconv -I../../libq -I../../../glob -I../../../regex -I../../../pthread -I../../../gmp --link -L. -L../../../iconv -liconv -L../../../glob -lglob -L../../../regex -lregex -L../../../pthread -lpthreadGC -L../../../gmp -lgmp -L../../libq system$(SHLEXT): system.c ! $(QCC) $(QCCFLAGS) -o system$(SHLEXT) system.c -- $(CFLAGS) $(DEFS) -I. -I../../../iconv -I../../../intl -I../../libq -I../../../pthread -I../../../readline -I../../../gmp --link -L. -L../../../iconv -liconv -L../../../intl -lintl -lwsock32 -L../../../pthread -lpthreadGC -L../../../readline -lreadline -L../../../gmp -lgmp -L../../libq clean mostlyclean distclean maintainer-clean:: |
From: Albert G. <ag...@us...> - 2008-01-27 09:35:53
|
Update of /cvsroot/q-lang/q-openal/src In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32626/src Modified Files: Makefile.mingw Log Message: fixes for Windows/OpenAL 1.1 compatibility Index: Makefile.mingw =================================================================== RCS file: /cvsroot/q-lang/q-openal/src/Makefile.mingw,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.mingw 18 Jul 2005 17:25:45 -0000 1.2 --- Makefile.mingw 27 Jan 2008 09:35:49 -0000 1.3 *************** *** 1,11 **** DEFS = -D__WIN32__ ! INCLUDES = -I../../q/libq ! LIBS = -L../../q/libq all: openal.q openal.dll openal.dll: openal_wrap.c ! qcc -o openal.dll openal_wrap.c -- $(DEFS) $(INCLUDES) --link -lalut -lopenal32 $(LIBS) openal_wrap.c openal.q: openal.i --- 1,11 ---- DEFS = -D__WIN32__ ! INCLUDES = -I../../q/libq -I../../openal/include ! LIBS = -L../../q/libq -L../../openal/lib all: openal.q openal.dll openal.dll: openal_wrap.c ! qcc -o openal.dll openal_wrap.c -- $(DEFS) $(INCLUDES) --link -lalut -lopenal $(LIBS) openal_wrap.c openal.q: openal.i |
From: Albert G. <ag...@us...> - 2008-01-27 09:35:14
|
Update of /cvsroot/q-lang/q-openal In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32596 Modified Files: INSTALL Log Message: update Windows installation instructions Index: INSTALL =================================================================== RCS file: /cvsroot/q-lang/q-openal/INSTALL,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** INSTALL 15 Dec 2007 00:36:30 -0000 1.3 --- INSTALL 27 Jan 2008 09:35:09 -0000 1.4 *************** *** 46,51 **** To compile on Windows you'll need a recent version of MinGW and MSys from www.mingw.org, as well as some Q-related development stuff contained in the ! Qpad package. You'll also need the OpenAL import libraries for mingw, which ! are available as a Dev-C++ DevPak, see http://www.bloodshed.net. In the src directory, run "make -f Makefile.mingw realclean", then "make -f --- 46,52 ---- To compile on Windows you'll need a recent version of MinGW and MSys from www.mingw.org, as well as some Q-related development stuff contained in the ! Qpad package. OpenAL/ALUT 1.1 import libraries for mingw don't appear to be ! available on the net yet, so I made them available in the Q Windows source ! archive (Q-x.y-Win32.zip). In the src directory, run "make -f Makefile.mingw realclean", then "make -f |
From: Albert G. <ag...@us...> - 2008-01-27 09:34:42
|
Update of /cvsroot/q-lang/q-openal In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32190 Modified Files: README Log Message: update README Index: README =================================================================== RCS file: /cvsroot/q-lang/q-openal/README,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** README 15 Dec 2007 00:36:30 -0000 1.6 --- README 27 Jan 2008 09:34:37 -0000 1.7 *************** *** 3,7 **** ======== ! An OpenAL module for the Q programming language. Copyright (c) 2005-2007 by Albert Graef and Jonas Joebges, Johannes Gutenberg University Mainz, Germany. Distributed under the GNU General Public License (GPL) Version 2 or later (see --- 3,7 ---- ======== ! An OpenAL module for the Q programming language. Copyright (c) 2005-2008 by Albert Graef and Jonas Joebges, Johannes Gutenberg University Mainz, Germany. Distributed under the GNU General Public License (GPL) Version 2 or later (see *************** *** 43,46 **** Enjoy! ! December 2007 Albert Graef --- 43,46 ---- Enjoy! ! January 2008 Albert Graef |
From: Albert G. <ag...@us...> - 2008-01-26 19:54:52
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv25942 Modified Files: qcalc.q Log Message: update copyright Index: qcalc.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/qcalc.q,v retrieving revision 1.217 retrieving revision 1.218 diff -C2 -d -r1.217 -r1.218 *** qcalc.q 26 Jan 2008 19:51:14 -0000 1.217 --- qcalc.q 26 Jan 2008 19:54:49 -0000 1.218 *************** *** 44,48 **** def VERSION = "1.2", CVS_VERSION = "$Id$", ! COPYRIGHT = "Copyright \169 2007 by Albert Gr\228f"; import smokeqt, dict, hdict, set, system; --- 44,48 ---- def VERSION = "1.2", CVS_VERSION = "$Id$", ! COPYRIGHT = "Copyright \169 2007-2008 by Albert Gr\228f"; import smokeqt, dict, hdict, set, system; |
From: Albert G. <ag...@us...> - 2008-01-26 19:51:18
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24094 Modified Files: qcalc.q Log Message: update version number Index: qcalc.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/qcalc.q,v retrieving revision 1.216 retrieving revision 1.217 diff -C2 -d -r1.216 -r1.217 *** qcalc.q 4 Dec 2007 18:45:13 -0000 1.216 --- qcalc.q 26 Jan 2008 19:51:14 -0000 1.217 *************** *** 42,46 **** their own separate qcalc version. */ ! def VERSION = "1.0", CVS_VERSION = "$Id$", COPYRIGHT = "Copyright \169 2007 by Albert Gr\228f"; --- 42,46 ---- their own separate qcalc version. */ ! def VERSION = "1.2", CVS_VERSION = "$Id$", COPYRIGHT = "Copyright \169 2007 by Albert Gr\228f"; |
From: Albert G. <ag...@us...> - 2008-01-26 19:50:36
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24069 Modified Files: Makefile Log Message: add missing world.dat file in distribution Index: Makefile =================================================================== RCS file: /cvsroot/q-lang/qcalc/Makefile,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Makefile 23 Jan 2008 06:02:20 -0000 1.15 --- Makefile 26 Jan 2008 19:50:31 -0000 1.16 *************** *** 6,10 **** # application name and version number: app = qcalc ! version = 1.1 dist = $(app)-$(version) --- 6,10 ---- # application name and version number: app = qcalc ! version = 1.2 dist = $(app)-$(version) *************** *** 16,20 **** PIXMAPS = pixmaps/qcalc.png pixmaps/flag.png pixmaps/1rightarrow.png pixmaps/1rightarrow-green.png pixmaps/locked.png pixmaps/unlocked.png pixmaps/floppybuddy.gif ! DISTFILES = Makefile COPYING README calclib.q $(app).desktop $(app).q *.ui $(PIXMAPS) doc/Makefile doc/*.html doc/*.png doc/*.xml doc/*.texi doc/texinfo.tex examples/*.qcalc examples/*.q all: --- 16,20 ---- PIXMAPS = pixmaps/qcalc.png pixmaps/flag.png pixmaps/1rightarrow.png pixmaps/1rightarrow-green.png pixmaps/locked.png pixmaps/unlocked.png pixmaps/floppybuddy.gif ! DISTFILES = Makefile COPYING README calclib.q $(app).desktop $(app).q *.ui $(PIXMAPS) doc/Makefile doc/*.html doc/*.png doc/*.xml doc/*.texi doc/texinfo.tex examples/*.qcalc examples/*.q examples/*.dat all: *************** *** 38,42 **** cp COPYING README *.ui "$(DESTDIR)$(appdir)" cp doc/*.html doc/*.png "$(DESTDIR)$(appdir)/doc" ! cp examples/*.qcalc examples/*.q "$(DESTDIR)$(appdir)/examples" cp $(PIXMAPS) "$(DESTDIR)$(appdir)/pixmaps" sed -e 's?#! -p/usr/local?#! -p$(prefix)?g' < "$(app).q" > "$(DESTDIR)$(appdir)/$(app).q" --- 38,42 ---- cp COPYING README *.ui "$(DESTDIR)$(appdir)" cp doc/*.html doc/*.png "$(DESTDIR)$(appdir)/doc" ! cp examples/*.qcalc examples/*.q examples/*.dat "$(DESTDIR)$(appdir)/examples" cp $(PIXMAPS) "$(DESTDIR)$(appdir)/pixmaps" sed -e 's?#! -p/usr/local?#! -p$(prefix)?g' < "$(app).q" > "$(DESTDIR)$(appdir)/$(app).q" |
From: RER <ed...@us...> - 2008-01-25 22:09:53
|
Update of /cvsroot/q-lang/q-csv In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12095 Modified Files: csv.c csv.q Log Message: code cleanups suggested by Albert Index: csv.c =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** csv.c 24 Jan 2008 22:26:07 -0000 1.14 --- csv.c 25 Jan 2008 22:09:46 -0000 1.15 *************** *** 1,3 **** ! /* CSV according to RFC 4180 (http://tools.ietf.rg/html/rfc4180.txt) This is free software; you can redistribute it and/or --- 1,4 ---- ! /* This file contains CSV reading and writing functions loosely based on ! Python's csv module (http://docs.python.org/lib/module-csv.html) This is free software; you can redistribute it and/or *************** *** 17,21 **** $Id$ ! Written by Eddie Rucker 3-22 Jan, 2008 */ #include <stdio.h> --- 18,22 ---- $Id$ ! Written by Eddie Rucker 3-25 Jan, 2008 */ #include <stdio.h> *************** *** 25,37 **** MODULE(csv); #define BSIZE 512 ! enum {FORCEQUOTE, AUTOQUOTE, NOQUOTE}; enum {CSV_DELIMITER, CSV_ESCAPE, CSV_QUOTE, CSV_QUOTING, CSV_LINETERMINATOR, CSV_SKIPSPACE}; ! /* fread_block reads embbeded '\n's. Does not account for badly formatted records. */ - FUNCTION (csv, fread_csvstr, argc, argv) { --- 26,46 ---- MODULE(csv); + static int quoting_style; + + INIT(csv) + { + quoting_style = sym(csv_quote_all); + } + #define BSIZE 512 ! enum {CSV_DELIMITER, CSV_ESCAPE, CSV_QUOTE, CSV_QUOTING, CSV_LINETERMINATOR, CSV_SKIPSPACE}; ! enum {CSV_QUOTE_ALL, CSV_QUOTE_STRINGS, CSV_QUOTE_NONE}; ! ! /* fread_csvstr reads embbeded '\n's. Does not account for badly formatted records. */ FUNCTION (csv, fread_csvstr, argc, argv) { *************** *** 91,95 **** double d; char *p, *t; ! if (cvt_f) { i = strtol(s, &p, 0); --- 100,104 ---- double d; char *p, *t; ! if (cvt_f) { i = strtol(s, &p, 0); *************** *** 100,128 **** return mkfloat(d); } ! if (!(t = strdup(s))) ! return NULL; ! return mkstr(t); } ! #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 --- 109,135 ---- return mkfloat(d); } ! return !(t = strdup(s)) ? NULL : mkstr(t); } ! #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 *************** *** 132,136 **** arg[0]: (Conversion flag, field delimeter char, string delimeter char) arg[1]: CSV formatted string ! output: tuple of fields --- 139,143 ---- arg[0]: (Conversion flag, field delimeter char, string delimeter char) arg[1]: CSV formatted string ! output: tuple of fields *************** *** 140,145 **** Notes: ! \r char is treated as white space except inside "" */ ! FUNCTION(csv, csvstr_to_tuple, argc, argv) { --- 147,152 ---- Notes: ! \r char is treated as white space except inside "" ! */ FUNCTION(csv, csvstr_to_tuple, argc, argv) { *************** *** 151,155 **** expr *xs, *rec, *trec; char *sp; ! if (argc != 2 || !istuple(argv[0], &n, &xs) --- 158,162 ---- expr *xs, *rec, *trec; char *sp; ! if (argc != 2 || !istuple(argv[0], &n, &xs) *************** *** 158,162 **** || !isstr(xs[CSV_ESCAPE], &escape) || !isstr(xs[CSV_QUOTE], "e) - || !isint(xs[CSV_QUOTING], "ing) || !isstr(xs[CSV_LINETERMINATOR], &lineterm) || !isbool(xs[CSV_SKIPSPACE], &skipspace_f) --- 165,168 ---- *************** *** 164,170 **** return __FAIL; if (!(fld = (char *)malloc(fld_sz))) return __ERROR; ! if (!(rec = (expr *)malloc(rec_sz*sizeof(expr)))) { free(fld); --- 170,180 ---- return __FAIL; + if ((quoting = exprsym(xs[CSV_QUOTING]) - quoting_style) < CSV_QUOTE_ALL + || quoting > CSV_QUOTE_NONE) + return __FAIL; + if (!(fld = (char *)malloc(fld_sz))) return __ERROR; ! if (!(rec = (expr *)malloc(rec_sz*sizeof(expr)))) { free(fld); *************** *** 185,189 **** if (!strncmp(s, delimiter, n_delimiter)) { *fldp = 0; ! putrec(FORCEQUOTE); s += n_delimiter; } else if (!strncmp(s, quote, n_quote)) { --- 195,199 ---- if (!strncmp(s, delimiter, n_delimiter)) { *fldp = 0; ! putrec(CSV_QUOTE_ALL); s += n_delimiter; } else if (!strncmp(s, quote, n_quote)) { *************** *** 210,214 **** sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, quote); st = 20; ! } else if (!strncmp(s, escape, n_escape)) { s += n_escape; putfld(1); --- 220,224 ---- sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, quote); st = 20; ! } else if (!strncmp(s, escape, n_escape)) { s += n_escape; putfld(1); *************** *** 225,238 **** 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; } else if (isspace(*s)) { ++s; st = 3; ! } else { sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, delimiter); st = 20; --- 235,248 ---- st = 1; } else if (!strncmp(s, delimiter, n_delimiter)) { ! putrec(CSV_QUOTE_ALL); s += n_delimiter; st = 0; } else if (!*s || *s == EOF || !strncmp(s, lineterm, n_lineterm)) { ! putrec(CSV_QUOTE_ALL); st = 10; } else if (isspace(*s)) { ++s; st = 3; ! } else { sprintf(errmsg, "Column %d: Expected {%s}.", n_fld+1, delimiter); st = 20; *************** *** 241,249 **** case 3: if (!strncmp(s, delimiter, n_delimiter)) { ! putrec(FORCEQUOTE); s += n_delimiter; st = 0; } else if (!*s || *s == '\n' || *s == EOF) { ! putrec(FORCEQUOTE); st = 10; } else if (isspace(*s)) { --- 251,259 ---- case 3: if (!strncmp(s, delimiter, n_delimiter)) { ! putrec(CSV_QUOTE_ALL); s += n_delimiter; st = 0; } else if (!*s || *s == '\n' || *s == EOF) { ! putrec(CSV_QUOTE_ALL); st = 10; } else if (isspace(*s)) { *************** *** 279,319 **** } } ! 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]); ! 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 \ ! mrk = len; \ ! len += strlen(tb); \ ! resize_str; \ strncpy(t, tb, len - mrk) /* convert tuple to csv string ! input: arg[0]: (Conversion flag, field delimeter char, string delimeter char) arg[1]: tuple to be converted ! output: CSV formatted string --- 289,327 ---- } } ! done: ! free(fld); ! if (st == 10) ! return mktuplev(n_rec, realloc(rec, sizeof(expr)*n_rec)); ! else { ! for (n = 0; n < n_rec; ++n) ! dispose(rec[n]); ! free(rec); ! return st==20 ? mkapp(mksym(sym(csv_error)), mkstr(strdup(errmsg))) ! : __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 \ ! mrk = len; \ ! len += strlen(tb); \ ! resize_str; \ strncpy(t, tb, len - mrk) /* convert tuple to csv string ! input: arg[0]: (Conversion flag, field delimeter char, string delimeter char) arg[1]: tuple to be converted ! output: CSV formatted string *************** *** 323,328 **** Notes: ! \r char is treated as white space except inside "" */ ! FUNCTION (csv, tuple_to_csvstr, argc, argv) { --- 331,336 ---- Notes: ! \r char is treated as white space except inside "" ! */ FUNCTION (csv, tuple_to_csvstr, argc, argv) { *************** *** 342,355 **** || !isstr(ys[CSV_ESCAPE], &escape) || !isstr(ys[CSV_QUOTE], "e) - || !isint(ys[CSV_QUOTING], "ing) || !isstr(ys[CSV_LINETERMINATOR], &lineterm) || !isbool(ys[CSV_SKIPSPACE], &skipspace_f) ! || !istuple(argv[1], &n, &xs)) { return __FAIL; - } if (!(s = (char *)malloc(sz))) return __ERROR; ! n_escape = strlen(escape); n_quote = strlen(quote); --- 350,365 ---- || !isstr(ys[CSV_ESCAPE], &escape) || !isstr(ys[CSV_QUOTE], "e) || !isstr(ys[CSV_LINETERMINATOR], &lineterm) || !isbool(ys[CSV_SKIPSPACE], &skipspace_f) ! || !istuple(argv[1], &n, &xs)) ! return __FAIL; ! ! if ((quoting = exprsym(ys[CSV_QUOTING]) - quoting_style) < CSV_QUOTE_ALL ! || quoting > CSV_QUOTE_NONE) return __FAIL; if (!(s = (char *)malloc(sz))) return __ERROR; ! n_escape = strlen(escape); n_quote = strlen(quote); *************** *** 374,432 **** 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); --- 384,441 ---- lineterm_cnt = 0; p = sval; ! if (skipspace_f && quoting == CSV_QUOTE_NONE) ! 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 == CSV_QUOTE_NONE && !(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); *************** *** 437,446 **** len += n_lineterm; resize_str; ! strcpy(t,lineterm); ! if (!(t = strdup(s))) { ! free(s); ! return __ERROR; ! } ! free(s); ! return mkstr(t); } --- 446,450 ---- len += n_lineterm; resize_str; ! strcpy(t, lineterm); ! return mkstr((char *)realloc(s, len+1)); } Index: csv.q =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.q,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** csv.q 24 Jan 2008 22:26:07 -0000 1.14 --- csv.q 25 Jan 2008 22:09:47 -0000 1.15 *************** *** 22,46 **** Python's csv module (http://docs.python.org/lib/module-csv.html) */ - public extern fread_csvstr FILE QUOTE; - public extern tuple_to_csvstr ARGS REC; - public 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; ! public const var ! csv_delimiter = 0, ! csv_escape = 1, ! csv_quote = 2, ! csv_quoting = 3, ! csv_lineterminator = 4, ! csv_skipspace = 5; ! public const var ! csv_quote_all = 0, ! csv_quote_strings = 1, ! csv_quote_none = 2; /* Dialect Options --- 22,33 ---- Python's csv module (http://docs.python.org/lib/module-csv.html) */ from dict import dict, insert, vals, member; ! private extern fread_csvstr FILE QUOTE; ! private extern tuple_to_csvstr ARGS REC; ! private extern csvstr_to_tuple ARGS STR; ! /* User may define csv_error for custom error handling. */ ! public csv_error MSG; /* Dialect Options *************** *** 66,70 **** csv_skipspace: Skip white space flag. Defaults to true. Reading/Writing: If true, white spaces before fields are removed. ! Quoted fields always retain white space. */ /* QuoteStyle constants used by csv quoting. --- 53,60 ---- csv_skipspace: Skip white space flag. Defaults to true. Reading/Writing: If true, white spaces before fields are removed. ! Quoted fields always retain white space. ! */ ! public type DialectOption = const csv_delimiter, csv_escape, csv_quote, csv_quoting, ! csv_lineterminator, csv_skipspace; /* QuoteStyle constants used by csv quoting. *************** *** 72,78 **** csv_quote_strings: Quote only strings fields, numeric fields are not quoted. csv_quote_none: Only fields containing embedded field delimeters, line ! terminators, or escaped quotes are quoted. */ ! /* Defaults to RFC 4180 (http://www.ietf.org/rfc/rfc4180.txt) */ def DEFAULTS = dict [csv_delimiter, ","; --- 62,70 ---- csv_quote_strings: Quote only strings fields, numeric fields are not quoted. csv_quote_none: Only fields containing embedded field delimeters, line ! terminators, or escaped quotes are quoted. ! */ ! public type QuoteStyle = const csv_quote_all, csv_quote_strings, csv_quote_none; ! /* Defaults are set to RFC 4180 (http://www.ietf.org/rfc/rfc4180.txt) */ def DEFAULTS = dict [csv_delimiter, ","; *************** *** 145,149 **** 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 $ fread_csvstr F "\""; --- 137,141 ---- public freadcsv ARGS; freadcsv (F:File, Dialect:Tuple) ! = csvstr_to_tuple Dialect $ fread_csvstr F (Dialect!ord csv_quote); freadcsv F:File = csvstr_to_tuple RFC4180 $ fread_csvstr F "\""; |
From: RER <ed...@us...> - 2008-01-24 22:29:27
|
Update of /cvsroot/q-lang/q-csv/examples In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12080 Added Files: write-sample5.csv Log Message: --- NEW FILE: write-sample5.csv --- "this"," that ",23,-3,"" "a %"b%"","c c",10,3.2," " "a, b","",0,0,"00" |
From: RER <ed...@us...> - 2008-01-24 22:26:25
|
Update of /cvsroot/q-lang/q-csv In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10914 Modified Files: csv.c csv.q Log Message: csv.c line terminator fix and csv.q clean up Index: csv.c =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** csv.c 23 Jan 2008 16:05:04 -0000 1.13 --- csv.c 24 Jan 2008 22:26:07 -0000 1.14 *************** *** 26,32 **** #define BSIZE 512 ! #define FORCEQUOTE 0 ! #define AUTOQUOTE 1 ! #define NOQUOTE 2 /* fread_block reads embbeded '\n's. --- 26,32 ---- #define BSIZE 512 ! enum {FORCEQUOTE, AUTOQUOTE, NOQUOTE}; ! enum {CSV_DELIMITER, CSV_ESCAPE, CSV_QUOTE, CSV_QUOTING, CSV_LINETERMINATOR, ! CSV_SKIPSPACE}; /* fread_block reads embbeded '\n's. *************** *** 35,39 **** FUNCTION (csv, fread_csvstr, argc, argv) ! { FILE *fp; char *bf, *tb, *qt_s, *s; --- 35,39 ---- FUNCTION (csv, fread_csvstr, argc, argv) ! { FILE *fp; char *bf, *tb, *qt_s, *s; *************** *** 54,59 **** if (n + BSIZE > sz) { if (!(tb = realloc(bf, sz <<= 1))) { ! free(bf); ! return __ERROR; } s = (bf = tb) + n; --- 54,59 ---- if (n + BSIZE > sz) { if (!(tb = realloc(bf, sz <<= 1))) { ! free(bf); ! return __ERROR; } s = (bf = tb) + n; *************** *** 71,81 **** 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); free(bf); --- 71,81 ---- 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); free(bf); *************** *** 145,152 **** { 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; --- 145,151 ---- { 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; *************** *** 156,165 **** || !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; --- 155,164 ---- || !istuple(argv[0], &n, &xs) || n != 6 ! || !isstr(xs[CSV_DELIMITER], &delimiter) ! || !isstr(xs[CSV_ESCAPE], &escape) ! || !isstr(xs[CSV_QUOTE], "e) ! || !isint(xs[CSV_QUOTING], "ing) ! || !isstr(xs[CSV_LINETERMINATOR], &lineterm) ! || !isbool(xs[CSV_SKIPSPACE], &skipspace_f) || !isstr(argv[1], &s)) return __FAIL; *************** *** 181,296 **** while (st < 10) { switch (st) { ! case 0: ! 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); ! ++s; ! st = 4; ! } ! 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); ! ++s; ! } ! 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; ! } else if (isspace(*s)) { ! ++s; ! 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) { ! putrec(FORCEQUOTE); ! st = 10; ! } else if (isspace(*s)) { ! ++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)) { ! n_ws = n_ws ? n_ws+1 : 1; ! putfld(1); ! ++s; ! } else { ! n_ws = 0; ! putfld(1); ! ++s; ! } ! break; } } 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]); ! free(rec); ! if (st == 20) ! return mkapp(mksym(sym(csv_error)), mkstr(strdup(errmsg))); ! return __ERROR; ! } } --- 180,295 ---- while (st < 10) { switch (st) { ! case 0: ! 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); ! ++s; ! st = 4; ! } ! 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); ! ++s; ! } ! 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; ! } else if (isspace(*s)) { ! ++s; ! 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) { ! putrec(FORCEQUOTE); ! st = 10; ! } else if (isspace(*s)) { ! ++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)) { ! n_ws = n_ws ? n_ws+1 : 1; ! putfld(1); ! ++s; ! } else { ! n_ws = 0; ! putfld(1); ! ++s; ! } ! break; } } 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]); ! free(rec); ! if (st == 20) ! return mkapp(mksym(sym(csv_error)), mkstr(strdup(errmsg))); ! return __ERROR; ! } } *************** *** 340,349 **** || !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; --- 339,348 ---- || !istuple(argv[0], &i, &ys) || i != 6 ! || !isstr(ys[CSV_DELIMITER], &delimiter) ! || !isstr(ys[CSV_ESCAPE], &escape) ! || !isstr(ys[CSV_QUOTE], "e) ! || !isint(ys[CSV_QUOTING], "ing) ! || !isstr(ys[CSV_LINETERMINATOR], &lineterm) ! || !isbool(ys[CSV_SKIPSPACE], &skipspace_f) || !istuple(argv[1], &n, &xs)) { return __FAIL; *************** *** 360,372 **** 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)) { --- 359,371 ---- 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)) { *************** *** 376,433 **** 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); --- 375,432 ---- 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); *************** *** 438,441 **** --- 437,441 ---- len += n_lineterm; resize_str; + strcpy(t,lineterm); if (!(t = strdup(s))) { free(s); Index: csv.q =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.q,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** csv.q 23 Jan 2008 16:05:04 -0000 1.13 --- csv.q 24 Jan 2008 22:26:07 -0000 1.14 *************** *** 22,28 **** 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; --- 22,28 ---- Python's csv module (http://docs.python.org/lib/module-csv.html) */ ! public extern fread_csvstr FILE QUOTE; ! public extern tuple_to_csvstr ARGS REC; ! public extern csvstr_to_tuple ARGS STR; public csv_error MSG; *************** *** 31,93 **** 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; ! /* Some CSV formats */ public const var ! RFC4180 = csv_dialect [], ! UNIX = csv_dialect [csv_lineterminator,"\n";]; ! /* Convert a tuple (record) to a CSV string Dialect: CSV format specification. If none is given, defaults to the RFC4180 dialect. --- 31,105 ---- from dict import dict, insert, vals, member; ! public const var ! csv_delimiter = 0, ! csv_escape = 1, ! csv_quote = 2, ! csv_quoting = 3, ! csv_lineterminator = 4, ! csv_skipspace = 5; ! public const var ! csv_quote_all = 0, ! csv_quote_strings = 1, ! csv_quote_none = 2; ! ! /* Dialect Options ! csv_delimiter: Field delimiter. Defaults to ",". ! ! csv_escape: 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: Quote character. Defaults to "\"". ! Note: If embedded quotes are doubled, csv_escape must equal ! csv_quote. The csv_dialect function will automatically set ! the csv_escape character to csv_quote if csv_escape is not ! specified. ! ! csv_quoting: Quoting options: Defaults to csv_quote_strings. ! See QuoteStyle constants below. ! ! csv_lineterminator: Record terminator. Defaults to "\r\n". ! ! csv_skipspace: Skip white space flag. Defaults to true. ! Reading/Writing: If true, white spaces before fields are removed. ! Quoted fields always retain white space. */ ! ! /* QuoteStyle constants used by csv quoting. ! csv_quote_all: Every field, including numeric fields, is quoted. ! csv_quote_strings: Quote only strings fields, numeric fields are not quoted. ! csv_quote_none: Only fields containing embedded field delimeters, line ! terminators, or escaped quotes are quoted. */ /* 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; ! /* Some typical CSV formats */ public const var ! RFC4180 = csv_dialect [], ! UNIX = csv_dialect [csv_lineterminator, "\n";], ! EXCEL = csv_dialect [csv_quoting, csv_quote_none;]; ! ! /* Convert a tuple (record) to a CSV string. Dialect: CSV format specification. If none is given, defaults to the RFC4180 dialect. *************** *** 99,112 **** public swritecsv ARGS; swritecsv (Dialect:Tuple, Rec:Tuple) ! = tuple_to_csvstr Dialect Rec; swritecsv Rec:Tuple ! = tuple_to_csvstr RFC4180 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) L; /* Convert a tuple (record) to a CSV string --- 111,124 ---- public swritecsv ARGS; swritecsv (Dialect:Tuple, Rec:Tuple) ! = tuple_to_csvstr Dialect Rec; swritecsv Rec:Tuple ! = tuple_to_csvstr RFC4180 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) L; /* Convert a tuple (record) to a CSV string *************** *** 119,155 **** public sreadcsv ARGS; sreadcsv (Rec:Tuple, Dialect:Tuple) ! = csvstr_to_tuple Dialect Rec; sreadcsv Rec:Tuple ! = csvstr_to_tuple RFC4180 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) 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 $ 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 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 --- 131,167 ---- public sreadcsv ARGS; sreadcsv (Rec:Tuple, Dialect:Tuple) ! = csvstr_to_tuple Dialect Rec; sreadcsv Rec:Tuple ! = csvstr_to_tuple RFC4180 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) 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 $ 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 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: RER <ed...@us...> - 2008-01-23 16:05:08
|
Update of /cvsroot/q-lang/q-csv In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18353 Modified Files: csv.c csv.q Log Message: Fixed a memory leak in csv.c and made dialects constant in csv.q Index: csv.c =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** csv.c 22 Jan 2008 16:45:16 -0000 1.12 --- csv.c 23 Jan 2008 16:05:04 -0000 1.13 *************** *** 17,21 **** $Id$ ! Written by Eddie Rucker 3-17 Jan, 2008 */ #include <stdio.h> --- 17,21 ---- $Id$ ! Written by Eddie Rucker 3-22 Jan, 2008 */ #include <stdio.h> *************** *** 328,335 **** 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; --- 328,335 ---- 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; *************** *** 438,444 **** len += n_lineterm; resize_str; ! strcpy(t, lineterm); ! if (!(t = strdup(s))) return __ERROR; return mkstr(t); } --- 438,446 ---- len += n_lineterm; resize_str; ! if (!(t = strdup(s))) { ! free(s); return __ERROR; + } + free(s); return mkstr(t); } Index: csv.q =================================================================== RCS file: /cvsroot/q-lang/q-csv/csv.q,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** csv.q 22 Jan 2008 16:45:16 -0000 1.12 --- csv.q 23 Jan 2008 16:05:04 -0000 1.13 *************** *** 84,100 **** = 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. */ --- 84,98 ---- = tuple $ vals $ foldl insert DEFAULTS $ Opts; ! /* Some CSV formats */ ! public const var ! RFC4180 = csv_dialect [], ! UNIX = csv_dialect [csv_lineterminator,"\n";]; /* Convert a tuple (record) to a CSV string ! Dialect: CSV format specification. If none is given, defaults to the ! 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. */ *************** *** 103,107 **** = 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. */ --- 101,105 ---- = tuple_to_csvstr Dialect Rec; swritecsv Rec:Tuple ! = tuple_to_csvstr RFC4180 Rec; /* Convert a list of tuples to a list of CSV formated strings. */ *************** *** 110,118 **** = 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. --- 108,116 ---- = map (tuple_to_csvstr Dialect) L; swritecsvlist L:List ! = map (tuple_to_csvstr RFC4180) L; /* Convert a tuple (record) to a CSV string ! Dialect: CSV format specification. If none is given, defaults to the ! RFC4180 dialect. Rec: Tuple of fields to be converted to CSV format. *************** *** 123,127 **** = 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 */ --- 121,125 ---- = csvstr_to_tuple Dialect Rec; sreadcsv Rec:Tuple ! = csvstr_to_tuple RFC4180 Rec; /* Convert a list of CSV formated strings to a list of tuples */ *************** *** 130,134 **** = map (csvstr_to_tuple Dialect) L; sreadcsvlist L:List ! = map (csvstr_to_tuple rfc4180_dialect) L; /* File handling functions */ --- 128,132 ---- = map (csvstr_to_tuple Dialect) L; sreadcsvlist L:List ! = map (csvstr_to_tuple RFC4180) L; /* File handling functions */ *************** *** 137,141 **** = 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; --- 135,139 ---- = csvstr_to_tuple Dialect $ fread_csvstr F (Dialect!csv_quote); freadcsv F:File ! = csvstr_to_tuple RFC4180 $ fread_csvstr F "\""; public fwritecsv ARGS REC; *************** *** 143,147 **** = fwrites F $ tuple_to_csvstr Dialect Rec; fwritecsv F:File Rec:Tuple ! = fwrites F $ tuple_to_csvstr rfc4180_dialect Rec; public freadcsvlist ARGS; --- 141,145 ---- = fwrites F $ tuple_to_csvstr Dialect Rec; fwritecsv F:File Rec:Tuple ! = fwrites F $ tuple_to_csvstr RFC4180 Rec; public freadcsvlist ARGS; |
From: Albert G. <ag...@us...> - 2008-01-23 07:09:12
|
Update of /cvsroot/q-lang/q/doc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv28481 Modified Files: qdoc.texi Log Message: update documentation Index: qdoc.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/qdoc.texi,v retrieving revision 1.145 retrieving revision 1.146 diff -C2 -d -r1.145 -r1.146 *** qdoc.texi 23 Jan 2008 06:49:08 -0000 1.145 --- qdoc.texi 23 Jan 2008 07:09:07 -0000 1.146 *************** *** 14497,14501 **** Matching filenames against patterns with shell wildcards (@code{*}, @code{?} etc.), also known as filename ``globbing'', is implemented by the following ! functions from @code{system.q}: @findex fnmatch --- 14497,14501 ---- Matching filenames against patterns with shell wildcards (@code{*}, @code{?} etc.), also known as filename ``globbing'', is implemented by the following ! functions from @code{clib.q}: @findex fnmatch |
From: Albert G. <ag...@us...> - 2008-01-23 06:49:12
|
Update of /cvsroot/q-lang/q/doc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv27694 Modified Files: qdoc.texi Log Message: update copyright Index: qdoc.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/qdoc.texi,v retrieving revision 1.144 retrieving revision 1.145 diff -C2 -d -r1.144 -r1.145 *** qdoc.texi 23 Jan 2008 06:23:38 -0000 1.144 --- qdoc.texi 23 Jan 2008 06:49:08 -0000 1.145 *************** *** 46,50 **** The Q Programming Language, Version @value{VERSION}, @value{UPDATED}. ! Copyright (c) 1992-2007 by Albert Graef. This manual has been published in the series @cite{Musikinformatik und --- 46,50 ---- The Q Programming Language, Version @value{VERSION}, @value{UPDATED}. ! Copyright (c) 1992-2008 by Albert Graef. This manual has been published in the series @cite{Musikinformatik und *************** *** 91,95 **** @page @vskip 0pt plus 1filll ! Copyright @copyright{} 1992-2007 by Albert Gr@"af This document describes version @value{VERSION} of the Q programming --- 91,95 ---- @page @vskip 0pt plus 1filll ! Copyright @copyright{} 1992-2008 by Albert Gr@"af This document describes version @value{VERSION} of the Q programming |
From: Albert G. <ag...@us...> - 2008-01-23 06:28:51
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv25966 Modified Files: ChangeLog Log Message: update ChangeLog Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.318 retrieving revision 1.319 diff -C2 -d -r1.318 -r1.319 *** ChangeLog 23 Jan 2008 05:33:08 -0000 1.318 --- ChangeLog 23 Jan 2008 06:28:46 -0000 1.319 *************** *** 1,4 **** --- 1,6 ---- 2008-01-23 Albert Graef <Dr....@t-...> + + 7.11 RC1 + * modules/clib: move glob and regex functions from system back into clib |
From: Albert G. <ag...@us...> - 2008-01-23 06:23:42
|
Update of /cvsroot/q-lang/q/doc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24776 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.143 retrieving revision 1.144 diff -C2 -d -r1.143 -r1.144 *** qdoc.texi 22 Jan 2008 12:41:38 -0000 1.143 --- qdoc.texi 23 Jan 2008 06:23:38 -0000 1.144 *************** *** 12749,12753 **** @smallexample ! ==> import system // if necessary ==> readline "input> " --- 12749,12753 ---- @smallexample ! ==> import system ==> readline "input> " *************** *** 13042,13046 **** @smallexample ! ==> import system // if necessary ==> uname --- 13042,13046 ---- @smallexample ! ==> import system ==> uname *************** *** 14509,14514 **** @smallexample - ==> import system - ==> map (fnmatch "*.q") ["clib.q","clib.c"] [true,false] --- 14509,14512 ---- *************** *** 14560,14564 **** @cindex regular expressions ! The @code{system} module implements regular expression matching using the POSIX @code{regcomp} and @code{regexec} functions. Regular expressions are generally specified using the @dfn{extended} (@code{egrep}-like) --- 14558,14562 ---- @cindex regular expressions ! The @code{clib} module implements regular expression matching using the POSIX @code{regcomp} and @code{regexec} functions. Regular expressions are generally specified using the @dfn{extended} (@code{egrep}-like) *************** *** 14795,14800 **** @smallexample - ==> import system // if needed - ==> regex "g" "[A-Za-z][A-Za-z0-9]*" "1var foo 99 BAR $%&" (reg 0) ["var","foo","BAR"] --- 14793,14796 ---- Index: version.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/version.texi,v retrieving revision 1.97 retrieving revision 1.98 diff -C2 -d -r1.97 -r1.98 *** version.texi 22 Jan 2008 12:41:38 -0000 1.97 --- version.texi 23 Jan 2008 06:23:38 -0000 1.98 *************** *** 1,3 **** ! @set UPDATED 22 January 2008 @set UPDATED-MONTH January 2008 @set EDITION 7.11 --- 1,3 ---- ! @set UPDATED 23 January 2008 @set UPDATED-MONTH January 2008 @set EDITION 7.11 |
From: Albert G. <ag...@us...> - 2008-01-23 06:02:23
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23970 Modified Files: Makefile Log Message: bump version number Index: Makefile =================================================================== RCS file: /cvsroot/q-lang/qcalc/Makefile,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Makefile 28 Nov 2007 16:02:08 -0000 1.14 --- Makefile 23 Jan 2008 06:02:20 -0000 1.15 *************** *** 6,10 **** # application name and version number: app = qcalc ! version = 1.0 dist = $(app)-$(version) --- 6,10 ---- # application name and version number: app = qcalc ! version = 1.1 dist = $(app)-$(version) |
From: Albert G. <ag...@us...> - 2008-01-23 05:57:25
|
Update of /cvsroot/q-lang/q/stdlib In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23520/stdlib Modified Files: getopt.q Log Message: fixes for latest clib Index: getopt.q =================================================================== RCS file: /cvsroot/q-lang/q/stdlib/getopt.q,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** getopt.q 27 Sep 2007 10:09:05 -0000 1.4 --- getopt.q 23 Jan 2008 05:57:22 -0000 1.5 *************** *** 21,26 **** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - from system import regex, reg; - /* The getopt function takes two arguments: OPTS, a list of option descriptions in the format described below, and ARGS, a list of strings --- 21,24 ---- |
From: Albert G. <ag...@us...> - 2008-01-23 05:57:25
|
Update of /cvsroot/q-lang/q/examples In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23520/examples Modified Files: csv.q except.q Log Message: fixes for latest clib Index: except.q =================================================================== RCS file: /cvsroot/q-lang/q/examples/except.q,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** except.q 29 Sep 2007 08:10:14 -0000 1.18 --- except.q 23 Jan 2008 05:57:22 -0000 1.19 *************** *** 209,212 **** --- 209,244 ---- bstr B = throw (clib_err (bstr B)); bytes B = throw (clib_err (bytes B)); + get_int8 B I = throw (clib_err (get_int8 B I)); + get_int16 B I = throw (clib_err (get_int16 B I)); + get_int32 B I = throw (clib_err (get_int32 B I)); + get_uint8 B I = throw (clib_err (get_uint8 B I)); + get_uint16 B I = throw (clib_err (get_uint16 B I)); + get_uint32 B I = throw (clib_err (get_uint32 B I)); + get_float B I = throw (clib_err (get_float B I)); + get_double B I = throw (clib_err (get_double B I)); + put_int8 B I X = throw (clib_err (put_int8 B I X)); + put_int16 B I X = throw (clib_err (put_int16 B I X)); + put_int32 B I X = throw (clib_err (put_int32 B I X)); + put_uint8 B I X = throw (clib_err (put_uint8 B I X)); + put_uint16 B I X = throw (clib_err (put_uint16 B I X)); + put_uint32 B I X = throw (clib_err (put_uint32 B I X)); + put_float B I X = throw (clib_err (put_float B I X)); + put_double B I X = throw (clib_err (put_double B I X)); + int8_list B = throw (clib_err (int8_list B)); + int16_list B = throw (clib_err (int16_list B)); + int32_list B = throw (clib_err (int32_list B)); + uint8_list B = throw (clib_err (uint8_list B)); + uint16_list B = throw (clib_err (uint16_list B)); + uint32_list B = throw (clib_err (uint32_list B)); + float_list B = throw (clib_err (float_list B)); + double_list B = throw (clib_err (double_list B)); + int8_vect Xs = throw (clib_err (int8_vect Xs)); + int16_vect Xs = throw (clib_err (int16_vect Xs)); + int32_vect Xs = throw (clib_err (int32_vect Xs)); + uint8_vect Xs = throw (clib_err (uint8_vect Xs)); + uint16_vect Xs = throw (clib_err (uint16_vect Xs)); + uint32_vect Xs = throw (clib_err (uint32_vect Xs)); + float_vect Xs = throw (clib_err (float_vect Xs)); + double_vect Xs = throw (clib_err (double_vect Xs)); fdopen FD MODE = throw (clib_err (fdopen FD MODE)); freopen NAME MODE F = throw (clib_err (freopen NAME MODE F)); *************** *** 272,275 **** --- 304,319 ---- jacobi M N = throw (clib_err (jacobi M N)); sort P Xs = throw (clib_err (sort P Xs)); + fnmatch PATTERN S = throw (clib_err (fnmatch PATTERN S)); + glob PATTERN = throw (clib_err (glob PATTERN)); + regmatch OPTS REGEX S = throw (clib_err (regmatch OPTS REGEX S)); + regnext = throw (clib_err regnext); + regdone = throw (clib_err regdone); + regex OPTS REGEX S EXPR = throw (clib_err (regex OPTS REGEX S EXPR)); + regstart = throw (clib_err regstart); + regskip = throw (clib_err regskip); + reg N = throw (clib_err (reg N)); + regpos N = throw (clib_err (regpos N)); + regend N = throw (clib_err (regend N)); + regs = throw (clib_err regs); /* complex *******************************************************************/ *************** *** 684,697 **** dcngettext DOMAIN MSGID1 MSGID2 N CATEGORY = throw (system_err (dcngettext DOMAIN MSGID1 MSGID2 N CATEGORY)); - fnmatch PATTERN S = throw (system_err (fnmatch PATTERN S)); - glob PATTERN = throw (system_err (glob PATTERN)); - regmatch OPTS REGEX S = throw (system_err (regmatch OPTS REGEX S)); - regnext = throw (system_err regnext); - regdone = throw (system_err regdone); - regex OPTS REGEX S EXPR = throw (system_err (regex OPTS REGEX S EXPR)); - regstart = throw (system_err regstart); - regskip = throw (system_err regskip); - reg N = throw (system_err (reg N)); - regpos N = throw (system_err (regpos N)); - regend N = throw (system_err (regend N)); - regs = throw (system_err regs); --- 728,729 ---- Index: csv.q =================================================================== RCS file: /cvsroot/q-lang/q/examples/csv.q,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** csv.q 28 Sep 2007 22:40:58 -0000 1.2 --- csv.q 23 Jan 2008 05:57:22 -0000 1.3 *************** *** 46,51 **** */ - from system import regex, reg, regs, regskip; - public csvreadfile F, csvreadline F, csvread S; public csvwritefile F L, csvwriteline F L, csvwrite L; --- 46,49 ---- |
From: Albert G. <ag...@us...> - 2008-01-23 05:56:10
|
Update of /cvsroot/q-lang/q/modules/clib In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23486 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.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** clib.q 23 Jan 2008 05:24:32 -0000 1.36 --- clib.q 23 Jan 2008 05:56:06 -0000 1.37 *************** *** 175,179 **** public extern ungetc C, fungetc F C; ! /* Some aliases for C afficionados. */ public ::readc as getc, ::freadc F as fgetc; --- 175,179 ---- public extern ungetc C, fungetc F C; ! /* Some aliases for C aficionados. */ public ::readc as getc, ::freadc F as fgetc; |
From: Albert G. <ag...@us...> - 2008-01-23 05:55:19
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23403 Modified Files: calclib.q Log Message: fixes for Q 7.11 compatibility Index: calclib.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/calclib.q,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** calclib.q 4 Dec 2007 11:41:41 -0000 1.58 --- calclib.q 23 Jan 2008 05:55:14 -0000 1.59 *************** *** 119,124 **** /* Some helper routines. */ - from system import regex, reg; - private colno C, cno C, colstr N, qadic; --- 119,122 ---- |
From: Albert G. <ag...@us...> - 2008-01-23 05:34:11
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv22030 Modified Files: NEWS Log Message: update NEWS Index: NEWS =================================================================== RCS file: /cvsroot/q-lang/q/NEWS,v retrieving revision 1.137 retrieving revision 1.138 diff -C2 -d -r1.137 -r1.138 *** NEWS 18 Jan 2008 10:12:41 -0000 1.137 --- NEWS 23 Jan 2008 05:34:05 -0000 1.138 *************** *** 17,20 **** --- 17,24 ---- provided as well. + - The glob and regex functions were moved back from system into clib. + + As usual, please see the ChangeLog for details. + ------------------------------------------------------------------------------ *************** *** 945,949 **** * 4.2 26 March 2003 ! Good news for Macintosh afficionados: Q has finally been ported to OS X! Moreover, the interpreter now provides signal handling via the new `trap' builtin, and the clib module has had a major overhaul and now provides well --- 949,953 ---- * 4.2 26 March 2003 ! Good news for Macintosh aficionados: Q has finally been ported to OS X! Moreover, the interpreter now provides signal handling via the new `trap' builtin, and the clib module has had a major overhaul and now provides well |
From: Albert G. <ag...@us...> - 2008-01-23 05:33:11
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21985 Modified Files: ChangeLog Log Message: update ChangeLog Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.317 retrieving revision 1.318 diff -C2 -d -r1.317 -r1.318 *** ChangeLog 22 Jan 2008 12:05:02 -0000 1.317 --- ChangeLog 23 Jan 2008 05:33:08 -0000 1.318 *************** *** 1,2 **** --- 1,7 ---- + 2008-01-23 Albert Graef <Dr....@t-...> + + * modules/clib: move glob and regex functions from system back + into clib + 2008-01-22 Albert Graef <Dr....@t-...> |
From: Albert G. <ag...@us...> - 2008-01-23 05:24:36
|
Update of /cvsroot/q-lang/q/modules/clib In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21680 Modified Files: clib.c clib.q system.c system.q Log Message: move glob and regex functions back into clib Index: system.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/clib/system.q,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** system.q 16 Dec 2007 20:23:21 -0000 1.4 --- system.q 23 Jan 2008 05:24:32 -0000 1.5 *************** *** 921,981 **** public extern ngettext MSGID1 MSGID2 N, dngettext DOMAIN MSGID1 MSGID2 N, dcngettext DOMAIN MSGID1 MSGID2 N CATEGORY; - - /****************************************************************************/ - - /* Filename globbing using the shell's wildcard syntax (*, ? etc.). */ - - public extern fnmatch PATTERN S; // check whether S matches PATTERN - public extern glob PATTERN; // return the list of all filenames - // matching PATTERN - - /****************************************************************************/ - - /* Regular expression matching using "extended" (egrep-like) syntax as defined - by POSIX 1003.2/D11.2. */ - - /* 1. Low-level interface. The following functions are directly implemented in - C using the POSIX regex functions. The regmatch function searches for the - first match, regnext for the next, and regdone terminates a global search - still in progress. The OPTS string allows you to specify various options - for the search. In particular, "g" denotes a global, "i" a - case-insensitive, and "n" a "multi-line" search; see the documentation for - further details. */ - - public extern regmatch OPTS REGEX S, regnext, regdone; - - /* 2. High-level interface. The regex function evaluates, for each match of - the given regular expression in the given string, the special EXPR - argument, and returns the collection of all results as a list. The OPTS - argument has the same meaning as with the low-level functions. In - particular, if the "g" option is omitted, then only the first match will be - reported, if any. */ - - public special regex ~OPTS ~REGEX ~S EXPR; - - private special regex_next ~Xs EXPR, check ~P X Y; - - regex OPTS:String REGEX:String S:String EXPR - = check (regmatch OPTS REGEX S) - (reverse (regex_next [EXPR] EXPR)) []; - - regex_next Xs EXPR = check regnext - (regex_next [EXPR|Xs] EXPR) Xs; - - check P:Bool X Y = X if P; - = Y otherwise; - check P X Y = P otherwise; - - /* 3. Match state information. These functions are typically invoked after - regmatch, regnext, or in the EXPR argument of regex, to return information - about the current match. The match state is maintained on a hidden stack - manipulated with the regmatch/regnext/regdone functions, hence multiple - nested searches are possible. */ - - public extern regstart, regskip, reg N, regpos N, regend N, regs; - - /* An expression of the form `regerr MSG', where MSG is the error message, is - used to return abnormal error conditions such as bad regular expression - syntax. You can redefine `regerr' as appropriate for your application. */ - - public regerr MSG; --- 921,922 ---- Index: clib.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/clib/clib.q,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** clib.q 22 Jan 2008 12:00:46 -0000 1.35 --- clib.q 23 Jan 2008 05:24:32 -0000 1.36 *************** *** 443,444 **** --- 443,503 ---- #SEM:Semaphore = get_size SEM; + + /****************************************************************************/ + + /* Filename globbing using the shell's wildcard syntax (*, ? etc.). */ + + public extern fnmatch PATTERN S; // check whether S matches PATTERN + public extern glob PATTERN; // return the list of all filenames + // matching PATTERN + + /****************************************************************************/ + + /* Regular expression matching using "extended" (egrep-like) syntax as defined + by POSIX 1003.2/D11.2. */ + + /* 1. Low-level interface. The following functions are directly implemented in + C using the POSIX regex functions. The regmatch function searches for the + first match, regnext for the next, and regdone terminates a global search + still in progress. The OPTS string allows you to specify various options + for the search. In particular, "g" denotes a global, "i" a + case-insensitive, and "n" a "multi-line" search; see the documentation for + further details. */ + + public extern regmatch OPTS REGEX S, regnext, regdone; + + /* 2. High-level interface. The regex function evaluates, for each match of + the given regular expression in the given string, the special EXPR + argument, and returns the collection of all results as a list. The OPTS + argument has the same meaning as with the low-level functions. In + particular, if the "g" option is omitted, then only the first match will be + reported, if any. */ + + public special regex ~OPTS ~REGEX ~S EXPR; + + private special regex_next ~Xs EXPR, check ~P X Y; + + regex OPTS:String REGEX:String S:String EXPR + = check (regmatch OPTS REGEX S) + (reverse (regex_next [EXPR] EXPR)) []; + + regex_next Xs EXPR = check regnext + (regex_next [EXPR|Xs] EXPR) Xs; + + check P:Bool X Y = X if P; + = Y otherwise; + check P X Y = P otherwise; + + /* 3. Match state information. These functions are typically invoked after + regmatch, regnext, or in the EXPR argument of regex, to return information + about the current match. The match state is maintained on a hidden stack + manipulated with the regmatch/regnext/regdone functions, hence multiple + nested searches are possible. */ + + public extern regstart, regskip, reg N, regpos N, regend N, regs; + + /* An expression of the form `regerr MSG', where MSG is the error message, is + used to return abnormal error conditions such as bad regular expression + syntax. You can redefine `regerr' as appropriate for your application. */ + + public regerr MSG; Index: system.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/clib/system.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** system.c 16 Dec 2007 20:23:21 -0000 1.4 --- system.c 23 Jan 2008 05:24:32 -0000 1.5 *************** *** 147,162 **** #endif - #ifdef HAVE_REGEX_H - #include <regex.h> - #endif - - #ifdef HAVE_GLOB_H - #include <glob.h> - #endif - - #ifdef HAVE_FNMATCH_H - #include <fnmatch.h> - #endif - #ifdef USE_READLINE #include <readline/readline.h> --- 147,150 ---- *************** *** 241,247 **** #include <iconv.h> #include <libintl.h> - #include <fnmatch.h> - #include <glob.h> - #include <regex.h> #include <readline.h> #include <history.h> --- 229,232 ---- *************** *** 250,257 **** #define HAVE_RL_COMPLETION_MATCHES 1 - #define HAVE_FNMATCH 1 - #define HAVE_GLOB 1 - #define HAVE_REGCOMP 1 - #define HAVE_STRDUP 1 #define HAVE_MEMCPY 1 --- 235,238 ---- *************** *** 6375,6863 **** #endif - /* filename globbing: *****************************************************/ - - FUNCTION(system,fnmatch,argc,argv) - { - #ifdef HAVE_FNMATCH - char *pattern, *s; - if (argc == 2 && isstr(argv[0], &pattern) && isstr(argv[1], &s)) { - int res; - pattern = utf8_to_sys(pattern); s = utf8_to_sys(s); - if (!pattern || !s) { - if (pattern) free(pattern); if (s) free(s); - return __ERROR; - } - res = fnmatch(pattern, s, 0); - free(pattern); free(s); - if (res) - return mkfalse; - else - return mktrue; - } else - #endif - return __FAIL; - } - - FUNCTION(system,glob,argc,argv) - { - #ifdef HAVE_GLOB - char *pattern; - if (argc == 1 && isstr(argv[0], &pattern)) { - glob_t g; - int res; - g.gl_offs = 0; - pattern = utf8_to_sys(pattern); - if (!pattern) return __ERROR; - res = glob(pattern, 0, NULL, &g); - free(pattern); - if (res == GLOB_NOMATCH) - return mknil; - else if (res) - return __FAIL; - else { - expr x = mknil; - int i = g.gl_pathc; - while (x && --i >= 0) - x = mkcons(mkstr(sys_to_utf8(g.gl_pathv[i])), x); - globfree(&g); - if (x) - return x; - else - return __ERROR; - } - } else - #endif - return __FAIL; - } - - /* regular expression matching: *******************************************/ - - #ifdef HAVE_REGCOMP - - /* regexp stack */ - - typedef struct { - unsigned done:1, global:2, matched:1; - int cflags, eflags; - regex_t rx; - regmatch_t *matches; - char *s, *p, *start; - } regstate_t; - - long regalloc = 0; - regstate_t *regstack = NULL, *regp = NULL; - char regmsg[BUFSZ]; - - #define REGALLOC 50 - - static int reg_push(void) - { - if (!regstack) - if ((regstack = malloc(REGALLOC*sizeof(regstate_t)))) { - regalloc = REGALLOC; - regp = regstack; - } else - return -1; - else if (!regp) - regp = regstack; - else if (regp-regstack+1 == regalloc) { - regstate_t *newstack = realloc(regstack, - (regalloc+REGALLOC)*sizeof(regstate_t)); - if (newstack) { - regstack = newstack; - regp = regstack+regalloc; - regalloc += REGALLOC; - } else - return -1; - } else - regp++; - regp->done = regp->global = regp->matched = 0; - regp->cflags = regp->eflags = 0; - regp->matches = NULL; - regp->s = regp->p = regp->start = NULL; - return 0; - } - - static void reg_pop(void) - { - if (!regp) return; - regfree(®p->rx); - if (regp->matches) free(regp->matches); - if (regp->s) free(regp->s); - if (regp > regstack) - regp--; - else - regp = NULL; - } - - /* push a new expression on the stack */ - - static int reg_add(char *pattern, char *s, int global, int cflags, int eflags) - { - int ret; - if (regp && regp->done) reg_pop(); - if (reg_push()) return -1; - regp->global = global; - regp->cflags = cflags; - regp->eflags = eflags; - ret = regcomp(®p->rx, pattern, REG_EXTENDED|cflags); - *regmsg = 0; - if (ret) { - regerror(ret, ®p->rx, regmsg, BUFSZ); - reg_pop(); - return ret; - } - if (!(regp->s = strdup(s))) { - reg_pop(); - return -1; - } - regp->p = regp->s; regp->start = NULL; - if (!(regp->matches = malloc((regp->rx.re_nsub+1)*sizeof(regmatch_t)))) { - reg_pop(); - return -1; - } - return 0; - } - - /* search */ - - static int reg_flags(char *p) - { - int flags; - flags = regp->eflags; - if (p > regp->s) - if (regp->cflags & REG_NEWLINE) - if (p[-1] == '\n') - flags &= ~REG_NOTBOL; - else - flags |= REG_NOTBOL; - else - flags |= REG_NOTBOL; - return flags; - } - - static int reg_search(void) - { - int ret; - char *prev; - while (regp && regp->done && regp>regstack) reg_pop(); - if (!regp) return -1; - if (regp->matched) - /* note the beginning of the previous match */ - prev = regp->start+regp->matches[0].rm_so; - regp->start = regp->p; - if (regp->global || !regp->matched) { - ret = regexec(®p->rx, regp->p, regp->rx.re_nsub+1, regp->matches, - reg_flags(regp->p)); - if (!ret) { - if (regp->matched) - if (regp->matches[0].rm_eo == regp->matches[0].rm_so && - regp->p == prev) - /* an extra empty match: if not at end of string then advance to the - next position and try again; otherwise simply ignore this match - and fail */ - if (*regp->p) { - int i; - /* this cannot fail since we can always match the empty string */ - ret = regexec(®p->rx, regp->p+1, regp->rx.re_nsub+1, - regp->matches, reg_flags(regp->p+1)); - /* translate offsets */ - for (i = 0; i <= regp->rx.re_nsub; i++) { - regp->matches[i].rm_so++; - regp->matches[i].rm_eo++; - } - } else - ret = REG_NOMATCH; - regp->matched = 1; - } - } else - ret = REG_NOMATCH; - *regmsg = 0; - if (ret) { - regp->done = 1; - regerror(ret, ®p->rx, regmsg, BUFSZ); - } else if (regp->global == 2 && - regp->matches[0].rm_eo > regp->matches[0].rm_so) - regp->p += regp->matches[0].rm_so+1; - else - regp->p += regp->matches[0].rm_eo; - return ret; - } - - /* stop search */ - - static void reg_done(void) - { - if (regp) { - regp->start = regp->p; - regp->done = 1; - } - } - - /* return matches */ - - static size_t reg_nmatches(void) - { - if (regp) - return regp->rx.re_nsub; - else - return 0; - } - - static long reg_start(void) - { - if (regp && regp->start) - return regp->start-regp->s; - else - return -1; - } - - static char *reg_skipstr(void) - { - if (regp && regp->start) - return regp->start; - else - return NULL; - } - - static long reg_pos(int i) - { - if (regp && regp->start && 0 <= i && i <= regp->rx.re_nsub) - if (!regp->done && regp->matches[i].rm_so >= 0) - return regp->start+regp->matches[i].rm_so-regp->s; - else - return -1; - else - return -1; - } - - static long reg_end(int i) - { - if (regp && regp->start && 0 <= i && i <= regp->rx.re_nsub) - if (!regp->done && regp->matches[i].rm_eo >= 0) - return regp->start+regp->matches[i].rm_eo-regp->s; - else - return -1; - else - return -1; - } - - static char *reg_str(int i) - { - if (regp && regp->start && 0 <= i && i <= regp->rx.re_nsub) - if (!regp->done && regp->matches[i].rm_so >= 0) - return regp->start+regp->matches[i].rm_so; - else - return NULL; - else - return NULL; - } - - #endif - - /* interface functions */ - - FUNCTION(system,regmatch,argc,argv) - { - #ifdef HAVE_REGCOMP - char *opts, *regex, *s; - int cflags = 0, eflags = 0, global = 0, ret; - if (argc != 3 || !isstr(argv[0], &opts) || !isstr(argv[1], ®ex) || - !isstr(argv[2], &s)) - return __FAIL; - while (*opts) - switch (*(opts++)) { - case 'g': - if (!global) global = 1; - break; - case 'G': - global = 2; - break; - case 'i': - cflags |= REG_ICASE; - break; - case 'n': - cflags |= REG_NEWLINE; - break; - case '^': - eflags |= REG_NOTBOL; - break; - case '$': - eflags |= REG_NOTEOL; - break; - default: - return __FAIL; - } - regex = utf8_to_sys(regex); s = utf8_to_sys(s); - if (!regex || !s) { - if (regex) free(regex); if (s) free(s); - return __ERROR; - } - ret = reg_add(regex, s, global, cflags, eflags); - free(regex); free(s); - if (ret == -1) - return __ERROR; - else if (ret) - return mkapp(mksym(sym(regerr)), mkstr(sys_to_utf8(regmsg))); - ret = reg_search(); - if (ret == -1 || ret == REG_NOMATCH) - return mkfalse; - else if (ret) - return mkapp(mksym(sym(regerr)), mkstr(sys_to_utf8(regmsg))); - else - return mktrue; - #else - return __FAIL; - #endif - } - - FUNCTION(system,regnext,argc,argv) - { - #ifdef HAVE_REGCOMP - int ret; - if (argc != 0) return __FAIL; - ret = reg_search(); - if (ret == -1 || ret == REG_NOMATCH) - return mkfalse; - else if (ret) - return mkapp(mksym(sym(regerr)), mkstr(sys_to_utf8(regmsg))); - else - return mktrue; - #else - return __FAIL; - #endif - } - - FUNCTION(system,regdone,argc,argv) - { - #ifdef HAVE_REGCOMP - if (argc != 0) return __FAIL; - reg_done(); - return mkvoid; - #else - return __FAIL; - #endif - } - - FUNCTION(system,regstart,argc,argv) - { - #ifdef HAVE_REGCOMP - long start; - if (argc != 0) return __FAIL; - start = reg_start(); - if (start >= 0) - return mkint(start); - else - return __FAIL; - #else - return __FAIL; - #endif - } - - FUNCTION(system,regskip,argc,argv) - { - #ifdef HAVE_REGCOMP - char *skip; - if (argc != 0) return __FAIL; - if ((skip = reg_skipstr())) { - long start = reg_start(), pos = reg_pos(0); - char *s, *t; - if (pos >= start) - s = malloc(pos-start+1); - else - s = malloc(strlen(skip)+1); - if (!s) return __ERROR; - if (pos >= start) { - strncpy(s, skip, pos-start); - s[pos-start] = 0; - } else - strcpy(s, skip); - t = sys_to_utf8(s); free(s); - return mkstr(t); - } else - return __FAIL; - #else - return __FAIL; - #endif - } - - FUNCTION(system,reg,argc,argv) - { - #ifdef HAVE_REGCOMP - long i; - if (argc != 1 || !isint(argv[0], &i) || i < 0 || i > reg_nmatches()) - return __FAIL; - if (reg_start() >= 0) { - long pos = reg_pos(i), end = reg_end(i); - char *s, *t; - if (pos < 0 || end < 0) - s = strdup(""); - else if (!(s = malloc(end-pos+1))) - return __ERROR; - else { - strncpy(s, reg_str(i), end-pos); - s[end-pos] = 0; - } - t = sys_to_utf8(s); free(s); - return mkstr(t); - } else - return __FAIL; - #else - return __FAIL; - #endif - } - - FUNCTION(system,regpos,argc,argv) - { - #ifdef HAVE_REGCOMP - long i; - if (argc != 1 || !isint(argv[0], &i) || i < 0 || i > reg_nmatches()) - return __FAIL; - if (reg_start() >= 0) - return mkint(reg_pos(i)); - else - return __FAIL; - #else - return __FAIL; - #endif - } - - FUNCTION(system,regend,argc,argv) - { - #ifdef HAVE_REGCOMP - long i; - if (argc != 1 || !isint(argv[0], &i) || i < 0 || i > reg_nmatches()) - return __FAIL; - if (reg_start() >= 0) - return mkint(reg_end(i)); - else - return __FAIL; - #else - return __FAIL; - #endif - } - - FUNCTION(system,regs,argc,argv) - { - #ifdef HAVE_REGCOMP - expr x; - size_t i; - if (argc != 0) return __FAIL; - x = mknil; - i = reg_nmatches(); - while (x && i > 0) { - if (reg_pos(i) >= 0 && reg_end(i) >= 0) - x = mkcons(mkint(i), x); - i--; - } - if (x) - return x; - else - return __ERROR; - #else - return __FAIL; - #endif - } - INIT(system) { --- 6356,6359 ---- Index: clib.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/clib/clib.c,v retrieving revision 1.84 retrieving revision 1.85 diff -C2 -d -r1.84 -r1.85 *** clib.c 22 Jan 2008 12:00:46 -0000 1.84 --- clib.c 23 Jan 2008 05:24:32 -0000 1.85 *************** *** 72,75 **** --- 72,87 ---- #endif + #ifdef HAVE_REGEX_H + #include <regex.h> + #endif + + #ifdef HAVE_GLOB_H + #include <glob.h> + #endif + + #ifdef HAVE_FNMATCH_H + #include <fnmatch.h> + #endif + #ifdef USE_THREADS #ifdef HAVE_SCHED_H *************** *** 102,105 **** --- 114,120 ---- #include <wctype.h> #include <iconv.h> + #include <fnmatch.h> + #include <glob.h> + #include <regex.h> #define HAVE_STRDUP 1 *************** *** 109,112 **** --- 124,131 ---- #define HAVE_MEMSET 1 + #define HAVE_FNMATCH 1 + #define HAVE_GLOB 1 + #define HAVE_REGCOMP 1 + #define HAVE_UNICODE 1 #define HAVE_LOCALE_H 1 *************** *** 5985,5988 **** --- 6004,6492 ---- } + /* filename globbing: *****************************************************/ + + FUNCTION(clib,fnmatch,argc,argv) + { + #ifdef HAVE_FNMATCH + char *pattern, *s; + if (argc == 2 && isstr(argv[0], &pattern) && isstr(argv[1], &s)) { + int res; + pattern = utf8_to_sys(pattern); s = utf8_to_sys(s); + if (!pattern || !s) { + if (pattern) free(pattern); if (s) free(s); + return __ERROR; + } + res = fnmatch(pattern, s, 0); + free(pattern); free(s); + if (res) + return mkfalse; + else + return mktrue; + } else + #endif + return __FAIL; + } + + FUNCTION(clib,glob,argc,argv) + { + #ifdef HAVE_GLOB + char *pattern; + if (argc == 1 && isstr(argv[0], &pattern)) { + glob_t g; + int res; + g.gl_offs = 0; + pattern = utf8_to_sys(pattern); + if (!pattern) return __ERROR; + res = glob(pattern, 0, NULL, &g); + free(pattern); + if (res == GLOB_NOMATCH) + return mknil; + else if (res) + return __FAIL; + else { + expr x = mknil; + int i = g.gl_pathc; + while (x && --i >= 0) + x = mkcons(mkstr(sys_to_utf8(g.gl_pathv[i])), x); + globfree(&g); + if (x) + return x; + else + return __ERROR; + } + } else + #endif + return __FAIL; + } + + /* regular expression matching: *******************************************/ + + #ifdef HAVE_REGCOMP + + /* regexp stack */ + + typedef struct { + unsigned done:1, global:2, matched:1; + int cflags, eflags; + regex_t rx; + regmatch_t *matches; + char *s, *p, *start; + } regstate_t; + + long regalloc = 0; + regstate_t *regstack = NULL, *regp = NULL; + char regmsg[BUFSZ]; + + #define REGALLOC 50 + + static int reg_push(void) + { + if (!regstack) + if ((regstack = malloc(REGALLOC*sizeof(regstate_t)))) { + regalloc = REGALLOC; + regp = regstack; + } else + return -1; + else if (!regp) + regp = regstack; + else if (regp-regstack+1 == regalloc) { + regstate_t *newstack = realloc(regstack, + (regalloc+REGALLOC)*sizeof(regstate_t)); + if (newstack) { + regstack = newstack; + regp = regstack+regalloc; + regalloc += REGALLOC; + } else + return -1; + } else + regp++; + regp->done = regp->global = regp->matched = 0; + regp->cflags = regp->eflags = 0; + regp->matches = NULL; + regp->s = regp->p = regp->start = NULL; + return 0; + } + + static void reg_pop(void) + { + if (!regp) return; + regfree(®p->rx); + if (regp->matches) free(regp->matches); + if (regp->s) free(regp->s); + if (regp > regstack) + regp--; + else + regp = NULL; + } + + /* push a new expression on the stack */ + + static int reg_add(char *pattern, char *s, int global, int cflags, int eflags) + { + int ret; + if (regp && regp->done) reg_pop(); + if (reg_push()) return -1; + regp->global = global; + regp->cflags = cflags; + regp->eflags = eflags; + ret = regcomp(®p->rx, pattern, REG_EXTENDED|cflags); + *regmsg = 0; + if (ret) { + regerror(ret, ®p->rx, regmsg, BUFSZ); + reg_pop(); + return ret; + } + if (!(regp->s = strdup(s))) { + reg_pop(); + return -1; + } + regp->p = regp->s; regp->start = NULL; + if (!(regp->matches = malloc((regp->rx.re_nsub+1)*sizeof(regmatch_t)))) { + reg_pop(); + return -1; + } + return 0; + } + + /* search */ + + static int reg_flags(char *p) + { + int flags; + flags = regp->eflags; + if (p > regp->s) + if (regp->cflags & REG_NEWLINE) + if (p[-1] == '\n') + flags &= ~REG_NOTBOL; + else + flags |= REG_NOTBOL; + else + flags |= REG_NOTBOL; + return flags; + } + + static int reg_search(void) + { + int ret; + char *prev; + while (regp && regp->done && regp>regstack) reg_pop(); + if (!regp) return -1; + if (regp->matched) + /* note the beginning of the previous match */ + prev = regp->start+regp->matches[0].rm_so; + regp->start = regp->p; + if (regp->global || !regp->matched) { + ret = regexec(®p->rx, regp->p, regp->rx.re_nsub+1, regp->matches, + reg_flags(regp->p)); + if (!ret) { + if (regp->matched) + if (regp->matches[0].rm_eo == regp->matches[0].rm_so && + regp->p == prev) + /* an extra empty match: if not at end of string then advance to the + next position and try again; otherwise simply ignore this match + and fail */ + if (*regp->p) { + int i; + /* this cannot fail since we can always match the empty string */ + ret = regexec(®p->rx, regp->p+1, regp->rx.re_nsub+1, + regp->matches, reg_flags(regp->p+1)); + /* translate offsets */ + for (i = 0; i <= regp->rx.re_nsub; i++) { + regp->matches[i].rm_so++; + regp->matches[i].rm_eo++; + } + } else + ret = REG_NOMATCH; + regp->matched = 1; + } + } else + ret = REG_NOMATCH; + *regmsg = 0; + if (ret) { + regp->done = 1; + regerror(ret, ®p->rx, regmsg, BUFSZ); + } else if (regp->global == 2 && + regp->matches[0].rm_eo > regp->matches[0].rm_so) + regp->p += regp->matches[0].rm_so+1; + else + regp->p += regp->matches[0].rm_eo; + return ret; + } + + /* stop search */ + + static void reg_done(void) + { + if (regp) { + regp->start = regp->p; + regp->done = 1; + } + } + + /* return matches */ + + static size_t reg_nmatches(void) + { + if (regp) + return regp->rx.re_nsub; + else + return 0; + } + + static long reg_start(void) + { + if (regp && regp->start) + return regp->start-regp->s; + else + return -1; + } + + static char *reg_skipstr(void) + { + if (regp && regp->start) + return regp->start; + else + return NULL; + } + + static long reg_pos(int i) + { + if (regp && regp->start && 0 <= i && i <= regp->rx.re_nsub) + if (!regp->done && regp->matches[i].rm_so >= 0) + return regp->start+regp->matches[i].rm_so-regp->s; + else + return -1; + else + return -1; + } + + static long reg_end(int i) + { + if (regp && regp->start && 0 <= i && i <= regp->rx.re_nsub) + if (!regp->done && regp->matches[i].rm_eo >= 0) + return regp->start+regp->matches[i].rm_eo-regp->s; + else + return -1; + else + return -1; + } + + static char *reg_str(int i) + { + if (regp && regp->start && 0 <= i && i <= regp->rx.re_nsub) + if (!regp->done && regp->matches[i].rm_so >= 0) + return regp->start+regp->matches[i].rm_so; + else + return NULL; + else + return NULL; + } + + #endif + + /* interface functions */ + + FUNCTION(clib,regmatch,argc,argv) + { + #ifdef HAVE_REGCOMP + char *opts, *regex, *s; + int cflags = 0, eflags = 0, global = 0, ret; + if (argc != 3 || !isstr(argv[0], &opts) || !isstr(argv[1], ®ex) || + !isstr(argv[2], &s)) + return __FAIL; + while (*opts) + switch (*(opts++)) { + case 'g': + if (!global) global = 1; + break; + case 'G': + global = 2; + break; + case 'i': + cflags |= REG_ICASE; + break; + case 'n': + cflags |= REG_NEWLINE; + break; + case '^': + eflags |= REG_NOTBOL; + break; + case '$': + eflags |= REG_NOTEOL; + break; + default: + return __FAIL; + } + regex = utf8_to_sys(regex); s = utf8_to_sys(s); + if (!regex || !s) { + if (regex) free(regex); if (s) free(s); + return __ERROR; + } + ret = reg_add(regex, s, global, cflags, eflags); + free(regex); free(s); + if (ret == -1) + return __ERROR; + else if (ret) + return mkapp(mksym(sym(regerr)), mkstr(sys_to_utf8(regmsg))); + ret = reg_search(); + if (ret == -1 || ret == REG_NOMATCH) + return mkfalse; + else if (ret) + return mkapp(mksym(sym(regerr)), mkstr(sys_to_utf8(regmsg))); + else + return mktrue; + #else + return __FAIL; + #endif + } + + FUNCTION(clib,regnext,argc,argv) + { + #ifdef HAVE_REGCOMP + int ret; + if (argc != 0) return __FAIL; + ret = reg_search(); + if (ret == -1 || ret == REG_NOMATCH) + return mkfalse; + else if (ret) + return mkapp(mksym(sym(regerr)), mkstr(sys_to_utf8(regmsg))); + else + return mktrue; + #else + return __FAIL; + #endif + } + + FUNCTION(clib,regdone,argc,argv) + { + #ifdef HAVE_REGCOMP + if (argc != 0) return __FAIL; + reg_done(); + return mkvoid; + #else + return __FAIL; + #endif + } + + FUNCTION(clib,regstart,argc,argv) + { + #ifdef HAVE_REGCOMP + long start; + if (argc != 0) return __FAIL; + start = reg_start(); + if (start >= 0) + return mkint(start); + else + return __FAIL; + #else + return __FAIL; + #endif + } + + FUNCTION(clib,regskip,argc,argv) + { + #ifdef HAVE_REGCOMP + char *skip; + if (argc != 0) return __FAIL; + if ((skip = reg_skipstr())) { + long start = reg_start(), pos = reg_pos(0); + char *s, *t; + if (pos >= start) + s = malloc(pos-start+1); + else + s = malloc(strlen(skip)+1); + if (!s) return __ERROR; + if (pos >= start) { + strncpy(s, skip, pos-start); + s[pos-start] = 0; + } else + strcpy(s, skip); + t = sys_to_utf8(s); free(s); + return mkstr(t); + } else + return __FAIL; + #else + return __FAIL; + #endif + } + + FUNCTION(clib,reg,argc,argv) + { + #ifdef HAVE_REGCOMP + long i; + if (argc != 1 || !isint(argv[0], &i) || i < 0 || i > reg_nmatches()) + return __FAIL; + if (reg_start() >= 0) { + long pos = reg_pos(i), end = reg_end(i); + char *s, *t; + if (pos < 0 || end < 0) + s = strdup(""); + else if (!(s = malloc(end-pos+1))) + return __ERROR; + else { + strncpy(s, reg_str(i), end-pos); + s[end-pos] = 0; + } + t = sys_to_utf8(s); free(s); + return mkstr(t); + } else + return __FAIL; + #else + return __FAIL; + #endif + } + + FUNCTION(clib,regpos,argc,argv) + { + #ifdef HAVE_REGCOMP + long i; + if (argc != 1 || !isint(argv[0], &i) || i < 0 || i > reg_nmatches()) + return __FAIL; + if (reg_start() >= 0) + return mkint(reg_pos(i)); + else + return __FAIL; + #else + return __FAIL; + #endif + } + + FUNCTION(clib,regend,argc,argv) + { + #ifdef HAVE_REGCOMP + long i; + if (argc != 1 || !isint(argv[0], &i) || i < 0 || i > reg_nmatches()) + return __FAIL; + if (reg_start() >= 0) + return mkint(reg_end(i)); + else + return __FAIL; + #else + return __FAIL; + #endif + } + + FUNCTION(clib,regs,argc,argv) + { + #ifdef HAVE_REGCOMP + expr x; + size_t i; + if (argc != 0) return __FAIL; + x = mknil; + i = reg_nmatches(); + while (x && i > 0) { + if (reg_pos(i) >= 0 && reg_end(i) >= 0) + x = mkcons(mkint(i), x); + i--; + } + if (x) + return x; + else + return __ERROR; + #else + return __FAIL; + #endif + } + /* initialization: ********************************************************/ |
From: RER <ed...@us...> - 2008-01-22 16:47:38
|
Update of /cvsroot/q-lang/q-csv In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9417 Modified Files: README Log Message: updated README Index: README =================================================================== RCS file: /cvsroot/q-lang/q-csv/README,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** README 14 Jan 2008 06:43:09 -0000 1.9 --- README 22 Jan 2008 16:47:30 -0000 1.10 *************** *** 4,10 **** 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. INSTALLATION --- 4,9 ---- 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) INSTALLATION *************** *** 21,41 **** USAGE ! Data records are represented as tuples of strings and numeric data. Two ! variants of reading and writing are available. Basically, the functions whose ! names end in _data will convert numeric (integer and floating point) values ! automatically, while the _string variants will treat them as ordinary (string) ! data. More precisely: ! - freadcsv_data converts non-quoted numeric fields to integer or double values ! automatically. Invalidly formatted CSV causes return of a 'csv_error MSG' ! term (see NOTES below). ! fwritecsv_data writes integer or double values to non-quoted fields. The ! handling of quoted or non-quoted fields is automatic. Fields with types ! other than floats, integers or strings cause return of a 'csv_error MSG' ! term (see NOTES below). ! ! - freadcsv_string and fwritecsv_string read all fields as strings ! disregarding any conversion. ! fwritecsv_string writes all values as quoted fields. The above routines are defined in terms of the following primary interface --- 20,41 ---- USAGE ! Data records are represented as tuples of strings and numeric data. Dialects ! are created using csv_dialect with a list of specifications outlined in csv.q. ! - sreadcsv reads a CSV formated string and converts it to a tuple of fields ! according to the dialect specified. If no dialect is specified, conversion ! is performed using RFC 4180 rules (http://www.ietf.org/rfc/rfc4180.txt). ! Invalidly formatted CSV causes return of a 'csv_error MSG' term ! (see NOTES below). ! ! - swritecsv converts a tuple of fields, which includes only strings, integers, ! and floats to a CSV formated string according to the dialect specified. If ! no dialect is specified, conversion is performed using RFC 4180 rules ! (http://www.ietf.org/rfc/rfc4180.txt). Tuples that are not strings, integers, ! or floats invoke a 'csv_error MSG' term (see NOTES below). ! ! - freadcsv is equivalent to sreadcsv except that reading is from a file. ! ! - fwritecsv is equivalent to swritecsv except that writing is to a file. The above routines are defined in terms of the following primary interface *************** *** 53,64 **** The routines described above read/write one record at a time. Additional ! functions (freadcsvfile_data and fwritecsvfile_data) are provided to convert ! between entire CSV files and lists of tuples. Note that these require that ! the entire data fits into RAM and will thus be inefficient for huge datasets. NOTES ! - Errors in the conversion routines (input strings that do not abide by the ! RFC 4180 rules; records containing field types other than strings, integers and floats) cause a special 'csv_error MSG' term to be returned, where MSG is a string describing the particular error. To handle error conditions, --- 53,65 ---- The routines described above read/write one record at a time. Additional ! functions (sreadcsvlist, swritecsvlist, freadcsvlist and fwritecsvlist) are ! provided to convert between entire CSV files and lists of tuples. Note that ! these require that the entire data fits into RAM and will thus be inefficient ! for huge datasets. NOTES ! - Errors in the conversion routines (input that does not abide by the ! dialect rules; records containing field types other than strings, integers and floats) cause a special 'csv_error MSG' term to be returned, where MSG is a string describing the particular error. To handle error conditions, *************** *** 69,76 **** csv_error MSG = throw MSG; ! - MS Excel files should be read using the _string variants as Excel does not ! quote values such as 0004. These types of values will be converted to ! integers and the leading significant 0s will be lost. Significant leading or ! trailing space may likewise be lost without using the _string variant. TO DO --- 70,76 ---- csv_error MSG = throw MSG; ! - MS Excel files should be written using "=""0004""" if leading 0s are ! significant. Use the same technique if leading space is significant. Use this ! quirk only if written files are going to be imported to MS Excel. TO DO |
From: RER <ed...@us...> - 2008-01-22 16:45:39
|
Update of /cvsroot/q-lang/q-csv/examples In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv8598/examples Modified Files: readsamples.q writesamples.q Log Message: Changed module to be loosely compatible with Python's CSV module Index: writesamples.q =================================================================== RCS file: /cvsroot/q-lang/q-csv/examples/writesamples.q,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** writesamples.q 18 Jan 2008 21:34:13 -0000 1.4 --- writesamples.q 22 Jan 2008 16:45:17 -0000 1.5 *************** *** 15,36 **** /* Illustration of fwritecsv ! Note that certain fields are not quoted. */ writefile F [] = (); ! writefile F [L|Ls] = [fwritecsv_data F L | writefile F Ls]; /* Illustration of writecsv_string Note that all fields are quoted. */ writefile_string F [] = (); ! writefile_string F [L|Ls] = [fwritecsv_string F L | writefile_string F Ls]; /* Illustration of fwritecsv with tab delimeter */ writefile_tab F [] = (); ! writefile_tab F [L|Ls] = [fwritecsv_data (F, "\t", "\"") L | writefile_tab F Ls]; /* Illustration of fwritecsv with tab and quote delimeters */ writefile_tab_quote F [] = (); ! writefile_tab_quote F [L|Ls] = [fwritecsv_data (F, "\t", "'") L | writefile_tab_quote F Ls]; def Sample1 = [("this", " that ", 23, -3.0, ""), ("a \"b\"", "c c", 10, 3.2, " "), --- 15,46 ---- /* Illustration of fwritecsv ! Note that interger and float fields are not quoted. */ writefile F [] = (); ! writefile F [L|Ls] = [fwritecsv F L | writefile F Ls]; /* Illustration of writecsv_string Note that all fields are quoted. */ + def Dialect1 = csv_dialect [csv_quoting,csv_quote_all;]; writefile_string F [] = (); ! writefile_string F [L|Ls] = [fwritecsv (F,Dialect1) L ! | writefile_string F Ls]; /* Illustration of fwritecsv with tab delimeter */ + def Dialect2 = csv_dialect [csv_delimiter,"\t";]; writefile_tab F [] = (); ! writefile_tab F [L|Ls] = [fwritecsv (F, Dialect2) L | writefile_tab F Ls]; /* Illustration of fwritecsv with tab and quote delimeters */ + def Dialect3 = csv_dialect [csv_delimiter,"\t"; csv_quote,"'";]; writefile_tab_quote F [] = (); ! writefile_tab_quote F [L|Ls] = [fwritecsv (F, Dialect3) L | writefile_tab_quote F Ls]; + /* Illustration of fwritecsv with escape char */ + def Dialect4 = csv_dialect [csv_escape,"%";]; + writefile_escape F [] = (); + writefile_escape F [L|Ls] = [fwritecsv (F, Dialect4) L + | writefile_escape F Ls]; + def Sample1 = [("this", " that ", 23, -3.0, ""), ("a \"b\"", "c c", 10, 3.2, " "), *************** *** 56,58 **** || 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 --- 66,71 ---- || writes "Writing 'write-sample4.csv:' (tab delimited, single quoted)" || writefile_tab_quote (fopen "write-sample4.csv" "w") Sample3 ! || writes "\ndone.\n\n-----" ! || writes "Writing 'write-sample5.csv:' (quotes are escaped)" ! || writefile_escape (fopen "write-sample5.csv" "w") Sample1 ! || writes "\ndone.\n"; \ No newline at end of file Index: readsamples.q =================================================================== RCS file: /cvsroot/q-lang/q-csv/examples/readsamples.q,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** readsamples.q 18 Jan 2008 21:34:13 -0000 1.4 --- readsamples.q 22 Jan 2008 16:45:16 -0000 1.5 *************** *** 17,34 **** Note that integer and float fields are automatically converted. */ readfile F = [] if feof F; ! = [freadcsv_data F | readfile F]; /* Illustration of freadcsv_string Note that integer and float fields are interpreted as strings. */ readfile_string F = [] if feof F; ! = [freadcsv_string F | readfile_string F]; /* Illustration of freadcsv with tab delimeter */ readfile_tab F = [] if feof F; ! = [freadcsv_data (F, "\t", "\"") | readfile_tab F]; /* 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" --- 17,41 ---- Note that integer and float fields are automatically converted. */ readfile F = [] if feof F; ! = [freadcsv F | readfile F]; /* Illustration of freadcsv_string Note that integer and float fields are interpreted as strings. */ + def Dialect1 = csv_dialect [csv_quoting,csv_quote_all;]; readfile_string F = [] if feof F; ! = [freadcsv (F, Dialect1) | readfile_string F]; /* Illustration of freadcsv with tab delimeter */ + def Dialect2 = csv_dialect [csv_delimiter,"\t";]; readfile_tab F = [] if feof F; ! = [freadcsv (F, Dialect2) | readfile_tab F]; /* Illustration of freadcsv with tab and quote delimeters */ + def Dialect3 = csv_dialect [csv_delimiter,"\t"; csv_quote,"'";]; readfile_tab_quote F = [] if feof F; ! = [freadcsv (F, Dialect3) | readfile_tab_quote F]; ! ! def Dialect4 = csv_dialect [csv_escape,"%";]; ! readfile_escape F = [] if feof F; ! = [freadcsv (F, Dialect4) | readfile_escape F]; main = writes "Reading 'read-sample1.csv:' (standard CSV)\n" *************** *** 44,47 **** --- 51,57 ---- || write (readfile_tab_quote (fopen "read-sample3.csv" "r")) || writes "\n\n-----" + || writes "Reading 'write-sample5.csv' (escaped quotes)\n" + || write (readfile_escape (fopen "write-sample5.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 |