diff options
-rw-r--r-- | rpmconstant/AUTHORS | 5 | ||||
-rw-r--r-- | rpmconstant/COPYING | 340 | ||||
-rw-r--r-- | rpmconstant/ChangeLog | 33 | ||||
-rw-r--r-- | rpmconstant/INSTALL | 7 | ||||
-rw-r--r-- | rpmconstant/Makefile.am | 29 | ||||
-rw-r--r-- | rpmconstant/NEWS | 0 | ||||
-rw-r--r-- | rpmconstant/README | 2 | ||||
-rw-r--r-- | rpmconstant/configure.ac | 29 | ||||
-rw-r--r-- | rpmconstant/constant.c | 108 | ||||
-rw-r--r-- | rpmconstant/rpmconstant.c | 191 | ||||
-rw-r--r-- | rpmconstant/rpmconstant.h | 209 | ||||
-rw-r--r-- | rpmconstant/rpmconstant_internal.c | 60 | ||||
-rwxr-xr-x | rpmconstant/rpmh2tbl | 214 |
13 files changed, 1227 insertions, 0 deletions
diff --git a/rpmconstant/AUTHORS b/rpmconstant/AUTHORS new file mode 100644 index 0000000..7dc4431 --- /dev/null +++ b/rpmconstant/AUTHORS @@ -0,0 +1,5 @@ +Olivier Thauvin <nanardon@mandrake.org> + +Thanks to: +- Jeff Johnson (rpm help) +- Guillaume Rousse (autotools help) diff --git a/rpmconstant/COPYING b/rpmconstant/COPYING new file mode 100644 index 0000000..d60c31a --- /dev/null +++ b/rpmconstant/COPYING @@ -0,0 +1,340 @@ + 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. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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. + + <signature of Ty Coon>, 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. diff --git a/rpmconstant/ChangeLog b/rpmconstant/ChangeLog new file mode 100644 index 0000000..7069bd3 --- /dev/null +++ b/rpmconstant/ChangeLog @@ -0,0 +1,33 @@ +------------------------------------------------------------------------ +r29 | nanardon | 2005-10-04 04:29:56 +0200 (mar, 04 oct 2005) | 1 line +Chemins modifiés : + M /rpmconstant/Makefile.am + +- ChangeLog from svn now +------------------------------------------------------------------------ +r28 | nanardon | 2005-10-04 04:19:57 +0200 (mar, 04 oct 2005) | 1 line +Chemins modifiés : + M /rpmconstant/configure.ac + +- fix email adress +------------------------------------------------------------------------ +r1 | nanardon | 2005-07-07 12:14:03 +0200 (jeu, 07 jui 2005) | 2 lines +Chemins modifiés : + A /rpmconstant + A /rpmconstant/AUTHORS + A /rpmconstant/COPYING + A /rpmconstant/ChangeLog + A /rpmconstant/INSTALL + A /rpmconstant/Makefile.am + A /rpmconstant/NEWS + A /rpmconstant/README + A /rpmconstant/configure.ac + A /rpmconstant/constant.c + A /rpmconstant/rpmconstant.c + A /rpmconstant/rpmconstant.h + A /rpmconstant/rpmconstant_internal.c + A /rpmconstant/rpmh2tbl + +- move from mandriva cvs + +------------------------------------------------------------------------ diff --git a/rpmconstant/INSTALL b/rpmconstant/INSTALL new file mode 100644 index 0000000..4eee409 --- /dev/null +++ b/rpmconstant/INSTALL @@ -0,0 +1,7 @@ +# To build + +aclocal +libtoolize --force +autoconf +automake --add-missing + diff --git a/rpmconstant/Makefile.am b/rpmconstant/Makefile.am new file mode 100644 index 0000000..b30d56a --- /dev/null +++ b/rpmconstant/Makefile.am @@ -0,0 +1,29 @@ +# $Id$ + +bin_PROGRAMS = rpmconstant +lib_LTLIBRARIES = librpmconstant.la +librpmconstant_la_LDFLAGS = -version-info 0:0:0 +librpmconstant_la_SOURCES = rpmconstant.c \ + rpmconstant.h \ + rpmconstanttbl.c \ + rpmconstant_internal.c \ + rpmh2tbl + +rpmconstant_SOURCES = constant.c +rpmconstant_LDADD = librpmconstant.la +pkgincdir = $(pkgincludedir) +pkginc_HEADERS = rpmconstant.h + +RPM_INCLUDE_DIR = /usr/include/rpm +BUILT_SOURCES = rpmconstanttbl.c +CLEANFILES = rpmconstanttbl.c + +rpmconstanttbl.c: Makefile.am rpmh2tbl + $(top_srcdir)/rpmh2tbl $(RPM_INCLUDE_DIR)/*.h > $@ + +rpmh2tbl: + +.PHONY: ChangeLog + +ChangeLog: + svn update && svn log --verbose > ChangeLog diff --git a/rpmconstant/NEWS b/rpmconstant/NEWS new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/rpmconstant/NEWS diff --git a/rpmconstant/README b/rpmconstant/README new file mode 100644 index 0000000..e4cc066 --- /dev/null +++ b/rpmconstant/README @@ -0,0 +1,2 @@ +This small libraries find constant in rpm header and provide function to find +value <=> constant name pair. diff --git a/rpmconstant/configure.ac b/rpmconstant/configure.ac new file mode 100644 index 0000000..e59bf9b --- /dev/null +++ b/rpmconstant/configure.ac @@ -0,0 +1,29 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. +# $Id$ + +AC_PREREQ(2.59) +AC_INIT(rpmconstant, 0.1.0, nanardon@zarb.org) +AC_CONFIG_SRCDIR([rpmconstant.c]) +AM_INIT_AUTOMAKE(1.8) + +# Checks for programs. +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_LIBTOOL + +# Checks for libraries. +# FIXME: Replace `main' with a function in `-lpopt': +AC_CHECK_LIB([popt], [poptGetContext]) + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([string.h rpm/rpmlib.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST + +# Checks for library functions. + +AC_OUTPUT(Makefile) + diff --git a/rpmconstant/constant.c b/rpmconstant/constant.c new file mode 100644 index 0000000..e0438aa --- /dev/null +++ b/rpmconstant/constant.c @@ -0,0 +1,108 @@ +/* Nanar <nanardon@mandrake.org> + * $Id$ + */ + +#include <stdio.h> +#include <string.h> +#include "rpmconstant.h" +#include <popt.h> + + + +int main(int argc, const char *argv[]) { + char * context =NULL; + char c; + const char * name; + int val = 0; + int token; + long qmode = 0; + int showprefix; + + poptContext optcon; + +#define QMODE_LIST (1 << 0) +#define QMODE_SET (1 << 1) +#define QMODE_REVERSE (1 << 2) +#define QMODE_SHOWPREFIX (1 << 3) + + struct poptOption optionstable[] = { + { "context", 'c', POPT_ARG_STRING, &context, 1, "Set context of search", "Context" }, + { "list-context", 'l', POPT_BIT_SET, &qmode, QMODE_LIST, "list available table", "List" }, + { "set", 's', POPT_BIT_SET, &qmode, QMODE_SET, "Show the value for all flag", NULL }, + { "reverse", 'r', POPT_BIT_SET, &qmode, QMODE_REVERSE, "Make a reverse query", "Reverse" }, + { "prefix", 'p', POPT_BIT_SET, &qmode, QMODE_SHOWPREFIX, "Show prefix on constant", "Prefix" }, + POPT_AUTOHELP + POPT_TABLEEND + }; + + optcon = poptGetContext(NULL, argc, argv, optionstable, 0); + + while ((c = poptGetNextOpt(optcon)) >= 0) {} + + if (!(qmode & QMODE_LIST) && poptPeekArg(optcon) == NULL) { + poptPrintUsage(optcon, stderr, 0); + exit(1); + } + + if (qmode & QMODE_SHOWPREFIX) + showprefix = PREFIXED_YES; + else + showprefix = PREFIXED_NO; + + if (qmode & QMODE_LIST) { + rpmconst consti = rpmconstNew(); + if (context) { + if (rpmconstInitToContext(consti, context)) { + while (rpmconstNextC(consti)) { + printf("%s: %d\n", rpmconstName(consti, showprefix), rpmconstValue(consti)); + } + } else { + printf("context '%s' not found\n", context); + } + } else { + while (rpmconstNextL(consti)) { + printf("%s\n", rpmconstContext(consti)); + } + } + consti = rpmconstFree(consti); + return 0; + } + while ((name = poptGetArg(optcon)) != NULL) { + if (qmode & QMODE_REVERSE) { + if(sscanf(name, "%d", &token)) { + if (qmode & QMODE_SET) { + printf("%d:", token); + int i = 0; + while ((val = rpmconstantFindMask(context, token, (void *) &name, showprefix))) { + printf(" %s", name); + token &= ~val; + if (++i > 20) return 0; + } + printf("\n"); + } else { + if (rpmconstantFindValue(context, token, (void *) &name, showprefix)) + printf("%d: %s\n", token, name); + else + printf("%d: Not found\n", token); + } + } else { + printf("%s is not a integer value\n", name); + } + } else if(context) { + if (rpmconstantFindName(context, name, &val, 0)) { + if (~qmode & QMODE_SET) { + printf("%s: %d\n", name, val); + val = 0; /* resetting */ + } + } else + printf("%s: Not found\n", name); + } else { + poptPrintUsage(optcon, stderr, 0); + exit(1); + } + } + if (qmode & QMODE_SET && !(qmode & QMODE_REVERSE)) + printf("Value: %d\n", val); + poptFreeContext(optcon); + return 0; +} diff --git a/rpmconstant/rpmconstant.c b/rpmconstant/rpmconstant.c new file mode 100644 index 0000000..910cb5f --- /dev/null +++ b/rpmconstant/rpmconstant.c @@ -0,0 +1,191 @@ +/* Nanar <nanardon@mandrake.org> + * $Id$ + */ + +#include <string.h> +#define RPMCONSTANT_INTERNAL +#include "rpmconstant.h" + +rpmconst rpmconstNew() +{ + rpmconst c = NULL; + c = xcalloc(1, sizeof(*c)); + c->list = NULL; + c->constant = NULL; + return c; +} + +rpmconst rpmconstFree(rpmconst c) +{ + free(c); + return c = NULL; +} + +void rpmconstInitC(rpmconst c) +{ + c->constant = NULL; +} + +int rpmconstNextC(rpmconst c) +{ + if (c->list == NULL) + return 0; + c->constant = c->constant == NULL ? + rpmConstantListC(c->list) : + rpmConstantNext(c->constant); + return c->constant == NULL ? 0 : 1; +} + + +void rpmconstInitL(rpmconst c) +{ + c->list = NULL; + c->constant = NULL; +} + +int rpmconstNextL(rpmconst c) +{ + c->list = c->list == NULL ? + (void *) rpmconstanttype : + rpmConstantListNext(c->list); + c->constant = NULL; + return c->list == NULL ? 0 : 1; +} + +const char * rpmconstContext(rpmconst c) +{ + return rpmConstantListContext(c->list); +} + +const char * rpmconstPrefix(rpmconst c) +{ + return rpmConstantListPrefix(c->list); +} + +const char * rpmconstName(rpmconst c, int stripprefix) +{ + char * name; + int len; + name = rpmConstantName(c->constant); + if (stripprefix && name && rpmConstantListPrefix(c->list)) { + len = strlen(rpmConstantListPrefix(c->list)); + name += len < strlen(name) ? len : 0; + } + return name; +} + +int rpmconstValue(rpmconst c) +{ + return rpmConstantValue(c->constant); +} + +int rpmconstInitToContext(rpmconst c, const char * context) +{ + char * lccontext = strdup(context); + char * ptr; + int rc = 0; + for (ptr = lccontext; *ptr != 0; ptr++) + *ptr = tolower(*ptr); + if (!context) return 0; /* programmer error */ + rpmconstInitL(c); + while (rpmconstNextL(c)) { + if (!strcmp(lccontext, rpmconstContext(c))) { + rc = 1; + break; + } + } + free(lccontext); + return rc; /* not found */ +} + +int rpmconstNameMatch(rpmconst c, const char * name, int prefixed) +{ + char * uc; + int rc = 0; + char * ucname = strdup(name); + + for (uc = ucname; *uc != 0; uc++) + *uc = toupper(*uc); + + if (!prefixed) prefixed = ALLCASE_PREFIX; + if (prefixed & WITH_PREFIX) + if (strcmp(ucname, rpmconstName(c, PREFIXED_YES)) == 0) + rc = 1; + if (!rc && (prefixed & WITHOUT_PREFIX)) + if (strcmp(ucname, rpmconstName(c, PREFIXED_NO)) == 0) + rc = 1; + free(ucname); + return rc; +} + +int rpmconstFindValue(rpmconst c, const int val) +{ + rpmconstInitC(c); + while (rpmconstNextC(c)) { + if (val == rpmconstValue(c)) + return 1; + } + return 0; +} + +int rpmconstFindMask(rpmconst c, const int val) +{ + rpmconstInitC(c); + while (rpmconstNextC(c)) { + if (!rpmconstValue(c)) + continue; + if (rpmconstValue(c) & val) + return 1; + } + return 0; +} + +int rpmconstFindName(rpmconst c, const char * name, int prefixed) +{ + rpmconstInitC(c); + while (rpmconstNextC(c)) { + if (rpmconstNameMatch(c, name, prefixed)) + return 1; + } + return 0; +} + +int rpmconstantFindValue(char * context, const int val, const char **name, int prefixed) +{ + int rc = 0; + rpmconst c = rpmconstNew(); + if (rpmconstInitToContext(c, context)) + if (rpmconstFindValue(c, val)) { + *name = rpmconstName(c, prefixed); + rc = 1; + } + c = rpmconstFree(c); + return rc; +} + +int rpmconstantFindMask(char * context, const int val, const char **name, int prefixed) +{ + int rc = 0; + rpmconst c = rpmconstNew(); + if (rpmconstInitToContext(c, context)) + if (rpmconstFindMask(c, val)) { + *name = rpmconstName(c, prefixed); + rc = rpmconstValue(c); + } + c = rpmconstFree(c); + return rc; +} + +int rpmconstantFindName(char * context, const char * name, int *val, int prefixed) +{ + int rc = 0; + rpmconst c = rpmconstNew(); + if (rpmconstInitToContext(c, context)) { + if (rpmconstFindName(c, name, prefixed)) { + *val |= rpmconstValue(c); + rc = 1; + } + } + c = rpmconstFree(c); + return rc; +} diff --git a/rpmconstant/rpmconstant.h b/rpmconstant/rpmconstant.h new file mode 100644 index 0000000..bc0cfbb --- /dev/null +++ b/rpmconstant/rpmconstant.h @@ -0,0 +1,209 @@ +/* Nanar <nanardon@mandrake.org> + * $Id$ + */ + +#ifndef H_RPMCONSTANT +#define H_RPMCONSTANT + +#ifndef xcalloc +#define xcalloc(n,s) calloc((n),(s)) +#endif + +#define PREFIXED_YES 0 +#define PREFIXED_NO 1 + +#define WITH_PREFIX (1 << 0) +#define WITHOUT_PREFIX (1 << 1) +#define ALLCASE_PREFIX (WITH_PREFIX | WITHOUT_PREFIX) + +/** + * \ingroup rpmconstant + * \file rpmconstant.h + * + */ + +#include <stdio.h> +#include <rpm/header.h> +#include <rpm/rpmio.h> +#include <rpm/rpmdb.h> +#include <rpm/rpmts.h> +#include <rpm/rpmte.h> +#include <rpm/rpmps.h> +#include <rpm/rpmds.h> +#include <rpm/rpmfi.h> +#include <rpm/rpmpgp.h> +#include <rpm/misc.h> +#include <rpm/rpmbuild.h> +#include <rpm/rpmlib.h> + +/** + * A constant pair name/value + */ +typedef /*@abstract@*/ struct rpmconstant_s *rpmconstant; + + +/** + * A constant list set + */ +typedef /*@abstract@*/ struct rpmconstantlist_s * rpmconstantlist; + +typedef struct rpmconst_s * rpmconst; + +#ifdef RPMCONSTANT_INTERNAL + +/** + * A constant pair name/value + */ +struct rpmconstant_s { + const char * name; /*!< Constant name. */ +/*@null@*/ + int value; /*!< Constant value. */ +}; + +/** + * A contantlist entry + */ +struct rpmconstantlist_s { + const rpmconstant constant; /*<! Constant pointer */ +/*@null@*/ + char *context; /*<! Name of the list */ + char *prefix; /*<! Common prefix of constant name */ +/*@null@*/ +}; + +struct rpmconst_s { + rpmconstantlist list; + rpmconstant constant; +}; + +/** + * Pointer to first element of rpmconstantlist. + */ +/*@-redecl@*/ +/*@observer@*/ /*@unchecked@*/ +extern const struct rpmconstantlist_s * rpmconstanttype; +/*@=redecl@*/ + +/** + * Return name from contant item. + * + * @param c constant item + * @return pointer to name from item + */ +const char * rpmConstantName(rpmconstant c) + /*@*/; + +/** + * Return value from constant item. + * + * @param c constant item + * @return value from current item + */ +int rpmConstantValue(rpmconstant c) + /*@*/; + +/** + * Return next constant item from constant list (or NULL at end of list). + * + * @param c current constant item + * @return next constant item + */ +/*@null@*/ +rpmconstant rpmConstantNext(rpmconstant c) + /*@*/; + + +/** + * Get a pointer to first rpmconstantlist item + * + * @return first constantlist item + */ +rpmconstantlist rpmGetConstantList() + /*@*/; + +/** + * Return next constantlist item from list (or NULL at the end of list). + * + * @param cl current constantlist item + * @return next constantlist item + */ +/*@null@*/ +rpmconstantlist rpmConstantListNext(rpmconstantlist cl) + /*@*/; + +/** + * Return constantlist item corresponding to context + * + * @param context ptr to constext + * @return constant list item matching context + */ +rpmconstantlist rpmGetConstantListFromContext(const char * context) + /*@*/; + +/** + * Return a pointer to first constant item from constantlist. + * + * @param cl constantlist item + * @retval first constant item from list + */ +rpmconstant rpmConstantListC(rpmconstantlist cl) + /*@*/; + +/** + * Return the common prefix of constant name. + * + * @param cl constantlist item + * @return pointer to prefix string (or NULL is not availlable) + */ +/*@null@*/ +const char * rpmConstantListPrefix (rpmconstantlist cl) + /*@*/; + +/** + * Return context name from constantlist item + * + * @param cl constantlist item + * @return pointer to context name + */ +const char * rpmConstantListContext (rpmconstantlist cl) + /*@*/; + +#endif + +rpmconst rpmconstNew(); + +rpmconst rpmconstFree(rpmconst c); + +void rpmconstInitC(rpmconst c); + +int rpmconstNextC(rpmconst c); + +void rpmconstInitL(rpmconst c); + +int rpmconstNextL(rpmconst c); + +const char * rpmconstContext(rpmconst c); + +const char * rpmconstPrefix(rpmconst c); + +const char * rpmconstName(rpmconst c, int stripprefix); + +int rpmconstValue(rpmconst c); + +int rpmconstInitToContext(rpmconst c, const char * context); + +int rpmconstNameMatch(rpmconst c, const char * name, int prefixed); + +int rpmconstFindValue(rpmconst c, const int val); + +int rpmconstFindMask(rpmconst c, const int val); + +int rpmconstFindName(rpmconst c, const char * name, int prefixed); + +int rpmconstantFindValue(char * context, const int val, const char **name, int prefixed); + +int rpmconstantFindMask(char * context, const int val, const char **name, int prefixed); + +int rpmconstantFindName(char * context, const char * name, int *val, int prefixed); + +#endif /* H_RPMCONSTANT */ diff --git a/rpmconstant/rpmconstant_internal.c b/rpmconstant/rpmconstant_internal.c new file mode 100644 index 0000000..db3e902 --- /dev/null +++ b/rpmconstant/rpmconstant_internal.c @@ -0,0 +1,60 @@ +/* Nanar <nanardon@mandrake.org> + * $Id$ + */ + +#include <string.h> +#define RPMCONSTANT_INTERNAL +#include "rpmconstant.h" + +const char * rpmConstantName(rpmconstant c) +{ + return c->name; +} + +int rpmConstantValue(rpmconstant c) +{ + return c->value; +} + +rpmconstant rpmConstantNext(rpmconstant c) +{ + return (c + 1)->name ? c + 1 : NULL; +} + +/**/ + +rpmconstantlist rpmGetConstantList() +{ + return (void *) rpmconstanttype; +} + +rpmconstantlist rpmConstantListNext(rpmconstantlist cl) +{ + return (cl + 1)->constant ? cl + 1 : NULL; +} + +rpmconstantlist rpmGetConstantListFromContext(const char * context) +{ + rpmconstantlist cl; + for (cl = rpmGetConstantList(); cl; cl=rpmConstantListNext(cl)) { + if (context && strcmp(context, rpmConstantListContext(cl)) == 0) + return cl; + } + return NULL; +} + +const char * rpmConstantListPrefix (rpmconstantlist cl) +{ + return cl->prefix; +} + +const char * rpmConstantListContext (rpmconstantlist cl) +{ + return cl->context; +} + +rpmconstant rpmConstantListC(rpmconstantlist cl) +{ + return cl->constant; +} + diff --git a/rpmconstant/rpmh2tbl b/rpmconstant/rpmh2tbl new file mode 100755 index 0000000..91d715c --- /dev/null +++ b/rpmconstant/rpmh2tbl @@ -0,0 +1,214 @@ +#!/usr/bin/perl + +##- Nanar <nanardon@mandrake.org> +##- +##- 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, 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. +# +# $Id$ + +use strict; +use warnings; + +use Getopt::Long; + +my @availlabletables; + +# Binding we want +# In this file we'll found +# FILE.h => +# Constant matching the REGEXP goes in this table. +# 'REGEXP' => table, + +my %file_const = ( + 'rpmts.h' => { + '^_?(RPMVSF_[\w_]+)' => 'rpmvsflags', + '^(RPMTRANS_TYPE_[\w_]+)' => 'rpmtsType', + '^(RPMTS_OP_[\w_]+)' => 'rpmtsOpX', + }, + 'rpmlib.h' => { + '^(RPMDBI_[\w_]+)' => 'rpmdbi', + '^_?(RPMSENSE_[\w_]+)' => 'rpmsenseflags', + '^(RPMTAG_[\w_]+)' => 'rpmTag', + '^(RPMRC_[\w_]+)' => 'rpmRC', + '^(RPMFILE_[^(STATE_)][\w_]+)' => 'rpmfileAttrs', + '^(RPMFILE_STATE_[\w_]+)' => 'rpmfileState', + '^(RPM_MACHTABLE_[\w_]+)' => 'rpm_machtable', + '^(RPMPROB_FILTER_[\w_]+)' => 'rpmprobFilterFlags', + '^(FA_[\w_]+)' => 'fileAction', + '^(PIPE|CDEV|XDIR|BDEV|REG|LINK|SOCK)$' => 'fileTypes', + '^(RPMTRANS_FLAG_[\w_]+)' => 'rpmtransFlags', + '^(INSTALL_[\w_]+)' => 'rpmInstallInterfaceFlags', + '^(UNINSTALL_[\w_]+)' => 'rpmEraseInterfaceFlags', + '^(RPMSIGTAG_[\w_]+)' => 'rpmtagSignature', + }, + 'rpmps.h' => { + '^(RPMPROB_[\w_]+)' => 'rpmProblemType', + }, + 'rpmcli.h' => { + '^(RPMSIGN_[\w_]+)' => 'rpmSignFlags', + '^(VERIFY_[\w_]+)' => 'rpmVerifyFlags', + }, + 'rpmdb.h' => { + '^(RPMMIRE_[\w_]+)' => 'rpmMireMode', + }, + 'header.h' => { + '^(HEADER_MAGIC_[\w_]+)' => 'hMagic', + '^(RPM_[\w]+)_TYPE$' => 'rpmTagType', + }, + 'rpmbuild.h' => { + '^(RPMBUILD_[\w_]+)' => 'rpmBuildFlags', + '^(PART_[\w_]+)' => 'rpmParseState', + }, + 'rpmerr.h' => { + '^(RPMERR_[\w_]+)' => 'rpmerrCode', + }, + 'rpmmacro.h' => { + '^(RMIL_[\w_]+)' => 'rpmMacrosContext', + }, + 'rpmte.h' => { + '^(TR_[\w_]+)' => 'rpmElementType', + }, + 'rpmlog.h' => { + '^(RPMLOG_(?!PRI$|MAKEPRI$|FAC$|MASK$|UPTO$)[\w_]+)' => 'rpmlog', + }, + 'rpmmessage.h' => { + '^(RPMCALLBACK_[\w_]+)' => 'rpmCallbackType', + '^(RPMMESS_[\w_]+)' => 'rpmmess', + }, +); + +my %tableprefix = ( + rpmmess => 'RPMMESS_', + rpmCallbackType => 'RPMCALLBACK_', + rpmlog => 'RPMLOG_', + rpmdbi => 'RPMDBI_', + rpmElementType => 'TR_', + rpmMacrosContext => 'RMIL_', + rpmerrCode => 'RPMERR_', + rpmParseState => 'PART_', + rpmBuildFlags => 'RPMBUILD_', + rpmTagType => 'RPM_', + hMagic => '', + rpmMireMode => 'RPMMIRE_', + rpmsenseflags => 'RPMSENSE_', + rpmtsTransFlag => 'RPMVSF_', + rpmTag => 'RPMTAG_', + rpmtsType => 'RPMTRANS_TYPE_', + rpmtsOpX => 'RPMTS_OP_', + rpmRC => 'RPMRC_', + rpmfileState => 'RPMFILE_STATE_', + rpmfileState => 'RPMFILE_', + rpm_machtable => 'RPM_MACHTABLE_', + rpmprobFilterFlags => 'RPMPROB_FILTER_', + fileAction => 'FA_', + fileTypes => '', + rpmtransFlags => 'RPMTRANS_FLAG_', + rpmInstallInterfaceFlags => 'INSTALL_', + rpmEraseInterfaceFlags => 'UNINSTALL_', + rpmtagSignature => 'RPMSIGTAG_', + rpmProblemType => 'RPMPROB_', + rpmSignFlags => 'RPMSIGN_', + rpmVerifyFlags => 'VERIFY_', + rpmvsflags => 'RPMVSF_', +); + + +my $ch = *STDOUT; + +sub parseconst { + my ($header) = @_; + my ($hbasename) = $header =~ m#(?:.*/)(.*)$#; + + my $hconstant = $file_const{$hbasename} or return; + open(my $hheader, "<", $header) or die "Can't open $header\n"; + + my %constants_found; + my $i; + + my $line = <$hheader>; + $line =~ /^\s*#\s*ifndef\s+(\S+)/; + my $headerdef = $1 if($1); + + while ($line = <$hheader>) { + $line =~ s#^\s*/\*[^\*]*\*/##; + my ($w, $c) = $line =~ m!(?:#\s*define\s*)?([\w_]+)[^(/\*)]*(/\*.*\*/)?!; + defined($w) or next; + foreach my $regexp (keys %{$hconstant}) { + if ($w =~ /$regexp/) { + $constants_found{$hconstant->{$regexp}}{$w}{n} ||= ++$i; + $constants_found{$hconstant->{$regexp}}{$w}{c} ||= $c; + $constants_found{$hconstant->{$regexp}}{$w}{s} ||= $1; + } + } + } + + close($hheader); + + while (my ($tbl, $const) = each (%constants_found)) { + $tableprefix{$tbl} ||= ""; + print $ch <<EOF; + +/* From $hbasename + * prefix tag: $tableprefix{$tbl} + * table: $tbl */ +EOF + printf $ch "static const struct rpmconstant_s %sctbl[] = {\n", + $tbl; + print $ch "#ifdef $headerdef\n" if ($headerdef); + foreach my $c (sort { $const->{$a}{n} <=> $const->{$b}{n} } keys %$const) { + printf $ch "\t{ \"%s\", %s }, %s\n", + uc($const->{$c}{s} || $c), $c, $const->{$c}{c} || ""; + } + print $ch "#endif /* $headerdef */\n" if ($headerdef); + printf $ch "\t{ %s, %s } /* NULL terminated (%s) */\n", "NULL", "0", $tbl; + print $ch "};\n"; + printf $ch "const struct rpmconstant_s * %sctable = %sctbl;\n\n", $tbl, $tbl; + + push @availlabletables, $tbl; + } +} + +printf $ch <<EOF +/* File automatically generate by $0 + * Olivier Thauvin <thauvin at aerov.jussieu.fr> + * Parsed files: + * %s + */ + +#define RPMCONSTANT_INTERNAL +#include "rpmconstant.h" + +EOF +, join("\n * ", @ARGV); + +GetOptions( +); + +foreach (@ARGV) { + parseconst($_); +} + +print $ch "static const struct rpmconstantlist_s rpmconstanttp[] = {\n"; +foreach (sort(@availlabletables)) { + printf $ch "\t{ %s, %s, %s },\n", + '(void *)'.$_."ctbl", + '"' . lc($_) . '"', + $tableprefix{$_} ? "\"$tableprefix{$_}\"" : "NULL"; +} +printf $ch "\t{ %s, %s, %s } /* NULL terminated */\n", "(void *) NULL", "NULL", "NULL"; +print $ch "};\n"; +printf $ch "const struct rpmconstantlist_s * rpmconstanttype = rpmconstanttp;\n"; +print $ch "const int rpmconstanttypesize = sizeof(rpmconstanttp) / sizeof(rpmconstanttp[0]) -1;\n"; + |