pax_global_header00006660000000000000000000000064136326653540014527gustar00rootroot0000000000000052 comment=586f87aca3cba49df8787dc624de8e3a58e32dab xmlindent-0.2.18/000077500000000000000000000000001363266535400136215ustar00rootroot00000000000000xmlindent-0.2.18/BUGS000066400000000000000000000004751363266535400143120ustar00rootroot00000000000000 BUGS The current version has the following known bugs and limitations: - Attributes inside start-tags and empty element tags are not indented. - The scanner trips over on characters that are not part of 7-bit ASCII (ISO-8859-1 and UTF-8, for example, don't work correctly). - Comments are not formatted. xmlindent-0.2.18/ChangeLog000066400000000000000000000162351363266535400154020ustar00rootroot000000000000002020-03-13 Pekka Enberg * Release 0.2.18. 2020-02-26 Walter Doekes * build: Fix makefile to be (almost) debian compatible (#2) 2020-02-23 Walter Doekes * build: Fix rebuild of indent.c after xmlindent.yy update (#1) * parse: Fix whitespace consumption within text nodes (#3) 2020-02-10 Walter Doekes * parse: Don't abort() on parse errors; cope with NULs; handle EOF (#4) 2012-01-24 Pekka Enberg * Fix whitespace corruption in XML elements. 2004-09-17 Pekka Enberg * Release 0.2.17. 2004-09-07 Pekka Enberg * New README file. * Better usage printout. * Support for multiple files in the command line. 2004-03-29 Heikki Orsila * Fixed Makefile dependencies. 2004-03-28 Pekka Enberg * Update BUGS, bump up version, and release 0.2.16. 2004-03-28 Alexander Dupuy * Fixed a bug in line wrapping code that caused corrupted output. 2004-02-16 Pekka Enberg * Released 0.2.15. * Updated BUGS. 2004-02-16 Aubin Paul * Debian packaging. 2004-02-15 Pekka Enberg * Released 0.2.14. * Added a LICENSE file and standard GPL banner to source files. * Added processing instruction parsing (see Section 2.6 of XML 1.0 specification). Thanks to Rob Austein for the bug report. 2004-02-05 Pekka Enberg * Bump up version number and re-release 0.2.13. * Fix for the doctype section parsing fix. Thanks David for testing. * Release 0.2.13 * Fix DOCTYPE parsing error that caused corruption in output file. Bug reported by . 2003-09-28 Pekka Enberg * Release 0.2.12 * Fix empty element indentation. Thanks to Gabriel C Millerd and Mika Viljanen for the bug reports. 2003-09-26 Pekka Enberg * Release 0.2.11 * Fix error in empty element tag indentation that caused corruption in files (spotted by Mika Viljanen). * Avoid zero-length files. Thanks to Mika Viljanen for spotting this one! 2003-09-18 Pekka Enberg * Release 0.2.10 * Code cleanups * Follow indent options for empty element tags too. Thanks to Todd Hammer for pointing out the limitation. 2003-08-09 Pekka Enberg * Release 0.2.9 2003-08-09 Nicola S. Vitale * Parse attributes with character references properly. 2003-07-08 Pekka Enberg * Release 0.2.8 * Minor cleanups to Basile's patch 2003-07-08 Basile Starynkevitch * Fix compile with Flex 2.5.31 2003-07-02 Pekka Enberg * Release 0.2.7 2003-06-11 Nicola S. Vitale * Fix incorrect EOF handling. 2003-06-08 Pekka Enberg * Release 0.2.6 * Add new command line option '-f' (force newline for elements without children) to fix a bug reported by Paul Campbell. 2003-06-04 Pekka Enberg * Release 0.2.5 * Fix bug in parsing attributes scattered across multiple lines. * Fix start-tag attribute parsing bug. 2003-05-14 Pekka Enberg * Fix compile warnings when compiled with '-Wstrict-prototypes' 2003-05-14 Graham Barr * Fix too greedy CDATA section parsing 2003-03-10 Pekka Enberg * Release version 0.2.4 * Cleanups for automatic newline suppressing code. 2003-03-07 Pekka Enberg * Reverse meaning of '-n * Release version 0.2.3 * Fix DOCTYPE parsing error that caused problems with DocBook XMLs. 2003-02-26 Pekka Enberg * Fix EOF check on PPC and probably some other non IA-32 platforms as well 2003-02-25 Pekka Enberg * Makefile fix for Solaris 2003-02-12 Pekka Enberg * Fix bug in line wrapping that ate whitespace from next line. * Add '-nbs' and '-nbe' options. * Release version 0.2.2 * Fix comment parsing bug found by Nicolas Girard. 2003-02-11 Pekka Enberg * Make it compile with non-ANSI C99 compiliant compiler (thanks to Nicolas Girard for spotting this one) 2003-02-08 Pekka Enberg * Release version 0.2.1 * Remove support for forcing newline before tags because it produces too funky results * Support line wrapping command line option '-l' 2003-02-06 Pekka Enberg * Avoid duplicate newlines * Eat whitespace after newline 2003-02-03 Pekka Enberg * Release version 0.2.0 * Support forcing newline after and before start and end-tags. * Use flex for generating the XML parser. Regressions -c not supported anymore. 2002-10-26 Pekka Enberg * Release version 0.1.9 2002-10-25 Pekka Enberg * Emit last line even if there was no newline before end of file. 2002-10-04 Peter Bray * Avoid reallocations for long lines. 2002-10-04 Pekka Enberg * Release version 0.1.8 * Fix segfault for lines longer than 1024 characters. Thanks to Peter Bray for spotting this one. 2002-10-01 Brett Pemberton * RPM spec and Makefile fixes 2002-10-01 Pekka Enberg * Recognize two character end of line markers. * Added overwrite original file command line option -w. 2002-09-29 Pekka Enberg * Release version 0.1.7 2002-09-28 Pekka Enberg * Add RPM spec file. * Add version printing command line option -v. * Add output filename command line option -o. * Fix eats empty lines. * Release version 0.1.6 2002-09-25 Pekka Enberg * Use instead of . * Add compile, install, and uninstall targets to Makefile. 2002-09-24 Thomas Fischer * Add man page. 2002-09-24 Pekka Enberg * Release version 0.1.5 * Leave CDATA sections alone. 2002-09-23 Pekka Enberg * Release version 0.1.4 * Add use tabs command line option. 2002-09-23 Brett Pemberton * Break up xmlindent to xmlindent.c and main.c. * Parse command line arguments with getopts. 2002-09-21 Pekka Enberg * Release version 0.1.3 * Better end of line recognizition. * Add leave comments alone command line option -c. * Recognize start-tags beginning with underscore or colon. 2002-09-21 Markus Hjort * Add indent level command line option -i. 2002-09-19 Pekka Enberg * Release version 0.1.2 * Fix closed XML tag after XML begin tag caused indent errors. * Release version 0.1.1 * Recognize XML comments. * Eat leading whitespace. * Remove fixed-size buffer. Recognize begin tags better. 2002-09-18 Pekka Enberg * Release version 0.1 xmlindent-0.2.18/LICENSE000066400000000000000000000431311363266535400146300ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. xmlindent-0.2.18/Makefile000066400000000000000000000014351363266535400152640ustar00rootroot00000000000000all: xmlindent PREFIX=/usr/local DESTDIR= BIN_INSTALL_DIR=$(PREFIX)/bin MAN_INSTALL_DIR=$(PREFIX)/share/man/man1 CFLAGS=-Wall -g LDFLAGS=-Wl,-z,defs -Wl,-as-needed -Wl,--no-undefined xmlindent: buffer.o error.o indent.o main.o $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ .c.o: $(CC) $(CFLAGS) $^ -c -o $@ indent.c: lex.yy.c touch indent.c lex.yy.c: xmlindent.yy flex xmlindent.yy install: xmlindent mkdir -p $(DESTDIR)$(BIN_INSTALL_DIR) mkdir -p $(DESTDIR)$(MAN_INSTALL_DIR) install -m555 xmlindent $(DESTDIR)$(BIN_INSTALL_DIR)/xmlindent install -m444 xmlindent.1 $(DESTDIR)$(MAN_INSTALL_DIR)/xmlindent.1 uninstall: rm -f $(DESTDIR)$(BIN_INSTALL_DIR)/xmlindent rm -f $(DESTDIR)$(MAN_INSTALL_DIR)/xmlindent.1 clean: rm -f xmlindent *.o core lex.yy.c .PHONY: all clean install uninstall xmlindent-0.2.18/README000066400000000000000000000011061363266535400144770ustar00rootroot00000000000000WHAT IS IT? XML Indent is a XML stream reformatter written in ANSI C. You can find the latest version here: - http://www.cs.helsinki.fi/u/penberg/xmlindent/ PLATFORMS Compiles and runs on most POSIX compatible systems. MAINTAINER Pekka Enberg CONTRIBUTORS Graham Barr, Peter Bray, Alexander Dupuy, Thomas Fischer, Markus Hjort, Aubin Paul, Brett Pemberton, Basile Starynkevitch, and Nicola S. Vitale. LICENSE XML Indent is Free Software released under the GNU General Public License (GPL). See the file LICENSE for details. xmlindent-0.2.18/buffer.c000066400000000000000000000060261363266535400152420ustar00rootroot00000000000000/* * Copyright (C) 2002 Pekka Enberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "error.h" #include "buffer.h" /* Initialize buffer. */ void buffer_init(struct buffer * buffer, size_t initial_capacity) { buffer->data = malloc(initial_capacity * sizeof(unsigned char)); buffer->length = 0; buffer->capacity = initial_capacity; } /* Release buffer. */ void buffer_release(struct buffer * buffer) { if (buffer->capacity > 0) { free(buffer->data); buffer->data = NULL; buffer->capacity = 0; } buffer->length = 0; } /* Check if buffer is full. */ bool buffer_is_full(struct buffer * buffer) { return (buffer->capacity == buffer->length); } #define BUFFER_GROWTH_INCREMENT 256 /* Grow buffer by one. */ void buffer_grow(struct buffer * buffer) { buffer->data = realloc(buffer->data, (buffer->capacity + BUFFER_GROWTH_INCREMENT) * sizeof(unsigned char)); if (buffer->data == NULL) { error("Could not allocate memory for buffer."); exit(1); } buffer->capacity += BUFFER_GROWTH_INCREMENT; } /* Push character at the end of buffer. */ void buffer_push_char(struct buffer * buffer, int c) { if (buffer_is_full(buffer)) { buffer_grow(buffer); } buffer->data[buffer->length] = c; buffer->length++; } /* Push string at the end of buffer. */ void buffer_push_str(struct buffer * buffer, const char * text) { int i; for (i = 0; i < strlen(text); i++) { buffer_push_char(buffer, (int) text[i]); } } /* Pop item from back of buffer. */ int buffer_pop_char(struct buffer * buffer) { int result = -1; if (buffer->length > 0) { buffer->length--; result = buffer->data[buffer->length]; } else { error("Buffer underflow."); } return result; } /* Flush buffer to output stream. */ void buffer_flush(struct buffer * buffer, FILE * output) { int i; for (i = 0; i < buffer->length; i++) { fputc(buffer->data[i], output); } buffer->length = 0; } /* Return buffer size. */ size_t buffer_size(struct buffer * buffer) { return buffer->length; } void buffer_copy(struct buffer * dest, struct buffer * src) { int i; for (i = 0; i < src->length; i++) { buffer_push_char(dest, src->data[i]); } } void buffer_clear(struct buffer * buf) { buf->length = 0; } xmlindent-0.2.18/buffer.h000066400000000000000000000027111363266535400152440ustar00rootroot00000000000000/* * Copyright (C) 2002 Pekka Enberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _BUFFER_H_ #define _BUFFER_H_ 1 #include #include #include /* Buffer used to hold XML stream. */ struct buffer { char * data; size_t length; size_t capacity; }; void buffer_init(struct buffer * buffer, size_t initial_capacity); void buffer_release(struct buffer * buffer); void buffer_push_str(struct buffer * buffer, const char * text); void buffer_push_char(struct buffer * buffer, int c); int buffer_pop_char(struct buffer * buffer); void buffer_flush(struct buffer * buffer, FILE * output); void buffer_copy(struct buffer * dest, struct buffer * src); void buffer_clear(struct buffer * buf); size_t buffer_size(struct buffer * buffer); #endif xmlindent-0.2.18/debian/000077500000000000000000000000001363266535400150435ustar00rootroot00000000000000xmlindent-0.2.18/debian/changelog000066400000000000000000000002101363266535400167060ustar00rootroot00000000000000xmlindent (0.2.14-1) unstable; urgency=low * Initial Release. -- Aubin Paul Mon, 16 Feb 2004 09:36:11 -0500 xmlindent-0.2.18/debian/compat000066400000000000000000000000021363266535400162410ustar00rootroot000000000000004 xmlindent-0.2.18/debian/control000066400000000000000000000005621363266535400164510ustar00rootroot00000000000000Source: xmlindent Section: devel Priority: optional Maintainer: Aubin Paul Build-Depends: debhelper (>= 4.0.0) Standards-Version: 3.6.0 Package: xmlindent Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: An XML stream reformatter XML Indent is a XML stream reformatter written in ANSI C. It is analogous to GNU indent. xmlindent-0.2.18/debian/copyright000066400000000000000000000006661363266535400170060ustar00rootroot00000000000000This package was debianized by Aubin Paul on Mon, 16 Feb 2004 09:36:11 -0500. It was downloaded from http://www.cs.helsinki.fi/u/penberg/xmlindent/ Upstream Author: Pekka Enberg xmlindent.1 touch build-stamp clean: dh_testdir dh_testroot rm -f build-stamp configure-stamp # Add here commands to clean up after the build process. -$(MAKE) clean dh_clean install: build dh_testdir dh_testroot dh_clean -k dh_installdirs $(MAKE) install PREFIX=$(CURDIR)/debian/xmlindent/usr # Build architecture-independent files here. binary-indep: build install # We have nothing to do by default. # Build architecture-dependent files here. binary-arch: build install dh_testdir dh_testroot dh_installchangelogs ChangeLog dh_installdocs dh_installexamples # dh_install # dh_installmenu # dh_installdebconf # dh_installlogrotate # dh_installemacsen # dh_installpam # dh_installmime # dh_installinit # dh_installcron # dh_installinfo dh_installman dh_link dh_strip dh_compress dh_fixperms # dh_perl # dh_python # dh_makeshlibs dh_installdeb dh_shlibdeps dh_gencontrol dh_md5sums dh_builddeb binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary install configure xmlindent-0.2.18/error.c000066400000000000000000000020251363266535400151150ustar00rootroot00000000000000/* * Copyright (C) 2002 Pekka Enberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include /* Print error message. */ void error(const char * format, ...) { va_list args; fprintf(stderr, "Error: "); va_start(args, format); vfprintf(stderr, format, args); va_end(args); fputc('\n', stderr); } xmlindent-0.2.18/error.h000066400000000000000000000015711363266535400151270ustar00rootroot00000000000000/* * Copyright (C) 2002 Pekka Enberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _ERROR_H_ #define _ERROR_H_ 1 /* Print error message. */ void error(const char * format, ...); #endif xmlindent-0.2.18/indent.c000066400000000000000000000302101363266535400152420ustar00rootroot00000000000000/* * Copyright (C) 2002-2004 Pekka Enberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "buffer.h" #include "indent.h" /* * Functions the generated scanner uses. */ static void xml_declaration(void); static void cdata_section(void); static void doctype_declaration(void); static void start_tag(void); static void end_tag(void); static void empty_element_tag(void); static void comment(void); static void content(void); static void processing_insn(void); static void do_newline(struct buffer * buffer, const char * text); #include "lex.yy.c" /* * Flex unput() wrapper */ extern void do_unput(int); /* * Functions we use. */ static void newline(void); /* * We have three buffers: primary, secondary, and tag buffer. The first one * has all data before previous start-tag, second one has data encountered * after previous start-tag, and the last one _has_ the start-tag. */ struct buffer primary_buf; struct buffer secondary_buf; struct buffer tag_buf; struct buffer * current_buf; /* * Indent options. To be modified only trough set_options. */ static char indent_char; static int num_indent_chars; static bool force_newline_after_start_tag; static bool force_newline_after_end_tag; static bool force_newline_before_start_tag; static bool force_newline_before_end_tag; static bool force_always; static int max_columns; static bool wrap_long_lines; static FILE * indent_output; /* * Default options. */ #define DEFAULT_INDENT_CHAR ' ' #define DEFAULT_NUM_INDENT_CHARS 4 /* Set default indent options. */ void indent_options_set_defaults(struct indent_options * opts) { opts->indent_char = DEFAULT_INDENT_CHAR; opts->num_indent_chars = DEFAULT_NUM_INDENT_CHARS; opts->max_columns = -1; opts->wrap_long_lines = false; opts->force_newline_after_start_tag = true; opts->force_newline_after_end_tag = true; opts->force_newline_before_start_tag = true; opts->force_newline_before_end_tag = true; opts->force_always = false; } /* Set indent options. */ static void set_options(struct indent_options * opts) { indent_char = opts->indent_char; num_indent_chars = opts->num_indent_chars; max_columns = opts->max_columns; wrap_long_lines = opts->wrap_long_lines; force_newline_after_start_tag = opts->force_newline_after_start_tag; force_newline_after_end_tag = opts->force_newline_after_end_tag; force_newline_before_start_tag = opts->force_newline_before_start_tag; force_newline_before_end_tag = opts->force_newline_before_end_tag; force_always = opts->force_always; } #define BUFFER_INITIAL_CAPACITY 1024 void indent(FILE * input, FILE * output, struct indent_options * opts) { set_options(opts); buffer_init(&primary_buf, BUFFER_INITIAL_CAPACITY); buffer_init(&secondary_buf, BUFFER_INITIAL_CAPACITY); buffer_init(&tag_buf, BUFFER_INITIAL_CAPACITY); current_buf = &primary_buf; yyin = input; indent_output = output; yylex(); /* * There might not have been a newline before EOF. */ buffer_flush(current_buf, indent_output); buffer_release(&primary_buf); buffer_release(&secondary_buf); buffer_release(&tag_buf); } /* Print indent characters. */ static void print_indent(FILE * output, int indent_level) { int i; for (i = 0; i < (num_indent_chars * indent_level); i++) { fputc(indent_char, output); } } static void xml_declaration(void) { buffer_push_str(current_buf, yytext); } static void cdata_section(void) { buffer_push_str(current_buf, yytext); } static void doctype_declaration(void) { buffer_push_str(current_buf, yytext); } /* XML end of line characters. */ #define CARRIAGE_RETURN 0x0D #define LINE_FEED 0x0A #define NEL 0x85 static inline bool is_newline(int current) { if ((CARRIAGE_RETURN == current) || (LINE_FEED == current) || (NEL == current)) return true; return false; } /* Check for whitespace character. */ static inline bool is_whitespace(int c) { return ((c == ' ') || (c == '\f') || (c == '\t') || (c == '\v')); } /* Eat whitespace from stream. */ static void eat_whitespace(void) { for (;;) { int current = input(); if (!is_whitespace(current)) { do_unput(current); break; } } } static int indent_level = 0; static int indent_delta = 0; /* Force newline before tag. Use buffer for getting current character. */ static void force_newline_before_tag(struct buffer * buffer) { int current; if (buffer_size(buffer) == 0) { /* * We just did a newline, no need to force it. */ return; } current = buffer_pop_char(buffer); buffer_push_char(buffer, current); if (!is_newline(current)) { do_newline(buffer, "\n"); if (is_whitespace(current)) { eat_whitespace(); return; } } } /* Force newline after tag. Use lexer to get current character. */ static void force_newline_after_tag(struct buffer * buffer) { int current = input(); do_unput(current); if (!is_newline(current)) { do_newline(buffer, "\n"); eat_whitespace(); } } static bool using_primary_buf(void) { return current_buf == &primary_buf; } /* Merge tag and secondary buffer to primary buffer. Force newlines if necessary. This routine is used with start-tags. */ static void merge_buffers_start_tag(void) { if (force_newline_before_start_tag) { force_newline_before_tag(&primary_buf); } buffer_copy(&primary_buf, &tag_buf); indent_delta++; if (force_newline_after_start_tag) { force_newline_after_tag(&primary_buf); } buffer_copy(&primary_buf, &secondary_buf); buffer_clear(&tag_buf); buffer_clear(&secondary_buf); current_buf = &primary_buf; } /* Merge tag and secondary buffer back to primary buffer. */ static void merge_buffers(void) { buffer_copy(&primary_buf, &tag_buf); buffer_copy(&primary_buf, &secondary_buf); buffer_clear(&tag_buf); buffer_clear(&secondary_buf); current_buf = &primary_buf; /* We just processed a start-tag so bump up indent_delta. */ indent_delta++; } /* Force newline for wrapping line. Use lexer to get current character and do not eat whitespace from next line. */ static void force_newline_for_wrap(struct buffer * buffer) { int current = input(); /* * Flush all pending stuff before doing the newline. */ if (!using_primary_buf()) { merge_buffers(); } do_newline(current_buf, "\n"); if (!is_newline(current)) do_unput(current); } static void start_tag(void) { char * tmp; /* * Save text because merge_buffers_start_tag may trash it. */ tmp = strdup(yytext); if (!using_primary_buf()) { /* * This is second start-tag. Thus first one has children. We can force * newline here if we want. */ merge_buffers_start_tag(); } buffer_push_str(&tag_buf, tmp); current_buf = &secondary_buf; free(tmp); } static void end_tag(void) { bool can_force_newline; char * tmp; /* * Save text because force_newline_before_tag can trash it. */ tmp = strdup(yytext); if (using_primary_buf()) { can_force_newline = true; } else { /* The element didn't have any children - force newline only if user explicity requested that. */ merge_buffers(); can_force_newline = force_always; } if (force_newline_before_end_tag && can_force_newline) { force_newline_before_tag(current_buf); } buffer_push_str(current_buf, tmp); indent_delta--; if (force_newline_after_end_tag && can_force_newline) { force_newline_after_tag(current_buf); } free(tmp); } static void empty_element_tag(void) { bool can_force_newline; char * tmp; /* * Save text because force_newline_before_tag can trash it. */ tmp = strdup(yytext); /* We treat empty element tag as a "merged" start-tag and end-tag. Therefore we use start-tag options before the tag and end-tag options after the tag. */ if (!using_primary_buf()) { /* * This is second start-tag. Thus first one has children. We can force * newline here if we want. */ merge_buffers_start_tag(); can_force_newline = force_always; } else { can_force_newline = true; } buffer_push_str(current_buf, tmp); if (force_newline_after_end_tag && can_force_newline) { /* Empty element never has any children. Force newline only if user explicitly requested it. */ force_newline_after_tag(current_buf); } free(tmp); } static int input_and_push(void) { int ret = input(); if (ret != EOF) buffer_push_char(current_buf, ret); return ret; } static void comment(void) { int c; buffer_push_str(current_buf, yytext); for (;;) { while ((c = input_and_push()) != '-' && c != EOF) ; if ((c = input_and_push()) != '-') { continue; } if ((c = input_and_push()) == '>') { break; } } } static void do_newline(struct buffer * buffer, const char * text) { buffer_push_str(buffer, text); if (indent_delta < 0) indent_level += indent_delta; print_indent(indent_output, indent_level); if (indent_delta > 0) indent_level += indent_delta; indent_delta = 0; buffer_flush(buffer, indent_output); } static void newline(void) { /* * Flush all pending stuff before doing the newline. */ if (!using_primary_buf()) { merge_buffers(); } do_newline(current_buf, "\n"); eat_whitespace(); } /* * We assume tab is equal to 8 spaces. */ #define TAB_SIZE 8 static unsigned long indent_size(void) { return (indent_char == '\t' ? indent_level * TAB_SIZE : indent_level * num_indent_chars); } static bool need_wrap(struct buffer * buffer) { if (buffer == &primary_buf) return buffer_size(buffer) + indent_size() == max_columns; else return (buffer_size(&primary_buf) + buffer_size(&tag_buf) + buffer_size(buffer) + indent_size()) >= max_columns; } /* * We detect EOF by getting a call to yywrap() when the only input file * is completely read. */ static bool is_at_eof; int yywrap() { is_at_eof = 1; return 1; /* 1=nothing more to read */ } static void content(void) { char current; /* * We should get one character at a time. */ assert(yyleng == 1); /* strlen(yytext) fails at NUL or EOF */ current = yytext[0]; if (is_at_eof) return; if (is_newline(current)) { newline(); return; } buffer_push_char(current_buf, current); /* * Forcing newline changes 'text' so lets do it after we've pushed * it to the buffer. */ if (wrap_long_lines && need_wrap(current_buf)) { struct buffer tmp; buffer_init(&tmp, buffer_size(current_buf)); /* * Find last character that was not whitespace */ for (;;) { int c; if (buffer_size(current_buf) == 0) break; c = buffer_pop_char(current_buf); if (is_whitespace(c)) { /* * Do not push whitespace because it would appear * after the newline. */ break; } /* * Characters are put in tmp buffer in reverse order. */ buffer_push_char(&tmp, c); } force_newline_for_wrap(current_buf); /* * Restore non-wrapped text into buffer. */ while (buffer_size(&tmp) > 0) { buffer_push_char(current_buf, buffer_pop_char(&tmp)); } buffer_release(&tmp); } } static void processing_insn(void) { buffer_push_str(current_buf, yytext); } xmlindent-0.2.18/indent.h000066400000000000000000000024731363266535400152610ustar00rootroot00000000000000/* * Copyright (C) 2002-2003 Pekka Enberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _INDENT_H_ #define _INDENT_H_ 1 #include "buffer.h" #include /* * Indent options */ struct indent_options { char indent_char; int num_indent_chars; bool force_newline_after_start_tag; bool force_newline_after_end_tag; bool force_newline_before_start_tag; bool force_newline_before_end_tag; bool force_always; int max_columns; bool wrap_long_lines; }; void indent_options_set_defaults(struct indent_options * opts); void indent(FILE * input, FILE * output, struct indent_options * opts); #endif xmlindent-0.2.18/main.c000066400000000000000000000121121363266535400147060ustar00rootroot00000000000000/* * Copyright (C) 2002-2004 Pekka Enberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "buffer.h" #include "error.h" #include "indent.h" #include "version.h" #include #include #include #include #include #include static void version(void) { printf("XML Indent, version %s\n", VERSION); printf("Copyright (C) 2002-2004 Pekka Enberg\n"); } static void usage(void) { printf("Usage: %s [options] [filename] ...\n", PACKAGE); printf("Options:\n"); printf("\t-o \tOutput file\n"); printf("\t-i \tIndent level\n"); printf("\t-t\t\tUse tabs instead of spaces for indent\n"); printf("\t-l \tMaximum columns for line wrapping\n"); printf("\t-n \tSuppress newline at position\n"); printf("\t-f\t\tForce newline on elements without children\n"); printf("\t-h\t\tHelp\n"); printf("\t-v\t\tVersion information\n"); printf("\t-w\t\tOverwrite original file\n"); } /* Overwrite original files. */ static bool overwrite = false; static int format_file(const char * filename, char * output_filename, struct indent_options * opts) { char input_filename[FILENAME_MAX]; FILE * input; FILE * output; input_filename[0] = '\0'; if (filename != NULL) { strcpy(input_filename, filename); /* Avoid zero-length files. */ if (overwrite || strcmp(input_filename, output_filename) == 0) { char backup_filename[FILENAME_MAX]; strcpy(backup_filename, input_filename); strcat(backup_filename, "~"); rename(input_filename, backup_filename); strcpy(output_filename, input_filename); strcpy(input_filename, backup_filename); } } if (strlen(input_filename) > 0) { input = fopen(input_filename, "r"); if (NULL == input) { error("Could not open '%s': %s.", input_filename, strerror(errno)); return EXIT_FAILURE; } } else { input = stdin; } if (strlen(output_filename) > 0) { output = fopen(output_filename, "w"); if (NULL == output) { error("Could not open '%s': %s.", output_filename, strerror(errno)); return EXIT_FAILURE; } } else { output = stdout; } indent(input, output, opts); if (output != stdout) fclose(output); if (input != stdout) fclose(input); return EXIT_SUCCESS; } static void parse_force_newline_arg(char * arg, struct indent_options * opts) { if (strcmp(arg, "as") == 0) { opts->force_newline_after_start_tag = false; } else if (strcmp(arg, "ae") == 0) { opts->force_newline_after_end_tag = false; } else if (strcmp(arg, "bs") == 0) { opts->force_newline_before_start_tag = false; } else if (strcmp(arg, "be") == 0) { opts->force_newline_before_end_tag = false; } } static void parse_args(int argc, char * argv[], struct indent_options * opts, char * output_filename) { bool explicit_indent_level = false; for (;;) { int arg_index = getopt(argc, argv, "hfi:l:o:n:tvw"); if (arg_index == -1) { break; } switch (arg_index) { case 'h': usage(); exit(EXIT_SUCCESS); case 'i': opts->num_indent_chars = atoi(optarg); explicit_indent_level = true; break; case 'l': opts->max_columns = atoi(optarg); opts->wrap_long_lines = true; break; case 't': opts->indent_char = '\t'; if (!explicit_indent_level) { /* Default indent level for tabs is different. */ opts->num_indent_chars = 1; } break; case 'f': opts->force_always = true; break; case 'o': strcpy(output_filename, optarg); break; case 'n': parse_force_newline_arg(optarg, opts); break; case 'v': version(); exit(EXIT_SUCCESS); case 'w': overwrite = true; break; default: usage(); exit(EXIT_FAILURE); } } } int main(int argc, char * argv[]) { char output_filename[FILENAME_MAX]; struct indent_options opts; int ret = EXIT_SUCCESS; int i; output_filename[0] = '\0'; indent_options_set_defaults(&opts); parse_args(argc, argv, &opts, output_filename); /* Iterate over all input files. */ for (i = optind; i < argc; i++) { ret = format_file(argv[i], output_filename, &opts); if (ret != EXIT_SUCCESS) break; } /* When we have no input files to process, wait for stdin. */ if (optind == argc) ret = format_file(NULL, output_filename, &opts); return ret; } xmlindent-0.2.18/test.xml000066400000000000000000000010151363266535400153170ustar00rootroot00000000000000 <_root> <:node>

we don't want to force newline here

but in here, do want that

This line is clearly too long for 80-column terminal. Perhaps it should be wrapped? xmlindent-0.2.18/tests/000077500000000000000000000000001363266535400147635ustar00rootroot00000000000000xmlindent-0.2.18/tests/whitespace-in-content.expected.xml000066400000000000000000000000461363266535400235150ustar00rootroot00000000000000 1 2 3 4 5 xmlindent-0.2.18/tests/whitespace-in-content.orig.xml000066400000000000000000000000401363266535400226460ustar00rootroot000000000000001 2 3 4 5 xmlindent-0.2.18/version.h000066400000000000000000000015641363266535400154650ustar00rootroot00000000000000/* * Copyright (C) 2002-2004 Pekka Enberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _VERSION_H #define _VERSION_H 1 #define PACKAGE "xmlindent" #define VERSION "0.2.18" #endif xmlindent-0.2.18/xmlindent.1000066400000000000000000000023071363266535400157070ustar00rootroot00000000000000.TH "xmlindent" "1" "0.2.18" "Thomas Fischer" "" .SH "NAME" .LP xmlindent \- XML stream reformatter .SH "SYNTAX" .LP xmlindent [\fB\-o\fP \fIoutput file\fP] [\fB\-i\fP \fIindent level\fP] [\fB\-l\fP \fImax columns\fP] [\fB\-n\fP \fInewline position\fP] [\fB\-t\fP] [\fB\-c\fP] [\fB-f\fP] [\fB\-w\fP] [\fB\-h\fP] [\fB\-v\fP] .SH "DESCRIPTION" .LP XML Indent is a XML stream reformatter written in ANSI C. It is analogous to GNU indent. .SH "OPTIONS" .LP .TP \fB\-o\fR \fIoutput file\fP Write indented XML to \fIoutput file\fP .TP \fB\-i\fR \fIindent level\fP Indent each level \fIindent level\fP spaces deeper .TP \fB\-l\fR \fImax columns\fP Wrap lines longer than \fImax columns\fP .TP \fB\-t\fR Use tabs instead of spaces .TP \fB\-nas\fR Suppress newline after start-tag .TP \fB\-nae\fR Suppress newline after end-tag .TP \fB\-nbs\fR Suppress newline before start-tag .TP \fB\-nbe\fR Suppress newline before end-tag .TP \fB\-f\fR Force newline on elements without children .TP \fB\-w\fR Overwrite original file .TP \fB\-v\fR Show version .TP \fB\-h\fR Show command line help .SH "AUTHORS" .LP Pekka Enberg .br Thomas Fischer (man page) .SH "SEE ALSO" .LP indent(1) xmlindent-0.2.18/xmlindent.spec000066400000000000000000000013221363266535400164750ustar00rootroot00000000000000%define version 0.2.18 %define release 1 %define name xmlindent Summary: a XML stream reformatter Name: %{name} Version: %{version} Release: %{release} Copyright: GPL Group: Text Processing/Markup/XML Source: http://www.cs.helsinki.fi/u/~penberg/xmlindent/src/xmlindent-%{version}.tar.gz URL: http://www.cs.helsinki.fi/u/~penberg/xmlindent/ BuildRoot: /var/tmp/%{name}-%{version} Packager: Pekka Enberg %description XML Indent is a XML stream reformatter written in ANSI C. It is analogous to GNU indent. %prep %setup %build make all %install rm -rf $RPM_BUILD_ROOT make PREFIX="$RPM_BUILD_ROOT/usr" install %clean rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root) %{_bindir}/* %{_mandir}/*/* xmlindent-0.2.18/xmlindent.yy000066400000000000000000000050311363266535400162050ustar00rootroot00000000000000/* * Copyright (C) 2002-2004 Pekka Enberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Scanner for XML Indent. */ %{ /* Flex 2.5.31 and higher limits use of unput() to definitions section of the input file. */ static void yyunput(int, char *); void do_unput(int c) { unput(c); } %} /* * We're mostly following the XML 1.0 specification: * http://www.w3.org/TR/2000/REC-xml-20001006 */ LETTER [[:alpha:]] DIGIT [[:digit:]] NAME_CHAR ({LETTER}|{DIGIT}|\.|-|_|:) NAME ({LETTER}|_|:)({NAME_CHAR})* SPACE [ \t\r\n]+ QUOTED_LITERAL (\"[^\"]*\")|(\'[^\']*\') SYSTEM_LITERAL {QUOTED_LITERAL} PUBID_LITERAL {QUOTED_LITERAL} EXTERNAL_ID ("SYSTEM"{SPACE}{SYSTEM_LITERAL}|"PUBLIC"{SPACE}{PUBID_LITERAL}{SPACE}{SYSTEM_LITERAL}) XML_DECLARATION "" DOCTYPE_DECLARATION "])*"]")?{SPACE}*">" CDATA_SECTION "])*"]]>" PROCESSING_INSN "" ENTITY_REF (\&{NAME};) CHAR_REF ((\&#[0-9]+;)|(\&#x[0-9a-fA-F]+;)) REFERENCE ({ENTITY_REF}|{CHAR_REF}) ATT_VALUE ((\"([^<\&\"]|{REFERENCE})*\")|(\'([^<\&\']|{REFERENCE})*\')) ATTRIBUTE {NAME}{SPACE}*"="{SPACE}*{ATT_VALUE} START_TAG "<"{NAME}({SPACE}*{ATTRIBUTE})*{SPACE}*">" END_TAG "" EMPTY_ELEMENT_TAG "<"{NAME}({SPACE}*{ATTRIBUTE})*{SPACE}*"/>" CONTENT [^\<] COMMENT "