summaryrefslogtreecommitdiffstats
path: root/lib.c
Commit message (Collapse)AuthorAgeFilesLines
* * lib.c (eof_s): New symbol variable.Kaz Kylheku2011-09-271-1/+2
| | | | | | | | | | | (obj_init): New variable initialized. * lib.h (eof_s): Declared. * match.c (match_files): New @(eof) directive explicitly matches end of data. * txr.1: Updated.
* Support &#xNNNN; hex escapes in html. Bugfix in field formatting.Kaz Kylheku2011-09-261-5/+9
| | | | | | | | | | | | | | | | | | | chr function inlined. * filter.c (trie_value_at, trie_lookup_feed_char): Handle function case. (build_filter): New parameter, compress_p. (html_hex_continue, html_hex_handler): New functions. (filter_init): Add a function-based node to the from_html trie. * lib.c (chr): Function removed. (functionp) New function. * lib.h (chr): Declaration replaced with inline function. (functionp): Declared. * match.c (format_field): Bugfix: failed to apply filter that came in as an argument.
* New feature: @(deffilter)Kaz Kylheku2011-09-261-3/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | Bugfix in @(throw) when non-symbol is thrown: exception message referred to the symbol throw rather than the erroneous object. * filter.c (build_filter_from_list, register_filter): New functions. * filter.h (register_filter): New function declared. * lib.c (deffilter_s): New variable defined. (chain): Function changed from single list argument to variable argument list to reduce the complexity of use. (do_and, and): New functions. (obj_init): deffilter_s initializatio added. * lib.h (deffilter_s, and): New declarations. (chain): Declaration updated to new function signature. (eq): Changed from macro to inline function. * match.c (do_output_line): Simplified expression involving chain. (do_output): Likewise. (match_files): Bugfix in error handling of throw. Implementation of deffilter. * txr.1: Documented deffilter.
* Trie compression. Hash table iteration.Kaz Kylheku2011-09-261-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bugfix in typeof. * filter.c (trie_compress): New function. (trie_value_at, trie_lookup_feed_char, filter_string): Handle cons cell nodes in trie. (build_filter): Call trie_compress. * gc.c (cobj_destroy_op): Function renamed to cobj_destroy_stub_op since it doesn't do anything. (cobj_destroy_free_op): New function. * hash.c (struct hash_iter): New type. (hash_destroy): Function removed. (hash_ops): Reference to hash_destroy replaced with cobj_destroy_free_op. (hash_count, hash_iter_mark, hash_begin, hash_next): New functions. (hash_iter_ops): New static structure. * hash.h (hash_count, hash_begin, hash_next): New functions declared. * lib.c (hash_iter_s): New symbol variable. (typeof): Bugfix: TAG_LIT type tag not handled. (vecref): New function. (obj_init): Initialize hash_iter_s. * lib.h (cobj_destroy_op): Declaration renamed. (cobj_destroy_free_op, vecref): New functions declared. (hash_iter_s): New variable declared. * stream.c (string_in_ops, byte_in_ops): cobj_destroy_op renamed to cobj_destroy_stub_op.
* Filtering feature for variable substitution in output.Kaz Kylheku2011-09-251-1/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * filter.c, filter.h: New files. * Makefile (OBJS): filter.o added. * gc.c (mark_obj): Mark new alloc field of string objets. * hash.c (struct hash): New member, userdata. (hash_mark): Mark new userdata member of hash. (make_hash): Initialize userdata. (get_hash_userdata, set_hash_userdata, hashp): New functions. * hash.h (get_hash_userdata, set_hash_userdata, hashp): New functions declared. * lib.c (getplist, string_extend, cobjp): New functions. (string_own, string, string_utf8): Initialize new alloc field to nil. (mkstring, mkustring): Initialize new alloc field to actual size. (length_str): When length is computed and cached, also compute and cache alloc. (init): Call filter_init. * lib.h (string string): New member, alloc. (num_fast): Macro converted to inline function. (getplist, string_extend, cobjp): New functions declared. * match.c (match_line): Follows change of modifier s-exp syntax. (format_field): New parameter, filter. New modifier syntax parsed. Filter retrieved, and applied. (subst_vars): New parameter, filter. Filter is either applied in this function or passed to format_field, as needed. (eval_form): Pass nil to new parameter of subst_vars. (do_output_line): New parameter, filter. Passed down to subst_vars. (do_output): New parameter, filter. Passed down to do_output_line. (match_files): Pass nil filter to subst_vars in cat directive. Output directive refactored to parse keywords, extract the filter and pass down to do_output. * parser.y (regex): Generate (sys:regex regex syntax ...) instead of (regex syntax ...). (elem, expr): Updated w.r.t. regex syntax change. (var): Cases '{' IDENT regex '}' and '{' IDENT NUMBER '}' are removed. new syntax '{' IDENT exprs '}' to handle these more generally and allow for keywords. * txr.1: Updated.
* Numeric constants become real constants.Kaz Kylheku2011-09-241-15/+6
| | | | | | | | | | | | Vector code cleanup. * lib.h (zero, one, two, negone, maxint, minint): Extern declarations removed, macros introduced for these identifiers. * lib.c (zero, one, two, negone, maxint, minint): File scope definitions removed. (vector): Use vec_alloc and vec_fill enums instead of constants. (obj_init): Remove references to removed definitions.
* * LICENSE, Makefile, configure, gc.c, gc.h, hash.c, hash.h, lib.c,Kaz Kylheku2011-09-231-1/+1
| | | | | | lib.h, match.c, match.h, parser.h, parser.l, parser.y, regex.c, regex.h, stream.c, stream.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Updated copyright year.
* Bump copyrights to 2010.Kaz Kylheku2010-10-051-1/+1
|
* * lib.h (lazy_string): Fix incorrect comment.Kaz Kylheku2010-10-031-0/+12
| | | | | | | | * lib.c (split_str, split_str_set): It is necessary to protect input parameters against GC, because we cache their internal pointers, after which we no longer refer to the objects themselves. Moreover, we perform object allocation, and then keep using the internal pointers.
* * lib.c (length_str_gt, length_str_ge, length_str_lt, length_str_le):Kaz Kylheku2010-02-281-36/+64
| | | | Added missing support for literal string type.
* * lib.c (search_str): Bugfix for empty haystack case: checks for endKaz Kylheku2010-02-271-2/+2
| | | | | of string must use postincrement on the index, otherwise the access goes past the null terminator.
* * lib.h (split_str_sep): Declared.Kaz Kylheku2010-02-271-5/+22
| | | | | | | | | * lib.c (split_str_sep): New function. (split_str): Semantics changed; the second argument is not a set of separator characters (like in split_str_sep) but rather a separator string. Fixed bug: if the input string is empty, the output list is empty. This caused infinite looping behavior in @(freeform).
* * lib.c (init_str): Bugfix: copy only len characters, not len + 1, soKaz Kylheku2010-02-241-1/+1
| | | | | | that we don't clobber the null terminator in the target string, or try read past the end of the source data. This affects the @(freeform) directive.
* Optimization in derivative-based regex engine.Kaz Kylheku2010-01-261-0/+17
| | | | | | | | Exponential memory consumption behavior was observed when matching the input aaaaaa.... against the regex a?a?a?a?....aaaa.... The fix is to eliminate common subexpressions from the derivative for the or operator.
* Implemented non-greedy operator.Kaz Kylheku2010-01-151-1/+2
|
* Impelement derivative-based regular expressions.Kaz Kylheku2010-01-131-1/+4
|
* Merge branch 'master' of ssh://git.sv.gnu.org/srv/git/txrKaz Kylheku2010-01-051-9/+11
|\ | | | | | | | | Conflicts: ChangeLog
| * * lib.c (make_package, find_package): Eliminate declarationKaz Kylheku2009-12-171-9/+11
| | | | | | | | | | | | | | | | in the middle of statement block. * lib.h (TAG_MASK): Becomes type cnum rather than long. (nao): Based off 1 rather than -1 to avoid left shift of negative number.
* | Implemented the regular expression ~ and & operators.Kaz Kylheku2010-01-051-1/+3
|/ | | | | | | | | | | | | | | This turns out to be easy to do in NFA land. The complement of an NFA has exactly the same number and configuration of states and transitions, except that the states have an inverted meaning; and furthermore, failed character transitions are routed to an extra state (which in this impelmentation is permanently allocated and shared by all regexes). The regex & is implemented trivially using DeMorgan's. Also, bugfix: regular expressions like A|B|C are allowed now by the syntax, rather than constituting syntax error. Previously, this would have been entered as (A|B)|C.
* * hash.c (sethash): New function.Kaz Kylheku2009-12-091-0/+6
| | | | | | | | * hash.h (sethash): Declared. * lib.c (cobj_handle): New function. * lib.h (cobj_handle): Declared.
* All COBJ operations have default implementations now;Kaz Kylheku2009-12-081-0/+13
| | | | | | no null pointer check over struct cobj_ops operations. New typechecking function for COBJ objects.
* Eliminate the void * disease. Generic pointers are of mem_t *Kaz Kylheku2009-12-041-12/+11
| | | | | from now on, which is compatible with unsigned char *. No implicit conversion to or from this type, in C or C++.
* Code cleanup. All private functions static. Private stuffKaz Kylheku2009-11-281-3/+3
| | | | in regex module not exposed in header. Etc.
* More valgrind integration. Vector objects keep displaced pointersKaz Kylheku2009-11-251-0/+6
| | | | | | | | to vector data; they point to element 0 which is actually the third element of the vector. If an object is only referenced by interior pointers, Valgrind reports it as possibly leaked. This change conditionally adds a pointer to the true start of the vector, if Valgrind support is enabled.
* Fix uninitialized memory locations.Kaz Kylheku2009-11-241-1/+3
|
* Switching to keyword symbols for :args and :nothrow.Kaz Kylheku2009-11-241-6/+9
|
* Changes to make the code portable to C++ compilers, whichKaz Kylheku2009-11-241-13/+14
| | | | can be taken advantage of for better diagnostics.
* Renaming global variables that denote symbols, such that theyKaz Kylheku2009-11-241-95/+98
| | | | have a _s suffix.
* Follow up on 64 bit compilation warnings.Kaz Kylheku2009-11-231-2/+2
|
* * lib.c (chk_malloc, chk_realloc): Fix diagnosable conversion,Kaz Kylheku2009-11-231-2/+2
| | | | caught by gcc 4.1.1.
* Improving portability. It is no longer assumed that pointersKaz Kylheku2009-11-231-26/+27
| | | | | | | | can be converted to a type long and vice versa. The configure script tries to detect the appropriate type to use. Also, some run-time checking is performed in the streams module to detect which conversions specifier strings to use for printing numbers.
* Introducing symbol packages. Internal symbols are now inKaz Kylheku2009-11-211-81/+162
| | | | | | | | | | a system package instead of being hacked with the $ prefix. Keyword symbols are provided. In the matcher, evaluation is tightened up. Keywords, nil and t are not bindeable, and errors are thrown if attempts are made to bind them. Destructuring in dest_bind is strict in the number of items. String streams are exploited to print bindings to objects that are not strings or characters. Numerous bugfixes.
* * unwind.c (uw_throw): If streams are not initialized,Kaz Kylheku2009-11-201-23/+18
| | | | | | we have an unhandled exception too early in initialization. Use C stream to print an error message and abort. Using the nil stream variable will just cause a recursion bomb.
* * lib.c (flatten): Semantics change. The flatten functionKaz Kylheku2009-11-201-0/+3
| | | | should not map nil -> (nil), but nil -> nil.
* Changing ``obj_t *'' occurences to a ``val'' typedef. (Ideally,Kaz Kylheku2009-11-201-255/+241
| | | | | we wouldn't have to declare object variables at all, so why use an obtuse syntax to do so?)
* Get rid of macros in favor of safer inline functions.Kaz Kylheku2009-11-191-2/+2
| | | | | The recent auto_str("byte str") error could have been caught at compile time.
* Use unsigned char * as allocator return value.Kaz Kylheku2009-11-191-2/+2
|
* Following-up on diagnostics obtained by running code through C++Kaz Kylheku2009-11-181-9/+16
| | | | | | compiler. Idea: allocator functions return char * instead of void *, like malloc did in classic pre-ANSI C. That way we are forced to use a cast except when the target pointer is char * already.
* * lib.c (chrp): Fix broken is_chr(num) call.Kaz Kylheku2009-11-171-1/+1
|
* Fixes for compliance to C89.Kaz Kylheku2009-11-171-1/+2
|
* Big round of changes to switch the code base to use the streamKaz Kylheku2009-11-161-70/+71
| | | | | | | | | | | | | | | | | abstraction instead of directly using C standard I/O, to eliminate most uses of C formatted I/O, and fix numerous bugs, such variadic argument lists which lack a terminating ``nao'' sentinel. Bug 28033 is addressed by this patch, since streams no longer provide printf-compatible formatting. The native formatter is extended with some additional capabilities to take over. The work on literal objects is expanded and they are now used throughout the code base. Fixed bad realloc in string output stream: reallocating by number of wide chars rather than bytes.
* Use the 11 tag bit pattern to denote a new type: LIT. This is aKaz Kylheku2009-11-161-96/+129
| | | | | pointer to a C static string, intended for literals. We can now treat literal strings as light-weight objects.
* * lib.c (chr): Take wchar_t argument, not int. Dropped range check.Kaz Kylheku2009-11-151-4/+3
| | | | | | (c_chr): Return wchar_t not int. * lib.h (chr, c_chr): Declarations updated.
* Version 021 preparation.txr-021Kaz Kylheku2009-11-151-1/+1
| | | | Bumped version numbers, and cleaned up trailing whitespace from some files.
* Provide both char * and unsigned char * interfaces in UTF-8 module.Kaz Kylheku2009-11-141-1/+1
| | | | Fix unsigned and plan char * mixing.
* * lib.c (symbolp): Bugfix: function crashed on NUM argument.Kaz Kylheku2009-11-131-2/+3
| | | | | | | | | | | (lazy_str): Fix for gc correctness: object from make_obj must be completely intialized before any gc-triggering operation is invoked, otherwise the garbage collector will be traversing an object whose fields contain old garbage. (lazy_str_force_upto): Off-by-one error. To force the object up to index position N, means forcing up to length N+1. This bug can make it look like a lazy string is much shorter than it really is.
* Continuing wchar_t conversion. Making sure all stdio callsKaz Kylheku2009-11-121-10/+10
| | | | | use wide character functions so that there is no illicit mixing. (But the goal is to replace this usage with txr streams).
* Big conversion to wide characters and UTF-8 support.Kaz Kylheku2009-11-111-158/+170
| | | | | | | | | This is incomplete. There are too many dependencies on wide character support from the C stream I/O library, and implicit use of some encoding which may not be UTF-8. The regex code does not handle wide characters properly. Character type is still int in some places, rather than wchar_t. Test suite passes though.
* Changing representation of objects to allow for unboxed characters.Kaz Kylheku2009-11-091-28/+32
| | | | | Now numbers and characters fit into a cell. We lose one more bit from the range of numbers.
* Changing representation of objects to allow the NUM type to beKaz Kylheku2009-11-091-44/+50
| | | | | | | | unboxed. If the lowest bit of the obj_t * pointer is 1, then the remaining bits are a number. A lot of assumptions are made: - the long type can be converted to and from a pointer - two's complement. - behavior of << and >> operators when the sign bit is involved.