From: Bruno Haible Date: Sat, 12 Dec 2009 11:22:07 +0000 (+0100) Subject: Untabify. X-Git-Tag: v0.18~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4031b5252bc3c539b5c041c2e30fd7fb88382d9;p=thirdparty%2Fgettext.git Untabify. --- diff --git a/AUTHORS b/AUTHORS index 6fb0716fd..4e80e5d94 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,19 +3,19 @@ Authors of GNU gettext. The following contributions warranted legal paper exchanges with the Free Software Foundation. Also see files ChangeLog and THANKS. -GETTEXT Ulrich Drepper +GETTEXT Ulrich Drepper Assigns program. -GETTEXT Peter Miller +GETTEXT Peter Miller Assigns past and future changes. -GETTEXT Bruno Haible +GETTEXT Bruno Haible Assigns past and future changes. -GETTEXT Karl Eichwalder +GETTEXT Karl Eichwalder Assigns past and future changes. -GETTEXT SuSE Linux AG 2002-07-03 +GETTEXT SuSE Linux AG 2002-07-03 Disclaimer for Karl Eichwalder, in the past and for the next 5 years. -GETTEXT Michele Cicciotti alias KJK::Hyperion +GETTEXT Michele Cicciotti alias KJK::Hyperion Assigns past and future changes. diff --git a/ChangeLog b/ChangeLog index 073c42987..a60d6c7e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-12-12 Bruno Haible + + * AUTHORS: Untabify. + * README: Untabify. + * THANKS: Untabify. + 2009-12-01 Bruno Haible * m4/init-package-version.m4 (gl_INIT_PACKAGE): Set AC_PACKAGE_NAME. diff --git a/README b/README index 9ab83925b..0f72a435f 100644 --- a/README +++ b/README @@ -26,7 +26,7 @@ the other possibility does. Please share your results with us. If this package compiles ok for you future GNU release will likely also not fail, at least for reasons found in message handling. Send comments and bug reports to - bug-gnu-gettext@gnu.org + bug-gnu-gettext@gnu.org The goal of this library was to give a unique interface to message @@ -49,7 +49,7 @@ The configure script provides two non-standard options. These will also be available in other packages if they use the functionality of GNU gettext. Use - --disable-nls + --disable-nls if you absolutely don't want to have messages handling code. You will always get the original messages (mostly English). You could consider @@ -62,19 +62,19 @@ specified while configuring. Of course they must be available but the intersection of these two sets are computed automatically. You could once and for all define in your profile/cshrc the variable LINGUAS: -(Bourne Shell) LINGUAS="de fr nl"; export LINGUAS +(Bourne Shell) LINGUAS="de fr nl"; export LINGUAS -(C Shell) setenv LINGUAS "de fr nl" +(C Shell) setenv LINGUAS "de fr nl" or specify it directly while configuring - env LINGUAS="de fr nl" ./configure + env LINGUAS="de fr nl" ./configure Consult the manual for more information on language names. The second configure option is - --with-included-gettext + --with-included-gettext This forces to use the GNU implementation of the message handling library regardless what the local C library provides. This possibility is @@ -84,12 +84,12 @@ have all the features the included libintl has. Other files you might look into: -`ABOUT-NLS' - current state of the GNU internationalization effort -`COPYING' - copying conditions +`ABOUT-NLS' - current state of the GNU internationalization effort +`COPYING' - copying conditions `DEPENDENCIES' - list of prerequisite packages, to be installed before this one -`INSTALL' - general compilation and installation rules -`NEWS' - major changes in the current version -`THANKS' - list of contributors +`INSTALL' - general compilation and installation rules +`NEWS' - major changes in the current version +`THANKS' - list of contributors Some points you might be interested in before installing the package: @@ -112,7 +112,7 @@ Some points you might be interested in before installing the package: implemented in the X Window System. Especially the alias data base file can be shared. Normally this file is found at something like - /usr/lib/X11/locale/locale.alias + /usr/lib/X11/locale/locale.alias If you have the X Window System installed try to find this file and specify the path at the make run: diff --git a/THANKS b/THANKS index 68e773c81..e7a6ed011 100644 --- a/THANKS +++ b/THANKS @@ -6,7 +6,7 @@ Therefore a lot of people participated in the process of creating this software. Written in April-June 1995 by -Ulrich Drepper drepper@ipd.info.uni-karlsruhe.de +Ulrich Drepper drepper@ipd.info.uni-karlsruhe.de Special thanks to François Pinard , who did a major part of the testing, provided the Emacs PO mode, and wrote major @@ -24,311 +24,311 @@ Gora Mohanty wrote the tutorial. Thanks to all of the following for their valuable hints/fixes/discussions/contributions: -Aaron Stone aaron@serendipity.cx -Aaron Williams aaron_williams@net.com -Abel Cheung abelcheung@gmail.com -Adam Heath doogie@debian.org -Adrian Bunk bunk@fs.tum.de -Akim Demaille akim@epita.fr -Alain Bench messtic@oreka.com -Alain Guibert derogaton+bggt@oreka.com, alguibert@free.fr -Albert Chin-A-Young china@thewrittenword.com -Alexander V. Lukyanov lav@yars.free.net -Alexander Turbov AVTurbov@gwise.eltech.ru -Alexandre Duret-Lutz aduret@enst.fr -Alfred M. Szmidt ams@kemisten.nu -Alfredo alfredio@ciaoweb.it -Amos Batto amosbatto@yahoo.com -Andreas Buening andreas.buening@nexgo.de -Andreas Fischer a.fischer@asentics.de -Andreas Schwab schwab@issan.informatik.uni-dortmund.de -Andrew Suffield asuffield@debian.org -Andrew V. Samoilov kai@cmail.ru -Andrew Walrond andrew@walrond.org -Andrew Zabolotny zap@cobra.ru -Andries Brouwer andries.brouwer@cwi.nl -Andriy Gapon avg@icyb.net.ua -Arkadiusz Miśkiewicz arekm@pld-linux.org -Arpad Biro biro_arpad@yahoo.com -Artem Vakhitov temcat@mail.ru -Arto C. Nirkko anirkko@insel.ch -Asgeir Frimannsson asgeirf@redhat.com -A. Sopicki a.sopicki@gmx.de -? atras-ch@mail.msiu.ru -Bang Jun Young bangjy@nownuri.nowcom.co.kr -Barry A. Warsaw barry@zope.com -Behdad Esfahbod behdad@cs.toronto.edu -Ben Elliston bje@redhat.com -Benoît Sibaud benoit.sibaud@rd.francetelecom.com -Bernard Massot bmassot@free.fr -Bernhard Herzog bernhard@users.sourceforge.net -Bethor bethor@gmx.li -Bill Perry wmperry@aventail.com -Bjoern Voigt bjoern@cs.tu-berlin.de -Bob Rossi bob_rossi@cox.net -Bram Moolenaar bram@moolenaar.net -Bruno Haible haible@ma2s2.mathematik.uni-karlsruhe.de -Carlo Wood carlo@alinoe.com -Carlos Perelló Marín carlos@gnome.org -Cary Farah cfarah@jjkeller.com -Charles Wilson cwilson@ece.gatech.edu -Chris Pickett chris.pickett@mail.mcgill.ca -Chris Zubrzycki beren@mac.com -Christian Casteyde casteyde.christian@free.fr -Christian Neumair chris@gnome-de.org -Christian von Roques roques@pond.sub.org -Christoph Thielecke u15119@hs-harz.de -Christopher Seip chris.seip@hp.com -Chuck Berg chuckhberg@yahoo.com -Chusslove Illich (Часлав Илић) caslav.ilic@gmx.net -Claudio Fontana claudio@gnu.org -Clytie Siddall clytie@riverland.net.au -Colin Marquardt colin@marquardt-home.de -Colin Watson cjwatson@debian.org -Crispin Flowerday cflowerday@zeus.com -Dalibor Topic robilad@kaffe.org -Daniel Burrows dburrows@debian.org -Daniel Leidert daniel.leidert@wgdd.de -Daniel Schepler schepler@math.berkeley.edu -Danilo Å egan (Данило Шеган) danilo@gnome.org -Dave Patton dpatton@confluence.org -David Faure faure@kde.org -David Fraser davidf@sjsoft.com -Denis Barbier barbier@linuxfr.org -Denis Excoffier Denis.Excoffier@free.fr -Deniz Akkus deniz@arayan.com -Dennis Bjorklund db@zigo.dhs.org -Dennis Schridde devurandom@gmx.net -Derek Clegg derek_clegg@next.com -Derek Robert Price derek@ximbiot.com -Dwayne Bailey dwayne@obsidian.co.za -Earnie Boyd earnie_boyd@yahoo.com -Ed Avis avised@kbcfp.com -Eddy Petrişor eddy.petrisor@gmail.com -Edmund Grimley Evans edmundo@rano.org -Egmont Koblinger egmont@uhulinux.hu -Eli Zaretskii eliz@is.elta.co.il -Enrico Scholz enrico.scholz@informatik.tu-chemnitz.de -Enrique Melero Gómez justine@iprolink.ch -Eric Backus ericb@lsid.hp.com -Eric Blake ebb9@byu.net -Eric Botcazou ebotcazou@libertysurf.fr -Erik Sigra sigra@home.se -Farzaneh Sarafraz farzaneh@farsiweb.info -Fatih Demir kabalak@gtranslator.org -Felipe Contreras al593181@mail.mty.itesm.mx -Felix Natter f.natter@ndh.net -Finlay Dobbie finlay.dobbie@gmail.com -Francesco Potortì pot@fly.cnuce.cnr.it -Frank Donahoe fdonahoe@wilkes1.wilkes.edu -Frédéric L. W. Meunier 0@pervalidus.tk -Gabor Kelemen kelemeng@gnome.hu -Gabriele Stilli superenzima@libero.it -Gaëtan Frenoy gaetan@frenoy.net -Gary V. Vaughan gary@gnu.org -Gerald Combs gerald@ethereal.com -Glenn Popelka gpp@mail.gpopelka.com -Golubev I. N. gin@mo.msk.ru -Greg McGary gkm@magilla.cichlid.com -Göran Uddeborg gvran@uddeborg.pp.se -Hagen Fritsch itooktheredpill@gmx.de -Haibin Zhang dragzhb@yahoo.com.cn -Han Boetes han@mijncomputer.nl -Hans Ulrich Niedermann debian@n-dimensional.de -Henry Nelson netb@yuba.ne.jp -H. J. Lu hjl@lucon.org -Hrvoje Niksic hniksic@srce.hr -Igor Brezac igor@ipass.net -I. Thomas Cundiff tcundiff@eclipse.net -Jacob (=Jouk) Jansen joukj@hrem.stm.tudelft.nl -Jakub Bogusz qboosh@pld-linux.org -Jakub Jelinek jj@sunsite.ms.mff.cuni.cz -James A Baker jabaker@mac.com -James Henstridge james@daa.com.au -James Youngman jay@gnu.org -Jan Djärv jan.djarv@mbox200.swipnet.se -Jan-Marek Glogowski glogow@stud.fbi.fh-darmstadt.de -Jan Schneider jan@horde.org -Jason Keltz jas@cs.yorku.ca -Javier Fernández-Sanguino Peña jfs@computer.org -Jeff Bonggren jbon@cfl.rr.com -Jeff Rizzo riz@netbsd.org -Jens A. Tkotz jens@peino.de -Jens Petersen petersen@redhat.com -Jim Meyering meyering@na-net.ornl.gov -Jochen Hein jochen@jochen.org -Joel Reicher joel@panacea.null.org -Jörg Schilling schilling@fokus.fraunhofer.de -Joey Hess joeyh@debian.org -Jonas Koch Bentzen jonas@understroem.dk -Joosep-Georg Järvemaa joosep-georg.jarvemaa_4898@eesti.ee -Jorn Baayen jbaayen@dds.nl -Josep Puigdemont baldrick@terra.es -Joshua R. Poulson jrp@plaza.ds.adp.com -Jouko Orava joorava@pcu.helsinki.fi -Jozef Riha jose1711@gmail.com -Juan Manuel Guerrero st001906@hrz1.hrz.tu-darmstadt.de -Jürgen A. Erhard jae+debian@jerhard.org -Julien Chiron julien.chiron@univ.u-3mrs.fr -Jun Sawataishi jsawa@attglobal.net -Kalle Niemitalo tosi@ees2.oulu.fi -Karl Berry kb@cs.umb.edu -Karl Chen quarl@hkn.eecs.berkeley.edu -Karl Eichwalder ke@suse.de -Kaveh R. Ghazi ghazi@caip.rutgers.edu -Kenichi Handa handa@etl.go.jp -Ken Y. Clark kclark@logsoft.com -Kevin Ryde user42@zip.com.au -Kingpin mthurn@copper.dulles.tasc.com -Kiyotaka Sakai ksakai@isr.co.jp -Kouichi Hashikawa z01a7ksy@cs.ecip.tohoku.ac.jp -Larry Schwimmer rosebud@cyclone.stanford.edu -Lars Hecking lhecking@nmrc.ie -Laurent Bourbeau bourbeau@progiciels-bpi.ca -Len Makin len@hpc.csiro.au -Leonard den Ottolander leonard@den.ottolander.nl -Leonardo Fontenelle leo.fontenelle@gmail.com -Liu Garfield jackliu9999@hotmail.com -Lorenzo Gil Sanchez lgs@sicem.biz -Luke Schierer lschiere@rackspace.com -Maciej W. Rozycki macro@ds2.pg.gda.pl -Mads Martin Joergensen mmj@suse.de -Marc Prior MarcPrior@compuserve.com -Marcel Telka marcel@telka.sk -Marcus Daniels marcus@sysc.pdx.edu -Marcus Meissner meissner@suse.de -Marin Purgar pmc@asgard.hr -Marius Schamschula mschamschula@gmail.com -Mark A. Wicks mwicks@kettering.edu -Mark D. Baushke mdb@cvshome.org -Mark Detrick Mark.Detrick@mcdata.com -Mark Eichin eichin@thok.org -Mark Junker mjscod@gmx.de -Martin MokrejÅ¡ mmokrejs@natur.cuni.cz -Martin Pitt mpitt@debian.org -Martin Quinson martin.quinson@ens-lyon.fr -Martin v. Löwis martin@loewis.home.cs.tu-berlin.de -Matt Dreezer matthew.dreezer@edl.uk.eds.com -Matthew McGillis matthew@jenika.com -Matthias Clasen mclasen@redhat.com -Mattias Ellert mattias.ellert@tsl.uu.se -Matthias Kiefer kiefer@kde.org -Max de Mendizabal max@acer.com.mx -Michael C. Toren mct@toren.net -Michael Opdenacker m-opdenacker@ti.com -Michael Schloh von Bennewitz michael.schloh@cw.com -Michael Stather michaelstather@nuzi.de -Michal Černoevič Michal.Cernoevic@pvt.cz -Michel Robitaille robitail@iro.umontreal.ca -Michelle Konzack linux4michelle@freenet.de -Mike Frysinger vapier@gentoo.org -Miroslaw Dobrzanski-Neumann mne@mosaic-ag.com -? mus1876@gmx.info -Nelson H. F. Beebe beebe@math.utah.edu -Nick Clifton nickc@redhat.com -Nicolas François nicolas.francois@centraliens.net -Niki Waibel niki.waibel@newlogic.com -Nils Magnus Larsgard nmlarsgaard@atmel.no -Nils Naumann naumann@unileoben.ac.at -Nina Kusnetsova nina@ns.kinetics.nsc.ru -Noah Friedman friedman@splode.com -Noah Slater nslater@gmail.com -Olly Betts olly@survex.com -O'Riva oriva@earthlink.net -Owen Taylor otaylor@redhat.com -Pablo Saratxaga pablo@mandrakesoft.com -Paolo Bonzini bonzini@gnu.org -Paul D. Smith psmith@gnu.org -Paul Eggert eggert@twinsun.com -Paul Jarc prj@po.cwru.edu -Paul Martinolich martinol@nrlssc.navy.mil -Pavel Roskin proski@gnu.org -Pekka Järveläinen pj@csc.fi -Pepa cerna.zelva@seznam.cz -Perry Rapp prapp@erols.com, lifelines_3_0_18@hotmail.com -Perry Smith pedz@easesoftware.com -Peter Breitenlohner peb@mppmu.mpg.de -Pierre pierre42d@9online.fr -Philipp Thomas pthomas@suse.de -Primoz Peterlin primoz.peterlin@biofiz.mf.uni-lj.si -Rafał Maszkowski rzm@icm.edu.pl -Ralf Corsepius rc040203@freenet.de -Ralf Menzel menzel@ls6.cs.uni-dortmund.de -Ralf Wildenhues Ralf.Wildenhues@gmx.de -Raphaël Zhou xzhou@tlmcom.fr -Recai Oktaş roktas@omu.edu.tr -Reinout van Schouwen reinout@cs.vu.nl -Rhys Weatherley rweather@zip.com.au -Richard Lloyd richard.lloyd@connectinternetsolutions.com -Richard S. Blake blakers@presence-group.com -Richard Stallman rms@gnu.org -Rob Landley rob@landley.net -Rob Leslie rob@mars.org -Robert Millan rmh@aybabtu.com -Robert Vock RobertVock@gmx.de -Roberto Bagnara bagnara@cs.unipr.it -Rodrigo Stulzer Lopes rodrigo@conectiva.com.br -Roger Leigh rl117@york.ac.uk -Roland McGrath roland@gnu.ai.mit.edu -Ron Lee ron@debian.org -Roozbeh Pournader roozbeh@sharif.edu -Ross Golder ross@golder.org -Ryan Anderson ryan@autoweb.net -Ryan Schmidt gettext-2007b@ryandesign.com -Sakai Kiyotaka ksakai@netwk.ntt-at.co.jp -Sam Hocevar sam@zoy.org -Sam Steingold sds@gnu.org -Santiago Vila Doncel sanvila@unex.es -Sebastian Günther sguenther@gmx.de -Sergey Poznyakoff gray@mirddin.farlep.net -Sergio Talens-Oliag sto@debian.org -Simon Josefsson jas@extundo.com -Simon Watts swatts@ngms.eu.com -Simos Xenitellis simos74@gmx.net -Stanislav Brabec sbrabec@suse.cz -Stanislav Visnovsky visnovsky@nenya.ms.mff.cuni.cz -Stefan Hundhammer sh@suse.de -Stefan Kost kost@imn.htwk-leipzig.de -Stefan Kowski stefan.kowski@parks-informatik.de -Stefan Nordhausen nordhaus@informatik.hu-berlin.de -Steffen Macke sdteffen@gmail.com -Stepan Kasal kasal@math.cas.cz -Stephan Kulow coolo@kde.org -Stephane Matamontero stephane.matamontero@gemodek.de -Stephen Cartwright sgcartwr@ucalgary.ca -Stephen Gildea gildea@stop.mail-abuse.org -Steven Edwards Steven_Ed4153@yahoo.com -Svante Seleborg svante@axantum.com -Sven Joachim sven_joachim@web.de -Sven Utcke utcke@informatik.uni-hamburg.de -Sylvain Beucler beuc@gnu.org -Thomas E. Dickey dickey@clark.net -Thomas Vander Stichele thomas@apestaart.org -Thorsten Kukuk kukuk@suse.de -Thorsten Maerz torte@netztorte.de -Tim Mooney mooney@dogbert.cc.ndsu.nodak.edu -Tim Van Holder tim.van.holder@pandora.be -Tom Tromey tromey@cygnus.com -Tommy Johansson tommy@kanalen.org -Tor Lillqvist tml@iki.fi -Trond Eivind Glomsrød teg@redhat.com -Uwe Ohse uwe@tirka.gun.de -Vaclav Haisman V.Haisman@sh.cvut.cz -Valery Beaud valery.beaud@art.alcatel.fr -Vera Mickael vera.mickael@free.fr -Veronica Loell info@nakawe.se -Vincent Torri vtorri@univ-evry.fr -Volodymyr M. Lisivka lvm@mystery.lviv.net -Wang Jian lark@linux.net.cn -Warren L Dodge warrend@mdhost.cse.tek.com -Werner Koch wk@gnupg.org -Werner Lemberg wl@gnu.org -Wesley J. Landaker wjl@icecavern.net -William J Poser wjposer@ldc.upenn.edu -Wojciech Polak polak@gnu.org -Xiong Jiang jxiong@offtopic.org -Yann Dirson ydirson@altern.org -Yves Codet ycodet@club-internet.fr +Aaron Stone aaron@serendipity.cx +Aaron Williams aaron_williams@net.com +Abel Cheung abelcheung@gmail.com +Adam Heath doogie@debian.org +Adrian Bunk bunk@fs.tum.de +Akim Demaille akim@epita.fr +Alain Bench messtic@oreka.com +Alain Guibert derogaton+bggt@oreka.com, alguibert@free.fr +Albert Chin-A-Young china@thewrittenword.com +Alexander V. Lukyanov lav@yars.free.net +Alexander Turbov AVTurbov@gwise.eltech.ru +Alexandre Duret-Lutz aduret@enst.fr +Alfred M. Szmidt ams@kemisten.nu +Alfredo alfredio@ciaoweb.it +Amos Batto amosbatto@yahoo.com +Andreas Buening andreas.buening@nexgo.de +Andreas Fischer a.fischer@asentics.de +Andreas Schwab schwab@issan.informatik.uni-dortmund.de +Andrew Suffield asuffield@debian.org +Andrew V. Samoilov kai@cmail.ru +Andrew Walrond andrew@walrond.org +Andrew Zabolotny zap@cobra.ru +Andries Brouwer andries.brouwer@cwi.nl +Andriy Gapon avg@icyb.net.ua +Arkadiusz Miśkiewicz arekm@pld-linux.org +Arpad Biro biro_arpad@yahoo.com +Artem Vakhitov temcat@mail.ru +Arto C. Nirkko anirkko@insel.ch +Asgeir Frimannsson asgeirf@redhat.com +A. Sopicki a.sopicki@gmx.de +? atras-ch@mail.msiu.ru +Bang Jun Young bangjy@nownuri.nowcom.co.kr +Barry A. Warsaw barry@zope.com +Behdad Esfahbod behdad@cs.toronto.edu +Ben Elliston bje@redhat.com +Benoît Sibaud benoit.sibaud@rd.francetelecom.com +Bernard Massot bmassot@free.fr +Bernhard Herzog bernhard@users.sourceforge.net +Bethor bethor@gmx.li +Bill Perry wmperry@aventail.com +Bjoern Voigt bjoern@cs.tu-berlin.de +Bob Rossi bob_rossi@cox.net +Bram Moolenaar bram@moolenaar.net +Bruno Haible haible@ma2s2.mathematik.uni-karlsruhe.de +Carlo Wood carlo@alinoe.com +Carlos Perelló Marín carlos@gnome.org +Cary Farah cfarah@jjkeller.com +Charles Wilson cwilson@ece.gatech.edu +Chris Pickett chris.pickett@mail.mcgill.ca +Chris Zubrzycki beren@mac.com +Christian Casteyde casteyde.christian@free.fr +Christian Neumair chris@gnome-de.org +Christian von Roques roques@pond.sub.org +Christoph Thielecke u15119@hs-harz.de +Christopher Seip chris.seip@hp.com +Chuck Berg chuckhberg@yahoo.com +Chusslove Illich (Часлав Илић) caslav.ilic@gmx.net +Claudio Fontana claudio@gnu.org +Clytie Siddall clytie@riverland.net.au +Colin Marquardt colin@marquardt-home.de +Colin Watson cjwatson@debian.org +Crispin Flowerday cflowerday@zeus.com +Dalibor Topic robilad@kaffe.org +Daniel Burrows dburrows@debian.org +Daniel Leidert daniel.leidert@wgdd.de +Daniel Schepler schepler@math.berkeley.edu +Danilo Å egan (Данило Шеган) danilo@gnome.org +Dave Patton dpatton@confluence.org +David Faure faure@kde.org +David Fraser davidf@sjsoft.com +Denis Barbier barbier@linuxfr.org +Denis Excoffier Denis.Excoffier@free.fr +Deniz Akkus deniz@arayan.com +Dennis Bjorklund db@zigo.dhs.org +Dennis Schridde devurandom@gmx.net +Derek Clegg derek_clegg@next.com +Derek Robert Price derek@ximbiot.com +Dwayne Bailey dwayne@obsidian.co.za +Earnie Boyd earnie_boyd@yahoo.com +Ed Avis avised@kbcfp.com +Eddy Petrişor eddy.petrisor@gmail.com +Edmund Grimley Evans edmundo@rano.org +Egmont Koblinger egmont@uhulinux.hu +Eli Zaretskii eliz@is.elta.co.il +Enrico Scholz enrico.scholz@informatik.tu-chemnitz.de +Enrique Melero Gómez justine@iprolink.ch +Eric Backus ericb@lsid.hp.com +Eric Blake ebb9@byu.net +Eric Botcazou ebotcazou@libertysurf.fr +Erik Sigra sigra@home.se +Farzaneh Sarafraz farzaneh@farsiweb.info +Fatih Demir kabalak@gtranslator.org +Felipe Contreras al593181@mail.mty.itesm.mx +Felix Natter f.natter@ndh.net +Finlay Dobbie finlay.dobbie@gmail.com +Francesco Potortì pot@fly.cnuce.cnr.it +Frank Donahoe fdonahoe@wilkes1.wilkes.edu +Frédéric L. W. Meunier 0@pervalidus.tk +Gabor Kelemen kelemeng@gnome.hu +Gabriele Stilli superenzima@libero.it +Gaëtan Frenoy gaetan@frenoy.net +Gary V. Vaughan gary@gnu.org +Gerald Combs gerald@ethereal.com +Glenn Popelka gpp@mail.gpopelka.com +Golubev I. N. gin@mo.msk.ru +Greg McGary gkm@magilla.cichlid.com +Göran Uddeborg gvran@uddeborg.pp.se +Hagen Fritsch itooktheredpill@gmx.de +Haibin Zhang dragzhb@yahoo.com.cn +Han Boetes han@mijncomputer.nl +Hans Ulrich Niedermann debian@n-dimensional.de +Henry Nelson netb@yuba.ne.jp +H. J. Lu hjl@lucon.org +Hrvoje Niksic hniksic@srce.hr +Igor Brezac igor@ipass.net +I. Thomas Cundiff tcundiff@eclipse.net +Jacob (=Jouk) Jansen joukj@hrem.stm.tudelft.nl +Jakub Bogusz qboosh@pld-linux.org +Jakub Jelinek jj@sunsite.ms.mff.cuni.cz +James A Baker jabaker@mac.com +James Henstridge james@daa.com.au +James Youngman jay@gnu.org +Jan Djärv jan.djarv@mbox200.swipnet.se +Jan-Marek Glogowski glogow@stud.fbi.fh-darmstadt.de +Jan Schneider jan@horde.org +Jason Keltz jas@cs.yorku.ca +Javier Fernández-Sanguino Peña jfs@computer.org +Jeff Bonggren jbon@cfl.rr.com +Jeff Rizzo riz@netbsd.org +Jens A. Tkotz jens@peino.de +Jens Petersen petersen@redhat.com +Jim Meyering meyering@na-net.ornl.gov +Jochen Hein jochen@jochen.org +Joel Reicher joel@panacea.null.org +Jörg Schilling schilling@fokus.fraunhofer.de +Joey Hess joeyh@debian.org +Jonas Koch Bentzen jonas@understroem.dk +Joosep-Georg Järvemaa joosep-georg.jarvemaa_4898@eesti.ee +Jorn Baayen jbaayen@dds.nl +Josep Puigdemont baldrick@terra.es +Joshua R. Poulson jrp@plaza.ds.adp.com +Jouko Orava joorava@pcu.helsinki.fi +Jozef Riha jose1711@gmail.com +Juan Manuel Guerrero st001906@hrz1.hrz.tu-darmstadt.de +Jürgen A. Erhard jae+debian@jerhard.org +Julien Chiron julien.chiron@univ.u-3mrs.fr +Jun Sawataishi jsawa@attglobal.net +Kalle Niemitalo tosi@ees2.oulu.fi +Karl Berry kb@cs.umb.edu +Karl Chen quarl@hkn.eecs.berkeley.edu +Karl Eichwalder ke@suse.de +Kaveh R. Ghazi ghazi@caip.rutgers.edu +Kenichi Handa handa@etl.go.jp +Ken Y. Clark kclark@logsoft.com +Kevin Ryde user42@zip.com.au +Kingpin mthurn@copper.dulles.tasc.com +Kiyotaka Sakai ksakai@isr.co.jp +Kouichi Hashikawa z01a7ksy@cs.ecip.tohoku.ac.jp +Larry Schwimmer rosebud@cyclone.stanford.edu +Lars Hecking lhecking@nmrc.ie +Laurent Bourbeau bourbeau@progiciels-bpi.ca +Len Makin len@hpc.csiro.au +Leonard den Ottolander leonard@den.ottolander.nl +Leonardo Fontenelle leo.fontenelle@gmail.com +Liu Garfield jackliu9999@hotmail.com +Lorenzo Gil Sanchez lgs@sicem.biz +Luke Schierer lschiere@rackspace.com +Maciej W. Rozycki macro@ds2.pg.gda.pl +Mads Martin Joergensen mmj@suse.de +Marc Prior MarcPrior@compuserve.com +Marcel Telka marcel@telka.sk +Marcus Daniels marcus@sysc.pdx.edu +Marcus Meissner meissner@suse.de +Marin Purgar pmc@asgard.hr +Marius Schamschula mschamschula@gmail.com +Mark A. Wicks mwicks@kettering.edu +Mark D. Baushke mdb@cvshome.org +Mark Detrick Mark.Detrick@mcdata.com +Mark Eichin eichin@thok.org +Mark Junker mjscod@gmx.de +Martin MokrejÅ¡ mmokrejs@natur.cuni.cz +Martin Pitt mpitt@debian.org +Martin Quinson martin.quinson@ens-lyon.fr +Martin v. Löwis martin@loewis.home.cs.tu-berlin.de +Matt Dreezer matthew.dreezer@edl.uk.eds.com +Matthew McGillis matthew@jenika.com +Matthias Clasen mclasen@redhat.com +Mattias Ellert mattias.ellert@tsl.uu.se +Matthias Kiefer kiefer@kde.org +Max de Mendizabal max@acer.com.mx +Michael C. Toren mct@toren.net +Michael Opdenacker m-opdenacker@ti.com +Michael Schloh von Bennewitz michael.schloh@cw.com +Michael Stather michaelstather@nuzi.de +Michal Černoevič Michal.Cernoevic@pvt.cz +Michel Robitaille robitail@iro.umontreal.ca +Michelle Konzack linux4michelle@freenet.de +Mike Frysinger vapier@gentoo.org +Miroslaw Dobrzanski-Neumann mne@mosaic-ag.com +? mus1876@gmx.info +Nelson H. F. Beebe beebe@math.utah.edu +Nick Clifton nickc@redhat.com +Nicolas François nicolas.francois@centraliens.net +Niki Waibel niki.waibel@newlogic.com +Nils Magnus Larsgard nmlarsgaard@atmel.no +Nils Naumann naumann@unileoben.ac.at +Nina Kusnetsova nina@ns.kinetics.nsc.ru +Noah Friedman friedman@splode.com +Noah Slater nslater@gmail.com +Olly Betts olly@survex.com +O'Riva oriva@earthlink.net +Owen Taylor otaylor@redhat.com +Pablo Saratxaga pablo@mandrakesoft.com +Paolo Bonzini bonzini@gnu.org +Paul D. Smith psmith@gnu.org +Paul Eggert eggert@twinsun.com +Paul Jarc prj@po.cwru.edu +Paul Martinolich martinol@nrlssc.navy.mil +Pavel Roskin proski@gnu.org +Pekka Järveläinen pj@csc.fi +Pepa cerna.zelva@seznam.cz +Perry Rapp prapp@erols.com, lifelines_3_0_18@hotmail.com +Perry Smith pedz@easesoftware.com +Peter Breitenlohner peb@mppmu.mpg.de +Pierre pierre42d@9online.fr +Philipp Thomas pthomas@suse.de +Primoz Peterlin primoz.peterlin@biofiz.mf.uni-lj.si +Rafał Maszkowski rzm@icm.edu.pl +Ralf Corsepius rc040203@freenet.de +Ralf Menzel menzel@ls6.cs.uni-dortmund.de +Ralf Wildenhues Ralf.Wildenhues@gmx.de +Raphaël Zhou xzhou@tlmcom.fr +Recai Oktaş roktas@omu.edu.tr +Reinout van Schouwen reinout@cs.vu.nl +Rhys Weatherley rweather@zip.com.au +Richard Lloyd richard.lloyd@connectinternetsolutions.com +Richard S. Blake blakers@presence-group.com +Richard Stallman rms@gnu.org +Rob Landley rob@landley.net +Rob Leslie rob@mars.org +Robert Millan rmh@aybabtu.com +Robert Vock RobertVock@gmx.de +Roberto Bagnara bagnara@cs.unipr.it +Rodrigo Stulzer Lopes rodrigo@conectiva.com.br +Roger Leigh rl117@york.ac.uk +Roland McGrath roland@gnu.ai.mit.edu +Ron Lee ron@debian.org +Roozbeh Pournader roozbeh@sharif.edu +Ross Golder ross@golder.org +Ryan Anderson ryan@autoweb.net +Ryan Schmidt gettext-2007b@ryandesign.com +Sakai Kiyotaka ksakai@netwk.ntt-at.co.jp +Sam Hocevar sam@zoy.org +Sam Steingold sds@gnu.org +Santiago Vila Doncel sanvila@unex.es +Sebastian Günther sguenther@gmx.de +Sergey Poznyakoff gray@mirddin.farlep.net +Sergio Talens-Oliag sto@debian.org +Simon Josefsson jas@extundo.com +Simon Watts swatts@ngms.eu.com +Simos Xenitellis simos74@gmx.net +Stanislav Brabec sbrabec@suse.cz +Stanislav Visnovsky visnovsky@nenya.ms.mff.cuni.cz +Stefan Hundhammer sh@suse.de +Stefan Kost kost@imn.htwk-leipzig.de +Stefan Kowski stefan.kowski@parks-informatik.de +Stefan Nordhausen nordhaus@informatik.hu-berlin.de +Steffen Macke sdteffen@gmail.com +Stepan Kasal kasal@math.cas.cz +Stephan Kulow coolo@kde.org +Stephane Matamontero stephane.matamontero@gemodek.de +Stephen Cartwright sgcartwr@ucalgary.ca +Stephen Gildea gildea@stop.mail-abuse.org +Steven Edwards Steven_Ed4153@yahoo.com +Svante Seleborg svante@axantum.com +Sven Joachim sven_joachim@web.de +Sven Utcke utcke@informatik.uni-hamburg.de +Sylvain Beucler beuc@gnu.org +Thomas E. Dickey dickey@clark.net +Thomas Vander Stichele thomas@apestaart.org +Thorsten Kukuk kukuk@suse.de +Thorsten Maerz torte@netztorte.de +Tim Mooney mooney@dogbert.cc.ndsu.nodak.edu +Tim Van Holder tim.van.holder@pandora.be +Tom Tromey tromey@cygnus.com +Tommy Johansson tommy@kanalen.org +Tor Lillqvist tml@iki.fi +Trond Eivind Glomsrød teg@redhat.com +Uwe Ohse uwe@tirka.gun.de +Vaclav Haisman V.Haisman@sh.cvut.cz +Valery Beaud valery.beaud@art.alcatel.fr +Vera Mickael vera.mickael@free.fr +Veronica Loell info@nakawe.se +Vincent Torri vtorri@univ-evry.fr +Volodymyr M. Lisivka lvm@mystery.lviv.net +Wang Jian lark@linux.net.cn +Warren L Dodge warrend@mdhost.cse.tek.com +Werner Koch wk@gnupg.org +Werner Lemberg wl@gnu.org +Wesley J. Landaker wjl@icecavern.net +William J Poser wjposer@ldc.upenn.edu +Wojciech Polak polak@gnu.org +Xiong Jiang jxiong@offtopic.org +Yann Dirson ydirson@altern.org +Yves Codet ycodet@club-internet.fr Thanks to all members of the translation teams for the different diff --git a/autoconf-lib-link/m4/ChangeLog b/autoconf-lib-link/m4/ChangeLog index 8ba013af5..705f8c959 100644 --- a/autoconf-lib-link/m4/ChangeLog +++ b/autoconf-lib-link/m4/ChangeLog @@ -1,3 +1,7 @@ +2009-12-10 Bruno Haible + + * *.m4: Untabify. + 2009-06-24 Bruno Haible * lib-link.m4 (AC_LIB_HAVE_LINKFLAGS): Fix description of diff --git a/autoconf-lib-link/m4/lib-ld.m4 b/autoconf-lib-link/m4/lib-ld.m4 index e4863f2c9..4b4db0798 100644 --- a/autoconf-lib-link/m4/lib-ld.m4 +++ b/autoconf-lib-link/m4/lib-ld.m4 @@ -59,7 +59,7 @@ if test "$GCC" = yes; then # Canonicalize the path of ld ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'` while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do - ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` + ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` done test -z "$LD" && LD="$ac_prog" ;; @@ -89,9 +89,9 @@ AC_CACHE_VAL([acl_cv_path_LD], # Break only if it was the GNU/non-GNU ld that we prefer. case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in *GNU* | *'with BFD'*) - test "$with_gnu_ld" != no && break ;; + test "$with_gnu_ld" != no && break ;; *) - test "$with_gnu_ld" != yes && break ;; + test "$with_gnu_ld" != yes && break ;; esac fi done diff --git a/djgpp/djpwd.h b/djgpp/djpwd.h index 78596e53c..e87c24d31 100644 --- a/djgpp/djpwd.h +++ b/djgpp/djpwd.h @@ -24,23 +24,23 @@ __DJ_uid_t #define __DJ_uid_t struct passwd { - char * pw_name; /* Username. */ - uid_t pw_uid; /* User ID. */ - gid_t pw_gid; /* Group ID. */ - char * pw_dir; /* Home directory. */ - char * pw_shell; /* Shell program. */ - char * pw_gecos; /* Real name. */ - char * pw_passwd; /* Password. */ + char * pw_name; /* Username. */ + uid_t pw_uid; /* User ID. */ + gid_t pw_gid; /* Group ID. */ + char * pw_dir; /* Home directory. */ + char * pw_shell; /* Shell program. */ + char * pw_gecos; /* Real name. */ + char * pw_passwd; /* Password. */ }; -struct passwd * getpwuid(uid_t _uid); -struct passwd * getpwnam(const char *_name); +struct passwd * getpwuid(uid_t _uid); +struct passwd * getpwnam(const char *_name); #ifndef _POSIX_SOURCE -struct passwd *getpwent(void); -void setpwent(void); -void endpwent(void); +struct passwd *getpwent(void); +void setpwent(void); +void endpwent(void); #endif /* !_POSIX_SOURCE */ #endif /* !__STRICT_ANSI__ */ diff --git a/gettext-runtime/intl/ChangeLog b/gettext-runtime/intl/ChangeLog index 6659fe3df..e7448acb7 100644 --- a/gettext-runtime/intl/ChangeLog +++ b/gettext-runtime/intl/ChangeLog @@ -1,3 +1,28 @@ +2009-12-12 Bruno Haible + + * intl-compat.c: Untabify. + * intl-exports.c: Untabify. + * langprefs.c: Untabify. + * libgnuintl.h.in: Untabify. + * localcharset.c: Untabify. + * localename.c: Untabify. + * lock.c: Untabify. + * log.c: Untabify. + * os2compat.h: Untabify. + * printf-args.c: Untabify. + * printf-args.h: Untabify. + * printf-parse.c: Untabify. + * printf-parse.h: Untabify. + * printf.c: Untabify. + * relocatable.c: Untabify. + * relocatable.h: Untabify. + * threadlib.c: Untabify. + * tsearch.c: Untabify. + * tsearch.h: Untabify. + * vasnprintf.c: Untabify. + * vasnwprintf.h: Untabify. + * wprintf-parse.h: Untabify. + 2009-12-11 Bruno Haible * config.charset: Untabify. diff --git a/gettext-runtime/intl/intl-compat.c b/gettext-runtime/intl/intl-compat.c index 9b9ecbb64..43d45174e 100644 --- a/gettext-runtime/intl/intl-compat.c +++ b/gettext-runtime/intl/intl-compat.c @@ -93,7 +93,7 @@ ngettext (const char *msgid1, const char *msgid2, unsigned long int n) DLL_EXPORTED char * dngettext (const char *domainname, - const char *msgid1, const char *msgid2, unsigned long int n) + const char *msgid1, const char *msgid2, unsigned long int n) { return libintl_dngettext (domainname, msgid1, msgid2, n); } @@ -102,8 +102,8 @@ dngettext (const char *domainname, DLL_EXPORTED char * dcngettext (const char *domainname, - const char *msgid1, const char *msgid2, unsigned long int n, - int category) + const char *msgid1, const char *msgid2, unsigned long int n, + int category) { return libintl_dcngettext (domainname, msgid1, msgid2, n, category); } diff --git a/gettext-runtime/intl/intl-exports.c b/gettext-runtime/intl/intl-exports.c index 717658994..9e0a13e8f 100644 --- a/gettext-runtime/intl/intl-exports.c +++ b/gettext-runtime/intl/intl-exports.c @@ -23,14 +23,14 @@ /* Ensure that the variable x is exported from the library, and that a pseudo-variable IMP(x) is available. */ #define VARIABLE(x) \ - /* Export x without redefining x. This code was found by compiling a \ - snippet: \ - extern __declspec(dllexport) int x; int x = 42; */ \ - asm (".section .drectve\n"); \ - asm (".ascii \" -export:" #x ",data\"\n"); \ - asm (".data\n"); \ - /* Allocate a pseudo-variable IMP(x). */ \ - extern int x; \ + /* Export x without redefining x. This code was found by compiling a \ + snippet: \ + extern __declspec(dllexport) int x; int x = 42; */ \ + asm (".section .drectve\n"); \ + asm (".ascii \" -export:" #x ",data\"\n"); \ + asm (".data\n"); \ + /* Allocate a pseudo-variable IMP(x). */ \ + extern int x; \ void * IMP(x) = &x; VARIABLE(libintl_version) diff --git a/gettext-runtime/intl/langprefs.c b/gettext-runtime/intl/langprefs.c index 847a94aff..de66ad8cc 100644 --- a/gettext-runtime/intl/langprefs.c +++ b/gettext-runtime/intl/langprefs.c @@ -59,9 +59,9 @@ static const char * _nl_language_preferences_win32_mui (HMODULE kernel32) { /* DWORD GetUserPreferredUILanguages (ULONG dwFlags, - PULONG pulNumLanguages, - PWSTR pwszLanguagesBuffer, - PULONG pcchLanguagesBuffer); */ + PULONG pulNumLanguages, + PWSTR pwszLanguagesBuffer, + PULONG pcchLanguagesBuffer); */ typedef DWORD (WINAPI *GetUserPreferredUILanguages_func) (ULONG, PULONG, PWSTR, PULONG); GetUserPreferredUILanguages_func p_GetUserPreferredUILanguages; @@ -76,71 +76,71 @@ _nl_language_preferences_win32_mui (HMODULE kernel32) bufsize = 0; ret = p_GetUserPreferredUILanguages (MUI_LANGUAGE_NAME, - &num_languages, - NULL, &bufsize); + &num_languages, + NULL, &bufsize); if (ret == 0 - && GetLastError () == STATUS_BUFFER_OVERFLOW - && bufsize > 0) - { - WCHAR *buffer = (WCHAR *) malloc (bufsize * sizeof (WCHAR)); - if (buffer != NULL) - { - ret = p_GetUserPreferredUILanguages (MUI_LANGUAGE_NAME, - &num_languages, - buffer, &bufsize); - if (ret) - { - /* Convert the list from NUL-delimited WCHAR[] Win32 locale - names to colon-delimited char[] Unix locale names. - We assume that all these locale names are in ASCII, - nonempty and contain no colons. */ - char *languages = - (char *) malloc (bufsize + num_languages * 10 + 1); - if (languages != NULL) - { - const WCHAR *p = buffer; - char *q = languages; - ULONG i; - for (i = 0; i < num_languages; i++) - { - char *q1; - char *q2; - - q1 = q; - if (i > 0) - *q++ = ':'; - q2 = q; - for (; *p != (WCHAR)'\0'; p++) - { - if ((unsigned char) *p != *p || *p == ':') - { - /* A non-ASCII character or a colon inside - the Win32 locale name! Punt. */ - q = q1; - break; - } - *q++ = (unsigned char) *p; - } - if (q == q1) - /* An unexpected Win32 locale name occurred. */ - break; - *q = '\0'; - _nl_locale_name_canonicalize (q2); - q = q2 + strlen (q2); - p++; - } - *q = '\0'; - if (q > languages) - { - free (buffer); - return languages; - } - free (languages); - } - } - free (buffer); - } - } + && GetLastError () == STATUS_BUFFER_OVERFLOW + && bufsize > 0) + { + WCHAR *buffer = (WCHAR *) malloc (bufsize * sizeof (WCHAR)); + if (buffer != NULL) + { + ret = p_GetUserPreferredUILanguages (MUI_LANGUAGE_NAME, + &num_languages, + buffer, &bufsize); + if (ret) + { + /* Convert the list from NUL-delimited WCHAR[] Win32 locale + names to colon-delimited char[] Unix locale names. + We assume that all these locale names are in ASCII, + nonempty and contain no colons. */ + char *languages = + (char *) malloc (bufsize + num_languages * 10 + 1); + if (languages != NULL) + { + const WCHAR *p = buffer; + char *q = languages; + ULONG i; + for (i = 0; i < num_languages; i++) + { + char *q1; + char *q2; + + q1 = q; + if (i > 0) + *q++ = ':'; + q2 = q; + for (; *p != (WCHAR)'\0'; p++) + { + if ((unsigned char) *p != *p || *p == ':') + { + /* A non-ASCII character or a colon inside + the Win32 locale name! Punt. */ + q = q1; + break; + } + *q++ = (unsigned char) *p; + } + if (q == q1) + /* An unexpected Win32 locale name occurred. */ + break; + *q = '\0'; + _nl_locale_name_canonicalize (q2); + q = q2 + strlen (q2); + p++; + } + *q = '\0'; + if (q > languages) + { + free (buffer); + return languages; + } + free (languages); + } + } + free (buffer); + } + } } return NULL; } @@ -168,8 +168,8 @@ _nl_language_preferences_win32_95 () HKEY desktop_resource_locale_key; if (RegOpenKeyExA (HKEY_CURRENT_USER, - "Control Panel\\Desktop\\ResourceLocale", - 0, KEY_QUERY_VALUE, &desktop_resource_locale_key) + "Control Panel\\Desktop\\ResourceLocale", + 0, KEY_QUERY_VALUE, &desktop_resource_locale_key) == NO_ERROR) { DWORD type; @@ -178,29 +178,29 @@ _nl_language_preferences_win32_95 () DWORD ret; ret = RegQueryValueExA (desktop_resource_locale_key, NULL, NULL, - &type, data, &data_size); + &type, data, &data_size); RegCloseKey (desktop_resource_locale_key); if (ret == NO_ERROR) { - /* We expect a string, at most 8 bytes long, that parses as a - hexadecimal number. */ - if (type == REG_SZ - && data_size <= sizeof (data) - && (data_size < sizeof (data) - || data[sizeof (data) - 1] == '\0')) - { - LCID lcid; - char *endp; - /* Ensure it's NUL terminated. */ - if (data_size < sizeof (data)) - data[data_size] = '\0'; - /* Parse it as a hexadecimal number. */ - lcid = strtoul (data, &endp, 16); - if (endp > data && *endp == '\0') - return _nl_locale_name_from_win32_LCID (lcid); - } - } + /* We expect a string, at most 8 bytes long, that parses as a + hexadecimal number. */ + if (type == REG_SZ + && data_size <= sizeof (data) + && (data_size < sizeof (data) + || data[sizeof (data) - 1] == '\0')) + { + LCID lcid; + char *endp; + /* Ensure it's NUL terminated. */ + if (data_size < sizeof (data)) + data[data_size] = '\0'; + /* Parse it as a hexadecimal number. */ + lcid = strtoul (data, &endp, 16); + if (endp > data && *endp == '\0') + return _nl_locale_name_from_win32_LCID (lcid); + } + } } return NULL; } @@ -219,7 +219,7 @@ _nl_language_preferences_win32_system (HMODULE kernel32) /* Ignore the warning on mingw here. mingw has a wrong definition of the last parameter type of ENUMRESLANGPROC. */ EnumResourceLanguages (kernel32, RT_VERSION, MAKEINTRESOURCE (1), - ret_first_language, (LONG_PTR)&languages); + ret_first_language, (LONG_PTR)&languages); return languages; } @@ -243,75 +243,75 @@ _nl_language_preferences_default (void) if (!cache_initialized) { - CFTypeRef preferences = - CFPreferencesCopyAppValue (CFSTR ("AppleLanguages"), - kCFPreferencesCurrentApplication); - if (preferences != NULL - && CFGetTypeID (preferences) == CFArrayGetTypeID ()) - { - CFArrayRef prefArray = (CFArrayRef)preferences; - int n = CFArrayGetCount (prefArray); - char buf[256]; - size_t size = 0; - int i; - - for (i = 0; i < n; i++) - { - CFTypeRef element = CFArrayGetValueAtIndex (prefArray, i); - if (element != NULL - && CFGetTypeID (element) == CFStringGetTypeID () - && CFStringGetCString ((CFStringRef)element, - buf, sizeof (buf), - kCFStringEncodingASCII)) - { - _nl_locale_name_canonicalize (buf); - size += strlen (buf) + 1; - /* Most GNU programs use msgids in English and don't ship - an en.mo message catalog. Therefore when we see "en" - in the preferences list, arrange for gettext() to - return the msgid, and ignore all further elements of - the preferences list. */ - if (strcmp (buf, "en") == 0) - break; - } - else - break; - } - if (size > 0) - { - char *languages = (char *) malloc (size); - - if (languages != NULL) - { - char *p = languages; - - for (i = 0; i < n; i++) - { - CFTypeRef element = - CFArrayGetValueAtIndex (prefArray, i); - if (element != NULL - && CFGetTypeID (element) == CFStringGetTypeID () - && CFStringGetCString ((CFStringRef)element, - buf, sizeof (buf), - kCFStringEncodingASCII)) - { - _nl_locale_name_canonicalize (buf); - strcpy (p, buf); - p += strlen (buf); - *p++ = ':'; - if (strcmp (buf, "en") == 0) - break; - } - else - break; - } - *--p = '\0'; - - cached_languages = languages; - } - } - } - cache_initialized = 1; + CFTypeRef preferences = + CFPreferencesCopyAppValue (CFSTR ("AppleLanguages"), + kCFPreferencesCurrentApplication); + if (preferences != NULL + && CFGetTypeID (preferences) == CFArrayGetTypeID ()) + { + CFArrayRef prefArray = (CFArrayRef)preferences; + int n = CFArrayGetCount (prefArray); + char buf[256]; + size_t size = 0; + int i; + + for (i = 0; i < n; i++) + { + CFTypeRef element = CFArrayGetValueAtIndex (prefArray, i); + if (element != NULL + && CFGetTypeID (element) == CFStringGetTypeID () + && CFStringGetCString ((CFStringRef)element, + buf, sizeof (buf), + kCFStringEncodingASCII)) + { + _nl_locale_name_canonicalize (buf); + size += strlen (buf) + 1; + /* Most GNU programs use msgids in English and don't ship + an en.mo message catalog. Therefore when we see "en" + in the preferences list, arrange for gettext() to + return the msgid, and ignore all further elements of + the preferences list. */ + if (strcmp (buf, "en") == 0) + break; + } + else + break; + } + if (size > 0) + { + char *languages = (char *) malloc (size); + + if (languages != NULL) + { + char *p = languages; + + for (i = 0; i < n; i++) + { + CFTypeRef element = + CFArrayGetValueAtIndex (prefArray, i); + if (element != NULL + && CFGetTypeID (element) == CFStringGetTypeID () + && CFStringGetCString ((CFStringRef)element, + buf, sizeof (buf), + kCFStringEncodingASCII)) + { + _nl_locale_name_canonicalize (buf); + strcpy (p, buf); + p += strlen (buf); + *p++ = ':'; + if (strcmp (buf, "en") == 0) + break; + } + else + break; + } + *--p = '\0'; + + cached_languages = languages; + } + } + } + cache_initialized = 1; } if (cached_languages != NULL) return cached_languages; @@ -328,23 +328,23 @@ _nl_language_preferences_default (void) set, for the time being, since the new code is not well tested. */ if (!cache_initialized && getenv ("GETTEXT_MUI") != NULL) { - const char *languages = NULL; - HMODULE kernel32 = GetModuleHandle ("kernel32"); + const char *languages = NULL; + HMODULE kernel32 = GetModuleHandle ("kernel32"); - if (kernel32 != NULL) - languages = _nl_language_preferences_win32_mui (kernel32); + if (kernel32 != NULL) + languages = _nl_language_preferences_win32_mui (kernel32); - if (languages == NULL && kernel32 != NULL) - languages = _nl_language_preferences_win32_ME (kernel32); + if (languages == NULL && kernel32 != NULL) + languages = _nl_language_preferences_win32_ME (kernel32); - if (languages == NULL) - languages = _nl_language_preferences_win32_95 (); + if (languages == NULL) + languages = _nl_language_preferences_win32_95 (); - if (languages == NULL && kernel32 != NULL) - languages = _nl_language_preferences_win32_system (kernel32); + if (languages == NULL && kernel32 != NULL) + languages = _nl_language_preferences_win32_system (kernel32); - cached_languages = languages; - cache_initialized = 1; + cached_languages = languages; + cache_initialized = 1; } if (cached_languages != NULL) return cached_languages; diff --git a/gettext-runtime/intl/libgnuintl.h.in b/gettext-runtime/intl/libgnuintl.h.in index 2ecff884b..06ea95c75 100644 --- a/gettext-runtime/intl/libgnuintl.h.in +++ b/gettext-runtime/intl/libgnuintl.h.in @@ -17,7 +17,7 @@ USA. */ #ifndef _LIBINTL_H -#define _LIBINTL_H 1 +#define _LIBINTL_H 1 #include @@ -157,10 +157,10 @@ extern char *dgettext (const char *__domainname, const char *__msgid) locale. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dcgettext (const char *__domainname, const char *__msgid, - int __category) + int __category) _INTL_MAY_RETURN_STRING_ARG (2); static inline char *dcgettext (const char *__domainname, const char *__msgid, - int __category) + int __category) { return libintl_dcgettext (__domainname, __msgid, __category); } @@ -169,7 +169,7 @@ static inline char *dcgettext (const char *__domainname, const char *__msgid, # define dcgettext libintl_dcgettext #endif extern char *dcgettext (const char *__domainname, const char *__msgid, - int __category) + int __category) _INTL_ASM (libintl_dcgettext) _INTL_MAY_RETURN_STRING_ARG (2); #endif @@ -179,10 +179,10 @@ extern char *dcgettext (const char *__domainname, const char *__msgid, number N. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2, - unsigned long int __n) + unsigned long int __n) _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); static inline char *ngettext (const char *__msgid1, const char *__msgid2, - unsigned long int __n) + unsigned long int __n) { return libintl_ngettext (__msgid1, __msgid2, __n); } @@ -191,7 +191,7 @@ static inline char *ngettext (const char *__msgid1, const char *__msgid2, # define ngettext libintl_ngettext #endif extern char *ngettext (const char *__msgid1, const char *__msgid2, - unsigned long int __n) + unsigned long int __n) _INTL_ASM (libintl_ngettext) _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); #endif @@ -200,10 +200,10 @@ extern char *ngettext (const char *__msgid1, const char *__msgid2, number N. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dngettext (const char *__domainname, const char *__msgid1, - const char *__msgid2, unsigned long int __n) + const char *__msgid2, unsigned long int __n) _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); static inline char *dngettext (const char *__domainname, const char *__msgid1, - const char *__msgid2, unsigned long int __n) + const char *__msgid2, unsigned long int __n) { return libintl_dngettext (__domainname, __msgid1, __msgid2, __n); } @@ -212,8 +212,8 @@ static inline char *dngettext (const char *__domainname, const char *__msgid1, # define dngettext libintl_dngettext #endif extern char *dngettext (const char *__domainname, - const char *__msgid1, const char *__msgid2, - unsigned long int __n) + const char *__msgid1, const char *__msgid2, + unsigned long int __n) _INTL_ASM (libintl_dngettext) _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); #endif @@ -222,12 +222,12 @@ extern char *dngettext (const char *__domainname, number N. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dcngettext (const char *__domainname, - const char *__msgid1, const char *__msgid2, - unsigned long int __n, int __category) + const char *__msgid1, const char *__msgid2, + unsigned long int __n, int __category) _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); static inline char *dcngettext (const char *__domainname, - const char *__msgid1, const char *__msgid2, - unsigned long int __n, int __category) + const char *__msgid1, const char *__msgid2, + unsigned long int __n, int __category) { return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category); } @@ -236,8 +236,8 @@ static inline char *dcngettext (const char *__domainname, # define dcngettext libintl_dcngettext #endif extern char *dcngettext (const char *__domainname, - const char *__msgid1, const char *__msgid2, - unsigned long int __n, int __category) + const char *__msgid1, const char *__msgid2, + unsigned long int __n, int __category) _INTL_ASM (libintl_dcngettext) _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); #endif @@ -266,9 +266,9 @@ extern char *textdomain (const char *__domainname) in DIRNAME rather than in the system locale data base. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_bindtextdomain (const char *__domainname, - const char *__dirname); + const char *__dirname); static inline char *bindtextdomain (const char *__domainname, - const char *__dirname) + const char *__dirname) { return libintl_bindtextdomain (__domainname, __dirname); } @@ -284,9 +284,9 @@ extern char *bindtextdomain (const char *__domainname, const char *__dirname) DOMAINNAME message catalog will be returned. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_bind_textdomain_codeset (const char *__domainname, - const char *__codeset); + const char *__codeset); static inline char *bind_textdomain_codeset (const char *__domainname, - const char *__codeset) + const char *__codeset) { return libintl_bind_textdomain_codeset (__domainname, __codeset); } @@ -295,7 +295,7 @@ static inline char *bind_textdomain_codeset (const char *__domainname, # define bind_textdomain_codeset libintl_bind_textdomain_codeset #endif extern char *bind_textdomain_codeset (const char *__domainname, - const char *__codeset) + const char *__codeset) _INTL_ASM (libintl_bind_textdomain_codeset); #endif @@ -429,7 +429,7 @@ extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list); #define libintl_set_relocation_prefix libintl_set_relocation_prefix extern void libintl_set_relocation_prefix (const char *orig_prefix, - const char *curr_prefix); + const char *curr_prefix); #ifdef __cplusplus diff --git a/gettext-runtime/intl/localcharset.c b/gettext-runtime/intl/localcharset.c index e80896798..5f13f84e0 100644 --- a/gettext-runtime/intl/localcharset.c +++ b/gettext-runtime/intl/localcharset.c @@ -130,214 +130,214 @@ get_charset_aliases (void) char *file_name; /* Make it possible to override the charset.alias location. This is - necessary for running the testsuite before "make install". */ + necessary for running the testsuite before "make install". */ dir = getenv ("CHARSETALIASDIR"); if (dir == NULL || dir[0] == '\0') - dir = relocate (LIBDIR); + dir = relocate (LIBDIR); /* Concatenate dir and base into freshly allocated file_name. */ { - size_t dir_len = strlen (dir); - size_t base_len = strlen (base); - int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); - file_name = (char *) malloc (dir_len + add_slash + base_len + 1); - if (file_name != NULL) - { - memcpy (file_name, dir, dir_len); - if (add_slash) - file_name[dir_len] = DIRECTORY_SEPARATOR; - memcpy (file_name + dir_len + add_slash, base, base_len + 1); - } + size_t dir_len = strlen (dir); + size_t base_len = strlen (base); + int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); + file_name = (char *) malloc (dir_len + add_slash + base_len + 1); + if (file_name != NULL) + { + memcpy (file_name, dir, dir_len); + if (add_slash) + file_name[dir_len] = DIRECTORY_SEPARATOR; + memcpy (file_name + dir_len + add_slash, base, base_len + 1); + } } if (file_name == NULL) - /* Out of memory. Treat the file as empty. */ - cp = ""; + /* Out of memory. Treat the file as empty. */ + cp = ""; else - { - int fd; - - /* Open the file. Reject symbolic links on platforms that support - O_NOFOLLOW. This is a security feature. Without it, an attacker - could retrieve parts of the contents (namely, the tail of the - first line that starts with "* ") of an arbitrary file by placing - a symbolic link to that file under the name "charset.alias" in - some writable directory and defining the environment variable - CHARSETALIASDIR to point to that directory. */ - fd = open (file_name, - O_RDONLY | (HAVE_WORKING_O_NOFOLLOW ? O_NOFOLLOW : 0)); - if (fd < 0) - /* File not found. Treat it as empty. */ - cp = ""; - else - { - FILE *fp; - - fp = fdopen (fd, "r"); - if (fp == NULL) - { - /* Out of memory. Treat the file as empty. */ - close (fd); - cp = ""; - } - else - { - /* Parse the file's contents. */ - char *res_ptr = NULL; - size_t res_size = 0; - - for (;;) - { - int c; - char buf1[50+1]; - char buf2[50+1]; - size_t l1, l2; - char *old_res_ptr; - - c = getc (fp); - if (c == EOF) - break; - if (c == '\n' || c == ' ' || c == '\t') - continue; - if (c == '#') - { - /* Skip comment, to end of line. */ - do - c = getc (fp); - while (!(c == EOF || c == '\n')); - if (c == EOF) - break; - continue; - } - ungetc (c, fp); - if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) - break; - l1 = strlen (buf1); - l2 = strlen (buf2); - old_res_ptr = res_ptr; - if (res_size == 0) - { - res_size = l1 + 1 + l2 + 1; - res_ptr = (char *) malloc (res_size + 1); - } - else - { - res_size += l1 + 1 + l2 + 1; - res_ptr = (char *) realloc (res_ptr, res_size + 1); - } - if (res_ptr == NULL) - { - /* Out of memory. */ - res_size = 0; - if (old_res_ptr != NULL) - free (old_res_ptr); - break; - } - strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); - strcpy (res_ptr + res_size - (l2 + 1), buf2); - } - fclose (fp); - if (res_size == 0) - cp = ""; - else - { - *(res_ptr + res_size) = '\0'; - cp = res_ptr; - } - } - } - - free (file_name); - } + { + int fd; + + /* Open the file. Reject symbolic links on platforms that support + O_NOFOLLOW. This is a security feature. Without it, an attacker + could retrieve parts of the contents (namely, the tail of the + first line that starts with "* ") of an arbitrary file by placing + a symbolic link to that file under the name "charset.alias" in + some writable directory and defining the environment variable + CHARSETALIASDIR to point to that directory. */ + fd = open (file_name, + O_RDONLY | (HAVE_WORKING_O_NOFOLLOW ? O_NOFOLLOW : 0)); + if (fd < 0) + /* File not found. Treat it as empty. */ + cp = ""; + else + { + FILE *fp; + + fp = fdopen (fd, "r"); + if (fp == NULL) + { + /* Out of memory. Treat the file as empty. */ + close (fd); + cp = ""; + } + else + { + /* Parse the file's contents. */ + char *res_ptr = NULL; + size_t res_size = 0; + + for (;;) + { + int c; + char buf1[50+1]; + char buf2[50+1]; + size_t l1, l2; + char *old_res_ptr; + + c = getc (fp); + if (c == EOF) + break; + if (c == '\n' || c == ' ' || c == '\t') + continue; + if (c == '#') + { + /* Skip comment, to end of line. */ + do + c = getc (fp); + while (!(c == EOF || c == '\n')); + if (c == EOF) + break; + continue; + } + ungetc (c, fp); + if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) + break; + l1 = strlen (buf1); + l2 = strlen (buf2); + old_res_ptr = res_ptr; + if (res_size == 0) + { + res_size = l1 + 1 + l2 + 1; + res_ptr = (char *) malloc (res_size + 1); + } + else + { + res_size += l1 + 1 + l2 + 1; + res_ptr = (char *) realloc (res_ptr, res_size + 1); + } + if (res_ptr == NULL) + { + /* Out of memory. */ + res_size = 0; + if (old_res_ptr != NULL) + free (old_res_ptr); + break; + } + strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); + strcpy (res_ptr + res_size - (l2 + 1), buf2); + } + fclose (fp); + if (res_size == 0) + cp = ""; + else + { + *(res_ptr + res_size) = '\0'; + cp = res_ptr; + } + } + } + + free (file_name); + } #else # if defined DARWIN7 /* To avoid the trouble of installing a file that is shared by many - GNU packages -- many packaging systems have problems with this --, - simply inline the aliases here. */ + GNU packages -- many packaging systems have problems with this --, + simply inline the aliases here. */ cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" - "ISO8859-2" "\0" "ISO-8859-2" "\0" - "ISO8859-4" "\0" "ISO-8859-4" "\0" - "ISO8859-5" "\0" "ISO-8859-5" "\0" - "ISO8859-7" "\0" "ISO-8859-7" "\0" - "ISO8859-9" "\0" "ISO-8859-9" "\0" - "ISO8859-13" "\0" "ISO-8859-13" "\0" - "ISO8859-15" "\0" "ISO-8859-15" "\0" - "KOI8-R" "\0" "KOI8-R" "\0" - "KOI8-U" "\0" "KOI8-U" "\0" - "CP866" "\0" "CP866" "\0" - "CP949" "\0" "CP949" "\0" - "CP1131" "\0" "CP1131" "\0" - "CP1251" "\0" "CP1251" "\0" - "eucCN" "\0" "GB2312" "\0" - "GB2312" "\0" "GB2312" "\0" - "eucJP" "\0" "EUC-JP" "\0" - "eucKR" "\0" "EUC-KR" "\0" - "Big5" "\0" "BIG5" "\0" - "Big5HKSCS" "\0" "BIG5-HKSCS" "\0" - "GBK" "\0" "GBK" "\0" - "GB18030" "\0" "GB18030" "\0" - "SJIS" "\0" "SHIFT_JIS" "\0" - "ARMSCII-8" "\0" "ARMSCII-8" "\0" - "PT154" "\0" "PT154" "\0" - /*"ISCII-DEV" "\0" "?" "\0"*/ - "*" "\0" "UTF-8" "\0"; + "ISO8859-2" "\0" "ISO-8859-2" "\0" + "ISO8859-4" "\0" "ISO-8859-4" "\0" + "ISO8859-5" "\0" "ISO-8859-5" "\0" + "ISO8859-7" "\0" "ISO-8859-7" "\0" + "ISO8859-9" "\0" "ISO-8859-9" "\0" + "ISO8859-13" "\0" "ISO-8859-13" "\0" + "ISO8859-15" "\0" "ISO-8859-15" "\0" + "KOI8-R" "\0" "KOI8-R" "\0" + "KOI8-U" "\0" "KOI8-U" "\0" + "CP866" "\0" "CP866" "\0" + "CP949" "\0" "CP949" "\0" + "CP1131" "\0" "CP1131" "\0" + "CP1251" "\0" "CP1251" "\0" + "eucCN" "\0" "GB2312" "\0" + "GB2312" "\0" "GB2312" "\0" + "eucJP" "\0" "EUC-JP" "\0" + "eucKR" "\0" "EUC-KR" "\0" + "Big5" "\0" "BIG5" "\0" + "Big5HKSCS" "\0" "BIG5-HKSCS" "\0" + "GBK" "\0" "GBK" "\0" + "GB18030" "\0" "GB18030" "\0" + "SJIS" "\0" "SHIFT_JIS" "\0" + "ARMSCII-8" "\0" "ARMSCII-8" "\0" + "PT154" "\0" "PT154" "\0" + /*"ISCII-DEV" "\0" "?" "\0"*/ + "*" "\0" "UTF-8" "\0"; # endif # if defined VMS /* To avoid the troubles of an extra file charset.alias_vms in the - sources of many GNU packages, simply inline the aliases here. */ + sources of many GNU packages, simply inline the aliases here. */ /* The list of encodings is taken from the OpenVMS 7.3-1 documentation - "Compaq C Run-Time Library Reference Manual for OpenVMS systems" - section 10.7 "Handling Different Character Sets". */ + "Compaq C Run-Time Library Reference Manual for OpenVMS systems" + section 10.7 "Handling Different Character Sets". */ cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" - "ISO8859-2" "\0" "ISO-8859-2" "\0" - "ISO8859-5" "\0" "ISO-8859-5" "\0" - "ISO8859-7" "\0" "ISO-8859-7" "\0" - "ISO8859-8" "\0" "ISO-8859-8" "\0" - "ISO8859-9" "\0" "ISO-8859-9" "\0" - /* Japanese */ - "eucJP" "\0" "EUC-JP" "\0" - "SJIS" "\0" "SHIFT_JIS" "\0" - "DECKANJI" "\0" "DEC-KANJI" "\0" - "SDECKANJI" "\0" "EUC-JP" "\0" - /* Chinese */ - "eucTW" "\0" "EUC-TW" "\0" - "DECHANYU" "\0" "DEC-HANYU" "\0" - "DECHANZI" "\0" "GB2312" "\0" - /* Korean */ - "DECKOREAN" "\0" "EUC-KR" "\0"; + "ISO8859-2" "\0" "ISO-8859-2" "\0" + "ISO8859-5" "\0" "ISO-8859-5" "\0" + "ISO8859-7" "\0" "ISO-8859-7" "\0" + "ISO8859-8" "\0" "ISO-8859-8" "\0" + "ISO8859-9" "\0" "ISO-8859-9" "\0" + /* Japanese */ + "eucJP" "\0" "EUC-JP" "\0" + "SJIS" "\0" "SHIFT_JIS" "\0" + "DECKANJI" "\0" "DEC-KANJI" "\0" + "SDECKANJI" "\0" "EUC-JP" "\0" + /* Chinese */ + "eucTW" "\0" "EUC-TW" "\0" + "DECHANYU" "\0" "DEC-HANYU" "\0" + "DECHANZI" "\0" "GB2312" "\0" + /* Korean */ + "DECKOREAN" "\0" "EUC-KR" "\0"; # endif # if defined WIN32_NATIVE || defined __CYGWIN__ /* To avoid the troubles of installing a separate file in the same - directory as the DLL and of retrieving the DLL's directory at - runtime, simply inline the aliases here. */ + directory as the DLL and of retrieving the DLL's directory at + runtime, simply inline the aliases here. */ cp = "CP936" "\0" "GBK" "\0" - "CP1361" "\0" "JOHAB" "\0" - "CP20127" "\0" "ASCII" "\0" - "CP20866" "\0" "KOI8-R" "\0" - "CP20936" "\0" "GB2312" "\0" - "CP21866" "\0" "KOI8-RU" "\0" - "CP28591" "\0" "ISO-8859-1" "\0" - "CP28592" "\0" "ISO-8859-2" "\0" - "CP28593" "\0" "ISO-8859-3" "\0" - "CP28594" "\0" "ISO-8859-4" "\0" - "CP28595" "\0" "ISO-8859-5" "\0" - "CP28596" "\0" "ISO-8859-6" "\0" - "CP28597" "\0" "ISO-8859-7" "\0" - "CP28598" "\0" "ISO-8859-8" "\0" - "CP28599" "\0" "ISO-8859-9" "\0" - "CP28605" "\0" "ISO-8859-15" "\0" - "CP38598" "\0" "ISO-8859-8" "\0" - "CP51932" "\0" "EUC-JP" "\0" - "CP51936" "\0" "GB2312" "\0" - "CP51949" "\0" "EUC-KR" "\0" - "CP51950" "\0" "EUC-TW" "\0" - "CP54936" "\0" "GB18030" "\0" - "CP65001" "\0" "UTF-8" "\0"; + "CP1361" "\0" "JOHAB" "\0" + "CP20127" "\0" "ASCII" "\0" + "CP20866" "\0" "KOI8-R" "\0" + "CP20936" "\0" "GB2312" "\0" + "CP21866" "\0" "KOI8-RU" "\0" + "CP28591" "\0" "ISO-8859-1" "\0" + "CP28592" "\0" "ISO-8859-2" "\0" + "CP28593" "\0" "ISO-8859-3" "\0" + "CP28594" "\0" "ISO-8859-4" "\0" + "CP28595" "\0" "ISO-8859-5" "\0" + "CP28596" "\0" "ISO-8859-6" "\0" + "CP28597" "\0" "ISO-8859-7" "\0" + "CP28598" "\0" "ISO-8859-8" "\0" + "CP28599" "\0" "ISO-8859-9" "\0" + "CP28605" "\0" "ISO-8859-15" "\0" + "CP38598" "\0" "ISO-8859-8" "\0" + "CP51932" "\0" "EUC-JP" "\0" + "CP51936" "\0" "GB2312" "\0" + "CP51949" "\0" "EUC-KR" "\0" + "CP51950" "\0" "EUC-TW" "\0" + "CP54936" "\0" "GB18030" "\0" + "CP65001" "\0" "UTF-8" "\0"; # endif #endif @@ -381,34 +381,34 @@ locale_charset (void) locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') - { - locale = getenv ("LC_CTYPE"); - if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); - } + { + locale = getenv ("LC_CTYPE"); + if (locale == NULL || locale[0] == '\0') + locale = getenv ("LANG"); + } if (locale != NULL && locale[0] != '\0') - { - /* If the locale name contains an encoding after the dot, return - it. */ - const char *dot = strchr (locale, '.'); - - if (dot != NULL) - { - const char *modifier; - - dot++; - /* Look for the possible @... trailer and remove it, if any. */ - modifier = strchr (dot, '@'); - if (modifier == NULL) - return dot; - if (modifier - dot < sizeof (buf)) - { - memcpy (buf, dot, modifier - dot); - buf [modifier - dot] = '\0'; - return buf; - } - } - } + { + /* If the locale name contains an encoding after the dot, return + it. */ + const char *dot = strchr (locale, '.'); + + if (dot != NULL) + { + const char *modifier; + + dot++; + /* Look for the possible @... trailer and remove it, if any. */ + modifier = strchr (dot, '@'); + if (modifier == NULL) + return dot; + if (modifier - dot < sizeof (buf)) + { + memcpy (buf, dot, modifier - dot); + buf [modifier - dot] = '\0'; + return buf; + } + } + } /* Woe32 has a function returning the locale's codepage as a number. */ sprintf (buf, "CP%u", GetACP ()); @@ -432,11 +432,11 @@ locale_charset (void) { locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') - { - locale = getenv ("LC_CTYPE"); - if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); - } + { + locale = getenv ("LC_CTYPE"); + if (locale == NULL || locale[0] == '\0') + locale = getenv ("LANG"); + } } /* On some old systems, one used to set locale = "iso8859_1". On others, @@ -468,7 +468,7 @@ locale_charset (void) { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); + locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { @@ -476,21 +476,21 @@ locale_charset (void) const char *dot = strchr (locale, '.'); if (dot != NULL) - { - const char *modifier; - - dot++; - /* Look for the possible @... trailer and remove it, if any. */ - modifier = strchr (dot, '@'); - if (modifier == NULL) - return dot; - if (modifier - dot < sizeof (buf)) - { - memcpy (buf, dot, modifier - dot); - buf [modifier - dot] = '\0'; - return buf; - } - } + { + const char *modifier; + + dot++; + /* Look for the possible @... trailer and remove it, if any. */ + modifier = strchr (dot, '@'); + if (modifier == NULL) + return dot; + if (modifier - dot < sizeof (buf)) + { + memcpy (buf, dot, modifier - dot); + buf [modifier - dot] = '\0'; + return buf; + } + } /* Resolve through the charset.alias file. */ codeset = locale; @@ -499,12 +499,12 @@ locale_charset (void) { /* OS/2 has a function returning the locale's codepage as a number. */ if (DosQueryCp (sizeof (cp), cp, &cplen)) - codeset = ""; + codeset = ""; else - { - sprintf (buf, "CP%u", cp[0]); - codeset = buf; - } + { + sprintf (buf, "CP%u", cp[0]); + codeset = buf; + } } #endif @@ -518,10 +518,10 @@ locale_charset (void) *aliases != '\0'; aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) if (strcmp (codeset, aliases) == 0 - || (aliases[0] == '*' && aliases[1] == '\0')) + || (aliases[0] == '*' && aliases[1] == '\0')) { - codeset = aliases + strlen (aliases) + 1; - break; + codeset = aliases + strlen (aliases) + 1; + break; } /* Don't return an empty string. GNU libc and GNU libiconv interpret diff --git a/gettext-runtime/intl/localename.c b/gettext-runtime/intl/localename.c index 9f4c18191..c4273c3b6 100644 --- a/gettext-runtime/intl/localename.c +++ b/gettext-runtime/intl/localename.c @@ -784,7 +784,7 @@ gl_locale_name_canonicalize (char *name) MacOS X 10.3.8 function CFLocaleCreateCanonicalLocaleIdentifierFromString(). */ typedef struct { const char legacy[21+1]; const char unixy[5+1]; } - legacy_entry; + legacy_entry; static const legacy_entry legacy_table[] = { { "Afrikaans", "af" }, { "Albanian", "sq" }, @@ -922,7 +922,7 @@ gl_locale_name_canonicalize (char *name) /* Convert new-style locale names with language tags (ISO 639 and ISO 15924) to Unix (ISO 639 and ISO 3166) names. */ typedef struct { const char langtag[7+1]; const char unixy[12+1]; } - langtag_entry; + langtag_entry; static const langtag_entry langtag_table[] = { /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn". The default script for az on Unix is Latin. */ @@ -952,7 +952,7 @@ gl_locale_name_canonicalize (char *name) /* Convert script names (ISO 15924) to Unix conventions. See http://www.unicode.org/iso15924/iso15924-codes.html */ typedef struct { const char script[4+1]; const char unixy[9+1]; } - script_entry; + script_entry; static const script_entry script_table[] = { { "Arab", "arabic" }, { "Cyrl", "cyrillic" }, @@ -966,21 +966,21 @@ gl_locale_name_canonicalize (char *name) i1 = 0; i2 = sizeof (legacy_table) / sizeof (legacy_entry); while (i2 - i1 > 1) - { - /* At this point we know that if name occurs in legacy_table, - its index must be >= i1 and < i2. */ - unsigned int i = (i1 + i2) >> 1; - const legacy_entry *p = &legacy_table[i]; - if (strcmp (name, p->legacy) < 0) - i2 = i; - else - i1 = i; - } + { + /* At this point we know that if name occurs in legacy_table, + its index must be >= i1 and < i2. */ + unsigned int i = (i1 + i2) >> 1; + const legacy_entry *p = &legacy_table[i]; + if (strcmp (name, p->legacy) < 0) + i2 = i; + else + i1 = i; + } if (strcmp (name, legacy_table[i1].legacy) == 0) - { - strcpy (name, legacy_table[i1].unixy); - return; - } + { + strcpy (name, legacy_table[i1].unixy); + return; + } } /* Step 2: Convert using langtag_table and script_table. */ @@ -990,41 +990,41 @@ gl_locale_name_canonicalize (char *name) i1 = 0; i2 = sizeof (langtag_table) / sizeof (langtag_entry); while (i2 - i1 > 1) - { - /* At this point we know that if name occurs in langtag_table, - its index must be >= i1 and < i2. */ - unsigned int i = (i1 + i2) >> 1; - const langtag_entry *p = &langtag_table[i]; - if (strcmp (name, p->langtag) < 0) - i2 = i; - else - i1 = i; - } + { + /* At this point we know that if name occurs in langtag_table, + its index must be >= i1 and < i2. */ + unsigned int i = (i1 + i2) >> 1; + const langtag_entry *p = &langtag_table[i]; + if (strcmp (name, p->langtag) < 0) + i2 = i; + else + i1 = i; + } if (strcmp (name, langtag_table[i1].langtag) == 0) - { - strcpy (name, langtag_table[i1].unixy); - return; - } + { + strcpy (name, langtag_table[i1].unixy); + return; + } i1 = 0; i2 = sizeof (script_table) / sizeof (script_entry); while (i2 - i1 > 1) - { - /* At this point we know that if (name + 3) occurs in script_table, - its index must be >= i1 and < i2. */ - unsigned int i = (i1 + i2) >> 1; - const script_entry *p = &script_table[i]; - if (strcmp (name + 3, p->script) < 0) - i2 = i; - else - i1 = i; - } + { + /* At this point we know that if (name + 3) occurs in script_table, + its index must be >= i1 and < i2. */ + unsigned int i = (i1 + i2) >> 1; + const script_entry *p = &script_table[i]; + if (strcmp (name + 3, p->script) < 0) + i2 = i; + else + i1 = i; + } if (strcmp (name + 3, script_table[i1].script) == 0) - { - name[2] = '@'; - strcpy (name + 3, script_table[i1].unixy); - return; - } + { + name[2] = '@'; + strcpy (name + 3, script_table[i1].unixy); + return; + } } /* Step 3: Convert new-style dash to Unix underscore. */ @@ -1032,7 +1032,7 @@ gl_locale_name_canonicalize (char *name) char *p; for (p = name; *p != '\0'; p++) if (*p == '-') - *p = '_'; + *p = '_'; } } @@ -1058,19 +1058,19 @@ gl_locale_name_canonicalize (char *name) for (p = name; *p != '\0'; p++) if (*p == '-') { - *p = '_'; - p++; - for (; *p != '\0'; p++) - { - if (*p >= 'a' && *p <= 'z') - *p += 'A' - 'a'; - if (*p == '-') - { - *p = '\0'; - return; - } - } - return; + *p = '_'; + p++; + for (; *p != '\0'; p++) + { + if (*p >= 'a' && *p <= 'z') + *p += 'A' - 'a'; + if (*p == '-') + { + *p = '\0'; + return; + } + } + return; } } @@ -1087,15 +1087,15 @@ gl_locale_name_from_win32_LANGID (LANGID langid) static char namebuf[256]; /* Query the system's notion of locale name. - On Windows95/98/ME, GetLocaleInfoA returns some incorrect results. - But we don't need to support systems that are so old. */ + On Windows95/98/ME, GetLocaleInfoA returns some incorrect results. + But we don't need to support systems that are so old. */ if (GetLocaleInfoA (MAKELCID (langid, SORT_DEFAULT), LOCALE_SNAME, - namebuf, sizeof (namebuf) - 1)) - { - /* Convert it to a Unix locale name. */ - gl_locale_name_canonicalize (namebuf); - return namebuf; - } + namebuf, sizeof (namebuf) - 1)) + { + /* Convert it to a Unix locale name. */ + gl_locale_name_canonicalize (namebuf); + return namebuf; + } } /* Internet Explorer has an LCID to RFC3066 name mapping stored in HKEY_CLASSES_ROOT\Mime\Database\Rfc1766. But we better don't use that @@ -1119,176 +1119,176 @@ gl_locale_name_from_win32_LANGID (LANGID langid) case LANG_ALBANIAN: return "sq_AL"; case LANG_AMHARIC: return "am_ET"; case LANG_ARABIC: - switch (sub) - { - case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA"; - case SUBLANG_ARABIC_IRAQ: return "ar_IQ"; - case SUBLANG_ARABIC_EGYPT: return "ar_EG"; - case SUBLANG_ARABIC_LIBYA: return "ar_LY"; - case SUBLANG_ARABIC_ALGERIA: return "ar_DZ"; - case SUBLANG_ARABIC_MOROCCO: return "ar_MA"; - case SUBLANG_ARABIC_TUNISIA: return "ar_TN"; - case SUBLANG_ARABIC_OMAN: return "ar_OM"; - case SUBLANG_ARABIC_YEMEN: return "ar_YE"; - case SUBLANG_ARABIC_SYRIA: return "ar_SY"; - case SUBLANG_ARABIC_JORDAN: return "ar_JO"; - case SUBLANG_ARABIC_LEBANON: return "ar_LB"; - case SUBLANG_ARABIC_KUWAIT: return "ar_KW"; - case SUBLANG_ARABIC_UAE: return "ar_AE"; - case SUBLANG_ARABIC_BAHRAIN: return "ar_BH"; - case SUBLANG_ARABIC_QATAR: return "ar_QA"; - } - return "ar"; + switch (sub) + { + case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA"; + case SUBLANG_ARABIC_IRAQ: return "ar_IQ"; + case SUBLANG_ARABIC_EGYPT: return "ar_EG"; + case SUBLANG_ARABIC_LIBYA: return "ar_LY"; + case SUBLANG_ARABIC_ALGERIA: return "ar_DZ"; + case SUBLANG_ARABIC_MOROCCO: return "ar_MA"; + case SUBLANG_ARABIC_TUNISIA: return "ar_TN"; + case SUBLANG_ARABIC_OMAN: return "ar_OM"; + case SUBLANG_ARABIC_YEMEN: return "ar_YE"; + case SUBLANG_ARABIC_SYRIA: return "ar_SY"; + case SUBLANG_ARABIC_JORDAN: return "ar_JO"; + case SUBLANG_ARABIC_LEBANON: return "ar_LB"; + case SUBLANG_ARABIC_KUWAIT: return "ar_KW"; + case SUBLANG_ARABIC_UAE: return "ar_AE"; + case SUBLANG_ARABIC_BAHRAIN: return "ar_BH"; + case SUBLANG_ARABIC_QATAR: return "ar_QA"; + } + return "ar"; case LANG_ARMENIAN: return "hy_AM"; case LANG_ASSAMESE: return "as_IN"; case LANG_AZERI: - switch (sub) - { - /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */ - case SUBLANG_AZERI_LATIN: return "az_AZ@latin"; - case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic"; - } - return "az"; + switch (sub) + { + /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */ + case SUBLANG_AZERI_LATIN: return "az_AZ@latin"; + case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic"; + } + return "az"; case LANG_BASQUE: - switch (sub) - { - case SUBLANG_DEFAULT: return "eu_ES"; - } - return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */ + switch (sub) + { + case SUBLANG_DEFAULT: return "eu_ES"; + } + return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */ case LANG_BELARUSIAN: return "be_BY"; case LANG_BENGALI: - switch (sub) - { - case SUBLANG_BENGALI_INDIA: return "bn_IN"; - case SUBLANG_BENGALI_BANGLADESH: return "bn_BD"; - } - return "bn"; + switch (sub) + { + case SUBLANG_BENGALI_INDIA: return "bn_IN"; + case SUBLANG_BENGALI_BANGLADESH: return "bn_BD"; + } + return "bn"; case LANG_BULGARIAN: return "bg_BG"; case LANG_BURMESE: return "my_MM"; case LANG_CAMBODIAN: return "km_KH"; case LANG_CATALAN: return "ca_ES"; case LANG_CHEROKEE: return "chr_US"; case LANG_CHINESE: - switch (sub) - { - case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW"; - case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN"; - case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; - case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; - case SUBLANG_CHINESE_MACAU: return "zh_MO"; - } - return "zh"; + switch (sub) + { + case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW"; + case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN"; + case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; + case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; + case SUBLANG_CHINESE_MACAU: return "zh_MO"; + } + return "zh"; case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN - * What used to be called Serbo-Croatian - * should really now be two separate - * languages because of political reasons. - * (Says tml, who knows nothing about Serbian - * or Croatian.) - * (I can feel those flames coming already.) - */ - switch (sub) - { - case SUBLANG_CROATIAN_CROATIA: return "hr_HR"; - case SUBLANG_SERBIAN_LATIN: return "sr_CS"; - case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic"; - case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA"; - case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA"; - case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic"; - } - return "hr"; + * What used to be called Serbo-Croatian + * should really now be two separate + * languages because of political reasons. + * (Says tml, who knows nothing about Serbian + * or Croatian.) + * (I can feel those flames coming already.) + */ + switch (sub) + { + case SUBLANG_CROATIAN_CROATIA: return "hr_HR"; + case SUBLANG_SERBIAN_LATIN: return "sr_CS"; + case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic"; + case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA"; + case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA"; + case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic"; + } + return "hr"; case LANG_CZECH: return "cs_CZ"; case LANG_DANISH: return "da_DK"; case LANG_DIVEHI: return "dv_MV"; case LANG_DUTCH: - switch (sub) - { - case SUBLANG_DUTCH: return "nl_NL"; - case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE"; - } - return "nl"; + switch (sub) + { + case SUBLANG_DUTCH: return "nl_NL"; + case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE"; + } + return "nl"; case LANG_EDO: return "bin_NG"; case LANG_ENGLISH: - switch (sub) - { - /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought - * English was the language spoken in England. - * Oh well. - */ - case SUBLANG_ENGLISH_US: return "en_US"; - case SUBLANG_ENGLISH_UK: return "en_GB"; - case SUBLANG_ENGLISH_AUS: return "en_AU"; - case SUBLANG_ENGLISH_CAN: return "en_CA"; - case SUBLANG_ENGLISH_NZ: return "en_NZ"; - case SUBLANG_ENGLISH_EIRE: return "en_IE"; - case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA"; - case SUBLANG_ENGLISH_JAMAICA: return "en_JM"; - case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */ - case SUBLANG_ENGLISH_BELIZE: return "en_BZ"; - case SUBLANG_ENGLISH_TRINIDAD: return "en_TT"; - case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW"; - case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH"; - case SUBLANG_ENGLISH_INDONESIA: return "en_ID"; - case SUBLANG_ENGLISH_HONGKONG: return "en_HK"; - case SUBLANG_ENGLISH_INDIA: return "en_IN"; - case SUBLANG_ENGLISH_MALAYSIA: return "en_MY"; - case SUBLANG_ENGLISH_SINGAPORE: return "en_SG"; - } - return "en"; + switch (sub) + { + /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought + * English was the language spoken in England. + * Oh well. + */ + case SUBLANG_ENGLISH_US: return "en_US"; + case SUBLANG_ENGLISH_UK: return "en_GB"; + case SUBLANG_ENGLISH_AUS: return "en_AU"; + case SUBLANG_ENGLISH_CAN: return "en_CA"; + case SUBLANG_ENGLISH_NZ: return "en_NZ"; + case SUBLANG_ENGLISH_EIRE: return "en_IE"; + case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA"; + case SUBLANG_ENGLISH_JAMAICA: return "en_JM"; + case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */ + case SUBLANG_ENGLISH_BELIZE: return "en_BZ"; + case SUBLANG_ENGLISH_TRINIDAD: return "en_TT"; + case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW"; + case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH"; + case SUBLANG_ENGLISH_INDONESIA: return "en_ID"; + case SUBLANG_ENGLISH_HONGKONG: return "en_HK"; + case SUBLANG_ENGLISH_INDIA: return "en_IN"; + case SUBLANG_ENGLISH_MALAYSIA: return "en_MY"; + case SUBLANG_ENGLISH_SINGAPORE: return "en_SG"; + } + return "en"; case LANG_ESTONIAN: return "et_EE"; case LANG_FAEROESE: return "fo_FO"; case LANG_FARSI: return "fa_IR"; case LANG_FINNISH: return "fi_FI"; case LANG_FRENCH: - switch (sub) - { - case SUBLANG_FRENCH: return "fr_FR"; - case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE"; - case SUBLANG_FRENCH_CANADIAN: return "fr_CA"; - case SUBLANG_FRENCH_SWISS: return "fr_CH"; - case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU"; - case SUBLANG_FRENCH_MONACO: return "fr_MC"; - case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */ - case SUBLANG_FRENCH_REUNION: return "fr_RE"; - case SUBLANG_FRENCH_CONGO: return "fr_CG"; - case SUBLANG_FRENCH_SENEGAL: return "fr_SN"; - case SUBLANG_FRENCH_CAMEROON: return "fr_CM"; - case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI"; - case SUBLANG_FRENCH_MALI: return "fr_ML"; - case SUBLANG_FRENCH_MOROCCO: return "fr_MA"; - case SUBLANG_FRENCH_HAITI: return "fr_HT"; - } - return "fr"; + switch (sub) + { + case SUBLANG_FRENCH: return "fr_FR"; + case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE"; + case SUBLANG_FRENCH_CANADIAN: return "fr_CA"; + case SUBLANG_FRENCH_SWISS: return "fr_CH"; + case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU"; + case SUBLANG_FRENCH_MONACO: return "fr_MC"; + case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */ + case SUBLANG_FRENCH_REUNION: return "fr_RE"; + case SUBLANG_FRENCH_CONGO: return "fr_CG"; + case SUBLANG_FRENCH_SENEGAL: return "fr_SN"; + case SUBLANG_FRENCH_CAMEROON: return "fr_CM"; + case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI"; + case SUBLANG_FRENCH_MALI: return "fr_ML"; + case SUBLANG_FRENCH_MOROCCO: return "fr_MA"; + case SUBLANG_FRENCH_HAITI: return "fr_HT"; + } + return "fr"; case LANG_FRISIAN: return "fy_NL"; case LANG_FULFULDE: - /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */ - return "ff_NG"; + /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */ + return "ff_NG"; case LANG_GAELIC: - switch (sub) - { - case 0x01: /* SCOTTISH */ return "gd_GB"; - case 0x02: /* IRISH */ return "ga_IE"; - } - return "C"; + switch (sub) + { + case 0x01: /* SCOTTISH */ return "gd_GB"; + case 0x02: /* IRISH */ return "ga_IE"; + } + return "C"; case LANG_GALICIAN: return "gl_ES"; case LANG_GEORGIAN: return "ka_GE"; case LANG_GERMAN: - switch (sub) - { - case SUBLANG_GERMAN: return "de_DE"; - case SUBLANG_GERMAN_SWISS: return "de_CH"; - case SUBLANG_GERMAN_AUSTRIAN: return "de_AT"; - case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU"; - case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI"; - } - return "de"; + switch (sub) + { + case SUBLANG_GERMAN: return "de_DE"; + case SUBLANG_GERMAN_SWISS: return "de_CH"; + case SUBLANG_GERMAN_AUSTRIAN: return "de_AT"; + case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU"; + case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI"; + } + return "de"; case LANG_GREEK: return "el_GR"; case LANG_GUARANI: return "gn_PY"; case LANG_GUJARATI: return "gu_IN"; case LANG_HAUSA: return "ha_NG"; case LANG_HAWAIIAN: - /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers) - or Hawaii Creole English ("cpe_US", 600000 speakers)? */ - return "cpe_US"; + /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers) + or Hawaii Creole English ("cpe_US", 600000 speakers)? */ + return "cpe_US"; case LANG_HEBREW: return "he_IL"; case LANG_HINDI: return "hi_IN"; case LANG_HUNGARIAN: return "hu_HU"; @@ -1298,26 +1298,26 @@ gl_locale_name_from_win32_LANGID (LANGID langid) case LANG_INDONESIAN: return "id_ID"; case LANG_INUKTITUT: return "iu_CA"; case LANG_ITALIAN: - switch (sub) - { - case SUBLANG_ITALIAN: return "it_IT"; - case SUBLANG_ITALIAN_SWISS: return "it_CH"; - } - return "it"; + switch (sub) + { + case SUBLANG_ITALIAN: return "it_IT"; + case SUBLANG_ITALIAN_SWISS: return "it_CH"; + } + return "it"; case LANG_JAPANESE: return "ja_JP"; case LANG_KANNADA: return "kn_IN"; case LANG_KANURI: return "kr_NG"; case LANG_KASHMIRI: - switch (sub) - { - case SUBLANG_DEFAULT: return "ks_PK"; - case SUBLANG_KASHMIRI_INDIA: return "ks_IN"; - } - return "ks"; + switch (sub) + { + case SUBLANG_DEFAULT: return "ks_PK"; + case SUBLANG_KASHMIRI_INDIA: return "ks_IN"; + } + return "ks"; case LANG_KAZAK: return "kk_KZ"; case LANG_KONKANI: - /* FIXME: Adjust this when such locales appear on Unix. */ - return "kok_IN"; + /* FIXME: Adjust this when such locales appear on Unix. */ + return "kok_IN"; case LANG_KOREAN: return "ko_KR"; case LANG_KYRGYZ: return "ky_KG"; case LANG_LAO: return "lo_LA"; @@ -1326,207 +1326,207 @@ gl_locale_name_from_win32_LANGID (LANGID langid) case LANG_LITHUANIAN: return "lt_LT"; case LANG_MACEDONIAN: return "mk_MK"; case LANG_MALAY: - switch (sub) - { - case SUBLANG_MALAY_MALAYSIA: return "ms_MY"; - case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN"; - } - return "ms"; + switch (sub) + { + case SUBLANG_MALAY_MALAYSIA: return "ms_MY"; + case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN"; + } + return "ms"; case LANG_MALAYALAM: return "ml_IN"; case LANG_MALTESE: return "mt_MT"; case LANG_MANIPURI: - /* FIXME: Adjust this when such locales appear on Unix. */ - return "mni_IN"; + /* FIXME: Adjust this when such locales appear on Unix. */ + return "mni_IN"; case LANG_MAORI: return "mi_NZ"; case LANG_MARATHI: return "mr_IN"; case LANG_MONGOLIAN: - switch (sub) - { - case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: return "mn_MN"; - case SUBLANG_MONGOLIAN_PRC: return "mn_CN"; - } - return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */ + switch (sub) + { + case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: return "mn_MN"; + case SUBLANG_MONGOLIAN_PRC: return "mn_CN"; + } + return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */ case LANG_NEPALI: - switch (sub) - { - case SUBLANG_DEFAULT: return "ne_NP"; - case SUBLANG_NEPALI_INDIA: return "ne_IN"; - } - return "ne"; + switch (sub) + { + case SUBLANG_DEFAULT: return "ne_NP"; + case SUBLANG_NEPALI_INDIA: return "ne_IN"; + } + return "ne"; case LANG_NORWEGIAN: - switch (sub) - { - case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO"; - case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO"; - } - return "no"; + switch (sub) + { + case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO"; + case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO"; + } + return "no"; case LANG_ORIYA: return "or_IN"; case LANG_OROMO: return "om_ET"; case LANG_PAPIAMENTU: return "pap_AN"; case LANG_PASHTO: - return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */ + return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */ case LANG_POLISH: return "pl_PL"; case LANG_PORTUGUESE: - switch (sub) - { - case SUBLANG_PORTUGUESE: return "pt_PT"; - /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT. - Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */ - case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR"; - } - return "pt"; + switch (sub) + { + case SUBLANG_PORTUGUESE: return "pt_PT"; + /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT. + Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */ + case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR"; + } + return "pt"; case LANG_PUNJABI: - switch (sub) - { - case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */ - case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */ - } - return "pa"; + switch (sub) + { + case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */ + case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */ + } + return "pa"; case LANG_QUECHUA: - switch (sub) - { - case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO"; - case SUBLANG_QUECHUA_ECUADOR: return "qu_EC"; - case SUBLANG_QUECHUA_PERU: return "qu_PE"; - } - return "qu"; + switch (sub) + { + case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO"; + case SUBLANG_QUECHUA_ECUADOR: return "qu_EC"; + case SUBLANG_QUECHUA_PERU: return "qu_PE"; + } + return "qu"; case LANG_RHAETO_ROMANCE: return "rm_CH"; case LANG_ROMANIAN: - switch (sub) - { - case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO"; - case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD"; - } - return "ro"; + switch (sub) + { + case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO"; + case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD"; + } + return "ro"; case LANG_RUSSIAN: - switch (sub) - { - case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU"; - case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD"; - } - return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */ + switch (sub) + { + case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU"; + case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD"; + } + return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */ case LANG_SAAMI: /* actually Northern Sami */ return "se_NO"; case LANG_SANSKRIT: return "sa_IN"; case LANG_SINDHI: - switch (sub) - { - case SUBLANG_SINDHI_INDIA: return "sd_IN"; - case SUBLANG_SINDHI_PAKISTAN: return "sd_PK"; - /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/ - } - return "sd"; + switch (sub) + { + case SUBLANG_SINDHI_INDIA: return "sd_IN"; + case SUBLANG_SINDHI_PAKISTAN: return "sd_PK"; + /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/ + } + return "sd"; case LANG_SINHALESE: return "si_LK"; case LANG_SLOVAK: return "sk_SK"; case LANG_SLOVENIAN: return "sl_SI"; case LANG_SOMALI: return "so_SO"; case LANG_SORBIAN: - /* FIXME: Adjust this when such locales appear on Unix. */ - return "wen_DE"; + /* FIXME: Adjust this when such locales appear on Unix. */ + return "wen_DE"; case LANG_SOTHO: - /* calls - it "Sepedi"; according to - - - it's the same as Northern Sotho. */ - return "nso_ZA"; + /* calls + it "Sepedi"; according to + + + it's the same as Northern Sotho. */ + return "nso_ZA"; case LANG_SPANISH: - switch (sub) - { - case SUBLANG_SPANISH: return "es_ES"; - case SUBLANG_SPANISH_MEXICAN: return "es_MX"; - case SUBLANG_SPANISH_MODERN: - return "es_ES@modern"; /* not seen on Unix */ - case SUBLANG_SPANISH_GUATEMALA: return "es_GT"; - case SUBLANG_SPANISH_COSTA_RICA: return "es_CR"; - case SUBLANG_SPANISH_PANAMA: return "es_PA"; - case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO"; - case SUBLANG_SPANISH_VENEZUELA: return "es_VE"; - case SUBLANG_SPANISH_COLOMBIA: return "es_CO"; - case SUBLANG_SPANISH_PERU: return "es_PE"; - case SUBLANG_SPANISH_ARGENTINA: return "es_AR"; - case SUBLANG_SPANISH_ECUADOR: return "es_EC"; - case SUBLANG_SPANISH_CHILE: return "es_CL"; - case SUBLANG_SPANISH_URUGUAY: return "es_UY"; - case SUBLANG_SPANISH_PARAGUAY: return "es_PY"; - case SUBLANG_SPANISH_BOLIVIA: return "es_BO"; - case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV"; - case SUBLANG_SPANISH_HONDURAS: return "es_HN"; - case SUBLANG_SPANISH_NICARAGUA: return "es_NI"; - case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR"; - case SUBLANG_SPANISH_US: return "es_US"; - } - return "es"; + switch (sub) + { + case SUBLANG_SPANISH: return "es_ES"; + case SUBLANG_SPANISH_MEXICAN: return "es_MX"; + case SUBLANG_SPANISH_MODERN: + return "es_ES@modern"; /* not seen on Unix */ + case SUBLANG_SPANISH_GUATEMALA: return "es_GT"; + case SUBLANG_SPANISH_COSTA_RICA: return "es_CR"; + case SUBLANG_SPANISH_PANAMA: return "es_PA"; + case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO"; + case SUBLANG_SPANISH_VENEZUELA: return "es_VE"; + case SUBLANG_SPANISH_COLOMBIA: return "es_CO"; + case SUBLANG_SPANISH_PERU: return "es_PE"; + case SUBLANG_SPANISH_ARGENTINA: return "es_AR"; + case SUBLANG_SPANISH_ECUADOR: return "es_EC"; + case SUBLANG_SPANISH_CHILE: return "es_CL"; + case SUBLANG_SPANISH_URUGUAY: return "es_UY"; + case SUBLANG_SPANISH_PARAGUAY: return "es_PY"; + case SUBLANG_SPANISH_BOLIVIA: return "es_BO"; + case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV"; + case SUBLANG_SPANISH_HONDURAS: return "es_HN"; + case SUBLANG_SPANISH_NICARAGUA: return "es_NI"; + case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR"; + case SUBLANG_SPANISH_US: return "es_US"; + } + return "es"; case LANG_SUTU: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */ case LANG_SWAHILI: return "sw_KE"; case LANG_SWEDISH: - switch (sub) - { - case SUBLANG_DEFAULT: return "sv_SE"; - case SUBLANG_SWEDISH_FINLAND: return "sv_FI"; - } - return "sv"; + switch (sub) + { + case SUBLANG_DEFAULT: return "sv_SE"; + case SUBLANG_SWEDISH_FINLAND: return "sv_FI"; + } + return "sv"; case LANG_SYRIAC: return "syr_TR"; /* An extinct language. */ case LANG_TAGALOG: return "tl_PH"; case LANG_TAJIK: return "tg_TJ"; case LANG_TAMAZIGHT: - switch (sub) - { - /* FIXME: Adjust this when Tamazight locales appear on Unix. */ - case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic"; - case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin"; - } - return "ber_MA"; + switch (sub) + { + /* FIXME: Adjust this when Tamazight locales appear on Unix. */ + case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic"; + case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin"; + } + return "ber_MA"; case LANG_TAMIL: - switch (sub) - { - case SUBLANG_DEFAULT: return "ta_IN"; - } - return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */ + switch (sub) + { + case SUBLANG_DEFAULT: return "ta_IN"; + } + return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */ case LANG_TATAR: return "tt_RU"; case LANG_TELUGU: return "te_IN"; case LANG_THAI: return "th_TH"; case LANG_TIBETAN: - switch (sub) - { - case SUBLANG_TIBETAN_PRC: - /* Most Tibetans would not like "bo_CN". But Tibet does not yet - have a country code of its own. */ - return "bo"; - case SUBLANG_TIBETAN_BHUTAN: return "bo_BT"; - } - return "bo"; + switch (sub) + { + case SUBLANG_TIBETAN_PRC: + /* Most Tibetans would not like "bo_CN". But Tibet does not yet + have a country code of its own. */ + return "bo"; + case SUBLANG_TIBETAN_BHUTAN: return "bo_BT"; + } + return "bo"; case LANG_TIGRINYA: - switch (sub) - { - case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET"; - case SUBLANG_TIGRINYA_ERITREA: return "ti_ER"; - } - return "ti"; + switch (sub) + { + case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET"; + case SUBLANG_TIGRINYA_ERITREA: return "ti_ER"; + } + return "ti"; case LANG_TSONGA: return "ts_ZA"; case LANG_TSWANA: return "tn_BW"; case LANG_TURKISH: return "tr_TR"; case LANG_TURKMEN: return "tk_TM"; case LANG_UIGHUR: - switch (sub) - { - case SUBLANG_UIGHUR_PRC: return "ug_CN"; - } - return "ug"; + switch (sub) + { + case SUBLANG_UIGHUR_PRC: return "ug_CN"; + } + return "ug"; case LANG_UKRAINIAN: return "uk_UA"; case LANG_URDU: - switch (sub) - { - case SUBLANG_URDU_PAKISTAN: return "ur_PK"; - case SUBLANG_URDU_INDIA: return "ur_IN"; - } - return "ur"; + switch (sub) + { + case SUBLANG_URDU_PAKISTAN: return "ur_PK"; + case SUBLANG_URDU_INDIA: return "ur_IN"; + } + return "ur"; case LANG_UZBEK: - switch (sub) - { - case SUBLANG_UZBEK_LATIN: return "uz_UZ"; - case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic"; - } - return "uz"; + switch (sub) + { + case SUBLANG_UZBEK_LATIN: return "uz_UZ"; + case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic"; + } + return "uz"; case LANG_VENDA: return "ve_ZA"; case LANG_VIETNAMESE: return "vi_VN"; case LANG_WELSH: return "cy_GB"; @@ -1633,33 +1633,33 @@ gl_locale_name_default (void) if (cached_localename == NULL) { - char namebuf[256]; + char namebuf[256]; # if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */ - CFLocaleRef locale = CFLocaleCopyCurrent (); - CFStringRef name = CFLocaleGetIdentifier (locale); + CFLocaleRef locale = CFLocaleCopyCurrent (); + CFStringRef name = CFLocaleGetIdentifier (locale); - if (CFStringGetCString (name, namebuf, sizeof(namebuf), - kCFStringEncodingASCII)) - { - gl_locale_name_canonicalize (namebuf); - cached_localename = strdup (namebuf); - } - CFRelease (locale); + if (CFStringGetCString (name, namebuf, sizeof(namebuf), + kCFStringEncodingASCII)) + { + gl_locale_name_canonicalize (namebuf); + cached_localename = strdup (namebuf); + } + CFRelease (locale); # elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ - CFTypeRef value = - CFPreferencesCopyAppValue (CFSTR ("AppleLocale"), - kCFPreferencesCurrentApplication); - if (value != NULL - && CFGetTypeID (value) == CFStringGetTypeID () - && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf), - kCFStringEncodingASCII)) - { - gl_locale_name_canonicalize (namebuf); - cached_localename = strdup (namebuf); - } + CFTypeRef value = + CFPreferencesCopyAppValue (CFSTR ("AppleLocale"), + kCFPreferencesCurrentApplication); + if (value != NULL + && CFGetTypeID (value) == CFStringGetTypeID () + && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf), + kCFStringEncodingASCII)) + { + gl_locale_name_canonicalize (namebuf); + cached_localename = strdup (namebuf); + } # endif - if (cached_localename == NULL) - cached_localename = "C"; + if (cached_localename == NULL) + cached_localename = "C"; } return cached_localename; } diff --git a/gettext-runtime/intl/lock.c b/gettext-runtime/intl/lock.c index dcc2db0e8..561423e0d 100644 --- a/gettext-runtime/intl/lock.c +++ b/gettext-runtime/intl/lock.c @@ -57,19 +57,19 @@ glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) err = pthread_mutex_lock (&lock->guard); if (err != 0) - return err; + return err; if (!lock->initialized) - { - err = glthread_rwlock_init_multithreaded (lock); - if (err != 0) - { - pthread_mutex_unlock (&lock->guard); - return err; - } - } + { + err = glthread_rwlock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } err = pthread_mutex_unlock (&lock->guard); if (err != 0) - return err; + return err; } return pthread_rwlock_rdlock (&lock->rwlock); } @@ -83,19 +83,19 @@ glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) err = pthread_mutex_lock (&lock->guard); if (err != 0) - return err; + return err; if (!lock->initialized) - { - err = glthread_rwlock_init_multithreaded (lock); - if (err != 0) - { - pthread_mutex_unlock (&lock->guard); - return err; - } - } + { + err = glthread_rwlock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } err = pthread_mutex_unlock (&lock->guard); if (err != 0) - return err; + return err; } return pthread_rwlock_wrlock (&lock->rwlock); } @@ -162,13 +162,13 @@ glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) { /* This thread has to wait for a while. Enqueue it among the - waiting_readers. */ + waiting_readers. */ err = pthread_cond_wait (&lock->waiting_readers, &lock->lock); if (err != 0) - { - pthread_mutex_unlock (&lock->lock); - return err; - } + { + pthread_mutex_unlock (&lock->lock); + return err; + } } lock->runcount++; return pthread_mutex_unlock (&lock->lock); @@ -186,15 +186,15 @@ glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) while (!(lock->runcount == 0)) { /* This thread has to wait for a while. Enqueue it among the - waiting_writers. */ + waiting_writers. */ lock->waiting_writers_count++; err = pthread_cond_wait (&lock->waiting_writers, &lock->lock); if (err != 0) - { - lock->waiting_writers_count--; - pthread_mutex_unlock (&lock->lock); - return err; - } + { + lock->waiting_writers_count--; + pthread_mutex_unlock (&lock->lock); + return err; + } lock->waiting_writers_count--; } lock->runcount--; /* runcount becomes -1 */ @@ -213,46 +213,46 @@ glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) { /* Drop a writer lock. */ if (!(lock->runcount == -1)) - { - pthread_mutex_unlock (&lock->lock); - return EINVAL; - } + { + pthread_mutex_unlock (&lock->lock); + return EINVAL; + } lock->runcount = 0; } else { /* Drop a reader lock. */ if (!(lock->runcount > 0)) - { - pthread_mutex_unlock (&lock->lock); - return EINVAL; - } + { + pthread_mutex_unlock (&lock->lock); + return EINVAL; + } lock->runcount--; } if (lock->runcount == 0) { /* POSIX recommends that "write locks shall take precedence over read - locks", to avoid "writer starvation". */ + locks", to avoid "writer starvation". */ if (lock->waiting_writers_count > 0) - { - /* Wake up one of the waiting writers. */ - err = pthread_cond_signal (&lock->waiting_writers); - if (err != 0) - { - pthread_mutex_unlock (&lock->lock); - return err; - } - } + { + /* Wake up one of the waiting writers. */ + err = pthread_cond_signal (&lock->waiting_writers); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } else - { - /* Wake up all waiting readers. */ - err = pthread_cond_broadcast (&lock->waiting_readers); - if (err != 0) - { - pthread_mutex_unlock (&lock->lock); - return err; - } - } + { + /* Wake up all waiting readers. */ + err = pthread_cond_broadcast (&lock->waiting_readers); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } } return pthread_mutex_unlock (&lock->lock); } @@ -348,19 +348,19 @@ glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) err = pthread_mutex_lock (&lock->guard); if (err != 0) - return err; + return err; if (!lock->initialized) - { - err = glthread_recursive_lock_init_multithreaded (lock); - if (err != 0) - { - pthread_mutex_unlock (&lock->guard); - return err; - } - } + { + err = glthread_recursive_lock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } err = pthread_mutex_unlock (&lock->guard); if (err != 0) - return err; + return err; } return pthread_mutex_lock (&lock->recmutex); } @@ -414,7 +414,7 @@ glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) err = pthread_mutex_lock (&lock->mutex); if (err != 0) - return err; + return err; lock->owner = self; } if (++(lock->depth) == 0) /* wraparound? */ @@ -553,7 +553,7 @@ glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) err = mutex_lock (&lock->mutex); if (err != 0) - return err; + return err; lock->owner = self; } if (++(lock->depth) == 0) /* wraparound? */ @@ -598,15 +598,15 @@ glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void int err; /* Use the mutex to guarantee that if another thread is already calling - the initfunction, this thread waits until it's finished. */ + the initfunction, this thread waits until it's finished. */ err = mutex_lock (&once_control->mutex); if (err != 0) - return err; + return err; if (!once_control->inited) - { - once_control->inited = 1; - initfunction (); - } + { + once_control->inited = 1; + initfunction (); + } return mutex_unlock (&once_control->mutex); } else @@ -648,13 +648,13 @@ glthread_lock_lock_func (gl_lock_t *lock) if (!lock->guard.done) { if (InterlockedIncrement (&lock->guard.started) == 0) - /* This thread is the first one to need this lock. Initialize it. */ - glthread_lock_init (lock); + /* This thread is the first one to need this lock. Initialize it. */ + glthread_lock_init (lock); else - /* Yield the CPU while waiting for another thread to finish - initializing this lock. */ - while (!lock->guard.done) - Sleep (0); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); } EnterCriticalSection (&lock->lock); return 0; @@ -705,28 +705,28 @@ gl_waitqueue_add (gl_waitqueue_t *wq) { unsigned int new_alloc = 2 * wq->alloc + 1; HANDLE *new_array = - (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE)); + (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE)); if (new_array == NULL) - /* No more memory. */ - return INVALID_HANDLE_VALUE; + /* No more memory. */ + return INVALID_HANDLE_VALUE; /* Now is a good opportunity to rotate the array so that its contents - starts at offset 0. */ + starts at offset 0. */ if (wq->offset > 0) - { - unsigned int old_count = wq->count; - unsigned int old_alloc = wq->alloc; - unsigned int old_offset = wq->offset; - unsigned int i; - if (old_offset + old_count > old_alloc) - { - unsigned int limit = old_offset + old_count - old_alloc; - for (i = 0; i < limit; i++) - new_array[old_alloc + i] = new_array[i]; - } - for (i = 0; i < old_count; i++) - new_array[i] = new_array[old_offset + i]; - wq->offset = 0; - } + { + unsigned int old_count = wq->count; + unsigned int old_alloc = wq->alloc; + unsigned int old_offset = wq->offset; + unsigned int i; + if (old_offset + old_count > old_alloc) + { + unsigned int limit = old_offset + old_count - old_alloc; + for (i = 0; i < limit; i++) + new_array[old_alloc + i] = new_array[i]; + } + for (i = 0; i < old_count; i++) + new_array[i] = new_array[old_offset + i]; + wq->offset = 0; + } wq->array = new_array; wq->alloc = new_alloc; } @@ -765,7 +765,7 @@ gl_waitqueue_notify_all (gl_waitqueue_t *wq) { unsigned int index = wq->offset + i; if (index >= wq->alloc) - index -= wq->alloc; + index -= wq->alloc; SetEvent (wq->array[index]); } wq->count = 0; @@ -788,13 +788,13 @@ glthread_rwlock_rdlock_func (gl_rwlock_t *lock) if (!lock->guard.done) { if (InterlockedIncrement (&lock->guard.started) == 0) - /* This thread is the first one to need this lock. Initialize it. */ - glthread_rwlock_init (lock); + /* This thread is the first one to need this lock. Initialize it. */ + glthread_rwlock_init (lock); else - /* Yield the CPU while waiting for another thread to finish - initializing this lock. */ - while (!lock->guard.done) - Sleep (0); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); } EnterCriticalSection (&lock->lock); /* Test whether only readers are currently running, and whether the runcount @@ -802,34 +802,34 @@ glthread_rwlock_rdlock_func (gl_rwlock_t *lock) if (!(lock->runcount + 1 > 0)) { /* This thread has to wait for a while. Enqueue it among the - waiting_readers. */ + waiting_readers. */ HANDLE event = gl_waitqueue_add (&lock->waiting_readers); if (event != INVALID_HANDLE_VALUE) - { - DWORD result; - LeaveCriticalSection (&lock->lock); - /* Wait until another thread signals this event. */ - result = WaitForSingleObject (event, INFINITE); - if (result == WAIT_FAILED || result == WAIT_TIMEOUT) - abort (); - CloseHandle (event); - /* The thread which signalled the event already did the bookkeeping: - removed us from the waiting_readers, incremented lock->runcount. */ - if (!(lock->runcount > 0)) - abort (); - return 0; - } + { + DWORD result; + LeaveCriticalSection (&lock->lock); + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiting_readers, incremented lock->runcount. */ + if (!(lock->runcount > 0)) + abort (); + return 0; + } else - { - /* Allocation failure. Weird. */ - do - { - LeaveCriticalSection (&lock->lock); - Sleep (1); - EnterCriticalSection (&lock->lock); - } - while (!(lock->runcount + 1 > 0)); - } + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount + 1 > 0)); + } } lock->runcount++; LeaveCriticalSection (&lock->lock); @@ -842,47 +842,47 @@ glthread_rwlock_wrlock_func (gl_rwlock_t *lock) if (!lock->guard.done) { if (InterlockedIncrement (&lock->guard.started) == 0) - /* This thread is the first one to need this lock. Initialize it. */ - glthread_rwlock_init (lock); + /* This thread is the first one to need this lock. Initialize it. */ + glthread_rwlock_init (lock); else - /* Yield the CPU while waiting for another thread to finish - initializing this lock. */ - while (!lock->guard.done) - Sleep (0); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); } EnterCriticalSection (&lock->lock); /* Test whether no readers or writers are currently running. */ if (!(lock->runcount == 0)) { /* This thread has to wait for a while. Enqueue it among the - waiting_writers. */ + waiting_writers. */ HANDLE event = gl_waitqueue_add (&lock->waiting_writers); if (event != INVALID_HANDLE_VALUE) - { - DWORD result; - LeaveCriticalSection (&lock->lock); - /* Wait until another thread signals this event. */ - result = WaitForSingleObject (event, INFINITE); - if (result == WAIT_FAILED || result == WAIT_TIMEOUT) - abort (); - CloseHandle (event); - /* The thread which signalled the event already did the bookkeeping: - removed us from the waiting_writers, set lock->runcount = -1. */ - if (!(lock->runcount == -1)) - abort (); - return 0; - } + { + DWORD result; + LeaveCriticalSection (&lock->lock); + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiting_writers, set lock->runcount = -1. */ + if (!(lock->runcount == -1)) + abort (); + return 0; + } else - { - /* Allocation failure. Weird. */ - do - { - LeaveCriticalSection (&lock->lock); - Sleep (1); - EnterCriticalSection (&lock->lock); - } - while (!(lock->runcount == 0)); - } + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount == 0)); + } } lock->runcount--; /* runcount becomes -1 */ LeaveCriticalSection (&lock->lock); @@ -899,35 +899,35 @@ glthread_rwlock_unlock_func (gl_rwlock_t *lock) { /* Drop a writer lock. */ if (!(lock->runcount == -1)) - abort (); + abort (); lock->runcount = 0; } else { /* Drop a reader lock. */ if (!(lock->runcount > 0)) - { - LeaveCriticalSection (&lock->lock); - return EPERM; - } + { + LeaveCriticalSection (&lock->lock); + return EPERM; + } lock->runcount--; } if (lock->runcount == 0) { /* POSIX recommends that "write locks shall take precedence over read - locks", to avoid "writer starvation". */ + locks", to avoid "writer starvation". */ if (lock->waiting_writers.count > 0) - { - /* Wake up one of the waiting writers. */ - lock->runcount--; - gl_waitqueue_notify_first (&lock->waiting_writers); - } + { + /* Wake up one of the waiting writers. */ + lock->runcount--; + gl_waitqueue_notify_first (&lock->waiting_writers); + } else - { - /* Wake up all waiting readers. */ - lock->runcount += lock->waiting_readers.count; - gl_waitqueue_notify_all (&lock->waiting_readers); - } + { + /* Wake up all waiting readers. */ + lock->runcount += lock->waiting_readers.count; + gl_waitqueue_notify_all (&lock->waiting_readers); + } } LeaveCriticalSection (&lock->lock); return 0; @@ -966,25 +966,25 @@ glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock) if (!lock->guard.done) { if (InterlockedIncrement (&lock->guard.started) == 0) - /* This thread is the first one to need this lock. Initialize it. */ - glthread_recursive_lock_init (lock); + /* This thread is the first one to need this lock. Initialize it. */ + glthread_recursive_lock_init (lock); else - /* Yield the CPU while waiting for another thread to finish - initializing this lock. */ - while (!lock->guard.done) - Sleep (0); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); } { DWORD self = GetCurrentThreadId (); if (lock->owner != self) { - EnterCriticalSection (&lock->lock); - lock->owner = self; + EnterCriticalSection (&lock->lock); + lock->owner = self; } if (++(lock->depth) == 0) /* wraparound? */ { - lock->depth--; - return EAGAIN; + lock->depth--; + return EAGAIN; } } return 0; @@ -1023,34 +1023,34 @@ glthread_once_func (gl_once_t *once_control, void (*initfunction) (void)) if (once_control->inited <= 0) { if (InterlockedIncrement (&once_control->started) == 0) - { - /* This thread is the first one to come to this once_control. */ - InitializeCriticalSection (&once_control->lock); - EnterCriticalSection (&once_control->lock); - once_control->inited = 0; - initfunction (); - once_control->inited = 1; - LeaveCriticalSection (&once_control->lock); - } + { + /* This thread is the first one to come to this once_control. */ + InitializeCriticalSection (&once_control->lock); + EnterCriticalSection (&once_control->lock); + once_control->inited = 0; + initfunction (); + once_control->inited = 1; + LeaveCriticalSection (&once_control->lock); + } else - { - /* Undo last operation. */ - InterlockedDecrement (&once_control->started); - /* Some other thread has already started the initialization. - Yield the CPU while waiting for the other thread to finish - initializing and taking the lock. */ - while (once_control->inited < 0) - Sleep (0); - if (once_control->inited <= 0) - { - /* Take the lock. This blocks until the other thread has - finished calling the initfunction. */ - EnterCriticalSection (&once_control->lock); - LeaveCriticalSection (&once_control->lock); - if (!(once_control->inited > 0)) - abort (); - } - } + { + /* Undo last operation. */ + InterlockedDecrement (&once_control->started); + /* Some other thread has already started the initialization. + Yield the CPU while waiting for the other thread to finish + initializing and taking the lock. */ + while (once_control->inited < 0) + Sleep (0); + if (once_control->inited <= 0) + { + /* Take the lock. This blocks until the other thread has + finished calling the initfunction. */ + EnterCriticalSection (&once_control->lock); + LeaveCriticalSection (&once_control->lock); + if (!(once_control->inited > 0)) + abort (); + } + } } } diff --git a/gettext-runtime/intl/log.c b/gettext-runtime/intl/log.c index 3f18b166c..a3e4b2726 100644 --- a/gettext-runtime/intl/log.c +++ b/gettext-runtime/intl/log.c @@ -44,16 +44,16 @@ print_escaped (FILE *stream, const char *str, const char *str_end) for (; str != str_end; str++) if (*str == '\n') { - fputs ("\\n\"", stream); - if (str + 1 == str_end) - return; - fputs ("\n\"", stream); + fputs ("\\n\"", stream); + if (str + 1 == str_end) + return; + fputs ("\n\"", stream); } else { - if (*str == '"' || *str == '\\') - putc ('\\', stream); - putc (*str, stream); + if (*str == '"' || *str == '\\') + putc ('\\', stream); + putc (*str, stream); } putc ('"', stream); } @@ -64,7 +64,7 @@ __libc_lock_define_initialized (static, lock) static inline void _nl_log_untranslated_locked (const char *logfilename, const char *domainname, - const char *msgid1, const char *msgid2, int plural) + const char *msgid1, const char *msgid2, int plural) { FILE *logfile; const char *separator; @@ -74,23 +74,23 @@ _nl_log_untranslated_locked (const char *logfilename, const char *domainname, { /* Close the last used logfile. */ if (last_logfilename != NULL) - { - if (last_logfile != NULL) - { - fclose (last_logfile); - last_logfile = NULL; - } - free (last_logfilename); - last_logfilename = NULL; - } + { + if (last_logfile != NULL) + { + fclose (last_logfile); + last_logfile = NULL; + } + free (last_logfilename); + last_logfilename = NULL; + } /* Open the logfile. */ last_logfilename = (char *) malloc (strlen (logfilename) + 1); if (last_logfilename == NULL) - return; + return; strcpy (last_logfilename, logfilename); last_logfile = fopen (logfilename, "a"); if (last_logfile == NULL) - return; + return; } logfile = last_logfile; @@ -120,7 +120,7 @@ _nl_log_untranslated_locked (const char *logfilename, const char *domainname, /* Add to the log file an entry denoting a failed translation. */ void _nl_log_untranslated (const char *logfilename, const char *domainname, - const char *msgid1, const char *msgid2, int plural) + const char *msgid1, const char *msgid2, int plural) { __libc_lock_lock (lock); _nl_log_untranslated_locked (logfilename, domainname, msgid1, msgid2, plural); diff --git a/gettext-runtime/intl/os2compat.h b/gettext-runtime/intl/os2compat.h index a18d582cd..702031c1d 100644 --- a/gettext-runtime/intl/os2compat.h +++ b/gettext-runtime/intl/os2compat.h @@ -21,15 +21,15 @@ #ifndef OS2_AWARE #undef LIBDIR -#define LIBDIR _nlos2_libdir +#define LIBDIR _nlos2_libdir extern char *_nlos2_libdir; #undef LOCALEDIR -#define LOCALEDIR _nlos2_localedir +#define LOCALEDIR _nlos2_localedir extern char *_nlos2_localedir; #undef LOCALE_ALIAS_PATH -#define LOCALE_ALIAS_PATH _nlos2_localealiaspath +#define LOCALE_ALIAS_PATH _nlos2_localealiaspath extern char *_nlos2_localealiaspath; #endif diff --git a/gettext-runtime/intl/printf-args.c b/gettext-runtime/intl/printf-args.c index cbd437d87..44e50a33c 100644 --- a/gettext-runtime/intl/printf-args.c +++ b/gettext-runtime/intl/printf-args.c @@ -43,146 +43,146 @@ PRINTF_FETCHARGS (va_list args, arguments *a) switch (ap->type) { case TYPE_SCHAR: - ap->a.a_schar = va_arg (args, /*signed char*/ int); - break; + ap->a.a_schar = va_arg (args, /*signed char*/ int); + break; case TYPE_UCHAR: - ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); - break; + ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); + break; case TYPE_SHORT: - ap->a.a_short = va_arg (args, /*short*/ int); - break; + ap->a.a_short = va_arg (args, /*short*/ int); + break; case TYPE_USHORT: - ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); - break; + ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); + break; case TYPE_INT: - ap->a.a_int = va_arg (args, int); - break; + ap->a.a_int = va_arg (args, int); + break; case TYPE_UINT: - ap->a.a_uint = va_arg (args, unsigned int); - break; + ap->a.a_uint = va_arg (args, unsigned int); + break; case TYPE_LONGINT: - ap->a.a_longint = va_arg (args, long int); - break; + ap->a.a_longint = va_arg (args, long int); + break; case TYPE_ULONGINT: - ap->a.a_ulongint = va_arg (args, unsigned long int); - break; + ap->a.a_ulongint = va_arg (args, unsigned long int); + break; #if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: - ap->a.a_longlongint = va_arg (args, long long int); - break; + ap->a.a_longlongint = va_arg (args, long long int); + break; case TYPE_ULONGLONGINT: - ap->a.a_ulonglongint = va_arg (args, unsigned long long int); - break; + ap->a.a_ulonglongint = va_arg (args, unsigned long long int); + break; #endif case TYPE_DOUBLE: - ap->a.a_double = va_arg (args, double); - break; + ap->a.a_double = va_arg (args, double); + break; case TYPE_LONGDOUBLE: - ap->a.a_longdouble = va_arg (args, long double); - break; + ap->a.a_longdouble = va_arg (args, long double); + break; case TYPE_CHAR: - ap->a.a_char = va_arg (args, int); - break; + ap->a.a_char = va_arg (args, int); + break; #if HAVE_WINT_T case TYPE_WIDE_CHAR: - /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by - default argument promotions", this is not the case in mingw32, - where wint_t is 'unsigned short'. */ - ap->a.a_wide_char = - (sizeof (wint_t) < sizeof (int) - ? va_arg (args, int) - : va_arg (args, wint_t)); - break; + /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by + default argument promotions", this is not the case in mingw32, + where wint_t is 'unsigned short'. */ + ap->a.a_wide_char = + (sizeof (wint_t) < sizeof (int) + ? va_arg (args, int) + : va_arg (args, wint_t)); + break; #endif case TYPE_STRING: - ap->a.a_string = va_arg (args, const char *); - /* A null pointer is an invalid argument for "%s", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_string == NULL) - ap->a.a_string = "(NULL)"; - break; + ap->a.a_string = va_arg (args, const char *); + /* A null pointer is an invalid argument for "%s", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_string == NULL) + ap->a.a_string = "(NULL)"; + break; #if HAVE_WCHAR_T case TYPE_WIDE_STRING: - ap->a.a_wide_string = va_arg (args, const wchar_t *); - /* A null pointer is an invalid argument for "%ls", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_wide_string == NULL) - { - static const wchar_t wide_null_string[] = - { - (wchar_t)'(', - (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', - (wchar_t)')', - (wchar_t)0 - }; - ap->a.a_wide_string = wide_null_string; - } - break; + ap->a.a_wide_string = va_arg (args, const wchar_t *); + /* A null pointer is an invalid argument for "%ls", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_wide_string == NULL) + { + static const wchar_t wide_null_string[] = + { + (wchar_t)'(', + (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', + (wchar_t)')', + (wchar_t)0 + }; + ap->a.a_wide_string = wide_null_string; + } + break; #endif case TYPE_POINTER: - ap->a.a_pointer = va_arg (args, void *); - break; + ap->a.a_pointer = va_arg (args, void *); + break; case TYPE_COUNT_SCHAR_POINTER: - ap->a.a_count_schar_pointer = va_arg (args, signed char *); - break; + ap->a.a_count_schar_pointer = va_arg (args, signed char *); + break; case TYPE_COUNT_SHORT_POINTER: - ap->a.a_count_short_pointer = va_arg (args, short *); - break; + ap->a.a_count_short_pointer = va_arg (args, short *); + break; case TYPE_COUNT_INT_POINTER: - ap->a.a_count_int_pointer = va_arg (args, int *); - break; + ap->a.a_count_int_pointer = va_arg (args, int *); + break; case TYPE_COUNT_LONGINT_POINTER: - ap->a.a_count_longint_pointer = va_arg (args, long int *); - break; + ap->a.a_count_longint_pointer = va_arg (args, long int *); + break; #if HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: - ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); - break; + ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); + break; #endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ case TYPE_U8_STRING: - ap->a.a_u8_string = va_arg (args, const uint8_t *); - /* A null pointer is an invalid argument for "%U", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u8_string == NULL) - { - static const uint8_t u8_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u8_string = u8_null_string; - } - break; + ap->a.a_u8_string = va_arg (args, const uint8_t *); + /* A null pointer is an invalid argument for "%U", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u8_string == NULL) + { + static const uint8_t u8_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u8_string = u8_null_string; + } + break; case TYPE_U16_STRING: - ap->a.a_u16_string = va_arg (args, const uint16_t *); - /* A null pointer is an invalid argument for "%lU", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u16_string == NULL) - { - static const uint16_t u16_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u16_string = u16_null_string; - } - break; + ap->a.a_u16_string = va_arg (args, const uint16_t *); + /* A null pointer is an invalid argument for "%lU", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u16_string == NULL) + { + static const uint16_t u16_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u16_string = u16_null_string; + } + break; case TYPE_U32_STRING: - ap->a.a_u32_string = va_arg (args, const uint32_t *); - /* A null pointer is an invalid argument for "%llU", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u32_string == NULL) - { - static const uint32_t u32_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u32_string = u32_null_string; - } - break; + ap->a.a_u32_string = va_arg (args, const uint32_t *); + /* A null pointer is an invalid argument for "%llU", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u32_string == NULL) + { + static const uint32_t u32_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u32_string = u32_null_string; + } + break; #endif default: - /* Unknown type. */ - return -1; + /* Unknown type. */ + return -1; } return 0; } diff --git a/gettext-runtime/intl/printf-args.h b/gettext-runtime/intl/printf-args.h index cf89c3e71..f95e6bd9c 100644 --- a/gettext-runtime/intl/printf-args.h +++ b/gettext-runtime/intl/printf-args.h @@ -94,42 +94,42 @@ typedef struct arg_type type; union { - signed char a_schar; - unsigned char a_uchar; - short a_short; - unsigned short a_ushort; - int a_int; - unsigned int a_uint; - long int a_longint; - unsigned long int a_ulongint; + signed char a_schar; + unsigned char a_uchar; + short a_short; + unsigned short a_ushort; + int a_int; + unsigned int a_uint; + long int a_longint; + unsigned long int a_ulongint; #if HAVE_LONG_LONG_INT - long long int a_longlongint; - unsigned long long int a_ulonglongint; + long long int a_longlongint; + unsigned long long int a_ulonglongint; #endif - float a_float; - double a_double; - long double a_longdouble; - int a_char; + float a_float; + double a_double; + long double a_longdouble; + int a_char; #if HAVE_WINT_T - wint_t a_wide_char; + wint_t a_wide_char; #endif - const char* a_string; + const char* a_string; #if HAVE_WCHAR_T - const wchar_t* a_wide_string; + const wchar_t* a_wide_string; #endif - void* a_pointer; - signed char * a_count_schar_pointer; - short * a_count_short_pointer; - int * a_count_int_pointer; - long int * a_count_longint_pointer; + void* a_pointer; + signed char * a_count_schar_pointer; + short * a_count_short_pointer; + int * a_count_int_pointer; + long int * a_count_longint_pointer; #if HAVE_LONG_LONG_INT - long long int * a_count_longlongint_pointer; + long long int * a_count_longlongint_pointer; #endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ - const uint8_t * a_u8_string; - const uint16_t * a_u16_string; - const uint32_t * a_u32_string; + const uint8_t * a_u8_string; + const uint16_t * a_u16_string; + const uint32_t * a_u32_string; #endif } a; diff --git a/gettext-runtime/intl/printf-parse.c b/gettext-runtime/intl/printf-parse.c index 6245337cf..3f3174d06 100644 --- a/gettext-runtime/intl/printf-parse.c +++ b/gettext-runtime/intl/printf-parse.c @@ -81,10 +81,10 @@ STATIC int PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) { - const CHAR_T *cp = format; /* pointer into format */ - size_t arg_posn = 0; /* number of regular arguments consumed */ - size_t d_allocated; /* allocated elements of d->dir */ - size_t a_allocated; /* allocated elements of a->arg */ + const CHAR_T *cp = format; /* pointer into format */ + size_t arg_posn = 0; /* number of regular arguments consumed */ + size_t d_allocated; /* allocated elements of d->dir */ + size_t a_allocated; /* allocated elements of a->arg */ size_t max_width_length = 0; size_t max_precision_length = 0; @@ -100,501 +100,501 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) a->arg = NULL; #define REGISTER_ARG(_index_,_type_) \ - { \ - size_t n = (_index_); \ - if (n >= a_allocated) \ - { \ - size_t memory_size; \ - argument *memory; \ - \ - a_allocated = xtimes (a_allocated, 2); \ - if (a_allocated <= n) \ - a_allocated = xsum (n, 1); \ - memory_size = xtimes (a_allocated, sizeof (argument)); \ - if (size_overflow_p (memory_size)) \ - /* Overflow, would lead to out of memory. */ \ - goto out_of_memory; \ - memory = (argument *) (a->arg \ - ? realloc (a->arg, memory_size) \ - : malloc (memory_size)); \ - if (memory == NULL) \ - /* Out of memory. */ \ - goto out_of_memory; \ - a->arg = memory; \ - } \ - while (a->count <= n) \ - a->arg[a->count++].type = TYPE_NONE; \ - if (a->arg[n].type == TYPE_NONE) \ - a->arg[n].type = (_type_); \ - else if (a->arg[n].type != (_type_)) \ - /* Ambiguous type for positional argument. */ \ - goto error; \ + { \ + size_t n = (_index_); \ + if (n >= a_allocated) \ + { \ + size_t memory_size; \ + argument *memory; \ + \ + a_allocated = xtimes (a_allocated, 2); \ + if (a_allocated <= n) \ + a_allocated = xsum (n, 1); \ + memory_size = xtimes (a_allocated, sizeof (argument)); \ + if (size_overflow_p (memory_size)) \ + /* Overflow, would lead to out of memory. */ \ + goto out_of_memory; \ + memory = (argument *) (a->arg \ + ? realloc (a->arg, memory_size) \ + : malloc (memory_size)); \ + if (memory == NULL) \ + /* Out of memory. */ \ + goto out_of_memory; \ + a->arg = memory; \ + } \ + while (a->count <= n) \ + a->arg[a->count++].type = TYPE_NONE; \ + if (a->arg[n].type == TYPE_NONE) \ + a->arg[n].type = (_type_); \ + else if (a->arg[n].type != (_type_)) \ + /* Ambiguous type for positional argument. */ \ + goto error; \ } while (*cp != '\0') { CHAR_T c = *cp++; if (c == '%') - { - size_t arg_index = ARG_NONE; - DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */ - - /* Initialize the next directive. */ - dp->dir_start = cp - 1; - dp->flags = 0; - dp->width_start = NULL; - dp->width_end = NULL; - dp->width_arg_index = ARG_NONE; - dp->precision_start = NULL; - dp->precision_end = NULL; - dp->precision_arg_index = ARG_NONE; - dp->arg_index = ARG_NONE; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory later. */ - goto error; - arg_index = n - 1; - cp = np + 1; - } - } - - /* Read the flags. */ - for (;;) - { - if (*cp == '\'') - { - dp->flags |= FLAG_GROUP; - cp++; - } - else if (*cp == '-') - { - dp->flags |= FLAG_LEFT; - cp++; - } - else if (*cp == '+') - { - dp->flags |= FLAG_SHOWSIGN; - cp++; - } - else if (*cp == ' ') - { - dp->flags |= FLAG_SPACE; - cp++; - } - else if (*cp == '#') - { - dp->flags |= FLAG_ALT; - cp++; - } - else if (*cp == '0') - { - dp->flags |= FLAG_ZERO; - cp++; - } - else - break; - } - - /* Parse the field width. */ - if (*cp == '*') - { - dp->width_start = cp; - cp++; - dp->width_end = cp; - if (max_width_length < 1) - max_width_length = 1; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory later. */ - goto error; - dp->width_arg_index = n - 1; - cp = np + 1; - } - } - if (dp->width_arg_index == ARG_NONE) - { - dp->width_arg_index = arg_posn++; - if (dp->width_arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->width_arg_index, TYPE_INT); - } - else if (*cp >= '0' && *cp <= '9') - { - size_t width_length; - - dp->width_start = cp; - for (; *cp >= '0' && *cp <= '9'; cp++) - ; - dp->width_end = cp; - width_length = dp->width_end - dp->width_start; - if (max_width_length < width_length) - max_width_length = width_length; - } - - /* Parse the precision. */ - if (*cp == '.') - { - cp++; - if (*cp == '*') - { - dp->precision_start = cp - 1; - cp++; - dp->precision_end = cp; - if (max_precision_length < 2) - max_precision_length = 2; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory - later. */ - goto error; - dp->precision_arg_index = n - 1; - cp = np + 1; - } - } - if (dp->precision_arg_index == ARG_NONE) - { - dp->precision_arg_index = arg_posn++; - if (dp->precision_arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->precision_arg_index, TYPE_INT); - } - else - { - size_t precision_length; - - dp->precision_start = cp - 1; - for (; *cp >= '0' && *cp <= '9'; cp++) - ; - dp->precision_end = cp; - precision_length = dp->precision_end - dp->precision_start; - if (max_precision_length < precision_length) - max_precision_length = precision_length; - } - } - - { - arg_type type; - - /* Parse argument type/size specifiers. */ - { - int flags = 0; - - for (;;) - { - if (*cp == 'h') - { - flags |= (1 << (flags & 1)); - cp++; - } - else if (*cp == 'L') - { - flags |= 4; - cp++; - } - else if (*cp == 'l') - { - flags += 8; - cp++; - } - else if (*cp == 'j') - { - if (sizeof (intmax_t) > sizeof (long)) - { - /* intmax_t = long long */ - flags += 16; - } - else if (sizeof (intmax_t) > sizeof (int)) - { - /* intmax_t = long */ - flags += 8; - } - cp++; - } - else if (*cp == 'z' || *cp == 'Z') - { - /* 'z' is standardized in ISO C 99, but glibc uses 'Z' - because the warning facility in gcc-2.95.2 understands - only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ - if (sizeof (size_t) > sizeof (long)) - { - /* size_t = long long */ - flags += 16; - } - else if (sizeof (size_t) > sizeof (int)) - { - /* size_t = long */ - flags += 8; - } - cp++; - } - else if (*cp == 't') - { - if (sizeof (ptrdiff_t) > sizeof (long)) - { - /* ptrdiff_t = long long */ - flags += 16; - } - else if (sizeof (ptrdiff_t) > sizeof (int)) - { - /* ptrdiff_t = long */ - flags += 8; - } - cp++; - } + { + size_t arg_index = ARG_NONE; + DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */ + + /* Initialize the next directive. */ + dp->dir_start = cp - 1; + dp->flags = 0; + dp->width_start = NULL; + dp->width_end = NULL; + dp->width_arg_index = ARG_NONE; + dp->precision_start = NULL; + dp->precision_end = NULL; + dp->precision_arg_index = ARG_NONE; + dp->arg_index = ARG_NONE; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory later. */ + goto error; + arg_index = n - 1; + cp = np + 1; + } + } + + /* Read the flags. */ + for (;;) + { + if (*cp == '\'') + { + dp->flags |= FLAG_GROUP; + cp++; + } + else if (*cp == '-') + { + dp->flags |= FLAG_LEFT; + cp++; + } + else if (*cp == '+') + { + dp->flags |= FLAG_SHOWSIGN; + cp++; + } + else if (*cp == ' ') + { + dp->flags |= FLAG_SPACE; + cp++; + } + else if (*cp == '#') + { + dp->flags |= FLAG_ALT; + cp++; + } + else if (*cp == '0') + { + dp->flags |= FLAG_ZERO; + cp++; + } + else + break; + } + + /* Parse the field width. */ + if (*cp == '*') + { + dp->width_start = cp; + cp++; + dp->width_end = cp; + if (max_width_length < 1) + max_width_length = 1; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory later. */ + goto error; + dp->width_arg_index = n - 1; + cp = np + 1; + } + } + if (dp->width_arg_index == ARG_NONE) + { + dp->width_arg_index = arg_posn++; + if (dp->width_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->width_arg_index, TYPE_INT); + } + else if (*cp >= '0' && *cp <= '9') + { + size_t width_length; + + dp->width_start = cp; + for (; *cp >= '0' && *cp <= '9'; cp++) + ; + dp->width_end = cp; + width_length = dp->width_end - dp->width_start; + if (max_width_length < width_length) + max_width_length = width_length; + } + + /* Parse the precision. */ + if (*cp == '.') + { + cp++; + if (*cp == '*') + { + dp->precision_start = cp - 1; + cp++; + dp->precision_end = cp; + if (max_precision_length < 2) + max_precision_length = 2; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory + later. */ + goto error; + dp->precision_arg_index = n - 1; + cp = np + 1; + } + } + if (dp->precision_arg_index == ARG_NONE) + { + dp->precision_arg_index = arg_posn++; + if (dp->precision_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->precision_arg_index, TYPE_INT); + } + else + { + size_t precision_length; + + dp->precision_start = cp - 1; + for (; *cp >= '0' && *cp <= '9'; cp++) + ; + dp->precision_end = cp; + precision_length = dp->precision_end - dp->precision_start; + if (max_precision_length < precision_length) + max_precision_length = precision_length; + } + } + + { + arg_type type; + + /* Parse argument type/size specifiers. */ + { + int flags = 0; + + for (;;) + { + if (*cp == 'h') + { + flags |= (1 << (flags & 1)); + cp++; + } + else if (*cp == 'L') + { + flags |= 4; + cp++; + } + else if (*cp == 'l') + { + flags += 8; + cp++; + } + else if (*cp == 'j') + { + if (sizeof (intmax_t) > sizeof (long)) + { + /* intmax_t = long long */ + flags += 16; + } + else if (sizeof (intmax_t) > sizeof (int)) + { + /* intmax_t = long */ + flags += 8; + } + cp++; + } + else if (*cp == 'z' || *cp == 'Z') + { + /* 'z' is standardized in ISO C 99, but glibc uses 'Z' + because the warning facility in gcc-2.95.2 understands + only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ + if (sizeof (size_t) > sizeof (long)) + { + /* size_t = long long */ + flags += 16; + } + else if (sizeof (size_t) > sizeof (int)) + { + /* size_t = long */ + flags += 8; + } + cp++; + } + else if (*cp == 't') + { + if (sizeof (ptrdiff_t) > sizeof (long)) + { + /* ptrdiff_t = long long */ + flags += 16; + } + else if (sizeof (ptrdiff_t) > sizeof (int)) + { + /* ptrdiff_t = long */ + flags += 8; + } + cp++; + } #if defined __APPLE__ && defined __MACH__ - /* On MacOS X 10.3, PRIdMAX is defined as "qd". - We cannot change it to "lld" because PRIdMAX must also - be understood by the system's printf routines. */ - else if (*cp == 'q') - { - if (64 / 8 > sizeof (long)) - { - /* int64_t = long long */ - flags += 16; - } - else - { - /* int64_t = long */ - flags += 8; - } - cp++; - } + /* On MacOS X 10.3, PRIdMAX is defined as "qd". + We cannot change it to "lld" because PRIdMAX must also + be understood by the system's printf routines. */ + else if (*cp == 'q') + { + if (64 / 8 > sizeof (long)) + { + /* int64_t = long long */ + flags += 16; + } + else + { + /* int64_t = long */ + flags += 8; + } + cp++; + } #endif #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* On native Win32, PRIdMAX is defined as "I64d". - We cannot change it to "lld" because PRIdMAX must also - be understood by the system's printf routines. */ - else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4') - { - if (64 / 8 > sizeof (long)) - { - /* __int64 = long long */ - flags += 16; - } - else - { - /* __int64 = long */ - flags += 8; - } - cp += 3; - } + /* On native Win32, PRIdMAX is defined as "I64d". + We cannot change it to "lld" because PRIdMAX must also + be understood by the system's printf routines. */ + else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4') + { + if (64 / 8 > sizeof (long)) + { + /* __int64 = long long */ + flags += 16; + } + else + { + /* __int64 = long */ + flags += 8; + } + cp += 3; + } #endif - else - break; - } - - /* Read the conversion character. */ - c = *cp++; - switch (c) - { - case 'd': case 'i': + else + break; + } + + /* Read the conversion character. */ + c = *cp++; + switch (c) + { + case 'd': case 'i': #if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_LONGLONGINT; - else + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_LONGLONGINT; + else #endif - /* If 'long long' exists and is the same as 'long', we parse - "lld" into TYPE_LONGINT. */ - if (flags >= 8) - type = TYPE_LONGINT; - else if (flags & 2) - type = TYPE_SCHAR; - else if (flags & 1) - type = TYPE_SHORT; - else - type = TYPE_INT; - break; - case 'o': case 'u': case 'x': case 'X': + /* If 'long long' exists and is the same as 'long', we parse + "lld" into TYPE_LONGINT. */ + if (flags >= 8) + type = TYPE_LONGINT; + else if (flags & 2) + type = TYPE_SCHAR; + else if (flags & 1) + type = TYPE_SHORT; + else + type = TYPE_INT; + break; + case 'o': case 'u': case 'x': case 'X': #if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_ULONGLONGINT; - else + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_ULONGLONGINT; + else #endif - /* If 'unsigned long long' exists and is the same as - 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ - if (flags >= 8) - type = TYPE_ULONGINT; - else if (flags & 2) - type = TYPE_UCHAR; - else if (flags & 1) - type = TYPE_USHORT; - else - type = TYPE_UINT; - break; - case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': - case 'a': case 'A': - if (flags >= 16 || (flags & 4)) - type = TYPE_LONGDOUBLE; - else - type = TYPE_DOUBLE; - break; - case 'c': - if (flags >= 8) + /* If 'unsigned long long' exists and is the same as + 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ + if (flags >= 8) + type = TYPE_ULONGINT; + else if (flags & 2) + type = TYPE_UCHAR; + else if (flags & 1) + type = TYPE_USHORT; + else + type = TYPE_UINT; + break; + case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': + case 'a': case 'A': + if (flags >= 16 || (flags & 4)) + type = TYPE_LONGDOUBLE; + else + type = TYPE_DOUBLE; + break; + case 'c': + if (flags >= 8) #if HAVE_WINT_T - type = TYPE_WIDE_CHAR; + type = TYPE_WIDE_CHAR; #else - goto error; + goto error; #endif - else - type = TYPE_CHAR; - break; + else + type = TYPE_CHAR; + break; #if HAVE_WINT_T - case 'C': - type = TYPE_WIDE_CHAR; - c = 'c'; - break; + case 'C': + type = TYPE_WIDE_CHAR; + c = 'c'; + break; #endif - case 's': - if (flags >= 8) + case 's': + if (flags >= 8) #if HAVE_WCHAR_T - type = TYPE_WIDE_STRING; + type = TYPE_WIDE_STRING; #else - goto error; + goto error; #endif - else - type = TYPE_STRING; - break; + else + type = TYPE_STRING; + break; #if HAVE_WCHAR_T - case 'S': - type = TYPE_WIDE_STRING; - c = 's'; - break; + case 'S': + type = TYPE_WIDE_STRING; + c = 's'; + break; #endif - case 'p': - type = TYPE_POINTER; - break; - case 'n': + case 'p': + type = TYPE_POINTER; + break; + case 'n': #if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_COUNT_LONGLONGINT_POINTER; - else + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_COUNT_LONGLONGINT_POINTER; + else #endif - /* If 'long long' exists and is the same as 'long', we parse - "lln" into TYPE_COUNT_LONGINT_POINTER. */ - if (flags >= 8) - type = TYPE_COUNT_LONGINT_POINTER; - else if (flags & 2) - type = TYPE_COUNT_SCHAR_POINTER; - else if (flags & 1) - type = TYPE_COUNT_SHORT_POINTER; - else - type = TYPE_COUNT_INT_POINTER; - break; + /* If 'long long' exists and is the same as 'long', we parse + "lln" into TYPE_COUNT_LONGINT_POINTER. */ + if (flags >= 8) + type = TYPE_COUNT_LONGINT_POINTER; + else if (flags & 2) + type = TYPE_COUNT_SCHAR_POINTER; + else if (flags & 1) + type = TYPE_COUNT_SHORT_POINTER; + else + type = TYPE_COUNT_INT_POINTER; + break; #if ENABLE_UNISTDIO - /* The unistdio extensions. */ - case 'U': - if (flags >= 16) - type = TYPE_U32_STRING; - else if (flags >= 8) - type = TYPE_U16_STRING; - else - type = TYPE_U8_STRING; - break; + /* The unistdio extensions. */ + case 'U': + if (flags >= 16) + type = TYPE_U32_STRING; + else if (flags >= 8) + type = TYPE_U16_STRING; + else + type = TYPE_U8_STRING; + break; #endif - case '%': - type = TYPE_NONE; - break; - default: - /* Unknown conversion character. */ - goto error; - } - } - - if (type != TYPE_NONE) - { - dp->arg_index = arg_index; - if (dp->arg_index == ARG_NONE) - { - dp->arg_index = arg_posn++; - if (dp->arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->arg_index, type); - } - dp->conversion = c; - dp->dir_end = cp; - } - - d->count++; - if (d->count >= d_allocated) - { - size_t memory_size; - DIRECTIVE *memory; - - d_allocated = xtimes (d_allocated, 2); - memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); - if (size_overflow_p (memory_size)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - memory = (DIRECTIVE *) realloc (d->dir, memory_size); - if (memory == NULL) - /* Out of memory. */ - goto out_of_memory; - d->dir = memory; - } - } + case '%': + type = TYPE_NONE; + break; + default: + /* Unknown conversion character. */ + goto error; + } + } + + if (type != TYPE_NONE) + { + dp->arg_index = arg_index; + if (dp->arg_index == ARG_NONE) + { + dp->arg_index = arg_posn++; + if (dp->arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->arg_index, type); + } + dp->conversion = c; + dp->dir_end = cp; + } + + d->count++; + if (d->count >= d_allocated) + { + size_t memory_size; + DIRECTIVE *memory; + + d_allocated = xtimes (d_allocated, 2); + memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); + if (size_overflow_p (memory_size)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + memory = (DIRECTIVE *) realloc (d->dir, memory_size); + if (memory == NULL) + /* Out of memory. */ + goto out_of_memory; + d->dir = memory; + } + } #if CHAR_T_ONLY_ASCII else if (!c_isascii (c)) - { - /* Non-ASCII character. Not supported. */ - goto error; - } + { + /* Non-ASCII character. Not supported. */ + goto error; + } #endif } d->dir[d->count].dir_start = cp; diff --git a/gettext-runtime/intl/printf-parse.h b/gettext-runtime/intl/printf-parse.h index e78533895..51ead29ec 100644 --- a/gettext-runtime/intl/printf-parse.h +++ b/gettext-runtime/intl/printf-parse.h @@ -23,15 +23,15 @@ /* Flags */ -#define FLAG_GROUP 1 /* ' flag */ -#define FLAG_LEFT 2 /* - flag */ -#define FLAG_SHOWSIGN 4 /* + flag */ -#define FLAG_SPACE 8 /* space flag */ -#define FLAG_ALT 16 /* # flag */ -#define FLAG_ZERO 32 +#define FLAG_GROUP 1 /* ' flag */ +#define FLAG_LEFT 2 /* - flag */ +#define FLAG_SHOWSIGN 4 /* + flag */ +#define FLAG_SPACE 8 /* space flag */ +#define FLAG_ALT 16 /* # flag */ +#define FLAG_ZERO 32 /* arg_index value indicating that no argument is consumed. */ -#define ARG_NONE (~(size_t)0) +#define ARG_NONE (~(size_t)0) /* A parsed directive. */ typedef struct diff --git a/gettext-runtime/intl/printf.c b/gettext-runtime/intl/printf.c index 754851404..b7cdc5d82 100644 --- a/gettext-runtime/intl/printf.c +++ b/gettext-runtime/intl/printf.c @@ -104,17 +104,17 @@ libintl_vfprintf (FILE *stream, const char *format, va_list args) char *result = libintl_vasnprintf (NULL, &length, format, args); int retval = -1; if (result != NULL) - { - size_t written = fwrite (result, 1, length, stream); - free (result); - if (written == length) - { - if (length > INT_MAX) - errno = EOVERFLOW; - else - retval = length; - } - } + { + size_t written = fwrite (result, 1, length, stream); + free (result); + if (written == length) + { + if (length > INT_MAX) + errno = EOVERFLOW; + else + retval = length; + } + } return retval; } } @@ -163,17 +163,17 @@ libintl_vsprintf (char *resultbuf, const char *format, va_list args) size_t length = (size_t) ~0 / (4 * sizeof (char)); char *result = libintl_vasnprintf (resultbuf, &length, format, args); if (result != resultbuf) - { - free (result); - return -1; - } + { + free (result); + return -1; + } if (length > INT_MAX) - { - errno = EOVERFLOW; - return -1; - } + { + errno = EOVERFLOW; + return -1; + } else - return length; + return length; } } @@ -211,23 +211,23 @@ libintl_vsnprintf (char *resultbuf, size_t length, const char *format, va_list a size_t maxlength = length; char *result = libintl_vasnprintf (resultbuf, &length, format, args); if (result != resultbuf) - { - if (maxlength > 0) - { - size_t pruned_length = - (length < maxlength ? length : maxlength - 1); - memcpy (resultbuf, result, pruned_length); - resultbuf[pruned_length] = '\0'; - } - free (result); - } + { + if (maxlength > 0) + { + size_t pruned_length = + (length < maxlength ? length : maxlength - 1); + memcpy (resultbuf, result, pruned_length); + resultbuf[pruned_length] = '\0'; + } + free (result); + } if (length > INT_MAX) - { - errno = EOVERFLOW; - return -1; - } + { + errno = EOVERFLOW; + return -1; + } else - return length; + return length; } } @@ -323,20 +323,20 @@ libintl_vfwprintf (FILE *stream, const wchar_t *format, va_list args) wchar_t *result = libintl_vasnwprintf (NULL, &length, format, args); int retval = -1; if (result != NULL) - { - size_t i; - for (i = 0; i < length; i++) - if (fputwc (result[i], stream) == WEOF) - break; - free (result); - if (i == length) - { - if (length > INT_MAX) - errno = EOVERFLOW; - else - retval = length; - } - } + { + size_t i; + for (i = 0; i < length; i++) + if (fputwc (result[i], stream) == WEOF) + break; + free (result); + if (i == length) + { + if (length > INT_MAX) + errno = EOVERFLOW; + else + retval = length; + } + } return retval; } } @@ -385,29 +385,29 @@ libintl_vswprintf (wchar_t *resultbuf, size_t length, const wchar_t *format, va_ size_t maxlength = length; wchar_t *result = libintl_vasnwprintf (resultbuf, &length, format, args); if (result != resultbuf) - { - if (maxlength > 0) - { - size_t pruned_length = - (length < maxlength ? length : maxlength - 1); - memcpy (resultbuf, result, pruned_length * sizeof (wchar_t)); - resultbuf[pruned_length] = 0; - } - free (result); - /* Unlike vsnprintf, which has to return the number of character that - would have been produced if the resultbuf had been sufficiently - large, the vswprintf function has to return a negative value if - the resultbuf was not sufficiently large. */ - if (length >= maxlength) - return -1; - } + { + if (maxlength > 0) + { + size_t pruned_length = + (length < maxlength ? length : maxlength - 1); + memcpy (resultbuf, result, pruned_length * sizeof (wchar_t)); + resultbuf[pruned_length] = 0; + } + free (result); + /* Unlike vsnprintf, which has to return the number of character that + would have been produced if the resultbuf had been sufficiently + large, the vswprintf function has to return a negative value if + the resultbuf was not sufficiently large. */ + if (length >= maxlength) + return -1; + } if (length > INT_MAX) - { - errno = EOVERFLOW; - return -1; - } + { + errno = EOVERFLOW; + return -1; + } else - return length; + return length; } } diff --git a/gettext-runtime/intl/relocatable.c b/gettext-runtime/intl/relocatable.c index b49442003..f1bed781b 100644 --- a/gettext-runtime/intl/relocatable.c +++ b/gettext-runtime/intl/relocatable.c @@ -22,7 +22,7 @@ This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 +# define _GNU_SOURCE 1 #endif #include @@ -102,11 +102,11 @@ static size_t curr_prefix_len; instead of "/"). */ static void set_this_relocation_prefix (const char *orig_prefix_arg, - const char *curr_prefix_arg) + const char *curr_prefix_arg) { if (orig_prefix_arg != NULL && curr_prefix_arg != NULL /* Optimization: if orig_prefix and curr_prefix are equal, the - relocation is a nop. */ + relocation is a nop. */ && strcmp (orig_prefix_arg, curr_prefix_arg) != 0) { /* Duplicate the argument strings. */ @@ -118,14 +118,14 @@ set_this_relocation_prefix (const char *orig_prefix_arg, #ifdef NO_XMALLOC if (memory != NULL) #endif - { - memcpy (memory, orig_prefix_arg, orig_prefix_len + 1); - orig_prefix = memory; - memory += orig_prefix_len + 1; - memcpy (memory, curr_prefix_arg, curr_prefix_len + 1); - curr_prefix = memory; - return; - } + { + memcpy (memory, orig_prefix_arg, orig_prefix_len + 1); + orig_prefix = memory; + memory += orig_prefix_len + 1; + memcpy (memory, curr_prefix_arg, curr_prefix_len + 1); + curr_prefix = memory; + return; + } } orig_prefix = NULL; curr_prefix = NULL; @@ -168,8 +168,8 @@ static #endif char * compute_curr_prefix (const char *orig_installprefix, - const char *orig_installdir, - const char *curr_pathname) + const char *orig_installdir, + const char *curr_pathname) { char *curr_installdir; const char *rel_installdir; @@ -194,9 +194,9 @@ compute_curr_prefix (const char *orig_installprefix, while (p > p_base) { - p--; - if (ISSLASH (*p)) - break; + p--; + if (ISSLASH (*p)) + break; } q = (char *) xmalloc (p - curr_pathname + 1); @@ -219,46 +219,46 @@ compute_curr_prefix (const char *orig_installprefix, while (rp > rel_installdir && cp > cp_base) { - bool same = false; - const char *rpi = rp; - const char *cpi = cp; - - while (rpi > rel_installdir && cpi > cp_base) - { - rpi--; - cpi--; - if (ISSLASH (*rpi) || ISSLASH (*cpi)) - { - if (ISSLASH (*rpi) && ISSLASH (*cpi)) - same = true; - break; - } - /* Do case-insensitive comparison if the file system is always or - often case-insensitive. It's better to accept the comparison - if the difference is only in case, rather than to fail. */ + bool same = false; + const char *rpi = rp; + const char *cpi = cp; + + while (rpi > rel_installdir && cpi > cp_base) + { + rpi--; + cpi--; + if (ISSLASH (*rpi) || ISSLASH (*cpi)) + { + if (ISSLASH (*rpi) && ISSLASH (*cpi)) + same = true; + break; + } + /* Do case-insensitive comparison if the file system is always or + often case-insensitive. It's better to accept the comparison + if the difference is only in case, rather than to fail. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ - /* Win32, Cygwin, OS/2, DOS - case insignificant file system */ - if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi) - != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi)) - break; + /* Win32, Cygwin, OS/2, DOS - case insignificant file system */ + if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi) + != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi)) + break; #else - if (*rpi != *cpi) - break; + if (*rpi != *cpi) + break; #endif - } - if (!same) - break; - /* The last pathname component was the same. opi and cpi now point - to the slash before it. */ - rp = rpi; - cp = cpi; + } + if (!same) + break; + /* The last pathname component was the same. opi and cpi now point + to the slash before it. */ + rp = rpi; + cp = cpi; } if (rp > rel_installdir) { - /* Unexpected: The curr_installdir does not end with rel_installdir. */ - free (curr_installdir); - return NULL; + /* Unexpected: The curr_installdir does not end with rel_installdir. */ + free (curr_installdir); + return NULL; } { @@ -268,10 +268,10 @@ compute_curr_prefix (const char *orig_installprefix, curr_prefix = (char *) xmalloc (curr_prefix_len + 1); #ifdef NO_XMALLOC if (curr_prefix == NULL) - { - free (curr_installdir); - return NULL; - } + { + free (curr_installdir); + return NULL; + } #endif memcpy (curr_prefix, curr_installdir, curr_prefix_len); curr_prefix[curr_prefix_len] = '\0'; @@ -305,30 +305,30 @@ DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved) static char location[MAX_PATH]; if (!GetModuleFileName (module_handle, location, sizeof (location))) - /* Shouldn't happen. */ - return FALSE; + /* Shouldn't happen. */ + return FALSE; if (!IS_PATH_WITH_DIR (location)) - /* Shouldn't happen. */ - return FALSE; + /* Shouldn't happen. */ + return FALSE; { #if defined __CYGWIN__ - /* On Cygwin, we need to convert paths coming from Win32 system calls - to the Unix-like slashified notation. */ - static char location_as_posix_path[2 * MAX_PATH]; - /* There's no error return defined for cygwin_conv_to_posix_path. - See cygwin-api/func-cygwin-conv-to-posix-path.html. - Does it overflow the buffer of expected size MAX_PATH or does it - truncate the path? I don't know. Let's catch both. */ - cygwin_conv_to_posix_path (location, location_as_posix_path); - location_as_posix_path[MAX_PATH - 1] = '\0'; - if (strlen (location_as_posix_path) >= MAX_PATH - 1) - /* A sign of buffer overflow or path truncation. */ - return FALSE; - shared_library_fullname = strdup (location_as_posix_path); + /* On Cygwin, we need to convert paths coming from Win32 system calls + to the Unix-like slashified notation. */ + static char location_as_posix_path[2 * MAX_PATH]; + /* There's no error return defined for cygwin_conv_to_posix_path. + See cygwin-api/func-cygwin-conv-to-posix-path.html. + Does it overflow the buffer of expected size MAX_PATH or does it + truncate the path? I don't know. Let's catch both. */ + cygwin_conv_to_posix_path (location, location_as_posix_path); + location_as_posix_path[MAX_PATH - 1] = '\0'; + if (strlen (location_as_posix_path) >= MAX_PATH - 1) + /* A sign of buffer overflow or path truncation. */ + return FALSE; + shared_library_fullname = strdup (location_as_posix_path); #else - shared_library_fullname = strdup (location); + shared_library_fullname = strdup (location); #endif } } @@ -351,37 +351,37 @@ find_shared_library_fullname () { unsigned long address = (unsigned long) &find_shared_library_fullname; for (;;) - { - unsigned long start, end; - int c; - - if (fscanf (fp, "%lx-%lx", &start, &end) != 2) - break; - if (address >= start && address <= end - 1) - { - /* Found it. Now see if this line contains a filename. */ - while (c = getc (fp), c != EOF && c != '\n' && c != '/') - continue; - if (c == '/') - { - size_t size; - int len; - - ungetc (c, fp); - shared_library_fullname = NULL; size = 0; - len = getline (&shared_library_fullname, &size, fp); - if (len >= 0) - { - /* Success: filled shared_library_fullname. */ - if (len > 0 && shared_library_fullname[len - 1] == '\n') - shared_library_fullname[len - 1] = '\0'; - } - } - break; - } - while (c = getc (fp), c != EOF && c != '\n') - continue; - } + { + unsigned long start, end; + int c; + + if (fscanf (fp, "%lx-%lx", &start, &end) != 2) + break; + if (address >= start && address <= end - 1) + { + /* Found it. Now see if this line contains a filename. */ + while (c = getc (fp), c != EOF && c != '\n' && c != '/') + continue; + if (c == '/') + { + size_t size; + int len; + + ungetc (c, fp); + shared_library_fullname = NULL; size = 0; + len = getline (&shared_library_fullname, &size, fp); + if (len >= 0) + { + /* Success: filled shared_library_fullname. */ + if (len > 0 && shared_library_fullname[len - 1] == '\n') + shared_library_fullname[len - 1] = '\0'; + } + } + break; + } + while (c = getc (fp), c != EOF && c != '\n') + continue; + } fclose (fp); } #endif @@ -422,28 +422,28 @@ relocate (const char *pathname) if (!initialized) { /* At this point, orig_prefix and curr_prefix likely have already been - set through the main program's set_program_name_and_installdir - function. This is sufficient in the case that the library has - initially been installed in the same orig_prefix. But we can do - better, to also cover the cases that 1. it has been installed - in a different prefix before being moved to orig_prefix and (later) - to curr_prefix, 2. unlike the program, it has not moved away from - orig_prefix. */ + set through the main program's set_program_name_and_installdir + function. This is sufficient in the case that the library has + initially been installed in the same orig_prefix. But we can do + better, to also cover the cases that 1. it has been installed + in a different prefix before being moved to orig_prefix and (later) + to curr_prefix, 2. unlike the program, it has not moved away from + orig_prefix. */ const char *orig_installprefix = INSTALLPREFIX; const char *orig_installdir = INSTALLDIR; char *curr_prefix_better; curr_prefix_better = - compute_curr_prefix (orig_installprefix, orig_installdir, - get_shared_library_fullname ()); + compute_curr_prefix (orig_installprefix, orig_installdir, + get_shared_library_fullname ()); set_relocation_prefix (orig_installprefix, - curr_prefix_better != NULL - ? curr_prefix_better - : curr_prefix); + curr_prefix_better != NULL + ? curr_prefix_better + : curr_prefix); if (curr_prefix_better != NULL) - free (curr_prefix_better); + free (curr_prefix_better); initialized = 1; } @@ -457,34 +457,34 @@ relocate (const char *pathname) && strncmp (pathname, orig_prefix, orig_prefix_len) == 0) { if (pathname[orig_prefix_len] == '\0') - { - /* pathname equals orig_prefix. */ - char *result = (char *) xmalloc (strlen (curr_prefix) + 1); + { + /* pathname equals orig_prefix. */ + char *result = (char *) xmalloc (strlen (curr_prefix) + 1); #ifdef NO_XMALLOC - if (result != NULL) + if (result != NULL) #endif - { - strcpy (result, curr_prefix); - return result; - } - } + { + strcpy (result, curr_prefix); + return result; + } + } else if (ISSLASH (pathname[orig_prefix_len])) - { - /* pathname starts with orig_prefix. */ - const char *pathname_tail = &pathname[orig_prefix_len]; - char *result = - (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1); + { + /* pathname starts with orig_prefix. */ + const char *pathname_tail = &pathname[orig_prefix_len]; + char *result = + (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1); #ifdef NO_XMALLOC - if (result != NULL) + if (result != NULL) #endif - { - memcpy (result, curr_prefix, curr_prefix_len); - strcpy (result + curr_prefix_len, pathname_tail); - return result; - } - } + { + memcpy (result, curr_prefix, curr_prefix_len); + strcpy (result + curr_prefix_len, pathname_tail); + return result; + } + } } /* Nothing to relocate. */ return pathname; diff --git a/gettext-runtime/intl/relocatable.h b/gettext-runtime/intl/relocatable.h index 5dfd71083..3acb5343e 100644 --- a/gettext-runtime/intl/relocatable.h +++ b/gettext-runtime/intl/relocatable.h @@ -46,7 +46,7 @@ extern "C" { instead of "/"). */ extern RELOCATABLE_DLL_EXPORTED void set_relocation_prefix (const char *orig_prefix, - const char *curr_prefix); + const char *curr_prefix); /* Returns the pathname, relocated according to the current installation directory. @@ -65,8 +65,8 @@ extern const char * relocate (const char *pathname); file, and the current pathname of this file. Returns it, freshly allocated. Returns NULL upon failure. */ extern char * compute_curr_prefix (const char *orig_installprefix, - const char *orig_installdir, - const char *curr_pathname); + const char *orig_installdir, + const char *curr_pathname); #else diff --git a/gettext-runtime/intl/threadlib.c b/gettext-runtime/intl/threadlib.c index f62f46c82..cb4fe4f05 100644 --- a/gettext-runtime/intl/threadlib.c +++ b/gettext-runtime/intl/threadlib.c @@ -49,16 +49,16 @@ glthread_in_use (void) pthread_t thread; if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) - /* Thread creation failed. */ - result = 0; + /* Thread creation failed. */ + result = 0; else - { - /* Thread creation works. */ - void *retval; - if (pthread_join (thread, &retval) != 0) - abort (); - result = 1; - } + { + /* Thread creation works. */ + void *retval; + if (pthread_join (thread, &retval) != 0) + abort (); + result = 1; + } tested = 1; } return result; diff --git a/gettext-runtime/intl/tsearch.c b/gettext-runtime/intl/tsearch.c index d549dd45a..5f2da1b44 100644 --- a/gettext-runtime/intl/tsearch.c +++ b/gettext-runtime/intl/tsearch.c @@ -179,7 +179,7 @@ check_tree (node root) edges between GPARENTP and ROOTP. */ static void maybe_split_for_insert (node *rootp, node *parentp, node *gparentp, - int p_r, int gp_r, int mode) + int p_r, int gp_r, int mode) { node root = *rootp; node *rp, *lp; @@ -193,67 +193,67 @@ maybe_split_for_insert (node *rootp, node *parentp, node *gparentp, /* This node becomes red, its successors black. */ root->red = 1; if (*rp) - (*rp)->red = 0; + (*rp)->red = 0; if (*lp) - (*lp)->red = 0; + (*lp)->red = 0; /* If the parent of this node is also red, we have to do - rotations. */ + rotations. */ if (parentp != NULL && (*parentp)->red) - { - node gp = *gparentp; - node p = *parentp; - /* There are two main cases: - 1. The edge types (left or right) of the two red edges differ. - 2. Both red edges are of the same type. - There exist two symmetries of each case, so there is a total of - 4 cases. */ - if ((p_r > 0) != (gp_r > 0)) - { - /* Put the child at the top of the tree, with its parent - and grandparent as successors. */ - p->red = 1; - gp->red = 1; - root->red = 0; - if (p_r < 0) - { - /* Child is left of parent. */ - p->left = *rp; - *rp = p; - gp->right = *lp; - *lp = gp; - } - else - { - /* Child is right of parent. */ - p->right = *lp; - *lp = p; - gp->left = *rp; - *rp = gp; - } - *gparentp = root; - } - else - { - *gparentp = *parentp; - /* Parent becomes the top of the tree, grandparent and - child are its successors. */ - p->red = 0; - gp->red = 1; - if (p_r < 0) - { - /* Left edges. */ - gp->left = p->right; - p->right = gp; - } - else - { - /* Right edges. */ - gp->right = p->left; - p->left = gp; - } - } - } + { + node gp = *gparentp; + node p = *parentp; + /* There are two main cases: + 1. The edge types (left or right) of the two red edges differ. + 2. Both red edges are of the same type. + There exist two symmetries of each case, so there is a total of + 4 cases. */ + if ((p_r > 0) != (gp_r > 0)) + { + /* Put the child at the top of the tree, with its parent + and grandparent as successors. */ + p->red = 1; + gp->red = 1; + root->red = 0; + if (p_r < 0) + { + /* Child is left of parent. */ + p->left = *rp; + *rp = p; + gp->right = *lp; + *lp = gp; + } + else + { + /* Child is right of parent. */ + p->right = *lp; + *lp = p; + gp->left = *rp; + *rp = gp; + } + *gparentp = root; + } + else + { + *gparentp = *parentp; + /* Parent becomes the top of the tree, grandparent and + child are its successors. */ + p->red = 0; + gp->red = 1; + if (p_r < 0) + { + /* Left edges. */ + gp->left = p->right; + p->right = gp; + } + else + { + /* Right edges. */ + gp->right = p->left; + p->left = gp; + } + } + } } } @@ -284,16 +284,16 @@ __tsearch (const void *key, void **vrootp, __compar_fn_t compar) node root = *rootp; r = (*compar) (key, root->key); if (r == 0) - return root; + return root; maybe_split_for_insert (rootp, parentp, gparentp, p_r, gp_r, 0); /* If that did any rotations, parentp and gparentp are now garbage. - That doesn't matter, because the values they contain are never - used again in that case. */ + That doesn't matter, because the values they contain are never + used again in that case. */ nextp = r < 0 ? &root->left : &root->right; if (*nextp == NULL) - break; + break; gparentp = parentp; parentp = rootp; @@ -306,15 +306,15 @@ __tsearch (const void *key, void **vrootp, __compar_fn_t compar) q = (struct node_t *) malloc (sizeof (struct node_t)); if (q != NULL) { - *nextp = q; /* link new node to old */ - q->key = key; /* initialize new node */ + *nextp = q; /* link new node to old */ + q->key = key; /* initialize new node */ q->red = 1; q->left = q->right = NULL; if (nextp != rootp) - /* There may be two red edges in a row now, which we must avoid by - rotating the tree. */ - maybe_split_for_insert (nextp, rootp, parentp, r, p_r, 1); + /* There may be two red edges in a row now, which we must avoid by + rotating the tree. */ + maybe_split_for_insert (nextp, rootp, parentp, r, p_r, 1); } return q; @@ -347,7 +347,7 @@ __tfind (key, vrootp, compar) r = (*compar) (key, root->key); if (r == 0) - return root; + return root; rootp = r < 0 ? &root->left : &root->right; } @@ -386,15 +386,15 @@ __tdelete (const void *key, void **vrootp, __compar_fn_t compar) while ((cmp = (*compar) (key, (*rootp)->key)) != 0) { if (sp == stacksize) - abort (); + abort (); nodestack[sp++] = rootp; p = *rootp; rootp = ((cmp < 0) - ? &(*rootp)->left - : &(*rootp)->right); + ? &(*rootp)->left + : &(*rootp)->right); if (*rootp == NULL) - return NULL; + return NULL; } /* This is bogus if the node to be deleted is the root... this routine @@ -417,15 +417,15 @@ __tdelete (const void *key, void **vrootp, __compar_fn_t compar) { node *parent = rootp, *up = &root->right; for (;;) - { - if (sp == stacksize) - abort (); - nodestack[sp++] = parent; - parent = up; - if ((*up)->left == NULL) - break; - up = &(*up)->left; - } + { + if (sp == stacksize) + abort (); + nodestack[sp++] = parent; + parent = up; + if ((*up)->left == NULL) + break; + up = &(*up)->left; + } unchained = *up; } @@ -440,9 +440,9 @@ __tdelete (const void *key, void **vrootp, __compar_fn_t compar) { q = *nodestack[sp-1]; if (unchained == q->right) - q->right = r; + q->right = r; else - q->left = r; + q->left = r; } if (unchained != root) @@ -450,156 +450,156 @@ __tdelete (const void *key, void **vrootp, __compar_fn_t compar) if (!unchained->red) { /* Now we lost a black edge, which means that the number of black - edges on every path is no longer constant. We must balance the - tree. */ + edges on every path is no longer constant. We must balance the + tree. */ /* NODESTACK now contains all parents of R. R is likely to be NULL - in the first iteration. */ + in the first iteration. */ /* NULL nodes are considered black throughout - this is necessary for - correctness. */ + correctness. */ while (sp > 0 && (r == NULL || !r->red)) - { - node *pp = nodestack[sp - 1]; - p = *pp; - /* Two symmetric cases. */ - if (r == p->left) - { - /* Q is R's brother, P is R's parent. The subtree with root - R has one black edge less than the subtree with root Q. */ - q = p->right; - if (q->red) - { - /* If Q is red, we know that P is black. We rotate P left - so that Q becomes the top node in the tree, with P below - it. P is colored red, Q is colored black. - This action does not change the black edge count for any - leaf in the tree, but we will be able to recognize one - of the following situations, which all require that Q - is black. */ - q->red = 0; - p->red = 1; - /* Left rotate p. */ - p->right = q->left; - q->left = p; - *pp = q; - /* Make sure pp is right if the case below tries to use - it. */ - nodestack[sp++] = pp = &q->left; - q = p->right; - } - /* We know that Q can't be NULL here. We also know that Q is - black. */ - if ((q->left == NULL || !q->left->red) - && (q->right == NULL || !q->right->red)) - { - /* Q has two black successors. We can simply color Q red. - The whole subtree with root P is now missing one black - edge. Note that this action can temporarily make the - tree invalid (if P is red). But we will exit the loop - in that case and set P black, which both makes the tree - valid and also makes the black edge count come out - right. If P is black, we are at least one step closer - to the root and we'll try again the next iteration. */ - q->red = 1; - r = p; - } - else - { - /* Q is black, one of Q's successors is red. We can - repair the tree with one operation and will exit the - loop afterwards. */ - if (q->right == NULL || !q->right->red) - { - /* The left one is red. We perform the same action as - in maybe_split_for_insert where two red edges are - adjacent but point in different directions: - Q's left successor (let's call it Q2) becomes the - top of the subtree we are looking at, its parent (Q) - and grandparent (P) become its successors. The former - successors of Q2 are placed below P and Q. - P becomes black, and Q2 gets the color that P had. - This changes the black edge count only for node R and - its successors. */ - node q2 = q->left; - q2->red = p->red; - p->right = q2->left; - q->left = q2->right; - q2->right = q; - q2->left = p; - *pp = q2; - p->red = 0; - } - else - { - /* It's the right one. Rotate P left. P becomes black, - and Q gets the color that P had. Q's right successor - also becomes black. This changes the black edge - count only for node R and its successors. */ - q->red = p->red; - p->red = 0; - - q->right->red = 0; - - /* left rotate p */ - p->right = q->left; - q->left = p; - *pp = q; - } - - /* We're done. */ - sp = 1; - r = NULL; - } - } - else - { - /* Comments: see above. */ - q = p->left; - if (q->red) - { - q->red = 0; - p->red = 1; - p->left = q->right; - q->right = p; - *pp = q; - nodestack[sp++] = pp = &q->right; - q = p->left; - } - if ((q->right == NULL || !q->right->red) - && (q->left == NULL || !q->left->red)) - { - q->red = 1; - r = p; - } - else - { - if (q->left == NULL || !q->left->red) - { - node q2 = q->right; - q2->red = p->red; - p->left = q2->right; - q->right = q2->left; - q2->left = q; - q2->right = p; - *pp = q2; - p->red = 0; - } - else - { - q->red = p->red; - p->red = 0; - q->left->red = 0; - p->left = q->right; - q->right = p; - *pp = q; - } - sp = 1; - r = NULL; - } - } - --sp; - } + { + node *pp = nodestack[sp - 1]; + p = *pp; + /* Two symmetric cases. */ + if (r == p->left) + { + /* Q is R's brother, P is R's parent. The subtree with root + R has one black edge less than the subtree with root Q. */ + q = p->right; + if (q->red) + { + /* If Q is red, we know that P is black. We rotate P left + so that Q becomes the top node in the tree, with P below + it. P is colored red, Q is colored black. + This action does not change the black edge count for any + leaf in the tree, but we will be able to recognize one + of the following situations, which all require that Q + is black. */ + q->red = 0; + p->red = 1; + /* Left rotate p. */ + p->right = q->left; + q->left = p; + *pp = q; + /* Make sure pp is right if the case below tries to use + it. */ + nodestack[sp++] = pp = &q->left; + q = p->right; + } + /* We know that Q can't be NULL here. We also know that Q is + black. */ + if ((q->left == NULL || !q->left->red) + && (q->right == NULL || !q->right->red)) + { + /* Q has two black successors. We can simply color Q red. + The whole subtree with root P is now missing one black + edge. Note that this action can temporarily make the + tree invalid (if P is red). But we will exit the loop + in that case and set P black, which both makes the tree + valid and also makes the black edge count come out + right. If P is black, we are at least one step closer + to the root and we'll try again the next iteration. */ + q->red = 1; + r = p; + } + else + { + /* Q is black, one of Q's successors is red. We can + repair the tree with one operation and will exit the + loop afterwards. */ + if (q->right == NULL || !q->right->red) + { + /* The left one is red. We perform the same action as + in maybe_split_for_insert where two red edges are + adjacent but point in different directions: + Q's left successor (let's call it Q2) becomes the + top of the subtree we are looking at, its parent (Q) + and grandparent (P) become its successors. The former + successors of Q2 are placed below P and Q. + P becomes black, and Q2 gets the color that P had. + This changes the black edge count only for node R and + its successors. */ + node q2 = q->left; + q2->red = p->red; + p->right = q2->left; + q->left = q2->right; + q2->right = q; + q2->left = p; + *pp = q2; + p->red = 0; + } + else + { + /* It's the right one. Rotate P left. P becomes black, + and Q gets the color that P had. Q's right successor + also becomes black. This changes the black edge + count only for node R and its successors. */ + q->red = p->red; + p->red = 0; + + q->right->red = 0; + + /* left rotate p */ + p->right = q->left; + q->left = p; + *pp = q; + } + + /* We're done. */ + sp = 1; + r = NULL; + } + } + else + { + /* Comments: see above. */ + q = p->left; + if (q->red) + { + q->red = 0; + p->red = 1; + p->left = q->right; + q->right = p; + *pp = q; + nodestack[sp++] = pp = &q->right; + q = p->left; + } + if ((q->right == NULL || !q->right->red) + && (q->left == NULL || !q->left->red)) + { + q->red = 1; + r = p; + } + else + { + if (q->left == NULL || !q->left->red) + { + node q2 = q->right; + q2->red = p->red; + p->left = q2->right; + q->right = q2->left; + q2->left = q; + q2->right = p; + *pp = q2; + p->red = 0; + } + else + { + q->red = p->red; + p->red = 0; + q->left->red = 0; + p->left = q->right; + q->right = p; + *pp = q; + } + sp = 1; + r = NULL; + } + } + --sp; + } if (r != NULL) - r->red = 0; + r->red = 0; } free (unchained); @@ -625,10 +625,10 @@ trecurse (const void *vroot, __action_fn_t action, int level) { (*action) (root, preorder, level); if (root->left != NULL) - trecurse (root->left, action, level + 1); + trecurse (root->left, action, level + 1); (*action) (root, postorder, level); if (root->right != NULL) - trecurse (root->right, action, level + 1); + trecurse (root->right, action, level + 1); (*action) (root, endorder, level); } } diff --git a/gettext-runtime/intl/tsearch.h b/gettext-runtime/intl/tsearch.h index f08e4a913..3d3fd14ce 100644 --- a/gettext-runtime/intl/tsearch.h +++ b/gettext-runtime/intl/tsearch.h @@ -47,18 +47,18 @@ VISIT; If one is found, it is returned. Otherwise, a new element equal to KEY is inserted in the tree and is returned. */ extern void * tsearch (const void *key, void **vrootp, - int (*compar) (const void *, const void *)); + int (*compar) (const void *, const void *)); /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is returned. Otherwise, NULL is returned. */ extern void * tfind (const void *key, void *const *vrootp, - int (*compar) (const void *, const void *)); + int (*compar) (const void *, const void *)); /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is removed from the tree, and its parent node is returned. Otherwise, NULL is returned. */ extern void * tdelete (const void *key, void **vrootp, - int (*compar) (const void *, const void *)); + int (*compar) (const void *, const void *)); /* Perform a depth-first, left-to-right traversal of the tree VROOT. The ACTION function is called: @@ -72,7 +72,7 @@ extern void * tdelete (const void *key, void **vrootp, 2. an indicator which visit of the node this is, 3. the level of the node in the tree (0 for the root). */ extern void twalk (const void *vroot, - void (*action) (const void *, VISIT, int)); + void (*action) (const void *, VISIT, int)); #ifdef __cplusplus } diff --git a/gettext-runtime/intl/vasnprintf.c b/gettext-runtime/intl/vasnprintf.c index d64cec2c5..08949b428 100644 --- a/gettext-runtime/intl/vasnprintf.c +++ b/gettext-runtime/intl/vasnprintf.c @@ -68,13 +68,13 @@ # endif #endif -#include /* localeconv() */ -#include /* snprintf(), sprintf() */ -#include /* abort(), malloc(), realloc(), free() */ -#include /* memcpy(), strlen() */ -#include /* errno */ -#include /* CHAR_BIT */ -#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ +#include /* localeconv() */ +#include /* snprintf(), sprintf() */ +#include /* abort(), malloc(), realloc(), free() */ +#include /* memcpy(), strlen() */ +#include /* errno */ +#include /* CHAR_BIT */ +#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ #if HAVE_NL_LANGINFO # include #endif @@ -365,26 +365,26 @@ multiply (mpn_t src1, mpn_t src2, mpn_t *dest) dlen = len1 + len2; dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t)); if (dp == NULL) - return NULL; + return NULL; for (k = len2; k > 0; ) - dp[--k] = 0; + dp[--k] = 0; for (i = 0; i < len1; i++) - { - mp_limb_t digit1 = p1[i]; - mp_twolimb_t carry = 0; - for (j = 0; j < len2; j++) - { - mp_limb_t digit2 = p2[j]; - carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; - carry += dp[i + j]; - dp[i + j] = (mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; - } - dp[i + len2] = (mp_limb_t) carry; - } + { + mp_limb_t digit1 = p1[i]; + mp_twolimb_t carry = 0; + for (j = 0; j < len2; j++) + { + mp_limb_t digit2 = p2[j]; + carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; + carry += dp[i + j]; + dp[i + j] = (mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; + } + dp[i + len2] = (mp_limb_t) carry; + } /* Normalise. */ while (dlen > 0 && dp[dlen - 1] == 0) - dlen--; + dlen--; dest->nlimbs = dlen; dest->limbs = dp; } @@ -478,12 +478,12 @@ divide (mpn_t a, mpn_t b, mpn_t *q) for (;;) { if (b_len == 0) - /* Division by zero. */ - abort (); + /* Division by zero. */ + abort (); if (b_ptr[b_len - 1] == 0) - b_len--; + b_len--; else - break; + break; } /* Here m = a_len >= 0 and n = b_len > 0. */ @@ -500,261 +500,261 @@ divide (mpn_t a, mpn_t b, mpn_t *q) else if (b_len == 1) { /* n=1: single precision division. - beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */ + beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */ r_ptr = roomptr; q_ptr = roomptr + 1; { - mp_limb_t den = b_ptr[0]; - mp_limb_t remainder = 0; - const mp_limb_t *sourceptr = a_ptr + a_len; - mp_limb_t *destptr = q_ptr + a_len; - size_t count; - for (count = a_len; count > 0; count--) - { - mp_twolimb_t num = - ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr; - *--destptr = num / den; - remainder = num % den; - } - /* Normalise and store r. */ - if (remainder > 0) - { - r_ptr[0] = remainder; - r_len = 1; - } - else - r_len = 0; - /* Normalise q. */ - q_len = a_len; - if (q_ptr[q_len - 1] == 0) - q_len--; + mp_limb_t den = b_ptr[0]; + mp_limb_t remainder = 0; + const mp_limb_t *sourceptr = a_ptr + a_len; + mp_limb_t *destptr = q_ptr + a_len; + size_t count; + for (count = a_len; count > 0; count--) + { + mp_twolimb_t num = + ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr; + *--destptr = num / den; + remainder = num % den; + } + /* Normalise and store r. */ + if (remainder > 0) + { + r_ptr[0] = remainder; + r_len = 1; + } + else + r_len = 0; + /* Normalise q. */ + q_len = a_len; + if (q_ptr[q_len - 1] == 0) + q_len--; } } else { /* n>1: multiple precision division. - beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==> - beta^(m-n-1) <= a/b < beta^(m-n+1). */ + beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==> + beta^(m-n-1) <= a/b < beta^(m-n+1). */ /* Determine s. */ size_t s; { - mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ - s = 31; - if (msd >= 0x10000) - { - msd = msd >> 16; - s -= 16; - } - if (msd >= 0x100) - { - msd = msd >> 8; - s -= 8; - } - if (msd >= 0x10) - { - msd = msd >> 4; - s -= 4; - } - if (msd >= 0x4) - { - msd = msd >> 2; - s -= 2; - } - if (msd >= 0x2) - { - msd = msd >> 1; - s -= 1; - } + mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ + s = 31; + if (msd >= 0x10000) + { + msd = msd >> 16; + s -= 16; + } + if (msd >= 0x100) + { + msd = msd >> 8; + s -= 8; + } + if (msd >= 0x10) + { + msd = msd >> 4; + s -= 4; + } + if (msd >= 0x4) + { + msd = msd >> 2; + s -= 2; + } + if (msd >= 0x2) + { + msd = msd >> 1; + s -= 1; + } } /* 0 <= s < GMP_LIMB_BITS. - Copy b, shifting it left by s bits. */ + Copy b, shifting it left by s bits. */ if (s > 0) - { - tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t)); - if (tmp_roomptr == NULL) - { - free (roomptr); - return NULL; - } - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = tmp_roomptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - /* accu must be zero, since that was how s was determined. */ - if (accu != 0) - abort (); - } - b_ptr = tmp_roomptr; - } + { + tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t)); + if (tmp_roomptr == NULL) + { + free (roomptr); + return NULL; + } + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = tmp_roomptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + /* accu must be zero, since that was how s was determined. */ + if (accu != 0) + abort (); + } + b_ptr = tmp_roomptr; + } /* Copy a, shifting it left by s bits, yields r. - Memory layout: - At the beginning: r = roomptr[0..a_len], - at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */ + Memory layout: + At the beginning: r = roomptr[0..a_len], + at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */ r_ptr = roomptr; if (s == 0) - { - memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t)); - r_ptr[a_len] = 0; - } + { + memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t)); + r_ptr[a_len] = 0; + } else - { - const mp_limb_t *sourceptr = a_ptr; - mp_limb_t *destptr = r_ptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = a_len; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - *destptr++ = (mp_limb_t) accu; - } + { + const mp_limb_t *sourceptr = a_ptr; + mp_limb_t *destptr = r_ptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = a_len; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + *destptr++ = (mp_limb_t) accu; + } q_ptr = roomptr + b_len; q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */ { - size_t j = a_len - b_len; /* m-n */ - mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */ - mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */ - mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */ - ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd; - /* Division loop, traversed m-n+1 times. - j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */ - for (;;) - { - mp_limb_t q_star; - mp_limb_t c1; - if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */ - { - /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */ - mp_twolimb_t num = - ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS) - | r_ptr[j + b_len - 1]; - q_star = num / b_msd; - c1 = num % b_msd; - } - else - { - /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */ - q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */ - /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta - <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta - <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) - {<= beta !}. - If yes, jump directly to the subtraction loop. - (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta - <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */ - if (r_ptr[j + b_len] > b_msd - || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd) - /* r[j+n] >= b[n-1]+1 or - r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a - carry. */ - goto subtract; - } - /* q_star = q*, - c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, 0, decrease it by - b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2 - this can happen only twice. */ - if (c3 > c2) - { - q_star = q_star - 1; /* q* := q* - 1 */ - if (c3 - c2 > b_msdd) - q_star = q_star - 1; /* q* := q* - 1 */ - } - } - if (q_star > 0) - subtract: - { - /* Subtract r := r - b * q* * beta^j. */ - mp_limb_t cr; - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = r_ptr + j; - mp_twolimb_t carry = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - /* Here 0 <= carry <= q*. */ - carry = - carry - + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++ - + (mp_limb_t) ~(*destptr); - /* Here 0 <= carry <= beta*q* + beta-1. */ - *destptr++ = ~(mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; /* <= q* */ - } - cr = (mp_limb_t) carry; - } - /* Subtract cr from r_ptr[j + b_len], then forget about - r_ptr[j + b_len]. */ - if (cr > r_ptr[j + b_len]) - { - /* Subtraction gave a carry. */ - q_star = q_star - 1; /* q* := q* - 1 */ - /* Add b back. */ - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = r_ptr + j; - mp_limb_t carry = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - mp_limb_t source1 = *sourceptr++; - mp_limb_t source2 = *destptr; - *destptr++ = source1 + source2 + carry; - carry = - (carry - ? source1 >= (mp_limb_t) ~source2 - : source1 > (mp_limb_t) ~source2); - } - } - /* Forget about the carry and about r[j+n]. */ - } - } - /* q* is determined. Store it as q[j]. */ - q_ptr[j] = q_star; - if (j == 0) - break; - j--; - } + size_t j = a_len - b_len; /* m-n */ + mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */ + mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */ + mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */ + ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd; + /* Division loop, traversed m-n+1 times. + j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */ + for (;;) + { + mp_limb_t q_star; + mp_limb_t c1; + if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */ + { + /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */ + mp_twolimb_t num = + ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS) + | r_ptr[j + b_len - 1]; + q_star = num / b_msd; + c1 = num % b_msd; + } + else + { + /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */ + q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */ + /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta + <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta + <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) + {<= beta !}. + If yes, jump directly to the subtraction loop. + (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta + <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */ + if (r_ptr[j + b_len] > b_msd + || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd) + /* r[j+n] >= b[n-1]+1 or + r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a + carry. */ + goto subtract; + } + /* q_star = q*, + c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, 0, decrease it by + b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2 + this can happen only twice. */ + if (c3 > c2) + { + q_star = q_star - 1; /* q* := q* - 1 */ + if (c3 - c2 > b_msdd) + q_star = q_star - 1; /* q* := q* - 1 */ + } + } + if (q_star > 0) + subtract: + { + /* Subtract r := r - b * q* * beta^j. */ + mp_limb_t cr; + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = r_ptr + j; + mp_twolimb_t carry = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + /* Here 0 <= carry <= q*. */ + carry = + carry + + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++ + + (mp_limb_t) ~(*destptr); + /* Here 0 <= carry <= beta*q* + beta-1. */ + *destptr++ = ~(mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; /* <= q* */ + } + cr = (mp_limb_t) carry; + } + /* Subtract cr from r_ptr[j + b_len], then forget about + r_ptr[j + b_len]. */ + if (cr > r_ptr[j + b_len]) + { + /* Subtraction gave a carry. */ + q_star = q_star - 1; /* q* := q* - 1 */ + /* Add b back. */ + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = r_ptr + j; + mp_limb_t carry = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + mp_limb_t source1 = *sourceptr++; + mp_limb_t source2 = *destptr; + *destptr++ = source1 + source2 + carry; + carry = + (carry + ? source1 >= (mp_limb_t) ~source2 + : source1 > (mp_limb_t) ~source2); + } + } + /* Forget about the carry and about r[j+n]. */ + } + } + /* q* is determined. Store it as q[j]. */ + q_ptr[j] = q_star; + if (j == 0) + break; + j--; + } } r_len = b_len; /* Normalise q. */ if (q_ptr[q_len - 1] == 0) - q_len--; + q_len--; # if 0 /* Not needed here, since we need r only to compare it with b/2, and - b is shifted left by s bits. */ + b is shifted left by s bits. */ /* Shift r right by s bits. */ if (s > 0) - { - mp_limb_t ptr = r_ptr + r_len; - mp_twolimb_t accu = 0; - size_t count; - for (count = r_len; count > 0; count--) - { - accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS; - accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s); - *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS); - } - } + { + mp_limb_t ptr = r_ptr + r_len; + mp_twolimb_t accu = 0; + size_t count; + for (count = r_len; count > 0; count--) + { + accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS; + accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s); + *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS); + } + } # endif /* Normalise r. */ while (r_len > 0 && r_ptr[r_len - 1] == 0) - r_len--; + r_len--; } /* Compare r << 1 with b. */ if (r_len > b_len) @@ -763,17 +763,17 @@ divide (mpn_t a, mpn_t b, mpn_t *q) size_t i; for (i = b_len;;) { - mp_limb_t r_i = - (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0) - | (i < r_len ? r_ptr[i] << 1 : 0); - mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0); - if (r_i > b_i) - goto increment_q; - if (r_i < b_i) - goto keep_q; - if (i == 0) - break; - i--; + mp_limb_t r_i = + (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0) + | (i < r_len ? r_ptr[i] << 1 : 0); + mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0); + if (r_i > b_i) + goto increment_q; + if (r_i < b_i) + goto keep_q; + if (i == 0) + break; + i--; } } if (q_len > 0 && ((q_ptr[0] & 1) != 0)) @@ -782,8 +782,8 @@ divide (mpn_t a, mpn_t b, mpn_t *q) { size_t i; for (i = 0; i < q_len; i++) - if (++(q_ptr[i]) != 0) - goto keep_q; + if (++(q_ptr[i]) != 0) + goto keep_q; q_ptr[q_len++] = 1; } keep_q: @@ -812,36 +812,36 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes) { char *d_ptr = c_ptr; for (; extra_zeroes > 0; extra_zeroes--) - *d_ptr++ = '0'; + *d_ptr++ = '0'; while (a_len > 0) - { - /* Divide a by 10^9, in-place. */ - mp_limb_t remainder = 0; - mp_limb_t *ptr = a_ptr + a_len; - size_t count; - for (count = a_len; count > 0; count--) - { - mp_twolimb_t num = - ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr; - *ptr = num / 1000000000; - remainder = num % 1000000000; - } - /* Store the remainder as 9 decimal digits. */ - for (count = 9; count > 0; count--) - { - *d_ptr++ = '0' + (remainder % 10); - remainder = remainder / 10; - } - /* Normalize a. */ - if (a_ptr[a_len - 1] == 0) - a_len--; - } + { + /* Divide a by 10^9, in-place. */ + mp_limb_t remainder = 0; + mp_limb_t *ptr = a_ptr + a_len; + size_t count; + for (count = a_len; count > 0; count--) + { + mp_twolimb_t num = + ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr; + *ptr = num / 1000000000; + remainder = num % 1000000000; + } + /* Store the remainder as 9 decimal digits. */ + for (count = 9; count > 0; count--) + { + *d_ptr++ = '0' + (remainder % 10); + remainder = remainder / 10; + } + /* Normalize a. */ + if (a_ptr[a_len - 1] == 0) + a_len--; + } /* Remove leading zeroes. */ while (d_ptr > c_ptr && d_ptr[-1] == '0') - d_ptr--; + d_ptr--; /* But keep at least one zero. */ if (d_ptr == c_ptr) - *d_ptr++ = '0'; + *d_ptr++ = '0'; /* Terminate the string. */ *d_ptr = '\0'; } @@ -886,12 +886,12 @@ decode_long_double (long double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; } # else @@ -901,7 +901,7 @@ decode_long_double (long double x, int *ep, mpn_t *mp) d = (int) y; y -= d; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d; } # endif @@ -913,12 +913,12 @@ decode_long_double (long double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; } #if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess @@ -974,12 +974,12 @@ decode_double (double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; } # else @@ -989,7 +989,7 @@ decode_double (double x, int *ep, mpn_t *mp) d = (int) y; y -= d; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d; } # endif @@ -1001,12 +1001,12 @@ decode_double (double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; } if (!(y == 0.0)) @@ -1064,8 +1064,8 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) abs_n = (n >= 0 ? n : -n); abs_s = (s >= 0 ? s : -s); pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1 - + abs_s / GMP_LIMB_BITS + 1) - * sizeof (mp_limb_t)); + + abs_s / GMP_LIMB_BITS + 1) + * sizeof (mp_limb_t)); if (pow5_ptr == NULL) { free (memory); @@ -1078,26 +1078,26 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) if (abs_n > 0) { static mp_limb_t const small_pow5[13 + 1] = - { - 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, - 48828125, 244140625, 1220703125 - }; + { + 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, + 48828125, 244140625, 1220703125 + }; unsigned int n13; for (n13 = 0; n13 <= abs_n; n13 += 13) - { - mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13]; - size_t j; - mp_twolimb_t carry = 0; - for (j = 0; j < pow5_len; j++) - { - mp_limb_t digit2 = pow5_ptr[j]; - carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; - pow5_ptr[j] = (mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; - } - if (carry > 0) - pow5_ptr[pow5_len++] = (mp_limb_t) carry; - } + { + mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13]; + size_t j; + mp_twolimb_t carry = 0; + for (j = 0; j < pow5_len; j++) + { + mp_limb_t digit2 = pow5_ptr[j]; + carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; + pow5_ptr[j] = (mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; + } + if (carry > 0) + pow5_ptr[pow5_len++] = (mp_limb_t) carry; + } } s_limbs = abs_s / GMP_LIMB_BITS; s_bits = abs_s % GMP_LIMB_BITS; @@ -1105,129 +1105,129 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) { /* Multiply with 2^|s|. */ if (s_bits > 0) - { - mp_limb_t *ptr = pow5_ptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = pow5_len; count > 0; count--) - { - accu += (mp_twolimb_t) *ptr << s_bits; - *ptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - if (accu > 0) - { - *ptr = (mp_limb_t) accu; - pow5_len++; - } - } + { + mp_limb_t *ptr = pow5_ptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = pow5_len; count > 0; count--) + { + accu += (mp_twolimb_t) *ptr << s_bits; + *ptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + if (accu > 0) + { + *ptr = (mp_limb_t) accu; + pow5_len++; + } + } if (s_limbs > 0) - { - size_t count; - for (count = pow5_len; count > 0;) - { - count--; - pow5_ptr[s_limbs + count] = pow5_ptr[count]; - } - for (count = s_limbs; count > 0;) - { - count--; - pow5_ptr[count] = 0; - } - pow5_len += s_limbs; - } + { + size_t count; + for (count = pow5_len; count > 0;) + { + count--; + pow5_ptr[s_limbs + count] = pow5_ptr[count]; + } + for (count = s_limbs; count > 0;) + { + count--; + pow5_ptr[count] = 0; + } + pow5_len += s_limbs; + } pow5.limbs = pow5_ptr; pow5.nlimbs = pow5_len; if (n >= 0) - { - /* Multiply m with pow5. No division needed. */ - z_memory = multiply (m, pow5, &z); - } + { + /* Multiply m with pow5. No division needed. */ + z_memory = multiply (m, pow5, &z); + } else - { - /* Divide m by pow5 and round. */ - z_memory = divide (m, pow5, &z); - } + { + /* Divide m by pow5 and round. */ + z_memory = divide (m, pow5, &z); + } } else { pow5.limbs = pow5_ptr; pow5.nlimbs = pow5_len; if (n >= 0) - { - /* n >= 0, s < 0. - Multiply m with pow5, then divide by 2^|s|. */ - mpn_t numerator; - mpn_t denominator; - void *tmp_memory; - tmp_memory = multiply (m, pow5, &numerator); - if (tmp_memory == NULL) - { - free (pow5_ptr); - free (memory); - return NULL; - } - /* Construct 2^|s|. */ - { - mp_limb_t *ptr = pow5_ptr + pow5_len; - size_t i; - for (i = 0; i < s_limbs; i++) - ptr[i] = 0; - ptr[s_limbs] = (mp_limb_t) 1 << s_bits; - denominator.limbs = ptr; - denominator.nlimbs = s_limbs + 1; - } - z_memory = divide (numerator, denominator, &z); - free (tmp_memory); - } + { + /* n >= 0, s < 0. + Multiply m with pow5, then divide by 2^|s|. */ + mpn_t numerator; + mpn_t denominator; + void *tmp_memory; + tmp_memory = multiply (m, pow5, &numerator); + if (tmp_memory == NULL) + { + free (pow5_ptr); + free (memory); + return NULL; + } + /* Construct 2^|s|. */ + { + mp_limb_t *ptr = pow5_ptr + pow5_len; + size_t i; + for (i = 0; i < s_limbs; i++) + ptr[i] = 0; + ptr[s_limbs] = (mp_limb_t) 1 << s_bits; + denominator.limbs = ptr; + denominator.nlimbs = s_limbs + 1; + } + z_memory = divide (numerator, denominator, &z); + free (tmp_memory); + } else - { - /* n < 0, s > 0. - Multiply m with 2^s, then divide by pow5. */ - mpn_t numerator; - mp_limb_t *num_ptr; - num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1) - * sizeof (mp_limb_t)); - if (num_ptr == NULL) - { - free (pow5_ptr); - free (memory); - return NULL; - } - { - mp_limb_t *destptr = num_ptr; - { - size_t i; - for (i = 0; i < s_limbs; i++) - *destptr++ = 0; - } - if (s_bits > 0) - { - const mp_limb_t *sourceptr = m.limbs; - mp_twolimb_t accu = 0; - size_t count; - for (count = m.nlimbs; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s_bits; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - if (accu > 0) - *destptr++ = (mp_limb_t) accu; - } - else - { - const mp_limb_t *sourceptr = m.limbs; - size_t count; - for (count = m.nlimbs; count > 0; count--) - *destptr++ = *sourceptr++; - } - numerator.limbs = num_ptr; - numerator.nlimbs = destptr - num_ptr; - } - z_memory = divide (numerator, pow5, &z); - free (num_ptr); - } + { + /* n < 0, s > 0. + Multiply m with 2^s, then divide by pow5. */ + mpn_t numerator; + mp_limb_t *num_ptr; + num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1) + * sizeof (mp_limb_t)); + if (num_ptr == NULL) + { + free (pow5_ptr); + free (memory); + return NULL; + } + { + mp_limb_t *destptr = num_ptr; + { + size_t i; + for (i = 0; i < s_limbs; i++) + *destptr++ = 0; + } + if (s_bits > 0) + { + const mp_limb_t *sourceptr = m.limbs; + mp_twolimb_t accu = 0; + size_t count; + for (count = m.nlimbs; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s_bits; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + if (accu > 0) + *destptr++ = (mp_limb_t) accu; + } + else + { + const mp_limb_t *sourceptr = m.limbs; + size_t count; + for (count = m.nlimbs; count > 0; count--) + *destptr++ = *sourceptr++; + } + numerator.limbs = num_ptr; + numerator.nlimbs = destptr - num_ptr; + } + z_memory = divide (numerator, pow5, &z); + free (num_ptr); + } } free (pow5_ptr); free (memory); @@ -1299,35 +1299,35 @@ floorlog10l (long double x) if (y < 0.5L) { while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) - { - y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); - exp -= GMP_LIMB_BITS; - } + { + y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); + exp -= GMP_LIMB_BITS; + } if (y < (1.0L / (1 << 16))) - { - y *= 1.0L * (1 << 16); - exp -= 16; - } + { + y *= 1.0L * (1 << 16); + exp -= 16; + } if (y < (1.0L / (1 << 8))) - { - y *= 1.0L * (1 << 8); - exp -= 8; - } + { + y *= 1.0L * (1 << 8); + exp -= 8; + } if (y < (1.0L / (1 << 4))) - { - y *= 1.0L * (1 << 4); - exp -= 4; - } + { + y *= 1.0L * (1 << 4); + exp -= 4; + } if (y < (1.0L / (1 << 2))) - { - y *= 1.0L * (1 << 2); - exp -= 2; - } + { + y *= 1.0L * (1 << 2); + exp -= 2; + } if (y < (1.0L / (1 << 1))) - { - y *= 1.0L * (1 << 1); - exp -= 1; - } + { + y *= 1.0L * (1 << 1); + exp -= 1; + } } if (!(y >= 0.5L && y < 1.0L)) abort (); @@ -1390,35 +1390,35 @@ floorlog10 (double x) if (y < 0.5) { while (y < (1.0 / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) - { - y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); - exp -= GMP_LIMB_BITS; - } + { + y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); + exp -= GMP_LIMB_BITS; + } if (y < (1.0 / (1 << 16))) - { - y *= 1.0 * (1 << 16); - exp -= 16; - } + { + y *= 1.0 * (1 << 16); + exp -= 16; + } if (y < (1.0 / (1 << 8))) - { - y *= 1.0 * (1 << 8); - exp -= 8; - } + { + y *= 1.0 * (1 << 8); + exp -= 8; + } if (y < (1.0 / (1 << 4))) - { - y *= 1.0 * (1 << 4); - exp -= 4; - } + { + y *= 1.0 * (1 << 4); + exp -= 4; + } if (y < (1.0 / (1 << 2))) - { - y *= 1.0 * (1 << 2); - exp -= 2; - } + { + y *= 1.0 * (1 << 2); + exp -= 2; + } if (y < (1.0 / (1 << 1))) - { - y *= 1.0 * (1 << 1); - exp -= 1; - } + { + y *= 1.0 * (1 << 1); + exp -= 1; + } } if (!(y >= 0.5 && y < 1.0)) abort (); @@ -1477,7 +1477,7 @@ is_borderline (const char *digits, size_t precision) DCHAR_T * VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, - const FCHAR_T *format, va_list args) + const FCHAR_T *format, va_list args) { DIRECTIVES d; arguments a; @@ -1487,8 +1487,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, return NULL; #define CLEANUP() \ - free (d.dir); \ - if (a.arg) \ + free (d.dir); \ + if (a.arg) \ free (a.arg); if (PRINTF_FETCHARGS (args, &a) < 0) @@ -1517,30 +1517,30 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, #if HAVE_ALLOCA if (buf_neededlength < 4000 / sizeof (TCHAR_T)) { - buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); - buf_malloced = NULL; + buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); + buf_malloced = NULL; } else #endif { - size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T)); - if (size_overflow_p (buf_memsize)) - goto out_of_memory_1; - buf = (TCHAR_T *) malloc (buf_memsize); - if (buf == NULL) - goto out_of_memory_1; - buf_malloced = buf; + size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T)); + if (size_overflow_p (buf_memsize)) + goto out_of_memory_1; + buf = (TCHAR_T *) malloc (buf_memsize); + if (buf == NULL) + goto out_of_memory_1; + buf_malloced = buf; } if (resultbuf != NULL) { - result = resultbuf; - allocated = *lengthp; + result = resultbuf; + allocated = *lengthp; } else { - result = NULL; - allocated = 0; + result = NULL; + allocated = 0; } length = 0; /* Invariants: @@ -1550,3881 +1550,3881 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, /* Ensures that allocated >= needed. Aborts through a jump to out_of_memory if needed is SIZE_MAX or otherwise too big. */ #define ENSURE_ALLOCATION(needed) \ - if ((needed) > allocated) \ - { \ - size_t memory_size; \ - DCHAR_T *memory; \ - \ - allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ - if ((needed) > allocated) \ - allocated = (needed); \ - memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ - if (size_overflow_p (memory_size)) \ - goto out_of_memory; \ - if (result == resultbuf || result == NULL) \ - memory = (DCHAR_T *) malloc (memory_size); \ - else \ - memory = (DCHAR_T *) realloc (result, memory_size); \ - if (memory == NULL) \ - goto out_of_memory; \ - if (result == resultbuf && length > 0) \ - DCHAR_CPY (memory, result, length); \ - result = memory; \ + if ((needed) > allocated) \ + { \ + size_t memory_size; \ + DCHAR_T *memory; \ + \ + allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ + if ((needed) > allocated) \ + allocated = (needed); \ + memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ + if (size_overflow_p (memory_size)) \ + goto out_of_memory; \ + if (result == resultbuf || result == NULL) \ + memory = (DCHAR_T *) malloc (memory_size); \ + else \ + memory = (DCHAR_T *) realloc (result, memory_size); \ + if (memory == NULL) \ + goto out_of_memory; \ + if (result == resultbuf && length > 0) \ + DCHAR_CPY (memory, result, length); \ + result = memory; \ } for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) { - if (cp != dp->dir_start) - { - size_t n = dp->dir_start - cp; - size_t augmented_length = xsum (length, n); - - ENSURE_ALLOCATION (augmented_length); - /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we - need that the format string contains only ASCII characters - if FCHAR_T and DCHAR_T are not the same type. */ - if (sizeof (FCHAR_T) == sizeof (DCHAR_T)) - { - DCHAR_CPY (result + length, (const DCHAR_T *) cp, n); - length = augmented_length; - } - else - { - do - result[length++] = (unsigned char) *cp++; - while (--n > 0); - } - } - if (i == d.count) - break; - - /* Execute a single directive. */ - if (dp->conversion == '%') - { - size_t augmented_length; - - if (!(dp->arg_index == ARG_NONE)) - abort (); - augmented_length = xsum (length, 1); - ENSURE_ALLOCATION (augmented_length); - result[length] = '%'; - length = augmented_length; - } - else - { - if (!(dp->arg_index != ARG_NONE)) - abort (); - - if (dp->conversion == 'n') - { - switch (a.arg[dp->arg_index].type) - { - case TYPE_COUNT_SCHAR_POINTER: - *a.arg[dp->arg_index].a.a_count_schar_pointer = length; - break; - case TYPE_COUNT_SHORT_POINTER: - *a.arg[dp->arg_index].a.a_count_short_pointer = length; - break; - case TYPE_COUNT_INT_POINTER: - *a.arg[dp->arg_index].a.a_count_int_pointer = length; - break; - case TYPE_COUNT_LONGINT_POINTER: - *a.arg[dp->arg_index].a.a_count_longint_pointer = length; - break; + if (cp != dp->dir_start) + { + size_t n = dp->dir_start - cp; + size_t augmented_length = xsum (length, n); + + ENSURE_ALLOCATION (augmented_length); + /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we + need that the format string contains only ASCII characters + if FCHAR_T and DCHAR_T are not the same type. */ + if (sizeof (FCHAR_T) == sizeof (DCHAR_T)) + { + DCHAR_CPY (result + length, (const DCHAR_T *) cp, n); + length = augmented_length; + } + else + { + do + result[length++] = (unsigned char) *cp++; + while (--n > 0); + } + } + if (i == d.count) + break; + + /* Execute a single directive. */ + if (dp->conversion == '%') + { + size_t augmented_length; + + if (!(dp->arg_index == ARG_NONE)) + abort (); + augmented_length = xsum (length, 1); + ENSURE_ALLOCATION (augmented_length); + result[length] = '%'; + length = augmented_length; + } + else + { + if (!(dp->arg_index != ARG_NONE)) + abort (); + + if (dp->conversion == 'n') + { + switch (a.arg[dp->arg_index].type) + { + case TYPE_COUNT_SCHAR_POINTER: + *a.arg[dp->arg_index].a.a_count_schar_pointer = length; + break; + case TYPE_COUNT_SHORT_POINTER: + *a.arg[dp->arg_index].a.a_count_short_pointer = length; + break; + case TYPE_COUNT_INT_POINTER: + *a.arg[dp->arg_index].a.a_count_int_pointer = length; + break; + case TYPE_COUNT_LONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longint_pointer = length; + break; #if HAVE_LONG_LONG_INT - case TYPE_COUNT_LONGLONGINT_POINTER: - *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; - break; + case TYPE_COUNT_LONGLONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; + break; #endif - default: - abort (); - } - } + default: + abort (); + } + } #if ENABLE_UNISTDIO - /* The unistdio extensions. */ - else if (dp->conversion == 'U') - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - switch (type) - { - case TYPE_U8_STRING: - { - const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string; - const uint8_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u8_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u8_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u8_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + /* The unistdio extensions. */ + else if (dp->conversion == 'U') + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + switch (type) + { + case TYPE_U8_STRING: + { + const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string; + const uint8_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u8_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u8_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u8_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_UINT8_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } # else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR - /* Convert from UTF-8 to locale encoding. */ - converted = - u8_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - converted, &converted_len); + /* Convert from UTF-8 to locale encoding. */ + converted = + u8_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); # else - /* Convert from UTF-8 to UTF-16/UTF-32. */ - converted = - U8_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); + /* Convert from UTF-8 to UTF-16/UTF-32. */ + converted = + U8_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); # endif - if (converted == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } # endif - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - case TYPE_U16_STRING: - { - const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string; - const uint16_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u16_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u16_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u16_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + case TYPE_U16_STRING: + { + const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string; + const uint16_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u16_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u16_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u16_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_UINT16_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } # else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR - /* Convert from UTF-16 to locale encoding. */ - converted = - u16_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - converted, &converted_len); + /* Convert from UTF-16 to locale encoding. */ + converted = + u16_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); # else - /* Convert from UTF-16 to UTF-8/UTF-32. */ - converted = - U16_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); + /* Convert from UTF-16 to UTF-8/UTF-32. */ + converted = + U16_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); # endif - if (converted == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } # endif - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - case TYPE_U32_STRING: - { - const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string; - const uint32_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u32_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u32_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u32_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + case TYPE_U32_STRING: + { + const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string; + const uint32_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u32_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u32_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u32_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_UINT32_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } # else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR - /* Convert from UTF-32 to locale encoding. */ - converted = - u32_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - converted, &converted_len); + /* Convert from UTF-32 to locale encoding. */ + converted = + u32_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); # else - /* Convert from UTF-32 to UTF-8/UTF-16. */ - converted = - U32_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); + /* Convert from UTF-32 to UTF-8/UTF-16. */ + converted = + U32_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); # endif - if (converted == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } # endif - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - default: - abort (); - } - } + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + default: + abort (); + } + } #endif #if (!USE_SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T - else if (dp->conversion == 's' + else if (dp->conversion == 's' # if WIDE_CHAR_VERSION - && a.arg[dp->arg_index].type != TYPE_WIDE_STRING + && a.arg[dp->arg_index].type != TYPE_WIDE_STRING # else - && a.arg[dp->arg_index].type == TYPE_WIDE_STRING + && a.arg[dp->arg_index].type == TYPE_WIDE_STRING # endif - ) - { - /* The normal handling of the 's' directive below requires - allocating a temporary buffer. The determination of its - length (tmp_length), in the case when a precision is - specified, below requires a conversion between a char[] - string and a wchar_t[] wide string. It could be done, but - we have no guarantee that the implementation of sprintf will - use the exactly same algorithm. Without this guarantee, it - is possible to have buffer overrun bugs. In order to avoid - such bugs, we implement the entire processing of the 's' - directive ourselves. */ - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 6; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } + ) + { + /* The normal handling of the 's' directive below requires + allocating a temporary buffer. The determination of its + length (tmp_length), in the case when a precision is + specified, below requires a conversion between a char[] + string and a wchar_t[] wide string. It could be done, but + we have no guarantee that the implementation of sprintf will + use the exactly same algorithm. Without this guarantee, it + is possible to have buffer overrun bugs. In order to avoid + such bugs, we implement the entire processing of the 's' + directive ourselves. */ + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 6; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } # if WIDE_CHAR_VERSION - /* %s in vasnwprintf. See the specification of fwprintf. */ - { - const char *arg = a.arg[dp->arg_index].a.a_string; - const char *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only as many bytes as needed to produce PRECISION - wide characters, from the left. */ + /* %s in vasnwprintf. See the specification of fwprintf. */ + { + const char *arg = a.arg[dp->arg_index].a.a_string; + const char *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only as many bytes as needed to produce PRECISION + wide characters, from the left. */ # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count; + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count; # if HAVE_MBRTOWC - count = mbrlen (arg_end, MB_CUR_MAX, &state); + count = mbrlen (arg_end, MB_CUR_MAX, &state); # else - count = mblen (arg_end, MB_CUR_MAX); + count = mblen (arg_end, MB_CUR_MAX); # endif - if (count == 0) - /* Found the terminating NUL. */ - break; - if (count < 0) - { - /* Invalid or incomplete multibyte character. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of wide - characters. */ + if (count == 0) + /* Found the terminating NUL. */ + break; + if (count < 0) + { + /* Invalid or incomplete multibyte character. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of wide + characters. */ # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (;;) - { - int count; + arg_end = arg; + characters = 0; + for (;;) + { + int count; # if HAVE_MBRTOWC - count = mbrlen (arg_end, MB_CUR_MAX, &state); + count = mbrlen (arg_end, MB_CUR_MAX, &state); # else - count = mblen (arg_end, MB_CUR_MAX); + count = mblen (arg_end, MB_CUR_MAX); # endif - if (count == 0) - /* Found the terminating NUL. */ - break; - if (count < 0) - { - /* Invalid or incomplete multibyte character. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - - if (has_precision || has_width) - { - /* We know the number of wide characters in advance. */ - size_t remaining; + if (count == 0) + /* Found the terminating NUL. */ + break; + if (count < 0) + { + /* Invalid or incomplete multibyte character. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + + if (has_precision || has_width) + { + /* We know the number of wide characters in advance. */ + size_t remaining; # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - ENSURE_ALLOCATION (xsum (length, characters)); - for (remaining = characters; remaining > 0; remaining--) - { - wchar_t wc; - int count; + ENSURE_ALLOCATION (xsum (length, characters)); + for (remaining = characters; remaining > 0; remaining--) + { + wchar_t wc; + int count; # if HAVE_MBRTOWC - count = mbrtowc (&wc, arg, arg_end - arg, &state); + count = mbrtowc (&wc, arg, arg_end - arg, &state); # else - count = mbtowc (&wc, arg, arg_end - arg); + count = mbtowc (&wc, arg, arg_end - arg); # endif - if (count <= 0) - /* mbrtowc not consistent with mbrlen, or mbtowc - not consistent with mblen. */ - abort (); - result[length++] = wc; - arg += count; - } - if (!(arg == arg_end)) - abort (); - } - else - { + if (count <= 0) + /* mbrtowc not consistent with mbrlen, or mbtowc + not consistent with mblen. */ + abort (); + result[length++] = wc; + arg += count; + } + if (!(arg == arg_end)) + abort (); + } + else + { # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - while (arg < arg_end) - { - wchar_t wc; - int count; + while (arg < arg_end) + { + wchar_t wc; + int count; # if HAVE_MBRTOWC - count = mbrtowc (&wc, arg, arg_end - arg, &state); + count = mbrtowc (&wc, arg, arg_end - arg, &state); # else - count = mbtowc (&wc, arg, arg_end - arg); + count = mbtowc (&wc, arg, arg_end - arg); # endif - if (count <= 0) - /* mbrtowc not consistent with mbrlen, or mbtowc - not consistent with mblen. */ - abort (); - ENSURE_ALLOCATION (xsum (length, 1)); - result[length++] = wc; - arg += count; - } - } - - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } + if (count <= 0) + /* mbrtowc not consistent with mbrlen, or mbtowc + not consistent with mblen. */ + abort (); + ENSURE_ALLOCATION (xsum (length, 1)); + result[length++] = wc; + arg += count; + } + } + + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } # else - /* %ls in vasnprintf. See the specification of fprintf. */ - { - const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; - const wchar_t *arg_end; - size_t characters; + /* %ls in vasnprintf. See the specification of fprintf. */ + { + const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; + const wchar_t *arg_end; + size_t characters; # if !DCHAR_IS_TCHAR - /* This code assumes that TCHAR_T is 'char'. */ - typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1]; - TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t tmpdst_len; + /* This code assumes that TCHAR_T is 'char'. */ + typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1]; + TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t tmpdst_len; # endif - size_t w; + size_t w; - if (has_precision) - { - /* Use only as many wide characters as needed to produce - at most PRECISION bytes, from the left. */ + if (has_precision) + { + /* Use only as many wide characters as needed to produce + at most PRECISION bytes, from the left. */ # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - while (precision > 0) - { - char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg_end == 0) - /* Found the terminating null wide character. */ - break; + arg_end = arg; + characters = 0; + while (precision > 0) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg_end == 0) + /* Found the terminating null wide character. */ + break; # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg_end, &state); + count = wcrtomb (cbuf, *arg_end, &state); # else - count = wctomb (cbuf, *arg_end); + count = wctomb (cbuf, *arg_end); # endif - if (count < 0) - { - /* Cannot convert. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - if (precision < count) - break; - arg_end++; - characters += count; - precision -= count; - } - } + if (count < 0) + { + /* Cannot convert. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + if (precision < count) + break; + arg_end++; + characters += count; + precision -= count; + } + } # if DCHAR_IS_TCHAR - else if (has_width) + else if (has_width) # else - else + else # endif - { - /* Use the entire string, and count the number of - bytes. */ + { + /* Use the entire string, and count the number of + bytes. */ # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (;;) - { - char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg_end == 0) - /* Found the terminating null wide character. */ - break; + arg_end = arg; + characters = 0; + for (;;) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg_end == 0) + /* Found the terminating null wide character. */ + break; # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg_end, &state); + count = wcrtomb (cbuf, *arg_end, &state); # else - count = wctomb (cbuf, *arg_end); + count = wctomb (cbuf, *arg_end); # endif - if (count < 0) - { - /* Cannot convert. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end++; - characters += count; - } - } + if (count < 0) + { + /* Cannot convert. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end++; + characters += count; + } + } # if DCHAR_IS_TCHAR - else - { - /* Use the entire string. */ - arg_end = arg + local_wcslen (arg); - /* The number of bytes doesn't matter. */ - characters = 0; - } + else + { + /* Use the entire string. */ + arg_end = arg + local_wcslen (arg); + /* The number of bytes doesn't matter. */ + characters = 0; + } # endif # if !DCHAR_IS_TCHAR - /* Convert the string into a piece of temporary memory. */ - tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T)); - if (tmpsrc == NULL) - goto out_of_memory; - { - TCHAR_T *tmpptr = tmpsrc; - size_t remaining; + /* Convert the string into a piece of temporary memory. */ + tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T)); + if (tmpsrc == NULL) + goto out_of_memory; + { + TCHAR_T *tmpptr = tmpsrc; + size_t remaining; # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - for (remaining = characters; remaining > 0; ) - { - char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; + for (remaining = characters; remaining > 0; ) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; - if (*arg == 0) - abort (); + if (*arg == 0) + abort (); # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg, &state); + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (cbuf, *arg); + count = wctomb (cbuf, *arg); # endif - if (count <= 0) - /* Inconsistency. */ - abort (); - memcpy (tmpptr, cbuf, count); - tmpptr += count; - arg++; - remaining -= count; - } - if (!(arg == arg_end)) - abort (); - } - - /* Convert from TCHAR_T[] to DCHAR_T[]. */ - tmpdst = - DCHAR_CONV_FROM_ENCODING (locale_charset (), - iconveh_question_mark, - tmpsrc, characters, - NULL, - NULL, &tmpdst_len); - if (tmpdst == NULL) - { - int saved_errno = errno; - free (tmpsrc); - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - free (tmpsrc); + if (count <= 0) + /* Inconsistency. */ + abort (); + memcpy (tmpptr, cbuf, count); + tmpptr += count; + arg++; + remaining -= count; + } + if (!(arg == arg_end)) + abort (); + } + + /* Convert from TCHAR_T[] to DCHAR_T[]. */ + tmpdst = + DCHAR_CONV_FROM_ENCODING (locale_charset (), + iconveh_question_mark, + tmpsrc, characters, + NULL, + NULL, &tmpdst_len); + if (tmpdst == NULL) + { + int saved_errno = errno; + free (tmpsrc); + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + free (tmpsrc); # endif - if (has_width) - { + if (has_width) + { # if ENABLE_UNISTDIO - /* Outside POSIX, it's preferrable to compare the width - against the number of _characters_ of the converted - value. */ - w = DCHAR_MBSNLEN (result + length, characters); + /* Outside POSIX, it's preferrable to compare the width + against the number of _characters_ of the converted + value. */ + w = DCHAR_MBSNLEN (result + length, characters); # else - /* The width is compared against the number of _bytes_ - of the converted value, says POSIX. */ - w = characters; + /* The width is compared against the number of _bytes_ + of the converted value, says POSIX. */ + w = characters; # endif - } - else - /* w doesn't matter. */ - w = 0; - - if (has_width && width > w - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - w; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + } + else + /* w doesn't matter. */ + w = 0; + + if (has_width && width > w + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - w; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_TCHAR - if (has_precision || has_width) - { - /* We know the number of bytes in advance. */ - size_t remaining; + if (has_precision || has_width) + { + /* We know the number of bytes in advance. */ + size_t remaining; # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - ENSURE_ALLOCATION (xsum (length, characters)); - for (remaining = characters; remaining > 0; ) - { - char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg == 0) - abort (); + ENSURE_ALLOCATION (xsum (length, characters)); + for (remaining = characters; remaining > 0; ) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg == 0) + abort (); # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg, &state); + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (cbuf, *arg); + count = wctomb (cbuf, *arg); # endif - if (count <= 0) - /* Inconsistency. */ - abort (); - memcpy (result + length, cbuf, count); - length += count; - arg++; - remaining -= count; - } - if (!(arg == arg_end)) - abort (); - } - else - { + if (count <= 0) + /* Inconsistency. */ + abort (); + memcpy (result + length, cbuf, count); + length += count; + arg++; + remaining -= count; + } + if (!(arg == arg_end)) + abort (); + } + else + { # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - while (arg < arg_end) - { - char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; + while (arg < arg_end) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; - if (*arg == 0) - abort (); + if (*arg == 0) + abort (); # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg, &state); + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (cbuf, *arg); + count = wctomb (cbuf, *arg); # endif - if (count <= 0) - /* Inconsistency. */ - abort (); - ENSURE_ALLOCATION (xsum (length, count)); - memcpy (result + length, cbuf, count); - length += count; - arg++; - } - } + if (count <= 0) + /* Inconsistency. */ + abort (); + ENSURE_ALLOCATION (xsum (length, count)); + memcpy (result + length, cbuf, count); + length += count; + arg++; + } + } # else - ENSURE_ALLOCATION (xsum (length, tmpdst_len)); - DCHAR_CPY (result + length, tmpdst, tmpdst_len); - free (tmpdst); - length += tmpdst_len; + ENSURE_ALLOCATION (xsum (length, tmpdst_len)); + DCHAR_CPY (result + length, tmpdst, tmpdst_len); + free (tmpdst); + length += tmpdst_len; # endif - if (has_width && width > w - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - w; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - } + if (has_width && width > w + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - w; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + } # endif #endif #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL - else if ((dp->conversion == 'a' || dp->conversion == 'A') + else if ((dp->conversion == 'a' || dp->conversion == 'A') # if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE)) - && (0 + && (0 # if NEED_PRINTF_DOUBLE - || a.arg[dp->arg_index].type == TYPE_DOUBLE + || a.arg[dp->arg_index].type == TYPE_DOUBLE # endif # if NEED_PRINTF_LONG_DOUBLE - || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE # endif - ) + ) # endif - ) - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - size_t tmp_length; - DCHAR_T tmpbuf[700]; - DCHAR_T *tmp; - DCHAR_T *pad_ptr; - DCHAR_T *p; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - /* Allocate a temporary buffer of sufficient size. */ - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) ((LDBL_DIG + 1) - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) ((DBL_DIG + 1) - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); - - if (tmp_length < width) - tmp_length = width; - - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - - if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); - - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (DCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } - - pad_ptr = NULL; - p = tmp; - if (type == TYPE_LONGDOUBLE) - { + ) + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + size_t tmp_length; + DCHAR_T tmpbuf[700]; + DCHAR_T *tmp; + DCHAR_T *pad_ptr; + DCHAR_T *p; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + /* Allocate a temporary buffer of sufficient size. */ + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) ((LDBL_DIG + 1) + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) ((DBL_DIG + 1) + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); + + if (tmp_length < width) + tmp_length = width; + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + + if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); + + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (DCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } + + pad_ptr = NULL; + p = tmp; + if (type == TYPE_LONGDOUBLE) + { # if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE - long double arg = a.arg[dp->arg_index].a.a_longdouble; - - if (isnanl (arg)) - { - if (dp->conversion == 'A') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - DECL_LONG_DOUBLE_ROUNDING - - BEGIN_LONG_DOUBLE_ROUNDING (); - - if (signbit (arg)) /* arg < 0.0L or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0L && arg + arg == arg) - { - if (dp->conversion == 'A') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { - int exponent; - long double mantissa; - - if (arg > 0.0L) - mantissa = printf_frexpl (arg, &exponent); - else - { - exponent = 0; - mantissa = 0.0L; - } - - if (has_precision - && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1) - { - /* Round the mantissa. */ - long double tail = mantissa; - size_t q; - - for (q = precision; ; q--) - { - int digit = (int) tail; - tail -= digit; - if (q == 0) - { - if (digit & 1 ? tail >= 0.5L : tail > 0.5L) - tail = 1 - tail; - else - tail = - tail; - break; - } - tail *= 16.0L; - } - if (tail != 0.0L) - for (q = precision; q > 0; q--) - tail *= 0.0625L; - mantissa += tail; - } - - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - { - int digit; - - digit = (int) mantissa; - mantissa -= digit; - *p++ = '0' + digit; - if ((flags & FLAG_ALT) - || mantissa > 0.0L || precision > 0) - { - *p++ = decimal_point_char (); - /* This loop terminates because we assume - that FLT_RADIX is a power of 2. */ - while (mantissa > 0.0L) - { - mantissa *= 16.0L; - digit = (int) mantissa; - mantissa -= digit; - *p++ = digit - + (digit < 10 - ? '0' - : dp->conversion - 10); - if (precision > 0) - precision--; - } - while (precision > 0) - { - *p++ = '0'; - precision--; - } - } - } - *p++ = dp->conversion - 'A' + 'P'; + long double arg = a.arg[dp->arg_index].a.a_longdouble; + + if (isnanl (arg)) + { + if (dp->conversion == 'A') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + DECL_LONG_DOUBLE_ROUNDING + + BEGIN_LONG_DOUBLE_ROUNDING (); + + if (signbit (arg)) /* arg < 0.0L or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0L && arg + arg == arg) + { + if (dp->conversion == 'A') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { + int exponent; + long double mantissa; + + if (arg > 0.0L) + mantissa = printf_frexpl (arg, &exponent); + else + { + exponent = 0; + mantissa = 0.0L; + } + + if (has_precision + && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1) + { + /* Round the mantissa. */ + long double tail = mantissa; + size_t q; + + for (q = precision; ; q--) + { + int digit = (int) tail; + tail -= digit; + if (q == 0) + { + if (digit & 1 ? tail >= 0.5L : tail > 0.5L) + tail = 1 - tail; + else + tail = - tail; + break; + } + tail *= 16.0L; + } + if (tail != 0.0L) + for (q = precision; q > 0; q--) + tail *= 0.0625L; + mantissa += tail; + } + + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + { + int digit; + + digit = (int) mantissa; + mantissa -= digit; + *p++ = '0' + digit; + if ((flags & FLAG_ALT) + || mantissa > 0.0L || precision > 0) + { + *p++ = decimal_point_char (); + /* This loop terminates because we assume + that FLT_RADIX is a power of 2. */ + while (mantissa > 0.0L) + { + mantissa *= 16.0L; + digit = (int) mantissa; + mantissa -= digit; + *p++ = digit + + (digit < 10 + ? '0' + : dp->conversion - 10); + if (precision > 0) + precision--; + } + while (precision > 0) + { + *p++ = '0'; + precision--; + } + } + } + *p++ = dp->conversion - 'A' + 'P'; # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } + } - END_LONG_DOUBLE_ROUNDING (); - } + END_LONG_DOUBLE_ROUNDING (); + } # else - abort (); + abort (); # endif - } - else - { + } + else + { # if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE - double arg = a.arg[dp->arg_index].a.a_double; - - if (isnand (arg)) - { - if (dp->conversion == 'A') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - - if (signbit (arg)) /* arg < 0.0 or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0 && arg + arg == arg) - { - if (dp->conversion == 'A') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { - int exponent; - double mantissa; - - if (arg > 0.0) - mantissa = printf_frexp (arg, &exponent); - else - { - exponent = 0; - mantissa = 0.0; - } - - if (has_precision - && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1) - { - /* Round the mantissa. */ - double tail = mantissa; - size_t q; - - for (q = precision; ; q--) - { - int digit = (int) tail; - tail -= digit; - if (q == 0) - { - if (digit & 1 ? tail >= 0.5 : tail > 0.5) - tail = 1 - tail; - else - tail = - tail; - break; - } - tail *= 16.0; - } - if (tail != 0.0) - for (q = precision; q > 0; q--) - tail *= 0.0625; - mantissa += tail; - } - - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - { - int digit; - - digit = (int) mantissa; - mantissa -= digit; - *p++ = '0' + digit; - if ((flags & FLAG_ALT) - || mantissa > 0.0 || precision > 0) - { - *p++ = decimal_point_char (); - /* This loop terminates because we assume - that FLT_RADIX is a power of 2. */ - while (mantissa > 0.0) - { - mantissa *= 16.0; - digit = (int) mantissa; - mantissa -= digit; - *p++ = digit - + (digit < 10 - ? '0' - : dp->conversion - 10); - if (precision > 0) - precision--; - } - while (precision > 0) - { - *p++ = '0'; - precision--; - } - } - } - *p++ = dp->conversion - 'A' + 'P'; + double arg = a.arg[dp->arg_index].a.a_double; + + if (isnand (arg)) + { + if (dp->conversion == 'A') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + + if (signbit (arg)) /* arg < 0.0 or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0 && arg + arg == arg) + { + if (dp->conversion == 'A') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { + int exponent; + double mantissa; + + if (arg > 0.0) + mantissa = printf_frexp (arg, &exponent); + else + { + exponent = 0; + mantissa = 0.0; + } + + if (has_precision + && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1) + { + /* Round the mantissa. */ + double tail = mantissa; + size_t q; + + for (q = precision; ; q--) + { + int digit = (int) tail; + tail -= digit; + if (q == 0) + { + if (digit & 1 ? tail >= 0.5 : tail > 0.5) + tail = 1 - tail; + else + tail = - tail; + break; + } + tail *= 16.0; + } + if (tail != 0.0) + for (q = precision; q > 0; q--) + tail *= 0.0625; + mantissa += tail; + } + + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + { + int digit; + + digit = (int) mantissa; + mantissa -= digit; + *p++ = '0' + digit; + if ((flags & FLAG_ALT) + || mantissa > 0.0 || precision > 0) + { + *p++ = decimal_point_char (); + /* This loop terminates because we assume + that FLT_RADIX is a power of 2. */ + while (mantissa > 0.0) + { + mantissa *= 16.0; + digit = (int) mantissa; + mantissa -= digit; + *p++ = digit + + (digit < 10 + ? '0' + : dp->conversion - 10); + if (precision > 0) + precision--; + } + while (precision > 0) + { + *p++ = '0'; + precision--; + } + } + } + *p++ = dp->conversion - 'A' + 'P'; # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } - } + } + } # else - abort (); + abort (); # endif - } - /* The generated string now extends from tmp to p, with the - zero padding insertion point being at pad_ptr. */ - if (has_width && p - tmp < width) - { - size_t pad = width - (p - tmp); - DCHAR_T *end = p + pad; - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > tmp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - - p = end; - } - - { - size_t count = p - tmp; - - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); - - /* Make room for the result. */ - if (count >= allocated - length) - { - size_t n = xsum (length, count); - - ENSURE_ALLOCATION (n); - } - - /* Append the result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); - if (tmp != tmpbuf) - free (tmp); - length += count; - } - } + } + /* The generated string now extends from tmp to p, with the + zero padding insertion point being at pad_ptr. */ + if (has_width && p - tmp < width) + { + size_t pad = width - (p - tmp); + DCHAR_T *end = p + pad; + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > tmp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + + p = end; + } + + { + size_t count = p - tmp; + + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); + + /* Make room for the result. */ + if (count >= allocated - length) + { + size_t n = xsum (length, count); + + ENSURE_ALLOCATION (n); + } + + /* Append the result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + if (tmp != tmpbuf) + free (tmp); + length += count; + } + } #endif #if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL - else if ((dp->conversion == 'f' || dp->conversion == 'F' - || dp->conversion == 'e' || dp->conversion == 'E' - || dp->conversion == 'g' || dp->conversion == 'G' - || dp->conversion == 'a' || dp->conversion == 'A') - && (0 + else if ((dp->conversion == 'f' || dp->conversion == 'F' + || dp->conversion == 'e' || dp->conversion == 'E' + || dp->conversion == 'g' || dp->conversion == 'G' + || dp->conversion == 'a' || dp->conversion == 'A') + && (0 # if NEED_PRINTF_DOUBLE - || a.arg[dp->arg_index].type == TYPE_DOUBLE + || a.arg[dp->arg_index].type == TYPE_DOUBLE # elif NEED_PRINTF_INFINITE_DOUBLE - || (a.arg[dp->arg_index].type == TYPE_DOUBLE - /* The systems (mingw) which produce wrong output - for Inf, -Inf, and NaN also do so for -0.0. - Therefore we treat this case here as well. */ - && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) + || (a.arg[dp->arg_index].type == TYPE_DOUBLE + /* The systems (mingw) which produce wrong output + for Inf, -Inf, and NaN also do so for -0.0. + Therefore we treat this case here as well. */ + && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) # endif # if NEED_PRINTF_LONG_DOUBLE - || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE # elif NEED_PRINTF_INFINITE_LONG_DOUBLE - || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE - /* Some systems produce wrong output for Inf, - -Inf, and NaN. Some systems in this category - (IRIX 5.3) also do so for -0.0. Therefore we - treat this case here as well. */ - && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble)) + || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + /* Some systems produce wrong output for Inf, + -Inf, and NaN. Some systems in this category + (IRIX 5.3) also do so for -0.0. Therefore we + treat this case here as well. */ + && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble)) # endif - )) - { + )) + { # if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) - arg_type type = a.arg[dp->arg_index].type; + arg_type type = a.arg[dp->arg_index].type; # endif - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - size_t tmp_length; - DCHAR_T tmpbuf[700]; - DCHAR_T *tmp; - DCHAR_T *pad_ptr; - DCHAR_T *p; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - /* POSIX specifies the default precision to be 6 for %f, %F, - %e, %E, but not for %g, %G. Implementations appear to use - the same default precision also for %g, %G. But for %a, %A, - the default precision is 0. */ - if (!has_precision) - if (!(dp->conversion == 'a' || dp->conversion == 'A')) - precision = 6; - - /* Allocate a temporary buffer of sufficient size. */ + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + size_t tmp_length; + DCHAR_T tmpbuf[700]; + DCHAR_T *tmp; + DCHAR_T *pad_ptr; + DCHAR_T *p; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + /* POSIX specifies the default precision to be 6 for %f, %F, + %e, %E, but not for %g, %G. Implementations appear to use + the same default precision also for %g, %G. But for %a, %A, + the default precision is 0. */ + if (!has_precision) + if (!(dp->conversion == 'a' || dp->conversion == 'A')) + precision = 6; + + /* Allocate a temporary buffer of sufficient size. */ # if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE - tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1); + tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1); # elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE - tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); + tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); # elif NEED_PRINTF_LONG_DOUBLE - tmp_length = LDBL_DIG + 1; + tmp_length = LDBL_DIG + 1; # elif NEED_PRINTF_DOUBLE - tmp_length = DBL_DIG + 1; + tmp_length = DBL_DIG + 1; # else - tmp_length = 0; + tmp_length = 0; # endif - if (tmp_length < precision) - tmp_length = precision; + if (tmp_length < precision) + tmp_length = precision; # if NEED_PRINTF_LONG_DOUBLE # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - if (type == TYPE_LONGDOUBLE) + if (type == TYPE_LONGDOUBLE) # endif - if (dp->conversion == 'f' || dp->conversion == 'F') - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - if (!(isnanl (arg) || arg + arg == arg)) - { - /* arg is finite and nonzero. */ - int exponent = floorlog10l (arg < 0 ? -arg : arg); - if (exponent >= 0 && tmp_length < exponent + precision) - tmp_length = exponent + precision; - } - } + if (dp->conversion == 'f' || dp->conversion == 'F') + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + if (!(isnanl (arg) || arg + arg == arg)) + { + /* arg is finite and nonzero. */ + int exponent = floorlog10l (arg < 0 ? -arg : arg); + if (exponent >= 0 && tmp_length < exponent + precision) + tmp_length = exponent + precision; + } + } # endif # if NEED_PRINTF_DOUBLE # if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE - if (type == TYPE_DOUBLE) + if (type == TYPE_DOUBLE) # endif - if (dp->conversion == 'f' || dp->conversion == 'F') - { - double arg = a.arg[dp->arg_index].a.a_double; - if (!(isnand (arg) || arg + arg == arg)) - { - /* arg is finite and nonzero. */ - int exponent = floorlog10 (arg < 0 ? -arg : arg); - if (exponent >= 0 && tmp_length < exponent + precision) - tmp_length = exponent + precision; - } - } + if (dp->conversion == 'f' || dp->conversion == 'F') + { + double arg = a.arg[dp->arg_index].a.a_double; + if (!(isnand (arg) || arg + arg == arg)) + { + /* arg is finite and nonzero. */ + int exponent = floorlog10 (arg < 0 ? -arg : arg); + if (exponent >= 0 && tmp_length < exponent + precision) + tmp_length = exponent + precision; + } + } # endif - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); - if (tmp_length < width) - tmp_length = width; + if (tmp_length < width) + tmp_length = width; - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); + if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (DCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (DCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } - pad_ptr = NULL; - p = tmp; + pad_ptr = NULL; + p = tmp; # if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - if (type == TYPE_LONGDOUBLE) + if (type == TYPE_LONGDOUBLE) # endif - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - - if (isnanl (arg)) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - DECL_LONG_DOUBLE_ROUNDING - - BEGIN_LONG_DOUBLE_ROUNDING (); - - if (signbit (arg)) /* arg < 0.0L or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0L && arg + arg == arg) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + + if (isnanl (arg)) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + DECL_LONG_DOUBLE_ROUNDING + + BEGIN_LONG_DOUBLE_ROUNDING (); + + if (signbit (arg)) /* arg < 0.0L or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0L && arg + arg == arg) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { # if NEED_PRINTF_LONG_DOUBLE - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - char *digits; - size_t ndigits; - - digits = - scale10_round_decimal_long_double (arg, precision); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits > precision) - do - { - --ndigits; - *p++ = digits[ndigits]; - } - while (ndigits > precision); - else - *p++ = '0'; - /* Here ndigits <= precision. */ - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > ndigits; precision--) - *p++ = '0'; - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - int exponent; - - if (arg == 0.0L) - { - exponent = 0; - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else - { - /* arg > 0.0L. */ - int adjusted; - char *digits; - size_t ndigits; - - exponent = floorlog10l (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_long_double (arg, - (int)precision - exponent); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits == precision + 1) - break; - if (ndigits < precision - || ndigits > precision + 2) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits == precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision+1. */ - if (is_borderline (digits, precision)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_long_double (arg, - (int)precision - exponent + 1); - if (digits2 == NULL) - { - free (digits); - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - if (strlen (digits2) == precision + 1) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision+1. */ - - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - - *p++ = dp->conversion; /* 'e' or 'E' */ + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + char *digits; + size_t ndigits; + + digits = + scale10_round_decimal_long_double (arg, precision); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits > precision) + do + { + --ndigits; + *p++ = digits[ndigits]; + } + while (ndigits > precision); + else + *p++ = '0'; + /* Here ndigits <= precision. */ + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > ndigits; precision--) + *p++ = '0'; + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + int exponent; + + if (arg == 0.0L) + { + exponent = 0; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else + { + /* arg > 0.0L. */ + int adjusted; + char *digits; + size_t ndigits; + + exponent = floorlog10l (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_long_double (arg, + (int)precision - exponent); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits == precision + 1) + break; + if (ndigits < precision + || ndigits > precision + 2) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits == precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision+1. */ + if (is_borderline (digits, precision)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_long_double (arg, + (int)precision - exponent + 1); + if (digits2 == NULL) + { + free (digits); + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + if (strlen (digits2) == precision + 1) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision+1. */ + + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + + *p++ = dp->conversion; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', '.', '2', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', '.', '2', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+.2d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+.2d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+.2d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+.2d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - if (precision == 0) - precision = 1; - /* precision >= 1. */ - - if (arg == 0.0L) - /* The exponent is 0, >= -4, < precision. - Use fixed-point notation. */ - { - size_t ndigits = precision; - /* Number of trailing zeroes that have to be - dropped. */ - size_t nzeroes = - (flags & FLAG_ALT ? 0 : precision - 1); - - --ndigits; - *p++ = '0'; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = '0'; - } - } - } - else - { - /* arg > 0.0L. */ - int exponent; - int adjusted; - char *digits; - size_t ndigits; - size_t nzeroes; - - exponent = floorlog10l (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_long_double (arg, - (int)(precision - 1) - exponent); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits == precision) - break; - if (ndigits < precision - 1 - || ndigits > precision + 1) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits < precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision. */ - if (is_borderline (digits, precision - 1)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_long_double (arg, - (int)(precision - 1) - exponent + 1); - if (digits2 == NULL) - { - free (digits); - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - if (strlen (digits2) == precision) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision. */ - - /* Determine the number of trailing zeroes - that have to be dropped. */ - nzeroes = 0; - if ((flags & FLAG_ALT) == 0) - while (nzeroes < ndigits - && digits[nzeroes] == '0') - nzeroes++; - - /* The exponent is now determined. */ - if (exponent >= -4 - && exponent < (long)precision) - { - /* Fixed-point notation: - max(exponent,0)+1 digits, then the - decimal point, then the remaining - digits without trailing zeroes. */ - if (exponent >= 0) - { - size_t count = exponent + 1; - /* Note: count <= precision = ndigits. */ - for (; count > 0; count--) - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - size_t count = -exponent - 1; - *p++ = '0'; - *p++ = decimal_point_char (); - for (; count > 0; count--) - *p++ = '0'; - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - /* Exponential notation. */ - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + if (precision == 0) + precision = 1; + /* precision >= 1. */ + + if (arg == 0.0L) + /* The exponent is 0, >= -4, < precision. + Use fixed-point notation. */ + { + size_t ndigits = precision; + /* Number of trailing zeroes that have to be + dropped. */ + size_t nzeroes = + (flags & FLAG_ALT ? 0 : precision - 1); + + --ndigits; + *p++ = '0'; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = '0'; + } + } + } + else + { + /* arg > 0.0L. */ + int exponent; + int adjusted; + char *digits; + size_t ndigits; + size_t nzeroes; + + exponent = floorlog10l (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_long_double (arg, + (int)(precision - 1) - exponent); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits == precision) + break; + if (ndigits < precision - 1 + || ndigits > precision + 1) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits < precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision. */ + if (is_borderline (digits, precision - 1)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_long_double (arg, + (int)(precision - 1) - exponent + 1); + if (digits2 == NULL) + { + free (digits); + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + if (strlen (digits2) == precision) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision. */ + + /* Determine the number of trailing zeroes + that have to be dropped. */ + nzeroes = 0; + if ((flags & FLAG_ALT) == 0) + while (nzeroes < ndigits + && digits[nzeroes] == '0') + nzeroes++; + + /* The exponent is now determined. */ + if (exponent >= -4 + && exponent < (long)precision) + { + /* Fixed-point notation: + max(exponent,0)+1 digits, then the + decimal point, then the remaining + digits without trailing zeroes. */ + if (exponent >= 0) + { + size_t count = exponent + 1; + /* Note: count <= precision = ndigits. */ + for (; count > 0; count--) + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + size_t count = -exponent - 1; + *p++ = '0'; + *p++ = decimal_point_char (); + for (; count > 0; count--) + *p++ = '0'; + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + /* Exponential notation. */ + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', '.', '2', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', '.', '2', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+.2d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+.2d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+.2d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+.2d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } + } - free (digits); - } - } - else - abort (); + free (digits); + } + } + else + abort (); # else - /* arg is finite. */ - if (!(arg == 0.0L)) - abort (); - - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - *p++ = dp->conversion; /* 'e' or 'E' */ - *p++ = '+'; - *p++ = '0'; - *p++ = '0'; - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - *p++ = '0'; - if (flags & FLAG_ALT) - { - size_t ndigits = - (precision > 0 ? precision - 1 : 0); - *p++ = decimal_point_char (); - for (; ndigits > 0; --ndigits) - *p++ = '0'; - } - } - else if (dp->conversion == 'a' || dp->conversion == 'A') - { - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - *p++ = dp->conversion - 'A' + 'P'; - *p++ = '+'; - *p++ = '0'; - } - else - abort (); + /* arg is finite. */ + if (!(arg == 0.0L)) + abort (); + + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion; /* 'e' or 'E' */ + *p++ = '+'; + *p++ = '0'; + *p++ = '0'; + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + *p++ = '0'; + if (flags & FLAG_ALT) + { + size_t ndigits = + (precision > 0 ? precision - 1 : 0); + *p++ = decimal_point_char (); + for (; ndigits > 0; --ndigits) + *p++ = '0'; + } + } + else if (dp->conversion == 'a' || dp->conversion == 'A') + { + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion - 'A' + 'P'; + *p++ = '+'; + *p++ = '0'; + } + else + abort (); # endif - } + } - END_LONG_DOUBLE_ROUNDING (); - } - } + END_LONG_DOUBLE_ROUNDING (); + } + } # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - else + else # endif # endif # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - { - double arg = a.arg[dp->arg_index].a.a_double; - - if (isnand (arg)) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - - if (signbit (arg)) /* arg < 0.0 or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0 && arg + arg == arg) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { + { + double arg = a.arg[dp->arg_index].a.a_double; + + if (isnand (arg)) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + + if (signbit (arg)) /* arg < 0.0 or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0 && arg + arg == arg) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { # if NEED_PRINTF_DOUBLE - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - char *digits; - size_t ndigits; - - digits = - scale10_round_decimal_double (arg, precision); - if (digits == NULL) - goto out_of_memory; - ndigits = strlen (digits); - - if (ndigits > precision) - do - { - --ndigits; - *p++ = digits[ndigits]; - } - while (ndigits > precision); - else - *p++ = '0'; - /* Here ndigits <= precision. */ - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > ndigits; precision--) - *p++ = '0'; - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - int exponent; - - if (arg == 0.0) - { - exponent = 0; - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else - { - /* arg > 0.0. */ - int adjusted; - char *digits; - size_t ndigits; - - exponent = floorlog10 (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_double (arg, - (int)precision - exponent); - if (digits == NULL) - goto out_of_memory; - ndigits = strlen (digits); - - if (ndigits == precision + 1) - break; - if (ndigits < precision - || ndigits > precision + 2) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits == precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision+1. */ - if (is_borderline (digits, precision)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_double (arg, - (int)precision - exponent + 1); - if (digits2 == NULL) - { - free (digits); - goto out_of_memory; - } - if (strlen (digits2) == precision + 1) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision+1. */ - - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - - *p++ = dp->conversion; /* 'e' or 'E' */ + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + char *digits; + size_t ndigits; + + digits = + scale10_round_decimal_double (arg, precision); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits > precision) + do + { + --ndigits; + *p++ = digits[ndigits]; + } + while (ndigits > precision); + else + *p++ = '0'; + /* Here ndigits <= precision. */ + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > ndigits; precision--) + *p++ = '0'; + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + int exponent; + + if (arg == 0.0) + { + exponent = 0; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else + { + /* arg > 0.0. */ + int adjusted; + char *digits; + size_t ndigits; + + exponent = floorlog10 (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_double (arg, + (int)precision - exponent); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits == precision + 1) + break; + if (ndigits < precision + || ndigits > precision + 2) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits == precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision+1. */ + if (is_borderline (digits, precision)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_double (arg, + (int)precision - exponent + 1); + if (digits2 == NULL) + { + free (digits); + goto out_of_memory; + } + if (strlen (digits2) == precision + 1) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision+1. */ + + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + + *p++ = dp->conversion; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const wchar_t decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - { '%', '+', '.', '3', 'd', '\0' }; + { '%', '+', '.', '3', 'd', '\0' }; # else - { '%', '+', '.', '2', 'd', '\0' }; + { '%', '+', '.', '2', 'd', '\0' }; # endif - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - { - static const char decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const char decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - "%+.3d"; + "%+.3d"; # else - "%+.2d"; + "%+.2d"; # endif - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, decimal_format, exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, decimal_format, exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, decimal_format, exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, decimal_format, exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } + } # endif - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - if (precision == 0) - precision = 1; - /* precision >= 1. */ - - if (arg == 0.0) - /* The exponent is 0, >= -4, < precision. - Use fixed-point notation. */ - { - size_t ndigits = precision; - /* Number of trailing zeroes that have to be - dropped. */ - size_t nzeroes = - (flags & FLAG_ALT ? 0 : precision - 1); - - --ndigits; - *p++ = '0'; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = '0'; - } - } - } - else - { - /* arg > 0.0. */ - int exponent; - int adjusted; - char *digits; - size_t ndigits; - size_t nzeroes; - - exponent = floorlog10 (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_double (arg, - (int)(precision - 1) - exponent); - if (digits == NULL) - goto out_of_memory; - ndigits = strlen (digits); - - if (ndigits == precision) - break; - if (ndigits < precision - 1 - || ndigits > precision + 1) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits < precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision. */ - if (is_borderline (digits, precision - 1)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_double (arg, - (int)(precision - 1) - exponent + 1); - if (digits2 == NULL) - { - free (digits); - goto out_of_memory; - } - if (strlen (digits2) == precision) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision. */ - - /* Determine the number of trailing zeroes - that have to be dropped. */ - nzeroes = 0; - if ((flags & FLAG_ALT) == 0) - while (nzeroes < ndigits - && digits[nzeroes] == '0') - nzeroes++; - - /* The exponent is now determined. */ - if (exponent >= -4 - && exponent < (long)precision) - { - /* Fixed-point notation: - max(exponent,0)+1 digits, then the - decimal point, then the remaining - digits without trailing zeroes. */ - if (exponent >= 0) - { - size_t count = exponent + 1; - /* Note: count <= precision = ndigits. */ - for (; count > 0; count--) - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - size_t count = -exponent - 1; - *p++ = '0'; - *p++ = decimal_point_char (); - for (; count > 0; count--) - *p++ = '0'; - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - /* Exponential notation. */ - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + if (precision == 0) + precision = 1; + /* precision >= 1. */ + + if (arg == 0.0) + /* The exponent is 0, >= -4, < precision. + Use fixed-point notation. */ + { + size_t ndigits = precision; + /* Number of trailing zeroes that have to be + dropped. */ + size_t nzeroes = + (flags & FLAG_ALT ? 0 : precision - 1); + + --ndigits; + *p++ = '0'; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = '0'; + } + } + } + else + { + /* arg > 0.0. */ + int exponent; + int adjusted; + char *digits; + size_t ndigits; + size_t nzeroes; + + exponent = floorlog10 (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_double (arg, + (int)(precision - 1) - exponent); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits == precision) + break; + if (ndigits < precision - 1 + || ndigits > precision + 1) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits < precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision. */ + if (is_borderline (digits, precision - 1)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_double (arg, + (int)(precision - 1) - exponent + 1); + if (digits2 == NULL) + { + free (digits); + goto out_of_memory; + } + if (strlen (digits2) == precision) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision. */ + + /* Determine the number of trailing zeroes + that have to be dropped. */ + nzeroes = 0; + if ((flags & FLAG_ALT) == 0) + while (nzeroes < ndigits + && digits[nzeroes] == '0') + nzeroes++; + + /* The exponent is now determined. */ + if (exponent >= -4 + && exponent < (long)precision) + { + /* Fixed-point notation: + max(exponent,0)+1 digits, then the + decimal point, then the remaining + digits without trailing zeroes. */ + if (exponent >= 0) + { + size_t count = exponent + 1; + /* Note: count <= precision = ndigits. */ + for (; count > 0; count--) + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + size_t count = -exponent - 1; + *p++ = '0'; + *p++ = decimal_point_char (); + for (; count > 0; count--) + *p++ = '0'; + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + /* Exponential notation. */ + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const wchar_t decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - { '%', '+', '.', '3', 'd', '\0' }; + { '%', '+', '.', '3', 'd', '\0' }; # else - { '%', '+', '.', '2', 'd', '\0' }; + { '%', '+', '.', '2', 'd', '\0' }; # endif - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - { - static const char decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const char decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - "%+.3d"; + "%+.3d"; # else - "%+.2d"; + "%+.2d"; # endif - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, decimal_format, exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, decimal_format, exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, decimal_format, exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, decimal_format, exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } + } # endif - } + } - free (digits); - } - } - else - abort (); + free (digits); + } + } + else + abort (); # else - /* arg is finite. */ - if (!(arg == 0.0)) - abort (); - - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - *p++ = dp->conversion; /* 'e' or 'E' */ - *p++ = '+'; - /* Produce the same number of exponent digits as - the native printf implementation. */ + /* arg is finite. */ + if (!(arg == 0.0)) + abort (); + + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion; /* 'e' or 'E' */ + *p++ = '+'; + /* Produce the same number of exponent digits as + the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - *p++ = '0'; + *p++ = '0'; # endif - *p++ = '0'; - *p++ = '0'; - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - *p++ = '0'; - if (flags & FLAG_ALT) - { - size_t ndigits = - (precision > 0 ? precision - 1 : 0); - *p++ = decimal_point_char (); - for (; ndigits > 0; --ndigits) - *p++ = '0'; - } - } - else - abort (); + *p++ = '0'; + *p++ = '0'; + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + *p++ = '0'; + if (flags & FLAG_ALT) + { + size_t ndigits = + (precision > 0 ? precision - 1 : 0); + *p++ = decimal_point_char (); + for (; ndigits > 0; --ndigits) + *p++ = '0'; + } + } + else + abort (); # endif - } - } - } + } + } + } # endif - /* The generated string now extends from tmp to p, with the - zero padding insertion point being at pad_ptr. */ - if (has_width && p - tmp < width) - { - size_t pad = width - (p - tmp); - DCHAR_T *end = p + pad; - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > tmp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - - p = end; - } - - { - size_t count = p - tmp; - - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); - - /* Make room for the result. */ - if (count >= allocated - length) - { - size_t n = xsum (length, count); - - ENSURE_ALLOCATION (n); - } - - /* Append the result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); - if (tmp != tmpbuf) - free (tmp); - length += count; - } - } + /* The generated string now extends from tmp to p, with the + zero padding insertion point being at pad_ptr. */ + if (has_width && p - tmp < width) + { + size_t pad = width - (p - tmp); + DCHAR_T *end = p + pad; + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > tmp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + + p = end; + } + + { + size_t count = p - tmp; + + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); + + /* Make room for the result. */ + if (count >= allocated - length) + { + size_t n = xsum (length, count); + + ENSURE_ALLOCATION (n); + } + + /* Append the result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + if (tmp != tmpbuf) + free (tmp); + length += count; + } + } #endif - else - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; + else + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; #if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - int has_width; - size_t width; + int has_width; + size_t width; #endif #if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION - int has_precision; - size_t precision; + int has_precision; + size_t precision; #endif #if NEED_PRINTF_UNBOUNDED_PRECISION - int prec_ourselves; + int prec_ourselves; #else -# define prec_ourselves 0 +# define prec_ourselves 0 #endif #if NEED_PRINTF_FLAG_LEFTADJUST -# define pad_ourselves 1 +# define pad_ourselves 1 #elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - int pad_ourselves; + int pad_ourselves; #else -# define pad_ourselves 0 +# define pad_ourselves 0 #endif - TCHAR_T *fbp; - unsigned int prefix_count; - int prefixes[2] IF_LINT (= { 0 }); + TCHAR_T *fbp; + unsigned int prefix_count; + int prefixes[2] IF_LINT (= { 0 }); #if !USE_SNPRINTF - size_t tmp_length; - TCHAR_T tmpbuf[700]; - TCHAR_T *tmp; + size_t tmp_length; + TCHAR_T tmpbuf[700]; + TCHAR_T *tmp; #endif #if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } #endif #if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION - has_precision = 0; - precision = 6; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } + has_precision = 0; + precision = 6; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } #endif - /* Decide whether to handle the precision ourselves. */ + /* Decide whether to handle the precision ourselves. */ #if NEED_PRINTF_UNBOUNDED_PRECISION - switch (dp->conversion) - { - case 'd': case 'i': case 'u': - case 'o': - case 'x': case 'X': case 'p': - prec_ourselves = has_precision && (precision > 0); - break; - default: - prec_ourselves = 0; - break; - } + switch (dp->conversion) + { + case 'd': case 'i': case 'u': + case 'o': + case 'x': case 'X': case 'p': + prec_ourselves = has_precision && (precision > 0); + break; + default: + prec_ourselves = 0; + break; + } #endif - /* Decide whether to perform the padding ourselves. */ + /* Decide whether to perform the padding ourselves. */ #if !NEED_PRINTF_FLAG_LEFTADJUST && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION) - switch (dp->conversion) - { + switch (dp->conversion) + { # if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO - /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need - to perform the padding after this conversion. Functions - with unistdio extensions perform the padding based on - character count rather than element count. */ - case 'c': case 's': + /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need + to perform the padding after this conversion. Functions + with unistdio extensions perform the padding based on + character count rather than element count. */ + case 'c': case 's': # endif # if NEED_PRINTF_FLAG_ZERO - case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': - case 'a': case 'A': + case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': + case 'a': case 'A': # endif - pad_ourselves = 1; - break; - default: - pad_ourselves = prec_ourselves; - break; - } + pad_ourselves = 1; + break; + default: + pad_ourselves = prec_ourselves; + break; + } #endif #if !USE_SNPRINTF - /* Allocate a temporary buffer of sufficient size for calling - sprintf. */ - { - switch (dp->conversion) - { + /* Allocate a temporary buffer of sufficient size for calling + sprintf. */ + { + switch (dp->conversion) + { - case 'd': case 'i': case 'u': + case 'd': case 'i': case 'u': # if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - else + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else # endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Multiply by 2, as an estimate for FLAG_GROUP. */ - tmp_length = xsum (tmp_length, tmp_length); - /* Add 1, to account for a leading sign. */ - tmp_length = xsum (tmp_length, 1); - break; - - case 'o': + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Multiply by 2, as an estimate for FLAG_GROUP. */ + tmp_length = xsum (tmp_length, tmp_length); + /* Add 1, to account for a leading sign. */ + tmp_length = xsum (tmp_length, 1); + break; + + case 'o': # if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - else + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else # endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Add 1, to account for a leading sign. */ - tmp_length = xsum (tmp_length, 1); - break; - - case 'x': case 'X': + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Add 1, to account for a leading sign. */ + tmp_length = xsum (tmp_length, 1); + break; + + case 'x': case 'X': # if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else # endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Add 2, to account for a leading sign or alternate form. */ - tmp_length = xsum (tmp_length, 2); - break; - - case 'f': case 'F': - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) (LDBL_MAX_EXP - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 10; /* sign, decimal point etc. */ - else - tmp_length = - (unsigned int) (DBL_MAX_EXP - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 10; /* sign, decimal point etc. */ - tmp_length = xsum (tmp_length, precision); - break; - - case 'e': case 'E': case 'g': case 'G': - tmp_length = - 12; /* sign, decimal point, exponent etc. */ - tmp_length = xsum (tmp_length, precision); - break; - - case 'a': case 'A': - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) (LDBL_DIG - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (DBL_DIG - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); - break; - - case 'c': + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Add 2, to account for a leading sign or alternate form. */ + tmp_length = xsum (tmp_length, 2); + break; + + case 'f': case 'F': + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) (LDBL_MAX_EXP + * 0.30103 /* binary -> decimal */ + * 2 /* estimate for FLAG_GROUP */ + ) + + 1 /* turn floor into ceil */ + + 10; /* sign, decimal point etc. */ + else + tmp_length = + (unsigned int) (DBL_MAX_EXP + * 0.30103 /* binary -> decimal */ + * 2 /* estimate for FLAG_GROUP */ + ) + + 1 /* turn floor into ceil */ + + 10; /* sign, decimal point etc. */ + tmp_length = xsum (tmp_length, precision); + break; + + case 'e': case 'E': case 'g': case 'G': + tmp_length = + 12; /* sign, decimal point, exponent etc. */ + tmp_length = xsum (tmp_length, precision); + break; + + case 'a': case 'A': + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) (LDBL_DIG + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (DBL_DIG + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); + break; + + case 'c': # if HAVE_WINT_T && !WIDE_CHAR_VERSION - if (type == TYPE_WIDE_CHAR) - tmp_length = MB_CUR_MAX; - else + if (type == TYPE_WIDE_CHAR) + tmp_length = MB_CUR_MAX; + else # endif - tmp_length = 1; - break; + tmp_length = 1; + break; - case 's': + case 's': # if HAVE_WCHAR_T - if (type == TYPE_WIDE_STRING) - { + if (type == TYPE_WIDE_STRING) + { # if WIDE_CHAR_VERSION - /* ISO C says about %ls in fwprintf: - "If the precision is not specified or is greater - than the size of the array, the array shall - contain a null wide character." - So if there is a precision, we must not use - wcslen. */ - const wchar_t *arg = - a.arg[dp->arg_index].a.a_wide_string; - - if (has_precision) - tmp_length = local_wcsnlen (arg, precision); - else - tmp_length = local_wcslen (arg); + /* ISO C says about %ls in fwprintf: + "If the precision is not specified or is greater + than the size of the array, the array shall + contain a null wide character." + So if there is a precision, we must not use + wcslen. */ + const wchar_t *arg = + a.arg[dp->arg_index].a.a_wide_string; + + if (has_precision) + tmp_length = local_wcsnlen (arg, precision); + else + tmp_length = local_wcslen (arg); # else - /* ISO C says about %ls in fprintf: - "If a precision is specified, no more than that - many bytes are written (including shift - sequences, if any), and the array shall contain - a null wide character if, to equal the - multibyte character sequence length given by - the precision, the function would need to - access a wide character one past the end of the - array." - So if there is a precision, we must not use - wcslen. */ - /* This case has already been handled above. */ - abort (); + /* ISO C says about %ls in fprintf: + "If a precision is specified, no more than that + many bytes are written (including shift + sequences, if any), and the array shall contain + a null wide character if, to equal the + multibyte character sequence length given by + the precision, the function would need to + access a wide character one past the end of the + array." + So if there is a precision, we must not use + wcslen. */ + /* This case has already been handled above. */ + abort (); # endif - } - else + } + else # endif - { + { # if WIDE_CHAR_VERSION - /* ISO C says about %s in fwprintf: - "If the precision is not specified or is greater - than the size of the converted array, the - converted array shall contain a null wide - character." - So if there is a precision, we must not use - strlen. */ - /* This case has already been handled above. */ - abort (); + /* ISO C says about %s in fwprintf: + "If the precision is not specified or is greater + than the size of the converted array, the + converted array shall contain a null wide + character." + So if there is a precision, we must not use + strlen. */ + /* This case has already been handled above. */ + abort (); # else - /* ISO C says about %s in fprintf: - "If the precision is not specified or greater - than the size of the array, the array shall - contain a null character." - So if there is a precision, we must not use - strlen. */ - const char *arg = a.arg[dp->arg_index].a.a_string; - - if (has_precision) - tmp_length = local_strnlen (arg, precision); - else - tmp_length = strlen (arg); + /* ISO C says about %s in fprintf: + "If the precision is not specified or greater + than the size of the array, the array shall + contain a null character." + So if there is a precision, we must not use + strlen. */ + const char *arg = a.arg[dp->arg_index].a.a_string; + + if (has_precision) + tmp_length = local_strnlen (arg, precision); + else + tmp_length = strlen (arg); # endif - } - break; - - case 'p': - tmp_length = - (unsigned int) (sizeof (void *) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1 /* turn floor into ceil */ - + 2; /* account for leading 0x */ - break; - - default: - abort (); - } - - if (!pad_ourselves) - { + } + break; + + case 'p': + tmp_length = + (unsigned int) (sizeof (void *) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1 /* turn floor into ceil */ + + 2; /* account for leading 0x */ + break; + + default: + abort (); + } + + if (!pad_ourselves) + { # if ENABLE_UNISTDIO - /* Padding considers the number of characters, therefore - the number of elements after padding may be - > max (tmp_length, width) - but is certainly - <= tmp_length + width. */ - tmp_length = xsum (tmp_length, width); + /* Padding considers the number of characters, therefore + the number of elements after padding may be + > max (tmp_length, width) + but is certainly + <= tmp_length + width. */ + tmp_length = xsum (tmp_length, width); # else - /* Padding considers the number of elements, - says POSIX. */ - if (tmp_length < width) - tmp_length = width; + /* Padding considers the number of elements, + says POSIX. */ + if (tmp_length < width) + tmp_length = width; # endif - } - - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - } - - if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T)); - - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (TCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } + } + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + } + + if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T)); + + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (TCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } #endif - /* Construct the format string for calling snprintf or - sprintf. */ - fbp = buf; - *fbp++ = '%'; + /* Construct the format string for calling snprintf or + sprintf. */ + fbp = buf; + *fbp++ = '%'; #if NEED_PRINTF_FLAG_GROUPING - /* The underlying implementation doesn't support the ' flag. - Produce no grouping characters in this case; this is - acceptable because the grouping is locale dependent. */ + /* The underlying implementation doesn't support the ' flag. + Produce no grouping characters in this case; this is + acceptable because the grouping is locale dependent. */ #else - if (flags & FLAG_GROUP) - *fbp++ = '\''; + if (flags & FLAG_GROUP) + *fbp++ = '\''; #endif - if (flags & FLAG_LEFT) - *fbp++ = '-'; - if (flags & FLAG_SHOWSIGN) - *fbp++ = '+'; - if (flags & FLAG_SPACE) - *fbp++ = ' '; - if (flags & FLAG_ALT) - *fbp++ = '#'; - if (!pad_ourselves) - { - if (flags & FLAG_ZERO) - *fbp++ = '0'; - if (dp->width_start != dp->width_end) - { - size_t n = dp->width_end - dp->width_start; - /* The width specification is known to consist only - of standard ASCII characters. */ - if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) - { - memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T)); - fbp += n; - } - else - { - const FCHAR_T *mp = dp->width_start; - do - *fbp++ = (unsigned char) *mp++; - while (--n > 0); - } - } - } - if (!prec_ourselves) - { - if (dp->precision_start != dp->precision_end) - { - size_t n = dp->precision_end - dp->precision_start; - /* The precision specification is known to consist only - of standard ASCII characters. */ - if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) - { - memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T)); - fbp += n; - } - else - { - const FCHAR_T *mp = dp->precision_start; - do - *fbp++ = (unsigned char) *mp++; - while (--n > 0); - } - } - } - - switch (type) - { + if (flags & FLAG_LEFT) + *fbp++ = '-'; + if (flags & FLAG_SHOWSIGN) + *fbp++ = '+'; + if (flags & FLAG_SPACE) + *fbp++ = ' '; + if (flags & FLAG_ALT) + *fbp++ = '#'; + if (!pad_ourselves) + { + if (flags & FLAG_ZERO) + *fbp++ = '0'; + if (dp->width_start != dp->width_end) + { + size_t n = dp->width_end - dp->width_start; + /* The width specification is known to consist only + of standard ASCII characters. */ + if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) + { + memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T)); + fbp += n; + } + else + { + const FCHAR_T *mp = dp->width_start; + do + *fbp++ = (unsigned char) *mp++; + while (--n > 0); + } + } + } + if (!prec_ourselves) + { + if (dp->precision_start != dp->precision_end) + { + size_t n = dp->precision_end - dp->precision_start; + /* The precision specification is known to consist only + of standard ASCII characters. */ + if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) + { + memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T)); + fbp += n; + } + else + { + const FCHAR_T *mp = dp->precision_start; + do + *fbp++ = (unsigned char) *mp++; + while (--n > 0); + } + } + } + + switch (type) + { #if HAVE_LONG_LONG_INT - case TYPE_LONGLONGINT: - case TYPE_ULONGLONGINT: + case TYPE_LONGLONGINT: + case TYPE_ULONGLONGINT: # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - *fbp++ = 'I'; - *fbp++ = '6'; - *fbp++ = '4'; - break; + *fbp++ = 'I'; + *fbp++ = '6'; + *fbp++ = '4'; + break; # else - *fbp++ = 'l'; - /*FALLTHROUGH*/ + *fbp++ = 'l'; + /*FALLTHROUGH*/ # endif #endif - case TYPE_LONGINT: - case TYPE_ULONGINT: + case TYPE_LONGINT: + case TYPE_ULONGINT: #if HAVE_WINT_T - case TYPE_WIDE_CHAR: + case TYPE_WIDE_CHAR: #endif #if HAVE_WCHAR_T - case TYPE_WIDE_STRING: + case TYPE_WIDE_STRING: #endif - *fbp++ = 'l'; - break; - case TYPE_LONGDOUBLE: - *fbp++ = 'L'; - break; - default: - break; - } + *fbp++ = 'l'; + break; + case TYPE_LONGDOUBLE: + *fbp++ = 'L'; + break; + default: + break; + } #if NEED_PRINTF_DIRECTIVE_F - if (dp->conversion == 'F') - *fbp = 'f'; - else + if (dp->conversion == 'F') + *fbp = 'f'; + else #endif - *fbp = dp->conversion; + *fbp = dp->conversion; #if USE_SNPRINTF # if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) - fbp[1] = '%'; - fbp[2] = 'n'; - fbp[3] = '\0'; + fbp[1] = '%'; + fbp[2] = 'n'; + fbp[3] = '\0'; # else - /* On glibc2 systems from glibc >= 2.3 - probably also older - ones - we know that snprintf's returns value conforms to - ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes. - Therefore we can avoid using %n in this situation. - On glibc2 systems from 2004-10-18 or newer, the use of %n - in format strings in writable memory may crash the program - (if compiled with _FORTIFY_SOURCE=2), so we should avoid it - in this situation. */ - /* On native Win32 systems (such as mingw), we can avoid using - %n because: - - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, - snprintf does not write more than the specified number - of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes - '4', '5', '6' into buf, not '4', '5', '\0'.) - - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf - allows us to recognize the case of an insufficient - buffer size: it returns -1 in this case. - On native Win32 systems (such as mingw) where the OS is - Windows Vista, the use of %n in format strings by default - crashes the program. See - and - - So we should avoid %n in this situation. */ - fbp[1] = '\0'; + /* On glibc2 systems from glibc >= 2.3 - probably also older + ones - we know that snprintf's returns value conforms to + ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes. + Therefore we can avoid using %n in this situation. + On glibc2 systems from 2004-10-18 or newer, the use of %n + in format strings in writable memory may crash the program + (if compiled with _FORTIFY_SOURCE=2), so we should avoid it + in this situation. */ + /* On native Win32 systems (such as mingw), we can avoid using + %n because: + - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, + snprintf does not write more than the specified number + of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes + '4', '5', '6' into buf, not '4', '5', '\0'.) + - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf + allows us to recognize the case of an insufficient + buffer size: it returns -1 in this case. + On native Win32 systems (such as mingw) where the OS is + Windows Vista, the use of %n in format strings by default + crashes the program. See + and + + So we should avoid %n in this situation. */ + fbp[1] = '\0'; # endif #else - fbp[1] = '\0'; + fbp[1] = '\0'; #endif - /* Construct the arguments for calling snprintf or sprintf. */ - prefix_count = 0; - if (!pad_ourselves && dp->width_arg_index != ARG_NONE) - { - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; - } - if (!prec_ourselves && dp->precision_arg_index != ARG_NONE) - { - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; - } + /* Construct the arguments for calling snprintf or sprintf. */ + prefix_count = 0; + if (!pad_ourselves && dp->width_arg_index != ARG_NONE) + { + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; + } + if (!prec_ourselves && dp->precision_arg_index != ARG_NONE) + { + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; + } #if USE_SNPRINTF - /* The SNPRINTF result is appended after result[0..length]. - The latter is an array of DCHAR_T; SNPRINTF appends an - array of TCHAR_T to it. This is possible because - sizeof (TCHAR_T) divides sizeof (DCHAR_T) and - alignof (TCHAR_T) <= alignof (DCHAR_T). */ + /* The SNPRINTF result is appended after result[0..length]. + The latter is an array of DCHAR_T; SNPRINTF appends an + array of TCHAR_T to it. This is possible because + sizeof (TCHAR_T) divides sizeof (DCHAR_T) and + alignof (TCHAR_T) <= alignof (DCHAR_T). */ # define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T)) - /* Ensure that maxlen below will be >= 2. Needed on BeOS, - where an snprintf() with maxlen==1 acts like sprintf(). */ - ENSURE_ALLOCATION (xsum (length, - (2 + TCHARS_PER_DCHAR - 1) - / TCHARS_PER_DCHAR)); - /* Prepare checking whether snprintf returns the count - via %n. */ - *(TCHAR_T *) (result + length) = '\0'; + /* Ensure that maxlen below will be >= 2. Needed on BeOS, + where an snprintf() with maxlen==1 acts like sprintf(). */ + ENSURE_ALLOCATION (xsum (length, + (2 + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR)); + /* Prepare checking whether snprintf returns the count + via %n. */ + *(TCHAR_T *) (result + length) = '\0'; #endif - for (;;) - { - int count = -1; + for (;;) + { + int count = -1; #if USE_SNPRINTF - int retcount = 0; - size_t maxlen = allocated - length; - /* SNPRINTF can fail if its second argument is - > INT_MAX. */ - if (maxlen > INT_MAX / TCHARS_PER_DCHAR) - maxlen = INT_MAX / TCHARS_PER_DCHAR; - maxlen = maxlen * TCHARS_PER_DCHAR; + int retcount = 0; + size_t maxlen = allocated - length; + /* SNPRINTF can fail if its second argument is + > INT_MAX. */ + if (maxlen > INT_MAX / TCHARS_PER_DCHAR) + maxlen = INT_MAX / TCHARS_PER_DCHAR; + maxlen = maxlen * TCHARS_PER_DCHAR; # define SNPRINTF_BUF(arg) \ - switch (prefix_count) \ - { \ - case 0: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - arg, &count); \ - break; \ - case 1: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - prefixes[0], arg, &count); \ - break; \ - case 2: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - prefixes[0], prefixes[1], arg, \ - &count); \ - break; \ - default: \ - abort (); \ - } + switch (prefix_count) \ + { \ + case 0: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + arg, &count); \ + break; \ + case 1: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + prefixes[0], arg, &count); \ + break; \ + case 2: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + prefixes[0], prefixes[1], arg, \ + &count); \ + break; \ + default: \ + abort (); \ + } #else # define SNPRINTF_BUF(arg) \ - switch (prefix_count) \ - { \ - case 0: \ - count = sprintf (tmp, buf, arg); \ - break; \ - case 1: \ - count = sprintf (tmp, buf, prefixes[0], arg); \ - break; \ - case 2: \ - count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ - arg); \ - break; \ - default: \ - abort (); \ - } + switch (prefix_count) \ + { \ + case 0: \ + count = sprintf (tmp, buf, arg); \ + break; \ + case 1: \ + count = sprintf (tmp, buf, prefixes[0], arg); \ + break; \ + case 2: \ + count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ + arg); \ + break; \ + default: \ + abort (); \ + } #endif - switch (type) - { - case TYPE_SCHAR: - { - int arg = a.arg[dp->arg_index].a.a_schar; - SNPRINTF_BUF (arg); - } - break; - case TYPE_UCHAR: - { - unsigned int arg = a.arg[dp->arg_index].a.a_uchar; - SNPRINTF_BUF (arg); - } - break; - case TYPE_SHORT: - { - int arg = a.arg[dp->arg_index].a.a_short; - SNPRINTF_BUF (arg); - } - break; - case TYPE_USHORT: - { - unsigned int arg = a.arg[dp->arg_index].a.a_ushort; - SNPRINTF_BUF (arg); - } - break; - case TYPE_INT: - { - int arg = a.arg[dp->arg_index].a.a_int; - SNPRINTF_BUF (arg); - } - break; - case TYPE_UINT: - { - unsigned int arg = a.arg[dp->arg_index].a.a_uint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_LONGINT: - { - long int arg = a.arg[dp->arg_index].a.a_longint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_ULONGINT: - { - unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; - SNPRINTF_BUF (arg); - } - break; + switch (type) + { + case TYPE_SCHAR: + { + int arg = a.arg[dp->arg_index].a.a_schar; + SNPRINTF_BUF (arg); + } + break; + case TYPE_UCHAR: + { + unsigned int arg = a.arg[dp->arg_index].a.a_uchar; + SNPRINTF_BUF (arg); + } + break; + case TYPE_SHORT: + { + int arg = a.arg[dp->arg_index].a.a_short; + SNPRINTF_BUF (arg); + } + break; + case TYPE_USHORT: + { + unsigned int arg = a.arg[dp->arg_index].a.a_ushort; + SNPRINTF_BUF (arg); + } + break; + case TYPE_INT: + { + int arg = a.arg[dp->arg_index].a.a_int; + SNPRINTF_BUF (arg); + } + break; + case TYPE_UINT: + { + unsigned int arg = a.arg[dp->arg_index].a.a_uint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_LONGINT: + { + long int arg = a.arg[dp->arg_index].a.a_longint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_ULONGINT: + { + unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; + SNPRINTF_BUF (arg); + } + break; #if HAVE_LONG_LONG_INT - case TYPE_LONGLONGINT: - { - long long int arg = a.arg[dp->arg_index].a.a_longlongint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_ULONGLONGINT: - { - unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; - SNPRINTF_BUF (arg); - } - break; + case TYPE_LONGLONGINT: + { + long long int arg = a.arg[dp->arg_index].a.a_longlongint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_ULONGLONGINT: + { + unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; + SNPRINTF_BUF (arg); + } + break; #endif - case TYPE_DOUBLE: - { - double arg = a.arg[dp->arg_index].a.a_double; - SNPRINTF_BUF (arg); - } - break; - case TYPE_LONGDOUBLE: - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - SNPRINTF_BUF (arg); - } - break; - case TYPE_CHAR: - { - int arg = a.arg[dp->arg_index].a.a_char; - SNPRINTF_BUF (arg); - } - break; + case TYPE_DOUBLE: + { + double arg = a.arg[dp->arg_index].a.a_double; + SNPRINTF_BUF (arg); + } + break; + case TYPE_LONGDOUBLE: + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + SNPRINTF_BUF (arg); + } + break; + case TYPE_CHAR: + { + int arg = a.arg[dp->arg_index].a.a_char; + SNPRINTF_BUF (arg); + } + break; #if HAVE_WINT_T - case TYPE_WIDE_CHAR: - { - wint_t arg = a.arg[dp->arg_index].a.a_wide_char; - SNPRINTF_BUF (arg); - } - break; + case TYPE_WIDE_CHAR: + { + wint_t arg = a.arg[dp->arg_index].a.a_wide_char; + SNPRINTF_BUF (arg); + } + break; #endif - case TYPE_STRING: - { - const char *arg = a.arg[dp->arg_index].a.a_string; - SNPRINTF_BUF (arg); - } - break; + case TYPE_STRING: + { + const char *arg = a.arg[dp->arg_index].a.a_string; + SNPRINTF_BUF (arg); + } + break; #if HAVE_WCHAR_T - case TYPE_WIDE_STRING: - { - const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; - SNPRINTF_BUF (arg); - } - break; + case TYPE_WIDE_STRING: + { + const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; + SNPRINTF_BUF (arg); + } + break; #endif - case TYPE_POINTER: - { - void *arg = a.arg[dp->arg_index].a.a_pointer; - SNPRINTF_BUF (arg); - } - break; - default: - abort (); - } + case TYPE_POINTER: + { + void *arg = a.arg[dp->arg_index].a.a_pointer; + SNPRINTF_BUF (arg); + } + break; + default: + abort (); + } #if USE_SNPRINTF - /* Portability: Not all implementations of snprintf() - are ISO C 99 compliant. Determine the number of - bytes that snprintf() has produced or would have - produced. */ - if (count >= 0) - { - /* Verify that snprintf() has NUL-terminated its - result. */ - if (count < maxlen - && ((TCHAR_T *) (result + length)) [count] != '\0') - abort (); - /* Portability hack. */ - if (retcount > count) - count = retcount; - } - else - { - /* snprintf() doesn't understand the '%n' - directive. */ - if (fbp[1] != '\0') - { - /* Don't use the '%n' directive; instead, look - at the snprintf() return value. */ - fbp[1] = '\0'; - continue; - } - else - { - /* Look at the snprintf() return value. */ - if (retcount < 0) - { - /* HP-UX 10.20 snprintf() is doubly deficient: - It doesn't understand the '%n' directive, - *and* it returns -1 (rather than the length - that would have been required) when the - buffer is too small. */ - size_t bigger_need = - xsum (xtimes (allocated, 2), 12); - ENSURE_ALLOCATION (bigger_need); - continue; - } - else - count = retcount; - } - } + /* Portability: Not all implementations of snprintf() + are ISO C 99 compliant. Determine the number of + bytes that snprintf() has produced or would have + produced. */ + if (count >= 0) + { + /* Verify that snprintf() has NUL-terminated its + result. */ + if (count < maxlen + && ((TCHAR_T *) (result + length)) [count] != '\0') + abort (); + /* Portability hack. */ + if (retcount > count) + count = retcount; + } + else + { + /* snprintf() doesn't understand the '%n' + directive. */ + if (fbp[1] != '\0') + { + /* Don't use the '%n' directive; instead, look + at the snprintf() return value. */ + fbp[1] = '\0'; + continue; + } + else + { + /* Look at the snprintf() return value. */ + if (retcount < 0) + { + /* HP-UX 10.20 snprintf() is doubly deficient: + It doesn't understand the '%n' directive, + *and* it returns -1 (rather than the length + that would have been required) when the + buffer is too small. */ + size_t bigger_need = + xsum (xtimes (allocated, 2), 12); + ENSURE_ALLOCATION (bigger_need); + continue; + } + else + count = retcount; + } + } #endif - /* Attempt to handle failure. */ - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EINVAL; - return NULL; - } + /* Attempt to handle failure. */ + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EINVAL; + return NULL; + } #if USE_SNPRINTF - /* Handle overflow of the allocated buffer. - If such an overflow occurs, a C99 compliant snprintf() - returns a count >= maxlen. However, a non-compliant - snprintf() function returns only count = maxlen - 1. To - cover both cases, test whether count >= maxlen - 1. */ - if ((unsigned int) count + 1 >= maxlen) - { - /* If maxlen already has attained its allowed maximum, - allocating more memory will not increase maxlen. - Instead of looping, bail out. */ - if (maxlen == INT_MAX / TCHARS_PER_DCHAR) - goto overflow; - else - { - /* Need at least (count + 1) * sizeof (TCHAR_T) - bytes. (The +1 is for the trailing NUL.) - But ask for (count + 2) * sizeof (TCHAR_T) - bytes, so that in the next round, we likely get - maxlen > (unsigned int) count + 1 - and so we don't get here again. - And allocate proportionally, to avoid looping - eternally if snprintf() reports a too small - count. */ - size_t n = - xmax (xsum (length, - ((unsigned int) count + 2 - + TCHARS_PER_DCHAR - 1) - / TCHARS_PER_DCHAR), - xtimes (allocated, 2)); - - ENSURE_ALLOCATION (n); - continue; - } - } + /* Handle overflow of the allocated buffer. + If such an overflow occurs, a C99 compliant snprintf() + returns a count >= maxlen. However, a non-compliant + snprintf() function returns only count = maxlen - 1. To + cover both cases, test whether count >= maxlen - 1. */ + if ((unsigned int) count + 1 >= maxlen) + { + /* If maxlen already has attained its allowed maximum, + allocating more memory will not increase maxlen. + Instead of looping, bail out. */ + if (maxlen == INT_MAX / TCHARS_PER_DCHAR) + goto overflow; + else + { + /* Need at least (count + 1) * sizeof (TCHAR_T) + bytes. (The +1 is for the trailing NUL.) + But ask for (count + 2) * sizeof (TCHAR_T) + bytes, so that in the next round, we likely get + maxlen > (unsigned int) count + 1 + and so we don't get here again. + And allocate proportionally, to avoid looping + eternally if snprintf() reports a too small + count. */ + size_t n = + xmax (xsum (length, + ((unsigned int) count + 2 + + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR), + xtimes (allocated, 2)); + + ENSURE_ALLOCATION (n); + continue; + } + } #endif #if NEED_PRINTF_UNBOUNDED_PRECISION - if (prec_ourselves) - { - /* Handle the precision. */ - TCHAR_T *prec_ptr = + if (prec_ourselves) + { + /* Handle the precision. */ + TCHAR_T *prec_ptr = # if USE_SNPRINTF - (TCHAR_T *) (result + length); + (TCHAR_T *) (result + length); # else - tmp; + tmp; # endif - size_t prefix_count; - size_t move; - - prefix_count = 0; - /* Put the additional zeroes after the sign. */ - if (count >= 1 - && (*prec_ptr == '-' || *prec_ptr == '+' - || *prec_ptr == ' ')) - prefix_count = 1; - /* Put the additional zeroes after the 0x prefix if - (flags & FLAG_ALT) || (dp->conversion == 'p'). */ - else if (count >= 2 - && prec_ptr[0] == '0' - && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X')) - prefix_count = 2; - - move = count - prefix_count; - if (precision > move) - { - /* Insert zeroes. */ - size_t insert = precision - move; - TCHAR_T *prec_end; + size_t prefix_count; + size_t move; + + prefix_count = 0; + /* Put the additional zeroes after the sign. */ + if (count >= 1 + && (*prec_ptr == '-' || *prec_ptr == '+' + || *prec_ptr == ' ')) + prefix_count = 1; + /* Put the additional zeroes after the 0x prefix if + (flags & FLAG_ALT) || (dp->conversion == 'p'). */ + else if (count >= 2 + && prec_ptr[0] == '0' + && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X')) + prefix_count = 2; + + move = count - prefix_count; + if (precision > move) + { + /* Insert zeroes. */ + size_t insert = precision - move; + TCHAR_T *prec_end; # if USE_SNPRINTF - size_t n = - xsum (length, - (count + insert + TCHARS_PER_DCHAR - 1) - / TCHARS_PER_DCHAR); - length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; - ENSURE_ALLOCATION (n); - length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; - prec_ptr = (TCHAR_T *) (result + length); + size_t n = + xsum (length, + (count + insert + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR); + length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; + ENSURE_ALLOCATION (n); + length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; + prec_ptr = (TCHAR_T *) (result + length); # endif - prec_end = prec_ptr + count; - prec_ptr += prefix_count; + prec_end = prec_ptr + count; + prec_ptr += prefix_count; - while (prec_end > prec_ptr) - { - prec_end--; - prec_end[insert] = prec_end[0]; - } + while (prec_end > prec_ptr) + { + prec_end--; + prec_end[insert] = prec_end[0]; + } - prec_end += insert; - do - *--prec_end = '0'; - while (prec_end > prec_ptr); + prec_end += insert; + do + *--prec_end = '0'; + while (prec_end > prec_ptr); - count += insert; - } - } + count += insert; + } + } #endif #if !USE_SNPRINTF - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); #endif #if !DCHAR_IS_TCHAR - /* Convert from TCHAR_T[] to DCHAR_T[]. */ - if (dp->conversion == 'c' || dp->conversion == 's') - { - /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING - TYPE_WIDE_STRING. - The result string is not certainly ASCII. */ - const TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t tmpdst_len; - /* This code assumes that TCHAR_T is 'char'. */ - typedef int TCHAR_T_verify - [2 * (sizeof (TCHAR_T) == 1) - 1]; + /* Convert from TCHAR_T[] to DCHAR_T[]. */ + if (dp->conversion == 'c' || dp->conversion == 's') + { + /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING + TYPE_WIDE_STRING. + The result string is not certainly ASCII. */ + const TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t tmpdst_len; + /* This code assumes that TCHAR_T is 'char'. */ + typedef int TCHAR_T_verify + [2 * (sizeof (TCHAR_T) == 1) - 1]; # if USE_SNPRINTF - tmpsrc = (TCHAR_T *) (result + length); + tmpsrc = (TCHAR_T *) (result + length); # else - tmpsrc = tmp; + tmpsrc = tmp; # endif - tmpdst = - DCHAR_CONV_FROM_ENCODING (locale_charset (), - iconveh_question_mark, - tmpsrc, count, - NULL, - NULL, &tmpdst_len); - if (tmpdst == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - ENSURE_ALLOCATION (xsum (length, tmpdst_len)); - DCHAR_CPY (result + length, tmpdst, tmpdst_len); - free (tmpdst); - count = tmpdst_len; - } - else - { - /* The result string is ASCII. - Simple 1:1 conversion. */ + tmpdst = + DCHAR_CONV_FROM_ENCODING (locale_charset (), + iconveh_question_mark, + tmpsrc, count, + NULL, + NULL, &tmpdst_len); + if (tmpdst == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + ENSURE_ALLOCATION (xsum (length, tmpdst_len)); + DCHAR_CPY (result + length, tmpdst, tmpdst_len); + free (tmpdst); + count = tmpdst_len; + } + else + { + /* The result string is ASCII. + Simple 1:1 conversion. */ # if USE_SNPRINTF - /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a - no-op conversion, in-place on the array starting - at (result + length). */ - if (sizeof (DCHAR_T) != sizeof (TCHAR_T)) + /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a + no-op conversion, in-place on the array starting + at (result + length). */ + if (sizeof (DCHAR_T) != sizeof (TCHAR_T)) # endif - { - const TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t n; + { + const TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t n; # if USE_SNPRINTF - if (result == resultbuf) - { - tmpsrc = (TCHAR_T *) (result + length); - /* ENSURE_ALLOCATION will not move tmpsrc - (because it's part of resultbuf). */ - ENSURE_ALLOCATION (xsum (length, count)); - } - else - { - /* ENSURE_ALLOCATION will move the array - (because it uses realloc(). */ - ENSURE_ALLOCATION (xsum (length, count)); - tmpsrc = (TCHAR_T *) (result + length); - } + if (result == resultbuf) + { + tmpsrc = (TCHAR_T *) (result + length); + /* ENSURE_ALLOCATION will not move tmpsrc + (because it's part of resultbuf). */ + ENSURE_ALLOCATION (xsum (length, count)); + } + else + { + /* ENSURE_ALLOCATION will move the array + (because it uses realloc(). */ + ENSURE_ALLOCATION (xsum (length, count)); + tmpsrc = (TCHAR_T *) (result + length); + } # else - tmpsrc = tmp; - ENSURE_ALLOCATION (xsum (length, count)); + tmpsrc = tmp; + ENSURE_ALLOCATION (xsum (length, count)); # endif - tmpdst = result + length; - /* Copy backwards, because of overlapping. */ - tmpsrc += count; - tmpdst += count; - for (n = count; n > 0; n--) - *--tmpdst = (unsigned char) *--tmpsrc; - } - } + tmpdst = result + length; + /* Copy backwards, because of overlapping. */ + tmpsrc += count; + tmpdst += count; + for (n = count; n > 0; n--) + *--tmpdst = (unsigned char) *--tmpsrc; + } + } #endif #if DCHAR_IS_TCHAR && !USE_SNPRINTF - /* Make room for the result. */ - if (count > allocated - length) - { - /* Need at least count elements. But allocate - proportionally. */ - size_t n = - xmax (xsum (length, count), xtimes (allocated, 2)); - - ENSURE_ALLOCATION (n); - } + /* Make room for the result. */ + if (count > allocated - length) + { + /* Need at least count elements. But allocate + proportionally. */ + size_t n = + xmax (xsum (length, count), xtimes (allocated, 2)); + + ENSURE_ALLOCATION (n); + } #endif - /* Here count <= allocated - length. */ + /* Here count <= allocated - length. */ - /* Perform padding. */ + /* Perform padding. */ #if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - if (pad_ourselves && has_width) - { - size_t w; + if (pad_ourselves && has_width) + { + size_t w; # if ENABLE_UNISTDIO - /* Outside POSIX, it's preferrable to compare the width - against the number of _characters_ of the converted - value. */ - w = DCHAR_MBSNLEN (result + length, count); + /* Outside POSIX, it's preferrable to compare the width + against the number of _characters_ of the converted + value. */ + w = DCHAR_MBSNLEN (result + length, count); # else - /* The width is compared against the number of _bytes_ - of the converted value, says POSIX. */ - w = count; + /* The width is compared against the number of _bytes_ + of the converted value, says POSIX. */ + w = count; # endif - if (w < width) - { - size_t pad = width - w; - - /* Make room for the result. */ - if (xsum (count, pad) > allocated - length) - { - /* Need at least count + pad elements. But - allocate proportionally. */ - size_t n = - xmax (xsum3 (length, count, pad), - xtimes (allocated, 2)); + if (w < width) + { + size_t pad = width - w; + + /* Make room for the result. */ + if (xsum (count, pad) > allocated - length) + { + /* Need at least count + pad elements. But + allocate proportionally. */ + size_t n = + xmax (xsum3 (length, count, pad), + xtimes (allocated, 2)); # if USE_SNPRINTF - length += count; - ENSURE_ALLOCATION (n); - length -= count; + length += count; + ENSURE_ALLOCATION (n); + length -= count; # else - ENSURE_ALLOCATION (n); + ENSURE_ALLOCATION (n); # endif - } - /* Here count + pad <= allocated - length. */ + } + /* Here count + pad <= allocated - length. */ - { + { # if !DCHAR_IS_TCHAR || USE_SNPRINTF - DCHAR_T * const rp = result + length; + DCHAR_T * const rp = result + length; # else - DCHAR_T * const rp = tmp; + DCHAR_T * const rp = tmp; # endif - DCHAR_T *p = rp + count; - DCHAR_T *end = p + pad; - DCHAR_T *pad_ptr; + DCHAR_T *p = rp + count; + DCHAR_T *end = p + pad; + DCHAR_T *pad_ptr; # if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO - if (dp->conversion == 'c' - || dp->conversion == 's') - /* No zero-padding for string directives. */ - pad_ptr = NULL; - else + if (dp->conversion == 'c' + || dp->conversion == 's') + /* No zero-padding for string directives. */ + pad_ptr = NULL; + else # endif - { - pad_ptr = (*rp == '-' ? rp + 1 : rp); - /* No zero-padding of "inf" and "nan". */ - if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z') - || (*pad_ptr >= 'a' && *pad_ptr <= 'z')) - pad_ptr = NULL; - } - /* The generated string now extends from rp to p, - with the zero padding insertion point being at - pad_ptr. */ - - count = count + pad; /* = end - rp */ - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > rp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - } - } - } + { + pad_ptr = (*rp == '-' ? rp + 1 : rp); + /* No zero-padding of "inf" and "nan". */ + if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z') + || (*pad_ptr >= 'a' && *pad_ptr <= 'z')) + pad_ptr = NULL; + } + /* The generated string now extends from rp to p, + with the zero padding insertion point being at + pad_ptr. */ + + count = count + pad; /* = end - rp */ + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > rp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + } + } + } #endif - /* Here still count <= allocated - length. */ + /* Here still count <= allocated - length. */ #if !DCHAR_IS_TCHAR || USE_SNPRINTF - /* The snprintf() result did fit. */ + /* The snprintf() result did fit. */ #else - /* Append the sprintf() result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + /* Append the sprintf() result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); #endif #if !USE_SNPRINTF - if (tmp != tmpbuf) - free (tmp); + if (tmp != tmpbuf) + free (tmp); #endif #if NEED_PRINTF_DIRECTIVE_F - if (dp->conversion == 'F') - { - /* Convert the %f result to upper case for %F. */ - DCHAR_T *rp = result + length; - size_t rc; - for (rc = count; rc > 0; rc--, rp++) - if (*rp >= 'a' && *rp <= 'z') - *rp = *rp - 'a' + 'A'; - } + if (dp->conversion == 'F') + { + /* Convert the %f result to upper case for %F. */ + DCHAR_T *rp = result + length; + size_t rc; + for (rc = count; rc > 0; rc--, rp++) + if (*rp >= 'a' && *rp <= 'z') + *rp = *rp - 'a' + 'A'; + } #endif - length += count; - break; - } - } - } + length += count; + break; + } + } + } } /* Add the final NUL. */ @@ -5433,12 +5433,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, if (result != resultbuf && length + 1 < allocated) { - /* Shrink the allocated memory if possible. */ - DCHAR_T *memory; + /* Shrink the allocated memory if possible. */ + DCHAR_T *memory; - memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); - if (memory != NULL) - result = memory; + memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); + if (memory != NULL) + result = memory; } if (buf_malloced != NULL) diff --git a/gettext-runtime/intl/vasnwprintf.h b/gettext-runtime/intl/vasnwprintf.h index 6ff03ce16..a01745bd7 100644 --- a/gettext-runtime/intl/vasnwprintf.h +++ b/gettext-runtime/intl/vasnwprintf.h @@ -25,7 +25,7 @@ /* Get wchar_t, size_t. */ #include -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -39,7 +39,7 @@ extern "C" { extern wchar_t * asnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, ...); extern wchar_t * vasnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, va_list args); -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/gettext-runtime/intl/wprintf-parse.h b/gettext-runtime/intl/wprintf-parse.h index 600b89adc..a08356ed6 100644 --- a/gettext-runtime/intl/wprintf-parse.h +++ b/gettext-runtime/intl/wprintf-parse.h @@ -23,15 +23,15 @@ /* Flags */ -#define FLAG_GROUP 1 /* ' flag */ -#define FLAG_LEFT 2 /* - flag */ -#define FLAG_SHOWSIGN 4 /* + flag */ -#define FLAG_SPACE 8 /* space flag */ -#define FLAG_ALT 16 /* # flag */ -#define FLAG_ZERO 32 +#define FLAG_GROUP 1 /* ' flag */ +#define FLAG_LEFT 2 /* - flag */ +#define FLAG_SHOWSIGN 4 /* + flag */ +#define FLAG_SPACE 8 /* space flag */ +#define FLAG_ALT 16 /* # flag */ +#define FLAG_ZERO 32 /* arg_index value indicating that no argument is consumed. */ -#define ARG_NONE (~(size_t)0) +#define ARG_NONE (~(size_t)0) /* A parsed directive. */ typedef struct diff --git a/gettext-runtime/libasprintf/ChangeLog b/gettext-runtime/libasprintf/ChangeLog index c81433fcd..1bd01bc8d 100644 --- a/gettext-runtime/libasprintf/ChangeLog +++ b/gettext-runtime/libasprintf/ChangeLog @@ -1,3 +1,7 @@ +2009-12-12 Bruno Haible + + * *.h, *.c: Untabify. + 2009-11-22 Bruno Haible * vasnprintf.c (decimal_point_char): Choose the fast path also on diff --git a/gettext-runtime/libasprintf/printf-args.c b/gettext-runtime/libasprintf/printf-args.c index cbd437d87..44e50a33c 100644 --- a/gettext-runtime/libasprintf/printf-args.c +++ b/gettext-runtime/libasprintf/printf-args.c @@ -43,146 +43,146 @@ PRINTF_FETCHARGS (va_list args, arguments *a) switch (ap->type) { case TYPE_SCHAR: - ap->a.a_schar = va_arg (args, /*signed char*/ int); - break; + ap->a.a_schar = va_arg (args, /*signed char*/ int); + break; case TYPE_UCHAR: - ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); - break; + ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); + break; case TYPE_SHORT: - ap->a.a_short = va_arg (args, /*short*/ int); - break; + ap->a.a_short = va_arg (args, /*short*/ int); + break; case TYPE_USHORT: - ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); - break; + ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); + break; case TYPE_INT: - ap->a.a_int = va_arg (args, int); - break; + ap->a.a_int = va_arg (args, int); + break; case TYPE_UINT: - ap->a.a_uint = va_arg (args, unsigned int); - break; + ap->a.a_uint = va_arg (args, unsigned int); + break; case TYPE_LONGINT: - ap->a.a_longint = va_arg (args, long int); - break; + ap->a.a_longint = va_arg (args, long int); + break; case TYPE_ULONGINT: - ap->a.a_ulongint = va_arg (args, unsigned long int); - break; + ap->a.a_ulongint = va_arg (args, unsigned long int); + break; #if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: - ap->a.a_longlongint = va_arg (args, long long int); - break; + ap->a.a_longlongint = va_arg (args, long long int); + break; case TYPE_ULONGLONGINT: - ap->a.a_ulonglongint = va_arg (args, unsigned long long int); - break; + ap->a.a_ulonglongint = va_arg (args, unsigned long long int); + break; #endif case TYPE_DOUBLE: - ap->a.a_double = va_arg (args, double); - break; + ap->a.a_double = va_arg (args, double); + break; case TYPE_LONGDOUBLE: - ap->a.a_longdouble = va_arg (args, long double); - break; + ap->a.a_longdouble = va_arg (args, long double); + break; case TYPE_CHAR: - ap->a.a_char = va_arg (args, int); - break; + ap->a.a_char = va_arg (args, int); + break; #if HAVE_WINT_T case TYPE_WIDE_CHAR: - /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by - default argument promotions", this is not the case in mingw32, - where wint_t is 'unsigned short'. */ - ap->a.a_wide_char = - (sizeof (wint_t) < sizeof (int) - ? va_arg (args, int) - : va_arg (args, wint_t)); - break; + /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by + default argument promotions", this is not the case in mingw32, + where wint_t is 'unsigned short'. */ + ap->a.a_wide_char = + (sizeof (wint_t) < sizeof (int) + ? va_arg (args, int) + : va_arg (args, wint_t)); + break; #endif case TYPE_STRING: - ap->a.a_string = va_arg (args, const char *); - /* A null pointer is an invalid argument for "%s", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_string == NULL) - ap->a.a_string = "(NULL)"; - break; + ap->a.a_string = va_arg (args, const char *); + /* A null pointer is an invalid argument for "%s", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_string == NULL) + ap->a.a_string = "(NULL)"; + break; #if HAVE_WCHAR_T case TYPE_WIDE_STRING: - ap->a.a_wide_string = va_arg (args, const wchar_t *); - /* A null pointer is an invalid argument for "%ls", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_wide_string == NULL) - { - static const wchar_t wide_null_string[] = - { - (wchar_t)'(', - (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', - (wchar_t)')', - (wchar_t)0 - }; - ap->a.a_wide_string = wide_null_string; - } - break; + ap->a.a_wide_string = va_arg (args, const wchar_t *); + /* A null pointer is an invalid argument for "%ls", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_wide_string == NULL) + { + static const wchar_t wide_null_string[] = + { + (wchar_t)'(', + (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', + (wchar_t)')', + (wchar_t)0 + }; + ap->a.a_wide_string = wide_null_string; + } + break; #endif case TYPE_POINTER: - ap->a.a_pointer = va_arg (args, void *); - break; + ap->a.a_pointer = va_arg (args, void *); + break; case TYPE_COUNT_SCHAR_POINTER: - ap->a.a_count_schar_pointer = va_arg (args, signed char *); - break; + ap->a.a_count_schar_pointer = va_arg (args, signed char *); + break; case TYPE_COUNT_SHORT_POINTER: - ap->a.a_count_short_pointer = va_arg (args, short *); - break; + ap->a.a_count_short_pointer = va_arg (args, short *); + break; case TYPE_COUNT_INT_POINTER: - ap->a.a_count_int_pointer = va_arg (args, int *); - break; + ap->a.a_count_int_pointer = va_arg (args, int *); + break; case TYPE_COUNT_LONGINT_POINTER: - ap->a.a_count_longint_pointer = va_arg (args, long int *); - break; + ap->a.a_count_longint_pointer = va_arg (args, long int *); + break; #if HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: - ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); - break; + ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); + break; #endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ case TYPE_U8_STRING: - ap->a.a_u8_string = va_arg (args, const uint8_t *); - /* A null pointer is an invalid argument for "%U", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u8_string == NULL) - { - static const uint8_t u8_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u8_string = u8_null_string; - } - break; + ap->a.a_u8_string = va_arg (args, const uint8_t *); + /* A null pointer is an invalid argument for "%U", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u8_string == NULL) + { + static const uint8_t u8_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u8_string = u8_null_string; + } + break; case TYPE_U16_STRING: - ap->a.a_u16_string = va_arg (args, const uint16_t *); - /* A null pointer is an invalid argument for "%lU", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u16_string == NULL) - { - static const uint16_t u16_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u16_string = u16_null_string; - } - break; + ap->a.a_u16_string = va_arg (args, const uint16_t *); + /* A null pointer is an invalid argument for "%lU", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u16_string == NULL) + { + static const uint16_t u16_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u16_string = u16_null_string; + } + break; case TYPE_U32_STRING: - ap->a.a_u32_string = va_arg (args, const uint32_t *); - /* A null pointer is an invalid argument for "%llU", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u32_string == NULL) - { - static const uint32_t u32_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u32_string = u32_null_string; - } - break; + ap->a.a_u32_string = va_arg (args, const uint32_t *); + /* A null pointer is an invalid argument for "%llU", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u32_string == NULL) + { + static const uint32_t u32_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u32_string = u32_null_string; + } + break; #endif default: - /* Unknown type. */ - return -1; + /* Unknown type. */ + return -1; } return 0; } diff --git a/gettext-runtime/libasprintf/printf-args.h b/gettext-runtime/libasprintf/printf-args.h index cf89c3e71..f95e6bd9c 100644 --- a/gettext-runtime/libasprintf/printf-args.h +++ b/gettext-runtime/libasprintf/printf-args.h @@ -94,42 +94,42 @@ typedef struct arg_type type; union { - signed char a_schar; - unsigned char a_uchar; - short a_short; - unsigned short a_ushort; - int a_int; - unsigned int a_uint; - long int a_longint; - unsigned long int a_ulongint; + signed char a_schar; + unsigned char a_uchar; + short a_short; + unsigned short a_ushort; + int a_int; + unsigned int a_uint; + long int a_longint; + unsigned long int a_ulongint; #if HAVE_LONG_LONG_INT - long long int a_longlongint; - unsigned long long int a_ulonglongint; + long long int a_longlongint; + unsigned long long int a_ulonglongint; #endif - float a_float; - double a_double; - long double a_longdouble; - int a_char; + float a_float; + double a_double; + long double a_longdouble; + int a_char; #if HAVE_WINT_T - wint_t a_wide_char; + wint_t a_wide_char; #endif - const char* a_string; + const char* a_string; #if HAVE_WCHAR_T - const wchar_t* a_wide_string; + const wchar_t* a_wide_string; #endif - void* a_pointer; - signed char * a_count_schar_pointer; - short * a_count_short_pointer; - int * a_count_int_pointer; - long int * a_count_longint_pointer; + void* a_pointer; + signed char * a_count_schar_pointer; + short * a_count_short_pointer; + int * a_count_int_pointer; + long int * a_count_longint_pointer; #if HAVE_LONG_LONG_INT - long long int * a_count_longlongint_pointer; + long long int * a_count_longlongint_pointer; #endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ - const uint8_t * a_u8_string; - const uint16_t * a_u16_string; - const uint32_t * a_u32_string; + const uint8_t * a_u8_string; + const uint16_t * a_u16_string; + const uint32_t * a_u32_string; #endif } a; diff --git a/gettext-runtime/libasprintf/printf-parse.c b/gettext-runtime/libasprintf/printf-parse.c index 6245337cf..3f3174d06 100644 --- a/gettext-runtime/libasprintf/printf-parse.c +++ b/gettext-runtime/libasprintf/printf-parse.c @@ -81,10 +81,10 @@ STATIC int PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) { - const CHAR_T *cp = format; /* pointer into format */ - size_t arg_posn = 0; /* number of regular arguments consumed */ - size_t d_allocated; /* allocated elements of d->dir */ - size_t a_allocated; /* allocated elements of a->arg */ + const CHAR_T *cp = format; /* pointer into format */ + size_t arg_posn = 0; /* number of regular arguments consumed */ + size_t d_allocated; /* allocated elements of d->dir */ + size_t a_allocated; /* allocated elements of a->arg */ size_t max_width_length = 0; size_t max_precision_length = 0; @@ -100,501 +100,501 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) a->arg = NULL; #define REGISTER_ARG(_index_,_type_) \ - { \ - size_t n = (_index_); \ - if (n >= a_allocated) \ - { \ - size_t memory_size; \ - argument *memory; \ - \ - a_allocated = xtimes (a_allocated, 2); \ - if (a_allocated <= n) \ - a_allocated = xsum (n, 1); \ - memory_size = xtimes (a_allocated, sizeof (argument)); \ - if (size_overflow_p (memory_size)) \ - /* Overflow, would lead to out of memory. */ \ - goto out_of_memory; \ - memory = (argument *) (a->arg \ - ? realloc (a->arg, memory_size) \ - : malloc (memory_size)); \ - if (memory == NULL) \ - /* Out of memory. */ \ - goto out_of_memory; \ - a->arg = memory; \ - } \ - while (a->count <= n) \ - a->arg[a->count++].type = TYPE_NONE; \ - if (a->arg[n].type == TYPE_NONE) \ - a->arg[n].type = (_type_); \ - else if (a->arg[n].type != (_type_)) \ - /* Ambiguous type for positional argument. */ \ - goto error; \ + { \ + size_t n = (_index_); \ + if (n >= a_allocated) \ + { \ + size_t memory_size; \ + argument *memory; \ + \ + a_allocated = xtimes (a_allocated, 2); \ + if (a_allocated <= n) \ + a_allocated = xsum (n, 1); \ + memory_size = xtimes (a_allocated, sizeof (argument)); \ + if (size_overflow_p (memory_size)) \ + /* Overflow, would lead to out of memory. */ \ + goto out_of_memory; \ + memory = (argument *) (a->arg \ + ? realloc (a->arg, memory_size) \ + : malloc (memory_size)); \ + if (memory == NULL) \ + /* Out of memory. */ \ + goto out_of_memory; \ + a->arg = memory; \ + } \ + while (a->count <= n) \ + a->arg[a->count++].type = TYPE_NONE; \ + if (a->arg[n].type == TYPE_NONE) \ + a->arg[n].type = (_type_); \ + else if (a->arg[n].type != (_type_)) \ + /* Ambiguous type for positional argument. */ \ + goto error; \ } while (*cp != '\0') { CHAR_T c = *cp++; if (c == '%') - { - size_t arg_index = ARG_NONE; - DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */ - - /* Initialize the next directive. */ - dp->dir_start = cp - 1; - dp->flags = 0; - dp->width_start = NULL; - dp->width_end = NULL; - dp->width_arg_index = ARG_NONE; - dp->precision_start = NULL; - dp->precision_end = NULL; - dp->precision_arg_index = ARG_NONE; - dp->arg_index = ARG_NONE; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory later. */ - goto error; - arg_index = n - 1; - cp = np + 1; - } - } - - /* Read the flags. */ - for (;;) - { - if (*cp == '\'') - { - dp->flags |= FLAG_GROUP; - cp++; - } - else if (*cp == '-') - { - dp->flags |= FLAG_LEFT; - cp++; - } - else if (*cp == '+') - { - dp->flags |= FLAG_SHOWSIGN; - cp++; - } - else if (*cp == ' ') - { - dp->flags |= FLAG_SPACE; - cp++; - } - else if (*cp == '#') - { - dp->flags |= FLAG_ALT; - cp++; - } - else if (*cp == '0') - { - dp->flags |= FLAG_ZERO; - cp++; - } - else - break; - } - - /* Parse the field width. */ - if (*cp == '*') - { - dp->width_start = cp; - cp++; - dp->width_end = cp; - if (max_width_length < 1) - max_width_length = 1; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory later. */ - goto error; - dp->width_arg_index = n - 1; - cp = np + 1; - } - } - if (dp->width_arg_index == ARG_NONE) - { - dp->width_arg_index = arg_posn++; - if (dp->width_arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->width_arg_index, TYPE_INT); - } - else if (*cp >= '0' && *cp <= '9') - { - size_t width_length; - - dp->width_start = cp; - for (; *cp >= '0' && *cp <= '9'; cp++) - ; - dp->width_end = cp; - width_length = dp->width_end - dp->width_start; - if (max_width_length < width_length) - max_width_length = width_length; - } - - /* Parse the precision. */ - if (*cp == '.') - { - cp++; - if (*cp == '*') - { - dp->precision_start = cp - 1; - cp++; - dp->precision_end = cp; - if (max_precision_length < 2) - max_precision_length = 2; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory - later. */ - goto error; - dp->precision_arg_index = n - 1; - cp = np + 1; - } - } - if (dp->precision_arg_index == ARG_NONE) - { - dp->precision_arg_index = arg_posn++; - if (dp->precision_arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->precision_arg_index, TYPE_INT); - } - else - { - size_t precision_length; - - dp->precision_start = cp - 1; - for (; *cp >= '0' && *cp <= '9'; cp++) - ; - dp->precision_end = cp; - precision_length = dp->precision_end - dp->precision_start; - if (max_precision_length < precision_length) - max_precision_length = precision_length; - } - } - - { - arg_type type; - - /* Parse argument type/size specifiers. */ - { - int flags = 0; - - for (;;) - { - if (*cp == 'h') - { - flags |= (1 << (flags & 1)); - cp++; - } - else if (*cp == 'L') - { - flags |= 4; - cp++; - } - else if (*cp == 'l') - { - flags += 8; - cp++; - } - else if (*cp == 'j') - { - if (sizeof (intmax_t) > sizeof (long)) - { - /* intmax_t = long long */ - flags += 16; - } - else if (sizeof (intmax_t) > sizeof (int)) - { - /* intmax_t = long */ - flags += 8; - } - cp++; - } - else if (*cp == 'z' || *cp == 'Z') - { - /* 'z' is standardized in ISO C 99, but glibc uses 'Z' - because the warning facility in gcc-2.95.2 understands - only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ - if (sizeof (size_t) > sizeof (long)) - { - /* size_t = long long */ - flags += 16; - } - else if (sizeof (size_t) > sizeof (int)) - { - /* size_t = long */ - flags += 8; - } - cp++; - } - else if (*cp == 't') - { - if (sizeof (ptrdiff_t) > sizeof (long)) - { - /* ptrdiff_t = long long */ - flags += 16; - } - else if (sizeof (ptrdiff_t) > sizeof (int)) - { - /* ptrdiff_t = long */ - flags += 8; - } - cp++; - } + { + size_t arg_index = ARG_NONE; + DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */ + + /* Initialize the next directive. */ + dp->dir_start = cp - 1; + dp->flags = 0; + dp->width_start = NULL; + dp->width_end = NULL; + dp->width_arg_index = ARG_NONE; + dp->precision_start = NULL; + dp->precision_end = NULL; + dp->precision_arg_index = ARG_NONE; + dp->arg_index = ARG_NONE; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory later. */ + goto error; + arg_index = n - 1; + cp = np + 1; + } + } + + /* Read the flags. */ + for (;;) + { + if (*cp == '\'') + { + dp->flags |= FLAG_GROUP; + cp++; + } + else if (*cp == '-') + { + dp->flags |= FLAG_LEFT; + cp++; + } + else if (*cp == '+') + { + dp->flags |= FLAG_SHOWSIGN; + cp++; + } + else if (*cp == ' ') + { + dp->flags |= FLAG_SPACE; + cp++; + } + else if (*cp == '#') + { + dp->flags |= FLAG_ALT; + cp++; + } + else if (*cp == '0') + { + dp->flags |= FLAG_ZERO; + cp++; + } + else + break; + } + + /* Parse the field width. */ + if (*cp == '*') + { + dp->width_start = cp; + cp++; + dp->width_end = cp; + if (max_width_length < 1) + max_width_length = 1; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory later. */ + goto error; + dp->width_arg_index = n - 1; + cp = np + 1; + } + } + if (dp->width_arg_index == ARG_NONE) + { + dp->width_arg_index = arg_posn++; + if (dp->width_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->width_arg_index, TYPE_INT); + } + else if (*cp >= '0' && *cp <= '9') + { + size_t width_length; + + dp->width_start = cp; + for (; *cp >= '0' && *cp <= '9'; cp++) + ; + dp->width_end = cp; + width_length = dp->width_end - dp->width_start; + if (max_width_length < width_length) + max_width_length = width_length; + } + + /* Parse the precision. */ + if (*cp == '.') + { + cp++; + if (*cp == '*') + { + dp->precision_start = cp - 1; + cp++; + dp->precision_end = cp; + if (max_precision_length < 2) + max_precision_length = 2; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory + later. */ + goto error; + dp->precision_arg_index = n - 1; + cp = np + 1; + } + } + if (dp->precision_arg_index == ARG_NONE) + { + dp->precision_arg_index = arg_posn++; + if (dp->precision_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->precision_arg_index, TYPE_INT); + } + else + { + size_t precision_length; + + dp->precision_start = cp - 1; + for (; *cp >= '0' && *cp <= '9'; cp++) + ; + dp->precision_end = cp; + precision_length = dp->precision_end - dp->precision_start; + if (max_precision_length < precision_length) + max_precision_length = precision_length; + } + } + + { + arg_type type; + + /* Parse argument type/size specifiers. */ + { + int flags = 0; + + for (;;) + { + if (*cp == 'h') + { + flags |= (1 << (flags & 1)); + cp++; + } + else if (*cp == 'L') + { + flags |= 4; + cp++; + } + else if (*cp == 'l') + { + flags += 8; + cp++; + } + else if (*cp == 'j') + { + if (sizeof (intmax_t) > sizeof (long)) + { + /* intmax_t = long long */ + flags += 16; + } + else if (sizeof (intmax_t) > sizeof (int)) + { + /* intmax_t = long */ + flags += 8; + } + cp++; + } + else if (*cp == 'z' || *cp == 'Z') + { + /* 'z' is standardized in ISO C 99, but glibc uses 'Z' + because the warning facility in gcc-2.95.2 understands + only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ + if (sizeof (size_t) > sizeof (long)) + { + /* size_t = long long */ + flags += 16; + } + else if (sizeof (size_t) > sizeof (int)) + { + /* size_t = long */ + flags += 8; + } + cp++; + } + else if (*cp == 't') + { + if (sizeof (ptrdiff_t) > sizeof (long)) + { + /* ptrdiff_t = long long */ + flags += 16; + } + else if (sizeof (ptrdiff_t) > sizeof (int)) + { + /* ptrdiff_t = long */ + flags += 8; + } + cp++; + } #if defined __APPLE__ && defined __MACH__ - /* On MacOS X 10.3, PRIdMAX is defined as "qd". - We cannot change it to "lld" because PRIdMAX must also - be understood by the system's printf routines. */ - else if (*cp == 'q') - { - if (64 / 8 > sizeof (long)) - { - /* int64_t = long long */ - flags += 16; - } - else - { - /* int64_t = long */ - flags += 8; - } - cp++; - } + /* On MacOS X 10.3, PRIdMAX is defined as "qd". + We cannot change it to "lld" because PRIdMAX must also + be understood by the system's printf routines. */ + else if (*cp == 'q') + { + if (64 / 8 > sizeof (long)) + { + /* int64_t = long long */ + flags += 16; + } + else + { + /* int64_t = long */ + flags += 8; + } + cp++; + } #endif #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* On native Win32, PRIdMAX is defined as "I64d". - We cannot change it to "lld" because PRIdMAX must also - be understood by the system's printf routines. */ - else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4') - { - if (64 / 8 > sizeof (long)) - { - /* __int64 = long long */ - flags += 16; - } - else - { - /* __int64 = long */ - flags += 8; - } - cp += 3; - } + /* On native Win32, PRIdMAX is defined as "I64d". + We cannot change it to "lld" because PRIdMAX must also + be understood by the system's printf routines. */ + else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4') + { + if (64 / 8 > sizeof (long)) + { + /* __int64 = long long */ + flags += 16; + } + else + { + /* __int64 = long */ + flags += 8; + } + cp += 3; + } #endif - else - break; - } - - /* Read the conversion character. */ - c = *cp++; - switch (c) - { - case 'd': case 'i': + else + break; + } + + /* Read the conversion character. */ + c = *cp++; + switch (c) + { + case 'd': case 'i': #if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_LONGLONGINT; - else + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_LONGLONGINT; + else #endif - /* If 'long long' exists and is the same as 'long', we parse - "lld" into TYPE_LONGINT. */ - if (flags >= 8) - type = TYPE_LONGINT; - else if (flags & 2) - type = TYPE_SCHAR; - else if (flags & 1) - type = TYPE_SHORT; - else - type = TYPE_INT; - break; - case 'o': case 'u': case 'x': case 'X': + /* If 'long long' exists and is the same as 'long', we parse + "lld" into TYPE_LONGINT. */ + if (flags >= 8) + type = TYPE_LONGINT; + else if (flags & 2) + type = TYPE_SCHAR; + else if (flags & 1) + type = TYPE_SHORT; + else + type = TYPE_INT; + break; + case 'o': case 'u': case 'x': case 'X': #if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_ULONGLONGINT; - else + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_ULONGLONGINT; + else #endif - /* If 'unsigned long long' exists and is the same as - 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ - if (flags >= 8) - type = TYPE_ULONGINT; - else if (flags & 2) - type = TYPE_UCHAR; - else if (flags & 1) - type = TYPE_USHORT; - else - type = TYPE_UINT; - break; - case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': - case 'a': case 'A': - if (flags >= 16 || (flags & 4)) - type = TYPE_LONGDOUBLE; - else - type = TYPE_DOUBLE; - break; - case 'c': - if (flags >= 8) + /* If 'unsigned long long' exists and is the same as + 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ + if (flags >= 8) + type = TYPE_ULONGINT; + else if (flags & 2) + type = TYPE_UCHAR; + else if (flags & 1) + type = TYPE_USHORT; + else + type = TYPE_UINT; + break; + case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': + case 'a': case 'A': + if (flags >= 16 || (flags & 4)) + type = TYPE_LONGDOUBLE; + else + type = TYPE_DOUBLE; + break; + case 'c': + if (flags >= 8) #if HAVE_WINT_T - type = TYPE_WIDE_CHAR; + type = TYPE_WIDE_CHAR; #else - goto error; + goto error; #endif - else - type = TYPE_CHAR; - break; + else + type = TYPE_CHAR; + break; #if HAVE_WINT_T - case 'C': - type = TYPE_WIDE_CHAR; - c = 'c'; - break; + case 'C': + type = TYPE_WIDE_CHAR; + c = 'c'; + break; #endif - case 's': - if (flags >= 8) + case 's': + if (flags >= 8) #if HAVE_WCHAR_T - type = TYPE_WIDE_STRING; + type = TYPE_WIDE_STRING; #else - goto error; + goto error; #endif - else - type = TYPE_STRING; - break; + else + type = TYPE_STRING; + break; #if HAVE_WCHAR_T - case 'S': - type = TYPE_WIDE_STRING; - c = 's'; - break; + case 'S': + type = TYPE_WIDE_STRING; + c = 's'; + break; #endif - case 'p': - type = TYPE_POINTER; - break; - case 'n': + case 'p': + type = TYPE_POINTER; + break; + case 'n': #if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_COUNT_LONGLONGINT_POINTER; - else + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_COUNT_LONGLONGINT_POINTER; + else #endif - /* If 'long long' exists and is the same as 'long', we parse - "lln" into TYPE_COUNT_LONGINT_POINTER. */ - if (flags >= 8) - type = TYPE_COUNT_LONGINT_POINTER; - else if (flags & 2) - type = TYPE_COUNT_SCHAR_POINTER; - else if (flags & 1) - type = TYPE_COUNT_SHORT_POINTER; - else - type = TYPE_COUNT_INT_POINTER; - break; + /* If 'long long' exists and is the same as 'long', we parse + "lln" into TYPE_COUNT_LONGINT_POINTER. */ + if (flags >= 8) + type = TYPE_COUNT_LONGINT_POINTER; + else if (flags & 2) + type = TYPE_COUNT_SCHAR_POINTER; + else if (flags & 1) + type = TYPE_COUNT_SHORT_POINTER; + else + type = TYPE_COUNT_INT_POINTER; + break; #if ENABLE_UNISTDIO - /* The unistdio extensions. */ - case 'U': - if (flags >= 16) - type = TYPE_U32_STRING; - else if (flags >= 8) - type = TYPE_U16_STRING; - else - type = TYPE_U8_STRING; - break; + /* The unistdio extensions. */ + case 'U': + if (flags >= 16) + type = TYPE_U32_STRING; + else if (flags >= 8) + type = TYPE_U16_STRING; + else + type = TYPE_U8_STRING; + break; #endif - case '%': - type = TYPE_NONE; - break; - default: - /* Unknown conversion character. */ - goto error; - } - } - - if (type != TYPE_NONE) - { - dp->arg_index = arg_index; - if (dp->arg_index == ARG_NONE) - { - dp->arg_index = arg_posn++; - if (dp->arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->arg_index, type); - } - dp->conversion = c; - dp->dir_end = cp; - } - - d->count++; - if (d->count >= d_allocated) - { - size_t memory_size; - DIRECTIVE *memory; - - d_allocated = xtimes (d_allocated, 2); - memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); - if (size_overflow_p (memory_size)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - memory = (DIRECTIVE *) realloc (d->dir, memory_size); - if (memory == NULL) - /* Out of memory. */ - goto out_of_memory; - d->dir = memory; - } - } + case '%': + type = TYPE_NONE; + break; + default: + /* Unknown conversion character. */ + goto error; + } + } + + if (type != TYPE_NONE) + { + dp->arg_index = arg_index; + if (dp->arg_index == ARG_NONE) + { + dp->arg_index = arg_posn++; + if (dp->arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->arg_index, type); + } + dp->conversion = c; + dp->dir_end = cp; + } + + d->count++; + if (d->count >= d_allocated) + { + size_t memory_size; + DIRECTIVE *memory; + + d_allocated = xtimes (d_allocated, 2); + memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); + if (size_overflow_p (memory_size)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + memory = (DIRECTIVE *) realloc (d->dir, memory_size); + if (memory == NULL) + /* Out of memory. */ + goto out_of_memory; + d->dir = memory; + } + } #if CHAR_T_ONLY_ASCII else if (!c_isascii (c)) - { - /* Non-ASCII character. Not supported. */ - goto error; - } + { + /* Non-ASCII character. Not supported. */ + goto error; + } #endif } d->dir[d->count].dir_start = cp; diff --git a/gettext-runtime/libasprintf/printf-parse.h b/gettext-runtime/libasprintf/printf-parse.h index e78533895..51ead29ec 100644 --- a/gettext-runtime/libasprintf/printf-parse.h +++ b/gettext-runtime/libasprintf/printf-parse.h @@ -23,15 +23,15 @@ /* Flags */ -#define FLAG_GROUP 1 /* ' flag */ -#define FLAG_LEFT 2 /* - flag */ -#define FLAG_SHOWSIGN 4 /* + flag */ -#define FLAG_SPACE 8 /* space flag */ -#define FLAG_ALT 16 /* # flag */ -#define FLAG_ZERO 32 +#define FLAG_GROUP 1 /* ' flag */ +#define FLAG_LEFT 2 /* - flag */ +#define FLAG_SHOWSIGN 4 /* + flag */ +#define FLAG_SPACE 8 /* space flag */ +#define FLAG_ALT 16 /* # flag */ +#define FLAG_ZERO 32 /* arg_index value indicating that no argument is consumed. */ -#define ARG_NONE (~(size_t)0) +#define ARG_NONE (~(size_t)0) /* A parsed directive. */ typedef struct diff --git a/gettext-runtime/libasprintf/vasnprintf.c b/gettext-runtime/libasprintf/vasnprintf.c index d64cec2c5..08949b428 100644 --- a/gettext-runtime/libasprintf/vasnprintf.c +++ b/gettext-runtime/libasprintf/vasnprintf.c @@ -68,13 +68,13 @@ # endif #endif -#include /* localeconv() */ -#include /* snprintf(), sprintf() */ -#include /* abort(), malloc(), realloc(), free() */ -#include /* memcpy(), strlen() */ -#include /* errno */ -#include /* CHAR_BIT */ -#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ +#include /* localeconv() */ +#include /* snprintf(), sprintf() */ +#include /* abort(), malloc(), realloc(), free() */ +#include /* memcpy(), strlen() */ +#include /* errno */ +#include /* CHAR_BIT */ +#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ #if HAVE_NL_LANGINFO # include #endif @@ -365,26 +365,26 @@ multiply (mpn_t src1, mpn_t src2, mpn_t *dest) dlen = len1 + len2; dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t)); if (dp == NULL) - return NULL; + return NULL; for (k = len2; k > 0; ) - dp[--k] = 0; + dp[--k] = 0; for (i = 0; i < len1; i++) - { - mp_limb_t digit1 = p1[i]; - mp_twolimb_t carry = 0; - for (j = 0; j < len2; j++) - { - mp_limb_t digit2 = p2[j]; - carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; - carry += dp[i + j]; - dp[i + j] = (mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; - } - dp[i + len2] = (mp_limb_t) carry; - } + { + mp_limb_t digit1 = p1[i]; + mp_twolimb_t carry = 0; + for (j = 0; j < len2; j++) + { + mp_limb_t digit2 = p2[j]; + carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; + carry += dp[i + j]; + dp[i + j] = (mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; + } + dp[i + len2] = (mp_limb_t) carry; + } /* Normalise. */ while (dlen > 0 && dp[dlen - 1] == 0) - dlen--; + dlen--; dest->nlimbs = dlen; dest->limbs = dp; } @@ -478,12 +478,12 @@ divide (mpn_t a, mpn_t b, mpn_t *q) for (;;) { if (b_len == 0) - /* Division by zero. */ - abort (); + /* Division by zero. */ + abort (); if (b_ptr[b_len - 1] == 0) - b_len--; + b_len--; else - break; + break; } /* Here m = a_len >= 0 and n = b_len > 0. */ @@ -500,261 +500,261 @@ divide (mpn_t a, mpn_t b, mpn_t *q) else if (b_len == 1) { /* n=1: single precision division. - beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */ + beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */ r_ptr = roomptr; q_ptr = roomptr + 1; { - mp_limb_t den = b_ptr[0]; - mp_limb_t remainder = 0; - const mp_limb_t *sourceptr = a_ptr + a_len; - mp_limb_t *destptr = q_ptr + a_len; - size_t count; - for (count = a_len; count > 0; count--) - { - mp_twolimb_t num = - ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr; - *--destptr = num / den; - remainder = num % den; - } - /* Normalise and store r. */ - if (remainder > 0) - { - r_ptr[0] = remainder; - r_len = 1; - } - else - r_len = 0; - /* Normalise q. */ - q_len = a_len; - if (q_ptr[q_len - 1] == 0) - q_len--; + mp_limb_t den = b_ptr[0]; + mp_limb_t remainder = 0; + const mp_limb_t *sourceptr = a_ptr + a_len; + mp_limb_t *destptr = q_ptr + a_len; + size_t count; + for (count = a_len; count > 0; count--) + { + mp_twolimb_t num = + ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr; + *--destptr = num / den; + remainder = num % den; + } + /* Normalise and store r. */ + if (remainder > 0) + { + r_ptr[0] = remainder; + r_len = 1; + } + else + r_len = 0; + /* Normalise q. */ + q_len = a_len; + if (q_ptr[q_len - 1] == 0) + q_len--; } } else { /* n>1: multiple precision division. - beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==> - beta^(m-n-1) <= a/b < beta^(m-n+1). */ + beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==> + beta^(m-n-1) <= a/b < beta^(m-n+1). */ /* Determine s. */ size_t s; { - mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ - s = 31; - if (msd >= 0x10000) - { - msd = msd >> 16; - s -= 16; - } - if (msd >= 0x100) - { - msd = msd >> 8; - s -= 8; - } - if (msd >= 0x10) - { - msd = msd >> 4; - s -= 4; - } - if (msd >= 0x4) - { - msd = msd >> 2; - s -= 2; - } - if (msd >= 0x2) - { - msd = msd >> 1; - s -= 1; - } + mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ + s = 31; + if (msd >= 0x10000) + { + msd = msd >> 16; + s -= 16; + } + if (msd >= 0x100) + { + msd = msd >> 8; + s -= 8; + } + if (msd >= 0x10) + { + msd = msd >> 4; + s -= 4; + } + if (msd >= 0x4) + { + msd = msd >> 2; + s -= 2; + } + if (msd >= 0x2) + { + msd = msd >> 1; + s -= 1; + } } /* 0 <= s < GMP_LIMB_BITS. - Copy b, shifting it left by s bits. */ + Copy b, shifting it left by s bits. */ if (s > 0) - { - tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t)); - if (tmp_roomptr == NULL) - { - free (roomptr); - return NULL; - } - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = tmp_roomptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - /* accu must be zero, since that was how s was determined. */ - if (accu != 0) - abort (); - } - b_ptr = tmp_roomptr; - } + { + tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t)); + if (tmp_roomptr == NULL) + { + free (roomptr); + return NULL; + } + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = tmp_roomptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + /* accu must be zero, since that was how s was determined. */ + if (accu != 0) + abort (); + } + b_ptr = tmp_roomptr; + } /* Copy a, shifting it left by s bits, yields r. - Memory layout: - At the beginning: r = roomptr[0..a_len], - at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */ + Memory layout: + At the beginning: r = roomptr[0..a_len], + at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */ r_ptr = roomptr; if (s == 0) - { - memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t)); - r_ptr[a_len] = 0; - } + { + memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t)); + r_ptr[a_len] = 0; + } else - { - const mp_limb_t *sourceptr = a_ptr; - mp_limb_t *destptr = r_ptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = a_len; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - *destptr++ = (mp_limb_t) accu; - } + { + const mp_limb_t *sourceptr = a_ptr; + mp_limb_t *destptr = r_ptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = a_len; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + *destptr++ = (mp_limb_t) accu; + } q_ptr = roomptr + b_len; q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */ { - size_t j = a_len - b_len; /* m-n */ - mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */ - mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */ - mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */ - ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd; - /* Division loop, traversed m-n+1 times. - j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */ - for (;;) - { - mp_limb_t q_star; - mp_limb_t c1; - if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */ - { - /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */ - mp_twolimb_t num = - ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS) - | r_ptr[j + b_len - 1]; - q_star = num / b_msd; - c1 = num % b_msd; - } - else - { - /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */ - q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */ - /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta - <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta - <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) - {<= beta !}. - If yes, jump directly to the subtraction loop. - (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta - <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */ - if (r_ptr[j + b_len] > b_msd - || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd) - /* r[j+n] >= b[n-1]+1 or - r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a - carry. */ - goto subtract; - } - /* q_star = q*, - c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, 0, decrease it by - b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2 - this can happen only twice. */ - if (c3 > c2) - { - q_star = q_star - 1; /* q* := q* - 1 */ - if (c3 - c2 > b_msdd) - q_star = q_star - 1; /* q* := q* - 1 */ - } - } - if (q_star > 0) - subtract: - { - /* Subtract r := r - b * q* * beta^j. */ - mp_limb_t cr; - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = r_ptr + j; - mp_twolimb_t carry = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - /* Here 0 <= carry <= q*. */ - carry = - carry - + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++ - + (mp_limb_t) ~(*destptr); - /* Here 0 <= carry <= beta*q* + beta-1. */ - *destptr++ = ~(mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; /* <= q* */ - } - cr = (mp_limb_t) carry; - } - /* Subtract cr from r_ptr[j + b_len], then forget about - r_ptr[j + b_len]. */ - if (cr > r_ptr[j + b_len]) - { - /* Subtraction gave a carry. */ - q_star = q_star - 1; /* q* := q* - 1 */ - /* Add b back. */ - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = r_ptr + j; - mp_limb_t carry = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - mp_limb_t source1 = *sourceptr++; - mp_limb_t source2 = *destptr; - *destptr++ = source1 + source2 + carry; - carry = - (carry - ? source1 >= (mp_limb_t) ~source2 - : source1 > (mp_limb_t) ~source2); - } - } - /* Forget about the carry and about r[j+n]. */ - } - } - /* q* is determined. Store it as q[j]. */ - q_ptr[j] = q_star; - if (j == 0) - break; - j--; - } + size_t j = a_len - b_len; /* m-n */ + mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */ + mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */ + mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */ + ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd; + /* Division loop, traversed m-n+1 times. + j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */ + for (;;) + { + mp_limb_t q_star; + mp_limb_t c1; + if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */ + { + /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */ + mp_twolimb_t num = + ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS) + | r_ptr[j + b_len - 1]; + q_star = num / b_msd; + c1 = num % b_msd; + } + else + { + /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */ + q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */ + /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta + <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta + <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) + {<= beta !}. + If yes, jump directly to the subtraction loop. + (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta + <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */ + if (r_ptr[j + b_len] > b_msd + || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd) + /* r[j+n] >= b[n-1]+1 or + r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a + carry. */ + goto subtract; + } + /* q_star = q*, + c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, 0, decrease it by + b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2 + this can happen only twice. */ + if (c3 > c2) + { + q_star = q_star - 1; /* q* := q* - 1 */ + if (c3 - c2 > b_msdd) + q_star = q_star - 1; /* q* := q* - 1 */ + } + } + if (q_star > 0) + subtract: + { + /* Subtract r := r - b * q* * beta^j. */ + mp_limb_t cr; + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = r_ptr + j; + mp_twolimb_t carry = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + /* Here 0 <= carry <= q*. */ + carry = + carry + + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++ + + (mp_limb_t) ~(*destptr); + /* Here 0 <= carry <= beta*q* + beta-1. */ + *destptr++ = ~(mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; /* <= q* */ + } + cr = (mp_limb_t) carry; + } + /* Subtract cr from r_ptr[j + b_len], then forget about + r_ptr[j + b_len]. */ + if (cr > r_ptr[j + b_len]) + { + /* Subtraction gave a carry. */ + q_star = q_star - 1; /* q* := q* - 1 */ + /* Add b back. */ + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = r_ptr + j; + mp_limb_t carry = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + mp_limb_t source1 = *sourceptr++; + mp_limb_t source2 = *destptr; + *destptr++ = source1 + source2 + carry; + carry = + (carry + ? source1 >= (mp_limb_t) ~source2 + : source1 > (mp_limb_t) ~source2); + } + } + /* Forget about the carry and about r[j+n]. */ + } + } + /* q* is determined. Store it as q[j]. */ + q_ptr[j] = q_star; + if (j == 0) + break; + j--; + } } r_len = b_len; /* Normalise q. */ if (q_ptr[q_len - 1] == 0) - q_len--; + q_len--; # if 0 /* Not needed here, since we need r only to compare it with b/2, and - b is shifted left by s bits. */ + b is shifted left by s bits. */ /* Shift r right by s bits. */ if (s > 0) - { - mp_limb_t ptr = r_ptr + r_len; - mp_twolimb_t accu = 0; - size_t count; - for (count = r_len; count > 0; count--) - { - accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS; - accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s); - *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS); - } - } + { + mp_limb_t ptr = r_ptr + r_len; + mp_twolimb_t accu = 0; + size_t count; + for (count = r_len; count > 0; count--) + { + accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS; + accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s); + *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS); + } + } # endif /* Normalise r. */ while (r_len > 0 && r_ptr[r_len - 1] == 0) - r_len--; + r_len--; } /* Compare r << 1 with b. */ if (r_len > b_len) @@ -763,17 +763,17 @@ divide (mpn_t a, mpn_t b, mpn_t *q) size_t i; for (i = b_len;;) { - mp_limb_t r_i = - (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0) - | (i < r_len ? r_ptr[i] << 1 : 0); - mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0); - if (r_i > b_i) - goto increment_q; - if (r_i < b_i) - goto keep_q; - if (i == 0) - break; - i--; + mp_limb_t r_i = + (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0) + | (i < r_len ? r_ptr[i] << 1 : 0); + mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0); + if (r_i > b_i) + goto increment_q; + if (r_i < b_i) + goto keep_q; + if (i == 0) + break; + i--; } } if (q_len > 0 && ((q_ptr[0] & 1) != 0)) @@ -782,8 +782,8 @@ divide (mpn_t a, mpn_t b, mpn_t *q) { size_t i; for (i = 0; i < q_len; i++) - if (++(q_ptr[i]) != 0) - goto keep_q; + if (++(q_ptr[i]) != 0) + goto keep_q; q_ptr[q_len++] = 1; } keep_q: @@ -812,36 +812,36 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes) { char *d_ptr = c_ptr; for (; extra_zeroes > 0; extra_zeroes--) - *d_ptr++ = '0'; + *d_ptr++ = '0'; while (a_len > 0) - { - /* Divide a by 10^9, in-place. */ - mp_limb_t remainder = 0; - mp_limb_t *ptr = a_ptr + a_len; - size_t count; - for (count = a_len; count > 0; count--) - { - mp_twolimb_t num = - ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr; - *ptr = num / 1000000000; - remainder = num % 1000000000; - } - /* Store the remainder as 9 decimal digits. */ - for (count = 9; count > 0; count--) - { - *d_ptr++ = '0' + (remainder % 10); - remainder = remainder / 10; - } - /* Normalize a. */ - if (a_ptr[a_len - 1] == 0) - a_len--; - } + { + /* Divide a by 10^9, in-place. */ + mp_limb_t remainder = 0; + mp_limb_t *ptr = a_ptr + a_len; + size_t count; + for (count = a_len; count > 0; count--) + { + mp_twolimb_t num = + ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr; + *ptr = num / 1000000000; + remainder = num % 1000000000; + } + /* Store the remainder as 9 decimal digits. */ + for (count = 9; count > 0; count--) + { + *d_ptr++ = '0' + (remainder % 10); + remainder = remainder / 10; + } + /* Normalize a. */ + if (a_ptr[a_len - 1] == 0) + a_len--; + } /* Remove leading zeroes. */ while (d_ptr > c_ptr && d_ptr[-1] == '0') - d_ptr--; + d_ptr--; /* But keep at least one zero. */ if (d_ptr == c_ptr) - *d_ptr++ = '0'; + *d_ptr++ = '0'; /* Terminate the string. */ *d_ptr = '\0'; } @@ -886,12 +886,12 @@ decode_long_double (long double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; } # else @@ -901,7 +901,7 @@ decode_long_double (long double x, int *ep, mpn_t *mp) d = (int) y; y -= d; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d; } # endif @@ -913,12 +913,12 @@ decode_long_double (long double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; } #if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess @@ -974,12 +974,12 @@ decode_double (double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; } # else @@ -989,7 +989,7 @@ decode_double (double x, int *ep, mpn_t *mp) d = (int) y; y -= d; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d; } # endif @@ -1001,12 +1001,12 @@ decode_double (double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; } if (!(y == 0.0)) @@ -1064,8 +1064,8 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) abs_n = (n >= 0 ? n : -n); abs_s = (s >= 0 ? s : -s); pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1 - + abs_s / GMP_LIMB_BITS + 1) - * sizeof (mp_limb_t)); + + abs_s / GMP_LIMB_BITS + 1) + * sizeof (mp_limb_t)); if (pow5_ptr == NULL) { free (memory); @@ -1078,26 +1078,26 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) if (abs_n > 0) { static mp_limb_t const small_pow5[13 + 1] = - { - 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, - 48828125, 244140625, 1220703125 - }; + { + 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, + 48828125, 244140625, 1220703125 + }; unsigned int n13; for (n13 = 0; n13 <= abs_n; n13 += 13) - { - mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13]; - size_t j; - mp_twolimb_t carry = 0; - for (j = 0; j < pow5_len; j++) - { - mp_limb_t digit2 = pow5_ptr[j]; - carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; - pow5_ptr[j] = (mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; - } - if (carry > 0) - pow5_ptr[pow5_len++] = (mp_limb_t) carry; - } + { + mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13]; + size_t j; + mp_twolimb_t carry = 0; + for (j = 0; j < pow5_len; j++) + { + mp_limb_t digit2 = pow5_ptr[j]; + carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; + pow5_ptr[j] = (mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; + } + if (carry > 0) + pow5_ptr[pow5_len++] = (mp_limb_t) carry; + } } s_limbs = abs_s / GMP_LIMB_BITS; s_bits = abs_s % GMP_LIMB_BITS; @@ -1105,129 +1105,129 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) { /* Multiply with 2^|s|. */ if (s_bits > 0) - { - mp_limb_t *ptr = pow5_ptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = pow5_len; count > 0; count--) - { - accu += (mp_twolimb_t) *ptr << s_bits; - *ptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - if (accu > 0) - { - *ptr = (mp_limb_t) accu; - pow5_len++; - } - } + { + mp_limb_t *ptr = pow5_ptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = pow5_len; count > 0; count--) + { + accu += (mp_twolimb_t) *ptr << s_bits; + *ptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + if (accu > 0) + { + *ptr = (mp_limb_t) accu; + pow5_len++; + } + } if (s_limbs > 0) - { - size_t count; - for (count = pow5_len; count > 0;) - { - count--; - pow5_ptr[s_limbs + count] = pow5_ptr[count]; - } - for (count = s_limbs; count > 0;) - { - count--; - pow5_ptr[count] = 0; - } - pow5_len += s_limbs; - } + { + size_t count; + for (count = pow5_len; count > 0;) + { + count--; + pow5_ptr[s_limbs + count] = pow5_ptr[count]; + } + for (count = s_limbs; count > 0;) + { + count--; + pow5_ptr[count] = 0; + } + pow5_len += s_limbs; + } pow5.limbs = pow5_ptr; pow5.nlimbs = pow5_len; if (n >= 0) - { - /* Multiply m with pow5. No division needed. */ - z_memory = multiply (m, pow5, &z); - } + { + /* Multiply m with pow5. No division needed. */ + z_memory = multiply (m, pow5, &z); + } else - { - /* Divide m by pow5 and round. */ - z_memory = divide (m, pow5, &z); - } + { + /* Divide m by pow5 and round. */ + z_memory = divide (m, pow5, &z); + } } else { pow5.limbs = pow5_ptr; pow5.nlimbs = pow5_len; if (n >= 0) - { - /* n >= 0, s < 0. - Multiply m with pow5, then divide by 2^|s|. */ - mpn_t numerator; - mpn_t denominator; - void *tmp_memory; - tmp_memory = multiply (m, pow5, &numerator); - if (tmp_memory == NULL) - { - free (pow5_ptr); - free (memory); - return NULL; - } - /* Construct 2^|s|. */ - { - mp_limb_t *ptr = pow5_ptr + pow5_len; - size_t i; - for (i = 0; i < s_limbs; i++) - ptr[i] = 0; - ptr[s_limbs] = (mp_limb_t) 1 << s_bits; - denominator.limbs = ptr; - denominator.nlimbs = s_limbs + 1; - } - z_memory = divide (numerator, denominator, &z); - free (tmp_memory); - } + { + /* n >= 0, s < 0. + Multiply m with pow5, then divide by 2^|s|. */ + mpn_t numerator; + mpn_t denominator; + void *tmp_memory; + tmp_memory = multiply (m, pow5, &numerator); + if (tmp_memory == NULL) + { + free (pow5_ptr); + free (memory); + return NULL; + } + /* Construct 2^|s|. */ + { + mp_limb_t *ptr = pow5_ptr + pow5_len; + size_t i; + for (i = 0; i < s_limbs; i++) + ptr[i] = 0; + ptr[s_limbs] = (mp_limb_t) 1 << s_bits; + denominator.limbs = ptr; + denominator.nlimbs = s_limbs + 1; + } + z_memory = divide (numerator, denominator, &z); + free (tmp_memory); + } else - { - /* n < 0, s > 0. - Multiply m with 2^s, then divide by pow5. */ - mpn_t numerator; - mp_limb_t *num_ptr; - num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1) - * sizeof (mp_limb_t)); - if (num_ptr == NULL) - { - free (pow5_ptr); - free (memory); - return NULL; - } - { - mp_limb_t *destptr = num_ptr; - { - size_t i; - for (i = 0; i < s_limbs; i++) - *destptr++ = 0; - } - if (s_bits > 0) - { - const mp_limb_t *sourceptr = m.limbs; - mp_twolimb_t accu = 0; - size_t count; - for (count = m.nlimbs; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s_bits; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - if (accu > 0) - *destptr++ = (mp_limb_t) accu; - } - else - { - const mp_limb_t *sourceptr = m.limbs; - size_t count; - for (count = m.nlimbs; count > 0; count--) - *destptr++ = *sourceptr++; - } - numerator.limbs = num_ptr; - numerator.nlimbs = destptr - num_ptr; - } - z_memory = divide (numerator, pow5, &z); - free (num_ptr); - } + { + /* n < 0, s > 0. + Multiply m with 2^s, then divide by pow5. */ + mpn_t numerator; + mp_limb_t *num_ptr; + num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1) + * sizeof (mp_limb_t)); + if (num_ptr == NULL) + { + free (pow5_ptr); + free (memory); + return NULL; + } + { + mp_limb_t *destptr = num_ptr; + { + size_t i; + for (i = 0; i < s_limbs; i++) + *destptr++ = 0; + } + if (s_bits > 0) + { + const mp_limb_t *sourceptr = m.limbs; + mp_twolimb_t accu = 0; + size_t count; + for (count = m.nlimbs; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s_bits; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + if (accu > 0) + *destptr++ = (mp_limb_t) accu; + } + else + { + const mp_limb_t *sourceptr = m.limbs; + size_t count; + for (count = m.nlimbs; count > 0; count--) + *destptr++ = *sourceptr++; + } + numerator.limbs = num_ptr; + numerator.nlimbs = destptr - num_ptr; + } + z_memory = divide (numerator, pow5, &z); + free (num_ptr); + } } free (pow5_ptr); free (memory); @@ -1299,35 +1299,35 @@ floorlog10l (long double x) if (y < 0.5L) { while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) - { - y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); - exp -= GMP_LIMB_BITS; - } + { + y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); + exp -= GMP_LIMB_BITS; + } if (y < (1.0L / (1 << 16))) - { - y *= 1.0L * (1 << 16); - exp -= 16; - } + { + y *= 1.0L * (1 << 16); + exp -= 16; + } if (y < (1.0L / (1 << 8))) - { - y *= 1.0L * (1 << 8); - exp -= 8; - } + { + y *= 1.0L * (1 << 8); + exp -= 8; + } if (y < (1.0L / (1 << 4))) - { - y *= 1.0L * (1 << 4); - exp -= 4; - } + { + y *= 1.0L * (1 << 4); + exp -= 4; + } if (y < (1.0L / (1 << 2))) - { - y *= 1.0L * (1 << 2); - exp -= 2; - } + { + y *= 1.0L * (1 << 2); + exp -= 2; + } if (y < (1.0L / (1 << 1))) - { - y *= 1.0L * (1 << 1); - exp -= 1; - } + { + y *= 1.0L * (1 << 1); + exp -= 1; + } } if (!(y >= 0.5L && y < 1.0L)) abort (); @@ -1390,35 +1390,35 @@ floorlog10 (double x) if (y < 0.5) { while (y < (1.0 / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) - { - y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); - exp -= GMP_LIMB_BITS; - } + { + y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); + exp -= GMP_LIMB_BITS; + } if (y < (1.0 / (1 << 16))) - { - y *= 1.0 * (1 << 16); - exp -= 16; - } + { + y *= 1.0 * (1 << 16); + exp -= 16; + } if (y < (1.0 / (1 << 8))) - { - y *= 1.0 * (1 << 8); - exp -= 8; - } + { + y *= 1.0 * (1 << 8); + exp -= 8; + } if (y < (1.0 / (1 << 4))) - { - y *= 1.0 * (1 << 4); - exp -= 4; - } + { + y *= 1.0 * (1 << 4); + exp -= 4; + } if (y < (1.0 / (1 << 2))) - { - y *= 1.0 * (1 << 2); - exp -= 2; - } + { + y *= 1.0 * (1 << 2); + exp -= 2; + } if (y < (1.0 / (1 << 1))) - { - y *= 1.0 * (1 << 1); - exp -= 1; - } + { + y *= 1.0 * (1 << 1); + exp -= 1; + } } if (!(y >= 0.5 && y < 1.0)) abort (); @@ -1477,7 +1477,7 @@ is_borderline (const char *digits, size_t precision) DCHAR_T * VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, - const FCHAR_T *format, va_list args) + const FCHAR_T *format, va_list args) { DIRECTIVES d; arguments a; @@ -1487,8 +1487,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, return NULL; #define CLEANUP() \ - free (d.dir); \ - if (a.arg) \ + free (d.dir); \ + if (a.arg) \ free (a.arg); if (PRINTF_FETCHARGS (args, &a) < 0) @@ -1517,30 +1517,30 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, #if HAVE_ALLOCA if (buf_neededlength < 4000 / sizeof (TCHAR_T)) { - buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); - buf_malloced = NULL; + buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); + buf_malloced = NULL; } else #endif { - size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T)); - if (size_overflow_p (buf_memsize)) - goto out_of_memory_1; - buf = (TCHAR_T *) malloc (buf_memsize); - if (buf == NULL) - goto out_of_memory_1; - buf_malloced = buf; + size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T)); + if (size_overflow_p (buf_memsize)) + goto out_of_memory_1; + buf = (TCHAR_T *) malloc (buf_memsize); + if (buf == NULL) + goto out_of_memory_1; + buf_malloced = buf; } if (resultbuf != NULL) { - result = resultbuf; - allocated = *lengthp; + result = resultbuf; + allocated = *lengthp; } else { - result = NULL; - allocated = 0; + result = NULL; + allocated = 0; } length = 0; /* Invariants: @@ -1550,3881 +1550,3881 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, /* Ensures that allocated >= needed. Aborts through a jump to out_of_memory if needed is SIZE_MAX or otherwise too big. */ #define ENSURE_ALLOCATION(needed) \ - if ((needed) > allocated) \ - { \ - size_t memory_size; \ - DCHAR_T *memory; \ - \ - allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ - if ((needed) > allocated) \ - allocated = (needed); \ - memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ - if (size_overflow_p (memory_size)) \ - goto out_of_memory; \ - if (result == resultbuf || result == NULL) \ - memory = (DCHAR_T *) malloc (memory_size); \ - else \ - memory = (DCHAR_T *) realloc (result, memory_size); \ - if (memory == NULL) \ - goto out_of_memory; \ - if (result == resultbuf && length > 0) \ - DCHAR_CPY (memory, result, length); \ - result = memory; \ + if ((needed) > allocated) \ + { \ + size_t memory_size; \ + DCHAR_T *memory; \ + \ + allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ + if ((needed) > allocated) \ + allocated = (needed); \ + memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ + if (size_overflow_p (memory_size)) \ + goto out_of_memory; \ + if (result == resultbuf || result == NULL) \ + memory = (DCHAR_T *) malloc (memory_size); \ + else \ + memory = (DCHAR_T *) realloc (result, memory_size); \ + if (memory == NULL) \ + goto out_of_memory; \ + if (result == resultbuf && length > 0) \ + DCHAR_CPY (memory, result, length); \ + result = memory; \ } for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) { - if (cp != dp->dir_start) - { - size_t n = dp->dir_start - cp; - size_t augmented_length = xsum (length, n); - - ENSURE_ALLOCATION (augmented_length); - /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we - need that the format string contains only ASCII characters - if FCHAR_T and DCHAR_T are not the same type. */ - if (sizeof (FCHAR_T) == sizeof (DCHAR_T)) - { - DCHAR_CPY (result + length, (const DCHAR_T *) cp, n); - length = augmented_length; - } - else - { - do - result[length++] = (unsigned char) *cp++; - while (--n > 0); - } - } - if (i == d.count) - break; - - /* Execute a single directive. */ - if (dp->conversion == '%') - { - size_t augmented_length; - - if (!(dp->arg_index == ARG_NONE)) - abort (); - augmented_length = xsum (length, 1); - ENSURE_ALLOCATION (augmented_length); - result[length] = '%'; - length = augmented_length; - } - else - { - if (!(dp->arg_index != ARG_NONE)) - abort (); - - if (dp->conversion == 'n') - { - switch (a.arg[dp->arg_index].type) - { - case TYPE_COUNT_SCHAR_POINTER: - *a.arg[dp->arg_index].a.a_count_schar_pointer = length; - break; - case TYPE_COUNT_SHORT_POINTER: - *a.arg[dp->arg_index].a.a_count_short_pointer = length; - break; - case TYPE_COUNT_INT_POINTER: - *a.arg[dp->arg_index].a.a_count_int_pointer = length; - break; - case TYPE_COUNT_LONGINT_POINTER: - *a.arg[dp->arg_index].a.a_count_longint_pointer = length; - break; + if (cp != dp->dir_start) + { + size_t n = dp->dir_start - cp; + size_t augmented_length = xsum (length, n); + + ENSURE_ALLOCATION (augmented_length); + /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we + need that the format string contains only ASCII characters + if FCHAR_T and DCHAR_T are not the same type. */ + if (sizeof (FCHAR_T) == sizeof (DCHAR_T)) + { + DCHAR_CPY (result + length, (const DCHAR_T *) cp, n); + length = augmented_length; + } + else + { + do + result[length++] = (unsigned char) *cp++; + while (--n > 0); + } + } + if (i == d.count) + break; + + /* Execute a single directive. */ + if (dp->conversion == '%') + { + size_t augmented_length; + + if (!(dp->arg_index == ARG_NONE)) + abort (); + augmented_length = xsum (length, 1); + ENSURE_ALLOCATION (augmented_length); + result[length] = '%'; + length = augmented_length; + } + else + { + if (!(dp->arg_index != ARG_NONE)) + abort (); + + if (dp->conversion == 'n') + { + switch (a.arg[dp->arg_index].type) + { + case TYPE_COUNT_SCHAR_POINTER: + *a.arg[dp->arg_index].a.a_count_schar_pointer = length; + break; + case TYPE_COUNT_SHORT_POINTER: + *a.arg[dp->arg_index].a.a_count_short_pointer = length; + break; + case TYPE_COUNT_INT_POINTER: + *a.arg[dp->arg_index].a.a_count_int_pointer = length; + break; + case TYPE_COUNT_LONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longint_pointer = length; + break; #if HAVE_LONG_LONG_INT - case TYPE_COUNT_LONGLONGINT_POINTER: - *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; - break; + case TYPE_COUNT_LONGLONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; + break; #endif - default: - abort (); - } - } + default: + abort (); + } + } #if ENABLE_UNISTDIO - /* The unistdio extensions. */ - else if (dp->conversion == 'U') - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - switch (type) - { - case TYPE_U8_STRING: - { - const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string; - const uint8_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u8_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u8_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u8_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + /* The unistdio extensions. */ + else if (dp->conversion == 'U') + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + switch (type) + { + case TYPE_U8_STRING: + { + const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string; + const uint8_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u8_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u8_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u8_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_UINT8_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } # else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR - /* Convert from UTF-8 to locale encoding. */ - converted = - u8_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - converted, &converted_len); + /* Convert from UTF-8 to locale encoding. */ + converted = + u8_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); # else - /* Convert from UTF-8 to UTF-16/UTF-32. */ - converted = - U8_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); + /* Convert from UTF-8 to UTF-16/UTF-32. */ + converted = + U8_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); # endif - if (converted == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } # endif - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - case TYPE_U16_STRING: - { - const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string; - const uint16_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u16_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u16_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u16_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + case TYPE_U16_STRING: + { + const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string; + const uint16_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u16_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u16_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u16_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_UINT16_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } # else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR - /* Convert from UTF-16 to locale encoding. */ - converted = - u16_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - converted, &converted_len); + /* Convert from UTF-16 to locale encoding. */ + converted = + u16_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); # else - /* Convert from UTF-16 to UTF-8/UTF-32. */ - converted = - U16_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); + /* Convert from UTF-16 to UTF-8/UTF-32. */ + converted = + U16_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); # endif - if (converted == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } # endif - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - case TYPE_U32_STRING: - { - const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string; - const uint32_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u32_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u32_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u32_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + case TYPE_U32_STRING: + { + const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string; + const uint32_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u32_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u32_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u32_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_UINT32_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } # else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR - /* Convert from UTF-32 to locale encoding. */ - converted = - u32_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - converted, &converted_len); + /* Convert from UTF-32 to locale encoding. */ + converted = + u32_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); # else - /* Convert from UTF-32 to UTF-8/UTF-16. */ - converted = - U32_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); + /* Convert from UTF-32 to UTF-8/UTF-16. */ + converted = + U32_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); # endif - if (converted == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } # endif - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - default: - abort (); - } - } + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + default: + abort (); + } + } #endif #if (!USE_SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T - else if (dp->conversion == 's' + else if (dp->conversion == 's' # if WIDE_CHAR_VERSION - && a.arg[dp->arg_index].type != TYPE_WIDE_STRING + && a.arg[dp->arg_index].type != TYPE_WIDE_STRING # else - && a.arg[dp->arg_index].type == TYPE_WIDE_STRING + && a.arg[dp->arg_index].type == TYPE_WIDE_STRING # endif - ) - { - /* The normal handling of the 's' directive below requires - allocating a temporary buffer. The determination of its - length (tmp_length), in the case when a precision is - specified, below requires a conversion between a char[] - string and a wchar_t[] wide string. It could be done, but - we have no guarantee that the implementation of sprintf will - use the exactly same algorithm. Without this guarantee, it - is possible to have buffer overrun bugs. In order to avoid - such bugs, we implement the entire processing of the 's' - directive ourselves. */ - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 6; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } + ) + { + /* The normal handling of the 's' directive below requires + allocating a temporary buffer. The determination of its + length (tmp_length), in the case when a precision is + specified, below requires a conversion between a char[] + string and a wchar_t[] wide string. It could be done, but + we have no guarantee that the implementation of sprintf will + use the exactly same algorithm. Without this guarantee, it + is possible to have buffer overrun bugs. In order to avoid + such bugs, we implement the entire processing of the 's' + directive ourselves. */ + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 6; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } # if WIDE_CHAR_VERSION - /* %s in vasnwprintf. See the specification of fwprintf. */ - { - const char *arg = a.arg[dp->arg_index].a.a_string; - const char *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only as many bytes as needed to produce PRECISION - wide characters, from the left. */ + /* %s in vasnwprintf. See the specification of fwprintf. */ + { + const char *arg = a.arg[dp->arg_index].a.a_string; + const char *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only as many bytes as needed to produce PRECISION + wide characters, from the left. */ # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count; + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count; # if HAVE_MBRTOWC - count = mbrlen (arg_end, MB_CUR_MAX, &state); + count = mbrlen (arg_end, MB_CUR_MAX, &state); # else - count = mblen (arg_end, MB_CUR_MAX); + count = mblen (arg_end, MB_CUR_MAX); # endif - if (count == 0) - /* Found the terminating NUL. */ - break; - if (count < 0) - { - /* Invalid or incomplete multibyte character. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of wide - characters. */ + if (count == 0) + /* Found the terminating NUL. */ + break; + if (count < 0) + { + /* Invalid or incomplete multibyte character. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of wide + characters. */ # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (;;) - { - int count; + arg_end = arg; + characters = 0; + for (;;) + { + int count; # if HAVE_MBRTOWC - count = mbrlen (arg_end, MB_CUR_MAX, &state); + count = mbrlen (arg_end, MB_CUR_MAX, &state); # else - count = mblen (arg_end, MB_CUR_MAX); + count = mblen (arg_end, MB_CUR_MAX); # endif - if (count == 0) - /* Found the terminating NUL. */ - break; - if (count < 0) - { - /* Invalid or incomplete multibyte character. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - - if (has_precision || has_width) - { - /* We know the number of wide characters in advance. */ - size_t remaining; + if (count == 0) + /* Found the terminating NUL. */ + break; + if (count < 0) + { + /* Invalid or incomplete multibyte character. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + + if (has_precision || has_width) + { + /* We know the number of wide characters in advance. */ + size_t remaining; # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - ENSURE_ALLOCATION (xsum (length, characters)); - for (remaining = characters; remaining > 0; remaining--) - { - wchar_t wc; - int count; + ENSURE_ALLOCATION (xsum (length, characters)); + for (remaining = characters; remaining > 0; remaining--) + { + wchar_t wc; + int count; # if HAVE_MBRTOWC - count = mbrtowc (&wc, arg, arg_end - arg, &state); + count = mbrtowc (&wc, arg, arg_end - arg, &state); # else - count = mbtowc (&wc, arg, arg_end - arg); + count = mbtowc (&wc, arg, arg_end - arg); # endif - if (count <= 0) - /* mbrtowc not consistent with mbrlen, or mbtowc - not consistent with mblen. */ - abort (); - result[length++] = wc; - arg += count; - } - if (!(arg == arg_end)) - abort (); - } - else - { + if (count <= 0) + /* mbrtowc not consistent with mbrlen, or mbtowc + not consistent with mblen. */ + abort (); + result[length++] = wc; + arg += count; + } + if (!(arg == arg_end)) + abort (); + } + else + { # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - while (arg < arg_end) - { - wchar_t wc; - int count; + while (arg < arg_end) + { + wchar_t wc; + int count; # if HAVE_MBRTOWC - count = mbrtowc (&wc, arg, arg_end - arg, &state); + count = mbrtowc (&wc, arg, arg_end - arg, &state); # else - count = mbtowc (&wc, arg, arg_end - arg); + count = mbtowc (&wc, arg, arg_end - arg); # endif - if (count <= 0) - /* mbrtowc not consistent with mbrlen, or mbtowc - not consistent with mblen. */ - abort (); - ENSURE_ALLOCATION (xsum (length, 1)); - result[length++] = wc; - arg += count; - } - } - - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } + if (count <= 0) + /* mbrtowc not consistent with mbrlen, or mbtowc + not consistent with mblen. */ + abort (); + ENSURE_ALLOCATION (xsum (length, 1)); + result[length++] = wc; + arg += count; + } + } + + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } # else - /* %ls in vasnprintf. See the specification of fprintf. */ - { - const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; - const wchar_t *arg_end; - size_t characters; + /* %ls in vasnprintf. See the specification of fprintf. */ + { + const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; + const wchar_t *arg_end; + size_t characters; # if !DCHAR_IS_TCHAR - /* This code assumes that TCHAR_T is 'char'. */ - typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1]; - TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t tmpdst_len; + /* This code assumes that TCHAR_T is 'char'. */ + typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1]; + TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t tmpdst_len; # endif - size_t w; + size_t w; - if (has_precision) - { - /* Use only as many wide characters as needed to produce - at most PRECISION bytes, from the left. */ + if (has_precision) + { + /* Use only as many wide characters as needed to produce + at most PRECISION bytes, from the left. */ # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - while (precision > 0) - { - char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg_end == 0) - /* Found the terminating null wide character. */ - break; + arg_end = arg; + characters = 0; + while (precision > 0) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg_end == 0) + /* Found the terminating null wide character. */ + break; # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg_end, &state); + count = wcrtomb (cbuf, *arg_end, &state); # else - count = wctomb (cbuf, *arg_end); + count = wctomb (cbuf, *arg_end); # endif - if (count < 0) - { - /* Cannot convert. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - if (precision < count) - break; - arg_end++; - characters += count; - precision -= count; - } - } + if (count < 0) + { + /* Cannot convert. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + if (precision < count) + break; + arg_end++; + characters += count; + precision -= count; + } + } # if DCHAR_IS_TCHAR - else if (has_width) + else if (has_width) # else - else + else # endif - { - /* Use the entire string, and count the number of - bytes. */ + { + /* Use the entire string, and count the number of + bytes. */ # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (;;) - { - char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg_end == 0) - /* Found the terminating null wide character. */ - break; + arg_end = arg; + characters = 0; + for (;;) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg_end == 0) + /* Found the terminating null wide character. */ + break; # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg_end, &state); + count = wcrtomb (cbuf, *arg_end, &state); # else - count = wctomb (cbuf, *arg_end); + count = wctomb (cbuf, *arg_end); # endif - if (count < 0) - { - /* Cannot convert. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end++; - characters += count; - } - } + if (count < 0) + { + /* Cannot convert. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end++; + characters += count; + } + } # if DCHAR_IS_TCHAR - else - { - /* Use the entire string. */ - arg_end = arg + local_wcslen (arg); - /* The number of bytes doesn't matter. */ - characters = 0; - } + else + { + /* Use the entire string. */ + arg_end = arg + local_wcslen (arg); + /* The number of bytes doesn't matter. */ + characters = 0; + } # endif # if !DCHAR_IS_TCHAR - /* Convert the string into a piece of temporary memory. */ - tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T)); - if (tmpsrc == NULL) - goto out_of_memory; - { - TCHAR_T *tmpptr = tmpsrc; - size_t remaining; + /* Convert the string into a piece of temporary memory. */ + tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T)); + if (tmpsrc == NULL) + goto out_of_memory; + { + TCHAR_T *tmpptr = tmpsrc; + size_t remaining; # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - for (remaining = characters; remaining > 0; ) - { - char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; + for (remaining = characters; remaining > 0; ) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; - if (*arg == 0) - abort (); + if (*arg == 0) + abort (); # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg, &state); + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (cbuf, *arg); + count = wctomb (cbuf, *arg); # endif - if (count <= 0) - /* Inconsistency. */ - abort (); - memcpy (tmpptr, cbuf, count); - tmpptr += count; - arg++; - remaining -= count; - } - if (!(arg == arg_end)) - abort (); - } - - /* Convert from TCHAR_T[] to DCHAR_T[]. */ - tmpdst = - DCHAR_CONV_FROM_ENCODING (locale_charset (), - iconveh_question_mark, - tmpsrc, characters, - NULL, - NULL, &tmpdst_len); - if (tmpdst == NULL) - { - int saved_errno = errno; - free (tmpsrc); - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - free (tmpsrc); + if (count <= 0) + /* Inconsistency. */ + abort (); + memcpy (tmpptr, cbuf, count); + tmpptr += count; + arg++; + remaining -= count; + } + if (!(arg == arg_end)) + abort (); + } + + /* Convert from TCHAR_T[] to DCHAR_T[]. */ + tmpdst = + DCHAR_CONV_FROM_ENCODING (locale_charset (), + iconveh_question_mark, + tmpsrc, characters, + NULL, + NULL, &tmpdst_len); + if (tmpdst == NULL) + { + int saved_errno = errno; + free (tmpsrc); + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + free (tmpsrc); # endif - if (has_width) - { + if (has_width) + { # if ENABLE_UNISTDIO - /* Outside POSIX, it's preferrable to compare the width - against the number of _characters_ of the converted - value. */ - w = DCHAR_MBSNLEN (result + length, characters); + /* Outside POSIX, it's preferrable to compare the width + against the number of _characters_ of the converted + value. */ + w = DCHAR_MBSNLEN (result + length, characters); # else - /* The width is compared against the number of _bytes_ - of the converted value, says POSIX. */ - w = characters; + /* The width is compared against the number of _bytes_ + of the converted value, says POSIX. */ + w = characters; # endif - } - else - /* w doesn't matter. */ - w = 0; - - if (has_width && width > w - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - w; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + } + else + /* w doesn't matter. */ + w = 0; + + if (has_width && width > w + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - w; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_TCHAR - if (has_precision || has_width) - { - /* We know the number of bytes in advance. */ - size_t remaining; + if (has_precision || has_width) + { + /* We know the number of bytes in advance. */ + size_t remaining; # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - ENSURE_ALLOCATION (xsum (length, characters)); - for (remaining = characters; remaining > 0; ) - { - char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg == 0) - abort (); + ENSURE_ALLOCATION (xsum (length, characters)); + for (remaining = characters; remaining > 0; ) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg == 0) + abort (); # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg, &state); + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (cbuf, *arg); + count = wctomb (cbuf, *arg); # endif - if (count <= 0) - /* Inconsistency. */ - abort (); - memcpy (result + length, cbuf, count); - length += count; - arg++; - remaining -= count; - } - if (!(arg == arg_end)) - abort (); - } - else - { + if (count <= 0) + /* Inconsistency. */ + abort (); + memcpy (result + length, cbuf, count); + length += count; + arg++; + remaining -= count; + } + if (!(arg == arg_end)) + abort (); + } + else + { # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - while (arg < arg_end) - { - char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; + while (arg < arg_end) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; - if (*arg == 0) - abort (); + if (*arg == 0) + abort (); # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg, &state); + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (cbuf, *arg); + count = wctomb (cbuf, *arg); # endif - if (count <= 0) - /* Inconsistency. */ - abort (); - ENSURE_ALLOCATION (xsum (length, count)); - memcpy (result + length, cbuf, count); - length += count; - arg++; - } - } + if (count <= 0) + /* Inconsistency. */ + abort (); + ENSURE_ALLOCATION (xsum (length, count)); + memcpy (result + length, cbuf, count); + length += count; + arg++; + } + } # else - ENSURE_ALLOCATION (xsum (length, tmpdst_len)); - DCHAR_CPY (result + length, tmpdst, tmpdst_len); - free (tmpdst); - length += tmpdst_len; + ENSURE_ALLOCATION (xsum (length, tmpdst_len)); + DCHAR_CPY (result + length, tmpdst, tmpdst_len); + free (tmpdst); + length += tmpdst_len; # endif - if (has_width && width > w - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - w; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - } + if (has_width && width > w + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - w; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + } # endif #endif #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL - else if ((dp->conversion == 'a' || dp->conversion == 'A') + else if ((dp->conversion == 'a' || dp->conversion == 'A') # if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE)) - && (0 + && (0 # if NEED_PRINTF_DOUBLE - || a.arg[dp->arg_index].type == TYPE_DOUBLE + || a.arg[dp->arg_index].type == TYPE_DOUBLE # endif # if NEED_PRINTF_LONG_DOUBLE - || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE # endif - ) + ) # endif - ) - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - size_t tmp_length; - DCHAR_T tmpbuf[700]; - DCHAR_T *tmp; - DCHAR_T *pad_ptr; - DCHAR_T *p; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - /* Allocate a temporary buffer of sufficient size. */ - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) ((LDBL_DIG + 1) - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) ((DBL_DIG + 1) - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); - - if (tmp_length < width) - tmp_length = width; - - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - - if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); - - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (DCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } - - pad_ptr = NULL; - p = tmp; - if (type == TYPE_LONGDOUBLE) - { + ) + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + size_t tmp_length; + DCHAR_T tmpbuf[700]; + DCHAR_T *tmp; + DCHAR_T *pad_ptr; + DCHAR_T *p; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + /* Allocate a temporary buffer of sufficient size. */ + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) ((LDBL_DIG + 1) + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) ((DBL_DIG + 1) + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); + + if (tmp_length < width) + tmp_length = width; + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + + if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); + + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (DCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } + + pad_ptr = NULL; + p = tmp; + if (type == TYPE_LONGDOUBLE) + { # if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE - long double arg = a.arg[dp->arg_index].a.a_longdouble; - - if (isnanl (arg)) - { - if (dp->conversion == 'A') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - DECL_LONG_DOUBLE_ROUNDING - - BEGIN_LONG_DOUBLE_ROUNDING (); - - if (signbit (arg)) /* arg < 0.0L or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0L && arg + arg == arg) - { - if (dp->conversion == 'A') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { - int exponent; - long double mantissa; - - if (arg > 0.0L) - mantissa = printf_frexpl (arg, &exponent); - else - { - exponent = 0; - mantissa = 0.0L; - } - - if (has_precision - && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1) - { - /* Round the mantissa. */ - long double tail = mantissa; - size_t q; - - for (q = precision; ; q--) - { - int digit = (int) tail; - tail -= digit; - if (q == 0) - { - if (digit & 1 ? tail >= 0.5L : tail > 0.5L) - tail = 1 - tail; - else - tail = - tail; - break; - } - tail *= 16.0L; - } - if (tail != 0.0L) - for (q = precision; q > 0; q--) - tail *= 0.0625L; - mantissa += tail; - } - - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - { - int digit; - - digit = (int) mantissa; - mantissa -= digit; - *p++ = '0' + digit; - if ((flags & FLAG_ALT) - || mantissa > 0.0L || precision > 0) - { - *p++ = decimal_point_char (); - /* This loop terminates because we assume - that FLT_RADIX is a power of 2. */ - while (mantissa > 0.0L) - { - mantissa *= 16.0L; - digit = (int) mantissa; - mantissa -= digit; - *p++ = digit - + (digit < 10 - ? '0' - : dp->conversion - 10); - if (precision > 0) - precision--; - } - while (precision > 0) - { - *p++ = '0'; - precision--; - } - } - } - *p++ = dp->conversion - 'A' + 'P'; + long double arg = a.arg[dp->arg_index].a.a_longdouble; + + if (isnanl (arg)) + { + if (dp->conversion == 'A') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + DECL_LONG_DOUBLE_ROUNDING + + BEGIN_LONG_DOUBLE_ROUNDING (); + + if (signbit (arg)) /* arg < 0.0L or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0L && arg + arg == arg) + { + if (dp->conversion == 'A') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { + int exponent; + long double mantissa; + + if (arg > 0.0L) + mantissa = printf_frexpl (arg, &exponent); + else + { + exponent = 0; + mantissa = 0.0L; + } + + if (has_precision + && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1) + { + /* Round the mantissa. */ + long double tail = mantissa; + size_t q; + + for (q = precision; ; q--) + { + int digit = (int) tail; + tail -= digit; + if (q == 0) + { + if (digit & 1 ? tail >= 0.5L : tail > 0.5L) + tail = 1 - tail; + else + tail = - tail; + break; + } + tail *= 16.0L; + } + if (tail != 0.0L) + for (q = precision; q > 0; q--) + tail *= 0.0625L; + mantissa += tail; + } + + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + { + int digit; + + digit = (int) mantissa; + mantissa -= digit; + *p++ = '0' + digit; + if ((flags & FLAG_ALT) + || mantissa > 0.0L || precision > 0) + { + *p++ = decimal_point_char (); + /* This loop terminates because we assume + that FLT_RADIX is a power of 2. */ + while (mantissa > 0.0L) + { + mantissa *= 16.0L; + digit = (int) mantissa; + mantissa -= digit; + *p++ = digit + + (digit < 10 + ? '0' + : dp->conversion - 10); + if (precision > 0) + precision--; + } + while (precision > 0) + { + *p++ = '0'; + precision--; + } + } + } + *p++ = dp->conversion - 'A' + 'P'; # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } + } - END_LONG_DOUBLE_ROUNDING (); - } + END_LONG_DOUBLE_ROUNDING (); + } # else - abort (); + abort (); # endif - } - else - { + } + else + { # if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE - double arg = a.arg[dp->arg_index].a.a_double; - - if (isnand (arg)) - { - if (dp->conversion == 'A') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - - if (signbit (arg)) /* arg < 0.0 or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0 && arg + arg == arg) - { - if (dp->conversion == 'A') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { - int exponent; - double mantissa; - - if (arg > 0.0) - mantissa = printf_frexp (arg, &exponent); - else - { - exponent = 0; - mantissa = 0.0; - } - - if (has_precision - && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1) - { - /* Round the mantissa. */ - double tail = mantissa; - size_t q; - - for (q = precision; ; q--) - { - int digit = (int) tail; - tail -= digit; - if (q == 0) - { - if (digit & 1 ? tail >= 0.5 : tail > 0.5) - tail = 1 - tail; - else - tail = - tail; - break; - } - tail *= 16.0; - } - if (tail != 0.0) - for (q = precision; q > 0; q--) - tail *= 0.0625; - mantissa += tail; - } - - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - { - int digit; - - digit = (int) mantissa; - mantissa -= digit; - *p++ = '0' + digit; - if ((flags & FLAG_ALT) - || mantissa > 0.0 || precision > 0) - { - *p++ = decimal_point_char (); - /* This loop terminates because we assume - that FLT_RADIX is a power of 2. */ - while (mantissa > 0.0) - { - mantissa *= 16.0; - digit = (int) mantissa; - mantissa -= digit; - *p++ = digit - + (digit < 10 - ? '0' - : dp->conversion - 10); - if (precision > 0) - precision--; - } - while (precision > 0) - { - *p++ = '0'; - precision--; - } - } - } - *p++ = dp->conversion - 'A' + 'P'; + double arg = a.arg[dp->arg_index].a.a_double; + + if (isnand (arg)) + { + if (dp->conversion == 'A') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + + if (signbit (arg)) /* arg < 0.0 or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0 && arg + arg == arg) + { + if (dp->conversion == 'A') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { + int exponent; + double mantissa; + + if (arg > 0.0) + mantissa = printf_frexp (arg, &exponent); + else + { + exponent = 0; + mantissa = 0.0; + } + + if (has_precision + && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1) + { + /* Round the mantissa. */ + double tail = mantissa; + size_t q; + + for (q = precision; ; q--) + { + int digit = (int) tail; + tail -= digit; + if (q == 0) + { + if (digit & 1 ? tail >= 0.5 : tail > 0.5) + tail = 1 - tail; + else + tail = - tail; + break; + } + tail *= 16.0; + } + if (tail != 0.0) + for (q = precision; q > 0; q--) + tail *= 0.0625; + mantissa += tail; + } + + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + { + int digit; + + digit = (int) mantissa; + mantissa -= digit; + *p++ = '0' + digit; + if ((flags & FLAG_ALT) + || mantissa > 0.0 || precision > 0) + { + *p++ = decimal_point_char (); + /* This loop terminates because we assume + that FLT_RADIX is a power of 2. */ + while (mantissa > 0.0) + { + mantissa *= 16.0; + digit = (int) mantissa; + mantissa -= digit; + *p++ = digit + + (digit < 10 + ? '0' + : dp->conversion - 10); + if (precision > 0) + precision--; + } + while (precision > 0) + { + *p++ = '0'; + precision--; + } + } + } + *p++ = dp->conversion - 'A' + 'P'; # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } - } + } + } # else - abort (); + abort (); # endif - } - /* The generated string now extends from tmp to p, with the - zero padding insertion point being at pad_ptr. */ - if (has_width && p - tmp < width) - { - size_t pad = width - (p - tmp); - DCHAR_T *end = p + pad; - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > tmp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - - p = end; - } - - { - size_t count = p - tmp; - - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); - - /* Make room for the result. */ - if (count >= allocated - length) - { - size_t n = xsum (length, count); - - ENSURE_ALLOCATION (n); - } - - /* Append the result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); - if (tmp != tmpbuf) - free (tmp); - length += count; - } - } + } + /* The generated string now extends from tmp to p, with the + zero padding insertion point being at pad_ptr. */ + if (has_width && p - tmp < width) + { + size_t pad = width - (p - tmp); + DCHAR_T *end = p + pad; + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > tmp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + + p = end; + } + + { + size_t count = p - tmp; + + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); + + /* Make room for the result. */ + if (count >= allocated - length) + { + size_t n = xsum (length, count); + + ENSURE_ALLOCATION (n); + } + + /* Append the result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + if (tmp != tmpbuf) + free (tmp); + length += count; + } + } #endif #if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL - else if ((dp->conversion == 'f' || dp->conversion == 'F' - || dp->conversion == 'e' || dp->conversion == 'E' - || dp->conversion == 'g' || dp->conversion == 'G' - || dp->conversion == 'a' || dp->conversion == 'A') - && (0 + else if ((dp->conversion == 'f' || dp->conversion == 'F' + || dp->conversion == 'e' || dp->conversion == 'E' + || dp->conversion == 'g' || dp->conversion == 'G' + || dp->conversion == 'a' || dp->conversion == 'A') + && (0 # if NEED_PRINTF_DOUBLE - || a.arg[dp->arg_index].type == TYPE_DOUBLE + || a.arg[dp->arg_index].type == TYPE_DOUBLE # elif NEED_PRINTF_INFINITE_DOUBLE - || (a.arg[dp->arg_index].type == TYPE_DOUBLE - /* The systems (mingw) which produce wrong output - for Inf, -Inf, and NaN also do so for -0.0. - Therefore we treat this case here as well. */ - && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) + || (a.arg[dp->arg_index].type == TYPE_DOUBLE + /* The systems (mingw) which produce wrong output + for Inf, -Inf, and NaN also do so for -0.0. + Therefore we treat this case here as well. */ + && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) # endif # if NEED_PRINTF_LONG_DOUBLE - || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE # elif NEED_PRINTF_INFINITE_LONG_DOUBLE - || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE - /* Some systems produce wrong output for Inf, - -Inf, and NaN. Some systems in this category - (IRIX 5.3) also do so for -0.0. Therefore we - treat this case here as well. */ - && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble)) + || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + /* Some systems produce wrong output for Inf, + -Inf, and NaN. Some systems in this category + (IRIX 5.3) also do so for -0.0. Therefore we + treat this case here as well. */ + && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble)) # endif - )) - { + )) + { # if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) - arg_type type = a.arg[dp->arg_index].type; + arg_type type = a.arg[dp->arg_index].type; # endif - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - size_t tmp_length; - DCHAR_T tmpbuf[700]; - DCHAR_T *tmp; - DCHAR_T *pad_ptr; - DCHAR_T *p; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - /* POSIX specifies the default precision to be 6 for %f, %F, - %e, %E, but not for %g, %G. Implementations appear to use - the same default precision also for %g, %G. But for %a, %A, - the default precision is 0. */ - if (!has_precision) - if (!(dp->conversion == 'a' || dp->conversion == 'A')) - precision = 6; - - /* Allocate a temporary buffer of sufficient size. */ + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + size_t tmp_length; + DCHAR_T tmpbuf[700]; + DCHAR_T *tmp; + DCHAR_T *pad_ptr; + DCHAR_T *p; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + /* POSIX specifies the default precision to be 6 for %f, %F, + %e, %E, but not for %g, %G. Implementations appear to use + the same default precision also for %g, %G. But for %a, %A, + the default precision is 0. */ + if (!has_precision) + if (!(dp->conversion == 'a' || dp->conversion == 'A')) + precision = 6; + + /* Allocate a temporary buffer of sufficient size. */ # if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE - tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1); + tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1); # elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE - tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); + tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); # elif NEED_PRINTF_LONG_DOUBLE - tmp_length = LDBL_DIG + 1; + tmp_length = LDBL_DIG + 1; # elif NEED_PRINTF_DOUBLE - tmp_length = DBL_DIG + 1; + tmp_length = DBL_DIG + 1; # else - tmp_length = 0; + tmp_length = 0; # endif - if (tmp_length < precision) - tmp_length = precision; + if (tmp_length < precision) + tmp_length = precision; # if NEED_PRINTF_LONG_DOUBLE # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - if (type == TYPE_LONGDOUBLE) + if (type == TYPE_LONGDOUBLE) # endif - if (dp->conversion == 'f' || dp->conversion == 'F') - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - if (!(isnanl (arg) || arg + arg == arg)) - { - /* arg is finite and nonzero. */ - int exponent = floorlog10l (arg < 0 ? -arg : arg); - if (exponent >= 0 && tmp_length < exponent + precision) - tmp_length = exponent + precision; - } - } + if (dp->conversion == 'f' || dp->conversion == 'F') + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + if (!(isnanl (arg) || arg + arg == arg)) + { + /* arg is finite and nonzero. */ + int exponent = floorlog10l (arg < 0 ? -arg : arg); + if (exponent >= 0 && tmp_length < exponent + precision) + tmp_length = exponent + precision; + } + } # endif # if NEED_PRINTF_DOUBLE # if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE - if (type == TYPE_DOUBLE) + if (type == TYPE_DOUBLE) # endif - if (dp->conversion == 'f' || dp->conversion == 'F') - { - double arg = a.arg[dp->arg_index].a.a_double; - if (!(isnand (arg) || arg + arg == arg)) - { - /* arg is finite and nonzero. */ - int exponent = floorlog10 (arg < 0 ? -arg : arg); - if (exponent >= 0 && tmp_length < exponent + precision) - tmp_length = exponent + precision; - } - } + if (dp->conversion == 'f' || dp->conversion == 'F') + { + double arg = a.arg[dp->arg_index].a.a_double; + if (!(isnand (arg) || arg + arg == arg)) + { + /* arg is finite and nonzero. */ + int exponent = floorlog10 (arg < 0 ? -arg : arg); + if (exponent >= 0 && tmp_length < exponent + precision) + tmp_length = exponent + precision; + } + } # endif - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); - if (tmp_length < width) - tmp_length = width; + if (tmp_length < width) + tmp_length = width; - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); + if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (DCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (DCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } - pad_ptr = NULL; - p = tmp; + pad_ptr = NULL; + p = tmp; # if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - if (type == TYPE_LONGDOUBLE) + if (type == TYPE_LONGDOUBLE) # endif - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - - if (isnanl (arg)) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - DECL_LONG_DOUBLE_ROUNDING - - BEGIN_LONG_DOUBLE_ROUNDING (); - - if (signbit (arg)) /* arg < 0.0L or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0L && arg + arg == arg) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + + if (isnanl (arg)) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + DECL_LONG_DOUBLE_ROUNDING + + BEGIN_LONG_DOUBLE_ROUNDING (); + + if (signbit (arg)) /* arg < 0.0L or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0L && arg + arg == arg) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { # if NEED_PRINTF_LONG_DOUBLE - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - char *digits; - size_t ndigits; - - digits = - scale10_round_decimal_long_double (arg, precision); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits > precision) - do - { - --ndigits; - *p++ = digits[ndigits]; - } - while (ndigits > precision); - else - *p++ = '0'; - /* Here ndigits <= precision. */ - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > ndigits; precision--) - *p++ = '0'; - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - int exponent; - - if (arg == 0.0L) - { - exponent = 0; - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else - { - /* arg > 0.0L. */ - int adjusted; - char *digits; - size_t ndigits; - - exponent = floorlog10l (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_long_double (arg, - (int)precision - exponent); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits == precision + 1) - break; - if (ndigits < precision - || ndigits > precision + 2) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits == precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision+1. */ - if (is_borderline (digits, precision)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_long_double (arg, - (int)precision - exponent + 1); - if (digits2 == NULL) - { - free (digits); - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - if (strlen (digits2) == precision + 1) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision+1. */ - - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - - *p++ = dp->conversion; /* 'e' or 'E' */ + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + char *digits; + size_t ndigits; + + digits = + scale10_round_decimal_long_double (arg, precision); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits > precision) + do + { + --ndigits; + *p++ = digits[ndigits]; + } + while (ndigits > precision); + else + *p++ = '0'; + /* Here ndigits <= precision. */ + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > ndigits; precision--) + *p++ = '0'; + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + int exponent; + + if (arg == 0.0L) + { + exponent = 0; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else + { + /* arg > 0.0L. */ + int adjusted; + char *digits; + size_t ndigits; + + exponent = floorlog10l (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_long_double (arg, + (int)precision - exponent); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits == precision + 1) + break; + if (ndigits < precision + || ndigits > precision + 2) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits == precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision+1. */ + if (is_borderline (digits, precision)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_long_double (arg, + (int)precision - exponent + 1); + if (digits2 == NULL) + { + free (digits); + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + if (strlen (digits2) == precision + 1) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision+1. */ + + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + + *p++ = dp->conversion; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', '.', '2', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', '.', '2', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+.2d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+.2d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+.2d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+.2d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - if (precision == 0) - precision = 1; - /* precision >= 1. */ - - if (arg == 0.0L) - /* The exponent is 0, >= -4, < precision. - Use fixed-point notation. */ - { - size_t ndigits = precision; - /* Number of trailing zeroes that have to be - dropped. */ - size_t nzeroes = - (flags & FLAG_ALT ? 0 : precision - 1); - - --ndigits; - *p++ = '0'; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = '0'; - } - } - } - else - { - /* arg > 0.0L. */ - int exponent; - int adjusted; - char *digits; - size_t ndigits; - size_t nzeroes; - - exponent = floorlog10l (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_long_double (arg, - (int)(precision - 1) - exponent); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits == precision) - break; - if (ndigits < precision - 1 - || ndigits > precision + 1) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits < precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision. */ - if (is_borderline (digits, precision - 1)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_long_double (arg, - (int)(precision - 1) - exponent + 1); - if (digits2 == NULL) - { - free (digits); - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - if (strlen (digits2) == precision) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision. */ - - /* Determine the number of trailing zeroes - that have to be dropped. */ - nzeroes = 0; - if ((flags & FLAG_ALT) == 0) - while (nzeroes < ndigits - && digits[nzeroes] == '0') - nzeroes++; - - /* The exponent is now determined. */ - if (exponent >= -4 - && exponent < (long)precision) - { - /* Fixed-point notation: - max(exponent,0)+1 digits, then the - decimal point, then the remaining - digits without trailing zeroes. */ - if (exponent >= 0) - { - size_t count = exponent + 1; - /* Note: count <= precision = ndigits. */ - for (; count > 0; count--) - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - size_t count = -exponent - 1; - *p++ = '0'; - *p++ = decimal_point_char (); - for (; count > 0; count--) - *p++ = '0'; - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - /* Exponential notation. */ - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + if (precision == 0) + precision = 1; + /* precision >= 1. */ + + if (arg == 0.0L) + /* The exponent is 0, >= -4, < precision. + Use fixed-point notation. */ + { + size_t ndigits = precision; + /* Number of trailing zeroes that have to be + dropped. */ + size_t nzeroes = + (flags & FLAG_ALT ? 0 : precision - 1); + + --ndigits; + *p++ = '0'; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = '0'; + } + } + } + else + { + /* arg > 0.0L. */ + int exponent; + int adjusted; + char *digits; + size_t ndigits; + size_t nzeroes; + + exponent = floorlog10l (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_long_double (arg, + (int)(precision - 1) - exponent); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits == precision) + break; + if (ndigits < precision - 1 + || ndigits > precision + 1) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits < precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision. */ + if (is_borderline (digits, precision - 1)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_long_double (arg, + (int)(precision - 1) - exponent + 1); + if (digits2 == NULL) + { + free (digits); + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + if (strlen (digits2) == precision) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision. */ + + /* Determine the number of trailing zeroes + that have to be dropped. */ + nzeroes = 0; + if ((flags & FLAG_ALT) == 0) + while (nzeroes < ndigits + && digits[nzeroes] == '0') + nzeroes++; + + /* The exponent is now determined. */ + if (exponent >= -4 + && exponent < (long)precision) + { + /* Fixed-point notation: + max(exponent,0)+1 digits, then the + decimal point, then the remaining + digits without trailing zeroes. */ + if (exponent >= 0) + { + size_t count = exponent + 1; + /* Note: count <= precision = ndigits. */ + for (; count > 0; count--) + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + size_t count = -exponent - 1; + *p++ = '0'; + *p++ = decimal_point_char (); + for (; count > 0; count--) + *p++ = '0'; + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + /* Exponential notation. */ + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', '.', '2', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', '.', '2', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+.2d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+.2d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+.2d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+.2d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } + } - free (digits); - } - } - else - abort (); + free (digits); + } + } + else + abort (); # else - /* arg is finite. */ - if (!(arg == 0.0L)) - abort (); - - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - *p++ = dp->conversion; /* 'e' or 'E' */ - *p++ = '+'; - *p++ = '0'; - *p++ = '0'; - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - *p++ = '0'; - if (flags & FLAG_ALT) - { - size_t ndigits = - (precision > 0 ? precision - 1 : 0); - *p++ = decimal_point_char (); - for (; ndigits > 0; --ndigits) - *p++ = '0'; - } - } - else if (dp->conversion == 'a' || dp->conversion == 'A') - { - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - *p++ = dp->conversion - 'A' + 'P'; - *p++ = '+'; - *p++ = '0'; - } - else - abort (); + /* arg is finite. */ + if (!(arg == 0.0L)) + abort (); + + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion; /* 'e' or 'E' */ + *p++ = '+'; + *p++ = '0'; + *p++ = '0'; + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + *p++ = '0'; + if (flags & FLAG_ALT) + { + size_t ndigits = + (precision > 0 ? precision - 1 : 0); + *p++ = decimal_point_char (); + for (; ndigits > 0; --ndigits) + *p++ = '0'; + } + } + else if (dp->conversion == 'a' || dp->conversion == 'A') + { + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion - 'A' + 'P'; + *p++ = '+'; + *p++ = '0'; + } + else + abort (); # endif - } + } - END_LONG_DOUBLE_ROUNDING (); - } - } + END_LONG_DOUBLE_ROUNDING (); + } + } # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - else + else # endif # endif # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - { - double arg = a.arg[dp->arg_index].a.a_double; - - if (isnand (arg)) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - - if (signbit (arg)) /* arg < 0.0 or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0 && arg + arg == arg) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { + { + double arg = a.arg[dp->arg_index].a.a_double; + + if (isnand (arg)) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + + if (signbit (arg)) /* arg < 0.0 or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0 && arg + arg == arg) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { # if NEED_PRINTF_DOUBLE - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - char *digits; - size_t ndigits; - - digits = - scale10_round_decimal_double (arg, precision); - if (digits == NULL) - goto out_of_memory; - ndigits = strlen (digits); - - if (ndigits > precision) - do - { - --ndigits; - *p++ = digits[ndigits]; - } - while (ndigits > precision); - else - *p++ = '0'; - /* Here ndigits <= precision. */ - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > ndigits; precision--) - *p++ = '0'; - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - int exponent; - - if (arg == 0.0) - { - exponent = 0; - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else - { - /* arg > 0.0. */ - int adjusted; - char *digits; - size_t ndigits; - - exponent = floorlog10 (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_double (arg, - (int)precision - exponent); - if (digits == NULL) - goto out_of_memory; - ndigits = strlen (digits); - - if (ndigits == precision + 1) - break; - if (ndigits < precision - || ndigits > precision + 2) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits == precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision+1. */ - if (is_borderline (digits, precision)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_double (arg, - (int)precision - exponent + 1); - if (digits2 == NULL) - { - free (digits); - goto out_of_memory; - } - if (strlen (digits2) == precision + 1) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision+1. */ - - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - - *p++ = dp->conversion; /* 'e' or 'E' */ + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + char *digits; + size_t ndigits; + + digits = + scale10_round_decimal_double (arg, precision); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits > precision) + do + { + --ndigits; + *p++ = digits[ndigits]; + } + while (ndigits > precision); + else + *p++ = '0'; + /* Here ndigits <= precision. */ + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > ndigits; precision--) + *p++ = '0'; + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + int exponent; + + if (arg == 0.0) + { + exponent = 0; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else + { + /* arg > 0.0. */ + int adjusted; + char *digits; + size_t ndigits; + + exponent = floorlog10 (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_double (arg, + (int)precision - exponent); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits == precision + 1) + break; + if (ndigits < precision + || ndigits > precision + 2) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits == precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision+1. */ + if (is_borderline (digits, precision)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_double (arg, + (int)precision - exponent + 1); + if (digits2 == NULL) + { + free (digits); + goto out_of_memory; + } + if (strlen (digits2) == precision + 1) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision+1. */ + + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + + *p++ = dp->conversion; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const wchar_t decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - { '%', '+', '.', '3', 'd', '\0' }; + { '%', '+', '.', '3', 'd', '\0' }; # else - { '%', '+', '.', '2', 'd', '\0' }; + { '%', '+', '.', '2', 'd', '\0' }; # endif - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - { - static const char decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const char decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - "%+.3d"; + "%+.3d"; # else - "%+.2d"; + "%+.2d"; # endif - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, decimal_format, exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, decimal_format, exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, decimal_format, exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, decimal_format, exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } + } # endif - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - if (precision == 0) - precision = 1; - /* precision >= 1. */ - - if (arg == 0.0) - /* The exponent is 0, >= -4, < precision. - Use fixed-point notation. */ - { - size_t ndigits = precision; - /* Number of trailing zeroes that have to be - dropped. */ - size_t nzeroes = - (flags & FLAG_ALT ? 0 : precision - 1); - - --ndigits; - *p++ = '0'; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = '0'; - } - } - } - else - { - /* arg > 0.0. */ - int exponent; - int adjusted; - char *digits; - size_t ndigits; - size_t nzeroes; - - exponent = floorlog10 (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_double (arg, - (int)(precision - 1) - exponent); - if (digits == NULL) - goto out_of_memory; - ndigits = strlen (digits); - - if (ndigits == precision) - break; - if (ndigits < precision - 1 - || ndigits > precision + 1) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits < precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision. */ - if (is_borderline (digits, precision - 1)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_double (arg, - (int)(precision - 1) - exponent + 1); - if (digits2 == NULL) - { - free (digits); - goto out_of_memory; - } - if (strlen (digits2) == precision) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision. */ - - /* Determine the number of trailing zeroes - that have to be dropped. */ - nzeroes = 0; - if ((flags & FLAG_ALT) == 0) - while (nzeroes < ndigits - && digits[nzeroes] == '0') - nzeroes++; - - /* The exponent is now determined. */ - if (exponent >= -4 - && exponent < (long)precision) - { - /* Fixed-point notation: - max(exponent,0)+1 digits, then the - decimal point, then the remaining - digits without trailing zeroes. */ - if (exponent >= 0) - { - size_t count = exponent + 1; - /* Note: count <= precision = ndigits. */ - for (; count > 0; count--) - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - size_t count = -exponent - 1; - *p++ = '0'; - *p++ = decimal_point_char (); - for (; count > 0; count--) - *p++ = '0'; - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - /* Exponential notation. */ - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + if (precision == 0) + precision = 1; + /* precision >= 1. */ + + if (arg == 0.0) + /* The exponent is 0, >= -4, < precision. + Use fixed-point notation. */ + { + size_t ndigits = precision; + /* Number of trailing zeroes that have to be + dropped. */ + size_t nzeroes = + (flags & FLAG_ALT ? 0 : precision - 1); + + --ndigits; + *p++ = '0'; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = '0'; + } + } + } + else + { + /* arg > 0.0. */ + int exponent; + int adjusted; + char *digits; + size_t ndigits; + size_t nzeroes; + + exponent = floorlog10 (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_double (arg, + (int)(precision - 1) - exponent); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits == precision) + break; + if (ndigits < precision - 1 + || ndigits > precision + 1) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits < precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision. */ + if (is_borderline (digits, precision - 1)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_double (arg, + (int)(precision - 1) - exponent + 1); + if (digits2 == NULL) + { + free (digits); + goto out_of_memory; + } + if (strlen (digits2) == precision) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision. */ + + /* Determine the number of trailing zeroes + that have to be dropped. */ + nzeroes = 0; + if ((flags & FLAG_ALT) == 0) + while (nzeroes < ndigits + && digits[nzeroes] == '0') + nzeroes++; + + /* The exponent is now determined. */ + if (exponent >= -4 + && exponent < (long)precision) + { + /* Fixed-point notation: + max(exponent,0)+1 digits, then the + decimal point, then the remaining + digits without trailing zeroes. */ + if (exponent >= 0) + { + size_t count = exponent + 1; + /* Note: count <= precision = ndigits. */ + for (; count > 0; count--) + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + size_t count = -exponent - 1; + *p++ = '0'; + *p++ = decimal_point_char (); + for (; count > 0; count--) + *p++ = '0'; + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + /* Exponential notation. */ + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const wchar_t decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - { '%', '+', '.', '3', 'd', '\0' }; + { '%', '+', '.', '3', 'd', '\0' }; # else - { '%', '+', '.', '2', 'd', '\0' }; + { '%', '+', '.', '2', 'd', '\0' }; # endif - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - { - static const char decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const char decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - "%+.3d"; + "%+.3d"; # else - "%+.2d"; + "%+.2d"; # endif - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, decimal_format, exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, decimal_format, exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, decimal_format, exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, decimal_format, exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } + } # endif - } + } - free (digits); - } - } - else - abort (); + free (digits); + } + } + else + abort (); # else - /* arg is finite. */ - if (!(arg == 0.0)) - abort (); - - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - *p++ = dp->conversion; /* 'e' or 'E' */ - *p++ = '+'; - /* Produce the same number of exponent digits as - the native printf implementation. */ + /* arg is finite. */ + if (!(arg == 0.0)) + abort (); + + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion; /* 'e' or 'E' */ + *p++ = '+'; + /* Produce the same number of exponent digits as + the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - *p++ = '0'; + *p++ = '0'; # endif - *p++ = '0'; - *p++ = '0'; - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - *p++ = '0'; - if (flags & FLAG_ALT) - { - size_t ndigits = - (precision > 0 ? precision - 1 : 0); - *p++ = decimal_point_char (); - for (; ndigits > 0; --ndigits) - *p++ = '0'; - } - } - else - abort (); + *p++ = '0'; + *p++ = '0'; + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + *p++ = '0'; + if (flags & FLAG_ALT) + { + size_t ndigits = + (precision > 0 ? precision - 1 : 0); + *p++ = decimal_point_char (); + for (; ndigits > 0; --ndigits) + *p++ = '0'; + } + } + else + abort (); # endif - } - } - } + } + } + } # endif - /* The generated string now extends from tmp to p, with the - zero padding insertion point being at pad_ptr. */ - if (has_width && p - tmp < width) - { - size_t pad = width - (p - tmp); - DCHAR_T *end = p + pad; - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > tmp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - - p = end; - } - - { - size_t count = p - tmp; - - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); - - /* Make room for the result. */ - if (count >= allocated - length) - { - size_t n = xsum (length, count); - - ENSURE_ALLOCATION (n); - } - - /* Append the result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); - if (tmp != tmpbuf) - free (tmp); - length += count; - } - } + /* The generated string now extends from tmp to p, with the + zero padding insertion point being at pad_ptr. */ + if (has_width && p - tmp < width) + { + size_t pad = width - (p - tmp); + DCHAR_T *end = p + pad; + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > tmp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + + p = end; + } + + { + size_t count = p - tmp; + + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); + + /* Make room for the result. */ + if (count >= allocated - length) + { + size_t n = xsum (length, count); + + ENSURE_ALLOCATION (n); + } + + /* Append the result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + if (tmp != tmpbuf) + free (tmp); + length += count; + } + } #endif - else - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; + else + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; #if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - int has_width; - size_t width; + int has_width; + size_t width; #endif #if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION - int has_precision; - size_t precision; + int has_precision; + size_t precision; #endif #if NEED_PRINTF_UNBOUNDED_PRECISION - int prec_ourselves; + int prec_ourselves; #else -# define prec_ourselves 0 +# define prec_ourselves 0 #endif #if NEED_PRINTF_FLAG_LEFTADJUST -# define pad_ourselves 1 +# define pad_ourselves 1 #elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - int pad_ourselves; + int pad_ourselves; #else -# define pad_ourselves 0 +# define pad_ourselves 0 #endif - TCHAR_T *fbp; - unsigned int prefix_count; - int prefixes[2] IF_LINT (= { 0 }); + TCHAR_T *fbp; + unsigned int prefix_count; + int prefixes[2] IF_LINT (= { 0 }); #if !USE_SNPRINTF - size_t tmp_length; - TCHAR_T tmpbuf[700]; - TCHAR_T *tmp; + size_t tmp_length; + TCHAR_T tmpbuf[700]; + TCHAR_T *tmp; #endif #if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } #endif #if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION - has_precision = 0; - precision = 6; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } + has_precision = 0; + precision = 6; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } #endif - /* Decide whether to handle the precision ourselves. */ + /* Decide whether to handle the precision ourselves. */ #if NEED_PRINTF_UNBOUNDED_PRECISION - switch (dp->conversion) - { - case 'd': case 'i': case 'u': - case 'o': - case 'x': case 'X': case 'p': - prec_ourselves = has_precision && (precision > 0); - break; - default: - prec_ourselves = 0; - break; - } + switch (dp->conversion) + { + case 'd': case 'i': case 'u': + case 'o': + case 'x': case 'X': case 'p': + prec_ourselves = has_precision && (precision > 0); + break; + default: + prec_ourselves = 0; + break; + } #endif - /* Decide whether to perform the padding ourselves. */ + /* Decide whether to perform the padding ourselves. */ #if !NEED_PRINTF_FLAG_LEFTADJUST && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION) - switch (dp->conversion) - { + switch (dp->conversion) + { # if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO - /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need - to perform the padding after this conversion. Functions - with unistdio extensions perform the padding based on - character count rather than element count. */ - case 'c': case 's': + /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need + to perform the padding after this conversion. Functions + with unistdio extensions perform the padding based on + character count rather than element count. */ + case 'c': case 's': # endif # if NEED_PRINTF_FLAG_ZERO - case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': - case 'a': case 'A': + case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': + case 'a': case 'A': # endif - pad_ourselves = 1; - break; - default: - pad_ourselves = prec_ourselves; - break; - } + pad_ourselves = 1; + break; + default: + pad_ourselves = prec_ourselves; + break; + } #endif #if !USE_SNPRINTF - /* Allocate a temporary buffer of sufficient size for calling - sprintf. */ - { - switch (dp->conversion) - { + /* Allocate a temporary buffer of sufficient size for calling + sprintf. */ + { + switch (dp->conversion) + { - case 'd': case 'i': case 'u': + case 'd': case 'i': case 'u': # if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - else + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else # endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Multiply by 2, as an estimate for FLAG_GROUP. */ - tmp_length = xsum (tmp_length, tmp_length); - /* Add 1, to account for a leading sign. */ - tmp_length = xsum (tmp_length, 1); - break; - - case 'o': + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Multiply by 2, as an estimate for FLAG_GROUP. */ + tmp_length = xsum (tmp_length, tmp_length); + /* Add 1, to account for a leading sign. */ + tmp_length = xsum (tmp_length, 1); + break; + + case 'o': # if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - else + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else # endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Add 1, to account for a leading sign. */ - tmp_length = xsum (tmp_length, 1); - break; - - case 'x': case 'X': + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Add 1, to account for a leading sign. */ + tmp_length = xsum (tmp_length, 1); + break; + + case 'x': case 'X': # if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else # endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Add 2, to account for a leading sign or alternate form. */ - tmp_length = xsum (tmp_length, 2); - break; - - case 'f': case 'F': - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) (LDBL_MAX_EXP - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 10; /* sign, decimal point etc. */ - else - tmp_length = - (unsigned int) (DBL_MAX_EXP - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 10; /* sign, decimal point etc. */ - tmp_length = xsum (tmp_length, precision); - break; - - case 'e': case 'E': case 'g': case 'G': - tmp_length = - 12; /* sign, decimal point, exponent etc. */ - tmp_length = xsum (tmp_length, precision); - break; - - case 'a': case 'A': - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) (LDBL_DIG - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (DBL_DIG - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); - break; - - case 'c': + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Add 2, to account for a leading sign or alternate form. */ + tmp_length = xsum (tmp_length, 2); + break; + + case 'f': case 'F': + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) (LDBL_MAX_EXP + * 0.30103 /* binary -> decimal */ + * 2 /* estimate for FLAG_GROUP */ + ) + + 1 /* turn floor into ceil */ + + 10; /* sign, decimal point etc. */ + else + tmp_length = + (unsigned int) (DBL_MAX_EXP + * 0.30103 /* binary -> decimal */ + * 2 /* estimate for FLAG_GROUP */ + ) + + 1 /* turn floor into ceil */ + + 10; /* sign, decimal point etc. */ + tmp_length = xsum (tmp_length, precision); + break; + + case 'e': case 'E': case 'g': case 'G': + tmp_length = + 12; /* sign, decimal point, exponent etc. */ + tmp_length = xsum (tmp_length, precision); + break; + + case 'a': case 'A': + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) (LDBL_DIG + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (DBL_DIG + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); + break; + + case 'c': # if HAVE_WINT_T && !WIDE_CHAR_VERSION - if (type == TYPE_WIDE_CHAR) - tmp_length = MB_CUR_MAX; - else + if (type == TYPE_WIDE_CHAR) + tmp_length = MB_CUR_MAX; + else # endif - tmp_length = 1; - break; + tmp_length = 1; + break; - case 's': + case 's': # if HAVE_WCHAR_T - if (type == TYPE_WIDE_STRING) - { + if (type == TYPE_WIDE_STRING) + { # if WIDE_CHAR_VERSION - /* ISO C says about %ls in fwprintf: - "If the precision is not specified or is greater - than the size of the array, the array shall - contain a null wide character." - So if there is a precision, we must not use - wcslen. */ - const wchar_t *arg = - a.arg[dp->arg_index].a.a_wide_string; - - if (has_precision) - tmp_length = local_wcsnlen (arg, precision); - else - tmp_length = local_wcslen (arg); + /* ISO C says about %ls in fwprintf: + "If the precision is not specified or is greater + than the size of the array, the array shall + contain a null wide character." + So if there is a precision, we must not use + wcslen. */ + const wchar_t *arg = + a.arg[dp->arg_index].a.a_wide_string; + + if (has_precision) + tmp_length = local_wcsnlen (arg, precision); + else + tmp_length = local_wcslen (arg); # else - /* ISO C says about %ls in fprintf: - "If a precision is specified, no more than that - many bytes are written (including shift - sequences, if any), and the array shall contain - a null wide character if, to equal the - multibyte character sequence length given by - the precision, the function would need to - access a wide character one past the end of the - array." - So if there is a precision, we must not use - wcslen. */ - /* This case has already been handled above. */ - abort (); + /* ISO C says about %ls in fprintf: + "If a precision is specified, no more than that + many bytes are written (including shift + sequences, if any), and the array shall contain + a null wide character if, to equal the + multibyte character sequence length given by + the precision, the function would need to + access a wide character one past the end of the + array." + So if there is a precision, we must not use + wcslen. */ + /* This case has already been handled above. */ + abort (); # endif - } - else + } + else # endif - { + { # if WIDE_CHAR_VERSION - /* ISO C says about %s in fwprintf: - "If the precision is not specified or is greater - than the size of the converted array, the - converted array shall contain a null wide - character." - So if there is a precision, we must not use - strlen. */ - /* This case has already been handled above. */ - abort (); + /* ISO C says about %s in fwprintf: + "If the precision is not specified or is greater + than the size of the converted array, the + converted array shall contain a null wide + character." + So if there is a precision, we must not use + strlen. */ + /* This case has already been handled above. */ + abort (); # else - /* ISO C says about %s in fprintf: - "If the precision is not specified or greater - than the size of the array, the array shall - contain a null character." - So if there is a precision, we must not use - strlen. */ - const char *arg = a.arg[dp->arg_index].a.a_string; - - if (has_precision) - tmp_length = local_strnlen (arg, precision); - else - tmp_length = strlen (arg); + /* ISO C says about %s in fprintf: + "If the precision is not specified or greater + than the size of the array, the array shall + contain a null character." + So if there is a precision, we must not use + strlen. */ + const char *arg = a.arg[dp->arg_index].a.a_string; + + if (has_precision) + tmp_length = local_strnlen (arg, precision); + else + tmp_length = strlen (arg); # endif - } - break; - - case 'p': - tmp_length = - (unsigned int) (sizeof (void *) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1 /* turn floor into ceil */ - + 2; /* account for leading 0x */ - break; - - default: - abort (); - } - - if (!pad_ourselves) - { + } + break; + + case 'p': + tmp_length = + (unsigned int) (sizeof (void *) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1 /* turn floor into ceil */ + + 2; /* account for leading 0x */ + break; + + default: + abort (); + } + + if (!pad_ourselves) + { # if ENABLE_UNISTDIO - /* Padding considers the number of characters, therefore - the number of elements after padding may be - > max (tmp_length, width) - but is certainly - <= tmp_length + width. */ - tmp_length = xsum (tmp_length, width); + /* Padding considers the number of characters, therefore + the number of elements after padding may be + > max (tmp_length, width) + but is certainly + <= tmp_length + width. */ + tmp_length = xsum (tmp_length, width); # else - /* Padding considers the number of elements, - says POSIX. */ - if (tmp_length < width) - tmp_length = width; + /* Padding considers the number of elements, + says POSIX. */ + if (tmp_length < width) + tmp_length = width; # endif - } - - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - } - - if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T)); - - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (TCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } + } + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + } + + if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T)); + + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (TCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } #endif - /* Construct the format string for calling snprintf or - sprintf. */ - fbp = buf; - *fbp++ = '%'; + /* Construct the format string for calling snprintf or + sprintf. */ + fbp = buf; + *fbp++ = '%'; #if NEED_PRINTF_FLAG_GROUPING - /* The underlying implementation doesn't support the ' flag. - Produce no grouping characters in this case; this is - acceptable because the grouping is locale dependent. */ + /* The underlying implementation doesn't support the ' flag. + Produce no grouping characters in this case; this is + acceptable because the grouping is locale dependent. */ #else - if (flags & FLAG_GROUP) - *fbp++ = '\''; + if (flags & FLAG_GROUP) + *fbp++ = '\''; #endif - if (flags & FLAG_LEFT) - *fbp++ = '-'; - if (flags & FLAG_SHOWSIGN) - *fbp++ = '+'; - if (flags & FLAG_SPACE) - *fbp++ = ' '; - if (flags & FLAG_ALT) - *fbp++ = '#'; - if (!pad_ourselves) - { - if (flags & FLAG_ZERO) - *fbp++ = '0'; - if (dp->width_start != dp->width_end) - { - size_t n = dp->width_end - dp->width_start; - /* The width specification is known to consist only - of standard ASCII characters. */ - if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) - { - memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T)); - fbp += n; - } - else - { - const FCHAR_T *mp = dp->width_start; - do - *fbp++ = (unsigned char) *mp++; - while (--n > 0); - } - } - } - if (!prec_ourselves) - { - if (dp->precision_start != dp->precision_end) - { - size_t n = dp->precision_end - dp->precision_start; - /* The precision specification is known to consist only - of standard ASCII characters. */ - if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) - { - memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T)); - fbp += n; - } - else - { - const FCHAR_T *mp = dp->precision_start; - do - *fbp++ = (unsigned char) *mp++; - while (--n > 0); - } - } - } - - switch (type) - { + if (flags & FLAG_LEFT) + *fbp++ = '-'; + if (flags & FLAG_SHOWSIGN) + *fbp++ = '+'; + if (flags & FLAG_SPACE) + *fbp++ = ' '; + if (flags & FLAG_ALT) + *fbp++ = '#'; + if (!pad_ourselves) + { + if (flags & FLAG_ZERO) + *fbp++ = '0'; + if (dp->width_start != dp->width_end) + { + size_t n = dp->width_end - dp->width_start; + /* The width specification is known to consist only + of standard ASCII characters. */ + if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) + { + memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T)); + fbp += n; + } + else + { + const FCHAR_T *mp = dp->width_start; + do + *fbp++ = (unsigned char) *mp++; + while (--n > 0); + } + } + } + if (!prec_ourselves) + { + if (dp->precision_start != dp->precision_end) + { + size_t n = dp->precision_end - dp->precision_start; + /* The precision specification is known to consist only + of standard ASCII characters. */ + if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) + { + memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T)); + fbp += n; + } + else + { + const FCHAR_T *mp = dp->precision_start; + do + *fbp++ = (unsigned char) *mp++; + while (--n > 0); + } + } + } + + switch (type) + { #if HAVE_LONG_LONG_INT - case TYPE_LONGLONGINT: - case TYPE_ULONGLONGINT: + case TYPE_LONGLONGINT: + case TYPE_ULONGLONGINT: # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - *fbp++ = 'I'; - *fbp++ = '6'; - *fbp++ = '4'; - break; + *fbp++ = 'I'; + *fbp++ = '6'; + *fbp++ = '4'; + break; # else - *fbp++ = 'l'; - /*FALLTHROUGH*/ + *fbp++ = 'l'; + /*FALLTHROUGH*/ # endif #endif - case TYPE_LONGINT: - case TYPE_ULONGINT: + case TYPE_LONGINT: + case TYPE_ULONGINT: #if HAVE_WINT_T - case TYPE_WIDE_CHAR: + case TYPE_WIDE_CHAR: #endif #if HAVE_WCHAR_T - case TYPE_WIDE_STRING: + case TYPE_WIDE_STRING: #endif - *fbp++ = 'l'; - break; - case TYPE_LONGDOUBLE: - *fbp++ = 'L'; - break; - default: - break; - } + *fbp++ = 'l'; + break; + case TYPE_LONGDOUBLE: + *fbp++ = 'L'; + break; + default: + break; + } #if NEED_PRINTF_DIRECTIVE_F - if (dp->conversion == 'F') - *fbp = 'f'; - else + if (dp->conversion == 'F') + *fbp = 'f'; + else #endif - *fbp = dp->conversion; + *fbp = dp->conversion; #if USE_SNPRINTF # if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) - fbp[1] = '%'; - fbp[2] = 'n'; - fbp[3] = '\0'; + fbp[1] = '%'; + fbp[2] = 'n'; + fbp[3] = '\0'; # else - /* On glibc2 systems from glibc >= 2.3 - probably also older - ones - we know that snprintf's returns value conforms to - ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes. - Therefore we can avoid using %n in this situation. - On glibc2 systems from 2004-10-18 or newer, the use of %n - in format strings in writable memory may crash the program - (if compiled with _FORTIFY_SOURCE=2), so we should avoid it - in this situation. */ - /* On native Win32 systems (such as mingw), we can avoid using - %n because: - - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, - snprintf does not write more than the specified number - of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes - '4', '5', '6' into buf, not '4', '5', '\0'.) - - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf - allows us to recognize the case of an insufficient - buffer size: it returns -1 in this case. - On native Win32 systems (such as mingw) where the OS is - Windows Vista, the use of %n in format strings by default - crashes the program. See - and - - So we should avoid %n in this situation. */ - fbp[1] = '\0'; + /* On glibc2 systems from glibc >= 2.3 - probably also older + ones - we know that snprintf's returns value conforms to + ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes. + Therefore we can avoid using %n in this situation. + On glibc2 systems from 2004-10-18 or newer, the use of %n + in format strings in writable memory may crash the program + (if compiled with _FORTIFY_SOURCE=2), so we should avoid it + in this situation. */ + /* On native Win32 systems (such as mingw), we can avoid using + %n because: + - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, + snprintf does not write more than the specified number + of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes + '4', '5', '6' into buf, not '4', '5', '\0'.) + - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf + allows us to recognize the case of an insufficient + buffer size: it returns -1 in this case. + On native Win32 systems (such as mingw) where the OS is + Windows Vista, the use of %n in format strings by default + crashes the program. See + and + + So we should avoid %n in this situation. */ + fbp[1] = '\0'; # endif #else - fbp[1] = '\0'; + fbp[1] = '\0'; #endif - /* Construct the arguments for calling snprintf or sprintf. */ - prefix_count = 0; - if (!pad_ourselves && dp->width_arg_index != ARG_NONE) - { - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; - } - if (!prec_ourselves && dp->precision_arg_index != ARG_NONE) - { - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; - } + /* Construct the arguments for calling snprintf or sprintf. */ + prefix_count = 0; + if (!pad_ourselves && dp->width_arg_index != ARG_NONE) + { + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; + } + if (!prec_ourselves && dp->precision_arg_index != ARG_NONE) + { + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; + } #if USE_SNPRINTF - /* The SNPRINTF result is appended after result[0..length]. - The latter is an array of DCHAR_T; SNPRINTF appends an - array of TCHAR_T to it. This is possible because - sizeof (TCHAR_T) divides sizeof (DCHAR_T) and - alignof (TCHAR_T) <= alignof (DCHAR_T). */ + /* The SNPRINTF result is appended after result[0..length]. + The latter is an array of DCHAR_T; SNPRINTF appends an + array of TCHAR_T to it. This is possible because + sizeof (TCHAR_T) divides sizeof (DCHAR_T) and + alignof (TCHAR_T) <= alignof (DCHAR_T). */ # define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T)) - /* Ensure that maxlen below will be >= 2. Needed on BeOS, - where an snprintf() with maxlen==1 acts like sprintf(). */ - ENSURE_ALLOCATION (xsum (length, - (2 + TCHARS_PER_DCHAR - 1) - / TCHARS_PER_DCHAR)); - /* Prepare checking whether snprintf returns the count - via %n. */ - *(TCHAR_T *) (result + length) = '\0'; + /* Ensure that maxlen below will be >= 2. Needed on BeOS, + where an snprintf() with maxlen==1 acts like sprintf(). */ + ENSURE_ALLOCATION (xsum (length, + (2 + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR)); + /* Prepare checking whether snprintf returns the count + via %n. */ + *(TCHAR_T *) (result + length) = '\0'; #endif - for (;;) - { - int count = -1; + for (;;) + { + int count = -1; #if USE_SNPRINTF - int retcount = 0; - size_t maxlen = allocated - length; - /* SNPRINTF can fail if its second argument is - > INT_MAX. */ - if (maxlen > INT_MAX / TCHARS_PER_DCHAR) - maxlen = INT_MAX / TCHARS_PER_DCHAR; - maxlen = maxlen * TCHARS_PER_DCHAR; + int retcount = 0; + size_t maxlen = allocated - length; + /* SNPRINTF can fail if its second argument is + > INT_MAX. */ + if (maxlen > INT_MAX / TCHARS_PER_DCHAR) + maxlen = INT_MAX / TCHARS_PER_DCHAR; + maxlen = maxlen * TCHARS_PER_DCHAR; # define SNPRINTF_BUF(arg) \ - switch (prefix_count) \ - { \ - case 0: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - arg, &count); \ - break; \ - case 1: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - prefixes[0], arg, &count); \ - break; \ - case 2: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - prefixes[0], prefixes[1], arg, \ - &count); \ - break; \ - default: \ - abort (); \ - } + switch (prefix_count) \ + { \ + case 0: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + arg, &count); \ + break; \ + case 1: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + prefixes[0], arg, &count); \ + break; \ + case 2: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + prefixes[0], prefixes[1], arg, \ + &count); \ + break; \ + default: \ + abort (); \ + } #else # define SNPRINTF_BUF(arg) \ - switch (prefix_count) \ - { \ - case 0: \ - count = sprintf (tmp, buf, arg); \ - break; \ - case 1: \ - count = sprintf (tmp, buf, prefixes[0], arg); \ - break; \ - case 2: \ - count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ - arg); \ - break; \ - default: \ - abort (); \ - } + switch (prefix_count) \ + { \ + case 0: \ + count = sprintf (tmp, buf, arg); \ + break; \ + case 1: \ + count = sprintf (tmp, buf, prefixes[0], arg); \ + break; \ + case 2: \ + count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ + arg); \ + break; \ + default: \ + abort (); \ + } #endif - switch (type) - { - case TYPE_SCHAR: - { - int arg = a.arg[dp->arg_index].a.a_schar; - SNPRINTF_BUF (arg); - } - break; - case TYPE_UCHAR: - { - unsigned int arg = a.arg[dp->arg_index].a.a_uchar; - SNPRINTF_BUF (arg); - } - break; - case TYPE_SHORT: - { - int arg = a.arg[dp->arg_index].a.a_short; - SNPRINTF_BUF (arg); - } - break; - case TYPE_USHORT: - { - unsigned int arg = a.arg[dp->arg_index].a.a_ushort; - SNPRINTF_BUF (arg); - } - break; - case TYPE_INT: - { - int arg = a.arg[dp->arg_index].a.a_int; - SNPRINTF_BUF (arg); - } - break; - case TYPE_UINT: - { - unsigned int arg = a.arg[dp->arg_index].a.a_uint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_LONGINT: - { - long int arg = a.arg[dp->arg_index].a.a_longint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_ULONGINT: - { - unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; - SNPRINTF_BUF (arg); - } - break; + switch (type) + { + case TYPE_SCHAR: + { + int arg = a.arg[dp->arg_index].a.a_schar; + SNPRINTF_BUF (arg); + } + break; + case TYPE_UCHAR: + { + unsigned int arg = a.arg[dp->arg_index].a.a_uchar; + SNPRINTF_BUF (arg); + } + break; + case TYPE_SHORT: + { + int arg = a.arg[dp->arg_index].a.a_short; + SNPRINTF_BUF (arg); + } + break; + case TYPE_USHORT: + { + unsigned int arg = a.arg[dp->arg_index].a.a_ushort; + SNPRINTF_BUF (arg); + } + break; + case TYPE_INT: + { + int arg = a.arg[dp->arg_index].a.a_int; + SNPRINTF_BUF (arg); + } + break; + case TYPE_UINT: + { + unsigned int arg = a.arg[dp->arg_index].a.a_uint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_LONGINT: + { + long int arg = a.arg[dp->arg_index].a.a_longint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_ULONGINT: + { + unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; + SNPRINTF_BUF (arg); + } + break; #if HAVE_LONG_LONG_INT - case TYPE_LONGLONGINT: - { - long long int arg = a.arg[dp->arg_index].a.a_longlongint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_ULONGLONGINT: - { - unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; - SNPRINTF_BUF (arg); - } - break; + case TYPE_LONGLONGINT: + { + long long int arg = a.arg[dp->arg_index].a.a_longlongint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_ULONGLONGINT: + { + unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; + SNPRINTF_BUF (arg); + } + break; #endif - case TYPE_DOUBLE: - { - double arg = a.arg[dp->arg_index].a.a_double; - SNPRINTF_BUF (arg); - } - break; - case TYPE_LONGDOUBLE: - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - SNPRINTF_BUF (arg); - } - break; - case TYPE_CHAR: - { - int arg = a.arg[dp->arg_index].a.a_char; - SNPRINTF_BUF (arg); - } - break; + case TYPE_DOUBLE: + { + double arg = a.arg[dp->arg_index].a.a_double; + SNPRINTF_BUF (arg); + } + break; + case TYPE_LONGDOUBLE: + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + SNPRINTF_BUF (arg); + } + break; + case TYPE_CHAR: + { + int arg = a.arg[dp->arg_index].a.a_char; + SNPRINTF_BUF (arg); + } + break; #if HAVE_WINT_T - case TYPE_WIDE_CHAR: - { - wint_t arg = a.arg[dp->arg_index].a.a_wide_char; - SNPRINTF_BUF (arg); - } - break; + case TYPE_WIDE_CHAR: + { + wint_t arg = a.arg[dp->arg_index].a.a_wide_char; + SNPRINTF_BUF (arg); + } + break; #endif - case TYPE_STRING: - { - const char *arg = a.arg[dp->arg_index].a.a_string; - SNPRINTF_BUF (arg); - } - break; + case TYPE_STRING: + { + const char *arg = a.arg[dp->arg_index].a.a_string; + SNPRINTF_BUF (arg); + } + break; #if HAVE_WCHAR_T - case TYPE_WIDE_STRING: - { - const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; - SNPRINTF_BUF (arg); - } - break; + case TYPE_WIDE_STRING: + { + const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; + SNPRINTF_BUF (arg); + } + break; #endif - case TYPE_POINTER: - { - void *arg = a.arg[dp->arg_index].a.a_pointer; - SNPRINTF_BUF (arg); - } - break; - default: - abort (); - } + case TYPE_POINTER: + { + void *arg = a.arg[dp->arg_index].a.a_pointer; + SNPRINTF_BUF (arg); + } + break; + default: + abort (); + } #if USE_SNPRINTF - /* Portability: Not all implementations of snprintf() - are ISO C 99 compliant. Determine the number of - bytes that snprintf() has produced or would have - produced. */ - if (count >= 0) - { - /* Verify that snprintf() has NUL-terminated its - result. */ - if (count < maxlen - && ((TCHAR_T *) (result + length)) [count] != '\0') - abort (); - /* Portability hack. */ - if (retcount > count) - count = retcount; - } - else - { - /* snprintf() doesn't understand the '%n' - directive. */ - if (fbp[1] != '\0') - { - /* Don't use the '%n' directive; instead, look - at the snprintf() return value. */ - fbp[1] = '\0'; - continue; - } - else - { - /* Look at the snprintf() return value. */ - if (retcount < 0) - { - /* HP-UX 10.20 snprintf() is doubly deficient: - It doesn't understand the '%n' directive, - *and* it returns -1 (rather than the length - that would have been required) when the - buffer is too small. */ - size_t bigger_need = - xsum (xtimes (allocated, 2), 12); - ENSURE_ALLOCATION (bigger_need); - continue; - } - else - count = retcount; - } - } + /* Portability: Not all implementations of snprintf() + are ISO C 99 compliant. Determine the number of + bytes that snprintf() has produced or would have + produced. */ + if (count >= 0) + { + /* Verify that snprintf() has NUL-terminated its + result. */ + if (count < maxlen + && ((TCHAR_T *) (result + length)) [count] != '\0') + abort (); + /* Portability hack. */ + if (retcount > count) + count = retcount; + } + else + { + /* snprintf() doesn't understand the '%n' + directive. */ + if (fbp[1] != '\0') + { + /* Don't use the '%n' directive; instead, look + at the snprintf() return value. */ + fbp[1] = '\0'; + continue; + } + else + { + /* Look at the snprintf() return value. */ + if (retcount < 0) + { + /* HP-UX 10.20 snprintf() is doubly deficient: + It doesn't understand the '%n' directive, + *and* it returns -1 (rather than the length + that would have been required) when the + buffer is too small. */ + size_t bigger_need = + xsum (xtimes (allocated, 2), 12); + ENSURE_ALLOCATION (bigger_need); + continue; + } + else + count = retcount; + } + } #endif - /* Attempt to handle failure. */ - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EINVAL; - return NULL; - } + /* Attempt to handle failure. */ + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EINVAL; + return NULL; + } #if USE_SNPRINTF - /* Handle overflow of the allocated buffer. - If such an overflow occurs, a C99 compliant snprintf() - returns a count >= maxlen. However, a non-compliant - snprintf() function returns only count = maxlen - 1. To - cover both cases, test whether count >= maxlen - 1. */ - if ((unsigned int) count + 1 >= maxlen) - { - /* If maxlen already has attained its allowed maximum, - allocating more memory will not increase maxlen. - Instead of looping, bail out. */ - if (maxlen == INT_MAX / TCHARS_PER_DCHAR) - goto overflow; - else - { - /* Need at least (count + 1) * sizeof (TCHAR_T) - bytes. (The +1 is for the trailing NUL.) - But ask for (count + 2) * sizeof (TCHAR_T) - bytes, so that in the next round, we likely get - maxlen > (unsigned int) count + 1 - and so we don't get here again. - And allocate proportionally, to avoid looping - eternally if snprintf() reports a too small - count. */ - size_t n = - xmax (xsum (length, - ((unsigned int) count + 2 - + TCHARS_PER_DCHAR - 1) - / TCHARS_PER_DCHAR), - xtimes (allocated, 2)); - - ENSURE_ALLOCATION (n); - continue; - } - } + /* Handle overflow of the allocated buffer. + If such an overflow occurs, a C99 compliant snprintf() + returns a count >= maxlen. However, a non-compliant + snprintf() function returns only count = maxlen - 1. To + cover both cases, test whether count >= maxlen - 1. */ + if ((unsigned int) count + 1 >= maxlen) + { + /* If maxlen already has attained its allowed maximum, + allocating more memory will not increase maxlen. + Instead of looping, bail out. */ + if (maxlen == INT_MAX / TCHARS_PER_DCHAR) + goto overflow; + else + { + /* Need at least (count + 1) * sizeof (TCHAR_T) + bytes. (The +1 is for the trailing NUL.) + But ask for (count + 2) * sizeof (TCHAR_T) + bytes, so that in the next round, we likely get + maxlen > (unsigned int) count + 1 + and so we don't get here again. + And allocate proportionally, to avoid looping + eternally if snprintf() reports a too small + count. */ + size_t n = + xmax (xsum (length, + ((unsigned int) count + 2 + + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR), + xtimes (allocated, 2)); + + ENSURE_ALLOCATION (n); + continue; + } + } #endif #if NEED_PRINTF_UNBOUNDED_PRECISION - if (prec_ourselves) - { - /* Handle the precision. */ - TCHAR_T *prec_ptr = + if (prec_ourselves) + { + /* Handle the precision. */ + TCHAR_T *prec_ptr = # if USE_SNPRINTF - (TCHAR_T *) (result + length); + (TCHAR_T *) (result + length); # else - tmp; + tmp; # endif - size_t prefix_count; - size_t move; - - prefix_count = 0; - /* Put the additional zeroes after the sign. */ - if (count >= 1 - && (*prec_ptr == '-' || *prec_ptr == '+' - || *prec_ptr == ' ')) - prefix_count = 1; - /* Put the additional zeroes after the 0x prefix if - (flags & FLAG_ALT) || (dp->conversion == 'p'). */ - else if (count >= 2 - && prec_ptr[0] == '0' - && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X')) - prefix_count = 2; - - move = count - prefix_count; - if (precision > move) - { - /* Insert zeroes. */ - size_t insert = precision - move; - TCHAR_T *prec_end; + size_t prefix_count; + size_t move; + + prefix_count = 0; + /* Put the additional zeroes after the sign. */ + if (count >= 1 + && (*prec_ptr == '-' || *prec_ptr == '+' + || *prec_ptr == ' ')) + prefix_count = 1; + /* Put the additional zeroes after the 0x prefix if + (flags & FLAG_ALT) || (dp->conversion == 'p'). */ + else if (count >= 2 + && prec_ptr[0] == '0' + && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X')) + prefix_count = 2; + + move = count - prefix_count; + if (precision > move) + { + /* Insert zeroes. */ + size_t insert = precision - move; + TCHAR_T *prec_end; # if USE_SNPRINTF - size_t n = - xsum (length, - (count + insert + TCHARS_PER_DCHAR - 1) - / TCHARS_PER_DCHAR); - length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; - ENSURE_ALLOCATION (n); - length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; - prec_ptr = (TCHAR_T *) (result + length); + size_t n = + xsum (length, + (count + insert + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR); + length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; + ENSURE_ALLOCATION (n); + length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; + prec_ptr = (TCHAR_T *) (result + length); # endif - prec_end = prec_ptr + count; - prec_ptr += prefix_count; + prec_end = prec_ptr + count; + prec_ptr += prefix_count; - while (prec_end > prec_ptr) - { - prec_end--; - prec_end[insert] = prec_end[0]; - } + while (prec_end > prec_ptr) + { + prec_end--; + prec_end[insert] = prec_end[0]; + } - prec_end += insert; - do - *--prec_end = '0'; - while (prec_end > prec_ptr); + prec_end += insert; + do + *--prec_end = '0'; + while (prec_end > prec_ptr); - count += insert; - } - } + count += insert; + } + } #endif #if !USE_SNPRINTF - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); #endif #if !DCHAR_IS_TCHAR - /* Convert from TCHAR_T[] to DCHAR_T[]. */ - if (dp->conversion == 'c' || dp->conversion == 's') - { - /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING - TYPE_WIDE_STRING. - The result string is not certainly ASCII. */ - const TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t tmpdst_len; - /* This code assumes that TCHAR_T is 'char'. */ - typedef int TCHAR_T_verify - [2 * (sizeof (TCHAR_T) == 1) - 1]; + /* Convert from TCHAR_T[] to DCHAR_T[]. */ + if (dp->conversion == 'c' || dp->conversion == 's') + { + /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING + TYPE_WIDE_STRING. + The result string is not certainly ASCII. */ + const TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t tmpdst_len; + /* This code assumes that TCHAR_T is 'char'. */ + typedef int TCHAR_T_verify + [2 * (sizeof (TCHAR_T) == 1) - 1]; # if USE_SNPRINTF - tmpsrc = (TCHAR_T *) (result + length); + tmpsrc = (TCHAR_T *) (result + length); # else - tmpsrc = tmp; + tmpsrc = tmp; # endif - tmpdst = - DCHAR_CONV_FROM_ENCODING (locale_charset (), - iconveh_question_mark, - tmpsrc, count, - NULL, - NULL, &tmpdst_len); - if (tmpdst == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - ENSURE_ALLOCATION (xsum (length, tmpdst_len)); - DCHAR_CPY (result + length, tmpdst, tmpdst_len); - free (tmpdst); - count = tmpdst_len; - } - else - { - /* The result string is ASCII. - Simple 1:1 conversion. */ + tmpdst = + DCHAR_CONV_FROM_ENCODING (locale_charset (), + iconveh_question_mark, + tmpsrc, count, + NULL, + NULL, &tmpdst_len); + if (tmpdst == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + ENSURE_ALLOCATION (xsum (length, tmpdst_len)); + DCHAR_CPY (result + length, tmpdst, tmpdst_len); + free (tmpdst); + count = tmpdst_len; + } + else + { + /* The result string is ASCII. + Simple 1:1 conversion. */ # if USE_SNPRINTF - /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a - no-op conversion, in-place on the array starting - at (result + length). */ - if (sizeof (DCHAR_T) != sizeof (TCHAR_T)) + /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a + no-op conversion, in-place on the array starting + at (result + length). */ + if (sizeof (DCHAR_T) != sizeof (TCHAR_T)) # endif - { - const TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t n; + { + const TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t n; # if USE_SNPRINTF - if (result == resultbuf) - { - tmpsrc = (TCHAR_T *) (result + length); - /* ENSURE_ALLOCATION will not move tmpsrc - (because it's part of resultbuf). */ - ENSURE_ALLOCATION (xsum (length, count)); - } - else - { - /* ENSURE_ALLOCATION will move the array - (because it uses realloc(). */ - ENSURE_ALLOCATION (xsum (length, count)); - tmpsrc = (TCHAR_T *) (result + length); - } + if (result == resultbuf) + { + tmpsrc = (TCHAR_T *) (result + length); + /* ENSURE_ALLOCATION will not move tmpsrc + (because it's part of resultbuf). */ + ENSURE_ALLOCATION (xsum (length, count)); + } + else + { + /* ENSURE_ALLOCATION will move the array + (because it uses realloc(). */ + ENSURE_ALLOCATION (xsum (length, count)); + tmpsrc = (TCHAR_T *) (result + length); + } # else - tmpsrc = tmp; - ENSURE_ALLOCATION (xsum (length, count)); + tmpsrc = tmp; + ENSURE_ALLOCATION (xsum (length, count)); # endif - tmpdst = result + length; - /* Copy backwards, because of overlapping. */ - tmpsrc += count; - tmpdst += count; - for (n = count; n > 0; n--) - *--tmpdst = (unsigned char) *--tmpsrc; - } - } + tmpdst = result + length; + /* Copy backwards, because of overlapping. */ + tmpsrc += count; + tmpdst += count; + for (n = count; n > 0; n--) + *--tmpdst = (unsigned char) *--tmpsrc; + } + } #endif #if DCHAR_IS_TCHAR && !USE_SNPRINTF - /* Make room for the result. */ - if (count > allocated - length) - { - /* Need at least count elements. But allocate - proportionally. */ - size_t n = - xmax (xsum (length, count), xtimes (allocated, 2)); - - ENSURE_ALLOCATION (n); - } + /* Make room for the result. */ + if (count > allocated - length) + { + /* Need at least count elements. But allocate + proportionally. */ + size_t n = + xmax (xsum (length, count), xtimes (allocated, 2)); + + ENSURE_ALLOCATION (n); + } #endif - /* Here count <= allocated - length. */ + /* Here count <= allocated - length. */ - /* Perform padding. */ + /* Perform padding. */ #if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - if (pad_ourselves && has_width) - { - size_t w; + if (pad_ourselves && has_width) + { + size_t w; # if ENABLE_UNISTDIO - /* Outside POSIX, it's preferrable to compare the width - against the number of _characters_ of the converted - value. */ - w = DCHAR_MBSNLEN (result + length, count); + /* Outside POSIX, it's preferrable to compare the width + against the number of _characters_ of the converted + value. */ + w = DCHAR_MBSNLEN (result + length, count); # else - /* The width is compared against the number of _bytes_ - of the converted value, says POSIX. */ - w = count; + /* The width is compared against the number of _bytes_ + of the converted value, says POSIX. */ + w = count; # endif - if (w < width) - { - size_t pad = width - w; - - /* Make room for the result. */ - if (xsum (count, pad) > allocated - length) - { - /* Need at least count + pad elements. But - allocate proportionally. */ - size_t n = - xmax (xsum3 (length, count, pad), - xtimes (allocated, 2)); + if (w < width) + { + size_t pad = width - w; + + /* Make room for the result. */ + if (xsum (count, pad) > allocated - length) + { + /* Need at least count + pad elements. But + allocate proportionally. */ + size_t n = + xmax (xsum3 (length, count, pad), + xtimes (allocated, 2)); # if USE_SNPRINTF - length += count; - ENSURE_ALLOCATION (n); - length -= count; + length += count; + ENSURE_ALLOCATION (n); + length -= count; # else - ENSURE_ALLOCATION (n); + ENSURE_ALLOCATION (n); # endif - } - /* Here count + pad <= allocated - length. */ + } + /* Here count + pad <= allocated - length. */ - { + { # if !DCHAR_IS_TCHAR || USE_SNPRINTF - DCHAR_T * const rp = result + length; + DCHAR_T * const rp = result + length; # else - DCHAR_T * const rp = tmp; + DCHAR_T * const rp = tmp; # endif - DCHAR_T *p = rp + count; - DCHAR_T *end = p + pad; - DCHAR_T *pad_ptr; + DCHAR_T *p = rp + count; + DCHAR_T *end = p + pad; + DCHAR_T *pad_ptr; # if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO - if (dp->conversion == 'c' - || dp->conversion == 's') - /* No zero-padding for string directives. */ - pad_ptr = NULL; - else + if (dp->conversion == 'c' + || dp->conversion == 's') + /* No zero-padding for string directives. */ + pad_ptr = NULL; + else # endif - { - pad_ptr = (*rp == '-' ? rp + 1 : rp); - /* No zero-padding of "inf" and "nan". */ - if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z') - || (*pad_ptr >= 'a' && *pad_ptr <= 'z')) - pad_ptr = NULL; - } - /* The generated string now extends from rp to p, - with the zero padding insertion point being at - pad_ptr. */ - - count = count + pad; /* = end - rp */ - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > rp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - } - } - } + { + pad_ptr = (*rp == '-' ? rp + 1 : rp); + /* No zero-padding of "inf" and "nan". */ + if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z') + || (*pad_ptr >= 'a' && *pad_ptr <= 'z')) + pad_ptr = NULL; + } + /* The generated string now extends from rp to p, + with the zero padding insertion point being at + pad_ptr. */ + + count = count + pad; /* = end - rp */ + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > rp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + } + } + } #endif - /* Here still count <= allocated - length. */ + /* Here still count <= allocated - length. */ #if !DCHAR_IS_TCHAR || USE_SNPRINTF - /* The snprintf() result did fit. */ + /* The snprintf() result did fit. */ #else - /* Append the sprintf() result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + /* Append the sprintf() result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); #endif #if !USE_SNPRINTF - if (tmp != tmpbuf) - free (tmp); + if (tmp != tmpbuf) + free (tmp); #endif #if NEED_PRINTF_DIRECTIVE_F - if (dp->conversion == 'F') - { - /* Convert the %f result to upper case for %F. */ - DCHAR_T *rp = result + length; - size_t rc; - for (rc = count; rc > 0; rc--, rp++) - if (*rp >= 'a' && *rp <= 'z') - *rp = *rp - 'a' + 'A'; - } + if (dp->conversion == 'F') + { + /* Convert the %f result to upper case for %F. */ + DCHAR_T *rp = result + length; + size_t rc; + for (rc = count; rc > 0; rc--, rp++) + if (*rp >= 'a' && *rp <= 'z') + *rp = *rp - 'a' + 'A'; + } #endif - length += count; - break; - } - } - } + length += count; + break; + } + } + } } /* Add the final NUL. */ @@ -5433,12 +5433,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, if (result != resultbuf && length + 1 < allocated) { - /* Shrink the allocated memory if possible. */ - DCHAR_T *memory; + /* Shrink the allocated memory if possible. */ + DCHAR_T *memory; - memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); - if (memory != NULL) - result = memory; + memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); + if (memory != NULL) + result = memory; } if (buf_malloced != NULL) diff --git a/gettext-runtime/libasprintf/vasprintf.h b/gettext-runtime/libasprintf/vasprintf.h index 3911d0084..158647d93 100644 --- a/gettext-runtime/libasprintf/vasprintf.h +++ b/gettext-runtime/libasprintf/vasprintf.h @@ -35,7 +35,7 @@ # endif #endif -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -48,7 +48,7 @@ extern int asprintf (char **result, const char *format, ...) extern int vasprintf (char **result, const char *format, va_list args) __attribute__ ((__format__ (__printf__, 2, 0))); -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/gettext-runtime/m4/ChangeLog b/gettext-runtime/m4/ChangeLog index f854b705a..21ca5af46 100644 --- a/gettext-runtime/m4/ChangeLog +++ b/gettext-runtime/m4/ChangeLog @@ -1,3 +1,10 @@ +2009-12-12 Bruno Haible + + * fcntl_h.m4: Untabify. + * glibc2.m4: Untabify. + * glibc21.m4: Untabify. + * longlong.m4: Untabify. + 2009-10-18 Bruno Haible * fcntl_h.m4: New file, from gnulib. diff --git a/gettext-runtime/m4/fcntl_h.m4 b/gettext-runtime/m4/fcntl_h.m4 index 223fa4830..40a18034d 100644 --- a/gettext-runtime/m4/fcntl_h.m4 +++ b/gettext-runtime/m4/fcntl_h.m4 @@ -26,53 +26,53 @@ AC_DEFUN([gl_FCNTL_O_FLAGS], AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( - [[#include - #include - #include - #include - #ifndef O_NOATIME - #define O_NOATIME 0 - #endif - #ifndef O_NOFOLLOW - #define O_NOFOLLOW 0 - #endif - static int const constants[] = - { - O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, - O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY - }; - ]], - [[ - int status = !constants; - { - static char const sym[] = "conftest.sym"; - if (symlink (".", sym) != 0 - || close (open (sym, O_RDONLY | O_NOFOLLOW)) == 0) - status |= 32; - unlink (sym); - } - { - static char const file[] = "confdefs.h"; - int fd = open (file, O_RDONLY | O_NOATIME); - char c; - struct stat st0, st1; - if (fd < 0 - || fstat (fd, &st0) != 0 - || sleep (1) != 0 - || read (fd, &c, 1) != 1 - || close (fd) != 0 - || stat (file, &st1) != 0 - || st0.st_atime != st1.st_atime) - status |= 64; - } - return status;]])], + [[#include + #include + #include + #include + #ifndef O_NOATIME + #define O_NOATIME 0 + #endif + #ifndef O_NOFOLLOW + #define O_NOFOLLOW 0 + #endif + static int const constants[] = + { + O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, + O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY + }; + ]], + [[ + int status = !constants; + { + static char const sym[] = "conftest.sym"; + if (symlink (".", sym) != 0 + || close (open (sym, O_RDONLY | O_NOFOLLOW)) == 0) + status |= 32; + unlink (sym); + } + { + static char const file[] = "confdefs.h"; + int fd = open (file, O_RDONLY | O_NOATIME); + char c; + struct stat st0, st1; + if (fd < 0 + || fstat (fd, &st0) != 0 + || sleep (1) != 0 + || read (fd, &c, 1) != 1 + || close (fd) != 0 + || stat (file, &st1) != 0 + || st0.st_atime != st1.st_atime) + status |= 64; + } + return status;]])], [gl_cv_header_working_fcntl_h=yes], [case $? in #( - 32) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #( - 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #( - 96) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #( - *) gl_cv_header_working_fcntl_h='no';; - esac], + 32) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #( + 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #( + 96) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #( + *) gl_cv_header_working_fcntl_h='no';; + esac], [gl_cv_header_working_fcntl_h=cross-compiling])]) case $gl_cv_header_working_fcntl_h in #( diff --git a/gettext-runtime/m4/glibc2.m4 b/gettext-runtime/m4/glibc2.m4 index fe58a0f32..3435aa233 100644 --- a/gettext-runtime/m4/glibc2.m4 +++ b/gettext-runtime/m4/glibc2.m4 @@ -12,16 +12,16 @@ AC_DEFUN([gt_GLIBC2], AC_CACHE_CHECK([whether we are using the GNU C Library 2 or newer], [ac_cv_gnu_library_2], [AC_EGREP_CPP([Lucky GNU user], - [ + [ #include #ifdef __GNU_LIBRARY__ #if (__GLIBC__ >= 2) Lucky GNU user #endif #endif - ], - [ac_cv_gnu_library_2=yes], - [ac_cv_gnu_library_2=no]) + ], + [ac_cv_gnu_library_2=yes], + [ac_cv_gnu_library_2=no]) ] ) AC_SUBST([GLIBC2]) diff --git a/gettext-runtime/m4/glibc21.m4 b/gettext-runtime/m4/glibc21.m4 index 93fbf4745..12cddfe8b 100644 --- a/gettext-runtime/m4/glibc21.m4 +++ b/gettext-runtime/m4/glibc21.m4 @@ -12,16 +12,16 @@ AC_DEFUN([gl_GLIBC21], AC_CACHE_CHECK([whether we are using the GNU C Library 2.1 or newer], [ac_cv_gnu_library_2_1], [AC_EGREP_CPP([Lucky GNU user], - [ + [ #include #ifdef __GNU_LIBRARY__ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2) Lucky GNU user #endif #endif - ], - [ac_cv_gnu_library_2_1=yes], - [ac_cv_gnu_library_2_1=no]) + ], + [ac_cv_gnu_library_2_1=yes], + [ac_cv_gnu_library_2_1=no]) ] ) AC_SUBST([GLIBC21]) diff --git a/gettext-runtime/m4/longlong.m4 b/gettext-runtime/m4/longlong.m4 index eedc8d568..6d17ea373 100644 --- a/gettext-runtime/m4/longlong.m4 +++ b/gettext-runtime/m4/longlong.m4 @@ -20,30 +20,30 @@ AC_DEFUN([AC_TYPE_LONG_LONG_INT], [AC_LINK_IFELSE( [_AC_TYPE_LONG_LONG_SNIPPET], [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. - dnl If cross compiling, assume the bug isn't important, since - dnl nobody cross compiles for this platform as far as we know. - AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [[@%:@include - @%:@ifndef LLONG_MAX - @%:@ define HALF \ - (1LL << (sizeof (long long int) * CHAR_BIT - 2)) - @%:@ define LLONG_MAX (HALF - 1 + HALF) - @%:@endif]], - [[long long int n = 1; - int i; - for (i = 0; ; i++) - { - long long int m = n << i; - if (m >> i != n) - return 1; - if (LLONG_MAX / 2 < m) - break; - } - return 0;]])], - [ac_cv_type_long_long_int=yes], - [ac_cv_type_long_long_int=no], - [ac_cv_type_long_long_int=yes])], + dnl If cross compiling, assume the bug isn't important, since + dnl nobody cross compiles for this platform as far as we know. + AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[@%:@include + @%:@ifndef LLONG_MAX + @%:@ define HALF \ + (1LL << (sizeof (long long int) * CHAR_BIT - 2)) + @%:@ define LLONG_MAX (HALF - 1 + HALF) + @%:@endif]], + [[long long int n = 1; + int i; + for (i = 0; ; i++) + { + long long int m = n << i; + if (m >> i != n) + return 1; + if (LLONG_MAX / 2 < m) + break; + } + return 0;]])], + [ac_cv_type_long_long_int=yes], + [ac_cv_type_long_long_int=no], + [ac_cv_type_long_long_int=yes])], [ac_cv_type_long_long_int=no])]) if test $ac_cv_type_long_long_int = yes; then AC_DEFINE([HAVE_LONG_LONG_INT], [1], @@ -83,24 +83,24 @@ AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET], [ AC_LANG_PROGRAM( [[/* For now, do not test the preprocessor; as of 2007 there are too many - implementations with broken preprocessors. Perhaps this can - be revisited in 2012. In the meantime, code should not expect - #if to work with literals wider than 32 bits. */ + implementations with broken preprocessors. Perhaps this can + be revisited in 2012. In the meantime, code should not expect + #if to work with literals wider than 32 bits. */ /* Test literals. */ long long int ll = 9223372036854775807ll; long long int nll = -9223372036854775807LL; unsigned long long int ull = 18446744073709551615ULL; /* Test constant expressions. */ typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) - ? 1 : -1)]; + ? 1 : -1)]; typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1 - ? 1 : -1)]; + ? 1 : -1)]; int i = 63;]], [[/* Test availability of runtime routines for shift and division. */ long long int llmax = 9223372036854775807ll; unsigned long long int ullmax = 18446744073709551615ull; return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) - | (llmax / ll) | (llmax % ll) - | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) - | (ullmax / ull) | (ullmax % ull));]]) + | (llmax / ll) | (llmax % ll) + | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) + | (ullmax / ull) | (ullmax % ull));]]) ]) diff --git a/gettext-runtime/src/ChangeLog b/gettext-runtime/src/ChangeLog index 9d685bd69..da8169c20 100644 --- a/gettext-runtime/src/ChangeLog +++ b/gettext-runtime/src/ChangeLog @@ -1,3 +1,7 @@ +2009-12-12 Bruno Haible + + * *.c: Untabify. + 2009-01-17 Bruno Haible Update after gnulib changed. diff --git a/gettext-runtime/src/envsubst.c b/gettext-runtime/src/envsubst.c index 59c05edeb..511c1d9cf 100644 --- a/gettext-runtime/src/envsubst.c +++ b/gettext-runtime/src/envsubst.c @@ -89,7 +89,7 @@ main (int argc, char *argv[]) while ((opt = getopt_long (argc, argv, "hvV", long_options, NULL)) != EOF) switch (opt) { - case '\0': /* Long option. */ + case '\0': /* Long option. */ break; case 'h': do_help = true; @@ -114,7 +114,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2003-2007"); + "2003-2007"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -131,31 +131,31 @@ There is NO WARRANTY, to the extent permitted by law.\n\ { /* Output only the variables. */ switch (argc - optind) - { - case 1: - break; - case 0: - error (EXIT_FAILURE, 0, _("missing arguments")); - default: - abort (); - } + { + case 1: + break; + case 0: + error (EXIT_FAILURE, 0, _("missing arguments")); + default: + abort (); + } print_variables (argv[optind++]); } else { /* Actually perform the substitutions. */ switch (argc - optind) - { - case 1: - all_variables = false; - note_variables (argv[optind++]); - break; - case 0: - all_variables = true; - break; - default: - abort (); - } + { + case 1: + all_variables = false; + note_variables (argv[optind++]); + break; + case 0: + all_variables = true; + break; + default: + abort (); + } subst_from_stdin (); } @@ -169,7 +169,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { /* xgettext: no-wrap */ @@ -234,45 +234,45 @@ of the environment variables that are referenced in SHELL-FORMAT, one per line.\ encodings. */ static void find_variables (const char *string, - void (*callback) (const char *var_ptr, size_t var_len)) + void (*callback) (const char *var_ptr, size_t var_len)) { for (; *string != '\0';) if (*string++ == '$') { - const char *variable_start; - const char *variable_end; - bool valid; - char c; - - if (*string == '{') - string++; - - variable_start = string; - c = *string; - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') - { - do - c = *++string; - while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9') || c == '_'); - variable_end = string; - - if (variable_start[-1] == '{') - { - if (*string == '}') - { - string++; - valid = true; - } - else - valid = false; - } - else - valid = true; - - if (valid) - callback (variable_start, variable_end - variable_start); - } + const char *variable_start; + const char *variable_end; + bool valid; + char c; + + if (*string == '{') + string++; + + variable_start = string; + c = *string; + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') + { + do + c = *++string; + while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') + || (c >= '0' && c <= '9') || c == '_'); + variable_end = string; + + if (variable_start[-1] == '{') + { + if (*string == '}') + { + string++; + valid = true; + } + else + valid = false; + } + else + valid = true; + + if (valid) + callback (variable_start, variable_end - variable_start); + } } } @@ -373,22 +373,22 @@ sorted_string_list_member (const string_list_ty *slp, const char *s) { /* Binary search. */ while (j2 - j1 > 1) - { - /* Here we know that if s is in the list, it is at an index j - with j1 <= j < j2. */ - size_t j = (j1 + j2) >> 1; - int result = strcmp (slp->item[j], s); - - if (result > 0) - j2 = j; - else if (result == 0) - return 1; - else - j1 = j + 1; - } + { + /* Here we know that if s is in the list, it is at an index j + with j1 <= j < j2. */ + size_t j = (j1 + j2) >> 1; + int result = strcmp (slp->item[j], s); + + if (result > 0) + j2 = j; + else if (result == 0) + return 1; + else + j1 = j + 1; + } if (j2 > j1) - if (strcmp (slp->item[j1], s) == 0) - return 1; + if (strcmp (slp->item[j1], s) == 0) + return 1; } return 0; } @@ -439,7 +439,7 @@ do_getc () if (c == EOF) { if (ferror (stdin)) - error (EXIT_FAILURE, errno, _("\ + error (EXIT_FAILURE, errno, _("\ error while reading \"%s\""), _("standard input")); } @@ -466,104 +466,104 @@ subst_from_stdin () { c = do_getc (); if (c == EOF) - break; + break; /* Look for $VARIABLE or ${VARIABLE}. */ if (c == '$') - { - bool opening_brace = false; - bool closing_brace = false; - - c = do_getc (); - if (c == '{') - { - opening_brace = true; - c = do_getc (); - } - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') - { - bool valid; - - /* Accumulate the VARIABLE in buffer. */ - buflen = 0; - do - { - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[buflen++] = c; - - c = do_getc (); - } - while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9') || c == '_'); - - if (opening_brace) - { - if (c == '}') - { - closing_brace = true; - valid = true; - } - else - { - valid = false; - do_ungetc (c); - } - } - else - { - valid = true; - do_ungetc (c); - } - - if (valid) - { - /* Terminate the variable in the buffer. */ - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[buflen] = '\0'; - - /* Test whether the variable shall be substituted. */ - if (!all_variables - && !sorted_string_list_member (&variables_set, buffer)) - valid = false; - } - - if (valid) - { - /* Substitute the variable's value from the environment. */ - const char *env_value = getenv (buffer); - - if (env_value != NULL) - fputs (env_value, stdout); - } - else - { - /* Perform no substitution at all. Since the buffered input - contains no other '$' than at the start, we can just - output all the buffered contents. */ - putchar ('$'); - if (opening_brace) - putchar ('{'); - fwrite (buffer, buflen, 1, stdout); - if (closing_brace) - putchar ('}'); - } - } - else - { - do_ungetc (c); - putchar ('$'); - if (opening_brace) - putchar ('{'); - } - } + { + bool opening_brace = false; + bool closing_brace = false; + + c = do_getc (); + if (c == '{') + { + opening_brace = true; + c = do_getc (); + } + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') + { + bool valid; + + /* Accumulate the VARIABLE in buffer. */ + buflen = 0; + do + { + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[buflen++] = c; + + c = do_getc (); + } + while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') + || (c >= '0' && c <= '9') || c == '_'); + + if (opening_brace) + { + if (c == '}') + { + closing_brace = true; + valid = true; + } + else + { + valid = false; + do_ungetc (c); + } + } + else + { + valid = true; + do_ungetc (c); + } + + if (valid) + { + /* Terminate the variable in the buffer. */ + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[buflen] = '\0'; + + /* Test whether the variable shall be substituted. */ + if (!all_variables + && !sorted_string_list_member (&variables_set, buffer)) + valid = false; + } + + if (valid) + { + /* Substitute the variable's value from the environment. */ + const char *env_value = getenv (buffer); + + if (env_value != NULL) + fputs (env_value, stdout); + } + else + { + /* Perform no substitution at all. Since the buffered input + contains no other '$' than at the start, we can just + output all the buffered contents. */ + putchar ('$'); + if (opening_brace) + putchar ('{'); + fwrite (buffer, buflen, 1, stdout); + if (closing_brace) + putchar ('}'); + } + } + else + { + do_ungetc (c); + putchar ('$'); + if (opening_brace) + putchar ('{'); + } + } else - putchar (c); + putchar (c); } } diff --git a/gettext-runtime/src/gettext.c b/gettext-runtime/src/gettext.c index c051bf87a..145347953 100644 --- a/gettext-runtime/src/gettext.c +++ b/gettext-runtime/src/gettext.c @@ -95,10 +95,10 @@ main (int argc, char *argv[]) /* Parse command line options. */ while ((optchar = getopt_long (argc, argv, "+d:eEhnsV", long_options, NULL)) - != EOF) + != EOF) switch (optchar) { - case '\0': /* Long option. */ + case '\0': /* Long option. */ break; case 'd': domain = optarg; @@ -135,7 +135,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "1995-1997, 2000-2007"); + "1995-1997, 2000-2007"); printf (_("Written by %s.\n"), proper_name ("Ulrich Drepper")); exit (EXIT_SUCCESS); } @@ -152,78 +152,78 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Get arguments. */ switch (argc - optind) - { - default: - error (EXIT_FAILURE, 0, _("too many arguments")); + { + default: + error (EXIT_FAILURE, 0, _("too many arguments")); - case 2: - domain = argv[optind++]; - /* FALLTHROUGH */ + case 2: + domain = argv[optind++]; + /* FALLTHROUGH */ - case 1: - break; + case 1: + break; - case 0: - error (EXIT_FAILURE, 0, _("missing arguments")); - } + case 0: + error (EXIT_FAILURE, 0, _("missing arguments")); + } msgid = argv[optind++]; /* Expand escape sequences if enabled. */ if (do_expand) - msgid = expand_escape (msgid); + msgid = expand_escape (msgid); /* If no domain name is given we don't translate. */ if (domain == NULL || domain[0] == '\0') - { - fputs (msgid, stdout); - } + { + fputs (msgid, stdout); + } else - { - /* Bind domain to appropriate directory. */ - if (domaindir != NULL && domaindir[0] != '\0') - bindtextdomain (domain, domaindir); - - /* Write out the result. */ - fputs (dgettext (domain, msgid), stdout); - } + { + /* Bind domain to appropriate directory. */ + if (domaindir != NULL && domaindir[0] != '\0') + bindtextdomain (domain, domaindir); + + /* Write out the result. */ + fputs (dgettext (domain, msgid), stdout); + } } else { if (optind < argc) - { - /* If no domain name is given we print the original string. - We mark this assigning NULL to domain. */ - if (domain == NULL || domain[0] == '\0') - domain = NULL; - else - /* Bind domain to appropriate directory. */ - if (domaindir != NULL && domaindir[0] != '\0') - bindtextdomain (domain, domaindir); - - /* We have to simulate `echo'. All arguments are strings. */ - do - { - msgid = argv[optind++]; - - /* Expand escape sequences if enabled. */ - if (do_expand) - msgid = expand_escape (msgid); - - /* Write out the result. */ - fputs (domain == NULL ? msgid : dgettext (domain, msgid), - stdout); - - /* We separate the arguments by a single ' '. */ - if (optind < argc) - fputc (' ', stdout); - } - while (optind < argc); - } + { + /* If no domain name is given we print the original string. + We mark this assigning NULL to domain. */ + if (domain == NULL || domain[0] == '\0') + domain = NULL; + else + /* Bind domain to appropriate directory. */ + if (domaindir != NULL && domaindir[0] != '\0') + bindtextdomain (domain, domaindir); + + /* We have to simulate `echo'. All arguments are strings. */ + do + { + msgid = argv[optind++]; + + /* Expand escape sequences if enabled. */ + if (do_expand) + msgid = expand_escape (msgid); + + /* Write out the result. */ + fputs (domain == NULL ? msgid : dgettext (domain, msgid), + stdout); + + /* We separate the arguments by a single ' '. */ + if (optind < argc) + fputc (' ', stdout); + } + while (optind < argc); + } /* If not otherwise told: add trailing newline. */ if (add_newline) - fputc ('\n', stdout); + fputc ('\n', stdout); } exit (EXIT_SUCCESS); @@ -236,7 +236,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { /* xgettext: no-wrap */ @@ -270,7 +270,7 @@ When used with the -s option the program behaves like the `echo' command.\n\ But it does not simply copy its arguments to stdout. Instead those messages\n\ found in the selected catalog are translated.\n\ Standard search directory: %s\n"), - getenv ("IN_HELP2MAN") == NULL ? LOCALEDIR : "@localedir@"); + getenv ("IN_HELP2MAN") == NULL ? LOCALEDIR : "@localedir@"); printf ("\n"); /* TRANSLATORS: The placeholder indicates the bug-reporting address for this package. Please add _another line_ saying @@ -293,14 +293,14 @@ expand_escape (const char *str) for (;;) { while (cp[0] != '\0' && cp[0] != '\\') - ++cp; + ++cp; if (cp[0] == '\0') - return str; + return str; /* Found a backslash. */ if (cp[1] == '\0') - return str; + return str; if (strchr ("abcfnrtv\\01234567", cp[1]) != NULL) - break; + break; ++cp; } @@ -313,69 +313,69 @@ expand_escape (const char *str) { /* Here cp[0] == '\\'. */ switch (*++cp) - { - case 'a': /* alert */ - *rp++ = '\a'; - ++cp; - break; - case 'b': /* backspace */ - *rp++ = '\b'; - ++cp; - break; - case 'c': /* suppress trailing newline */ - add_newline = false; - ++cp; - break; - case 'f': /* form feed */ - *rp++ = '\f'; - ++cp; - break; - case 'n': /* new line */ - *rp++ = '\n'; - ++cp; - break; - case 'r': /* carriage return */ - *rp++ = '\r'; - ++cp; - break; - case 't': /* horizontal tab */ - *rp++ = '\t'; - ++cp; - break; - case 'v': /* vertical tab */ - *rp++ = '\v'; - ++cp; - break; - case '\\': - *rp = '\\'; - ++cp; - break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - { - int ch = *cp++ - '0'; - - if (*cp >= '0' && *cp <= '7') - { - ch *= 8; - ch += *cp++ - '0'; - - if (*cp >= '0' && *cp <= '7') - { - ch *= 8; - ch += *cp++ - '0'; - } - } - *rp = ch; - } - break; - default: - *rp = '\\'; - break; - } + { + case 'a': /* alert */ + *rp++ = '\a'; + ++cp; + break; + case 'b': /* backspace */ + *rp++ = '\b'; + ++cp; + break; + case 'c': /* suppress trailing newline */ + add_newline = false; + ++cp; + break; + case 'f': /* form feed */ + *rp++ = '\f'; + ++cp; + break; + case 'n': /* new line */ + *rp++ = '\n'; + ++cp; + break; + case 'r': /* carriage return */ + *rp++ = '\r'; + ++cp; + break; + case 't': /* horizontal tab */ + *rp++ = '\t'; + ++cp; + break; + case 'v': /* vertical tab */ + *rp++ = '\v'; + ++cp; + break; + case '\\': + *rp = '\\'; + ++cp; + break; + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + { + int ch = *cp++ - '0'; + + if (*cp >= '0' && *cp <= '7') + { + ch *= 8; + ch += *cp++ - '0'; + + if (*cp >= '0' && *cp <= '7') + { + ch *= 8; + ch += *cp++ - '0'; + } + } + *rp = ch; + } + break; + default: + *rp = '\\'; + break; + } while (cp[0] != '\0' && cp[0] != '\\') - *rp++ = *cp++; + *rp++ = *cp++; } while (cp[0] != '\0'); diff --git a/gettext-runtime/src/ngettext.c b/gettext-runtime/src/ngettext.c index be394630f..8a8ecb5bf 100644 --- a/gettext-runtime/src/ngettext.c +++ b/gettext-runtime/src/ngettext.c @@ -91,10 +91,10 @@ main (int argc, char *argv[]) /* Parse command line options. */ while ((optchar = getopt_long (argc, argv, "+d:eEhV", long_options, NULL)) - != EOF) + != EOF) switch (optchar) { - case '\0': /* Long option. */ + case '\0': /* Long option. */ break; case 'd': domain = optarg; @@ -125,7 +125,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "1995-1997, 2000-2007"); + "1995-1997, 2000-2007"); printf (_("Written by %s.\n"), proper_name ("Ulrich Drepper")); exit (EXIT_SUCCESS); } @@ -189,7 +189,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\ { /* Bind domain to appropriate directory. */ if (domaindir != NULL && domaindir[0] != '\0') - bindtextdomain (domain, domaindir); + bindtextdomain (domain, domaindir); /* Write out the result. */ fputs (dngettext (domain, msgid, msgid_plural, n), stdout); @@ -205,7 +205,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { /* xgettext: no-wrap */ @@ -236,7 +236,7 @@ environment variable TEXTDOMAIN. If the message catalog is not found in the\n\ regular directory, another location can be specified with the environment\n\ variable TEXTDOMAINDIR.\n\ Standard search directory: %s\n"), - getenv ("IN_HELP2MAN") == NULL ? LOCALEDIR : "@localedir@"); + getenv ("IN_HELP2MAN") == NULL ? LOCALEDIR : "@localedir@"); printf ("\n"); /* TRANSLATORS: The placeholder indicates the bug-reporting address for this package. Please add _another line_ saying @@ -259,14 +259,14 @@ expand_escape (const char *str) for (;;) { while (cp[0] != '\0' && cp[0] != '\\') - ++cp; + ++cp; if (cp[0] == '\0') - return str; + return str; /* Found a backslash. */ if (cp[1] == '\0') - return str; + return str; if (strchr ("abcfnrtv\\01234567", cp[1]) != NULL) - break; + break; ++cp; } @@ -279,65 +279,65 @@ expand_escape (const char *str) { /* Here cp[0] == '\\'. */ switch (*++cp) - { - case 'a': /* alert */ - *rp++ = '\a'; - ++cp; - break; - case 'b': /* backspace */ - *rp++ = '\b'; - ++cp; - break; - case 'f': /* form feed */ - *rp++ = '\f'; - ++cp; - break; - case 'n': /* new line */ - *rp++ = '\n'; - ++cp; - break; - case 'r': /* carriage return */ - *rp++ = '\r'; - ++cp; - break; - case 't': /* horizontal tab */ - *rp++ = '\t'; - ++cp; - break; - case 'v': /* vertical tab */ - *rp++ = '\v'; - ++cp; - break; - case '\\': - *rp = '\\'; - ++cp; - break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - { - int ch = *cp++ - '0'; - - if (*cp >= '0' && *cp <= '7') - { - ch *= 8; - ch += *cp++ - '0'; - - if (*cp >= '0' && *cp <= '7') - { - ch *= 8; - ch += *cp++ - '0'; - } - } - *rp = ch; - } - break; - default: - *rp = '\\'; - break; - } + { + case 'a': /* alert */ + *rp++ = '\a'; + ++cp; + break; + case 'b': /* backspace */ + *rp++ = '\b'; + ++cp; + break; + case 'f': /* form feed */ + *rp++ = '\f'; + ++cp; + break; + case 'n': /* new line */ + *rp++ = '\n'; + ++cp; + break; + case 'r': /* carriage return */ + *rp++ = '\r'; + ++cp; + break; + case 't': /* horizontal tab */ + *rp++ = '\t'; + ++cp; + break; + case 'v': /* vertical tab */ + *rp++ = '\v'; + ++cp; + break; + case '\\': + *rp = '\\'; + ++cp; + break; + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + { + int ch = *cp++ - '0'; + + if (*cp >= '0' && *cp <= '7') + { + ch *= 8; + ch += *cp++ - '0'; + + if (*cp >= '0' && *cp <= '7') + { + ch *= 8; + ch += *cp++ - '0'; + } + } + *rp = ch; + } + break; + default: + *rp = '\\'; + break; + } while (cp[0] != '\0' && cp[0] != '\\') - *rp++ = *cp++; + *rp++ = *cp++; } while (cp[0] != '\0'); diff --git a/gettext-runtime/tests/ChangeLog b/gettext-runtime/tests/ChangeLog index fc8b01e0a..b87b324aa 100644 --- a/gettext-runtime/tests/ChangeLog +++ b/gettext-runtime/tests/ChangeLog @@ -1,3 +1,7 @@ +2009-12-12 Bruno Haible + + * test-lock.c: Untabify. + 2009-05-21 Bruno Haible * Makefile.am (AUTOMAKE_OPTIONS): Add 1.11 and color-tests. diff --git a/gettext-runtime/tests/test-lock.c b/gettext-runtime/tests/test-lock.c index e6895ecd8..2cbaf6126 100644 --- a/gettext-runtime/tests/test-lock.c +++ b/gettext-runtime/tests/test-lock.c @@ -537,10 +537,10 @@ once_contender_thread (void *arg) gl_lock_unlock (ready_lock[id]); if (repeat == REPEAT_COUNT) - break; + break; dbgprintf ("Contender %p waiting for signal for round %d\n", - gl_thread_self (), repeat); + gl_thread_self (), repeat); #if ENABLE_LOCKING /* Wait for the signal to go. */ gl_rwlock_rdlock (fire_signal[repeat]); @@ -549,10 +549,10 @@ once_contender_thread (void *arg) #else /* Wait for the signal to go. */ while (fire_signal_state <= repeat) - yield (); + yield (); #endif dbgprintf ("Contender %p got the signal for round %d\n", - gl_thread_self (), repeat); + gl_thread_self (), repeat); /* Contend for execution. */ gl_once (once_control, once_execute); @@ -593,30 +593,30 @@ test_once (void) /* Wait until every thread is ready. */ dbgprintf ("Main thread before synchonizing for round %d\n", repeat); for (;;) - { - int ready_count = 0; - for (i = 0; i < THREAD_COUNT; i++) - { - gl_lock_lock (ready_lock[i]); - ready_count += ready[i]; - gl_lock_unlock (ready_lock[i]); - } - if (ready_count == THREAD_COUNT) - break; - yield (); - } + { + int ready_count = 0; + for (i = 0; i < THREAD_COUNT; i++) + { + gl_lock_lock (ready_lock[i]); + ready_count += ready[i]; + gl_lock_unlock (ready_lock[i]); + } + if (ready_count == THREAD_COUNT) + break; + yield (); + } dbgprintf ("Main thread after synchonizing for round %d\n", repeat); if (repeat > 0) - { - /* Check that exactly one thread executed the once_execute() - function. */ - if (performed != 1) - abort (); - } + { + /* Check that exactly one thread executed the once_execute() + function. */ + if (performed != 1) + abort (); + } if (repeat == REPEAT_COUNT) - break; + break; /* Preparation for the next round: Initialize once_control. */ memcpy (&once_control, &fresh_once, sizeof (gl_once_t)); @@ -626,11 +626,11 @@ test_once (void) /* Preparation for the next round: Reset the ready flags. */ for (i = 0; i < THREAD_COUNT; i++) - { - gl_lock_lock (ready_lock[i]); - ready[i] = 0; - gl_lock_unlock (ready_lock[i]); - } + { + gl_lock_lock (ready_lock[i]); + ready[i] = 0; + gl_lock_unlock (ready_lock[i]); + } /* Signal all threads simultaneously. */ dbgprintf ("Main thread giving signal for round %d\n", repeat); diff --git a/gettext-tools/ChangeLog b/gettext-tools/ChangeLog index 2ac988c26..870920aa4 100644 --- a/gettext-tools/ChangeLog +++ b/gettext-tools/ChangeLog @@ -1,3 +1,7 @@ +2009-12-12 Bruno Haible + + * woe32dll/export.h: Untabify. + 2009-09-27 Bruno Haible * configure.ac: Accept --without-cvs, --with-git options. Substitute diff --git a/gettext-tools/libgettextpo/ChangeLog b/gettext-tools/libgettextpo/ChangeLog index f4c7de2ae..86fdf9b5b 100644 --- a/gettext-tools/libgettextpo/ChangeLog +++ b/gettext-tools/libgettextpo/ChangeLog @@ -1,3 +1,8 @@ +2009-12-12 Bruno Haible + + * gettext-po.h.in: Untabify. + * gettext-po.c: Untabify. + 2009-11-30 Guido Flohr * Makefile.am (MOSTLYCLEANDIRS): New variable. diff --git a/gettext-tools/libgettextpo/gettext-po.c b/gettext-tools/libgettextpo/gettext-po.c index 20347aa04..e574840b4 100644 --- a/gettext-tools/libgettextpo/gettext-po.c +++ b/gettext-tools/libgettextpo/gettext-po.c @@ -106,7 +106,7 @@ po_file_read (const char *filename, po_xerror_handler_t handler) { fp = fopen (filename, "r"); if (fp == NULL) - return NULL; + return NULL; } /* Establish error handler around read_catalog_stream(). */ @@ -122,7 +122,7 @@ po_file_read (const char *filename, po_xerror_handler_t handler) file->real_filename = filename; file->logical_filename = filename; file->mdlp = read_catalog_stream (fp, file->real_filename, - file->logical_filename, &input_format_po); + file->logical_filename, &input_format_po); file->domains = NULL; /* Restore error handler. */ @@ -154,7 +154,7 @@ po_file_read_v2 (const char *filename, po_error_handler_t handler) { fp = fopen (filename, "r"); if (fp == NULL) - return NULL; + return NULL; } /* Establish error handler around read_catalog_stream(). */ @@ -168,7 +168,7 @@ po_file_read_v2 (const char *filename, po_error_handler_t handler) file->real_filename = filename; file->logical_filename = filename; file->mdlp = read_catalog_stream (fp, file->real_filename, - file->logical_filename, &input_format_po); + file->logical_filename, &input_format_po); file->domains = NULL; /* Restore error handler. */ @@ -202,14 +202,14 @@ po_file_read (const char *filename) { fp = fopen (filename, "r"); if (fp == NULL) - return NULL; + return NULL; } file = XMALLOC (struct po_file); file->real_filename = filename; file->logical_filename = filename; file->mdlp = read_catalog_stream (fp, file->real_filename, - file->logical_filename, &input_format_po); + file->logical_filename, &input_format_po); file->domains = NULL; if (fp != stdin) @@ -291,7 +291,7 @@ po_file_domains (po_file_t file) size_t j; for (j = 0; j < n; j++) - domains[j] = file->mdlp->item[j]->domain; + domains[j] = file->mdlp->item[j]->domain; domains[n] = NULL; file->domains = domains; @@ -317,14 +317,14 @@ po_file_domain_header (po_file_t file, const char *domain) if (mlp != NULL) for (j = 0; j < mlp->nitems; j++) if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - return xstrdup (header); - else - return NULL; - } + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + return xstrdup (header); + else + return NULL; + } return NULL; } @@ -342,30 +342,30 @@ po_header_field (const char *header, const char *field) for (line = header;;) { if (strncmp (line, field, field_len) == 0 && line[field_len] == ':') - { - const char *value_start; - const char *value_end; - char *value; + { + const char *value_start; + const char *value_end; + char *value; - value_start = line + field_len + 1; - if (*value_start == ' ') - value_start++; - value_end = strchr (value_start, '\n'); - if (value_end == NULL) - value_end = value_start + strlen (value_start); + value_start = line + field_len + 1; + if (*value_start == ' ') + value_start++; + value_end = strchr (value_start, '\n'); + if (value_end == NULL) + value_end = value_start + strlen (value_start); - value = XNMALLOC (value_end - value_start + 1, char); - memcpy (value, value_start, value_end - value_start); - value[value_end - value_start] = '\0'; + value = XNMALLOC (value_end - value_start + 1, char); + memcpy (value, value_start, value_end - value_start); + value[value_end - value_start] = '\0'; - return value; - } + return value; + } line = strchr (line, '\n'); if (line != NULL) - line++; + line++; else - break; + break; } return NULL; @@ -388,43 +388,43 @@ po_header_set_field (const char *header, const char *field, const char *value) for (line = header;;) { - if (strncmp (line, field, field_len) == 0 && line[field_len] == ':') - { - const char *oldvalue_start; - const char *oldvalue_end; - size_t oldvalue_len; - size_t header_part1_len; - size_t header_part3_len; - size_t result_len; - char *result; - - oldvalue_start = line + field_len + 1; - if (*oldvalue_start == ' ') - oldvalue_start++; - oldvalue_end = strchr (oldvalue_start, '\n'); - if (oldvalue_end == NULL) - oldvalue_end = oldvalue_start + strlen (oldvalue_start); - oldvalue_len = oldvalue_end - oldvalue_start; - - header_part1_len = oldvalue_start - header; - header_part3_len = header + header_len - oldvalue_end; - result_len = header_part1_len + value_len + header_part3_len; - /* = header_len - oldvalue_len + value_len */ - result = XNMALLOC (result_len + 1, char); - memcpy (result, header, header_part1_len); - memcpy (result + header_part1_len, value, value_len); - memcpy (result + header_part1_len + value_len, oldvalue_end, - header_part3_len); - *(result + result_len) = '\0'; - - return result; - } - - line = strchr (line, '\n'); - if (line != NULL) - line++; - else - break; + if (strncmp (line, field, field_len) == 0 && line[field_len] == ':') + { + const char *oldvalue_start; + const char *oldvalue_end; + size_t oldvalue_len; + size_t header_part1_len; + size_t header_part3_len; + size_t result_len; + char *result; + + oldvalue_start = line + field_len + 1; + if (*oldvalue_start == ' ') + oldvalue_start++; + oldvalue_end = strchr (oldvalue_start, '\n'); + if (oldvalue_end == NULL) + oldvalue_end = oldvalue_start + strlen (oldvalue_start); + oldvalue_len = oldvalue_end - oldvalue_start; + + header_part1_len = oldvalue_start - header; + header_part3_len = header + header_len - oldvalue_end; + result_len = header_part1_len + value_len + header_part3_len; + /* = header_len - oldvalue_len + value_len */ + result = XNMALLOC (result_len + 1, char); + memcpy (result, header, header_part1_len); + memcpy (result + header_part1_len, value, value_len); + memcpy (result + header_part1_len + value_len, oldvalue_end, + header_part3_len); + *(result + result_len) = '\0'; + + return result; + } + + line = strchr (line, '\n'); + if (line != NULL) + line++; + else + break; } } { @@ -550,7 +550,7 @@ po_message_set_msgctxt (po_message_t message, const char *msgctxt) mp->msgctxt = (msgctxt != NULL ? xstrdup (msgctxt) : NULL); if (old_msgctxt != NULL) - free (old_msgctxt); + free (old_msgctxt); } } @@ -579,7 +579,7 @@ po_message_set_msgid (po_message_t message, const char *msgid) mp->msgid = xstrdup (msgid); if (old_msgid != NULL) - free (old_msgid); + free (old_msgid); } } @@ -610,7 +610,7 @@ po_message_set_msgid_plural (po_message_t message, const char *msgid_plural) mp->msgid_plural = (msgid_plural != NULL ? xstrdup (msgid_plural) : NULL); if (old_msgid_plural != NULL) - free (old_msgid_plural); + free (old_msgid_plural); } } @@ -642,7 +642,7 @@ po_message_set_msgstr (po_message_t message, const char *msgstr) mp->msgstr = xstrdup (msgstr); mp->msgstr_len = strlen (mp->msgstr) + 1; if (old_msgstr != NULL) - free (old_msgstr); + free (old_msgstr); } } @@ -661,12 +661,12 @@ po_message_msgstr_plural (po_message_t message, int index) const char *p_end = mp->msgstr + mp->msgstr_len; for (p = mp->msgstr; ; p += strlen (p) + 1, index--) - { - if (p >= p_end) - return NULL; - if (index == 0) - break; - } + { + if (p >= p_end) + return NULL; + if (index == 0) + break; + } return p; } else @@ -689,66 +689,66 @@ po_message_set_msgstr_plural (po_message_t message, int index, const char *msgst char *copied_msgstr; /* Special care must be taken of the case that msgstr points into the - mp->msgstr string list, because mp->msgstr may be relocated before we - are done with msgstr. */ + mp->msgstr string list, because mp->msgstr may be relocated before we + are done with msgstr. */ if (msgstr >= p && msgstr < p_end) - msgstr = copied_msgstr = xstrdup (msgstr); + msgstr = copied_msgstr = xstrdup (msgstr); else - copied_msgstr = NULL; + copied_msgstr = NULL; for (; ; p += strlen (p) + 1, index--) - { - if (p >= p_end) - { - /* Append at the end. */ - if (msgstr != NULL) - { - size_t new_msgstr_len = mp->msgstr_len + index + strlen (msgstr) + 1; - - mp->msgstr = - (char *) xrealloc ((char *) mp->msgstr, new_msgstr_len); - p = (char *) mp->msgstr + mp->msgstr_len; - for (; index > 0; index--) - *p++ = '\0'; - memcpy (p, msgstr, strlen (msgstr) + 1); - mp->msgstr_len = new_msgstr_len; - } - if (copied_msgstr != NULL) - free (copied_msgstr); - return; - } - if (index == 0) - break; - } + { + if (p >= p_end) + { + /* Append at the end. */ + if (msgstr != NULL) + { + size_t new_msgstr_len = mp->msgstr_len + index + strlen (msgstr) + 1; + + mp->msgstr = + (char *) xrealloc ((char *) mp->msgstr, new_msgstr_len); + p = (char *) mp->msgstr + mp->msgstr_len; + for (; index > 0; index--) + *p++ = '\0'; + memcpy (p, msgstr, strlen (msgstr) + 1); + mp->msgstr_len = new_msgstr_len; + } + if (copied_msgstr != NULL) + free (copied_msgstr); + return; + } + if (index == 0) + break; + } if (msgstr == NULL) - { - if (p + strlen (p) + 1 >= p_end) - { - /* Remove the string that starts at p. */ - mp->msgstr_len = p - mp->msgstr; - return; - } - /* It is not possible to remove an element of the string list - except the last one. So just replace it with the empty string. - That's the best we can do here. */ - msgstr = ""; - } + { + if (p + strlen (p) + 1 >= p_end) + { + /* Remove the string that starts at p. */ + mp->msgstr_len = p - mp->msgstr; + return; + } + /* It is not possible to remove an element of the string list + except the last one. So just replace it with the empty string. + That's the best we can do here. */ + msgstr = ""; + } { - /* Replace the string that starts at p. */ - size_t i1 = p - mp->msgstr; - size_t i2before = i1 + strlen (p); - size_t i2after = i1 + strlen (msgstr); - size_t new_msgstr_len = mp->msgstr_len - i2before + i2after; - - if (i2after > i2before) - mp->msgstr = (char *) xrealloc ((char *) mp->msgstr, new_msgstr_len); - memmove ((char *) mp->msgstr + i2after, mp->msgstr + i2before, - mp->msgstr_len - i2before); - memcpy ((char *) mp->msgstr + i1, msgstr, i2after - i1); - mp->msgstr_len = new_msgstr_len; + /* Replace the string that starts at p. */ + size_t i1 = p - mp->msgstr; + size_t i2before = i1 + strlen (p); + size_t i2after = i1 + strlen (msgstr); + size_t new_msgstr_len = mp->msgstr_len - i2before + i2after; + + if (i2after > i2before) + mp->msgstr = (char *) xrealloc ((char *) mp->msgstr, new_msgstr_len); + memmove ((char *) mp->msgstr + i2after, mp->msgstr + i2before, + mp->msgstr_len - i2before); + memcpy ((char *) mp->msgstr + i1, msgstr, i2after - i1); + mp->msgstr_len = new_msgstr_len; } if (copied_msgstr != NULL) - free (copied_msgstr); + free (copied_msgstr); } } @@ -784,19 +784,19 @@ po_message_set_comments (po_message_t message, const char *comments) rest = copy; while (*rest != '\0') { - char *newline = strchr (rest, '\n'); - - if (newline != NULL) - { - *newline = '\0'; - string_list_append (slp, rest); - rest = newline + 1; - } - else - { - string_list_append (slp, rest); - break; - } + char *newline = strchr (rest, '\n'); + + if (newline != NULL) + { + *newline = '\0'; + string_list_append (slp, rest); + rest = newline + 1; + } + else + { + string_list_append (slp, rest); + break; + } } free (copy); } @@ -839,19 +839,19 @@ po_message_set_extracted_comments (po_message_t message, const char *comments) rest = copy; while (*rest != '\0') { - char *newline = strchr (rest, '\n'); - - if (newline != NULL) - { - *newline = '\0'; - string_list_append (slp, rest); - rest = newline + 1; - } - else - { - string_list_append (slp, rest); - break; - } + char *newline = strchr (rest, '\n'); + + if (newline != NULL) + { + *newline = '\0'; + string_list_append (slp, rest); + rest = newline + 1; + } + else + { + string_list_append (slp, rest); + break; + } } free (copy); } @@ -893,12 +893,12 @@ po_message_remove_filepos (po_message_t message, int i) size_t n = mp->filepos_count; if (j < n) - { - mp->filepos_count = n = n - 1; - free ((char *) mp->filepos[j].file_name); - for (; j < n; j++) - mp->filepos[j] = mp->filepos[j + 1]; - } + { + mp->filepos_count = n = n - 1; + free ((char *) mp->filepos[j].file_name); + for (; j < n; j++) + mp->filepos[j] = mp->filepos[j + 1]; + } } } @@ -942,7 +942,7 @@ po_message_set_prev_msgctxt (po_message_t message, const char *prev_msgctxt) mp->prev_msgctxt = (prev_msgctxt != NULL ? xstrdup (prev_msgctxt) : NULL); if (old_prev_msgctxt != NULL) - free (old_prev_msgctxt); + free (old_prev_msgctxt); } } @@ -973,7 +973,7 @@ po_message_set_prev_msgid (po_message_t message, const char *prev_msgid) mp->prev_msgid = (prev_msgid != NULL ? xstrdup (prev_msgid) : NULL); if (old_prev_msgid != NULL) - free (old_prev_msgid); + free (old_prev_msgid); } } @@ -1003,9 +1003,9 @@ po_message_set_prev_msgid_plural (po_message_t message, const char *prev_msgid_p char *old_prev_msgid_plural = (char *) mp->prev_msgid_plural; mp->prev_msgid_plural = - (prev_msgid_plural != NULL ? xstrdup (prev_msgid_plural) : NULL); + (prev_msgid_plural != NULL ? xstrdup (prev_msgid_plural) : NULL); if (old_prev_msgid_plural != NULL) - free (old_prev_msgid_plural); + free (old_prev_msgid_plural); } } @@ -1067,9 +1067,9 @@ po_message_is_format (po_message_t message, const char *format_type) if (len >= 7 && memcmp (format_type + len - 7, "-format", 7) == 0) for (i = 0; i < NFORMATS; i++) if (strlen (format_language[i]) == len - 7 - && memcmp (format_language[i], format_type, len - 7) == 0) - /* The given format_type corresponds to (enum format_type) i. */ - return (possible_format_p (mp->is_format[i]) ? 1 : 0); + && memcmp (format_language[i], format_type, len - 7) == 0) + /* The given format_type corresponds to (enum format_type) i. */ + return (possible_format_p (mp->is_format[i]) ? 1 : 0); return 0; } @@ -1086,9 +1086,9 @@ po_message_set_format (po_message_t message, const char *format_type, /*bool*/in if (len >= 7 && memcmp (format_type + len - 7, "-format", 7) == 0) for (i = 0; i < NFORMATS; i++) if (strlen (format_language[i]) == len - 7 - && memcmp (format_language[i], format_type, len - 7) == 0) - /* The given format_type corresponds to (enum format_type) i. */ - mp->is_format[i] = (value ? yes : no); + && memcmp (format_language[i], format_type, len - 7) == 0) + /* The given format_type corresponds to (enum format_type) i. */ + mp->is_format[i] = (value ? yes : no); } @@ -1168,7 +1168,7 @@ po_format_list (void) const char **list = XNMALLOC (NFORMATS + 1, const char *); size_t i; for (i = 0; i < NFORMATS; i++) - list[i] = xasprintf ("%s-format", format_language[i]); + list[i] = xasprintf ("%s-format", format_language[i]); list[i] = NULL; whole_list = list; } @@ -1189,9 +1189,9 @@ po_format_pretty_name (const char *format_type) if (len >= 7 && memcmp (format_type + len - 7, "-format", 7) == 0) for (i = 0; i < NFORMATS; i++) if (strlen (format_language[i]) == len - 7 - && memcmp (format_language[i], format_type, len - 7) == 0) - /* The given format_type corresponds to (enum format_type) i. */ - return format_language_pretty[i]; + && memcmp (format_language[i], format_type, len - 7) == 0) + /* The given format_type corresponds to (enum format_type) i. */ + return format_language_pretty[i]; return NULL; } @@ -1229,7 +1229,7 @@ po_file_check_all (po_file_t file, po_xerror_handler_t handler) void po_message_check_all (po_message_t message, po_message_iterator_t iterator, - po_xerror_handler_t handler) + po_xerror_handler_t handler) { message_ty *mp = (message_ty *) message; @@ -1253,14 +1253,14 @@ po_message_check_all (po_message_t message, po_message_iterator_t iterator, header = NULL; mlp = - msgdomain_list_sublist (iterator->file->mdlp, iterator->domain, false); + msgdomain_list_sublist (iterator->file->mdlp, iterator->domain, false); if (mlp != NULL) - for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - header = mlp->item[j]; - break; - } + for (j = 0; j < mlp->nitems; j++) + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + header = mlp->item[j]; + break; + } } { @@ -1272,9 +1272,9 @@ po_message_check_all (po_message_t message, po_message_iterator_t iterator, ml.use_hashtable = false; if (header != NULL) - message_list_append (&ml, header); + message_list_append (&ml, header); if (mp != header) - message_list_append (&ml, mp); + message_list_append (&ml, mp); check_message_list (&ml, 1, 1, 1, 0, 0, 0); } @@ -1346,8 +1346,8 @@ po_message_check_format (po_message_t message, po_error_handler_t handler) po_error = handler->error; check_msgid_msgstr_format (mp->msgid, mp->msgid_plural, - mp->msgstr, mp->msgstr_len, - mp->is_format, mp->range, NULL, po_error_logger); + mp->msgstr, mp->msgstr_len, + mp->is_format, mp->range, NULL, po_error_logger); /* Restore error handler. */ po_error = error; diff --git a/gettext-tools/libgettextpo/gettext-po.h.in b/gettext-tools/libgettextpo/gettext-po.h.in index 800053823..fc09ee671 100644 --- a/gettext-tools/libgettextpo/gettext-po.h.in +++ b/gettext-tools/libgettextpo/gettext-po.h.in @@ -54,7 +54,7 @@ struct po_error_handler Must increment the error_message_count variable declared in error.h. Must not return if STATUS is nonzero. */ void (*error) (int status, int errnum, - const char *format, ...) + const char *format, ...) #if ((__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3) && !__STRICT_ANSI__ __attribute__ ((__format__ (__printf__, 3, 4))) #endif @@ -66,8 +66,8 @@ struct po_error_handler Must increment the error_message_count variable declared in error.h. Must not return if STATUS is nonzero. */ void (*error_at_line) (int status, int errnum, - const char *filename, unsigned int lineno, - const char *format, ...) + const char *filename, unsigned int lineno, + const char *format, ...) #if ((__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3) && !__STRICT_ANSI__ __attribute__ ((__format__ (__printf__, 5, 6))) #endif @@ -86,9 +86,9 @@ struct po_error_handler typedef const struct po_error_handler *po_error_handler_t; /* A po_xerror_handler handles warnings, error and fatal error situations. */ -#define PO_SEVERITY_WARNING 0 /* just a warning, tell the user */ -#define PO_SEVERITY_ERROR 1 /* an error, the operation cannot complete */ -#define PO_SEVERITY_FATAL_ERROR 2 /* an error, the operation must be aborted */ +#define PO_SEVERITY_WARNING 0 /* just a warning, tell the user */ +#define PO_SEVERITY_ERROR 1 /* an error, the operation cannot complete */ +#define PO_SEVERITY_FATAL_ERROR 2 /* an error, the operation must be aborted */ struct po_xerror_handler { /* Signal a problem of the given severity. @@ -101,20 +101,20 @@ struct po_xerror_handler usually a single line). Must not return if SEVERITY is PO_SEVERITY_FATAL_ERROR. */ void (*xerror) (int severity, - po_message_t message, - const char *filename, size_t lineno, size_t column, - int multiline_p, const char *message_text); + po_message_t message, + const char *filename, size_t lineno, size_t column, + int multiline_p, const char *message_text); /* Signal a problem that refers to two messages. Similar to two calls to xerror. If possible, a "..." can be appended to MESSAGE_TEXT1 and prepended to MESSAGE_TEXT2. */ void (*xerror2) (int severity, - po_message_t message1, - const char *filename1, size_t lineno1, size_t column1, - int multiline_p1, const char *message_text1, - po_message_t message2, - const char *filename2, size_t lineno2, size_t column2, - int multiline_p2, const char *message_text2); + po_message_t message1, + const char *filename1, size_t lineno1, size_t column1, + int multiline_p1, const char *message_text1, + po_message_t message2, + const char *filename2, size_t lineno2, size_t column2, + int multiline_p2, const char *message_text2); }; typedef const struct po_xerror_handler *po_xerror_handler_t; @@ -134,13 +134,13 @@ extern po_file_t po_file_create (void); Return its contents. Upon failure, return NULL and set errno. */ #define po_file_read po_file_read_v3 extern po_file_t po_file_read (const char *filename, - po_xerror_handler_t handler); + po_xerror_handler_t handler); /* Write an in-memory PO file to a file. Upon failure, return NULL and set errno. */ #define po_file_write po_file_write_v2 extern po_file_t po_file_write (po_file_t file, const char *filename, - po_xerror_handler_t handler); + po_xerror_handler_t handler); /* Free a PO file from memory. */ extern void po_file_free (po_file_t file); diff --git a/gettext-tools/libgrep/ChangeLog b/gettext-tools/libgrep/ChangeLog index 897d75f45..69212251d 100644 --- a/gettext-tools/libgrep/ChangeLog +++ b/gettext-tools/libgrep/ChangeLog @@ -1,3 +1,9 @@ +2009-12-12 Bruno Haible + + * libgrep.h: Untabify. + * hard-locale.c: Untabify. + * memchr.c: Untabify. + 2009-08-15 Bruno Haible Stop using gnulib module 'strdup'. diff --git a/gettext-tools/libgrep/hard-locale.c b/gettext-tools/libgrep/hard-locale.c index bc33b4d51..04271acb5 100644 --- a/gettext-tools/libgrep/hard-locale.c +++ b/gettext-tools/libgrep/hard-locale.c @@ -42,29 +42,29 @@ hard_locale (int category) if (p) { if (2 <= GLIBC_VERSION) - { - if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) - hard = false; - } + { + if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) + hard = false; + } else - { - char *locale = strdup (p); - if (locale) - { - /* Temporarily set the locale to the "C" and "POSIX" locales - to find their names, so that we can determine whether one - or the other is the caller's locale. */ - if (((p = setlocale (category, "C")) - && strcmp (p, locale) == 0) - || ((p = setlocale (category, "POSIX")) - && strcmp (p, locale) == 0)) - hard = false; + { + char *locale = strdup (p); + if (locale) + { + /* Temporarily set the locale to the "C" and "POSIX" locales + to find their names, so that we can determine whether one + or the other is the caller's locale. */ + if (((p = setlocale (category, "C")) + && strcmp (p, locale) == 0) + || ((p = setlocale (category, "POSIX")) + && strcmp (p, locale) == 0)) + hard = false; - /* Restore the caller's locale. */ - setlocale (category, locale); - free (locale); - } - } + /* Restore the caller's locale. */ + setlocale (category, locale); + free (locale); + } + } } return hard; diff --git a/gettext-tools/libgrep/libgrep.h b/gettext-tools/libgrep/libgrep.h index 542f36e39..162910b22 100644 --- a/gettext-tools/libgrep/libgrep.h +++ b/gettext-tools/libgrep/libgrep.h @@ -31,13 +31,13 @@ typedef struct { /* Compile a pattern and return the compiled pattern. */ void * (*compile) (const char *pattern, size_t pattern_size, - bool match_icase, bool match_words, bool match_lines, - char eolbyte); + bool match_icase, bool match_words, bool match_lines, + char eolbyte); /* Execute a search. */ size_t (*execute) (const void *compiled_pattern, - const char *buf, size_t buf_size, - size_t *match_size, bool exact); + const char *buf, size_t buf_size, + size_t *match_size, bool exact); /* Free a compiled pattern. */ void (*free) (void *compiled_pattern); diff --git a/gettext-tools/libgrep/memchr.c b/gettext-tools/libgrep/memchr.c index 2253d2d65..a23ff788d 100644 --- a/gettext-tools/libgrep/memchr.c +++ b/gettext-tools/libgrep/memchr.c @@ -97,15 +97,15 @@ __memchr (void const *s, int c_in, size_t n) repeated_one |= repeated_one << 31 << 1; repeated_c |= repeated_c << 31 << 1; if (8 < sizeof (longword)) - { - size_t i; - - for (i = 64; i < sizeof (longword) * 8; i *= 2) - { - repeated_one |= repeated_one << i; - repeated_c |= repeated_c << i; - } - } + { + size_t i; + + for (i = 64; i < sizeof (longword) * 8; i *= 2) + { + repeated_one |= repeated_one << i; + repeated_c |= repeated_c << i; + } + } } /* Instead of the traditional loop which tests each byte, we will test a @@ -144,8 +144,8 @@ __memchr (void const *s, int c_in, size_t n) longword longword1 = *longword_ptr ^ repeated_c; if ((((longword1 - repeated_one) & ~longword1) - & (repeated_one << 7)) != 0) - break; + & (repeated_one << 7)) != 0) + break; longword_ptr++; n -= sizeof (longword); } @@ -162,7 +162,7 @@ __memchr (void const *s, int c_in, size_t n) for (; n > 0; --n, ++char_ptr) { if (*char_ptr == c) - return (void *) char_ptr; + return (void *) char_ptr; } return NULL; diff --git a/gettext-tools/m4/ChangeLog b/gettext-tools/m4/ChangeLog index 0923c53cc..c26ee3f76 100644 --- a/gettext-tools/m4/ChangeLog +++ b/gettext-tools/m4/ChangeLog @@ -1,3 +1,7 @@ +2009-12-12 Bruno Haible + + * regex.m4: Untabify. + 2009-10-18 Bruno Haible * Makefile.am (aclocal_DATA): Add fcntl_h.m4. diff --git a/gettext-tools/m4/regex.m4 b/gettext-tools/m4/regex.m4 index 513f59bc4..7c2a68a64 100644 --- a/gettext-tools/m4/regex.m4 +++ b/gettext-tools/m4/regex.m4 @@ -31,60 +31,60 @@ AC_DEFUN([gl_INCLUDED_REGEX], # regex.c. The first failing regular expression is from `Spencer ere # test #75' in grep-2.3. AC_CACHE_CHECK([for working re_compile_pattern], - jm_cv_func_working_re_compile_pattern, + jm_cv_func_working_re_compile_pattern, [AC_TRY_RUN( [#include #include #include #include - int - main () - { - static struct re_pattern_buffer regex; - const char *s; - struct re_registers regs; - re_set_syntax (RE_SYNTAX_POSIX_EGREP); - memset (®ex, 0, sizeof (regex)); - [s = re_compile_pattern ("a[[:@:>@:]]b\n", 9, ®ex);] - /* This should fail with _Invalid character class name_ error. */ - if (!s) - exit (1); - - /* This should succeed, but doesn't for e.g. glibc-2.1.3. */ - memset (®ex, 0, sizeof (regex)); - s = re_compile_pattern ("{1", 2, ®ex); - - if (s) - exit (1); - - /* The following example is derived from a problem report + int + main () + { + static struct re_pattern_buffer regex; + const char *s; + struct re_registers regs; + re_set_syntax (RE_SYNTAX_POSIX_EGREP); + memset (®ex, 0, sizeof (regex)); + [s = re_compile_pattern ("a[[:@:>@:]]b\n", 9, ®ex);] + /* This should fail with _Invalid character class name_ error. */ + if (!s) + exit (1); + + /* This should succeed, but doesn't for e.g. glibc-2.1.3. */ + memset (®ex, 0, sizeof (regex)); + s = re_compile_pattern ("{1", 2, ®ex); + + if (s) + exit (1); + + /* The following example is derived from a problem report against gawk from Jorge Stolfi . */ - memset (®ex, 0, sizeof (regex)); - s = re_compile_pattern ("[[an\371]]*n", 7, ®ex); - if (s) - exit (1); - - /* This should match, but doesn't for e.g. glibc-2.2.1. */ - if (re_match (®ex, "an", 2, 0, ®s) != 2) - exit (1); - - memset (®ex, 0, sizeof (regex)); - s = re_compile_pattern ("x", 1, ®ex); - if (s) - exit (1); - - /* The version of regex.c in e.g. GNU libc-2.2.93 didn't - work with a negative RANGE argument. */ - if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1) - exit (1); - - exit (0); - } - ], - jm_cv_func_working_re_compile_pattern=yes, - jm_cv_func_working_re_compile_pattern=no, - dnl When crosscompiling, assume it's broken. - jm_cv_func_working_re_compile_pattern=no)]) + memset (®ex, 0, sizeof (regex)); + s = re_compile_pattern ("[[an\371]]*n", 7, ®ex); + if (s) + exit (1); + + /* This should match, but doesn't for e.g. glibc-2.2.1. */ + if (re_match (®ex, "an", 2, 0, ®s) != 2) + exit (1); + + memset (®ex, 0, sizeof (regex)); + s = re_compile_pattern ("x", 1, ®ex); + if (s) + exit (1); + + /* The version of regex.c in e.g. GNU libc-2.2.93 didn't + work with a negative RANGE argument. */ + if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1) + exit (1); + + exit (0); + } + ], + jm_cv_func_working_re_compile_pattern=yes, + jm_cv_func_working_re_compile_pattern=no, + dnl When crosscompiling, assume it's broken. + jm_cv_func_working_re_compile_pattern=no)]) if test $jm_cv_func_working_re_compile_pattern = yes; then ac_use_included_regex=no fi @@ -93,16 +93,16 @@ AC_DEFUN([gl_INCLUDED_REGEX], m4_syscmd([test -f $1]) ifelse(m4_sysval, 0, [ - AC_ARG_WITH(included-regex, - [ --without-included-regex don't compile regex; this is the default on + AC_ARG_WITH(included-regex, + [ --without-included-regex don't compile regex; this is the default on systems with version 2 of the GNU C library (use with caution on other system)], - jm_with_regex=$withval, - jm_with_regex=$ac_use_included_regex) - if test "$jm_with_regex" = yes; then - AC_LIBOBJ(regex) - gl_PREREQ_REGEX - fi + jm_with_regex=$withval, + jm_with_regex=$ac_use_included_regex) + if test "$jm_with_regex" = yes; then + AC_LIBOBJ(regex) + gl_PREREQ_REGEX + fi ], ) ] diff --git a/gettext-tools/misc/ChangeLog b/gettext-tools/misc/ChangeLog index 5f0aa94a8..e93ed3ead 100644 --- a/gettext-tools/misc/ChangeLog +++ b/gettext-tools/misc/ChangeLog @@ -1,3 +1,8 @@ +2009-12-12 Bruno Haible + + * po-compat.el: Untabify. + * gettextize.in: Partially untabify. + 2009-10-18 Bruno Haible * gettextize.in (m4filelist): Add fcntl_h.m4 to the list. diff --git a/gettext-tools/misc/gettextize.in b/gettext-tools/misc/gettextize.in index 8c30f74a4..43d41bae6 100644 --- a/gettext-tools/misc/gettextize.in +++ b/gettext-tools/misc/gettextize.in @@ -247,7 +247,7 @@ func_fatal_error () --version | --versio | --versi | --vers | --ver | --ve | --v ) func_version exit 0 ;; - -- ) # Stop option prcessing + -- ) # Stop option prcessing shift; break ;; -* ) echo "gettextize: unknown option $1" 1>&2 diff --git a/gettext-tools/misc/po-compat.el b/gettext-tools/misc/po-compat.el index ae7ff85c1..02feafdbc 100644 --- a/gettext-tools/misc/po-compat.el +++ b/gettext-tools/misc/po-compat.el @@ -44,10 +44,10 @@ ;; - GNU Emacs (version 19) -> no flag. (eval-and-compile (cond ((string-match "XEmacs\\|Lucid" emacs-version) - (setq po-EMACS20 nil po-XEMACS t)) - ((and (string-lessp "19" emacs-version) (featurep 'faces)) - (setq po-EMACS20 t po-XEMACS nil)) - (t (setq po-EMACS20 nil po-XEMACS nil)))) + (setq po-EMACS20 nil po-XEMACS t)) + ((and (string-lessp "19" emacs-version) (featurep 'faces)) + (setq po-EMACS20 t po-XEMACS nil)) + (t (setq po-EMACS20 nil po-XEMACS nil)))) ;; Handle missing 'with-temp-buffer' function. (eval-and-compile @@ -57,17 +57,17 @@ (defmacro po-with-temp-buffer (&rest forms) "Create a temporary buffer, and evaluate FORMS there like 'progn'." (let ((curr-buffer (make-symbol "curr-buffer")) - (temp-buffer (make-symbol "temp-buffer"))) - `(let ((,curr-buffer (current-buffer)) - (,temp-buffer (get-buffer-create - (generate-new-buffer-name " *po-temp*")))) - (unwind-protect - (progn - (set-buffer ,temp-buffer) - ,@forms) - (set-buffer ,curr-buffer) - (and (buffer-name ,temp-buffer) - (kill-buffer ,temp-buffer)))))))) + (temp-buffer (make-symbol "temp-buffer"))) + `(let ((,curr-buffer (current-buffer)) + (,temp-buffer (get-buffer-create + (generate-new-buffer-name " *po-temp*")))) + (unwind-protect + (progn + (set-buffer ,temp-buffer) + ,@forms) + (set-buffer ,curr-buffer) + (and (buffer-name ,temp-buffer) + (kill-buffer ,temp-buffer)))))))) (defconst po-content-type-charset-alist '(; Note: Emacs 21 doesn't support all encodings, thus the missing entries. @@ -154,8 +154,8 @@ Content-Type into a Mule coding system.") "Return PO file charset value." (interactive) (let ((charset-regexp - "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"") - (short-read nil)) + "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"") + (short-read nil)) ;; Try the first 4096 bytes. In case we cannot find the charset value ;; within the first 4096 bytes (the PO file might start with a long ;; comment) try the next 4096 bytes repeatedly until we'll know for sure @@ -163,64 +163,64 @@ Content-Type into a Mule coding system.") (while (not (or short-read (re-search-forward "^msgid" nil t))) (save-excursion (goto-char (point-max)) - (let ((pair (insert-file-contents-literally filename nil - (1- (point)) - (1- (+ (point) 4096))))) - (setq short-read (< (nth 1 pair) 4096))))) + (let ((pair (insert-file-contents-literally filename nil + (1- (point)) + (1- (+ (point) 4096))))) + (setq short-read (< (nth 1 pair) 4096))))) (cond ((re-search-forward charset-regexp nil t) (match-string 1)) - (short-read nil) - ;; We've found the first msgid; maybe, only a part of the msgstr - ;; value was loaded. Load the next 1024 bytes; if charset still - ;; isn't available, give up. - (t (save-excursion - (goto-char (point-max)) - (insert-file-contents-literally filename nil - (1- (point)) - (1- (+ (point) 1024)))) - (if (re-search-forward charset-regexp nil t) - (match-string 1)))))) + (short-read nil) + ;; We've found the first msgid; maybe, only a part of the msgstr + ;; value was loaded. Load the next 1024 bytes; if charset still + ;; isn't available, give up. + (t (save-excursion + (goto-char (point-max)) + (insert-file-contents-literally filename nil + (1- (point)) + (1- (+ (point) 1024)))) + (if (re-search-forward charset-regexp nil t) + (match-string 1)))))) (eval-and-compile (if po-EMACS20 (defun po-find-file-coding-system-guts (operation filename) - "\ + "\ Return a Mule (DECODING . ENCODING) pair, according to PO file charset. Called through file-coding-system-alist, before the file is visited for real." - (and (eq operation 'insert-file-contents) - (file-exists-p filename) - (po-with-temp-buffer - (let* ((coding-system-for-read 'no-conversion) - (charset (or (po-find-charset filename) "ascii")) - (charset-upper (upcase charset)) - (charset-lower (downcase charset)) - (candidate - (cdr (assoc charset-upper po-content-type-charset-alist))) - (try-symbol (or candidate (intern-soft charset-lower))) - (try-string - (if try-symbol (symbol-name try-symbol) charset-lower))) - (list (cond ((and try-symbol (coding-system-p try-symbol)) - try-symbol) - ((and po-EMACS20 - (string-match "\\`cp[1-9][0-9][0-9]?\\'" - try-string) - (assoc (substring try-string 2) - (cp-supported-codepages))) - (codepage-setup (substring try-string 2)) - (intern try-string)) - (t - 'no-conversion)))))))) + (and (eq operation 'insert-file-contents) + (file-exists-p filename) + (po-with-temp-buffer + (let* ((coding-system-for-read 'no-conversion) + (charset (or (po-find-charset filename) "ascii")) + (charset-upper (upcase charset)) + (charset-lower (downcase charset)) + (candidate + (cdr (assoc charset-upper po-content-type-charset-alist))) + (try-symbol (or candidate (intern-soft charset-lower))) + (try-string + (if try-symbol (symbol-name try-symbol) charset-lower))) + (list (cond ((and try-symbol (coding-system-p try-symbol)) + try-symbol) + ((and po-EMACS20 + (string-match "\\`cp[1-9][0-9][0-9]?\\'" + try-string) + (assoc (substring try-string 2) + (cp-supported-codepages))) + (codepage-setup (substring try-string 2)) + (intern try-string)) + (t + 'no-conversion)))))))) (if po-XEMACS (defun po-find-file-coding-system-guts (operation filename) - "\ + "\ Return a Mule (DECODING . ENCODING) pair, according to PO file charset. Called through file-coding-system-alist, before the file is visited for real." - (and (eq operation 'insert-file-contents) - (file-exists-p filename) - (po-with-temp-buffer - (let ((coding-system-for-read 'no-conversion)) + (and (eq operation 'insert-file-contents) + (file-exists-p filename) + (po-with-temp-buffer + (let ((coding-system-for-read 'no-conversion)) (let* ((charset (or (po-find-charset filename) - "ascii")) + "ascii")) (charset-upper (upcase charset)) (charset-lower (intern (downcase charset)))) (list (or (cdr (assoc charset-upper @@ -231,17 +231,17 @@ Called through file-coding-system-alist, before the file is visited for real." (if po-EMACS20 (defun po-find-file-coding-system (arg-list) - "\ + "\ Return a Mule (DECODING . ENCODING) pair, according to PO file charset. Called through file-coding-system-alist, before the file is visited for real." - (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list))))) + (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list))))) (if po-XEMACS (defun po-find-file-coding-system (operation filename) - "\ + "\ Return a Mule (DECODING . ENCODING) pair, according to PO file charset. Called through file-coding-system-alist, before the file is visited for real." - (po-find-file-coding-system-guts operation filename))) + (po-find-file-coding-system-guts operation filename))) ) diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 678a86157..a260a9300 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,7 @@ +2009-12-12 Bruno Haible + + * *.h, *.c, *.y: Untabify. + 2009-11-28 Bruno Haible * x-perl.c (extract_variable): Fix tp->type when returning at EOF. diff --git a/gettext-tools/src/color.c b/gettext-tools/src/color.c index 7b52ea7e5..47daf0010 100644 --- a/gettext-tools/src/color.c +++ b/gettext-tools/src/color.c @@ -51,20 +51,20 @@ handle_color_option (const char *option) if (option != NULL) { if (strcmp (option, "never") == 0 || strcmp (option, "no") == 0) - color_mode = color_no; + color_mode = color_no; else if (strcmp (option, "auto") == 0 || strcmp (option, "tty") == 0) - color_mode = color_tty; + color_mode = color_tty; else if (strcmp (option, "always") == 0 || strcmp (option, "yes") == 0) - color_mode = color_yes; + color_mode = color_yes; else if (strcmp (option, "html") == 0) - color_mode = color_html; + color_mode = color_html; else if (strcmp (option, "test") == 0) - color_test_mode = true; + color_test_mode = true; else - { - fprintf (stderr, "invalid --color argument: %s\n", option); - return true; - } + { + fprintf (stderr, "invalid --color argument: %s\n", option); + return true; + } } else /* --color is equivalent to --color=yes. */ @@ -122,23 +122,23 @@ print_color_test () ostream_write_str (stream, name); ostream_write_mem (stream, " ", 7 - strlen (name)); for (col = 0; col <= 8; col++) - { - term_color_t row_color = colors[row].c; - term_color_t col_color = colors[col].c; - - ostream_write_str (stream, "|"); - term_ostream_set_color (stream, row_color); - term_ostream_set_bgcolor (stream, col_color); - if (!(term_ostream_get_color (stream) == row_color - && term_ostream_get_bgcolor (stream) == col_color)) - abort (); - ostream_write_str (stream, " Words "); - term_ostream_set_color (stream, COLOR_DEFAULT); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - if (!(term_ostream_get_color (stream) == COLOR_DEFAULT - && term_ostream_get_bgcolor (stream) == COLOR_DEFAULT)) - abort (); - } + { + term_color_t row_color = colors[row].c; + term_color_t col_color = colors[col].c; + + ostream_write_str (stream, "|"); + term_ostream_set_color (stream, row_color); + term_ostream_set_bgcolor (stream, col_color); + if (!(term_ostream_get_color (stream) == row_color + && term_ostream_get_bgcolor (stream) == col_color)) + abort (); + ostream_write_str (stream, " Words "); + term_ostream_set_color (stream, COLOR_DEFAULT); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + if (!(term_ostream_get_color (stream) == COLOR_DEFAULT + && term_ostream_get_bgcolor (stream) == COLOR_DEFAULT)) + abort (); + } ostream_write_str (stream, "\n"); } ostream_write_str (stream, "\n"); @@ -149,15 +149,15 @@ print_color_test () { ostream_write_str (stream, row == 0 ? "red: " : " "); for (col = 0; col <= 64; col++) - { - int r = 255; - int b = (int) (255.0f / 64.0f * col + 0.5f); - int g = b + (int) (row / 17.0f * (r - b) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int r = 255; + int b = (int) (255.0f / 64.0f * col + 0.5f); + int g = b + (int) (row / 17.0f * (r - b) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } /* Hue from 1 to 2. */ @@ -165,15 +165,15 @@ print_color_test () { ostream_write_str (stream, row == 17 ? "yellow: " : " "); for (col = 0; col <= 64; col++) - { - int g = 255; - int b = (int) (255.0f / 64.0f * col + 0.5f); - int r = b + (int) (row / 17.0f * (g - b) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int g = 255; + int b = (int) (255.0f / 64.0f * col + 0.5f); + int r = b + (int) (row / 17.0f * (g - b) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } /* Hue from 2 to 3. */ @@ -181,15 +181,15 @@ print_color_test () { ostream_write_str (stream, row == 0 ? "green: " : " "); for (col = 0; col <= 64; col++) - { - int g = 255; - int r = (int) (255.0f / 64.0f * col + 0.5f); - int b = r + (int) (row / 17.0f * (g - r) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int g = 255; + int r = (int) (255.0f / 64.0f * col + 0.5f); + int b = r + (int) (row / 17.0f * (g - r) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } /* Hue from 3 to 4. */ @@ -197,15 +197,15 @@ print_color_test () { ostream_write_str (stream, row == 17 ? "cyan: " : " "); for (col = 0; col <= 64; col++) - { - int b = 255; - int r = (int) (255.0f / 64.0f * col + 0.5f); - int g = r + (int) (row / 17.0f * (b - r) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int b = 255; + int r = (int) (255.0f / 64.0f * col + 0.5f); + int g = r + (int) (row / 17.0f * (b - r) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } /* Hue from 4 to 5. */ @@ -213,32 +213,32 @@ print_color_test () { ostream_write_str (stream, row == 0 ? "blue: " : " "); for (col = 0; col <= 64; col++) - { - int b = 255; - int g = (int) (255.0f / 64.0f * col + 0.5f); - int r = g + (int) (row / 17.0f * (b - g) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int b = 255; + int g = (int) (255.0f / 64.0f * col + 0.5f); + int r = g + (int) (row / 17.0f * (b - g) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } /* Hue from 5 to 6. */ for (row = 17; row >= 0; row--) { ostream_write_str (stream, row == 17 ? "magenta: " : - row == 0 ? "red: " : " "); + row == 0 ? "red: " : " "); for (col = 0; col <= 64; col++) - { - int r = 255; - int g = (int) (255.0f / 64.0f * col + 0.5f); - int b = g + (int) (row / 17.0f * (r - g) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int r = 255; + int g = (int) (255.0f / 64.0f * col + 0.5f); + int b = g + (int) (row / 17.0f * (r - g) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } ostream_write_str (stream, "\n"); @@ -392,23 +392,23 @@ style_file_lookup (const char *file_name) if (!IS_PATH_WITH_DIR (file_name)) { /* It's a file name without a directory specification. - If it does not exist in the current directory... */ + If it does not exist in the current directory... */ struct stat statbuf; if (stat (file_name, &statbuf) < 0) - { - /* ... but it exists in the styles installation location... */ - const char *gettextstylesdir = relocate (GETTEXTDATADIR "/styles"); - char *possible_file_name = - xconcatenated_filename (gettextstylesdir, file_name, NULL); - - if (stat (possible_file_name, &statbuf) >= 0) - { - /* ... then use the file in the styles installation directory. */ - return possible_file_name; - } - free (possible_file_name); - } + { + /* ... but it exists in the styles installation location... */ + const char *gettextstylesdir = relocate (GETTEXTDATADIR "/styles"); + char *possible_file_name = + xconcatenated_filename (gettextstylesdir, file_name, NULL); + + if (stat (possible_file_name, &statbuf) >= 0) + { + /* ... then use the file in the styles installation directory. */ + return possible_file_name; + } + free (possible_file_name); + } /* Let the CSS library show a warning. */ } @@ -424,21 +424,21 @@ style_file_prepare () const char *user_preference = getenv ("PO_STYLE"); if (user_preference != NULL && user_preference[0] != '\0') - style_file_name = style_file_lookup (xstrdup (user_preference)); + style_file_name = style_file_lookup (xstrdup (user_preference)); else - { - const char *gettextdatadir; - - /* Make it possible to override the po-default.css location. This is - necessary for running the testsuite before "make install". */ - gettextdatadir = getenv ("GETTEXTDATADIR"); - if (gettextdatadir == NULL || gettextdatadir[0] == '\0') - gettextdatadir = relocate (GETTEXTDATADIR); - - style_file_name = - xconcatenated_filename (gettextdatadir, "styles/po-default.css", - NULL); - } + { + const char *gettextdatadir; + + /* Make it possible to override the po-default.css location. This is + necessary for running the testsuite before "make install". */ + gettextdatadir = getenv ("GETTEXTDATADIR"); + if (gettextdatadir == NULL || gettextdatadir[0] == '\0') + gettextdatadir = relocate (GETTEXTDATADIR); + + style_file_name = + xconcatenated_filename (gettextdatadir, "styles/po-default.css", + NULL); + } } else style_file_name = style_file_lookup (style_file_name); diff --git a/gettext-tools/src/dir-list.c b/gettext-tools/src/dir-list.c index e69a64fa0..ee46d0503 100644 --- a/gettext-tools/src/dir-list.c +++ b/gettext-tools/src/dir-list.c @@ -77,7 +77,7 @@ dir_list_restore (void *saved_value) if (directory != NULL) { if (directory->item != NULL) - free (directory->item); + free (directory->item); free (directory); } diff --git a/gettext-tools/src/file-list.c b/gettext-tools/src/file-list.c index 8096217d9..2ee983d0b 100644 --- a/gettext-tools/src/file-list.c +++ b/gettext-tools/src/file-list.c @@ -49,8 +49,8 @@ read_names_from_file (const char *file_name) { fp = fopen (file_name, "r"); if (fp == NULL) - error (EXIT_FAILURE, errno, - _("error while opening \"%s\" for reading"), file_name); + error (EXIT_FAILURE, errno, + _("error while opening \"%s\" for reading"), file_name); } result = string_list_alloc (); @@ -62,20 +62,20 @@ read_names_from_file (const char *file_name) /* In case of an error leave loop. */ if (len < 0) - break; + break; /* Remove trailing '\n' and trailing whitespace. */ if (len > 0 && line_buf[len - 1] == '\n') - line_buf[--len] = '\0'; + line_buf[--len] = '\0'; while (len > 0 - && (line_buf[len - 1] == ' ' - || line_buf[len - 1] == '\t' - || line_buf[len - 1] == '\r')) - line_buf[--len] = '\0'; + && (line_buf[len - 1] == ' ' + || line_buf[len - 1] == '\t' + || line_buf[len - 1] == '\r')) + line_buf[--len] = '\0'; /* Test if we have to ignore the line. */ if (*line_buf == '\0' || *line_buf == '#') - continue; + continue; string_list_append_unique (result, line_buf); } diff --git a/gettext-tools/src/filter-sr-latin.c b/gettext-tools/src/filter-sr-latin.c index e76fbe70a..d6dbd958c 100644 --- a/gettext-tools/src/filter-sr-latin.c +++ b/gettext-tools/src/filter-sr-latin.c @@ -289,7 +289,7 @@ static const char table[240][3 + 1] = void serbian_to_latin (const char *input, size_t input_len, - char **output_p, size_t *output_len_p) + char **output_p, size_t *output_len_p) { /* Loop through the input string, producing a replacement for each character. Only characters in the range U+0400..U+04EF (\xD0\x80..\xD3\xAF) need to @@ -317,69 +317,69 @@ serbian_to_latin (const char *input, size_t input_len, /* Test for the first byte of a Cyrillic character. */ if ((byte >= 0xd0 && byte <= 0xd3) && (ip + 1 < input_end)) - { - unsigned char second_byte = (unsigned char) ip[1]; + { + unsigned char second_byte = (unsigned char) ip[1]; - /* Verify the second byte is valid. */ - if (second_byte >= 0x80 && second_byte < 0xc0) - { - unsigned int uc = ((byte & 0x1f) << 6) | (second_byte & 0x3f); + /* Verify the second byte is valid. */ + if (second_byte >= 0x80 && second_byte < 0xc0) + { + unsigned int uc = ((byte & 0x1f) << 6) | (second_byte & 0x3f); - if (uc >= 0x0400 && uc <= 0x04ef) - { - /* Look up replacement from the table. */ - const char *repl = table[uc - 0x0400]; + if (uc >= 0x0400 && uc <= 0x04ef) + { + /* Look up replacement from the table. */ + const char *repl = table[uc - 0x0400]; - if (repl[0] != '\0') - { - /* Found a replacement. - Now handle the special cases. */ - if (uc == 0x0409 || uc == 0x040a || uc == 0x040f) - if ((ip + 2 < input_end - && IS_UPPERCASE_LATIN ((unsigned char) ip[2])) - || (ip + 3 < input_end - && IS_UPPERCASE_CYRILLIC ((unsigned char) ip[2], - (unsigned char) ip[3])) - || (ip >= input + 1 - && IS_UPPERCASE_LATIN ((unsigned char) ip[-1])) - || (ip >= input + 2 - && IS_UPPERCASE_CYRILLIC ((unsigned char) ip[-2], - (unsigned char) ip[-1]))) - { - /* Use the upper-case replacement instead of - the mixed-case replacement. */ - switch (uc) - { - case 0x0409: - repl = "LJ"; break; - case 0x040a: - repl = "NJ"; break; - case 0x040f: - repl = "D\xC5\xBD"/* "DŽ" */; break; - default: - abort (); - } - } + if (repl[0] != '\0') + { + /* Found a replacement. + Now handle the special cases. */ + if (uc == 0x0409 || uc == 0x040a || uc == 0x040f) + if ((ip + 2 < input_end + && IS_UPPERCASE_LATIN ((unsigned char) ip[2])) + || (ip + 3 < input_end + && IS_UPPERCASE_CYRILLIC ((unsigned char) ip[2], + (unsigned char) ip[3])) + || (ip >= input + 1 + && IS_UPPERCASE_LATIN ((unsigned char) ip[-1])) + || (ip >= input + 2 + && IS_UPPERCASE_CYRILLIC ((unsigned char) ip[-2], + (unsigned char) ip[-1]))) + { + /* Use the upper-case replacement instead of + the mixed-case replacement. */ + switch (uc) + { + case 0x0409: + repl = "LJ"; break; + case 0x040a: + repl = "NJ"; break; + case 0x040f: + repl = "D\xC5\xBD"/* "DŽ" */; break; + default: + abort (); + } + } - /* Use the replacement. */ - *op++ = *repl++; - if (*repl != '\0') - { - *op++ = *repl++; - if (*repl != '\0') - { - *op++ = *repl++; - /* All replacements have at most 3 bytes. */ - if (*repl != '\0') - abort (); - } - } - ip += 2; - continue; - } - } - } - } + /* Use the replacement. */ + *op++ = *repl++; + if (*repl != '\0') + { + *op++ = *repl++; + if (*repl != '\0') + { + *op++ = *repl++; + /* All replacements have at most 3 bytes. */ + if (*repl != '\0') + abort (); + } + } + ip += 2; + continue; + } + } + } + } *op++ = *ip++; } diff --git a/gettext-tools/src/filters.h b/gettext-tools/src/filters.h index 9efe6bf5f..93128b0b4 100644 --- a/gettext-tools/src/filters.h +++ b/gettext-tools/src/filters.h @@ -27,7 +27,7 @@ extern "C" { in *OUTPUT_LEN_P. Input and output are in UTF-8 encoding. */ extern void serbian_to_latin (const char *input, size_t input_len, - char **output_p, size_t *output_len_p); + char **output_p, size_t *output_len_p); #ifdef __cplusplus } diff --git a/gettext-tools/src/format-awk.c b/gettext-tools/src/format-awk.c index e931bea63..91251c4d6 100644 --- a/gettext-tools/src/format-awk.c +++ b/gettext-tools/src/format-awk.c @@ -94,7 +94,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -110,294 +110,294 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - unsigned int number = 0; - enum format_arg_type type; - - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = INVALID_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - number = m; - format = ++f; - } - } - - /* Parse flags. */ - while (*format == ' ' || *format == '+' || *format == '-' - || *format == '#' || *format == '0') - format++; - - /* Parse width. */ - if (*format == '*') - { - unsigned int width_number = 0; - - format++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = - INVALID_WIDTH_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - width_number = m; - format = ++f; - } - } - - if (width_number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (unnumbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = width_number; - spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; - spec.numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (spec.numbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; - spec.numbered[unnumbered_arg_count].type = FAT_INTEGER; - unnumbered_arg_count++; - } - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - - /* Parse precision. */ - if (*format == '.') - { - format++; - - if (*format == '*') - { - unsigned int precision_number = 0; - - format++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = - INVALID_PRECISION_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - precision_number = m; - format = ++f; - } - } - - if (precision_number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (unnumbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = precision_number; - spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; - spec.numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (spec.numbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; - spec.numbered[unnumbered_arg_count].type = FAT_INTEGER; - unnumbered_arg_count++; - } - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - } - - switch (*format) - { - case '%': - type = FAT_NONE; - break; - case 'c': - type = FAT_CHARACTER; - break; - case 's': - type = FAT_STRING; - break; - case 'i': case 'd': - type = FAT_INTEGER; - break; - case 'u': case 'o': case 'x': case 'X': - type = FAT_UNSIGNED_INTEGER; - break; - case 'e': case 'E': case 'f': case 'g': case 'G': - type = FAT_FLOAT; - break; - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - if (type != FAT_NONE) - { - if (number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (unnumbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = type; - spec.numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (spec.numbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; - spec.numbered[unnumbered_arg_count].type = type; - unnumbered_arg_count++; - } - } - - FDI_SET (format, FMTDIR_END); - - format++; + /* A directive. */ + unsigned int number = 0; + enum format_arg_type type; + + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = INVALID_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + number = m; + format = ++f; + } + } + + /* Parse flags. */ + while (*format == ' ' || *format == '+' || *format == '-' + || *format == '#' || *format == '0') + format++; + + /* Parse width. */ + if (*format == '*') + { + unsigned int width_number = 0; + + format++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = + INVALID_WIDTH_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + width_number = m; + format = ++f; + } + } + + if (width_number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (unnumbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = width_number; + spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; + spec.numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (spec.numbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; + spec.numbered[unnumbered_arg_count].type = FAT_INTEGER; + unnumbered_arg_count++; + } + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + + /* Parse precision. */ + if (*format == '.') + { + format++; + + if (*format == '*') + { + unsigned int precision_number = 0; + + format++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = + INVALID_PRECISION_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + precision_number = m; + format = ++f; + } + } + + if (precision_number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (unnumbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = precision_number; + spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; + spec.numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (spec.numbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; + spec.numbered[unnumbered_arg_count].type = FAT_INTEGER; + unnumbered_arg_count++; + } + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + } + + switch (*format) + { + case '%': + type = FAT_NONE; + break; + case 'c': + type = FAT_CHARACTER; + break; + case 's': + type = FAT_STRING; + break; + case 'i': case 'd': + type = FAT_INTEGER; + break; + case 'u': case 'o': case 'x': case 'X': + type = FAT_UNSIGNED_INTEGER; + break; + case 'e': case 'E': case 'f': case 'g': case 'G': + type = FAT_FLOAT; + break; + default: + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (spec.directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + + if (type != FAT_NONE) + { + if (number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (unnumbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered[spec.numbered_arg_count].type = type; + spec.numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (spec.numbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; + spec.numbered[unnumbered_arg_count].type = type; + unnumbered_arg_count++; + } + } + + FDI_SET (format, FMTDIR_END); + + format++; } /* Convert the unnumbered argument array to numbered arguments. */ @@ -410,44 +410,44 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (spec.numbered, spec.numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < spec.numbered_arg_count; i++) - if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) - { - enum format_arg_type type1 = spec.numbered[i].type; - enum format_arg_type type2 = spec.numbered[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2) - type_both = type1; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); - err = true; - } - - spec.numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - spec.numbered[j].number = spec.numbered[i].number; - spec.numbered[j].type = spec.numbered[i].type; - } - j++; - } + if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) + { + enum format_arg_type type1 = spec.numbered[i].type; + enum format_arg_type type2 = spec.numbered[j-1].type; + enum format_arg_type type_both; + + if (type1 == type2) + type_both = type1; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); + err = true; + } + + spec.numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + spec.numbered[j].number = spec.numbered[i].number; + spec.numbered[j].type = spec.numbered[i].type; + } + j++; + } spec.numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -480,8 +480,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -494,60 +494,60 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->numbered_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } /* Check the argument types are the same. */ if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } + for (i = 0, j = 0; j < n2; ) + { + if (spec1->numbered[i].number == spec2->numbered[j].number) + { + if (spec1->numbered[i].type != spec2->numbered[j].type) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, + spec2->numbered[j].number); + err = true; + break; + } + j++, i++; + } + else + i++; + } } return err; @@ -591,31 +591,31 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); switch (spec->numbered[i].type) - { - case FAT_CHARACTER: - printf ("c"); - break; - case FAT_STRING: - printf ("s"); - break; - case FAT_INTEGER: - printf ("i"); - break; - case FAT_UNSIGNED_INTEGER: - printf ("[unsigned]i"); - break; - case FAT_FLOAT: - printf ("f"); - break; - default: - abort (); - } + { + case FAT_CHARACTER: + printf ("c"); + break; + case FAT_STRING: + printf ("s"); + break; + case FAT_INTEGER: + printf ("i"); + break; + case FAT_UNSIGNED_INTEGER: + printf ("[unsigned]i"); + break; + case FAT_FLOAT: + printf ("f"); + break; + default: + abort (); + } last = number + 1; } printf (")"); @@ -634,9 +634,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -644,7 +644,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-boost.c b/gettext-tools/src/format-boost.c index b24d7f6e8..688ba97b8 100644 --- a/gettext-tools/src/format-boost.c +++ b/gettext-tools/src/format-boost.c @@ -73,13 +73,13 @@ enum format_arg_type { - FAT_NONE = 0, + FAT_NONE = 0, /* Basic types */ - FAT_INTEGER = 1, - FAT_DOUBLE = 2, - FAT_CHAR = 3, - FAT_POINTER = 4, - FAT_ANY = 5 + FAT_INTEGER = 1, + FAT_DOUBLE = 2, + FAT_CHAR = 3, + FAT_POINTER = 4, + FAT_ANY = 5 }; struct numbered_arg @@ -114,7 +114,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -130,380 +130,380 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (*format == '%') - format++; - else - { - bool brackets = false; - bool done = false; - unsigned int number = 0; - enum format_arg_type type = FAT_NONE; - - if (*format == '|') - { - format++; - brackets = true; - } - - if (isdigit (*format) && *format != '0') - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if ((!brackets && *f == '%') || *f == '$') - { - if (m == 0) /* can happen if m overflows */ - { - *invalid_reason = INVALID_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - number = m; - if (*f == '%') - { - type = FAT_ANY; - done = true; - } - format = ++f; - } - } - - if (!done) - { - /* Parse flags. */ - for (;;) - { - if (*format == ' ' || *format == '+' || *format == '-' - || *format == '#' || *format == '0' || *format == '\'' - || *format == '_' || *format == '=' || *format == 'h' - || *format == 'l') - format++; - else - break; - } - - /* Parse width. */ - if (*format == '*') - { - unsigned int width_number = 0; - - format++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = - INVALID_WIDTH_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - width_number = m; - format = ++f; - } - } - - if (width_number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are - exclusive. */ - if (unnumbered_arg_count > 0) - { - *invalid_reason = - INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = width_number; - spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; - spec.numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are - exclusive. */ - if (spec.numbered_arg_count > 0) - { - *invalid_reason = - INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; - spec.numbered[unnumbered_arg_count].type = FAT_INTEGER; - unnumbered_arg_count++; - } - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - - /* Parse precision. */ - if (*format == '.') - { - format++; - - if (*format == '*') - { - unsigned int precision_number = 0; - - format++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = - INVALID_PRECISION_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - precision_number = m; - format = ++f; - } - } - - if (precision_number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are - exclusive. */ - if (unnumbered_arg_count > 0) - { - *invalid_reason = - INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = precision_number; - spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; - spec.numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are - exclusive. */ - if (spec.numbered_arg_count > 0) - { - *invalid_reason = - INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; - spec.numbered[unnumbered_arg_count].type = FAT_INTEGER; - unnumbered_arg_count++; - } - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - } - - /* Parse size. */ - for (;;) - { - if (*format == 'h' || *format == 'l' || *format == 'L') - format++; - else - break; - } - - switch (*format++) - { - case 'c': case 'C': - type = FAT_CHAR; - break; - case 's': case 'S': - type = FAT_ANY; - break; - case 'i': case 'd': case 'o': case 'u': case 'x': case 'X': - type = FAT_INTEGER; - break; - case 'e': case 'E': case 'f': case 'g': case 'G': - type = FAT_DOUBLE; - break; - case 'p': - type = FAT_POINTER; - break; - case 't': - type = FAT_NONE; - break; - case 'T': - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - format++; - type = FAT_NONE; - break; - case 'n': - type = FAT_NONE; - break; - case '|': - if (brackets) - { - --format; - type = FAT_ANY; - break; - } - /*FALLTHROUGH*/ - default: - --format; - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec.directives, - *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - if (brackets) - { - if (*format != '|') - { - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - xasprintf (_("The directive number %u starts with | but does not end with |."), - spec.directives); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - format++; - } - } - - if (type != FAT_NONE) - { - if (number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (unnumbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = type; - spec.numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (spec.numbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; - spec.numbered[unnumbered_arg_count].type = type; - unnumbered_arg_count++; - } - } - } - - FDI_SET (format - 1, FMTDIR_END); + /* A directive. */ + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (*format == '%') + format++; + else + { + bool brackets = false; + bool done = false; + unsigned int number = 0; + enum format_arg_type type = FAT_NONE; + + if (*format == '|') + { + format++; + brackets = true; + } + + if (isdigit (*format) && *format != '0') + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if ((!brackets && *f == '%') || *f == '$') + { + if (m == 0) /* can happen if m overflows */ + { + *invalid_reason = INVALID_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + number = m; + if (*f == '%') + { + type = FAT_ANY; + done = true; + } + format = ++f; + } + } + + if (!done) + { + /* Parse flags. */ + for (;;) + { + if (*format == ' ' || *format == '+' || *format == '-' + || *format == '#' || *format == '0' || *format == '\'' + || *format == '_' || *format == '=' || *format == 'h' + || *format == 'l') + format++; + else + break; + } + + /* Parse width. */ + if (*format == '*') + { + unsigned int width_number = 0; + + format++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = + INVALID_WIDTH_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + width_number = m; + format = ++f; + } + } + + if (width_number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are + exclusive. */ + if (unnumbered_arg_count > 0) + { + *invalid_reason = + INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = width_number; + spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; + spec.numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are + exclusive. */ + if (spec.numbered_arg_count > 0) + { + *invalid_reason = + INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; + spec.numbered[unnumbered_arg_count].type = FAT_INTEGER; + unnumbered_arg_count++; + } + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + + /* Parse precision. */ + if (*format == '.') + { + format++; + + if (*format == '*') + { + unsigned int precision_number = 0; + + format++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = + INVALID_PRECISION_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + precision_number = m; + format = ++f; + } + } + + if (precision_number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are + exclusive. */ + if (unnumbered_arg_count > 0) + { + *invalid_reason = + INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = precision_number; + spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; + spec.numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are + exclusive. */ + if (spec.numbered_arg_count > 0) + { + *invalid_reason = + INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; + spec.numbered[unnumbered_arg_count].type = FAT_INTEGER; + unnumbered_arg_count++; + } + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + } + + /* Parse size. */ + for (;;) + { + if (*format == 'h' || *format == 'l' || *format == 'L') + format++; + else + break; + } + + switch (*format++) + { + case 'c': case 'C': + type = FAT_CHAR; + break; + case 's': case 'S': + type = FAT_ANY; + break; + case 'i': case 'd': case 'o': case 'u': case 'x': case 'X': + type = FAT_INTEGER; + break; + case 'e': case 'E': case 'f': case 'g': case 'G': + type = FAT_DOUBLE; + break; + case 'p': + type = FAT_POINTER; + break; + case 't': + type = FAT_NONE; + break; + case 'T': + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + format++; + type = FAT_NONE; + break; + case 'n': + type = FAT_NONE; + break; + case '|': + if (brackets) + { + --format; + type = FAT_ANY; + break; + } + /*FALLTHROUGH*/ + default: + --format; + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (spec.directives, + *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + if (brackets) + { + if (*format != '|') + { + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + xasprintf (_("The directive number %u starts with | but does not end with |."), + spec.directives); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + format++; + } + } + + if (type != FAT_NONE) + { + if (number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (unnumbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered[spec.numbered_arg_count].type = type; + spec.numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (spec.numbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; + spec.numbered[unnumbered_arg_count].type = type; + unnumbered_arg_count++; + } + } + } + + FDI_SET (format - 1, FMTDIR_END); } /* Convert the unnumbered argument array to numbered arguments. */ @@ -516,46 +516,46 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (spec.numbered, spec.numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < spec.numbered_arg_count; i++) - if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) - { - enum format_arg_type type1 = spec.numbered[i].type; - enum format_arg_type type2 = spec.numbered[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2 || type2 == FAT_ANY) - type_both = type1; - else if (type1 == FAT_ANY) - type_both = type2; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); - err = true; - } - - spec.numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - spec.numbered[j].number = spec.numbered[i].number; - spec.numbered[j].type = spec.numbered[i].type; - } - j++; - } + if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) + { + enum format_arg_type type1 = spec.numbered[i].type; + enum format_arg_type type2 = spec.numbered[j-1].type; + enum format_arg_type type_both; + + if (type1 == type2 || type2 == FAT_ANY) + type_both = type1; + else if (type1 == FAT_ANY) + type_both = type2; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); + err = true; + } + + spec.numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + spec.numbered[j].number = spec.numbered[i].number; + spec.numbered[j].type = spec.numbered[i].type; + } + j++; + } spec.numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -588,8 +588,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -602,60 +602,60 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->numbered_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } /* Check the argument types are the same. */ if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } + for (i = 0, j = 0; j < n2; ) + { + if (spec1->numbered[i].number == spec2->numbered[j].number) + { + if (spec1->numbered[i].type != spec2->numbered[j].type) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, + spec2->numbered[j].number); + err = true; + break; + } + j++, i++; + } + else + i++; + } } return err; @@ -699,31 +699,31 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); switch (spec->numbered[i].type) - { - case FAT_INTEGER: - printf ("i"); - break; - case FAT_DOUBLE: - printf ("f"); - break; - case FAT_CHAR: - printf ("c"); - break; - case FAT_POINTER: - printf ("p"); - break; - case FAT_ANY: - printf ("*"); - break; - default: - abort (); - } + { + case FAT_INTEGER: + printf ("i"); + break; + case FAT_DOUBLE: + printf ("f"); + break; + case FAT_CHAR: + printf ("c"); + break; + case FAT_POINTER: + printf ("p"); + break; + case FAT_ANY: + printf ("*"); + break; + default: + abort (); + } last = number + 1; } printf (")"); @@ -742,9 +742,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -752,7 +752,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-c.c b/gettext-tools/src/format-c.c index 025952700..929e835c0 100644 --- a/gettext-tools/src/format-c.c +++ b/gettext-tools/src/format-c.c @@ -65,73 +65,73 @@ enum format_arg_type { - FAT_NONE = 0, + FAT_NONE = 0, /* Basic types */ - FAT_INTEGER = 1, - FAT_DOUBLE = 2, - FAT_CHAR = 3, - FAT_STRING = 4, - FAT_OBJC_OBJECT = 5, - FAT_POINTER = 6, - FAT_COUNT_POINTER = 7, + FAT_INTEGER = 1, + FAT_DOUBLE = 2, + FAT_CHAR = 3, + FAT_STRING = 4, + FAT_OBJC_OBJECT = 5, + FAT_POINTER = 6, + FAT_COUNT_POINTER = 7, /* Flags */ - FAT_UNSIGNED = 1 << 3, - FAT_SIZE_SHORT = 1 << 4, - FAT_SIZE_CHAR = 2 << 4, - FAT_SIZE_LONG = 1 << 6, - FAT_SIZE_LONGLONG = 2 << 6, - FAT_SIZE_8_T = 1 << 8, - FAT_SIZE_16_T = 1 << 9, - FAT_SIZE_32_T = 1 << 10, - FAT_SIZE_64_T = 1 << 11, - FAT_SIZE_LEAST8_T = 1 << 12, - FAT_SIZE_LEAST16_T = 1 << 13, - FAT_SIZE_LEAST32_T = 1 << 14, - FAT_SIZE_LEAST64_T = 1 << 15, - FAT_SIZE_FAST8_T = 1 << 16, - FAT_SIZE_FAST16_T = 1 << 17, - FAT_SIZE_FAST32_T = 1 << 18, - FAT_SIZE_FAST64_T = 1 << 19, - FAT_SIZE_INTMAX_T = 1 << 20, - FAT_SIZE_INTPTR_T = 1 << 21, - FAT_SIZE_SIZE_T = 1 << 22, - FAT_SIZE_PTRDIFF_T = 1 << 23, - FAT_WIDE = FAT_SIZE_LONG, + FAT_UNSIGNED = 1 << 3, + FAT_SIZE_SHORT = 1 << 4, + FAT_SIZE_CHAR = 2 << 4, + FAT_SIZE_LONG = 1 << 6, + FAT_SIZE_LONGLONG = 2 << 6, + FAT_SIZE_8_T = 1 << 8, + FAT_SIZE_16_T = 1 << 9, + FAT_SIZE_32_T = 1 << 10, + FAT_SIZE_64_T = 1 << 11, + FAT_SIZE_LEAST8_T = 1 << 12, + FAT_SIZE_LEAST16_T = 1 << 13, + FAT_SIZE_LEAST32_T = 1 << 14, + FAT_SIZE_LEAST64_T = 1 << 15, + FAT_SIZE_FAST8_T = 1 << 16, + FAT_SIZE_FAST16_T = 1 << 17, + FAT_SIZE_FAST32_T = 1 << 18, + FAT_SIZE_FAST64_T = 1 << 19, + FAT_SIZE_INTMAX_T = 1 << 20, + FAT_SIZE_INTPTR_T = 1 << 21, + FAT_SIZE_SIZE_T = 1 << 22, + FAT_SIZE_PTRDIFF_T = 1 << 23, + FAT_WIDE = FAT_SIZE_LONG, /* Meaningful combinations of basic types and flags: - 'signed char' = FAT_INTEGER | FAT_SIZE_CHAR, - 'unsigned char' = FAT_INTEGER | FAT_SIZE_CHAR | FAT_UNSIGNED, - 'short' = FAT_INTEGER | FAT_SIZE_SHORT, - 'unsigned short' = FAT_INTEGER | FAT_SIZE_SHORT | FAT_UNSIGNED, - 'int' = FAT_INTEGER, - 'unsigned int' = FAT_INTEGER | FAT_UNSIGNED, - 'long int' = FAT_INTEGER | FAT_SIZE_LONG, - 'unsigned long int' = FAT_INTEGER | FAT_SIZE_LONG | FAT_UNSIGNED, - 'long long int' = FAT_INTEGER | FAT_SIZE_LONGLONG, - 'unsigned long long int' = FAT_INTEGER | FAT_SIZE_LONGLONG | FAT_UNSIGNED, - 'double' = FAT_DOUBLE, - 'long double' = FAT_DOUBLE | FAT_SIZE_LONGLONG, - 'char'/'int' = FAT_CHAR, - 'wchar_t'/'wint_t' = FAT_CHAR | FAT_SIZE_LONG, - 'const char *' = FAT_STRING, - 'const wchar_t *' = FAT_STRING | FAT_SIZE_LONG, - 'void *' = FAT_POINTER, - FAT_COUNT_SCHAR_POINTER = FAT_COUNT_POINTER | FAT_SIZE_CHAR, - FAT_COUNT_SHORT_POINTER = FAT_COUNT_POINTER | FAT_SIZE_SHORT, - FAT_COUNT_INT_POINTER = FAT_COUNT_POINTER, - FAT_COUNT_LONGINT_POINTER = FAT_COUNT_POINTER | FAT_SIZE_LONG, - FAT_COUNT_LONGLONGINT_POINTER = FAT_COUNT_POINTER | FAT_SIZE_LONGLONG, + 'signed char' = FAT_INTEGER | FAT_SIZE_CHAR, + 'unsigned char' = FAT_INTEGER | FAT_SIZE_CHAR | FAT_UNSIGNED, + 'short' = FAT_INTEGER | FAT_SIZE_SHORT, + 'unsigned short' = FAT_INTEGER | FAT_SIZE_SHORT | FAT_UNSIGNED, + 'int' = FAT_INTEGER, + 'unsigned int' = FAT_INTEGER | FAT_UNSIGNED, + 'long int' = FAT_INTEGER | FAT_SIZE_LONG, + 'unsigned long int' = FAT_INTEGER | FAT_SIZE_LONG | FAT_UNSIGNED, + 'long long int' = FAT_INTEGER | FAT_SIZE_LONGLONG, + 'unsigned long long int' = FAT_INTEGER | FAT_SIZE_LONGLONG | FAT_UNSIGNED, + 'double' = FAT_DOUBLE, + 'long double' = FAT_DOUBLE | FAT_SIZE_LONGLONG, + 'char'/'int' = FAT_CHAR, + 'wchar_t'/'wint_t' = FAT_CHAR | FAT_SIZE_LONG, + 'const char *' = FAT_STRING, + 'const wchar_t *' = FAT_STRING | FAT_SIZE_LONG, + 'void *' = FAT_POINTER, + FAT_COUNT_SCHAR_POINTER = FAT_COUNT_POINTER | FAT_SIZE_CHAR, + FAT_COUNT_SHORT_POINTER = FAT_COUNT_POINTER | FAT_SIZE_SHORT, + FAT_COUNT_INT_POINTER = FAT_COUNT_POINTER, + FAT_COUNT_LONGINT_POINTER = FAT_COUNT_POINTER | FAT_SIZE_LONG, + FAT_COUNT_LONGLONGINT_POINTER = FAT_COUNT_POINTER | FAT_SIZE_LONGLONG, */ /* Bitmasks */ - FAT_SIZE_MASK = (FAT_SIZE_SHORT | FAT_SIZE_CHAR - | FAT_SIZE_LONG | FAT_SIZE_LONGLONG - | FAT_SIZE_8_T | FAT_SIZE_16_T - | FAT_SIZE_32_T | FAT_SIZE_64_T - | FAT_SIZE_LEAST8_T | FAT_SIZE_LEAST16_T - | FAT_SIZE_LEAST32_T | FAT_SIZE_LEAST64_T - | FAT_SIZE_FAST8_T | FAT_SIZE_FAST16_T - | FAT_SIZE_FAST32_T | FAT_SIZE_FAST64_T - | FAT_SIZE_INTMAX_T | FAT_SIZE_INTPTR_T - | FAT_SIZE_SIZE_T | FAT_SIZE_PTRDIFF_T) + FAT_SIZE_MASK = (FAT_SIZE_SHORT | FAT_SIZE_CHAR + | FAT_SIZE_LONG | FAT_SIZE_LONGLONG + | FAT_SIZE_8_T | FAT_SIZE_16_T + | FAT_SIZE_32_T | FAT_SIZE_64_T + | FAT_SIZE_LEAST8_T | FAT_SIZE_LEAST16_T + | FAT_SIZE_LEAST32_T | FAT_SIZE_LEAST64_T + | FAT_SIZE_FAST8_T | FAT_SIZE_FAST16_T + | FAT_SIZE_FAST32_T | FAT_SIZE_FAST64_T + | FAT_SIZE_INTMAX_T | FAT_SIZE_INTPTR_T + | FAT_SIZE_SIZE_T | FAT_SIZE_PTRDIFF_T) }; #ifdef __cplusplus typedef int format_arg_type_t; @@ -182,7 +182,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, bool objc_extensions, - char *fdi, char **invalid_reason) + char *fdi, char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -203,555 +203,555 @@ format_parse (const char *format, bool translated, bool objc_extensions, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - unsigned int number = 0; - format_arg_type_t type; - format_arg_type_t size; - - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = INVALID_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - number = m; - format = ++f; - } - } - - /* Parse flags. */ - for (;;) - { - if (*format == ' ' || *format == '+' || *format == '-' - || *format == '#' || *format == '0' || *format == '\'') - format++; - else if (translated && *format == 'I') - { - spec.sysdep_directives = - (const char **) - xrealloc (spec.sysdep_directives, - 2 * (spec.sysdep_directives_count + 1) - * sizeof (const char *)); - spec.sysdep_directives[2 * spec.sysdep_directives_count] = format; - spec.sysdep_directives[2 * spec.sysdep_directives_count + 1] = format + 1; - spec.sysdep_directives_count++; - format++; - } - else - break; - } - - /* Parse width. */ - if (*format == '*') - { - unsigned int width_number = 0; - - format++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = - INVALID_WIDTH_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - width_number = m; - format = ++f; - } - } - - if (width_number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (spec.unnumbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, spec.allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = width_number; - numbered[numbered_arg_count].type = FAT_INTEGER; - numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (numbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.unnumbered = (struct unnumbered_arg *) xrealloc (spec.unnumbered, spec.allocated * sizeof (struct unnumbered_arg)); - } - spec.unnumbered[spec.unnumbered_arg_count].type = FAT_INTEGER; - spec.unnumbered_arg_count++; - } - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - - /* Parse precision. */ - if (*format == '.') - { - format++; - - if (*format == '*') - { - unsigned int precision_number = 0; - - format++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = - INVALID_PRECISION_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - precision_number = m; - format = ++f; - } - } - - if (precision_number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (spec.unnumbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, spec.allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = precision_number; - numbered[numbered_arg_count].type = FAT_INTEGER; - numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (numbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.unnumbered = (struct unnumbered_arg *) xrealloc (spec.unnumbered, spec.allocated * sizeof (struct unnumbered_arg)); - } - spec.unnumbered[spec.unnumbered_arg_count].type = FAT_INTEGER; - spec.unnumbered_arg_count++; - } - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - } - - if (*format == '<') - { - spec.sysdep_directives = - (const char **) - xrealloc (spec.sysdep_directives, - 2 * (spec.sysdep_directives_count + 1) - * sizeof (const char *)); - spec.sysdep_directives[2 * spec.sysdep_directives_count] = format; - - format++; - /* Parse ISO C 99 section 7.8.1 format string directive. - Syntax: - P R I { d | i | o | u | x | X } - { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */ - if (*format != 'P') - { - *invalid_reason = INVALID_C99_MACRO (spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); - goto bad_format; - } - format++; - if (*format != 'R') - { - *invalid_reason = INVALID_C99_MACRO (spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); - goto bad_format; - } - format++; - if (*format != 'I') - { - *invalid_reason = INVALID_C99_MACRO (spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); - goto bad_format; - } - format++; - - switch (*format) - { - case 'i': case 'd': - type = FAT_INTEGER; - break; - case 'u': case 'o': case 'x': case 'X': - type = FAT_INTEGER | FAT_UNSIGNED; - break; - default: - *invalid_reason = INVALID_C99_MACRO (spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); - goto bad_format; - } - format++; - - if (format[0] == 'M' && format[1] == 'A' && format[2] == 'X') - { - type |= FAT_SIZE_INTMAX_T; - format += 3; - } - else if (format[0] == 'P' && format[1] == 'T' && format[2] == 'R') - { - type |= FAT_SIZE_INTPTR_T; - format += 3; - } - else - { - if (format[0] == 'L' && format[1] == 'E' && format[2] == 'A' - && format[3] == 'S' && format[4] == 'T') - { - format += 5; - if (format[0] == '8') - { - type |= FAT_SIZE_LEAST8_T; - format++; - } - else if (format[0] == '1' && format[1] == '6') - { - type |= FAT_SIZE_LEAST16_T; - format += 2; - } - else if (format[0] == '3' && format[1] == '2') - { - type |= FAT_SIZE_LEAST32_T; - format += 2; - } - else if (format[0] == '6' && format[1] == '4') - { - type |= FAT_SIZE_LEAST64_T; - format += 2; - } - else - { - *invalid_reason = INVALID_C99_MACRO (spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, - FMTDIR_ERROR); - goto bad_format; - } - } - else if (format[0] == 'F' && format[1] == 'A' - && format[2] == 'S' && format[3] == 'T') - { - format += 4; - if (format[0] == '8') - { - type |= FAT_SIZE_FAST8_T; - format++; - } - else if (format[0] == '1' && format[1] == '6') - { - type |= FAT_SIZE_FAST16_T; - format += 2; - } - else if (format[0] == '3' && format[1] == '2') - { - type |= FAT_SIZE_FAST32_T; - format += 2; - } - else if (format[0] == '6' && format[1] == '4') - { - type |= FAT_SIZE_FAST64_T; - format += 2; - } - else - { - *invalid_reason = INVALID_C99_MACRO (spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, - FMTDIR_ERROR); - goto bad_format; - } - } - else - { - if (format[0] == '8') - { - type |= FAT_SIZE_8_T; - format++; - } - else if (format[0] == '1' && format[1] == '6') - { - type |= FAT_SIZE_16_T; - format += 2; - } - else if (format[0] == '3' && format[1] == '2') - { - type |= FAT_SIZE_32_T; - format += 2; - } - else if (format[0] == '6' && format[1] == '4') - { - type |= FAT_SIZE_64_T; - format += 2; - } - else - { - *invalid_reason = INVALID_C99_MACRO (spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, - FMTDIR_ERROR); - goto bad_format; - } - } - } - - if (*format != '>') - { - *invalid_reason = - xasprintf (_("In the directive number %u, the token after '<' is not followed by '>'."), spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); - goto bad_format; - } - - spec.sysdep_directives[2 * spec.sysdep_directives_count + 1] = format + 1; - spec.sysdep_directives_count++; - } - else - { - /* Parse size. */ - size = 0; - for (;; format++) - { - if (*format == 'h') - { - if (size & (FAT_SIZE_SHORT | FAT_SIZE_CHAR)) - size = FAT_SIZE_CHAR; - else - size = FAT_SIZE_SHORT; - } - else if (*format == 'l') - { - if (size & (FAT_SIZE_LONG | FAT_SIZE_LONGLONG)) - size = FAT_SIZE_LONGLONG; - else - size = FAT_SIZE_LONG; - } - else if (*format == 'L') - size = FAT_SIZE_LONGLONG; - else if (*format == 'q') - /* Old BSD 4.4 convention. */ - size = FAT_SIZE_LONGLONG; - else if (*format == 'j') - size = FAT_SIZE_INTMAX_T; - else if (*format == 'z' || *format == 'Z') - /* 'z' is standardized in ISO C 99, but glibc uses 'Z' - because the warning facility in gcc-2.95.2 understands - only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ - size = FAT_SIZE_SIZE_T; - else if (*format == 't') - size = FAT_SIZE_PTRDIFF_T; - else - break; - } - - switch (*format) - { - case '%': - /* Programmers writing _("%2%") most often will not want to - use this string as a c-format string, but rather as a - literal or as a different kind of format string. */ - if (format[-1] != '%') - spec.unlikely_intentional = true; - type = FAT_NONE; - break; - case 'm': /* glibc extension */ - type = FAT_NONE; - break; - case 'c': - type = FAT_CHAR; - type |= (size & (FAT_SIZE_LONG | FAT_SIZE_LONGLONG) - ? FAT_WIDE : 0); - break; - case 'C': /* obsolete */ - type = FAT_CHAR | FAT_WIDE; - break; - case 's': - type = FAT_STRING; - type |= (size & (FAT_SIZE_LONG | FAT_SIZE_LONGLONG) - ? FAT_WIDE : 0); - break; - case 'S': /* obsolete */ - type = FAT_STRING | FAT_WIDE; - break; - case 'i': case 'd': - type = FAT_INTEGER; - type |= (size & FAT_SIZE_MASK); - break; - case 'u': case 'o': case 'x': case 'X': - type = FAT_INTEGER | FAT_UNSIGNED; - type |= (size & FAT_SIZE_MASK); - break; - case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': - case 'a': case 'A': - type = FAT_DOUBLE; - type |= (size & FAT_SIZE_LONGLONG); - break; - case '@': - if (objc_extensions) - { - type = FAT_OBJC_OBJECT; - break; - } - goto other; - case 'p': - type = FAT_POINTER; - break; - case 'n': - type = FAT_COUNT_POINTER; - type |= (size & FAT_SIZE_MASK); - break; - other: - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - } - - if (type != FAT_NONE) - { - if (number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (spec.unnumbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, spec.allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = number; - numbered[numbered_arg_count].type = type; - numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (numbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.unnumbered = (struct unnumbered_arg *) xrealloc (spec.unnumbered, spec.allocated * sizeof (struct unnumbered_arg)); - } - spec.unnumbered[spec.unnumbered_arg_count].type = type; - spec.unnumbered_arg_count++; - } - } - - FDI_SET (format, FMTDIR_END); - - format++; + /* A directive. */ + unsigned int number = 0; + format_arg_type_t type; + format_arg_type_t size; + + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = INVALID_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + number = m; + format = ++f; + } + } + + /* Parse flags. */ + for (;;) + { + if (*format == ' ' || *format == '+' || *format == '-' + || *format == '#' || *format == '0' || *format == '\'') + format++; + else if (translated && *format == 'I') + { + spec.sysdep_directives = + (const char **) + xrealloc (spec.sysdep_directives, + 2 * (spec.sysdep_directives_count + 1) + * sizeof (const char *)); + spec.sysdep_directives[2 * spec.sysdep_directives_count] = format; + spec.sysdep_directives[2 * spec.sysdep_directives_count + 1] = format + 1; + spec.sysdep_directives_count++; + format++; + } + else + break; + } + + /* Parse width. */ + if (*format == '*') + { + unsigned int width_number = 0; + + format++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = + INVALID_WIDTH_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + width_number = m; + format = ++f; + } + } + + if (width_number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (spec.unnumbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, spec.allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = width_number; + numbered[numbered_arg_count].type = FAT_INTEGER; + numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (numbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.unnumbered = (struct unnumbered_arg *) xrealloc (spec.unnumbered, spec.allocated * sizeof (struct unnumbered_arg)); + } + spec.unnumbered[spec.unnumbered_arg_count].type = FAT_INTEGER; + spec.unnumbered_arg_count++; + } + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + + /* Parse precision. */ + if (*format == '.') + { + format++; + + if (*format == '*') + { + unsigned int precision_number = 0; + + format++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = + INVALID_PRECISION_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + precision_number = m; + format = ++f; + } + } + + if (precision_number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (spec.unnumbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, spec.allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = precision_number; + numbered[numbered_arg_count].type = FAT_INTEGER; + numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (numbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.unnumbered = (struct unnumbered_arg *) xrealloc (spec.unnumbered, spec.allocated * sizeof (struct unnumbered_arg)); + } + spec.unnumbered[spec.unnumbered_arg_count].type = FAT_INTEGER; + spec.unnumbered_arg_count++; + } + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + } + + if (*format == '<') + { + spec.sysdep_directives = + (const char **) + xrealloc (spec.sysdep_directives, + 2 * (spec.sysdep_directives_count + 1) + * sizeof (const char *)); + spec.sysdep_directives[2 * spec.sysdep_directives_count] = format; + + format++; + /* Parse ISO C 99 section 7.8.1 format string directive. + Syntax: + P R I { d | i | o | u | x | X } + { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */ + if (*format != 'P') + { + *invalid_reason = INVALID_C99_MACRO (spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); + goto bad_format; + } + format++; + if (*format != 'R') + { + *invalid_reason = INVALID_C99_MACRO (spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); + goto bad_format; + } + format++; + if (*format != 'I') + { + *invalid_reason = INVALID_C99_MACRO (spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); + goto bad_format; + } + format++; + + switch (*format) + { + case 'i': case 'd': + type = FAT_INTEGER; + break; + case 'u': case 'o': case 'x': case 'X': + type = FAT_INTEGER | FAT_UNSIGNED; + break; + default: + *invalid_reason = INVALID_C99_MACRO (spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); + goto bad_format; + } + format++; + + if (format[0] == 'M' && format[1] == 'A' && format[2] == 'X') + { + type |= FAT_SIZE_INTMAX_T; + format += 3; + } + else if (format[0] == 'P' && format[1] == 'T' && format[2] == 'R') + { + type |= FAT_SIZE_INTPTR_T; + format += 3; + } + else + { + if (format[0] == 'L' && format[1] == 'E' && format[2] == 'A' + && format[3] == 'S' && format[4] == 'T') + { + format += 5; + if (format[0] == '8') + { + type |= FAT_SIZE_LEAST8_T; + format++; + } + else if (format[0] == '1' && format[1] == '6') + { + type |= FAT_SIZE_LEAST16_T; + format += 2; + } + else if (format[0] == '3' && format[1] == '2') + { + type |= FAT_SIZE_LEAST32_T; + format += 2; + } + else if (format[0] == '6' && format[1] == '4') + { + type |= FAT_SIZE_LEAST64_T; + format += 2; + } + else + { + *invalid_reason = INVALID_C99_MACRO (spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, + FMTDIR_ERROR); + goto bad_format; + } + } + else if (format[0] == 'F' && format[1] == 'A' + && format[2] == 'S' && format[3] == 'T') + { + format += 4; + if (format[0] == '8') + { + type |= FAT_SIZE_FAST8_T; + format++; + } + else if (format[0] == '1' && format[1] == '6') + { + type |= FAT_SIZE_FAST16_T; + format += 2; + } + else if (format[0] == '3' && format[1] == '2') + { + type |= FAT_SIZE_FAST32_T; + format += 2; + } + else if (format[0] == '6' && format[1] == '4') + { + type |= FAT_SIZE_FAST64_T; + format += 2; + } + else + { + *invalid_reason = INVALID_C99_MACRO (spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, + FMTDIR_ERROR); + goto bad_format; + } + } + else + { + if (format[0] == '8') + { + type |= FAT_SIZE_8_T; + format++; + } + else if (format[0] == '1' && format[1] == '6') + { + type |= FAT_SIZE_16_T; + format += 2; + } + else if (format[0] == '3' && format[1] == '2') + { + type |= FAT_SIZE_32_T; + format += 2; + } + else if (format[0] == '6' && format[1] == '4') + { + type |= FAT_SIZE_64_T; + format += 2; + } + else + { + *invalid_reason = INVALID_C99_MACRO (spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, + FMTDIR_ERROR); + goto bad_format; + } + } + } + + if (*format != '>') + { + *invalid_reason = + xasprintf (_("In the directive number %u, the token after '<' is not followed by '>'."), spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); + goto bad_format; + } + + spec.sysdep_directives[2 * spec.sysdep_directives_count + 1] = format + 1; + spec.sysdep_directives_count++; + } + else + { + /* Parse size. */ + size = 0; + for (;; format++) + { + if (*format == 'h') + { + if (size & (FAT_SIZE_SHORT | FAT_SIZE_CHAR)) + size = FAT_SIZE_CHAR; + else + size = FAT_SIZE_SHORT; + } + else if (*format == 'l') + { + if (size & (FAT_SIZE_LONG | FAT_SIZE_LONGLONG)) + size = FAT_SIZE_LONGLONG; + else + size = FAT_SIZE_LONG; + } + else if (*format == 'L') + size = FAT_SIZE_LONGLONG; + else if (*format == 'q') + /* Old BSD 4.4 convention. */ + size = FAT_SIZE_LONGLONG; + else if (*format == 'j') + size = FAT_SIZE_INTMAX_T; + else if (*format == 'z' || *format == 'Z') + /* 'z' is standardized in ISO C 99, but glibc uses 'Z' + because the warning facility in gcc-2.95.2 understands + only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ + size = FAT_SIZE_SIZE_T; + else if (*format == 't') + size = FAT_SIZE_PTRDIFF_T; + else + break; + } + + switch (*format) + { + case '%': + /* Programmers writing _("%2%") most often will not want to + use this string as a c-format string, but rather as a + literal or as a different kind of format string. */ + if (format[-1] != '%') + spec.unlikely_intentional = true; + type = FAT_NONE; + break; + case 'm': /* glibc extension */ + type = FAT_NONE; + break; + case 'c': + type = FAT_CHAR; + type |= (size & (FAT_SIZE_LONG | FAT_SIZE_LONGLONG) + ? FAT_WIDE : 0); + break; + case 'C': /* obsolete */ + type = FAT_CHAR | FAT_WIDE; + break; + case 's': + type = FAT_STRING; + type |= (size & (FAT_SIZE_LONG | FAT_SIZE_LONGLONG) + ? FAT_WIDE : 0); + break; + case 'S': /* obsolete */ + type = FAT_STRING | FAT_WIDE; + break; + case 'i': case 'd': + type = FAT_INTEGER; + type |= (size & FAT_SIZE_MASK); + break; + case 'u': case 'o': case 'x': case 'X': + type = FAT_INTEGER | FAT_UNSIGNED; + type |= (size & FAT_SIZE_MASK); + break; + case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': + case 'a': case 'A': + type = FAT_DOUBLE; + type |= (size & FAT_SIZE_LONGLONG); + break; + case '@': + if (objc_extensions) + { + type = FAT_OBJC_OBJECT; + break; + } + goto other; + case 'p': + type = FAT_POINTER; + break; + case 'n': + type = FAT_COUNT_POINTER; + type |= (size & FAT_SIZE_MASK); + break; + other: + default: + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (spec.directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + } + + if (type != FAT_NONE) + { + if (number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (spec.unnumbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, spec.allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = number; + numbered[numbered_arg_count].type = type; + numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (numbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.unnumbered = (struct unnumbered_arg *) xrealloc (spec.unnumbered, spec.allocated * sizeof (struct unnumbered_arg)); + } + spec.unnumbered[spec.unnumbered_arg_count].type = type; + spec.unnumbered_arg_count++; + } + } + + FDI_SET (format, FMTDIR_END); + + format++; } /* Sort the numbered argument array, and eliminate duplicates. */ @@ -761,44 +761,44 @@ format_parse (const char *format, bool translated, bool objc_extensions, bool err; qsort (numbered, numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < numbered_arg_count; i++) - if (j > 0 && numbered[i].number == numbered[j-1].number) - { - format_arg_type_t type1 = numbered[i].type; - format_arg_type_t type2 = numbered[j-1].type; - format_arg_type_t type_both; - - if (type1 == type2) - type_both = type1; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (numbered[i].number); - err = true; - } - - numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - numbered[j].number = numbered[i].number; - numbered[j].type = numbered[i].type; - } - j++; - } + if (j > 0 && numbered[i].number == numbered[j-1].number) + { + format_arg_type_t type1 = numbered[i].type; + format_arg_type_t type2 = numbered[j-1].type; + format_arg_type_t type_both; + + if (type1 == type2) + type_both = type1; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (numbered[i].number); + err = true; + } + + numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + numbered[j].number = numbered[i].number; + numbered[j].type = numbered[i].type; + } + j++; + } numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } /* Verify that the format strings uses all arguments up to the highest @@ -808,20 +808,20 @@ format_parse (const char *format, bool translated, bool objc_extensions, unsigned int i; for (i = 0; i < numbered_arg_count; i++) - if (numbered[i].number != i + 1) - { - *invalid_reason = - xasprintf (_("The string refers to argument number %u but ignores argument number %u."), numbered[i].number, i + 1); - goto bad_format; - } + if (numbered[i].number != i + 1) + { + *invalid_reason = + xasprintf (_("The string refers to argument number %u but ignores argument number %u."), numbered[i].number, i + 1); + goto bad_format; + } /* So now the numbered arguments array is equivalent to a sequence - of unnumbered arguments. */ + of unnumbered arguments. */ spec.unnumbered_arg_count = numbered_arg_count; spec.allocated = spec.unnumbered_arg_count; spec.unnumbered = XNMALLOC (spec.allocated, struct unnumbered_arg); for (i = 0; i < spec.unnumbered_arg_count; i++) - spec.unnumbered[i].type = numbered[i].type; + spec.unnumbered[i].type = numbered[i].type; free (numbered); numbered_arg_count = 0; } @@ -842,14 +842,14 @@ format_parse (const char *format, bool translated, bool objc_extensions, static void * format_c_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { return format_parse (format, translated, false, fdi, invalid_reason); } static void * format_objc_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { return format_parse (format, translated, true, fdi, invalid_reason); } @@ -884,8 +884,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -898,19 +898,19 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, : spec1->unnumbered_arg_count < spec2->unnumbered_arg_count) { if (error_logger) - error_logger (_("number of format specifications in '%s' and '%s' does not match"), - pretty_msgid, pretty_msgstr); + error_logger (_("number of format specifications in '%s' and '%s' does not match"), + pretty_msgid, pretty_msgstr); err = true; } else for (i = 0; i < spec2->unnumbered_arg_count; i++) if (spec1->unnumbered[i].type != spec2->unnumbered[i].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, i + 1); - err = true; - } + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, i + 1); + err = true; + } return err; } @@ -938,7 +938,7 @@ struct formatstring_parser formatstring_objc = void get_sysdep_c_format_directives (const char *string, bool translated, - struct interval **intervalsp, size_t *lengthp) + struct interval **intervalsp, size_t *lengthp) { /* Parse the format string with all possible extensions turned on. (The caller has already verified that the format string is valid for the @@ -955,10 +955,10 @@ get_sysdep_c_format_directives (const char *string, bool translated, unsigned int i; for (i = 0; i < n; i++) - { - intervals[i].startpos = descr->sysdep_directives[2 * i] - string; - intervals[i].endpos = descr->sysdep_directives[2 * i + 1] - string; - } + { + intervals[i].startpos = descr->sysdep_directives[2 * i] - string; + intervals[i].endpos = descr->sysdep_directives[2 * i + 1] - string; + } *intervalsp = intervals; *lengthp = n; } @@ -998,102 +998,102 @@ format_print (void *descr) for (i = 0; i < spec->unnumbered_arg_count; i++) { if (i > 0) - printf (" "); + printf (" "); if (spec->unnumbered[i].type & FAT_UNSIGNED) - printf ("[unsigned]"); + printf ("[unsigned]"); switch (spec->unnumbered[i].type & FAT_SIZE_MASK) - { - case 0: - break; - case FAT_SIZE_SHORT: - printf ("[short]"); - break; - case FAT_SIZE_CHAR: - printf ("[char]"); - break; - case FAT_SIZE_LONG: - printf ("[long]"); - break; - case FAT_SIZE_LONGLONG: - printf ("[long long]"); - break; - case FAT_SIZE_8_T: - printf ("[int8_t]"); - break; - case FAT_SIZE_16_T: - printf ("[int16_t]"); - break; - case FAT_SIZE_32_T: - printf ("[int32_t]"); - break; - case FAT_SIZE_64_T: - printf ("[int64_t]"); - break; - case FAT_SIZE_LEAST8_T: - printf ("[int_least8_t]"); - break; - case FAT_SIZE_LEAST16_T: - printf ("[int_least16_t]"); - break; - case FAT_SIZE_LEAST32_T: - printf ("[int_least32_t]"); - break; - case FAT_SIZE_LEAST64_T: - printf ("[int_least64_t]"); - break; - case FAT_SIZE_FAST8_T: - printf ("[int_fast8_t]"); - break; - case FAT_SIZE_FAST16_T: - printf ("[int_fast16_t]"); - break; - case FAT_SIZE_FAST32_T: - printf ("[int_fast32_t]"); - break; - case FAT_SIZE_FAST64_T: - printf ("[int_fast64_t]"); - break; - case FAT_SIZE_INTMAX_T: - printf ("[intmax_t]"); - break; - case FAT_SIZE_INTPTR_T: - printf ("[intptr_t]"); - break; - case FAT_SIZE_SIZE_T: - printf ("[size_t]"); - break; - case FAT_SIZE_PTRDIFF_T: - printf ("[ptrdiff_t]"); - break; - default: - abort (); - } + { + case 0: + break; + case FAT_SIZE_SHORT: + printf ("[short]"); + break; + case FAT_SIZE_CHAR: + printf ("[char]"); + break; + case FAT_SIZE_LONG: + printf ("[long]"); + break; + case FAT_SIZE_LONGLONG: + printf ("[long long]"); + break; + case FAT_SIZE_8_T: + printf ("[int8_t]"); + break; + case FAT_SIZE_16_T: + printf ("[int16_t]"); + break; + case FAT_SIZE_32_T: + printf ("[int32_t]"); + break; + case FAT_SIZE_64_T: + printf ("[int64_t]"); + break; + case FAT_SIZE_LEAST8_T: + printf ("[int_least8_t]"); + break; + case FAT_SIZE_LEAST16_T: + printf ("[int_least16_t]"); + break; + case FAT_SIZE_LEAST32_T: + printf ("[int_least32_t]"); + break; + case FAT_SIZE_LEAST64_T: + printf ("[int_least64_t]"); + break; + case FAT_SIZE_FAST8_T: + printf ("[int_fast8_t]"); + break; + case FAT_SIZE_FAST16_T: + printf ("[int_fast16_t]"); + break; + case FAT_SIZE_FAST32_T: + printf ("[int_fast32_t]"); + break; + case FAT_SIZE_FAST64_T: + printf ("[int_fast64_t]"); + break; + case FAT_SIZE_INTMAX_T: + printf ("[intmax_t]"); + break; + case FAT_SIZE_INTPTR_T: + printf ("[intptr_t]"); + break; + case FAT_SIZE_SIZE_T: + printf ("[size_t]"); + break; + case FAT_SIZE_PTRDIFF_T: + printf ("[ptrdiff_t]"); + break; + default: + abort (); + } switch (spec->unnumbered[i].type & ~(FAT_UNSIGNED | FAT_SIZE_MASK)) - { - case FAT_INTEGER: - printf ("i"); - break; - case FAT_DOUBLE: - printf ("f"); - break; - case FAT_CHAR: - printf ("c"); - break; - case FAT_STRING: - printf ("s"); - break; - case FAT_OBJC_OBJECT: - printf ("@"); - break; - case FAT_POINTER: - printf ("p"); - break; - case FAT_COUNT_POINTER: - printf ("n"); - break; - default: - abort (); - } + { + case FAT_INTEGER: + printf ("i"); + break; + case FAT_DOUBLE: + printf ("f"); + break; + case FAT_CHAR: + printf ("c"); + break; + case FAT_STRING: + printf ("s"); + break; + case FAT_OBJC_OBJECT: + printf ("@"); + break; + case FAT_POINTER: + printf ("p"); + break; + case FAT_COUNT_POINTER: + printf ("n"); + break; + default: + abort (); + } } printf (")"); } @@ -1111,9 +1111,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_c_parse (line, false, NULL, &invalid_reason); @@ -1121,7 +1121,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-csharp.c b/gettext-tools/src/format-csharp.c index b054aa622..feb3fcfaf 100644 --- a/gettext-tools/src/format-csharp.c +++ b/gettext-tools/src/format-csharp.c @@ -57,7 +57,7 @@ struct spec static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -71,100 +71,100 @@ format_parse (const char *format, bool translated, char *fdi, char c = *format++; if (c == '{') - { - FDI_SET (format - 1, FMTDIR_START); - if (*format == '{') - format++; - else - { - /* A directive. */ - unsigned int number; - - spec.directives++; - - if (!c_isdigit (*format)) - { - *invalid_reason = - xasprintf (_("In the directive number %u, '{' is not followed by an argument number."), spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); - return NULL; - } - number = 0; - do - { - number = 10 * number + (*format - '0'); - format++; - } - while (c_isdigit (*format)); - - if (*format == ',') - { - /* Parse width. */ - format++; - if (*format == '-') - format++; - if (!c_isdigit (*format)) - { - *invalid_reason = - xasprintf (_("In the directive number %u, ',' is not followed by a number."), spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, - FMTDIR_ERROR); - return NULL; - } - do - format++; - while (c_isdigit (*format)); - } - - if (*format == ':') - { - /* Parse format specifiers. */ - do - format++; - while (*format != '\0' && *format != '}'); - } - - if (*format == '\0') - { - *invalid_reason = - xstrdup (_("The string ends in the middle of a directive: found '{' without matching '}'.")); - FDI_SET (format - 1, FMTDIR_ERROR); - return NULL; - } - - if (*format != '}') - { - *invalid_reason = - (c_isprint (*format) - ? xasprintf (_("The directive number %u ends with an invalid character '%c' instead of '}'."), spec.directives, *format) - : xasprintf (_("The directive number %u ends with an invalid character instead of '}'."), spec.directives)); - FDI_SET (format, FMTDIR_ERROR); - return NULL; - } - - format++; - - if (spec.numbered_arg_count <= number) - spec.numbered_arg_count = number + 1; - } - FDI_SET (format - 1, FMTDIR_END); - } + { + FDI_SET (format - 1, FMTDIR_START); + if (*format == '{') + format++; + else + { + /* A directive. */ + unsigned int number; + + spec.directives++; + + if (!c_isdigit (*format)) + { + *invalid_reason = + xasprintf (_("In the directive number %u, '{' is not followed by an argument number."), spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); + return NULL; + } + number = 0; + do + { + number = 10 * number + (*format - '0'); + format++; + } + while (c_isdigit (*format)); + + if (*format == ',') + { + /* Parse width. */ + format++; + if (*format == '-') + format++; + if (!c_isdigit (*format)) + { + *invalid_reason = + xasprintf (_("In the directive number %u, ',' is not followed by a number."), spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, + FMTDIR_ERROR); + return NULL; + } + do + format++; + while (c_isdigit (*format)); + } + + if (*format == ':') + { + /* Parse format specifiers. */ + do + format++; + while (*format != '\0' && *format != '}'); + } + + if (*format == '\0') + { + *invalid_reason = + xstrdup (_("The string ends in the middle of a directive: found '{' without matching '}'.")); + FDI_SET (format - 1, FMTDIR_ERROR); + return NULL; + } + + if (*format != '}') + { + *invalid_reason = + (c_isprint (*format) + ? xasprintf (_("The directive number %u ends with an invalid character '%c' instead of '}'."), spec.directives, *format) + : xasprintf (_("The directive number %u ends with an invalid character instead of '}'."), spec.directives)); + FDI_SET (format, FMTDIR_ERROR); + return NULL; + } + + format++; + + if (spec.numbered_arg_count <= number) + spec.numbered_arg_count = number + 1; + } + FDI_SET (format - 1, FMTDIR_END); + } else if (c == '}') - { - FDI_SET (format - 1, FMTDIR_START); - if (*format == '}') - format++; - else - { - *invalid_reason = - (spec.directives == 0 - ? xstrdup (_("The string starts in the middle of a directive: found '}' without matching '{'.")) - : xasprintf (_("The string contains a lone '}' after directive number %u."), spec.directives)); - FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); - return NULL; - } - FDI_SET (format - 1, FMTDIR_END); - } + { + FDI_SET (format - 1, FMTDIR_START); + if (*format == '}') + format++; + else + { + *invalid_reason = + (spec.directives == 0 + ? xstrdup (_("The string starts in the middle of a directive: found '}' without matching '{'.")) + : xasprintf (_("The string contains a lone '}' after directive number %u."), spec.directives)); + FDI_SET (*format == '\0' ? format - 1 : format, FMTDIR_ERROR); + return NULL; + } + FDI_SET (format - 1, FMTDIR_END); + } } result = XMALLOC (struct spec); @@ -190,8 +190,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -203,8 +203,8 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, : spec1->numbered_arg_count < spec2->numbered_arg_count) { if (error_logger) - error_logger (_("number of format specifications in '%s' and '%s' does not match"), - pretty_msgid, pretty_msgstr); + error_logger (_("number of format specifications in '%s' and '%s' does not match"), + pretty_msgid, pretty_msgstr); err = true; } @@ -245,7 +245,7 @@ format_print (void *descr) for (i = 0; i < spec->numbered_arg_count; i++) { if (i > 0) - printf (" "); + printf (" "); printf ("*"); } printf (")"); @@ -264,9 +264,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -274,7 +274,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-elisp.c b/gettext-tools/src/format-elisp.c index c6f2f1efc..2e43fde13 100644 --- a/gettext-tools/src/format-elisp.c +++ b/gettext-tools/src/format-elisp.c @@ -95,7 +95,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -111,135 +111,135 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - enum format_arg_type type; - - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$' && m > 0) - { - number = m; - format = ++f; - } - } - - /* Parse flags. */ - while (*format == ' ' || *format == '+' || *format == '-' - || *format == '#' || *format == '0') - format++; - - /* Parse width. */ - if (*format == '*') - { - format++; - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; - spec.numbered_arg_count++; - - number++; - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - - /* Parse precision. */ - if (*format == '.') - { - format++; - - if (*format == '*') - { - format++; - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; - spec.numbered_arg_count++; - - number++; - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - } - - switch (*format) - { - case '%': - type = FAT_NONE; - break; - case 'c': - type = FAT_CHARACTER; - break; - case 'd': case 'i': case 'x': case 'X': case 'o': - type = FAT_INTEGER; - break; - case 'e': case 'E': case 'f': case 'g': case 'G': - type = FAT_FLOAT; - break; - case 's': - type = FAT_OBJECT_PRETTY; - break; - case 'S': - type = FAT_OBJECT; - break; - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - if (type != FAT_NONE) - { - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = type; - spec.numbered_arg_count++; - - number++; - } - - FDI_SET (format, FMTDIR_END); - - format++; + /* A directive. */ + enum format_arg_type type; + + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$' && m > 0) + { + number = m; + format = ++f; + } + } + + /* Parse flags. */ + while (*format == ' ' || *format == '+' || *format == '-' + || *format == '#' || *format == '0') + format++; + + /* Parse width. */ + if (*format == '*') + { + format++; + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; + spec.numbered_arg_count++; + + number++; + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + + /* Parse precision. */ + if (*format == '.') + { + format++; + + if (*format == '*') + { + format++; + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; + spec.numbered_arg_count++; + + number++; + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + } + + switch (*format) + { + case '%': + type = FAT_NONE; + break; + case 'c': + type = FAT_CHARACTER; + break; + case 'd': case 'i': case 'x': case 'X': case 'o': + type = FAT_INTEGER; + break; + case 'e': case 'E': case 'f': case 'g': case 'G': + type = FAT_FLOAT; + break; + case 's': + type = FAT_OBJECT_PRETTY; + break; + case 'S': + type = FAT_OBJECT; + break; + default: + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (spec.directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + + if (type != FAT_NONE) + { + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered[spec.numbered_arg_count].type = type; + spec.numbered_arg_count++; + + number++; + } + + FDI_SET (format, FMTDIR_END); + + format++; } /* Sort the numbered argument array, and eliminate duplicates. */ @@ -249,44 +249,44 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (spec.numbered, spec.numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < spec.numbered_arg_count; i++) - if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) - { - enum format_arg_type type1 = spec.numbered[i].type; - enum format_arg_type type2 = spec.numbered[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2) - type_both = type1; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); - err = true; - } - - spec.numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - spec.numbered[j].number = spec.numbered[i].number; - spec.numbered[j].type = spec.numbered[i].type; - } - j++; - } + if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) + { + enum format_arg_type type1 = spec.numbered[i].type; + enum format_arg_type type2 = spec.numbered[j-1].type; + enum format_arg_type type_both; + + if (type1 == type2) + type_both = type1; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); + err = true; + } + + spec.numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + spec.numbered[j].number = spec.numbered[i].number; + spec.numbered[j].type = spec.numbered[i].type; + } + j++; + } spec.numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -319,8 +319,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -333,60 +333,60 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->numbered_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } /* Check the argument types are the same. */ if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } + for (i = 0, j = 0; j < n2; ) + { + if (spec1->numbered[i].number == spec2->numbered[j].number) + { + if (spec1->numbered[i].type != spec2->numbered[j].type) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, + spec2->numbered[j].number); + err = true; + break; + } + j++, i++; + } + else + i++; + } } return err; @@ -430,31 +430,31 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); switch (spec->numbered[i].type) - { - case FAT_CHARACTER: - printf ("c"); - break; - case FAT_INTEGER: - printf ("i"); - break; - case FAT_FLOAT: - printf ("f"); - break; - case FAT_OBJECT_PRETTY: - printf ("s"); - break; - case FAT_OBJECT: - printf ("*"); - break; - default: - abort (); - } + { + case FAT_CHARACTER: + printf ("c"); + break; + case FAT_INTEGER: + printf ("i"); + break; + case FAT_FLOAT: + printf ("f"); + break; + case FAT_OBJECT_PRETTY: + printf ("s"); + break; + case FAT_OBJECT: + printf ("*"); + break; + default: + abort (); + } last = number + 1; } printf (")"); @@ -473,9 +473,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -483,7 +483,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-gcc-internal.c b/gettext-tools/src/format-gcc-internal.c index 15510ba81..7057628da 100644 --- a/gettext-tools/src/format-gcc-internal.c +++ b/gettext-tools/src/format-gcc-internal.c @@ -92,33 +92,33 @@ enum format_arg_type { - FAT_NONE = 0, + FAT_NONE = 0, /* Basic types */ - FAT_INTEGER = 1, - FAT_CHAR = 2, - FAT_STRING = 3, - FAT_POINTER = 4, - FAT_LOCATION = 5, - FAT_TREE = 6, - FAT_TREE_CODE = 7, - FAT_LANGUAGES = 8, + FAT_INTEGER = 1, + FAT_CHAR = 2, + FAT_STRING = 3, + FAT_POINTER = 4, + FAT_LOCATION = 5, + FAT_TREE = 6, + FAT_TREE_CODE = 7, + FAT_LANGUAGES = 8, /* Flags */ - FAT_UNSIGNED = 1 << 4, - FAT_SIZE_LONG = 1 << 5, - FAT_SIZE_LONGLONG = 2 << 5, - FAT_SIZE_WIDE = 3 << 5, - FAT_TREE_DECL = 1 << 7, - FAT_TREE_STATEMENT = 2 << 7, - FAT_TREE_FUNCDECL = 3 << 7, - FAT_TREE_TYPE = 4 << 7, - FAT_TREE_ARGUMENT = 5 << 7, - FAT_TREE_EXPRESSION = 6 << 7, - FAT_TREE_CV = 7 << 7, - FAT_TREE_CODE_BINOP = 1 << 10, - FAT_TREE_CODE_ASSOP = 2 << 10, - FAT_FUNCPARAM = 1 << 12, + FAT_UNSIGNED = 1 << 4, + FAT_SIZE_LONG = 1 << 5, + FAT_SIZE_LONGLONG = 2 << 5, + FAT_SIZE_WIDE = 3 << 5, + FAT_TREE_DECL = 1 << 7, + FAT_TREE_STATEMENT = 2 << 7, + FAT_TREE_FUNCDECL = 3 << 7, + FAT_TREE_TYPE = 4 << 7, + FAT_TREE_ARGUMENT = 5 << 7, + FAT_TREE_EXPRESSION = 6 << 7, + FAT_TREE_CV = 7 << 7, + FAT_TREE_CODE_BINOP = 1 << 10, + FAT_TREE_CODE_ASSOP = 2 << 10, + FAT_FUNCPARAM = 1 << 12, /* Bitmasks */ - FAT_SIZE_MASK = (FAT_SIZE_LONG | FAT_SIZE_LONGLONG | FAT_SIZE_WIDE) + FAT_SIZE_MASK = (FAT_SIZE_LONG | FAT_SIZE_LONGLONG | FAT_SIZE_WIDE) }; #ifdef __cplusplus typedef int format_arg_type_t; @@ -159,7 +159,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -176,346 +176,346 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (*format == '%' || *format == '<' || *format == '>' - || *format == '\'') - ; - else if (*format == 'm') - spec.uses_err_no = true; - else - { - unsigned int number = 0; - unsigned int flag_q = 0; - unsigned int flag_l = 0; - unsigned int flag_w = 0; - unsigned int flag_plus = 0; - unsigned int flag_sharp = 0; - format_arg_type_t size; - format_arg_type_t type; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = INVALID_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - number = m; - format = ++f; - } - } - - /* Parse flags and size. */ - for (;; format++) - { - switch (*format) - { - case 'q': - if (flag_q > 0) - goto invalid_flags; - flag_q = 1; - continue; - case 'l': - if (flag_l > 1 || flag_w) - goto invalid_flags; - flag_l++; - continue; - case 'w': - if (flag_w > 0 || flag_l) - goto invalid_flags; - flag_w = 1; - continue; - case '+': - if (flag_plus > 0) - goto invalid_flags; - flag_plus = 1; - continue; - case '#': - if (flag_sharp > 0) - goto invalid_flags; - flag_sharp = 1; - continue; - invalid_flags: - *invalid_reason = xasprintf (_("In the directive number %u, the flags combination is invalid."), spec.directives); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - default: - break; - } - break; - } - size = (flag_l == 2 ? FAT_SIZE_LONGLONG : - flag_l == 1 ? FAT_SIZE_LONG : - flag_w ? FAT_SIZE_WIDE : - 0); - - if (*format == 'c') - type = FAT_CHAR; - else if (*format == 's') - type = FAT_STRING; - else if (*format == '.') - { - format++; - - if (isdigit (*format)) - { - do - format++; - while (isdigit (*format)); - - if (*format != 's') - { - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, a precision is not allowed before '%c'."), spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - type = FAT_STRING; - } - else if (*format == '*') - { - unsigned int precision_number = 0; - - format++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = INVALID_WIDTH_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - if (unnumbered_arg_count > 0 || number == 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - if (m != number - 1) - { - *invalid_reason = xasprintf (_("In the directive number %u, the argument number for the precision must be equal to %u."), spec.directives, number - 1); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - precision_number = m; - format = ++f; - } - } - - if (precision_number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (unnumbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = precision_number; - spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; - spec.numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (spec.numbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; - spec.numbered[unnumbered_arg_count].type = FAT_INTEGER; - unnumbered_arg_count++; - } - - if (*format == 's') - type = FAT_STRING; - else - { - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, a precision specification is not allowed before '%c'."), spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - } - else - { - *invalid_reason = xasprintf (_("In the directive number %u, the precision specification is invalid."), spec.directives); - FDI_SET (*format == '\0' ? format - 1 : format, - FMTDIR_ERROR); - goto bad_format; - } - } - else if (*format == 'i' || *format == 'd') - type = FAT_INTEGER | size; - else if (*format == 'o' || *format == 'u' || *format == 'x') - type = FAT_INTEGER | FAT_UNSIGNED | size; - else if (*format == 'p') - type = FAT_POINTER; - else if (*format == 'H') - type = FAT_LOCATION; - else if (*format == 'J') - type = FAT_TREE | FAT_TREE_DECL; - else if (*format == 'K') - type = FAT_TREE | FAT_TREE_STATEMENT; - else - { - if (*format == 'D') - type = FAT_TREE | FAT_TREE_DECL; - else if (*format == 'F') - type = FAT_TREE | FAT_TREE_FUNCDECL; - else if (*format == 'T') - type = FAT_TREE | FAT_TREE_TYPE; - else if (*format == 'E') - type = FAT_TREE | FAT_TREE_EXPRESSION; - else if (*format == 'A') - type = FAT_TREE | FAT_TREE_ARGUMENT; - else if (*format == 'C') - type = FAT_TREE_CODE; - else if (*format == 'L') - type = FAT_LANGUAGES; - else if (*format == 'O') - type = FAT_TREE_CODE | FAT_TREE_CODE_BINOP; - else if (*format == 'P') - type = FAT_INTEGER | FAT_FUNCPARAM; - else if (*format == 'Q') - type = FAT_TREE_CODE | FAT_TREE_CODE_ASSOP; - else if (*format == 'V') - type = FAT_TREE | FAT_TREE_CV; - else - { - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - (*format == 'c' - || *format == 's' - || *format == 'i' || *format == 'd' - || *format == 'o' || *format == 'u' || *format == 'x' - || *format == 'H' - ? xasprintf (_("In the directive number %u, flags are not allowed before '%c'."), spec.directives, *format) - : INVALID_CONVERSION_SPECIFIER (spec.directives, - *format)); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - } - - if (number) - { - /* Numbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (unnumbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = type; - spec.numbered_arg_count++; - } - else - { - /* Unnumbered argument. */ - - /* Numbered and unnumbered specifications are exclusive. */ - if (spec.numbered_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == unnumbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; - spec.numbered[unnumbered_arg_count].type = type; - unnumbered_arg_count++; - } - } - - FDI_SET (format, FMTDIR_END); - - format++; + /* A directive. */ + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (*format == '%' || *format == '<' || *format == '>' + || *format == '\'') + ; + else if (*format == 'm') + spec.uses_err_no = true; + else + { + unsigned int number = 0; + unsigned int flag_q = 0; + unsigned int flag_l = 0; + unsigned int flag_w = 0; + unsigned int flag_plus = 0; + unsigned int flag_sharp = 0; + format_arg_type_t size; + format_arg_type_t type; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = INVALID_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + number = m; + format = ++f; + } + } + + /* Parse flags and size. */ + for (;; format++) + { + switch (*format) + { + case 'q': + if (flag_q > 0) + goto invalid_flags; + flag_q = 1; + continue; + case 'l': + if (flag_l > 1 || flag_w) + goto invalid_flags; + flag_l++; + continue; + case 'w': + if (flag_w > 0 || flag_l) + goto invalid_flags; + flag_w = 1; + continue; + case '+': + if (flag_plus > 0) + goto invalid_flags; + flag_plus = 1; + continue; + case '#': + if (flag_sharp > 0) + goto invalid_flags; + flag_sharp = 1; + continue; + invalid_flags: + *invalid_reason = xasprintf (_("In the directive number %u, the flags combination is invalid."), spec.directives); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + default: + break; + } + break; + } + size = (flag_l == 2 ? FAT_SIZE_LONGLONG : + flag_l == 1 ? FAT_SIZE_LONG : + flag_w ? FAT_SIZE_WIDE : + 0); + + if (*format == 'c') + type = FAT_CHAR; + else if (*format == 's') + type = FAT_STRING; + else if (*format == '.') + { + format++; + + if (isdigit (*format)) + { + do + format++; + while (isdigit (*format)); + + if (*format != 's') + { + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + xasprintf (_("In the directive number %u, a precision is not allowed before '%c'."), spec.directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + + type = FAT_STRING; + } + else if (*format == '*') + { + unsigned int precision_number = 0; + + format++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = INVALID_WIDTH_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + if (unnumbered_arg_count > 0 || number == 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + if (m != number - 1) + { + *invalid_reason = xasprintf (_("In the directive number %u, the argument number for the precision must be equal to %u."), spec.directives, number - 1); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + precision_number = m; + format = ++f; + } + } + + if (precision_number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (unnumbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = precision_number; + spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; + spec.numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (spec.numbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; + spec.numbered[unnumbered_arg_count].type = FAT_INTEGER; + unnumbered_arg_count++; + } + + if (*format == 's') + type = FAT_STRING; + else + { + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + xasprintf (_("In the directive number %u, a precision specification is not allowed before '%c'."), spec.directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + } + else + { + *invalid_reason = xasprintf (_("In the directive number %u, the precision specification is invalid."), spec.directives); + FDI_SET (*format == '\0' ? format - 1 : format, + FMTDIR_ERROR); + goto bad_format; + } + } + else if (*format == 'i' || *format == 'd') + type = FAT_INTEGER | size; + else if (*format == 'o' || *format == 'u' || *format == 'x') + type = FAT_INTEGER | FAT_UNSIGNED | size; + else if (*format == 'p') + type = FAT_POINTER; + else if (*format == 'H') + type = FAT_LOCATION; + else if (*format == 'J') + type = FAT_TREE | FAT_TREE_DECL; + else if (*format == 'K') + type = FAT_TREE | FAT_TREE_STATEMENT; + else + { + if (*format == 'D') + type = FAT_TREE | FAT_TREE_DECL; + else if (*format == 'F') + type = FAT_TREE | FAT_TREE_FUNCDECL; + else if (*format == 'T') + type = FAT_TREE | FAT_TREE_TYPE; + else if (*format == 'E') + type = FAT_TREE | FAT_TREE_EXPRESSION; + else if (*format == 'A') + type = FAT_TREE | FAT_TREE_ARGUMENT; + else if (*format == 'C') + type = FAT_TREE_CODE; + else if (*format == 'L') + type = FAT_LANGUAGES; + else if (*format == 'O') + type = FAT_TREE_CODE | FAT_TREE_CODE_BINOP; + else if (*format == 'P') + type = FAT_INTEGER | FAT_FUNCPARAM; + else if (*format == 'Q') + type = FAT_TREE_CODE | FAT_TREE_CODE_ASSOP; + else if (*format == 'V') + type = FAT_TREE | FAT_TREE_CV; + else + { + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + (*format == 'c' + || *format == 's' + || *format == 'i' || *format == 'd' + || *format == 'o' || *format == 'u' || *format == 'x' + || *format == 'H' + ? xasprintf (_("In the directive number %u, flags are not allowed before '%c'."), spec.directives, *format) + : INVALID_CONVERSION_SPECIFIER (spec.directives, + *format)); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + } + + if (number) + { + /* Numbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (unnumbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered[spec.numbered_arg_count].type = type; + spec.numbered_arg_count++; + } + else + { + /* Unnumbered argument. */ + + /* Numbered and unnumbered specifications are exclusive. */ + if (spec.numbered_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == unnumbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[unnumbered_arg_count].number = unnumbered_arg_count + 1; + spec.numbered[unnumbered_arg_count].type = type; + unnumbered_arg_count++; + } + } + + FDI_SET (format, FMTDIR_END); + + format++; } /* Convert the unnumbered argument array to numbered arguments. */ @@ -528,44 +528,44 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (spec.numbered, spec.numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < spec.numbered_arg_count; i++) - if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) - { - format_arg_type_t type1 = spec.numbered[i].type; - format_arg_type_t type2 = spec.numbered[j-1].type; - format_arg_type_t type_both; - - if (type1 == type2) - type_both = type1; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); - err = true; - } - - spec.numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - spec.numbered[j].number = spec.numbered[i].number; - spec.numbered[j].type = spec.numbered[i].type; - } - j++; - } + if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) + { + format_arg_type_t type1 = spec.numbered[i].type; + format_arg_type_t type2 = spec.numbered[j-1].type; + format_arg_type_t type_both; + + if (type1 == type2) + type_both = type1; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); + err = true; + } + + spec.numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + spec.numbered[j].number = spec.numbered[i].number; + spec.numbered[j].type = spec.numbered[i].type; + } + j++; + } spec.numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -598,8 +598,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -612,74 +612,74 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->numbered_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } /* Check the argument types are the same. */ if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } + for (i = 0, j = 0; j < n2; ) + { + if (spec1->numbered[i].number == spec2->numbered[j].number) + { + if (spec1->numbered[i].type != spec2->numbered[j].type) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, + spec2->numbered[j].number); + err = true; + break; + } + j++, i++; + } + else + i++; + } } /* Check that the use of err_no is the same. */ if (spec1->uses_err_no != spec2->uses_err_no) { if (error_logger) - { - if (spec1->uses_err_no) - error_logger (_("'%s' uses %%m but '%s' doesn't"), - pretty_msgid, pretty_msgstr); - else - error_logger (_("'%s' does not use %%m but '%s' uses %%m"), - pretty_msgid, pretty_msgstr); - } + { + if (spec1->uses_err_no) + error_logger (_("'%s' uses %%m but '%s' doesn't"), + pretty_msgid, pretty_msgstr); + else + error_logger (_("'%s' does not use %%m but '%s' uses %%m"), + pretty_msgid, pretty_msgstr); + } err = true; } @@ -724,85 +724,85 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); if (spec->numbered[i].type & FAT_UNSIGNED) - printf ("[unsigned]"); + printf ("[unsigned]"); switch (spec->numbered[i].type & FAT_SIZE_MASK) - { - case 0: - break; - case FAT_SIZE_LONG: - printf ("[long]"); - break; - case FAT_SIZE_LONGLONG: - printf ("[long long]"); - break; - case FAT_SIZE_WIDE: - printf ("[host-wide]"); - break; - default: - abort (); - } + { + case 0: + break; + case FAT_SIZE_LONG: + printf ("[long]"); + break; + case FAT_SIZE_LONGLONG: + printf ("[long long]"); + break; + case FAT_SIZE_WIDE: + printf ("[host-wide]"); + break; + default: + abort (); + } switch (spec->numbered[i].type & ~(FAT_UNSIGNED | FAT_SIZE_MASK)) - { - case FAT_INTEGER: - printf ("i"); - break; - case FAT_INTEGER | FAT_FUNCPARAM: - printf ("P"); - break; - case FAT_CHAR: - printf ("c"); - break; - case FAT_STRING: - printf ("s"); - break; - case FAT_POINTER: - printf ("p"); - break; - case FAT_LOCATION: - printf ("H"); - break; - case FAT_TREE | FAT_TREE_DECL: - printf ("D"); - break; - case FAT_TREE | FAT_TREE_STATEMENT: - printf ("K"); - break; - case FAT_TREE | FAT_TREE_FUNCDECL: - printf ("F"); - break; - case FAT_TREE | FAT_TREE_TYPE: - printf ("T"); - break; - case FAT_TREE | FAT_TREE_ARGUMENT: - printf ("A"); - break; - case FAT_TREE | FAT_TREE_EXPRESSION: - printf ("E"); - break; - case FAT_TREE | FAT_TREE_CV: - printf ("V"); - break; - case FAT_TREE_CODE: - printf ("C"); - break; - case FAT_TREE_CODE | FAT_TREE_CODE_BINOP: - printf ("O"); - break; - case FAT_TREE_CODE | FAT_TREE_CODE_ASSOP: - printf ("Q"); - break; - case FAT_LANGUAGES: - printf ("L"); - break; - default: - abort (); - } + { + case FAT_INTEGER: + printf ("i"); + break; + case FAT_INTEGER | FAT_FUNCPARAM: + printf ("P"); + break; + case FAT_CHAR: + printf ("c"); + break; + case FAT_STRING: + printf ("s"); + break; + case FAT_POINTER: + printf ("p"); + break; + case FAT_LOCATION: + printf ("H"); + break; + case FAT_TREE | FAT_TREE_DECL: + printf ("D"); + break; + case FAT_TREE | FAT_TREE_STATEMENT: + printf ("K"); + break; + case FAT_TREE | FAT_TREE_FUNCDECL: + printf ("F"); + break; + case FAT_TREE | FAT_TREE_TYPE: + printf ("T"); + break; + case FAT_TREE | FAT_TREE_ARGUMENT: + printf ("A"); + break; + case FAT_TREE | FAT_TREE_EXPRESSION: + printf ("E"); + break; + case FAT_TREE | FAT_TREE_CV: + printf ("V"); + break; + case FAT_TREE_CODE: + printf ("C"); + break; + case FAT_TREE_CODE | FAT_TREE_CODE_BINOP: + printf ("O"); + break; + case FAT_TREE_CODE | FAT_TREE_CODE_ASSOP: + printf ("Q"); + break; + case FAT_LANGUAGES: + printf ("L"); + break; + default: + abort (); + } last = number + 1; } printf (")"); @@ -823,9 +823,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -833,7 +833,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-gfc-internal.c b/gettext-tools/src/format-gfc-internal.c index ebe9ddef4..4fbbc66db 100644 --- a/gettext-tools/src/format-gfc-internal.c +++ b/gettext-tools/src/format-gfc-internal.c @@ -62,18 +62,18 @@ enum format_arg_type { - FAT_NONE = 0, + FAT_NONE = 0, /* Basic types */ - FAT_VOID = 1, - FAT_INTEGER = 2, - FAT_CHAR = 3, - FAT_STRING = 4, - FAT_LOCUS = 5, + FAT_VOID = 1, + FAT_INTEGER = 2, + FAT_CHAR = 3, + FAT_STRING = 4, + FAT_LOCUS = 5, /* Flags */ - FAT_UNSIGNED = 1 << 3, - FAT_SIZE_LONG = 1 << 4, + FAT_UNSIGNED = 1 << 3, + FAT_SIZE_LONG = 1 << 4, /* Bitmasks */ - FAT_SIZE_MASK = FAT_SIZE_LONG + FAT_SIZE_MASK = FAT_SIZE_LONG }; #ifdef __cplusplus typedef int format_arg_type_t; @@ -118,7 +118,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -138,96 +138,96 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (*format != '%') - { - format_arg_type_t type; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = INVALID_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - number = m; - format = ++f; - } - } - - if (*format == 'C') - { - type = FAT_VOID; - spec.uses_currentloc = true; - } - else if (*format == 'L') - type = FAT_LOCUS; - else if (*format == 'c') - type = FAT_CHAR; - else if (*format == 's') - type = FAT_STRING; - else - { - format_arg_type_t size = 0; - - if (*format == 'l') - { - ++format; - size = FAT_SIZE_LONG; - } - - if (*format == 'i' || *format == 'd') - type = FAT_INTEGER | size; - else if (*format == 'u') - type = FAT_INTEGER | FAT_UNSIGNED | size; - else - { - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - } - - if (allocated == numbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = number; - numbered[numbered_arg_count].type = type; - numbered_arg_count++; + /* A directive. */ + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (*format != '%') + { + format_arg_type_t type; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = INVALID_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + number = m; + format = ++f; + } + } + + if (*format == 'C') + { + type = FAT_VOID; + spec.uses_currentloc = true; + } + else if (*format == 'L') + type = FAT_LOCUS; + else if (*format == 'c') + type = FAT_CHAR; + else if (*format == 's') + type = FAT_STRING; + else + { + format_arg_type_t size = 0; + + if (*format == 'l') + { + ++format; + size = FAT_SIZE_LONG; + } + + if (*format == 'i' || *format == 'd') + type = FAT_INTEGER | size; + else if (*format == 'u') + type = FAT_INTEGER | FAT_UNSIGNED | size; + else + { + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (spec.directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + } + + if (allocated == numbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = number; + numbered[numbered_arg_count].type = type; + numbered_arg_count++; number++; - } + } - FDI_SET (format, FMTDIR_END); + FDI_SET (format, FMTDIR_END); - format++; + format++; } /* Sort the numbered argument array, and eliminate duplicates. */ @@ -237,44 +237,44 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (numbered, numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < numbered_arg_count; i++) - if (j > 0 && numbered[i].number == numbered[j-1].number) - { - format_arg_type_t type1 = numbered[i].type; - format_arg_type_t type2 = numbered[j-1].type; - format_arg_type_t type_both; - - if (type1 == type2) - type_both = type1; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (numbered[i].number); - err = true; - } - - numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - numbered[j].number = numbered[i].number; - numbered[j].type = numbered[i].type; - } - j++; - } + if (j > 0 && numbered[i].number == numbered[j-1].number) + { + format_arg_type_t type1 = numbered[i].type; + format_arg_type_t type2 = numbered[j-1].type; + format_arg_type_t type_both; + + if (type1 == type2) + type_both = type1; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (numbered[i].number); + err = true; + } + + numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + numbered[j].number = numbered[i].number; + numbered[j].type = numbered[i].type; + } + j++; + } numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } /* Verify that the format strings uses all arguments up to the highest @@ -284,11 +284,11 @@ format_parse (const char *format, bool translated, char *fdi, for (i = 0; i < numbered_arg_count; i++) if (numbered[i].number != i + 1) - { - *invalid_reason = - xasprintf (_("The string refers to argument number %u but ignores argument number %u."), numbered[i].number, i + 1); - goto bad_format; - } + { + *invalid_reason = + xasprintf (_("The string refers to argument number %u but ignores argument number %u."), numbered[i].number, i + 1); + goto bad_format; + } } /* So now the numbered arguments array is equivalent to a sequence @@ -299,17 +299,17 @@ format_parse (const char *format, bool translated, char *fdi, spec.unnumbered_arg_count = 0; for (i = 0; i < numbered_arg_count; i++) if (numbered[i].type != FAT_VOID) - spec.unnumbered_arg_count++; + spec.unnumbered_arg_count++; if (spec.unnumbered_arg_count > 0) { - unsigned int j; + unsigned int j; - spec.unnumbered = XNMALLOC (spec.unnumbered_arg_count, struct unnumbered_arg); - j = 0; - for (i = 0; i < numbered_arg_count; i++) - if (numbered[i].type != FAT_VOID) - spec.unnumbered[j++].type = numbered[i].type; + spec.unnumbered = XNMALLOC (spec.unnumbered_arg_count, struct unnumbered_arg); + j = 0; + for (i = 0; i < numbered_arg_count; i++) + if (numbered[i].type != FAT_VOID) + spec.unnumbered[j++].type = numbered[i].type; } else spec.unnumbered = NULL; @@ -346,8 +346,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -360,32 +360,32 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, : spec1->unnumbered_arg_count < spec2->unnumbered_arg_count) { if (error_logger) - error_logger (_("number of format specifications in '%s' and '%s' does not match"), - pretty_msgid, pretty_msgstr); + error_logger (_("number of format specifications in '%s' and '%s' does not match"), + pretty_msgid, pretty_msgstr); err = true; } else for (i = 0; i < spec2->unnumbered_arg_count; i++) if (spec1->unnumbered[i].type != spec2->unnumbered[i].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, i + 1); - err = true; - } + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, i + 1); + err = true; + } /* Check that the use of currentloc is the same. */ if (spec1->uses_currentloc != spec2->uses_currentloc) { if (error_logger) - { - if (spec1->uses_currentloc) - error_logger (_("'%s' uses %%C but '%s' doesn't"), - pretty_msgid, pretty_msgstr); - else - error_logger (_("'%s' does not use %%C but '%s' uses %%C"), - pretty_msgid, pretty_msgstr); - } + { + if (spec1->uses_currentloc) + error_logger (_("'%s' uses %%C but '%s' doesn't"), + pretty_msgid, pretty_msgstr); + else + error_logger (_("'%s' does not use %%C but '%s' uses %%C"), + pretty_msgid, pretty_msgstr); + } err = true; } @@ -426,36 +426,36 @@ format_print (void *descr) for (i = 0; i < spec->unnumbered_arg_count; i++) { if (i > 0) - printf (" "); + printf (" "); if (spec->unnumbered[i].type & FAT_UNSIGNED) - printf ("[unsigned]"); + printf ("[unsigned]"); switch (spec->unnumbered[i].type & FAT_SIZE_MASK) - { - case 0: - break; - case FAT_SIZE_LONG: - printf ("[long]"); - break; - default: - abort (); - } + { + case 0: + break; + case FAT_SIZE_LONG: + printf ("[long]"); + break; + default: + abort (); + } switch (spec->unnumbered[i].type & ~(FAT_UNSIGNED | FAT_SIZE_MASK)) - { - case FAT_INTEGER: - printf ("i"); - break; - case FAT_CHAR: - printf ("c"); - break; - case FAT_STRING: - printf ("s"); - break; - case FAT_LOCUS: - printf ("L"); - break; - default: - abort (); - } + { + case FAT_INTEGER: + printf ("i"); + break; + case FAT_CHAR: + printf ("c"); + break; + case FAT_STRING: + printf ("s"); + break; + case FAT_LOCUS: + printf ("L"); + break; + default: + abort (); + } } printf (")"); if (spec->uses_currentloc) @@ -475,9 +475,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -485,7 +485,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-java.c b/gettext-tools/src/format-java.c index dfc757ecd..5196835d1 100644 --- a/gettext-tools/src/format-java.c +++ b/gettext-tools/src/format-java.c @@ -106,9 +106,9 @@ enum format_arg_type { FAT_NONE, - FAT_OBJECT, /* java.lang.Object */ - FAT_NUMBER, /* java.lang.Number */ - FAT_DATE /* java.util.Date */ + FAT_OBJECT, /* java.lang.Object */ + FAT_NUMBER, /* java.lang.Number */ + FAT_DATE /* java.util.Date */ }; struct numbered_arg @@ -130,7 +130,7 @@ struct spec static bool date_format_parse (const char *format); static bool number_format_parse (const char *format); static bool choice_format_parse (const char *format, struct spec *spec, - char **invalid_reason); + char **invalid_reason); /* Quote handling: @@ -149,7 +149,7 @@ static bool choice_format_parse (const char *format, struct spec *spec, Extracts argument type information into spec. */ static bool message_format_parse (const char *format, char *fdi, struct spec *spec, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; bool quoting = false; @@ -158,199 +158,199 @@ message_format_parse (const char *format, char *fdi, struct spec *spec, { HANDLE_QUOTE; if (!quoting && *format == '{') - { - unsigned int depth; - const char *element_start; - const char *element_end; - size_t n; - char *element_alloced; - char *element; - unsigned int number; - enum format_arg_type type; - - FDI_SET (format, FMTDIR_START); - spec->directives++; - - element_start = ++format; - depth = 0; - for (; *format != '\0'; format++) - { - if (*format == '{') - depth++; - else if (*format == '}') - { - if (depth == 0) - break; - else - depth--; - } - } - if (*format == '\0') - { - *invalid_reason = - xstrdup (_("The string ends in the middle of a directive: found '{' without matching '}'.")); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - element_end = format++; - - n = element_end - element_start; - element = element_alloced = (char *) xmalloca (n + 1); - memcpy (element, element_start, n); - element[n] = '\0'; - - if (!c_isdigit (*element)) - { - *invalid_reason = - xasprintf (_("In the directive number %u, '{' is not followed by an argument number."), spec->directives); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - number = 0; - do - { - number = 10 * number + (*element - '0'); - element++; - } - while (c_isdigit (*element)); - - type = FAT_OBJECT; - if (*element == '\0') - ; - else if (strncmp (element, ",time", 5) == 0 - || strncmp (element, ",date", 5) == 0) - { - type = FAT_DATE; - element += 5; - if (*element == '\0') - ; - else if (*element == ',') - { - element++; - if (strcmp (element, "short") == 0 - || strcmp (element, "medium") == 0 - || strcmp (element, "long") == 0 - || strcmp (element, "full") == 0 - || date_format_parse (element)) - ; - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, the substring \"%s\" is not a valid date/time style."), spec->directives, element); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else - { - *element = '\0'; - element -= 4; - *invalid_reason = - xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else if (strncmp (element, ",number", 7) == 0) - { - type = FAT_NUMBER; - element += 7; - if (*element == '\0') - ; - else if (*element == ',') - { - element++; - if (strcmp (element, "currency") == 0 - || strcmp (element, "percent") == 0 - || strcmp (element, "integer") == 0 - || number_format_parse (element)) - ; - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, the substring \"%s\" is not a valid number style."), spec->directives, element); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else - { - *element = '\0'; - element -= 6; - *invalid_reason = - xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else if (strncmp (element, ",choice", 7) == 0) - { - type = FAT_NUMBER; /* because ChoiceFormat extends NumberFormat */ - element += 7; - if (*element == '\0') - ; - else if (*element == ',') - { - element++; - if (choice_format_parse (element, spec, invalid_reason)) - ; - else - { - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else - { - *element = '\0'; - element -= 6; - *invalid_reason = - xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - } - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, the argument number is not followed by a comma and one of \"%s\", \"%s\", \"%s\", \"%s\"."), spec->directives, "time", "date", "number", "choice"); - FDI_SET (format - 1, FMTDIR_ERROR); - freea (element_alloced); - return false; - } - freea (element_alloced); - - if (spec->allocated == spec->numbered_arg_count) - { - spec->allocated = 2 * spec->allocated + 1; - spec->numbered = (struct numbered_arg *) xrealloc (spec->numbered, spec->allocated * sizeof (struct numbered_arg)); - } - spec->numbered[spec->numbered_arg_count].number = number; - spec->numbered[spec->numbered_arg_count].type = type; - spec->numbered_arg_count++; - - FDI_SET (format - 1, FMTDIR_END); - } + { + unsigned int depth; + const char *element_start; + const char *element_end; + size_t n; + char *element_alloced; + char *element; + unsigned int number; + enum format_arg_type type; + + FDI_SET (format, FMTDIR_START); + spec->directives++; + + element_start = ++format; + depth = 0; + for (; *format != '\0'; format++) + { + if (*format == '{') + depth++; + else if (*format == '}') + { + if (depth == 0) + break; + else + depth--; + } + } + if (*format == '\0') + { + *invalid_reason = + xstrdup (_("The string ends in the middle of a directive: found '{' without matching '}'.")); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + element_end = format++; + + n = element_end - element_start; + element = element_alloced = (char *) xmalloca (n + 1); + memcpy (element, element_start, n); + element[n] = '\0'; + + if (!c_isdigit (*element)) + { + *invalid_reason = + xasprintf (_("In the directive number %u, '{' is not followed by an argument number."), spec->directives); + FDI_SET (format - 1, FMTDIR_ERROR); + freea (element_alloced); + return false; + } + number = 0; + do + { + number = 10 * number + (*element - '0'); + element++; + } + while (c_isdigit (*element)); + + type = FAT_OBJECT; + if (*element == '\0') + ; + else if (strncmp (element, ",time", 5) == 0 + || strncmp (element, ",date", 5) == 0) + { + type = FAT_DATE; + element += 5; + if (*element == '\0') + ; + else if (*element == ',') + { + element++; + if (strcmp (element, "short") == 0 + || strcmp (element, "medium") == 0 + || strcmp (element, "long") == 0 + || strcmp (element, "full") == 0 + || date_format_parse (element)) + ; + else + { + *invalid_reason = + xasprintf (_("In the directive number %u, the substring \"%s\" is not a valid date/time style."), spec->directives, element); + FDI_SET (format - 1, FMTDIR_ERROR); + freea (element_alloced); + return false; + } + } + else + { + *element = '\0'; + element -= 4; + *invalid_reason = + xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); + FDI_SET (format - 1, FMTDIR_ERROR); + freea (element_alloced); + return false; + } + } + else if (strncmp (element, ",number", 7) == 0) + { + type = FAT_NUMBER; + element += 7; + if (*element == '\0') + ; + else if (*element == ',') + { + element++; + if (strcmp (element, "currency") == 0 + || strcmp (element, "percent") == 0 + || strcmp (element, "integer") == 0 + || number_format_parse (element)) + ; + else + { + *invalid_reason = + xasprintf (_("In the directive number %u, the substring \"%s\" is not a valid number style."), spec->directives, element); + FDI_SET (format - 1, FMTDIR_ERROR); + freea (element_alloced); + return false; + } + } + else + { + *element = '\0'; + element -= 6; + *invalid_reason = + xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); + FDI_SET (format - 1, FMTDIR_ERROR); + freea (element_alloced); + return false; + } + } + else if (strncmp (element, ",choice", 7) == 0) + { + type = FAT_NUMBER; /* because ChoiceFormat extends NumberFormat */ + element += 7; + if (*element == '\0') + ; + else if (*element == ',') + { + element++; + if (choice_format_parse (element, spec, invalid_reason)) + ; + else + { + FDI_SET (format - 1, FMTDIR_ERROR); + freea (element_alloced); + return false; + } + } + else + { + *element = '\0'; + element -= 6; + *invalid_reason = + xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); + FDI_SET (format - 1, FMTDIR_ERROR); + freea (element_alloced); + return false; + } + } + else + { + *invalid_reason = + xasprintf (_("In the directive number %u, the argument number is not followed by a comma and one of \"%s\", \"%s\", \"%s\", \"%s\"."), spec->directives, "time", "date", "number", "choice"); + FDI_SET (format - 1, FMTDIR_ERROR); + freea (element_alloced); + return false; + } + freea (element_alloced); + + if (spec->allocated == spec->numbered_arg_count) + { + spec->allocated = 2 * spec->allocated + 1; + spec->numbered = (struct numbered_arg *) xrealloc (spec->numbered, spec->allocated * sizeof (struct numbered_arg)); + } + spec->numbered[spec->numbered_arg_count].number = number; + spec->numbered[spec->numbered_arg_count].type = type; + spec->numbered_arg_count++; + + FDI_SET (format - 1, FMTDIR_END); + } /* The doc says "ab}de" is invalid. Even though JDK accepts it. */ else if (!quoting && *format == '}') - { - FDI_SET (format, FMTDIR_START); - *invalid_reason = - xstrdup (_("The string starts in the middle of a directive: found '}' without matching '{'.")); - FDI_SET (format, FMTDIR_ERROR); - return false; - } + { + FDI_SET (format, FMTDIR_START); + *invalid_reason = + xstrdup (_("The string starts in the middle of a directive: found '}' without matching '{'.")); + FDI_SET (format, FMTDIR_ERROR); + return false; + } else if (*format != '\0') - format++; + format++; else - break; + break; } return true; @@ -401,110 +401,110 @@ number_format_parse (const char *format) { /* Parse prefix. */ while (*format != '\0' - && !(!quoting && (*format == '0' || *format == '#'))) - { - if (format[0] == '\\') - { - if (format[1] == 'u' - && c_isxdigit (format[2]) - && c_isxdigit (format[3]) - && c_isxdigit (format[4]) - && c_isxdigit (format[5])) - format += 6; - else - format += 2; - } - else - format += 1; - HANDLE_QUOTE; - } + && !(!quoting && (*format == '0' || *format == '#'))) + { + if (format[0] == '\\') + { + if (format[1] == 'u' + && c_isxdigit (format[2]) + && c_isxdigit (format[3]) + && c_isxdigit (format[4]) + && c_isxdigit (format[5])) + format += 6; + else + format += 2; + } + else + format += 1; + HANDLE_QUOTE; + } /* Parse integer. */ if (!(!quoting && (*format == '0' || *format == '#'))) - return false; + return false; while (!quoting && *format == '#') - { - format++; - HANDLE_QUOTE; - if (!quoting && *format == ',') - { - format++; - HANDLE_QUOTE; - } - } + { + format++; + HANDLE_QUOTE; + if (!quoting && *format == ',') + { + format++; + HANDLE_QUOTE; + } + } while (!quoting && *format == '0') - { - format++; - HANDLE_QUOTE; - if (!quoting && *format == ',') - { - format++; - HANDLE_QUOTE; - } - } + { + format++; + HANDLE_QUOTE; + if (!quoting && *format == ',') + { + format++; + HANDLE_QUOTE; + } + } /* Parse fraction. */ if (!quoting && *format == '.') - { - format++; - HANDLE_QUOTE; - while (!quoting && *format == '0') - { - format++; - HANDLE_QUOTE; - } - while (!quoting && *format == '#') - { - format++; - HANDLE_QUOTE; - } - } + { + format++; + HANDLE_QUOTE; + while (!quoting && *format == '0') + { + format++; + HANDLE_QUOTE; + } + while (!quoting && *format == '#') + { + format++; + HANDLE_QUOTE; + } + } /* Parse exponent. */ if (!quoting && *format == 'E') - { - const char *format_save = format; - format++; - HANDLE_QUOTE; - if (!quoting && *format == '0') - { - do - { - format++; - HANDLE_QUOTE; - } - while (!quoting && *format == '0'); - } - else - { - /* Back up. */ - format = format_save; - quoting = false; - } - } + { + const char *format_save = format; + format++; + HANDLE_QUOTE; + if (!quoting && *format == '0') + { + do + { + format++; + HANDLE_QUOTE; + } + while (!quoting && *format == '0'); + } + else + { + /* Back up. */ + format = format_save; + quoting = false; + } + } /* Parse suffix. */ while (*format != '\0' - && (seen_semicolon || !(!quoting && *format == ';'))) - { - if (format[0] == '\\') - { - if (format[1] == 'u' - && c_isxdigit (format[2]) - && c_isxdigit (format[3]) - && c_isxdigit (format[4]) - && c_isxdigit (format[5])) - format += 6; - else - format += 2; - } - else - format += 1; - HANDLE_QUOTE; - } + && (seen_semicolon || !(!quoting && *format == ';'))) + { + if (format[0] == '\\') + { + if (format[1] == 'u' + && c_isxdigit (format[2]) + && c_isxdigit (format[3]) + && c_isxdigit (format[4]) + && c_isxdigit (format[5])) + format += 6; + else + format += 2; + } + else + format += 1; + HANDLE_QUOTE; + } if (seen_semicolon || !(!quoting && *format == ';')) - break; + break; } return (*format == '\0'); @@ -514,7 +514,7 @@ number_format_parse (const char *format) Extracts argument type information into spec. */ static bool choice_format_parse (const char *format, struct spec *spec, - char **invalid_reason) + char **invalid_reason) { /* Pattern syntax: pattern := | choice | choice '|' pattern @@ -532,7 +532,7 @@ choice_format_parse (const char *format, struct spec *spec, for (;;) { /* Don't bother looking too precisely into the syntax of the number. - It can contain various Unicode characters. */ + It can contain various Unicode characters. */ bool number_nonempty; char *msgformat; char *mp; @@ -541,70 +541,70 @@ choice_format_parse (const char *format, struct spec *spec, /* Parse number. */ number_nonempty = false; while (*format != '\0' - && !(!quoting && (*format == '<' || *format == '#' - || strncmp (format, "\\u2264", 6) == 0 - || *format == '|'))) - { - if (format[0] == '\\') - { - if (format[1] == 'u' - && c_isxdigit (format[2]) - && c_isxdigit (format[3]) - && c_isxdigit (format[4]) - && c_isxdigit (format[5])) - format += 6; - else - format += 2; - } - else - format += 1; - number_nonempty = true; - HANDLE_QUOTE; - } + && !(!quoting && (*format == '<' || *format == '#' + || strncmp (format, "\\u2264", 6) == 0 + || *format == '|'))) + { + if (format[0] == '\\') + { + if (format[1] == 'u' + && c_isxdigit (format[2]) + && c_isxdigit (format[3]) + && c_isxdigit (format[4]) + && c_isxdigit (format[5])) + format += 6; + else + format += 2; + } + else + format += 1; + number_nonempty = true; + HANDLE_QUOTE; + } /* Short clause at end of pattern is valid and is ignored! */ if (*format == '\0') - break; + break; if (!number_nonempty) - { - *invalid_reason = - xasprintf (_("In the directive number %u, a choice contains no number."), spec->directives); - return false; - } + { + *invalid_reason = + xasprintf (_("In the directive number %u, a choice contains no number."), spec->directives); + return false; + } if (*format == '<' || *format == '#') - format += 1; + format += 1; else if (strncmp (format, "\\u2264", 6) == 0) - format += 6; + format += 6; else - { - *invalid_reason = - xasprintf (_("In the directive number %u, a choice contains a number that is not followed by '<', '#' or '%s'."), spec->directives, "\\u2264"); - return false; - } + { + *invalid_reason = + xasprintf (_("In the directive number %u, a choice contains a number that is not followed by '<', '#' or '%s'."), spec->directives, "\\u2264"); + return false; + } HANDLE_QUOTE; msgformat = (char *) xmalloca (strlen (format) + 1); mp = msgformat; while (*format != '\0' && !(!quoting && *format == '|')) - { - *mp++ = *format++; - HANDLE_QUOTE; - } + { + *mp++ = *format++; + HANDLE_QUOTE; + } *mp = '\0'; msgformat_valid = - message_format_parse (msgformat, NULL, spec, invalid_reason); + message_format_parse (msgformat, NULL, spec, invalid_reason); freea (msgformat); if (!msgformat_valid) - return false; + return false; if (*format == '\0') - break; + break; format++; HANDLE_QUOTE; @@ -624,7 +624,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { struct spec spec; struct spec *result; @@ -644,46 +644,46 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (spec.numbered, spec.numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < spec.numbered_arg_count; i++) - if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) - { - enum format_arg_type type1 = spec.numbered[i].type; - enum format_arg_type type2 = spec.numbered[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2 || type2 == FAT_OBJECT) - type_both = type1; - else if (type1 == FAT_OBJECT) - type_both = type2; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); - err = true; - } - - spec.numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - spec.numbered[j].number = spec.numbered[i].number; - spec.numbered[j].type = spec.numbered[i].type; - } - j++; - } + if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) + { + enum format_arg_type type1 = spec.numbered[i].type; + enum format_arg_type type2 = spec.numbered[j-1].type; + enum format_arg_type type_both; + + if (type1 == type2 || type2 == FAT_OBJECT) + type_both = type1; + else if (type1 == FAT_OBJECT) + type_both = type2; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); + err = true; + } + + spec.numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + spec.numbered[j].number = spec.numbered[i].number; + spec.numbered[j].type = spec.numbered[i].type; + } + j++; + } spec.numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -716,8 +716,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -730,60 +730,60 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->numbered_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument {%u}, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument {%u} doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument {%u}, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument {%u} doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } /* Check the argument types are the same. */ if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument {%u} are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } + for (i = 0, j = 0; j < n2; ) + { + if (spec1->numbered[i].number == spec2->numbered[j].number) + { + if (spec1->numbered[i].type != spec2->numbered[j].type) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument {%u} are not the same"), + pretty_msgid, pretty_msgstr, + spec2->numbered[j].number); + err = true; + break; + } + j++, i++; + } + else + i++; + } } return err; @@ -827,25 +827,25 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); switch (spec->numbered[i].type) - { - case FAT_OBJECT: - printf ("*"); - break; - case FAT_NUMBER: - printf ("Number"); - break; - case FAT_DATE: - printf ("Date"); - break; - default: - abort (); - } + { + case FAT_OBJECT: + printf ("*"); + break; + case FAT_NUMBER: + printf ("Number"); + break; + case FAT_DATE: + printf ("Date"); + break; + default: + abort (); + } last = number + 1; } printf (")"); @@ -864,9 +864,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -874,7 +874,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-kde.c b/gettext-tools/src/format-kde.c index f08576c89..90e887d89 100644 --- a/gettext-tools/src/format-kde.c +++ b/gettext-tools/src/format-kde.c @@ -70,7 +70,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -84,35 +84,35 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - const char *dir_start = format - 1; - - if (*format > '0' && *format <= '9') - { - /* A directive. */ - unsigned int number; - - FDI_SET (dir_start, FMTDIR_START); - spec.directives++; - - number = *format - '0'; - while (format[1] >= '0' && format[1] <= '9') - { - number = 10 * number + (format[1] - '0'); - format++; - } - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered_arg_count++; - - FDI_SET (format, FMTDIR_END); - - format++; - } + const char *dir_start = format - 1; + + if (*format > '0' && *format <= '9') + { + /* A directive. */ + unsigned int number; + + FDI_SET (dir_start, FMTDIR_START); + spec.directives++; + + number = *format - '0'; + while (format[1] >= '0' && format[1] <= '9') + { + number = 10 * number + (format[1] - '0'); + format++; + } + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered_arg_count++; + + FDI_SET (format, FMTDIR_END); + + format++; + } } /* Sort the numbered argument array, and eliminate duplicates. */ @@ -121,18 +121,18 @@ format_parse (const char *format, bool translated, char *fdi, unsigned int i, j; qsort (spec.numbered, spec.numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ for (i = j = 0; i < spec.numbered_arg_count; i++) - if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) - ; - else - { - if (j < i) - spec.numbered[j].number = spec.numbered[i].number; - j++; - } + if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) + ; + else + { + if (j < i) + spec.numbered[j].number = spec.numbered[i].number; + j++; + } spec.numbered_arg_count = j; } /* Now spec.numbered[i] >= i + 1 for i = 0,..,spec.numbered_arg_count-1 @@ -147,20 +147,20 @@ format_parse (const char *format, bool translated, char *fdi, i = 0; for (; i < spec.numbered_arg_count; i++) - if (spec.numbered[i].number > i + 1) - { - unsigned int first_gap = i + 1; - for (; i < spec.numbered_arg_count; i++) - if (spec.numbered[i].number > i + 2) - { - unsigned int second_gap = i + 2; - *invalid_reason = - xasprintf (_("The string refers to argument number %u but ignores the arguments %u and %u."), - spec.numbered[i].number, first_gap, second_gap); - goto bad_format; - } - break; - } + if (spec.numbered[i].number > i + 1) + { + unsigned int first_gap = i + 1; + for (; i < spec.numbered_arg_count; i++) + if (spec.numbered[i].number > i + 2) + { + unsigned int second_gap = i + 2; + *invalid_reason = + xasprintf (_("The string refers to argument number %u but ignores the arguments %u and %u."), + spec.numbered[i].number, first_gap, second_gap); + goto bad_format; + } + break; + } } result = XMALLOC (struct spec); @@ -193,8 +193,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -208,52 +208,52 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int missing = 0; /* only used if !equality */ /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else if (missing) - { - if (error_logger) - error_logger (_("a format specification for arguments %u and %u doesn't exist in '%s', only one argument may be ignored"), - missing, spec1->numbered[i].number, - pretty_msgstr); - err = true; - break; - } - else - { - missing = spec1->numbered[i].number; - i++; - } - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else if (missing) + { + if (error_logger) + error_logger (_("a format specification for arguments %u and %u doesn't exist in '%s', only one argument may be ignored"), + missing, spec1->numbered[i].number, + pretty_msgstr); + err = true; + break; + } + else + { + missing = spec1->numbered[i].number; + i++; + } + } + else + j++, i++; + } } return err; @@ -297,11 +297,11 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); last = number + 1; } printf (")"); @@ -320,9 +320,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -330,7 +330,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-librep.c b/gettext-tools/src/format-librep.c index 667a65324..05185ad13 100644 --- a/gettext-tools/src/format-librep.c +++ b/gettext-tools/src/format-librep.c @@ -92,7 +92,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -108,102 +108,102 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - enum format_arg_type type; - - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$' && m > 0) - { - number = m; - format = ++f; - } - } - - /* Parse flags. */ - while (*format == '-' || *format == '^' || *format == '0' - || *format == '+' || *format == ' ') - format++; - - /* Parse width. */ - if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - - /* Parse precision. */ - if (*format == '.') - { - format++; - - if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - } - - switch (*format) - { - case '%': - type = FAT_NONE; - break; - case 'c': - type = FAT_CHARACTER; - break; - case 'd': case 'x': case 'X': case 'o': - type = FAT_INTEGER; - break; - case 's': - type = FAT_OBJECT_PRETTY; - break; - case 'S': - type = FAT_OBJECT; - break; - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - if (type != FAT_NONE) - { - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = type; - spec.numbered_arg_count++; - - number++; - } - - FDI_SET (format, FMTDIR_END); - - format++; + /* A directive. */ + enum format_arg_type type; + + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$' && m > 0) + { + number = m; + format = ++f; + } + } + + /* Parse flags. */ + while (*format == '-' || *format == '^' || *format == '0' + || *format == '+' || *format == ' ') + format++; + + /* Parse width. */ + if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + + /* Parse precision. */ + if (*format == '.') + { + format++; + + if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + } + + switch (*format) + { + case '%': + type = FAT_NONE; + break; + case 'c': + type = FAT_CHARACTER; + break; + case 'd': case 'x': case 'X': case 'o': + type = FAT_INTEGER; + break; + case 's': + type = FAT_OBJECT_PRETTY; + break; + case 'S': + type = FAT_OBJECT; + break; + default: + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (spec.directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + + if (type != FAT_NONE) + { + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered[spec.numbered_arg_count].type = type; + spec.numbered_arg_count++; + + number++; + } + + FDI_SET (format, FMTDIR_END); + + format++; } /* Sort the numbered argument array, and eliminate duplicates. */ @@ -213,44 +213,44 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (spec.numbered, spec.numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < spec.numbered_arg_count; i++) - if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) - { - enum format_arg_type type1 = spec.numbered[i].type; - enum format_arg_type type2 = spec.numbered[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2) - type_both = type1; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); - err = true; - } - - spec.numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - spec.numbered[j].number = spec.numbered[i].number; - spec.numbered[j].type = spec.numbered[i].type; - } - j++; - } + if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) + { + enum format_arg_type type1 = spec.numbered[i].type; + enum format_arg_type type2 = spec.numbered[j-1].type; + enum format_arg_type type_both; + + if (type1 == type2) + type_both = type1; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); + err = true; + } + + spec.numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + spec.numbered[j].number = spec.numbered[i].number; + spec.numbered[j].type = spec.numbered[i].type; + } + j++; + } spec.numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -283,8 +283,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -297,60 +297,60 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->numbered_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } /* Check the argument types are the same. */ if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } + for (i = 0, j = 0; j < n2; ) + { + if (spec1->numbered[i].number == spec2->numbered[j].number) + { + if (spec1->numbered[i].type != spec2->numbered[j].type) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, + spec2->numbered[j].number); + err = true; + break; + } + j++, i++; + } + else + i++; + } } return err; @@ -394,28 +394,28 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); switch (spec->numbered[i].type) - { - case FAT_CHARACTER: - printf ("c"); - break; - case FAT_INTEGER: - printf ("i"); - break; - case FAT_OBJECT_PRETTY: - printf ("s"); - break; - case FAT_OBJECT: - printf ("*"); - break; - default: - abort (); - } + { + case FAT_CHARACTER: + printf ("c"); + break; + case FAT_INTEGER: + printf ("i"); + break; + case FAT_OBJECT_PRETTY: + printf ("s"); + break; + case FAT_OBJECT: + printf ("*"); + break; + default: + abort (); + } last = number + 1; } printf (")"); @@ -434,9 +434,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -444,7 +444,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-lisp.c b/gettext-tools/src/format-lisp.c index cf155edc3..c29aef33e 100644 --- a/gettext-tools/src/format-lisp.c +++ b/gettext-tools/src/format-lisp.c @@ -48,42 +48,42 @@ enum format_cdr_type { - FCT_REQUIRED, /* The format argument list cannot end before this argument. */ - FCT_OPTIONAL /* The format argument list may end before this argument. */ + FCT_REQUIRED, /* The format argument list cannot end before this argument. */ + FCT_OPTIONAL /* The format argument list may end before this argument. */ }; enum format_arg_type { - FAT_OBJECT, /* Any object, type T. */ - FAT_CHARACTER_INTEGER_NULL, /* Type (OR CHARACTER INTEGER NULL). */ - FAT_CHARACTER_NULL, /* Type (OR CHARACTER NULL). */ - FAT_CHARACTER, /* Type CHARACTER. */ - FAT_INTEGER_NULL, /* Type (OR INTEGER NULL). */ - FAT_INTEGER, /* Meant for objects of type INTEGER. */ - FAT_REAL, /* Meant for objects of type REAL. */ - FAT_LIST, /* Meant for proper lists. */ - FAT_FORMATSTRING, /* Format strings. */ - FAT_FUNCTION /* Function. */ + FAT_OBJECT, /* Any object, type T. */ + FAT_CHARACTER_INTEGER_NULL, /* Type (OR CHARACTER INTEGER NULL). */ + FAT_CHARACTER_NULL, /* Type (OR CHARACTER NULL). */ + FAT_CHARACTER, /* Type CHARACTER. */ + FAT_INTEGER_NULL, /* Type (OR INTEGER NULL). */ + FAT_INTEGER, /* Meant for objects of type INTEGER. */ + FAT_REAL, /* Meant for objects of type REAL. */ + FAT_LIST, /* Meant for proper lists. */ + FAT_FORMATSTRING, /* Format strings. */ + FAT_FUNCTION /* Function. */ }; struct format_arg { unsigned int repcount; /* Number of consecutive arguments this constraint - applies to. Normally 1, but unconstrained - arguments are often repeated. */ + applies to. Normally 1, but unconstrained + arguments are often repeated. */ enum format_cdr_type presence; /* Can the argument list end right before - this argument? */ - enum format_arg_type type; /* Possible values for this argument. */ - struct format_arg_list *list; /* For FAT_LIST: List elements. */ + this argument? */ + enum format_arg_type type; /* Possible values for this argument. */ + struct format_arg_list *list; /* For FAT_LIST: List elements. */ }; struct segment { - unsigned int count; /* Number of format_arg records used. */ + unsigned int count; /* Number of format_arg records used. */ unsigned int allocated; - struct format_arg *element; /* Argument constraints. */ + struct format_arg *element; /* Argument constraints. */ unsigned int length; /* Number of arguments represented by this segment. - This is the sum of all repcounts in the segment. */ + This is the sum of all repcounts in the segment. */ }; struct format_arg_list @@ -98,8 +98,8 @@ struct format_arg_list A finite sequence is represented entirely in the initial segment; the loop segment is empty. */ - struct segment initial; /* Initial arguments segment. */ - struct segment repeated; /* Endlessly repeated segment. */ + struct segment initial; /* Initial arguments segment. */ + struct segment repeated; /* Endlessly repeated segment. */ }; struct spec @@ -112,17 +112,17 @@ struct spec /* Parameter for a directive. */ enum param_type { - PT_NIL, /* param not present */ - PT_CHARACTER, /* character */ - PT_INTEGER, /* integer */ - PT_ARGCOUNT, /* number of remaining arguments */ - PT_V /* variable taken from argument list */ + PT_NIL, /* param not present */ + PT_CHARACTER, /* character */ + PT_INTEGER, /* integer */ + PT_ARGCOUNT, /* number of remaining arguments */ + PT_V /* variable taken from argument list */ }; struct param { enum param_type type; - int value; /* for PT_INTEGER: the value, for PT_V: the position */ + int value; /* for PT_INTEGER: the value, for PT_V: the position */ }; @@ -132,15 +132,15 @@ static void verify_list (const struct format_arg_list *list); static void free_list (struct format_arg_list *list); static struct format_arg_list * copy_list (const struct format_arg_list *list); static bool equal_list (const struct format_arg_list *list1, - const struct format_arg_list *list2); + const struct format_arg_list *list2); static struct format_arg_list * make_intersected_list - (struct format_arg_list *list1, - struct format_arg_list *list2); + (struct format_arg_list *list1, + struct format_arg_list *list2); static struct format_arg_list * make_intersection_with_empty_list - (struct format_arg_list *list); + (struct format_arg_list *list); static struct format_arg_list * make_union_list - (struct format_arg_list *list1, - struct format_arg_list *list2); + (struct format_arg_list *list1, + struct format_arg_list *list2); /* ======================= Verify a format_arg_list ======================= */ @@ -218,7 +218,7 @@ free_list (struct format_arg_list *list) /* Copy the data belonging to an argument list element. */ static inline void copy_element (struct format_arg *newelement, - const struct format_arg *oldelement) + const struct format_arg *oldelement) { newelement->repcount = oldelement->repcount; newelement->presence = oldelement->presence; @@ -247,13 +247,13 @@ copy_list (const struct format_arg_list *list) else { newlist->initial.element = - XNMALLOC (newlist->initial.allocated, struct format_arg); + XNMALLOC (newlist->initial.allocated, struct format_arg); for (i = 0; i < list->initial.count; i++) - { - copy_element (&newlist->initial.element[i], - &list->initial.element[i]); - length += list->initial.element[i].repcount; - } + { + copy_element (&newlist->initial.element[i], + &list->initial.element[i]); + length += list->initial.element[i].repcount; + } } ASSERT (length == list->initial.length); newlist->initial.length = length; @@ -265,13 +265,13 @@ copy_list (const struct format_arg_list *list) else { newlist->repeated.element = - XNMALLOC (newlist->repeated.allocated, struct format_arg); + XNMALLOC (newlist->repeated.allocated, struct format_arg); for (i = 0; i < list->repeated.count; i++) - { - copy_element (&newlist->repeated.element[i], - &list->repeated.element[i]); - length += list->repeated.element[i].repcount; - } + { + copy_element (&newlist->repeated.element[i], + &list->repeated.element[i]); + length += list->repeated.element[i].repcount; + } } ASSERT (length == list->repeated.length); newlist->repeated.length = length; @@ -290,15 +290,15 @@ static bool equal_element (const struct format_arg * e1, const struct format_arg * e2) { return (e1->presence == e2->presence - && e1->type == e2->type - && (e1->type == FAT_LIST ? equal_list (e1->list, e2->list) : true)); + && e1->type == e2->type + && (e1->type == FAT_LIST ? equal_list (e1->list, e2->list) : true)); } /* Tests whether two normalized argument list constraints are equivalent. */ /* Memory effects: none. */ static bool equal_list (const struct format_arg_list *list1, - const struct format_arg_list *list2) + const struct format_arg_list *list2) { unsigned int n, i; @@ -314,7 +314,7 @@ equal_list (const struct format_arg_list *list1, const struct format_arg * e2 = &list2->initial.element[i]; if (!(e1->repcount == e2->repcount && equal_element (e1, e2))) - return false; + return false; } n = list1->repeated.count; @@ -326,7 +326,7 @@ equal_list (const struct format_arg_list *list1, const struct format_arg * e2 = &list2->repeated.element[i]; if (!(e1->repcount == e2->repcount && equal_element (e1, e2))) - return false; + return false; } return true; @@ -342,11 +342,11 @@ ensure_initial_alloc (struct format_arg_list *list, unsigned int newcount) if (newcount > list->initial.allocated) { list->initial.allocated = - MAX (2 * list->initial.allocated + 1, newcount); + MAX (2 * list->initial.allocated + 1, newcount); list->initial.element = - (struct format_arg *) - xrealloc (list->initial.element, - list->initial.allocated * sizeof (struct format_arg)); + (struct format_arg *) + xrealloc (list->initial.element, + list->initial.allocated * sizeof (struct format_arg)); } } @@ -357,11 +357,11 @@ grow_initial_alloc (struct format_arg_list *list) if (list->initial.count >= list->initial.allocated) { list->initial.allocated = - MAX (2 * list->initial.allocated + 1, list->initial.count + 1); + MAX (2 * list->initial.allocated + 1, list->initial.count + 1); list->initial.element = - (struct format_arg *) - xrealloc (list->initial.element, - list->initial.allocated * sizeof (struct format_arg)); + (struct format_arg *) + xrealloc (list->initial.element, + list->initial.allocated * sizeof (struct format_arg)); } } @@ -372,11 +372,11 @@ ensure_repeated_alloc (struct format_arg_list *list, unsigned int newcount) if (newcount > list->repeated.allocated) { list->repeated.allocated = - MAX (2 * list->repeated.allocated + 1, newcount); + MAX (2 * list->repeated.allocated + 1, newcount); list->repeated.element = - (struct format_arg *) - xrealloc (list->repeated.element, - list->repeated.allocated * sizeof (struct format_arg)); + (struct format_arg *) + xrealloc (list->repeated.element, + list->repeated.allocated * sizeof (struct format_arg)); } } @@ -387,11 +387,11 @@ grow_repeated_alloc (struct format_arg_list *list) if (list->repeated.count >= list->repeated.allocated) { list->repeated.allocated = - MAX (2 * list->repeated.allocated + 1, list->repeated.count + 1); + MAX (2 * list->repeated.allocated + 1, list->repeated.count + 1); list->repeated.element = - (struct format_arg *) - xrealloc (list->repeated.element, - list->repeated.allocated * sizeof (struct format_arg)); + (struct format_arg *) + xrealloc (list->repeated.element, + list->repeated.allocated * sizeof (struct format_arg)); } } @@ -412,36 +412,36 @@ normalize_outermost_list (struct format_arg_list *list) n = list->initial.count; for (i = j = 0; i < n; i++) if (j > 0 - && equal_element (&list->initial.element[i], - &list->initial.element[j-1])) + && equal_element (&list->initial.element[i], + &list->initial.element[j-1])) { - list->initial.element[j-1].repcount += - list->initial.element[i].repcount; - free_element (&list->initial.element[i]); + list->initial.element[j-1].repcount += + list->initial.element[i].repcount; + free_element (&list->initial.element[i]); } else { - if (j < i) - list->initial.element[j] = list->initial.element[i]; - j++; + if (j < i) + list->initial.element[j] = list->initial.element[i]; + j++; } list->initial.count = j; n = list->repeated.count; for (i = j = 0; i < n; i++) if (j > 0 - && equal_element (&list->repeated.element[i], - &list->repeated.element[j-1])) + && equal_element (&list->repeated.element[i], + &list->repeated.element[j-1])) { - list->repeated.element[j-1].repcount += - list->repeated.element[i].repcount; - free_element (&list->repeated.element[i]); + list->repeated.element[j-1].repcount += + list->repeated.element[i].repcount; + free_element (&list->repeated.element[i]); } else { - if (j < i) - list->repeated.element[j] = list->repeated.element[i]; - j++; + if (j < i) + list->repeated.element[j] = list->repeated.element[i]; + j++; } list->repeated.count = j; @@ -454,104 +454,104 @@ normalize_outermost_list (struct format_arg_list *list) n = list->repeated.count; repcount0_extra = 0; if (n > 1 - && equal_element (&list->repeated.element[0], - &list->repeated.element[n-1])) - { - repcount0_extra = list->repeated.element[n-1].repcount; - n--; - } + && equal_element (&list->repeated.element[0], + &list->repeated.element[n-1])) + { + repcount0_extra = list->repeated.element[n-1].repcount; + n--; + } /* Proceed as if the loop period were n, with - list->repeated.element[0].repcount incremented by repcount0_extra. */ + list->repeated.element[0].repcount incremented by repcount0_extra. */ for (m = 2; m <= n / 2; n++) - if ((n % m) == 0) - { - /* m is a divisor of n. Try to reduce the loop period to n. */ - bool ok = true; - - for (i = 0; i < n - m; i++) - if (!((list->repeated.element[i].repcount - + (i == 0 ? repcount0_extra : 0) - == list->repeated.element[i+m].repcount) - && equal_element (&list->repeated.element[i], - &list->repeated.element[i+m]))) - { - ok = false; - break; - } - if (ok) - { - for (i = m; i < n; i++) - free_element (&list->repeated.element[i]); - if (n < list->repeated.count) - list->repeated.element[m] = list->repeated.element[n]; - list->repeated.count = list->repeated.count - n + m; - list->repeated.length /= n / m; - break; - } - } + if ((n % m) == 0) + { + /* m is a divisor of n. Try to reduce the loop period to n. */ + bool ok = true; + + for (i = 0; i < n - m; i++) + if (!((list->repeated.element[i].repcount + + (i == 0 ? repcount0_extra : 0) + == list->repeated.element[i+m].repcount) + && equal_element (&list->repeated.element[i], + &list->repeated.element[i+m]))) + { + ok = false; + break; + } + if (ok) + { + for (i = m; i < n; i++) + free_element (&list->repeated.element[i]); + if (n < list->repeated.count) + list->repeated.element[m] = list->repeated.element[n]; + list->repeated.count = list->repeated.count - n + m; + list->repeated.length /= n / m; + break; + } + } /* Step 3: Roll as much as possible of the initial segment's tail - into the loop. */ + into the loop. */ if (list->repeated.count == 1) - { - if (list->initial.count > 0 - && equal_element (&list->initial.element[list->initial.count-1], - &list->repeated.element[0])) - { - /* Roll the last element of the initial segment into the loop. - Its repcount is irrelevant. The second-to-last element is - certainly different and doesn't need to be considered. */ - list->initial.length -= - list->initial.element[list->initial.count-1].repcount; - list->initial.count--; - } - } + { + if (list->initial.count > 0 + && equal_element (&list->initial.element[list->initial.count-1], + &list->repeated.element[0])) + { + /* Roll the last element of the initial segment into the loop. + Its repcount is irrelevant. The second-to-last element is + certainly different and doesn't need to be considered. */ + list->initial.length -= + list->initial.element[list->initial.count-1].repcount; + list->initial.count--; + } + } else - { - while (list->initial.count > 0 - && equal_element (&list->initial.element[list->initial.count-1], - &list->repeated.element[list->repeated.count-1])) - { - unsigned int moved_repcount = - MIN (list->initial.element[list->initial.count-1].repcount, - list->repeated.element[list->repeated.count-1].repcount); - - /* Add the element at the start of list->repeated. */ - if (equal_element (&list->repeated.element[0], - &list->repeated.element[list->repeated.count-1])) - list->repeated.element[0].repcount += moved_repcount; - else - { - unsigned int newcount = list->repeated.count + 1; - ensure_repeated_alloc (list, newcount); - for (i = newcount - 1; i > 0; i--) - list->repeated.element[i] = list->repeated.element[i-1]; - list->repeated.count = newcount; - copy_element (&list->repeated.element[0], - &list->repeated.element[list->repeated.count-1]); - list->repeated.element[0].repcount = moved_repcount; - } - - /* Remove the element from the end of list->repeated. */ - list->repeated.element[list->repeated.count-1].repcount -= - moved_repcount; - if (list->repeated.element[list->repeated.count-1].repcount == 0) - { - free_element (&list->repeated.element[list->repeated.count-1]); - list->repeated.count--; - } - - /* Remove the element from the end of list->initial. */ - list->initial.element[list->initial.count-1].repcount -= - moved_repcount; - if (list->initial.element[list->initial.count-1].repcount == 0) - { - free_element (&list->initial.element[list->initial.count-1]); - list->initial.count--; - } - list->initial.length -= moved_repcount; - } - } + { + while (list->initial.count > 0 + && equal_element (&list->initial.element[list->initial.count-1], + &list->repeated.element[list->repeated.count-1])) + { + unsigned int moved_repcount = + MIN (list->initial.element[list->initial.count-1].repcount, + list->repeated.element[list->repeated.count-1].repcount); + + /* Add the element at the start of list->repeated. */ + if (equal_element (&list->repeated.element[0], + &list->repeated.element[list->repeated.count-1])) + list->repeated.element[0].repcount += moved_repcount; + else + { + unsigned int newcount = list->repeated.count + 1; + ensure_repeated_alloc (list, newcount); + for (i = newcount - 1; i > 0; i--) + list->repeated.element[i] = list->repeated.element[i-1]; + list->repeated.count = newcount; + copy_element (&list->repeated.element[0], + &list->repeated.element[list->repeated.count-1]); + list->repeated.element[0].repcount = moved_repcount; + } + + /* Remove the element from the end of list->repeated. */ + list->repeated.element[list->repeated.count-1].repcount -= + moved_repcount; + if (list->repeated.element[list->repeated.count-1].repcount == 0) + { + free_element (&list->repeated.element[list->repeated.count-1]); + list->repeated.count--; + } + + /* Remove the element from the end of list->initial. */ + list->initial.element[list->initial.count-1].repcount -= + moved_repcount; + if (list->initial.element[list->initial.count-1].repcount == 0) + { + free_element (&list->initial.element[list->initial.count-1]); + list->initial.count--; + } + list->initial.length -= moved_repcount; + } + } } } @@ -661,8 +661,8 @@ unfold_loop (struct format_arg_list *list, unsigned int m) ensure_repeated_alloc (list, newcount); i = list->repeated.count; for (k = 1; k < m; k++) - for (j = 0; j < list->repeated.count; j++, i++) - copy_element (&list->repeated.element[i], &list->repeated.element[j]); + for (j = 0; j < list->repeated.count; j++, i++) + copy_element (&list->repeated.element[i], &list->repeated.element[j]); list->repeated.count = newcount; list->repeated.length = list->repeated.length * m; } @@ -680,7 +680,7 @@ rotate_loop (struct format_arg_list *list, unsigned int m) if (list->repeated.count == 1) { /* Instead of multiple copies of list->repeated.element[0], a single - copy with higher repcount is appended to list->initial. */ + copy with higher repcount is appended to list->initial. */ unsigned int i, newcount; newcount = list->initial.count + 1; @@ -700,76 +700,76 @@ rotate_loop (struct format_arg_list *list, unsigned int m) unsigned int r = (m - list->initial.length) % n; /* Determine how many entries of list->repeated are needed for - length r. */ + length r. */ unsigned int s; unsigned int t; for (t = r, s = 0; - s < list->repeated.count && t >= list->repeated.element[s].repcount; - t -= list->repeated.element[s].repcount, s++) - ; + s < list->repeated.count && t >= list->repeated.element[s].repcount; + t -= list->repeated.element[s].repcount, s++) + ; /* s must be < list->repeated.count, otherwise r would have been >= n. */ ASSERT (s < list->repeated.count); /* So we need to add to list->initial: - q full copies of list->repeated, - plus the s first elements of list->repeated, - plus, if t > 0, a splitoff of list->repeated.element[s]. */ + q full copies of list->repeated, + plus the s first elements of list->repeated, + plus, if t > 0, a splitoff of list->repeated.element[s]. */ { - unsigned int i, j, k, newcount; - - i = list->initial.count; - newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0); - ensure_initial_alloc (list, newcount); - for (k = 0; k < q; k++) - for (j = 0; j < list->repeated.count; j++, i++) - copy_element (&list->initial.element[i], - &list->repeated.element[j]); - for (j = 0; j < s; j++, i++) - copy_element (&list->initial.element[i], &list->repeated.element[j]); - if (t > 0) - { - copy_element (&list->initial.element[i], - &list->repeated.element[j]); - list->initial.element[i].repcount = t; - i++; - } - ASSERT (i == newcount); - list->initial.count = newcount; - /* The new length of the initial segment is - = list->initial.length - + q * list->repeated.length - + list->repeated[0..s-1].repcount + t - = list->initial.length + q * n + r - = m. - */ - list->initial.length = m; + unsigned int i, j, k, newcount; + + i = list->initial.count; + newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0); + ensure_initial_alloc (list, newcount); + for (k = 0; k < q; k++) + for (j = 0; j < list->repeated.count; j++, i++) + copy_element (&list->initial.element[i], + &list->repeated.element[j]); + for (j = 0; j < s; j++, i++) + copy_element (&list->initial.element[i], &list->repeated.element[j]); + if (t > 0) + { + copy_element (&list->initial.element[i], + &list->repeated.element[j]); + list->initial.element[i].repcount = t; + i++; + } + ASSERT (i == newcount); + list->initial.count = newcount; + /* The new length of the initial segment is + = list->initial.length + + q * list->repeated.length + + list->repeated[0..s-1].repcount + t + = list->initial.length + q * n + r + = m. + */ + list->initial.length = m; } /* And rotate list->repeated. */ if (r > 0) - { - unsigned int i, j, oldcount, newcount; - struct format_arg *newelement; - - oldcount = list->repeated.count; - newcount = list->repeated.count + (t > 0 ? 1 : 0); - newelement = XNMALLOC (newcount, struct format_arg); - i = 0; - for (j = s; j < oldcount; j++, i++) - newelement[i] = list->repeated.element[j]; - for (j = 0; j < s; j++, i++) - newelement[i] = list->repeated.element[j]; - if (t > 0) - { - copy_element (&newelement[oldcount], &newelement[0]); - newelement[0].repcount -= t; - newelement[oldcount].repcount = t; - } - free (list->repeated.element); - list->repeated.element = newelement; - } + { + unsigned int i, j, oldcount, newcount; + struct format_arg *newelement; + + oldcount = list->repeated.count; + newcount = list->repeated.count + (t > 0 ? 1 : 0); + newelement = XNMALLOC (newcount, struct format_arg); + i = 0; + for (j = s; j < oldcount; j++, i++) + newelement[i] = list->repeated.element[j]; + for (j = 0; j < s; j++, i++) + newelement[i] = list->repeated.element[j]; + if (t > 0) + { + copy_element (&newelement[oldcount], &newelement[0]); + newelement[0].repcount -= t; + newelement[oldcount].repcount = t; + } + free (list->repeated.element); + list->repeated.element = newelement; + } } } @@ -857,44 +857,44 @@ initial_unshare (struct format_arg_list *list, unsigned int n) if (list->initial.element[s].repcount > 1) { /* Split the entry into at most three entries: for indices < n, - for index n, and for indices > n. */ + for index n, and for indices > n. */ unsigned int oldrepcount = list->initial.element[s].repcount; unsigned int newcount = - list->initial.count + (t == 0 || t == oldrepcount - 1 ? 1 : 2); + list->initial.count + (t == 0 || t == oldrepcount - 1 ? 1 : 2); ensure_initial_alloc (list, newcount); if (t == 0 || t == oldrepcount - 1) - { - unsigned int i; - - for (i = list->initial.count - 1; i > s; i--) - list->initial.element[i+1] = list->initial.element[i]; - copy_element (&list->initial.element[s+1], &list->initial.element[s]); - if (t == 0) - { - list->initial.element[s].repcount = 1; - list->initial.element[s+1].repcount = oldrepcount - 1; - } - else - { - list->initial.element[s].repcount = oldrepcount - 1; - list->initial.element[s+1].repcount = 1; - } - } + { + unsigned int i; + + for (i = list->initial.count - 1; i > s; i--) + list->initial.element[i+1] = list->initial.element[i]; + copy_element (&list->initial.element[s+1], &list->initial.element[s]); + if (t == 0) + { + list->initial.element[s].repcount = 1; + list->initial.element[s+1].repcount = oldrepcount - 1; + } + else + { + list->initial.element[s].repcount = oldrepcount - 1; + list->initial.element[s+1].repcount = 1; + } + } else - { - unsigned int i; - - for (i = list->initial.count - 1; i > s; i--) - list->initial.element[i+2] = list->initial.element[i]; - copy_element (&list->initial.element[s+2], &list->initial.element[s]); - copy_element (&list->initial.element[s+1], &list->initial.element[s]); - list->initial.element[s].repcount = t; - list->initial.element[s+1].repcount = 1; - list->initial.element[s+2].repcount = oldrepcount - 1 - t; - } + { + unsigned int i; + + for (i = list->initial.count - 1; i > s; i--) + list->initial.element[i+2] = list->initial.element[i]; + copy_element (&list->initial.element[s+2], &list->initial.element[s]); + copy_element (&list->initial.element[s+1], &list->initial.element[s]); + list->initial.element[s].repcount = t; + list->initial.element[s+1].repcount = 1; + list->initial.element[s+2].repcount = oldrepcount - 1 - t; + } list->initial.count = newcount; if (t > 0) - s++; + s++; } /* Now the entry for index n has repcount 1. */ @@ -919,7 +919,7 @@ shift_list (struct format_arg_list *list, unsigned int n) grow_initial_alloc (list); for (i = list->initial.count; i > 0; i--) - list->initial.element[i] = list->initial.element[i-1]; + list->initial.element[i] = list->initial.element[i-1]; list->initial.element[0].repcount = n; list->initial.element[0].presence = FCT_REQUIRED; list->initial.element[0].type = FAT_OBJECT; @@ -941,8 +941,8 @@ shift_list (struct format_arg_list *list, unsigned int n) /* Memory effects: Freshly allocated element's sublist. */ static bool make_intersected_element (struct format_arg *re, - const struct format_arg * e1, - const struct format_arg * e2) + const struct format_arg * e1, + const struct format_arg * e2) { /* Intersect the cdr types. */ if (e1->presence == FCT_REQUIRED || e2->presence == FCT_REQUIRED) @@ -955,43 +955,43 @@ make_intersected_element (struct format_arg *re, { re->type = e2->type; if (re->type == FAT_LIST) - re->list = copy_list (e2->list); + re->list = copy_list (e2->list); } else if (e2->type == FAT_OBJECT) { re->type = e1->type; if (re->type == FAT_LIST) - re->list = copy_list (e1->list); + re->list = copy_list (e1->list); } else if (e1->type == FAT_LIST - && (e2->type == FAT_CHARACTER_INTEGER_NULL - || e2->type == FAT_CHARACTER_NULL - || e2->type == FAT_INTEGER_NULL)) + && (e2->type == FAT_CHARACTER_INTEGER_NULL + || e2->type == FAT_CHARACTER_NULL + || e2->type == FAT_INTEGER_NULL)) { re->type = e1->type; re->list = make_intersection_with_empty_list (e1->list); if (re->list == NULL) - return false; + return false; } else if (e2->type == FAT_LIST - && (e1->type == FAT_CHARACTER_INTEGER_NULL - || e1->type == FAT_CHARACTER_NULL - || e1->type == FAT_INTEGER_NULL)) + && (e1->type == FAT_CHARACTER_INTEGER_NULL + || e1->type == FAT_CHARACTER_NULL + || e1->type == FAT_INTEGER_NULL)) { re->type = e2->type; re->list = make_intersection_with_empty_list (e2->list); if (re->list == NULL) - return false; + return false; } else if (e1->type == FAT_CHARACTER_INTEGER_NULL - && (e2->type == FAT_CHARACTER_NULL || e2->type == FAT_CHARACTER - || e2->type == FAT_INTEGER_NULL || e2->type == FAT_INTEGER)) + && (e2->type == FAT_CHARACTER_NULL || e2->type == FAT_CHARACTER + || e2->type == FAT_INTEGER_NULL || e2->type == FAT_INTEGER)) { re->type = e2->type; } else if (e2->type == FAT_CHARACTER_INTEGER_NULL - && (e1->type == FAT_CHARACTER_NULL || e1->type == FAT_CHARACTER - || e1->type == FAT_INTEGER_NULL || e1->type == FAT_INTEGER)) + && (e1->type == FAT_CHARACTER_NULL || e1->type == FAT_CHARACTER + || e1->type == FAT_INTEGER_NULL || e1->type == FAT_INTEGER)) { re->type = e1->type; } @@ -1023,12 +1023,12 @@ make_intersected_element (struct format_arg *re, { re->type = e1->type; if (re->type == FAT_LIST) - { - re->list = make_intersected_list (copy_list (e1->list), - copy_list (e2->list)); - if (re->list == NULL) - return false; - } + { + re->list = make_intersected_list (copy_list (e1->list), + copy_list (e2->list)); + if (re->list == NULL) + return false; + } } else /* Each of FAT_CHARACTER, FAT_INTEGER, FAT_LIST, FAT_FORMATSTRING, @@ -1052,7 +1052,7 @@ append_repeated_to_initial (struct format_arg_list *list) ensure_initial_alloc (list, newcount); i = list->initial.count; for (j = 0; j < list->repeated.count; j++, i++) - list->initial.element[i] = list->repeated.element[j]; + list->initial.element[i] = list->repeated.element[j]; list->initial.count = newcount; list->initial.length = list->initial.length + list->repeated.length; free (list->repeated.element); @@ -1078,26 +1078,26 @@ backtrack_in_initial (struct format_arg_list *list) { unsigned int i = list->initial.count - 1; if (list->initial.element[i].presence == FCT_REQUIRED) - { - /* Throw away this element. */ - list->initial.length -= list->initial.element[i].repcount; - free_element (&list->initial.element[i]); - list->initial.count = i; - } + { + /* Throw away this element. */ + list->initial.length -= list->initial.element[i].repcount; + free_element (&list->initial.element[i]); + list->initial.count = i; + } else /* list->initial.element[i].presence == FCT_OPTIONAL */ - { - /* The list must end here. */ - list->initial.length--; - if (list->initial.element[i].repcount > 1) - list->initial.element[i].repcount--; - else - { - free_element (&list->initial.element[i]); - list->initial.count = i; - } - VERIFY_LIST (list); - return list; - } + { + /* The list must end here. */ + list->initial.length--; + if (list->initial.element[i].repcount > 1) + list->initial.element[i].repcount--; + else + { + free_element (&list->initial.element[i]); + list->initial.count = i; + } + VERIFY_LIST (list); + return list; + } } free_list (list); @@ -1111,7 +1111,7 @@ backtrack_in_initial (struct format_arg_list *list) freshly allocated. */ static struct format_arg_list * make_intersected_list (struct format_arg_list *list1, - struct format_arg_list *list2) + struct format_arg_list *list2) { struct format_arg_list *result; @@ -1141,9 +1141,9 @@ make_intersected_list (struct format_arg_list *list1, unsigned int m = MAX (list1->initial.length, list2->initial.length); if (list1->repeated.length > 0) - rotate_loop (list1, m); + rotate_loop (list1, m); if (list2->repeated.length > 0) - rotate_loop (list2, m); + rotate_loop (list2, m); } if (list1->repeated.length > 0 && list2->repeated.length > 0) @@ -1174,78 +1174,78 @@ make_intersected_list (struct format_arg_list *list1, e2 = list2->initial.element; c2 = list2->initial.count; while (c1 > 0 && c2 > 0) { - struct format_arg *re; - - /* Ensure room in result->initial. */ - grow_initial_alloc (result); - re = &result->initial.element[result->initial.count]; - re->repcount = MIN (e1->repcount, e2->repcount); - - /* Intersect the argument types. */ - if (!make_intersected_element (re, e1, e2)) - { - /* If re->presence == FCT_OPTIONAL, the result list ends here. */ - if (re->presence == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - goto done; - } - - result->initial.count++; - result->initial.length += re->repcount; - - e1->repcount -= re->repcount; - if (e1->repcount == 0) - { - e1++; - c1--; - } - e2->repcount -= re->repcount; - if (e2->repcount == 0) - { - e2++; - c2--; - } + struct format_arg *re; + + /* Ensure room in result->initial. */ + grow_initial_alloc (result); + re = &result->initial.element[result->initial.count]; + re->repcount = MIN (e1->repcount, e2->repcount); + + /* Intersect the argument types. */ + if (!make_intersected_element (re, e1, e2)) + { + /* If re->presence == FCT_OPTIONAL, the result list ends here. */ + if (re->presence == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + goto done; + } + + result->initial.count++; + result->initial.length += re->repcount; + + e1->repcount -= re->repcount; + if (e1->repcount == 0) + { + e1++; + c1--; + } + e2->repcount -= re->repcount; + if (e2->repcount == 0) + { + e2++; + c2--; + } } if (list1->repeated.count == 0 && list2->repeated.count == 0) { - /* Intersecting two finite lists. */ - if (c1 > 0) - { - /* list1 longer than list2. */ - if (e1->presence == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - } - else if (c2 > 0) - { - /* list2 longer than list1. */ - if (e2->presence == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - } - goto done; + /* Intersecting two finite lists. */ + if (c1 > 0) + { + /* list1 longer than list2. */ + if (e1->presence == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + } + else if (c2 > 0) + { + /* list2 longer than list1. */ + if (e2->presence == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + } + goto done; } else if (list1->repeated.count == 0) { - /* Intersecting a finite and an infinite list. */ - ASSERT (c1 == 0); - if ((c2 > 0 ? e2->presence : list2->repeated.element[0].presence) - == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - goto done; + /* Intersecting a finite and an infinite list. */ + ASSERT (c1 == 0); + if ((c2 > 0 ? e2->presence : list2->repeated.element[0].presence) + == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + goto done; } else if (list2->repeated.count == 0) { - /* Intersecting an infinite and a finite list. */ - ASSERT (c2 == 0); - if ((c1 > 0 ? e1->presence : list1->repeated.element[0].presence) - == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - goto done; + /* Intersecting an infinite and a finite list. */ + ASSERT (c2 == 0); + if ((c1 > 0 ? e1->presence : list1->repeated.element[0].presence) + == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + goto done; } /* Intersecting two infinite lists. */ ASSERT (c1 == 0 && c2 == 0); @@ -1262,41 +1262,41 @@ make_intersected_list (struct format_arg_list *list1, e2 = list2->repeated.element; c2 = list2->repeated.count; while (c1 > 0 && c2 > 0) { - struct format_arg *re; - - /* Ensure room in result->repeated. */ - grow_repeated_alloc (result); - re = &result->repeated.element[result->repeated.count]; - re->repcount = MIN (e1->repcount, e2->repcount); - - /* Intersect the argument types. */ - if (!make_intersected_element (re, e1, e2)) - { - append_repeated_to_initial (result); - - /* If re->presence == FCT_OPTIONAL, the result list ends here. */ - if (re->presence == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - - goto done; - } - - result->repeated.count++; - result->repeated.length += re->repcount; - - e1->repcount -= re->repcount; - if (e1->repcount == 0) - { - e1++; - c1--; - } - e2->repcount -= re->repcount; - if (e2->repcount == 0) - { - e2++; - c2--; - } + struct format_arg *re; + + /* Ensure room in result->repeated. */ + grow_repeated_alloc (result); + re = &result->repeated.element[result->repeated.count]; + re->repcount = MIN (e1->repcount, e2->repcount); + + /* Intersect the argument types. */ + if (!make_intersected_element (re, e1, e2)) + { + append_repeated_to_initial (result); + + /* If re->presence == FCT_OPTIONAL, the result list ends here. */ + if (re->presence == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + + goto done; + } + + result->repeated.count++; + result->repeated.length += re->repcount; + + e1->repcount -= re->repcount; + if (e1->repcount == 0) + { + e1++; + c1--; + } + e2->repcount -= re->repcount; + if (e2->repcount == 0) + { + e2++; + c2--; + } } ASSERT (c1 == 0 && c2 == 0); } @@ -1326,7 +1326,7 @@ make_intersection_with_empty_list (struct format_arg_list *list) if (list->initial.count > 0 ? list->initial.element[0].presence == FCT_REQUIRED : list->repeated.count > 0 - && list->repeated.element[0].presence == FCT_REQUIRED) + && list->repeated.element[0].presence == FCT_REQUIRED) return NULL; else return make_empty_list (); @@ -1345,22 +1345,22 @@ intersection (struct format_arg_list *list1, struct format_arg_list *list2) if (list1 != NULL) { if (list2 != NULL) - return make_intersected_list (list1, list2); + return make_intersected_list (list1, list2); else - { - free_list (list1); - return NULL; - } + { + free_list (list1); + return NULL; + } } else { if (list2 != NULL) - { - free_list (list2); - return NULL; - } + { + free_list (list2); + return NULL; + } else - return NULL; + return NULL; } } #endif @@ -1372,8 +1372,8 @@ intersection (struct format_arg_list *list1, struct format_arg_list *list2) constraints. */ static void make_union_element (struct format_arg *re, - const struct format_arg * e1, - const struct format_arg * e2) + const struct format_arg * e1, + const struct format_arg * e2) { /* Union of the cdr types. */ if (e1->presence == FCT_REQUIRED && e2->presence == FCT_REQUIRED) @@ -1386,18 +1386,18 @@ make_union_element (struct format_arg *re, { re->type = e1->type; if (re->type == FAT_LIST) - re->list = make_union_list (copy_list (e1->list), - copy_list (e2->list)); + re->list = make_union_list (copy_list (e1->list), + copy_list (e2->list)); } else if (e1->type == FAT_CHARACTER_INTEGER_NULL - && (e2->type == FAT_CHARACTER_NULL || e2->type == FAT_CHARACTER - || e2->type == FAT_INTEGER_NULL || e2->type == FAT_INTEGER)) + && (e2->type == FAT_CHARACTER_NULL || e2->type == FAT_CHARACTER + || e2->type == FAT_INTEGER_NULL || e2->type == FAT_INTEGER)) { re->type = e1->type; } else if (e2->type == FAT_CHARACTER_INTEGER_NULL - && (e1->type == FAT_CHARACTER_NULL || e1->type == FAT_CHARACTER - || e1->type == FAT_INTEGER_NULL || e1->type == FAT_INTEGER)) + && (e1->type == FAT_CHARACTER_NULL || e1->type == FAT_CHARACTER + || e1->type == FAT_INTEGER_NULL || e1->type == FAT_INTEGER)) { re->type = e2->type; } @@ -1428,36 +1428,36 @@ make_union_element (struct format_arg *re, else if (e1->type == FAT_LIST && is_empty_list (e1->list)) { if (e2->type == FAT_CHARACTER_INTEGER_NULL - || e2->type == FAT_CHARACTER_NULL - || e2->type == FAT_INTEGER_NULL) - re->type = e2->type; + || e2->type == FAT_CHARACTER_NULL + || e2->type == FAT_INTEGER_NULL) + re->type = e2->type; else if (e2->type == FAT_CHARACTER) - re->type = FAT_CHARACTER_NULL; + re->type = FAT_CHARACTER_NULL; else if (e2->type == FAT_INTEGER) - re->type = FAT_INTEGER_NULL; + re->type = FAT_INTEGER_NULL; else - re->type = FAT_OBJECT; + re->type = FAT_OBJECT; } else if (e2->type == FAT_LIST && is_empty_list (e2->list)) { if (e1->type == FAT_CHARACTER_INTEGER_NULL - || e1->type == FAT_CHARACTER_NULL - || e1->type == FAT_INTEGER_NULL) - re->type = e1->type; + || e1->type == FAT_CHARACTER_NULL + || e1->type == FAT_INTEGER_NULL) + re->type = e1->type; else if (e1->type == FAT_CHARACTER) - re->type = FAT_CHARACTER_NULL; + re->type = FAT_CHARACTER_NULL; else if (e1->type == FAT_INTEGER) - re->type = FAT_INTEGER_NULL; + re->type = FAT_INTEGER_NULL; else - re->type = FAT_OBJECT; + re->type = FAT_OBJECT; } else if ((e1->type == FAT_CHARACTER || e1->type == FAT_CHARACTER_NULL) - && (e2->type == FAT_INTEGER || e2->type == FAT_INTEGER_NULL)) + && (e2->type == FAT_INTEGER || e2->type == FAT_INTEGER_NULL)) { re->type = FAT_CHARACTER_INTEGER_NULL; } else if ((e2->type == FAT_CHARACTER || e2->type == FAT_CHARACTER_NULL) - && (e1->type == FAT_INTEGER || e1->type == FAT_INTEGER_NULL)) + && (e1->type == FAT_INTEGER || e1->type == FAT_INTEGER_NULL)) { re->type = FAT_CHARACTER_INTEGER_NULL; } @@ -1484,23 +1484,23 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2) { /* Step 1: Ensure list1->repeated.length == list2->repeated.length. */ { - unsigned int n1 = list1->repeated.length; - unsigned int n2 = list2->repeated.length; - unsigned int g = gcd (n1, n2); - unsigned int m1 = n2 / g; /* = lcm(n1,n2) / n1 */ - unsigned int m2 = n1 / g; /* = lcm(n1,n2) / n2 */ - - unfold_loop (list1, m1); - unfold_loop (list2, m2); - /* Now list1->repeated.length = list2->repeated.length = lcm(n1,n2). */ + unsigned int n1 = list1->repeated.length; + unsigned int n2 = list2->repeated.length; + unsigned int g = gcd (n1, n2); + unsigned int m1 = n2 / g; /* = lcm(n1,n2) / n1 */ + unsigned int m2 = n1 / g; /* = lcm(n1,n2) / n2 */ + + unfold_loop (list1, m1); + unfold_loop (list2, m2); + /* Now list1->repeated.length = list2->repeated.length = lcm(n1,n2). */ } /* Step 2: Ensure that list1->initial.length == list2->initial.length. */ { - unsigned int m = MAX (list1->initial.length, list2->initial.length); + unsigned int m = MAX (list1->initial.length, list2->initial.length); - rotate_loop (list1, m); - rotate_loop (list2, m); + rotate_loop (list1, m); + rotate_loop (list2, m); } ASSERT (list1->initial.length == list2->initial.length); @@ -1509,24 +1509,24 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2) else if (list1->repeated.length > 0) { /* Ensure the initial segment of the result can be computed from the - initial segment of list1. */ + initial segment of list1. */ if (list2->initial.length >= list1->initial.length) - { - rotate_loop (list1, list2->initial.length); - if (list1->repeated.element[0].presence == FCT_REQUIRED) - rotate_loop (list1, list1->initial.length + 1); - } + { + rotate_loop (list1, list2->initial.length); + if (list1->repeated.element[0].presence == FCT_REQUIRED) + rotate_loop (list1, list1->initial.length + 1); + } } else if (list2->repeated.length > 0) { /* Ensure the initial segment of the result can be computed from the - initial segment of list2. */ + initial segment of list2. */ if (list1->initial.length >= list2->initial.length) - { - rotate_loop (list2, list1->initial.length); - if (list2->repeated.element[0].presence == FCT_REQUIRED) - rotate_loop (list2, list2->initial.length + 1); - } + { + rotate_loop (list2, list1->initial.length); + if (list2->repeated.element[0].presence == FCT_REQUIRED) + rotate_loop (list2, list2->initial.length + 1); + } } /* Step 3: Allocate the result. */ @@ -1551,112 +1551,112 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2) e2 = list2->initial.element; c2 = list2->initial.count; while (c1 > 0 && c2 > 0) { - struct format_arg *re; - - /* Ensure room in result->initial. */ - grow_initial_alloc (result); - re = &result->initial.element[result->initial.count]; - re->repcount = MIN (e1->repcount, e2->repcount); - - /* Union of the argument types. */ - make_union_element (re, e1, e2); - - result->initial.count++; - result->initial.length += re->repcount; - - e1->repcount -= re->repcount; - if (e1->repcount == 0) - { - e1++; - c1--; - } - e2->repcount -= re->repcount; - if (e2->repcount == 0) - { - e2++; - c2--; - } + struct format_arg *re; + + /* Ensure room in result->initial. */ + grow_initial_alloc (result); + re = &result->initial.element[result->initial.count]; + re->repcount = MIN (e1->repcount, e2->repcount); + + /* Union of the argument types. */ + make_union_element (re, e1, e2); + + result->initial.count++; + result->initial.length += re->repcount; + + e1->repcount -= re->repcount; + if (e1->repcount == 0) + { + e1++; + c1--; + } + e2->repcount -= re->repcount; + if (e2->repcount == 0) + { + e2++; + c2--; + } } if (c1 > 0) { - /* list2 already terminated, but still more elements in list1->initial. - Copy them all, but turn the first presence to FCT_OPTIONAL. */ - ASSERT (list2->repeated.count == 0); - - if (e1->presence == FCT_REQUIRED) - { - struct format_arg *re; - - /* Ensure room in result->initial. */ - grow_initial_alloc (result); - re = &result->initial.element[result->initial.count]; - copy_element (re, e1); - re->presence = FCT_OPTIONAL; - re->repcount = 1; - result->initial.count++; - result->initial.length += 1; - e1->repcount -= 1; - if (e1->repcount == 0) - { - e1++; - c1--; - } - } - - /* Ensure room in result->initial. */ - ensure_initial_alloc (result, result->initial.count + c1); - while (c1 > 0) - { - struct format_arg *re; - - re = &result->initial.element[result->initial.count]; - copy_element (re, e1); - result->initial.count++; - result->initial.length += re->repcount; - e1++; - c1--; - } + /* list2 already terminated, but still more elements in list1->initial. + Copy them all, but turn the first presence to FCT_OPTIONAL. */ + ASSERT (list2->repeated.count == 0); + + if (e1->presence == FCT_REQUIRED) + { + struct format_arg *re; + + /* Ensure room in result->initial. */ + grow_initial_alloc (result); + re = &result->initial.element[result->initial.count]; + copy_element (re, e1); + re->presence = FCT_OPTIONAL; + re->repcount = 1; + result->initial.count++; + result->initial.length += 1; + e1->repcount -= 1; + if (e1->repcount == 0) + { + e1++; + c1--; + } + } + + /* Ensure room in result->initial. */ + ensure_initial_alloc (result, result->initial.count + c1); + while (c1 > 0) + { + struct format_arg *re; + + re = &result->initial.element[result->initial.count]; + copy_element (re, e1); + result->initial.count++; + result->initial.length += re->repcount; + e1++; + c1--; + } } else if (c2 > 0) { - /* list1 already terminated, but still more elements in list2->initial. - Copy them all, but turn the first presence to FCT_OPTIONAL. */ - ASSERT (list1->repeated.count == 0); - - if (e2->presence == FCT_REQUIRED) - { - struct format_arg *re; - - /* Ensure room in result->initial. */ - grow_initial_alloc (result); - re = &result->initial.element[result->initial.count]; - copy_element (re, e2); - re->presence = FCT_OPTIONAL; - re->repcount = 1; - result->initial.count++; - result->initial.length += 1; - e2->repcount -= 1; - if (e2->repcount == 0) - { - e2++; - c2--; - } - } - - /* Ensure room in result->initial. */ - ensure_initial_alloc (result, result->initial.count + c2); - while (c2 > 0) - { - struct format_arg *re; - - re = &result->initial.element[result->initial.count]; - copy_element (re, e2); - result->initial.count++; - result->initial.length += re->repcount; - e2++; - c2--; - } + /* list1 already terminated, but still more elements in list2->initial. + Copy them all, but turn the first presence to FCT_OPTIONAL. */ + ASSERT (list1->repeated.count == 0); + + if (e2->presence == FCT_REQUIRED) + { + struct format_arg *re; + + /* Ensure room in result->initial. */ + grow_initial_alloc (result); + re = &result->initial.element[result->initial.count]; + copy_element (re, e2); + re->presence = FCT_OPTIONAL; + re->repcount = 1; + result->initial.count++; + result->initial.length += 1; + e2->repcount -= 1; + if (e2->repcount == 0) + { + e2++; + c2--; + } + } + + /* Ensure room in result->initial. */ + ensure_initial_alloc (result, result->initial.count + c2); + while (c2 > 0) + { + struct format_arg *re; + + re = &result->initial.element[result->initial.count]; + copy_element (re, e2); + result->initial.count++; + result->initial.length += re->repcount; + e2++; + c2--; + } } ASSERT (c1 == 0 && c2 == 0); } @@ -1672,63 +1672,63 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2) e1 = list1->repeated.element; c1 = list1->repeated.count; e2 = list2->repeated.element; c2 = list2->repeated.count; while (c1 > 0 && c2 > 0) - { - struct format_arg *re; - - /* Ensure room in result->repeated. */ - grow_repeated_alloc (result); - re = &result->repeated.element[result->repeated.count]; - re->repcount = MIN (e1->repcount, e2->repcount); - - /* Union of the argument types. */ - make_union_element (re, e1, e2); - - result->repeated.count++; - result->repeated.length += re->repcount; - - e1->repcount -= re->repcount; - if (e1->repcount == 0) - { - e1++; - c1--; - } - e2->repcount -= re->repcount; - if (e2->repcount == 0) - { - e2++; - c2--; - } - } + { + struct format_arg *re; + + /* Ensure room in result->repeated. */ + grow_repeated_alloc (result); + re = &result->repeated.element[result->repeated.count]; + re->repcount = MIN (e1->repcount, e2->repcount); + + /* Union of the argument types. */ + make_union_element (re, e1, e2); + + result->repeated.count++; + result->repeated.length += re->repcount; + + e1->repcount -= re->repcount; + if (e1->repcount == 0) + { + e1++; + c1--; + } + e2->repcount -= re->repcount; + if (e2->repcount == 0) + { + e2++; + c2--; + } + } ASSERT (c1 == 0 && c2 == 0); } else if (list1->repeated.length > 0) { /* Turning FCT_REQUIRED into FCT_OPTIONAL was already handled in the - initial segment. Just copy the repeated segment of list1. */ + initial segment. Just copy the repeated segment of list1. */ unsigned int i; result->repeated.count = list1->repeated.count; result->repeated.allocated = result->repeated.count; result->repeated.element = - XNMALLOC (result->repeated.allocated, struct format_arg); + XNMALLOC (result->repeated.allocated, struct format_arg); for (i = 0; i < list1->repeated.count; i++) - copy_element (&result->repeated.element[i], - &list1->repeated.element[i]); + copy_element (&result->repeated.element[i], + &list1->repeated.element[i]); result->repeated.length = list1->repeated.length; } else if (list2->repeated.length > 0) { /* Turning FCT_REQUIRED into FCT_OPTIONAL was already handled in the - initial segment. Just copy the repeated segment of list2. */ + initial segment. Just copy the repeated segment of list2. */ unsigned int i; result->repeated.count = list2->repeated.count; result->repeated.allocated = result->repeated.count; result->repeated.element = - XNMALLOC (result->repeated.allocated, struct format_arg); + XNMALLOC (result->repeated.allocated, struct format_arg); for (i = 0; i < list2->repeated.count; i++) - copy_element (&result->repeated.element[i], - &list2->repeated.element[i]); + copy_element (&result->repeated.element[i], + &list2->repeated.element[i]); result->repeated.length = list2->repeated.length; } @@ -1754,7 +1754,7 @@ make_union_with_empty_list (struct format_arg_list *list) if (list->initial.count > 0 ? list->initial.element[0].presence == FCT_REQUIRED : list->repeated.count > 0 - && list->repeated.element[0].presence == FCT_REQUIRED) + && list->repeated.element[0].presence == FCT_REQUIRED) { initial_splitelement (list, 1); ASSERT (list->initial.count > 0); @@ -1763,7 +1763,7 @@ make_union_with_empty_list (struct format_arg_list *list) list->initial.element[0].presence = FCT_OPTIONAL; /* We might need to merge list->initial.element[0] and - list->initial.element[1]. */ + list->initial.element[1]. */ normalize_outermost_list (list); } @@ -1784,16 +1784,16 @@ union (struct format_arg_list *list1, struct format_arg_list *list2) if (list1 != NULL) { if (list2 != NULL) - return make_union_list (list1, list2); + return make_union_list (list1, list2); else - return list1; + return list1; } else { if (list2 != NULL) - return list2; + return list2; else - return NULL; + return NULL; } } @@ -1824,9 +1824,9 @@ is_required (const struct format_arg_list *list, unsigned int n) if (s < list->initial.count) { if (list->initial.element[s].presence != FCT_REQUIRED) - return false; + return false; else - return true; + return true; } /* Walk the list->repeated segment. */ @@ -1845,9 +1845,9 @@ is_required (const struct format_arg_list *list, unsigned int n) if (s < list->repeated.count) { if (list->repeated.element[s].presence != FCT_REQUIRED) - return false; + return false; else - return true; + return true; } /* The list->repeated segment consists only of FCT_REQUIRED. So, @@ -1873,7 +1873,7 @@ add_required_constraint (struct format_arg_list *list, unsigned int n) if (list->repeated.count == 0 && list->initial.length <= n) { /* list is already constrained to have at most length n. - Contradiction. */ + Contradiction. */ free_list (list); return NULL; } @@ -1947,7 +1947,7 @@ add_end_constraint (struct format_arg_list *list, unsigned int n) /* Memory effects: list is freed. The result is freshly allocated. */ static struct format_arg_list * add_type_constraint (struct format_arg_list *list, unsigned int n, - enum format_arg_type type) + enum format_arg_type type) { unsigned int s; struct format_arg newconstraint; @@ -1964,7 +1964,7 @@ add_type_constraint (struct format_arg_list *list, unsigned int n, newconstraint.presence = FCT_OPTIONAL; newconstraint.type = type; if (!make_intersected_element (&tmpelement, - &list->initial.element[s], &newconstraint)) + &list->initial.element[s], &newconstraint)) return add_end_constraint (list, n); free_element (&list->initial.element[s]); list->initial.element[s].type = tmpelement.type; @@ -1982,8 +1982,8 @@ add_type_constraint (struct format_arg_list *list, unsigned int n, /* Memory effects: list is freed. The result is freshly allocated. */ static struct format_arg_list * add_listtype_constraint (struct format_arg_list *list, unsigned int n, - enum format_arg_type type, - struct format_arg_list *sublist) + enum format_arg_type type, + struct format_arg_list *sublist) { unsigned int s; struct format_arg newconstraint; @@ -2001,7 +2001,7 @@ add_listtype_constraint (struct format_arg_list *list, unsigned int n, newconstraint.type = type; newconstraint.list = sublist; if (!make_intersected_element (&tmpelement, - &list->initial.element[s], &newconstraint)) + &list->initial.element[s], &newconstraint)) return add_end_constraint (list, n); free_element (&list->initial.element[s]); list->initial.element[s].type = tmpelement.type; @@ -2017,7 +2017,7 @@ add_listtype_constraint (struct format_arg_list *list, unsigned int n, static void add_req_type_constraint (struct format_arg_list **listp, - unsigned int position, enum format_arg_type type) + unsigned int position, enum format_arg_type type) { *listp = add_required_constraint (*listp, position); *listp = add_type_constraint (*listp, position, type); @@ -2026,8 +2026,8 @@ add_req_type_constraint (struct format_arg_list **listp, static void add_req_listtype_constraint (struct format_arg_list **listp, - unsigned int position, enum format_arg_type type, - struct format_arg_list *sublist) + unsigned int position, enum format_arg_type type, + struct format_arg_list *sublist) { *listp = add_required_constraint (*listp, position); *listp = add_listtype_constraint (*listp, position, type, sublist); @@ -2097,9 +2097,9 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) /* L is a finite list. */ if (sublist->initial.length < period) - /* L and (*^period L) is a contradition, so we need to consider - only 1 and 0 iterations. */ - return make_union_with_empty_list (sublist); + /* L and (*^period L) is a contradition, so we need to consider + only 1 and 0 iterations. */ + return make_union_with_empty_list (sublist); srcseg = &sublist->initial; p = period; @@ -2115,14 +2115,14 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) p = m * Lp; /* Concatenate the initial and the repeated segments into a single - segment. */ + segment. */ tmp.count = sublist->initial.count + sublist->repeated.count; tmp.allocated = tmp.count; tmp.element = XNMALLOC (tmp.allocated, struct format_arg); for (i = 0; i < sublist->initial.count; i++) - tmp.element[i] = sublist->initial.element[i]; + tmp.element[i] = sublist->initial.element[i]; for (j = 0; j < sublist->repeated.count; i++, j++) - tmp.element[i] = sublist->initial.element[j]; + tmp.element[i] = sublist->initial.element[j]; tmp.length = sublist->initial.length + sublist->repeated.length; srcseg = &tmp; @@ -2171,7 +2171,7 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) /* Ensure room in list->initial. */ grow_initial_alloc (list); copy_element (&list->initial.element[list->initial.count], - &srcseg->element[si]); + &srcseg->element[si]); list->initial.element[list->initial.count].repcount = k; list->initial.count++; list->initial.length += k; @@ -2179,10 +2179,10 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) i += k; ti += k; if (ti == srcseg->element[si].repcount) - { - ti = 0; - si++; - } + { + ti = 0; + si++; + } } ASSERT (list->initial.count > 0); @@ -2198,29 +2198,29 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) while (i < n) { unsigned int k = - MIN (srcseg->element[si].repcount - ti, - list->initial.element[sj].repcount - tj); + MIN (srcseg->element[si].repcount - ti, + list->initial.element[sj].repcount - tj); /* Ensure room in list->initial. */ grow_initial_alloc (list); if (!make_intersected_element (&list->initial.element[list->initial.count], - &srcseg->element[si], - &list->initial.element[sj])) - { - if (list->initial.element[list->initial.count].presence == FCT_REQUIRED) - { - /* Contradiction. Backtrack. */ - list = backtrack_in_initial (list); - ASSERT (list != NULL); /* at least the empty list is valid */ - return list; - } - else - { - /* The list ends here. */ - ended = true; - break; - } - } + &srcseg->element[si], + &list->initial.element[sj])) + { + if (list->initial.element[list->initial.count].presence == FCT_REQUIRED) + { + /* Contradiction. Backtrack. */ + list = backtrack_in_initial (list); + ASSERT (list != NULL); /* at least the empty list is valid */ + return list; + } + else + { + /* The list ends here. */ + ended = true; + break; + } + } list->initial.element[list->initial.count].repcount = k; list->initial.count++; list->initial.length += k; @@ -2228,18 +2228,18 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) i += k; ti += k; if (ti == srcseg->element[si].repcount) - { - ti = 0; - si++; - } + { + ti = 0; + si++; + } j += k; tj += k; if (tj == list->initial.element[sj].repcount) - { - tj = 0; - sj++; - } + { + tj = 0; + sj++; + } } if (!ended) ASSERT (list->initial.length == n); @@ -2258,12 +2258,12 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) splitindex = initial_splitelement (list, n - p); newcount = list->initial.count - splitindex; if (newcount > list->repeated.allocated) - { - list->repeated.allocated = newcount; - list->repeated.element = XNMALLOC (newcount, struct format_arg); - } + { + list->repeated.allocated = newcount; + list->repeated.element = XNMALLOC (newcount, struct format_arg); + } for (i = splitindex, j = 0; i < n; i++, j++) - list->repeated.element[j] = list->initial.element[i]; + list->repeated.element[j] = list->initial.element[i]; list->repeated.count = newcount; list->repeated.length = p; list->initial.count = splitindex; @@ -2312,81 +2312,81 @@ static const enum format_arg_type THREE [3] = { invalid. */ static bool check_params (struct format_arg_list **listp, - unsigned int paramcount, struct param *params, - unsigned int t_count, const enum format_arg_type *t_types, - unsigned int directives, char **invalid_reason) + unsigned int paramcount, struct param *params, + unsigned int t_count, const enum format_arg_type *t_types, + unsigned int directives, char **invalid_reason) { unsigned int orig_paramcount = paramcount; unsigned int orig_t_count = t_count; for (; paramcount > 0 && t_count > 0; - params++, paramcount--, t_types++, t_count--) + params++, paramcount--, t_types++, t_count--) { switch (*t_types) - { - case FAT_CHARACTER_INTEGER_NULL: - break; - case FAT_CHARACTER_NULL: - switch (params->type) - { - case PT_NIL: case PT_CHARACTER: case PT_V: - break; - case PT_INTEGER: case PT_ARGCOUNT: - /* wrong param type */ - *invalid_reason = - xasprintf (_("In the directive number %u, parameter %u is of type '%s' but a parameter of type '%s' is expected."), directives, orig_paramcount - paramcount + 1, "integer", "character"); - return false; - } - break; - case FAT_INTEGER_NULL: - switch (params->type) - { - case PT_NIL: case PT_INTEGER: case PT_ARGCOUNT: case PT_V: - break; - case PT_CHARACTER: - /* wrong param type */ - *invalid_reason = - xasprintf (_("In the directive number %u, parameter %u is of type '%s' but a parameter of type '%s' is expected."), directives, orig_paramcount - paramcount + 1, "character", "integer"); - return false; - } - break; - default: - abort (); - } + { + case FAT_CHARACTER_INTEGER_NULL: + break; + case FAT_CHARACTER_NULL: + switch (params->type) + { + case PT_NIL: case PT_CHARACTER: case PT_V: + break; + case PT_INTEGER: case PT_ARGCOUNT: + /* wrong param type */ + *invalid_reason = + xasprintf (_("In the directive number %u, parameter %u is of type '%s' but a parameter of type '%s' is expected."), directives, orig_paramcount - paramcount + 1, "integer", "character"); + return false; + } + break; + case FAT_INTEGER_NULL: + switch (params->type) + { + case PT_NIL: case PT_INTEGER: case PT_ARGCOUNT: case PT_V: + break; + case PT_CHARACTER: + /* wrong param type */ + *invalid_reason = + xasprintf (_("In the directive number %u, parameter %u is of type '%s' but a parameter of type '%s' is expected."), directives, orig_paramcount - paramcount + 1, "character", "integer"); + return false; + } + break; + default: + abort (); + } if (params->type == PT_V) - { - int position = params->value; - if (position >= 0) - add_req_type_constraint (listp, position, *t_types); - } + { + int position = params->value; + if (position >= 0) + add_req_type_constraint (listp, position, *t_types); + } } for (; paramcount > 0; params++, paramcount--) switch (params->type) { case PT_NIL: - break; + break; case PT_CHARACTER: case PT_INTEGER: case PT_ARGCOUNT: - /* too many params for directive */ - *invalid_reason = - xasprintf (ngettext ("In the directive number %u, too many parameters are given; expected at most %u parameter.", - "In the directive number %u, too many parameters are given; expected at most %u parameters.", - orig_t_count), - directives, orig_t_count); - return false; + /* too many params for directive */ + *invalid_reason = + xasprintf (ngettext ("In the directive number %u, too many parameters are given; expected at most %u parameter.", + "In the directive number %u, too many parameters are given; expected at most %u parameters.", + orig_t_count), + directives, orig_t_count); + return false; case PT_V: - /* Force argument to be NIL. */ - { - int position = params->value; - if (position >= 0) - { - struct format_arg_list *empty_list = make_empty_list (); - add_req_listtype_constraint (listp, position, - FAT_LIST, empty_list); - free_list (empty_list); - } - } - break; + /* Force argument to be NIL. */ + { + int position = params->value; + if (position >= 0) + { + struct format_arg_list *empty_list = make_empty_list (); + add_req_listtype_constraint (listp, position, + FAT_LIST, empty_list); + free_list (empty_list); + } + } + break; } return true; @@ -2399,8 +2399,8 @@ check_params (struct format_arg_list **listp, invalid. */ static bool nocheck_params (struct format_arg_list **listp, - unsigned int paramcount, struct param *params, - unsigned int directives, char **invalid_reason) + unsigned int paramcount, struct param *params, + unsigned int directives, char **invalid_reason) { (void) directives; (void) invalid_reason; @@ -2408,8 +2408,8 @@ nocheck_params (struct format_arg_list **listp, for (; paramcount > 0; params++, paramcount--) if (params->type == PT_V) { - int position = params->value; - add_req_type_constraint (listp, position, FAT_CHARACTER_INTEGER_NULL); + int position = params->value; + add_req_type_constraint (listp, position, FAT_CHARACTER_INTEGER_NULL); } return true; @@ -2438,10 +2438,10 @@ nocheck_params (struct format_arg_list **listp, set to an error message explaining why. */ static bool parse_upto (const char **formatp, - int *positionp, struct format_arg_list **listp, - struct format_arg_list **escapep, int *separatorp, - struct spec *spec, char terminator, bool separator, - char *fdi, char **invalid_reason) + int *positionp, struct format_arg_list **listp, + struct format_arg_list **escapep, int *separatorp, + struct spec *spec, char terminator, bool separator, + char *fdi, char **invalid_reason) { const char *format = *formatp; const char *const format_start = format; @@ -2452,939 +2452,939 @@ parse_upto (const char **formatp, for (; *format != '\0'; ) if (*format++ == '~') { - bool colon_p = false; - bool atsign_p = false; - unsigned int paramcount = 0; - struct param *params = NULL; - - FDI_SET (format - 1, FMTDIR_START); - - /* Count number of directives. */ - spec->directives++; - - /* Parse parameters. */ - for (;;) - { - enum param_type type = PT_NIL; - int value = 0; - - if (c_isdigit (*format)) - { - type = PT_INTEGER; - do - { - value = 10 * value + (*format - '0'); - format++; - } - while (c_isdigit (*format)); - } - else if (*format == '+' || *format == '-') - { - bool negative = (*format == '-'); - type = PT_INTEGER; - format++; - if (!c_isdigit (*format)) - { - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, '%c' is not followed by a digit."), spec->directives, format[-1]); - FDI_SET (format, FMTDIR_ERROR); - } - return false; - } - do - { - value = 10 * value + (*format - '0'); - format++; - } - while (c_isdigit (*format)); - if (negative) - value = -value; - } - else if (*format == '\'') - { - type = PT_CHARACTER; - format++; - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - format++; - } - else if (*format == 'V' || *format == 'v') - { - type = PT_V; - format++; - value = position; - /* Consumes an argument. */ - if (position >= 0) - position++; - } - else if (*format == '#') - { - type = PT_ARGCOUNT; - format++; - } - - params = - (struct param *) - xrealloc (params, (paramcount + 1) * sizeof (struct param)); - params[paramcount].type = type; - params[paramcount].value = value; - paramcount++; - - if (*format == ',') - format++; - else - break; - } - - /* Parse modifiers. */ - for (;;) - { - if (*format == ':') - { - format++; - colon_p = true; - } - else if (*format == '@') - { - format++; - atsign_p = true; - } - else - break; - } - - /* Parse directive. */ - switch (*format++) - { - case 'A': case 'a': /* 22.3.4.1 FORMAT-ASCII */ - case 'S': case 's': /* 22.3.4.2 FORMAT-S-EXPRESSION */ - if (!check_params (&list, paramcount, params, 4, IIIC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_OBJECT); - break; - - case 'W': case 'w': /* 22.3.4.3 FORMAT-WRITE */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_OBJECT); - break; - - case 'D': case 'd': /* 22.3.2.2 FORMAT-DECIMAL */ - case 'B': case 'b': /* 22.3.2.3 FORMAT-BINARY */ - case 'O': case 'o': /* 22.3.2.4 FORMAT-OCTAL */ - case 'X': case 'x': /* 22.3.2.5 FORMAT-HEXADECIMAL */ - if (!check_params (&list, paramcount, params, 4, ICCI, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_INTEGER); - break; - - case 'R': case 'r': /* 22.3.2.1 FORMAT-RADIX */ - if (!check_params (&list, paramcount, params, 5, IICCI, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_INTEGER); - break; - - case 'P': case 'p': /* 22.3.8.3 FORMAT-PLURAL */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (colon_p) - { - /* Go back by 1 argument. */ - if (position > 0) - position--; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_OBJECT); - break; - - case 'C': case 'c': /* 22.3.1.1 FORMAT-CHARACTER */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_CHARACTER); - break; - - case 'F': case 'f': /* 22.3.3.1 FORMAT-FIXED-FLOAT */ - if (!check_params (&list, paramcount, params, 5, IIICC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_REAL); - break; - - case 'E': case 'e': /* 22.3.3.2 FORMAT-EXPONENTIAL-FLOAT */ - case 'G': case 'g': /* 22.3.3.3 FORMAT-GENERAL-FLOAT */ - if (!check_params (&list, paramcount, params, 7, IIIICCC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_REAL); - break; - - case '$': /* 22.3.3.4 FORMAT-DOLLARS-FLOAT */ - if (!check_params (&list, paramcount, params, 4, IIIC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_REAL); - break; - - case '%': /* 22.3.1.2 FORMAT-TERPRI */ - case '&': /* 22.3.1.3 FORMAT-FRESH-LINE */ - case '|': /* 22.3.1.4 FORMAT-PAGE */ - case '~': /* 22.3.1.5 FORMAT-TILDE */ - case 'I': case 'i': /* 22.3.5.3 */ - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - break; - - case '\n': /* 22.3.9.3 #\Newline */ - case '_': /* 22.3.5.1 */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - break; - - case 'T': case 't': /* 22.3.6.1 FORMAT-TABULATE */ - if (!check_params (&list, paramcount, params, 2, II, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - break; - - case '*': /* 22.3.7.1 FORMAT-GOTO */ - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - { - int n; /* value of first parameter */ - if (paramcount == 0 - || (paramcount >= 1 && params[0].type == PT_NIL)) - n = (atsign_p ? 0 : 1); - else if (paramcount >= 1 && params[0].type == PT_INTEGER) - n = params[0].value; - else - { - /* Unknown argument, leads to an unknown position. */ - position = -1; - break; - } - if (n < 0) - { - /* invalid argument */ - *invalid_reason = - xasprintf (_("In the directive number %u, the argument %d is negative."), spec->directives, n); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (atsign_p) - { - /* Absolute goto. */ - position = n; - } - else if (colon_p) - { - /* Backward goto. */ - if (n > 0) - { - if (position >= 0) - { - if (position >= n) - position -= n; - else - position = 0; - } - else - position = -1; - } - } - else - { - /* Forward goto. */ - if (position >= 0) - position += n; - } - } - break; - - case '?': /* 22.3.7.6 FORMAT-INDIRECTION */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_FORMATSTRING); - if (atsign_p) - position = -1; - else - if (position >= 0) - { - struct format_arg_list *sublist = make_unconstrained_list (); - add_req_listtype_constraint (&list, position++, - FAT_LIST, sublist); - free_list (sublist); - } - break; - - case '/': /* 22.3.5.4 FORMAT-CALL-USER-FUNCTION */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_OBJECT); - while (*format != '\0' && *format != '/') - format++; - if (*format == '\0') - { - *invalid_reason = - xstrdup (_("The string ends in the middle of a ~/.../ directive.")); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - format++; - break; - - case '(': /* 22.3.8.1 FORMAT-CASE-CONVERSION */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - { - if (!parse_upto (formatp, positionp, listp, escapep, - NULL, spec, ')', false, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - } - format = *formatp; - position = *positionp; - list = *listp; - escape = *escapep; - break; - - case ')': /* 22.3.8.2 FORMAT-CASE-CONVERSION-END */ - if (terminator != ')') - { - *invalid_reason = - xasprintf (_("Found '~%c' without matching '~%c'."), ')', '('); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - return true; - - case '[': /* 22.3.7.2 FORMAT-CONDITIONAL */ - if (atsign_p && colon_p) - { - *invalid_reason = - xasprintf (_("In the directive number %u, both the @ and the : modifiers are given."), spec->directives); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - else if (atsign_p) - { - struct format_arg_list *nil_list; - struct format_arg_list *union_list; - - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - - *formatp = format; - *escapep = escape; - - /* First alternative: argument is NIL. */ - nil_list = (list != NULL ? copy_list (list) : NULL); - if (position >= 0) - { - struct format_arg_list *empty_list = make_empty_list (); - add_req_listtype_constraint (&nil_list, position, - FAT_LIST, empty_list); - free_list (empty_list); - } - - /* Second alternative: use sub-format. */ - { - int sub_position = position; - struct format_arg_list *sub_list = - (list != NULL ? copy_list (list) : NULL); - if (!parse_upto (formatp, &sub_position, &sub_list, escapep, - NULL, spec, ']', false, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - if (sub_list != NULL) - { - if (position >= 0) - { - if (sub_position == position + 1) - /* new position is branch independent */ - position = position + 1; - else - /* new position is branch dependent */ - position = -1; - } - } - else - { - if (position >= 0) - position = position + 1; - } - union_list = union (nil_list, sub_list); - } - - format = *formatp; - escape = *escapep; - - if (list != NULL) - free_list (list); - list = union_list; - } - else if (colon_p) - { - int union_position; - struct format_arg_list *union_list; - - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_OBJECT); - - *formatp = format; - *escapep = escape; - union_position = -2; - union_list = NULL; - - /* First alternative. */ - { - int sub_position = position; - struct format_arg_list *sub_list = - (list != NULL ? copy_list (list) : NULL); - int sub_separator = 0; - if (position >= 0) - { - struct format_arg_list *empty_list = make_empty_list (); - add_req_listtype_constraint (&sub_list, position - 1, - FAT_LIST, empty_list); - free_list (empty_list); - } - if (!parse_upto (formatp, &sub_position, &sub_list, escapep, - &sub_separator, spec, ']', true, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - if (!sub_separator) - { - *invalid_reason = - xasprintf (_("In the directive number %u, '~:[' is not followed by two clauses, separated by '~;'."), spec->directives); - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - if (sub_list != NULL) - union_position = sub_position; - union_list = union (union_list, sub_list); - } - - /* Second alternative. */ - { - int sub_position = position; - struct format_arg_list *sub_list = - (list != NULL ? copy_list (list) : NULL); - if (!parse_upto (formatp, &sub_position, &sub_list, escapep, - NULL, spec, ']', false, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - if (sub_list != NULL) - { - if (union_position == -2) - union_position = sub_position; - else if (sub_position < 0 - || sub_position != union_position) - union_position = -1; - } - union_list = union (union_list, sub_list); - } - - format = *formatp; - escape = *escapep; - - if (union_position != -2) - position = union_position; - if (list != NULL) - free_list (list); - list = union_list; - } - else - { - int arg_position; - int union_position; - struct format_arg_list *union_list; - bool last_alternative; - - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - - /* If there was no first parameter, an argument is consumed. */ - arg_position = -1; - if (!(paramcount >= 1 && params[0].type != PT_NIL)) - if (position >= 0) - { - arg_position = position; - add_req_type_constraint (&list, position++, FAT_OBJECT); - } - - *formatp = format; - *escapep = escape; - - union_position = -2; - union_list = NULL; - last_alternative = false; - for (;;) - { - /* Next alternative. */ - int sub_position = position; - struct format_arg_list *sub_list = - (list != NULL ? copy_list (list) : NULL); - int sub_separator = 0; - if (!parse_upto (formatp, &sub_position, &sub_list, escapep, - &sub_separator, spec, ']', !last_alternative, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - /* If this alternative is chosen, the argument arg_position - is an integer, namely the index of this alternative. */ - if (!last_alternative && arg_position >= 0) - add_req_type_constraint (&sub_list, arg_position, - FAT_INTEGER); - if (sub_list != NULL) - { - if (union_position == -2) - union_position = sub_position; - else if (sub_position < 0 - || sub_position != union_position) - union_position = -1; - } - union_list = union (union_list, sub_list); - if (sub_separator == 2) - last_alternative = true; - if (!sub_separator) - break; - } - if (!last_alternative) - { - /* An implicit default alternative. */ - if (union_position == -2) - union_position = position; - else if (position < 0 || position != union_position) - union_position = -1; - if (list != NULL) - union_list = union (union_list, copy_list (list)); - } - - format = *formatp; - escape = *escapep; - - if (union_position != -2) - position = union_position; - if (list != NULL) - free_list (list); - list = union_list; - } - break; - - case ']': /* 22.3.7.3 FORMAT-CONDITIONAL-END */ - if (terminator != ']') - { - *invalid_reason = - xasprintf (_("Found '~%c' without matching '~%c'."), ']', '['); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - return true; - - case '{': /* 22.3.7.4 FORMAT-ITERATION */ - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - { - int sub_position = 0; - struct format_arg_list *sub_list = make_unconstrained_list (); - struct format_arg_list *sub_escape = NULL; - struct spec sub_spec; - sub_spec.directives = 0; - sub_spec.list = sub_list; - if (!parse_upto (formatp, &sub_position, &sub_list, &sub_escape, - NULL, &sub_spec, '}', false, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - spec->directives += sub_spec.directives; - - /* If the sub-formatstring is empty, except for the terminating - ~} directive, a formatstring argument is consumed. */ - if (*format == '~' && sub_spec.directives == 1) - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_FORMATSTRING); - - if (colon_p) - { - /* Each iteration uses a new sublist. */ - struct format_arg_list *listlist; - - /* ~{ catches ~^. */ - sub_list = union (sub_list, sub_escape); - - listlist = make_repeated_list_of_lists (sub_list); - - sub_list = listlist; - } - else - { - /* Each iteration's arguments are all concatenated in a - single list. */ - struct format_arg_list *looplist; - - /* FIXME: This is far from correct. Test cases: - abc~{~^~} - abc~{~S~^~S~} - abc~{~D~^~C~} - abc~{~D~^~D~} - abc~{~D~^~S~} - abc~{~D~^~C~}~:*~{~S~^~D~} - */ - - /* ~{ catches ~^. */ - sub_list = union (sub_list, sub_escape); - - if (sub_list == NULL) - looplist = make_empty_list (); - else - if (sub_position < 0 || sub_position == 0) - /* Too hard to track the possible argument types - when the iteration is performed 2 times or more. - So be satisfied with the constraints of executing - the iteration 1 or 0 times. */ - looplist = make_union_with_empty_list (sub_list); - else - looplist = make_repeated_list (sub_list, sub_position); - - sub_list = looplist; - } - - if (atsign_p) - { - /* All remaining arguments are used. */ - if (list != NULL && position >= 0) - { - shift_list (sub_list, position); - list = make_intersected_list (list, sub_list); - } - position = -1; - } - else - { - /* The argument is a list. */ - if (position >= 0) - add_req_listtype_constraint (&list, position++, - FAT_LIST, sub_list); - } - } - format = *formatp; - break; - - case '}': /* 22.3.7.5 FORMAT-ITERATION-END */ - if (terminator != '}') - { - *invalid_reason = - xasprintf (_("Found '~%c' without matching '~%c'."), '}', '{'); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - return true; - - case '<': /* 22.3.6.2, 22.3.5.2 FORMAT-JUSTIFICATION */ - if (!check_params (&list, paramcount, params, 4, IIIC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - { - struct format_arg_list *sub_escape = NULL; - - *formatp = format; - *positionp = position; - *listp = list; - - for (;;) - { - int sub_separator = 0; - if (!parse_upto (formatp, positionp, listp, &sub_escape, - &sub_separator, spec, '>', true, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - if (!sub_separator) - break; - } - - format = *formatp; - position = *positionp; - list = *listp; - - /* ~< catches ~^. */ - if (sub_escape != NULL) - position = -1; - list = union (list, sub_escape); - } - break; - - case '>': /* 22.3.6.3 FORMAT-JUSTIFICATION-END */ - if (terminator != '>') - { - *invalid_reason = - xasprintf (_("Found '~%c' without matching '~%c'."), '>', '<'); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - return true; - - case '^': /* 22.3.9.2 FORMAT-UP-AND-OUT */ - if (!check_params (&list, paramcount, params, 3, THREE, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0 && list != NULL && is_required (list, position)) - /* This ~^ can never be executed. Ignore it. */ - break; - if (list != NULL) - { - struct format_arg_list *this_escape = copy_list (list); - if (position >= 0) - this_escape = add_end_constraint (this_escape, position); - escape = union (escape, this_escape); - } - if (position >= 0) - list = add_required_constraint (list, position); - break; - - case ';': /* 22.3.9.1 FORMAT-SEPARATOR */ - if (!separator) - { - *invalid_reason = - xasprintf (_("In the directive number %u, '~;' is used in an invalid position."), spec->directives); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (terminator == '>') - { - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - } - else - { - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - *separatorp = (colon_p ? 2 : 1); - return true; - - case '!': /* FORMAT-CALL, a CLISP extension */ - if (!nocheck_params (&list, paramcount, params, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - { - add_req_type_constraint (&list, position++, FAT_FUNCTION); - add_req_type_constraint (&list, position++, FAT_OBJECT); - } - break; - - default: - --format; - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec->directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - return false; - } - - FDI_SET (format - 1, FMTDIR_END); - - free (params); + bool colon_p = false; + bool atsign_p = false; + unsigned int paramcount = 0; + struct param *params = NULL; + + FDI_SET (format - 1, FMTDIR_START); + + /* Count number of directives. */ + spec->directives++; + + /* Parse parameters. */ + for (;;) + { + enum param_type type = PT_NIL; + int value = 0; + + if (c_isdigit (*format)) + { + type = PT_INTEGER; + do + { + value = 10 * value + (*format - '0'); + format++; + } + while (c_isdigit (*format)); + } + else if (*format == '+' || *format == '-') + { + bool negative = (*format == '-'); + type = PT_INTEGER; + format++; + if (!c_isdigit (*format)) + { + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + xasprintf (_("In the directive number %u, '%c' is not followed by a digit."), spec->directives, format[-1]); + FDI_SET (format, FMTDIR_ERROR); + } + return false; + } + do + { + value = 10 * value + (*format - '0'); + format++; + } + while (c_isdigit (*format)); + if (negative) + value = -value; + } + else if (*format == '\'') + { + type = PT_CHARACTER; + format++; + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + format++; + } + else if (*format == 'V' || *format == 'v') + { + type = PT_V; + format++; + value = position; + /* Consumes an argument. */ + if (position >= 0) + position++; + } + else if (*format == '#') + { + type = PT_ARGCOUNT; + format++; + } + + params = + (struct param *) + xrealloc (params, (paramcount + 1) * sizeof (struct param)); + params[paramcount].type = type; + params[paramcount].value = value; + paramcount++; + + if (*format == ',') + format++; + else + break; + } + + /* Parse modifiers. */ + for (;;) + { + if (*format == ':') + { + format++; + colon_p = true; + } + else if (*format == '@') + { + format++; + atsign_p = true; + } + else + break; + } + + /* Parse directive. */ + switch (*format++) + { + case 'A': case 'a': /* 22.3.4.1 FORMAT-ASCII */ + case 'S': case 's': /* 22.3.4.2 FORMAT-S-EXPRESSION */ + if (!check_params (&list, paramcount, params, 4, IIIC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_OBJECT); + break; + + case 'W': case 'w': /* 22.3.4.3 FORMAT-WRITE */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_OBJECT); + break; + + case 'D': case 'd': /* 22.3.2.2 FORMAT-DECIMAL */ + case 'B': case 'b': /* 22.3.2.3 FORMAT-BINARY */ + case 'O': case 'o': /* 22.3.2.4 FORMAT-OCTAL */ + case 'X': case 'x': /* 22.3.2.5 FORMAT-HEXADECIMAL */ + if (!check_params (&list, paramcount, params, 4, ICCI, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_INTEGER); + break; + + case 'R': case 'r': /* 22.3.2.1 FORMAT-RADIX */ + if (!check_params (&list, paramcount, params, 5, IICCI, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_INTEGER); + break; + + case 'P': case 'p': /* 22.3.8.3 FORMAT-PLURAL */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (colon_p) + { + /* Go back by 1 argument. */ + if (position > 0) + position--; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_OBJECT); + break; + + case 'C': case 'c': /* 22.3.1.1 FORMAT-CHARACTER */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_CHARACTER); + break; + + case 'F': case 'f': /* 22.3.3.1 FORMAT-FIXED-FLOAT */ + if (!check_params (&list, paramcount, params, 5, IIICC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_REAL); + break; + + case 'E': case 'e': /* 22.3.3.2 FORMAT-EXPONENTIAL-FLOAT */ + case 'G': case 'g': /* 22.3.3.3 FORMAT-GENERAL-FLOAT */ + if (!check_params (&list, paramcount, params, 7, IIIICCC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_REAL); + break; + + case '$': /* 22.3.3.4 FORMAT-DOLLARS-FLOAT */ + if (!check_params (&list, paramcount, params, 4, IIIC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_REAL); + break; + + case '%': /* 22.3.1.2 FORMAT-TERPRI */ + case '&': /* 22.3.1.3 FORMAT-FRESH-LINE */ + case '|': /* 22.3.1.4 FORMAT-PAGE */ + case '~': /* 22.3.1.5 FORMAT-TILDE */ + case 'I': case 'i': /* 22.3.5.3 */ + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + break; + + case '\n': /* 22.3.9.3 #\Newline */ + case '_': /* 22.3.5.1 */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + break; + + case 'T': case 't': /* 22.3.6.1 FORMAT-TABULATE */ + if (!check_params (&list, paramcount, params, 2, II, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + break; + + case '*': /* 22.3.7.1 FORMAT-GOTO */ + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + { + int n; /* value of first parameter */ + if (paramcount == 0 + || (paramcount >= 1 && params[0].type == PT_NIL)) + n = (atsign_p ? 0 : 1); + else if (paramcount >= 1 && params[0].type == PT_INTEGER) + n = params[0].value; + else + { + /* Unknown argument, leads to an unknown position. */ + position = -1; + break; + } + if (n < 0) + { + /* invalid argument */ + *invalid_reason = + xasprintf (_("In the directive number %u, the argument %d is negative."), spec->directives, n); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (atsign_p) + { + /* Absolute goto. */ + position = n; + } + else if (colon_p) + { + /* Backward goto. */ + if (n > 0) + { + if (position >= 0) + { + if (position >= n) + position -= n; + else + position = 0; + } + else + position = -1; + } + } + else + { + /* Forward goto. */ + if (position >= 0) + position += n; + } + } + break; + + case '?': /* 22.3.7.6 FORMAT-INDIRECTION */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_FORMATSTRING); + if (atsign_p) + position = -1; + else + if (position >= 0) + { + struct format_arg_list *sublist = make_unconstrained_list (); + add_req_listtype_constraint (&list, position++, + FAT_LIST, sublist); + free_list (sublist); + } + break; + + case '/': /* 22.3.5.4 FORMAT-CALL-USER-FUNCTION */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_OBJECT); + while (*format != '\0' && *format != '/') + format++; + if (*format == '\0') + { + *invalid_reason = + xstrdup (_("The string ends in the middle of a ~/.../ directive.")); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + format++; + break; + + case '(': /* 22.3.8.1 FORMAT-CASE-CONVERSION */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + { + if (!parse_upto (formatp, positionp, listp, escapep, + NULL, spec, ')', false, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + } + format = *formatp; + position = *positionp; + list = *listp; + escape = *escapep; + break; + + case ')': /* 22.3.8.2 FORMAT-CASE-CONVERSION-END */ + if (terminator != ')') + { + *invalid_reason = + xasprintf (_("Found '~%c' without matching '~%c'."), ')', '('); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + return true; + + case '[': /* 22.3.7.2 FORMAT-CONDITIONAL */ + if (atsign_p && colon_p) + { + *invalid_reason = + xasprintf (_("In the directive number %u, both the @ and the : modifiers are given."), spec->directives); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + else if (atsign_p) + { + struct format_arg_list *nil_list; + struct format_arg_list *union_list; + + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + + *formatp = format; + *escapep = escape; + + /* First alternative: argument is NIL. */ + nil_list = (list != NULL ? copy_list (list) : NULL); + if (position >= 0) + { + struct format_arg_list *empty_list = make_empty_list (); + add_req_listtype_constraint (&nil_list, position, + FAT_LIST, empty_list); + free_list (empty_list); + } + + /* Second alternative: use sub-format. */ + { + int sub_position = position; + struct format_arg_list *sub_list = + (list != NULL ? copy_list (list) : NULL); + if (!parse_upto (formatp, &sub_position, &sub_list, escapep, + NULL, spec, ']', false, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + if (sub_list != NULL) + { + if (position >= 0) + { + if (sub_position == position + 1) + /* new position is branch independent */ + position = position + 1; + else + /* new position is branch dependent */ + position = -1; + } + } + else + { + if (position >= 0) + position = position + 1; + } + union_list = union (nil_list, sub_list); + } + + format = *formatp; + escape = *escapep; + + if (list != NULL) + free_list (list); + list = union_list; + } + else if (colon_p) + { + int union_position; + struct format_arg_list *union_list; + + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_OBJECT); + + *formatp = format; + *escapep = escape; + union_position = -2; + union_list = NULL; + + /* First alternative. */ + { + int sub_position = position; + struct format_arg_list *sub_list = + (list != NULL ? copy_list (list) : NULL); + int sub_separator = 0; + if (position >= 0) + { + struct format_arg_list *empty_list = make_empty_list (); + add_req_listtype_constraint (&sub_list, position - 1, + FAT_LIST, empty_list); + free_list (empty_list); + } + if (!parse_upto (formatp, &sub_position, &sub_list, escapep, + &sub_separator, spec, ']', true, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + if (!sub_separator) + { + *invalid_reason = + xasprintf (_("In the directive number %u, '~:[' is not followed by two clauses, separated by '~;'."), spec->directives); + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + if (sub_list != NULL) + union_position = sub_position; + union_list = union (union_list, sub_list); + } + + /* Second alternative. */ + { + int sub_position = position; + struct format_arg_list *sub_list = + (list != NULL ? copy_list (list) : NULL); + if (!parse_upto (formatp, &sub_position, &sub_list, escapep, + NULL, spec, ']', false, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + if (sub_list != NULL) + { + if (union_position == -2) + union_position = sub_position; + else if (sub_position < 0 + || sub_position != union_position) + union_position = -1; + } + union_list = union (union_list, sub_list); + } + + format = *formatp; + escape = *escapep; + + if (union_position != -2) + position = union_position; + if (list != NULL) + free_list (list); + list = union_list; + } + else + { + int arg_position; + int union_position; + struct format_arg_list *union_list; + bool last_alternative; + + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + + /* If there was no first parameter, an argument is consumed. */ + arg_position = -1; + if (!(paramcount >= 1 && params[0].type != PT_NIL)) + if (position >= 0) + { + arg_position = position; + add_req_type_constraint (&list, position++, FAT_OBJECT); + } + + *formatp = format; + *escapep = escape; + + union_position = -2; + union_list = NULL; + last_alternative = false; + for (;;) + { + /* Next alternative. */ + int sub_position = position; + struct format_arg_list *sub_list = + (list != NULL ? copy_list (list) : NULL); + int sub_separator = 0; + if (!parse_upto (formatp, &sub_position, &sub_list, escapep, + &sub_separator, spec, ']', !last_alternative, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + /* If this alternative is chosen, the argument arg_position + is an integer, namely the index of this alternative. */ + if (!last_alternative && arg_position >= 0) + add_req_type_constraint (&sub_list, arg_position, + FAT_INTEGER); + if (sub_list != NULL) + { + if (union_position == -2) + union_position = sub_position; + else if (sub_position < 0 + || sub_position != union_position) + union_position = -1; + } + union_list = union (union_list, sub_list); + if (sub_separator == 2) + last_alternative = true; + if (!sub_separator) + break; + } + if (!last_alternative) + { + /* An implicit default alternative. */ + if (union_position == -2) + union_position = position; + else if (position < 0 || position != union_position) + union_position = -1; + if (list != NULL) + union_list = union (union_list, copy_list (list)); + } + + format = *formatp; + escape = *escapep; + + if (union_position != -2) + position = union_position; + if (list != NULL) + free_list (list); + list = union_list; + } + break; + + case ']': /* 22.3.7.3 FORMAT-CONDITIONAL-END */ + if (terminator != ']') + { + *invalid_reason = + xasprintf (_("Found '~%c' without matching '~%c'."), ']', '['); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + return true; + + case '{': /* 22.3.7.4 FORMAT-ITERATION */ + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + { + int sub_position = 0; + struct format_arg_list *sub_list = make_unconstrained_list (); + struct format_arg_list *sub_escape = NULL; + struct spec sub_spec; + sub_spec.directives = 0; + sub_spec.list = sub_list; + if (!parse_upto (formatp, &sub_position, &sub_list, &sub_escape, + NULL, &sub_spec, '}', false, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + spec->directives += sub_spec.directives; + + /* If the sub-formatstring is empty, except for the terminating + ~} directive, a formatstring argument is consumed. */ + if (*format == '~' && sub_spec.directives == 1) + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_FORMATSTRING); + + if (colon_p) + { + /* Each iteration uses a new sublist. */ + struct format_arg_list *listlist; + + /* ~{ catches ~^. */ + sub_list = union (sub_list, sub_escape); + + listlist = make_repeated_list_of_lists (sub_list); + + sub_list = listlist; + } + else + { + /* Each iteration's arguments are all concatenated in a + single list. */ + struct format_arg_list *looplist; + + /* FIXME: This is far from correct. Test cases: + abc~{~^~} + abc~{~S~^~S~} + abc~{~D~^~C~} + abc~{~D~^~D~} + abc~{~D~^~S~} + abc~{~D~^~C~}~:*~{~S~^~D~} + */ + + /* ~{ catches ~^. */ + sub_list = union (sub_list, sub_escape); + + if (sub_list == NULL) + looplist = make_empty_list (); + else + if (sub_position < 0 || sub_position == 0) + /* Too hard to track the possible argument types + when the iteration is performed 2 times or more. + So be satisfied with the constraints of executing + the iteration 1 or 0 times. */ + looplist = make_union_with_empty_list (sub_list); + else + looplist = make_repeated_list (sub_list, sub_position); + + sub_list = looplist; + } + + if (atsign_p) + { + /* All remaining arguments are used. */ + if (list != NULL && position >= 0) + { + shift_list (sub_list, position); + list = make_intersected_list (list, sub_list); + } + position = -1; + } + else + { + /* The argument is a list. */ + if (position >= 0) + add_req_listtype_constraint (&list, position++, + FAT_LIST, sub_list); + } + } + format = *formatp; + break; + + case '}': /* 22.3.7.5 FORMAT-ITERATION-END */ + if (terminator != '}') + { + *invalid_reason = + xasprintf (_("Found '~%c' without matching '~%c'."), '}', '{'); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + return true; + + case '<': /* 22.3.6.2, 22.3.5.2 FORMAT-JUSTIFICATION */ + if (!check_params (&list, paramcount, params, 4, IIIC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + { + struct format_arg_list *sub_escape = NULL; + + *formatp = format; + *positionp = position; + *listp = list; + + for (;;) + { + int sub_separator = 0; + if (!parse_upto (formatp, positionp, listp, &sub_escape, + &sub_separator, spec, '>', true, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + if (!sub_separator) + break; + } + + format = *formatp; + position = *positionp; + list = *listp; + + /* ~< catches ~^. */ + if (sub_escape != NULL) + position = -1; + list = union (list, sub_escape); + } + break; + + case '>': /* 22.3.6.3 FORMAT-JUSTIFICATION-END */ + if (terminator != '>') + { + *invalid_reason = + xasprintf (_("Found '~%c' without matching '~%c'."), '>', '<'); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + return true; + + case '^': /* 22.3.9.2 FORMAT-UP-AND-OUT */ + if (!check_params (&list, paramcount, params, 3, THREE, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0 && list != NULL && is_required (list, position)) + /* This ~^ can never be executed. Ignore it. */ + break; + if (list != NULL) + { + struct format_arg_list *this_escape = copy_list (list); + if (position >= 0) + this_escape = add_end_constraint (this_escape, position); + escape = union (escape, this_escape); + } + if (position >= 0) + list = add_required_constraint (list, position); + break; + + case ';': /* 22.3.9.1 FORMAT-SEPARATOR */ + if (!separator) + { + *invalid_reason = + xasprintf (_("In the directive number %u, '~;' is used in an invalid position."), spec->directives); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (terminator == '>') + { + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + } + else + { + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + *separatorp = (colon_p ? 2 : 1); + return true; + + case '!': /* FORMAT-CALL, a CLISP extension */ + if (!nocheck_params (&list, paramcount, params, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + { + add_req_type_constraint (&list, position++, FAT_FUNCTION); + add_req_type_constraint (&list, position++, FAT_OBJECT); + } + break; + + default: + --format; + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (spec->directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + return false; + } + + FDI_SET (format - 1, FMTDIR_END); + + free (params); } *formatp = format; @@ -3394,7 +3394,7 @@ parse_upto (const char **formatp, if (terminator != '\0') { *invalid_reason = - xasprintf (_("Found '~%c' without matching '~%c'."), terminator - 1, terminator); + xasprintf (_("Found '~%c' without matching '~%c'."), terminator - 1, terminator); return false; } return true; @@ -3405,7 +3405,7 @@ parse_upto (const char **formatp, static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { struct spec spec; struct spec *result; @@ -3417,8 +3417,8 @@ format_parse (const char *format, bool translated, char *fdi, escape = NULL; if (!parse_upto (&format, &position, &spec.list, &escape, - NULL, &spec, '\0', false, - fdi, invalid_reason)) + NULL, &spec, '\0', false, + fdi, invalid_reason)) /* Invalid format string. */ return NULL; @@ -3429,7 +3429,7 @@ format_parse (const char *format, bool translated, char *fdi, { /* Contradictory argument type information. */ *invalid_reason = - xstrdup (_("The string refers to some argument in incompatible ways.")); + xstrdup (_("The string refers to some argument in incompatible ways.")); return NULL; } @@ -3459,8 +3459,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -3469,28 +3469,28 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, if (equality) { if (!equal_list (spec1->list, spec2->list)) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' are not equivalent"), - pretty_msgid, pretty_msgstr); - err = true; - } + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' are not equivalent"), + pretty_msgid, pretty_msgstr); + err = true; + } } else { struct format_arg_list *intersection = - make_intersected_list (copy_list (spec1->list), - copy_list (spec2->list)); + make_intersected_list (copy_list (spec1->list), + copy_list (spec2->list)); if (!(intersection != NULL - && (normalize_list (intersection), - equal_list (intersection, spec2->list)))) - { - if (error_logger) - error_logger (_("format specifications in '%s' are not a subset of those in '%s'"), - pretty_msgstr, pretty_msgid); - err = true; - } + && (normalize_list (intersection), + equal_list (intersection, spec2->list)))) + { + if (error_logger) + error_logger (_("format specifications in '%s' are not a subset of those in '%s'"), + pretty_msgstr, pretty_msgid); + err = true; + } } return err; @@ -3581,20 +3581,20 @@ print_list (struct format_arg_list *list) for (i = 0; i < list->initial.count; i++) for (j = 0; j < list->initial.element[i].repcount; j++) { - if (i > 0 || j > 0) - printf (" "); - print_element (&list->initial.element[i]); + if (i > 0 || j > 0) + printf (" "); + print_element (&list->initial.element[i]); } if (list->repeated.count > 0) { printf (" |"); for (i = 0; i < list->repeated.count; i++) - for (j = 0; j < list->repeated.element[i].repcount; j++) - { - printf (" "); - print_element (&list->repeated.element[i]); - } + for (j = 0; j < list->repeated.element[i].repcount; j++) + { + printf (" "); + print_element (&list->repeated.element[i]); + } } printf (")"); @@ -3627,9 +3627,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -3637,7 +3637,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-pascal.c b/gettext-tools/src/format-pascal.c index be5e3cc5e..c8fea176e 100644 --- a/gettext-tools/src/format-pascal.c +++ b/gettext-tools/src/format-pascal.c @@ -64,10 +64,10 @@ enum format_arg_type { - FAT_INTEGER, /* integer */ - FAT_INTEGER64, /* integer, int64 */ - FAT_FLOAT, /* extended */ - FAT_STRING, /* string, char, pchar, ansistring */ + FAT_INTEGER, /* integer */ + FAT_INTEGER64, /* integer, int64 */ + FAT_FLOAT, /* extended */ + FAT_STRING, /* string, char, pchar, ansistring */ FAT_POINTER }; @@ -103,7 +103,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; unsigned int directives; @@ -115,9 +115,9 @@ format_parse (const char *format, bool translated, char *fdi, enum arg_index { - index_numbered, /* index given by a fixed integer */ - index_unnumbered, /* index given by unnumbered_arg_count++ */ - index_unknown /* index is only known at run time */ + index_numbered, /* index given by a fixed integer */ + index_unnumbered, /* index given by unnumbered_arg_count++ */ + index_unknown /* index is only known at run time */ }; directives = 0; @@ -129,164 +129,164 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - FDI_SET (format - 1, FMTDIR_START); - directives++; - - if (*format != '%') - { - /* A complex directive. */ - enum arg_index main_arg = index_unnumbered; - unsigned int main_number = 0; - enum format_arg_type type; - - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == ':') - { - main_number = m; - main_arg = index_numbered; - format = ++f; - } - } - else if (*format == '*') - { - if (format[1] == ':') - { - main_arg = index_unknown; - format += 2; - } - } - - /* Parse flags. */ - if (*format == '-') - format++; - - /* Parse width. */ - if (isdigit (*format)) - { - do - format++; - while (isdigit (*format)); - } - else if (*format == '*') - { - /* Unnumbered argument of type FAT_INTEGER. */ - if (allocated == numbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = unnumbered_arg_count; - numbered[numbered_arg_count].type = FAT_INTEGER; - numbered_arg_count++; - unnumbered_arg_count++; - - format++; - } - - /* Parse precision. */ - if (*format == '.') - { - format++; - - if (isdigit (*format)) - { - do - format++; - while (isdigit (*format)); - } - else if (*format == '*') - { - /* Unnumbered argument of type FAT_INTEGER. */ - if (allocated == unnumbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = unnumbered_arg_count; - numbered[numbered_arg_count].type = FAT_INTEGER; - numbered_arg_count++; - unnumbered_arg_count++; - - format++; - } - else - --format; /* will jump to bad_format */ - } - - switch (c_tolower (*format)) - { - case 'd': - type = FAT_INTEGER64; - break; - case 'e': case 'f': case 'g': case 'n': case 'm': - type = FAT_FLOAT; - break; - case 's': - type = FAT_STRING; - break; - case 'p': - type = FAT_POINTER; - break; - case 'x': - type = FAT_INTEGER; - break; - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - if (allocated == numbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - switch (main_arg) - { - case index_unnumbered: - numbered[numbered_arg_count].number = unnumbered_arg_count; - numbered[numbered_arg_count].type = type; - unnumbered_arg_count++; - break; - case index_numbered: - numbered[numbered_arg_count].number = main_number; - numbered[numbered_arg_count].type = type; - break; - case index_unknown: - numbered[numbered_arg_count].number = unnumbered_arg_count; - numbered[numbered_arg_count].type = FAT_INTEGER; - unnumbered_arg_count++; - break; - default: - abort (); - } - numbered_arg_count++; - } - - FDI_SET (format, FMTDIR_END); - - format++; + /* A directive. */ + FDI_SET (format - 1, FMTDIR_START); + directives++; + + if (*format != '%') + { + /* A complex directive. */ + enum arg_index main_arg = index_unnumbered; + unsigned int main_number = 0; + enum format_arg_type type; + + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == ':') + { + main_number = m; + main_arg = index_numbered; + format = ++f; + } + } + else if (*format == '*') + { + if (format[1] == ':') + { + main_arg = index_unknown; + format += 2; + } + } + + /* Parse flags. */ + if (*format == '-') + format++; + + /* Parse width. */ + if (isdigit (*format)) + { + do + format++; + while (isdigit (*format)); + } + else if (*format == '*') + { + /* Unnumbered argument of type FAT_INTEGER. */ + if (allocated == numbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = unnumbered_arg_count; + numbered[numbered_arg_count].type = FAT_INTEGER; + numbered_arg_count++; + unnumbered_arg_count++; + + format++; + } + + /* Parse precision. */ + if (*format == '.') + { + format++; + + if (isdigit (*format)) + { + do + format++; + while (isdigit (*format)); + } + else if (*format == '*') + { + /* Unnumbered argument of type FAT_INTEGER. */ + if (allocated == unnumbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = unnumbered_arg_count; + numbered[numbered_arg_count].type = FAT_INTEGER; + numbered_arg_count++; + unnumbered_arg_count++; + + format++; + } + else + --format; /* will jump to bad_format */ + } + + switch (c_tolower (*format)) + { + case 'd': + type = FAT_INTEGER64; + break; + case 'e': case 'f': case 'g': case 'n': case 'm': + type = FAT_FLOAT; + break; + case 's': + type = FAT_STRING; + break; + case 'p': + type = FAT_POINTER; + break; + case 'x': + type = FAT_INTEGER; + break; + default: + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + + if (allocated == numbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + switch (main_arg) + { + case index_unnumbered: + numbered[numbered_arg_count].number = unnumbered_arg_count; + numbered[numbered_arg_count].type = type; + unnumbered_arg_count++; + break; + case index_numbered: + numbered[numbered_arg_count].number = main_number; + numbered[numbered_arg_count].type = type; + break; + case index_unknown: + numbered[numbered_arg_count].number = unnumbered_arg_count; + numbered[numbered_arg_count].type = FAT_INTEGER; + unnumbered_arg_count++; + break; + default: + abort (); + } + numbered_arg_count++; + } + + FDI_SET (format, FMTDIR_END); + + format++; } /* Sort the numbered argument array, and eliminate duplicates. */ @@ -296,47 +296,47 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (numbered, numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < numbered_arg_count; i++) - if (j > 0 && numbered[i].number == numbered[j-1].number) - { - enum format_arg_type type1 = numbered[i].type; - enum format_arg_type type2 = numbered[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2) - type_both = type1; - else if ((type1 == FAT_INTEGER && type2 == FAT_INTEGER64) - || (type1 == FAT_INTEGER64 && type2 == FAT_INTEGER)) - type_both = FAT_INTEGER; - else - { - /* Incompatible types. */ - type_both = type1; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (numbered[i].number); - err = true; - } - - numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - numbered[j].number = numbered[i].number; - numbered[j].type = numbered[i].type; - } - j++; - } + if (j > 0 && numbered[i].number == numbered[j-1].number) + { + enum format_arg_type type1 = numbered[i].type; + enum format_arg_type type2 = numbered[j-1].type; + enum format_arg_type type_both; + + if (type1 == type2) + type_both = type1; + else if ((type1 == FAT_INTEGER && type2 == FAT_INTEGER64) + || (type1 == FAT_INTEGER64 && type2 == FAT_INTEGER)) + type_both = FAT_INTEGER; + else + { + /* Incompatible types. */ + type_both = type1; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (numbered[i].number); + err = true; + } + + numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + numbered[j].number = numbered[i].number; + numbered[j].type = numbered[i].type; + } + j++; + } numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -372,8 +372,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -386,60 +386,60 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->numbered_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } /* Check the argument types are the same. */ if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } + for (i = 0, j = 0; j < n2; ) + { + if (spec1->numbered[i].number == spec2->numbered[j].number) + { + if (spec1->numbered[i].type != spec2->numbered[j].type) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, + spec2->numbered[j].number); + err = true; + break; + } + j++, i++; + } + else + i++; + } } return err; @@ -483,31 +483,31 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); switch (spec->numbered[i].type) - { - case FAT_INTEGER: - printf ("i"); - break; - case FAT_INTEGER64: - printf ("I"); - break; - case FAT_FLOAT: - printf ("f"); - break; - case FAT_STRING: - printf ("s"); - break; - case FAT_POINTER: - printf ("p"); - break; - default: - abort (); - } + { + case FAT_INTEGER: + printf ("i"); + break; + case FAT_INTEGER64: + printf ("I"); + break; + case FAT_FLOAT: + printf ("f"); + break; + case FAT_STRING: + printf ("s"); + break; + case FAT_POINTER: + printf ("p"); + break; + default: + abort (); + } last = number + 1; } printf (")"); @@ -526,9 +526,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -536,7 +536,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-perl-brace.c b/gettext-tools/src/format-perl-brace.c index 65f9d20ff..3ab05ce93 100644 --- a/gettext-tools/src/format-perl-brace.c +++ b/gettext-tools/src/format-perl-brace.c @@ -55,12 +55,12 @@ static int named_arg_compare (const void *p1, const void *p2) { return strcmp (((const struct named_arg *) p1)->name, - ((const struct named_arg *) p2)->name); + ((const struct named_arg *) p2)->name); } static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -74,45 +74,45 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '{') { - const char *f = format; - char c; - - c = *f; - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') - { - do - c = *++f; - while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' - || (c >= '0' && c <= '9')); - if (c == '}') - { - /* A directive. */ - char *name; - const char *name_start = format; - const char *name_end = f; - size_t n = name_end - name_start; - - FDI_SET (format - 1, FMTDIR_START); - - name = XNMALLOC (n + 1, char); - memcpy (name, name_start, n); - name[n] = '\0'; - - spec.directives++; - - if (spec.allocated == spec.named_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.named = (struct named_arg *) xrealloc (spec.named, spec.allocated * sizeof (struct named_arg)); - } - spec.named[spec.named_arg_count].name = name; - spec.named_arg_count++; - - FDI_SET (f, FMTDIR_END); - - format = ++f; - } - } + const char *f = format; + char c; + + c = *f; + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') + { + do + c = *++f; + while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' + || (c >= '0' && c <= '9')); + if (c == '}') + { + /* A directive. */ + char *name; + const char *name_start = format; + const char *name_end = f; + size_t n = name_end - name_start; + + FDI_SET (format - 1, FMTDIR_START); + + name = XNMALLOC (n + 1, char); + memcpy (name, name_start, n); + name[n] = '\0'; + + spec.directives++; + + if (spec.allocated == spec.named_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.named = (struct named_arg *) xrealloc (spec.named, spec.allocated * sizeof (struct named_arg)); + } + spec.named[spec.named_arg_count].name = name; + spec.named_arg_count++; + + FDI_SET (f, FMTDIR_END); + + format = ++f; + } + } } /* Sort the named argument array, and eliminate duplicates. */ @@ -121,18 +121,18 @@ format_parse (const char *format, bool translated, char *fdi, unsigned int i, j; qsort (spec.named, spec.named_arg_count, sizeof (struct named_arg), - named_arg_compare); + named_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ for (i = j = 0; i < spec.named_arg_count; i++) - if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0) - free (spec.named[i].name); - else - { - if (j < i) - spec.named[j].name = spec.named[i].name; - j++; - } + if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0) + free (spec.named[i].name); + else + { + if (j < i) + spec.named[j].name = spec.named[i].name; + j++; + } spec.named_arg_count = j; } @@ -150,7 +150,7 @@ format_free (void *descr) { unsigned int i; for (i = 0; i < spec->named_arg_count; i++) - free (spec->named[i].name); + free (spec->named[i].name); free (spec->named); } free (spec); @@ -166,8 +166,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -180,33 +180,33 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->named_arg_count; /* Check the argument names in spec1 are contained in those of spec2. - Additional arguments in spec2 are allowed; they expand to themselves - (including the surrounding braces) at runtime. - Both arrays are sorted. We search for the differences. */ + Additional arguments in spec2 are allowed; they expand to themselves + (including the surrounding braces) at runtime. + Both arrays are sorted. We search for the differences. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - strcmp (spec1->named[i].name, spec2->named[j].name)); - - if (cmp > 0) - j++; - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument '%s' doesn't exist in '%s'"), - spec1->named[i].name, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + strcmp (spec1->named[i].name, spec2->named[j].name)); + + if (cmp > 0) + j++; + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument '%s' doesn't exist in '%s'"), + spec1->named[i].name, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } } return err; @@ -246,7 +246,7 @@ format_print (void *descr) for (i = 0; i < spec->named_arg_count; i++) { if (i > 0) - printf (", "); + printf (", "); printf ("'%s'", spec->named[i].name); } printf ("}"); @@ -265,9 +265,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -275,7 +275,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-perl.c b/gettext-tools/src/format-perl.c index 7a7dbc370..730d19010 100644 --- a/gettext-tools/src/format-perl.c +++ b/gettext-tools/src/format-perl.c @@ -73,25 +73,25 @@ enum format_arg_type { - FAT_NONE = 0, + FAT_NONE = 0, /* Basic types */ - FAT_INTEGER = 1, - FAT_DOUBLE = 2, - FAT_CHAR = 3, - FAT_STRING = 4, - FAT_SCALAR_VECTOR = 5, - FAT_POINTER = 6, - FAT_COUNT_POINTER = 7, + FAT_INTEGER = 1, + FAT_DOUBLE = 2, + FAT_CHAR = 3, + FAT_STRING = 4, + FAT_SCALAR_VECTOR = 5, + FAT_POINTER = 6, + FAT_COUNT_POINTER = 7, /* Flags */ - FAT_UNSIGNED = 1 << 3, - FAT_SIZE_SHORT = 1 << 4, - FAT_SIZE_V = 2 << 4, - FAT_SIZE_PTR = 3 << 4, - FAT_SIZE_LONG = 4 << 4, - FAT_SIZE_LONGLONG = 5 << 4, + FAT_UNSIGNED = 1 << 3, + FAT_SIZE_SHORT = 1 << 4, + FAT_SIZE_V = 2 << 4, + FAT_SIZE_PTR = 3 << 4, + FAT_SIZE_LONG = 4 << 4, + FAT_SIZE_LONGLONG = 5 << 4, /* Bitmasks */ - FAT_SIZE_MASK = (FAT_SIZE_SHORT | FAT_SIZE_V | FAT_SIZE_PTR - | FAT_SIZE_LONG | FAT_SIZE_LONGLONG) + FAT_SIZE_MASK = (FAT_SIZE_SHORT | FAT_SIZE_V | FAT_SIZE_PTR + | FAT_SIZE_LONG | FAT_SIZE_LONGLONG) }; #ifdef __cplusplus typedef int format_arg_type_t; @@ -134,7 +134,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; unsigned int directives; @@ -153,326 +153,326 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - unsigned int number = 0; - bool vectorize = false; - format_arg_type_t type; - format_arg_type_t size; - - FDI_SET (format - 1, FMTDIR_START); - directives++; - - if (isnonzerodigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - number = m; - format = ++f; - } - } - - /* Parse flags. */ - while (*format == ' ' || *format == '+' || *format == '-' - || *format == '#' || *format == '0') - format++; - - /* Parse vector. */ - if (*format == 'v') - { - format++; - vectorize = true; - } - else if (*format == '*') - { - const char *f = format; - - f++; - if (*f == 'v') - { - format = ++f; - vectorize = true; - - /* Unnumbered argument. */ - if (allocated == numbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = ++unnumbered_arg_count; - numbered[numbered_arg_count].type = FAT_SCALAR_VECTOR; /* or FAT_STRING? */ - numbered_arg_count++; - } - else if (isnonzerodigit (*f)) - { - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - f++; - if (*f == 'v') - { - unsigned int vector_number = m; - - format = ++f; - vectorize = true; - - /* Numbered argument. */ - /* Note: As of perl-5.8.0, this is not correctly - implemented in perl's sv.c. */ - if (allocated == numbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = vector_number; - numbered[numbered_arg_count].type = FAT_SCALAR_VECTOR; /* or FAT_STRING? */ - numbered_arg_count++; - } - } - } - } - - if (vectorize) - { - /* Numbered or unnumbered argument. */ - if (allocated == numbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = (number ? number : ++unnumbered_arg_count); - numbered[numbered_arg_count].type = FAT_SCALAR_VECTOR; - numbered_arg_count++; - } - - /* Parse width. */ - if (*format == '*') - { - unsigned int width_number = 0; - - format++; - - if (isnonzerodigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - width_number = m; - format = ++f; - } - } - - /* Numbered or unnumbered argument. */ - /* Note: As of perl-5.8.0, this is not correctly - implemented in perl's sv.c. */ - if (allocated == numbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = (width_number ? width_number : ++unnumbered_arg_count); - numbered[numbered_arg_count].type = FAT_INTEGER; - numbered_arg_count++; - } - else if (isnonzerodigit (*format)) - { - do format++; while (isdigit (*format)); - } - - /* Parse precision. */ - if (*format == '.') - { - format++; - - if (*format == '*') - { - unsigned int precision_number = 0; - - format++; - - if (isnonzerodigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - precision_number = m; - format = ++f; - } - } - - /* Numbered or unnumbered argument. */ - if (allocated == numbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = (precision_number ? precision_number : ++unnumbered_arg_count); - numbered[numbered_arg_count].type = FAT_INTEGER; - numbered_arg_count++; - } - else - { - while (isdigit (*format)) format++; - } - } - - /* Parse size. */ - size = 0; - if (*format == 'h') - { - size = FAT_SIZE_SHORT; - format++; - } - else if (*format == 'l') - { - if (format[1] == 'l') - { - size = FAT_SIZE_LONGLONG; - format += 2; - } - else - { - size = FAT_SIZE_LONG; - format++; - } - } - else if (*format == 'L' || *format == 'q') - { - size = FAT_SIZE_LONGLONG; - format++; - } - else if (*format == 'V') - { - size = FAT_SIZE_V; - format++; - } - else if (*format == 'I') - { - if (format[1] == '6' && format[2] == '4') - { - size = FAT_SIZE_LONGLONG; - format += 3; - } - else if (format[1] == '3' && format[2] == '2') - { - size = 0; /* FAT_SIZE_INT */ - format += 3; - } - else - { - size = FAT_SIZE_PTR; - format++; - } - } - - switch (*format) - { - case '%': - type = FAT_NONE; - break; - case 'c': - type = FAT_CHAR; - break; - case 's': - type = FAT_STRING; - break; - case '_': - type = FAT_SCALAR_VECTOR; - break; - case 'D': - type = FAT_INTEGER | FAT_SIZE_V; - break; - case 'i': case 'd': - type = FAT_INTEGER | size; - break; - case 'U': case 'O': - type = FAT_INTEGER | FAT_UNSIGNED | FAT_SIZE_V; - break; - case 'u': case 'b': case 'o': case 'x': case 'X': - type = FAT_INTEGER | FAT_UNSIGNED | size; - break; - case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': - if (size == FAT_SIZE_SHORT || size == FAT_SIZE_LONG) - { - *invalid_reason = - xasprintf (_("In the directive number %u, the size specifier is incompatible with the conversion specifier '%c'."), directives, *format); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - type = FAT_DOUBLE | size; - break; - case 'p': - type = FAT_POINTER; - break; - case 'n': - type = FAT_COUNT_POINTER | size; - break; - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - if (type != FAT_NONE && !vectorize) - { - /* Numbered or unnumbered argument. */ - if (allocated == numbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = (number ? number : ++unnumbered_arg_count); - numbered[numbered_arg_count].type = type; - numbered_arg_count++; - } - - FDI_SET (format, FMTDIR_END); - - format++; + /* A directive. */ + unsigned int number = 0; + bool vectorize = false; + format_arg_type_t type; + format_arg_type_t size; + + FDI_SET (format - 1, FMTDIR_START); + directives++; + + if (isnonzerodigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + number = m; + format = ++f; + } + } + + /* Parse flags. */ + while (*format == ' ' || *format == '+' || *format == '-' + || *format == '#' || *format == '0') + format++; + + /* Parse vector. */ + if (*format == 'v') + { + format++; + vectorize = true; + } + else if (*format == '*') + { + const char *f = format; + + f++; + if (*f == 'v') + { + format = ++f; + vectorize = true; + + /* Unnumbered argument. */ + if (allocated == numbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = ++unnumbered_arg_count; + numbered[numbered_arg_count].type = FAT_SCALAR_VECTOR; /* or FAT_STRING? */ + numbered_arg_count++; + } + else if (isnonzerodigit (*f)) + { + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + f++; + if (*f == 'v') + { + unsigned int vector_number = m; + + format = ++f; + vectorize = true; + + /* Numbered argument. */ + /* Note: As of perl-5.8.0, this is not correctly + implemented in perl's sv.c. */ + if (allocated == numbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = vector_number; + numbered[numbered_arg_count].type = FAT_SCALAR_VECTOR; /* or FAT_STRING? */ + numbered_arg_count++; + } + } + } + } + + if (vectorize) + { + /* Numbered or unnumbered argument. */ + if (allocated == numbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = (number ? number : ++unnumbered_arg_count); + numbered[numbered_arg_count].type = FAT_SCALAR_VECTOR; + numbered_arg_count++; + } + + /* Parse width. */ + if (*format == '*') + { + unsigned int width_number = 0; + + format++; + + if (isnonzerodigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + width_number = m; + format = ++f; + } + } + + /* Numbered or unnumbered argument. */ + /* Note: As of perl-5.8.0, this is not correctly + implemented in perl's sv.c. */ + if (allocated == numbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = (width_number ? width_number : ++unnumbered_arg_count); + numbered[numbered_arg_count].type = FAT_INTEGER; + numbered_arg_count++; + } + else if (isnonzerodigit (*format)) + { + do format++; while (isdigit (*format)); + } + + /* Parse precision. */ + if (*format == '.') + { + format++; + + if (*format == '*') + { + unsigned int precision_number = 0; + + format++; + + if (isnonzerodigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + precision_number = m; + format = ++f; + } + } + + /* Numbered or unnumbered argument. */ + if (allocated == numbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = (precision_number ? precision_number : ++unnumbered_arg_count); + numbered[numbered_arg_count].type = FAT_INTEGER; + numbered_arg_count++; + } + else + { + while (isdigit (*format)) format++; + } + } + + /* Parse size. */ + size = 0; + if (*format == 'h') + { + size = FAT_SIZE_SHORT; + format++; + } + else if (*format == 'l') + { + if (format[1] == 'l') + { + size = FAT_SIZE_LONGLONG; + format += 2; + } + else + { + size = FAT_SIZE_LONG; + format++; + } + } + else if (*format == 'L' || *format == 'q') + { + size = FAT_SIZE_LONGLONG; + format++; + } + else if (*format == 'V') + { + size = FAT_SIZE_V; + format++; + } + else if (*format == 'I') + { + if (format[1] == '6' && format[2] == '4') + { + size = FAT_SIZE_LONGLONG; + format += 3; + } + else if (format[1] == '3' && format[2] == '2') + { + size = 0; /* FAT_SIZE_INT */ + format += 3; + } + else + { + size = FAT_SIZE_PTR; + format++; + } + } + + switch (*format) + { + case '%': + type = FAT_NONE; + break; + case 'c': + type = FAT_CHAR; + break; + case 's': + type = FAT_STRING; + break; + case '_': + type = FAT_SCALAR_VECTOR; + break; + case 'D': + type = FAT_INTEGER | FAT_SIZE_V; + break; + case 'i': case 'd': + type = FAT_INTEGER | size; + break; + case 'U': case 'O': + type = FAT_INTEGER | FAT_UNSIGNED | FAT_SIZE_V; + break; + case 'u': case 'b': case 'o': case 'x': case 'X': + type = FAT_INTEGER | FAT_UNSIGNED | size; + break; + case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': + if (size == FAT_SIZE_SHORT || size == FAT_SIZE_LONG) + { + *invalid_reason = + xasprintf (_("In the directive number %u, the size specifier is incompatible with the conversion specifier '%c'."), directives, *format); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + type = FAT_DOUBLE | size; + break; + case 'p': + type = FAT_POINTER; + break; + case 'n': + type = FAT_COUNT_POINTER | size; + break; + default: + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + + if (type != FAT_NONE && !vectorize) + { + /* Numbered or unnumbered argument. */ + if (allocated == numbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = (number ? number : ++unnumbered_arg_count); + numbered[numbered_arg_count].type = type; + numbered_arg_count++; + } + + FDI_SET (format, FMTDIR_END); + + format++; } /* Sort the numbered argument array, and eliminate duplicates. */ @@ -482,44 +482,44 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (numbered, numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < numbered_arg_count; i++) - if (j > 0 && numbered[i].number == numbered[j-1].number) - { - format_arg_type_t type1 = numbered[i].type; - format_arg_type_t type2 = numbered[j-1].type; - format_arg_type_t type_both; - - if (type1 == type2) - type_both = type1; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (numbered[i].number); - err = true; - } - - numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - numbered[j].number = numbered[i].number; - numbered[j].type = numbered[i].type; - } - j++; - } + if (j > 0 && numbered[i].number == numbered[j-1].number) + { + format_arg_type_t type1 = numbered[i].type; + format_arg_type_t type2 = numbered[j-1].type; + format_arg_type_t type_both; + + if (type1 == type2) + type_both = type1; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (numbered[i].number); + err = true; + } + + numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + numbered[j].number = numbered[i].number; + numbered[j].type = numbered[i].type; + } + j++; + } numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -555,8 +555,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -569,60 +569,60 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->numbered_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } /* Check the argument types are the same. */ if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } + for (i = 0, j = 0; j < n2; ) + { + if (spec1->numbered[i].number == spec2->numbered[j].number) + { + if (spec1->numbered[i].type != spec2->numbered[j].type) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, + spec2->numbered[j].number); + err = true; + break; + } + j++, i++; + } + else + i++; + } } return err; @@ -666,61 +666,61 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); if (spec->numbered[i].type & FAT_UNSIGNED) - printf ("[unsigned]"); + printf ("[unsigned]"); switch (spec->numbered[i].type & FAT_SIZE_MASK) - { - case 0: - break; - case FAT_SIZE_SHORT: - printf ("[short]"); - break; - case FAT_SIZE_V: - printf ("[IV]"); - break; - case FAT_SIZE_PTR: - printf ("[PTR]"); - break; - case FAT_SIZE_LONG: - printf ("[long]"); - break; - case FAT_SIZE_LONGLONG: - printf ("[long long]"); - break; - default: - abort (); - } + { + case 0: + break; + case FAT_SIZE_SHORT: + printf ("[short]"); + break; + case FAT_SIZE_V: + printf ("[IV]"); + break; + case FAT_SIZE_PTR: + printf ("[PTR]"); + break; + case FAT_SIZE_LONG: + printf ("[long]"); + break; + case FAT_SIZE_LONGLONG: + printf ("[long long]"); + break; + default: + abort (); + } switch (spec->numbered[i].type & ~(FAT_UNSIGNED | FAT_SIZE_MASK)) - { - case FAT_INTEGER: - printf ("i"); - break; - case FAT_DOUBLE: - printf ("f"); - break; - case FAT_CHAR: - printf ("c"); - break; - case FAT_STRING: - printf ("s"); - break; - case FAT_SCALAR_VECTOR: - printf ("sv"); - break; - case FAT_POINTER: - printf ("p"); - break; - case FAT_COUNT_POINTER: - printf ("n"); - break; - default: - abort (); - } + { + case FAT_INTEGER: + printf ("i"); + break; + case FAT_DOUBLE: + printf ("f"); + break; + case FAT_CHAR: + printf ("c"); + break; + case FAT_STRING: + printf ("s"); + break; + case FAT_SCALAR_VECTOR: + printf ("sv"); + break; + case FAT_POINTER: + printf ("p"); + break; + case FAT_COUNT_POINTER: + printf ("n"); + break; + default: + abort (); + } last = number + 1; } printf (")"); @@ -739,9 +739,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -749,7 +749,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-php.c b/gettext-tools/src/format-php.c index 19735cb2c..5dd6d7fd8 100644 --- a/gettext-tools/src/format-php.c +++ b/gettext-tools/src/format-php.c @@ -94,7 +94,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; unsigned int directives; @@ -113,132 +113,132 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - FDI_SET (format - 1, FMTDIR_START); - directives++; - - if (*format != '%') - { - /* A complex directive. */ - unsigned int number; - enum format_arg_type type; - - number = ++unnumbered_arg_count; - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = INVALID_ARGNO_0 (directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - number = m; - format = ++f; - --unnumbered_arg_count; - } - } - - /* Parse flags. */ - for (;;) - { - if (*format == '0' || *format == '-' || *format == ' ') - format++; - else if (*format == '\'') - { - format++; - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - format++; - } - else - break; - } - - /* Parse width. */ - if (isdigit (*format)) - { - do - format++; - while (isdigit (*format)); - } - - /* Parse precision. */ - if (*format == '.') - { - format++; - - if (isdigit (*format)) - { - do - format++; - while (isdigit (*format)); - } - else - --format; /* will jump to bad_format */ - } - - /* Parse size. */ - if (*format == 'l') - format++; - - switch (*format) - { - case 'b': case 'd': case 'u': case 'o': case 'x': case 'X': - type = FAT_INTEGER; - break; - case 'e': case 'f': - type = FAT_FLOAT; - break; - case 'c': - type = FAT_CHARACTER; - break; - case 's': - type = FAT_STRING; - break; - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - if (allocated == numbered_arg_count) - { - allocated = 2 * allocated + 1; - numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); - } - numbered[numbered_arg_count].number = number; - numbered[numbered_arg_count].type = type; - numbered_arg_count++; - } - - FDI_SET (format, FMTDIR_END); - - format++; + /* A directive. */ + FDI_SET (format - 1, FMTDIR_START); + directives++; + + if (*format != '%') + { + /* A complex directive. */ + unsigned int number; + enum format_arg_type type; + + number = ++unnumbered_arg_count; + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = INVALID_ARGNO_0 (directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + number = m; + format = ++f; + --unnumbered_arg_count; + } + } + + /* Parse flags. */ + for (;;) + { + if (*format == '0' || *format == '-' || *format == ' ') + format++; + else if (*format == '\'') + { + format++; + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + format++; + } + else + break; + } + + /* Parse width. */ + if (isdigit (*format)) + { + do + format++; + while (isdigit (*format)); + } + + /* Parse precision. */ + if (*format == '.') + { + format++; + + if (isdigit (*format)) + { + do + format++; + while (isdigit (*format)); + } + else + --format; /* will jump to bad_format */ + } + + /* Parse size. */ + if (*format == 'l') + format++; + + switch (*format) + { + case 'b': case 'd': case 'u': case 'o': case 'x': case 'X': + type = FAT_INTEGER; + break; + case 'e': case 'f': + type = FAT_FLOAT; + break; + case 'c': + type = FAT_CHARACTER; + break; + case 's': + type = FAT_STRING; + break; + default: + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + + if (allocated == numbered_arg_count) + { + allocated = 2 * allocated + 1; + numbered = (struct numbered_arg *) xrealloc (numbered, allocated * sizeof (struct numbered_arg)); + } + numbered[numbered_arg_count].number = number; + numbered[numbered_arg_count].type = type; + numbered_arg_count++; + } + + FDI_SET (format, FMTDIR_END); + + format++; } /* Sort the numbered argument array, and eliminate duplicates. */ @@ -248,44 +248,44 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (numbered, numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < numbered_arg_count; i++) - if (j > 0 && numbered[i].number == numbered[j-1].number) - { - enum format_arg_type type1 = numbered[i].type; - enum format_arg_type type2 = numbered[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2) - type_both = type1; - else - { - /* Incompatible types. */ - type_both = type1; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (numbered[i].number); - err = true; - } - - numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - numbered[j].number = numbered[i].number; - numbered[j].type = numbered[i].type; - } - j++; - } + if (j > 0 && numbered[i].number == numbered[j-1].number) + { + enum format_arg_type type1 = numbered[i].type; + enum format_arg_type type2 = numbered[j-1].type; + enum format_arg_type type_both; + + if (type1 == type2) + type_both = type1; + else + { + /* Incompatible types. */ + type_both = type1; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (numbered[i].number); + err = true; + } + + numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + numbered[j].number = numbered[i].number; + numbered[j].type = numbered[i].type; + } + j++; + } numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -321,8 +321,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -335,60 +335,60 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->numbered_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } /* Check the argument types are the same. */ if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } + for (i = 0, j = 0; j < n2; ) + { + if (spec1->numbered[i].number == spec2->numbered[j].number) + { + if (spec1->numbered[i].type != spec2->numbered[j].type) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, + spec2->numbered[j].number); + err = true; + break; + } + j++, i++; + } + else + i++; + } } return err; @@ -432,28 +432,28 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); switch (spec->numbered[i].type) - { - case FAT_INTEGER: - printf ("i"); - break; - case FAT_FLOAT: - printf ("f"); - break; - case FAT_CHARACTER: - printf ("c"); - break; - case FAT_STRING: - printf ("s"); - break; - default: - abort (); - } + { + case FAT_INTEGER: + printf ("i"); + break; + case FAT_FLOAT: + printf ("f"); + break; + case FAT_CHARACTER: + printf ("c"); + break; + case FAT_STRING: + printf ("s"); + break; + default: + abort (); + } last = number + 1; } printf (")"); @@ -472,9 +472,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -482,7 +482,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-python.c b/gettext-tools/src/format-python.c index 55dbf1648..d6a1338a5 100644 --- a/gettext-tools/src/format-python.c +++ b/gettext-tools/src/format-python.c @@ -108,7 +108,7 @@ static int named_arg_compare (const void *p1, const void *p2) { return strcmp (((const struct named_arg *) p1)->name, - ((const struct named_arg *) p2)->name); + ((const struct named_arg *) p2)->name); } #define INVALID_MIXES_NAMED_UNNAMED() \ @@ -116,7 +116,7 @@ named_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -132,195 +132,195 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - char *name = NULL; - bool zero_precision = false; - enum format_arg_type type; - - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (*format == '(') - { - unsigned int depth; - const char *name_start; - const char *name_end; - size_t n; - - name_start = ++format; - depth = 0; - for (; *format != '\0'; format++) - { - if (*format == '(') - depth++; - else if (*format == ')') - { - if (depth == 0) - break; - else - depth--; - } - } - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - name_end = format++; - - n = name_end - name_start; - name = XNMALLOC (n + 1, char); - memcpy (name, name_start, n); - name[n] = '\0'; - } - - while (*format == '-' || *format == '+' || *format == ' ' - || *format == '#' || *format == '0') - format++; - - if (*format == '*') - { - format++; - - /* Named and unnamed specifications are exclusive. */ - if (spec.named_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NAMED_UNNAMED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.unnamed_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.unnamed = (struct unnamed_arg *) xrealloc (spec.unnamed, spec.allocated * sizeof (struct unnamed_arg)); - } - spec.unnamed[spec.unnamed_arg_count].type = FAT_INTEGER; - spec.unnamed_arg_count++; - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - - if (*format == '.') - { - format++; - - if (*format == '*') - { - format++; - - /* Named and unnamed specifications are exclusive. */ - if (spec.named_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NAMED_UNNAMED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.unnamed_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.unnamed = (struct unnamed_arg *) xrealloc (spec.unnamed, spec.allocated * sizeof (struct unnamed_arg)); - } - spec.unnamed[spec.unnamed_arg_count].type = FAT_INTEGER; - spec.unnamed_arg_count++; - } - else if (isdigit (*format)) - { - zero_precision = true; - do - { - if (*format != '0') - zero_precision = false; - format++; - } - while (isdigit (*format)); - } - } - - if (*format == 'h' || *format == 'l' || *format == 'L') - format++; - - switch (*format) - { - case '%': - type = FAT_NONE; - break; - case 'c': - type = FAT_CHARACTER; - break; - case 's': case 'r': - type = (zero_precision ? FAT_ANY : FAT_STRING); - break; - case 'i': case 'd': case 'u': case 'o': case 'x': case 'X': - type = FAT_INTEGER; - break; - case 'e': case 'E': case 'f': case 'g': case 'G': - type = FAT_FLOAT; - break; - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - if (name != NULL) - { - /* Named argument. */ - - /* Named and unnamed specifications are exclusive. */ - if (spec.unnamed_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NAMED_UNNAMED (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.named_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.named = (struct named_arg *) xrealloc (spec.named, spec.allocated * sizeof (struct named_arg)); - } - spec.named[spec.named_arg_count].name = name; - spec.named[spec.named_arg_count].type = type; - spec.named_arg_count++; - } - else if (*format != '%') - { - /* Unnamed argument. */ - - /* Named and unnamed specifications are exclusive. */ - if (spec.named_arg_count > 0) - { - *invalid_reason = INVALID_MIXES_NAMED_UNNAMED (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - - if (spec.allocated == spec.unnamed_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.unnamed = (struct unnamed_arg *) xrealloc (spec.unnamed, spec.allocated * sizeof (struct unnamed_arg)); - } - spec.unnamed[spec.unnamed_arg_count].type = type; - spec.unnamed_arg_count++; - } - - FDI_SET (format, FMTDIR_END); - - format++; + /* A directive. */ + char *name = NULL; + bool zero_precision = false; + enum format_arg_type type; + + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (*format == '(') + { + unsigned int depth; + const char *name_start; + const char *name_end; + size_t n; + + name_start = ++format; + depth = 0; + for (; *format != '\0'; format++) + { + if (*format == '(') + depth++; + else if (*format == ')') + { + if (depth == 0) + break; + else + depth--; + } + } + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + name_end = format++; + + n = name_end - name_start; + name = XNMALLOC (n + 1, char); + memcpy (name, name_start, n); + name[n] = '\0'; + } + + while (*format == '-' || *format == '+' || *format == ' ' + || *format == '#' || *format == '0') + format++; + + if (*format == '*') + { + format++; + + /* Named and unnamed specifications are exclusive. */ + if (spec.named_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NAMED_UNNAMED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.unnamed_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.unnamed = (struct unnamed_arg *) xrealloc (spec.unnamed, spec.allocated * sizeof (struct unnamed_arg)); + } + spec.unnamed[spec.unnamed_arg_count].type = FAT_INTEGER; + spec.unnamed_arg_count++; + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + + if (*format == '.') + { + format++; + + if (*format == '*') + { + format++; + + /* Named and unnamed specifications are exclusive. */ + if (spec.named_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NAMED_UNNAMED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.unnamed_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.unnamed = (struct unnamed_arg *) xrealloc (spec.unnamed, spec.allocated * sizeof (struct unnamed_arg)); + } + spec.unnamed[spec.unnamed_arg_count].type = FAT_INTEGER; + spec.unnamed_arg_count++; + } + else if (isdigit (*format)) + { + zero_precision = true; + do + { + if (*format != '0') + zero_precision = false; + format++; + } + while (isdigit (*format)); + } + } + + if (*format == 'h' || *format == 'l' || *format == 'L') + format++; + + switch (*format) + { + case '%': + type = FAT_NONE; + break; + case 'c': + type = FAT_CHARACTER; + break; + case 's': case 'r': + type = (zero_precision ? FAT_ANY : FAT_STRING); + break; + case 'i': case 'd': case 'u': case 'o': case 'x': case 'X': + type = FAT_INTEGER; + break; + case 'e': case 'E': case 'f': case 'g': case 'G': + type = FAT_FLOAT; + break; + default: + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (spec.directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + + if (name != NULL) + { + /* Named argument. */ + + /* Named and unnamed specifications are exclusive. */ + if (spec.unnamed_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NAMED_UNNAMED (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.named_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.named = (struct named_arg *) xrealloc (spec.named, spec.allocated * sizeof (struct named_arg)); + } + spec.named[spec.named_arg_count].name = name; + spec.named[spec.named_arg_count].type = type; + spec.named_arg_count++; + } + else if (*format != '%') + { + /* Unnamed argument. */ + + /* Named and unnamed specifications are exclusive. */ + if (spec.named_arg_count > 0) + { + *invalid_reason = INVALID_MIXES_NAMED_UNNAMED (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + + if (spec.allocated == spec.unnamed_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.unnamed = (struct unnamed_arg *) xrealloc (spec.unnamed, spec.allocated * sizeof (struct unnamed_arg)); + } + spec.unnamed[spec.unnamed_arg_count].type = type; + spec.unnamed_arg_count++; + } + + FDI_SET (format, FMTDIR_END); + + format++; } /* Sort the named argument array, and eliminate duplicates. */ @@ -330,47 +330,47 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (spec.named, spec.named_arg_count, sizeof (struct named_arg), - named_arg_compare); + named_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < spec.named_arg_count; i++) - if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0) - { - enum format_arg_type type1 = spec.named[i].type; - enum format_arg_type type2 = spec.named[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2 || type2 == FAT_ANY) - type_both = type1; - else if (type1 == FAT_ANY) - type_both = type2; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - xasprintf (_("The string refers to the argument named '%s' in incompatible ways."), spec.named[i].name); - err = true; - } - - spec.named[j-1].type = type_both; - free (spec.named[i].name); - } - else - { - if (j < i) - { - spec.named[j].name = spec.named[i].name; - spec.named[j].type = spec.named[i].type; - } - j++; - } + if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0) + { + enum format_arg_type type1 = spec.named[i].type; + enum format_arg_type type2 = spec.named[j-1].type; + enum format_arg_type type_both; + + if (type1 == type2 || type2 == FAT_ANY) + type_both = type1; + else if (type1 == FAT_ANY) + type_both = type2; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + xasprintf (_("The string refers to the argument named '%s' in incompatible ways."), spec.named[i].name); + err = true; + } + + spec.named[j-1].type = type_both; + free (spec.named[i].name); + } + else + { + if (j < i) + { + spec.named[j].name = spec.named[i].name; + spec.named[j].type = spec.named[i].type; + } + j++; + } spec.named_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -382,7 +382,7 @@ format_parse (const char *format, bool translated, char *fdi, { unsigned int i; for (i = 0; i < spec.named_arg_count; i++) - free (spec.named[i].name); + free (spec.named[i].name); free (spec.named); } if (spec.unnamed != NULL) @@ -399,7 +399,7 @@ format_free (void *descr) { unsigned int i; for (i = 0; i < spec->named_arg_count; i++) - free (spec->named[i].name); + free (spec->named[i].name); free (spec->named); } if (spec->unnamed != NULL) @@ -417,8 +417,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -427,108 +427,108 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, if (spec1->named_arg_count > 0 && spec2->unnamed_arg_count > 0) { if (error_logger) - error_logger (_("format specifications in '%s' expect a mapping, those in '%s' expect a tuple"), - pretty_msgid, pretty_msgstr); + error_logger (_("format specifications in '%s' expect a mapping, those in '%s' expect a tuple"), + pretty_msgid, pretty_msgstr); err = true; } else if (spec1->unnamed_arg_count > 0 && spec2->named_arg_count > 0) { if (error_logger) - error_logger (_("format specifications in '%s' expect a tuple, those in '%s' expect a mapping"), - pretty_msgid, pretty_msgstr); + error_logger (_("format specifications in '%s' expect a tuple, those in '%s' expect a mapping"), + pretty_msgid, pretty_msgstr); err = true; } else { if (spec1->named_arg_count + spec2->named_arg_count > 0) - { - unsigned int i, j; - unsigned int n1 = spec1->named_arg_count; - unsigned int n2 = spec2->named_arg_count; - - /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ - for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - strcmp (spec1->named[i].name, spec2->named[j].name)); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument '%s', as in '%s', doesn't exist in '%s'"), - spec2->named[j].name, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument '%s' doesn't exist in '%s'"), - spec1->named[i].name, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } - /* Check the argument types are the same. */ - if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (strcmp (spec1->named[i].name, spec2->named[j].name) == 0) - { - if (!(spec1->named[i].type == spec2->named[j].type - || (!equality - && (spec1->named[i].type == FAT_ANY - || spec2->named[j].type == FAT_ANY)))) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument '%s' are not the same"), - pretty_msgid, pretty_msgstr, - spec2->named[j].name); - err = true; - break; - } - j++, i++; - } - else - i++; - } - } + { + unsigned int i, j; + unsigned int n1 = spec1->named_arg_count; + unsigned int n2 = spec2->named_arg_count; + + /* Check the argument names are the same. + Both arrays are sorted. We search for the first difference. */ + for (i = 0, j = 0; i < n1 || j < n2; ) + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + strcmp (spec1->named[i].name, spec2->named[j].name)); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument '%s', as in '%s', doesn't exist in '%s'"), + spec2->named[j].name, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument '%s' doesn't exist in '%s'"), + spec1->named[i].name, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } + /* Check the argument types are the same. */ + if (!err) + for (i = 0, j = 0; j < n2; ) + { + if (strcmp (spec1->named[i].name, spec2->named[j].name) == 0) + { + if (!(spec1->named[i].type == spec2->named[j].type + || (!equality + && (spec1->named[i].type == FAT_ANY + || spec2->named[j].type == FAT_ANY)))) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument '%s' are not the same"), + pretty_msgid, pretty_msgstr, + spec2->named[j].name); + err = true; + break; + } + j++, i++; + } + else + i++; + } + } if (spec1->unnamed_arg_count + spec2->unnamed_arg_count > 0) - { - unsigned int i; - - /* Check the argument types are the same. */ - if (spec1->unnamed_arg_count != spec2->unnamed_arg_count) - { - if (error_logger) - error_logger (_("number of format specifications in '%s' and '%s' does not match"), - pretty_msgid, pretty_msgstr); - err = true; - } - else - for (i = 0; i < spec2->unnamed_arg_count; i++) - if (!(spec1->unnamed[i].type == spec2->unnamed[i].type - || (!equality - && (spec1->unnamed[i].type == FAT_ANY - || spec2->unnamed[i].type == FAT_ANY)))) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, i + 1); - err = true; - } - } + { + unsigned int i; + + /* Check the argument types are the same. */ + if (spec1->unnamed_arg_count != spec2->unnamed_arg_count) + { + if (error_logger) + error_logger (_("number of format specifications in '%s' and '%s' does not match"), + pretty_msgid, pretty_msgstr); + err = true; + } + else + for (i = 0; i < spec2->unnamed_arg_count; i++) + if (!(spec1->unnamed[i].type == spec2->unnamed[i].type + || (!equality + && (spec1->unnamed[i].type == FAT_ANY + || spec2->unnamed[i].type == FAT_ANY)))) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, i + 1); + err = true; + } + } } return err; @@ -590,65 +590,65 @@ format_print (void *descr) if (spec->named_arg_count > 0) { if (spec->unnamed_arg_count > 0) - abort (); + abort (); printf ("{"); for (i = 0; i < spec->named_arg_count; i++) - { - if (i > 0) - printf (", "); - printf ("'%s':", spec->named[i].name); - switch (spec->named[i].type) - { - case FAT_ANY: - printf ("*"); - break; - case FAT_CHARACTER: - printf ("c"); - break; - case FAT_STRING: - printf ("s"); - break; - case FAT_INTEGER: - printf ("i"); - break; - case FAT_FLOAT: - printf ("f"); - break; - default: - abort (); - } - } + { + if (i > 0) + printf (", "); + printf ("'%s':", spec->named[i].name); + switch (spec->named[i].type) + { + case FAT_ANY: + printf ("*"); + break; + case FAT_CHARACTER: + printf ("c"); + break; + case FAT_STRING: + printf ("s"); + break; + case FAT_INTEGER: + printf ("i"); + break; + case FAT_FLOAT: + printf ("f"); + break; + default: + abort (); + } + } printf ("}"); } else { printf ("("); for (i = 0; i < spec->unnamed_arg_count; i++) - { - if (i > 0) - printf (" "); - switch (spec->unnamed[i].type) - { - case FAT_ANY: - printf ("*"); - break; - case FAT_CHARACTER: - printf ("c"); - break; - case FAT_STRING: - printf ("s"); - break; - case FAT_INTEGER: - printf ("i"); - break; - case FAT_FLOAT: - printf ("f"); - break; - default: - abort (); - } - } + { + if (i > 0) + printf (" "); + switch (spec->unnamed[i].type) + { + case FAT_ANY: + printf ("*"); + break; + case FAT_CHARACTER: + printf ("c"); + break; + case FAT_STRING: + printf ("s"); + break; + case FAT_INTEGER: + printf ("i"); + break; + case FAT_FLOAT: + printf ("f"); + break; + default: + abort (); + } + } printf (")"); } } @@ -666,9 +666,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -676,7 +676,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-qt-plural.c b/gettext-tools/src/format-qt-plural.c index b224253ec..5301d4292 100644 --- a/gettext-tools/src/format-qt-plural.c +++ b/gettext-tools/src/format-qt-plural.c @@ -46,7 +46,7 @@ struct spec static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -57,19 +57,19 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - const char *dir_start = format - 1; - - if (*format == 'L') - format++; - if (*format == 'n') - { - /* A directive. */ - FDI_SET (dir_start, FMTDIR_START); - spec.directives++; - FDI_SET (format, FMTDIR_END); - - format++; - } + const char *dir_start = format - 1; + + if (*format == 'L') + format++; + if (*format == 'n') + { + /* A directive. */ + FDI_SET (dir_start, FMTDIR_START); + spec.directives++; + FDI_SET (format, FMTDIR_END); + + format++; + } } result = XMALLOC (struct spec); @@ -95,8 +95,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -107,8 +107,8 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, || (equality && spec1->directives > 0 && spec2->directives == 0)) { if (error_logger) - error_logger (_("number of format specifications in '%s' and '%s' does not match"), - pretty_msgid, pretty_msgstr); + error_logger (_("number of format specifications in '%s' and '%s' does not match"), + pretty_msgid, pretty_msgstr); err = true; } @@ -165,9 +165,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -175,7 +175,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-qt.c b/gettext-tools/src/format-qt.c index 2296d86cd..3f759a224 100644 --- a/gettext-tools/src/format-qt.c +++ b/gettext-tools/src/format-qt.c @@ -66,7 +66,7 @@ struct spec static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -79,40 +79,40 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - const char *dir_start = format - 1; - bool locale_flag = false; - - if (*format == 'L') - { - locale_flag = true; - format++; - } - if (*format >= '0' && *format <= '9') - { - /* A directive. */ - unsigned int number; - - FDI_SET (dir_start, FMTDIR_START); - spec.directives++; - if (locale_flag) - spec.simple = false; - - number = *format - '0'; - if (format[1] >= '0' && format[1] <= '9') - { - number = 10 * number + (format[1] - '0'); - spec.simple = false; - format++; - } - - while (spec.arg_count <= number) - spec.args_used[spec.arg_count++] = false; - spec.args_used[number] = true; - - FDI_SET (format, FMTDIR_END); - - format++; - } + const char *dir_start = format - 1; + bool locale_flag = false; + + if (*format == 'L') + { + locale_flag = true; + format++; + } + if (*format >= '0' && *format <= '9') + { + /* A directive. */ + unsigned int number; + + FDI_SET (dir_start, FMTDIR_START); + spec.directives++; + if (locale_flag) + spec.simple = false; + + number = *format - '0'; + if (format[1] >= '0' && format[1] <= '9') + { + number = 10 * number + (format[1] - '0'); + spec.simple = false; + format++; + } + + while (spec.arg_count <= number) + spec.args_used[spec.arg_count++] = false; + spec.args_used[number] = true; + + FDI_SET (format, FMTDIR_END); + + format++; + } } result = XMALLOC (struct spec); @@ -138,8 +138,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -149,33 +149,33 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, if (spec1->simple && !spec2->simple) { if (error_logger) - error_logger (_("'%s' is a simple format string, but '%s' is not: it contains an 'L' flag or a double-digit argument number"), - pretty_msgid, pretty_msgstr); + error_logger (_("'%s' is a simple format string, but '%s' is not: it contains an 'L' flag or a double-digit argument number"), + pretty_msgid, pretty_msgstr); err = true; } if (!err) for (i = 0; i < spec1->arg_count || i < spec2->arg_count; i++) { - bool arg_used1 = (i < spec1->arg_count && spec1->args_used[i]); - bool arg_used2 = (i < spec2->arg_count && spec2->args_used[i]); - - /* The translator cannot omit a %n from the msgstr because that would - yield a "Argument missing" warning at runtime. */ - if (arg_used1 != arg_used2) - { - if (error_logger) - { - if (arg_used1) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - i, pretty_msgstr); - else - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - i, pretty_msgstr, pretty_msgid); - } - err = true; - break; - } + bool arg_used1 = (i < spec1->arg_count && spec1->args_used[i]); + bool arg_used2 = (i < spec2->arg_count && spec2->args_used[i]); + + /* The translator cannot omit a %n from the msgstr because that would + yield a "Argument missing" warning at runtime. */ + if (arg_used1 != arg_used2) + { + if (error_logger) + { + if (arg_used1) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + i, pretty_msgstr); + else + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + i, pretty_msgstr, pretty_msgid); + } + err = true; + break; + } } return err; @@ -215,11 +215,11 @@ format_print (void *descr) for (i = 0; i < spec->arg_count; i++) { if (i > 0) - printf (" "); + printf (" "); if (spec->args_used[i]) - printf ("*"); + printf ("*"); else - printf ("_"); + printf ("_"); } printf (")"); } @@ -237,9 +237,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -247,7 +247,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-scheme.c b/gettext-tools/src/format-scheme.c index 77ec7fb3a..fd315fac9 100644 --- a/gettext-tools/src/format-scheme.c +++ b/gettext-tools/src/format-scheme.c @@ -51,42 +51,42 @@ enum format_cdr_type { - FCT_REQUIRED, /* The format argument list cannot end before this argument. */ - FCT_OPTIONAL /* The format argument list may end before this argument. */ + FCT_REQUIRED, /* The format argument list cannot end before this argument. */ + FCT_OPTIONAL /* The format argument list may end before this argument. */ }; enum format_arg_type { - FAT_OBJECT, /* Any object, type T. */ - FAT_CHARACTER_INTEGER_NULL, /* Type (OR CHARACTER INTEGER NULL). */ - FAT_CHARACTER_NULL, /* Type (OR CHARACTER NULL). */ - FAT_CHARACTER, /* Type CHARACTER. */ - FAT_INTEGER_NULL, /* Type (OR INTEGER NULL). */ - FAT_INTEGER, /* Meant for objects of type INTEGER. */ - FAT_REAL, /* Meant for objects of type REAL. */ - FAT_COMPLEX, /* Meant for objects of type COMPLEX. */ - FAT_LIST, /* Meant for proper lists. */ - FAT_FORMATSTRING /* Format strings. */ + FAT_OBJECT, /* Any object, type T. */ + FAT_CHARACTER_INTEGER_NULL, /* Type (OR CHARACTER INTEGER NULL). */ + FAT_CHARACTER_NULL, /* Type (OR CHARACTER NULL). */ + FAT_CHARACTER, /* Type CHARACTER. */ + FAT_INTEGER_NULL, /* Type (OR INTEGER NULL). */ + FAT_INTEGER, /* Meant for objects of type INTEGER. */ + FAT_REAL, /* Meant for objects of type REAL. */ + FAT_COMPLEX, /* Meant for objects of type COMPLEX. */ + FAT_LIST, /* Meant for proper lists. */ + FAT_FORMATSTRING /* Format strings. */ }; struct format_arg { unsigned int repcount; /* Number of consecutive arguments this constraint - applies to. Normally 1, but unconstrained - arguments are often repeated. */ + applies to. Normally 1, but unconstrained + arguments are often repeated. */ enum format_cdr_type presence; /* Can the argument list end right before - this argument? */ - enum format_arg_type type; /* Possible values for this argument. */ - struct format_arg_list *list; /* For FAT_LIST: List elements. */ + this argument? */ + enum format_arg_type type; /* Possible values for this argument. */ + struct format_arg_list *list; /* For FAT_LIST: List elements. */ }; struct segment { - unsigned int count; /* Number of format_arg records used. */ + unsigned int count; /* Number of format_arg records used. */ unsigned int allocated; - struct format_arg *element; /* Argument constraints. */ + struct format_arg *element; /* Argument constraints. */ unsigned int length; /* Number of arguments represented by this segment. - This is the sum of all repcounts in the segment. */ + This is the sum of all repcounts in the segment. */ }; struct format_arg_list @@ -101,8 +101,8 @@ struct format_arg_list A finite sequence is represented entirely in the initial segment; the loop segment is empty. */ - struct segment initial; /* Initial arguments segment. */ - struct segment repeated; /* Endlessly repeated segment. */ + struct segment initial; /* Initial arguments segment. */ + struct segment repeated; /* Endlessly repeated segment. */ }; struct spec @@ -115,17 +115,17 @@ struct spec /* Parameter for a directive. */ enum param_type { - PT_NIL, /* param not present */ - PT_CHARACTER, /* character */ - PT_INTEGER, /* integer */ - PT_ARGCOUNT, /* number of remaining arguments */ - PT_V /* variable taken from argument list */ + PT_NIL, /* param not present */ + PT_CHARACTER, /* character */ + PT_INTEGER, /* integer */ + PT_ARGCOUNT, /* number of remaining arguments */ + PT_V /* variable taken from argument list */ }; struct param { enum param_type type; - int value; /* for PT_INTEGER: the value, for PT_V: the position */ + int value; /* for PT_INTEGER: the value, for PT_V: the position */ }; @@ -135,15 +135,15 @@ static void verify_list (const struct format_arg_list *list); static void free_list (struct format_arg_list *list); static struct format_arg_list * copy_list (const struct format_arg_list *list); static bool equal_list (const struct format_arg_list *list1, - const struct format_arg_list *list2); + const struct format_arg_list *list2); static struct format_arg_list * make_intersected_list - (struct format_arg_list *list1, - struct format_arg_list *list2); + (struct format_arg_list *list1, + struct format_arg_list *list2); static struct format_arg_list * make_intersection_with_empty_list - (struct format_arg_list *list); + (struct format_arg_list *list); static struct format_arg_list * make_union_list - (struct format_arg_list *list1, - struct format_arg_list *list2); + (struct format_arg_list *list1, + struct format_arg_list *list2); /* ======================= Verify a format_arg_list ======================= */ @@ -221,7 +221,7 @@ free_list (struct format_arg_list *list) /* Copy the data belonging to an argument list element. */ static inline void copy_element (struct format_arg *newelement, - const struct format_arg *oldelement) + const struct format_arg *oldelement) { newelement->repcount = oldelement->repcount; newelement->presence = oldelement->presence; @@ -250,13 +250,13 @@ copy_list (const struct format_arg_list *list) else { newlist->initial.element = - XNMALLOC (newlist->initial.allocated, struct format_arg); + XNMALLOC (newlist->initial.allocated, struct format_arg); for (i = 0; i < list->initial.count; i++) - { - copy_element (&newlist->initial.element[i], - &list->initial.element[i]); - length += list->initial.element[i].repcount; - } + { + copy_element (&newlist->initial.element[i], + &list->initial.element[i]); + length += list->initial.element[i].repcount; + } } ASSERT (length == list->initial.length); newlist->initial.length = length; @@ -268,13 +268,13 @@ copy_list (const struct format_arg_list *list) else { newlist->repeated.element = - XNMALLOC (newlist->repeated.allocated, struct format_arg); + XNMALLOC (newlist->repeated.allocated, struct format_arg); for (i = 0; i < list->repeated.count; i++) - { - copy_element (&newlist->repeated.element[i], - &list->repeated.element[i]); - length += list->repeated.element[i].repcount; - } + { + copy_element (&newlist->repeated.element[i], + &list->repeated.element[i]); + length += list->repeated.element[i].repcount; + } } ASSERT (length == list->repeated.length); newlist->repeated.length = length; @@ -293,15 +293,15 @@ static bool equal_element (const struct format_arg * e1, const struct format_arg * e2) { return (e1->presence == e2->presence - && e1->type == e2->type - && (e1->type == FAT_LIST ? equal_list (e1->list, e2->list) : true)); + && e1->type == e2->type + && (e1->type == FAT_LIST ? equal_list (e1->list, e2->list) : true)); } /* Tests whether two normalized argument list constraints are equivalent. */ /* Memory effects: none. */ static bool equal_list (const struct format_arg_list *list1, - const struct format_arg_list *list2) + const struct format_arg_list *list2) { unsigned int n, i; @@ -317,7 +317,7 @@ equal_list (const struct format_arg_list *list1, const struct format_arg * e2 = &list2->initial.element[i]; if (!(e1->repcount == e2->repcount && equal_element (e1, e2))) - return false; + return false; } n = list1->repeated.count; @@ -329,7 +329,7 @@ equal_list (const struct format_arg_list *list1, const struct format_arg * e2 = &list2->repeated.element[i]; if (!(e1->repcount == e2->repcount && equal_element (e1, e2))) - return false; + return false; } return true; @@ -345,11 +345,11 @@ ensure_initial_alloc (struct format_arg_list *list, unsigned int newcount) if (newcount > list->initial.allocated) { list->initial.allocated = - MAX (2 * list->initial.allocated + 1, newcount); + MAX (2 * list->initial.allocated + 1, newcount); list->initial.element = - (struct format_arg *) - xrealloc (list->initial.element, - list->initial.allocated * sizeof (struct format_arg)); + (struct format_arg *) + xrealloc (list->initial.element, + list->initial.allocated * sizeof (struct format_arg)); } } @@ -360,11 +360,11 @@ grow_initial_alloc (struct format_arg_list *list) if (list->initial.count >= list->initial.allocated) { list->initial.allocated = - MAX (2 * list->initial.allocated + 1, list->initial.count + 1); + MAX (2 * list->initial.allocated + 1, list->initial.count + 1); list->initial.element = - (struct format_arg *) - xrealloc (list->initial.element, - list->initial.allocated * sizeof (struct format_arg)); + (struct format_arg *) + xrealloc (list->initial.element, + list->initial.allocated * sizeof (struct format_arg)); } } @@ -375,11 +375,11 @@ ensure_repeated_alloc (struct format_arg_list *list, unsigned int newcount) if (newcount > list->repeated.allocated) { list->repeated.allocated = - MAX (2 * list->repeated.allocated + 1, newcount); + MAX (2 * list->repeated.allocated + 1, newcount); list->repeated.element = - (struct format_arg *) - xrealloc (list->repeated.element, - list->repeated.allocated * sizeof (struct format_arg)); + (struct format_arg *) + xrealloc (list->repeated.element, + list->repeated.allocated * sizeof (struct format_arg)); } } @@ -390,11 +390,11 @@ grow_repeated_alloc (struct format_arg_list *list) if (list->repeated.count >= list->repeated.allocated) { list->repeated.allocated = - MAX (2 * list->repeated.allocated + 1, list->repeated.count + 1); + MAX (2 * list->repeated.allocated + 1, list->repeated.count + 1); list->repeated.element = - (struct format_arg *) - xrealloc (list->repeated.element, - list->repeated.allocated * sizeof (struct format_arg)); + (struct format_arg *) + xrealloc (list->repeated.element, + list->repeated.allocated * sizeof (struct format_arg)); } } @@ -415,36 +415,36 @@ normalize_outermost_list (struct format_arg_list *list) n = list->initial.count; for (i = j = 0; i < n; i++) if (j > 0 - && equal_element (&list->initial.element[i], - &list->initial.element[j-1])) + && equal_element (&list->initial.element[i], + &list->initial.element[j-1])) { - list->initial.element[j-1].repcount += - list->initial.element[i].repcount; - free_element (&list->initial.element[i]); + list->initial.element[j-1].repcount += + list->initial.element[i].repcount; + free_element (&list->initial.element[i]); } else { - if (j < i) - list->initial.element[j] = list->initial.element[i]; - j++; + if (j < i) + list->initial.element[j] = list->initial.element[i]; + j++; } list->initial.count = j; n = list->repeated.count; for (i = j = 0; i < n; i++) if (j > 0 - && equal_element (&list->repeated.element[i], - &list->repeated.element[j-1])) + && equal_element (&list->repeated.element[i], + &list->repeated.element[j-1])) { - list->repeated.element[j-1].repcount += - list->repeated.element[i].repcount; - free_element (&list->repeated.element[i]); + list->repeated.element[j-1].repcount += + list->repeated.element[i].repcount; + free_element (&list->repeated.element[i]); } else { - if (j < i) - list->repeated.element[j] = list->repeated.element[i]; - j++; + if (j < i) + list->repeated.element[j] = list->repeated.element[i]; + j++; } list->repeated.count = j; @@ -457,104 +457,104 @@ normalize_outermost_list (struct format_arg_list *list) n = list->repeated.count; repcount0_extra = 0; if (n > 1 - && equal_element (&list->repeated.element[0], - &list->repeated.element[n-1])) - { - repcount0_extra = list->repeated.element[n-1].repcount; - n--; - } + && equal_element (&list->repeated.element[0], + &list->repeated.element[n-1])) + { + repcount0_extra = list->repeated.element[n-1].repcount; + n--; + } /* Proceed as if the loop period were n, with - list->repeated.element[0].repcount incremented by repcount0_extra. */ + list->repeated.element[0].repcount incremented by repcount0_extra. */ for (m = 2; m <= n / 2; n++) - if ((n % m) == 0) - { - /* m is a divisor of n. Try to reduce the loop period to n. */ - bool ok = true; - - for (i = 0; i < n - m; i++) - if (!((list->repeated.element[i].repcount - + (i == 0 ? repcount0_extra : 0) - == list->repeated.element[i+m].repcount) - && equal_element (&list->repeated.element[i], - &list->repeated.element[i+m]))) - { - ok = false; - break; - } - if (ok) - { - for (i = m; i < n; i++) - free_element (&list->repeated.element[i]); - if (n < list->repeated.count) - list->repeated.element[m] = list->repeated.element[n]; - list->repeated.count = list->repeated.count - n + m; - list->repeated.length /= n / m; - break; - } - } + if ((n % m) == 0) + { + /* m is a divisor of n. Try to reduce the loop period to n. */ + bool ok = true; + + for (i = 0; i < n - m; i++) + if (!((list->repeated.element[i].repcount + + (i == 0 ? repcount0_extra : 0) + == list->repeated.element[i+m].repcount) + && equal_element (&list->repeated.element[i], + &list->repeated.element[i+m]))) + { + ok = false; + break; + } + if (ok) + { + for (i = m; i < n; i++) + free_element (&list->repeated.element[i]); + if (n < list->repeated.count) + list->repeated.element[m] = list->repeated.element[n]; + list->repeated.count = list->repeated.count - n + m; + list->repeated.length /= n / m; + break; + } + } /* Step 3: Roll as much as possible of the initial segment's tail - into the loop. */ + into the loop. */ if (list->repeated.count == 1) - { - if (list->initial.count > 0 - && equal_element (&list->initial.element[list->initial.count-1], - &list->repeated.element[0])) - { - /* Roll the last element of the initial segment into the loop. - Its repcount is irrelevant. The second-to-last element is - certainly different and doesn't need to be considered. */ - list->initial.length -= - list->initial.element[list->initial.count-1].repcount; - list->initial.count--; - } - } + { + if (list->initial.count > 0 + && equal_element (&list->initial.element[list->initial.count-1], + &list->repeated.element[0])) + { + /* Roll the last element of the initial segment into the loop. + Its repcount is irrelevant. The second-to-last element is + certainly different and doesn't need to be considered. */ + list->initial.length -= + list->initial.element[list->initial.count-1].repcount; + list->initial.count--; + } + } else - { - while (list->initial.count > 0 - && equal_element (&list->initial.element[list->initial.count-1], - &list->repeated.element[list->repeated.count-1])) - { - unsigned int moved_repcount = - MIN (list->initial.element[list->initial.count-1].repcount, - list->repeated.element[list->repeated.count-1].repcount); - - /* Add the element at the start of list->repeated. */ - if (equal_element (&list->repeated.element[0], - &list->repeated.element[list->repeated.count-1])) - list->repeated.element[0].repcount += moved_repcount; - else - { - unsigned int newcount = list->repeated.count + 1; - ensure_repeated_alloc (list, newcount); - for (i = newcount - 1; i > 0; i--) - list->repeated.element[i] = list->repeated.element[i-1]; - list->repeated.count = newcount; - copy_element (&list->repeated.element[0], - &list->repeated.element[list->repeated.count-1]); - list->repeated.element[0].repcount = moved_repcount; - } - - /* Remove the element from the end of list->repeated. */ - list->repeated.element[list->repeated.count-1].repcount -= - moved_repcount; - if (list->repeated.element[list->repeated.count-1].repcount == 0) - { - free_element (&list->repeated.element[list->repeated.count-1]); - list->repeated.count--; - } - - /* Remove the element from the end of list->initial. */ - list->initial.element[list->initial.count-1].repcount -= - moved_repcount; - if (list->initial.element[list->initial.count-1].repcount == 0) - { - free_element (&list->initial.element[list->initial.count-1]); - list->initial.count--; - } - list->initial.length -= moved_repcount; - } - } + { + while (list->initial.count > 0 + && equal_element (&list->initial.element[list->initial.count-1], + &list->repeated.element[list->repeated.count-1])) + { + unsigned int moved_repcount = + MIN (list->initial.element[list->initial.count-1].repcount, + list->repeated.element[list->repeated.count-1].repcount); + + /* Add the element at the start of list->repeated. */ + if (equal_element (&list->repeated.element[0], + &list->repeated.element[list->repeated.count-1])) + list->repeated.element[0].repcount += moved_repcount; + else + { + unsigned int newcount = list->repeated.count + 1; + ensure_repeated_alloc (list, newcount); + for (i = newcount - 1; i > 0; i--) + list->repeated.element[i] = list->repeated.element[i-1]; + list->repeated.count = newcount; + copy_element (&list->repeated.element[0], + &list->repeated.element[list->repeated.count-1]); + list->repeated.element[0].repcount = moved_repcount; + } + + /* Remove the element from the end of list->repeated. */ + list->repeated.element[list->repeated.count-1].repcount -= + moved_repcount; + if (list->repeated.element[list->repeated.count-1].repcount == 0) + { + free_element (&list->repeated.element[list->repeated.count-1]); + list->repeated.count--; + } + + /* Remove the element from the end of list->initial. */ + list->initial.element[list->initial.count-1].repcount -= + moved_repcount; + if (list->initial.element[list->initial.count-1].repcount == 0) + { + free_element (&list->initial.element[list->initial.count-1]); + list->initial.count--; + } + list->initial.length -= moved_repcount; + } + } } } @@ -664,8 +664,8 @@ unfold_loop (struct format_arg_list *list, unsigned int m) ensure_repeated_alloc (list, newcount); i = list->repeated.count; for (k = 1; k < m; k++) - for (j = 0; j < list->repeated.count; j++, i++) - copy_element (&list->repeated.element[i], &list->repeated.element[j]); + for (j = 0; j < list->repeated.count; j++, i++) + copy_element (&list->repeated.element[i], &list->repeated.element[j]); list->repeated.count = newcount; list->repeated.length = list->repeated.length * m; } @@ -683,7 +683,7 @@ rotate_loop (struct format_arg_list *list, unsigned int m) if (list->repeated.count == 1) { /* Instead of multiple copies of list->repeated.element[0], a single - copy with higher repcount is appended to list->initial. */ + copy with higher repcount is appended to list->initial. */ unsigned int i, newcount; newcount = list->initial.count + 1; @@ -703,76 +703,76 @@ rotate_loop (struct format_arg_list *list, unsigned int m) unsigned int r = (m - list->initial.length) % n; /* Determine how many entries of list->repeated are needed for - length r. */ + length r. */ unsigned int s; unsigned int t; for (t = r, s = 0; - s < list->repeated.count && t >= list->repeated.element[s].repcount; - t -= list->repeated.element[s].repcount, s++) - ; + s < list->repeated.count && t >= list->repeated.element[s].repcount; + t -= list->repeated.element[s].repcount, s++) + ; /* s must be < list->repeated.count, otherwise r would have been >= n. */ ASSERT (s < list->repeated.count); /* So we need to add to list->initial: - q full copies of list->repeated, - plus the s first elements of list->repeated, - plus, if t > 0, a splitoff of list->repeated.element[s]. */ + q full copies of list->repeated, + plus the s first elements of list->repeated, + plus, if t > 0, a splitoff of list->repeated.element[s]. */ { - unsigned int i, j, k, newcount; - - i = list->initial.count; - newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0); - ensure_initial_alloc (list, newcount); - for (k = 0; k < q; k++) - for (j = 0; j < list->repeated.count; j++, i++) - copy_element (&list->initial.element[i], - &list->repeated.element[j]); - for (j = 0; j < s; j++, i++) - copy_element (&list->initial.element[i], &list->repeated.element[j]); - if (t > 0) - { - copy_element (&list->initial.element[i], - &list->repeated.element[j]); - list->initial.element[i].repcount = t; - i++; - } - ASSERT (i == newcount); - list->initial.count = newcount; - /* The new length of the initial segment is - = list->initial.length - + q * list->repeated.length - + list->repeated[0..s-1].repcount + t - = list->initial.length + q * n + r - = m. - */ - list->initial.length = m; + unsigned int i, j, k, newcount; + + i = list->initial.count; + newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0); + ensure_initial_alloc (list, newcount); + for (k = 0; k < q; k++) + for (j = 0; j < list->repeated.count; j++, i++) + copy_element (&list->initial.element[i], + &list->repeated.element[j]); + for (j = 0; j < s; j++, i++) + copy_element (&list->initial.element[i], &list->repeated.element[j]); + if (t > 0) + { + copy_element (&list->initial.element[i], + &list->repeated.element[j]); + list->initial.element[i].repcount = t; + i++; + } + ASSERT (i == newcount); + list->initial.count = newcount; + /* The new length of the initial segment is + = list->initial.length + + q * list->repeated.length + + list->repeated[0..s-1].repcount + t + = list->initial.length + q * n + r + = m. + */ + list->initial.length = m; } /* And rotate list->repeated. */ if (r > 0) - { - unsigned int i, j, oldcount, newcount; - struct format_arg *newelement; - - oldcount = list->repeated.count; - newcount = list->repeated.count + (t > 0 ? 1 : 0); - newelement = XNMALLOC (newcount, struct format_arg); - i = 0; - for (j = s; j < oldcount; j++, i++) - newelement[i] = list->repeated.element[j]; - for (j = 0; j < s; j++, i++) - newelement[i] = list->repeated.element[j]; - if (t > 0) - { - copy_element (&newelement[oldcount], &newelement[0]); - newelement[0].repcount -= t; - newelement[oldcount].repcount = t; - } - free (list->repeated.element); - list->repeated.element = newelement; - } + { + unsigned int i, j, oldcount, newcount; + struct format_arg *newelement; + + oldcount = list->repeated.count; + newcount = list->repeated.count + (t > 0 ? 1 : 0); + newelement = XNMALLOC (newcount, struct format_arg); + i = 0; + for (j = s; j < oldcount; j++, i++) + newelement[i] = list->repeated.element[j]; + for (j = 0; j < s; j++, i++) + newelement[i] = list->repeated.element[j]; + if (t > 0) + { + copy_element (&newelement[oldcount], &newelement[0]); + newelement[0].repcount -= t; + newelement[oldcount].repcount = t; + } + free (list->repeated.element); + list->repeated.element = newelement; + } } } @@ -860,44 +860,44 @@ initial_unshare (struct format_arg_list *list, unsigned int n) if (list->initial.element[s].repcount > 1) { /* Split the entry into at most three entries: for indices < n, - for index n, and for indices > n. */ + for index n, and for indices > n. */ unsigned int oldrepcount = list->initial.element[s].repcount; unsigned int newcount = - list->initial.count + (t == 0 || t == oldrepcount - 1 ? 1 : 2); + list->initial.count + (t == 0 || t == oldrepcount - 1 ? 1 : 2); ensure_initial_alloc (list, newcount); if (t == 0 || t == oldrepcount - 1) - { - unsigned int i; - - for (i = list->initial.count - 1; i > s; i--) - list->initial.element[i+1] = list->initial.element[i]; - copy_element (&list->initial.element[s+1], &list->initial.element[s]); - if (t == 0) - { - list->initial.element[s].repcount = 1; - list->initial.element[s+1].repcount = oldrepcount - 1; - } - else - { - list->initial.element[s].repcount = oldrepcount - 1; - list->initial.element[s+1].repcount = 1; - } - } + { + unsigned int i; + + for (i = list->initial.count - 1; i > s; i--) + list->initial.element[i+1] = list->initial.element[i]; + copy_element (&list->initial.element[s+1], &list->initial.element[s]); + if (t == 0) + { + list->initial.element[s].repcount = 1; + list->initial.element[s+1].repcount = oldrepcount - 1; + } + else + { + list->initial.element[s].repcount = oldrepcount - 1; + list->initial.element[s+1].repcount = 1; + } + } else - { - unsigned int i; - - for (i = list->initial.count - 1; i > s; i--) - list->initial.element[i+2] = list->initial.element[i]; - copy_element (&list->initial.element[s+2], &list->initial.element[s]); - copy_element (&list->initial.element[s+1], &list->initial.element[s]); - list->initial.element[s].repcount = t; - list->initial.element[s+1].repcount = 1; - list->initial.element[s+2].repcount = oldrepcount - 1 - t; - } + { + unsigned int i; + + for (i = list->initial.count - 1; i > s; i--) + list->initial.element[i+2] = list->initial.element[i]; + copy_element (&list->initial.element[s+2], &list->initial.element[s]); + copy_element (&list->initial.element[s+1], &list->initial.element[s]); + list->initial.element[s].repcount = t; + list->initial.element[s+1].repcount = 1; + list->initial.element[s+2].repcount = oldrepcount - 1 - t; + } list->initial.count = newcount; if (t > 0) - s++; + s++; } /* Now the entry for index n has repcount 1. */ @@ -922,7 +922,7 @@ shift_list (struct format_arg_list *list, unsigned int n) grow_initial_alloc (list); for (i = list->initial.count; i > 0; i--) - list->initial.element[i] = list->initial.element[i-1]; + list->initial.element[i] = list->initial.element[i-1]; list->initial.element[0].repcount = n; list->initial.element[0].presence = FCT_REQUIRED; list->initial.element[0].type = FAT_OBJECT; @@ -944,8 +944,8 @@ shift_list (struct format_arg_list *list, unsigned int n) /* Memory effects: Freshly allocated element's sublist. */ static bool make_intersected_element (struct format_arg *re, - const struct format_arg * e1, - const struct format_arg * e2) + const struct format_arg * e1, + const struct format_arg * e2) { /* Intersect the cdr types. */ if (e1->presence == FCT_REQUIRED || e2->presence == FCT_REQUIRED) @@ -958,43 +958,43 @@ make_intersected_element (struct format_arg *re, { re->type = e2->type; if (re->type == FAT_LIST) - re->list = copy_list (e2->list); + re->list = copy_list (e2->list); } else if (e2->type == FAT_OBJECT) { re->type = e1->type; if (re->type == FAT_LIST) - re->list = copy_list (e1->list); + re->list = copy_list (e1->list); } else if (e1->type == FAT_LIST - && (e2->type == FAT_CHARACTER_INTEGER_NULL - || e2->type == FAT_CHARACTER_NULL - || e2->type == FAT_INTEGER_NULL)) + && (e2->type == FAT_CHARACTER_INTEGER_NULL + || e2->type == FAT_CHARACTER_NULL + || e2->type == FAT_INTEGER_NULL)) { re->type = e1->type; re->list = make_intersection_with_empty_list (e1->list); if (re->list == NULL) - return false; + return false; } else if (e2->type == FAT_LIST - && (e1->type == FAT_CHARACTER_INTEGER_NULL - || e1->type == FAT_CHARACTER_NULL - || e1->type == FAT_INTEGER_NULL)) + && (e1->type == FAT_CHARACTER_INTEGER_NULL + || e1->type == FAT_CHARACTER_NULL + || e1->type == FAT_INTEGER_NULL)) { re->type = e2->type; re->list = make_intersection_with_empty_list (e2->list); if (re->list == NULL) - return false; + return false; } else if (e1->type == FAT_CHARACTER_INTEGER_NULL - && (e2->type == FAT_CHARACTER_NULL || e2->type == FAT_CHARACTER - || e2->type == FAT_INTEGER_NULL || e2->type == FAT_INTEGER)) + && (e2->type == FAT_CHARACTER_NULL || e2->type == FAT_CHARACTER + || e2->type == FAT_INTEGER_NULL || e2->type == FAT_INTEGER)) { re->type = e2->type; } else if (e2->type == FAT_CHARACTER_INTEGER_NULL - && (e1->type == FAT_CHARACTER_NULL || e1->type == FAT_CHARACTER - || e1->type == FAT_INTEGER_NULL || e1->type == FAT_INTEGER)) + && (e1->type == FAT_CHARACTER_NULL || e1->type == FAT_CHARACTER + || e1->type == FAT_INTEGER_NULL || e1->type == FAT_INTEGER)) { re->type = e1->type; } @@ -1023,12 +1023,12 @@ make_intersected_element (struct format_arg *re, re->type = e1->type; } else if (e1->type == FAT_COMPLEX - && (e2->type == FAT_REAL || e2->type == FAT_INTEGER)) + && (e2->type == FAT_REAL || e2->type == FAT_INTEGER)) { re->type = e2->type; } else if (e2->type == FAT_COMPLEX - && (e1->type == FAT_REAL || e1->type == FAT_INTEGER)) + && (e1->type == FAT_REAL || e1->type == FAT_INTEGER)) { re->type = e1->type; } @@ -1036,12 +1036,12 @@ make_intersected_element (struct format_arg *re, { re->type = e1->type; if (re->type == FAT_LIST) - { - re->list = make_intersected_list (copy_list (e1->list), - copy_list (e2->list)); - if (re->list == NULL) - return false; - } + { + re->list = make_intersected_list (copy_list (e1->list), + copy_list (e2->list)); + if (re->list == NULL) + return false; + } } else /* Each of FAT_CHARACTER, FAT_INTEGER, FAT_LIST, FAT_FORMATSTRING @@ -1065,7 +1065,7 @@ append_repeated_to_initial (struct format_arg_list *list) ensure_initial_alloc (list, newcount); i = list->initial.count; for (j = 0; j < list->repeated.count; j++, i++) - list->initial.element[i] = list->repeated.element[j]; + list->initial.element[i] = list->repeated.element[j]; list->initial.count = newcount; list->initial.length = list->initial.length + list->repeated.length; free (list->repeated.element); @@ -1091,26 +1091,26 @@ backtrack_in_initial (struct format_arg_list *list) { unsigned int i = list->initial.count - 1; if (list->initial.element[i].presence == FCT_REQUIRED) - { - /* Throw away this element. */ - list->initial.length -= list->initial.element[i].repcount; - free_element (&list->initial.element[i]); - list->initial.count = i; - } + { + /* Throw away this element. */ + list->initial.length -= list->initial.element[i].repcount; + free_element (&list->initial.element[i]); + list->initial.count = i; + } else /* list->initial.element[i].presence == FCT_OPTIONAL */ - { - /* The list must end here. */ - list->initial.length--; - if (list->initial.element[i].repcount > 1) - list->initial.element[i].repcount--; - else - { - free_element (&list->initial.element[i]); - list->initial.count = i; - } - VERIFY_LIST (list); - return list; - } + { + /* The list must end here. */ + list->initial.length--; + if (list->initial.element[i].repcount > 1) + list->initial.element[i].repcount--; + else + { + free_element (&list->initial.element[i]); + list->initial.count = i; + } + VERIFY_LIST (list); + return list; + } } free_list (list); @@ -1124,7 +1124,7 @@ backtrack_in_initial (struct format_arg_list *list) freshly allocated. */ static struct format_arg_list * make_intersected_list (struct format_arg_list *list1, - struct format_arg_list *list2) + struct format_arg_list *list2) { struct format_arg_list *result; @@ -1154,9 +1154,9 @@ make_intersected_list (struct format_arg_list *list1, unsigned int m = MAX (list1->initial.length, list2->initial.length); if (list1->repeated.length > 0) - rotate_loop (list1, m); + rotate_loop (list1, m); if (list2->repeated.length > 0) - rotate_loop (list2, m); + rotate_loop (list2, m); } if (list1->repeated.length > 0 && list2->repeated.length > 0) @@ -1187,78 +1187,78 @@ make_intersected_list (struct format_arg_list *list1, e2 = list2->initial.element; c2 = list2->initial.count; while (c1 > 0 && c2 > 0) { - struct format_arg *re; - - /* Ensure room in result->initial. */ - grow_initial_alloc (result); - re = &result->initial.element[result->initial.count]; - re->repcount = MIN (e1->repcount, e2->repcount); - - /* Intersect the argument types. */ - if (!make_intersected_element (re, e1, e2)) - { - /* If re->presence == FCT_OPTIONAL, the result list ends here. */ - if (re->presence == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - goto done; - } - - result->initial.count++; - result->initial.length += re->repcount; - - e1->repcount -= re->repcount; - if (e1->repcount == 0) - { - e1++; - c1--; - } - e2->repcount -= re->repcount; - if (e2->repcount == 0) - { - e2++; - c2--; - } + struct format_arg *re; + + /* Ensure room in result->initial. */ + grow_initial_alloc (result); + re = &result->initial.element[result->initial.count]; + re->repcount = MIN (e1->repcount, e2->repcount); + + /* Intersect the argument types. */ + if (!make_intersected_element (re, e1, e2)) + { + /* If re->presence == FCT_OPTIONAL, the result list ends here. */ + if (re->presence == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + goto done; + } + + result->initial.count++; + result->initial.length += re->repcount; + + e1->repcount -= re->repcount; + if (e1->repcount == 0) + { + e1++; + c1--; + } + e2->repcount -= re->repcount; + if (e2->repcount == 0) + { + e2++; + c2--; + } } if (list1->repeated.count == 0 && list2->repeated.count == 0) { - /* Intersecting two finite lists. */ - if (c1 > 0) - { - /* list1 longer than list2. */ - if (e1->presence == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - } - else if (c2 > 0) - { - /* list2 longer than list1. */ - if (e2->presence == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - } - goto done; + /* Intersecting two finite lists. */ + if (c1 > 0) + { + /* list1 longer than list2. */ + if (e1->presence == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + } + else if (c2 > 0) + { + /* list2 longer than list1. */ + if (e2->presence == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + } + goto done; } else if (list1->repeated.count == 0) { - /* Intersecting a finite and an infinite list. */ - ASSERT (c1 == 0); - if ((c2 > 0 ? e2->presence : list2->repeated.element[0].presence) - == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - goto done; + /* Intersecting a finite and an infinite list. */ + ASSERT (c1 == 0); + if ((c2 > 0 ? e2->presence : list2->repeated.element[0].presence) + == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + goto done; } else if (list2->repeated.count == 0) { - /* Intersecting an infinite and a finite list. */ - ASSERT (c2 == 0); - if ((c1 > 0 ? e1->presence : list1->repeated.element[0].presence) - == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - goto done; + /* Intersecting an infinite and a finite list. */ + ASSERT (c2 == 0); + if ((c1 > 0 ? e1->presence : list1->repeated.element[0].presence) + == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + goto done; } /* Intersecting two infinite lists. */ ASSERT (c1 == 0 && c2 == 0); @@ -1275,41 +1275,41 @@ make_intersected_list (struct format_arg_list *list1, e2 = list2->repeated.element; c2 = list2->repeated.count; while (c1 > 0 && c2 > 0) { - struct format_arg *re; - - /* Ensure room in result->repeated. */ - grow_repeated_alloc (result); - re = &result->repeated.element[result->repeated.count]; - re->repcount = MIN (e1->repcount, e2->repcount); - - /* Intersect the argument types. */ - if (!make_intersected_element (re, e1, e2)) - { - append_repeated_to_initial (result); - - /* If re->presence == FCT_OPTIONAL, the result list ends here. */ - if (re->presence == FCT_REQUIRED) - /* Contradiction. Backtrack. */ - result = backtrack_in_initial (result); - - goto done; - } - - result->repeated.count++; - result->repeated.length += re->repcount; - - e1->repcount -= re->repcount; - if (e1->repcount == 0) - { - e1++; - c1--; - } - e2->repcount -= re->repcount; - if (e2->repcount == 0) - { - e2++; - c2--; - } + struct format_arg *re; + + /* Ensure room in result->repeated. */ + grow_repeated_alloc (result); + re = &result->repeated.element[result->repeated.count]; + re->repcount = MIN (e1->repcount, e2->repcount); + + /* Intersect the argument types. */ + if (!make_intersected_element (re, e1, e2)) + { + append_repeated_to_initial (result); + + /* If re->presence == FCT_OPTIONAL, the result list ends here. */ + if (re->presence == FCT_REQUIRED) + /* Contradiction. Backtrack. */ + result = backtrack_in_initial (result); + + goto done; + } + + result->repeated.count++; + result->repeated.length += re->repcount; + + e1->repcount -= re->repcount; + if (e1->repcount == 0) + { + e1++; + c1--; + } + e2->repcount -= re->repcount; + if (e2->repcount == 0) + { + e2++; + c2--; + } } ASSERT (c1 == 0 && c2 == 0); } @@ -1339,7 +1339,7 @@ make_intersection_with_empty_list (struct format_arg_list *list) if (list->initial.count > 0 ? list->initial.element[0].presence == FCT_REQUIRED : list->repeated.count > 0 - && list->repeated.element[0].presence == FCT_REQUIRED) + && list->repeated.element[0].presence == FCT_REQUIRED) return NULL; else return make_empty_list (); @@ -1358,22 +1358,22 @@ intersection (struct format_arg_list *list1, struct format_arg_list *list2) if (list1 != NULL) { if (list2 != NULL) - return make_intersected_list (list1, list2); + return make_intersected_list (list1, list2); else - { - free_list (list1); - return NULL; - } + { + free_list (list1); + return NULL; + } } else { if (list2 != NULL) - { - free_list (list2); - return NULL; - } + { + free_list (list2); + return NULL; + } else - return NULL; + return NULL; } } #endif @@ -1385,8 +1385,8 @@ intersection (struct format_arg_list *list1, struct format_arg_list *list2) constraints. */ static void make_union_element (struct format_arg *re, - const struct format_arg * e1, - const struct format_arg * e2) + const struct format_arg * e1, + const struct format_arg * e2) { /* Union of the cdr types. */ if (e1->presence == FCT_REQUIRED && e2->presence == FCT_REQUIRED) @@ -1399,18 +1399,18 @@ make_union_element (struct format_arg *re, { re->type = e1->type; if (re->type == FAT_LIST) - re->list = make_union_list (copy_list (e1->list), - copy_list (e2->list)); + re->list = make_union_list (copy_list (e1->list), + copy_list (e2->list)); } else if (e1->type == FAT_CHARACTER_INTEGER_NULL - && (e2->type == FAT_CHARACTER_NULL || e2->type == FAT_CHARACTER - || e2->type == FAT_INTEGER_NULL || e2->type == FAT_INTEGER)) + && (e2->type == FAT_CHARACTER_NULL || e2->type == FAT_CHARACTER + || e2->type == FAT_INTEGER_NULL || e2->type == FAT_INTEGER)) { re->type = e1->type; } else if (e2->type == FAT_CHARACTER_INTEGER_NULL - && (e1->type == FAT_CHARACTER_NULL || e1->type == FAT_CHARACTER - || e1->type == FAT_INTEGER_NULL || e1->type == FAT_INTEGER)) + && (e1->type == FAT_CHARACTER_NULL || e1->type == FAT_CHARACTER + || e1->type == FAT_INTEGER_NULL || e1->type == FAT_INTEGER)) { re->type = e2->type; } @@ -1439,48 +1439,48 @@ make_union_element (struct format_arg *re, re->type = e2->type; } else if (e1->type == FAT_COMPLEX - && (e2->type == FAT_REAL || e2->type == FAT_INTEGER)) + && (e2->type == FAT_REAL || e2->type == FAT_INTEGER)) { re->type = e1->type; } else if (e2->type == FAT_COMPLEX - && (e1->type == FAT_REAL || e1->type == FAT_INTEGER)) + && (e1->type == FAT_REAL || e1->type == FAT_INTEGER)) { re->type = e2->type; } else if (e1->type == FAT_LIST && is_empty_list (e1->list)) { if (e2->type == FAT_CHARACTER_INTEGER_NULL - || e2->type == FAT_CHARACTER_NULL - || e2->type == FAT_INTEGER_NULL) - re->type = e2->type; + || e2->type == FAT_CHARACTER_NULL + || e2->type == FAT_INTEGER_NULL) + re->type = e2->type; else if (e2->type == FAT_CHARACTER) - re->type = FAT_CHARACTER_NULL; + re->type = FAT_CHARACTER_NULL; else if (e2->type == FAT_INTEGER) - re->type = FAT_INTEGER_NULL; + re->type = FAT_INTEGER_NULL; else - re->type = FAT_OBJECT; + re->type = FAT_OBJECT; } else if (e2->type == FAT_LIST && is_empty_list (e2->list)) { if (e1->type == FAT_CHARACTER_INTEGER_NULL - || e1->type == FAT_CHARACTER_NULL - || e1->type == FAT_INTEGER_NULL) - re->type = e1->type; + || e1->type == FAT_CHARACTER_NULL + || e1->type == FAT_INTEGER_NULL) + re->type = e1->type; else if (e1->type == FAT_CHARACTER) - re->type = FAT_CHARACTER_NULL; + re->type = FAT_CHARACTER_NULL; else if (e1->type == FAT_INTEGER) - re->type = FAT_INTEGER_NULL; + re->type = FAT_INTEGER_NULL; else - re->type = FAT_OBJECT; + re->type = FAT_OBJECT; } else if ((e1->type == FAT_CHARACTER || e1->type == FAT_CHARACTER_NULL) - && (e2->type == FAT_INTEGER || e2->type == FAT_INTEGER_NULL)) + && (e2->type == FAT_INTEGER || e2->type == FAT_INTEGER_NULL)) { re->type = FAT_CHARACTER_INTEGER_NULL; } else if ((e2->type == FAT_CHARACTER || e2->type == FAT_CHARACTER_NULL) - && (e1->type == FAT_INTEGER || e1->type == FAT_INTEGER_NULL)) + && (e1->type == FAT_INTEGER || e1->type == FAT_INTEGER_NULL)) { re->type = FAT_CHARACTER_INTEGER_NULL; } @@ -1507,23 +1507,23 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2) { /* Step 1: Ensure list1->repeated.length == list2->repeated.length. */ { - unsigned int n1 = list1->repeated.length; - unsigned int n2 = list2->repeated.length; - unsigned int g = gcd (n1, n2); - unsigned int m1 = n2 / g; /* = lcm(n1,n2) / n1 */ - unsigned int m2 = n1 / g; /* = lcm(n1,n2) / n2 */ - - unfold_loop (list1, m1); - unfold_loop (list2, m2); - /* Now list1->repeated.length = list2->repeated.length = lcm(n1,n2). */ + unsigned int n1 = list1->repeated.length; + unsigned int n2 = list2->repeated.length; + unsigned int g = gcd (n1, n2); + unsigned int m1 = n2 / g; /* = lcm(n1,n2) / n1 */ + unsigned int m2 = n1 / g; /* = lcm(n1,n2) / n2 */ + + unfold_loop (list1, m1); + unfold_loop (list2, m2); + /* Now list1->repeated.length = list2->repeated.length = lcm(n1,n2). */ } /* Step 2: Ensure that list1->initial.length == list2->initial.length. */ { - unsigned int m = MAX (list1->initial.length, list2->initial.length); + unsigned int m = MAX (list1->initial.length, list2->initial.length); - rotate_loop (list1, m); - rotate_loop (list2, m); + rotate_loop (list1, m); + rotate_loop (list2, m); } ASSERT (list1->initial.length == list2->initial.length); @@ -1532,24 +1532,24 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2) else if (list1->repeated.length > 0) { /* Ensure the initial segment of the result can be computed from the - initial segment of list1. */ + initial segment of list1. */ if (list2->initial.length >= list1->initial.length) - { - rotate_loop (list1, list2->initial.length); - if (list1->repeated.element[0].presence == FCT_REQUIRED) - rotate_loop (list1, list1->initial.length + 1); - } + { + rotate_loop (list1, list2->initial.length); + if (list1->repeated.element[0].presence == FCT_REQUIRED) + rotate_loop (list1, list1->initial.length + 1); + } } else if (list2->repeated.length > 0) { /* Ensure the initial segment of the result can be computed from the - initial segment of list2. */ + initial segment of list2. */ if (list1->initial.length >= list2->initial.length) - { - rotate_loop (list2, list1->initial.length); - if (list2->repeated.element[0].presence == FCT_REQUIRED) - rotate_loop (list2, list2->initial.length + 1); - } + { + rotate_loop (list2, list1->initial.length); + if (list2->repeated.element[0].presence == FCT_REQUIRED) + rotate_loop (list2, list2->initial.length + 1); + } } /* Step 3: Allocate the result. */ @@ -1574,112 +1574,112 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2) e2 = list2->initial.element; c2 = list2->initial.count; while (c1 > 0 && c2 > 0) { - struct format_arg *re; - - /* Ensure room in result->initial. */ - grow_initial_alloc (result); - re = &result->initial.element[result->initial.count]; - re->repcount = MIN (e1->repcount, e2->repcount); - - /* Union of the argument types. */ - make_union_element (re, e1, e2); - - result->initial.count++; - result->initial.length += re->repcount; - - e1->repcount -= re->repcount; - if (e1->repcount == 0) - { - e1++; - c1--; - } - e2->repcount -= re->repcount; - if (e2->repcount == 0) - { - e2++; - c2--; - } + struct format_arg *re; + + /* Ensure room in result->initial. */ + grow_initial_alloc (result); + re = &result->initial.element[result->initial.count]; + re->repcount = MIN (e1->repcount, e2->repcount); + + /* Union of the argument types. */ + make_union_element (re, e1, e2); + + result->initial.count++; + result->initial.length += re->repcount; + + e1->repcount -= re->repcount; + if (e1->repcount == 0) + { + e1++; + c1--; + } + e2->repcount -= re->repcount; + if (e2->repcount == 0) + { + e2++; + c2--; + } } if (c1 > 0) { - /* list2 already terminated, but still more elements in list1->initial. - Copy them all, but turn the first presence to FCT_OPTIONAL. */ - ASSERT (list2->repeated.count == 0); - - if (e1->presence == FCT_REQUIRED) - { - struct format_arg *re; - - /* Ensure room in result->initial. */ - grow_initial_alloc (result); - re = &result->initial.element[result->initial.count]; - copy_element (re, e1); - re->presence = FCT_OPTIONAL; - re->repcount = 1; - result->initial.count++; - result->initial.length += 1; - e1->repcount -= 1; - if (e1->repcount == 0) - { - e1++; - c1--; - } - } - - /* Ensure room in result->initial. */ - ensure_initial_alloc (result, result->initial.count + c1); - while (c1 > 0) - { - struct format_arg *re; - - re = &result->initial.element[result->initial.count]; - copy_element (re, e1); - result->initial.count++; - result->initial.length += re->repcount; - e1++; - c1--; - } + /* list2 already terminated, but still more elements in list1->initial. + Copy them all, but turn the first presence to FCT_OPTIONAL. */ + ASSERT (list2->repeated.count == 0); + + if (e1->presence == FCT_REQUIRED) + { + struct format_arg *re; + + /* Ensure room in result->initial. */ + grow_initial_alloc (result); + re = &result->initial.element[result->initial.count]; + copy_element (re, e1); + re->presence = FCT_OPTIONAL; + re->repcount = 1; + result->initial.count++; + result->initial.length += 1; + e1->repcount -= 1; + if (e1->repcount == 0) + { + e1++; + c1--; + } + } + + /* Ensure room in result->initial. */ + ensure_initial_alloc (result, result->initial.count + c1); + while (c1 > 0) + { + struct format_arg *re; + + re = &result->initial.element[result->initial.count]; + copy_element (re, e1); + result->initial.count++; + result->initial.length += re->repcount; + e1++; + c1--; + } } else if (c2 > 0) { - /* list1 already terminated, but still more elements in list2->initial. - Copy them all, but turn the first presence to FCT_OPTIONAL. */ - ASSERT (list1->repeated.count == 0); - - if (e2->presence == FCT_REQUIRED) - { - struct format_arg *re; - - /* Ensure room in result->initial. */ - grow_initial_alloc (result); - re = &result->initial.element[result->initial.count]; - copy_element (re, e2); - re->presence = FCT_OPTIONAL; - re->repcount = 1; - result->initial.count++; - result->initial.length += 1; - e2->repcount -= 1; - if (e2->repcount == 0) - { - e2++; - c2--; - } - } - - /* Ensure room in result->initial. */ - ensure_initial_alloc (result, result->initial.count + c2); - while (c2 > 0) - { - struct format_arg *re; - - re = &result->initial.element[result->initial.count]; - copy_element (re, e2); - result->initial.count++; - result->initial.length += re->repcount; - e2++; - c2--; - } + /* list1 already terminated, but still more elements in list2->initial. + Copy them all, but turn the first presence to FCT_OPTIONAL. */ + ASSERT (list1->repeated.count == 0); + + if (e2->presence == FCT_REQUIRED) + { + struct format_arg *re; + + /* Ensure room in result->initial. */ + grow_initial_alloc (result); + re = &result->initial.element[result->initial.count]; + copy_element (re, e2); + re->presence = FCT_OPTIONAL; + re->repcount = 1; + result->initial.count++; + result->initial.length += 1; + e2->repcount -= 1; + if (e2->repcount == 0) + { + e2++; + c2--; + } + } + + /* Ensure room in result->initial. */ + ensure_initial_alloc (result, result->initial.count + c2); + while (c2 > 0) + { + struct format_arg *re; + + re = &result->initial.element[result->initial.count]; + copy_element (re, e2); + result->initial.count++; + result->initial.length += re->repcount; + e2++; + c2--; + } } ASSERT (c1 == 0 && c2 == 0); } @@ -1695,63 +1695,63 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2) e1 = list1->repeated.element; c1 = list1->repeated.count; e2 = list2->repeated.element; c2 = list2->repeated.count; while (c1 > 0 && c2 > 0) - { - struct format_arg *re; - - /* Ensure room in result->repeated. */ - grow_repeated_alloc (result); - re = &result->repeated.element[result->repeated.count]; - re->repcount = MIN (e1->repcount, e2->repcount); - - /* Union of the argument types. */ - make_union_element (re, e1, e2); - - result->repeated.count++; - result->repeated.length += re->repcount; - - e1->repcount -= re->repcount; - if (e1->repcount == 0) - { - e1++; - c1--; - } - e2->repcount -= re->repcount; - if (e2->repcount == 0) - { - e2++; - c2--; - } - } + { + struct format_arg *re; + + /* Ensure room in result->repeated. */ + grow_repeated_alloc (result); + re = &result->repeated.element[result->repeated.count]; + re->repcount = MIN (e1->repcount, e2->repcount); + + /* Union of the argument types. */ + make_union_element (re, e1, e2); + + result->repeated.count++; + result->repeated.length += re->repcount; + + e1->repcount -= re->repcount; + if (e1->repcount == 0) + { + e1++; + c1--; + } + e2->repcount -= re->repcount; + if (e2->repcount == 0) + { + e2++; + c2--; + } + } ASSERT (c1 == 0 && c2 == 0); } else if (list1->repeated.length > 0) { /* Turning FCT_REQUIRED into FCT_OPTIONAL was already handled in the - initial segment. Just copy the repeated segment of list1. */ + initial segment. Just copy the repeated segment of list1. */ unsigned int i; result->repeated.count = list1->repeated.count; result->repeated.allocated = result->repeated.count; result->repeated.element = - XNMALLOC (result->repeated.allocated, struct format_arg); + XNMALLOC (result->repeated.allocated, struct format_arg); for (i = 0; i < list1->repeated.count; i++) - copy_element (&result->repeated.element[i], - &list1->repeated.element[i]); + copy_element (&result->repeated.element[i], + &list1->repeated.element[i]); result->repeated.length = list1->repeated.length; } else if (list2->repeated.length > 0) { /* Turning FCT_REQUIRED into FCT_OPTIONAL was already handled in the - initial segment. Just copy the repeated segment of list2. */ + initial segment. Just copy the repeated segment of list2. */ unsigned int i; result->repeated.count = list2->repeated.count; result->repeated.allocated = result->repeated.count; result->repeated.element = - XNMALLOC (result->repeated.allocated, struct format_arg); + XNMALLOC (result->repeated.allocated, struct format_arg); for (i = 0; i < list2->repeated.count; i++) - copy_element (&result->repeated.element[i], - &list2->repeated.element[i]); + copy_element (&result->repeated.element[i], + &list2->repeated.element[i]); result->repeated.length = list2->repeated.length; } @@ -1777,7 +1777,7 @@ make_union_with_empty_list (struct format_arg_list *list) if (list->initial.count > 0 ? list->initial.element[0].presence == FCT_REQUIRED : list->repeated.count > 0 - && list->repeated.element[0].presence == FCT_REQUIRED) + && list->repeated.element[0].presence == FCT_REQUIRED) { initial_splitelement (list, 1); ASSERT (list->initial.count > 0); @@ -1786,7 +1786,7 @@ make_union_with_empty_list (struct format_arg_list *list) list->initial.element[0].presence = FCT_OPTIONAL; /* We might need to merge list->initial.element[0] and - list->initial.element[1]. */ + list->initial.element[1]. */ normalize_outermost_list (list); } @@ -1807,16 +1807,16 @@ union (struct format_arg_list *list1, struct format_arg_list *list2) if (list1 != NULL) { if (list2 != NULL) - return make_union_list (list1, list2); + return make_union_list (list1, list2); else - return list1; + return list1; } else { if (list2 != NULL) - return list2; + return list2; else - return NULL; + return NULL; } } @@ -1847,9 +1847,9 @@ is_required (const struct format_arg_list *list, unsigned int n) if (s < list->initial.count) { if (list->initial.element[s].presence != FCT_REQUIRED) - return false; + return false; else - return true; + return true; } /* Walk the list->repeated segment. */ @@ -1868,9 +1868,9 @@ is_required (const struct format_arg_list *list, unsigned int n) if (s < list->repeated.count) { if (list->repeated.element[s].presence != FCT_REQUIRED) - return false; + return false; else - return true; + return true; } /* The list->repeated segment consists only of FCT_REQUIRED. So, @@ -1896,7 +1896,7 @@ add_required_constraint (struct format_arg_list *list, unsigned int n) if (list->repeated.count == 0 && list->initial.length <= n) { /* list is already constrained to have at most length n. - Contradiction. */ + Contradiction. */ free_list (list); return NULL; } @@ -1970,7 +1970,7 @@ add_end_constraint (struct format_arg_list *list, unsigned int n) /* Memory effects: list is freed. The result is freshly allocated. */ static struct format_arg_list * add_type_constraint (struct format_arg_list *list, unsigned int n, - enum format_arg_type type) + enum format_arg_type type) { unsigned int s; struct format_arg newconstraint; @@ -1987,7 +1987,7 @@ add_type_constraint (struct format_arg_list *list, unsigned int n, newconstraint.presence = FCT_OPTIONAL; newconstraint.type = type; if (!make_intersected_element (&tmpelement, - &list->initial.element[s], &newconstraint)) + &list->initial.element[s], &newconstraint)) return add_end_constraint (list, n); free_element (&list->initial.element[s]); list->initial.element[s].type = tmpelement.type; @@ -2005,8 +2005,8 @@ add_type_constraint (struct format_arg_list *list, unsigned int n, /* Memory effects: list is freed. The result is freshly allocated. */ static struct format_arg_list * add_listtype_constraint (struct format_arg_list *list, unsigned int n, - enum format_arg_type type, - struct format_arg_list *sublist) + enum format_arg_type type, + struct format_arg_list *sublist) { unsigned int s; struct format_arg newconstraint; @@ -2024,7 +2024,7 @@ add_listtype_constraint (struct format_arg_list *list, unsigned int n, newconstraint.type = type; newconstraint.list = sublist; if (!make_intersected_element (&tmpelement, - &list->initial.element[s], &newconstraint)) + &list->initial.element[s], &newconstraint)) return add_end_constraint (list, n); free_element (&list->initial.element[s]); list->initial.element[s].type = tmpelement.type; @@ -2040,7 +2040,7 @@ add_listtype_constraint (struct format_arg_list *list, unsigned int n, static void add_req_type_constraint (struct format_arg_list **listp, - unsigned int position, enum format_arg_type type) + unsigned int position, enum format_arg_type type) { *listp = add_required_constraint (*listp, position); *listp = add_type_constraint (*listp, position, type); @@ -2049,8 +2049,8 @@ add_req_type_constraint (struct format_arg_list **listp, static void add_req_listtype_constraint (struct format_arg_list **listp, - unsigned int position, enum format_arg_type type, - struct format_arg_list *sublist) + unsigned int position, enum format_arg_type type, + struct format_arg_list *sublist) { *listp = add_required_constraint (*listp, position); *listp = add_listtype_constraint (*listp, position, type, sublist); @@ -2120,9 +2120,9 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) /* L is a finite list. */ if (sublist->initial.length < period) - /* L and (*^period L) is a contradition, so we need to consider - only 1 and 0 iterations. */ - return make_union_with_empty_list (sublist); + /* L and (*^period L) is a contradition, so we need to consider + only 1 and 0 iterations. */ + return make_union_with_empty_list (sublist); srcseg = &sublist->initial; p = period; @@ -2138,14 +2138,14 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) p = m * Lp; /* Concatenate the initial and the repeated segments into a single - segment. */ + segment. */ tmp.count = sublist->initial.count + sublist->repeated.count; tmp.allocated = tmp.count; tmp.element = XNMALLOC (tmp.allocated, struct format_arg); for (i = 0; i < sublist->initial.count; i++) - tmp.element[i] = sublist->initial.element[i]; + tmp.element[i] = sublist->initial.element[i]; for (j = 0; j < sublist->repeated.count; i++, j++) - tmp.element[i] = sublist->initial.element[j]; + tmp.element[i] = sublist->initial.element[j]; tmp.length = sublist->initial.length + sublist->repeated.length; srcseg = &tmp; @@ -2194,7 +2194,7 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) /* Ensure room in list->initial. */ grow_initial_alloc (list); copy_element (&list->initial.element[list->initial.count], - &srcseg->element[si]); + &srcseg->element[si]); list->initial.element[list->initial.count].repcount = k; list->initial.count++; list->initial.length += k; @@ -2202,10 +2202,10 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) i += k; ti += k; if (ti == srcseg->element[si].repcount) - { - ti = 0; - si++; - } + { + ti = 0; + si++; + } } ASSERT (list->initial.count > 0); @@ -2221,29 +2221,29 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) while (i < n) { unsigned int k = - MIN (srcseg->element[si].repcount - ti, - list->initial.element[sj].repcount - tj); + MIN (srcseg->element[si].repcount - ti, + list->initial.element[sj].repcount - tj); /* Ensure room in list->initial. */ grow_initial_alloc (list); if (!make_intersected_element (&list->initial.element[list->initial.count], - &srcseg->element[si], - &list->initial.element[sj])) - { - if (list->initial.element[list->initial.count].presence == FCT_REQUIRED) - { - /* Contradiction. Backtrack. */ - list = backtrack_in_initial (list); - ASSERT (list != NULL); /* at least the empty list is valid */ - return list; - } - else - { - /* The list ends here. */ - ended = true; - break; - } - } + &srcseg->element[si], + &list->initial.element[sj])) + { + if (list->initial.element[list->initial.count].presence == FCT_REQUIRED) + { + /* Contradiction. Backtrack. */ + list = backtrack_in_initial (list); + ASSERT (list != NULL); /* at least the empty list is valid */ + return list; + } + else + { + /* The list ends here. */ + ended = true; + break; + } + } list->initial.element[list->initial.count].repcount = k; list->initial.count++; list->initial.length += k; @@ -2251,18 +2251,18 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) i += k; ti += k; if (ti == srcseg->element[si].repcount) - { - ti = 0; - si++; - } + { + ti = 0; + si++; + } j += k; tj += k; if (tj == list->initial.element[sj].repcount) - { - tj = 0; - sj++; - } + { + tj = 0; + sj++; + } } if (!ended) ASSERT (list->initial.length == n); @@ -2281,12 +2281,12 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period) splitindex = initial_splitelement (list, n - p); newcount = list->initial.count - splitindex; if (newcount > list->repeated.allocated) - { - list->repeated.allocated = newcount; - list->repeated.element = XNMALLOC (newcount, struct format_arg); - } + { + list->repeated.allocated = newcount; + list->repeated.element = XNMALLOC (newcount, struct format_arg); + } for (i = splitindex, j = 0; i < n; i++, j++) - list->repeated.element[j] = list->initial.element[i]; + list->repeated.element[j] = list->initial.element[i]; list->repeated.count = newcount; list->repeated.length = p; list->initial.count = splitindex; @@ -2338,81 +2338,81 @@ static const enum format_arg_type THREE [3] = { invalid. */ static bool check_params (struct format_arg_list **listp, - unsigned int paramcount, struct param *params, - unsigned int t_count, const enum format_arg_type *t_types, - unsigned int directives, char **invalid_reason) + unsigned int paramcount, struct param *params, + unsigned int t_count, const enum format_arg_type *t_types, + unsigned int directives, char **invalid_reason) { unsigned int orig_paramcount = paramcount; unsigned int orig_t_count = t_count; for (; paramcount > 0 && t_count > 0; - params++, paramcount--, t_types++, t_count--) + params++, paramcount--, t_types++, t_count--) { switch (*t_types) - { - case FAT_CHARACTER_INTEGER_NULL: - break; - case FAT_CHARACTER_NULL: - switch (params->type) - { - case PT_NIL: case PT_CHARACTER: case PT_V: - break; - case PT_INTEGER: case PT_ARGCOUNT: - /* wrong param type */ - *invalid_reason = - xasprintf (_("In the directive number %u, parameter %u is of type '%s' but a parameter of type '%s' is expected."), directives, orig_paramcount - paramcount + 1, "integer", "character"); - return false; - } - break; - case FAT_INTEGER_NULL: - switch (params->type) - { - case PT_NIL: case PT_INTEGER: case PT_ARGCOUNT: case PT_V: - break; - case PT_CHARACTER: - /* wrong param type */ - *invalid_reason = - xasprintf (_("In the directive number %u, parameter %u is of type '%s' but a parameter of type '%s' is expected."), directives, orig_paramcount - paramcount + 1, "character", "integer"); - return false; - } - break; - default: - abort (); - } + { + case FAT_CHARACTER_INTEGER_NULL: + break; + case FAT_CHARACTER_NULL: + switch (params->type) + { + case PT_NIL: case PT_CHARACTER: case PT_V: + break; + case PT_INTEGER: case PT_ARGCOUNT: + /* wrong param type */ + *invalid_reason = + xasprintf (_("In the directive number %u, parameter %u is of type '%s' but a parameter of type '%s' is expected."), directives, orig_paramcount - paramcount + 1, "integer", "character"); + return false; + } + break; + case FAT_INTEGER_NULL: + switch (params->type) + { + case PT_NIL: case PT_INTEGER: case PT_ARGCOUNT: case PT_V: + break; + case PT_CHARACTER: + /* wrong param type */ + *invalid_reason = + xasprintf (_("In the directive number %u, parameter %u is of type '%s' but a parameter of type '%s' is expected."), directives, orig_paramcount - paramcount + 1, "character", "integer"); + return false; + } + break; + default: + abort (); + } if (params->type == PT_V) - { - int position = params->value; - if (position >= 0) - add_req_type_constraint (listp, position, *t_types); - } + { + int position = params->value; + if (position >= 0) + add_req_type_constraint (listp, position, *t_types); + } } for (; paramcount > 0; params++, paramcount--) switch (params->type) { case PT_NIL: - break; + break; case PT_CHARACTER: case PT_INTEGER: case PT_ARGCOUNT: - /* too many params for directive */ - *invalid_reason = - xasprintf (ngettext ("In the directive number %u, too many parameters are given; expected at most %u parameter.", - "In the directive number %u, too many parameters are given; expected at most %u parameters.", - orig_t_count), - directives, orig_t_count); - return false; + /* too many params for directive */ + *invalid_reason = + xasprintf (ngettext ("In the directive number %u, too many parameters are given; expected at most %u parameter.", + "In the directive number %u, too many parameters are given; expected at most %u parameters.", + orig_t_count), + directives, orig_t_count); + return false; case PT_V: - /* Force argument to be NIL. */ - { - int position = params->value; - if (position >= 0) - { - struct format_arg_list *empty_list = make_empty_list (); - add_req_listtype_constraint (listp, position, - FAT_LIST, empty_list); - free_list (empty_list); - } - } - break; + /* Force argument to be NIL. */ + { + int position = params->value; + if (position >= 0) + { + struct format_arg_list *empty_list = make_empty_list (); + add_req_listtype_constraint (listp, position, + FAT_LIST, empty_list); + free_list (empty_list); + } + } + break; } return true; @@ -2441,10 +2441,10 @@ check_params (struct format_arg_list **listp, set to an error message explaining why. */ static bool parse_upto (const char **formatp, - int *positionp, struct format_arg_list **listp, - struct format_arg_list **escapep, int *separatorp, - struct spec *spec, char terminator, bool separator, - char *fdi, char **invalid_reason) + int *positionp, struct format_arg_list **listp, + struct format_arg_list **escapep, int *separatorp, + struct spec *spec, char terminator, bool separator, + char *fdi, char **invalid_reason) { const char *format = *formatp; const char *const format_start = format; @@ -2455,859 +2455,859 @@ parse_upto (const char **formatp, for (; *format != '\0'; ) if (*format++ == '~') { - bool colon_p = false; - bool atsign_p = false; - unsigned int paramcount = 0; - struct param *params = NULL; - - FDI_SET (format - 1, FMTDIR_START); - - /* Count number of directives. */ - spec->directives++; - - /* Parse parameters. */ - for (;;) - { - enum param_type type = PT_NIL; - int value = 0; - - if (c_isdigit (*format)) - { - type = PT_INTEGER; - do - { - value = 10 * value + (*format - '0'); - format++; - } - while (c_isdigit (*format)); - } - else if (*format == '+' || *format == '-') - { - bool negative = (*format == '-'); - type = PT_INTEGER; - format++; - if (!c_isdigit (*format)) - { - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - xasprintf (_("In the directive number %u, '%c' is not followed by a digit."), spec->directives, format[-1]); - FDI_SET (format, FMTDIR_ERROR); - } - return false; - } - do - { - value = 10 * value + (*format - '0'); - format++; - } - while (c_isdigit (*format)); - if (negative) - value = -value; - } - else if (*format == '\'') - { - type = PT_CHARACTER; - format++; - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - format++; - } - else if (*format == 'V' || *format == 'v') - { - type = PT_V; - format++; - value = position; - /* Consumes an argument. */ - if (position >= 0) - position++; - } - else if (*format == '#') - { - type = PT_ARGCOUNT; - format++; - } - - params = - (struct param *) - xrealloc (params, (paramcount + 1) * sizeof (struct param)); - params[paramcount].type = type; - params[paramcount].value = value; - paramcount++; - - if (*format == ',') - format++; - else - break; - } - - /* Parse modifiers. */ - for (;;) - { - if (*format == ':') - { - format++; - colon_p = true; - } - else if (*format == '@') - { - format++; - atsign_p = true; - } - else - break; - } - - /* Parse directive. */ - switch (*format++) - { - case 'A': case 'a': /* 22.3.4.1 FORMAT-ASCII */ - case 'S': case 's': /* 22.3.4.2 FORMAT-S-EXPRESSION */ - if (!check_params (&list, paramcount, params, 4, IIIC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_OBJECT); - break; - - case 'C': case 'c': /* FORMAT-CHARACTER */ - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (paramcount == 0 - || (paramcount == 1 && params[0].type == PT_NIL)) - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_CHARACTER); - break; - - case 'D': case 'd': /* 22.3.2.2 FORMAT-DECIMAL */ - case 'B': case 'b': /* 22.3.2.3 FORMAT-BINARY */ - case 'O': case 'o': /* 22.3.2.4 FORMAT-OCTAL */ - case 'X': case 'x': /* 22.3.2.5 FORMAT-HEXADECIMAL */ - if (!check_params (&list, paramcount, params, 4, ICCI, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_INTEGER); - break; - - case 'R': case 'r': /* 22.3.2.1 FORMAT-RADIX */ - if (!check_params (&list, paramcount, params, 5, IICCI, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_INTEGER); - break; - - case 'P': case 'p': /* 22.3.8.3 FORMAT-PLURAL */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (colon_p) - { - /* Go back by 1 argument. */ - if (position > 0) - position--; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_OBJECT); - break; - - case 'F': case 'f': /* 22.3.3.1 FORMAT-FIXED-FLOAT */ - if (!check_params (&list, paramcount, params, 5, IIICC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_REAL); - break; - - case 'E': case 'e': /* 22.3.3.2 FORMAT-EXPONENTIAL-FLOAT */ - case 'G': case 'g': /* 22.3.3.3 FORMAT-GENERAL-FLOAT */ - if (!check_params (&list, paramcount, params, 7, IIIICCC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_REAL); - break; - - case '$': /* 22.3.3.4 FORMAT-DOLLARS-FLOAT */ - if (!check_params (&list, paramcount, params, 4, IIIC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_REAL); - break; - - case 'I': case 'i': /* FORMAT-FIXED-FLOAT-COMPLEX */ - if (!check_params (&list, paramcount, params, 5, IIICC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_COMPLEX); - break; - - case 'Y': case 'y': /* FORMAT-PRETTY */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_OBJECT); - break; - - case '%': /* 22.3.1.2 FORMAT-TERPRI */ - case '&': /* 22.3.1.3 FORMAT-FRESH-LINE */ - case '_': /* FORMAT-SPACE */ - case '/': /* FORMAT-TAB */ - case '|': /* 22.3.1.4 FORMAT-PAGE */ - case '~': /* 22.3.1.5 FORMAT-TILDE */ - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - break; - - case '!': /* FORMAT-FORCE-OUTPUT */ - case '\n': /* 22.3.9.3 #\Newline */ - case 'Q': case 'q': /* FORMAT-IMPLEMENTATION */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - break; - - case 'T': case 't': /* FORMAT-TABULATE */ - if (!check_params (&list, paramcount, params, 3, IIC, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - break; - - case '*': /* 22.3.7.1 FORMAT-GOTO */ - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - { - int n; /* value of first parameter */ - if (paramcount == 0 - || (paramcount >= 1 && params[0].type == PT_NIL)) - n = (atsign_p ? 0 : 1); - else if (paramcount >= 1 && params[0].type == PT_INTEGER) - n = params[0].value; - else - { - /* Unknown argument, leads to an unknown position. */ - position = -1; - break; - } - if (n < 0) - { - /* invalid argument */ - *invalid_reason = - xasprintf (_("In the directive number %u, the argument %d is negative."), spec->directives, n); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (atsign_p) - { - /* Absolute goto. */ - position = n; - } - else if (colon_p) - { - /* Backward goto. */ - if (n > 0) - { - if (position >= 0) - { - if (position >= n) - position -= n; - else - position = 0; - } - else - position = -1; - } - } - else - { - /* Forward goto. */ - if (position >= 0) - position += n; - } - } - break; - - case '?': case 'K': case 'k': /* 22.3.7.6 FORMAT-INDIRECTION */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_FORMATSTRING); - if (atsign_p) - position = -1; - else - if (position >= 0) - { - struct format_arg_list *sublist = make_unconstrained_list (); - add_req_listtype_constraint (&list, position++, - FAT_LIST, sublist); - free_list (sublist); - } - break; - - case '(': /* 22.3.8.1 FORMAT-CASE-CONVERSION */ - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - { - if (!parse_upto (formatp, positionp, listp, escapep, - NULL, spec, ')', false, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - } - format = *formatp; - position = *positionp; - list = *listp; - escape = *escapep; - break; - - case ')': /* 22.3.8.2 FORMAT-CASE-CONVERSION-END */ - if (terminator != ')') - { - *invalid_reason = - xasprintf (_("Found '~%c' without matching '~%c'."), ')', '('); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - return true; - - case '[': /* 22.3.7.2 FORMAT-CONDITIONAL */ - if (atsign_p && colon_p) - { - *invalid_reason = - xasprintf (_("In the directive number %u, both the @ and the : modifiers are given."), spec->directives); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - else if (atsign_p) - { - struct format_arg_list *nil_list; - struct format_arg_list *union_list; - - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - - *formatp = format; - *escapep = escape; - - /* First alternative: argument is NIL. */ - nil_list = (list != NULL ? copy_list (list) : NULL); - if (position >= 0) - { - struct format_arg_list *empty_list = make_empty_list (); - add_req_listtype_constraint (&nil_list, position, - FAT_LIST, empty_list); - free_list (empty_list); - } - - /* Second alternative: use sub-format. */ - { - int sub_position = position; - struct format_arg_list *sub_list = - (list != NULL ? copy_list (list) : NULL); - if (!parse_upto (formatp, &sub_position, &sub_list, escapep, - NULL, spec, ']', false, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - if (sub_list != NULL) - { - if (position >= 0) - { - if (sub_position == position + 1) - /* new position is branch independent */ - position = position + 1; - else - /* new position is branch dependent */ - position = -1; - } - } - else - { - if (position >= 0) - position = position + 1; - } - union_list = union (nil_list, sub_list); - } - - format = *formatp; - escape = *escapep; - - if (list != NULL) - free_list (list); - list = union_list; - } - else if (colon_p) - { - int union_position; - struct format_arg_list *union_list; - - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_OBJECT); - - *formatp = format; - *escapep = escape; - union_position = -2; - union_list = NULL; - - /* First alternative. */ - { - int sub_position = position; - struct format_arg_list *sub_list = - (list != NULL ? copy_list (list) : NULL); - int sub_separator = 0; - if (position >= 0) - { - struct format_arg_list *empty_list = make_empty_list (); - add_req_listtype_constraint (&sub_list, position - 1, - FAT_LIST, empty_list); - free_list (empty_list); - } - if (!parse_upto (formatp, &sub_position, &sub_list, escapep, - &sub_separator, spec, ']', true, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - if (!sub_separator) - { - *invalid_reason = - xasprintf (_("In the directive number %u, '~:[' is not followed by two clauses, separated by '~;'."), spec->directives); - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - if (sub_list != NULL) - union_position = sub_position; - union_list = union (union_list, sub_list); - } - - /* Second alternative. */ - { - int sub_position = position; - struct format_arg_list *sub_list = - (list != NULL ? copy_list (list) : NULL); - if (!parse_upto (formatp, &sub_position, &sub_list, escapep, - NULL, spec, ']', false, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - if (sub_list != NULL) - { - if (union_position == -2) - union_position = sub_position; - else if (sub_position < 0 - || sub_position != union_position) - union_position = -1; - } - union_list = union (union_list, sub_list); - } - - format = *formatp; - escape = *escapep; - - if (union_position != -2) - position = union_position; - if (list != NULL) - free_list (list); - list = union_list; - } - else - { - int arg_position; - int union_position; - struct format_arg_list *union_list; - bool last_alternative; - - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - - /* If there was no first parameter, an argument is consumed. */ - arg_position = -1; - if (!(paramcount >= 1 && params[0].type != PT_NIL)) - if (position >= 0) - { - arg_position = position; - add_req_type_constraint (&list, position++, FAT_OBJECT); - } - - *formatp = format; - *escapep = escape; - - union_position = -2; - union_list = NULL; - last_alternative = false; - for (;;) - { - /* Next alternative. */ - int sub_position = position; - struct format_arg_list *sub_list = - (list != NULL ? copy_list (list) : NULL); - int sub_separator = 0; - if (!parse_upto (formatp, &sub_position, &sub_list, escapep, - &sub_separator, spec, ']', !last_alternative, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - /* If this alternative is chosen, the argument arg_position - is an integer, namely the index of this alternative. */ - if (!last_alternative && arg_position >= 0) - add_req_type_constraint (&sub_list, arg_position, - FAT_INTEGER); - if (sub_list != NULL) - { - if (union_position == -2) - union_position = sub_position; - else if (sub_position < 0 - || sub_position != union_position) - union_position = -1; - } - union_list = union (union_list, sub_list); - if (sub_separator == 2) - last_alternative = true; - if (!sub_separator) - break; - } - if (!last_alternative) - { - /* An implicit default alternative. */ - if (union_position == -2) - union_position = position; - else if (position < 0 || position != union_position) - union_position = -1; - if (list != NULL) - union_list = union (union_list, copy_list (list)); - } - - format = *formatp; - escape = *escapep; - - if (union_position != -2) - position = union_position; - if (list != NULL) - free_list (list); - list = union_list; - } - break; - - case ']': /* 22.3.7.3 FORMAT-CONDITIONAL-END */ - if (terminator != ']') - { - *invalid_reason = - xasprintf (_("Found '~%c' without matching '~%c'."), ']', '['); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - return true; - - case '{': /* 22.3.7.4 FORMAT-ITERATION */ - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - { - int sub_position = 0; - struct format_arg_list *sub_list = make_unconstrained_list (); - struct format_arg_list *sub_escape = NULL; - struct spec sub_spec; - sub_spec.directives = 0; - sub_spec.list = sub_list; - if (!parse_upto (formatp, &sub_position, &sub_list, &sub_escape, - NULL, &sub_spec, '}', false, - NULL, invalid_reason)) - { - FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, - FMTDIR_ERROR); - return false; - } - spec->directives += sub_spec.directives; - - /* If the sub-formatstring is empty, except for the terminating - ~} directive, a formatstring argument is consumed. */ - if (*format == '~' && sub_spec.directives == 1) - if (position >= 0) - add_req_type_constraint (&list, position++, FAT_FORMATSTRING); - - if (colon_p) - { - /* Each iteration uses a new sublist. */ - struct format_arg_list *listlist; - - /* ~{ catches ~^. */ - sub_list = union (sub_list, sub_escape); - - listlist = make_repeated_list_of_lists (sub_list); - - sub_list = listlist; - } - else - { - /* Each iteration's arguments are all concatenated in a - single list. */ - struct format_arg_list *looplist; - - /* FIXME: This is far from correct. Test cases: - abc~{~^~} - abc~{~S~^~S~} - abc~{~D~^~C~} - abc~{~D~^~D~} - abc~{~D~^~S~} - abc~{~D~^~C~}~:*~{~S~^~D~} - */ - - /* ~{ catches ~^. */ - sub_list = union (sub_list, sub_escape); - - if (sub_list == NULL) - looplist = make_empty_list (); - else - if (sub_position < 0 || sub_position == 0) - /* Too hard to track the possible argument types - when the iteration is performed 2 times or more. - So be satisfied with the constraints of executing - the iteration 1 or 0 times. */ - looplist = make_union_with_empty_list (sub_list); - else - looplist = make_repeated_list (sub_list, sub_position); - - sub_list = looplist; - } - - if (atsign_p) - { - /* All remaining arguments are used. */ - if (list != NULL && position >= 0) - { - shift_list (sub_list, position); - list = make_intersected_list (list, sub_list); - } - position = -1; - } - else - { - /* The argument is a list. */ - if (position >= 0) - add_req_listtype_constraint (&list, position++, - FAT_LIST, sub_list); - } - } - format = *formatp; - break; - - case '}': /* 22.3.7.5 FORMAT-ITERATION-END */ - if (terminator != '}') - { - *invalid_reason = - xasprintf (_("Found '~%c' without matching '~%c'."), '}', '{'); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - return true; - - case '^': /* 22.3.9.2 FORMAT-UP-AND-OUT */ - if (!check_params (&list, paramcount, params, 3, THREE, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (position >= 0 && list != NULL && is_required (list, position)) - /* This ~^ can never be executed. Ignore it. */ - break; - if (list != NULL) - { - struct format_arg_list *this_escape = copy_list (list); - if (position >= 0) - this_escape = add_end_constraint (this_escape, position); - escape = union (escape, this_escape); - } - if (position >= 0) - list = add_required_constraint (list, position); - break; - - case ';': /* 22.3.9.1 FORMAT-SEPARATOR */ - if (!separator) - { - *invalid_reason = - xasprintf (_("In the directive number %u, '~;' is used in an invalid position."), spec->directives); - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - if (terminator == '>') - { - if (!check_params (&list, paramcount, params, 1, I, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - } - else - { - if (!check_params (&list, paramcount, params, 0, NULL, - spec->directives, invalid_reason)) - { - FDI_SET (format - 1, FMTDIR_ERROR); - return false; - } - } - *formatp = format; - *positionp = position; - *listp = list; - *escapep = escape; - *separatorp = (colon_p ? 2 : 1); - return true; - - default: - --format; - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec->directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - return false; - } - - FDI_SET (format - 1, FMTDIR_END); - - free (params); + bool colon_p = false; + bool atsign_p = false; + unsigned int paramcount = 0; + struct param *params = NULL; + + FDI_SET (format - 1, FMTDIR_START); + + /* Count number of directives. */ + spec->directives++; + + /* Parse parameters. */ + for (;;) + { + enum param_type type = PT_NIL; + int value = 0; + + if (c_isdigit (*format)) + { + type = PT_INTEGER; + do + { + value = 10 * value + (*format - '0'); + format++; + } + while (c_isdigit (*format)); + } + else if (*format == '+' || *format == '-') + { + bool negative = (*format == '-'); + type = PT_INTEGER; + format++; + if (!c_isdigit (*format)) + { + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + xasprintf (_("In the directive number %u, '%c' is not followed by a digit."), spec->directives, format[-1]); + FDI_SET (format, FMTDIR_ERROR); + } + return false; + } + do + { + value = 10 * value + (*format - '0'); + format++; + } + while (c_isdigit (*format)); + if (negative) + value = -value; + } + else if (*format == '\'') + { + type = PT_CHARACTER; + format++; + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + format++; + } + else if (*format == 'V' || *format == 'v') + { + type = PT_V; + format++; + value = position; + /* Consumes an argument. */ + if (position >= 0) + position++; + } + else if (*format == '#') + { + type = PT_ARGCOUNT; + format++; + } + + params = + (struct param *) + xrealloc (params, (paramcount + 1) * sizeof (struct param)); + params[paramcount].type = type; + params[paramcount].value = value; + paramcount++; + + if (*format == ',') + format++; + else + break; + } + + /* Parse modifiers. */ + for (;;) + { + if (*format == ':') + { + format++; + colon_p = true; + } + else if (*format == '@') + { + format++; + atsign_p = true; + } + else + break; + } + + /* Parse directive. */ + switch (*format++) + { + case 'A': case 'a': /* 22.3.4.1 FORMAT-ASCII */ + case 'S': case 's': /* 22.3.4.2 FORMAT-S-EXPRESSION */ + if (!check_params (&list, paramcount, params, 4, IIIC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_OBJECT); + break; + + case 'C': case 'c': /* FORMAT-CHARACTER */ + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (paramcount == 0 + || (paramcount == 1 && params[0].type == PT_NIL)) + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_CHARACTER); + break; + + case 'D': case 'd': /* 22.3.2.2 FORMAT-DECIMAL */ + case 'B': case 'b': /* 22.3.2.3 FORMAT-BINARY */ + case 'O': case 'o': /* 22.3.2.4 FORMAT-OCTAL */ + case 'X': case 'x': /* 22.3.2.5 FORMAT-HEXADECIMAL */ + if (!check_params (&list, paramcount, params, 4, ICCI, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_INTEGER); + break; + + case 'R': case 'r': /* 22.3.2.1 FORMAT-RADIX */ + if (!check_params (&list, paramcount, params, 5, IICCI, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_INTEGER); + break; + + case 'P': case 'p': /* 22.3.8.3 FORMAT-PLURAL */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (colon_p) + { + /* Go back by 1 argument. */ + if (position > 0) + position--; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_OBJECT); + break; + + case 'F': case 'f': /* 22.3.3.1 FORMAT-FIXED-FLOAT */ + if (!check_params (&list, paramcount, params, 5, IIICC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_REAL); + break; + + case 'E': case 'e': /* 22.3.3.2 FORMAT-EXPONENTIAL-FLOAT */ + case 'G': case 'g': /* 22.3.3.3 FORMAT-GENERAL-FLOAT */ + if (!check_params (&list, paramcount, params, 7, IIIICCC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_REAL); + break; + + case '$': /* 22.3.3.4 FORMAT-DOLLARS-FLOAT */ + if (!check_params (&list, paramcount, params, 4, IIIC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_REAL); + break; + + case 'I': case 'i': /* FORMAT-FIXED-FLOAT-COMPLEX */ + if (!check_params (&list, paramcount, params, 5, IIICC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_COMPLEX); + break; + + case 'Y': case 'y': /* FORMAT-PRETTY */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_OBJECT); + break; + + case '%': /* 22.3.1.2 FORMAT-TERPRI */ + case '&': /* 22.3.1.3 FORMAT-FRESH-LINE */ + case '_': /* FORMAT-SPACE */ + case '/': /* FORMAT-TAB */ + case '|': /* 22.3.1.4 FORMAT-PAGE */ + case '~': /* 22.3.1.5 FORMAT-TILDE */ + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + break; + + case '!': /* FORMAT-FORCE-OUTPUT */ + case '\n': /* 22.3.9.3 #\Newline */ + case 'Q': case 'q': /* FORMAT-IMPLEMENTATION */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + break; + + case 'T': case 't': /* FORMAT-TABULATE */ + if (!check_params (&list, paramcount, params, 3, IIC, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + break; + + case '*': /* 22.3.7.1 FORMAT-GOTO */ + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + { + int n; /* value of first parameter */ + if (paramcount == 0 + || (paramcount >= 1 && params[0].type == PT_NIL)) + n = (atsign_p ? 0 : 1); + else if (paramcount >= 1 && params[0].type == PT_INTEGER) + n = params[0].value; + else + { + /* Unknown argument, leads to an unknown position. */ + position = -1; + break; + } + if (n < 0) + { + /* invalid argument */ + *invalid_reason = + xasprintf (_("In the directive number %u, the argument %d is negative."), spec->directives, n); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (atsign_p) + { + /* Absolute goto. */ + position = n; + } + else if (colon_p) + { + /* Backward goto. */ + if (n > 0) + { + if (position >= 0) + { + if (position >= n) + position -= n; + else + position = 0; + } + else + position = -1; + } + } + else + { + /* Forward goto. */ + if (position >= 0) + position += n; + } + } + break; + + case '?': case 'K': case 'k': /* 22.3.7.6 FORMAT-INDIRECTION */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_FORMATSTRING); + if (atsign_p) + position = -1; + else + if (position >= 0) + { + struct format_arg_list *sublist = make_unconstrained_list (); + add_req_listtype_constraint (&list, position++, + FAT_LIST, sublist); + free_list (sublist); + } + break; + + case '(': /* 22.3.8.1 FORMAT-CASE-CONVERSION */ + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + { + if (!parse_upto (formatp, positionp, listp, escapep, + NULL, spec, ')', false, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + } + format = *formatp; + position = *positionp; + list = *listp; + escape = *escapep; + break; + + case ')': /* 22.3.8.2 FORMAT-CASE-CONVERSION-END */ + if (terminator != ')') + { + *invalid_reason = + xasprintf (_("Found '~%c' without matching '~%c'."), ')', '('); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + return true; + + case '[': /* 22.3.7.2 FORMAT-CONDITIONAL */ + if (atsign_p && colon_p) + { + *invalid_reason = + xasprintf (_("In the directive number %u, both the @ and the : modifiers are given."), spec->directives); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + else if (atsign_p) + { + struct format_arg_list *nil_list; + struct format_arg_list *union_list; + + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + + *formatp = format; + *escapep = escape; + + /* First alternative: argument is NIL. */ + nil_list = (list != NULL ? copy_list (list) : NULL); + if (position >= 0) + { + struct format_arg_list *empty_list = make_empty_list (); + add_req_listtype_constraint (&nil_list, position, + FAT_LIST, empty_list); + free_list (empty_list); + } + + /* Second alternative: use sub-format. */ + { + int sub_position = position; + struct format_arg_list *sub_list = + (list != NULL ? copy_list (list) : NULL); + if (!parse_upto (formatp, &sub_position, &sub_list, escapep, + NULL, spec, ']', false, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + if (sub_list != NULL) + { + if (position >= 0) + { + if (sub_position == position + 1) + /* new position is branch independent */ + position = position + 1; + else + /* new position is branch dependent */ + position = -1; + } + } + else + { + if (position >= 0) + position = position + 1; + } + union_list = union (nil_list, sub_list); + } + + format = *formatp; + escape = *escapep; + + if (list != NULL) + free_list (list); + list = union_list; + } + else if (colon_p) + { + int union_position; + struct format_arg_list *union_list; + + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_OBJECT); + + *formatp = format; + *escapep = escape; + union_position = -2; + union_list = NULL; + + /* First alternative. */ + { + int sub_position = position; + struct format_arg_list *sub_list = + (list != NULL ? copy_list (list) : NULL); + int sub_separator = 0; + if (position >= 0) + { + struct format_arg_list *empty_list = make_empty_list (); + add_req_listtype_constraint (&sub_list, position - 1, + FAT_LIST, empty_list); + free_list (empty_list); + } + if (!parse_upto (formatp, &sub_position, &sub_list, escapep, + &sub_separator, spec, ']', true, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + if (!sub_separator) + { + *invalid_reason = + xasprintf (_("In the directive number %u, '~:[' is not followed by two clauses, separated by '~;'."), spec->directives); + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + if (sub_list != NULL) + union_position = sub_position; + union_list = union (union_list, sub_list); + } + + /* Second alternative. */ + { + int sub_position = position; + struct format_arg_list *sub_list = + (list != NULL ? copy_list (list) : NULL); + if (!parse_upto (formatp, &sub_position, &sub_list, escapep, + NULL, spec, ']', false, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + if (sub_list != NULL) + { + if (union_position == -2) + union_position = sub_position; + else if (sub_position < 0 + || sub_position != union_position) + union_position = -1; + } + union_list = union (union_list, sub_list); + } + + format = *formatp; + escape = *escapep; + + if (union_position != -2) + position = union_position; + if (list != NULL) + free_list (list); + list = union_list; + } + else + { + int arg_position; + int union_position; + struct format_arg_list *union_list; + bool last_alternative; + + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + + /* If there was no first parameter, an argument is consumed. */ + arg_position = -1; + if (!(paramcount >= 1 && params[0].type != PT_NIL)) + if (position >= 0) + { + arg_position = position; + add_req_type_constraint (&list, position++, FAT_OBJECT); + } + + *formatp = format; + *escapep = escape; + + union_position = -2; + union_list = NULL; + last_alternative = false; + for (;;) + { + /* Next alternative. */ + int sub_position = position; + struct format_arg_list *sub_list = + (list != NULL ? copy_list (list) : NULL); + int sub_separator = 0; + if (!parse_upto (formatp, &sub_position, &sub_list, escapep, + &sub_separator, spec, ']', !last_alternative, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + /* If this alternative is chosen, the argument arg_position + is an integer, namely the index of this alternative. */ + if (!last_alternative && arg_position >= 0) + add_req_type_constraint (&sub_list, arg_position, + FAT_INTEGER); + if (sub_list != NULL) + { + if (union_position == -2) + union_position = sub_position; + else if (sub_position < 0 + || sub_position != union_position) + union_position = -1; + } + union_list = union (union_list, sub_list); + if (sub_separator == 2) + last_alternative = true; + if (!sub_separator) + break; + } + if (!last_alternative) + { + /* An implicit default alternative. */ + if (union_position == -2) + union_position = position; + else if (position < 0 || position != union_position) + union_position = -1; + if (list != NULL) + union_list = union (union_list, copy_list (list)); + } + + format = *formatp; + escape = *escapep; + + if (union_position != -2) + position = union_position; + if (list != NULL) + free_list (list); + list = union_list; + } + break; + + case ']': /* 22.3.7.3 FORMAT-CONDITIONAL-END */ + if (terminator != ']') + { + *invalid_reason = + xasprintf (_("Found '~%c' without matching '~%c'."), ']', '['); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + return true; + + case '{': /* 22.3.7.4 FORMAT-ITERATION */ + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + { + int sub_position = 0; + struct format_arg_list *sub_list = make_unconstrained_list (); + struct format_arg_list *sub_escape = NULL; + struct spec sub_spec; + sub_spec.directives = 0; + sub_spec.list = sub_list; + if (!parse_upto (formatp, &sub_position, &sub_list, &sub_escape, + NULL, &sub_spec, '}', false, + NULL, invalid_reason)) + { + FDI_SET (**formatp == '\0' ? *formatp - 1 : *formatp, + FMTDIR_ERROR); + return false; + } + spec->directives += sub_spec.directives; + + /* If the sub-formatstring is empty, except for the terminating + ~} directive, a formatstring argument is consumed. */ + if (*format == '~' && sub_spec.directives == 1) + if (position >= 0) + add_req_type_constraint (&list, position++, FAT_FORMATSTRING); + + if (colon_p) + { + /* Each iteration uses a new sublist. */ + struct format_arg_list *listlist; + + /* ~{ catches ~^. */ + sub_list = union (sub_list, sub_escape); + + listlist = make_repeated_list_of_lists (sub_list); + + sub_list = listlist; + } + else + { + /* Each iteration's arguments are all concatenated in a + single list. */ + struct format_arg_list *looplist; + + /* FIXME: This is far from correct. Test cases: + abc~{~^~} + abc~{~S~^~S~} + abc~{~D~^~C~} + abc~{~D~^~D~} + abc~{~D~^~S~} + abc~{~D~^~C~}~:*~{~S~^~D~} + */ + + /* ~{ catches ~^. */ + sub_list = union (sub_list, sub_escape); + + if (sub_list == NULL) + looplist = make_empty_list (); + else + if (sub_position < 0 || sub_position == 0) + /* Too hard to track the possible argument types + when the iteration is performed 2 times or more. + So be satisfied with the constraints of executing + the iteration 1 or 0 times. */ + looplist = make_union_with_empty_list (sub_list); + else + looplist = make_repeated_list (sub_list, sub_position); + + sub_list = looplist; + } + + if (atsign_p) + { + /* All remaining arguments are used. */ + if (list != NULL && position >= 0) + { + shift_list (sub_list, position); + list = make_intersected_list (list, sub_list); + } + position = -1; + } + else + { + /* The argument is a list. */ + if (position >= 0) + add_req_listtype_constraint (&list, position++, + FAT_LIST, sub_list); + } + } + format = *formatp; + break; + + case '}': /* 22.3.7.5 FORMAT-ITERATION-END */ + if (terminator != '}') + { + *invalid_reason = + xasprintf (_("Found '~%c' without matching '~%c'."), '}', '{'); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + return true; + + case '^': /* 22.3.9.2 FORMAT-UP-AND-OUT */ + if (!check_params (&list, paramcount, params, 3, THREE, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (position >= 0 && list != NULL && is_required (list, position)) + /* This ~^ can never be executed. Ignore it. */ + break; + if (list != NULL) + { + struct format_arg_list *this_escape = copy_list (list); + if (position >= 0) + this_escape = add_end_constraint (this_escape, position); + escape = union (escape, this_escape); + } + if (position >= 0) + list = add_required_constraint (list, position); + break; + + case ';': /* 22.3.9.1 FORMAT-SEPARATOR */ + if (!separator) + { + *invalid_reason = + xasprintf (_("In the directive number %u, '~;' is used in an invalid position."), spec->directives); + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + if (terminator == '>') + { + if (!check_params (&list, paramcount, params, 1, I, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + } + else + { + if (!check_params (&list, paramcount, params, 0, NULL, + spec->directives, invalid_reason)) + { + FDI_SET (format - 1, FMTDIR_ERROR); + return false; + } + } + *formatp = format; + *positionp = position; + *listp = list; + *escapep = escape; + *separatorp = (colon_p ? 2 : 1); + return true; + + default: + --format; + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (spec->directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + return false; + } + + FDI_SET (format - 1, FMTDIR_END); + + free (params); } *formatp = format; @@ -3317,7 +3317,7 @@ parse_upto (const char **formatp, if (terminator != '\0') { *invalid_reason = - xasprintf (_("Found '~%c' without matching '~%c'."), terminator - 1, terminator); + xasprintf (_("Found '~%c' without matching '~%c'."), terminator - 1, terminator); return false; } return true; @@ -3328,7 +3328,7 @@ parse_upto (const char **formatp, static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { struct spec spec; struct spec *result; @@ -3340,8 +3340,8 @@ format_parse (const char *format, bool translated, char *fdi, escape = NULL; if (!parse_upto (&format, &position, &spec.list, &escape, - NULL, &spec, '\0', false, - fdi, invalid_reason)) + NULL, &spec, '\0', false, + fdi, invalid_reason)) /* Invalid format string. */ return NULL; @@ -3352,7 +3352,7 @@ format_parse (const char *format, bool translated, char *fdi, { /* Contradictory argument type information. */ *invalid_reason = - xstrdup (_("The string refers to some argument in incompatible ways.")); + xstrdup (_("The string refers to some argument in incompatible ways.")); return NULL; } @@ -3382,8 +3382,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -3392,28 +3392,28 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, if (equality) { if (!equal_list (spec1->list, spec2->list)) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' are not equivalent"), - pretty_msgid, pretty_msgstr); - err = true; - } + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' are not equivalent"), + pretty_msgid, pretty_msgstr); + err = true; + } } else { struct format_arg_list *intersection = - make_intersected_list (copy_list (spec1->list), - copy_list (spec2->list)); + make_intersected_list (copy_list (spec1->list), + copy_list (spec2->list)); if (!(intersection != NULL - && (normalize_list (intersection), - equal_list (intersection, spec2->list)))) - { - if (error_logger) - error_logger (_("format specifications in '%s' are not a subset of those in '%s'"), - pretty_msgstr, pretty_msgid); - err = true; - } + && (normalize_list (intersection), + equal_list (intersection, spec2->list)))) + { + if (error_logger) + error_logger (_("format specifications in '%s' are not a subset of those in '%s'"), + pretty_msgstr, pretty_msgid); + err = true; + } } return err; @@ -3504,20 +3504,20 @@ print_list (struct format_arg_list *list) for (i = 0; i < list->initial.count; i++) for (j = 0; j < list->initial.element[i].repcount; j++) { - if (i > 0 || j > 0) - printf (" "); - print_element (&list->initial.element[i]); + if (i > 0 || j > 0) + printf (" "); + print_element (&list->initial.element[i]); } if (list->repeated.count > 0) { printf (" |"); for (i = 0; i < list->repeated.count; i++) - for (j = 0; j < list->repeated.element[i].repcount; j++) - { - printf (" "); - print_element (&list->repeated.element[i]); - } + for (j = 0; j < list->repeated.element[i].repcount; j++) + { + printf (" "); + print_element (&list->repeated.element[i]); + } } printf (")"); @@ -3550,9 +3550,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -3560,7 +3560,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-sh.c b/gettext-tools/src/format-sh.c index 5a7494ec4..b796fcd99 100644 --- a/gettext-tools/src/format-sh.c +++ b/gettext-tools/src/format-sh.c @@ -72,7 +72,7 @@ static int named_arg_compare (const void *p1, const void *p2) { return strcmp (((const struct named_arg *) p1)->name, - ((const struct named_arg *) p2)->name); + ((const struct named_arg *) p2)->name); } #define INVALID_NON_ASCII_VARIABLE() \ @@ -86,7 +86,7 @@ named_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -100,113 +100,113 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '$') { - /* A variable substitution. */ - char *name; - - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (*format == '{') - { - const char *name_start; - const char *name_end; - size_t n; - - name_start = ++format; - for (; *format != '\0'; format++) - { - if (*format == '}') - break; - if (!c_isascii (*format)) - { - *invalid_reason = INVALID_NON_ASCII_VARIABLE (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - if (format > name_start - && (*format == '-' || *format == '=' || *format == '+' - || *format == '?' || *format == ':')) - { - *invalid_reason = INVALID_SHELL_SYNTAX (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - if (!(c_isalnum (*format) || *format == '_') - || (format == name_start && c_isdigit (*format))) - { - *invalid_reason = INVALID_CONTEXT_DEPENDENT_VARIABLE (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - } - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - name_end = format++; - - n = name_end - name_start; - if (n == 0) - { - *invalid_reason = INVALID_EMPTY_VARIABLE (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - name = XNMALLOC (n + 1, char); - memcpy (name, name_start, n); - name[n] = '\0'; - } - else if (c_isalpha (*format) || *format == '_') - { - const char *name_start; - const char *name_end; - size_t n; - - name_start = format; - do - format++; - while (*format != '\0' && (c_isalnum (*format) || *format == '_')); - name_end = format; - - n = name_end - name_start; - name = XNMALLOC (n + 1, char); - memcpy (name, name_start, n); - name[n] = '\0'; - } - else if (*format != '\0') - { - if (!c_isascii (*format)) - { - *invalid_reason = INVALID_NON_ASCII_VARIABLE (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - else - { - *invalid_reason = INVALID_CONTEXT_DEPENDENT_VARIABLE (); - FDI_SET (format, FMTDIR_ERROR); - goto bad_format; - } - } - else - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - - /* Named argument. */ - if (spec.allocated == spec.named_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.named = (struct named_arg *) xrealloc (spec.named, spec.allocated * sizeof (struct named_arg)); - } - spec.named[spec.named_arg_count].name = name; - spec.named_arg_count++; - - FDI_SET (format - 1, FMTDIR_END); + /* A variable substitution. */ + char *name; + + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (*format == '{') + { + const char *name_start; + const char *name_end; + size_t n; + + name_start = ++format; + for (; *format != '\0'; format++) + { + if (*format == '}') + break; + if (!c_isascii (*format)) + { + *invalid_reason = INVALID_NON_ASCII_VARIABLE (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + if (format > name_start + && (*format == '-' || *format == '=' || *format == '+' + || *format == '?' || *format == ':')) + { + *invalid_reason = INVALID_SHELL_SYNTAX (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + if (!(c_isalnum (*format) || *format == '_') + || (format == name_start && c_isdigit (*format))) + { + *invalid_reason = INVALID_CONTEXT_DEPENDENT_VARIABLE (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + } + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + name_end = format++; + + n = name_end - name_start; + if (n == 0) + { + *invalid_reason = INVALID_EMPTY_VARIABLE (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + name = XNMALLOC (n + 1, char); + memcpy (name, name_start, n); + name[n] = '\0'; + } + else if (c_isalpha (*format) || *format == '_') + { + const char *name_start; + const char *name_end; + size_t n; + + name_start = format; + do + format++; + while (*format != '\0' && (c_isalnum (*format) || *format == '_')); + name_end = format; + + n = name_end - name_start; + name = XNMALLOC (n + 1, char); + memcpy (name, name_start, n); + name[n] = '\0'; + } + else if (*format != '\0') + { + if (!c_isascii (*format)) + { + *invalid_reason = INVALID_NON_ASCII_VARIABLE (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + else + { + *invalid_reason = INVALID_CONTEXT_DEPENDENT_VARIABLE (); + FDI_SET (format, FMTDIR_ERROR); + goto bad_format; + } + } + else + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + + /* Named argument. */ + if (spec.allocated == spec.named_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.named = (struct named_arg *) xrealloc (spec.named, spec.allocated * sizeof (struct named_arg)); + } + spec.named[spec.named_arg_count].name = name; + spec.named_arg_count++; + + FDI_SET (format - 1, FMTDIR_END); } /* Sort the named argument array, and eliminate duplicates. */ @@ -215,18 +215,18 @@ format_parse (const char *format, bool translated, char *fdi, unsigned int i, j; qsort (spec.named, spec.named_arg_count, sizeof (struct named_arg), - named_arg_compare); + named_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ for (i = j = 0; i < spec.named_arg_count; i++) - if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0) - free (spec.named[i].name); - else - { - if (j < i) - spec.named[j].name = spec.named[i].name; - j++; - } + if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0) + free (spec.named[i].name); + else + { + if (j < i) + spec.named[j].name = spec.named[i].name; + j++; + } spec.named_arg_count = j; } @@ -239,7 +239,7 @@ format_parse (const char *format, bool translated, char *fdi, { unsigned int i; for (i = 0; i < spec.named_arg_count; i++) - free (spec.named[i].name); + free (spec.named[i].name); free (spec.named); } return NULL; @@ -254,7 +254,7 @@ format_free (void *descr) { unsigned int i; for (i = 0; i < spec->named_arg_count; i++) - free (spec->named[i].name); + free (spec->named[i].name); free (spec->named); } free (spec); @@ -270,8 +270,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -284,38 +284,38 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->named_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - strcmp (spec1->named[i].name, spec2->named[j].name)); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument '%s', as in '%s', doesn't exist in '%s'"), - spec2->named[j].name, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument '%s' doesn't exist in '%s'"), - spec1->named[i].name, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + strcmp (spec1->named[i].name, spec2->named[j].name)); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument '%s', as in '%s', doesn't exist in '%s'"), + spec2->named[j].name, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument '%s' doesn't exist in '%s'"), + spec1->named[i].name, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } } return err; @@ -355,7 +355,7 @@ format_print (void *descr) for (i = 0; i < spec->named_arg_count; i++) { if (i > 0) - printf (", "); + printf (", "); printf ("'%s'", spec->named[i].name); } printf ("}"); @@ -374,9 +374,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -384,7 +384,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-tcl.c b/gettext-tools/src/format-tcl.c index 6549cdf08..e338c6dd1 100644 --- a/gettext-tools/src/format-tcl.c +++ b/gettext-tools/src/format-tcl.c @@ -98,7 +98,7 @@ numbered_arg_compare (const void *p1, const void *p2) static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -118,170 +118,170 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (*format != '%') - { - bool is_numbered_arg; - bool short_flag; - enum format_arg_type type; - - is_numbered_arg = false; - if (isdigit (*format)) - { - const char *f = format; - unsigned int m = 0; - - do - { - m = 10 * m + (*f - '0'); - f++; - } - while (isdigit (*f)); - - if (*f == '$') - { - if (m == 0) - { - *invalid_reason = INVALID_ARGNO_0 (spec.directives); - FDI_SET (f, FMTDIR_ERROR); - goto bad_format; - } - number = m; - format = ++f; - - /* Numbered and unnumbered specifications are exclusive. */ - if (seen_unnumbered_arg) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - is_numbered_arg = true; - seen_numbered_arg = true; - } - } - - /* Numbered and unnumbered specifications are exclusive. */ - if (!is_numbered_arg) - { - if (seen_numbered_arg) - { - *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); - FDI_SET (format - 1, FMTDIR_ERROR); - goto bad_format; - } - seen_unnumbered_arg = true; - } - - /* Parse flags. */ - while (*format == ' ' || *format == '+' || *format == '-' - || *format == '#' || *format == '0') - format++; - - /* Parse width. */ - if (*format == '*') - { - format++; - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; - spec.numbered_arg_count++; - - number++; - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - - /* Parse precision. */ - if (*format == '.') - { - format++; - - if (*format == '*') - { - format++; - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; - spec.numbered_arg_count++; - - number++; - } - else if (isdigit (*format)) - { - do format++; while (isdigit (*format)); - } - } - - /* Parse optional size specification. */ - short_flag = false; - if (*format == 'h') - short_flag = true, format++; - else if (*format == 'l') - format++; - - switch (*format) - { - case 'c': - type = FAT_CHARACTER; - break; - case 's': - type = FAT_STRING; - break; - case 'i': case 'd': - type = (short_flag ? FAT_SHORT_INTEGER : FAT_INTEGER); - break; - case 'u': case 'o': case 'x': case 'X': - type = (short_flag ? FAT_SHORT_UNSIGNED_INTEGER : FAT_UNSIGNED_INTEGER); - break; - case 'e': case 'E': case 'f': case 'g': case 'G': - type = FAT_FLOAT; - break; - default: - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - INVALID_CONVERSION_SPECIFIER (spec.directives, *format); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - if (spec.allocated == spec.numbered_arg_count) - { - spec.allocated = 2 * spec.allocated + 1; - spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); - } - spec.numbered[spec.numbered_arg_count].number = number; - spec.numbered[spec.numbered_arg_count].type = type; - spec.numbered_arg_count++; - - number++; - } - - FDI_SET (format, FMTDIR_END); - - format++; + /* A directive. */ + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (*format != '%') + { + bool is_numbered_arg; + bool short_flag; + enum format_arg_type type; + + is_numbered_arg = false; + if (isdigit (*format)) + { + const char *f = format; + unsigned int m = 0; + + do + { + m = 10 * m + (*f - '0'); + f++; + } + while (isdigit (*f)); + + if (*f == '$') + { + if (m == 0) + { + *invalid_reason = INVALID_ARGNO_0 (spec.directives); + FDI_SET (f, FMTDIR_ERROR); + goto bad_format; + } + number = m; + format = ++f; + + /* Numbered and unnumbered specifications are exclusive. */ + if (seen_unnumbered_arg) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + is_numbered_arg = true; + seen_numbered_arg = true; + } + } + + /* Numbered and unnumbered specifications are exclusive. */ + if (!is_numbered_arg) + { + if (seen_numbered_arg) + { + *invalid_reason = INVALID_MIXES_NUMBERED_UNNUMBERED (); + FDI_SET (format - 1, FMTDIR_ERROR); + goto bad_format; + } + seen_unnumbered_arg = true; + } + + /* Parse flags. */ + while (*format == ' ' || *format == '+' || *format == '-' + || *format == '#' || *format == '0') + format++; + + /* Parse width. */ + if (*format == '*') + { + format++; + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; + spec.numbered_arg_count++; + + number++; + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + + /* Parse precision. */ + if (*format == '.') + { + format++; + + if (*format == '*') + { + format++; + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered[spec.numbered_arg_count].type = FAT_INTEGER; + spec.numbered_arg_count++; + + number++; + } + else if (isdigit (*format)) + { + do format++; while (isdigit (*format)); + } + } + + /* Parse optional size specification. */ + short_flag = false; + if (*format == 'h') + short_flag = true, format++; + else if (*format == 'l') + format++; + + switch (*format) + { + case 'c': + type = FAT_CHARACTER; + break; + case 's': + type = FAT_STRING; + break; + case 'i': case 'd': + type = (short_flag ? FAT_SHORT_INTEGER : FAT_INTEGER); + break; + case 'u': case 'o': case 'x': case 'X': + type = (short_flag ? FAT_SHORT_UNSIGNED_INTEGER : FAT_UNSIGNED_INTEGER); + break; + case 'e': case 'E': case 'f': case 'g': case 'G': + type = FAT_FLOAT; + break; + default: + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + INVALID_CONVERSION_SPECIFIER (spec.directives, *format); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + + if (spec.allocated == spec.numbered_arg_count) + { + spec.allocated = 2 * spec.allocated + 1; + spec.numbered = (struct numbered_arg *) xrealloc (spec.numbered, spec.allocated * sizeof (struct numbered_arg)); + } + spec.numbered[spec.numbered_arg_count].number = number; + spec.numbered[spec.numbered_arg_count].type = type; + spec.numbered_arg_count++; + + number++; + } + + FDI_SET (format, FMTDIR_END); + + format++; } /* Sort the numbered argument array, and eliminate duplicates. */ @@ -291,44 +291,44 @@ format_parse (const char *format, bool translated, char *fdi, bool err; qsort (spec.numbered, spec.numbered_arg_count, - sizeof (struct numbered_arg), numbered_arg_compare); + sizeof (struct numbered_arg), numbered_arg_compare); /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i. */ err = false; for (i = j = 0; i < spec.numbered_arg_count; i++) - if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) - { - enum format_arg_type type1 = spec.numbered[i].type; - enum format_arg_type type2 = spec.numbered[j-1].type; - enum format_arg_type type_both; - - if (type1 == type2) - type_both = type1; - else - { - /* Incompatible types. */ - type_both = FAT_NONE; - if (!err) - *invalid_reason = - INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); - err = true; - } - - spec.numbered[j-1].type = type_both; - } - else - { - if (j < i) - { - spec.numbered[j].number = spec.numbered[i].number; - spec.numbered[j].type = spec.numbered[i].type; - } - j++; - } + if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number) + { + enum format_arg_type type1 = spec.numbered[i].type; + enum format_arg_type type2 = spec.numbered[j-1].type; + enum format_arg_type type_both; + + if (type1 == type2) + type_both = type1; + else + { + /* Incompatible types. */ + type_both = FAT_NONE; + if (!err) + *invalid_reason = + INVALID_INCOMPATIBLE_ARG_TYPES (spec.numbered[i].number); + err = true; + } + + spec.numbered[j-1].type = type_both; + } + else + { + if (j < i) + { + spec.numbered[j].number = spec.numbered[i].number; + spec.numbered[j].type = spec.numbered[i].type; + } + j++; + } spec.numbered_arg_count = j; if (err) - /* *invalid_reason has already been set above. */ - goto bad_format; + /* *invalid_reason has already been set above. */ + goto bad_format; } result = XMALLOC (struct spec); @@ -361,8 +361,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -375,60 +375,60 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n2 = spec2->numbered_arg_count; /* Check the argument names are the same. - Both arrays are sorted. We search for the first difference. */ + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) - { - int cmp = (i >= n1 ? 1 : - j >= n2 ? -1 : - spec1->numbered[i].number > spec2->numbered[j].number ? 1 : - spec1->numbered[i].number < spec2->numbered[j].number ? -1 : - 0); - - if (cmp > 0) - { - if (error_logger) - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - spec2->numbered[j].number, pretty_msgstr, - pretty_msgid); - err = true; - break; - } - else if (cmp < 0) - { - if (equality) - { - if (error_logger) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - spec1->numbered[i].number, pretty_msgstr); - err = true; - break; - } - else - i++; - } - else - j++, i++; - } + { + int cmp = (i >= n1 ? 1 : + j >= n2 ? -1 : + spec1->numbered[i].number > spec2->numbered[j].number ? 1 : + spec1->numbered[i].number < spec2->numbered[j].number ? -1 : + 0); + + if (cmp > 0) + { + if (error_logger) + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + spec2->numbered[j].number, pretty_msgstr, + pretty_msgid); + err = true; + break; + } + else if (cmp < 0) + { + if (equality) + { + if (error_logger) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + spec1->numbered[i].number, pretty_msgstr); + err = true; + break; + } + else + i++; + } + else + j++, i++; + } /* Check the argument types are the same. */ if (!err) - for (i = 0, j = 0; j < n2; ) - { - if (spec1->numbered[i].number == spec2->numbered[j].number) - { - if (spec1->numbered[i].type != spec2->numbered[j].type) - { - if (error_logger) - error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), - pretty_msgid, pretty_msgstr, - spec2->numbered[j].number); - err = true; - break; - } - j++, i++; - } - else - i++; - } + for (i = 0, j = 0; j < n2; ) + { + if (spec1->numbered[i].number == spec2->numbered[j].number) + { + if (spec1->numbered[i].type != spec2->numbered[j].type) + { + if (error_logger) + error_logger (_("format specifications in '%s' and '%s' for argument %u are not the same"), + pretty_msgid, pretty_msgstr, + spec2->numbered[j].number); + err = true; + break; + } + j++, i++; + } + else + i++; + } } return err; @@ -472,37 +472,37 @@ format_print (void *descr) unsigned int number = spec->numbered[i].number; if (i > 0) - printf (" "); + printf (" "); if (number < last) - abort (); + abort (); for (; last < number; last++) - printf ("_ "); + printf ("_ "); switch (spec->numbered[i].type) - { - case FAT_CHARACTER: - printf ("c"); - break; - case FAT_STRING: - printf ("s"); - break; - case FAT_INTEGER: - printf ("i"); - break; - case FAT_UNSIGNED_INTEGER: - printf ("[unsigned]i"); - break; - case FAT_SHORT_INTEGER: - printf ("hi"); - break; - case FAT_SHORT_UNSIGNED_INTEGER: - printf ("[unsigned]hi"); - break; - case FAT_FLOAT: - printf ("f"); - break; - default: - abort (); - } + { + case FAT_CHARACTER: + printf ("c"); + break; + case FAT_STRING: + printf ("s"); + break; + case FAT_INTEGER: + printf ("i"); + break; + case FAT_UNSIGNED_INTEGER: + printf ("[unsigned]i"); + break; + case FAT_SHORT_INTEGER: + printf ("hi"); + break; + case FAT_SHORT_UNSIGNED_INTEGER: + printf ("[unsigned]hi"); + break; + case FAT_FLOAT: + printf ("f"); + break; + default: + abort (); + } last = number + 1; } printf (")"); @@ -521,9 +521,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -531,7 +531,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format-ycp.c b/gettext-tools/src/format-ycp.c index 193f216ff..762a5d72d 100644 --- a/gettext-tools/src/format-ycp.c +++ b/gettext-tools/src/format-ycp.c @@ -48,7 +48,7 @@ struct spec static void * format_parse (const char *format, bool translated, char *fdi, - char **invalid_reason) + char **invalid_reason) { const char *const format_start = format; struct spec spec; @@ -60,41 +60,41 @@ format_parse (const char *format, bool translated, char *fdi, for (; *format != '\0';) if (*format++ == '%') { - /* A directive. */ - FDI_SET (format - 1, FMTDIR_START); - spec.directives++; - - if (*format == '%') - format++; - else if (*format >= '1' && *format <= '9') - { - unsigned int number = *format - '1'; - - while (spec.arg_count <= number) - spec.args_used[spec.arg_count++] = false; - spec.args_used[number] = true; - - format++; - } - else - { - if (*format == '\0') - { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format - 1, FMTDIR_ERROR); - } - else - { - *invalid_reason = - (c_isprint (*format) - ? xasprintf (_("In the directive number %u, the character '%c' is not a digit between 1 and 9."), spec.directives, *format) - : xasprintf (_("The character that terminates the directive number %u is not a digit between 1 and 9."), spec.directives)); - FDI_SET (format, FMTDIR_ERROR); - } - goto bad_format; - } - - FDI_SET (format - 1, FMTDIR_END); + /* A directive. */ + FDI_SET (format - 1, FMTDIR_START); + spec.directives++; + + if (*format == '%') + format++; + else if (*format >= '1' && *format <= '9') + { + unsigned int number = *format - '1'; + + while (spec.arg_count <= number) + spec.args_used[spec.arg_count++] = false; + spec.args_used[number] = true; + + format++; + } + else + { + if (*format == '\0') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format - 1, FMTDIR_ERROR); + } + else + { + *invalid_reason = + (c_isprint (*format) + ? xasprintf (_("In the directive number %u, the character '%c' is not a digit between 1 and 9."), spec.directives, *format) + : xasprintf (_("The character that terminates the directive number %u is not a digit between 1 and 9."), spec.directives)); + FDI_SET (format, FMTDIR_ERROR); + } + goto bad_format; + } + + FDI_SET (format - 1, FMTDIR_END); } result = XMALLOC (struct spec); @@ -123,8 +123,8 @@ format_get_number_of_directives (void *descr) static bool format_check (void *msgid_descr, void *msgstr_descr, bool equality, - formatstring_error_logger_t error_logger, - const char *pretty_msgid, const char *pretty_msgstr) + formatstring_error_logger_t error_logger, + const char *pretty_msgid, const char *pretty_msgstr) { struct spec *spec1 = (struct spec *) msgid_descr; struct spec *spec2 = (struct spec *) msgstr_descr; @@ -137,19 +137,19 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, bool arg_used2 = (i < spec2->arg_count && spec2->args_used[i]); if (equality ? (arg_used1 != arg_used2) : (!arg_used1 && arg_used2)) - { - if (error_logger) - { - if (arg_used1) - error_logger (_("a format specification for argument %u doesn't exist in '%s'"), - i + 1, pretty_msgstr); - else - error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), - i + 1, pretty_msgstr, pretty_msgid); - } - err = true; - break; - } + { + if (error_logger) + { + if (arg_used1) + error_logger (_("a format specification for argument %u doesn't exist in '%s'"), + i + 1, pretty_msgstr); + else + error_logger (_("a format specification for argument %u, as in '%s', doesn't exist in '%s'"), + i + 1, pretty_msgstr, pretty_msgid); + } + err = true; + break; + } } return err; @@ -199,11 +199,11 @@ format_print (void *descr) for (i = 0; i < spec->arg_count; i++) { if (i > 0) - printf (" "); + printf (" "); if (spec->args_used[i]) - printf ("*"); + printf ("*"); else - printf ("_"); + printf ("_"); } printf (")"); } @@ -221,9 +221,9 @@ main () line_len = getline (&line, &line_size, stdin); if (line_len < 0) - break; + break; if (line_len > 0 && line[line_len - 1] == '\n') - line[--line_len] = '\0'; + line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, NULL, &invalid_reason); @@ -231,7 +231,7 @@ main () format_print (descr); printf ("\n"); if (descr == NULL) - printf ("%s\n", invalid_reason); + printf ("%s\n", invalid_reason); free (invalid_reason); free (line); diff --git a/gettext-tools/src/format.c b/gettext-tools/src/format.c index 846ae6479..e6c5de996 100644 --- a/gettext-tools/src/format.c +++ b/gettext-tools/src/format.c @@ -34,41 +34,41 @@ /* Table of all format string parsers. */ struct formatstring_parser *formatstring_parsers[NFORMATS] = { - /* format_c */ &formatstring_c, - /* format_objc */ &formatstring_objc, - /* format_sh */ &formatstring_sh, - /* format_python */ &formatstring_python, - /* format_lisp */ &formatstring_lisp, - /* format_elisp */ &formatstring_elisp, - /* format_librep */ &formatstring_librep, - /* format_scheme */ &formatstring_scheme, - /* format_smalltalk */ &formatstring_smalltalk, - /* format_java */ &formatstring_java, - /* format_csharp */ &formatstring_csharp, - /* format_awk */ &formatstring_awk, - /* format_pascal */ &formatstring_pascal, - /* format_ycp */ &formatstring_ycp, - /* format_tcl */ &formatstring_tcl, - /* format_perl */ &formatstring_perl, - /* format_perl_brace */ &formatstring_perl_brace, - /* format_php */ &formatstring_php, - /* format_gcc_internal */ &formatstring_gcc_internal, - /* format_gfc_internal */ &formatstring_gfc_internal, - /* format_qt */ &formatstring_qt, - /* format_qt_plural */ &formatstring_qt_plural, - /* format_kde */ &formatstring_kde, - /* format_boost */ &formatstring_boost + /* format_c */ &formatstring_c, + /* format_objc */ &formatstring_objc, + /* format_sh */ &formatstring_sh, + /* format_python */ &formatstring_python, + /* format_lisp */ &formatstring_lisp, + /* format_elisp */ &formatstring_elisp, + /* format_librep */ &formatstring_librep, + /* format_scheme */ &formatstring_scheme, + /* format_smalltalk */ &formatstring_smalltalk, + /* format_java */ &formatstring_java, + /* format_csharp */ &formatstring_csharp, + /* format_awk */ &formatstring_awk, + /* format_pascal */ &formatstring_pascal, + /* format_ycp */ &formatstring_ycp, + /* format_tcl */ &formatstring_tcl, + /* format_perl */ &formatstring_perl, + /* format_perl_brace */ &formatstring_perl_brace, + /* format_php */ &formatstring_php, + /* format_gcc_internal */ &formatstring_gcc_internal, + /* format_gfc_internal */ &formatstring_gfc_internal, + /* format_qt */ &formatstring_qt, + /* format_qt_plural */ &formatstring_qt_plural, + /* format_kde */ &formatstring_kde, + /* format_boost */ &formatstring_boost }; /* Check whether both formats strings contain compatible format specifications for format type i (0 <= i < NFORMATS). */ int check_msgid_msgstr_format_i (const char *msgid, const char *msgid_plural, - const char *msgstr, size_t msgstr_len, - size_t i, - struct argument_range range, - const struct plural_distribution *distribution, - formatstring_error_logger_t error_logger) + const char *msgstr, size_t msgstr_len, + size_t i, + struct argument_range range, + const struct plural_distribution *distribution, + formatstring_error_logger_t error_logger) { int seen_errors = 0; @@ -87,12 +87,12 @@ check_msgid_msgstr_format_i (const char *msgid, const char *msgid_plural, char *invalid_reason = NULL; void *msgid_descr = parser->parse (msgid_plural != NULL ? msgid_plural : msgid, false, NULL, - &invalid_reason); + &invalid_reason); if (msgid_descr != NULL) { const char *pretty_msgid = - (msgid_plural != NULL ? "msgid_plural" : "msgid"); + (msgid_plural != NULL ? "msgid_plural" : "msgid"); char buf[18+1]; const char *pretty_msgstr = "msgstr"; bool has_plural_translations = (strlen (msgstr) + 1 < msgstr_len); @@ -101,58 +101,58 @@ check_msgid_msgstr_format_i (const char *msgid, const char *msgid_plural, unsigned int j; for (p = msgstr, j = 0; p < p_end; p += strlen (p) + 1, j++) - { - void *msgstr_descr; - - if (msgid_plural != NULL) - { - sprintf (buf, "msgstr[%u]", j); - pretty_msgstr = buf; - } - - msgstr_descr = parser->parse (p, true, NULL, &invalid_reason); - - if (msgstr_descr != NULL) - { - /* Use strict checking (require same number of format - directives on both sides) if the message has no plurals, - or if msgid_plural exists but on the msgstr[] side - there is only msgstr[0], or if distribution->often[j] - indicates that the variant applies to infinitely many - values of N and the N range is not restricted in a way - that the variant applies to only one N. - Use relaxed checking when there are at least two - msgstr[] forms and the distribution does not give more - precise information. */ - bool strict_checking = - (msgid_plural == NULL - || !has_plural_translations - || (distribution != NULL - && distribution->often != NULL - && j < distribution->often_length - && distribution->often[j] - && !(has_range_p (range) - && distribution->histogram (distribution, - range.min, range.max, j) - <= 1))); - - if (parser->check (msgid_descr, msgstr_descr, - strict_checking, - error_logger, pretty_msgid, pretty_msgstr)) - seen_errors++; - - parser->free (msgstr_descr); - } - else - { - error_logger (_("\ + { + void *msgstr_descr; + + if (msgid_plural != NULL) + { + sprintf (buf, "msgstr[%u]", j); + pretty_msgstr = buf; + } + + msgstr_descr = parser->parse (p, true, NULL, &invalid_reason); + + if (msgstr_descr != NULL) + { + /* Use strict checking (require same number of format + directives on both sides) if the message has no plurals, + or if msgid_plural exists but on the msgstr[] side + there is only msgstr[0], or if distribution->often[j] + indicates that the variant applies to infinitely many + values of N and the N range is not restricted in a way + that the variant applies to only one N. + Use relaxed checking when there are at least two + msgstr[] forms and the distribution does not give more + precise information. */ + bool strict_checking = + (msgid_plural == NULL + || !has_plural_translations + || (distribution != NULL + && distribution->often != NULL + && j < distribution->often_length + && distribution->often[j] + && !(has_range_p (range) + && distribution->histogram (distribution, + range.min, range.max, j) + <= 1))); + + if (parser->check (msgid_descr, msgstr_descr, + strict_checking, + error_logger, pretty_msgid, pretty_msgstr)) + seen_errors++; + + parser->free (msgstr_descr); + } + else + { + error_logger (_("\ '%s' is not a valid %s format string, unlike '%s'. Reason: %s"), - pretty_msgstr, format_language_pretty[i], - pretty_msgid, invalid_reason); - seen_errors++; - free (invalid_reason); - } - } + pretty_msgstr, format_language_pretty[i], + pretty_msgid, invalid_reason); + seen_errors++; + free (invalid_reason); + } + } parser->free (msgid_descr); } @@ -167,11 +167,11 @@ check_msgid_msgstr_format_i (const char *msgid, const char *msgid_plural, Return the number of errors that were seen. */ int check_msgid_msgstr_format (const char *msgid, const char *msgid_plural, - const char *msgstr, size_t msgstr_len, - const enum is_format is_format[NFORMATS], - struct argument_range range, - const struct plural_distribution *distribution, - formatstring_error_logger_t error_logger) + const char *msgstr, size_t msgstr_len, + const enum is_format is_format[NFORMATS], + struct argument_range range, + const struct plural_distribution *distribution, + formatstring_error_logger_t error_logger) { int seen_errors = 0; size_t i; @@ -185,10 +185,10 @@ check_msgid_msgstr_format (const char *msgid, const char *msgid_plural, for (i = 0; i < NFORMATS; i++) if (possible_format_p (is_format[i])) seen_errors += check_msgid_msgstr_format_i (msgid, msgid_plural, - msgstr, msgstr_len, i, - range, - distribution, - error_logger); + msgstr, msgstr_len, i, + range, + distribution, + error_logger); return seen_errors; } diff --git a/gettext-tools/src/format.h b/gettext-tools/src/format.h index ac6ca2e55..60f0adcfc 100644 --- a/gettext-tools/src/format.h +++ b/gettext-tools/src/format.h @@ -20,10 +20,10 @@ #include -#include "pos.h" /* Get lex_pos_ty. */ -#include "message.h" /* Get NFORMATS. */ +#include "pos.h" /* Get lex_pos_ty. */ +#include "message.h" /* Get NFORMATS. */ #include "plural-distrib.h" /* Get struct plural_distribution. */ -#include "error.h" /* Get fallback definition of __attribute__. */ +#include "error.h" /* Get fallback definition of __attribute__. */ #ifdef __cplusplus @@ -135,7 +135,7 @@ struct interval }; extern void get_sysdep_c_format_directives (const char *string, bool translated, - struct interval **intervalsp, size_t *lengthp); + struct interval **intervalsp, size_t *lengthp); /* Returns the number of unnamed arguments consumed by a Python format string. */ @@ -146,22 +146,22 @@ extern unsigned int get_python_format_unnamed_arg_count (const char *string); Return the number of errors that were seen. */ extern int check_msgid_msgstr_format_i (const char *msgid, const char *msgid_plural, - const char *msgstr, size_t msgstr_len, - size_t i, - struct argument_range range, - const struct plural_distribution *distribution, - formatstring_error_logger_t error_logger); + const char *msgstr, size_t msgstr_len, + size_t i, + struct argument_range range, + const struct plural_distribution *distribution, + formatstring_error_logger_t error_logger); /* Check whether both formats strings contain compatible format specifications. Return the number of errors that were seen. */ extern int check_msgid_msgstr_format (const char *msgid, const char *msgid_plural, - const char *msgstr, size_t msgstr_len, - const enum is_format is_format[NFORMATS], - struct argument_range range, - const struct plural_distribution *distribution, - formatstring_error_logger_t error_logger); + const char *msgstr, size_t msgstr_len, + const enum is_format is_format[NFORMATS], + struct argument_range range, + const struct plural_distribution *distribution, + formatstring_error_logger_t error_logger); #ifdef __cplusplus diff --git a/gettext-tools/src/hostname.c b/gettext-tools/src/hostname.c index 85a5b966c..bbfbd0c6a 100644 --- a/gettext-tools/src/hostname.c +++ b/gettext-tools/src/hostname.c @@ -145,10 +145,10 @@ main (int argc, char *argv[]) /* Parse command line options. */ while ((optchar = getopt_long (argc, argv, "fhisV", long_options, NULL)) - != EOF) + != EOF) switch (optchar) { - case '\0': /* Long option. */ + case '\0': /* Long option. */ break; case 'f': format = long_format; @@ -180,7 +180,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2003, 2006-2007"); + "2001-2003, 2006-2007"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -205,7 +205,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -237,7 +237,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); @@ -289,25 +289,25 @@ xgethostname () # elif HAVE_IN6_S6_ADDR16 # define ipv6_ntop(buffer,addr) \ sprintf (buffer, "%x:%x:%x:%x:%x:%x:%x:%x", \ - ntohs ((addr).s6_addr16[0]), \ - ntohs ((addr).s6_addr16[1]), \ - ntohs ((addr).s6_addr16[2]), \ - ntohs ((addr).s6_addr16[3]), \ - ntohs ((addr).s6_addr16[4]), \ - ntohs ((addr).s6_addr16[5]), \ - ntohs ((addr).s6_addr16[6]), \ - ntohs ((addr).s6_addr16[7])) + ntohs ((addr).s6_addr16[0]), \ + ntohs ((addr).s6_addr16[1]), \ + ntohs ((addr).s6_addr16[2]), \ + ntohs ((addr).s6_addr16[3]), \ + ntohs ((addr).s6_addr16[4]), \ + ntohs ((addr).s6_addr16[5]), \ + ntohs ((addr).s6_addr16[6]), \ + ntohs ((addr).s6_addr16[7])) # else # define ipv6_ntop(buffer,addr) \ sprintf (buffer, "%x:%x:%x:%x:%x:%x:%x:%x", \ - ((addr).s6_addr[0] << 8) | (addr).s6_addr[1], \ - ((addr).s6_addr[2] << 8) | (addr).s6_addr[3], \ - ((addr).s6_addr[4] << 8) | (addr).s6_addr[5], \ - ((addr).s6_addr[6] << 8) | (addr).s6_addr[7], \ - ((addr).s6_addr[8] << 8) | (addr).s6_addr[9], \ - ((addr).s6_addr[10] << 8) | (addr).s6_addr[11], \ - ((addr).s6_addr[12] << 8) | (addr).s6_addr[13], \ - ((addr).s6_addr[14] << 8) | (addr).s6_addr[15]) + ((addr).s6_addr[0] << 8) | (addr).s6_addr[1], \ + ((addr).s6_addr[2] << 8) | (addr).s6_addr[3], \ + ((addr).s6_addr[4] << 8) | (addr).s6_addr[5], \ + ((addr).s6_addr[6] << 8) | (addr).s6_addr[7], \ + ((addr).s6_addr[8] << 8) | (addr).s6_addr[9], \ + ((addr).s6_addr[10] << 8) | (addr).s6_addr[11], \ + ((addr).s6_addr[12] << 8) | (addr).s6_addr[13], \ + ((addr).s6_addr[14] << 8) | (addr).s6_addr[15]) # endif #endif @@ -335,7 +335,7 @@ print_hostname () /* Print only the part before the first dot. */ dot = strchr (hostname, '.'); if (dot != NULL) - *dot = '\0'; + *dot = '\0'; printf ("%s\n", hostname); break; @@ -344,15 +344,15 @@ print_hostname () #if HAVE_GETHOSTBYNAME h = gethostbyname (hostname); if (h != NULL) - { - printf ("%s\n", h->h_name); - if (h->h_aliases != NULL) - for (i = 0; h->h_aliases[i] != NULL; i++) - printf ("%s\n", h->h_aliases[i]); - } + { + printf ("%s\n", h->h_name); + if (h->h_aliases != NULL) + for (i = 0; h->h_aliases[i] != NULL; i++) + printf ("%s\n", h->h_aliases[i]); + } else #endif - printf ("%s\n", hostname); + printf ("%s\n", hostname); break; case ip_format: @@ -360,24 +360,24 @@ print_hostname () #if HAVE_GETHOSTBYNAME h = gethostbyname (hostname); if (h != NULL && h->h_addr_list != NULL) - for (i = 0; h->h_addr_list[i] != NULL; i++) - { + for (i = 0; h->h_addr_list[i] != NULL; i++) + { #if HAVE_IPV6 - if (h->h_addrtype == AF_INET6) - { - char buffer[45+1]; - ipv6_ntop (buffer, *(const struct in6_addr*) h->h_addr_list[i]); - printf("[%s]\n", buffer); - } - else + if (h->h_addrtype == AF_INET6) + { + char buffer[45+1]; + ipv6_ntop (buffer, *(const struct in6_addr*) h->h_addr_list[i]); + printf("[%s]\n", buffer); + } + else #endif - if (h->h_addrtype == AF_INET) - { - char buffer[15+1]; - ipv4_ntop (buffer, *(const struct in_addr*) h->h_addr_list[i]); - printf("[%s]\n", buffer); - } - } + if (h->h_addrtype == AF_INET) + { + char buffer[15+1]; + ipv4_ntop (buffer, *(const struct in_addr*) h->h_addr_list[i]); + printf("[%s]\n", buffer); + } + } #endif break; diff --git a/gettext-tools/src/message.c b/gettext-tools/src/message.c index 77ca08418..5162b06f3 100644 --- a/gettext-tools/src/message.c +++ b/gettext-tools/src/message.c @@ -34,58 +34,58 @@ const char *const format_language[NFORMATS] = { - /* format_c */ "c", - /* format_objc */ "objc", - /* format_sh */ "sh", - /* format_python */ "python", - /* format_lisp */ "lisp", - /* format_elisp */ "elisp", - /* format_librep */ "librep", - /* format_scheme */ "scheme", - /* format_smalltalk */ "smalltalk", - /* format_java */ "java", - /* format_csharp */ "csharp", - /* format_awk */ "awk", - /* format_pascal */ "object-pascal", - /* format_ycp */ "ycp", - /* format_tcl */ "tcl", - /* format_perl */ "perl", - /* format_perl_brace */ "perl-brace", - /* format_php */ "php", - /* format_gcc_internal */ "gcc-internal", - /* format_gfc_internal */ "gfc-internal", - /* format_qt */ "qt", - /* format_qt_plursl */ "qt-plural", - /* format_kde */ "kde", - /* format_boost */ "boost" + /* format_c */ "c", + /* format_objc */ "objc", + /* format_sh */ "sh", + /* format_python */ "python", + /* format_lisp */ "lisp", + /* format_elisp */ "elisp", + /* format_librep */ "librep", + /* format_scheme */ "scheme", + /* format_smalltalk */ "smalltalk", + /* format_java */ "java", + /* format_csharp */ "csharp", + /* format_awk */ "awk", + /* format_pascal */ "object-pascal", + /* format_ycp */ "ycp", + /* format_tcl */ "tcl", + /* format_perl */ "perl", + /* format_perl_brace */ "perl-brace", + /* format_php */ "php", + /* format_gcc_internal */ "gcc-internal", + /* format_gfc_internal */ "gfc-internal", + /* format_qt */ "qt", + /* format_qt_plursl */ "qt-plural", + /* format_kde */ "kde", + /* format_boost */ "boost" }; const char *const format_language_pretty[NFORMATS] = { - /* format_c */ "C", - /* format_objc */ "Objective C", - /* format_sh */ "Shell", - /* format_python */ "Python", - /* format_lisp */ "Lisp", - /* format_elisp */ "Emacs Lisp", - /* format_librep */ "librep", - /* format_scheme */ "Scheme", - /* format_smalltalk */ "Smalltalk", - /* format_java */ "Java", - /* format_csharp */ "C#", - /* format_awk */ "awk", - /* format_pascal */ "Object Pascal", - /* format_ycp */ "YCP", - /* format_tcl */ "Tcl", - /* format_perl */ "Perl", - /* format_perl_brace */ "Perl brace", - /* format_php */ "PHP", - /* format_gcc_internal */ "GCC internal", - /* format_gfc_internal */ "GFC internal", - /* format_qt */ "Qt", - /* format_qt_plural */ "Qt plural", - /* format_kde */ "KDE", - /* format_boost */ "Boost" + /* format_c */ "C", + /* format_objc */ "Objective C", + /* format_sh */ "Shell", + /* format_python */ "Python", + /* format_lisp */ "Lisp", + /* format_elisp */ "Emacs Lisp", + /* format_librep */ "librep", + /* format_scheme */ "Scheme", + /* format_smalltalk */ "Smalltalk", + /* format_java */ "Java", + /* format_csharp */ "C#", + /* format_awk */ "awk", + /* format_pascal */ "Object Pascal", + /* format_ycp */ "YCP", + /* format_tcl */ "Tcl", + /* format_perl */ "Perl", + /* format_perl_brace */ "Perl brace", + /* format_php */ "PHP", + /* format_gcc_internal */ "GCC internal", + /* format_gfc_internal */ "GFC internal", + /* format_qt */ "Qt", + /* format_qt_plural */ "Qt plural", + /* format_kde */ "KDE", + /* format_boost */ "Boost" }; @@ -93,16 +93,16 @@ bool possible_format_p (enum is_format is_format) { return is_format == possible - || is_format == yes_according_to_context - || is_format == yes; + || is_format == yes_according_to_context + || is_format == yes; } message_ty * message_alloc (const char *msgctxt, - const char *msgid, const char *msgid_plural, - const char *msgstr, size_t msgstr_len, - const lex_pos_ty *pp) + const char *msgid, const char *msgid_plural, + const char *msgstr, size_t msgstr_len, + const lex_pos_ty *pp) { message_ty *mp; size_t i; @@ -190,7 +190,7 @@ message_comment_filepos (message_ty *mp, const char *name, size_t line) { pp = &mp->filepos[j]; if (strcmp (pp->file_name, name) == 0 && pp->line_number == line) - return; + return; } /* Extend the list so that we can add a position to it. */ @@ -211,18 +211,18 @@ message_copy (message_ty *mp) size_t j, i; result = message_alloc (mp->msgctxt != NULL ? xstrdup (mp->msgctxt) : NULL, - xstrdup (mp->msgid), mp->msgid_plural, - mp->msgstr, mp->msgstr_len, &mp->pos); + xstrdup (mp->msgid), mp->msgid_plural, + mp->msgstr, mp->msgstr_len, &mp->pos); if (mp->comment) { for (j = 0; j < mp->comment->nitems; ++j) - message_comment_append (result, mp->comment->item[j]); + message_comment_append (result, mp->comment->item[j]); } if (mp->comment_dot) { for (j = 0; j < mp->comment_dot->nitems; ++j) - message_comment_dot_append (result, mp->comment_dot->item[j]); + message_comment_dot_append (result, mp->comment_dot->item[j]); } result->is_fuzzy = mp->is_fuzzy; for (i = 0; i < NFORMATS; i++) @@ -327,7 +327,7 @@ message_list_append (message_list_ty *mlp, message_ty *mp) if (mlp->use_hashtable) if (message_list_hash_insert_entry (&mlp->htable, mp)) /* A message list has duplicates, although it was allocated with the - assertion that it wouldn't have duplicates. It is a bug. */ + assertion that it wouldn't have duplicates. It is a bug. */ abort (); } @@ -353,7 +353,7 @@ message_list_prepend (message_list_ty *mlp, message_ty *mp) if (mlp->use_hashtable) if (message_list_hash_insert_entry (&mlp->htable, mp)) /* A message list has duplicates, although it was allocated with the - assertion that it wouldn't have duplicates. It is a bug. */ + assertion that it wouldn't have duplicates. It is a bug. */ abort (); } @@ -379,7 +379,7 @@ message_list_insert_at (message_list_ty *mlp, size_t n, message_ty *mp) if (mlp->use_hashtable) if (message_list_hash_insert_entry (&mlp->htable, mp)) /* A message list has duplicates, although it was allocated with the - assertion that it wouldn't have duplicates. It is a bug. */ + assertion that it wouldn't have duplicates. It is a bug. */ abort (); } @@ -409,7 +409,7 @@ message_list_delete_nth (message_list_ty *mlp, size_t n) void message_list_remove_if_not (message_list_ty *mlp, - message_predicate_ty *predicate) + message_predicate_ty *predicate) { size_t i, j; @@ -438,19 +438,19 @@ message_list_msgids_changed (message_list_ty *mlp) hash_init (&mlp->htable, size); for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - - if (message_list_hash_insert_entry (&mlp->htable, mp)) - /* A message list has duplicates, although it was allocated with - the assertion that it wouldn't have duplicates, and before the - msgids changed it indeed didn't have duplicates. */ - { - hash_destroy (&mlp->htable); - mlp->use_hashtable = false; - return true; - } - } + { + message_ty *mp = mlp->item[j]; + + if (message_list_hash_insert_entry (&mlp->htable, mp)) + /* A message list has duplicates, although it was allocated with + the assertion that it wouldn't have duplicates, and before the + msgids changed it indeed didn't have duplicates. */ + { + hash_destroy (&mlp->htable); + mlp->use_hashtable = false; + return true; + } + } } return false; } @@ -476,7 +476,7 @@ message_list_copy (message_list_ty *mlp, int copy_level) message_ty * message_list_search (message_list_ty *mlp, - const char *msgctxt, const char *msgid) + const char *msgctxt, const char *msgid) { if (mlp->use_hashtable) { @@ -485,35 +485,35 @@ message_list_search (message_list_ty *mlp, size_t keylen; if (msgctxt != NULL) - { - /* Concatenate the msgctxt and msgid, to form the hash table key. */ - size_t msgctxt_len = strlen (msgctxt); - size_t msgid_len = strlen (msgid); - keylen = msgctxt_len + 1 + msgid_len + 1; - alloced_key = (char *) xmalloca (keylen); - memcpy (alloced_key, msgctxt, msgctxt_len); - alloced_key[msgctxt_len] = MSGCTXT_SEPARATOR; - memcpy (alloced_key + msgctxt_len + 1, msgid, msgid_len + 1); - key = alloced_key; - } + { + /* Concatenate the msgctxt and msgid, to form the hash table key. */ + size_t msgctxt_len = strlen (msgctxt); + size_t msgid_len = strlen (msgid); + keylen = msgctxt_len + 1 + msgid_len + 1; + alloced_key = (char *) xmalloca (keylen); + memcpy (alloced_key, msgctxt, msgctxt_len); + alloced_key[msgctxt_len] = MSGCTXT_SEPARATOR; + memcpy (alloced_key + msgctxt_len + 1, msgid, msgid_len + 1); + key = alloced_key; + } else - { - alloced_key = NULL; - key = msgid; - keylen = strlen (msgid) + 1; - } + { + alloced_key = NULL; + key = msgid; + keylen = strlen (msgid) + 1; + } { - void *htable_value; - int found = !hash_find_entry (&mlp->htable, key, keylen, &htable_value); + void *htable_value; + int found = !hash_find_entry (&mlp->htable, key, keylen, &htable_value); - if (msgctxt != NULL) - freea (alloced_key); + if (msgctxt != NULL) + freea (alloced_key); - if (found) - return (message_ty *) htable_value; - else - return NULL; + if (found) + return (message_ty *) htable_value; + else + return NULL; } } else @@ -521,16 +521,16 @@ message_list_search (message_list_ty *mlp, size_t j; for (j = 0; j < mlp->nitems; ++j) - { - message_ty *mp; - - mp = mlp->item[j]; - if ((msgctxt != NULL - ? mp->msgctxt != NULL && strcmp (msgctxt, mp->msgctxt) == 0 - : mp->msgctxt == NULL) - && strcmp (msgid, mp->msgid) == 0) - return mp; - } + { + message_ty *mp; + + mp = mlp->item[j]; + if ((msgctxt != NULL + ? mp->msgctxt != NULL && strcmp (msgctxt, mp->msgctxt) == 0 + : mp->msgctxt == NULL) + && strcmp (msgid, mp->msgid) == 0) + return mp; + } return NULL; } } @@ -538,8 +538,8 @@ message_list_search (message_list_ty *mlp, double fuzzy_search_goal_function (const message_ty *mp, - const char *msgctxt, const char *msgid, - double lower_bound) + const char *msgctxt, const char *msgid, + double lower_bound) { double bonus = 0.0; /* A translation for a context is a good proposal also for another. But @@ -550,9 +550,9 @@ fuzzy_search_goal_function (const message_ty *mp, { bonus = 0.00001; /* Since we will consider (weight + bonus) at the end, we are only - interested in weights that are >= lower_bound - bonus. Subtract - a little more than the bonus, in order to avoid trouble due to - rounding errors. */ + interested in weights that are >= lower_bound - bonus. Subtract + a little more than the bonus, in order to avoid trouble due to + rounding errors. */ lower_bound -= bonus * 1.01; } @@ -574,8 +574,8 @@ fuzzy_search_goal_function (const message_ty *mp, static message_ty * message_list_search_fuzzy_inner (message_list_ty *mlp, - const char *msgctxt, const char *msgid, - double *best_weight_p) + const char *msgctxt, const char *msgid, + double *best_weight_p) { size_t j; message_ty *best_mp; @@ -588,15 +588,15 @@ message_list_search_fuzzy_inner (message_list_ty *mlp, mp = mlp->item[j]; if (mp->msgstr != NULL && mp->msgstr[0] != '\0') - { - double weight = - fuzzy_search_goal_function (mp, msgctxt, msgid, *best_weight_p); - if (weight > *best_weight_p) - { - *best_weight_p = weight; - best_mp = mp; - } - } + { + double weight = + fuzzy_search_goal_function (mp, msgctxt, msgid, *best_weight_p); + if (weight > *best_weight_p) + { + *best_weight_p = weight; + best_mp = mp; + } + } } return best_mp; } @@ -604,7 +604,7 @@ message_list_search_fuzzy_inner (message_list_ty *mlp, message_ty * message_list_search_fuzzy (message_list_ty *mlp, - const char *msgctxt, const char *msgid) + const char *msgctxt, const char *msgid) { double best_weight; @@ -657,7 +657,7 @@ message_list_list_append (message_list_list_ty *mllp, message_list_ty *mlp) void message_list_list_append_list (message_list_list_ty *mllp, - message_list_list_ty *mllp2) + message_list_list_ty *mllp2) { size_t j; @@ -668,7 +668,7 @@ message_list_list_append_list (message_list_list_ty *mllp, message_ty * message_list_list_search (message_list_list_ty *mllp, - const char *msgctxt, const char *msgid) + const char *msgctxt, const char *msgid) { message_ty *best_mp; int best_weight; /* 0: not found, 1: found without msgstr, 2: translated */ @@ -684,14 +684,14 @@ message_list_list_search (message_list_list_ty *mllp, mlp = mllp->item[j]; mp = message_list_search (mlp, msgctxt, msgid); if (mp) - { - int weight = (mp->msgstr_len == 1 && mp->msgstr[0] == '\0' ? 1 : 2); - if (weight > best_weight) - { - best_mp = mp; - best_weight = weight; - } - } + { + int weight = (mp->msgstr_len == 1 && mp->msgstr[0] == '\0' ? 1 : 2); + if (weight > best_weight) + { + best_mp = mp; + best_weight = weight; + } + } } return best_mp; } @@ -700,7 +700,7 @@ message_list_list_search (message_list_list_ty *mllp, #if 0 /* unused */ message_ty * message_list_list_search_fuzzy (message_list_list_ty *mllp, - const char *msgctxt, const char *msgid) + const char *msgctxt, const char *msgid) { size_t j; double best_weight; @@ -716,7 +716,7 @@ message_list_list_search_fuzzy (message_list_list_ty *mllp, mlp = mllp->item[j]; mp = message_list_search_fuzzy_inner (mlp, msgctxt, msgid, &best_weight); if (mp) - best_mp = mp; + best_mp = mp; } return best_mp; } @@ -803,7 +803,7 @@ msgdomain_list_append_list (msgdomain_list_ty *mdlp, msgdomain_list_ty *mdlp2) message_list_ty * msgdomain_list_sublist (msgdomain_list_ty *mdlp, const char *domain, - bool create) + bool create) { size_t j; @@ -843,16 +843,16 @@ msgdomain_list_copy (msgdomain_list_ty *mdlp, int copy_level) msgdomain_ty *mdp = mdlp->item[j]; if (copy_level < 2) - { - msgdomain_ty *result_mdp = XMALLOC (msgdomain_ty); + { + msgdomain_ty *result_mdp = XMALLOC (msgdomain_ty); - result_mdp->domain = mdp->domain; - result_mdp->messages = message_list_copy (mdp->messages, copy_level); + result_mdp->domain = mdp->domain; + result_mdp->messages = message_list_copy (mdp->messages, copy_level); - msgdomain_list_append (result, result_mdp); - } + msgdomain_list_append (result, result_mdp); + } else - msgdomain_list_append (result, mdp); + msgdomain_list_append (result, mdp); } return result; @@ -862,7 +862,7 @@ msgdomain_list_copy (msgdomain_list_ty *mdlp, int copy_level) #if 0 /* unused */ message_ty * msgdomain_list_search (msgdomain_list_ty *mdlp, - const char *msgctxt, const char *msgid) + const char *msgctxt, const char *msgid) { size_t j; @@ -874,7 +874,7 @@ msgdomain_list_search (msgdomain_list_ty *mdlp, mdp = mdlp->item[j]; mp = message_list_search (mdp->messages, msgctxt, msgid); if (mp) - return mp; + return mp; } return NULL; } @@ -884,7 +884,7 @@ msgdomain_list_search (msgdomain_list_ty *mdlp, #if 0 /* unused */ message_ty * msgdomain_list_search_fuzzy (msgdomain_list_ty *mdlp, - const char *msgctxt, const char *msgid) + const char *msgctxt, const char *msgid) { size_t j; double best_weight; @@ -899,9 +899,9 @@ msgdomain_list_search_fuzzy (msgdomain_list_ty *mdlp, mdp = mdlp->item[j]; mp = message_list_search_fuzzy_inner (mdp->messages, msgctxt, msgid, - &best_weight); + &best_weight); if (mp) - best_mp = mp; + best_mp = mp; } return best_mp; } diff --git a/gettext-tools/src/message.h b/gettext-tools/src/message.h index 031a2fd0f..af9244aed 100644 --- a/gettext-tools/src/message.h +++ b/gettext-tools/src/message.h @@ -68,7 +68,7 @@ enum format_type format_kde, format_boost }; -#define NFORMATS 24 /* Number of format_type enum values. */ +#define NFORMATS 24 /* Number of format_type enum values. */ extern DLL_VARIABLE const char *const format_language[NFORMATS]; extern DLL_VARIABLE const char *const format_language_pretty[NFORMATS]; @@ -196,9 +196,9 @@ struct message_ty extern message_ty * message_alloc (const char *msgctxt, - const char *msgid, const char *msgid_plural, - const char *msgstr, size_t msgstr_len, - const lex_pos_ty *pp); + const char *msgid, const char *msgid_plural, + const char *msgstr, size_t msgstr_len, + const lex_pos_ty *pp); #define is_header(mp) ((mp)->msgctxt == NULL && (mp)->msgid[0] == '\0') extern void message_free (message_ty *mp); @@ -219,7 +219,7 @@ struct message_list_ty size_t nitems; size_t nitems_max; bool use_hashtable; - hash_table htable; /* Table mapping msgid to 'message_ty *'. */ + hash_table htable; /* Table mapping msgid to 'message_ty *'. */ }; /* Create a fresh message list. @@ -244,7 +244,7 @@ extern void typedef bool message_predicate_ty (const message_ty *mp); extern void message_list_remove_if_not (message_list_ty *mlp, - message_predicate_ty *predicate); + message_predicate_ty *predicate); /* Recompute the hash table of a message list after the msgids or msgctxts changed. */ extern bool @@ -256,14 +256,14 @@ extern message_list_ty * message_list_copy (message_list_ty *mlp, int copy_level); extern message_ty * message_list_search (message_list_ty *mlp, - const char *msgctxt, const char *msgid); + const char *msgctxt, const char *msgid); /* Return the message in MLP which maximizes the fuzzy_search_goal_function. Only messages with a fuzzy_search_goal_function > FUZZY_THRESHOLD are considered. In case of several messages with the same goal function value, the one with the smaller index is returned. */ extern message_ty * message_list_search_fuzzy (message_list_ty *mlp, - const char *msgctxt, const char *msgid); + const char *msgctxt, const char *msgid); typedef struct message_list_list_ty message_list_list_ty; @@ -284,16 +284,16 @@ extern void message_list_list_free (message_list_list_ty *mllp, int keep_level); extern void message_list_list_append (message_list_list_ty *mllp, - message_list_ty *mlp); + message_list_ty *mlp); extern void message_list_list_append_list (message_list_list_ty *mllp, - message_list_list_ty *mllp2); + message_list_list_ty *mllp2); extern message_ty * message_list_list_search (message_list_list_ty *mllp, - const char *msgctxt, const char *msgid); + const char *msgctxt, const char *msgid); extern message_ty * message_list_list_search_fuzzy (message_list_list_ty *mllp, - const char *msgctxt, const char *msgid); + const char *msgctxt, const char *msgid); typedef struct msgdomain_ty msgdomain_ty; @@ -316,7 +316,7 @@ struct msgdomain_list_ty size_t nitems; size_t nitems_max; bool use_hashtable; - const char *encoding; /* canonicalized encoding or NULL if unknown */ + const char *encoding; /* canonicalized encoding or NULL if unknown */ }; extern msgdomain_list_ty * @@ -327,10 +327,10 @@ extern void msgdomain_list_append (msgdomain_list_ty *mdlp, msgdomain_ty *mdp); extern void msgdomain_list_append_list (msgdomain_list_ty *mdlp, - msgdomain_list_ty *mdlp2); + msgdomain_list_ty *mdlp2); extern message_list_ty * msgdomain_list_sublist (msgdomain_list_ty *mdlp, const char *domain, - bool create); + bool create); /* Copy a message domain list. If copy_level = 0, also copy the messages. If copy_level = 1, share the messages but copy the domains. If copy_level = 2, share the domains. */ @@ -338,10 +338,10 @@ extern msgdomain_list_ty * msgdomain_list_copy (msgdomain_list_ty *mdlp, int copy_level); extern message_ty * msgdomain_list_search (msgdomain_list_ty *mdlp, - const char *msgctxt, const char *msgid); + const char *msgctxt, const char *msgid); extern message_ty * msgdomain_list_search_fuzzy (msgdomain_list_ty *mdlp, - const char *msgctxt, const char *msgid); + const char *msgctxt, const char *msgid); /* The goal function used in fuzzy search. @@ -350,8 +350,8 @@ extern message_ty * be returned. */ extern double fuzzy_search_goal_function (const message_ty *mp, - const char *msgctxt, const char *msgid, - double lower_bound); + const char *msgctxt, const char *msgid, + double lower_bound); /* The threshold for fuzzy-searching. A message is considered only if diff --git a/gettext-tools/src/msgattrib.c b/gettext-tools/src/msgattrib.c index e0e56cd09..d5c8d40d6 100644 --- a/gettext-tools/src/msgattrib.c +++ b/gettext-tools/src/msgattrib.c @@ -54,23 +54,23 @@ static int force_po; /* Bit mask of subsets to remove. */ enum { - REMOVE_UNTRANSLATED = 1 << 0, - REMOVE_TRANSLATED = 1 << 1, - REMOVE_FUZZY = 1 << 2, - REMOVE_NONFUZZY = 1 << 3, - REMOVE_OBSOLETE = 1 << 4, - REMOVE_NONOBSOLETE = 1 << 5 + REMOVE_UNTRANSLATED = 1 << 0, + REMOVE_TRANSLATED = 1 << 1, + REMOVE_FUZZY = 1 << 2, + REMOVE_NONFUZZY = 1 << 3, + REMOVE_OBSOLETE = 1 << 4, + REMOVE_NONOBSOLETE = 1 << 5 }; static int to_remove; /* Bit mask of actions to perform on all messages. */ enum { - SET_FUZZY = 1 << 0, - RESET_FUZZY = 1 << 1, - SET_OBSOLETE = 1 << 2, - RESET_OBSOLETE = 1 << 3, - REMOVE_PREV = 1 << 4 + SET_FUZZY = 1 << 0, + RESET_FUZZY = 1 << 1, + SET_OBSOLETE = 1 << 2, + RESET_OBSOLETE = 1 << 3, + REMOVE_PREV = 1 << 4 }; static int to_change; @@ -118,12 +118,12 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; static msgdomain_list_ty *process_msgdomain_list (msgdomain_list_ty *mdlp, - msgdomain_list_ty *only_mdlp, - msgdomain_list_ty *ignore_mdlp); + msgdomain_list_ty *only_mdlp, + msgdomain_list_ty *ignore_mdlp); int @@ -170,151 +170,151 @@ main (int argc, char **argv) ignore_file = NULL; while ((optchar = getopt_long (argc, argv, "D:eEFhino:pPsVw:", long_options, - NULL)) != EOF) + NULL)) != EOF) switch (optchar) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'e': - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case 'E': - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case 'F': - sort_by_filepos = true; - break; + sort_by_filepos = true; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - message_print_style_indent (); - break; + message_print_style_indent (); + break; case 'n': - line_comment = 1; - break; + line_comment = 1; + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 's': - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case 'S': - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case CHAR_MAX + 1: /* --translated */ - to_remove |= REMOVE_UNTRANSLATED; - break; + to_remove |= REMOVE_UNTRANSLATED; + break; case CHAR_MAX + 2: /* --untranslated */ - to_remove |= REMOVE_TRANSLATED; - break; + to_remove |= REMOVE_TRANSLATED; + break; case CHAR_MAX + 3: /* --no-fuzzy */ - to_remove |= REMOVE_FUZZY; - break; + to_remove |= REMOVE_FUZZY; + break; case CHAR_MAX + 4: /* --only-fuzzy */ - to_remove |= REMOVE_NONFUZZY; - break; + to_remove |= REMOVE_NONFUZZY; + break; case CHAR_MAX + 5: /* --no-obsolete */ - to_remove |= REMOVE_OBSOLETE; - break; + to_remove |= REMOVE_OBSOLETE; + break; case CHAR_MAX + 6: /* --only-obsolete */ - to_remove |= REMOVE_NONOBSOLETE; - break; + to_remove |= REMOVE_NONOBSOLETE; + break; case CHAR_MAX + 7: /* --set-fuzzy */ - to_change |= SET_FUZZY; - break; + to_change |= SET_FUZZY; + break; case CHAR_MAX + 8: /* --clear-fuzzy */ - to_change |= RESET_FUZZY; - break; + to_change |= RESET_FUZZY; + break; case CHAR_MAX + 9: /* --set-obsolete */ - to_change |= SET_OBSOLETE; - break; + to_change |= SET_OBSOLETE; + break; case CHAR_MAX + 10: /* --clear-obsolete */ - to_change |= RESET_OBSOLETE; - break; + to_change |= RESET_OBSOLETE; + break; case CHAR_MAX + 11: /* --fuzzy */ - to_remove |= REMOVE_NONFUZZY; - to_change |= RESET_FUZZY; - break; + to_remove |= REMOVE_NONFUZZY; + to_change |= RESET_FUZZY; + break; case CHAR_MAX + 12: /* --obsolete */ - to_remove |= REMOVE_NONOBSOLETE; - to_change |= RESET_OBSOLETE; - break; + to_remove |= REMOVE_NONOBSOLETE; + to_change |= RESET_OBSOLETE; + break; case CHAR_MAX + 13: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 14: /* --only-file */ - only_file = optarg; - break; + only_file = optarg; + break; case CHAR_MAX + 15: /* --ignore-file */ - ignore_file = optarg; - break; + ignore_file = optarg; + break; case CHAR_MAX + 16: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 17: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; case CHAR_MAX + 18: /* --clear-previous */ - to_change |= REMOVE_PREV; - break; + to_change |= REMOVE_PREV; + break; default: - usage (EXIT_FAILURE); - /* NOTREACHED */ + usage (EXIT_FAILURE); + /* NOTREACHED */ } /* Version information requested. */ @@ -327,7 +327,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2009"); + "2001-2009"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -350,22 +350,22 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Verify selected options. */ if (!line_comment && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); + "--no-location", "--sort-by-file"); if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--sort-output", "--sort-by-file"); + "--sort-output", "--sort-by-file"); /* Read input file. */ result = read_catalog_file (input_file, input_syntax); /* Read optional files that limit the extent of the attribute changes. */ only_mdlp = (only_file != NULL - ? read_catalog_file (only_file, input_syntax) - : NULL); + ? read_catalog_file (only_file, input_syntax) + : NULL); ignore_mdlp = (ignore_file != NULL - ? read_catalog_file (ignore_file, input_syntax) - : NULL); + ? read_catalog_file (ignore_file, input_syntax) + : NULL); /* Filter the messages and manipulate the attributes. */ result = process_msgdomain_list (result, only_mdlp, ignore_mdlp); @@ -389,7 +389,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -506,7 +506,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); @@ -523,20 +523,20 @@ is_message_selected (const message_ty *mp) if ((to_remove & (REMOVE_UNTRANSLATED | REMOVE_TRANSLATED)) && (mp->msgstr[0] == '\0' - ? to_remove & REMOVE_UNTRANSLATED - : to_remove & REMOVE_TRANSLATED)) + ? to_remove & REMOVE_UNTRANSLATED + : to_remove & REMOVE_TRANSLATED)) return false; if ((to_remove & (REMOVE_FUZZY | REMOVE_NONFUZZY)) && (mp->is_fuzzy - ? to_remove & REMOVE_FUZZY - : to_remove & REMOVE_NONFUZZY)) + ? to_remove & REMOVE_FUZZY + : to_remove & REMOVE_NONFUZZY)) return false; if ((to_remove & (REMOVE_OBSOLETE | REMOVE_NONOBSOLETE)) && (mp->obsolete - ? to_remove & REMOVE_OBSOLETE - : to_remove & REMOVE_NONOBSOLETE)) + ? to_remove & REMOVE_OBSOLETE + : to_remove & REMOVE_NONOBSOLETE)) return false; return true; @@ -545,7 +545,7 @@ is_message_selected (const message_ty *mp) static void process_message_list (message_list_ty *mlp, - message_list_ty *only_mlp, message_list_ty *ignore_mlp) + message_list_ty *only_mlp, message_list_ty *ignore_mlp) { /* Keep only the selected messages. */ message_list_remove_if_not (mlp, is_message_selected); @@ -556,58 +556,58 @@ process_message_list (message_list_ty *mlp, size_t j; for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - - /* Attribute changes only affect messages listed in --only-file - and not listed in --ignore-file. */ - if ((only_mlp - ? message_list_search (only_mlp, mp->msgctxt, mp->msgid) != NULL - : true) - && (ignore_mlp - ? message_list_search (ignore_mlp, mp->msgctxt, mp->msgid) == NULL - : true)) - { - if (to_change & SET_FUZZY) - mp->is_fuzzy = true; - if (to_change & RESET_FUZZY) - mp->is_fuzzy = false; - /* Always keep the header entry non-obsolete. */ - if ((to_change & SET_OBSOLETE) && !is_header (mp)) - mp->obsolete = true; - if (to_change & RESET_OBSOLETE) - mp->obsolete = false; - if (to_change & REMOVE_PREV) - { - mp->prev_msgctxt = NULL; - mp->prev_msgid = NULL; - mp->prev_msgid_plural = NULL; - } - } - } + { + message_ty *mp = mlp->item[j]; + + /* Attribute changes only affect messages listed in --only-file + and not listed in --ignore-file. */ + if ((only_mlp + ? message_list_search (only_mlp, mp->msgctxt, mp->msgid) != NULL + : true) + && (ignore_mlp + ? message_list_search (ignore_mlp, mp->msgctxt, mp->msgid) == NULL + : true)) + { + if (to_change & SET_FUZZY) + mp->is_fuzzy = true; + if (to_change & RESET_FUZZY) + mp->is_fuzzy = false; + /* Always keep the header entry non-obsolete. */ + if ((to_change & SET_OBSOLETE) && !is_header (mp)) + mp->obsolete = true; + if (to_change & RESET_OBSOLETE) + mp->obsolete = false; + if (to_change & REMOVE_PREV) + { + mp->prev_msgctxt = NULL; + mp->prev_msgid = NULL; + mp->prev_msgid_plural = NULL; + } + } + } } } static msgdomain_list_ty * process_msgdomain_list (msgdomain_list_ty *mdlp, - msgdomain_list_ty *only_mdlp, - msgdomain_list_ty *ignore_mdlp) + msgdomain_list_ty *only_mdlp, + msgdomain_list_ty *ignore_mdlp) { size_t k; for (k = 0; k < mdlp->nitems; k++) process_message_list (mdlp->item[k]->messages, - only_mdlp - ? msgdomain_list_sublist (only_mdlp, - mdlp->item[k]->domain, - true) - : NULL, - ignore_mdlp - ? msgdomain_list_sublist (ignore_mdlp, - mdlp->item[k]->domain, - false) - : NULL); + only_mdlp + ? msgdomain_list_sublist (only_mdlp, + mdlp->item[k]->domain, + true) + : NULL, + ignore_mdlp + ? msgdomain_list_sublist (ignore_mdlp, + mdlp->item[k]->domain, + false) + : NULL); return mdlp; } diff --git a/gettext-tools/src/msgcat.c b/gettext-tools/src/msgcat.c index 9ddd65b11..025fd50d1 100644 --- a/gettext-tools/src/msgcat.c +++ b/gettext-tools/src/msgcat.c @@ -97,7 +97,7 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; @@ -147,138 +147,138 @@ main (int argc, char **argv) use_first = false; while ((optchar = getopt_long (argc, argv, "<:>:D:eEf:Fhino:pPst:uVw:", - long_options, NULL)) != EOF) + long_options, NULL)) != EOF) switch (optchar) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case '>': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - more_than = value; - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + more_than = value; + } + break; case '<': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - less_than = value; - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + less_than = value; + } + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'e': - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case 'E': - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case 'f': - files_from = optarg; - break; + files_from = optarg; + break; case 'F': - sort_by_filepos = true; - break; + sort_by_filepos = true; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - message_print_style_indent (); - break; + message_print_style_indent (); + break; case 'n': - line_comment = 1; - break; + line_comment = 1; + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 's': - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case 'S': - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case 't': - to_code = optarg; - break; + to_code = optarg; + break; case 'u': - less_than = 2; - break; + less_than = 2; + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case CHAR_MAX + 1: - use_first = true; - break; + use_first = true; + break; case CHAR_MAX + 2: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 3: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 4: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; case CHAR_MAX + 5: /* --color */ - if (handle_color_option (optarg)) - usage (EXIT_FAILURE); - break; + if (handle_color_option (optarg)) + usage (EXIT_FAILURE); + break; case CHAR_MAX + 6: /* --style */ - handle_style_option (optarg); - break; + handle_style_option (optarg); + break; case CHAR_MAX + 7: /* --lang */ - catalogname = optarg; - break; + catalogname = optarg; + break; default: - usage (EXIT_FAILURE); - /* NOTREACHED */ + usage (EXIT_FAILURE); + /* NOTREACHED */ } /* Version information requested. */ @@ -291,7 +291,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2009"); + "2001-2009"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -309,17 +309,17 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Verify selected options. */ if (!line_comment && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); + "--no-location", "--sort-by-file"); if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--sort-output", "--sort-by-file"); + "--sort-output", "--sort-by-file"); /* Check the message selection criteria for sanity. */ if (more_than >= less_than || less_than < 2) error (EXIT_FAILURE, 0, - _("impossible selection criteria specified (%d < n < %d)"), - more_than, less_than); + _("impossible selection criteria specified (%d < n < %d)"), + more_than, less_than); /* Determine list of files we have to process. */ if (files_from != NULL) @@ -333,7 +333,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Read input files, then filter, convert and merge messages. */ result = catenate_msgdomain_list (file_list, input_syntax, - output_syntax->requires_utf8 ? "UTF-8" : to_code); + output_syntax->requires_utf8 ? "UTF-8" : to_code); string_list_free (file_list); @@ -360,7 +360,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -477,7 +477,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); diff --git a/gettext-tools/src/msgcmp.c b/gettext-tools/src/msgcmp.c index 1048ceedf..6cf05306e 100644 --- a/gettext-tools/src/msgcmp.c +++ b/gettext-tools/src/msgcmp.c @@ -81,11 +81,11 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; static void compare (const char *fn1, const char *fn2, - catalog_input_format_ty input_syntax); + catalog_input_format_ty input_syntax); int @@ -117,51 +117,51 @@ main (int argc, char *argv[]) do_help = false; do_version = false; while ((optchar = getopt_long (argc, argv, "D:hmNPV", long_options, NULL)) - != EOF) + != EOF) switch (optchar) { - case '\0': /* long option */ - break; + case '\0': /* long option */ + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'm': - multi_domain_mode = true; - break; + multi_domain_mode = true; + break; case 'N': - use_fuzzy_matching = false; - break; + use_fuzzy_matching = false; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 'V': - do_version = true; - break; + do_version = true; + break; - case CHAR_MAX + 1: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + case CHAR_MAX + 1: /* --stringtable-input */ + input_syntax = &input_format_stringtable; + break; - case CHAR_MAX + 2: /* --use-fuzzy */ - include_fuzzies = true; - break; + case CHAR_MAX + 2: /* --use-fuzzy */ + include_fuzzies = true; + break; - case CHAR_MAX + 3: /* --use-untranslated */ - include_untranslated = true; - break; + case CHAR_MAX + 3: /* --use-untranslated */ + include_untranslated = true; + break; default: - usage (EXIT_FAILURE); - break; + usage (EXIT_FAILURE); + break; } /* Version information is requested. */ @@ -174,7 +174,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "1995-1998, 2000-2009"); + "1995-1998, 2000-2009"); printf (_("Written by %s.\n"), proper_name ("Peter Miller")); exit (EXIT_SUCCESS); } @@ -207,7 +207,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -300,10 +300,10 @@ remove_obsoletes (msgdomain_list_ty *mdlp) static void match_domain (const char *fn1, const char *fn2, - message_list_ty *defmlp, message_fuzzy_index_ty **defmlp_findex, - const char *def_canon_charset, - message_list_ty *refmlp, - int *nerrors) + message_list_ty *defmlp, message_fuzzy_index_ty **defmlp_findex, + const char *def_canon_charset, + message_list_ty *refmlp, + int *nerrors) { size_t j; @@ -317,66 +317,66 @@ match_domain (const char *fn1, const char *fn2, /* See if it is in the other file. */ defmsg = message_list_search (defmlp, refmsg->msgctxt, refmsg->msgid); if (defmsg) - { - if (!include_untranslated && defmsg->msgstr[0] == '\0') - { - (*nerrors)++; - po_gram_error_at_line (&defmsg->pos, _("\ + { + if (!include_untranslated && defmsg->msgstr[0] == '\0') + { + (*nerrors)++; + po_gram_error_at_line (&defmsg->pos, _("\ this message is untranslated")); - } - else if (!include_fuzzies && defmsg->is_fuzzy && !is_header (defmsg)) - { - (*nerrors)++; - po_gram_error_at_line (&defmsg->pos, _("\ + } + else if (!include_fuzzies && defmsg->is_fuzzy && !is_header (defmsg)) + { + (*nerrors)++; + po_gram_error_at_line (&defmsg->pos, _("\ this message needs to be reviewed by the translator")); - } - else - defmsg->used = 1; - } + } + else + defmsg->used = 1; + } else - { - /* If the message was not defined at all, try to find a very - similar message, it could be a typo, or the suggestion may - help. */ - (*nerrors)++; - if (use_fuzzy_matching) - { - if (false) - { - /* Old, slow code. */ - defmsg = - message_list_search_fuzzy (defmlp, - refmsg->msgctxt, refmsg->msgid); - } - else - { - /* Speedup through early abort in fstrcmp(), combined with - pre-sorting of the messages through a hashed index. */ - /* Create the fuzzy index lazily. */ - if (*defmlp_findex == NULL) - *defmlp_findex = - message_fuzzy_index_alloc (defmlp, def_canon_charset); - defmsg = - message_fuzzy_index_search (*defmlp_findex, - refmsg->msgctxt, refmsg->msgid, - FUZZY_THRESHOLD, false); - } - } - else - defmsg = NULL; - if (defmsg) - { - po_gram_error_at_line (&refmsg->pos, _("\ + { + /* If the message was not defined at all, try to find a very + similar message, it could be a typo, or the suggestion may + help. */ + (*nerrors)++; + if (use_fuzzy_matching) + { + if (false) + { + /* Old, slow code. */ + defmsg = + message_list_search_fuzzy (defmlp, + refmsg->msgctxt, refmsg->msgid); + } + else + { + /* Speedup through early abort in fstrcmp(), combined with + pre-sorting of the messages through a hashed index. */ + /* Create the fuzzy index lazily. */ + if (*defmlp_findex == NULL) + *defmlp_findex = + message_fuzzy_index_alloc (defmlp, def_canon_charset); + defmsg = + message_fuzzy_index_search (*defmlp_findex, + refmsg->msgctxt, refmsg->msgid, + FUZZY_THRESHOLD, false); + } + } + else + defmsg = NULL; + if (defmsg) + { + po_gram_error_at_line (&refmsg->pos, _("\ this message is used but not defined...")); - error_message_count--; - po_gram_error_at_line (&defmsg->pos, _("\ + error_message_count--; + po_gram_error_at_line (&defmsg->pos, _("\ ...but this definition is similar")); - defmsg->used = 1; - } - else - po_gram_error_at_line (&refmsg->pos, _("\ + defmsg->used = 1; + } + else + po_gram_error_at_line (&refmsg->pos, _("\ this message is used but not defined in %s"), fn1); - } + } } } @@ -404,30 +404,30 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax) bool was_utf8 = false; for (k = 0; k < ref->nitems; k++) { - message_list_ty *mlp = ref->item[k]->messages; - - for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) /* && !mlp->item[j]->obsolete */) - { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *charsetstr = c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - if (len == strlen ("UTF-8") - && c_strncasecmp (charsetstr, "UTF-8", len) == 0) - was_utf8 = true; - } - } - } - } + message_list_ty *mlp = ref->item[k]->messages; + + for (j = 0; j < mlp->nitems; j++) + if (is_header (mlp->item[j]) /* && !mlp->item[j]->obsolete */) + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *charsetstr = c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + if (len == strlen ("UTF-8") + && c_strncasecmp (charsetstr, "UTF-8", len) == 0) + was_utf8 = true; + } + } + } + } if (was_utf8) def = iconv_msgdomain_list (def, "UTF-8", true, fn1); } @@ -438,45 +438,45 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax) { def_canon_charset = def->encoding; if (def_canon_charset == NULL) - { - char *charset = NULL; - - /* Get the encoding of the definitions file. */ - for (k = 0; k < def->nitems; k++) - { - message_list_ty *mlp = def->item[k]->messages; - - for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *charsetstr = c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - charset = (char *) xmalloca (len + 1); - memcpy (charset, charsetstr, len); - charset[len] = '\0'; - break; - } - } - } - if (charset != NULL) - break; - } - if (charset != NULL) - def_canon_charset = po_charset_canonicalize (charset); - if (def_canon_charset == NULL) - /* Unspecified encoding. Assume unibyte encoding. */ - def_canon_charset = po_charset_ascii; - } + { + char *charset = NULL; + + /* Get the encoding of the definitions file. */ + for (k = 0; k < def->nitems; k++) + { + message_list_ty *mlp = def->item[k]->messages; + + for (j = 0; j < mlp->nitems; j++) + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *charsetstr = c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + charset = (char *) xmalloca (len + 1); + memcpy (charset, charsetstr, len); + charset[len] = '\0'; + break; + } + } + } + if (charset != NULL) + break; + } + if (charset != NULL) + def_canon_charset = po_charset_canonicalize (charset); + if (def_canon_charset == NULL) + /* Unspecified encoding. Assume unibyte encoding. */ + def_canon_charset = po_charset_ascii; + } } else def_canon_charset = NULL; @@ -489,45 +489,45 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax) if (!multi_domain_mode) for (k = 0; k < ref->nitems; k++) { - const char *domain = ref->item[k]->domain; - message_list_ty *refmlp = ref->item[k]->messages; - message_list_ty *defmlp; - message_fuzzy_index_ty *defmlp_findex; + const char *domain = ref->item[k]->domain; + message_list_ty *refmlp = ref->item[k]->messages; + message_list_ty *defmlp; + message_fuzzy_index_ty *defmlp_findex; - defmlp = msgdomain_list_sublist (def, domain, false); - if (defmlp == NULL) - defmlp = empty_list; + defmlp = msgdomain_list_sublist (def, domain, false); + if (defmlp == NULL) + defmlp = empty_list; - defmlp_findex = NULL; + defmlp_findex = NULL; - match_domain (fn1, fn2, defmlp, &defmlp_findex, def_canon_charset, - refmlp, &nerrors); + match_domain (fn1, fn2, defmlp, &defmlp_findex, def_canon_charset, + refmlp, &nerrors); - if (defmlp_findex != NULL) - message_fuzzy_index_free (defmlp_findex); + if (defmlp_findex != NULL) + message_fuzzy_index_free (defmlp_findex); } else { /* Apply the references messages in the default domain to each of - the definition domains. */ + the definition domains. */ message_list_ty *refmlp = ref->item[0]->messages; for (k = 0; k < def->nitems; k++) - { - message_list_ty *defmlp = def->item[k]->messages; + { + message_list_ty *defmlp = def->item[k]->messages; - /* Ignore the default message domain if it has no messages. */ - if (k > 0 || defmlp->nitems > 0) - { - message_fuzzy_index_ty *defmlp_findex = NULL; + /* Ignore the default message domain if it has no messages. */ + if (k > 0 || defmlp->nitems > 0) + { + message_fuzzy_index_ty *defmlp_findex = NULL; - match_domain (fn1, fn2, defmlp, &defmlp_findex, def_canon_charset, - refmlp, &nerrors); + match_domain (fn1, fn2, defmlp, &defmlp_findex, def_canon_charset, + refmlp, &nerrors); - if (defmlp_findex != NULL) - message_fuzzy_index_free (defmlp_findex); - } - } + if (defmlp_findex != NULL) + message_fuzzy_index_free (defmlp_findex); + } + } } /* Look for messages in the definition file, which are not present @@ -538,18 +538,18 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax) message_list_ty *defmlp = def->item[k]->messages; for (j = 0; j < defmlp->nitems; j++) - { - message_ty *defmsg = defmlp->item[j]; + { + message_ty *defmsg = defmlp->item[j]; - if (!defmsg->used) - po_gram_error_at_line (&defmsg->pos, - _("warning: this message is not used")); - } + if (!defmsg->used) + po_gram_error_at_line (&defmsg->pos, + _("warning: this message is not used")); + } } /* Exit with status 1 on any error. */ if (nerrors > 0) error (EXIT_FAILURE, 0, - ngettext ("found %d fatal error", "found %d fatal errors", nerrors), - nerrors); + ngettext ("found %d fatal error", "found %d fatal errors", nerrors), + nerrors); } diff --git a/gettext-tools/src/msgcomm.c b/gettext-tools/src/msgcomm.c index b51fe4335..4df0e9fb6 100644 --- a/gettext-tools/src/msgcomm.c +++ b/gettext-tools/src/msgcomm.c @@ -95,7 +95,7 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ > 4) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; @@ -139,125 +139,125 @@ main (int argc, char *argv[]) use_first = false; while ((optchar = getopt_long (argc, argv, "<:>:D:eEf:Fhino:pPst:uVw:", - long_options, NULL)) != EOF) + long_options, NULL)) != EOF) switch (optchar) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case '>': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - more_than = value; - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + more_than = value; + } + break; case '<': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - less_than = value; - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + less_than = value; + } + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'e': - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case 'E': - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case 'f': - files_from = optarg; - break; + files_from = optarg; + break; case 'F': - sort_by_filepos = true; - break; + sort_by_filepos = true; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - message_print_style_indent (); - break; + message_print_style_indent (); + break; case 'n': - line_comment = 1; - break; + line_comment = 1; + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 's': - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case 'S': - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case 't': - to_code = optarg; - break; + to_code = optarg; + break; case 'u': - less_than = 2; - break; + less_than = 2; + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case CHAR_MAX + 1: - omit_header = true; - break; + omit_header = true; + break; case CHAR_MAX + 2: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 3: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 4: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; default: - usage (EXIT_FAILURE); - /* NOTREACHED */ + usage (EXIT_FAILURE); + /* NOTREACHED */ } /* Version information requested. */ @@ -270,7 +270,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "1995-1998, 2000-2009"); + "1995-1998, 2000-2009"); printf (_("Written by %s.\n"), proper_name ("Peter Miller")); exit (EXIT_SUCCESS); } @@ -282,11 +282,11 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Verify selected options. */ if (!line_comment && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); + "--no-location", "--sort-by-file"); if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--sort-output", "--sort-by-file"); + "--sort-output", "--sort-by-file"); /* Determine list of files we have to process. */ if (files_from != NULL) @@ -311,8 +311,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ less_than = INT_MAX; if (more_than >= less_than || less_than < 2) error (EXIT_FAILURE, 0, - _("impossible selection criteria specified (%d < n < %d)"), - more_than, less_than); + _("impossible selection criteria specified (%d < n < %d)"), + more_than, less_than); /* Read input files, then filter, convert and merge messages. */ allow_duplicates = true; @@ -340,7 +340,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -445,7 +445,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); diff --git a/gettext-tools/src/msgconv.c b/gettext-tools/src/msgconv.c index 5ed149503..70d7a1ec6 100644 --- a/gettext-tools/src/msgconv.c +++ b/gettext-tools/src/msgconv.c @@ -86,7 +86,7 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; @@ -129,90 +129,90 @@ main (int argc, char **argv) input_file = NULL; while ((opt = getopt_long (argc, argv, "D:eEFhio:pPst:Vw:", long_options, - NULL)) - != EOF) + NULL)) + != EOF) switch (opt) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'e': - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case 'E': - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case 'F': - sort_by_filepos = true; - break; + sort_by_filepos = true; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - message_print_style_indent (); - break; + message_print_style_indent (); + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 's': - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case 'S': - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case 't': - to_code = optarg; - break; + to_code = optarg; + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case CHAR_MAX + 1: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 2: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 3: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; default: - usage (EXIT_FAILURE); - break; + usage (EXIT_FAILURE); + break; } /* Version information is requested. */ @@ -225,7 +225,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2009"); + "2001-2009"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -248,11 +248,11 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Verify selected options. */ if (!line_comment && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); + "--no-location", "--sort-by-file"); if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--sort-output", "--sort-by-file"); + "--sort-output", "--sort-by-file"); /* Default for target encoding is current locale's encoding. */ if (to_code == NULL) @@ -284,7 +284,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -371,7 +371,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); diff --git a/gettext-tools/src/msgen.c b/gettext-tools/src/msgen.c index dc344cd2b..4aac39c65 100644 --- a/gettext-tools/src/msgen.c +++ b/gettext-tools/src/msgen.c @@ -83,7 +83,7 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; @@ -126,89 +126,89 @@ main (int argc, char **argv) output_file = NULL; while ((opt = getopt_long (argc, argv, "D:eEFhio:pPsVw:", long_options, NULL)) - != EOF) + != EOF) switch (opt) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'e': - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case 'E': - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case 'F': - sort_by_filepos = true; - break; + sort_by_filepos = true; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - message_print_style_indent (); - break; + message_print_style_indent (); + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 's': - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case 'S': - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case CHAR_MAX + 1: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 2: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 3: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; case CHAR_MAX + 4: /* --lang */ - catalogname = optarg; - break; + catalogname = optarg; + break; default: - usage (EXIT_FAILURE); - break; + usage (EXIT_FAILURE); + break; } /* Version information is requested. */ @@ -221,7 +221,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2009"); + "2001-2009"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -245,11 +245,11 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Verify selected options. */ if (!line_comment && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); + "--no-location", "--sort-by-file"); if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--sort-output", "--sort-by-file"); + "--sort-output", "--sort-by-file"); /* Read input file. */ result = read_catalog_file (argv[optind], input_syntax); @@ -280,7 +280,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -366,7 +366,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); diff --git a/gettext-tools/src/msgexec.c b/gettext-tools/src/msgexec.c index f61130d4d..619794822 100644 --- a/gettext-tools/src/msgexec.c +++ b/gettext-tools/src/msgexec.c @@ -90,7 +90,7 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; static void process_msgdomain_list (const msgdomain_list_ty *mdlp); @@ -132,44 +132,44 @@ main (int argc, char **argv) /* The '+' in the options string causes option parsing to terminate when the first non-option, i.e. the subprogram name, is encountered. */ while ((opt = getopt_long (argc, argv, "+D:hi:PV", long_options, NULL)) - != EOF) + != EOF) switch (opt) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - if (input_file != NULL) - { - error (EXIT_SUCCESS, 0, _("at most one input file allowed")); - usage (EXIT_FAILURE); - } - input_file = optarg; - break; + if (input_file != NULL) + { + error (EXIT_SUCCESS, 0, _("at most one input file allowed")); + usage (EXIT_FAILURE); + } + input_file = optarg; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 'V': - do_version = true; - break; + do_version = true; + break; case CHAR_MAX + 1: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; default: - usage (EXIT_FAILURE); - break; + usage (EXIT_FAILURE); + break; } /* Version information is requested. */ @@ -182,7 +182,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2009"); + "2001-2009"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -216,20 +216,20 @@ There is NO WARRANTY, to the extent permitted by law.\n\ compare_po_locale_charsets (result); /* Block SIGPIPE for this process and for the subprocesses. - The subprogram may have side effects (additionally to producing some - output), therefore if there are no readers on stdout, processing of the - strings must continue nevertheless. */ + The subprogram may have side effects (additionally to producing some + output), therefore if there are no readers on stdout, processing of the + strings must continue nevertheless. */ { - sigset_t sigpipe_set; + sigset_t sigpipe_set; - sigemptyset (&sigpipe_set); - sigaddset (&sigpipe_set, SIGPIPE); - sigprocmask (SIG_UNBLOCK, &sigpipe_set, NULL); + sigemptyset (&sigpipe_set); + sigaddset (&sigpipe_set, SIGPIPE); + sigprocmask (SIG_UNBLOCK, &sigpipe_set, NULL); } /* Attempt to locate the program. - This is an optimization, to avoid that spawn/exec searches the PATH - on every call. */ + This is an optimization, to avoid that spawn/exec searches the PATH + on every call. */ sub_path = find_in_path (sub_name); /* Finish argument list for the program. */ @@ -251,7 +251,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -304,7 +304,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); @@ -342,7 +342,7 @@ process_string (const message_ty *mp, const char *str, size_t len) { /* Built-in command "0". */ if (full_write (STDOUT_FILENO, str, len + 1) < len + 1) - error (EXIT_FAILURE, errno, _("write to stdout failed")); + error (EXIT_FAILURE, errno, _("write to stdout failed")); } else { @@ -354,39 +354,39 @@ process_string (const message_ty *mp, const char *str, size_t len) int exitstatus; /* Set environment variables for the subprocess. - Note: These environment variables, especially MSGEXEC_MSGCTXT and - MSGEXEC_MSGCTXT, may contain non-ASCII characters. The subprocess - may not interpret these values correctly if the locale encoding is - different from the PO file's encoding. We want about this situation, - above. - On Unix, this problem is often harmless. On Windows, however, - both - native Windows and Cygwin - the values of environment variables *must* - be in the encoding that is the value of GetACP(), because the system - may convert the environment from char** to wchar_t** before spawning - the subprocess and back from wchar_t** to char** in the subprocess, - and it does so using the GetACP() codepage. */ + Note: These environment variables, especially MSGEXEC_MSGCTXT and + MSGEXEC_MSGCTXT, may contain non-ASCII characters. The subprocess + may not interpret these values correctly if the locale encoding is + different from the PO file's encoding. We want about this situation, + above. + On Unix, this problem is often harmless. On Windows, however, - both + native Windows and Cygwin - the values of environment variables *must* + be in the encoding that is the value of GetACP(), because the system + may convert the environment from char** to wchar_t** before spawning + the subprocess and back from wchar_t** to char** in the subprocess, + and it does so using the GetACP() codepage. */ if (mp->msgctxt != NULL) - xsetenv ("MSGEXEC_MSGCTXT", mp->msgctxt, 1); + xsetenv ("MSGEXEC_MSGCTXT", mp->msgctxt, 1); else - unsetenv ("MSGEXEC_MSGCTXT"); + unsetenv ("MSGEXEC_MSGCTXT"); xsetenv ("MSGEXEC_MSGID", mp->msgid, 1); location = xasprintf ("%s:%ld", mp->pos.file_name, - (long) mp->pos.line_number); + (long) mp->pos.line_number); xsetenv ("MSGEXEC_LOCATION", location, 1); free (location); /* Open a pipe to a subprocess. */ child = create_pipe_out (sub_name, sub_path, sub_argv, NULL, false, true, - true, fd); + true, fd); /* Ignore SIGPIPE here. We don't care if the subprocesses terminates - successfully without having read all of the input that we feed it. */ + successfully without having read all of the input that we feed it. */ orig_sigpipe_handler = signal (SIGPIPE, SIG_IGN); if (full_write (fd[0], str, len) < len) - if (errno != EPIPE) - error (EXIT_FAILURE, errno, - _("write to %s subprocess failed"), sub_name); + if (errno != EPIPE) + error (EXIT_FAILURE, errno, + _("write to %s subprocess failed"), sub_name); close (fd[0]); @@ -394,11 +394,11 @@ process_string (const message_ty *mp, const char *str, size_t len) /* Remove zombie process from process list, and retrieve exit status. */ /* FIXME: Should ignore_sigpipe be set to true here? It depends on the - semantics of the subprogram... */ + semantics of the subprogram... */ exitstatus = - wait_subprocess (child, sub_name, false, false, true, true, NULL); + wait_subprocess (child, sub_name, false, false, true, true, NULL); if (exitcode < exitstatus) - exitcode = exitstatus; + exitcode = exitstatus; } } diff --git a/gettext-tools/src/msgfilter.c b/gettext-tools/src/msgfilter.c index 4cb2642ae..a3769899c 100644 --- a/gettext-tools/src/msgfilter.c +++ b/gettext-tools/src/msgfilter.c @@ -114,7 +114,7 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; static void generic_filter (const char *str, size_t len, char **resultp, size_t *lengthp); @@ -162,95 +162,95 @@ main (int argc, char **argv) /* The '+' in the options string causes option parsing to terminate when the first non-option, i.e. the subprogram name, is encountered. */ while ((opt = getopt_long (argc, argv, "+D:EFhi:o:pPsVw:", long_options, - NULL)) - != EOF) + NULL)) + != EOF) switch (opt) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'E': - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case 'F': - sort_by_filepos = true; - break; + sort_by_filepos = true; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - if (input_file != NULL) - { - error (EXIT_SUCCESS, 0, _("at most one input file allowed")); - usage (EXIT_FAILURE); - } - input_file = optarg; - break; + if (input_file != NULL) + { + error (EXIT_SUCCESS, 0, _("at most one input file allowed")); + usage (EXIT_FAILURE); + } + input_file = optarg; + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 's': - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case 'S': - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case CHAR_MAX + 1: - message_print_style_indent (); - break; + message_print_style_indent (); + break; case CHAR_MAX + 2: - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case CHAR_MAX + 3: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 4: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 5: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; default: - usage (EXIT_FAILURE); - break; + usage (EXIT_FAILURE); + break; } /* Version information is requested. */ @@ -263,7 +263,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2009"); + "2001-2009"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -280,11 +280,11 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Verify selected options. */ if (!line_comment && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); + "--no-location", "--sort-by-file"); if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--sort-output", "--sort-by-file"); + "--sort-output", "--sort-by-file"); /* Build argument list for the program. */ sub_argc = argc - optind; @@ -297,24 +297,24 @@ There is NO WARRANTY, to the extent permitted by law.\n\ if (strcmp (sub_name, "sed") == 0) { if (sub_argc == 1) - error (EXIT_FAILURE, 0, - _("at least one sed script must be specified")); + error (EXIT_FAILURE, 0, + _("at least one sed script must be specified")); /* Replace GNU sed specific options with portable sed options. */ for (i = 1; i < sub_argc; i++) - { - if (strcmp (sub_argv[i], "--expression") == 0) - sub_argv[i] = "-e"; - else if (strcmp (sub_argv[i], "--file") == 0) - sub_argv[i] = "-f"; - else if (strcmp (sub_argv[i], "--quiet") == 0 - || strcmp (sub_argv[i], "--silent") == 0) - sub_argv[i] = "-n"; - - if (strcmp (sub_argv[i], "-e") == 0 - || strcmp (sub_argv[i], "-f") == 0) - i++; - } + { + if (strcmp (sub_argv[i], "--expression") == 0) + sub_argv[i] = "-e"; + else if (strcmp (sub_argv[i], "--file") == 0) + sub_argv[i] = "-f"; + else if (strcmp (sub_argv[i], "--quiet") == 0 + || strcmp (sub_argv[i], "--silent") == 0) + sub_argv[i] = "-n"; + + if (strcmp (sub_argv[i], "-e") == 0 + || strcmp (sub_argv[i], "-f") == 0) + i++; + } } /* By default, input comes from standard input. */ @@ -340,8 +340,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ compare_po_locale_charsets (result); /* Attempt to locate the program. - This is an optimization, to avoid that spawn/exec searches the PATH - on every call. */ + This is an optimization, to avoid that spawn/exec searches the PATH + on every call. */ sub_path = find_in_path (sub_name); /* Finish argument list for the program. */ @@ -370,7 +370,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -467,7 +467,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); @@ -548,8 +548,8 @@ generic_filter (const char *str, size_t len, char **resultp, size_t *lengthp) l.length = 0; pipe_filter_ii_execute (sub_name, sub_path, sub_argv, false, true, - prepare_write, done_write, prepare_read, done_read, - &l); + prepare_write, done_write, prepare_read, done_read, + &l); *resultp = l.result; *lengthp = l.length; @@ -574,16 +574,16 @@ process_string (const char *str, size_t len, char **resultp, size_t *lengthp) for (; p < pend; p++) if (*p == '\0') - { - char *q; - - q = p; - for (; p < pend; p++) - if (*p != '\0') - *q++ = *p; - length = q - result; - break; - } + { + char *q; + + q = p; + for (; p < pend; p++) + if (*p != '\0') + *q++ = *p; + length = q - result; + break; + } } *resultp = result; @@ -627,7 +627,7 @@ process_message (message_ty *mp) unsetenv ("MSGFILTER_MSGCTXT"); xsetenv ("MSGFILTER_MSGID", mp->msgid, 1); location = xasprintf ("%s:%ld", mp->pos.file_name, - (long) mp->pos.line_number); + (long) mp->pos.line_number); xsetenv ("MSGFILTER_LOCATION", location, 1); free (location); diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index 9f1465459..fcf2e299a 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -183,14 +183,14 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; static const char *add_mo_suffix (const char *); static struct msg_domain *new_domain (const char *name, const char *file_name); static bool is_nonobsolete (const message_ty *mp); static void read_catalog_file_msgfmt (char *filename, - catalog_input_format_ty input_syntax); + catalog_input_format_ty input_syntax); int @@ -228,134 +228,134 @@ main (int argc, char *argv[]) atexit (close_stdout); while ((opt = getopt_long (argc, argv, "a:cCd:D:fhjl:o:Pr:vV", long_options, - NULL)) - != EOF) + NULL)) + != EOF) switch (opt) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'a': - { - char *endp; - size_t new_align = strtoul (optarg, &endp, 0); - - if (endp != optarg) - alignment = new_align; - } - break; + { + char *endp; + size_t new_align = strtoul (optarg, &endp, 0); + + if (endp != optarg) + alignment = new_align; + } + break; case 'c': - check_domain = true; - check_format_strings = true; - check_header = true; - break; + check_domain = true; + check_format_strings = true; + check_header = true; + break; case 'C': - check_compatibility = true; - break; + check_compatibility = true; + break; case 'd': - java_class_directory = optarg; - csharp_base_directory = optarg; - tcl_base_directory = optarg; - break; + java_class_directory = optarg; + csharp_base_directory = optarg; + tcl_base_directory = optarg; + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'f': - include_fuzzies = true; - break; + include_fuzzies = true; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'j': - java_mode = true; - break; + java_mode = true; + break; case 'l': - java_locale_name = optarg; - csharp_locale_name = optarg; - tcl_locale_name = optarg; - break; + java_locale_name = optarg; + csharp_locale_name = optarg; + tcl_locale_name = optarg; + break; case 'o': - output_file_name = optarg; - break; + output_file_name = optarg; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 'r': - java_resource_name = optarg; - csharp_resource_name = optarg; - break; + java_resource_name = optarg; + csharp_resource_name = optarg; + break; case 'S': - strict_uniforum = true; - break; + strict_uniforum = true; + break; case 'v': - verbose++; - break; + verbose++; + break; case 'V': - do_version = true; - break; + do_version = true; + break; case CHAR_MAX + 1: /* --check-accelerators */ - check_accelerators = true; - if (optarg != NULL) - { - if (optarg[0] != '\0' && ispunct ((unsigned char) optarg[0]) - && optarg[1] == '\0') - accelerator_char = optarg[0]; - else - error (EXIT_FAILURE, 0, - _("the argument to %s should be a single punctuation character"), - "--check-accelerators"); - } - break; + check_accelerators = true; + if (optarg != NULL) + { + if (optarg[0] != '\0' && ispunct ((unsigned char) optarg[0]) + && optarg[1] == '\0') + accelerator_char = optarg[0]; + else + error (EXIT_FAILURE, 0, + _("the argument to %s should be a single punctuation character"), + "--check-accelerators"); + } + break; case CHAR_MAX + 2: /* --check-domain */ - check_domain = true; - break; + check_domain = true; + break; case CHAR_MAX + 3: /* --check-format */ - check_format_strings = true; - break; + check_format_strings = true; + break; case CHAR_MAX + 4: /* --check-header */ - check_header = true; - break; + check_header = true; + break; case CHAR_MAX + 5: /* --java2 */ - java_mode = true; - assume_java2 = true; - break; + java_mode = true; + assume_java2 = true; + break; case CHAR_MAX + 6: /* --no-hash */ - no_hash_table = true; - break; + no_hash_table = true; + break; case CHAR_MAX + 7: /* --tcl */ - tcl_mode = true; - break; + tcl_mode = true; + break; case CHAR_MAX + 8: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 9: /* --qt */ - qt_mode = true; - break; + qt_mode = true; + break; case CHAR_MAX + 10: /* --csharp */ - csharp_mode = true; - break; + csharp_mode = true; + break; case CHAR_MAX + 11: /* --csharp-resources */ - csharp_resources_mode = true; - break; + csharp_resources_mode = true; + break; case CHAR_MAX + 12: /* --use-untranslated (undocumented) */ - include_untranslated = true; - break; + include_untranslated = true; + break; case CHAR_MAX + 13: /* --endianness={big|little} */ - { - int endianness; - - if (strcmp (optarg, "big") == 0) - endianness = 1; - else if (strcmp (optarg, "little") == 0) - endianness = 0; - else - error (EXIT_FAILURE, 0, _("invalid endianness: %s"), optarg); - - byteswap = endianness ^ ENDIANNESS; - } - break; + { + int endianness; + + if (strcmp (optarg, "big") == 0) + endianness = 1; + else if (strcmp (optarg, "little") == 0) + endianness = 0; + else + error (EXIT_FAILURE, 0, _("invalid endianness: %s"), optarg); + + byteswap = endianness ^ ENDIANNESS; + } + break; default: - usage (EXIT_FAILURE); - break; + usage (EXIT_FAILURE); + break; } /* Version information is requested. */ @@ -368,7 +368,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "1995-1998, 2000-2009"); + "1995-1998, 2000-2009"); printf (_("Written by %s.\n"), proper_name ("Ulrich Drepper")); exit (EXIT_SUCCESS); } @@ -397,100 +397,100 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* More than one bit set? */ if (modes & (modes - 1)) { - const char *first_option; - const char *second_option; - unsigned int i; - for (i = 0; ; i++) - if (modes & (1 << i)) - break; - first_option = mode_options[i]; - for (i = i + 1; ; i++) - if (modes & (1 << i)) - break; - second_option = mode_options[i]; - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - first_option, second_option); + const char *first_option; + const char *second_option; + unsigned int i; + for (i = 0; ; i++) + if (modes & (1 << i)) + break; + first_option = mode_options[i]; + for (i = i + 1; ; i++) + if (modes & (1 << i)) + break; + second_option = mode_options[i]; + error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), + first_option, second_option); } } if (java_mode) { if (output_file_name != NULL) - { - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--java", "--output-file"); - } + { + error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), + "--java", "--output-file"); + } if (java_class_directory == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-d directory\" specification"), - "--java"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, + _("%s requires a \"-d directory\" specification"), + "--java"); + usage (EXIT_FAILURE); + } } else if (csharp_mode) { if (output_file_name != NULL) - { - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--csharp", "--output-file"); - } + { + error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), + "--csharp", "--output-file"); + } if (csharp_locale_name == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-l locale\" specification"), - "--csharp"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, + _("%s requires a \"-l locale\" specification"), + "--csharp"); + usage (EXIT_FAILURE); + } if (csharp_base_directory == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-d directory\" specification"), - "--csharp"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, + _("%s requires a \"-d directory\" specification"), + "--csharp"); + usage (EXIT_FAILURE); + } } else if (tcl_mode) { if (output_file_name != NULL) - { - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--tcl", "--output-file"); - } + { + error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), + "--tcl", "--output-file"); + } if (tcl_locale_name == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-l locale\" specification"), - "--tcl"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, + _("%s requires a \"-l locale\" specification"), + "--tcl"); + usage (EXIT_FAILURE); + } if (tcl_base_directory == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-d directory\" specification"), - "--tcl"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, + _("%s requires a \"-d directory\" specification"), + "--tcl"); + usage (EXIT_FAILURE); + } } else { if (java_resource_name != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"), - "--resource", "--java", "--csharp"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"), + "--resource", "--java", "--csharp"); + usage (EXIT_FAILURE); + } if (java_locale_name != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s, %s or %s"), - "--locale", "--java", "--csharp", "--tcl"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, _("%s is only valid with %s, %s or %s"), + "--locale", "--java", "--csharp", "--tcl"); + usage (EXIT_FAILURE); + } if (java_class_directory != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s, %s or %s"), - "-d", "--java", "--csharp", "--tcl"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, _("%s is only valid with %s, %s or %s"), + "-d", "--java", "--csharp", "--tcl"); + usage (EXIT_FAILURE); + } } /* The -o option determines the name of the domain and therefore @@ -498,17 +498,17 @@ There is NO WARRANTY, to the extent permitted by law.\n\ if (output_file_name != NULL) current_domain = new_domain (output_file_name, - strict_uniforum && !csharp_resources_mode && !qt_mode - ? add_mo_suffix (output_file_name) - : output_file_name); + strict_uniforum && !csharp_resources_mode && !qt_mode + ? add_mo_suffix (output_file_name) + : output_file_name); /* Process all given .po files. */ for (arg_i = optind; arg_i < argc; arg_i++) { /* Remember that we currently have not specified any domain. This - is of course not true when we saw the -o option. */ + is of course not true when we saw the -o option. */ if (output_file_name == NULL) - current_domain = NULL; + current_domain = NULL; /* And process the input file. */ read_catalog_file_msgfmt (argv[arg_i], input_syntax); @@ -529,19 +529,19 @@ There is NO WARRANTY, to the extent permitted by law.\n\ for (domain = domain_list; domain != NULL; domain = domain->next) nerrors += - check_message_list (domain->mlp, - 1, check_format_strings, check_header, - check_compatibility, - check_accelerators, accelerator_char); + check_message_list (domain->mlp, + 1, check_format_strings, check_header, + check_compatibility, + check_accelerators, accelerator_char); /* Exit with status 1 on any error. */ if (nerrors > 0) { - error (0, 0, - ngettext ("found %d fatal error", "found %d fatal errors", - nerrors), - nerrors); - exit_status = EXIT_FAILURE; + error (0, 0, + ngettext ("found %d fatal error", "found %d fatal errors", + nerrors), + nerrors); + exit_status = EXIT_FAILURE; } } @@ -549,44 +549,44 @@ There is NO WARRANTY, to the extent permitted by law.\n\ for (domain = domain_list; domain != NULL; domain = domain->next) { if (java_mode) - { - if (msgdomain_write_java (domain->mlp, canon_encoding, - java_resource_name, java_locale_name, - java_class_directory, assume_java2)) - exit_status = EXIT_FAILURE; - } + { + if (msgdomain_write_java (domain->mlp, canon_encoding, + java_resource_name, java_locale_name, + java_class_directory, assume_java2)) + exit_status = EXIT_FAILURE; + } else if (csharp_mode) - { - if (msgdomain_write_csharp (domain->mlp, canon_encoding, - csharp_resource_name, csharp_locale_name, - csharp_base_directory)) - exit_status = EXIT_FAILURE; - } + { + if (msgdomain_write_csharp (domain->mlp, canon_encoding, + csharp_resource_name, csharp_locale_name, + csharp_base_directory)) + exit_status = EXIT_FAILURE; + } else if (csharp_resources_mode) - { - if (msgdomain_write_csharp_resources (domain->mlp, canon_encoding, - domain->domain_name, - domain->file_name)) - exit_status = EXIT_FAILURE; - } + { + if (msgdomain_write_csharp_resources (domain->mlp, canon_encoding, + domain->domain_name, + domain->file_name)) + exit_status = EXIT_FAILURE; + } else if (tcl_mode) - { - if (msgdomain_write_tcl (domain->mlp, canon_encoding, - tcl_locale_name, tcl_base_directory)) - exit_status = EXIT_FAILURE; - } + { + if (msgdomain_write_tcl (domain->mlp, canon_encoding, + tcl_locale_name, tcl_base_directory)) + exit_status = EXIT_FAILURE; + } else if (qt_mode) - { - if (msgdomain_write_qt (domain->mlp, canon_encoding, - domain->domain_name, domain->file_name)) - exit_status = EXIT_FAILURE; - } + { + if (msgdomain_write_qt (domain->mlp, canon_encoding, + domain->domain_name, domain->file_name)) + exit_status = EXIT_FAILURE; + } else - { - if (msgdomain_write_mo (domain->mlp, domain->domain_name, - domain->file_name)) - exit_status = EXIT_FAILURE; - } + { + if (msgdomain_write_mo (domain->mlp, domain->domain_name, + domain->file_name)) + exit_status = EXIT_FAILURE; + } /* List is not used anymore. */ message_list_free (domain->mlp, 0); @@ -596,41 +596,41 @@ There is NO WARRANTY, to the extent permitted by law.\n\ if (verbose || do_statistics) { if (do_statistics + verbose >= 2 && optind < argc) - { - /* Print the input file name(s) in front of the statistics line. */ - char *all_input_file_names; - - { - string_list_ty input_file_names; - - string_list_init (&input_file_names);; - for (arg_i = optind; arg_i < argc; arg_i++) - string_list_append (&input_file_names, argv[arg_i]); - all_input_file_names = - string_list_join (&input_file_names, ", ", '\0', false); - string_list_destroy (&input_file_names); - } - - /* TRANSLATORS: The prefix before a statistics message. The argument - is a file name or a comma separated list of file names. */ - fprintf (stderr, _("%s: "), all_input_file_names); - free (all_input_file_names); - } + { + /* Print the input file name(s) in front of the statistics line. */ + char *all_input_file_names; + + { + string_list_ty input_file_names; + + string_list_init (&input_file_names);; + for (arg_i = optind; arg_i < argc; arg_i++) + string_list_append (&input_file_names, argv[arg_i]); + all_input_file_names = + string_list_join (&input_file_names, ", ", '\0', false); + string_list_destroy (&input_file_names); + } + + /* TRANSLATORS: The prefix before a statistics message. The argument + is a file name or a comma separated list of file names. */ + fprintf (stderr, _("%s: "), all_input_file_names); + free (all_input_file_names); + } fprintf (stderr, - ngettext ("%d translated message", "%d translated messages", - msgs_translated), - msgs_translated); + ngettext ("%d translated message", "%d translated messages", + msgs_translated), + msgs_translated); if (msgs_fuzzy > 0) - fprintf (stderr, - ngettext (", %d fuzzy translation", ", %d fuzzy translations", - msgs_fuzzy), - msgs_fuzzy); + fprintf (stderr, + ngettext (", %d fuzzy translation", ", %d fuzzy translations", + msgs_fuzzy), + msgs_fuzzy); if (msgs_untranslated > 0) - fprintf (stderr, - ngettext (", %d untranslated message", - ", %d untranslated messages", - msgs_untranslated), - msgs_untranslated); + fprintf (stderr, + ngettext (", %d untranslated message", + ", %d untranslated messages", + msgs_untranslated), + msgs_untranslated); fputs (".\n", stderr); } @@ -644,7 +644,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -885,26 +885,26 @@ msgfmt_parse_debrief (abstract_catalog_reader_ty *that) if (check_header) { if (!this->has_header_entry) - { - multiline_error (xasprintf ("%s: ", this->file_name), - xasprintf (_("\ + { + multiline_error (xasprintf ("%s: ", this->file_name), + xasprintf (_("\ warning: PO file header missing or invalid\n"))); - multiline_error (NULL, - xasprintf (_("\ + multiline_error (NULL, + xasprintf (_("\ warning: charset conversion will not work\n"))); - } + } else if (!this->has_nonfuzzy_header_entry) - { - /* Has only a fuzzy header entry. Since the versions 0.10.xx - ignore a fuzzy header entry and even give an error on it, we - give a warning, to increase operability with these older - msgfmt versions. This warning can go away in January 2003. */ - multiline_warning (xasprintf ("%s: ", this->file_name), - xasprintf (_("warning: PO file header fuzzy\n"))); - multiline_warning (NULL, - xasprintf (_("\ + { + /* Has only a fuzzy header entry. Since the versions 0.10.xx + ignore a fuzzy header entry and even give an error on it, we + give a warning, to increase operability with these older + msgfmt versions. This warning can go away in January 2003. */ + multiline_warning (xasprintf ("%s: ", this->file_name), + xasprintf (_("warning: PO file header fuzzy\n"))); + multiline_warning (NULL, + xasprintf (_("\ warning: older versions of msgfmt will give an error on this\n"))); - } + } } } @@ -922,19 +922,19 @@ msgfmt_set_domain (default_catalog_reader_ty *this, char *name) correct = strcspn (name, INVALID_PATH_CHAR); if (name[correct] != '\0') - { - exit_status = EXIT_FAILURE; - if (correct == 0) - { - error (0, 0, _("\ + { + exit_status = EXIT_FAILURE; + if (correct == 0) + { + error (0, 0, _("\ domain name \"%s\" not suitable as file name"), name); - return; - } - else - error (0, 0, _("\ + return; + } + else + error (0, 0, _("\ domain name \"%s\" not suitable as file name: will use prefix"), name); - name[correct] = '\0'; - } + name[correct] = '\0'; + } /* Set new domain. */ current_domain = new_domain (name, add_mo_suffix (name)); @@ -944,8 +944,8 @@ domain name \"%s\" not suitable as file name: will use prefix"), name); else { if (check_domain) - po_gram_error_at_line (&gram_pos, - _("`domain %s' directive ignored"), name); + po_gram_error_at_line (&gram_pos, + _("`domain %s' directive ignored"), name); /* NAME was allocated in po-gram-gen.y but is not used anywhere. */ free (name); @@ -955,23 +955,23 @@ domain name \"%s\" not suitable as file name: will use prefix"), name); static void msgfmt_add_message (default_catalog_reader_ty *this, - char *msgctxt, - char *msgid, - lex_pos_ty *msgid_pos, - char *msgid_plural, - char *msgstr, size_t msgstr_len, - lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, - char *prev_msgid_plural, - bool force_fuzzy, bool obsolete) + char *msgctxt, + char *msgid, + lex_pos_ty *msgid_pos, + char *msgid_plural, + char *msgstr, size_t msgstr_len, + lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, + char *prev_msgid_plural, + bool force_fuzzy, bool obsolete) { /* Check whether already a domain is specified. If not, use default domain. */ if (current_domain == NULL) { current_domain = new_domain (MESSAGE_DOMAIN_DEFAULT, - add_mo_suffix (MESSAGE_DOMAIN_DEFAULT)); + add_mo_suffix (MESSAGE_DOMAIN_DEFAULT)); /* Keep current_domain and this->domain synchronized. */ this->domain = current_domain->domain_name; this->mlp = current_domain->mlp; @@ -979,62 +979,62 @@ msgfmt_add_message (default_catalog_reader_ty *this, /* Invoke superclass method. */ default_add_message (this, msgctxt, msgid, msgid_pos, msgid_plural, - msgstr, msgstr_len, msgstr_pos, - prev_msgctxt, prev_msgid, prev_msgid_plural, - force_fuzzy, obsolete); + msgstr, msgstr_len, msgstr_pos, + prev_msgctxt, prev_msgid, prev_msgid_plural, + force_fuzzy, obsolete); } static void msgfmt_frob_new_message (default_catalog_reader_ty *that, message_ty *mp, - const lex_pos_ty *msgid_pos, - const lex_pos_ty *msgstr_pos) + const lex_pos_ty *msgid_pos, + const lex_pos_ty *msgstr_pos) { msgfmt_catalog_reader_ty *this = (msgfmt_catalog_reader_ty *) that; if (!mp->obsolete) { /* Don't emit untranslated entries. - Also don't emit fuzzy entries, unless --use-fuzzy was specified. - But ignore fuzziness of the header entry. */ + Also don't emit fuzzy entries, unless --use-fuzzy was specified. + But ignore fuzziness of the header entry. */ if ((!include_untranslated && mp->msgstr[0] == '\0') - || (!include_fuzzies && mp->is_fuzzy && !is_header (mp))) - { - if (check_compatibility) - { - error_with_progname = false; - error_at_line (0, 0, mp->pos.file_name, mp->pos.line_number, - (mp->msgstr[0] == '\0' - ? _("empty `msgstr' entry ignored") - : _("fuzzy `msgstr' entry ignored"))); - error_with_progname = true; - } - - /* Increment counter for fuzzy/untranslated messages. */ - if (mp->msgstr[0] == '\0') - ++msgs_untranslated; - else - ++msgs_fuzzy; - - mp->obsolete = true; - } + || (!include_fuzzies && mp->is_fuzzy && !is_header (mp))) + { + if (check_compatibility) + { + error_with_progname = false; + error_at_line (0, 0, mp->pos.file_name, mp->pos.line_number, + (mp->msgstr[0] == '\0' + ? _("empty `msgstr' entry ignored") + : _("fuzzy `msgstr' entry ignored"))); + error_with_progname = true; + } + + /* Increment counter for fuzzy/untranslated messages. */ + if (mp->msgstr[0] == '\0') + ++msgs_untranslated; + else + ++msgs_fuzzy; + + mp->obsolete = true; + } else - { - /* Test for header entry. */ - if (is_header (mp)) - { - this->has_header_entry = true; - if (!mp->is_fuzzy) - this->has_nonfuzzy_header_entry = true; - } - else - /* We don't count the header entry in the statistic so place - the counter incrementation here. */ - if (mp->is_fuzzy) - ++msgs_fuzzy; - else - ++msgs_translated; - } + { + /* Test for header entry. */ + if (is_header (mp)) + { + this->has_header_entry = true; + if (!mp->is_fuzzy) + this->has_nonfuzzy_header_entry = true; + } + else + /* We don't count the header entry in the statistic so place + the counter incrementation here. */ + if (mp->is_fuzzy) + ++msgs_fuzzy; + else + ++msgs_translated; + } } } @@ -1053,12 +1053,12 @@ msgfmt_comment_special (abstract_catalog_reader_ty *that, const char *s) static bool warned = false; if (!include_fuzzies && check_compatibility && !warned) - { - warned = true; - error (0, 0, _("\ + { + warned = true; + error (0, 0, _("\ %s: warning: source file contains fuzzy translation"), - gram_pos.file_name); - } + gram_pos.file_name); + } } } @@ -1115,7 +1115,7 @@ read_catalog_file_msgfmt (char *filename, catalog_input_format_ty input_syntax) } po_lex_pass_obsolete_entries (true); catalog_reader_parse ((abstract_catalog_reader_ty *) pop, fp, real_filename, - filename, input_syntax); + filename, input_syntax); catalog_reader_free ((abstract_catalog_reader_ty *) pop); if (fp != stdin) diff --git a/gettext-tools/src/msggrep.c b/gettext-tools/src/msggrep.c index c88357e68..34d3b06e5 100644 --- a/gettext-tools/src/msggrep.c +++ b/gettext-tools/src/msggrep.c @@ -129,12 +129,12 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void no_pass (int opt) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; static msgdomain_list_ty *process_msgdomain_list (msgdomain_list_ty *mdlp); @@ -194,200 +194,200 @@ main (int argc, char **argv) } while ((opt = getopt_long (argc, argv, "CD:e:Ef:FhiJKM:N:o:pPTvVw:X", - long_options, NULL)) - != EOF) + long_options, NULL)) + != EOF) switch (opt) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'C': - grep_pass = 3; - break; + grep_pass = 3; + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'e': - if (grep_pass < 0) - no_pass (opt); - { - struct grep_task *gt = &grep_task[grep_pass]; - /* Append optarg and a newline to gt->patterns. */ - size_t len = strlen (optarg); - gt->patterns = - (char *) xrealloc (gt->patterns, gt->patterns_size + len + 1); - memcpy (gt->patterns + gt->patterns_size, optarg, len); - gt->patterns_size += len; - *(gt->patterns + gt->patterns_size) = '\n'; - gt->patterns_size += 1; - gt->pattern_count++; - } - break; + if (grep_pass < 0) + no_pass (opt); + { + struct grep_task *gt = &grep_task[grep_pass]; + /* Append optarg and a newline to gt->patterns. */ + size_t len = strlen (optarg); + gt->patterns = + (char *) xrealloc (gt->patterns, gt->patterns_size + len + 1); + memcpy (gt->patterns + gt->patterns_size, optarg, len); + gt->patterns_size += len; + *(gt->patterns + gt->patterns_size) = '\n'; + gt->patterns_size += 1; + gt->pattern_count++; + } + break; case 'E': - if (grep_pass < 0) - no_pass (opt); - grep_task[grep_pass].matcher = &matcher_egrep; - break; + if (grep_pass < 0) + no_pass (opt); + grep_task[grep_pass].matcher = &matcher_egrep; + break; case 'f': - if (grep_pass < 0) - no_pass (opt); - { - struct grep_task *gt = &grep_task[grep_pass]; - /* Append the contents of the specified file to gt->patterns. */ - FILE *fp = fopen (optarg, "r"); - - if (fp == NULL) - error (EXIT_FAILURE, errno, _("\ + if (grep_pass < 0) + no_pass (opt); + { + struct grep_task *gt = &grep_task[grep_pass]; + /* Append the contents of the specified file to gt->patterns. */ + FILE *fp = fopen (optarg, "r"); + + if (fp == NULL) + error (EXIT_FAILURE, errno, _("\ error while opening \"%s\" for reading"), optarg); - while (!feof (fp)) - { - char buf[4096]; - size_t count = fread (buf, 1, sizeof buf, fp); + while (!feof (fp)) + { + char buf[4096]; + size_t count = fread (buf, 1, sizeof buf, fp); - if (count == 0) - { - if (ferror (fp)) - error (EXIT_FAILURE, errno, _("\ + if (count == 0) + { + if (ferror (fp)) + error (EXIT_FAILURE, errno, _("\ error while reading \"%s\""), optarg); - /* EOF reached. */ - break; - } - - gt->patterns = - (char *) xrealloc (gt->patterns, gt->patterns_size + count); - memcpy (gt->patterns + gt->patterns_size, buf, count); - gt->patterns_size += count; - } - - /* Append a final newline if file ended in a non-newline. */ - if (gt->patterns_size > 0 - && *(gt->patterns + gt->patterns_size - 1) != '\n') - { - gt->patterns = - (char *) xrealloc (gt->patterns, gt->patterns_size + 1); - *(gt->patterns + gt->patterns_size) = '\n'; - gt->patterns_size += 1; - } - - fclose (fp); - gt->pattern_count++; - } - break; + /* EOF reached. */ + break; + } + + gt->patterns = + (char *) xrealloc (gt->patterns, gt->patterns_size + count); + memcpy (gt->patterns + gt->patterns_size, buf, count); + gt->patterns_size += count; + } + + /* Append a final newline if file ended in a non-newline. */ + if (gt->patterns_size > 0 + && *(gt->patterns + gt->patterns_size - 1) != '\n') + { + gt->patterns = + (char *) xrealloc (gt->patterns, gt->patterns_size + 1); + *(gt->patterns + gt->patterns_size) = '\n'; + gt->patterns_size += 1; + } + + fclose (fp); + gt->pattern_count++; + } + break; case 'F': - if (grep_pass < 0) - no_pass (opt); - grep_task[grep_pass].matcher = &matcher_fgrep; - break; + if (grep_pass < 0) + no_pass (opt); + grep_task[grep_pass].matcher = &matcher_fgrep; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - if (grep_pass < 0) - no_pass (opt); - grep_task[grep_pass].case_insensitive = true; - break; + if (grep_pass < 0) + no_pass (opt); + grep_task[grep_pass].case_insensitive = true; + break; case 'J': - grep_pass = 0; - break; + grep_pass = 0; + break; case 'K': - grep_pass = 1; - break; + grep_pass = 1; + break; case 'M': - string_list_append (domain_names, optarg); - break; + string_list_append (domain_names, optarg); + break; case 'N': - string_list_append (location_files, optarg); - break; + string_list_append (location_files, optarg); + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 'S': - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case 'T': - grep_pass = 2; - break; + grep_pass = 2; + break; case 'v': - invert_match = true; - break; + invert_match = true; + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case 'X': - grep_pass = 4; - break; + grep_pass = 4; + break; case CHAR_MAX + 1: - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case CHAR_MAX + 2: - message_print_style_indent (); - break; + message_print_style_indent (); + break; case CHAR_MAX + 3: - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case CHAR_MAX + 4: - sort_by_filepos = true; - break; + sort_by_filepos = true; + break; case CHAR_MAX + 5: - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case CHAR_MAX + 6: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 7: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 8: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; default: - usage (EXIT_FAILURE); - break; + usage (EXIT_FAILURE); + break; } /* Version information is requested. */ @@ -400,7 +400,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2009"); + "2001-2009"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -423,11 +423,11 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Verify selected options. */ if (!line_comment && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); + "--no-location", "--sort-by-file"); if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--sort-output", "--sort-by-file"); + "--sort-output", "--sort-by-file"); /* Compile the patterns. */ for (grep_pass = 0; grep_pass < 5; grep_pass++) @@ -435,17 +435,17 @@ There is NO WARRANTY, to the extent permitted by law.\n\ struct grep_task *gt = &grep_task[grep_pass]; if (gt->pattern_count > 0) - { - if (gt->patterns_size > 0) - { - /* Strip trailing newline. */ - assert (gt->patterns[gt->patterns_size - 1] == '\n'); - gt->patterns_size--; - } - gt->compiled_patterns = - gt->matcher->compile (gt->patterns, gt->patterns_size, - gt->case_insensitive, false, false, '\n'); - } + { + if (gt->patterns_size > 0) + { + /* Strip trailing newline. */ + assert (gt->patterns[gt->patterns_size - 1] == '\n'); + gt->patterns_size--; + } + gt->compiled_patterns = + gt->matcher->compile (gt->patterns, gt->patterns_size, + gt->case_insensitive, false, false, '\n'); + } } /* Read input file. */ @@ -481,8 +481,8 @@ static void no_pass (int opt) { error (EXIT_SUCCESS, 0, - _("option '%c' cannot be used before 'J' or 'K' or 'T' or 'C' or 'X' has been specified"), - opt); + _("option '%c' cannot be used before 'J' or 'K' or 'T' or 'C' or 'X' has been specified"), + opt); usage (EXIT_FAILURE); } @@ -493,7 +493,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -614,7 +614,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); @@ -670,8 +670,8 @@ is_string_selected (int grep_pass, const char *str, size_t len) size_t match_offset; match_offset = - gt->matcher->execute (gt->compiled_patterns, str, len, - &match_size, false); + gt->matcher->execute (gt->compiled_patterns, str, len, + &match_size, false); return (match_offset != (size_t) -1); } else @@ -715,7 +715,7 @@ is_message_selected_no_invert (const message_ty *mp) size_t length = strlen (p); if (is_string_selected (2, p, length)) - return true; + return true; p += length + 1; } @@ -732,27 +732,27 @@ is_message_selected_no_invert (const message_ty *mp) length = 0; for (j = 0; j < mp->comment->nitems; j++) - length += strlen (mp->comment->item[j]) + 1; + length += strlen (mp->comment->item[j]) + 1; total_comment = (char *) xmalloca (length); q = total_comment; for (j = 0; j < mp->comment->nitems; j++) - { - size_t l = strlen (mp->comment->item[j]); + { + size_t l = strlen (mp->comment->item[j]); - memcpy (q, mp->comment->item[j], l); - q += l; - *q++ = '\n'; - } + memcpy (q, mp->comment->item[j], l); + q += l; + *q++ = '\n'; + } if (q != total_comment + length) - abort (); + abort (); selected = is_string_selected (3, total_comment, length); freea (total_comment); if (selected) - return true; + return true; } /* Test extracted comments using the --extracted-comment arguments. */ @@ -767,27 +767,27 @@ is_message_selected_no_invert (const message_ty *mp) length = 0; for (j = 0; j < mp->comment_dot->nitems; j++) - length += strlen (mp->comment_dot->item[j]) + 1; + length += strlen (mp->comment_dot->item[j]) + 1; total_comment = (char *) xmalloca (length); q = total_comment; for (j = 0; j < mp->comment_dot->nitems; j++) - { - size_t l = strlen (mp->comment_dot->item[j]); + { + size_t l = strlen (mp->comment_dot->item[j]); - memcpy (q, mp->comment_dot->item[j], l); - q += l; - *q++ = '\n'; - } + memcpy (q, mp->comment_dot->item[j], l); + q += l; + *q++ = '\n'; + } if (q != total_comment + length) - abort (); + abort (); selected = is_string_selected (4, total_comment, length); freea (total_comment); if (selected) - return true; + return true; } return false; diff --git a/gettext-tools/src/msginit.c b/gettext-tools/src/msginit.c index 5908925fc..c24d89520 100644 --- a/gettext-tools/src/msginit.c +++ b/gettext-tools/src/msginit.c @@ -178,74 +178,74 @@ main (int argc, char **argv) locale = NULL; while ((opt = getopt_long (argc, argv, "hi:l:o:pPVw:", long_options, NULL)) - != EOF) + != EOF) switch (opt) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - if (input_file != NULL) - { - error (EXIT_SUCCESS, 0, _("at most one input file allowed")); - usage (EXIT_FAILURE); - } - input_file = optarg; - break; + if (input_file != NULL) + { + error (EXIT_SUCCESS, 0, _("at most one input file allowed")); + usage (EXIT_FAILURE); + } + input_file = optarg; + break; case 'l': - locale = optarg; - break; + locale = optarg; + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case CHAR_MAX + 1: - no_translator = true; - break; + no_translator = true; + break; case CHAR_MAX + 2: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 3: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 4: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; default: - usage (EXIT_FAILURE); - break; + usage (EXIT_FAILURE); + break; } /* Version information is requested. */ @@ -258,7 +258,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2009"); + "2001-2009"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -280,14 +280,14 @@ There is NO WARRANTY, to the extent permitted by law.\n\ { locale = gl_locale_name (LC_MESSAGES, "LC_MESSAGES"); if (strcmp (locale, "C") == 0) - { - multiline_error (xstrdup (""), - xstrdup (_("\ + { + multiline_error (xstrdup (""), + xstrdup (_("\ You are in a language indifferent environment. Please set\n\ your LANG environment variable, as described in the ABOUT-NLS\n\ file. This is necessary so you can test your translations.\n"))); - exit (EXIT_FAILURE); - } + exit (EXIT_FAILURE); + } } { const char *alias = _nl_expand_alias (locale); @@ -304,15 +304,15 @@ file. This is necessary so you can test your translations.\n"))); /* But don't overwrite existing PO files. */ if (access (output_file, F_OK) == 0) - { - multiline_error (xstrdup (""), - xasprintf (_("\ + { + multiline_error (xstrdup (""), + xasprintf (_("\ Output file %s already exists.\n\ Please specify the locale through the --locale option or\n\ the output .po file through the --output-file option.\n"), - output_file)); - exit (EXIT_FAILURE); - } + output_file)); + exit (EXIT_FAILURE); + } } /* Read input file. */ @@ -344,7 +344,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -411,7 +411,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); @@ -430,45 +430,45 @@ find_pot () if (dirp != NULL) { for (;;) - { - struct dirent *dp; - - errno = 0; - dp = readdir (dirp); - if (dp != NULL) - { - const char *name = dp->d_name; - size_t namlen = strlen (name); - - if (namlen > 4 && memcmp (name + namlen - 4, ".pot", 4) == 0) - { - if (found == NULL) - found = xstrdup (name); - else - { - multiline_error (xstrdup (""), - xstrdup (_("\ + { + struct dirent *dp; + + errno = 0; + dp = readdir (dirp); + if (dp != NULL) + { + const char *name = dp->d_name; + size_t namlen = strlen (name); + + if (namlen > 4 && memcmp (name + namlen - 4, ".pot", 4) == 0) + { + if (found == NULL) + found = xstrdup (name); + else + { + multiline_error (xstrdup (""), + xstrdup (_("\ Found more than one .pot file.\n\ Please specify the input .pot file through the --input option.\n"))); - usage (EXIT_FAILURE); - } - } - } - else if (errno != 0) - error (EXIT_FAILURE, errno, _("error reading current directory")); - else - break; - } + usage (EXIT_FAILURE); + } + } + } + else if (errno != 0) + error (EXIT_FAILURE, errno, _("error reading current directory")); + else + break; + } if (closedir (dirp)) - error (EXIT_FAILURE, errno, _("error reading current directory")); + error (EXIT_FAILURE, errno, _("error reading current directory")); if (found != NULL) - return found; + return found; } #endif multiline_error (xstrdup (""), - xstrdup (_("\ + xstrdup (_("\ Found no .pot file in the current directory.\n\ Please specify the input .pot file through the --input option.\n"))); usage (EXIT_FAILURE); @@ -487,199 +487,199 @@ static const char * catalogname_for_locale (const char *locale) { static const char *locales_with_principal_territory[] = { - /* Language Main territory */ - "ace_ID", /* Achinese Indonesia */ - "af_ZA", /* Afrikaans South Africa */ - "ak_GH", /* Akan Ghana */ - "am_ET", /* Amharic Ethiopia */ - "an_ES", /* Aragonese Spain */ - "ang_GB", /* Old English Britain */ - "as_IN", /* Assamese India */ - "ast_ES", /* Asturian Spain */ - "av_RU", /* Avaric Russia */ - "awa_IN", /* Awadhi India */ - "az_AZ", /* Azerbaijani Azerbaijan */ - "ban_ID", /* Balinese Indonesia */ - "be_BY", /* Belarusian Belarus */ - "bej_SD", /* Beja Sudan */ - "bem_ZM", /* Bemba Zambia */ - "bg_BG", /* Bulgarian Bulgaria */ - "bho_IN", /* Bhojpuri India */ - "bik_PH", /* Bikol Philippines */ - "bin_NG", /* Bini Nigeria */ - "bm_ML", /* Bambara Mali */ - "bn_IN", /* Bengali India */ - "bo_CN", /* Tibetan China */ - "br_FR", /* Breton France */ - "bs_BA", /* Bosnian Bosnia */ - "bug_ID", /* Buginese Indonesia */ - "ca_ES", /* Catalan Spain */ - "ce_RU", /* Chechen Russia */ - "ceb_PH", /* Cebuano Philippines */ - "co_FR", /* Corsican France */ - "cr_CA", /* Cree Canada */ + /* Language Main territory */ + "ace_ID", /* Achinese Indonesia */ + "af_ZA", /* Afrikaans South Africa */ + "ak_GH", /* Akan Ghana */ + "am_ET", /* Amharic Ethiopia */ + "an_ES", /* Aragonese Spain */ + "ang_GB", /* Old English Britain */ + "as_IN", /* Assamese India */ + "ast_ES", /* Asturian Spain */ + "av_RU", /* Avaric Russia */ + "awa_IN", /* Awadhi India */ + "az_AZ", /* Azerbaijani Azerbaijan */ + "ban_ID", /* Balinese Indonesia */ + "be_BY", /* Belarusian Belarus */ + "bej_SD", /* Beja Sudan */ + "bem_ZM", /* Bemba Zambia */ + "bg_BG", /* Bulgarian Bulgaria */ + "bho_IN", /* Bhojpuri India */ + "bik_PH", /* Bikol Philippines */ + "bin_NG", /* Bini Nigeria */ + "bm_ML", /* Bambara Mali */ + "bn_IN", /* Bengali India */ + "bo_CN", /* Tibetan China */ + "br_FR", /* Breton France */ + "bs_BA", /* Bosnian Bosnia */ + "bug_ID", /* Buginese Indonesia */ + "ca_ES", /* Catalan Spain */ + "ce_RU", /* Chechen Russia */ + "ceb_PH", /* Cebuano Philippines */ + "co_FR", /* Corsican France */ + "cr_CA", /* Cree Canada */ /* Don't put "crh_UZ" or "crh_UA" here. That would be asking for fruitless political discussion. */ - "cs_CZ", /* Czech Czech Republic */ - "csb_PL", /* Kashubian Poland */ - "cy_GB", /* Welsh Britain */ - "da_DK", /* Danish Denmark */ - "de_DE", /* German Germany */ - "din_SD", /* Dinka Sudan */ - "doi_IN", /* Dogri India */ - "dv_MV", /* Divehi Maldives */ - "dz_BT", /* Dzongkha Bhutan */ - "ee_GH", /* Éwé Ghana */ - "el_GR", /* Greek Greece */ + "cs_CZ", /* Czech Czech Republic */ + "csb_PL", /* Kashubian Poland */ + "cy_GB", /* Welsh Britain */ + "da_DK", /* Danish Denmark */ + "de_DE", /* German Germany */ + "din_SD", /* Dinka Sudan */ + "doi_IN", /* Dogri India */ + "dv_MV", /* Divehi Maldives */ + "dz_BT", /* Dzongkha Bhutan */ + "ee_GH", /* Éwé Ghana */ + "el_GR", /* Greek Greece */ /* Don't put "en_GB" or "en_US" here. That would be asking for fruitless political discussion. */ - "es_ES", /* Spanish Spain */ - "et_EE", /* Estonian Estonia */ - "fa_IR", /* Persian Iran */ - "fi_FI", /* Finnish Finland */ - "fil_PH", /* Filipino Philippines */ - "fj_FJ", /* Fijian Fiji */ - "fo_FO", /* Faroese Faeroe Islands */ - "fon_BJ", /* Fon Benin */ - "fr_FR", /* French France */ - "fur_IT", /* Friulian Italy */ - "fy_NL", /* Western Frisian Netherlands */ - "ga_IE", /* Irish Ireland */ - "gd_GB", /* Scottish Gaelic Britain */ - "gon_IN", /* Gondi India */ - "gsw_CH", /* Swiss German Switzerland */ - "gu_IN", /* Gujarati India */ - "he_IL", /* Hebrew Israel */ - "hi_IN", /* Hindi India */ - "hil_PH", /* Hiligaynon Philippines */ - "hr_HR", /* Croatian Croatia */ - "ht_HT", /* Haitian Haiti */ - "hu_HU", /* Hungarian Hungary */ - "hy_AM", /* Armenian Armenia */ - "id_ID", /* Indonesian Indonesia */ - "ig_NG", /* Igbo Nigeria */ - "ii_CN", /* Sichuan Yi China */ - "ilo_PH", /* Iloko Philippines */ - "is_IS", /* Icelandic Iceland */ - "it_IT", /* Italian Italy */ - "ja_JP", /* Japanese Japan */ - "jab_NG", /* Hyam Nigeria */ - "jv_ID", /* Javanese Indonesia */ - "ka_GE", /* Georgian Georgia */ - "kab_DZ", /* Kabyle Algeria */ - "kaj_NG", /* Jju Nigeria */ - "kam_KE", /* Kamba Kenya */ - "kmb_AO", /* Kimbundu Angola */ - "kcg_NG", /* Tyap Nigeria */ - "kdm_NG", /* Kagoma Nigeria */ - "kg_CD", /* Kongo Democratic Republic of Congo */ - "kk_KZ", /* Kazakh Kazakhstan */ - "kl_GL", /* Kalaallisut Greenland */ - "km_KH", /* Central Khmer Cambodia */ - "kn_IN", /* Kannada India */ - "ko_KR", /* Korean Korea (South) */ - "kok_IN", /* Konkani India */ - "kr_NG", /* Kanuri Nigeria */ - "kru_IN", /* Kurukh India */ - "lg_UG", /* Ganda Uganda */ - "li_BE", /* Limburgish Belgium */ - "lo_LA", /* Laotian Laos */ - "lt_LT", /* Lithuanian Lithuania */ - "lu_CD", /* Luba-Katanga Democratic Republic of Congo */ - "lua_CD", /* Luba-Lulua Democratic Republic of Congo */ - "luo_KE", /* Luo Kenya */ - "lv_LV", /* Latvian Latvia */ - "mad_ID", /* Madurese Indonesia */ - "mag_IN", /* Magahi India */ - "mai_IN", /* Maithili India */ - "mak_ID", /* Makasar Indonesia */ - "man_ML", /* Mandingo Mali */ - "men_SL", /* Mende Sierra Leone */ - "mg_MG", /* Malagasy Madagascar */ - "mi_NZ", /* Maori New Zealand */ - "min_ID", /* Minangkabau Indonesia */ - "mk_MK", /* Macedonian Macedonia */ - "ml_IN", /* Malayalam India */ - "mn_MN", /* Mongolian Mongolia */ - "mni_IN", /* Manipuri India */ - "mos_BF", /* Mossi Burkina Faso */ - "mr_IN", /* Marathi India */ - "ms_MY", /* Malay Malaysia */ - "mt_MT", /* Maltese Malta */ - "mwr_IN", /* Marwari India */ - "my_MM", /* Burmese Myanmar */ - "na_NR", /* Nauru Nauru */ - "nah_MX", /* Nahuatl Mexico */ - "nap_IT", /* Neapolitan Italy */ - "nb_NO", /* Norwegian BokmÃ¥l Norway */ - "nds_DE", /* Low Saxon Germany */ - "ne_NP", /* Nepali Nepal */ - "nl_NL", /* Dutch Netherlands */ - "nn_NO", /* Norwegian Nynorsk Norway */ - "no_NO", /* Norwegian Norway */ - "nr_ZA", /* South Ndebele South Africa */ - "nso_ZA", /* Northern Sotho South Africa */ - "nym_TZ", /* Nyamwezi Tanzania */ - "nyn_UG", /* Nyankole Uganda */ - "oc_FR", /* Occitan France */ - "oj_CA", /* Ojibwa Canada */ - "or_IN", /* Oriya India */ - "pa_IN", /* Punjabi India */ - "pag_PH", /* Pangasinan Philippines */ - "pam_PH", /* Pampanga Philippines */ - "pap_AN", /* Papiamento Netherlands Antilles */ - "pbb_CO", /* Páez Colombia */ - "pl_PL", /* Polish Poland */ - "ps_AF", /* Pashto Afghanistan */ - "pt_PT", /* Portuguese Portugal */ - "raj_IN", /* Rajasthani India */ - "rm_CH", /* Romansh Switzerland */ - "rn_BI", /* Kirundi Burundi */ - "ro_RO", /* Romanian Romania */ - "ru_RU", /* Russian Russia */ - "sa_IN", /* Sanskrit India */ - "sas_ID", /* Sasak Indonesia */ - "sat_IN", /* Santali India */ - "sc_IT", /* Sardinian Italy */ - "scn_IT", /* Sicilian Italy */ - "sg_CF", /* Sango Central African Republic */ - "shn_MM", /* Shan Myanmar */ - "si_LK", /* Sinhala Sri Lanka */ - "sid_ET", /* Sidamo Ethiopia */ - "sk_SK", /* Slovak Slovakia */ - "sl_SI", /* Slovenian Slovenia */ - "so_SO", /* Somali Somalia */ - "sq_AL", /* Albanian Albania */ - "sr_RS", /* Serbian Serbia */ - "sr_YU", /* Serbian Yugoslavia - this line can be removed in 2010 */ - "srr_SN", /* Serer Senegal */ - "suk_TZ", /* Sukuma Tanzania */ - "sus_GN", /* Susu Guinea */ - "sv_SE", /* Swedish Sweden */ - "te_IN", /* Telugu India */ - "tem_SL", /* Timne Sierra Leone */ - "tet_ID", /* Tetum Indonesia */ - "tg_TJ", /* Tajik Tajikistan */ - "th_TH", /* Thai Thailand */ - "tiv_NG", /* Tiv Nigeria */ - "tk_TM", /* Turkmen Turkmenistan */ - "tl_PH", /* Tagalog Philippines */ - "to_TO", /* Tonga Tonga */ - "tr_TR", /* Turkish Turkey */ - "tum_MW", /* Tumbuka Malawi */ - "ug_CN", /* Uighur China */ - "uk_UA", /* Ukrainian Ukraine */ - "umb_AO", /* Umbundu Angola */ - "ur_PK", /* Urdu Pakistan */ - "uz_UZ", /* Uzbek Uzbekistan */ - "ve_ZA", /* Venda South Africa */ - "vi_VN", /* Vietnamese Vietnam */ - "wa_BE", /* Walloon Belgium */ - "wal_ET", /* Walamo Ethiopia */ - "war_PH", /* Waray Philippines */ - "wen_DE", /* Sorbian Germany */ - "yao_MW", /* Yao Malawi */ - "zap_MX" /* Zapotec Mexico */ + "es_ES", /* Spanish Spain */ + "et_EE", /* Estonian Estonia */ + "fa_IR", /* Persian Iran */ + "fi_FI", /* Finnish Finland */ + "fil_PH", /* Filipino Philippines */ + "fj_FJ", /* Fijian Fiji */ + "fo_FO", /* Faroese Faeroe Islands */ + "fon_BJ", /* Fon Benin */ + "fr_FR", /* French France */ + "fur_IT", /* Friulian Italy */ + "fy_NL", /* Western Frisian Netherlands */ + "ga_IE", /* Irish Ireland */ + "gd_GB", /* Scottish Gaelic Britain */ + "gon_IN", /* Gondi India */ + "gsw_CH", /* Swiss German Switzerland */ + "gu_IN", /* Gujarati India */ + "he_IL", /* Hebrew Israel */ + "hi_IN", /* Hindi India */ + "hil_PH", /* Hiligaynon Philippines */ + "hr_HR", /* Croatian Croatia */ + "ht_HT", /* Haitian Haiti */ + "hu_HU", /* Hungarian Hungary */ + "hy_AM", /* Armenian Armenia */ + "id_ID", /* Indonesian Indonesia */ + "ig_NG", /* Igbo Nigeria */ + "ii_CN", /* Sichuan Yi China */ + "ilo_PH", /* Iloko Philippines */ + "is_IS", /* Icelandic Iceland */ + "it_IT", /* Italian Italy */ + "ja_JP", /* Japanese Japan */ + "jab_NG", /* Hyam Nigeria */ + "jv_ID", /* Javanese Indonesia */ + "ka_GE", /* Georgian Georgia */ + "kab_DZ", /* Kabyle Algeria */ + "kaj_NG", /* Jju Nigeria */ + "kam_KE", /* Kamba Kenya */ + "kmb_AO", /* Kimbundu Angola */ + "kcg_NG", /* Tyap Nigeria */ + "kdm_NG", /* Kagoma Nigeria */ + "kg_CD", /* Kongo Democratic Republic of Congo */ + "kk_KZ", /* Kazakh Kazakhstan */ + "kl_GL", /* Kalaallisut Greenland */ + "km_KH", /* Central Khmer Cambodia */ + "kn_IN", /* Kannada India */ + "ko_KR", /* Korean Korea (South) */ + "kok_IN", /* Konkani India */ + "kr_NG", /* Kanuri Nigeria */ + "kru_IN", /* Kurukh India */ + "lg_UG", /* Ganda Uganda */ + "li_BE", /* Limburgish Belgium */ + "lo_LA", /* Laotian Laos */ + "lt_LT", /* Lithuanian Lithuania */ + "lu_CD", /* Luba-Katanga Democratic Republic of Congo */ + "lua_CD", /* Luba-Lulua Democratic Republic of Congo */ + "luo_KE", /* Luo Kenya */ + "lv_LV", /* Latvian Latvia */ + "mad_ID", /* Madurese Indonesia */ + "mag_IN", /* Magahi India */ + "mai_IN", /* Maithili India */ + "mak_ID", /* Makasar Indonesia */ + "man_ML", /* Mandingo Mali */ + "men_SL", /* Mende Sierra Leone */ + "mg_MG", /* Malagasy Madagascar */ + "mi_NZ", /* Maori New Zealand */ + "min_ID", /* Minangkabau Indonesia */ + "mk_MK", /* Macedonian Macedonia */ + "ml_IN", /* Malayalam India */ + "mn_MN", /* Mongolian Mongolia */ + "mni_IN", /* Manipuri India */ + "mos_BF", /* Mossi Burkina Faso */ + "mr_IN", /* Marathi India */ + "ms_MY", /* Malay Malaysia */ + "mt_MT", /* Maltese Malta */ + "mwr_IN", /* Marwari India */ + "my_MM", /* Burmese Myanmar */ + "na_NR", /* Nauru Nauru */ + "nah_MX", /* Nahuatl Mexico */ + "nap_IT", /* Neapolitan Italy */ + "nb_NO", /* Norwegian BokmÃ¥l Norway */ + "nds_DE", /* Low Saxon Germany */ + "ne_NP", /* Nepali Nepal */ + "nl_NL", /* Dutch Netherlands */ + "nn_NO", /* Norwegian Nynorsk Norway */ + "no_NO", /* Norwegian Norway */ + "nr_ZA", /* South Ndebele South Africa */ + "nso_ZA", /* Northern Sotho South Africa */ + "nym_TZ", /* Nyamwezi Tanzania */ + "nyn_UG", /* Nyankole Uganda */ + "oc_FR", /* Occitan France */ + "oj_CA", /* Ojibwa Canada */ + "or_IN", /* Oriya India */ + "pa_IN", /* Punjabi India */ + "pag_PH", /* Pangasinan Philippines */ + "pam_PH", /* Pampanga Philippines */ + "pap_AN", /* Papiamento Netherlands Antilles */ + "pbb_CO", /* Páez Colombia */ + "pl_PL", /* Polish Poland */ + "ps_AF", /* Pashto Afghanistan */ + "pt_PT", /* Portuguese Portugal */ + "raj_IN", /* Rajasthani India */ + "rm_CH", /* Romansh Switzerland */ + "rn_BI", /* Kirundi Burundi */ + "ro_RO", /* Romanian Romania */ + "ru_RU", /* Russian Russia */ + "sa_IN", /* Sanskrit India */ + "sas_ID", /* Sasak Indonesia */ + "sat_IN", /* Santali India */ + "sc_IT", /* Sardinian Italy */ + "scn_IT", /* Sicilian Italy */ + "sg_CF", /* Sango Central African Republic */ + "shn_MM", /* Shan Myanmar */ + "si_LK", /* Sinhala Sri Lanka */ + "sid_ET", /* Sidamo Ethiopia */ + "sk_SK", /* Slovak Slovakia */ + "sl_SI", /* Slovenian Slovenia */ + "so_SO", /* Somali Somalia */ + "sq_AL", /* Albanian Albania */ + "sr_RS", /* Serbian Serbia */ + "sr_YU", /* Serbian Yugoslavia - this line can be removed in 2010 */ + "srr_SN", /* Serer Senegal */ + "suk_TZ", /* Sukuma Tanzania */ + "sus_GN", /* Susu Guinea */ + "sv_SE", /* Swedish Sweden */ + "te_IN", /* Telugu India */ + "tem_SL", /* Timne Sierra Leone */ + "tet_ID", /* Tetum Indonesia */ + "tg_TJ", /* Tajik Tajikistan */ + "th_TH", /* Thai Thailand */ + "tiv_NG", /* Tiv Nigeria */ + "tk_TM", /* Turkmen Turkmenistan */ + "tl_PH", /* Tagalog Philippines */ + "to_TO", /* Tonga Tonga */ + "tr_TR", /* Turkish Turkey */ + "tum_MW", /* Tumbuka Malawi */ + "ug_CN", /* Uighur China */ + "uk_UA", /* Ukrainian Ukraine */ + "umb_AO", /* Umbundu Angola */ + "ur_PK", /* Urdu Pakistan */ + "uz_UZ", /* Uzbek Uzbekistan */ + "ve_ZA", /* Venda South Africa */ + "vi_VN", /* Vietnamese Vietnam */ + "wa_BE", /* Walloon Belgium */ + "wal_ET", /* Walamo Ethiopia */ + "war_PH", /* Waray Philippines */ + "wen_DE", /* Sorbian Germany */ + "yao_MW", /* Yao Malawi */ + "zap_MX" /* Zapotec Mexico */ }; const char *dot; size_t i; @@ -693,7 +693,7 @@ catalogname_for_locale (const char *locale) codeset_end = strpbrk (dot + 1, "_@"); if (codeset_end == NULL) - codeset_end = dot + strlen (dot); + codeset_end = dot + strlen (dot); shorter_locale = XNMALLOC (strlen (locale), char); memcpy (shorter_locale, locale, dot - locale); @@ -705,20 +705,20 @@ catalogname_for_locale (const char *locale) for (i = 0; i < SIZEOF (locales_with_principal_territory); i++) if (strcmp (locale, locales_with_principal_territory[i]) == 0) { - const char *language_end; - size_t len; - char *shorter_locale; - - language_end = strchr (locale, '_'); - if (language_end == NULL) - abort (); - - len = language_end - locale; - shorter_locale = XNMALLOC (len + 1, char); - memcpy (shorter_locale, locale, len); - shorter_locale[len] = '\0'; - locale = shorter_locale; - break; + const char *language_end; + size_t len; + char *shorter_locale; + + language_end = strchr (locale, '_'); + if (language_end == NULL) + abort (); + + len = language_end - locale; + shorter_locale = XNMALLOC (len + 1, char); + memcpy (shorter_locale, locale, len); + shorter_locale[len] = '\0'; + locale = shorter_locale; + break; } return locale; @@ -834,19 +834,19 @@ project_id (const char *header) last_space = strrchr (old_field, ' '); if (last_space != NULL) - { - while (last_space > old_field && last_space[-1] == ' ') - last_space--; - if (last_space > old_field) - { - size_t package_len = last_space - old_field; - char *package = XNMALLOC (package_len + 1, char); - memcpy (package, old_field, package_len); - package[package_len] = '\0'; - - return package; - } - } + { + while (last_space > old_field && last_space[-1] == ' ') + last_space--; + if (last_space > old_field) + { + size_t package_len = last_space - old_field; + char *package = XNMALLOC (package_len + 1, char); + memcpy (package, old_field, package_len); + package[package_len] = '\0'; + + return package; + } + } /* It contains no version, just a package name. */ return old_field; } @@ -862,7 +862,7 @@ project_id (const char *header) argv[1] = prog; argv[2] = NULL; child = create_pipe_in (prog, "/bin/sh", argv, DEV_NULL, false, true, false, - fd); + fd); if (child == -1) goto failed; @@ -892,7 +892,7 @@ project_id (const char *header) if (exitstatus != 0) { error (0, 0, _("%s subprocess failed with exit code %d"), - prog, exitstatus); + prog, exitstatus); goto failed; } @@ -937,7 +937,7 @@ project_id_version (const char *header) argv[2] = "yes"; argv[3] = NULL; child = create_pipe_in (prog, "/bin/sh", argv, DEV_NULL, false, true, false, - fd); + fd); if (child == -1) goto failed; @@ -967,7 +967,7 @@ project_id_version (const char *header) if (exitstatus != 0) { error (0, 0, _("%s subprocess failed with exit code %d"), - prog, exitstatus); + prog, exitstatus); goto failed; } @@ -1012,9 +1012,9 @@ get_user_pwd () errno = 0; userpasswd = getpwnam (username); if (userpasswd != NULL) - return userpasswd; + return userpasswd; if (errno != 0) - error (EXIT_FAILURE, errno, "getpwnam(\"%s\")", username); + error (EXIT_FAILURE, errno, "getpwnam(\"%s\")", username); } /* 2. attempt: getpwnam(getlogin()) */ @@ -1024,9 +1024,9 @@ get_user_pwd () errno = 0; userpasswd = getpwnam (username); if (userpasswd != NULL) - return userpasswd; + return userpasswd; if (errno != 0) - error (EXIT_FAILURE, errno, "getpwnam(\"%s\")", username); + error (EXIT_FAILURE, errno, "getpwnam(\"%s\")", username); } /* 3. attempt: getpwuid(getuid()) */ @@ -1060,7 +1060,7 @@ get_user_fullname () fullname = pwd->pw_gecos; fullname_end = strchr (fullname, ','); if (fullname_end == NULL) - fullname_end = fullname + strlen (fullname); + fullname_end = fullname + strlen (fullname); result = XNMALLOC (fullname_end - fullname + 1, char); memcpy (result, fullname, fullname_end - fullname); @@ -1097,7 +1097,7 @@ give you feedback about the translations, and so that maintainers can contact\n\ you in case of unexpected technical problems.\n"); argv[3] = NULL; child = create_pipe_in (prog, "/bin/sh", argv, DEV_NULL, false, true, false, - fd); + fd); if (child == -1) goto failed; @@ -1127,7 +1127,7 @@ you in case of unexpected technical problems.\n"); if (exitstatus != 0) { error (0, 0, _("%s subprocess failed with exit code %d"), - prog, exitstatus); + prog, exitstatus); goto failed; } @@ -1150,9 +1150,9 @@ last_translator () const char *email = get_user_email (); if (fullname != NULL) - return xasprintf ("%s <%s>", fullname, email); + return xasprintf ("%s <%s>", fullname, email); else - return xasprintf ("<%s>", email); + return xasprintf ("<%s>", email); } } @@ -1196,7 +1196,7 @@ language_team_address () argv[5] = (char *) language; argv[6] = NULL; child = create_pipe_in (prog, "/bin/sh", argv, DEV_NULL, false, true, false, - fd); + fd); if (child == -1) goto failed; @@ -1222,7 +1222,7 @@ language_team_address () if (exitstatus != 0) { error (0, 0, _("%s subprocess failed with exit code %d"), - prog, exitstatus); + prog, exitstatus); goto failed; } @@ -1245,9 +1245,9 @@ language_team () const char *address = language_team_address (); if (address != NULL && address[0] != '\0') - return xasprintf ("%s %s", englishname, address); + return xasprintf ("%s %s", englishname, address); else - return englishname; + return englishname; } } @@ -1286,13 +1286,13 @@ content_type (const char *header) const char *charsetstr = c_strstr (old_field, "charset="); if (charsetstr != NULL) - { - charsetstr += strlen ("charset="); - was_utf8 = (c_strcasecmp (charsetstr, "UTF-8") == 0); - } + { + charsetstr += strlen ("charset="); + was_utf8 = (c_strcasecmp (charsetstr, "UTF-8") == 0); + } } return xasprintf ("text/plain; charset=%s", - was_utf8 ? "UTF-8" : canonical_locale_charset ()); + was_utf8 ? "UTF-8" : canonical_locale_charset ()); } @@ -1357,30 +1357,30 @@ get_field (const char *header, const char *field) for (line = header;;) { if (strncmp (line, field, len) == 0 && line[len] == ':') - { - const char *value_start; - const char *value_end; - char *value; + { + const char *value_start; + const char *value_end; + char *value; - value_start = line + len + 1; - if (*value_start == ' ') - value_start++; - value_end = strchr (value_start, '\n'); - if (value_end == NULL) - value_end = value_start + strlen (value_start); + value_start = line + len + 1; + if (*value_start == ' ') + value_start++; + value_end = strchr (value_start, '\n'); + if (value_end == NULL) + value_end = value_start + strlen (value_start); - value = XNMALLOC (value_end - value_start + 1, char); - memcpy (value, value_start, value_end - value_start); - value[value_end - value_start] = '\0'; + value = XNMALLOC (value_end - value_start + 1, char); + memcpy (value, value_start, value_end - value_start); + value[value_end - value_start] = '\0'; - return value; - } + return value; + } line = strchr (line, '\n'); if (line != NULL) - line++; + line++; else - break; + break; } return NULL; @@ -1398,46 +1398,46 @@ put_field (const char *old_header, const char *field, const char *value) for (line = old_header;;) { if (strncmp (line, field, len) == 0 && line[len] == ':') - { - const char *value_start; - const char *value_end; - - value_start = line + len + 1; - if (*value_start == ' ') - value_start++; - value_end = strchr (value_start, '\n'); - if (value_end == NULL) - value_end = value_start + strlen (value_start); - - new_header = XNMALLOC (strlen (old_header) - - (value_end - value_start) - + strlen (value) - + (*value_end != '\n' ? 1 : 0) - + 1, - char); - p = new_header; - memcpy (p, old_header, value_start - old_header); - p += value_start - old_header; - memcpy (p, value, strlen (value)); - p += strlen (value); - if (*value_end != '\n') - *p++ = '\n'; - strcpy (p, value_end); - - return new_header; - } + { + const char *value_start; + const char *value_end; + + value_start = line + len + 1; + if (*value_start == ' ') + value_start++; + value_end = strchr (value_start, '\n'); + if (value_end == NULL) + value_end = value_start + strlen (value_start); + + new_header = XNMALLOC (strlen (old_header) + - (value_end - value_start) + + strlen (value) + + (*value_end != '\n' ? 1 : 0) + + 1, + char); + p = new_header; + memcpy (p, old_header, value_start - old_header); + p += value_start - old_header; + memcpy (p, value, strlen (value)); + p += strlen (value); + if (*value_end != '\n') + *p++ = '\n'; + strcpy (p, value_end); + + return new_header; + } line = strchr (line, '\n'); if (line != NULL) - line++; + line++; else - break; + break; } new_header = XNMALLOC (strlen (old_header) + 1 - + len + 2 + strlen (value) + 1 - + 1, - char); + + len + 2 + strlen (value) + 1 + + 1, + char); p = new_header; memcpy (p, old_header, strlen (old_header)); p += strlen (old_header); @@ -1479,7 +1479,7 @@ get_title () /* First, the English title. */ english = xasprintf ("%s translations for %%s package", - englishname_of_language ()); + englishname_of_language ()); /* Save LC_ALL, LANGUAGE, OUTPUT_CHARSET environment variables. */ @@ -1505,16 +1505,16 @@ get_title () { /* Fetch the translation. */ /* TRANSLATORS: "English" needs to be replaced by your language. - For example in it.po write "Traduzioni italiani ...", - *not* "Traduzioni inglesi ...". */ + For example in it.po write "Traduzioni italiani ...", + *not* "Traduzioni inglesi ...". */ msgid = N_("English translations for %s package"); result = gettext (msgid); if (result != msgid && strcmp (result, msgid) != 0) - /* Use the English and the foreign title. */ - result = xasprintf ("%s\n%s", english, result); + /* Use the English and the foreign title. */ + result = xasprintf ("%s\n%s", english, result); else - /* No translation found. Use the English title. */ - result = english; + /* No translation found. Use the English title. */ + result = english; } /* Restore LC_ALL, LANGUAGE, OUTPUT_CHARSET environment variables. */ @@ -1547,7 +1547,7 @@ get_title () subst[j][0] must not be the empty string. */ static const char * subst_string (const char *str, - unsigned int nsubst, const char *(*subst)[2]) + unsigned int nsubst, const char *(*subst)[2]) { if (nsubst > 0) { @@ -1558,36 +1558,36 @@ subst_string (const char *str, substlen = (size_t *) xmalloca (nsubst * sizeof (size_t)); for (j = 0; j < nsubst; j++) - { - substlen[j] = strlen (subst[j][0]); - if (substlen[j] == 0) - abort (); - } + { + substlen[j] = strlen (subst[j][0]); + if (substlen[j] == 0) + abort (); + } for (i = 0;;) - { - if (str[i] == '\0') - break; - for (j = 0; j < nsubst; j++) - if (*(str + i) == *subst[j][0] - && strncmp (str + i, subst[j][0], substlen[j]) == 0) - { - size_t replacement_len = strlen (subst[j][1]); - size_t new_len = strlen (str) - substlen[j] + replacement_len; - char *new_str = XNMALLOC (new_len + 1, char); - memcpy (new_str, str, i); - memcpy (new_str + i, subst[j][1], replacement_len); - strcpy (new_str + i + replacement_len, str + i + substlen[j]); - if (malloced != NULL) - free (malloced); - str = new_str; - malloced = new_str; - i += replacement_len; - break; - } - if (j == nsubst) - i++; - } + { + if (str[i] == '\0') + break; + for (j = 0; j < nsubst; j++) + if (*(str + i) == *subst[j][0] + && strncmp (str + i, subst[j][0], substlen[j]) == 0) + { + size_t replacement_len = strlen (subst[j][1]); + size_t new_len = strlen (str) - substlen[j] + replacement_len; + char *new_str = XNMALLOC (new_len + 1, char); + memcpy (new_str, str, i); + memcpy (new_str + i, subst[j][1], replacement_len); + strcpy (new_str + i + replacement_len, str + i + substlen[j]); + if (malloced != NULL) + free (malloced); + str = new_str; + malloced = new_str; + i += replacement_len; + break; + } + if (j == nsubst) + i++; + } freea (substlen); } @@ -1600,7 +1600,7 @@ subst_string (const char *str, must not be the empty string. */ static void subst_string_list (string_list_ty *slp, - unsigned int nsubst, const char *(*subst)[2]) + unsigned int nsubst, const char *(*subst)[2]) { size_t j; @@ -1626,74 +1626,74 @@ fill_header (msgdomain_list_ty *mdlp) message_list_ty *mlp = mdlp->item[k]->messages; if (mlp->nitems > 0) - { - message_ty *header_mp = NULL; - char *header; - - /* Search the header entry. */ - for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - header_mp = mlp->item[j]; - break; - } - - /* If it wasn't found, provide one. */ - if (header_mp == NULL) - { - static lex_pos_ty pos = { __FILE__, __LINE__ }; - - header_mp = message_alloc (NULL, "", NULL, "", 1, &pos); - message_list_prepend (mlp, header_mp); - } - - header = xstrdup (header_mp->msgstr); - - /* Fill in the fields. */ - for (i = 0; i < NFIELDS; i++) - { - if (field_value[i] == NULL) - field_value[i] = - (fields[i].getter1 != NULL - ? fields[i].getter1 (header) - : fields[i].getter0 ()); - - if (field_value[i] != NULL) - { - char *old_header = header; - header = put_field (header, fields[i].name, field_value[i]); - free (old_header); - } - } - - /* Replace the old translation in the header entry. */ - header_mp->msgstr = header; - header_mp->msgstr_len = strlen (header) + 1; - - /* Update the comments in the header entry. */ - if (header_mp->comment != NULL) - { - const char *subst[4][2]; - const char *id; - time_t now; - - id = project_id (header); - subst[0][0] = "SOME DESCRIPTIVE TITLE"; - subst[0][1] = xasprintf (get_title (), id, id); - subst[1][0] = "PACKAGE"; - subst[1][1] = id; - subst[2][0] = "FIRST AUTHOR "; - subst[2][1] = field_value[FIELD_LAST_TRANSLATOR]; - subst[3][0] = "YEAR"; - subst[3][1] = - xasprintf ("%d", - (time (&now), (localtime (&now))->tm_year + 1900)); - subst_string_list (header_mp->comment, SIZEOF (subst), subst); - } - - /* Finally remove the fuzzy attribute. */ - header_mp->is_fuzzy = false; - } + { + message_ty *header_mp = NULL; + char *header; + + /* Search the header entry. */ + for (j = 0; j < mlp->nitems; j++) + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + header_mp = mlp->item[j]; + break; + } + + /* If it wasn't found, provide one. */ + if (header_mp == NULL) + { + static lex_pos_ty pos = { __FILE__, __LINE__ }; + + header_mp = message_alloc (NULL, "", NULL, "", 1, &pos); + message_list_prepend (mlp, header_mp); + } + + header = xstrdup (header_mp->msgstr); + + /* Fill in the fields. */ + for (i = 0; i < NFIELDS; i++) + { + if (field_value[i] == NULL) + field_value[i] = + (fields[i].getter1 != NULL + ? fields[i].getter1 (header) + : fields[i].getter0 ()); + + if (field_value[i] != NULL) + { + char *old_header = header; + header = put_field (header, fields[i].name, field_value[i]); + free (old_header); + } + } + + /* Replace the old translation in the header entry. */ + header_mp->msgstr = header; + header_mp->msgstr_len = strlen (header) + 1; + + /* Update the comments in the header entry. */ + if (header_mp->comment != NULL) + { + const char *subst[4][2]; + const char *id; + time_t now; + + id = project_id (header); + subst[0][0] = "SOME DESCRIPTIVE TITLE"; + subst[0][1] = xasprintf (get_title (), id, id); + subst[1][0] = "PACKAGE"; + subst[1][1] = id; + subst[2][0] = "FIRST AUTHOR "; + subst[2][1] = field_value[FIELD_LAST_TRANSLATOR]; + subst[3][0] = "YEAR"; + subst[3][1] = + xasprintf ("%d", + (time (&now), (localtime (&now))->tm_year + 1900)); + subst_string_list (header_mp->comment, SIZEOF (subst), subst); + } + + /* Finally remove the fuzzy attribute. */ + header_mp->is_fuzzy = false; + } } return mdlp; @@ -1720,32 +1720,32 @@ update_msgstr_plurals (msgdomain_list_ty *mdlp) memset (untranslated_plural_msgstr, '\0', nplurals); for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - bool is_untranslated; - const char *p; - const char *pend; - - if (mp->msgid_plural != NULL) - { - /* Test if mp is untranslated. (It most likely is.) */ - is_untranslated = true; - for (p = mp->msgstr, pend = p + mp->msgstr_len; p < pend; p++) - if (*p != '\0') - { - is_untranslated = false; - break; - } - if (is_untranslated) - { - /* Change mp->msgstr_len consecutive empty strings into - nplurals consecutive empty strings. */ - if (nplurals > mp->msgstr_len) - mp->msgstr = untranslated_plural_msgstr; - mp->msgstr_len = nplurals; - } - } - } + { + message_ty *mp = mlp->item[j]; + bool is_untranslated; + const char *p; + const char *pend; + + if (mp->msgid_plural != NULL) + { + /* Test if mp is untranslated. (It most likely is.) */ + is_untranslated = true; + for (p = mp->msgstr, pend = p + mp->msgstr_len; p < pend; p++) + if (*p != '\0') + { + is_untranslated = false; + break; + } + if (is_untranslated) + { + /* Change mp->msgstr_len consecutive empty strings into + nplurals consecutive empty strings. */ + if (nplurals > mp->msgstr_len) + mp->msgstr = untranslated_plural_msgstr; + mp->msgstr_len = nplurals; + } + } + } } return mdlp; } diff --git a/gettext-tools/src/msgl-ascii.c b/gettext-tools/src/msgl-ascii.c index a6c021392..e3ca95304 100644 --- a/gettext-tools/src/msgl-ascii.c +++ b/gettext-tools/src/msgl-ascii.c @@ -46,7 +46,7 @@ is_ascii_string_list (string_list_ty *slp) if (slp != NULL) for (i = 0; i < slp->nitems; i++) if (!is_ascii_string (slp->item[i])) - return false; + return false; return true; } diff --git a/gettext-tools/src/msgl-cat.c b/gettext-tools/src/msgl-cat.c index 560a72191..4e243419a 100644 --- a/gettext-tools/src/msgl-cat.c +++ b/gettext-tools/src/msgl-cat.c @@ -71,8 +71,8 @@ is_message_selected (const message_ty *tmp) int used = (tmp->used >= 0 ? tmp->used : - tmp->used); return (is_header (tmp) - ? !omit_header /* keep the header entry */ - : (used > more_than && used < less_than)); + ? !omit_header /* keep the header entry */ + : (used > more_than && used < less_than)); } @@ -105,8 +105,8 @@ is_message_first_needed (const message_ty *mp) msgdomain_list_ty * catenate_msgdomain_list (string_list_ty *file_list, - catalog_input_format_ty input_syntax, - const char *to_code) + catalog_input_format_ty input_syntax, + const char *to_code) { const char * const *files = file_list->item; size_t nfiles = file_list->nitems; @@ -131,87 +131,87 @@ catenate_msgdomain_list (string_list_ty *file_list, canon_charsets[n] = XNMALLOC (mdlp->nitems, const char *); for (k = 0; k < mdlp->nitems; k++) - { - message_list_ty *mlp = mdlp->item[k]->messages; - const char *canon_from_code = NULL; - - if (mlp->nitems > 0) - { - for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *charsetstr = c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - char *charset; - const char *canon_charset; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - charset = (char *) xmalloca (len + 1); - memcpy (charset, charsetstr, len); - charset[len] = '\0'; - - canon_charset = po_charset_canonicalize (charset); - if (canon_charset == NULL) - { - /* Don't give an error for POT files, because - POT files usually contain only ASCII - msgids. */ - const char *filename = files[n]; - size_t filenamelen = strlen (filename); - - if (filenamelen >= 4 - && memcmp (filename + filenamelen - 4, - ".pot", 4) == 0 - && strcmp (charset, "CHARSET") == 0) - canon_charset = po_charset_ascii; - else - error (EXIT_FAILURE, 0, - _("\ + { + message_list_ty *mlp = mdlp->item[k]->messages; + const char *canon_from_code = NULL; + + if (mlp->nitems > 0) + { + for (j = 0; j < mlp->nitems; j++) + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *charsetstr = c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + char *charset; + const char *canon_charset; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + charset = (char *) xmalloca (len + 1); + memcpy (charset, charsetstr, len); + charset[len] = '\0'; + + canon_charset = po_charset_canonicalize (charset); + if (canon_charset == NULL) + { + /* Don't give an error for POT files, because + POT files usually contain only ASCII + msgids. */ + const char *filename = files[n]; + size_t filenamelen = strlen (filename); + + if (filenamelen >= 4 + && memcmp (filename + filenamelen - 4, + ".pot", 4) == 0 + && strcmp (charset, "CHARSET") == 0) + canon_charset = po_charset_ascii; + else + error (EXIT_FAILURE, 0, + _("\ present charset \"%s\" is not a portable encoding name"), - charset); - } + charset); + } - freea (charset); + freea (charset); - if (canon_from_code == NULL) - canon_from_code = canon_charset; - else if (canon_from_code != canon_charset) - error (EXIT_FAILURE, 0, - _("\ + if (canon_from_code == NULL) + canon_from_code = canon_charset; + else if (canon_from_code != canon_charset) + error (EXIT_FAILURE, 0, + _("\ two different charsets \"%s\" and \"%s\" in input file"), - canon_from_code, canon_charset); - } - } - } - if (canon_from_code == NULL) - { - if (is_ascii_message_list (mlp)) - canon_from_code = po_charset_ascii; - else if (mdlp->encoding != NULL) - canon_from_code = mdlp->encoding; - else - { - if (k == 0) - error (EXIT_FAILURE, 0, _("\ + canon_from_code, canon_charset); + } + } + } + if (canon_from_code == NULL) + { + if (is_ascii_message_list (mlp)) + canon_from_code = po_charset_ascii; + else if (mdlp->encoding != NULL) + canon_from_code = mdlp->encoding; + else + { + if (k == 0) + error (EXIT_FAILURE, 0, _("\ input file `%s' doesn't contain a header entry with a charset specification"), - files[n]); - else - error (EXIT_FAILURE, 0, _("\ + files[n]); + else + error (EXIT_FAILURE, 0, _("\ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset specification"), - mdlp->item[k]->domain, files[n]); - } - } - } - canon_charsets[n][k] = canon_from_code; - } + mdlp->item[k]->domain, files[n]); + } + } + } + canon_charsets[n][k] = canon_from_code; + } } /* Determine textual identifications of each file/domain combination. */ @@ -224,52 +224,52 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s identifications[n] = XNMALLOC (mdlp->nitems, const char *); for (k = 0; k < mdlp->nitems; k++) - { - const char *domain = mdlp->item[k]->domain; - message_list_ty *mlp = mdlp->item[k]->messages; - char *project_id = NULL; - - for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *cp = c_strstr (header, "Project-Id-Version:"); - - if (cp != NULL) - { - const char *endp; - - cp += sizeof ("Project-Id-Version:") - 1; - - endp = strchr (cp, '\n'); - if (endp == NULL) - endp = cp + strlen (cp); - - while (cp < endp && *cp == ' ') - cp++; - - if (cp < endp) - { - size_t len = endp - cp; - project_id = XNMALLOC (len + 1, char); - memcpy (project_id, cp, len); - project_id[len] = '\0'; - } - break; - } - } - } - - identifications[n][k] = - (project_id != NULL - ? (k > 0 ? xasprintf ("%s:%s (%s)", filename, domain, project_id) - : xasprintf ("%s (%s)", filename, project_id)) - : (k > 0 ? xasprintf ("%s:%s", filename, domain) - : xasprintf ("%s", filename))); - } + { + const char *domain = mdlp->item[k]->domain; + message_list_ty *mlp = mdlp->item[k]->messages; + char *project_id = NULL; + + for (j = 0; j < mlp->nitems; j++) + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *cp = c_strstr (header, "Project-Id-Version:"); + + if (cp != NULL) + { + const char *endp; + + cp += sizeof ("Project-Id-Version:") - 1; + + endp = strchr (cp, '\n'); + if (endp == NULL) + endp = cp + strlen (cp); + + while (cp < endp && *cp == ' ') + cp++; + + if (cp < endp) + { + size_t len = endp - cp; + project_id = XNMALLOC (len + 1, char); + memcpy (project_id, cp, len); + project_id[len] = '\0'; + } + break; + } + } + } + + identifications[n][k] = + (project_id != NULL + ? (k > 0 ? xasprintf ("%s:%s (%s)", filename, domain, project_id) + : xasprintf ("%s (%s)", filename, project_id)) + : (k > 0 ? xasprintf ("%s:%s", filename, domain) + : xasprintf ("%s", filename))); + } } /* Create list of resulting messages, but don't fill it. Only count @@ -284,54 +284,54 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s size_t k; for (k = 0; k < mdlp->nitems; k++) - { - const char *domain = mdlp->item[k]->domain; - message_list_ty *mlp = mdlp->item[k]->messages; - message_list_ty *total_mlp; - - total_mlp = msgdomain_list_sublist (total_mdlp, domain, true); - - for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - message_ty *tmp; - size_t i; - - tmp = message_list_search (total_mlp, mp->msgctxt, mp->msgid); - if (tmp == NULL) - { - tmp = message_alloc (mp->msgctxt, mp->msgid, mp->msgid_plural, - NULL, 0, &mp->pos); - tmp->is_fuzzy = true; /* may be set to false later */ - for (i = 0; i < NFORMATS; i++) - tmp->is_format[i] = undecided; /* may be set to yes/no later */ - tmp->range.min = - INT_MAX; - tmp->range.max = - INT_MAX; - tmp->do_wrap = yes; /* may be set to no later */ - tmp->obsolete = true; /* may be set to false later */ - tmp->alternative_count = 0; - tmp->alternative = NULL; - message_list_append (total_mlp, tmp); - } - - if (!msgcomm_mode - && ((!is_header (mp) && mp->is_fuzzy) - || mp->msgstr[0] == '\0')) - /* Weak translation. Counted as negative tmp->used. */ - { - if (tmp->used <= 0) - tmp->used--; - } - else - /* Good translation. Counted as positive tmp->used. */ - { - if (tmp->used < 0) - tmp->used = 0; - tmp->used++; - } - mp->tmp = tmp; - } - } + { + const char *domain = mdlp->item[k]->domain; + message_list_ty *mlp = mdlp->item[k]->messages; + message_list_ty *total_mlp; + + total_mlp = msgdomain_list_sublist (total_mdlp, domain, true); + + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + message_ty *tmp; + size_t i; + + tmp = message_list_search (total_mlp, mp->msgctxt, mp->msgid); + if (tmp == NULL) + { + tmp = message_alloc (mp->msgctxt, mp->msgid, mp->msgid_plural, + NULL, 0, &mp->pos); + tmp->is_fuzzy = true; /* may be set to false later */ + for (i = 0; i < NFORMATS; i++) + tmp->is_format[i] = undecided; /* may be set to yes/no later */ + tmp->range.min = - INT_MAX; + tmp->range.max = - INT_MAX; + tmp->do_wrap = yes; /* may be set to no later */ + tmp->obsolete = true; /* may be set to false later */ + tmp->alternative_count = 0; + tmp->alternative = NULL; + message_list_append (total_mlp, tmp); + } + + if (!msgcomm_mode + && ((!is_header (mp) && mp->is_fuzzy) + || mp->msgstr[0] == '\0')) + /* Weak translation. Counted as negative tmp->used. */ + { + if (tmp->used <= 0) + tmp->used--; + } + else + /* Good translation. Counted as positive tmp->used. */ + { + if (tmp->used < 0) + tmp->used = 0; + tmp->used++; + } + mp->tmp = tmp; + } + } } /* Remove messages that are not used and need not be converted. */ @@ -341,27 +341,27 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s size_t k; for (k = 0; k < mdlp->nitems; k++) - { - message_list_ty *mlp = mdlp->item[k]->messages; - - message_list_remove_if_not (mlp, - use_first - ? is_message_first_needed - : is_message_needed); - - /* If no messages are remaining, drop the charset. */ - if (mlp->nitems == 0) - canon_charsets[n][k] = NULL; - } + { + message_list_ty *mlp = mdlp->item[k]->messages; + + message_list_remove_if_not (mlp, + use_first + ? is_message_first_needed + : is_message_needed); + + /* If no messages are remaining, drop the charset. */ + if (mlp->nitems == 0) + canon_charsets[n][k] = NULL; + } } { size_t k; for (k = 0; k < total_mdlp->nitems; k++) { - message_list_ty *mlp = total_mdlp->item[k]->messages; + message_list_ty *mlp = total_mdlp->item[k]->messages; - message_list_remove_if_not (mlp, is_message_selected); + message_list_remove_if_not (mlp, is_message_selected); } } @@ -371,14 +371,14 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s bool all_same_encoding = true; for (n = 1; n < nfiles; n++) - if (mdlps[n]->encoding != mdlps[0]->encoding) - { - all_same_encoding = false; - break; - } + if (mdlps[n]->encoding != mdlps[0]->encoding) + { + all_same_encoding = false; + break; + } if (all_same_encoding) - total_mdlp->encoding = mdlps[0]->encoding; + total_mdlp->encoding = mdlps[0]->encoding; } /* Determine the target encoding for the remaining messages. */ @@ -387,14 +387,14 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s /* Canonicalize target encoding. */ canon_to_code = po_charset_canonicalize (to_code); if (canon_to_code == NULL) - error (EXIT_FAILURE, 0, - _("target charset \"%s\" is not a portable encoding name."), - to_code); + error (EXIT_FAILURE, 0, + _("target charset \"%s\" is not a portable encoding name."), + to_code); } else { /* No target encoding was specified. Test whether the messages are - all in a single encoding. If so, conversion is not needed. */ + all in a single encoding. If so, conversion is not needed. */ const char *first = NULL; const char *second = NULL; bool with_ASCII = false; @@ -402,98 +402,98 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s bool all_ASCII_compatible = true; for (n = 0; n < nfiles; n++) - { - msgdomain_list_ty *mdlp = mdlps[n]; - size_t k; - - for (k = 0; k < mdlp->nitems; k++) - if (canon_charsets[n][k] != NULL) - { - if (canon_charsets[n][k] == po_charset_ascii) - with_ASCII = true; - else - { - if (first == NULL) - first = canon_charsets[n][k]; - else if (canon_charsets[n][k] != first && second == NULL) - second = canon_charsets[n][k]; - - if (strcmp (canon_charsets[n][k], "UTF-8") == 0) - with_UTF8 = true; - - if (!po_charset_ascii_compatible (canon_charsets[n][k])) - all_ASCII_compatible = false; - } - } - } + { + msgdomain_list_ty *mdlp = mdlps[n]; + size_t k; + + for (k = 0; k < mdlp->nitems; k++) + if (canon_charsets[n][k] != NULL) + { + if (canon_charsets[n][k] == po_charset_ascii) + with_ASCII = true; + else + { + if (first == NULL) + first = canon_charsets[n][k]; + else if (canon_charsets[n][k] != first && second == NULL) + second = canon_charsets[n][k]; + + if (strcmp (canon_charsets[n][k], "UTF-8") == 0) + with_UTF8 = true; + + if (!po_charset_ascii_compatible (canon_charsets[n][k])) + all_ASCII_compatible = false; + } + } + } if (with_ASCII && !all_ASCII_compatible) - { - /* assert (first != NULL); */ - if (second == NULL) - second = po_charset_ascii; - } + { + /* assert (first != NULL); */ + if (second == NULL) + second = po_charset_ascii; + } if (second != NULL) - { - /* A conversion is needed. Warn the user since he hasn't asked - for it and might be surprised. */ - if (with_UTF8) - multiline_warning (xasprintf (_("warning: ")), - xasprintf (_("\ + { + /* A conversion is needed. Warn the user since he hasn't asked + for it and might be surprised. */ + if (with_UTF8) + multiline_warning (xasprintf (_("warning: ")), + xasprintf (_("\ Input files contain messages in different encodings, UTF-8 among others.\n\ Converting the output to UTF-8.\n\ "))); - else - multiline_warning (xasprintf (_("warning: ")), - xasprintf (_("\ + else + multiline_warning (xasprintf (_("warning: ")), + xasprintf (_("\ Input files contain messages in different encodings, %s and %s among others.\n\ Converting the output to UTF-8.\n\ To select a different output encoding, use the --to-code option.\n\ "), first, second)); - canon_to_code = po_charset_utf8; - } + canon_to_code = po_charset_utf8; + } else if (first != NULL && with_ASCII && all_ASCII_compatible) - { - /* The conversion is a no-op conversion. Don't warn the user, - but still perform the conversion, in order to check that the - input was really ASCII. */ - canon_to_code = first; - } + { + /* The conversion is a no-op conversion. Don't warn the user, + but still perform the conversion, in order to check that the + input was really ASCII. */ + canon_to_code = first; + } else - { - /* No conversion needed. */ - canon_to_code = NULL; - } + { + /* No conversion needed. */ + canon_to_code = NULL; + } } /* Now convert the remaining messages to to_code. */ if (canon_to_code != NULL) for (n = 0; n < nfiles; n++) { - msgdomain_list_ty *mdlp = mdlps[n]; - size_t k; - - for (k = 0; k < mdlp->nitems; k++) - if (canon_charsets[n][k] != NULL) - /* If the user hasn't given a to_code, don't bother doing a noop - conversion that would only replace the charset name in the - header entry with its canonical equivalent. */ - if (!(to_code == NULL && canon_charsets[n][k] == canon_to_code)) - if (iconv_message_list (mdlp->item[k]->messages, - canon_charsets[n][k], canon_to_code, - files[n])) - { - multiline_error (xstrdup (""), - xasprintf (_("\ + msgdomain_list_ty *mdlp = mdlps[n]; + size_t k; + + for (k = 0; k < mdlp->nitems; k++) + if (canon_charsets[n][k] != NULL) + /* If the user hasn't given a to_code, don't bother doing a noop + conversion that would only replace the charset name in the + header entry with its canonical equivalent. */ + if (!(to_code == NULL && canon_charsets[n][k] == canon_to_code)) + if (iconv_message_list (mdlp->item[k]->messages, + canon_charsets[n][k], canon_to_code, + files[n])) + { + multiline_error (xstrdup (""), + xasprintf (_("\ Conversion of file %s from %s encoding to %s encoding\n\ changes some msgids or msgctxts.\n\ Either change all msgids and msgctxts to be pure ASCII, or ensure they are\n\ UTF-8 encoded from the beginning, i.e. already in your source code files.\n"), - files[n], canon_charsets[n][k], - canon_to_code)); - exit (EXIT_FAILURE); - } + files[n], canon_charsets[n][k], + canon_to_code)); + exit (EXIT_FAILURE); + } } /* Fill the resulting messages. */ @@ -503,295 +503,295 @@ UTF-8 encoded from the beginning, i.e. already in your source code files.\n"), size_t k; for (k = 0; k < mdlp->nitems; k++) - { - message_list_ty *mlp = mdlp->item[k]->messages; - - for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - message_ty *tmp = mp->tmp; - size_t i; - - /* No need to discard unneeded weak translations here; - they have already been filtered out above. */ - if (use_first || tmp->used == 1 || tmp->used == -1) - { - /* Copy mp, as only message, into tmp. */ - tmp->msgstr = mp->msgstr; - tmp->msgstr_len = mp->msgstr_len; - tmp->pos = mp->pos; - if (mp->comment) - for (i = 0; i < mp->comment->nitems; i++) - message_comment_append (tmp, mp->comment->item[i]); - if (mp->comment_dot) - for (i = 0; i < mp->comment_dot->nitems; i++) - message_comment_dot_append (tmp, - mp->comment_dot->item[i]); - for (i = 0; i < mp->filepos_count; i++) - message_comment_filepos (tmp, mp->filepos[i].file_name, - mp->filepos[i].line_number); - tmp->is_fuzzy = mp->is_fuzzy; - for (i = 0; i < NFORMATS; i++) - tmp->is_format[i] = mp->is_format[i]; - tmp->range = mp->range; - tmp->do_wrap = mp->do_wrap; - tmp->prev_msgctxt = mp->prev_msgctxt; - tmp->prev_msgid = mp->prev_msgid; - tmp->prev_msgid_plural = mp->prev_msgid_plural; - tmp->obsolete = mp->obsolete; - } - else if (msgcomm_mode) - { - /* Copy mp, as only message, into tmp. */ - if (tmp->msgstr == NULL) - { - tmp->msgstr = mp->msgstr; - tmp->msgstr_len = mp->msgstr_len; - tmp->pos = mp->pos; - tmp->is_fuzzy = mp->is_fuzzy; - tmp->prev_msgctxt = mp->prev_msgctxt; - tmp->prev_msgid = mp->prev_msgid; - tmp->prev_msgid_plural = mp->prev_msgid_plural; - } - if (mp->comment && tmp->comment == NULL) - for (i = 0; i < mp->comment->nitems; i++) - message_comment_append (tmp, mp->comment->item[i]); - if (mp->comment_dot && tmp->comment_dot == NULL) - for (i = 0; i < mp->comment_dot->nitems; i++) - message_comment_dot_append (tmp, - mp->comment_dot->item[i]); - for (i = 0; i < mp->filepos_count; i++) - message_comment_filepos (tmp, mp->filepos[i].file_name, - mp->filepos[i].line_number); - for (i = 0; i < NFORMATS; i++) - if (tmp->is_format[i] == undecided) - tmp->is_format[i] = mp->is_format[i]; - if (tmp->range.min == - INT_MAX - && tmp->range.max == - INT_MAX) - tmp->range = mp->range; - else if (has_range_p (mp->range) && has_range_p (tmp->range)) - { - if (mp->range.min < tmp->range.min) - tmp->range.min = mp->range.min; - if (mp->range.max > tmp->range.max) - tmp->range.max = mp->range.max; - } - else - { - tmp->range.min = -1; - tmp->range.max = -1; - } - if (tmp->do_wrap == undecided) - tmp->do_wrap = mp->do_wrap; - tmp->obsolete = false; - } - else - { - /* Copy mp, among others, into tmp. */ - char *id = xasprintf ("#-#-#-#-# %s #-#-#-#-#", - identifications[n][k]); - size_t nbytes; - - if (tmp->alternative_count == 0) - tmp->pos = mp->pos; - - i = tmp->alternative_count; - nbytes = (i + 1) * sizeof (struct altstr); - tmp->alternative = xrealloc (tmp->alternative, nbytes); - tmp->alternative[i].msgstr = mp->msgstr; - tmp->alternative[i].msgstr_len = mp->msgstr_len; - tmp->alternative[i].msgstr_end = - tmp->alternative[i].msgstr + tmp->alternative[i].msgstr_len; - tmp->alternative[i].comment = mp->comment; - tmp->alternative[i].comment_dot = mp->comment_dot; - tmp->alternative[i].id = id; - tmp->alternative_count = i + 1; - - for (i = 0; i < mp->filepos_count; i++) - message_comment_filepos (tmp, mp->filepos[i].file_name, - mp->filepos[i].line_number); - if (!mp->is_fuzzy) - tmp->is_fuzzy = false; - for (i = 0; i < NFORMATS; i++) - if (mp->is_format[i] == yes) - tmp->is_format[i] = yes; - else if (mp->is_format[i] == no - && tmp->is_format[i] == undecided) - tmp->is_format[i] = no; - if (tmp->range.min == - INT_MAX - && tmp->range.max == - INT_MAX) - tmp->range = mp->range; - else if (has_range_p (mp->range) && has_range_p (tmp->range)) - { - if (mp->range.min < tmp->range.min) - tmp->range.min = mp->range.min; - if (mp->range.max > tmp->range.max) - tmp->range.max = mp->range.max; - } - else - { - tmp->range.min = -1; - tmp->range.max = -1; - } - if (mp->do_wrap == no) - tmp->do_wrap = no; - /* Don't fill tmp->prev_msgid in this case. */ - if (!mp->obsolete) - tmp->obsolete = false; - } - } - } + { + message_list_ty *mlp = mdlp->item[k]->messages; + + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + message_ty *tmp = mp->tmp; + size_t i; + + /* No need to discard unneeded weak translations here; + they have already been filtered out above. */ + if (use_first || tmp->used == 1 || tmp->used == -1) + { + /* Copy mp, as only message, into tmp. */ + tmp->msgstr = mp->msgstr; + tmp->msgstr_len = mp->msgstr_len; + tmp->pos = mp->pos; + if (mp->comment) + for (i = 0; i < mp->comment->nitems; i++) + message_comment_append (tmp, mp->comment->item[i]); + if (mp->comment_dot) + for (i = 0; i < mp->comment_dot->nitems; i++) + message_comment_dot_append (tmp, + mp->comment_dot->item[i]); + for (i = 0; i < mp->filepos_count; i++) + message_comment_filepos (tmp, mp->filepos[i].file_name, + mp->filepos[i].line_number); + tmp->is_fuzzy = mp->is_fuzzy; + for (i = 0; i < NFORMATS; i++) + tmp->is_format[i] = mp->is_format[i]; + tmp->range = mp->range; + tmp->do_wrap = mp->do_wrap; + tmp->prev_msgctxt = mp->prev_msgctxt; + tmp->prev_msgid = mp->prev_msgid; + tmp->prev_msgid_plural = mp->prev_msgid_plural; + tmp->obsolete = mp->obsolete; + } + else if (msgcomm_mode) + { + /* Copy mp, as only message, into tmp. */ + if (tmp->msgstr == NULL) + { + tmp->msgstr = mp->msgstr; + tmp->msgstr_len = mp->msgstr_len; + tmp->pos = mp->pos; + tmp->is_fuzzy = mp->is_fuzzy; + tmp->prev_msgctxt = mp->prev_msgctxt; + tmp->prev_msgid = mp->prev_msgid; + tmp->prev_msgid_plural = mp->prev_msgid_plural; + } + if (mp->comment && tmp->comment == NULL) + for (i = 0; i < mp->comment->nitems; i++) + message_comment_append (tmp, mp->comment->item[i]); + if (mp->comment_dot && tmp->comment_dot == NULL) + for (i = 0; i < mp->comment_dot->nitems; i++) + message_comment_dot_append (tmp, + mp->comment_dot->item[i]); + for (i = 0; i < mp->filepos_count; i++) + message_comment_filepos (tmp, mp->filepos[i].file_name, + mp->filepos[i].line_number); + for (i = 0; i < NFORMATS; i++) + if (tmp->is_format[i] == undecided) + tmp->is_format[i] = mp->is_format[i]; + if (tmp->range.min == - INT_MAX + && tmp->range.max == - INT_MAX) + tmp->range = mp->range; + else if (has_range_p (mp->range) && has_range_p (tmp->range)) + { + if (mp->range.min < tmp->range.min) + tmp->range.min = mp->range.min; + if (mp->range.max > tmp->range.max) + tmp->range.max = mp->range.max; + } + else + { + tmp->range.min = -1; + tmp->range.max = -1; + } + if (tmp->do_wrap == undecided) + tmp->do_wrap = mp->do_wrap; + tmp->obsolete = false; + } + else + { + /* Copy mp, among others, into tmp. */ + char *id = xasprintf ("#-#-#-#-# %s #-#-#-#-#", + identifications[n][k]); + size_t nbytes; + + if (tmp->alternative_count == 0) + tmp->pos = mp->pos; + + i = tmp->alternative_count; + nbytes = (i + 1) * sizeof (struct altstr); + tmp->alternative = xrealloc (tmp->alternative, nbytes); + tmp->alternative[i].msgstr = mp->msgstr; + tmp->alternative[i].msgstr_len = mp->msgstr_len; + tmp->alternative[i].msgstr_end = + tmp->alternative[i].msgstr + tmp->alternative[i].msgstr_len; + tmp->alternative[i].comment = mp->comment; + tmp->alternative[i].comment_dot = mp->comment_dot; + tmp->alternative[i].id = id; + tmp->alternative_count = i + 1; + + for (i = 0; i < mp->filepos_count; i++) + message_comment_filepos (tmp, mp->filepos[i].file_name, + mp->filepos[i].line_number); + if (!mp->is_fuzzy) + tmp->is_fuzzy = false; + for (i = 0; i < NFORMATS; i++) + if (mp->is_format[i] == yes) + tmp->is_format[i] = yes; + else if (mp->is_format[i] == no + && tmp->is_format[i] == undecided) + tmp->is_format[i] = no; + if (tmp->range.min == - INT_MAX + && tmp->range.max == - INT_MAX) + tmp->range = mp->range; + else if (has_range_p (mp->range) && has_range_p (tmp->range)) + { + if (mp->range.min < tmp->range.min) + tmp->range.min = mp->range.min; + if (mp->range.max > tmp->range.max) + tmp->range.max = mp->range.max; + } + else + { + tmp->range.min = -1; + tmp->range.max = -1; + } + if (mp->do_wrap == no) + tmp->do_wrap = no; + /* Don't fill tmp->prev_msgid in this case. */ + if (!mp->obsolete) + tmp->obsolete = false; + } + } + } } { size_t k; for (k = 0; k < total_mdlp->nitems; k++) { - message_list_ty *mlp = total_mdlp->item[k]->messages; - - for (j = 0; j < mlp->nitems; j++) - { - message_ty *tmp = mlp->item[j]; - - if (tmp->alternative_count > 0) - { - /* Test whether all alternative translations are equal. */ - struct altstr *first = &tmp->alternative[0]; - size_t i; - - for (i = 0; i < tmp->alternative_count; i++) - if (!(tmp->alternative[i].msgstr_len == first->msgstr_len - && memcmp (tmp->alternative[i].msgstr, first->msgstr, - first->msgstr_len) == 0)) - break; - - if (i == tmp->alternative_count) - { - /* All alternatives are equal. */ - tmp->msgstr = first->msgstr; - tmp->msgstr_len = first->msgstr_len; - } - else - { - /* Concatenate the alternative msgstrs into a single one, - separated by markers. */ - size_t len; - const char *p; - const char *p_end; - char *new_msgstr; - char *np; - - len = 0; - for (i = 0; i < tmp->alternative_count; i++) - { - size_t id_len = strlen (tmp->alternative[i].id); - - len += tmp->alternative[i].msgstr_len; - - p = tmp->alternative[i].msgstr; - p_end = tmp->alternative[i].msgstr_end; - for (; p < p_end; p += strlen (p) + 1) - len += id_len + 2; - } - - new_msgstr = XNMALLOC (len, char); - np = new_msgstr; - for (;;) - { - /* Test whether there's one more plural form to - process. */ - for (i = 0; i < tmp->alternative_count; i++) - if (tmp->alternative[i].msgstr - < tmp->alternative[i].msgstr_end) - break; - if (i == tmp->alternative_count) - break; - - /* Process next plural form. */ - for (i = 0; i < tmp->alternative_count; i++) - if (tmp->alternative[i].msgstr - < tmp->alternative[i].msgstr_end) - { - if (np > new_msgstr && np[-1] != '\0' - && np[-1] != '\n') - *np++ = '\n'; - - len = strlen (tmp->alternative[i].id); - memcpy (np, tmp->alternative[i].id, len); - np += len; - *np++ = '\n'; - - len = strlen (tmp->alternative[i].msgstr); - memcpy (np, tmp->alternative[i].msgstr, len); - np += len; - tmp->alternative[i].msgstr += len + 1; - } - - /* Plural forms are separated by NUL bytes. */ - *np++ = '\0'; - } - tmp->msgstr = new_msgstr; - tmp->msgstr_len = np - new_msgstr; - - tmp->is_fuzzy = true; - } - - /* Test whether all alternative comments are equal. */ - for (i = 0; i < tmp->alternative_count; i++) - if (tmp->alternative[i].comment == NULL - || !string_list_equal (tmp->alternative[i].comment, - first->comment)) - break; - - if (i == tmp->alternative_count) - /* All alternatives are equal. */ - tmp->comment = first->comment; - else - /* Concatenate the alternative comments into a single one, - separated by markers. */ - for (i = 0; i < tmp->alternative_count; i++) - { - string_list_ty *slp = tmp->alternative[i].comment; - - if (slp != NULL) - { - size_t l; - - message_comment_append (tmp, tmp->alternative[i].id); - for (l = 0; l < slp->nitems; l++) - message_comment_append (tmp, slp->item[l]); - } - } - - /* Test whether all alternative dot comments are equal. */ - for (i = 0; i < tmp->alternative_count; i++) - if (tmp->alternative[i].comment_dot == NULL - || !string_list_equal (tmp->alternative[i].comment_dot, - first->comment_dot)) - break; - - if (i == tmp->alternative_count) - /* All alternatives are equal. */ - tmp->comment_dot = first->comment_dot; - else - /* Concatenate the alternative dot comments into a single one, - separated by markers. */ - for (i = 0; i < tmp->alternative_count; i++) - { - string_list_ty *slp = tmp->alternative[i].comment_dot; - - if (slp != NULL) - { - size_t l; - - message_comment_dot_append (tmp, - tmp->alternative[i].id); - for (l = 0; l < slp->nitems; l++) - message_comment_dot_append (tmp, slp->item[l]); - } - } - } - } + message_list_ty *mlp = total_mdlp->item[k]->messages; + + for (j = 0; j < mlp->nitems; j++) + { + message_ty *tmp = mlp->item[j]; + + if (tmp->alternative_count > 0) + { + /* Test whether all alternative translations are equal. */ + struct altstr *first = &tmp->alternative[0]; + size_t i; + + for (i = 0; i < tmp->alternative_count; i++) + if (!(tmp->alternative[i].msgstr_len == first->msgstr_len + && memcmp (tmp->alternative[i].msgstr, first->msgstr, + first->msgstr_len) == 0)) + break; + + if (i == tmp->alternative_count) + { + /* All alternatives are equal. */ + tmp->msgstr = first->msgstr; + tmp->msgstr_len = first->msgstr_len; + } + else + { + /* Concatenate the alternative msgstrs into a single one, + separated by markers. */ + size_t len; + const char *p; + const char *p_end; + char *new_msgstr; + char *np; + + len = 0; + for (i = 0; i < tmp->alternative_count; i++) + { + size_t id_len = strlen (tmp->alternative[i].id); + + len += tmp->alternative[i].msgstr_len; + + p = tmp->alternative[i].msgstr; + p_end = tmp->alternative[i].msgstr_end; + for (; p < p_end; p += strlen (p) + 1) + len += id_len + 2; + } + + new_msgstr = XNMALLOC (len, char); + np = new_msgstr; + for (;;) + { + /* Test whether there's one more plural form to + process. */ + for (i = 0; i < tmp->alternative_count; i++) + if (tmp->alternative[i].msgstr + < tmp->alternative[i].msgstr_end) + break; + if (i == tmp->alternative_count) + break; + + /* Process next plural form. */ + for (i = 0; i < tmp->alternative_count; i++) + if (tmp->alternative[i].msgstr + < tmp->alternative[i].msgstr_end) + { + if (np > new_msgstr && np[-1] != '\0' + && np[-1] != '\n') + *np++ = '\n'; + + len = strlen (tmp->alternative[i].id); + memcpy (np, tmp->alternative[i].id, len); + np += len; + *np++ = '\n'; + + len = strlen (tmp->alternative[i].msgstr); + memcpy (np, tmp->alternative[i].msgstr, len); + np += len; + tmp->alternative[i].msgstr += len + 1; + } + + /* Plural forms are separated by NUL bytes. */ + *np++ = '\0'; + } + tmp->msgstr = new_msgstr; + tmp->msgstr_len = np - new_msgstr; + + tmp->is_fuzzy = true; + } + + /* Test whether all alternative comments are equal. */ + for (i = 0; i < tmp->alternative_count; i++) + if (tmp->alternative[i].comment == NULL + || !string_list_equal (tmp->alternative[i].comment, + first->comment)) + break; + + if (i == tmp->alternative_count) + /* All alternatives are equal. */ + tmp->comment = first->comment; + else + /* Concatenate the alternative comments into a single one, + separated by markers. */ + for (i = 0; i < tmp->alternative_count; i++) + { + string_list_ty *slp = tmp->alternative[i].comment; + + if (slp != NULL) + { + size_t l; + + message_comment_append (tmp, tmp->alternative[i].id); + for (l = 0; l < slp->nitems; l++) + message_comment_append (tmp, slp->item[l]); + } + } + + /* Test whether all alternative dot comments are equal. */ + for (i = 0; i < tmp->alternative_count; i++) + if (tmp->alternative[i].comment_dot == NULL + || !string_list_equal (tmp->alternative[i].comment_dot, + first->comment_dot)) + break; + + if (i == tmp->alternative_count) + /* All alternatives are equal. */ + tmp->comment_dot = first->comment_dot; + else + /* Concatenate the alternative dot comments into a single one, + separated by markers. */ + for (i = 0; i < tmp->alternative_count; i++) + { + string_list_ty *slp = tmp->alternative[i].comment_dot; + + if (slp != NULL) + { + size_t l; + + message_comment_dot_append (tmp, + tmp->alternative[i].id); + for (l = 0; l < slp->nitems; l++) + message_comment_dot_append (tmp, slp->item[l]); + } + } + } + } } } diff --git a/gettext-tools/src/msgl-cat.h b/gettext-tools/src/msgl-cat.h index 191a5689b..4de35d575 100644 --- a/gettext-tools/src/msgl-cat.h +++ b/gettext-tools/src/msgl-cat.h @@ -48,8 +48,8 @@ extern DLL_VARIABLE bool omit_header; extern msgdomain_list_ty * catenate_msgdomain_list (string_list_ty *file_list, - catalog_input_format_ty input_syntax, - const char *to_code); + catalog_input_format_ty input_syntax, + const char *to_code); #ifdef __cplusplus diff --git a/gettext-tools/src/msgl-charset.c b/gettext-tools/src/msgl-charset.c index dbf0a3467..e8deb58a0 100644 --- a/gettext-tools/src/msgl-charset.c +++ b/gettext-tools/src/msgl-charset.c @@ -60,72 +60,72 @@ compare_po_locale_charsets (const msgdomain_list_ty *mdlp) const message_list_ty *mlp = mdlp->item[k]->messages; for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *charsetstr = c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - char *charset; - const char *canon_charset; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - charset = (char *) xmalloca (len + 1); - memcpy (charset, charsetstr, len); - charset[len] = '\0'; - - canon_charset = po_charset_canonicalize (charset); - if (canon_charset == NULL) - error (EXIT_FAILURE, 0, - _("\ + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *charsetstr = c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + char *charset; + const char *canon_charset; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + charset = (char *) xmalloca (len + 1); + memcpy (charset, charsetstr, len); + charset[len] = '\0'; + + canon_charset = po_charset_canonicalize (charset); + if (canon_charset == NULL) + error (EXIT_FAILURE, 0, + _("\ present charset \"%s\" is not a portable encoding name"), - charset); - freea (charset); - if (canon_locale_code != canon_charset) - { - multiline_warning (xasprintf (_("warning: ")), - xasprintf (_("\ + charset); + freea (charset); + if (canon_locale_code != canon_charset) + { + multiline_warning (xasprintf (_("warning: ")), + xasprintf (_("\ Locale charset \"%s\" is different from\n\ input file charset \"%s\".\n\ Output of '%s' might be incorrect.\n\ Possible workarounds are:\n\ "), locale_code, canon_charset, basename (program_name))); - multiline_warning (NULL, - xasprintf (_("\ + multiline_warning (NULL, + xasprintf (_("\ - Set LC_ALL to a locale with encoding %s.\n\ "), canon_charset)); - if (canon_locale_code != NULL) - multiline_warning (NULL, - xasprintf (_("\ + if (canon_locale_code != NULL) + multiline_warning (NULL, + xasprintf (_("\ - Convert the translation catalog to %s using 'msgconv',\n\ then apply '%s',\n\ then convert back to %s using 'msgconv'.\n\ "), canon_locale_code, basename (program_name), canon_charset)); - if (strcmp (canon_charset, "UTF-8") != 0 - && (canon_locale_code == NULL - || strcmp (canon_locale_code, "UTF-8") != 0)) - multiline_warning (NULL, - xasprintf (_("\ + if (strcmp (canon_charset, "UTF-8") != 0 + && (canon_locale_code == NULL + || strcmp (canon_locale_code, "UTF-8") != 0)) + multiline_warning (NULL, + xasprintf (_("\ - Set LC_ALL to a locale with encoding %s,\n\ convert the translation catalog to %s using 'msgconv',\n\ then apply '%s',\n\ then convert back to %s using 'msgconv'.\n\ "), "UTF-8", "UTF-8", basename (program_name), canon_charset)); - warned = true; - } - } - } - } + warned = true; + } + } + } + } } if (canon_locale_code == NULL && !warned) multiline_warning (xasprintf (_("warning: ")), - xasprintf (_("\ + xasprintf (_("\ Locale charset \"%s\" is not a portable encoding name.\n\ Output of '%s' might be incorrect.\n\ A possible workaround is to set LC_ALL=C.\n\ diff --git a/gettext-tools/src/msgl-check.c b/gettext-tools/src/msgl-check.c index 74737cf76..cce42af04 100644 --- a/gettext-tools/src/msgl-check.c +++ b/gettext-tools/src/msgl-check.c @@ -51,7 +51,7 @@ and returns the estimated number of times the value j was assumed. */ static unsigned int plural_expression_histogram (const struct plural_distribution *self, - int min, int max, unsigned long j) + int min, int max, unsigned long j) { if (min < 0) min = 0; @@ -70,12 +70,12 @@ plural_expression_histogram (const struct plural_distribution *self, count = 0; for (n = min; n <= max; n++) - { - unsigned long val = plural_eval (expr, n); + { + unsigned long val = plural_eval (expr, n); - if (val == j) - count++; - } + if (val == j) + count++; + } /* End of protection against arithmetic exceptions. */ uninstall_sigfpe_handler (); @@ -94,9 +94,9 @@ plural_expression_histogram (const struct plural_distribution *self, values distribution. */ int check_plural_eval (const struct expression *plural_expr, - unsigned long nplurals_value, - const message_ty *header, - struct plural_distribution *distribution) + unsigned long nplurals_value, + const message_ty *header, + struct plural_distribution *distribution) { /* Do as if the plural formula assumes a value N infinitely often if it assumes it at least 5 times. */ @@ -118,49 +118,49 @@ check_plural_eval (const struct expression *plural_expr, install_sigfpe_handler (); for (n = 0; n <= 1000; n++) - { - unsigned long val = plural_eval (plural_expr, n); - - if ((long) val < 0) - { - /* End of protection against arithmetic exceptions. */ - uninstall_sigfpe_handler (); - - po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, - _("plural expression can produce negative values")); - free (array); - return 1; - } - else if (val >= nplurals_value) - { - char *msg; - - /* End of protection against arithmetic exceptions. */ - uninstall_sigfpe_handler (); - - msg = xasprintf (_("nplurals = %lu but plural expression can produce values as large as %lu"), - nplurals_value, val); - po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg); - free (msg); - free (array); - return 1; - } - - if (array != NULL && array[val] < OFTEN) - array[val]++; - } + { + unsigned long val = plural_eval (plural_expr, n); + + if ((long) val < 0) + { + /* End of protection against arithmetic exceptions. */ + uninstall_sigfpe_handler (); + + po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, + _("plural expression can produce negative values")); + free (array); + return 1; + } + else if (val >= nplurals_value) + { + char *msg; + + /* End of protection against arithmetic exceptions. */ + uninstall_sigfpe_handler (); + + msg = xasprintf (_("nplurals = %lu but plural expression can produce values as large as %lu"), + nplurals_value, val); + po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg); + free (msg); + free (array); + return 1; + } + + if (array != NULL && array[val] < OFTEN) + array[val]++; + } /* End of protection against arithmetic exceptions. */ uninstall_sigfpe_handler (); /* Normalize the array[val] statistics. */ if (array != NULL) - { - unsigned long val; + { + unsigned long val; - for (val = 0; val < nplurals_value; val++) - array[val] = (array[val] == OFTEN ? 1 : 0); - } + for (val = 0; val < nplurals_value; val++) + array[val] = (array[val] == OFTEN ? 1 : 0); + } distribution->expr = plural_expr; distribution->often = array; @@ -180,22 +180,22 @@ check_plural_eval (const struct expression *plural_expr, #if USE_SIGINFO switch (sigfpe_code) #endif - { + { #if USE_SIGINFO # ifdef FPE_INTDIV - case FPE_INTDIV: - msg = _("plural expression can produce division by zero"); - break; + case FPE_INTDIV: + msg = _("plural expression can produce division by zero"); + break; # endif # ifdef FPE_INTOVF - case FPE_INTOVF: - msg = _("plural expression can produce integer overflow"); - break; + case FPE_INTOVF: + msg = _("plural expression can produce integer overflow"); + break; # endif - default: + default: #endif - msg = _("plural expression can produce arithmetic exceptions, possibly division by zero"); - } + msg = _("plural expression can produce arithmetic exceptions, possibly division by zero"); + } po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg); @@ -220,22 +220,22 @@ plural_help (const char *nullentry) language = c_strstr (nullentry, "Language: "); if (language != NULL) { - size_t len; + size_t len; language += 10; - len = strcspn (language, " \t\n"); - if (len > 0) - { - size_t j; - - for (j = 0; j < plural_table_size; j++) - if (len == strlen (plural_table[j].lang) - && strncmp (language, plural_table[j].lang, len) == 0) - { - ptentry = &plural_table[j]; - break; - } - } + len = strcspn (language, " \t\n"); + if (len > 0) + { + size_t j; + + for (j = 0; j < plural_table_size; j++) + if (len == strlen (plural_table[j].lang) + && strncmp (language, plural_table[j].lang, len) == 0) + { + ptentry = &plural_table[j]; + break; + } + } } } @@ -245,29 +245,29 @@ plural_help (const char *nullentry) language = c_strstr (nullentry, "Language-Team: "); if (language != NULL) - { - size_t j; - - language += 15; - for (j = 0; j < plural_table_size; j++) - if (strncmp (language, - plural_table[j].language, - strlen (plural_table[j].language)) == 0) - { - ptentry = &plural_table[j]; - break; - } - } + { + size_t j; + + language += 15; + for (j = 0; j < plural_table_size; j++) + if (strncmp (language, + plural_table[j].language, + strlen (plural_table[j].language)) == 0) + { + ptentry = &plural_table[j]; + break; + } + } } if (ptentry != NULL) { char *helpline1 = - xasprintf (_("Try using the following, valid for %s:"), - ptentry->language); + xasprintf (_("Try using the following, valid for %s:"), + ptentry->language); char *help = - xasprintf ("%s\n\"Plural-Forms: %s\\n\"\n", - helpline1, ptentry->value); + xasprintf ("%s\n\"Plural-Forms: %s\\n\"\n", + helpline1, ptentry->value); free (helpline1); return help; } @@ -307,30 +307,30 @@ check_plural (message_list_ty *mlp, struct plural_distribution *distributionp) message_ty *mp = mlp->item[j]; if (!mp->obsolete && mp->msgid_plural != NULL) - { - const char *p; - const char *p_end; - unsigned long n; - - if (has_plural == NULL) - has_plural = mp; - - n = 0; - for (p = mp->msgstr, p_end = p + mp->msgstr_len; - p < p_end; - p += strlen (p) + 1) - n++; - if (min_nplurals > n) - { - min_nplurals = n; - min_pos = mp; - } - if (max_nplurals < n) - { - max_nplurals = n; - max_pos = mp; - } - } + { + const char *p; + const char *p_end; + unsigned long n; + + if (has_plural == NULL) + has_plural = mp; + + n = 0; + for (p = mp->msgstr, p_end = p + mp->msgstr_len; + p < p_end; + p += strlen (p) + 1) + n++; + if (min_nplurals > n) + { + min_nplurals = n; + min_pos = mp; + } + if (max_nplurals < n) + { + max_nplurals = n; + max_pos = mp; + } + } } /* Look at the plural entry for this domain. @@ -347,174 +347,174 @@ check_plural (message_list_ty *mlp, struct plural_distribution *distributionp) plural = c_strstr (nullentry, "plural="); nplurals = c_strstr (nullentry, "nplurals="); if (plural == NULL && has_plural != NULL) - { - const char *msg1 = - _("message catalog has plural form translations"); - const char *msg2 = - _("but header entry lacks a \"plural=EXPRESSION\" attribute"); - char *help = plural_help (nullentry); - - if (help != NULL) - { - char *msg2ext = xasprintf ("%s\n%s", msg2, help); - po_xerror2 (PO_SEVERITY_ERROR, - has_plural, NULL, 0, 0, false, msg1, - header, NULL, 0, 0, true, msg2ext); - free (msg2ext); - free (help); - } - else - po_xerror2 (PO_SEVERITY_ERROR, - has_plural, NULL, 0, 0, false, msg1, - header, NULL, 0, 0, false, msg2); - - seen_errors++; - } + { + const char *msg1 = + _("message catalog has plural form translations"); + const char *msg2 = + _("but header entry lacks a \"plural=EXPRESSION\" attribute"); + char *help = plural_help (nullentry); + + if (help != NULL) + { + char *msg2ext = xasprintf ("%s\n%s", msg2, help); + po_xerror2 (PO_SEVERITY_ERROR, + has_plural, NULL, 0, 0, false, msg1, + header, NULL, 0, 0, true, msg2ext); + free (msg2ext); + free (help); + } + else + po_xerror2 (PO_SEVERITY_ERROR, + has_plural, NULL, 0, 0, false, msg1, + header, NULL, 0, 0, false, msg2); + + seen_errors++; + } if (nplurals == NULL && has_plural != NULL) - { - const char *msg1 = - _("message catalog has plural form translations"); - const char *msg2 = - _("but header entry lacks a \"nplurals=INTEGER\" attribute"); - char *help = plural_help (nullentry); - - if (help != NULL) - { - char *msg2ext = xasprintf ("%s\n%s", msg2, help); - po_xerror2 (PO_SEVERITY_ERROR, - has_plural, NULL, 0, 0, false, msg1, - header, NULL, 0, 0, true, msg2ext); - free (msg2ext); - free (help); - } - else - po_xerror2 (PO_SEVERITY_ERROR, - has_plural, NULL, 0, 0, false, msg1, - header, NULL, 0, 0, false, msg2); - - seen_errors++; - } + { + const char *msg1 = + _("message catalog has plural form translations"); + const char *msg2 = + _("but header entry lacks a \"nplurals=INTEGER\" attribute"); + char *help = plural_help (nullentry); + + if (help != NULL) + { + char *msg2ext = xasprintf ("%s\n%s", msg2, help); + po_xerror2 (PO_SEVERITY_ERROR, + has_plural, NULL, 0, 0, false, msg1, + header, NULL, 0, 0, true, msg2ext); + free (msg2ext); + free (help); + } + else + po_xerror2 (PO_SEVERITY_ERROR, + has_plural, NULL, 0, 0, false, msg1, + header, NULL, 0, 0, false, msg2); + + seen_errors++; + } if (plural != NULL && nplurals != NULL) - { - const char *endp; - unsigned long int nplurals_value; - struct parse_args args; - const struct expression *plural_expr; - - /* First check the number. */ - nplurals += 9; - while (*nplurals != '\0' && c_isspace ((unsigned char) *nplurals)) - ++nplurals; - endp = nplurals; - nplurals_value = 0; - if (*nplurals >= '0' && *nplurals <= '9') - nplurals_value = strtoul (nplurals, (char **) &endp, 10); - if (nplurals == endp) - { - const char *msg = _("invalid nplurals value"); - char *help = plural_help (nullentry); - - if (help != NULL) - { - char *msgext = xasprintf ("%s\n%s", msg, help); - po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, true, - msgext); - free (msgext); - free (help); - } - else - po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg); - - seen_errors++; - } - - /* Then check the expression. */ - plural += 7; - args.cp = plural; - if (parse_plural_expression (&args) != 0) - { - const char *msg = _("invalid plural expression"); - char *help = plural_help (nullentry); - - if (help != NULL) - { - char *msgext = xasprintf ("%s\n%s", msg, help); - po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, true, - msgext); - free (msgext); - free (help); - } - else - po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg); - - seen_errors++; - } - plural_expr = args.res; - - /* See whether nplurals and plural fit together. */ - if (!seen_errors) - seen_errors = - check_plural_eval (plural_expr, nplurals_value, header, - &distribution); - - /* Check the number of plurals of the translations. */ - if (!seen_errors) - { - if (min_nplurals < nplurals_value) - { - char *msg1 = - xasprintf (_("nplurals = %lu"), nplurals_value); - char *msg2 = - xasprintf (ngettext ("but some messages have only one plural form", - "but some messages have only %lu plural forms", - min_nplurals), - min_nplurals); - po_xerror2 (PO_SEVERITY_ERROR, - header, NULL, 0, 0, false, msg1, - min_pos, NULL, 0, 0, false, msg2); - free (msg2); - free (msg1); - seen_errors++; - } - else if (max_nplurals > nplurals_value) - { - char *msg1 = - xasprintf (_("nplurals = %lu"), nplurals_value); - char *msg2 = - xasprintf (ngettext ("but some messages have one plural form", - "but some messages have %lu plural forms", - max_nplurals), - max_nplurals); - po_xerror2 (PO_SEVERITY_ERROR, - header, NULL, 0, 0, false, msg1, - max_pos, NULL, 0, 0, false, msg2); - free (msg2); - free (msg1); - seen_errors++; - } - /* The only valid case is max_nplurals <= n <= min_nplurals, - which means either has_plural == NULL or - max_nplurals = n = min_nplurals. */ - } - } + { + const char *endp; + unsigned long int nplurals_value; + struct parse_args args; + const struct expression *plural_expr; + + /* First check the number. */ + nplurals += 9; + while (*nplurals != '\0' && c_isspace ((unsigned char) *nplurals)) + ++nplurals; + endp = nplurals; + nplurals_value = 0; + if (*nplurals >= '0' && *nplurals <= '9') + nplurals_value = strtoul (nplurals, (char **) &endp, 10); + if (nplurals == endp) + { + const char *msg = _("invalid nplurals value"); + char *help = plural_help (nullentry); + + if (help != NULL) + { + char *msgext = xasprintf ("%s\n%s", msg, help); + po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, true, + msgext); + free (msgext); + free (help); + } + else + po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg); + + seen_errors++; + } + + /* Then check the expression. */ + plural += 7; + args.cp = plural; + if (parse_plural_expression (&args) != 0) + { + const char *msg = _("invalid plural expression"); + char *help = plural_help (nullentry); + + if (help != NULL) + { + char *msgext = xasprintf ("%s\n%s", msg, help); + po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, true, + msgext); + free (msgext); + free (help); + } + else + po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg); + + seen_errors++; + } + plural_expr = args.res; + + /* See whether nplurals and plural fit together. */ + if (!seen_errors) + seen_errors = + check_plural_eval (plural_expr, nplurals_value, header, + &distribution); + + /* Check the number of plurals of the translations. */ + if (!seen_errors) + { + if (min_nplurals < nplurals_value) + { + char *msg1 = + xasprintf (_("nplurals = %lu"), nplurals_value); + char *msg2 = + xasprintf (ngettext ("but some messages have only one plural form", + "but some messages have only %lu plural forms", + min_nplurals), + min_nplurals); + po_xerror2 (PO_SEVERITY_ERROR, + header, NULL, 0, 0, false, msg1, + min_pos, NULL, 0, 0, false, msg2); + free (msg2); + free (msg1); + seen_errors++; + } + else if (max_nplurals > nplurals_value) + { + char *msg1 = + xasprintf (_("nplurals = %lu"), nplurals_value); + char *msg2 = + xasprintf (ngettext ("but some messages have one plural form", + "but some messages have %lu plural forms", + max_nplurals), + max_nplurals); + po_xerror2 (PO_SEVERITY_ERROR, + header, NULL, 0, 0, false, msg1, + max_pos, NULL, 0, 0, false, msg2); + free (msg2); + free (msg1); + seen_errors++; + } + /* The only valid case is max_nplurals <= n <= min_nplurals, + which means either has_plural == NULL or + max_nplurals = n = min_nplurals. */ + } + } else - goto no_plural; + goto no_plural; } else { if (has_plural != NULL) - { - po_xerror (PO_SEVERITY_ERROR, has_plural, NULL, 0, 0, false, - _("message catalog has plural form translations, but lacks a header entry with \"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\"")); - seen_errors++; - } + { + po_xerror (PO_SEVERITY_ERROR, has_plural, NULL, 0, 0, false, + _("message catalog has plural form translations, but lacks a header entry with \"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\"")); + seen_errors++; + } no_plural: /* By default, the Germanic formula (n != 1) is used. */ distribution.expr = &germanic_plural; { - unsigned char *array = XCALLOC (2, unsigned char); - array[1] = 1; - distribution.often = array; + unsigned char *array = XCALLOC (2, unsigned char); + array[1] = 1; + distribution.often = array; } distribution.often_length = 2; distribution.histogram = plural_expression_histogram; @@ -550,8 +550,8 @@ formatstring_error_logger (const char *format, ...) error (EXIT_FAILURE, 0, _("memory exhausted")); va_end (args); po_xerror (PO_SEVERITY_ERROR, - curr_mp, curr_msgid_pos.file_name, curr_msgid_pos.line_number, - (size_t)(-1), false, msg); + curr_mp, curr_msgid_pos.file_name, curr_msgid_pos.line_number, + (size_t)(-1), false, msg); free (msg); } @@ -564,16 +564,16 @@ formatstring_error_logger (const char *format, ...) array. */ static int check_pair (const message_ty *mp, - const char *msgid, - const lex_pos_ty *msgid_pos, - const char *msgid_plural, - const char *msgstr, size_t msgstr_len, - const enum is_format is_format[NFORMATS], - int check_newlines, - int check_format_strings, - const struct plural_distribution *distribution, - int check_compatibility, - int check_accelerators, char accelerator_char) + const char *msgid, + const lex_pos_ty *msgid_pos, + const char *msgid_plural, + const char *msgstr, size_t msgstr_len, + const enum is_format is_format[NFORMATS], + int check_newlines, + int check_format_strings, + const struct plural_distribution *distribution, + int check_compatibility, + int check_accelerators, char accelerator_char) { int seen_errors; int has_newline; @@ -592,90 +592,90 @@ check_pair (const message_ty *mp, has_newline = (msgid[0] == '\n'); #define TEST_NEWLINE(p) (p[0] == '\n') if (msgid_plural != NULL) - { - const char *p; - - if (TEST_NEWLINE(msgid_plural) != has_newline) - { - po_xerror (PO_SEVERITY_ERROR, - mp, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, _("\ + { + const char *p; + + if (TEST_NEWLINE(msgid_plural) != has_newline) + { + po_xerror (PO_SEVERITY_ERROR, + mp, msgid_pos->file_name, msgid_pos->line_number, + (size_t)(-1), false, _("\ `msgid' and `msgid_plural' entries do not both begin with '\\n'")); - seen_errors++; - } - for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++) - if (TEST_NEWLINE(p) != has_newline) - { - char *msg = - xasprintf (_("\ + seen_errors++; + } + for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++) + if (TEST_NEWLINE(p) != has_newline) + { + char *msg = + xasprintf (_("\ `msgid' and `msgstr[%u]' entries do not both begin with '\\n'"), j); - po_xerror (PO_SEVERITY_ERROR, - mp, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, msg); - free (msg); - seen_errors++; - } - } + po_xerror (PO_SEVERITY_ERROR, + mp, msgid_pos->file_name, msgid_pos->line_number, + (size_t)(-1), false, msg); + free (msg); + seen_errors++; + } + } else - { - if (TEST_NEWLINE(msgstr) != has_newline) - { - po_xerror (PO_SEVERITY_ERROR, - mp, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, _("\ + { + if (TEST_NEWLINE(msgstr) != has_newline) + { + po_xerror (PO_SEVERITY_ERROR, + mp, msgid_pos->file_name, msgid_pos->line_number, + (size_t)(-1), false, _("\ `msgid' and `msgstr' entries do not both begin with '\\n'")); - seen_errors++; - } - } + seen_errors++; + } + } #undef TEST_NEWLINE /* Test 2: check whether all or none of the strings end with a '\n'. */ has_newline = (msgid[strlen (msgid) - 1] == '\n'); #define TEST_NEWLINE(p) (p[0] != '\0' && p[strlen (p) - 1] == '\n') if (msgid_plural != NULL) - { - const char *p; - - if (TEST_NEWLINE(msgid_plural) != has_newline) - { - po_xerror (PO_SEVERITY_ERROR, - mp, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, _("\ + { + const char *p; + + if (TEST_NEWLINE(msgid_plural) != has_newline) + { + po_xerror (PO_SEVERITY_ERROR, + mp, msgid_pos->file_name, msgid_pos->line_number, + (size_t)(-1), false, _("\ `msgid' and `msgid_plural' entries do not both end with '\\n'")); - seen_errors++; - } - for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++) - if (TEST_NEWLINE(p) != has_newline) - { - char *msg = - xasprintf (_("\ + seen_errors++; + } + for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++) + if (TEST_NEWLINE(p) != has_newline) + { + char *msg = + xasprintf (_("\ `msgid' and `msgstr[%u]' entries do not both end with '\\n'"), j); - po_xerror (PO_SEVERITY_ERROR, - mp, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, msg); - free (msg); - seen_errors++; - } - } + po_xerror (PO_SEVERITY_ERROR, + mp, msgid_pos->file_name, msgid_pos->line_number, + (size_t)(-1), false, msg); + free (msg); + seen_errors++; + } + } else - { - if (TEST_NEWLINE(msgstr) != has_newline) - { - po_xerror (PO_SEVERITY_ERROR, - mp, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, _("\ + { + if (TEST_NEWLINE(msgstr) != has_newline) + { + po_xerror (PO_SEVERITY_ERROR, + mp, msgid_pos->file_name, msgid_pos->line_number, + (size_t)(-1), false, _("\ `msgid' and `msgstr' entries do not both end with '\\n'")); - seen_errors++; - } - } + seen_errors++; + } + } #undef TEST_NEWLINE } if (check_compatibility && msgid_plural != NULL) { po_xerror (PO_SEVERITY_ERROR, - mp, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, _("\ + mp, msgid_pos->file_name, msgid_pos->line_number, + (size_t)(-1), false, _("\ plural handling is a GNU gettext extension")); seen_errors++; } @@ -687,9 +687,9 @@ plural handling is a GNU gettext extension")); curr_mp = mp; curr_msgid_pos = *msgid_pos; seen_errors += - check_msgid_msgstr_format (msgid, msgid_plural, msgstr, msgstr_len, - is_format, mp->range, distribution, - formatstring_error_logger); + check_msgid_msgstr_format (msgid, msgid_plural, msgstr, msgstr_len, + is_format, mp->range, distribution, + formatstring_error_logger); } if (check_accelerators && msgid_plural == NULL) @@ -704,37 +704,37 @@ plural handling is a GNU gettext extension")); /* We are only interested in msgids that contain exactly one '&'. */ p = strchr (msgid, accelerator_char); if (p != NULL && strchr (p + 1, accelerator_char) == NULL) - { - /* Count the number of '&' in msgstr, but ignore '&&'. */ - unsigned int count = 0; - - for (p = msgstr; (p = strchr (p, accelerator_char)) != NULL; p++) - if (p[1] == accelerator_char) - p++; - else - count++; - - if (count == 0) - { - char *msg = - xasprintf (_("msgstr lacks the keyboard accelerator mark '%c'"), - accelerator_char); - po_xerror (PO_SEVERITY_ERROR, - mp, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, msg); - free (msg); - } - else if (count > 1) - { - char *msg = - xasprintf (_("msgstr has too many keyboard accelerator marks '%c'"), - accelerator_char); - po_xerror (PO_SEVERITY_ERROR, - mp, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, msg); - free (msg); - } - } + { + /* Count the number of '&' in msgstr, but ignore '&&'. */ + unsigned int count = 0; + + for (p = msgstr; (p = strchr (p, accelerator_char)) != NULL; p++) + if (p[1] == accelerator_char) + p++; + else + count++; + + if (count == 0) + { + char *msg = + xasprintf (_("msgstr lacks the keyboard accelerator mark '%c'"), + accelerator_char); + po_xerror (PO_SEVERITY_ERROR, + mp, msgid_pos->file_name, msgid_pos->line_number, + (size_t)(-1), false, msg); + free (msg); + } + else if (count > 1) + { + char *msg = + xasprintf (_("msgstr has too many keyboard accelerator marks '%c'"), + accelerator_char); + po_xerror (PO_SEVERITY_ERROR, + mp, msgid_pos->file_name, msgid_pos->line_number, + (size_t)(-1), false, msg); + free (msg); + } + } } return seen_errors; @@ -767,64 +767,64 @@ check_header_entry (const message_ty *mp, const char *msgstr_string) for (cnt = 0; cnt < nfields; ++cnt) { int severity = - (cnt < nrequiredfields ? PO_SEVERITY_ERROR : PO_SEVERITY_WARNING); + (cnt < nrequiredfields ? PO_SEVERITY_ERROR : PO_SEVERITY_WARNING); const char *endp = c_strstr (msgstr_string, required_fields[cnt]); if (endp == NULL) - { - char *msg = - xasprintf (_("header field `%s' missing in header\n"), - required_fields[cnt]); - po_xerror (severity, mp, NULL, 0, 0, true, msg); - free (msg); - } + { + char *msg = + xasprintf (_("header field `%s' missing in header\n"), + required_fields[cnt]); + po_xerror (severity, mp, NULL, 0, 0, true, msg); + free (msg); + } else if (endp != msgstr_string && endp[-1] != '\n') - { - char *msg = - xasprintf (_("\ + { + char *msg = + xasprintf (_("\ header field `%s' should start at beginning of line\n"), - required_fields[cnt]); - po_xerror (severity, mp, NULL, 0, 0, true, msg); - free (msg); - } + required_fields[cnt]); + po_xerror (severity, mp, NULL, 0, 0, true, msg); + free (msg); + } else - { - const char *p = endp + strlen (required_fields[cnt]); - /* Test whether the field's value, starting at p, is the default - value. */ - if (*p == ':') - p++; - if (*p == ' ') - p++; - if (default_values[cnt] != NULL - && strncmp (p, default_values[cnt], - strlen (default_values[cnt])) == 0) - { - p += strlen (default_values[cnt]); - if (*p == '\0' || *p == '\n') - { - if (initial != -1) - { - po_xerror (severity, - mp, NULL, 0, 0, true, _("\ + { + const char *p = endp + strlen (required_fields[cnt]); + /* Test whether the field's value, starting at p, is the default + value. */ + if (*p == ':') + p++; + if (*p == ' ') + p++; + if (default_values[cnt] != NULL + && strncmp (p, default_values[cnt], + strlen (default_values[cnt])) == 0) + { + p += strlen (default_values[cnt]); + if (*p == '\0' || *p == '\n') + { + if (initial != -1) + { + po_xerror (severity, + mp, NULL, 0, 0, true, _("\ some header fields still have the initial default value\n")); - initial = -1; - break; - } - else - initial = cnt; - } - } - } + initial = -1; + break; + } + else + initial = cnt; + } + } + } } if (initial != -1) { int severity = - (initial < nrequiredfields ? PO_SEVERITY_ERROR : PO_SEVERITY_WARNING); + (initial < nrequiredfields ? PO_SEVERITY_ERROR : PO_SEVERITY_WARNING); char *msg = - xasprintf (_("header field `%s' still has the initial default value\n"), - required_fields[initial]); + xasprintf (_("header field `%s' still has the initial default value\n"), + required_fields[initial]); po_xerror (severity, mp, NULL, 0, 0, true, msg); free (msg); } @@ -835,26 +835,26 @@ some header fields still have the initial default value\n")); Return the number of errors that were seen. */ int check_message (const message_ty *mp, - const lex_pos_ty *msgid_pos, - int check_newlines, - int check_format_strings, - const struct plural_distribution *distribution, - int check_header, - int check_compatibility, - int check_accelerators, char accelerator_char) + const lex_pos_ty *msgid_pos, + int check_newlines, + int check_format_strings, + const struct plural_distribution *distribution, + int check_header, + int check_compatibility, + int check_accelerators, char accelerator_char) { if (check_header && is_header (mp)) check_header_entry (mp, mp->msgstr); return check_pair (mp, - mp->msgid, msgid_pos, mp->msgid_plural, - mp->msgstr, mp->msgstr_len, - mp->is_format, - check_newlines, - check_format_strings, - distribution, - check_compatibility, - check_accelerators, accelerator_char); + mp->msgid, msgid_pos, mp->msgid_plural, + mp->msgstr, mp->msgstr_len, + mp->is_format, + check_newlines, + check_format_strings, + distribution, + check_compatibility, + check_accelerators, accelerator_char); } @@ -862,11 +862,11 @@ check_message (const message_ty *mp, Return the number of errors that were seen. */ int check_message_list (message_list_ty *mlp, - int check_newlines, - int check_format_strings, - int check_header, - int check_compatibility, - int check_accelerators, char accelerator_char) + int check_newlines, + int check_format_strings, + int check_header, + int check_compatibility, + int check_accelerators, char accelerator_char) { int seen_errors = 0; struct plural_distribution distribution; @@ -885,12 +885,12 @@ check_message_list (message_list_ty *mlp, message_ty *mp = mlp->item[j]; if (!mp->obsolete) - seen_errors += check_message (mp, &mp->pos, - check_newlines, - check_format_strings, - &distribution, - check_header, check_compatibility, - check_accelerators, accelerator_char); + seen_errors += check_message (mp, &mp->pos, + check_newlines, + check_format_strings, + &distribution, + check_header, check_compatibility, + check_accelerators, accelerator_char); } return seen_errors; diff --git a/gettext-tools/src/msgl-check.h b/gettext-tools/src/msgl-check.h index a11e95947..a4e1091cb 100644 --- a/gettext-tools/src/msgl-check.h +++ b/gettext-tools/src/msgl-check.h @@ -35,28 +35,28 @@ extern "C" { If no errors, returns in *DISTRIBUTION information about the plural_eval values distribution. */ extern int check_plural_eval (const struct expression *plural_expr, - unsigned long nplurals_value, - const message_ty *header, - struct plural_distribution *distribution); + unsigned long nplurals_value, + const message_ty *header, + struct plural_distribution *distribution); /* Perform all checks on a non-obsolete message. */ extern int check_message (const message_ty *mp, - const lex_pos_ty *msgid_pos, - int check_newlines, - int check_format_strings, - const struct plural_distribution *distribution, - int check_header, - int check_compatibility, - int check_accelerators, char accelerator_char); + const lex_pos_ty *msgid_pos, + int check_newlines, + int check_format_strings, + const struct plural_distribution *distribution, + int check_header, + int check_compatibility, + int check_accelerators, char accelerator_char); /* Perform all checks on a message list. Return the number of errors that were seen. */ extern int check_message_list (message_list_ty *mlp, - int check_newlines, - int check_format_strings, - int check_header, - int check_compatibility, - int check_accelerators, char accelerator_char); + int check_newlines, + int check_format_strings, + int check_header, + int check_compatibility, + int check_accelerators, char accelerator_char); #ifdef __cplusplus diff --git a/gettext-tools/src/msgl-english.c b/gettext-tools/src/msgl-english.c index 784e1fa24..69d95a986 100644 --- a/gettext-tools/src/msgl-english.c +++ b/gettext-tools/src/msgl-english.c @@ -38,32 +38,32 @@ msgdomain_list_english (msgdomain_list_ty *mdlp) message_list_ty *mlp = mdlp->item[k]->messages; for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; + { + message_ty *mp = mlp->item[j]; - if (mp->msgid_plural == NULL) - { - if (mp->msgstr_len == 1 && mp->msgstr[0] == '\0') - { - mp->msgstr = mp->msgid; /* no need for xstrdup */ - mp->msgstr_len = strlen (mp->msgid) + 1; - } - } - else - { - if (mp->msgstr_len == 2 - && mp->msgstr[0] == '\0' && mp->msgstr[1] == '\0') - { - size_t len0 = strlen (mp->msgid) + 1; - size_t len1 = strlen (mp->msgid_plural) + 1; - char *cp = XNMALLOC (len0 + len1, char); - memcpy (cp, mp->msgid, len0); - memcpy (cp + len0, mp->msgid_plural, len1); - mp->msgstr = cp; - mp->msgstr_len = len0 + len1; - } - } - } + if (mp->msgid_plural == NULL) + { + if (mp->msgstr_len == 1 && mp->msgstr[0] == '\0') + { + mp->msgstr = mp->msgid; /* no need for xstrdup */ + mp->msgstr_len = strlen (mp->msgid) + 1; + } + } + else + { + if (mp->msgstr_len == 2 + && mp->msgstr[0] == '\0' && mp->msgstr[1] == '\0') + { + size_t len0 = strlen (mp->msgid) + 1; + size_t len1 = strlen (mp->msgid_plural) + 1; + char *cp = XNMALLOC (len0 + len1, char); + memcpy (cp, mp->msgid, len0); + memcpy (cp + len0, mp->msgid_plural, len1); + mp->msgstr = cp; + mp->msgstr_len = len0 + len1; + } + } + } } return mdlp; diff --git a/gettext-tools/src/msgl-equal.c b/gettext-tools/src/msgl-equal.c index f8d2e9f88..3c9efad78 100644 --- a/gettext-tools/src/msgl-equal.c +++ b/gettext-tools/src/msgl-equal.c @@ -29,15 +29,15 @@ static inline bool msgstr_equal (const char *msgstr1, size_t msgstr1_len, - const char *msgstr2, size_t msgstr2_len) + const char *msgstr2, size_t msgstr2_len) { return (msgstr1_len == msgstr2_len - && memcmp (msgstr1, msgstr2, msgstr1_len) == 0); + && memcmp (msgstr1, msgstr2, msgstr1_len) == 0); } static bool msgstr_equal_ignoring_potcdate (const char *msgstr1, size_t msgstr1_len, - const char *msgstr2, size_t msgstr2_len) + const char *msgstr2, size_t msgstr2_len) { const char *msgstr1_end = msgstr1 + msgstr1_len; const char *msgstr2_end = msgstr2 + msgstr2_len; @@ -50,15 +50,15 @@ msgstr_equal_ignoring_potcdate (const char *msgstr1, size_t msgstr1_len, for (ptr1 = msgstr1;;) { if (msgstr1_end - ptr1 < fieldlen) - { - ptr1 = NULL; - break; - } + { + ptr1 = NULL; + break; + } if (memcmp (ptr1, field, fieldlen) == 0) - break; + break; ptr1 = (const char *) memchr (ptr1, '\n', msgstr1_end - ptr1); if (ptr1 == NULL) - break; + break; ptr1++; } @@ -66,42 +66,42 @@ msgstr_equal_ignoring_potcdate (const char *msgstr1, size_t msgstr1_len, for (ptr2 = msgstr2;;) { if (msgstr2_end - ptr2 < fieldlen) - { - ptr2 = NULL; - break; - } + { + ptr2 = NULL; + break; + } if (memcmp (ptr2, field, fieldlen) == 0) - break; + break; ptr2 = (const char *) memchr (ptr2, '\n', msgstr2_end - ptr2); if (ptr2 == NULL) - break; + break; ptr2++; } if (ptr1 == NULL) { if (ptr2 == NULL) - return msgstr_equal (msgstr1, msgstr1_len, msgstr2, msgstr2_len); + return msgstr_equal (msgstr1, msgstr1_len, msgstr2, msgstr2_len); } else { if (ptr2 != NULL) - { - /* Compare, ignoring the lines starting at ptr1 and ptr2. */ - if (msgstr_equal (msgstr1, ptr1 - msgstr1, msgstr2, ptr2 - msgstr2)) - { - ptr1 = (const char *) memchr (ptr1, '\n', msgstr1_end - ptr1); - if (ptr1 == NULL) - ptr1 = msgstr1_end; - - ptr2 = (const char *) memchr (ptr2, '\n', msgstr2_end - ptr2); - if (ptr2 == NULL) - ptr2 = msgstr2_end; - - return msgstr_equal (ptr1, msgstr1_end - ptr1, - ptr2, msgstr2_end - ptr2); - } - } + { + /* Compare, ignoring the lines starting at ptr1 and ptr2. */ + if (msgstr_equal (msgstr1, ptr1 - msgstr1, msgstr2, ptr2 - msgstr2)) + { + ptr1 = (const char *) memchr (ptr1, '\n', msgstr1_end - ptr1); + if (ptr1 == NULL) + ptr1 = msgstr1_end; + + ptr2 = (const char *) memchr (ptr2, '\n', msgstr2_end - ptr2); + if (ptr2 == NULL) + ptr2 = msgstr2_end; + + return msgstr_equal (ptr1, msgstr1_end - ptr1, + ptr2, msgstr2_end - ptr2); + } + } } return false; } @@ -110,8 +110,8 @@ static inline bool pos_equal (const lex_pos_ty *pos1, const lex_pos_ty *pos2) { return ((pos1->file_name == pos2->file_name - || strcmp (pos1->file_name, pos2->file_name) == 0) - && pos1->line_number == pos2->line_number); + || strcmp (pos1->file_name, pos2->file_name) == 0) + && pos1->line_number == pos2->line_number); } bool @@ -131,29 +131,29 @@ string_list_equal (const string_list_ty *slp1, const string_list_ty *slp2) bool message_equal (const message_ty *mp1, const message_ty *mp2, - bool ignore_potcdate) + bool ignore_potcdate) { size_t i, i1, i2; if (!(mp1->msgctxt != NULL - ? mp2->msgctxt != NULL && strcmp (mp1->msgctxt, mp2->msgctxt) == 0 - : mp2->msgctxt == NULL)) + ? mp2->msgctxt != NULL && strcmp (mp1->msgctxt, mp2->msgctxt) == 0 + : mp2->msgctxt == NULL)) return false; if (strcmp (mp1->msgid, mp2->msgid) != 0) return false; if (!(mp1->msgid_plural != NULL - ? mp2->msgid_plural != NULL - && strcmp (mp1->msgid_plural, mp2->msgid_plural) == 0 - : mp2->msgid_plural == NULL)) + ? mp2->msgid_plural != NULL + && strcmp (mp1->msgid_plural, mp2->msgid_plural) == 0 + : mp2->msgid_plural == NULL)) return false; if (is_header (mp1) && ignore_potcdate ? !msgstr_equal_ignoring_potcdate (mp1->msgstr, mp1->msgstr_len, - mp2->msgstr, mp2->msgstr_len) + mp2->msgstr, mp2->msgstr_len) : !msgstr_equal (mp1->msgstr, mp1->msgstr_len, - mp2->msgstr, mp2->msgstr_len)) + mp2->msgstr, mp2->msgstr_len)) return false; if (!pos_equal (&mp1->pos, &mp2->pos)) @@ -184,21 +184,21 @@ message_equal (const message_ty *mp1, const message_ty *mp2, return false; if (!(mp1->prev_msgctxt != NULL - ? mp2->prev_msgctxt != NULL - && strcmp (mp1->prev_msgctxt, mp2->prev_msgctxt) == 0 - : mp2->prev_msgctxt == NULL)) + ? mp2->prev_msgctxt != NULL + && strcmp (mp1->prev_msgctxt, mp2->prev_msgctxt) == 0 + : mp2->prev_msgctxt == NULL)) return false; if (!(mp1->prev_msgid != NULL - ? mp2->prev_msgid != NULL - && strcmp (mp1->prev_msgid, mp2->prev_msgid) == 0 - : mp2->prev_msgid == NULL)) + ? mp2->prev_msgid != NULL + && strcmp (mp1->prev_msgid, mp2->prev_msgid) == 0 + : mp2->prev_msgid == NULL)) return false; if (!(mp1->prev_msgid_plural != NULL - ? mp2->prev_msgid_plural != NULL - && strcmp (mp1->prev_msgid_plural, mp2->prev_msgid_plural) == 0 - : mp2->prev_msgid_plural == NULL)) + ? mp2->prev_msgid_plural != NULL + && strcmp (mp1->prev_msgid_plural, mp2->prev_msgid_plural) == 0 + : mp2->prev_msgid_plural == NULL)) return false; if (mp1->obsolete != mp2->obsolete) @@ -209,7 +209,7 @@ message_equal (const message_ty *mp1, const message_ty *mp2, bool message_list_equal (const message_list_ty *mlp1, const message_list_ty *mlp2, - bool ignore_potcdate) + bool ignore_potcdate) { size_t i, i1, i2; @@ -225,17 +225,17 @@ message_list_equal (const message_list_ty *mlp1, const message_list_ty *mlp2, static inline bool msgdomain_equal (const msgdomain_ty *mdp1, const msgdomain_ty *mdp2, - bool ignore_potcdate) + bool ignore_potcdate) { return (strcmp (mdp1->domain, mdp2->domain) == 0 - && message_list_equal (mdp1->messages, mdp2->messages, - ignore_potcdate)); + && message_list_equal (mdp1->messages, mdp2->messages, + ignore_potcdate)); } bool msgdomain_list_equal (const msgdomain_list_ty *mdlp1, - const msgdomain_list_ty *mdlp2, - bool ignore_potcdate) + const msgdomain_list_ty *mdlp2, + bool ignore_potcdate) { size_t i, i1, i2; diff --git a/gettext-tools/src/msgl-equal.h b/gettext-tools/src/msgl-equal.h index e548cb791..6497a7fd7 100644 --- a/gettext-tools/src/msgl-equal.h +++ b/gettext-tools/src/msgl-equal.h @@ -30,22 +30,22 @@ extern "C" { extern bool string_list_equal (const string_list_ty *slp1, - const string_list_ty *slp2); + const string_list_ty *slp2); /* Test whether the written representation of two messages / message lists would be the same. */ extern bool message_equal (const message_ty *mp1, const message_ty *mp2, - bool ignore_potcdate); + bool ignore_potcdate); extern bool message_list_equal (const message_list_ty *mlp1, - const message_list_ty *mlp2, - bool ignore_potcdate); + const message_list_ty *mlp2, + bool ignore_potcdate); extern bool msgdomain_list_equal (const msgdomain_list_ty *mdlp1, - const msgdomain_list_ty *mdlp2, - bool ignore_potcdate); + const msgdomain_list_ty *mdlp2, + bool ignore_potcdate); #ifdef __cplusplus diff --git a/gettext-tools/src/msgl-fsearch.c b/gettext-tools/src/msgl-fsearch.c index dd2a1d367..d5cf71b65 100644 --- a/gettext-tools/src/msgl-fsearch.c +++ b/gettext-tools/src/msgl-fsearch.c @@ -145,11 +145,11 @@ add_index (index_list_ty list, index_ty idx) size_t mid = (lo + hi) / 2; /* lo <= mid < hi */ index_ty val = list[2 + mid]; if (val < idx) - lo = mid + 1; + lo = mid + 1; else if (val > idx) - hi = mid; + hi = mid; else - return NULL; + return NULL; } /* Now make room for one more list element. */ @@ -200,7 +200,7 @@ struct message_fuzzy_index_ty inside it must not be modified while the returned fuzzy index is in use. */ message_fuzzy_index_ty * message_fuzzy_index_alloc (const message_list_ty *mlp, - const char *canon_charset) + const char *canon_charset) { message_fuzzy_index_ty *findex = XMALLOC (message_fuzzy_index_ty); size_t count = mlp->nitems; @@ -218,58 +218,58 @@ message_fuzzy_index_alloc (const message_list_ty *mlp, message_ty *mp = mlp->item[j]; if (mp->msgstr != NULL && mp->msgstr[0] != '\0') - { - const char *str = mp->msgid; - - /* Let p0 < p1 < p2 < p3 < p4 walk through the string. */ - const char *p0 = str; - if (*p0 != '\0') - { - const char *p1 = p0 + findex->iterator (p0); - if (*p1 != '\0') - { - const char *p2 = p1 + findex->iterator (p1); - if (*p2 != '\0') - { - const char *p3 = p2 + findex->iterator (p2); - if (*p3 != '\0') - { - const char *p4 = p3 + findex->iterator (p3); - for (;;) - { - /* The segment from p0 to p4 is a 4-gram of - characters. Add a hash table entry that maps - it to the index j, or extend the existing - hash table entry accordingly. */ - void *found; - - if (hash_find_entry (&findex->gram4, p0, p4 - p0, - &found) == 0) - { - index_list_ty list = (index_list_ty) found; - list = addlast_index (list, j); - if (list != NULL) - hash_set_value (&findex->gram4, p0, p4 - p0, - list); - } - else - hash_insert_entry (&findex->gram4, p0, p4 - p0, - new_index (j)); - - /* Advance. */ - if (*p4 == '\0') - break; - p0 = p1; - p1 = p2; - p2 = p3; - p3 = p4; - p4 = p4 + findex->iterator (p4); - } - } - } - } - } - } + { + const char *str = mp->msgid; + + /* Let p0 < p1 < p2 < p3 < p4 walk through the string. */ + const char *p0 = str; + if (*p0 != '\0') + { + const char *p1 = p0 + findex->iterator (p0); + if (*p1 != '\0') + { + const char *p2 = p1 + findex->iterator (p1); + if (*p2 != '\0') + { + const char *p3 = p2 + findex->iterator (p2); + if (*p3 != '\0') + { + const char *p4 = p3 + findex->iterator (p3); + for (;;) + { + /* The segment from p0 to p4 is a 4-gram of + characters. Add a hash table entry that maps + it to the index j, or extend the existing + hash table entry accordingly. */ + void *found; + + if (hash_find_entry (&findex->gram4, p0, p4 - p0, + &found) == 0) + { + index_list_ty list = (index_list_ty) found; + list = addlast_index (list, j); + if (list != NULL) + hash_set_value (&findex->gram4, p0, p4 - p0, + list); + } + else + hash_insert_entry (&findex->gram4, p0, p4 - p0, + new_index (j)); + + /* Advance. */ + if (*p4 == '\0') + break; + p0 = p1; + p1 = p2; + p2 = p3; + p3 = p4; + p4 = p4 + findex->iterator (p4); + } + } + } + } + } + } } /* Shrink memory used by the hash table. */ @@ -281,16 +281,16 @@ message_fuzzy_index_alloc (const message_list_ty *mlp, iter = NULL; while (hash_iterate_modify (&findex->gram4, &iter, &key, &keylen, &valuep) - == 0) + == 0) { - index_list_ty list = (index_list_ty) *valuep; - index_ty length = list[IL_LENGTH]; - - if (length < list[IL_ALLOCATED]) - { - list[IL_ALLOCATED] = length; - *valuep = xrealloc (list, (2 + length) * sizeof (index_ty)); - } + index_list_ty list = (index_list_ty) *valuep; + index_ty length = list[IL_LENGTH]; + + if (length < list[IL_ALLOCATED]) + { + list[IL_ALLOCATED] = length; + *valuep = xrealloc (list, (2 + length) * sizeof (index_ty)); + } } } @@ -306,13 +306,13 @@ message_fuzzy_index_alloc (const message_list_ty *mlp, message_ty *mp = mlp->item[j]; if (mp->msgstr != NULL && mp->msgstr[0] != '\0') - { - const char *str = mp->msgid; - size_t len = strlen (str); + { + const char *str = mp->msgid; + size_t len = strlen (str); - if (len <= SHORT_MSG_MAX) - message_list_append (findex->short_messages[len], mp); - } + if (len <= SHORT_MSG_MAX) + message_list_append (findex->short_messages[len], mp); + } } /* Shrink memory used by the lists of short messages. */ @@ -321,12 +321,12 @@ message_fuzzy_index_alloc (const message_list_ty *mlp, message_list_ty *mlp = findex->short_messages[l]; if (mlp->nitems < mlp->nitems_max) - { - mlp->nitems_max = mlp->nitems; - mlp->item = - (message_ty **) - xrealloc (mlp->item, mlp->nitems_max * sizeof (message_ty *)); - } + { + mlp->nitems_max = mlp->nitems; + mlp->item = + (message_ty **) + xrealloc (mlp->item, mlp->nitems_max * sizeof (message_ty *)); + } } return findex; @@ -381,9 +381,9 @@ mult_index_list_accumulate (struct mult_index_list *accu, index_list_ty list) size_t new_max = 2 * accu->nitems2_max + 1; if (new_max < need) - new_max = need; + new_max = need; if (accu->item2 != NULL) - free (accu->item2); + free (accu->item2); accu->item2 = XNMALLOC (new_max, struct mult_index); accu->nitems2_max = new_max; } @@ -397,23 +397,23 @@ mult_index_list_accumulate (struct mult_index_list *accu, index_list_ty list) while (ptr1 < ptr1_end && ptr2 < ptr2_end) { if (ptr1->index < *ptr2) - { - *destptr = *ptr1; - ptr1++; - } + { + *destptr = *ptr1; + ptr1++; + } else if (ptr1->index > *ptr2) - { - destptr->index = *ptr2; - destptr->count = 1; - ptr2++; - } + { + destptr->index = *ptr2; + destptr->count = 1; + ptr2++; + } else /* ptr1->index == list[2 + i2] */ - { - destptr->index = ptr1->index; - destptr->count = ptr1->count + 1; - ptr1++; - ptr2++; - } + { + destptr->index = ptr1->index; + destptr->count = ptr1->count + 1; + ptr1++; + ptr2++; + } destptr++; } while (ptr1 < ptr1_end) @@ -470,7 +470,7 @@ mult_index_list_sort (struct mult_index_list *accu) { if (accu->nitems > 1) qsort (accu->item, accu->nitems, sizeof (struct mult_index), - mult_index_compare); + mult_index_compare); } /* Frees a list of indices with multiplicity. */ @@ -496,9 +496,9 @@ mult_index_list_free (struct mult_index_list *accu) choice). */ message_ty * message_fuzzy_index_search (message_fuzzy_index_ty *findex, - const char *msgctxt, const char *msgid, - double lower_bound, - bool heuristic) + const char *msgctxt, const char *msgid, + double lower_bound, + bool heuristic) { const char *str = msgid; @@ -508,90 +508,90 @@ message_fuzzy_index_search (message_fuzzy_index_ty *findex, { const char *p1 = p0 + findex->iterator (p0); if (*p1 != '\0') - { - const char *p2 = p1 + findex->iterator (p1); - if (*p2 != '\0') - { - const char *p3 = p2 + findex->iterator (p2); - if (*p3 != '\0') - { - const char *p4 = p3 + findex->iterator (p3); - struct mult_index_list accu; - - mult_index_list_init (&accu); - for (;;) - { - /* The segment from p0 to p4 is a 4-gram of - characters. Get the hash table entry containing - a list of indices, and add it to the accu. */ - void *found; - - if (hash_find_entry (&findex->gram4, p0, p4 - p0, - &found) == 0) - { - index_list_ty list = (index_list_ty) found; - mult_index_list_accumulate (&accu, list); - } - - /* Advance. */ - if (*p4 == '\0') - break; - p0 = p1; - p1 = p2; - p2 = p3; - p3 = p4; - p4 = p4 + findex->iterator (p4); - } - - /* Sort in decreasing count order. */ - mult_index_list_sort (&accu); - - /* Iterate over this sorted list, and maximize the - fuzzy_search_goal_function() result. - If HEURISTIC is true, take only the first few messages. - If HEURISTIC is false, consider all messages - to match - the behaviour of message_list_search_fuzzy -, but process - them in the order of the sorted list. This increases - the chances that the later calls to fstrcmp_bounded() (via - fuzzy_search_goal_function()) terminate quickly, thanks - to the best_weight which will be quite high already after - the first few messages. */ - { - size_t count; - struct mult_index *ptr; - message_ty *best_mp; - double best_weight; - - count = accu.nitems; - if (heuristic) - { - if (count > findex->firstfew) - count = findex->firstfew; - } - - best_weight = lower_bound; - best_mp = NULL; - for (ptr = accu.item; count > 0; ptr++, count--) - { - message_ty *mp = findex->messages[ptr->index]; - double weight = - fuzzy_search_goal_function (mp, msgctxt, msgid, - best_weight); - - if (weight > best_weight) - { - best_weight = weight; - best_mp = mp; - } - } - - mult_index_list_free (&accu); - - return best_mp; - } - } - } - } + { + const char *p2 = p1 + findex->iterator (p1); + if (*p2 != '\0') + { + const char *p3 = p2 + findex->iterator (p2); + if (*p3 != '\0') + { + const char *p4 = p3 + findex->iterator (p3); + struct mult_index_list accu; + + mult_index_list_init (&accu); + for (;;) + { + /* The segment from p0 to p4 is a 4-gram of + characters. Get the hash table entry containing + a list of indices, and add it to the accu. */ + void *found; + + if (hash_find_entry (&findex->gram4, p0, p4 - p0, + &found) == 0) + { + index_list_ty list = (index_list_ty) found; + mult_index_list_accumulate (&accu, list); + } + + /* Advance. */ + if (*p4 == '\0') + break; + p0 = p1; + p1 = p2; + p2 = p3; + p3 = p4; + p4 = p4 + findex->iterator (p4); + } + + /* Sort in decreasing count order. */ + mult_index_list_sort (&accu); + + /* Iterate over this sorted list, and maximize the + fuzzy_search_goal_function() result. + If HEURISTIC is true, take only the first few messages. + If HEURISTIC is false, consider all messages - to match + the behaviour of message_list_search_fuzzy -, but process + them in the order of the sorted list. This increases + the chances that the later calls to fstrcmp_bounded() (via + fuzzy_search_goal_function()) terminate quickly, thanks + to the best_weight which will be quite high already after + the first few messages. */ + { + size_t count; + struct mult_index *ptr; + message_ty *best_mp; + double best_weight; + + count = accu.nitems; + if (heuristic) + { + if (count > findex->firstfew) + count = findex->firstfew; + } + + best_weight = lower_bound; + best_mp = NULL; + for (ptr = accu.item; count > 0; ptr++, count--) + { + message_ty *mp = findex->messages[ptr->index]; + double weight = + fuzzy_search_goal_function (mp, msgctxt, msgid, + best_weight); + + if (weight > best_weight) + { + best_weight = weight; + best_mp = mp; + } + } + + mult_index_list_free (&accu); + + return best_mp; + } + } + } + } } /* The string had less than 4 characters. */ @@ -615,21 +615,21 @@ message_fuzzy_index_search (message_fuzzy_index_ty *findex, best_mp = NULL; for (l = lmin; l <= lmax; l++) { - message_list_ty *mlp = findex->short_messages[l]; - size_t j; - - for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - double weight = - fuzzy_search_goal_function (mp, msgctxt, msgid, best_weight); - - if (weight > best_weight) - { - best_weight = weight; - best_mp = mp; - } - } + message_list_ty *mlp = findex->short_messages[l]; + size_t j; + + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + double weight = + fuzzy_search_goal_function (mp, msgctxt, msgid, best_weight); + + if (weight > best_weight) + { + best_weight = weight; + best_mp = mp; + } + } } return best_mp; diff --git a/gettext-tools/src/msgl-fsearch.h b/gettext-tools/src/msgl-fsearch.h index c890f3717..c523d9308 100644 --- a/gettext-tools/src/msgl-fsearch.h +++ b/gettext-tools/src/msgl-fsearch.h @@ -38,7 +38,7 @@ typedef struct message_fuzzy_index_ty message_fuzzy_index_ty; inside it must not be modified while the returned fuzzy index is in use. */ extern message_fuzzy_index_ty * message_fuzzy_index_alloc (const message_list_ty *mlp, - const char *canon_charset); + const char *canon_charset); /* Find a good match for the given msgctxt and msgid in the given fuzzy index. The match does not need to be optimal. @@ -53,9 +53,9 @@ extern message_fuzzy_index_ty * choice). */ extern message_ty * message_fuzzy_index_search (message_fuzzy_index_ty *findex, - const char *msgctxt, const char *msgid, - double lower_bound, - bool heuristic); + const char *msgctxt, const char *msgid, + double lower_bound, + bool heuristic); /* Free a fuzzy index. */ extern void diff --git a/gettext-tools/src/msgl-header.c b/gettext-tools/src/msgl-header.c index 0e1ba9b8c..d1dafdb70 100644 --- a/gettext-tools/src/msgl-header.c +++ b/gettext-tools/src/msgl-header.c @@ -32,7 +32,7 @@ void msgdomain_list_set_header_field (msgdomain_list_ty *mdlp, - const char *field, const char *value) + const char *field, const char *value) { /* The known fields in their usual order. */ static const struct @@ -52,7 +52,7 @@ msgdomain_list_set_header_field (msgdomain_list_ty *mdlp, { "MIME-Version:", sizeof ("MIME-Version:") - 1 }, { "Content-Type:", sizeof ("Content-Type:") - 1 }, { "Content-Transfer-Encoding:", - sizeof ("Content-Transfer-Encoding:") - 1 } + sizeof ("Content-Transfer-Encoding:") - 1 } }; size_t field_len; int field_index; @@ -65,8 +65,8 @@ msgdomain_list_set_header_field (msgdomain_list_ty *mdlp, for (k = 0; k < SIZEOF (known_fields); k++) if (strcmp (known_fields[k].name, field) == 0) { - field_index = k; - break; + field_index = k; + break; } for (i = 0; i < mdlp->nitems; i++) @@ -76,95 +76,95 @@ msgdomain_list_set_header_field (msgdomain_list_ty *mdlp, /* Search the header entry. */ for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - message_ty *mp = mlp->item[j]; - - /* Modify the header entry. */ - const char *header = mp->msgstr; - char *new_header = - XNMALLOC (strlen (header) + 1 - + strlen (field) + 1 + strlen (value) + 1 + 1, - char); - - /* Test whether the field already occurs in the header entry. */ - const char *h; - - for (h = header; *h != '\0'; ) - { - if (strncmp (h, field, field_len) == 0) - break; - h = strchr (h, '\n'); - if (h == NULL) - break; - h++; - } - if (h != NULL && *h != '\0') - { - /* Replace the field. */ - char *p = new_header; - memcpy (p, header, h - header); - p += h - header; - p = stpcpy (p, field); - p = stpcpy (stpcpy (stpcpy (p, " "), value), "\n"); - h = strchr (h, '\n'); - if (h != NULL) - { - h++; - stpcpy (p, h); - } - } - else if (field_index < 0) - { - /* An unknown field. Append it at the end. */ - char *p = new_header; - p = stpcpy (p, header); - if (p > new_header && p[-1] != '\n') - *p++ = '\n'; - p = stpcpy (p, field); - stpcpy (stpcpy (stpcpy (p, " "), value), "\n"); - } - else - { - /* Find the appropriate position for inserting the field. */ - for (h = header; *h != '\0'; ) - { - /* Test whether h starts with a field name whose index is - > field_index. */ - for (k = field_index + 1; k < SIZEOF (known_fields); k++) - if (strncmp (h, known_fields[k].name, known_fields[k].len) - == 0) - break; - if (k < SIZEOF (known_fields)) - break; - h = strchr (h, '\n'); - if (h == NULL) - break; - h++; - } - if (h != NULL && *h != '\0') - { - /* Insert the field at position h. */ - char *p = new_header; - memcpy (p, header, h - header); - p += h - header; - p = stpcpy (p, field); - p = stpcpy (stpcpy (stpcpy (p, " "), value), "\n"); - stpcpy (p, h); - } - else - { - /* Append it at the end. */ - char *p = new_header; - p = stpcpy (p, header); - if (p > new_header && p[-1] != '\n') - *p++ = '\n'; - p = stpcpy (p, field); - stpcpy (stpcpy (stpcpy (p, " "), value), "\n"); - } - } - - mp->msgstr = new_header; - } + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + message_ty *mp = mlp->item[j]; + + /* Modify the header entry. */ + const char *header = mp->msgstr; + char *new_header = + XNMALLOC (strlen (header) + 1 + + strlen (field) + 1 + strlen (value) + 1 + 1, + char); + + /* Test whether the field already occurs in the header entry. */ + const char *h; + + for (h = header; *h != '\0'; ) + { + if (strncmp (h, field, field_len) == 0) + break; + h = strchr (h, '\n'); + if (h == NULL) + break; + h++; + } + if (h != NULL && *h != '\0') + { + /* Replace the field. */ + char *p = new_header; + memcpy (p, header, h - header); + p += h - header; + p = stpcpy (p, field); + p = stpcpy (stpcpy (stpcpy (p, " "), value), "\n"); + h = strchr (h, '\n'); + if (h != NULL) + { + h++; + stpcpy (p, h); + } + } + else if (field_index < 0) + { + /* An unknown field. Append it at the end. */ + char *p = new_header; + p = stpcpy (p, header); + if (p > new_header && p[-1] != '\n') + *p++ = '\n'; + p = stpcpy (p, field); + stpcpy (stpcpy (stpcpy (p, " "), value), "\n"); + } + else + { + /* Find the appropriate position for inserting the field. */ + for (h = header; *h != '\0'; ) + { + /* Test whether h starts with a field name whose index is + > field_index. */ + for (k = field_index + 1; k < SIZEOF (known_fields); k++) + if (strncmp (h, known_fields[k].name, known_fields[k].len) + == 0) + break; + if (k < SIZEOF (known_fields)) + break; + h = strchr (h, '\n'); + if (h == NULL) + break; + h++; + } + if (h != NULL && *h != '\0') + { + /* Insert the field at position h. */ + char *p = new_header; + memcpy (p, header, h - header); + p += h - header; + p = stpcpy (p, field); + p = stpcpy (stpcpy (stpcpy (p, " "), value), "\n"); + stpcpy (p, h); + } + else + { + /* Append it at the end. */ + char *p = new_header; + p = stpcpy (p, header); + if (p > new_header && p[-1] != '\n') + *p++ = '\n'; + p = stpcpy (p, field); + stpcpy (stpcpy (stpcpy (p, " "), value), "\n"); + } + } + + mp->msgstr = new_header; + } } } diff --git a/gettext-tools/src/msgl-header.h b/gettext-tools/src/msgl-header.h index 9fb501af5..f26b1a841 100644 --- a/gettext-tools/src/msgl-header.h +++ b/gettext-tools/src/msgl-header.h @@ -32,7 +32,7 @@ extern "C" { function. */ extern void msgdomain_list_set_header_field (msgdomain_list_ty *mdlp, - const char *field, const char *value); + const char *field, const char *value); #ifdef __cplusplus diff --git a/gettext-tools/src/msgl-iconv.c b/gettext-tools/src/msgl-iconv.c index 1e5832ae3..958455b54 100644 --- a/gettext-tools/src/msgl-iconv.c +++ b/gettext-tools/src/msgl-iconv.c @@ -62,21 +62,21 @@ conversion_error (const struct conversion_context* context) if (context->to_code == po_charset_utf8) /* If a conversion to UTF-8 fails, the problem lies in the input. */ po_xerror (PO_SEVERITY_FATAL_ERROR, context->message, NULL, 0, 0, false, - xasprintf (_("%s: input is not valid in \"%s\" encoding"), - context->from_filename, context->from_code)); + xasprintf (_("%s: input is not valid in \"%s\" encoding"), + context->from_filename, context->from_code)); else po_xerror (PO_SEVERITY_FATAL_ERROR, context->message, NULL, 0, 0, false, - xasprintf (_("\ + xasprintf (_("\ %s: error while converting from \"%s\" encoding to \"%s\" encoding"), - context->from_filename, context->from_code, - context->to_code)); + context->from_filename, context->from_code, + context->to_code)); /* NOTREACHED */ abort (); } char * convert_string_directly (iconv_t cd, const char *string, - const struct conversion_context* context) + const struct conversion_context* context) { size_t len = strlen (string) + 1; char *result = NULL; @@ -85,7 +85,7 @@ convert_string_directly (iconv_t cd, const char *string, if (xmem_cd_iconv (string, len, cd, &result, &resultlen) == 0) /* Verify the result has exactly one NUL byte, at the end. */ if (resultlen > 0 && result[resultlen - 1] == '\0' - && strlen (result) == resultlen - 1) + && strlen (result) == resultlen - 1) return result; conversion_error (context); @@ -95,17 +95,17 @@ convert_string_directly (iconv_t cd, const char *string, static char * convert_string (const iconveh_t *cd, const char *string, - const struct conversion_context* context) + const struct conversion_context* context) { size_t len = strlen (string) + 1; char *result = NULL; size_t resultlen = 0; if (xmem_cd_iconveh (string, len, cd, iconveh_error, NULL, - &result, &resultlen) == 0) + &result, &resultlen) == 0) /* Verify the result has exactly one NUL byte, at the end. */ if (resultlen > 0 && result[resultlen - 1] == '\0' - && strlen (result) == resultlen - 1) + && strlen (result) == resultlen - 1) return result; conversion_error (context); @@ -115,7 +115,7 @@ convert_string (const iconveh_t *cd, const char *string, static void convert_string_list (const iconveh_t *cd, string_list_ty *slp, - const struct conversion_context* context) + const struct conversion_context* context) { size_t i; @@ -126,7 +126,7 @@ convert_string_list (const iconveh_t *cd, string_list_ty *slp, static void convert_prev_msgid (const iconveh_t *cd, message_ty *mp, - const struct conversion_context* context) + const struct conversion_context* context) { if (mp->prev_msgctxt != NULL) mp->prev_msgctxt = convert_string (cd, mp->prev_msgctxt, context); @@ -138,7 +138,7 @@ convert_prev_msgid (const iconveh_t *cd, message_ty *mp, static void convert_msgid (const iconveh_t *cd, message_ty *mp, - const struct conversion_context* context) + const struct conversion_context* context) { if (mp->msgctxt != NULL) mp->msgctxt = convert_string (cd, mp->msgctxt, context); @@ -149,7 +149,7 @@ convert_msgid (const iconveh_t *cd, message_ty *mp, static void convert_msgstr (const iconveh_t *cd, message_ty *mp, - const struct conversion_context* context) + const struct conversion_context* context) { char *result = NULL; size_t resultlen = 0; @@ -158,29 +158,29 @@ convert_msgstr (const iconveh_t *cd, message_ty *mp, abort (); if (xmem_cd_iconveh (mp->msgstr, mp->msgstr_len, cd, iconveh_error, NULL, - &result, &resultlen) == 0) + &result, &resultlen) == 0) /* Verify the result has a NUL byte at the end. */ if (resultlen > 0 && result[resultlen - 1] == '\0') /* Verify the result has the same number of NUL bytes. */ { - const char *p; - const char *pend; - int nulcount1; - int nulcount2; - - for (p = mp->msgstr, pend = p + mp->msgstr_len, nulcount1 = 0; - p < pend; - p += strlen (p) + 1, nulcount1++); - for (p = result, pend = p + resultlen, nulcount2 = 0; - p < pend; - p += strlen (p) + 1, nulcount2++); - - if (nulcount1 == nulcount2) - { - mp->msgstr = result; - mp->msgstr_len = resultlen; - return; - } + const char *p; + const char *pend; + int nulcount1; + int nulcount2; + + for (p = mp->msgstr, pend = p + mp->msgstr_len, nulcount1 = 0; + p < pend; + p += strlen (p) + 1, nulcount1++); + for (p = result, pend = p + resultlen, nulcount2 = 0; + p < pend; + p += strlen (p) + 1, nulcount2++); + + if (nulcount1 == nulcount2) + { + mp->msgstr = result; + mp->msgstr_len = resultlen; + return; + } } conversion_error (context); @@ -191,10 +191,10 @@ convert_msgstr (const iconveh_t *cd, message_ty *mp, static bool iconv_message_list_internal (message_list_ty *mlp, - const char *canon_from_code, - const char *canon_to_code, - bool update_header, - const char *from_filename) + const char *canon_from_code, + const char *canon_to_code, + bool update_header, + const char *from_filename) { bool canon_from_code_overridden = (canon_from_code != NULL); bool msgids_changed; @@ -208,86 +208,86 @@ iconv_message_list_internal (message_list_ty *mlp, for (j = 0; j < mlp->nitems; j++) if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *charsetstr = c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - char *charset; - const char *canon_charset; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - charset = (char *) xmalloca (len + 1); - memcpy (charset, charsetstr, len); - charset[len] = '\0'; - - canon_charset = po_charset_canonicalize (charset); - if (canon_charset == NULL) - { - if (!canon_from_code_overridden) - { - /* Don't give an error for POT files, because POT - files usually contain only ASCII msgids. */ - const char *filename = from_filename; - size_t filenamelen; - - if (filename != NULL - && (filenamelen = strlen (filename)) >= 4 - && memcmp (filename + filenamelen - 4, ".pot", 4) - == 0 - && strcmp (charset, "CHARSET") == 0) - canon_charset = po_charset_ascii; - else - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, - false, xasprintf (_("\ + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *charsetstr = c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + char *charset; + const char *canon_charset; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + charset = (char *) xmalloca (len + 1); + memcpy (charset, charsetstr, len); + charset[len] = '\0'; + + canon_charset = po_charset_canonicalize (charset); + if (canon_charset == NULL) + { + if (!canon_from_code_overridden) + { + /* Don't give an error for POT files, because POT + files usually contain only ASCII msgids. */ + const char *filename = from_filename; + size_t filenamelen; + + if (filename != NULL + && (filenamelen = strlen (filename)) >= 4 + && memcmp (filename + filenamelen - 4, ".pot", 4) + == 0 + && strcmp (charset, "CHARSET") == 0) + canon_charset = po_charset_ascii; + else + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, + false, xasprintf (_("\ present charset \"%s\" is not a portable encoding name"), - charset)); - } - } - else - { - if (canon_from_code == NULL) - canon_from_code = canon_charset; - else if (canon_from_code != canon_charset) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, - false, - xasprintf (_("\ + charset)); + } + } + else + { + if (canon_from_code == NULL) + canon_from_code = canon_charset; + else if (canon_from_code != canon_charset) + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, + false, + xasprintf (_("\ two different charsets \"%s\" and \"%s\" in input file"), - canon_from_code, canon_charset)); - } - freea (charset); - - if (update_header) - { - size_t len1, len2, len3; - char *new_header; - - len1 = charsetstr - header; - len2 = strlen (canon_to_code); - len3 = (header + strlen (header)) - (charsetstr + len); - new_header = XNMALLOC (len1 + len2 + len3 + 1, char); - memcpy (new_header, header, len1); - memcpy (new_header + len1, canon_to_code, len2); - memcpy (new_header + len1 + len2, charsetstr + len, - len3 + 1); - mlp->item[j]->msgstr = new_header; - mlp->item[j]->msgstr_len = len1 + len2 + len3 + 1; - } - } - } + canon_from_code, canon_charset)); + } + freea (charset); + + if (update_header) + { + size_t len1, len2, len3; + char *new_header; + + len1 = charsetstr - header; + len2 = strlen (canon_to_code); + len3 = (header + strlen (header)) - (charsetstr + len); + new_header = XNMALLOC (len1 + len2 + len3 + 1, char); + memcpy (new_header, header, len1); + memcpy (new_header + len1, canon_to_code, len2); + memcpy (new_header + len1 + len2, charsetstr + len, + len3 + 1); + mlp->item[j]->msgstr = new_header; + mlp->item[j]->msgstr_len = len1 + len2 + len3 + 1; + } + } + } } if (canon_from_code == NULL) { if (is_ascii_message_list (mlp)) - canon_from_code = po_charset_ascii; + canon_from_code = po_charset_ascii; else - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - _("\ + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + _("\ input file doesn't contain a header entry with a charset specification")); } @@ -301,48 +301,48 @@ input file doesn't contain a header entry with a charset specification")); struct conversion_context context; if (iconveh_open (canon_to_code, canon_from_code, &cd) < 0) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf (_("\ + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf (_("\ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(), \ and iconv() does not support this conversion."), - canon_from_code, canon_to_code, - basename (program_name))); + canon_from_code, canon_to_code, + basename (program_name))); context.from_code = canon_from_code; context.to_code = canon_to_code; context.from_filename = from_filename; for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - - if ((mp->msgctxt != NULL && !is_ascii_string (mp->msgctxt)) - || !is_ascii_string (mp->msgid)) - msgids_changed = true; - context.message = mp; - convert_string_list (&cd, mp->comment, &context); - convert_string_list (&cd, mp->comment_dot, &context); - convert_prev_msgid (&cd, mp, &context); - convert_msgid (&cd, mp, &context); - convert_msgstr (&cd, mp, &context); - } + { + message_ty *mp = mlp->item[j]; + + if ((mp->msgctxt != NULL && !is_ascii_string (mp->msgctxt)) + || !is_ascii_string (mp->msgid)) + msgids_changed = true; + context.message = mp; + convert_string_list (&cd, mp->comment, &context); + convert_string_list (&cd, mp->comment_dot, &context); + convert_prev_msgid (&cd, mp, &context); + convert_msgid (&cd, mp, &context); + convert_msgstr (&cd, mp, &context); + } iconveh_close (&cd); if (msgids_changed) - if (message_list_msgids_changed (mlp)) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf (_("\ + if (message_list_msgids_changed (mlp)) + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf (_("\ Conversion from \"%s\" to \"%s\" introduces duplicates: \ some different msgids become equal."), - canon_from_code, canon_to_code)); + canon_from_code, canon_to_code)); #else - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf (_("\ + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf (_("\ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(). \ This version was built without iconv()."), - canon_from_code, canon_to_code, - basename (program_name))); + canon_from_code, canon_to_code, + basename (program_name))); #endif } @@ -351,19 +351,19 @@ This version was built without iconv()."), bool iconv_message_list (message_list_ty *mlp, - const char *canon_from_code, const char *canon_to_code, - const char *from_filename) + const char *canon_from_code, const char *canon_to_code, + const char *from_filename) { return iconv_message_list_internal (mlp, - canon_from_code, canon_to_code, true, - from_filename); + canon_from_code, canon_to_code, true, + from_filename); } msgdomain_list_ty * iconv_msgdomain_list (msgdomain_list_ty *mdlp, - const char *to_code, - bool update_header, - const char *from_filename) + const char *to_code, + bool update_header, + const char *from_filename) { const char *canon_to_code; size_t k; @@ -372,14 +372,14 @@ iconv_msgdomain_list (msgdomain_list_ty *mdlp, canon_to_code = po_charset_canonicalize (to_code); if (canon_to_code == NULL) po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf (_("\ + xasprintf (_("\ target charset \"%s\" is not a portable encoding name."), - to_code)); + to_code)); for (k = 0; k < mdlp->nitems; k++) iconv_message_list_internal (mdlp->item[k]->messages, - mdlp->encoding, canon_to_code, update_header, - from_filename); + mdlp->encoding, canon_to_code, update_header, + from_filename); mdlp->encoding = canon_to_code; return mdlp; @@ -395,11 +395,11 @@ iconvable_string (const iconveh_t *cd, const char *string) size_t resultlen = 0; if (xmem_cd_iconveh (string, len, cd, iconveh_error, NULL, - &result, &resultlen) == 0) + &result, &resultlen) == 0) { /* Test if the result has exactly one NUL byte, at the end. */ bool ok = (resultlen > 0 && result[resultlen - 1] == '\0' - && strlen (result) == resultlen - 1); + && strlen (result) == resultlen - 1); free (result); return ok; } @@ -414,7 +414,7 @@ iconvable_string_list (const iconveh_t *cd, string_list_ty *slp) if (slp != NULL) for (i = 0; i < slp->nitems; i++) if (!iconvable_string (cd, slp->item[i])) - return false; + return false; return true; } @@ -457,29 +457,29 @@ iconvable_msgstr (const iconveh_t *cd, message_ty *mp) abort (); if (xmem_cd_iconveh (mp->msgstr, mp->msgstr_len, cd, iconveh_error, NULL, - &result, &resultlen) == 0) + &result, &resultlen) == 0) { bool ok = false; /* Test if the result has a NUL byte at the end. */ if (resultlen > 0 && result[resultlen - 1] == '\0') - /* Test if the result has the same number of NUL bytes. */ - { - const char *p; - const char *pend; - int nulcount1; - int nulcount2; - - for (p = mp->msgstr, pend = p + mp->msgstr_len, nulcount1 = 0; - p < pend; - p += strlen (p) + 1, nulcount1++); - for (p = result, pend = p + resultlen, nulcount2 = 0; - p < pend; - p += strlen (p) + 1, nulcount2++); - - if (nulcount1 == nulcount2) - ok = true; - } + /* Test if the result has the same number of NUL bytes. */ + { + const char *p; + const char *pend; + int nulcount1; + int nulcount2; + + for (p = mp->msgstr, pend = p + mp->msgstr_len, nulcount1 = 0; + p < pend; + p += strlen (p) + 1, nulcount1++); + for (p = result, pend = p + resultlen, nulcount2 = 0; + p < pend; + p += strlen (p) + 1, nulcount2++); + + if (nulcount1 == nulcount2) + ok = true; + } free (result); return ok; @@ -491,8 +491,8 @@ iconvable_msgstr (const iconveh_t *cd, message_ty *mp) bool is_message_list_iconvable (message_list_ty *mlp, - const char *canon_from_code, - const char *canon_to_code) + const char *canon_from_code, + const char *canon_to_code) { bool canon_from_code_overridden = (canon_from_code != NULL); size_t j; @@ -505,63 +505,63 @@ is_message_list_iconvable (message_list_ty *mlp, for (j = 0; j < mlp->nitems; j++) if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *charsetstr = c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - char *charset; - const char *canon_charset; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - charset = (char *) xmalloca (len + 1); - memcpy (charset, charsetstr, len); - charset[len] = '\0'; - - canon_charset = po_charset_canonicalize (charset); - if (canon_charset == NULL) - { - if (!canon_from_code_overridden) - { - /* Don't give an error for POT files, because POT - files usually contain only ASCII msgids. */ - if (strcmp (charset, "CHARSET") == 0) - canon_charset = po_charset_ascii; - else - { - /* charset is not a portable encoding name. */ - freea (charset); - return false; - } - } - } - else - { - if (canon_from_code == NULL) - canon_from_code = canon_charset; - else if (canon_from_code != canon_charset) - { - /* Two different charsets in input file. */ - freea (charset); - return false; - } - } - freea (charset); - } - } + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *charsetstr = c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + char *charset; + const char *canon_charset; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + charset = (char *) xmalloca (len + 1); + memcpy (charset, charsetstr, len); + charset[len] = '\0'; + + canon_charset = po_charset_canonicalize (charset); + if (canon_charset == NULL) + { + if (!canon_from_code_overridden) + { + /* Don't give an error for POT files, because POT + files usually contain only ASCII msgids. */ + if (strcmp (charset, "CHARSET") == 0) + canon_charset = po_charset_ascii; + else + { + /* charset is not a portable encoding name. */ + freea (charset); + return false; + } + } + } + else + { + if (canon_from_code == NULL) + canon_from_code = canon_charset; + else if (canon_from_code != canon_charset) + { + /* Two different charsets in input file. */ + freea (charset); + return false; + } + } + freea (charset); + } + } } if (canon_from_code == NULL) { if (is_ascii_message_list (mlp)) - canon_from_code = po_charset_ascii; + canon_from_code = po_charset_ascii; else - /* Input file lacks a header entry with a charset specification. */ - return false; + /* Input file lacks a header entry with a charset specification. */ + return false; } /* If the two encodings are the same, nothing to check. */ @@ -571,20 +571,20 @@ is_message_list_iconvable (message_list_ty *mlp, iconveh_t cd; if (iconveh_open (canon_to_code, canon_from_code, &cd) < 0) - /* iconv() doesn't support this conversion. */ - return false; + /* iconv() doesn't support this conversion. */ + return false; for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - - if (!(iconvable_string_list (&cd, mp->comment) - && iconvable_string_list (&cd, mp->comment_dot) - && iconvable_prev_msgid (&cd, mp) - && iconvable_msgid (&cd, mp) - && iconvable_msgstr (&cd, mp))) - return false; - } + { + message_ty *mp = mlp->item[j]; + + if (!(iconvable_string_list (&cd, mp->comment) + && iconvable_string_list (&cd, mp->comment_dot) + && iconvable_prev_msgid (&cd, mp) + && iconvable_msgid (&cd, mp) + && iconvable_msgstr (&cd, mp))) + return false; + } iconveh_close (&cd); #else diff --git a/gettext-tools/src/msgl-iconv.h b/gettext-tools/src/msgl-iconv.h index 5833db11a..5a7fc00d9 100644 --- a/gettext-tools/src/msgl-iconv.h +++ b/gettext-tools/src/msgl-iconv.h @@ -45,7 +45,7 @@ struct conversion_context /* Converts the STRING through the conversion descriptor CD. Assumes that either FROM_CODE or TO_CODE is UTF-8. */ extern char *convert_string_directly (iconv_t cd, const char *string, - const struct conversion_context* context); + const struct conversion_context* context); #endif @@ -56,18 +56,18 @@ extern char *convert_string_directly (iconv_t cd, const char *string, some msgctxt or msgid changed due to the conversion. */ extern bool iconv_message_list (message_list_ty *mlp, - const char *canon_from_code, - const char *canon_to_code, - const char *from_filename); + const char *canon_from_code, + const char *canon_to_code, + const char *from_filename); /* Converts all the message lists in MDLP to the encoding TO_CODE. UPDATE_HEADER specifies whether to update the "charset=..." specification in the header; it should normally be true. */ extern msgdomain_list_ty * iconv_msgdomain_list (msgdomain_list_ty *mdlp, - const char *to_code, - bool update_header, - const char *from_filename); + const char *to_code, + bool update_header, + const char *from_filename); /* Tests whether the message list MLP could be converted to CANON_TO_CODE. The (already canonicalized) encoding before conversion can be passed as @@ -75,8 +75,8 @@ extern msgdomain_list_ty * in the header entry. */ extern bool is_message_list_iconvable (message_list_ty *mlp, - const char *canon_from_code, - const char *canon_to_code); + const char *canon_from_code, + const char *canon_to_code); #ifdef __cplusplus diff --git a/gettext-tools/src/msgmerge.c b/gettext-tools/src/msgmerge.c index b48c683f0..fde4ee503 100644 --- a/gettext-tools/src/msgmerge.c +++ b/gettext-tools/src/msgmerge.c @@ -152,14 +152,14 @@ struct statistics /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; static void compendium (const char *filename); static void msgdomain_list_stablesort_by_obsolete (msgdomain_list_ty *mdlp); static msgdomain_list_ty *merge (const char *fn1, const char *fn2, - catalog_input_format_ty input_syntax, - msgdomain_list_ty **defp); + catalog_input_format_ty input_syntax, + msgdomain_list_ty **defp); int @@ -202,126 +202,126 @@ main (int argc, char **argv) output_file = NULL; while ((opt = getopt_long (argc, argv, "C:D:eEFhimNo:pPqsUvVw:", - long_options, NULL)) - != EOF) + long_options, NULL)) + != EOF) switch (opt) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'C': - compendium (optarg); - break; + compendium (optarg); + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'e': - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case 'E': - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case 'F': - sort_by_filepos = true; - break; + sort_by_filepos = true; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - message_print_style_indent (); - break; + message_print_style_indent (); + break; case 'm': - multi_domain_mode = true; - break; + multi_domain_mode = true; + break; case 'N': - use_fuzzy_matching = false; - break; + use_fuzzy_matching = false; + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 'q': - quiet = true; - break; + quiet = true; + break; case 's': - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case 'U': - update_mode = true; - break; + update_mode = true; + break; case 'v': - ++verbosity_level; - break; + ++verbosity_level; + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case CHAR_MAX + 1: /* --backup */ - version_control_string = optarg; - break; + version_control_string = optarg; + break; case CHAR_MAX + 2: /* --strict */ - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case CHAR_MAX + 3: /* --suffix */ - backup_suffix_string = optarg; - break; + backup_suffix_string = optarg; + break; case CHAR_MAX + 4: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 5: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 6: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; case CHAR_MAX + 7: /* --previous */ - keep_previous = true; - break; + keep_previous = true; + break; case CHAR_MAX + 8: /* --lang */ - catalogname = optarg; - break; + catalogname = optarg; + break; default: - usage (EXIT_FAILURE); - break; + usage (EXIT_FAILURE); + break; } /* Version information is requested. */ @@ -334,7 +334,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "1995-1998, 2000-2009"); + "1995-1998, 2000-2009"); printf (_("Written by %s.\n"), proper_name ("Peter Miller")); exit (EXIT_SUCCESS); } @@ -359,34 +359,34 @@ There is NO WARRANTY, to the extent permitted by law.\n\ if (update_mode) { if (output_file != NULL) - { - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--update", "--output-file"); - } + { + error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), + "--update", "--output-file"); + } } else { if (version_control_string != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s"), - "--backup", "--update"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, _("%s is only valid with %s"), + "--backup", "--update"); + usage (EXIT_FAILURE); + } if (backup_suffix_string != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s"), - "--suffix", "--update"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, _("%s is only valid with %s"), + "--suffix", "--update"); + usage (EXIT_FAILURE); + } } if (!line_comment && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); + "--no-location", "--sort-by-file"); if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--sort-output", "--sort-by-file"); + "--sort-output", "--sort-by-file"); /* In update mode, --properties-input implies --properties-output. */ if (update_mode && input_syntax == &input_format_properties) @@ -407,49 +407,49 @@ There is NO WARRANTY, to the extent permitted by law.\n\ if (update_mode) { /* Before comparing result with def, sort the result into the same order - as would be done implicitly by output_syntax->print. */ + as would be done implicitly by output_syntax->print. */ if (output_syntax->sorts_obsoletes_to_end) - msgdomain_list_stablesort_by_obsolete (result); + msgdomain_list_stablesort_by_obsolete (result); /* Do nothing if the original file and the result are equal. Also do - nothing if the original file and the result differ only by the - POT-Creation-Date in the header entry; this is needed for projects - which don't put the .pot file under CVS. */ + nothing if the original file and the result differ only by the + POT-Creation-Date in the header entry; this is needed for projects + which don't put the .pot file under CVS. */ if (!msgdomain_list_equal (def, result, true)) - { - /* Back up def.po. */ - enum backup_type backup_type; - char *backup_file; - - output_file = argv[optind]; - - if (backup_suffix_string == NULL) - { - backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX"); - if (backup_suffix_string != NULL - && backup_suffix_string[0] == '\0') - backup_suffix_string = NULL; - } - if (backup_suffix_string != NULL) - simple_backup_suffix = backup_suffix_string; - - backup_type = xget_version (_("backup type"), version_control_string); - if (backup_type != none) - { - backup_file = find_backup_file_name (output_file, backup_type); - copy_file_preserving (output_file, backup_file); - } - - /* Write the merged message list out. */ - msgdomain_list_print (result, output_file, output_syntax, true, - false); - } + { + /* Back up def.po. */ + enum backup_type backup_type; + char *backup_file; + + output_file = argv[optind]; + + if (backup_suffix_string == NULL) + { + backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX"); + if (backup_suffix_string != NULL + && backup_suffix_string[0] == '\0') + backup_suffix_string = NULL; + } + if (backup_suffix_string != NULL) + simple_backup_suffix = backup_suffix_string; + + backup_type = xget_version (_("backup type"), version_control_string); + if (backup_type != none) + { + backup_file = find_backup_file_name (output_file, backup_type); + copy_file_preserving (output_file, backup_file); + } + + /* Write the merged message list out. */ + msgdomain_list_print (result, output_file, output_syntax, true, + false); + } } else { /* Write the merged message list out. */ msgdomain_list_print (result, output_file, output_syntax, force_po, - false); + false); } exit (EXIT_SUCCESS); @@ -462,7 +462,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -596,7 +596,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); @@ -635,34 +635,34 @@ msgdomain_list_stablesort_by_obsolete (msgdomain_list_ty *mdlp) /* Sort obsolete messages to the end. */ if (mlp->nitems > 0) - { - message_ty **l1 = XNMALLOC (mlp->nitems, message_ty *); - size_t n1; - message_ty **l2 = XNMALLOC (mlp->nitems, message_ty *); - size_t n2; - size_t j; - - /* Sort the non-obsolete messages into l1 and the obsolete messages - into l2. */ - n1 = 0; - n2 = 0; - for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - - if (mp->obsolete) - l2[n2++] = mp; - else - l1[n1++] = mp; - } - if (n1 > 0 && n2 > 0) - { - memcpy (mlp->item, l1, n1 * sizeof (message_ty *)); - memcpy (mlp->item + n1, l2, n2 * sizeof (message_ty *)); - } - free (l2); - free (l1); - } + { + message_ty **l1 = XNMALLOC (mlp->nitems, message_ty *); + size_t n1; + message_ty **l2 = XNMALLOC (mlp->nitems, message_ty *); + size_t n2; + size_t j; + + /* Sort the non-obsolete messages into l1 and the obsolete messages + into l2. */ + n1 = 0; + n2 = 0; + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + + if (mp->obsolete) + l2[n2++] = mp; + else + l1[n1++] = mp; + } + if (n1 > 0 && n2 > 0) + { + memcpy (mlp->item, l1, n1 * sizeof (message_ty *)); + memcpy (mlp->item + n1, l2, n2 * sizeof (message_ty *)); + } + free (l2); + free (l1); + } } } @@ -742,7 +742,7 @@ definitions_init_curr_findex (definitions_ty *definitions) if (definitions->curr_findex == NULL) definitions->curr_findex = message_fuzzy_index_alloc (definitions_current_list (definitions), - definitions->canon_charset); + definitions->canon_charset); gl_lock_unlock (definitions->curr_findex_init_lock); } @@ -756,23 +756,23 @@ definitions_init_comp_findex (definitions_ty *definitions) if (definitions->comp_findex == NULL) { /* Combine all the compendium message lists into a single one. Don't - bother checking for duplicates. */ + bother checking for duplicates. */ message_list_ty *all_compendium; size_t i; all_compendium = message_list_alloc (false); for (i = 0; i < compendiums->nitems; i++) - { - message_list_ty *mlp = compendiums->item[i]; - size_t j; + { + message_list_ty *mlp = compendiums->item[i]; + size_t j; - for (j = 0; j < mlp->nitems; j++) - message_list_append (all_compendium, mlp->item[j]); - } + for (j = 0; j < mlp->nitems; j++) + message_list_append (all_compendium, mlp->item[j]); + } /* Create the fuzzy index from it. */ definitions->comp_findex = - message_fuzzy_index_alloc (all_compendium, definitions->canon_charset); + message_fuzzy_index_alloc (all_compendium, definitions->canon_charset); } gl_lock_unlock (definitions->comp_findex_init_lock); } @@ -780,7 +780,7 @@ definitions_init_comp_findex (definitions_ty *definitions) /* Exact search. */ static inline message_ty * definitions_search (const definitions_ty *definitions, - const char *msgctxt, const char *msgid) + const char *msgctxt, const char *msgid) { return message_list_list_search (definitions->lists, msgctxt, msgid); } @@ -789,7 +789,7 @@ definitions_search (const definitions_ty *definitions, Used only if use_fuzzy_matching is true. */ static inline message_ty * definitions_search_fuzzy (definitions_ty *definitions, - const char *msgctxt, const char *msgid) + const char *msgctxt, const char *msgid) { message_ty *mp1; @@ -797,19 +797,19 @@ definitions_search_fuzzy (definitions_ty *definitions, { /* Old, slow code. */ mp1 = - message_list_search_fuzzy (definitions_current_list (definitions), - msgctxt, msgid); + message_list_search_fuzzy (definitions_current_list (definitions), + msgctxt, msgid); } else { /* Speedup through early abort in fstrcmp(), combined with pre-sorting - of the messages through a hashed index. */ + of the messages through a hashed index. */ /* Create the fuzzy index lazily. */ if (definitions->curr_findex == NULL) - definitions_init_curr_findex (definitions); + definitions_init_curr_findex (definitions); mp1 = message_fuzzy_index_search (definitions->curr_findex, - msgctxt, msgid, - FUZZY_THRESHOLD, false); + msgctxt, msgid, + FUZZY_THRESHOLD, false); } if (compendiums != NULL) @@ -818,28 +818,28 @@ definitions_search_fuzzy (definitions_ty *definitions, message_ty *mp2; lower_bound_for_mp2 = - (mp1 != NULL - ? fuzzy_search_goal_function (mp1, msgctxt, msgid, 0.0) - : FUZZY_THRESHOLD); + (mp1 != NULL + ? fuzzy_search_goal_function (mp1, msgctxt, msgid, 0.0) + : FUZZY_THRESHOLD); /* This lower bound must be >= FUZZY_THRESHOLD. */ if (!(lower_bound_for_mp2 >= FUZZY_THRESHOLD)) - abort (); + abort (); /* Create the fuzzy index lazily. */ if (definitions->comp_findex == NULL) - definitions_init_comp_findex (definitions); + definitions_init_comp_findex (definitions); mp2 = message_fuzzy_index_search (definitions->comp_findex, - msgctxt, msgid, - lower_bound_for_mp2, true); + msgctxt, msgid, + lower_bound_for_mp2, true); /* Choose the best among mp1, mp2. */ if (mp1 == NULL - || (mp2 != NULL - && (fuzzy_search_goal_function (mp2, msgctxt, msgid, - lower_bound_for_mp2) - > lower_bound_for_mp2))) - mp1 = mp2; + || (mp2 != NULL + && (fuzzy_search_goal_function (mp2, msgctxt, msgid, + lower_bound_for_mp2) + > lower_bound_for_mp2))) + mp1 = mp2; } return mp1; @@ -870,16 +870,16 @@ silent_error_logger (const char *format, ...) /* Another silent error logger. */ static void silent_xerror (int severity, - const struct message_ty *message, - const char *filename, size_t lineno, size_t column, - int multiline_p, const char *message_text) + const struct message_ty *message, + const char *filename, size_t lineno, size_t column, + int multiline_p, const char *message_text) { } static message_ty * message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, - const struct plural_distribution *distribution) + const struct plural_distribution *distribution) { const char *msgstr; size_t msgstr_len; @@ -902,37 +902,37 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, /* Oh, oh. The header entry and we have something to fill in. */ static const struct { - const char *name; - size_t len; + const char *name; + size_t len; } known_fields[] = { - { "Project-Id-Version:", sizeof ("Project-Id-Version:") - 1 }, -#define PROJECT_ID 0 - { "Report-Msgid-Bugs-To:", sizeof ("Report-Msgid-Bugs-To:") - 1 }, -#define REPORT_MSGID_BUGS_TO 1 - { "POT-Creation-Date:", sizeof ("POT-Creation-Date:") - 1 }, -#define POT_CREATION_DATE 2 - { "PO-Revision-Date:", sizeof ("PO-Revision-Date:") - 1 }, -#define PO_REVISION_DATE 3 - { "Last-Translator:", sizeof ("Last-Translator:") - 1 }, -#define LAST_TRANSLATOR 4 - { "Language-Team:", sizeof ("Language-Team:") - 1 }, -#define LANGUAGE_TEAM 5 - { "Language:", sizeof ("Language:") - 1 }, -#define LANGUAGE 6 - { "MIME-Version:", sizeof ("MIME-Version:") - 1 }, -#define MIME_VERSION 7 - { "Content-Type:", sizeof ("Content-Type:") - 1 }, -#define CONTENT_TYPE 8 - { "Content-Transfer-Encoding:", - sizeof ("Content-Transfer-Encoding:") - 1 } -#define CONTENT_TRANSFER 9 + { "Project-Id-Version:", sizeof ("Project-Id-Version:") - 1 }, +#define PROJECT_ID 0 + { "Report-Msgid-Bugs-To:", sizeof ("Report-Msgid-Bugs-To:") - 1 }, +#define REPORT_MSGID_BUGS_TO 1 + { "POT-Creation-Date:", sizeof ("POT-Creation-Date:") - 1 }, +#define POT_CREATION_DATE 2 + { "PO-Revision-Date:", sizeof ("PO-Revision-Date:") - 1 }, +#define PO_REVISION_DATE 3 + { "Last-Translator:", sizeof ("Last-Translator:") - 1 }, +#define LAST_TRANSLATOR 4 + { "Language-Team:", sizeof ("Language-Team:") - 1 }, +#define LANGUAGE_TEAM 5 + { "Language:", sizeof ("Language:") - 1 }, +#define LANGUAGE 6 + { "MIME-Version:", sizeof ("MIME-Version:") - 1 }, +#define MIME_VERSION 7 + { "Content-Type:", sizeof ("Content-Type:") - 1 }, +#define CONTENT_TYPE 8 + { "Content-Transfer-Encoding:", + sizeof ("Content-Transfer-Encoding:") - 1 } +#define CONTENT_TRANSFER 9 }; -#define UNKNOWN 10 +#define UNKNOWN 10 struct { - const char *string; - size_t len; + const char *string; + size_t len; } header_fields[UNKNOWN + 1]; struct obstack pool; const char *cp; @@ -947,239 +947,239 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, cp = def->msgstr; while (*cp != '\0') - { - const char *endp = strchr (cp, '\n'); - int terminated = endp != NULL; - - if (!terminated) - { - /* Add a trailing newline. */ - char *copy; - endp = strchr (cp, '\0'); - - len = endp - cp + 1; - - copy = (char *) obstack_alloc (&pool, len + 1); - stpcpy (stpcpy (copy, cp), "\n"); - cp = copy; - } - else - { - len = (endp - cp) + 1; - ++endp; - } - - /* Compare with any of the known fields. */ - for (cnt = 0; - cnt < sizeof (known_fields) / sizeof (known_fields[0]); - ++cnt) - if (c_strncasecmp (cp, known_fields[cnt].name, known_fields[cnt].len) - == 0) - break; - - if (cnt < sizeof (known_fields) / sizeof (known_fields[0])) - { - header_fields[cnt].string = &cp[known_fields[cnt].len]; - header_fields[cnt].len = len - known_fields[cnt].len; - } - else - { - /* It's an unknown field. Append content to what is already - known. */ - char *extended = - (char *) obstack_alloc (&pool, - header_fields[UNKNOWN].len + len + 1); - memcpy (extended, header_fields[UNKNOWN].string, - header_fields[UNKNOWN].len); - memcpy (&extended[header_fields[UNKNOWN].len], cp, len); - extended[header_fields[UNKNOWN].len + len] = '\0'; - header_fields[UNKNOWN].string = extended; - header_fields[UNKNOWN].len += len; - } - - cp = endp; - } + { + const char *endp = strchr (cp, '\n'); + int terminated = endp != NULL; + + if (!terminated) + { + /* Add a trailing newline. */ + char *copy; + endp = strchr (cp, '\0'); + + len = endp - cp + 1; + + copy = (char *) obstack_alloc (&pool, len + 1); + stpcpy (stpcpy (copy, cp), "\n"); + cp = copy; + } + else + { + len = (endp - cp) + 1; + ++endp; + } + + /* Compare with any of the known fields. */ + for (cnt = 0; + cnt < sizeof (known_fields) / sizeof (known_fields[0]); + ++cnt) + if (c_strncasecmp (cp, known_fields[cnt].name, known_fields[cnt].len) + == 0) + break; + + if (cnt < sizeof (known_fields) / sizeof (known_fields[0])) + { + header_fields[cnt].string = &cp[known_fields[cnt].len]; + header_fields[cnt].len = len - known_fields[cnt].len; + } + else + { + /* It's an unknown field. Append content to what is already + known. */ + char *extended = + (char *) obstack_alloc (&pool, + header_fields[UNKNOWN].len + len + 1); + memcpy (extended, header_fields[UNKNOWN].string, + header_fields[UNKNOWN].len); + memcpy (&extended[header_fields[UNKNOWN].len], cp, len); + extended[header_fields[UNKNOWN].len + len] = '\0'; + header_fields[UNKNOWN].string = extended; + header_fields[UNKNOWN].len += len; + } + + cp = endp; + } /* Set the Language field if specified on the command line. */ if (catalogname != NULL) - { - /* Prepend a space and append a newline. */ - size_t len = strlen (catalogname); - char *copy = (char *) obstack_alloc (&pool, 1 + len + 1 + 1); - stpcpy (stpcpy (stpcpy (copy, " "), catalogname), "\n"); - header_fields[LANGUAGE].string = copy; - header_fields[LANGUAGE].len = strlen (header_fields[LANGUAGE].string); - } + { + /* Prepend a space and append a newline. */ + size_t len = strlen (catalogname); + char *copy = (char *) obstack_alloc (&pool, 1 + len + 1 + 1); + stpcpy (stpcpy (stpcpy (copy, " "), catalogname), "\n"); + header_fields[LANGUAGE].string = copy; + header_fields[LANGUAGE].len = strlen (header_fields[LANGUAGE].string); + } /* Add a Language field to PO files that don't have one. The Language - field was introduced in gettext-0.18. */ + field was introduced in gettext-0.18. */ else if (header_fields[LANGUAGE].string == NULL) - { - const char *language_team_ptr = header_fields[LANGUAGE_TEAM].string; - - if (language_team_ptr != NULL) - { - size_t language_team_len = header_fields[LANGUAGE_TEAM].len; - - /* Trim leading blanks. */ - while (language_team_len > 0 - && (*language_team_ptr == ' ' - || *language_team_ptr == '\t')) - { - language_team_ptr++; - language_team_len--; - } - - /* Trim trailing blanks. */ - while (language_team_len > 0 - && (language_team_ptr[language_team_len - 1] == ' ' - || language_team_ptr[language_team_len - 1] == '\t')) - language_team_len--; - - /* Trim last word, if it looks like an URL or email address. */ - { - size_t i; - - for (i = language_team_len; i > 0; i--) - if (language_team_ptr[i - 1] == ' ' - || language_team_ptr[i - 1] == '\t') - break; - /* The last word: language_team_ptr[i..language_team_len-1]. */ - if (i < language_team_len - && (language_team_ptr[i] == '<' - || language_team_ptr[language_team_len - 1] == '>' - || memchr (language_team_ptr, '@', language_team_len) - != NULL - || memchr (language_team_ptr, '/', language_team_len) - != NULL)) - { - /* Trim last word and blanks before it. */ - while (i > 0 - && (language_team_ptr[i - 1] == ' ' - || language_team_ptr[i - 1] == '\t')) - i--; - language_team_len = i; - } - } - - /* The rest of the Language-Team field should be the english name - of the languge. Convert to ISO 639 and ISO 3166 syntax. */ - { - size_t i; - - for (i = 0; i < language_variant_table_size; i++) - if (strlen (language_variant_table[i].english) - == language_team_len - && memcmp (language_variant_table[i].english, - language_team_ptr, language_team_len) == 0) - { - header_fields[LANGUAGE].string = - language_variant_table[i].code; - break; - } - } - if (header_fields[LANGUAGE].string == NULL) - { - size_t i; - - for (i = 0; i < language_table_size; i++) - if (strlen (language_table[i].english) == language_team_len - && memcmp (language_table[i].english, - language_team_ptr, language_team_len) == 0) - { - header_fields[LANGUAGE].string = language_table[i].code; - break; - } - } - if (header_fields[LANGUAGE].string != NULL) - { - /* Prepend a space and append a newline. */ - const char *str = header_fields[LANGUAGE].string; - size_t len = strlen (str); - char *copy = (char *) obstack_alloc (&pool, 1 + len + 1 + 1); - stpcpy (stpcpy (stpcpy (copy, " "), str), "\n"); - header_fields[LANGUAGE].string = copy; - } - else - header_fields[LANGUAGE].string = " \n"; - header_fields[LANGUAGE].len = - strlen (header_fields[LANGUAGE].string); - } + { + const char *language_team_ptr = header_fields[LANGUAGE_TEAM].string; + + if (language_team_ptr != NULL) + { + size_t language_team_len = header_fields[LANGUAGE_TEAM].len; + + /* Trim leading blanks. */ + while (language_team_len > 0 + && (*language_team_ptr == ' ' + || *language_team_ptr == '\t')) + { + language_team_ptr++; + language_team_len--; + } + + /* Trim trailing blanks. */ + while (language_team_len > 0 + && (language_team_ptr[language_team_len - 1] == ' ' + || language_team_ptr[language_team_len - 1] == '\t')) + language_team_len--; + + /* Trim last word, if it looks like an URL or email address. */ + { + size_t i; + + for (i = language_team_len; i > 0; i--) + if (language_team_ptr[i - 1] == ' ' + || language_team_ptr[i - 1] == '\t') + break; + /* The last word: language_team_ptr[i..language_team_len-1]. */ + if (i < language_team_len + && (language_team_ptr[i] == '<' + || language_team_ptr[language_team_len - 1] == '>' + || memchr (language_team_ptr, '@', language_team_len) + != NULL + || memchr (language_team_ptr, '/', language_team_len) + != NULL)) + { + /* Trim last word and blanks before it. */ + while (i > 0 + && (language_team_ptr[i - 1] == ' ' + || language_team_ptr[i - 1] == '\t')) + i--; + language_team_len = i; + } + } + + /* The rest of the Language-Team field should be the english name + of the languge. Convert to ISO 639 and ISO 3166 syntax. */ + { + size_t i; + + for (i = 0; i < language_variant_table_size; i++) + if (strlen (language_variant_table[i].english) + == language_team_len + && memcmp (language_variant_table[i].english, + language_team_ptr, language_team_len) == 0) + { + header_fields[LANGUAGE].string = + language_variant_table[i].code; + break; + } + } + if (header_fields[LANGUAGE].string == NULL) + { + size_t i; + + for (i = 0; i < language_table_size; i++) + if (strlen (language_table[i].english) == language_team_len + && memcmp (language_table[i].english, + language_team_ptr, language_team_len) == 0) + { + header_fields[LANGUAGE].string = language_table[i].code; + break; + } + } + if (header_fields[LANGUAGE].string != NULL) + { + /* Prepend a space and append a newline. */ + const char *str = header_fields[LANGUAGE].string; + size_t len = strlen (str); + char *copy = (char *) obstack_alloc (&pool, 1 + len + 1 + 1); + stpcpy (stpcpy (stpcpy (copy, " "), str), "\n"); + header_fields[LANGUAGE].string = copy; + } + else + header_fields[LANGUAGE].string = " \n"; + header_fields[LANGUAGE].len = + strlen (header_fields[LANGUAGE].string); + } } { - const char *msgid_bugs_ptr; - - msgid_bugs_ptr = c_strstr (ref->msgstr, "Report-Msgid-Bugs-To:"); - if (msgid_bugs_ptr != NULL) - { - size_t msgid_bugs_len; - const char *endp; - - msgid_bugs_ptr += sizeof ("Report-Msgid-Bugs-To:") - 1; - - endp = strchr (msgid_bugs_ptr, '\n'); - if (endp == NULL) - { - /* Add a trailing newline. */ - char *extended; - endp = strchr (msgid_bugs_ptr, '\0'); - msgid_bugs_len = (endp - msgid_bugs_ptr) + 1; - extended = (char *) obstack_alloc (&pool, msgid_bugs_len + 1); - stpcpy (stpcpy (extended, msgid_bugs_ptr), "\n"); - msgid_bugs_ptr = extended; - } - else - msgid_bugs_len = (endp - msgid_bugs_ptr) + 1; - - header_fields[REPORT_MSGID_BUGS_TO].string = msgid_bugs_ptr; - header_fields[REPORT_MSGID_BUGS_TO].len = msgid_bugs_len; - } + const char *msgid_bugs_ptr; + + msgid_bugs_ptr = c_strstr (ref->msgstr, "Report-Msgid-Bugs-To:"); + if (msgid_bugs_ptr != NULL) + { + size_t msgid_bugs_len; + const char *endp; + + msgid_bugs_ptr += sizeof ("Report-Msgid-Bugs-To:") - 1; + + endp = strchr (msgid_bugs_ptr, '\n'); + if (endp == NULL) + { + /* Add a trailing newline. */ + char *extended; + endp = strchr (msgid_bugs_ptr, '\0'); + msgid_bugs_len = (endp - msgid_bugs_ptr) + 1; + extended = (char *) obstack_alloc (&pool, msgid_bugs_len + 1); + stpcpy (stpcpy (extended, msgid_bugs_ptr), "\n"); + msgid_bugs_ptr = extended; + } + else + msgid_bugs_len = (endp - msgid_bugs_ptr) + 1; + + header_fields[REPORT_MSGID_BUGS_TO].string = msgid_bugs_ptr; + header_fields[REPORT_MSGID_BUGS_TO].len = msgid_bugs_len; + } } { - const char *pot_date_ptr; - - pot_date_ptr = c_strstr (ref->msgstr, "POT-Creation-Date:"); - if (pot_date_ptr != NULL) - { - size_t pot_date_len; - const char *endp; - - pot_date_ptr += sizeof ("POT-Creation-Date:") - 1; - - endp = strchr (pot_date_ptr, '\n'); - if (endp == NULL) - { - /* Add a trailing newline. */ - char *extended; - endp = strchr (pot_date_ptr, '\0'); - pot_date_len = (endp - pot_date_ptr) + 1; - extended = (char *) obstack_alloc (&pool, pot_date_len + 1); - stpcpy (stpcpy (extended, pot_date_ptr), "\n"); - pot_date_ptr = extended; - } - else - pot_date_len = (endp - pot_date_ptr) + 1; - - header_fields[POT_CREATION_DATE].string = pot_date_ptr; - header_fields[POT_CREATION_DATE].len = pot_date_len; - } + const char *pot_date_ptr; + + pot_date_ptr = c_strstr (ref->msgstr, "POT-Creation-Date:"); + if (pot_date_ptr != NULL) + { + size_t pot_date_len; + const char *endp; + + pot_date_ptr += sizeof ("POT-Creation-Date:") - 1; + + endp = strchr (pot_date_ptr, '\n'); + if (endp == NULL) + { + /* Add a trailing newline. */ + char *extended; + endp = strchr (pot_date_ptr, '\0'); + pot_date_len = (endp - pot_date_ptr) + 1; + extended = (char *) obstack_alloc (&pool, pot_date_len + 1); + stpcpy (stpcpy (extended, pot_date_ptr), "\n"); + pot_date_ptr = extended; + } + else + pot_date_len = (endp - pot_date_ptr) + 1; + + header_fields[POT_CREATION_DATE].string = pot_date_ptr; + header_fields[POT_CREATION_DATE].len = pot_date_len; + } } /* Concatenate all the various fields. */ len = 0; for (cnt = 0; cnt < UNKNOWN; ++cnt) - if (header_fields[cnt].string != NULL) - len += known_fields[cnt].len + header_fields[cnt].len; + if (header_fields[cnt].string != NULL) + len += known_fields[cnt].len + header_fields[cnt].len; len += header_fields[UNKNOWN].len; cp = newp = XNMALLOC (len + 1, char); newp[len] = '\0'; -#define IF_FILLED(idx) \ - if (header_fields[idx].string) \ - newp = stpncpy (stpcpy (newp, known_fields[idx].name), \ - header_fields[idx].string, header_fields[idx].len) +#define IF_FILLED(idx) \ + if (header_fields[idx].string) \ + newp = stpncpy (stpcpy (newp, known_fields[idx].name), \ + header_fields[idx].string, header_fields[idx].len) IF_FILLED (PROJECT_ID); IF_FILLED (REPORT_MSGID_BUGS_TO); @@ -1192,7 +1192,7 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, IF_FILLED (CONTENT_TYPE); IF_FILLED (CONTENT_TRANSFER); if (header_fields[UNKNOWN].string != NULL) - stpcpy (newp, header_fields[UNKNOWN].string); + stpcpy (newp, header_fields[UNKNOWN].string); #undef IF_FILLED @@ -1212,22 +1212,22 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, msgstr_len = def->msgstr_len; if (def->is_fuzzy) - { - prev_msgctxt = def->prev_msgctxt; - prev_msgid = def->prev_msgid; - prev_msgid_plural = def->prev_msgid_plural; - } + { + prev_msgctxt = def->prev_msgctxt; + prev_msgid = def->prev_msgid; + prev_msgid_plural = def->prev_msgid_plural; + } else - { - prev_msgctxt = def->msgctxt; - prev_msgid = def->msgid; - prev_msgid_plural = def->msgid_plural; - } + { + prev_msgctxt = def->msgctxt; + prev_msgid = def->msgid; + prev_msgid_plural = def->msgid_plural; + } } result = message_alloc (ref->msgctxt != NULL ? xstrdup (ref->msgctxt) : NULL, - xstrdup (ref->msgid), ref->msgid_plural, - msgstr, msgstr_len, &def->pos); + xstrdup (ref->msgid), ref->msgid_plural, + msgstr, msgstr_len, &def->pos); /* Take the comments from the definition file. There will be none at all in the reference file, as it was generated by xgettext. */ @@ -1251,9 +1251,9 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, a reason to mark the result fuzzy. */ if (!result->is_fuzzy && (ref->msgid_plural != NULL - ? def->msgid_plural == NULL - || strcmp (ref->msgid_plural, def->msgid_plural) != 0 - : def->msgid_plural != NULL)) + ? def->msgid_plural == NULL + || strcmp (ref->msgid_plural, def->msgid_plural) != 0 + : def->msgid_plural != NULL)) result->is_fuzzy = true; for (i = 0; i < NFORMATS; i++) @@ -1261,20 +1261,20 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, result->is_format[i] = ref->is_format[i]; /* If the reference message is marked as being a format specifier, - but the definition message is not, we check if the resulting - message would pass "msgfmt -c". If yes, then all is fine. If - not, we add a fuzzy marker, because - 1. the message needs the translator's attention, - 2. msgmerge must not transform a PO file which passes "msgfmt -c" - into a PO file which doesn't. */ + but the definition message is not, we check if the resulting + message would pass "msgfmt -c". If yes, then all is fine. If + not, we add a fuzzy marker, because + 1. the message needs the translator's attention, + 2. msgmerge must not transform a PO file which passes "msgfmt -c" + into a PO file which doesn't. */ if (!result->is_fuzzy - && possible_format_p (ref->is_format[i]) - && !possible_format_p (def->is_format[i]) - && check_msgid_msgstr_format_i (ref->msgid, ref->msgid_plural, - msgstr, msgstr_len, i, ref->range, - distribution, silent_error_logger) - > 0) - result->is_fuzzy = true; + && possible_format_p (ref->is_format[i]) + && !possible_format_p (def->is_format[i]) + && check_msgid_msgstr_format_i (ref->msgid, ref->msgid_plural, + msgstr, msgstr_len, i, ref->range, + distribution, silent_error_logger) + > 0) + result->is_fuzzy = true; } result->range = ref->range; @@ -1283,12 +1283,12 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, not the same or a subset, we add a fuzzy marker, because 1. the message needs the translator's attention, 2. msgmerge must not transform a PO file which passes "msgfmt -c" - into a PO file which doesn't. */ + into a PO file which doesn't. */ if (!result->is_fuzzy && has_range_p (def->range) && !(has_range_p (ref->range) - && ref->range.min >= def->range.min - && ref->range.max <= def->range.max)) + && ref->range.min >= def->range.min + && ref->range.max <= def->range.max)) result->is_fuzzy = true; result->do_wrap = ref->do_wrap; @@ -1330,12 +1330,12 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, if (ref->msgid_plural != NULL) { if (def->msgid_plural == NULL) - result->used = 1; + result->used = 1; } else { if (def->msgid_plural != NULL) - result->used = 2; + result->used = 2; } /* All done, return the merged message to the caller. */ @@ -1347,9 +1347,9 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, static void match_domain (const char *fn1, const char *fn2, - definitions_ty *definitions, message_list_ty *refmlp, - message_list_ty *resultmlp, - struct statistics *stats, unsigned int *processed) + definitions_ty *definitions, message_list_ty *refmlp, + message_list_ty *resultmlp, + struct statistics *stats, unsigned int *processed) { message_ty *header_entry; unsigned long int nplurals; @@ -1362,7 +1362,7 @@ match_domain (const char *fn1, const char *fn2, header_entry = message_list_search (definitions_current_list (definitions), NULL, ""); extract_plural_expression (header_entry ? header_entry->msgstr : NULL, - &plural_expr, &nplurals); + &plural_expr, &nplurals); untranslated_plural_msgstr = XNMALLOC (nplurals, char); memset (untranslated_plural_msgstr, '\0', nplurals); @@ -1370,17 +1370,17 @@ match_domain (const char *fn1, const char *fn2, { /* Disable error output temporarily. */ void (*old_po_xerror) (int, const struct message_ty *, const char *, size_t, - size_t, int, const char *) + size_t, int, const char *) = po_xerror; po_xerror = silent_xerror; if (check_plural_eval (plural_expr, nplurals, header_entry, - &distribution) > 0) + &distribution) > 0) { - distribution.expr = NULL; - distribution.often = NULL; - distribution.often_length = 0; - distribution.histogram = NULL; + distribution.expr = NULL; + distribution.often = NULL; + distribution.often_length = 0; + distribution.histogram = NULL; } po_xerror = old_po_xerror; @@ -1405,41 +1405,41 @@ match_domain (const char *fn1, const char *fn2, #endif for (jj = 0; jj < nn; jj++) { - message_ty *refmsg = refmlp->item[jj]; - message_ty *defmsg; - - /* Because merging can take a while we print something to signal - we are not dead. */ - if (!quiet && verbosity_level <= 1 && *processed % DOT_FREQUENCY == 0) - fputc ('.', stderr); - #ifdef _OPENMP - #pragma omp atomic - #endif - (*processed)++; - - /* See if it is in the other file. */ - defmsg = - definitions_search (definitions, refmsg->msgctxt, refmsg->msgid); - if (defmsg != NULL) - { - search_results[jj].found = defmsg; - search_results[jj].fuzzy = false; - } - else if (!is_header (refmsg) - /* If the message was not defined at all, try to find a very - similar message, it could be a typo, or the suggestion may - help. */ - && use_fuzzy_matching - && ((defmsg = - definitions_search_fuzzy (definitions, - refmsg->msgctxt, - refmsg->msgid)) != NULL)) - { - search_results[jj].found = defmsg; - search_results[jj].fuzzy = true; - } - else - search_results[jj].found = NULL; + message_ty *refmsg = refmlp->item[jj]; + message_ty *defmsg; + + /* Because merging can take a while we print something to signal + we are not dead. */ + if (!quiet && verbosity_level <= 1 && *processed % DOT_FREQUENCY == 0) + fputc ('.', stderr); + #ifdef _OPENMP + #pragma omp atomic + #endif + (*processed)++; + + /* See if it is in the other file. */ + defmsg = + definitions_search (definitions, refmsg->msgctxt, refmsg->msgid); + if (defmsg != NULL) + { + search_results[jj].found = defmsg; + search_results[jj].fuzzy = false; + } + else if (!is_header (refmsg) + /* If the message was not defined at all, try to find a very + similar message, it could be a typo, or the suggestion may + help. */ + && use_fuzzy_matching + && ((defmsg = + definitions_search_fuzzy (definitions, + refmsg->msgctxt, + refmsg->msgid)) != NULL)) + { + search_results[jj].found = defmsg; + search_results[jj].fuzzy = true; + } + else + search_results[jj].found = NULL; } } @@ -1448,97 +1448,97 @@ match_domain (const char *fn1, const char *fn2, message_ty *refmsg = refmlp->item[j]; /* See if it is in the other file. - This used definitions_search. */ + This used definitions_search. */ if (search_results[j].found != NULL && !search_results[j].fuzzy) - { - message_ty *defmsg = search_results[j].found; - /* Merge the reference with the definition: take the #. and - #: comments from the reference, take the # comments from - the definition, take the msgstr from the definition. Add - this merged entry to the output message list. */ - message_ty *mp = - message_merge (defmsg, refmsg, false, &distribution); - - message_list_append (resultmlp, mp); - - /* Remember that this message has been used, when we scan - later to see if anything was omitted. */ - defmsg->used = 1; - stats->merged++; - } + { + message_ty *defmsg = search_results[j].found; + /* Merge the reference with the definition: take the #. and + #: comments from the reference, take the # comments from + the definition, take the msgstr from the definition. Add + this merged entry to the output message list. */ + message_ty *mp = + message_merge (defmsg, refmsg, false, &distribution); + + message_list_append (resultmlp, mp); + + /* Remember that this message has been used, when we scan + later to see if anything was omitted. */ + defmsg->used = 1; + stats->merged++; + } else if (!is_header (refmsg)) - { - /* If the message was not defined at all, try to find a very - similar message, it could be a typo, or the suggestion may - help. This search assumed use_fuzzy_matching and used - definitions_search_fuzzy. */ - if (search_results[j].found != NULL && search_results[j].fuzzy) - { - message_ty *defmsg = search_results[j].found; - message_ty *mp; - - if (verbosity_level > 1) - { - po_gram_error_at_line (&refmsg->pos, _("\ + { + /* If the message was not defined at all, try to find a very + similar message, it could be a typo, or the suggestion may + help. This search assumed use_fuzzy_matching and used + definitions_search_fuzzy. */ + if (search_results[j].found != NULL && search_results[j].fuzzy) + { + message_ty *defmsg = search_results[j].found; + message_ty *mp; + + if (verbosity_level > 1) + { + po_gram_error_at_line (&refmsg->pos, _("\ this message is used but not defined...")); - error_message_count--; - po_gram_error_at_line (&defmsg->pos, _("\ + error_message_count--; + po_gram_error_at_line (&defmsg->pos, _("\ ...but this definition is similar")); - } - - /* Merge the reference with the definition: take the #. and - #: comments from the reference, take the # comments from - the definition, take the msgstr from the definition. Add - this merged entry to the output message list. */ - mp = message_merge (defmsg, refmsg, true, &distribution); - - message_list_append (resultmlp, mp); - - /* Remember that this message has been used, when we scan - later to see if anything was omitted. */ - defmsg->used = 1; - stats->fuzzied++; - if (!quiet && verbosity_level <= 1) - /* Always print a dot if we handled a fuzzy match. */ - fputc ('.', stderr); - } - else - { - message_ty *mp; - bool is_untranslated; - const char *p; - const char *pend; - - if (verbosity_level > 1) - po_gram_error_at_line (&refmsg->pos, _("\ + } + + /* Merge the reference with the definition: take the #. and + #: comments from the reference, take the # comments from + the definition, take the msgstr from the definition. Add + this merged entry to the output message list. */ + mp = message_merge (defmsg, refmsg, true, &distribution); + + message_list_append (resultmlp, mp); + + /* Remember that this message has been used, when we scan + later to see if anything was omitted. */ + defmsg->used = 1; + stats->fuzzied++; + if (!quiet && verbosity_level <= 1) + /* Always print a dot if we handled a fuzzy match. */ + fputc ('.', stderr); + } + else + { + message_ty *mp; + bool is_untranslated; + const char *p; + const char *pend; + + if (verbosity_level > 1) + po_gram_error_at_line (&refmsg->pos, _("\ this message is used but not defined in %s"), fn1); - mp = message_copy (refmsg); - - if (mp->msgid_plural != NULL) - { - /* Test if mp is untranslated. (It most likely is.) */ - is_untranslated = true; - for (p = mp->msgstr, pend = p + mp->msgstr_len; p < pend; p++) - if (*p != '\0') - { - is_untranslated = false; - break; - } - if (is_untranslated) - { - /* Change mp->msgstr_len consecutive empty strings into - nplurals consecutive empty strings. */ - if (nplurals > mp->msgstr_len) - mp->msgstr = untranslated_plural_msgstr; - mp->msgstr_len = nplurals; - } - } - - message_list_append (resultmlp, mp); - stats->missing++; - } - } + mp = message_copy (refmsg); + + if (mp->msgid_plural != NULL) + { + /* Test if mp is untranslated. (It most likely is.) */ + is_untranslated = true; + for (p = mp->msgstr, pend = p + mp->msgstr_len; p < pend; p++) + if (*p != '\0') + { + is_untranslated = false; + break; + } + if (is_untranslated) + { + /* Change mp->msgstr_len consecutive empty strings into + nplurals consecutive empty strings. */ + if (nplurals > mp->msgstr_len) + mp->msgstr = untranslated_plural_msgstr; + mp->msgstr_len = nplurals; + } + } + + message_list_append (resultmlp, mp); + stats->missing++; + } + } } free (search_results); @@ -1555,68 +1555,68 @@ this message is used but not defined in %s"), fn1); if (problematic) { - unsigned long int nplurals = 0; - - if (problematic & 1) - { - /* Need to know nplurals of the result domain. */ - message_ty *header_entry = - message_list_search (resultmlp, NULL, ""); - - nplurals = get_plural_count (header_entry - ? header_entry->msgstr - : NULL); - } - - for (j = 0; j < resultmlp->nitems; j++) - { - message_ty *mp = resultmlp->item[j]; - - if ((mp->used & 1) && (nplurals > 0)) - { - /* ref->msgid_plural != NULL but def->msgid_plural == NULL. - Use a copy of def->msgstr for each possible plural form. */ - size_t new_msgstr_len; - char *new_msgstr; - char *p; - unsigned long i; - - if (verbosity_level > 1) - { - po_gram_error_at_line (&mp->pos, _("\ + unsigned long int nplurals = 0; + + if (problematic & 1) + { + /* Need to know nplurals of the result domain. */ + message_ty *header_entry = + message_list_search (resultmlp, NULL, ""); + + nplurals = get_plural_count (header_entry + ? header_entry->msgstr + : NULL); + } + + for (j = 0; j < resultmlp->nitems; j++) + { + message_ty *mp = resultmlp->item[j]; + + if ((mp->used & 1) && (nplurals > 0)) + { + /* ref->msgid_plural != NULL but def->msgid_plural == NULL. + Use a copy of def->msgstr for each possible plural form. */ + size_t new_msgstr_len; + char *new_msgstr; + char *p; + unsigned long i; + + if (verbosity_level > 1) + { + po_gram_error_at_line (&mp->pos, _("\ this message should define plural forms")); - } - - new_msgstr_len = nplurals * mp->msgstr_len; - new_msgstr = XNMALLOC (new_msgstr_len, char); - for (i = 0, p = new_msgstr; i < nplurals; i++) - { - memcpy (p, mp->msgstr, mp->msgstr_len); - p += mp->msgstr_len; - } - mp->msgstr = new_msgstr; - mp->msgstr_len = new_msgstr_len; - mp->is_fuzzy = true; - } - - if ((mp->used & 2) && (mp->msgstr_len > strlen (mp->msgstr) + 1)) - { - /* ref->msgid_plural == NULL but def->msgid_plural != NULL. - Use only the first among the plural forms. */ - - if (verbosity_level > 1) - { - po_gram_error_at_line (&mp->pos, _("\ + } + + new_msgstr_len = nplurals * mp->msgstr_len; + new_msgstr = XNMALLOC (new_msgstr_len, char); + for (i = 0, p = new_msgstr; i < nplurals; i++) + { + memcpy (p, mp->msgstr, mp->msgstr_len); + p += mp->msgstr_len; + } + mp->msgstr = new_msgstr; + mp->msgstr_len = new_msgstr_len; + mp->is_fuzzy = true; + } + + if ((mp->used & 2) && (mp->msgstr_len > strlen (mp->msgstr) + 1)) + { + /* ref->msgid_plural == NULL but def->msgid_plural != NULL. + Use only the first among the plural forms. */ + + if (verbosity_level > 1) + { + po_gram_error_at_line (&mp->pos, _("\ this message should not define plural forms")); - } + } - mp->msgstr_len = strlen (mp->msgstr) + 1; - mp->is_fuzzy = true; - } + mp->msgstr_len = strlen (mp->msgstr) + 1; + mp->is_fuzzy = true; + } - /* Postprocessing of this message is done. */ - mp->used = 0; - } + /* Postprocessing of this message is done. */ + mp->used = 0; + } } } @@ -1628,11 +1628,11 @@ this message should not define plural forms")); message_ty *mp = resultmlp->item[j]; if (!mp->is_fuzzy || mp->msgstr[0] == '\0') - { - mp->prev_msgctxt = NULL; - mp->prev_msgid = NULL; - mp->prev_msgid_plural = NULL; - } + { + mp->prev_msgctxt = NULL; + mp->prev_msgid = NULL; + mp->prev_msgid_plural = NULL; + } } } @@ -1662,10 +1662,10 @@ merge (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax, for (k = 0; k < ref->nitems; k++) if (message_list_search (ref->item[k]->messages, NULL, "") == NULL) { - static lex_pos_ty pos = { __FILE__, __LINE__ }; - message_ty *refheader = message_alloc (NULL, "", NULL, "", 1, &pos); + static lex_pos_ty pos = { __FILE__, __LINE__ }; + message_ty *refheader = message_alloc (NULL, "", NULL, "", 1, &pos); - message_list_prepend (ref->item[k]->messages, refheader); + message_list_prepend (ref->item[k]->messages, refheader); } /* The references file can be either in ASCII or in UTF-8. If it is @@ -1675,184 +1675,184 @@ merge (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax, bool was_utf8 = false; for (k = 0; k < ref->nitems; k++) { - message_list_ty *mlp = ref->item[k]->messages; - - for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *charsetstr = c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - if (len == strlen ("UTF-8") - && c_strncasecmp (charsetstr, "UTF-8", len) == 0) - was_utf8 = true; - } - } - } - } + message_list_ty *mlp = ref->item[k]->messages; + + for (j = 0; j < mlp->nitems; j++) + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *charsetstr = c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + if (len == strlen ("UTF-8") + && c_strncasecmp (charsetstr, "UTF-8", len) == 0) + was_utf8 = true; + } + } + } + } if (was_utf8) { - def = iconv_msgdomain_list (def, "UTF-8", true, fn1); - if (compendiums != NULL) - for (k = 0; k < compendiums->nitems; k++) - iconv_message_list (compendiums->item[k], NULL, po_charset_utf8, - compendium_filenames->item[k]); + def = iconv_msgdomain_list (def, "UTF-8", true, fn1); + if (compendiums != NULL) + for (k = 0; k < compendiums->nitems; k++) + iconv_message_list (compendiums->item[k], NULL, po_charset_utf8, + compendium_filenames->item[k]); } else if (compendiums != NULL && compendiums->nitems > 0) { - /* Ensure that the definitions and the compendiums are in the same - encoding. Prefer the encoding of the definitions file, if - possible; otherwise, if the definitions file is empty and the - compendiums are all in the same encoding, use that encoding; - otherwise, use UTF-8. */ - bool conversion_done = false; - { - char *charset = NULL; - - /* Get the encoding of the definitions file. */ - for (k = 0; k < def->nitems; k++) - { - message_list_ty *mlp = def->item[k]->messages; - - for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *charsetstr = c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - charset = (char *) xmalloca (len + 1); - memcpy (charset, charsetstr, len); - charset[len] = '\0'; - break; - } - } - } - if (charset != NULL) - break; - } - if (charset != NULL) - { - const char *canon_charset = po_charset_canonicalize (charset); - - if (canon_charset != NULL) - { - bool all_compendiums_iconvable = true; - - if (compendiums != NULL) - for (k = 0; k < compendiums->nitems; k++) - if (!is_message_list_iconvable (compendiums->item[k], - NULL, canon_charset)) - { - all_compendiums_iconvable = false; - break; - } - - if (all_compendiums_iconvable) - { - /* Convert the compendiums to def's encoding. */ - if (compendiums != NULL) - for (k = 0; k < compendiums->nitems; k++) - iconv_message_list (compendiums->item[k], - NULL, canon_charset, - compendium_filenames->item[k]); - conversion_done = true; - } - } - freea (charset); - } - } - if (!conversion_done) - { - if (def->nitems == 0 - || (def->nitems == 1 && def->item[0]->messages->nitems == 0)) - { - /* The definitions file is empty. - Compare the encodings of the compendiums. */ - const char *common_canon_charset = NULL; - - for (k = 0; k < compendiums->nitems; k++) - { - message_list_ty *mlp = compendiums->item[k]; - char *charset = NULL; - const char *canon_charset = NULL; - - for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *charsetstr = - c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - charset = (char *) xmalloca (len + 1); - memcpy (charset, charsetstr, len); - charset[len] = '\0'; - - break; - } - } - } - if (charset != NULL) - { - canon_charset = po_charset_canonicalize (charset); - freea (charset); - } - /* If no charset declaration was found in this file, - or if it is not a valid encoding name, or if it - differs from the common charset found so far, - we have no common charset. */ - if (canon_charset == NULL - || (common_canon_charset != NULL - && canon_charset != common_canon_charset)) - { - common_canon_charset = NULL; - break; - } - common_canon_charset = canon_charset; - } - - if (common_canon_charset != NULL) - /* No conversion needed in this case. */ - conversion_done = true; - } - if (!conversion_done) - { - /* It's too hairy to find out what would be the optimal target - encoding. So, convert everything to UTF-8. */ - def = iconv_msgdomain_list (def, "UTF-8", true, fn1); - if (compendiums != NULL) - for (k = 0; k < compendiums->nitems; k++) - iconv_message_list (compendiums->item[k], - NULL, po_charset_utf8, - compendium_filenames->item[k]); - } - } + /* Ensure that the definitions and the compendiums are in the same + encoding. Prefer the encoding of the definitions file, if + possible; otherwise, if the definitions file is empty and the + compendiums are all in the same encoding, use that encoding; + otherwise, use UTF-8. */ + bool conversion_done = false; + { + char *charset = NULL; + + /* Get the encoding of the definitions file. */ + for (k = 0; k < def->nitems; k++) + { + message_list_ty *mlp = def->item[k]->messages; + + for (j = 0; j < mlp->nitems; j++) + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *charsetstr = c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + charset = (char *) xmalloca (len + 1); + memcpy (charset, charsetstr, len); + charset[len] = '\0'; + break; + } + } + } + if (charset != NULL) + break; + } + if (charset != NULL) + { + const char *canon_charset = po_charset_canonicalize (charset); + + if (canon_charset != NULL) + { + bool all_compendiums_iconvable = true; + + if (compendiums != NULL) + for (k = 0; k < compendiums->nitems; k++) + if (!is_message_list_iconvable (compendiums->item[k], + NULL, canon_charset)) + { + all_compendiums_iconvable = false; + break; + } + + if (all_compendiums_iconvable) + { + /* Convert the compendiums to def's encoding. */ + if (compendiums != NULL) + for (k = 0; k < compendiums->nitems; k++) + iconv_message_list (compendiums->item[k], + NULL, canon_charset, + compendium_filenames->item[k]); + conversion_done = true; + } + } + freea (charset); + } + } + if (!conversion_done) + { + if (def->nitems == 0 + || (def->nitems == 1 && def->item[0]->messages->nitems == 0)) + { + /* The definitions file is empty. + Compare the encodings of the compendiums. */ + const char *common_canon_charset = NULL; + + for (k = 0; k < compendiums->nitems; k++) + { + message_list_ty *mlp = compendiums->item[k]; + char *charset = NULL; + const char *canon_charset = NULL; + + for (j = 0; j < mlp->nitems; j++) + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *charsetstr = + c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + charset = (char *) xmalloca (len + 1); + memcpy (charset, charsetstr, len); + charset[len] = '\0'; + + break; + } + } + } + if (charset != NULL) + { + canon_charset = po_charset_canonicalize (charset); + freea (charset); + } + /* If no charset declaration was found in this file, + or if it is not a valid encoding name, or if it + differs from the common charset found so far, + we have no common charset. */ + if (canon_charset == NULL + || (common_canon_charset != NULL + && canon_charset != common_canon_charset)) + { + common_canon_charset = NULL; + break; + } + common_canon_charset = canon_charset; + } + + if (common_canon_charset != NULL) + /* No conversion needed in this case. */ + conversion_done = true; + } + if (!conversion_done) + { + /* It's too hairy to find out what would be the optimal target + encoding. So, convert everything to UTF-8. */ + def = iconv_msgdomain_list (def, "UTF-8", true, fn1); + if (compendiums != NULL) + for (k = 0; k < compendiums->nitems; k++) + iconv_message_list (compendiums->item[k], + NULL, po_charset_utf8, + compendium_filenames->item[k]); + } + } } } @@ -1862,45 +1862,45 @@ merge (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax, { def_canon_charset = def->encoding; if (def_canon_charset == NULL) - { - char *charset = NULL; - - /* Get the encoding of the definitions file. */ - for (k = 0; k < def->nitems; k++) - { - message_list_ty *mlp = def->item[k]->messages; - - for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - const char *header = mlp->item[j]->msgstr; - - if (header != NULL) - { - const char *charsetstr = c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - charset = (char *) xmalloca (len + 1); - memcpy (charset, charsetstr, len); - charset[len] = '\0'; - break; - } - } - } - if (charset != NULL) - break; - } - if (charset != NULL) - def_canon_charset = po_charset_canonicalize (charset); - if (def_canon_charset == NULL) - /* Unspecified encoding. Assume unibyte encoding. */ - def_canon_charset = po_charset_ascii; - } + { + char *charset = NULL; + + /* Get the encoding of the definitions file. */ + for (k = 0; k < def->nitems; k++) + { + message_list_ty *mlp = def->item[k]->messages; + + for (j = 0; j < mlp->nitems; j++) + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + const char *header = mlp->item[j]->msgstr; + + if (header != NULL) + { + const char *charsetstr = c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + charset = (char *) xmalloca (len + 1); + memcpy (charset, charsetstr, len); + charset[len] = '\0'; + break; + } + } + } + if (charset != NULL) + break; + } + if (charset != NULL) + def_canon_charset = po_charset_canonicalize (charset); + if (def_canon_charset == NULL) + /* Unspecified encoding. Assume unibyte encoding. */ + def_canon_charset = po_charset_ascii; + } } else def_canon_charset = NULL; @@ -1916,43 +1916,43 @@ merge (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax, if (!multi_domain_mode) for (k = 0; k < ref->nitems; k++) { - const char *domain = ref->item[k]->domain; - message_list_ty *refmlp = ref->item[k]->messages; - message_list_ty *resultmlp = - msgdomain_list_sublist (result, domain, true); - message_list_ty *defmlp; - - defmlp = msgdomain_list_sublist (def, domain, false); - if (defmlp == NULL) - defmlp = empty_list; - definitions_set_current_list (&definitions, defmlp); - - match_domain (fn1, fn2, &definitions, refmlp, resultmlp, - &stats, &processed); + const char *domain = ref->item[k]->domain; + message_list_ty *refmlp = ref->item[k]->messages; + message_list_ty *resultmlp = + msgdomain_list_sublist (result, domain, true); + message_list_ty *defmlp; + + defmlp = msgdomain_list_sublist (def, domain, false); + if (defmlp == NULL) + defmlp = empty_list; + definitions_set_current_list (&definitions, defmlp); + + match_domain (fn1, fn2, &definitions, refmlp, resultmlp, + &stats, &processed); } else { /* Apply the references messages in the default domain to each of - the definition domains. */ + the definition domains. */ message_list_ty *refmlp = ref->item[0]->messages; for (k = 0; k < def->nitems; k++) - { - const char *domain = def->item[k]->domain; - message_list_ty *defmlp = def->item[k]->messages; - - /* Ignore the default message domain if it has no messages. */ - if (k > 0 || defmlp->nitems > 0) - { - message_list_ty *resultmlp = - msgdomain_list_sublist (result, domain, true); - - definitions_set_current_list (&definitions, defmlp); - - match_domain (fn1, fn2, &definitions, refmlp, resultmlp, - &stats, &processed); - } - } + { + const char *domain = def->item[k]->domain; + message_list_ty *defmlp = def->item[k]->messages; + + /* Ignore the default message domain if it has no messages. */ + if (k > 0 || defmlp->nitems > 0) + { + message_list_ty *resultmlp = + msgdomain_list_sublist (result, domain, true); + + definitions_set_current_list (&definitions, defmlp); + + match_domain (fn1, fn2, &definitions, refmlp, resultmlp, + &stats, &processed); + } + } } definitions_destroy (&definitions); @@ -1966,41 +1966,41 @@ merge (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax, message_list_ty *defmlp = def->item[k]->messages; for (j = 0; j < defmlp->nitems; j++) - { - message_ty *defmsg = defmlp->item[j]; - - if (!defmsg->used) - { - /* Remember the old translation although it is not used anymore. - But we mark it as obsolete. */ - message_ty *mp; - - mp = message_copy (defmsg); - /* Clear the extracted comments. */ - if (mp->comment_dot != NULL) - { - string_list_free (mp->comment_dot); - mp->comment_dot = NULL; - } - /* Clear the file position comments. */ - if (mp->filepos != NULL) - { - size_t i; - - for (i = 0; i < mp->filepos_count; i++) - free ((char *) mp->filepos[i].file_name); - mp->filepos_count = 0; - free (mp->filepos); - mp->filepos = NULL; - } - /* Mark as obsolete. */ - mp->obsolete = true; - - message_list_append (msgdomain_list_sublist (result, domain, true), - mp); - stats.obsolete++; - } - } + { + message_ty *defmsg = defmlp->item[j]; + + if (!defmsg->used) + { + /* Remember the old translation although it is not used anymore. + But we mark it as obsolete. */ + message_ty *mp; + + mp = message_copy (defmsg); + /* Clear the extracted comments. */ + if (mp->comment_dot != NULL) + { + string_list_free (mp->comment_dot); + mp->comment_dot = NULL; + } + /* Clear the file position comments. */ + if (mp->filepos != NULL) + { + size_t i; + + for (i = 0; i < mp->filepos_count; i++) + free ((char *) mp->filepos[i].file_name); + mp->filepos_count = 0; + free (mp->filepos); + mp->filepos = NULL; + } + /* Mark as obsolete. */ + mp->obsolete = true; + + message_list_append (msgdomain_list_sublist (result, domain, true), + mp); + stats.obsolete++; + } + } } /* Determine the known a-priori encoding, if any. */ @@ -2012,10 +2012,10 @@ merge (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax, fprintf (stderr, _("%s\ Read %ld old + %ld reference, \ merged %ld, fuzzied %ld, missing %ld, obsolete %ld.\n"), - !quiet && verbosity_level <= 1 ? "\n" : "", - (long) def->nitems, (long) ref->nitems, - (long) stats.merged, (long) stats.fuzzied, (long) stats.missing, - (long) stats.obsolete); + !quiet && verbosity_level <= 1 ? "\n" : "", + (long) def->nitems, (long) ref->nitems, + (long) stats.merged, (long) stats.fuzzied, (long) stats.missing, + (long) stats.obsolete); else if (!quiet) fputs (_(" done.\n"), stderr); diff --git a/gettext-tools/src/msgunfmt.c b/gettext-tools/src/msgunfmt.c index 85597441e..51884d31f 100644 --- a/gettext-tools/src/msgunfmt.c +++ b/gettext-tools/src/msgunfmt.c @@ -104,7 +104,7 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; static void read_one_file (message_list_ty *mlp, const char *filename); @@ -139,107 +139,107 @@ main (int argc, char **argv) atexit (close_stdout); while ((optchar = getopt_long (argc, argv, "d:eEhijl:o:pr:svVw:", - long_options, NULL)) - != EOF) + long_options, NULL)) + != EOF) switch (optchar) { case '\0': - /* long option */ - break; + /* long option */ + break; case 'd': - csharp_base_directory = optarg; - tcl_base_directory = optarg; - break; + csharp_base_directory = optarg; + tcl_base_directory = optarg; + break; case 'e': - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case 'E': - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - message_print_style_indent (); - break; + message_print_style_indent (); + break; case 'j': - java_mode = true; - break; + java_mode = true; + break; case 'l': - java_locale_name = optarg; - csharp_locale_name = optarg; - tcl_locale_name = optarg; - break; + java_locale_name = optarg; + csharp_locale_name = optarg; + tcl_locale_name = optarg; + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'r': - java_resource_name = optarg; - csharp_resource_name = optarg; - break; + java_resource_name = optarg; + csharp_resource_name = optarg; + break; case 's': - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case 'S': - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case 'v': - verbose = true; - break; + verbose = true; + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case CHAR_MAX + 1: /* --tcl */ - tcl_mode = true; - break; + tcl_mode = true; + break; case CHAR_MAX + 2: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 3: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; case CHAR_MAX + 4: /* --csharp */ - csharp_mode = true; - break; + csharp_mode = true; + break; case CHAR_MAX + 5: /* --csharp-resources */ - csharp_resources_mode = true; - break; + csharp_resources_mode = true; + break; default: - usage (EXIT_FAILURE); - break; + usage (EXIT_FAILURE); + break; } /* Version information is requested. */ @@ -252,7 +252,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "1995-1998, 2000-2009"); + "1995-1998, 2000-2009"); printf (_("Written by %s.\n"), proper_name ("Ulrich Drepper")); exit (EXIT_SUCCESS); } @@ -273,90 +273,90 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* More than one bit set? */ if (modes & (modes - 1)) { - const char *first_option; - const char *second_option; - unsigned int i; - for (i = 0; ; i++) - if (modes & (1 << i)) - break; - first_option = mode_options[i]; - for (i = i + 1; ; i++) - if (modes & (1 << i)) - break; - second_option = mode_options[i]; - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - first_option, second_option); + const char *first_option; + const char *second_option; + unsigned int i; + for (i = 0; ; i++) + if (modes & (1 << i)) + break; + first_option = mode_options[i]; + for (i = i + 1; ; i++) + if (modes & (1 << i)) + break; + second_option = mode_options[i]; + error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), + first_option, second_option); } } if (java_mode) { if (optind < argc) - { - error (EXIT_FAILURE, 0, - _("%s and explicit file names are mutually exclusive"), - "--java"); - } + { + error (EXIT_FAILURE, 0, + _("%s and explicit file names are mutually exclusive"), + "--java"); + } } else if (csharp_mode) { if (optind < argc) - { - error (EXIT_FAILURE, 0, - _("%s and explicit file names are mutually exclusive"), - "--csharp"); - } + { + error (EXIT_FAILURE, 0, + _("%s and explicit file names are mutually exclusive"), + "--csharp"); + } if (csharp_locale_name == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-l locale\" specification"), - "--csharp"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, + _("%s requires a \"-l locale\" specification"), + "--csharp"); + usage (EXIT_FAILURE); + } if (csharp_base_directory == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-d directory\" specification"), - "--csharp"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, + _("%s requires a \"-d directory\" specification"), + "--csharp"); + usage (EXIT_FAILURE); + } } else if (tcl_mode) { if (optind < argc) - { - error (EXIT_FAILURE, 0, - _("%s and explicit file names are mutually exclusive"), - "--tcl"); - } + { + error (EXIT_FAILURE, 0, + _("%s and explicit file names are mutually exclusive"), + "--tcl"); + } if (tcl_locale_name == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-l locale\" specification"), - "--tcl"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, + _("%s requires a \"-l locale\" specification"), + "--tcl"); + usage (EXIT_FAILURE); + } if (tcl_base_directory == NULL) - { - error (EXIT_SUCCESS, 0, - _("%s requires a \"-d directory\" specification"), - "--tcl"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, + _("%s requires a \"-d directory\" specification"), + "--tcl"); + usage (EXIT_FAILURE); + } } else { if (java_resource_name != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"), - "--resource", "--java", "--csharp"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"), + "--resource", "--java", "--csharp"); + usage (EXIT_FAILURE); + } if (java_locale_name != NULL) - { - error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"), - "--locale", "--java", "--csharp"); - usage (EXIT_FAILURE); - } + { + error (EXIT_SUCCESS, 0, _("%s is only valid with %s or %s"), + "--locale", "--java", "--csharp"); + usage (EXIT_FAILURE); + } } /* Read the given .mo file. */ @@ -367,7 +367,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\ else if (csharp_mode) { result = msgdomain_read_csharp (csharp_resource_name, csharp_locale_name, - csharp_base_directory); + csharp_base_directory); } else if (tcl_mode) { @@ -379,13 +379,13 @@ There is NO WARRANTY, to the extent permitted by law.\n\ mlp = message_list_alloc (false); if (optind < argc) - { - do - read_one_file (mlp, argv[optind]); - while (++optind < argc); - } + { + do + read_one_file (mlp, argv[optind]); + while (++optind < argc); + } else - read_one_file (mlp, "-"); + read_one_file (mlp, "-"); result = msgdomain_list_alloc (false); result->item[0]->messages = mlp; @@ -409,7 +409,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -520,7 +520,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); diff --git a/gettext-tools/src/msguniq.c b/gettext-tools/src/msguniq.c index d2ac73ac4..4751d7246 100644 --- a/gettext-tools/src/msguniq.c +++ b/gettext-tools/src/msguniq.c @@ -89,7 +89,7 @@ static const struct option long_options[] = /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; @@ -136,107 +136,107 @@ main (int argc, char **argv) use_first = false; while ((optchar = getopt_long (argc, argv, "dD:eEFhino:pPst:uVw:", - long_options, NULL)) != EOF) + long_options, NULL)) != EOF) switch (optchar) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'd': - more_than = 1; - less_than = INT_MAX; - break; + more_than = 1; + less_than = INT_MAX; + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'e': - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case 'E': - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case 'F': - sort_by_filepos = true; - break; + sort_by_filepos = true; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - message_print_style_indent (); - break; + message_print_style_indent (); + break; case 'n': - line_comment = 1; - break; + line_comment = 1; + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - output_syntax = &output_format_properties; - break; + output_syntax = &output_format_properties; + break; case 'P': - input_syntax = &input_format_properties; - break; + input_syntax = &input_format_properties; + break; case 's': - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case 'S': - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case 't': - to_code = optarg; - break; + to_code = optarg; + break; case 'u': - more_than = 0; - less_than = 2; - break; + more_than = 0; + less_than = 2; + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case CHAR_MAX + 1: - use_first = true; - break; + use_first = true; + break; case CHAR_MAX + 2: /* --no-wrap */ - message_page_width_ignore (); - break; + message_page_width_ignore (); + break; case CHAR_MAX + 3: /* --stringtable-input */ - input_syntax = &input_format_stringtable; - break; + input_syntax = &input_format_stringtable; + break; case CHAR_MAX + 4: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; + output_syntax = &output_format_stringtable; + break; default: - usage (EXIT_FAILURE); - /* NOTREACHED */ + usage (EXIT_FAILURE); + /* NOTREACHED */ } /* Version information requested. */ @@ -249,7 +249,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2009"); + "2001-2009"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -272,11 +272,11 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Verify selected options. */ if (!line_comment && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); + "--no-location", "--sort-by-file"); if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--sort-output", "--sort-by-file"); + "--sort-output", "--sort-by-file"); /* Determine list of files we have to process: a single file. */ file_list = string_list_alloc (); @@ -307,7 +307,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -407,7 +407,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); diff --git a/gettext-tools/src/open-catalog.c b/gettext-tools/src/open-catalog.c index 1f8470019..cef68e8e2 100644 --- a/gettext-tools/src/open-catalog.c +++ b/gettext-tools/src/open-catalog.c @@ -62,39 +62,39 @@ try_open_catalog_file (const char *input_name, char **real_file_name_p) if (IS_ABSOLUTE_PATH (input_name)) { for (k = 0; k < SIZEOF (extension); ++k) - { - file_name = xconcatenated_filename ("", input_name, extension[k]); - - ret_val = fopen (file_name, "r"); - if (ret_val != NULL || errno != ENOENT) - { - /* We found the file. */ - *real_file_name_p = file_name; - return ret_val; - } - - free (file_name); - } + { + file_name = xconcatenated_filename ("", input_name, extension[k]); + + ret_val = fopen (file_name, "r"); + if (ret_val != NULL || errno != ENOENT) + { + /* We found the file. */ + *real_file_name_p = file_name; + return ret_val; + } + + free (file_name); + } } else { /* For relative file names, look through the directory search list, - trying the various extensions. If no directory search list is - specified, the current directory is used. */ + trying the various extensions. If no directory search list is + specified, the current directory is used. */ for (j = 0; (dir = dir_list_nth (j)) != NULL; ++j) - for (k = 0; k < SIZEOF (extension); ++k) - { - file_name = xconcatenated_filename (dir, input_name, extension[k]); - - ret_val = fopen (file_name, "r"); - if (ret_val != NULL || errno != ENOENT) - { - *real_file_name_p = file_name; - return ret_val; - } - - free (file_name); - } + for (k = 0; k < SIZEOF (extension); ++k) + { + file_name = xconcatenated_filename (dir, input_name, extension[k]); + + ret_val = fopen (file_name, "r"); + if (ret_val != NULL || errno != ENOENT) + { + *real_file_name_p = file_name; + return ret_val; + } + + free (file_name); + } } /* File does not exist. */ @@ -110,7 +110,7 @@ try_open_catalog_file (const char *input_name, char **real_file_name_p) purposes. */ FILE * open_catalog_file (const char *input_name, char **real_file_name_p, - bool exit_on_error) + bool exit_on_error) { FILE *fp = try_open_catalog_file (input_name, real_file_name_p); @@ -118,10 +118,10 @@ open_catalog_file (const char *input_name, char **real_file_name_p, { const char *errno_description = strerror (errno); po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while opening \"%s\" for reading"), - *real_file_name_p), - errno_description)); + xasprintf ("%s: %s", + xasprintf (_("error while opening \"%s\" for reading"), + *real_file_name_p), + errno_description)); } return fp; diff --git a/gettext-tools/src/open-catalog.h b/gettext-tools/src/open-catalog.h index 5ec6c4e32..503371dc3 100644 --- a/gettext-tools/src/open-catalog.h +++ b/gettext-tools/src/open-catalog.h @@ -32,7 +32,7 @@ extern "C" { file's pathname is returned in *REAL_FILE_NAME_P, for error message purposes. */ extern FILE *open_catalog_file (const char *input_name, - char **real_file_name_p, bool exit_on_error); + char **real_file_name_p, bool exit_on_error); #ifdef __cplusplus diff --git a/gettext-tools/src/plural-distrib.h b/gettext-tools/src/plural-distrib.h index decde3c2c..4376f9f01 100644 --- a/gettext-tools/src/plural-distrib.h +++ b/gettext-tools/src/plural-distrib.h @@ -45,7 +45,7 @@ struct plural_distribution /* A function which evaluates the plural formula for min <= n <= max and returns the estimated number of times the value j was assumed. */ unsigned int (*histogram) (const struct plural_distribution *self, - int min, int max, unsigned long j); + int min, int max, unsigned long j); }; diff --git a/gettext-tools/src/po-charset.c b/gettext-tools/src/po-charset.c index e30b9c909..a48f90c9e 100644 --- a/gettext-tools/src/po-charset.c +++ b/gettext-tools/src/po-charset.c @@ -58,8 +58,8 @@ po_charset_canonicalize (const char *charset) iconv() across platforms. Taken from intl/config.charset. */ static const char *standard_charsets[] = { - ascii, "ANSI_X3.4-1968", "US-ASCII", /* i = 0..2 */ - "ISO-8859-1", "ISO_8859-1", /* i = 3, 4 */ + ascii, "ANSI_X3.4-1968", "US-ASCII", /* i = 0..2 */ + "ISO-8859-1", "ISO_8859-1", /* i = 3, 4 */ "ISO-8859-2", "ISO_8859-2", "ISO-8859-3", "ISO_8859-3", "ISO-8859-4", "ISO_8859-4", @@ -70,7 +70,7 @@ po_charset_canonicalize (const char *charset) "ISO-8859-9", "ISO_8859-9", "ISO-8859-13", "ISO_8859-13", "ISO-8859-14", "ISO_8859-14", - "ISO-8859-15", "ISO_8859-15", /* i = 25, 26 */ + "ISO-8859-15", "ISO_8859-15", /* i = 25, 26 */ "KOI8-R", "KOI8-U", "KOI8-T", @@ -152,13 +152,13 @@ bool po_is_charset_weird (const char *canon_charset) bool po_is_charset_weird_cjk (const char *canon_charset) { static const char *weird_cjk_charsets[] = - { /* single bytes double bytes */ - "BIG5", /* 0x{00..7F}, 0x{A1..F9}{40..FE} */ - "BIG5-HKSCS", /* 0x{00..7F}, 0x{88..FE}{40..FE} */ - "GBK", /* 0x{00..7F}, 0x{81..FE}{40..FE} */ - "GB18030", /* 0x{00..7F}, 0x{81..FE}{30..FE} */ - "SHIFT_JIS", /* 0x{00..7F}, 0x{81..F9}{40..FC} */ - "JOHAB" /* 0x{00..7F}, 0x{84..F9}{31..FE} */ + { /* single bytes double bytes */ + "BIG5", /* 0x{00..7F}, 0x{A1..F9}{40..FE} */ + "BIG5-HKSCS", /* 0x{00..7F}, 0x{88..FE}{40..FE} */ + "GBK", /* 0x{00..7F}, 0x{81..FE}{40..FE} */ + "GB18030", /* 0x{00..7F}, 0x{81..FE}{30..FE} */ + "SHIFT_JIS", /* 0x{00..7F}, 0x{81..F9}{40..FC} */ + "JOHAB" /* 0x{00..7F}, 0x{84..F9}{31..FE} */ }; size_t i; @@ -189,7 +189,7 @@ euc_character_iterator (const char *s) { unsigned char c2 = s[1]; if (c2 >= 0xa1 && c2 < 0xff) - return 2; + return 2; } return 1; } @@ -203,23 +203,23 @@ euc_jp_character_iterator (const char *s) { unsigned char c2 = s[1]; if (c2 >= 0xa1 && c2 < 0xff) - return 2; + return 2; } else if (c == 0x8e) { unsigned char c2 = s[1]; if (c2 >= 0xa1 && c2 < 0xe0) - return 2; + return 2; } else if (c == 0x8f) { unsigned char c2 = s[1]; if (c2 >= 0xa1 && c2 < 0xff) - { - unsigned char c3 = s[2]; - if (c3 >= 0xa1 && c3 < 0xff) - return 3; - } + { + unsigned char c3 = s[2]; + if (c3 >= 0xa1 && c3 < 0xff) + return 3; + } } return 1; } @@ -233,21 +233,21 @@ euc_tw_character_iterator (const char *s) { unsigned char c2 = s[1]; if (c2 >= 0xa1 && c2 < 0xff) - return 2; + return 2; } else if (c == 0x8e) { unsigned char c2 = s[1]; if (c2 >= 0xa1 && c2 <= 0xb0) - { - unsigned char c3 = s[2]; - if (c3 >= 0xa1 && c3 < 0xff) - { - unsigned char c4 = s[3]; - if (c4 >= 0xa1 && c4 < 0xff) - return 4; - } - } + { + unsigned char c3 = s[2]; + if (c3 >= 0xa1 && c3 < 0xff) + { + unsigned char c4 = s[3]; + if (c4 >= 0xa1 && c4 < 0xff) + return 4; + } + } } return 1; } @@ -261,7 +261,7 @@ big5_character_iterator (const char *s) { unsigned char c2 = s[1]; if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff)) - return 2; + return 2; } return 1; } @@ -275,7 +275,7 @@ big5hkscs_character_iterator (const char *s) { unsigned char c2 = s[1]; if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff)) - return 2; + return 2; } return 1; } @@ -290,7 +290,7 @@ gbk_character_iterator (const char *s) { unsigned char c2 = s[1]; if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0x80 && c2 < 0xff)) - return 2; + return 2; } return 1; } @@ -304,21 +304,21 @@ gb18030_character_iterator (const char *s) { unsigned char c2 = s[1]; if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0x80 && c2 < 0xff)) - return 2; + return 2; } if (c >= 0x81 && c <= 0x84) { unsigned char c2 = s[1]; if (c2 >= 0x30 && c2 <= 0x39) - { - unsigned char c3 = s[2]; - if (c3 >= 0x81 && c3 < 0xff) - { - unsigned char c4 = s[3]; - if (c4 >= 0x30 && c4 <= 0x39) - return 4; - } - } + { + unsigned char c3 = s[2]; + if (c3 >= 0x81 && c3 < 0xff) + { + unsigned char c4 = s[3]; + if (c4 >= 0x30 && c4 <= 0x39) + return 4; + } + } } return 1; } @@ -332,7 +332,7 @@ shift_jis_character_iterator (const char *s) { unsigned char c2 = s[1]; if ((c2 >= 0x40 && c2 <= 0x7e) || (c2 >= 0x80 && c2 <= 0xfc)) - return 2; + return 2; } return 1; } @@ -347,13 +347,13 @@ johab_character_iterator (const char *s) { unsigned char c2 = s[1]; if ((c2 >= 0x41 && c2 < 0x7f) || (c2 >= 0x81 && c2 < 0xff)) - return 2; + return 2; } else if (c >= 0xd9 && c <= 0xf9) { unsigned char c2 = s[1]; if ((c2 >= 0x31 && c2 <= 0x7e) || (c2 >= 0x91 && c2 <= 0xfe)) - return 2; + return 2; } return 1; } @@ -366,35 +366,35 @@ utf8_character_iterator (const char *s) if (c >= 0xc2) { if (c < 0xe0) - { - unsigned char c2 = s[1]; - if (c2 >= 0x80 && c2 < 0xc0) - return 2; - } + { + unsigned char c2 = s[1]; + if (c2 >= 0x80 && c2 < 0xc0) + return 2; + } else if (c < 0xf0) - { - unsigned char c2 = s[1]; - if (c2 >= 0x80 && c2 < 0xc0) - { - unsigned char c3 = s[2]; - if (c3 >= 0x80 && c3 < 0xc0) - return 3; - } - } + { + unsigned char c2 = s[1]; + if (c2 >= 0x80 && c2 < 0xc0) + { + unsigned char c3 = s[2]; + if (c3 >= 0x80 && c3 < 0xc0) + return 3; + } + } else if (c < 0xf8) - { - unsigned char c2 = s[1]; - if (c2 >= 0x80 && c2 < 0xc0) - { - unsigned char c3 = s[2]; - if (c3 >= 0x80 && c3 < 0xc0) - { - unsigned char c4 = s[3]; - if (c4 >= 0x80 && c4 < 0xc0) - return 4; - } - } - } + { + unsigned char c2 = s[1]; + if (c2 >= 0x80 && c2 < 0xc0) + { + unsigned char c3 = s[2]; + if (c3 >= 0x80 && c3 < 0xc0) + { + unsigned char c4 = s[3]; + if (c4 >= 0x80 && c4 < 0xc0) + return 4; + } + } + } } return 1; } @@ -457,9 +457,9 @@ po_lex_charset_set (const char *header_entry, const char *filename) { /* Verify the validity of CHARSET. It is necessary 1. for the correct treatment of multibyte characters containing - 0x5C bytes in the PO lexer, + 0x5C bytes in the PO lexer, 2. so that at run time, gettext() can call iconv() to convert - msgstr. */ + msgstr. */ const char *charsetstr = c_strstr (header_entry, "charset="); if (charsetstr != NULL) @@ -476,171 +476,171 @@ po_lex_charset_set (const char *header_entry, const char *filename) canon_charset = po_charset_canonicalize (charset); if (canon_charset == NULL) - { - /* Don't warn for POT files, because POT files usually contain - only ASCII msgids. */ - size_t filenamelen = strlen (filename); - - if (!(filenamelen >= 4 - && memcmp (filename + filenamelen - 4, ".pot", 4) == 0 - && strcmp (charset, "CHARSET") == 0)) - { - char *warning_message = - xasprintf (_("\ + { + /* Don't warn for POT files, because POT files usually contain + only ASCII msgids. */ + size_t filenamelen = strlen (filename); + + if (!(filenamelen >= 4 + && memcmp (filename + filenamelen - 4, ".pot", 4) == 0 + && strcmp (charset, "CHARSET") == 0)) + { + char *warning_message = + xasprintf (_("\ Charset \"%s\" is not a portable encoding name.\n\ Message conversion to user's charset might not work.\n"), - charset); - po_xerror (PO_SEVERITY_WARNING, NULL, - filename, (size_t)(-1), (size_t)(-1), true, - warning_message); - free (warning_message); - } - } + charset); + po_xerror (PO_SEVERITY_WARNING, NULL, + filename, (size_t)(-1), (size_t)(-1), true, + warning_message); + free (warning_message); + } + } else - { - const char *envval; + { + const char *envval; - po_lex_charset = canon_charset; + po_lex_charset = canon_charset; #if HAVE_ICONV - if (po_lex_iconv != (iconv_t)(-1)) - iconv_close (po_lex_iconv); + if (po_lex_iconv != (iconv_t)(-1)) + iconv_close (po_lex_iconv); #endif - /* The old Solaris/openwin msgfmt and GNU msgfmt <= 0.10.35 - don't know about multibyte encodings, and require a spurious - backslash after every multibyte character whose last byte is - 0x5C. Some programs, like vim, distribute PO files in this - broken format. GNU msgfmt must continue to support this old - PO file format when the Makefile requests it. */ - envval = getenv ("OLD_PO_FILE_INPUT"); - if (envval != NULL && *envval != '\0') - { - /* Assume the PO file is in old format, with extraneous - backslashes. */ + /* The old Solaris/openwin msgfmt and GNU msgfmt <= 0.10.35 + don't know about multibyte encodings, and require a spurious + backslash after every multibyte character whose last byte is + 0x5C. Some programs, like vim, distribute PO files in this + broken format. GNU msgfmt must continue to support this old + PO file format when the Makefile requests it. */ + envval = getenv ("OLD_PO_FILE_INPUT"); + if (envval != NULL && *envval != '\0') + { + /* Assume the PO file is in old format, with extraneous + backslashes. */ #if HAVE_ICONV - po_lex_iconv = (iconv_t)(-1); + po_lex_iconv = (iconv_t)(-1); #endif - po_lex_weird_cjk = false; - } - else - { - /* Use iconv() to parse multibyte characters. */ + po_lex_weird_cjk = false; + } + else + { + /* Use iconv() to parse multibyte characters. */ #if HAVE_ICONV - /* Avoid glibc-2.1 bug with EUC-KR. */ + /* Avoid glibc-2.1 bug with EUC-KR. */ # if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION - if (strcmp (po_lex_charset, "EUC-KR") == 0) - po_lex_iconv = (iconv_t)(-1); - else + if (strcmp (po_lex_charset, "EUC-KR") == 0) + po_lex_iconv = (iconv_t)(-1); + else # endif - /* Avoid Solaris 2.9 bug with GB2312, EUC-TW, BIG5, BIG5-HKSCS, - GBK, GB18030. */ + /* Avoid Solaris 2.9 bug with GB2312, EUC-TW, BIG5, BIG5-HKSCS, + GBK, GB18030. */ # if defined __sun && !defined _LIBICONV_VERSION - if ( strcmp (po_lex_charset, "GB2312") == 0 - || strcmp (po_lex_charset, "EUC-TW") == 0 - || strcmp (po_lex_charset, "BIG5") == 0 - || strcmp (po_lex_charset, "BIG5-HKSCS") == 0 - || strcmp (po_lex_charset, "GBK") == 0 - || strcmp (po_lex_charset, "GB18030") == 0) - po_lex_iconv = (iconv_t)(-1); - else + if ( strcmp (po_lex_charset, "GB2312") == 0 + || strcmp (po_lex_charset, "EUC-TW") == 0 + || strcmp (po_lex_charset, "BIG5") == 0 + || strcmp (po_lex_charset, "BIG5-HKSCS") == 0 + || strcmp (po_lex_charset, "GBK") == 0 + || strcmp (po_lex_charset, "GB18030") == 0) + po_lex_iconv = (iconv_t)(-1); + else # endif - po_lex_iconv = iconv_open ("UTF-8", po_lex_charset); - if (po_lex_iconv == (iconv_t)(-1)) - { - char *warning_message; - const char *recommendation; - const char *note; - char *whole_message; - - warning_message = - xasprintf (_("\ + po_lex_iconv = iconv_open ("UTF-8", po_lex_charset); + if (po_lex_iconv == (iconv_t)(-1)) + { + char *warning_message; + const char *recommendation; + const char *note; + char *whole_message; + + warning_message = + xasprintf (_("\ Charset \"%s\" is not supported. %s relies on iconv(),\n\ and iconv() does not support \"%s\".\n"), - po_lex_charset, basename (program_name), - po_lex_charset); + po_lex_charset, basename (program_name), + po_lex_charset); # if !defined _LIBICONV_VERSION - recommendation = _("\ + recommendation = _("\ Installing GNU libiconv and then reinstalling GNU gettext\n\ would fix this problem.\n"); # else - recommendation = ""; + recommendation = ""; # endif - /* Test for a charset which has double-byte characters - ending in 0x5C. For these encodings, the string parser - is likely to be confused if it can't see the character - boundaries. */ - po_lex_weird_cjk = po_is_charset_weird_cjk (po_lex_charset); - if (po_is_charset_weird (po_lex_charset) - && !po_lex_weird_cjk) - note = _("Continuing anyway, expect parse errors."); - else - note = _("Continuing anyway."); - - whole_message = - xasprintf ("%s%s%s\n", - warning_message, recommendation, note); - - po_xerror (PO_SEVERITY_WARNING, NULL, - filename, (size_t)(-1), (size_t)(-1), true, - whole_message); - - free (whole_message); - free (warning_message); - } + /* Test for a charset which has double-byte characters + ending in 0x5C. For these encodings, the string parser + is likely to be confused if it can't see the character + boundaries. */ + po_lex_weird_cjk = po_is_charset_weird_cjk (po_lex_charset); + if (po_is_charset_weird (po_lex_charset) + && !po_lex_weird_cjk) + note = _("Continuing anyway, expect parse errors."); + else + note = _("Continuing anyway."); + + whole_message = + xasprintf ("%s%s%s\n", + warning_message, recommendation, note); + + po_xerror (PO_SEVERITY_WARNING, NULL, + filename, (size_t)(-1), (size_t)(-1), true, + whole_message); + + free (whole_message); + free (warning_message); + } #else - /* Test for a charset which has double-byte characters - ending in 0x5C. For these encodings, the string parser - is likely to be confused if it can't see the character - boundaries. */ - po_lex_weird_cjk = po_is_charset_weird_cjk (po_lex_charset); - if (po_is_charset_weird (po_lex_charset) && !po_lex_weird_cjk) - { - char *warning_message; - const char *recommendation; - const char *note; - char *whole_message; - - warning_message = - xasprintf (_("\ + /* Test for a charset which has double-byte characters + ending in 0x5C. For these encodings, the string parser + is likely to be confused if it can't see the character + boundaries. */ + po_lex_weird_cjk = po_is_charset_weird_cjk (po_lex_charset); + if (po_is_charset_weird (po_lex_charset) && !po_lex_weird_cjk) + { + char *warning_message; + const char *recommendation; + const char *note; + char *whole_message; + + warning_message = + xasprintf (_("\ Charset \"%s\" is not supported. %s relies on iconv().\n\ This version was built without iconv().\n"), - po_lex_charset, basename (program_name)); + po_lex_charset, basename (program_name)); - recommendation = _("\ + recommendation = _("\ Installing GNU libiconv and then reinstalling GNU gettext\n\ would fix this problem.\n"); - note = _("Continuing anyway, expect parse errors."); + note = _("Continuing anyway, expect parse errors."); - whole_message = - xasprintf ("%s%s%s\n", - warning_message, recommendation, note); + whole_message = + xasprintf ("%s%s%s\n", + warning_message, recommendation, note); - po_xerror (PO_SEVERITY_WARNING, NULL, - filename, (size_t)(-1), (size_t)(-1), true, - whole_message); + po_xerror (PO_SEVERITY_WARNING, NULL, + filename, (size_t)(-1), (size_t)(-1), true, + whole_message); - free (whole_message); - free (warning_message); - } + free (whole_message); + free (warning_message); + } #endif - } - } + } + } freea (charset); } else { /* Don't warn for POT files, because POT files usually contain - only ASCII msgids. */ + only ASCII msgids. */ size_t filenamelen = strlen (filename); if (!(filenamelen >= 4 - && memcmp (filename + filenamelen - 4, ".pot", 4) == 0)) - po_xerror (PO_SEVERITY_WARNING, - NULL, filename, (size_t)(-1), (size_t)(-1), true, - _("\ + && memcmp (filename + filenamelen - 4, ".pot", 4) == 0)) + po_xerror (PO_SEVERITY_WARNING, + NULL, filename, (size_t)(-1), (size_t)(-1), true, + _("\ Charset missing in header.\n\ Message conversion to user's charset will not work.\n")); } diff --git a/gettext-tools/src/po-charset.h b/gettext-tools/src/po-charset.h index 56eb8e285..65798e77a 100644 --- a/gettext-tools/src/po-charset.h +++ b/gettext-tools/src/po-charset.h @@ -79,7 +79,7 @@ extern void po_lex_charset_init (void); /* Set the PO file's encoding from the header entry. */ extern void po_lex_charset_set (const char *header_entry, - const char *filename); + const char *filename); /* Finish up with the PO file's encoding. */ extern void po_lex_charset_close (void); diff --git a/gettext-tools/src/po-error.c b/gettext-tools/src/po-error.c index 235005441..067264a8a 100644 --- a/gettext-tools/src/po-error.c +++ b/gettext-tools/src/po-error.c @@ -28,12 +28,12 @@ void (*po_error) (int status, int errnum, - const char *format, ...) + const char *format, ...) = error; void (*po_error_at_line) (int status, int errnum, - const char *filename, unsigned int lineno, - const char *format, ...) + const char *filename, unsigned int lineno, + const char *format, ...) = error_at_line; void (*po_multiline_warning) (char *prefix, char *message) diff --git a/gettext-tools/src/po-error.h b/gettext-tools/src/po-error.h index f3ff64587..2cae33812 100644 --- a/gettext-tools/src/po-error.h +++ b/gettext-tools/src/po-error.h @@ -44,15 +44,15 @@ extern "C" { extern DLL_VARIABLE void (*po_error) (int status, int errnum, - const char *format, ...) + const char *format, ...) #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3 __attribute__ ((__format__ (__printf__, 3, 4))) #endif ; extern DLL_VARIABLE void (*po_error_at_line) (int status, int errnum, - const char *filename, unsigned int lineno, - const char *format, ...) + const char *filename, unsigned int lineno, + const char *format, ...) #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3 __attribute__ ((__format__ (__printf__, 5, 6))) #endif diff --git a/gettext-tools/src/po-gram-gen.y b/gettext-tools/src/po-gram-gen.y index f8827f005..fcb7f2dc4 100644 --- a/gettext-tools/src/po-gram-gen.y +++ b/gettext-tools/src/po-gram-gen.y @@ -94,50 +94,50 @@ static long plural_counter; static inline void do_callback_message (char *msgctxt, - char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural, - char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, char *prev_msgid_plural, - bool obsolete) + char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural, + char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, char *prev_msgid_plural, + bool obsolete) { /* Test for header entry. Ignore fuzziness of the header entry. */ if (msgctxt == NULL && msgid[0] == '\0' && !obsolete) po_lex_charset_set (msgstr, gram_pos.file_name); po_callback_message (msgctxt, - msgid, msgid_pos, msgid_plural, - msgstr, msgstr_len, msgstr_pos, - prev_msgctxt, prev_msgid, prev_msgid_plural, - false, obsolete); + msgid, msgid_pos, msgid_plural, + msgstr, msgstr_len, msgstr_pos, + prev_msgctxt, prev_msgid, prev_msgid_plural, + false, obsolete); } #define free_message_intro(value) \ - if ((value).prev_ctxt != NULL) \ - free ((value).prev_ctxt); \ - if ((value).prev_id != NULL) \ - free ((value).prev_id); \ - if ((value).prev_id_plural != NULL) \ - free ((value).prev_id_plural); \ - if ((value).ctxt != NULL) \ + if ((value).prev_ctxt != NULL) \ + free ((value).prev_ctxt); \ + if ((value).prev_id != NULL) \ + free ((value).prev_id); \ + if ((value).prev_id_plural != NULL) \ + free ((value).prev_id_plural); \ + if ((value).ctxt != NULL) \ free ((value).ctxt); %} -%token COMMENT -%token DOMAIN -%token JUNK -%token PREV_MSGCTXT -%token PREV_MSGID -%token PREV_MSGID_PLURAL -%token PREV_STRING -%token MSGCTXT -%token MSGID -%token MSGID_PLURAL -%token MSGSTR -%token NAME -%token '[' ']' -%token NUMBER -%token STRING +%token COMMENT +%token DOMAIN +%token JUNK +%token PREV_MSGCTXT +%token PREV_MSGID +%token PREV_MSGID_PLURAL +%token PREV_STRING +%token MSGCTXT +%token MSGID +%token MSGID_PLURAL +%token MSGSTR +%token NAME +%token '[' ']' +%token NUMBER +%token STRING %union { @@ -166,278 +166,278 @@ do_callback_message (char *msgctxt, %% po_file - : /* empty */ - | po_file comment - | po_file domain - | po_file message - | po_file error - ; + : /* empty */ + | po_file comment + | po_file domain + | po_file message + | po_file error + ; comment - : COMMENT - { - po_callback_comment_dispatcher ($1.string); - } - ; + : COMMENT + { + po_callback_comment_dispatcher ($1.string); + } + ; domain - : DOMAIN STRING - { - po_callback_domain ($2.string); - } - ; + : DOMAIN STRING + { + po_callback_domain ($2.string); + } + ; message - : message_intro string_list MSGSTR string_list - { - char *string2 = string_list_concat_destroy (&$2.stringlist); - char *string4 = string_list_concat_destroy (&$4.stringlist); - - check_obsolete ($1, $2); - check_obsolete ($1, $3); - check_obsolete ($1, $4); - if (!$1.obsolete || pass_obsolete_entries) - do_callback_message ($1.ctxt, string2, &$1.pos, NULL, - string4, strlen (string4) + 1, &$3.pos, - $1.prev_ctxt, - $1.prev_id, $1.prev_id_plural, - $1.obsolete); - else - { - free_message_intro ($1); - free (string2); - free (string4); - } - } - | message_intro string_list msgid_pluralform pluralform_list - { - char *string2 = string_list_concat_destroy (&$2.stringlist); - - check_obsolete ($1, $2); - check_obsolete ($1, $3); - check_obsolete ($1, $4); - if (!$1.obsolete || pass_obsolete_entries) - do_callback_message ($1.ctxt, string2, &$1.pos, $3.string, - $4.rhs.msgstr, $4.rhs.msgstr_len, &$4.pos, - $1.prev_ctxt, - $1.prev_id, $1.prev_id_plural, - $1.obsolete); - else - { - free_message_intro ($1); - free (string2); - free ($3.string); - free ($4.rhs.msgstr); - } - } - | message_intro string_list msgid_pluralform - { - check_obsolete ($1, $2); - check_obsolete ($1, $3); - po_gram_error_at_line (&$1.pos, _("missing `msgstr[]' section")); - free_message_intro ($1); - string_list_destroy (&$2.stringlist); - free ($3.string); - } - | message_intro string_list pluralform_list - { - check_obsolete ($1, $2); - check_obsolete ($1, $3); - po_gram_error_at_line (&$1.pos, _("missing `msgid_plural' section")); - free_message_intro ($1); - string_list_destroy (&$2.stringlist); - free ($3.rhs.msgstr); - } - | message_intro string_list - { - check_obsolete ($1, $2); - po_gram_error_at_line (&$1.pos, _("missing `msgstr' section")); - free_message_intro ($1); - string_list_destroy (&$2.stringlist); - } - ; + : message_intro string_list MSGSTR string_list + { + char *string2 = string_list_concat_destroy (&$2.stringlist); + char *string4 = string_list_concat_destroy (&$4.stringlist); + + check_obsolete ($1, $2); + check_obsolete ($1, $3); + check_obsolete ($1, $4); + if (!$1.obsolete || pass_obsolete_entries) + do_callback_message ($1.ctxt, string2, &$1.pos, NULL, + string4, strlen (string4) + 1, &$3.pos, + $1.prev_ctxt, + $1.prev_id, $1.prev_id_plural, + $1.obsolete); + else + { + free_message_intro ($1); + free (string2); + free (string4); + } + } + | message_intro string_list msgid_pluralform pluralform_list + { + char *string2 = string_list_concat_destroy (&$2.stringlist); + + check_obsolete ($1, $2); + check_obsolete ($1, $3); + check_obsolete ($1, $4); + if (!$1.obsolete || pass_obsolete_entries) + do_callback_message ($1.ctxt, string2, &$1.pos, $3.string, + $4.rhs.msgstr, $4.rhs.msgstr_len, &$4.pos, + $1.prev_ctxt, + $1.prev_id, $1.prev_id_plural, + $1.obsolete); + else + { + free_message_intro ($1); + free (string2); + free ($3.string); + free ($4.rhs.msgstr); + } + } + | message_intro string_list msgid_pluralform + { + check_obsolete ($1, $2); + check_obsolete ($1, $3); + po_gram_error_at_line (&$1.pos, _("missing `msgstr[]' section")); + free_message_intro ($1); + string_list_destroy (&$2.stringlist); + free ($3.string); + } + | message_intro string_list pluralform_list + { + check_obsolete ($1, $2); + check_obsolete ($1, $3); + po_gram_error_at_line (&$1.pos, _("missing `msgid_plural' section")); + free_message_intro ($1); + string_list_destroy (&$2.stringlist); + free ($3.rhs.msgstr); + } + | message_intro string_list + { + check_obsolete ($1, $2); + po_gram_error_at_line (&$1.pos, _("missing `msgstr' section")); + free_message_intro ($1); + string_list_destroy (&$2.stringlist); + } + ; message_intro - : msg_intro - { - $$.prev_ctxt = NULL; - $$.prev_id = NULL; - $$.prev_id_plural = NULL; - $$.ctxt = $1.string; - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - | prev msg_intro - { - check_obsolete ($1, $2); - $$.prev_ctxt = $1.ctxt; - $$.prev_id = $1.id; - $$.prev_id_plural = $1.id_plural; - $$.ctxt = $2.string; - $$.pos = $2.pos; - $$.obsolete = $2.obsolete; - } - ; + : msg_intro + { + $$.prev_ctxt = NULL; + $$.prev_id = NULL; + $$.prev_id_plural = NULL; + $$.ctxt = $1.string; + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + | prev msg_intro + { + check_obsolete ($1, $2); + $$.prev_ctxt = $1.ctxt; + $$.prev_id = $1.id; + $$.prev_id_plural = $1.id_plural; + $$.ctxt = $2.string; + $$.pos = $2.pos; + $$.obsolete = $2.obsolete; + } + ; prev - : prev_msg_intro prev_string_list - { - check_obsolete ($1, $2); - $$.ctxt = $1.string; - $$.id = string_list_concat_destroy (&$2.stringlist); - $$.id_plural = NULL; - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - | prev_msg_intro prev_string_list prev_msgid_pluralform - { - check_obsolete ($1, $2); - check_obsolete ($1, $3); - $$.ctxt = $1.string; - $$.id = string_list_concat_destroy (&$2.stringlist); - $$.id_plural = $3.string; - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - ; + : prev_msg_intro prev_string_list + { + check_obsolete ($1, $2); + $$.ctxt = $1.string; + $$.id = string_list_concat_destroy (&$2.stringlist); + $$.id_plural = NULL; + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + | prev_msg_intro prev_string_list prev_msgid_pluralform + { + check_obsolete ($1, $2); + check_obsolete ($1, $3); + $$.ctxt = $1.string; + $$.id = string_list_concat_destroy (&$2.stringlist); + $$.id_plural = $3.string; + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + ; msg_intro - : MSGID - { - $$.string = NULL; - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - | MSGCTXT string_list MSGID - { - check_obsolete ($1, $2); - check_obsolete ($1, $3); - $$.string = string_list_concat_destroy (&$2.stringlist); - $$.pos = $3.pos; - $$.obsolete = $3.obsolete; - } - ; + : MSGID + { + $$.string = NULL; + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + | MSGCTXT string_list MSGID + { + check_obsolete ($1, $2); + check_obsolete ($1, $3); + $$.string = string_list_concat_destroy (&$2.stringlist); + $$.pos = $3.pos; + $$.obsolete = $3.obsolete; + } + ; prev_msg_intro - : PREV_MSGID - { - $$.string = NULL; - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - | PREV_MSGCTXT prev_string_list PREV_MSGID - { - check_obsolete ($1, $2); - check_obsolete ($1, $3); - $$.string = string_list_concat_destroy (&$2.stringlist); - $$.pos = $3.pos; - $$.obsolete = $3.obsolete; - } - ; + : PREV_MSGID + { + $$.string = NULL; + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + | PREV_MSGCTXT prev_string_list PREV_MSGID + { + check_obsolete ($1, $2); + check_obsolete ($1, $3); + $$.string = string_list_concat_destroy (&$2.stringlist); + $$.pos = $3.pos; + $$.obsolete = $3.obsolete; + } + ; msgid_pluralform - : MSGID_PLURAL string_list - { - check_obsolete ($1, $2); - plural_counter = 0; - $$.string = string_list_concat_destroy (&$2.stringlist); - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - ; + : MSGID_PLURAL string_list + { + check_obsolete ($1, $2); + plural_counter = 0; + $$.string = string_list_concat_destroy (&$2.stringlist); + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + ; prev_msgid_pluralform - : PREV_MSGID_PLURAL prev_string_list - { - check_obsolete ($1, $2); - $$.string = string_list_concat_destroy (&$2.stringlist); - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - ; + : PREV_MSGID_PLURAL prev_string_list + { + check_obsolete ($1, $2); + $$.string = string_list_concat_destroy (&$2.stringlist); + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + ; pluralform_list - : pluralform - { - $$ = $1; - } - | pluralform_list pluralform - { - check_obsolete ($1, $2); - $$.rhs.msgstr = XNMALLOC ($1.rhs.msgstr_len + $2.rhs.msgstr_len, char); - memcpy ($$.rhs.msgstr, $1.rhs.msgstr, $1.rhs.msgstr_len); - memcpy ($$.rhs.msgstr + $1.rhs.msgstr_len, $2.rhs.msgstr, $2.rhs.msgstr_len); - $$.rhs.msgstr_len = $1.rhs.msgstr_len + $2.rhs.msgstr_len; - free ($1.rhs.msgstr); - free ($2.rhs.msgstr); - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - ; + : pluralform + { + $$ = $1; + } + | pluralform_list pluralform + { + check_obsolete ($1, $2); + $$.rhs.msgstr = XNMALLOC ($1.rhs.msgstr_len + $2.rhs.msgstr_len, char); + memcpy ($$.rhs.msgstr, $1.rhs.msgstr, $1.rhs.msgstr_len); + memcpy ($$.rhs.msgstr + $1.rhs.msgstr_len, $2.rhs.msgstr, $2.rhs.msgstr_len); + $$.rhs.msgstr_len = $1.rhs.msgstr_len + $2.rhs.msgstr_len; + free ($1.rhs.msgstr); + free ($2.rhs.msgstr); + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + ; pluralform - : MSGSTR '[' NUMBER ']' string_list - { - check_obsolete ($1, $2); - check_obsolete ($1, $3); - check_obsolete ($1, $4); - check_obsolete ($1, $5); - if ($3.number != plural_counter) - { - if (plural_counter == 0) - po_gram_error_at_line (&$1.pos, _("first plural form has nonzero index")); - else - po_gram_error_at_line (&$1.pos, _("plural form has wrong index")); - } - plural_counter++; - $$.rhs.msgstr = string_list_concat_destroy (&$5.stringlist); - $$.rhs.msgstr_len = strlen ($$.rhs.msgstr) + 1; - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - ; + : MSGSTR '[' NUMBER ']' string_list + { + check_obsolete ($1, $2); + check_obsolete ($1, $3); + check_obsolete ($1, $4); + check_obsolete ($1, $5); + if ($3.number != plural_counter) + { + if (plural_counter == 0) + po_gram_error_at_line (&$1.pos, _("first plural form has nonzero index")); + else + po_gram_error_at_line (&$1.pos, _("plural form has wrong index")); + } + plural_counter++; + $$.rhs.msgstr = string_list_concat_destroy (&$5.stringlist); + $$.rhs.msgstr_len = strlen ($$.rhs.msgstr) + 1; + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + ; string_list - : STRING - { - string_list_init (&$$.stringlist); - string_list_append (&$$.stringlist, $1.string); - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - | string_list STRING - { - check_obsolete ($1, $2); - $$.stringlist = $1.stringlist; - string_list_append (&$$.stringlist, $2.string); - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - ; + : STRING + { + string_list_init (&$$.stringlist); + string_list_append (&$$.stringlist, $1.string); + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + | string_list STRING + { + check_obsolete ($1, $2); + $$.stringlist = $1.stringlist; + string_list_append (&$$.stringlist, $2.string); + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + ; prev_string_list - : PREV_STRING - { - string_list_init (&$$.stringlist); - string_list_append (&$$.stringlist, $1.string); - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - | prev_string_list PREV_STRING - { - check_obsolete ($1, $2); - $$.stringlist = $1.stringlist; - string_list_append (&$$.stringlist, $2.string); - $$.pos = $1.pos; - $$.obsolete = $1.obsolete; - } - ; + : PREV_STRING + { + string_list_init (&$$.stringlist); + string_list_append (&$$.stringlist, $1.string); + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + | prev_string_list PREV_STRING + { + check_obsolete ($1, $2); + $$.stringlist = $1.stringlist; + string_list_append (&$$.stringlist, $2.string); + $$.pos = $1.pos; + $$.obsolete = $1.obsolete; + } + ; diff --git a/gettext-tools/src/po-lex.c b/gettext-tools/src/po-lex.c index 9de70068e..98943ec9c 100644 --- a/gettext-tools/src/po-lex.c +++ b/gettext-tools/src/po-lex.c @@ -83,7 +83,7 @@ po_gram_error (const char *fmt, ...) error (EXIT_FAILURE, 0, _("memory exhausted")); va_end (ap); po_xerror (PO_SEVERITY_ERROR, NULL, gram_pos.file_name, gram_pos.line_number, - gram_pos_column + 1, false, buffer); + gram_pos_column + 1, false, buffer); free (buffer); if (error_message_count >= gram_max_allowed_errors) @@ -102,7 +102,7 @@ po_gram_error_at_line (const lex_pos_ty *pp, const char *fmt, ...) error (EXIT_FAILURE, 0, _("memory exhausted")); va_end (ap); po_xerror (PO_SEVERITY_ERROR, NULL, pp->file_name, pp->line_number, - (size_t)(-1), false, buffer); + (size_t)(-1), false, buffer); free (buffer); if (error_message_count >= gram_max_allowed_errors) @@ -129,10 +129,10 @@ po_gram_error_at_line (const lex_pos_ty *pp, const char *fmt, ...) struct mbchar { - size_t bytes; /* number of bytes of current character, > 0 */ + size_t bytes; /* number of bytes of current character, > 0 */ #if HAVE_ICONV - bool uc_valid; /* true if uc is a valid Unicode character */ - ucs4_t uc; /* if uc_valid: the current character */ + bool uc_valid; /* true if uc is a valid Unicode character */ + ucs4_t uc; /* if uc_valid: the current character */ #endif char buf[MBCHAR_BUF_SIZE]; /* room for the bytes */ }; @@ -152,7 +152,7 @@ memcpy_small (void *dst, const void *src, size_t n) *q = *p; if (--n > 0) - do *++q = *++p; while (--n > 0); + do *++q = *++p; while (--n > 0); } } @@ -213,10 +213,10 @@ mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2) else #endif return (mbc1->bytes == mbc2->bytes - ? memcmp (mbc1->buf, mbc2->buf, mbc1->bytes) - : mbc1->bytes < mbc2->bytes - ? (memcmp (mbc1->buf, mbc2->buf, mbc1->bytes) > 0 ? 1 : -1) - : (memcmp (mbc1->buf, mbc2->buf, mbc2->bytes) >= 0 ? 1 : -1)); + ? memcmp (mbc1->buf, mbc2->buf, mbc1->bytes) + : mbc1->bytes < mbc2->bytes + ? (memcmp (mbc1->buf, mbc2->buf, mbc1->bytes) > 0 ? 1 : -1) + : (memcmp (mbc1->buf, mbc2->buf, mbc2->bytes) >= 0 ? 1 : -1)); } static inline bool @@ -228,7 +228,7 @@ mb_equal (const mbchar_t mbc1, const mbchar_t mbc2) else #endif return (mbc1->bytes == mbc2->bytes - && memcmp (mbc1->buf, mbc2->buf, mbc1->bytes) == 0); + && memcmp (mbc1->buf, mbc2->buf, mbc1->bytes) == 0); } /* , classification. */ @@ -243,12 +243,12 @@ mb_isascii (const mbchar_t mbc) #endif return (mbc->bytes == 1 #if CHAR_MIN < 0x00 /* to avoid gcc warning */ - && mbc->buf[0] >= 0x00 + && mbc->buf[0] >= 0x00 #endif #if CHAR_MAX > 0x7F /* to avoid gcc warning */ - && mbc->buf[0] <= 0x7F + && mbc->buf[0] <= 0x7F #endif - ); + ); } /* Extra function. */ @@ -264,40 +264,40 @@ mb_width (const mbchar_t mbc) { ucs4_t uc = mbc->uc; const char *encoding = - (po_lex_iconv != (iconv_t)(-1) ? po_lex_charset : ""); + (po_lex_iconv != (iconv_t)(-1) ? po_lex_charset : ""); int w = uc_width (uc, encoding); /* For unprintable characters, arbitrarily return 0 for control - characters (except tab) and MB_UNPRINTABLE_WIDTH otherwise. */ + characters (except tab) and MB_UNPRINTABLE_WIDTH otherwise. */ if (w >= 0) - return w; + return w; if (uc >= 0x0000 && uc <= 0x001F) - { - if (uc == 0x0009) - return 8 - (gram_pos_column & 7); - return 0; - } + { + if (uc == 0x0009) + return 8 - (gram_pos_column & 7); + return 0; + } if ((uc >= 0x007F && uc <= 0x009F) || (uc >= 0x2028 && uc <= 0x2029)) - return 0; + return 0; return MB_UNPRINTABLE_WIDTH; } else #endif { if (mbc->bytes == 1) - { - if ( + { + if ( #if CHAR_MIN < 0x00 /* to avoid gcc warning */ - mbc->buf[0] >= 0x00 && + mbc->buf[0] >= 0x00 && #endif - mbc->buf[0] <= 0x1F) - { - if (mbc->buf[0] == 0x09) - return 8 - (gram_pos_column & 7); - return 0; - } - if (mbc->buf[0] == 0x7F) - return 0; - } + mbc->buf[0] <= 0x1F) + { + if (mbc->buf[0] == 0x09) + return 8 - (gram_pos_column & 7); + return 0; + } + if (mbc->buf[0] == 0x7F) + return 0; + } return MB_UNPRINTABLE_WIDTH; } } @@ -393,10 +393,10 @@ mbfile_getc (mbchar_t mbc, mbfile_t mbf) { int c = getc (mbf->fp); if (c == EOF) - { - mbf->eof_seen = true; - goto eof; - } + { + mbf->eof_seen = true; + goto eof; + } mbf->buf[0] = (unsigned char) c; mbf->bufcount++; } @@ -405,151 +405,151 @@ mbfile_getc (mbchar_t mbc, mbfile_t mbf) if (po_lex_iconv != (iconv_t)(-1)) { /* Use iconv on an increasing number of bytes. Read only as many - bytes from mbf->fp as needed. This is needed to give reasonable - interactive behaviour when mbf->fp is connected to an interactive - tty. */ + bytes from mbf->fp as needed. This is needed to give reasonable + interactive behaviour when mbf->fp is connected to an interactive + tty. */ for (;;) - { - unsigned char scratchbuf[64]; - const char *inptr = &mbf->buf[0]; - size_t insize = mbf->bufcount; - char *outptr = (char *) &scratchbuf[0]; - size_t outsize = sizeof (scratchbuf); - - size_t res = iconv (po_lex_iconv, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - /* We expect that a character has been produced if and only if - some input bytes have been consumed. */ - if ((insize < mbf->bufcount) != (outsize < sizeof (scratchbuf))) - abort (); - if (outsize == sizeof (scratchbuf)) - { - /* No character has been produced. Must be an error. */ - if (res != (size_t)(-1)) - abort (); - - if (errno == EILSEQ) - { - /* An invalid multibyte sequence was encountered. */ - /* Return a single byte. */ - if (signal_eilseq) - po_gram_error (_("invalid multibyte sequence")); - bytes = 1; - mbc->uc_valid = false; - break; - } - else if (errno == EINVAL) - { - /* An incomplete multibyte character. */ - int c; - - if (mbf->bufcount == MBCHAR_BUF_SIZE) - { - /* An overlong incomplete multibyte sequence was - encountered. */ - /* Return a single byte. */ - bytes = 1; - mbc->uc_valid = false; - break; - } - - /* Read one more byte and retry iconv. */ - c = getc (mbf->fp); - if (c == EOF) - { - mbf->eof_seen = true; - if (ferror (mbf->fp)) - goto eof; - if (signal_eilseq) - po_gram_error (_("\ + { + unsigned char scratchbuf[64]; + const char *inptr = &mbf->buf[0]; + size_t insize = mbf->bufcount; + char *outptr = (char *) &scratchbuf[0]; + size_t outsize = sizeof (scratchbuf); + + size_t res = iconv (po_lex_iconv, + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); + /* We expect that a character has been produced if and only if + some input bytes have been consumed. */ + if ((insize < mbf->bufcount) != (outsize < sizeof (scratchbuf))) + abort (); + if (outsize == sizeof (scratchbuf)) + { + /* No character has been produced. Must be an error. */ + if (res != (size_t)(-1)) + abort (); + + if (errno == EILSEQ) + { + /* An invalid multibyte sequence was encountered. */ + /* Return a single byte. */ + if (signal_eilseq) + po_gram_error (_("invalid multibyte sequence")); + bytes = 1; + mbc->uc_valid = false; + break; + } + else if (errno == EINVAL) + { + /* An incomplete multibyte character. */ + int c; + + if (mbf->bufcount == MBCHAR_BUF_SIZE) + { + /* An overlong incomplete multibyte sequence was + encountered. */ + /* Return a single byte. */ + bytes = 1; + mbc->uc_valid = false; + break; + } + + /* Read one more byte and retry iconv. */ + c = getc (mbf->fp); + if (c == EOF) + { + mbf->eof_seen = true; + if (ferror (mbf->fp)) + goto eof; + if (signal_eilseq) + po_gram_error (_("\ incomplete multibyte sequence at end of file")); - bytes = mbf->bufcount; - mbc->uc_valid = false; - break; - } - mbf->buf[mbf->bufcount++] = (unsigned char) c; - if (c == '\n') - { - if (signal_eilseq) - po_gram_error (_("\ + bytes = mbf->bufcount; + mbc->uc_valid = false; + break; + } + mbf->buf[mbf->bufcount++] = (unsigned char) c; + if (c == '\n') + { + if (signal_eilseq) + po_gram_error (_("\ incomplete multibyte sequence at end of line")); - bytes = mbf->bufcount - 1; - mbc->uc_valid = false; - break; - } - } - else - { - const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - _("iconv failure"), - errno_description)); - } - } - else - { - size_t outbytes = sizeof (scratchbuf) - outsize; - bytes = mbf->bufcount - insize; - - /* We expect that one character has been produced. */ - if (bytes == 0) - abort (); - if (outbytes == 0) - abort (); - /* Convert it from UTF-8 to UCS-4. */ - if (u8_mbtouc (&mbc->uc, scratchbuf, outbytes) < outbytes) - { - /* scratchbuf contains an out-of-range Unicode character - (> 0x10ffff). */ - if (signal_eilseq) - po_gram_error (_("invalid multibyte sequence")); - mbc->uc_valid = false; - break; - } - mbc->uc_valid = true; - break; - } - } + bytes = mbf->bufcount - 1; + mbc->uc_valid = false; + break; + } + } + else + { + const char *errno_description = strerror (errno); + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + _("iconv failure"), + errno_description)); + } + } + else + { + size_t outbytes = sizeof (scratchbuf) - outsize; + bytes = mbf->bufcount - insize; + + /* We expect that one character has been produced. */ + if (bytes == 0) + abort (); + if (outbytes == 0) + abort (); + /* Convert it from UTF-8 to UCS-4. */ + if (u8_mbtouc (&mbc->uc, scratchbuf, outbytes) < outbytes) + { + /* scratchbuf contains an out-of-range Unicode character + (> 0x10ffff). */ + if (signal_eilseq) + po_gram_error (_("invalid multibyte sequence")); + mbc->uc_valid = false; + break; + } + mbc->uc_valid = true; + break; + } + } } else #endif { if (po_lex_weird_cjk - /* Special handling of encodings with CJK structure. */ - && (unsigned char) mbf->buf[0] >= 0x80) - { - if (mbf->bufcount == 1) - { - /* Read one more byte. */ - int c = getc (mbf->fp); - if (c == EOF) - { - if (ferror (mbf->fp)) - { - mbf->eof_seen = true; - goto eof; - } - } - else - { - mbf->buf[1] = (unsigned char) c; - mbf->bufcount++; - } - } - if (mbf->bufcount >= 2 && (unsigned char) mbf->buf[1] >= 0x30) - /* Return a double byte. */ - bytes = 2; - else - /* Return a single byte. */ - bytes = 1; - } + /* Special handling of encodings with CJK structure. */ + && (unsigned char) mbf->buf[0] >= 0x80) + { + if (mbf->bufcount == 1) + { + /* Read one more byte. */ + int c = getc (mbf->fp); + if (c == EOF) + { + if (ferror (mbf->fp)) + { + mbf->eof_seen = true; + goto eof; + } + } + else + { + mbf->buf[1] = (unsigned char) c; + mbf->bufcount++; + } + } + if (mbf->bufcount >= 2 && (unsigned char) mbf->buf[1] >= 0x30) + /* Return a double byte. */ + bytes = 2; + else + /* Return a single byte. */ + bytes = 1; + } else - { - /* Return a single byte. */ - bytes = 1; - } + { + /* Return a single byte. */ + bytes = 1; + } #if HAVE_ICONV mbc->uc_valid = false; #endif @@ -567,10 +567,10 @@ incomplete multibyte sequence at end of line")); char *p = &mbf->buf[0]; do - { - *p = *(p + bytes); - p++; - } + { + *p = *(p + bytes); + p++; + } while (--count > 0); } return; @@ -647,53 +647,53 @@ lex_getc (mbchar_t mbc) mbfile_getc (mbc, mbf); if (mb_iseof (mbc)) - { - if (ferror (mbf->fp)) - bomb: - { - const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while reading \"%s\""), - gram_pos.file_name), - errno_description)); - } - break; - } + { + if (ferror (mbf->fp)) + bomb: + { + const char *errno_description = strerror (errno); + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("error while reading \"%s\""), + gram_pos.file_name), + errno_description)); + } + break; + } if (mb_iseq (mbc, '\n')) - { - gram_pos.line_number++; - gram_pos_column = 0; - break; - } + { + gram_pos.line_number++; + gram_pos_column = 0; + break; + } gram_pos_column += mb_width (mbc); if (mb_iseq (mbc, '\\')) - { - mbchar_t mbc2; - - mbfile_getc (mbc2, mbf); - - if (mb_iseof (mbc2)) - { - if (ferror (mbf->fp)) - goto bomb; - break; - } - - if (!mb_iseq (mbc2, '\n')) - { - mbfile_ungetc (mbc2, mbf); - break; - } - - gram_pos.line_number++; - gram_pos_column = 0; - } + { + mbchar_t mbc2; + + mbfile_getc (mbc2, mbf); + + if (mb_iseof (mbc2)) + { + if (ferror (mbf->fp)) + goto bomb; + break; + } + + if (!mb_iseq (mbc2, '\n')) + { + mbfile_ungetc (mbc2, mbf); + break; + } + + gram_pos.line_number++; + gram_pos_column = 0; + } else - break; + break; } } @@ -704,11 +704,11 @@ lex_ungetc (const mbchar_t mbc) if (!mb_iseof (mbc)) { if (mb_iseq (mbc, '\n')) - /* Decrement the line number, but don't care about the column. */ - gram_pos.line_number--; + /* Decrement the line number, but don't care about the column. */ + gram_pos.line_number--; else - /* Decrement the column number. Also works well enough for tabs. */ - gram_pos_column -= mb_width (mbc); + /* Decrement the column number. Also works well enough for tabs. */ + gram_pos_column -= mb_width (mbc); mbfile_ungetc (mbc, mbf); } @@ -721,25 +721,25 @@ keyword_p (const char *s) if (!po_lex_previous) { if (!strcmp (s, "domain")) - return DOMAIN; + return DOMAIN; if (!strcmp (s, "msgid")) - return MSGID; + return MSGID; if (!strcmp (s, "msgid_plural")) - return MSGID_PLURAL; + return MSGID_PLURAL; if (!strcmp (s, "msgstr")) - return MSGSTR; + return MSGSTR; if (!strcmp (s, "msgctxt")) - return MSGCTXT; + return MSGCTXT; } else { /* Inside a "#|" context, the keywords have a different meaning. */ if (!strcmp (s, "msgid")) - return PREV_MSGID; + return PREV_MSGID; if (!strcmp (s, "msgid_plural")) - return PREV_MSGID_PLURAL; + return PREV_MSGID_PLURAL; if (!strcmp (s, "msgctxt")) - return PREV_MSGCTXT; + return PREV_MSGCTXT; } po_gram_error_at_line (&gram_pos, _("keyword \"%s\" unknown"), s); return NAME; @@ -758,95 +758,95 @@ control_sequence () switch (mb_ptr (mbc) [0]) { case 'n': - return '\n'; + return '\n'; case 't': - return '\t'; + return '\t'; case 'b': - return '\b'; + return '\b'; case 'r': - return '\r'; + return '\r'; case 'f': - return '\f'; + return '\f'; case 'v': - return '\v'; + return '\v'; case 'a': - return '\a'; + return '\a'; case '\\': case '"': - return mb_ptr (mbc) [0]; + return mb_ptr (mbc) [0]; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': - val = 0; - max = 0; - for (;;) - { - char c = mb_ptr (mbc) [0]; - /* Warning: not portable, can't depend on '0'..'7' ordering. */ - val = val * 8 + (c - '0'); - if (++max == 3) - break; - lex_getc (mbc); - if (mb_len (mbc) == 1) - switch (mb_ptr (mbc) [0]) - { - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - continue; - - default: - break; - } - lex_ungetc (mbc); - break; - } - return val; + val = 0; + max = 0; + for (;;) + { + char c = mb_ptr (mbc) [0]; + /* Warning: not portable, can't depend on '0'..'7' ordering. */ + val = val * 8 + (c - '0'); + if (++max == 3) + break; + lex_getc (mbc); + if (mb_len (mbc) == 1) + switch (mb_ptr (mbc) [0]) + { + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + continue; + + default: + break; + } + lex_ungetc (mbc); + break; + } + return val; case 'x': - lex_getc (mbc); - if (mb_iseof (mbc) || mb_len (mbc) != 1 - || !c_isxdigit (mb_ptr (mbc) [0])) - break; - - val = 0; - for (;;) - { - char c = mb_ptr (mbc) [0]; - val *= 16; - if (c_isdigit (c)) - /* Warning: not portable, can't depend on '0'..'9' ordering */ - val += c - '0'; - else if (c_isupper (c)) - /* Warning: not portable, can't depend on 'A'..'F' ordering */ - val += c - 'A' + 10; - else - /* Warning: not portable, can't depend on 'a'..'f' ordering */ - val += c - 'a' + 10; - - lex_getc (mbc); - if (mb_len (mbc) == 1) - switch (mb_ptr (mbc) [0]) - { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - continue; - - default: - break; - } - lex_ungetc (mbc); - break; - } - return val; + lex_getc (mbc); + if (mb_iseof (mbc) || mb_len (mbc) != 1 + || !c_isxdigit (mb_ptr (mbc) [0])) + break; + + val = 0; + for (;;) + { + char c = mb_ptr (mbc) [0]; + val *= 16; + if (c_isdigit (c)) + /* Warning: not portable, can't depend on '0'..'9' ordering */ + val += c - '0'; + else if (c_isupper (c)) + /* Warning: not portable, can't depend on 'A'..'F' ordering */ + val += c - 'A' + 10; + else + /* Warning: not portable, can't depend on 'a'..'f' ordering */ + val += c - 'a' + 10; + + lex_getc (mbc); + if (mb_len (mbc) == 1) + switch (mb_ptr (mbc) [0]) + { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + continue; + + default: + break; + } + lex_ungetc (mbc); + break; + } + return val; /* FIXME: \u and \U are not handled. */ } @@ -871,265 +871,265 @@ po_gram_lex () lex_getc (mbc); if (mb_iseof (mbc)) - /* Yacc want this for end of file. */ - return 0; + /* Yacc want this for end of file. */ + return 0; if (mb_len (mbc) == 1) - switch (mb_ptr (mbc) [0]) - { - case '\n': - po_lex_obsolete = false; - po_lex_previous = false; - /* Ignore whitespace, not relevant for the grammar. */ - break; - - case ' ': - case '\t': - case '\r': - case '\f': - case '\v': - /* Ignore whitespace, not relevant for the grammar. */ - break; - - case '#': - lex_getc (mbc); - if (mb_iseq (mbc, '~')) - /* A pseudo-comment beginning with #~ is found. This is - not a comment. It is the format for obsolete entries. - We simply discard the "#~" prefix. The following - characters are expected to be well formed. */ - { - po_lex_obsolete = true; - /* A pseudo-comment beginning with #~| denotes a previous - untranslated string in an obsolete entry. This does not - make much sense semantically, and is implemented here - for completeness only. */ - lex_getc (mbc); - if (mb_iseq (mbc, '|')) - po_lex_previous = true; - else - lex_ungetc (mbc); - break; - } - if (mb_iseq (mbc, '|')) - /* A pseudo-comment beginning with #| is found. This is - the previous untranslated string. We discard the "#|" - prefix, but change the keywords and string returns - accordingly. */ - { - po_lex_previous = true; - break; - } - - /* Accumulate comments into a buffer. If we have been asked - to pass comments, generate a COMMENT token, otherwise - discard it. */ - signal_eilseq = false; - if (pass_comments) - { - bufpos = 0; - for (;;) - { - while (bufpos + mb_len (mbc) >= bufmax) - { - bufmax += 100; - buf = xrealloc (buf, bufmax); - } - if (mb_iseof (mbc) || mb_iseq (mbc, '\n')) - break; - - memcpy_small (&buf[bufpos], mb_ptr (mbc), mb_len (mbc)); - bufpos += mb_len (mbc); - - lex_getc (mbc); - } - buf[bufpos] = '\0'; - - po_gram_lval.string.string = buf; - po_gram_lval.string.pos = gram_pos; - po_gram_lval.string.obsolete = po_lex_obsolete; - po_lex_obsolete = false; - signal_eilseq = true; - return COMMENT; - } - else - { - /* We do this in separate loop because collecting large - comments while they get not passed to the upper layers - is not very efficient. */ - while (!mb_iseof (mbc) && !mb_iseq (mbc, '\n')) - lex_getc (mbc); - po_lex_obsolete = false; - signal_eilseq = true; - } - break; - - case '"': - /* Accumulate a string. */ - bufpos = 0; - for (;;) - { - lex_getc (mbc); - while (bufpos + mb_len (mbc) >= bufmax) - { - bufmax += 100; - buf = xrealloc (buf, bufmax); - } - if (mb_iseof (mbc)) - { - po_gram_error_at_line (&gram_pos, - _("end-of-file within string")); - break; - } - if (mb_iseq (mbc, '\n')) - { - po_gram_error_at_line (&gram_pos, - _("end-of-line within string")); - break; - } - if (mb_iseq (mbc, '"')) - break; - if (mb_iseq (mbc, '\\')) - { - buf[bufpos++] = control_sequence (); - continue; - } - - /* Add mbc to the accumulator. */ - memcpy_small (&buf[bufpos], mb_ptr (mbc), mb_len (mbc)); - bufpos += mb_len (mbc); - } - buf[bufpos] = '\0'; - - /* Strings cannot contain the msgctxt separator, because it cannot - be faithfully represented in the msgid of a .mo file. */ - if (strchr (buf, MSGCTXT_SEPARATOR) != NULL) - po_gram_error_at_line (&gram_pos, - _("context separator within string")); - - /* FIXME: Treatment of embedded \000 chars is incorrect. */ - po_gram_lval.string.string = xstrdup (buf); - po_gram_lval.string.pos = gram_pos; - po_gram_lval.string.obsolete = po_lex_obsolete; - return (po_lex_previous ? PREV_STRING : STRING); - - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': case '$': - bufpos = 0; - for (;;) - { - char c = mb_ptr (mbc) [0]; - if (bufpos + 1 >= bufmax) - { - bufmax += 100; - buf = xrealloc (buf, bufmax); - } - buf[bufpos++] = c; - lex_getc (mbc); - if (mb_len (mbc) == 1) - switch (mb_ptr (mbc) [0]) - { - default: - break; - case 'a': case 'b': case 'c': case 'd': case 'e': - case 'f': case 'g': case 'h': case 'i': case 'j': - case 'k': case 'l': case 'm': case 'n': case 'o': - case 'p': case 'q': case 'r': case 's': case 't': - case 'u': case 'v': case 'w': case 'x': case 'y': - case 'z': - case 'A': case 'B': case 'C': case 'D': case 'E': - case 'F': case 'G': case 'H': case 'I': case 'J': - case 'K': case 'L': case 'M': case 'N': case 'O': - case 'P': case 'Q': case 'R': case 'S': case 'T': - case 'U': case 'V': case 'W': case 'X': case 'Y': - case 'Z': - case '_': case '$': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - continue; - } - break; - } - lex_ungetc (mbc); - - buf[bufpos] = '\0'; - - { - int k = keyword_p (buf); - if (k == NAME) - { - po_gram_lval.string.string = xstrdup (buf); - po_gram_lval.string.pos = gram_pos; - po_gram_lval.string.obsolete = po_lex_obsolete; - } - else - { - po_gram_lval.pos.pos = gram_pos; - po_gram_lval.pos.obsolete = po_lex_obsolete; - } - return k; - } - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - bufpos = 0; - for (;;) - { - char c = mb_ptr (mbc) [0]; - if (bufpos + 1 >= bufmax) - { - bufmax += 100; - buf = xrealloc (buf, bufmax + 1); - } - buf[bufpos++] = c; - lex_getc (mbc); - if (mb_len (mbc) == 1) - switch (mb_ptr (mbc) [0]) - { - default: - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - continue; - } - break; - } - lex_ungetc (mbc); - - buf[bufpos] = '\0'; - - po_gram_lval.number.number = atol (buf); - po_gram_lval.number.pos = gram_pos; - po_gram_lval.number.obsolete = po_lex_obsolete; - return NUMBER; - - case '[': - po_gram_lval.pos.pos = gram_pos; - po_gram_lval.pos.obsolete = po_lex_obsolete; - return '['; - - case ']': - po_gram_lval.pos.pos = gram_pos; - po_gram_lval.pos.obsolete = po_lex_obsolete; - return ']'; - - default: - /* This will cause a syntax error. */ - return JUNK; - } + switch (mb_ptr (mbc) [0]) + { + case '\n': + po_lex_obsolete = false; + po_lex_previous = false; + /* Ignore whitespace, not relevant for the grammar. */ + break; + + case ' ': + case '\t': + case '\r': + case '\f': + case '\v': + /* Ignore whitespace, not relevant for the grammar. */ + break; + + case '#': + lex_getc (mbc); + if (mb_iseq (mbc, '~')) + /* A pseudo-comment beginning with #~ is found. This is + not a comment. It is the format for obsolete entries. + We simply discard the "#~" prefix. The following + characters are expected to be well formed. */ + { + po_lex_obsolete = true; + /* A pseudo-comment beginning with #~| denotes a previous + untranslated string in an obsolete entry. This does not + make much sense semantically, and is implemented here + for completeness only. */ + lex_getc (mbc); + if (mb_iseq (mbc, '|')) + po_lex_previous = true; + else + lex_ungetc (mbc); + break; + } + if (mb_iseq (mbc, '|')) + /* A pseudo-comment beginning with #| is found. This is + the previous untranslated string. We discard the "#|" + prefix, but change the keywords and string returns + accordingly. */ + { + po_lex_previous = true; + break; + } + + /* Accumulate comments into a buffer. If we have been asked + to pass comments, generate a COMMENT token, otherwise + discard it. */ + signal_eilseq = false; + if (pass_comments) + { + bufpos = 0; + for (;;) + { + while (bufpos + mb_len (mbc) >= bufmax) + { + bufmax += 100; + buf = xrealloc (buf, bufmax); + } + if (mb_iseof (mbc) || mb_iseq (mbc, '\n')) + break; + + memcpy_small (&buf[bufpos], mb_ptr (mbc), mb_len (mbc)); + bufpos += mb_len (mbc); + + lex_getc (mbc); + } + buf[bufpos] = '\0'; + + po_gram_lval.string.string = buf; + po_gram_lval.string.pos = gram_pos; + po_gram_lval.string.obsolete = po_lex_obsolete; + po_lex_obsolete = false; + signal_eilseq = true; + return COMMENT; + } + else + { + /* We do this in separate loop because collecting large + comments while they get not passed to the upper layers + is not very efficient. */ + while (!mb_iseof (mbc) && !mb_iseq (mbc, '\n')) + lex_getc (mbc); + po_lex_obsolete = false; + signal_eilseq = true; + } + break; + + case '"': + /* Accumulate a string. */ + bufpos = 0; + for (;;) + { + lex_getc (mbc); + while (bufpos + mb_len (mbc) >= bufmax) + { + bufmax += 100; + buf = xrealloc (buf, bufmax); + } + if (mb_iseof (mbc)) + { + po_gram_error_at_line (&gram_pos, + _("end-of-file within string")); + break; + } + if (mb_iseq (mbc, '\n')) + { + po_gram_error_at_line (&gram_pos, + _("end-of-line within string")); + break; + } + if (mb_iseq (mbc, '"')) + break; + if (mb_iseq (mbc, '\\')) + { + buf[bufpos++] = control_sequence (); + continue; + } + + /* Add mbc to the accumulator. */ + memcpy_small (&buf[bufpos], mb_ptr (mbc), mb_len (mbc)); + bufpos += mb_len (mbc); + } + buf[bufpos] = '\0'; + + /* Strings cannot contain the msgctxt separator, because it cannot + be faithfully represented in the msgid of a .mo file. */ + if (strchr (buf, MSGCTXT_SEPARATOR) != NULL) + po_gram_error_at_line (&gram_pos, + _("context separator within string")); + + /* FIXME: Treatment of embedded \000 chars is incorrect. */ + po_gram_lval.string.string = xstrdup (buf); + po_gram_lval.string.pos = gram_pos; + po_gram_lval.string.obsolete = po_lex_obsolete; + return (po_lex_previous ? PREV_STRING : STRING); + + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': case '$': + bufpos = 0; + for (;;) + { + char c = mb_ptr (mbc) [0]; + if (bufpos + 1 >= bufmax) + { + bufmax += 100; + buf = xrealloc (buf, bufmax); + } + buf[bufpos++] = c; + lex_getc (mbc); + if (mb_len (mbc) == 1) + switch (mb_ptr (mbc) [0]) + { + default: + break; + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': case '$': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + continue; + } + break; + } + lex_ungetc (mbc); + + buf[bufpos] = '\0'; + + { + int k = keyword_p (buf); + if (k == NAME) + { + po_gram_lval.string.string = xstrdup (buf); + po_gram_lval.string.pos = gram_pos; + po_gram_lval.string.obsolete = po_lex_obsolete; + } + else + { + po_gram_lval.pos.pos = gram_pos; + po_gram_lval.pos.obsolete = po_lex_obsolete; + } + return k; + } + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + bufpos = 0; + for (;;) + { + char c = mb_ptr (mbc) [0]; + if (bufpos + 1 >= bufmax) + { + bufmax += 100; + buf = xrealloc (buf, bufmax + 1); + } + buf[bufpos++] = c; + lex_getc (mbc); + if (mb_len (mbc) == 1) + switch (mb_ptr (mbc) [0]) + { + default: + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + continue; + } + break; + } + lex_ungetc (mbc); + + buf[bufpos] = '\0'; + + po_gram_lval.number.number = atol (buf); + po_gram_lval.number.pos = gram_pos; + po_gram_lval.number.obsolete = po_lex_obsolete; + return NUMBER; + + case '[': + po_gram_lval.pos.pos = gram_pos; + po_gram_lval.pos.obsolete = po_lex_obsolete; + return '['; + + case ']': + po_gram_lval.pos.pos = gram_pos; + po_gram_lval.pos.obsolete = po_lex_obsolete; + return ']'; + + default: + /* This will cause a syntax error. */ + return JUNK; + } else - /* This will cause a syntax error. */ - return JUNK; + /* This will cause a syntax error. */ + return JUNK; } } diff --git a/gettext-tools/src/po-lex.h b/gettext-tools/src/po-lex.h index 3a585d093..df8276efa 100644 --- a/gettext-tools/src/po-lex.h +++ b/gettext-tools/src/po-lex.h @@ -65,7 +65,7 @@ extern DLL_VARIABLE bool pass_obsolete_entries; /* Prepare lexical analysis. */ extern void lex_start (FILE *fp, const char *real_filename, - const char *logical_filename); + const char *logical_filename); /* Terminate lexical analysis. */ extern void lex_end (void); diff --git a/gettext-tools/src/po-time.c b/gettext-tools/src/po-time.c index 70a3f2ca1..dd357f1da 100644 --- a/gettext-tools/src/po-time.c +++ b/gettext-tools/src/po-time.c @@ -35,18 +35,18 @@ difftm (const struct tm *a, const struct tm *b) int by = b->tm_year + TM_YEAR_ORIGIN - 1; /* Some compilers cannot handle this as a single return statement. */ long days = ( - /* difference in day of year */ - a->tm_yday - b->tm_yday - /* + intervening leap days */ - + ((ay >> 2) - (by >> 2)) - - (ay / 100 - by / 100) - + ((ay / 100 >> 2) - (by / 100 >> 2)) - /* + difference in years * 365 */ - + (long) (ay - by) * 365l); + /* difference in day of year */ + a->tm_yday - b->tm_yday + /* + intervening leap days */ + + ((ay >> 2) - (by >> 2)) + - (ay / 100 - by / 100) + + ((ay / 100 >> 2) - (by / 100 >> 2)) + /* + difference in years * 365 */ + + (long) (ay - by) * 365l); return 60l * (60l * (24l * days + (a->tm_hour - b->tm_hour)) - + (a->tm_min - b->tm_min)) - + (a->tm_sec - b->tm_sec); + + (a->tm_min - b->tm_min)) + + (a->tm_sec - b->tm_sec); } @@ -66,10 +66,10 @@ po_strftime (const time_t *tp) tz_sign = '-'; } return xasprintf ("%d-%02d-%02d %02d:%02d%c%02ld%02ld", - local_time.tm_year + TM_YEAR_ORIGIN, - local_time.tm_mon + 1, - local_time.tm_mday, - local_time.tm_hour, - local_time.tm_min, - tz_sign, tz_min / 60, tz_min % 60); + local_time.tm_year + TM_YEAR_ORIGIN, + local_time.tm_mon + 1, + local_time.tm_mday, + local_time.tm_hour, + local_time.tm_min, + tz_sign, tz_min / 60, tz_min % 60); } diff --git a/gettext-tools/src/po-xerror.c b/gettext-tools/src/po-xerror.c index 0e84e9011..3456484d6 100644 --- a/gettext-tools/src/po-xerror.c +++ b/gettext-tools/src/po-xerror.c @@ -41,8 +41,8 @@ static void xerror (int severity, const char *prefix_tail, - const char *filename, size_t lineno, size_t column, - int multiline_p, const char *message_text) + const char *filename, size_t lineno, size_t column, + int multiline_p, const char *message_text) { if (multiline_p) { @@ -50,61 +50,61 @@ xerror (int severity, const char *prefix_tail, char *prefix; if (filename != NULL) - { - if (lineno != (size_t)(-1)) - { - if (column != (size_t)(-1)) - prefix = - xasprintf ("%s:%ld:%ld: %s", filename, - (long) lineno, (long) column, prefix_tail); - else - prefix = - xasprintf ("%s:%ld: %s", filename, - (long) lineno, prefix_tail); - } - else - prefix = xasprintf ("%s: %s", filename, prefix_tail); - error_with_progname = false; - } + { + if (lineno != (size_t)(-1)) + { + if (column != (size_t)(-1)) + prefix = + xasprintf ("%s:%ld:%ld: %s", filename, + (long) lineno, (long) column, prefix_tail); + else + prefix = + xasprintf ("%s:%ld: %s", filename, + (long) lineno, prefix_tail); + } + else + prefix = xasprintf ("%s: %s", filename, prefix_tail); + error_with_progname = false; + } else - prefix = xasprintf ("%s: %s", program_name, prefix_tail); + prefix = xasprintf ("%s: %s", program_name, prefix_tail); if (severity >= PO_SEVERITY_ERROR) - po_multiline_error (prefix, xstrdup (message_text)); + po_multiline_error (prefix, xstrdup (message_text)); else - po_multiline_warning (prefix, xstrdup (message_text)); + po_multiline_warning (prefix, xstrdup (message_text)); error_with_progname = old_error_with_progname; if (severity == PO_SEVERITY_FATAL_ERROR) - exit (EXIT_FAILURE); + exit (EXIT_FAILURE); } else { int exit_status = - (severity == PO_SEVERITY_FATAL_ERROR ? EXIT_FAILURE : 0); + (severity == PO_SEVERITY_FATAL_ERROR ? EXIT_FAILURE : 0); if (filename != NULL) - { - error_with_progname = false; - if (lineno != (size_t)(-1)) - { - if (column != (size_t)(-1)) - po_error (exit_status, 0, "%s:%ld:%ld: %s%s", - filename, (long) lineno, (long) column, - prefix_tail, message_text); - else - po_error_at_line (exit_status, 0, filename, lineno, "%s%s", - prefix_tail, message_text); - } - else - po_error (exit_status, 0, "%s: %s%s", - filename, prefix_tail, message_text); - error_with_progname = true; - } + { + error_with_progname = false; + if (lineno != (size_t)(-1)) + { + if (column != (size_t)(-1)) + po_error (exit_status, 0, "%s:%ld:%ld: %s%s", + filename, (long) lineno, (long) column, + prefix_tail, message_text); + else + po_error_at_line (exit_status, 0, filename, lineno, "%s%s", + prefix_tail, message_text); + } + else + po_error (exit_status, 0, "%s: %s%s", + filename, prefix_tail, message_text); + error_with_progname = true; + } else - po_error (exit_status, 0, "%s%s", prefix_tail, message_text); + po_error (exit_status, 0, "%s%s", prefix_tail, message_text); if (severity < PO_SEVERITY_ERROR) - --error_message_count; + --error_message_count; } } @@ -113,9 +113,9 @@ xerror (int severity, const char *prefix_tail, other. */ void textmode_xerror (int severity, - const struct message_ty *message, - const char *filename, size_t lineno, size_t column, - int multiline_p, const char *message_text) + const struct message_ty *message, + const char *filename, size_t lineno, size_t column, + int multiline_p, const char *message_text) { const char *prefix_tail = (severity == PO_SEVERITY_WARNING ? _("warning: ") : ""); @@ -128,17 +128,17 @@ textmode_xerror (int severity, } xerror (severity, prefix_tail, filename, lineno, column, - multiline_p, message_text); + multiline_p, message_text); } void textmode_xerror2 (int severity, - const struct message_ty *message1, - const char *filename1, size_t lineno1, size_t column1, - int multiline_p1, const char *message_text1, - const struct message_ty *message2, - const char *filename2, size_t lineno2, size_t column2, - int multiline_p2, const char *message_text2) + const struct message_ty *message1, + const char *filename1, size_t lineno1, size_t column1, + int multiline_p1, const char *message_text1, + const struct message_ty *message2, + const char *filename2, size_t lineno2, size_t column2, + int multiline_p2, const char *message_text2) { int severity1 = /* Don't exit before both texts have been output. */ (severity == PO_SEVERITY_FATAL_ERROR ? PO_SEVERITY_ERROR : severity); @@ -161,19 +161,19 @@ textmode_xerror2 (int severity, if (multiline_p1) xerror (severity1, prefix_tail, filename1, lineno1, column1, multiline_p1, - message_text1); + message_text1); else { char *message_text1_extended = xasprintf ("%s...", message_text1); xerror (severity1, prefix_tail, filename1, lineno1, column1, - multiline_p1, message_text1_extended); + multiline_p1, message_text1_extended); free (message_text1_extended); } { char *message_text2_extended = xasprintf ("...%s", message_text2); xerror (severity, prefix_tail, filename2, lineno2, column2, - multiline_p2, message_text2_extended); + multiline_p2, message_text2_extended); free (message_text2_extended); } @@ -183,16 +183,16 @@ textmode_xerror2 (int severity, } void (*po_xerror) (int severity, - const struct message_ty *message, - const char *filename, size_t lineno, size_t column, - int multiline_p, const char *message_text) + const struct message_ty *message, + const char *filename, size_t lineno, size_t column, + int multiline_p, const char *message_text) = textmode_xerror; void (*po_xerror2) (int severity, - const struct message_ty *message1, - const char *filename1, size_t lineno1, size_t column1, - int multiline_p1, const char *message_text1, - const struct message_ty *message2, - const char *filename2, size_t lineno2, size_t column2, - int multiline_p2, const char *message_text2) + const struct message_ty *message1, + const char *filename1, size_t lineno1, size_t column1, + int multiline_p1, const char *message_text1, + const struct message_ty *message2, + const char *filename2, size_t lineno2, size_t column2, + int multiline_p2, const char *message_text2) = textmode_xerror2; diff --git a/gettext-tools/src/po-xerror.h b/gettext-tools/src/po-xerror.h index e82fdb330..521ec3f02 100644 --- a/gettext-tools/src/po-xerror.h +++ b/gettext-tools/src/po-xerror.h @@ -30,9 +30,9 @@ struct message_ty; /* A higher-level error handler than the one in po-error.h. */ /* These values must be the same as those in gettext-po.h. */ -#define PO_SEVERITY_WARNING 0 /* just a warning, tell the user */ -#define PO_SEVERITY_ERROR 1 /* an error, the operation cannot complete */ -#define PO_SEVERITY_FATAL_ERROR 2 /* an error, the operation must be aborted */ +#define PO_SEVERITY_WARNING 0 /* just a warning, tell the user */ +#define PO_SEVERITY_ERROR 1 /* an error, the operation cannot complete */ +#define PO_SEVERITY_FATAL_ERROR 2 /* an error, the operation must be aborted */ /* Signal a problem of the given severity. MESSAGE and/or FILENAME + LINENO indicate where the problem occurred. @@ -45,9 +45,9 @@ struct message_ty; Must not return if SEVERITY is PO_SEVERITY_FATAL_ERROR. */ extern DLL_VARIABLE void (*po_xerror) (int severity, - const struct message_ty *message, - const char *filename, size_t lineno, size_t column, - int multiline_p, const char *message_text); + const struct message_ty *message, + const char *filename, size_t lineno, size_t column, + int multiline_p, const char *message_text); /* Signal a problem that refers to two messages. Similar to two calls to po_xerror. @@ -55,25 +55,25 @@ extern DLL_VARIABLE MESSAGE_TEXT2. */ extern DLL_VARIABLE void (*po_xerror2) (int severity, - const struct message_ty *message1, - const char *filename1, size_t lineno1, size_t column1, - int multiline_p1, const char *message_text1, - const struct message_ty *message2, - const char *filename2, size_t lineno2, size_t column2, - int multiline_p2, const char *message_text2); + const struct message_ty *message1, + const char *filename1, size_t lineno1, size_t column1, + int multiline_p1, const char *message_text1, + const struct message_ty *message2, + const char *filename2, size_t lineno2, size_t column2, + int multiline_p2, const char *message_text2); /* The default error handler. */ extern void textmode_xerror (int severity, - const struct message_ty *message, - const char *filename, size_t lineno, size_t column, - int multiline_p, const char *message_text); + const struct message_ty *message, + const char *filename, size_t lineno, size_t column, + int multiline_p, const char *message_text); extern void textmode_xerror2 (int severity, - const struct message_ty *message1, - const char *filename1, size_t lineno1, size_t column1, - int multiline_p1, const char *message_text1, - const struct message_ty *message2, - const char *filename2, size_t lineno2, size_t column2, - int multiline_p2, const char *message_text2); + const struct message_ty *message1, + const char *filename1, size_t lineno1, size_t column1, + int multiline_p1, const char *message_text1, + const struct message_ty *message2, + const char *filename2, size_t lineno2, size_t column2, + int multiline_p2, const char *message_text2); #ifdef __cplusplus } diff --git a/gettext-tools/src/read-catalog-abstract.c b/gettext-tools/src/read-catalog-abstract.c index fd821f46c..fa932d4d3 100644 --- a/gettext-tools/src/read-catalog-abstract.c +++ b/gettext-tools/src/read-catalog-abstract.c @@ -90,25 +90,25 @@ call_directive_domain (abstract_catalog_reader_ty *pop, char *name) static inline void call_directive_message (abstract_catalog_reader_ty *pop, - char *msgctxt, - char *msgid, - lex_pos_ty *msgid_pos, - char *msgid_plural, - char *msgstr, size_t msgstr_len, - lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, - char *prev_msgid_plural, - bool force_fuzzy, bool obsolete) + char *msgctxt, + char *msgid, + lex_pos_ty *msgid_pos, + char *msgid_plural, + char *msgstr, size_t msgstr_len, + lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, + char *prev_msgid_plural, + bool force_fuzzy, bool obsolete) { if (pop->methods->directive_message) pop->methods->directive_message (pop, msgctxt, - msgid, msgid_pos, msgid_plural, - msgstr, msgstr_len, msgstr_pos, - prev_msgctxt, - prev_msgid, - prev_msgid_plural, - force_fuzzy, obsolete); + msgid, msgid_pos, msgid_plural, + msgstr, msgstr_len, msgstr_pos, + prev_msgctxt, + prev_msgid, + prev_msgid_plural, + force_fuzzy, obsolete); } static inline void @@ -127,7 +127,7 @@ call_comment_dot (abstract_catalog_reader_ty *pop, const char *s) static inline void call_comment_filepos (abstract_catalog_reader_ty *pop, const char *name, - size_t line) + size_t line) { if (pop->methods->comment_filepos) pop->methods->comment_filepos (pop, name, line); @@ -167,8 +167,8 @@ parse_end (abstract_catalog_reader_ty *pop) void catalog_reader_parse (abstract_catalog_reader_ty *pop, FILE *fp, - const char *real_filename, const char *logical_filename, - catalog_input_format_ty input_syntax) + const char *real_filename, const char *logical_filename, + catalog_input_format_ty input_syntax) { /* Parse the stream's content. */ parse_start (pop); @@ -177,11 +177,11 @@ catalog_reader_parse (abstract_catalog_reader_ty *pop, FILE *fp, if (error_message_count > 0) po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, - /*real_filename*/ NULL, (size_t)(-1), (size_t)(-1), false, - xasprintf (ngettext ("found %d fatal error", - "found %d fatal errors", - error_message_count), - error_message_count)); + /*real_filename*/ NULL, (size_t)(-1), (size_t)(-1), false, + xasprintf (ngettext ("found %d fatal error", + "found %d fatal errors", + error_message_count), + error_message_count)); error_message_count = 0; } @@ -205,19 +205,19 @@ po_callback_domain (char *name) seen. */ void po_callback_message (char *msgctxt, - char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural, - char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, - char *prev_msgid_plural, - bool force_fuzzy, bool obsolete) + char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural, + char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, + char *prev_msgid_plural, + bool force_fuzzy, bool obsolete) { /* assert(callback_arg); */ call_directive_message (callback_arg, msgctxt, - msgid, msgid_pos, msgid_plural, - msgstr, msgstr_len, msgstr_pos, - prev_msgctxt, prev_msgid, prev_msgid_plural, - force_fuzzy, obsolete); + msgid, msgid_pos, msgid_plural, + msgstr, msgstr_len, msgstr_pos, + prev_msgctxt, prev_msgid, prev_msgid_plural, + force_fuzzy, obsolete); } @@ -259,8 +259,8 @@ po_callback_comment_special (const char *s) *wrapp. */ void po_parse_comment_special (const char *s, - bool *fuzzyp, enum is_format formatp[NFORMATS], - struct argument_range *rangep, enum is_wrap *wrapp) + bool *fuzzyp, enum is_format formatp[NFORMATS], + struct argument_range *rangep, enum is_wrap *wrapp) { size_t i; @@ -277,135 +277,135 @@ po_parse_comment_special (const char *s, /* Skip whitespace. */ while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) != NULL) - s++; + s++; /* Collect a token. */ t = s; while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) == NULL) - s++; + s++; if (s != t) - { - size_t len = s - t; - - /* Accept fuzzy flag. */ - if (len == 5 && memcmp (t, "fuzzy", 5) == 0) - { - *fuzzyp = true; - continue; - } - - /* Accept format description. */ - if (len >= 7 && memcmp (t + len - 7, "-format", 7) == 0) - { - const char *p; - size_t n; - enum is_format value; - - p = t; - n = len - 7; - - if (n >= 3 && memcmp (p, "no-", 3) == 0) - { - p += 3; - n -= 3; - value = no; - } - else if (n >= 9 && memcmp (p, "possible-", 9) == 0) - { - p += 9; - n -= 9; - value = possible; - } - else if (n >= 11 && memcmp (p, "impossible-", 11) == 0) - { - p += 11; - n -= 11; - value = impossible; - } - else - value = yes; - - for (i = 0; i < NFORMATS; i++) - if (strlen (format_language[i]) == n - && memcmp (format_language[i], p, n) == 0) - { - formatp[i] = value; - break; - } - if (i < NFORMATS) - continue; - } - - /* Accept range description "range: ..". */ - if (len == 6 && memcmp (t, "range:", 6) == 0) - { - /* Skip whitespace. */ - while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) != NULL) - s++; - - /* Collect a token. */ - t = s; - while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) == NULL) - s++; - /* Parse it. */ - if (*t >= '0' && *t <= '9') - { - unsigned int min = 0; - - for (; *t >= '0' && *t <= '9'; t++) - { - if (min <= INT_MAX / 10) - { - min = 10 * min + (*t - '0'); - if (min > INT_MAX) - min = INT_MAX; - } - else - /* Avoid integer overflow. */ - min = INT_MAX; - } - if (*t++ == '.') - if (*t++ == '.') - if (*t >= '0' && *t <= '9') - { - unsigned int max = 0; - for (; *t >= '0' && *t <= '9'; t++) - { - if (max <= INT_MAX / 10) - { - max = 10 * max + (*t - '0'); - if (max > INT_MAX) - max = INT_MAX; - } - else - /* Avoid integer overflow. */ - max = INT_MAX; - } - if (min <= max) - { - rangep->min = min; - rangep->max = max; - continue; - } - } - } - } - - /* Accept wrap description. */ - if (len == 4 && memcmp (t, "wrap", 4) == 0) - { - *wrapp = yes; - continue; - } - if (len == 7 && memcmp (t, "no-wrap", 7) == 0) - { - *wrapp = no; - continue; - } - - /* Unknown special comment marker. It may have been generated - from a future xgettext version. Ignore it. */ - } + { + size_t len = s - t; + + /* Accept fuzzy flag. */ + if (len == 5 && memcmp (t, "fuzzy", 5) == 0) + { + *fuzzyp = true; + continue; + } + + /* Accept format description. */ + if (len >= 7 && memcmp (t + len - 7, "-format", 7) == 0) + { + const char *p; + size_t n; + enum is_format value; + + p = t; + n = len - 7; + + if (n >= 3 && memcmp (p, "no-", 3) == 0) + { + p += 3; + n -= 3; + value = no; + } + else if (n >= 9 && memcmp (p, "possible-", 9) == 0) + { + p += 9; + n -= 9; + value = possible; + } + else if (n >= 11 && memcmp (p, "impossible-", 11) == 0) + { + p += 11; + n -= 11; + value = impossible; + } + else + value = yes; + + for (i = 0; i < NFORMATS; i++) + if (strlen (format_language[i]) == n + && memcmp (format_language[i], p, n) == 0) + { + formatp[i] = value; + break; + } + if (i < NFORMATS) + continue; + } + + /* Accept range description "range: ..". */ + if (len == 6 && memcmp (t, "range:", 6) == 0) + { + /* Skip whitespace. */ + while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) != NULL) + s++; + + /* Collect a token. */ + t = s; + while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) == NULL) + s++; + /* Parse it. */ + if (*t >= '0' && *t <= '9') + { + unsigned int min = 0; + + for (; *t >= '0' && *t <= '9'; t++) + { + if (min <= INT_MAX / 10) + { + min = 10 * min + (*t - '0'); + if (min > INT_MAX) + min = INT_MAX; + } + else + /* Avoid integer overflow. */ + min = INT_MAX; + } + if (*t++ == '.') + if (*t++ == '.') + if (*t >= '0' && *t <= '9') + { + unsigned int max = 0; + for (; *t >= '0' && *t <= '9'; t++) + { + if (max <= INT_MAX / 10) + { + max = 10 * max + (*t - '0'); + if (max > INT_MAX) + max = INT_MAX; + } + else + /* Avoid integer overflow. */ + max = INT_MAX; + } + if (min <= max) + { + rangep->min = min; + rangep->max = max; + continue; + } + } + } + } + + /* Accept wrap description. */ + if (len == 4 && memcmp (t, "wrap", 4) == 0) + { + *wrapp = yes; + continue; + } + if (len == 7 && memcmp (t, "no-wrap", 7) == 0) + { + *wrapp = no; + continue; + } + + /* Unknown special comment marker. It may have been generated + from a future xgettext version. Ignore it. */ + } } } @@ -424,171 +424,171 @@ po_parse_comment_filepos (const char *s) while (*s != '\0') { while (*s == ' ' || *s == '\t' || *s == '\n') - s++; + s++; if (*s != '\0') - { - const char *string_start = s; - - do - s++; - while (!(*s == '\0' || *s == ' ' || *s == '\t' || *s == '\n')); - - /* See if there is a COLON and NUMBER after the STRING, separated - through optional spaces. */ - { - const char *p = s; - - while (*p == ' ' || *p == '\t' || *p == '\n') - p++; - - if (*p == ':') - { - p++; - - while (*p == ' ' || *p == '\t' || *p == '\n') - p++; - - if (*p >= '0' && *p <= '9') - { - /* Accumulate a number. */ - size_t n = 0; - - do - { - n = n * 10 + (*p - '0'); - p++; - } - while (*p >= '0' && *p <= '9'); - - if (*p == '\0' || *p == ' ' || *p == '\t' || *p == '\n') - { - /* Parsed a GNU style file comment with spaces. */ - const char *string_end = s; - size_t string_length = string_end - string_start; - char *string = XNMALLOC (string_length + 1, char); - - memcpy (string, string_start, string_length); - string[string_length] = '\0'; - - po_callback_comment_filepos (string, n); - - free (string); - - s = p; - continue; - } - } - } - } - - /* See if there is a COLON at the end of STRING and a NUMBER after - it, separated through optional spaces. */ - if (s[-1] == ':') - { - const char *p = s; - - while (*p == ' ' || *p == '\t' || *p == '\n') - p++; - - if (*p >= '0' && *p <= '9') - { - /* Accumulate a number. */ - size_t n = 0; - - do - { - n = n * 10 + (*p - '0'); - p++; - } - while (*p >= '0' && *p <= '9'); - - if (*p == '\0' || *p == ' ' || *p == '\t' || *p == '\n') - { - /* Parsed a GNU style file comment with spaces. */ - const char *string_end = s - 1; - size_t string_length = string_end - string_start; - char *string = XNMALLOC (string_length + 1, char); - - memcpy (string, string_start, string_length); - string[string_length] = '\0'; - - po_callback_comment_filepos (string, n); - - free (string); - - s = p; - continue; - } - } - } - - /* See if there is a COLON and NUMBER at the end of the STRING, - without separating spaces. */ - { - const char *p = s; - - while (p > string_start) - { - p--; - if (!(*p >= '0' && *p <= '9')) - { - p++; - break; - } - } - - /* p now points to the beginning of the trailing digits segment - at the end of STRING. */ - - if (p < s - && p > string_start + 1 - && p[-1] == ':') - { - /* Parsed a GNU style file comment without spaces. */ - const char *string_end = p - 1; - - /* Accumulate a number. */ - { - size_t n = 0; - - do - { - n = n * 10 + (*p - '0'); - p++; - } - while (p < s); - - { - size_t string_length = string_end - string_start; - char *string = XNMALLOC (string_length + 1, char); - - memcpy (string, string_start, string_length); - string[string_length] = '\0'; - - po_callback_comment_filepos (string, n); - - free (string); - - continue; - } - } - } - } - - /* Parsed a file comment without line number. */ - { - const char *string_end = s; - size_t string_length = string_end - string_start; - char *string = XNMALLOC (string_length + 1, char); - - memcpy (string, string_start, string_length); - string[string_length] = '\0'; - - po_callback_comment_filepos (string, (size_t)(-1)); - - free (string); - } - } + { + const char *string_start = s; + + do + s++; + while (!(*s == '\0' || *s == ' ' || *s == '\t' || *s == '\n')); + + /* See if there is a COLON and NUMBER after the STRING, separated + through optional spaces. */ + { + const char *p = s; + + while (*p == ' ' || *p == '\t' || *p == '\n') + p++; + + if (*p == ':') + { + p++; + + while (*p == ' ' || *p == '\t' || *p == '\n') + p++; + + if (*p >= '0' && *p <= '9') + { + /* Accumulate a number. */ + size_t n = 0; + + do + { + n = n * 10 + (*p - '0'); + p++; + } + while (*p >= '0' && *p <= '9'); + + if (*p == '\0' || *p == ' ' || *p == '\t' || *p == '\n') + { + /* Parsed a GNU style file comment with spaces. */ + const char *string_end = s; + size_t string_length = string_end - string_start; + char *string = XNMALLOC (string_length + 1, char); + + memcpy (string, string_start, string_length); + string[string_length] = '\0'; + + po_callback_comment_filepos (string, n); + + free (string); + + s = p; + continue; + } + } + } + } + + /* See if there is a COLON at the end of STRING and a NUMBER after + it, separated through optional spaces. */ + if (s[-1] == ':') + { + const char *p = s; + + while (*p == ' ' || *p == '\t' || *p == '\n') + p++; + + if (*p >= '0' && *p <= '9') + { + /* Accumulate a number. */ + size_t n = 0; + + do + { + n = n * 10 + (*p - '0'); + p++; + } + while (*p >= '0' && *p <= '9'); + + if (*p == '\0' || *p == ' ' || *p == '\t' || *p == '\n') + { + /* Parsed a GNU style file comment with spaces. */ + const char *string_end = s - 1; + size_t string_length = string_end - string_start; + char *string = XNMALLOC (string_length + 1, char); + + memcpy (string, string_start, string_length); + string[string_length] = '\0'; + + po_callback_comment_filepos (string, n); + + free (string); + + s = p; + continue; + } + } + } + + /* See if there is a COLON and NUMBER at the end of the STRING, + without separating spaces. */ + { + const char *p = s; + + while (p > string_start) + { + p--; + if (!(*p >= '0' && *p <= '9')) + { + p++; + break; + } + } + + /* p now points to the beginning of the trailing digits segment + at the end of STRING. */ + + if (p < s + && p > string_start + 1 + && p[-1] == ':') + { + /* Parsed a GNU style file comment without spaces. */ + const char *string_end = p - 1; + + /* Accumulate a number. */ + { + size_t n = 0; + + do + { + n = n * 10 + (*p - '0'); + p++; + } + while (p < s); + + { + size_t string_length = string_end - string_start; + char *string = XNMALLOC (string_length + 1, char); + + memcpy (string, string_start, string_length); + string[string_length] = '\0'; + + po_callback_comment_filepos (string, n); + + free (string); + + continue; + } + } + } + } + + /* Parsed a file comment without line number. */ + { + const char *string_end = s; + size_t string_length = string_end - string_start; + char *string = XNMALLOC (string_length + 1, char); + + memcpy (string, string_start, string_length); + string[string_length] = '\0'; + + po_callback_comment_filepos (string, (size_t)(-1)); + + free (string); + } + } } } @@ -618,81 +618,81 @@ po_parse_comment_solaris_filepos (const char *s) const char *string_end; { - const char *p = s + 6; + const char *p = s + 6; - while (*p == ' ' || *p == '\t') - p++; - string_start = p; + while (*p == ' ' || *p == '\t') + p++; + string_start = p; } for (string_end = string_start; *string_end != '\0'; string_end++) - { - const char *p = string_end; - - while (*p == ' ' || *p == '\t') - p++; - - if (*p == ',') - { - p++; - - while (*p == ' ' || *p == '\t') - p++; - - if (p[0] == 'l' && p[1] == 'i' && p[2] == 'n' && p[3] == 'e') - { - p += 4; - - while (*p == ' ' || *p == '\t') - p++; - - if (p[0] == 'n' && p[1] == 'u' && p[2] == 'm' - && p[3] == 'b' && p[4] == 'e' && p[5] == 'r') - { - p += 6; - while (*p == ' ' || *p == '\t') - p++; - } - - if (*p == ':') - { - p++; - - if (*p >= '0' && *p <= '9') - { - /* Accumulate a number. */ - size_t n = 0; - - do - { - n = n * 10 + (*p - '0'); - p++; - } - while (*p >= '0' && *p <= '9'); - - while (*p == ' ' || *p == '\t' || *p == '\n') - p++; - - if (*p == '\0') - { - /* Parsed a Sun style file comment. */ - size_t string_length = string_end - string_start; - char *string = - XNMALLOC (string_length + 1, char); - - memcpy (string, string_start, string_length); - string[string_length] = '\0'; - - po_callback_comment_filepos (string, n); - - free (string); - return true; - } - } - } - } - } - } + { + const char *p = string_end; + + while (*p == ' ' || *p == '\t') + p++; + + if (*p == ',') + { + p++; + + while (*p == ' ' || *p == '\t') + p++; + + if (p[0] == 'l' && p[1] == 'i' && p[2] == 'n' && p[3] == 'e') + { + p += 4; + + while (*p == ' ' || *p == '\t') + p++; + + if (p[0] == 'n' && p[1] == 'u' && p[2] == 'm' + && p[3] == 'b' && p[4] == 'e' && p[5] == 'r') + { + p += 6; + while (*p == ' ' || *p == '\t') + p++; + } + + if (*p == ':') + { + p++; + + if (*p >= '0' && *p <= '9') + { + /* Accumulate a number. */ + size_t n = 0; + + do + { + n = n * 10 + (*p - '0'); + p++; + } + while (*p >= '0' && *p <= '9'); + + while (*p == ' ' || *p == '\t' || *p == '\n') + p++; + + if (*p == '\0') + { + /* Parsed a Sun style file comment. */ + size_t string_length = string_end - string_start; + char *string = + XNMALLOC (string_length + 1, char); + + memcpy (string, string_start, string_length); + string[string_length] = '\0'; + + po_callback_comment_filepos (string, n); + + free (string); + return true; + } + } + } + } + } + } } return false; @@ -711,15 +711,15 @@ po_callback_comment_dispatcher (const char *s) { s++; /* There is usually a space before the comment. People don't - consider it part of the comment, therefore remove it here. */ + consider it part of the comment, therefore remove it here. */ if (*s == ' ') - s++; + s++; po_callback_comment_dot (s); } else if (*s == ':') { /* Parse the file location string. The appropriate callback will be - invoked. */ + invoked. */ po_parse_comment_filepos (s + 1); } else if (*s == ',' || *s == '!') @@ -730,17 +730,17 @@ po_callback_comment_dispatcher (const char *s) else { /* It looks like a plain vanilla comment, but Solaris-style file - position lines do, too. Try to parse the lot. If the parse - succeeds, the appropriate callback will be invoked. */ + position lines do, too. Try to parse the lot. If the parse + succeeds, the appropriate callback will be invoked. */ if (po_parse_comment_solaris_filepos (s)) - /* Do nothing, it is a Sun-style file pos line. */ ; + /* Do nothing, it is a Sun-style file pos line. */ ; else - { - /* There is usually a space before the comment. People don't - consider it part of the comment, therefore remove it here. */ - if (*s == ' ') - s++; - po_callback_comment (s); - } + { + /* There is usually a space before the comment. People don't + consider it part of the comment, therefore remove it here. */ + if (*s == ' ') + s++; + po_callback_comment (s); + } } } diff --git a/gettext-tools/src/read-catalog-abstract.h b/gettext-tools/src/read-catalog-abstract.h index 284746349..318fa68e7 100644 --- a/gettext-tools/src/read-catalog-abstract.h +++ b/gettext-tools/src/read-catalog-abstract.h @@ -75,14 +75,14 @@ struct abstract_catalog_reader_class_ty /* what to do with a message directive */ void (*directive_message) (struct abstract_catalog_reader_ty *pop, - char *msgctxt, - char *msgid, lex_pos_ty *msgid_pos, - char *msgid_plural, - char *msgstr, size_t msgstr_len, - lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, char *prev_msgid_plural, - bool force_fuzzy, bool obsolete); + char *msgctxt, + char *msgid, lex_pos_ty *msgid_pos, + char *msgid_plural, + char *msgstr, size_t msgstr_len, + lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, char *prev_msgid_plural, + bool force_fuzzy, bool obsolete); /* What to do with a plain-vanilla comment - the expectation is that they will be accumulated, and added to the next message @@ -100,13 +100,13 @@ struct abstract_catalog_reader_class_ty they will be accumulated, and added to the next message definition seen. Or completely ignored. */ void (*comment_filepos) (struct abstract_catalog_reader_ty *pop, - const char *s, size_t line); + const char *s, size_t line); /* What to do with a comment that starts with a ',' or '!' - this is a special comment. One of the possible uses is to indicate a inexact translation. */ void (*comment_special) (struct abstract_catalog_reader_ty *pop, - const char *s); + const char *s); }; @@ -133,7 +133,7 @@ struct catalog_input_format { /* Parses the contents of FP, invoking the appropriate callbacks. */ void (*parse) (abstract_catalog_reader_ty *pop, FILE *fp, - const char *real_filename, const char *logical_filename); + const char *real_filename, const char *logical_filename); /* Whether the parse function always produces messages encoded in UTF-8 encoding. */ @@ -152,9 +152,9 @@ extern abstract_catalog_reader_ty * abstract_catalog_reader_class_ty methods. */ extern void catalog_reader_parse (abstract_catalog_reader_ty *pop, FILE *fp, - const char *real_filename, - const char *logical_filename, - catalog_input_format_ty input_syntax); + const char *real_filename, + const char *logical_filename, + catalog_input_format_ty input_syntax); /* Call the destructor and deallocate a abstract_catalog_reader_ty (or derived class) instance. */ @@ -166,13 +166,13 @@ extern void catalog_reader_parse. */ extern void po_callback_domain (char *name); extern void po_callback_message (char *msgctxt, - char *msgid, lex_pos_ty *msgid_pos, - char *msgid_plural, - char *msgstr, size_t msgstr_len, - lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, char *prev_msgid_plural, - bool force_fuzzy, bool obsolete); + char *msgid, lex_pos_ty *msgid_pos, + char *msgid_plural, + char *msgstr, size_t msgstr_len, + lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, char *prev_msgid_plural, + bool force_fuzzy, bool obsolete); extern void po_callback_comment (const char *s); extern void po_callback_comment_dot (const char *s); extern void po_callback_comment_filepos (const char *s, size_t line); @@ -182,9 +182,9 @@ extern void po_callback_comment_dispatcher (const char *s); /* Parse a special comment and put the result in *fuzzyp, formatp, *rangep, *wrapp. */ extern void po_parse_comment_special (const char *s, bool *fuzzyp, - enum is_format formatp[NFORMATS], - struct argument_range *rangep, - enum is_wrap *wrapp); + enum is_format formatp[NFORMATS], + struct argument_range *rangep, + enum is_wrap *wrapp); #ifdef __cplusplus diff --git a/gettext-tools/src/read-catalog.c b/gettext-tools/src/read-catalog.c index ee54345c3..51e96e88e 100644 --- a/gettext-tools/src/read-catalog.c +++ b/gettext-tools/src/read-catalog.c @@ -50,27 +50,27 @@ call_set_domain (struct default_catalog_reader_ty *this, char *name) static inline void call_add_message (struct default_catalog_reader_ty *this, - char *msgctxt, - char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural, - char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos, - char *prev_msgctxt, char *prev_msgid, char *prev_msgid_plural, - bool force_fuzzy, bool obsolete) + char *msgctxt, + char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural, + char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos, + char *prev_msgctxt, char *prev_msgid, char *prev_msgid_plural, + bool force_fuzzy, bool obsolete) { default_catalog_reader_class_ty *methods = (default_catalog_reader_class_ty *) this->methods; if (methods->add_message) methods->add_message (this, msgctxt, - msgid, msgid_pos, msgid_plural, - msgstr, msgstr_len, msgstr_pos, - prev_msgctxt, prev_msgid, prev_msgid_plural, - force_fuzzy, obsolete); + msgid, msgid_pos, msgid_plural, + msgstr, msgstr_len, msgstr_pos, + prev_msgctxt, prev_msgid, prev_msgid_plural, + force_fuzzy, obsolete); } static inline void call_frob_new_message (struct default_catalog_reader_ty *this, message_ty *mp, - const lex_pos_ty *msgid_pos, - const lex_pos_ty *msgstr_pos) + const lex_pos_ty *msgid_pos, + const lex_pos_ty *msgstr_pos) { default_catalog_reader_class_ty *methods = (default_catalog_reader_class_ty *) this->methods; @@ -117,18 +117,18 @@ default_destructor (abstract_catalog_reader_ty *that) if (this->handle_comments) { if (this->comment != NULL) - string_list_free (this->comment); + string_list_free (this->comment); if (this->comment_dot != NULL) - string_list_free (this->comment_dot); + string_list_free (this->comment_dot); } if (this->handle_filepos_comments) { size_t j; for (j = 0; j < this->filepos_count; ++j) - free (this->filepos[j].file_name); + free (this->filepos[j].file_name); if (this->filepos != NULL) - free (this->filepos); + free (this->filepos); } } @@ -158,21 +158,21 @@ default_copy_comment_state (default_catalog_reader_ty *this, message_ty *mp) if (this->handle_comments) { if (this->comment != NULL) - for (j = 0; j < this->comment->nitems; ++j) - message_comment_append (mp, this->comment->item[j]); + for (j = 0; j < this->comment->nitems; ++j) + message_comment_append (mp, this->comment->item[j]); if (this->comment_dot != NULL) - for (j = 0; j < this->comment_dot->nitems; ++j) - message_comment_dot_append (mp, this->comment_dot->item[j]); + for (j = 0; j < this->comment_dot->nitems; ++j) + message_comment_dot_append (mp, this->comment_dot->item[j]); } if (this->handle_filepos_comments) { for (j = 0; j < this->filepos_count; ++j) - { - lex_pos_ty *pp; + { + lex_pos_ty *pp; - pp = &this->filepos[j]; - message_comment_filepos (mp, pp->file_name, pp->line_number); - } + pp = &this->filepos[j]; + message_comment_filepos (mp, pp->file_name, pp->line_number); + } } mp->is_fuzzy = this->is_fuzzy; for (i = 0; i < NFORMATS; i++) @@ -190,22 +190,22 @@ default_reset_comment_state (default_catalog_reader_ty *this) if (this->handle_comments) { if (this->comment != NULL) - { - string_list_free (this->comment); - this->comment = NULL; - } + { + string_list_free (this->comment); + this->comment = NULL; + } if (this->comment_dot != NULL) - { - string_list_free (this->comment_dot); - this->comment_dot = NULL; - } + { + string_list_free (this->comment_dot); + this->comment_dot = NULL; + } } if (this->handle_filepos_comments) { for (j = 0; j < this->filepos_count; ++j) - free (this->filepos[j].file_name); + free (this->filepos[j].file_name); if (this->filepos != NULL) - free (this->filepos); + free (this->filepos); this->filepos_count = 0; this->filepos = NULL; } @@ -236,22 +236,22 @@ default_directive_domain (abstract_catalog_reader_ty *that, char *name) /* Process ['msgctxt'/]'msgid'/'msgstr' pair from .po file. */ void default_directive_message (abstract_catalog_reader_ty *that, - char *msgctxt, - char *msgid, - lex_pos_ty *msgid_pos, - char *msgid_plural, - char *msgstr, size_t msgstr_len, - lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, char *prev_msgid_plural, - bool force_fuzzy, bool obsolete) + char *msgctxt, + char *msgid, + lex_pos_ty *msgid_pos, + char *msgid_plural, + char *msgstr, size_t msgstr_len, + lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, char *prev_msgid_plural, + bool force_fuzzy, bool obsolete) { default_catalog_reader_ty *this = (default_catalog_reader_ty *) that; call_add_message (this, msgctxt, msgid, msgid_pos, msgid_plural, - msgstr, msgstr_len, msgstr_pos, - prev_msgctxt, prev_msgid, prev_msgid_plural, - force_fuzzy, obsolete); + msgstr, msgstr_len, msgstr_pos, + prev_msgctxt, prev_msgid, prev_msgid_plural, + force_fuzzy, obsolete); /* Prepare for next message. */ default_reset_comment_state (this); @@ -266,7 +266,7 @@ default_comment (abstract_catalog_reader_ty *that, const char *s) if (this->handle_comments) { if (this->comment == NULL) - this->comment = string_list_alloc (); + this->comment = string_list_alloc (); string_list_append (this->comment, s); } } @@ -280,7 +280,7 @@ default_comment_dot (abstract_catalog_reader_ty *that, const char *s) if (this->handle_comments) { if (this->comment_dot == NULL) - this->comment_dot = string_list_alloc (); + this->comment_dot = string_list_alloc (); string_list_append (this->comment_dot, s); } } @@ -288,7 +288,7 @@ default_comment_dot (abstract_catalog_reader_ty *that, const char *s) void default_comment_filepos (abstract_catalog_reader_ty *that, - const char *name, size_t line) + const char *name, size_t line) { default_catalog_reader_ty *this = (default_catalog_reader_ty *) that; @@ -313,7 +313,7 @@ default_comment_special (abstract_catalog_reader_ty *that, const char *s) default_catalog_reader_ty *this = (default_catalog_reader_ty *) that; po_parse_comment_special (s, &this->is_fuzzy, this->is_format, &this->range, - &this->do_wrap); + &this->do_wrap); } @@ -329,7 +329,7 @@ default_set_domain (default_catalog_reader_ty *this, char *name) else { po_gram_error_at_line (&gram_pos, - _("this file may not contain domain directives")); + _("this file may not contain domain directives")); /* NAME was allocated in po-gram-gen.y but is not used anywhere. */ free (name); @@ -338,16 +338,16 @@ default_set_domain (default_catalog_reader_ty *this, char *name) void default_add_message (default_catalog_reader_ty *this, - char *msgctxt, - char *msgid, - lex_pos_ty *msgid_pos, - char *msgid_plural, - char *msgstr, size_t msgstr_len, - lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, - char *prev_msgid_plural, - bool force_fuzzy, bool obsolete) + char *msgctxt, + char *msgid, + lex_pos_ty *msgid_pos, + char *msgid_plural, + char *msgstr, size_t msgstr_len, + lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, + char *prev_msgid_plural, + bool force_fuzzy, bool obsolete) { message_ty *mp; @@ -365,33 +365,33 @@ default_add_message (default_catalog_reader_ty *this, if (mp) { if (!(this->allow_duplicates_if_same_msgstr - && msgstr_len == mp->msgstr_len - && memcmp (msgstr, mp->msgstr, msgstr_len) == 0)) - { - /* We give a fatal error about this, regardless whether the - translations are equal or different. This is for consistency - with msgmerge, msgcat and others. The user can use the - msguniq program to get rid of duplicates. */ - po_xerror2 (PO_SEVERITY_ERROR, - NULL, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, _("duplicate message definition"), - mp, NULL, 0, 0, false, - _("this is the location of the first definition")); - } + && msgstr_len == mp->msgstr_len + && memcmp (msgstr, mp->msgstr, msgstr_len) == 0)) + { + /* We give a fatal error about this, regardless whether the + translations are equal or different. This is for consistency + with msgmerge, msgcat and others. The user can use the + msguniq program to get rid of duplicates. */ + po_xerror2 (PO_SEVERITY_ERROR, + NULL, msgid_pos->file_name, msgid_pos->line_number, + (size_t)(-1), false, _("duplicate message definition"), + mp, NULL, 0, 0, false, + _("this is the location of the first definition")); + } /* We don't need the just constructed entries' parameter string - (allocated in po-gram-gen.y). */ + (allocated in po-gram-gen.y). */ free (msgid); if (msgid_plural != NULL) - free (msgid_plural); + free (msgid_plural); free (msgstr); if (msgctxt != NULL) - free (msgctxt); + free (msgctxt); if (prev_msgctxt != NULL) - free (prev_msgctxt); + free (prev_msgctxt); if (prev_msgid != NULL) - free (prev_msgid); + free (prev_msgid); if (prev_msgid_plural != NULL) - free (prev_msgid_plural); + free (prev_msgid_plural); /* Add the accumulated comments to the message. */ default_copy_comment_state (this, mp); @@ -399,18 +399,18 @@ default_add_message (default_catalog_reader_ty *this, else { /* Construct message to add to the list. - Obsolete message go into the list at least for duplicate checking. - It's the caller's responsibility to ignore obsolete messages when - appropriate. */ + Obsolete message go into the list at least for duplicate checking. + It's the caller's responsibility to ignore obsolete messages when + appropriate. */ mp = message_alloc (msgctxt, msgid, msgid_plural, msgstr, msgstr_len, - msgstr_pos); + msgstr_pos); mp->prev_msgctxt = prev_msgctxt; mp->prev_msgid = prev_msgid; mp->prev_msgid_plural = prev_msgid_plural; mp->obsolete = obsolete; default_copy_comment_state (this, mp); if (force_fuzzy) - mp->is_fuzzy = true; + mp->is_fuzzy = true; call_frob_new_message (this, mp, msgid_pos, msgstr_pos); @@ -470,8 +470,8 @@ bool allow_duplicates = false; msgdomain_list_ty * read_catalog_stream (FILE *fp, const char *real_filename, - const char *logical_filename, - catalog_input_format_ty input_syntax) + const char *logical_filename, + catalog_input_format_ty input_syntax) { default_catalog_reader_ty *pop; msgdomain_list_ty *mdlp; @@ -490,7 +490,7 @@ read_catalog_stream (FILE *fp, const char *real_filename, pop->mdlp->encoding = po_charset_utf8; po_lex_pass_obsolete_entries (true); catalog_reader_parse ((abstract_catalog_reader_ty *) pop, fp, real_filename, - logical_filename, input_syntax); + logical_filename, input_syntax); mdlp = pop->mdlp; catalog_reader_free ((abstract_catalog_reader_ty *) pop); return mdlp; diff --git a/gettext-tools/src/read-catalog.h b/gettext-tools/src/read-catalog.h index 64522a24f..8b7701404 100644 --- a/gettext-tools/src/read-catalog.h +++ b/gettext-tools/src/read-catalog.h @@ -55,68 +55,68 @@ struct default_catalog_reader_class_ty /* How to add a message to the list. */ void (*add_message) (struct default_catalog_reader_ty *pop, - char *msgctxt, - char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural, - char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, - char *prev_msgid_plural, - bool force_fuzzy, bool obsolete); + char *msgctxt, + char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural, + char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, + char *prev_msgid_plural, + bool force_fuzzy, bool obsolete); /* How to modify a new message before adding it to the list. */ void (*frob_new_message) (struct default_catalog_reader_ty *pop, - message_ty *mp, - const lex_pos_ty *msgid_pos, - const lex_pos_ty *msgstr_pos); + message_ty *mp, + const lex_pos_ty *msgid_pos, + const lex_pos_ty *msgstr_pos); }; #define DEFAULT_CATALOG_READER_TY \ - ABSTRACT_CATALOG_READER_TY \ - \ - /* If true, pay attention to comments and filepos comments. */ \ - bool handle_comments; \ - \ - /* If true, remember comments for file name and line number for each \ - msgid, if present in the reference input. */ \ - bool handle_filepos_comments; \ - \ - /* If false, domain directives lead to an error messsage. */ \ - bool allow_domain_directives; \ - \ - /* If false, duplicate msgids in the same domain and file generate an \ - error. If true, such msgids are allowed; the caller should treat \ - them appropriately. */ \ - bool allow_duplicates; \ - \ - /* If true, allow duplicates if they have the same translation. */ \ - bool allow_duplicates_if_same_msgstr; \ - \ - /* File name used in error messages. */ \ - const char *file_name; \ - \ - /* List of messages already appeared in the current file. */ \ - msgdomain_list_ty *mdlp; \ - \ - /* Name of domain we are currently examining. */ \ - const char *domain; \ - \ - /* List of messages belonging to the current domain. */ \ - message_list_ty *mlp; \ - \ - /* Accumulate comments for next message directive. */ \ - string_list_ty *comment; \ - string_list_ty *comment_dot; \ - \ - /* Accumulate filepos comments for the next message directive. */ \ - size_t filepos_count; \ - lex_pos_ty *filepos; \ - \ - /* Flags transported in special comments. */ \ - bool is_fuzzy; \ - enum is_format is_format[NFORMATS]; \ - struct argument_range range; \ - enum is_wrap do_wrap; \ + ABSTRACT_CATALOG_READER_TY \ + \ + /* If true, pay attention to comments and filepos comments. */ \ + bool handle_comments; \ + \ + /* If true, remember comments for file name and line number for each \ + msgid, if present in the reference input. */ \ + bool handle_filepos_comments; \ + \ + /* If false, domain directives lead to an error messsage. */ \ + bool allow_domain_directives; \ + \ + /* If false, duplicate msgids in the same domain and file generate an \ + error. If true, such msgids are allowed; the caller should treat \ + them appropriately. */ \ + bool allow_duplicates; \ + \ + /* If true, allow duplicates if they have the same translation. */ \ + bool allow_duplicates_if_same_msgstr; \ + \ + /* File name used in error messages. */ \ + const char *file_name; \ + \ + /* List of messages already appeared in the current file. */ \ + msgdomain_list_ty *mdlp; \ + \ + /* Name of domain we are currently examining. */ \ + const char *domain; \ + \ + /* List of messages belonging to the current domain. */ \ + message_list_ty *mlp; \ + \ + /* Accumulate comments for next message directive. */ \ + string_list_ty *comment; \ + string_list_ty *comment_dot; \ + \ + /* Accumulate filepos comments for the next message directive. */ \ + size_t filepos_count; \ + lex_pos_ty *filepos; \ + \ + /* Flags transported in special comments. */ \ + bool is_fuzzy; \ + enum is_format is_format[NFORMATS]; \ + struct argument_range range; \ + enum is_wrap do_wrap; \ typedef struct default_catalog_reader_ty default_catalog_reader_ty; struct default_catalog_reader_ty @@ -129,37 +129,37 @@ extern void default_destructor (abstract_catalog_reader_ty *that); extern void default_parse_brief (abstract_catalog_reader_ty *that); extern void default_parse_debrief (abstract_catalog_reader_ty *that); extern void default_directive_domain (abstract_catalog_reader_ty *that, - char *name); + char *name); extern void default_directive_message (abstract_catalog_reader_ty *that, - char *msgctxt, - char *msgid, - lex_pos_ty *msgid_pos, - char *msgid_plural, - char *msgstr, size_t msgstr_len, - lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, - char *prev_msgid_plural, - bool force_fuzzy, bool obsolete); + char *msgctxt, + char *msgid, + lex_pos_ty *msgid_pos, + char *msgid_plural, + char *msgstr, size_t msgstr_len, + lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, + char *prev_msgid_plural, + bool force_fuzzy, bool obsolete); extern void default_comment (abstract_catalog_reader_ty *that, const char *s); extern void default_comment_dot (abstract_catalog_reader_ty *that, - const char *s); + const char *s); extern void default_comment_filepos (abstract_catalog_reader_ty *that, - const char *name, size_t line); + const char *name, size_t line); extern void default_comment_special (abstract_catalog_reader_ty *that, - const char *s); + const char *s); extern void default_set_domain (default_catalog_reader_ty *this, char *name); extern void default_add_message (default_catalog_reader_ty *this, - char *msgctxt, - char *msgid, - lex_pos_ty *msgid_pos, - char *msgid_plural, - char *msgstr, size_t msgstr_len, - lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, - char *prev_msgid_plural, - bool force_fuzzy, bool obsolete); + char *msgctxt, + char *msgid, + lex_pos_ty *msgid_pos, + char *msgid_plural, + char *msgstr, size_t msgstr_len, + lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, + char *prev_msgid_plural, + bool force_fuzzy, bool obsolete); /* Allocate a fresh default_catalog_reader_ty (or derived class) instance and call its constructor. */ @@ -179,9 +179,9 @@ extern DLL_VARIABLE bool allow_duplicates; /* Read the input file from a stream. Returns a list of messages. */ extern msgdomain_list_ty * read_catalog_stream (FILE *fp, - const char *real_filename, - const char *logical_filename, - catalog_input_format_ty input_syntax); + const char *real_filename, + const char *logical_filename, + catalog_input_format_ty input_syntax); /* Read the input file with the name INPUT_NAME. The ending .po is added if necessary. If INPUT_NAME is not an absolute file name and the file is @@ -189,7 +189,7 @@ extern msgdomain_list_ty * a list of messages. */ extern msgdomain_list_ty * read_catalog_file (const char *input_name, - catalog_input_format_ty input_syntax); + catalog_input_format_ty input_syntax); #ifdef __cplusplus diff --git a/gettext-tools/src/read-csharp.c b/gettext-tools/src/read-csharp.c index e79c7c777..e06bcba50 100644 --- a/gettext-tools/src/read-csharp.c +++ b/gettext-tools/src/read-csharp.c @@ -54,8 +54,8 @@ struct locals static bool execute_and_read_po_output (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data) + const char *prog_path, char **prog_argv, + void *private_data) { struct locals *l = (struct locals *) private_data; pid_t child; @@ -65,7 +65,7 @@ execute_and_read_po_output (const char *progname, /* Open a pipe to the C# execution engine. */ child = create_pipe_in (progname, prog_path, prog_argv, DEV_NULL, false, - true, true, fd); + true, true, fd); fp = fdopen (fd[0], "r"); if (fp == NULL) @@ -81,7 +81,7 @@ execute_and_read_po_output (const char *progname, wait_subprocess (child, progname, false, false, true, true, NULL); if (exitstatus != 0) error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"), - progname, exitstatus); + progname, exitstatus); return false; } @@ -89,7 +89,7 @@ execute_and_read_po_output (const char *progname, msgdomain_list_ty * msgdomain_read_csharp (const char *resource_name, const char *locale_name, - const char *directory) + const char *directory) { char *culture_name; const char *args[4]; @@ -109,26 +109,26 @@ msgdomain_read_csharp (const char *resource_name, const char *locale_name, char *p; for (p = culture_name; *p != '\0'; p++) if (*p == '_') - *p = '-'; + *p = '-'; if (strncmp (culture_name, "sr-CS", 5) == 0) memcpy (culture_name, "sr-SP", 5); p = strchr (culture_name, '@'); if (p != NULL) { - if (strcmp (p, "@latin") == 0) - strcpy (p, "-Latn"); - else if (strcmp (p, "@cyrillic") == 0) - strcpy (p, "-Cyrl"); + if (strcmp (p, "@latin") == 0) + strcpy (p, "-Latn"); + else if (strcmp (p, "@cyrillic") == 0) + strcpy (p, "-Cyrl"); } if (strcmp (culture_name, "sr-SP") == 0) { - free (culture_name); - culture_name = xstrdup ("sr-SP-Latn"); + free (culture_name); + culture_name = xstrdup ("sr-SP-Latn"); } else if (strcmp (culture_name, "uz-UZ") == 0) { - free (culture_name); - culture_name = xstrdup ("uz-UZ-Latn"); + free (culture_name); + culture_name = xstrdup ("uz-UZ-Latn"); } } @@ -155,9 +155,9 @@ msgdomain_read_csharp (const char *resource_name, const char *locale_name, xconcatenated_filename (gettextexedir, "msgunfmt.net", ".exe"); libdirs[0] = gettextlibdir; if (execute_csharp_program (assembly_path, libdirs, 1, - args, - verbose, false, - execute_and_read_po_output, &locals)) + args, + verbose, false, + execute_and_read_po_output, &locals)) /* An error message should already have been provided. */ exit (EXIT_FAILURE); diff --git a/gettext-tools/src/read-csharp.h b/gettext-tools/src/read-csharp.h index 5935ad224..f8b66b35f 100644 --- a/gettext-tools/src/read-csharp.h +++ b/gettext-tools/src/read-csharp.h @@ -24,7 +24,7 @@ Returns a list of messages. */ extern msgdomain_list_ty * msgdomain_read_csharp (const char *resource_name, - const char *locale_name, - const char *directory); + const char *locale_name, + const char *directory); #endif /* _READ_CSHARP_H */ diff --git a/gettext-tools/src/read-java.c b/gettext-tools/src/read-java.c index c43910b99..68a759e0e 100644 --- a/gettext-tools/src/read-java.c +++ b/gettext-tools/src/read-java.c @@ -52,8 +52,8 @@ struct locals static bool execute_and_read_po_output (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data) + const char *prog_path, char **prog_argv, + void *private_data) { struct locals *l = (struct locals *) private_data; pid_t child; @@ -63,7 +63,7 @@ execute_and_read_po_output (const char *progname, /* Open a pipe to the JVM. */ child = create_pipe_in (progname, prog_path, prog_argv, DEV_NULL, false, - true, true, fd); + true, true, fd); fp = fdopen (fd[0], "r"); if (fp == NULL) @@ -79,7 +79,7 @@ execute_and_read_po_output (const char *progname, wait_subprocess (child, progname, false, false, true, true, NULL); if (exitstatus != 0) error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"), - progname, exitstatus); + progname, exitstatus); return false; } @@ -128,9 +128,9 @@ msgdomain_read_java (const char *resource_name, const char *locale_name) Here we use the user's CLASSPATH, not a minimal one, so that the resource can be found. */ if (execute_java_class (class_name, &gettextjar, 1, false, gettextjexedir, - args, - verbose, false, - execute_and_read_po_output, &locals)) + args, + verbose, false, + execute_and_read_po_output, &locals)) /* An error message should already have been provided. */ exit (EXIT_FAILURE); diff --git a/gettext-tools/src/read-java.h b/gettext-tools/src/read-java.h index 1afdacf37..6b4d03751 100644 --- a/gettext-tools/src/read-java.h +++ b/gettext-tools/src/read-java.h @@ -24,6 +24,6 @@ Returns a list of messages. */ extern msgdomain_list_ty * msgdomain_read_java (const char *resource_name, - const char *locale_name); + const char *locale_name); #endif /* _READ_JAVA_H */ diff --git a/gettext-tools/src/read-mo.c b/gettext-tools/src/read-mo.c index 7b72493ce..9e0220ce4 100644 --- a/gettext-tools/src/read-mo.c +++ b/gettext-tools/src/read-mo.c @@ -62,7 +62,7 @@ struct binary_mo_file /* Read the contents of the given input stream. */ static void read_binary_mo_file (struct binary_mo_file *bfp, - FILE *fp, const char *filename) + FILE *fp, const char *filename) { char *buf = NULL; size_t alloc = 0; @@ -73,21 +73,21 @@ read_binary_mo_file (struct binary_mo_file *bfp, { const size_t increment = 4096; if (size + increment > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + increment) - alloc = size + increment; - buf = (char *) xrealloc (buf, alloc); - } + { + alloc = alloc + alloc / 2; + if (alloc < size + increment) + alloc = size + increment; + buf = (char *) xrealloc (buf, alloc); + } count = fread (buf + size, 1, increment, fp); if (count == 0) - { - if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - filename); - } + { + if (ferror (fp)) + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + filename); + } else - size += count; + size += count; } buf = (char *) xrealloc (buf, size); bfp->filename = filename; @@ -126,8 +126,8 @@ get_string (const struct binary_mo_file *bfp, size_t offset, size_t *lengthp) error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename); if (bfp->data[s_offset + s_length] != '\0') error (EXIT_FAILURE, 0, - _("file \"%s\" contains a not NUL terminated string"), - bfp->filename); + _("file \"%s\" contains a not NUL terminated string"), + bfp->filename); *lengthp = s_length + 1; return bfp->data + s_offset; @@ -136,7 +136,7 @@ get_string (const struct binary_mo_file *bfp, size_t offset, size_t *lengthp) /* Get a system dependent string from the file, at the given file position. */ static char * get_sysdep_string (const struct binary_mo_file *bfp, size_t offset, - const struct mo_file_header *header, size_t *lengthp) + const struct mo_file_header *header, size_t *lengthp) { /* See 'struct sysdep_string'. */ size_t length; @@ -159,25 +159,25 @@ get_sysdep_string (const struct binary_mo_file *bfp, size_t offset, length += segsize; if (sysdepref == SEGMENTS_END) - break; + break; if (sysdepref >= header->n_sysdep_segments) - /* Invalid. */ - error (EXIT_FAILURE, 0, _("file \"%s\" is not in GNU .mo format"), - bfp->filename); + /* Invalid. */ + error (EXIT_FAILURE, 0, _("file \"%s\" is not in GNU .mo format"), + bfp->filename); /* See 'struct sysdep_segment'. */ sysdep_segment_offset = header->sysdep_segments_offset + sysdepref * 8; ss_length = get_uint32 (bfp, sysdep_segment_offset); ss_offset = get_uint32 (bfp, sysdep_segment_offset + 4); if (ss_offset + ss_length > bfp->size) - error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename); + error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename); if (!(ss_length > 0 && bfp->data[ss_offset + ss_length - 1] == '\0')) - { - char location[30]; - sprintf (location, "sysdep_segment[%u]", (unsigned int) sysdepref); - error (EXIT_FAILURE, 0, - _("file \"%s\" contains a not NUL terminated string, at %s"), - bfp->filename, location); - } + { + char location[30]; + sprintf (location, "sysdep_segment[%u]", (unsigned int) sysdepref); + error (EXIT_FAILURE, 0, + _("file \"%s\" contains a not NUL terminated string, at %s"), + bfp->filename, location); + } n = strlen (bfp->data + ss_offset); length += (n > 1 ? 1 + n + 1 : n); } @@ -196,30 +196,30 @@ get_sysdep_string (const struct binary_mo_file *bfp, size_t offset, size_t n; if (s_offset + segsize > bfp->size) - error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename); + error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename); memcpy (p, bfp->data + s_offset, segsize); p += segsize; s_offset += segsize; if (sysdepref == SEGMENTS_END) - break; + break; if (sysdepref >= header->n_sysdep_segments) - abort (); + abort (); /* See 'struct sysdep_segment'. */ sysdep_segment_offset = header->sysdep_segments_offset + sysdepref * 8; ss_length = get_uint32 (bfp, sysdep_segment_offset); ss_offset = get_uint32 (bfp, sysdep_segment_offset + 4); if (ss_offset + ss_length > bfp->size) - abort (); + abort (); if (!(ss_length > 0 && bfp->data[ss_offset + ss_length - 1] == '\0')) - abort (); + abort (); n = strlen (bfp->data + ss_offset); if (n > 1) - *p++ = '<'; + *p++ = '<'; memcpy (p, bfp->data + ss_offset, n); p += n; if (n > 1) - *p++ = '>'; + *p++ = '>'; } if (p != string + length) @@ -248,8 +248,8 @@ read_mo_file (message_list_ty *mlp, const char *filename) { fp = fopen (filename, "rb"); if (fp == NULL) - error (EXIT_FAILURE, errno, - _("error while opening \"%s\" for reading"), filename); + error (EXIT_FAILURE, errno, + _("error while opening \"%s\" for reading"), filename); } /* Read the file contents into memory. */ @@ -269,11 +269,11 @@ read_mo_file (message_list_ty *mlp, const char *filename) bf.endian = MO_LITTLE_ENDIAN; header.magic = GET_HEADER_FIELD (magic); if (header.magic != _MAGIC) - { - unrecognised: - error (EXIT_FAILURE, 0, _("file \"%s\" is not in GNU .mo format"), - filename); - } + { + unrecognised: + error (EXIT_FAILURE, 0, _("file \"%s\" is not in GNU .mo format"), + filename); + } } header.revision = GET_HEADER_FIELD (revision); @@ -291,165 +291,165 @@ read_mo_file (message_list_ty *mlp, const char *filename) header.hash_tab_offset = GET_HEADER_FIELD (hash_tab_offset); for (i = 0; i < header.nstrings; i++) - { - message_ty *mp; - char *msgctxt; - char *msgid; - size_t msgid_len; - char *separator; - char *msgstr; - size_t msgstr_len; - - /* Read the msgctxt and msgid. */ - msgid = get_string (&bf, header.orig_tab_offset + i * 8, - &msgid_len); - /* Split into msgctxt and msgid. */ - separator = strchr (msgid, MSGCTXT_SEPARATOR); - if (separator != NULL) - { - /* The part before the MSGCTXT_SEPARATOR is the msgctxt. */ - *separator = '\0'; - msgctxt = msgid; - msgid = separator + 1; - msgid_len -= msgid - msgctxt; - } - else - msgctxt = NULL; - - /* Read the msgstr. */ - msgstr = get_string (&bf, header.trans_tab_offset + i * 8, - &msgstr_len); - - mp = message_alloc (msgctxt, - msgid, - (strlen (msgid) + 1 < msgid_len - ? msgid + strlen (msgid) + 1 - : NULL), - msgstr, msgstr_len, - &pos); - message_list_append (mlp, mp); - } + { + message_ty *mp; + char *msgctxt; + char *msgid; + size_t msgid_len; + char *separator; + char *msgstr; + size_t msgstr_len; + + /* Read the msgctxt and msgid. */ + msgid = get_string (&bf, header.orig_tab_offset + i * 8, + &msgid_len); + /* Split into msgctxt and msgid. */ + separator = strchr (msgid, MSGCTXT_SEPARATOR); + if (separator != NULL) + { + /* The part before the MSGCTXT_SEPARATOR is the msgctxt. */ + *separator = '\0'; + msgctxt = msgid; + msgid = separator + 1; + msgid_len -= msgid - msgctxt; + } + else + msgctxt = NULL; + + /* Read the msgstr. */ + msgstr = get_string (&bf, header.trans_tab_offset + i * 8, + &msgstr_len); + + mp = message_alloc (msgctxt, + msgid, + (strlen (msgid) + 1 < msgid_len + ? msgid + strlen (msgid) + 1 + : NULL), + msgstr, msgstr_len, + &pos); + message_list_append (mlp, mp); + } switch (header.revision & 0xffff) - { - case 0: - break; - case 1: - default: - /* Fill the header parts that apply to minor revision >= 1. */ - header.n_sysdep_segments = GET_HEADER_FIELD (n_sysdep_segments); - header.sysdep_segments_offset = - GET_HEADER_FIELD (sysdep_segments_offset); - header.n_sysdep_strings = GET_HEADER_FIELD (n_sysdep_strings); - header.orig_sysdep_tab_offset = - GET_HEADER_FIELD (orig_sysdep_tab_offset); - header.trans_sysdep_tab_offset = - GET_HEADER_FIELD (trans_sysdep_tab_offset); - - for (i = 0; i < header.n_sysdep_strings; i++) - { - message_ty *mp; - char *msgctxt; - char *msgid; - size_t msgid_len; - char *separator; - char *msgstr; - size_t msgstr_len; - nls_uint32 offset; - size_t f; - - /* Read the msgctxt and msgid. */ - offset = get_uint32 (&bf, header.orig_sysdep_tab_offset + i * 4); - msgid = get_sysdep_string (&bf, offset, &header, &msgid_len); - /* Split into msgctxt and msgid. */ - separator = strchr (msgid, MSGCTXT_SEPARATOR); - if (separator != NULL) - { - /* The part before the MSGCTXT_SEPARATOR is the msgctxt. */ - *separator = '\0'; - msgctxt = msgid; - msgid = separator + 1; - msgid_len -= msgid - msgctxt; - } - else - msgctxt = NULL; - - /* Read the msgstr. */ - offset = get_uint32 (&bf, header.trans_sysdep_tab_offset + i * 4); - msgstr = get_sysdep_string (&bf, offset, &header, &msgstr_len); - - mp = message_alloc (msgctxt, - msgid, - (strlen (msgid) + 1 < msgid_len - ? msgid + strlen (msgid) + 1 - : NULL), - msgstr, msgstr_len, - &pos); - - /* Only messages with c-format or objc-format annotation are - recognized as having system-dependent strings by msgfmt. - Which one of the two, we don't know. We have to guess, - assuming that c-format is more probable than objc-format and - that the .mo was likely produced by "msgfmt -c". */ - for (f = format_c; ; f = format_objc) - { - bool valid = true; - struct formatstring_parser *parser = formatstring_parsers[f]; - const char *str_end; - const char *str; - - str_end = msgid + msgid_len; - for (str = msgid; str < str_end; str += strlen (str) + 1) - { - char *invalid_reason = NULL; - void *descr = - parser->parse (str, false, NULL, &invalid_reason); - - if (descr != NULL) - parser->free (descr); - else - { - free (invalid_reason); - valid = false; - break; - } - } - if (valid) - { - str_end = msgstr + msgstr_len; - for (str = msgstr; str < str_end; str += strlen (str) + 1) - { - char *invalid_reason = NULL; - void *descr = - parser->parse (str, true, NULL, &invalid_reason); - - if (descr != NULL) - parser->free (descr); - else - { - free (invalid_reason); - valid = false; - break; - } - } - } - - if (valid) - { - /* Found the most likely among c-format, objc-format. */ - mp->is_format[f] = yes; - break; - } - - /* Try next f. */ - if (f == format_objc) - break; - } - - message_list_append (mlp, mp); - } - break; - } + { + case 0: + break; + case 1: + default: + /* Fill the header parts that apply to minor revision >= 1. */ + header.n_sysdep_segments = GET_HEADER_FIELD (n_sysdep_segments); + header.sysdep_segments_offset = + GET_HEADER_FIELD (sysdep_segments_offset); + header.n_sysdep_strings = GET_HEADER_FIELD (n_sysdep_strings); + header.orig_sysdep_tab_offset = + GET_HEADER_FIELD (orig_sysdep_tab_offset); + header.trans_sysdep_tab_offset = + GET_HEADER_FIELD (trans_sysdep_tab_offset); + + for (i = 0; i < header.n_sysdep_strings; i++) + { + message_ty *mp; + char *msgctxt; + char *msgid; + size_t msgid_len; + char *separator; + char *msgstr; + size_t msgstr_len; + nls_uint32 offset; + size_t f; + + /* Read the msgctxt and msgid. */ + offset = get_uint32 (&bf, header.orig_sysdep_tab_offset + i * 4); + msgid = get_sysdep_string (&bf, offset, &header, &msgid_len); + /* Split into msgctxt and msgid. */ + separator = strchr (msgid, MSGCTXT_SEPARATOR); + if (separator != NULL) + { + /* The part before the MSGCTXT_SEPARATOR is the msgctxt. */ + *separator = '\0'; + msgctxt = msgid; + msgid = separator + 1; + msgid_len -= msgid - msgctxt; + } + else + msgctxt = NULL; + + /* Read the msgstr. */ + offset = get_uint32 (&bf, header.trans_sysdep_tab_offset + i * 4); + msgstr = get_sysdep_string (&bf, offset, &header, &msgstr_len); + + mp = message_alloc (msgctxt, + msgid, + (strlen (msgid) + 1 < msgid_len + ? msgid + strlen (msgid) + 1 + : NULL), + msgstr, msgstr_len, + &pos); + + /* Only messages with c-format or objc-format annotation are + recognized as having system-dependent strings by msgfmt. + Which one of the two, we don't know. We have to guess, + assuming that c-format is more probable than objc-format and + that the .mo was likely produced by "msgfmt -c". */ + for (f = format_c; ; f = format_objc) + { + bool valid = true; + struct formatstring_parser *parser = formatstring_parsers[f]; + const char *str_end; + const char *str; + + str_end = msgid + msgid_len; + for (str = msgid; str < str_end; str += strlen (str) + 1) + { + char *invalid_reason = NULL; + void *descr = + parser->parse (str, false, NULL, &invalid_reason); + + if (descr != NULL) + parser->free (descr); + else + { + free (invalid_reason); + valid = false; + break; + } + } + if (valid) + { + str_end = msgstr + msgstr_len; + for (str = msgstr; str < str_end; str += strlen (str) + 1) + { + char *invalid_reason = NULL; + void *descr = + parser->parse (str, true, NULL, &invalid_reason); + + if (descr != NULL) + parser->free (descr); + else + { + free (invalid_reason); + valid = false; + break; + } + } + } + + if (valid) + { + /* Found the most likely among c-format, objc-format. */ + mp->is_format[f] = yes; + break; + } + + /* Try next f. */ + if (f == format_objc) + break; + } + + message_list_append (mlp, mp); + } + break; + } break; default: diff --git a/gettext-tools/src/read-po.c b/gettext-tools/src/read-po.c index d4b0adf49..04f1b7474 100644 --- a/gettext-tools/src/read-po.c +++ b/gettext-tools/src/read-po.c @@ -34,7 +34,7 @@ abstract_catalog_reader_class_ty methods. */ static void po_parse (abstract_catalog_reader_ty *this, FILE *fp, - const char *real_filename, const char *logical_filename) + const char *real_filename, const char *logical_filename) { lex_start (fp, real_filename, logical_filename); po_gram_parse (); @@ -43,6 +43,6 @@ po_parse (abstract_catalog_reader_ty *this, FILE *fp, const struct catalog_input_format input_format_po = { - po_parse, /* parse */ - false /* produces_utf8 */ + po_parse, /* parse */ + false /* produces_utf8 */ }; diff --git a/gettext-tools/src/read-properties.c b/gettext-tools/src/read-properties.c index 82f676728..0c647305f 100644 --- a/gettext-tools/src/read-properties.c +++ b/gettext-tools/src/read-properties.c @@ -82,14 +82,14 @@ phase1_getc () if (c == EOF) { if (ferror (fp)) - { - const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while reading \"%s\""), - real_file_name), - errno_description)); - } + { + const char *errno_description = strerror (errno); + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("error while reading \"%s\""), + real_file_name), + errno_description)); + } return EOF; } @@ -122,13 +122,13 @@ phase2_getc () c = phase1_getc (); if (c == '\r') - { - int c2 = phase1_getc (); - if (c2 == '\n') - c = c2; - else - phase1_ungetc (c2); - } + { + int c2 = phase1_getc (); + if (c2 == '\n') + c = c2; + else + phase1_ungetc (c2); + } } if (c == '\n') @@ -159,18 +159,18 @@ phase3_getc () for (;;) { if (c != '\\') - return c; + return c; c = phase2_getc (); if (c != '\n') - { - phase2_ungetc (c); - return '\\'; - } + { + phase2_ungetc (c); + return '\\'; + } /* Skip the backslash-newline and all whitespace that follows it. */ do - c = phase2_getc (); + c = phase2_getc (); while (c == ' ' || c == '\t' || c == '\r' || c == '\f'); } } @@ -197,39 +197,39 @@ phase4_getuc () int c2 = phase3_getc (); if (c2 == 't') - return '\t'; + return '\t'; if (c2 == 'n') - return '\n'; + return '\n'; if (c2 == 'r') - return '\r'; + return '\r'; if (c2 == 'f') - return '\f'; + return '\f'; if (c2 == 'u') - { - unsigned int n = 0; - int i; - - for (i = 0; i < 4; i++) - { - int c1 = phase3_getc (); - - if (c1 >= '0' && c1 <= '9') - n = (n << 4) + (c1 - '0'); - else if (c1 >= 'A' && c1 <= 'F') - n = (n << 4) + (c1 - 'A' + 10); - else if (c1 >= 'a' && c1 <= 'f') - n = (n << 4) + (c1 - 'a' + 10); - else - { - phase3_ungetc (c1); - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, gram_pos.line_number, (size_t)(-1), - false, _("warning: invalid \\uxxxx syntax for Unicode character")); - return 'u'; - } - } - return n; - } + { + unsigned int n = 0; + int i; + + for (i = 0; i < 4; i++) + { + int c1 = phase3_getc (); + + if (c1 >= '0' && c1 <= '9') + n = (n << 4) + (c1 - '0'); + else if (c1 >= 'A' && c1 <= 'F') + n = (n << 4) + (c1 - 'A' + 10); + else if (c1 >= 'a' && c1 <= 'f') + n = (n << 4) + (c1 - 'a' + 10); + else + { + phase3_ungetc (c1); + po_xerror (PO_SEVERITY_ERROR, NULL, + real_file_name, gram_pos.line_number, (size_t)(-1), + false, _("warning: invalid \\uxxxx syntax for Unicode character")); + return 'u'; + } + } + return n; + } return c2; } @@ -254,12 +254,12 @@ conv_from_iso_8859_1 (char *string) const char *str_limit = str + length; while (str < str_limit) - { - unsigned int uc = (unsigned char) *str++; - int n = u8_uctomb (q, uc, 6); - assert (n > 0); - q += n; - } + { + unsigned int uc = (unsigned char) *str++; + int n = u8_uctomb (q, uc, 6); + assert (n > 0); + q += n; + } *q = '\0'; assert (q - utf8_string <= 2 * length); @@ -281,72 +281,72 @@ conv_from_java (char *string) while (*p != '\0') { if (p[0] == '\\' && p[1] == 'u') - { - unsigned int n = 0; - int i; - - for (i = 0; i < 4; i++) - { - int c1 = (unsigned char) p[2 + i]; - - if (c1 >= '0' && c1 <= '9') - n = (n << 4) + (c1 - '0'); - else if (c1 >= 'A' && c1 <= 'F') - n = (n << 4) + (c1 - 'A' + 10); - else if (c1 >= 'a' && c1 <= 'f') - n = (n << 4) + (c1 - 'a' + 10); - else - goto just_one_byte; - } - - if (i == 4) - { - unsigned int uc; - - if (n >= 0xd800 && n < 0xdc00) - { - if (p[6] == '\\' && p[7] == 'u') - { - unsigned int m = 0; - - for (i = 0; i < 4; i++) - { - int c1 = (unsigned char) p[8 + i]; - - if (c1 >= '0' && c1 <= '9') - m = (m << 4) + (c1 - '0'); - else if (c1 >= 'A' && c1 <= 'F') - m = (m << 4) + (c1 - 'A' + 10); - else if (c1 >= 'a' && c1 <= 'f') - m = (m << 4) + (c1 - 'a' + 10); - else - goto just_one_byte; - } - - if (i == 4 && (m >= 0xdc00 && m < 0xe000)) - { - /* Combine two UTF-16 words to a character. */ - uc = 0x10000 + ((n - 0xd800) << 10) + (m - 0xdc00); - p += 12; - } - else - goto just_one_byte; - } - else - goto just_one_byte; - } - else - { - uc = n; - p += 6; - } - - q += u8_uctomb (q, uc, 6); - continue; - } - } + { + unsigned int n = 0; + int i; + + for (i = 0; i < 4; i++) + { + int c1 = (unsigned char) p[2 + i]; + + if (c1 >= '0' && c1 <= '9') + n = (n << 4) + (c1 - '0'); + else if (c1 >= 'A' && c1 <= 'F') + n = (n << 4) + (c1 - 'A' + 10); + else if (c1 >= 'a' && c1 <= 'f') + n = (n << 4) + (c1 - 'a' + 10); + else + goto just_one_byte; + } + + if (i == 4) + { + unsigned int uc; + + if (n >= 0xd800 && n < 0xdc00) + { + if (p[6] == '\\' && p[7] == 'u') + { + unsigned int m = 0; + + for (i = 0; i < 4; i++) + { + int c1 = (unsigned char) p[8 + i]; + + if (c1 >= '0' && c1 <= '9') + m = (m << 4) + (c1 - '0'); + else if (c1 >= 'A' && c1 <= 'F') + m = (m << 4) + (c1 - 'A' + 10); + else if (c1 >= 'a' && c1 <= 'f') + m = (m << 4) + (c1 - 'a' + 10); + else + goto just_one_byte; + } + + if (i == 4 && (m >= 0xdc00 && m < 0xe000)) + { + /* Combine two UTF-16 words to a character. */ + uc = 0x10000 + ((n - 0xd800) << 10) + (m - 0xdc00); + p += 12; + } + else + goto just_one_byte; + } + else + goto just_one_byte; + } + else + { + uc = n; + p += 6; + } + + q += u8_uctomb (q, uc, 6); + continue; + } + } just_one_byte: - *q++ = (unsigned char) *p++; + *q++ = (unsigned char) *p++; } *q = '\0'; return string; @@ -387,38 +387,38 @@ read_escaped_string (bool in_key) for (;;) { if (in_key && (c == '=' || c == ':' - || c == ' ' || c == '\t' || c == '\r' || c == '\f')) - { - /* Skip whitespace after the string. */ - while (c == ' ' || c == '\t' || c == '\r' || c == '\f') - c = phase3_getc (); - /* Skip '=' or ':' separator. */ - if (!(c == '=' || c == ':')) - phase3_ungetc (c); - break; - } + || c == ' ' || c == '\t' || c == '\r' || c == '\f')) + { + /* Skip whitespace after the string. */ + while (c == ' ' || c == '\t' || c == '\r' || c == '\f') + c = phase3_getc (); + /* Skip '=' or ':' separator. */ + if (!(c == '=' || c == ':')) + phase3_ungetc (c); + break; + } phase3_ungetc (c); /* Read the next UTF-16 codepoint. */ c = phase4_getuc (); if (c < 0) - break; + break; /* Append it to the buffer. */ if (buflen >= bufmax) - { - bufmax += 100; - buffer = xrealloc (buffer, bufmax * sizeof (unsigned short)); - } + { + bufmax += 100; + buffer = xrealloc (buffer, bufmax * sizeof (unsigned short)); + } buffer[buflen++] = c; c = phase3_getc (); if (c == EOF || c == '\n') - { - if (in_key) - phase3_ungetc (c); - break; - } + { + if (in_key) + phase3_ungetc (c); + break; + } } /* Now convert from UTF-16 to UTF-8. */ @@ -431,13 +431,13 @@ read_escaped_string (bool in_key) utf8_string = XNMALLOC (3 * buflen + 1, unsigned char); for (pos = 0, q = utf8_string; pos < buflen; ) { - ucs4_t uc; - int n; + ucs4_t uc; + int n; - pos += u16_mbtouc (&uc, buffer + pos, buflen - pos); - n = u8_uctomb (q, uc, 6); - assert (n > 0); - q += n; + pos += u16_mbtouc (&uc, buffer + pos, buflen - pos); + n = u8_uctomb (q, uc, 6); + assert (n > 0); + q += n; } *q = '\0'; assert (q - utf8_string <= 3 * buflen); @@ -451,7 +451,7 @@ read_escaped_string (bool in_key) abstract_catalog_reader_class_ty methods. */ static void properties_parse (abstract_catalog_reader_ty *this, FILE *file, - const char *real_filename, const char *logical_filename) + const char *real_filename, const char *logical_filename) { fp = file; real_file_name = real_filename; @@ -467,85 +467,85 @@ properties_parse (abstract_catalog_reader_ty *this, FILE *file, c = phase2_getc (); if (c == EOF) - break; + break; comment = false; hidden = false; if (c == '#') - comment = true; + comment = true; else if (c == '!') - { - /* For compatibility with write-properties.c, we treat '!' not - followed by space as a fuzzy or untranslated message. */ - int c2 = phase2_getc (); - if (c2 == ' ' || c2 == '\n' || c2 == EOF) - comment = true; - else - hidden = true; - phase2_ungetc (c2); - } + { + /* For compatibility with write-properties.c, we treat '!' not + followed by space as a fuzzy or untranslated message. */ + int c2 = phase2_getc (); + if (c2 == ' ' || c2 == '\n' || c2 == EOF) + comment = true; + else + hidden = true; + phase2_ungetc (c2); + } else - phase2_ungetc (c); + phase2_ungetc (c); if (comment) - { - /* A comment line. */ - static char *buffer; - static size_t bufmax; - static size_t buflen; - - buflen = 0; - for (;;) - { - c = phase2_getc (); - - if (buflen >= bufmax) - { - bufmax += 100; - buffer = xrealloc (buffer, bufmax); - } - - if (c == EOF || c == '\n') - break; - - buffer[buflen++] = c; - } - buffer[buflen] = '\0'; - - po_callback_comment_dispatcher (conv_from_java (conv_from_iso_8859_1 (buffer))); - } + { + /* A comment line. */ + static char *buffer; + static size_t bufmax; + static size_t buflen; + + buflen = 0; + for (;;) + { + c = phase2_getc (); + + if (buflen >= bufmax) + { + bufmax += 100; + buffer = xrealloc (buffer, bufmax); + } + + if (c == EOF || c == '\n') + break; + + buffer[buflen++] = c; + } + buffer[buflen] = '\0'; + + po_callback_comment_dispatcher (conv_from_java (conv_from_iso_8859_1 (buffer))); + } else - { - /* A key/value pair. */ - char *msgid; - lex_pos_ty msgid_pos; - - msgid_pos = gram_pos; - msgid = read_escaped_string (true); - if (msgid == NULL) - /* Skip blank line. */ - ; - else - { - char *msgstr; - lex_pos_ty msgstr_pos; - bool force_fuzzy; - - msgstr_pos = gram_pos; - msgstr = read_escaped_string (false); - if (msgstr == NULL) - msgstr = xstrdup (""); - - /* Be sure to make the message fuzzy if it was commented out - and if it is not already header/fuzzy/untranslated. */ - force_fuzzy = (hidden && msgid[0] != '\0' && msgstr[0] != '\0'); - - po_callback_message (NULL, msgid, &msgid_pos, NULL, - msgstr, strlen (msgstr) + 1, &msgstr_pos, - NULL, NULL, NULL, - force_fuzzy, false); - } - } + { + /* A key/value pair. */ + char *msgid; + lex_pos_ty msgid_pos; + + msgid_pos = gram_pos; + msgid = read_escaped_string (true); + if (msgid == NULL) + /* Skip blank line. */ + ; + else + { + char *msgstr; + lex_pos_ty msgstr_pos; + bool force_fuzzy; + + msgstr_pos = gram_pos; + msgstr = read_escaped_string (false); + if (msgstr == NULL) + msgstr = xstrdup (""); + + /* Be sure to make the message fuzzy if it was commented out + and if it is not already header/fuzzy/untranslated. */ + force_fuzzy = (hidden && msgid[0] != '\0' && msgstr[0] != '\0'); + + po_callback_message (NULL, msgid, &msgid_pos, NULL, + msgstr, strlen (msgstr) + 1, &msgstr_pos, + NULL, NULL, NULL, + force_fuzzy, false); + } + } } fp = NULL; @@ -555,6 +555,6 @@ properties_parse (abstract_catalog_reader_ty *this, FILE *file, const struct catalog_input_format input_format_properties = { - properties_parse, /* parse */ - true /* produces_utf8 */ + properties_parse, /* parse */ + true /* produces_utf8 */ }; diff --git a/gettext-tools/src/read-resources.c b/gettext-tools/src/read-resources.c index 621c8e699..355f6296b 100644 --- a/gettext-tools/src/read-resources.c +++ b/gettext-tools/src/read-resources.c @@ -55,8 +55,8 @@ struct locals static bool execute_and_read_po_output (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data) + const char *prog_path, char **prog_argv, + void *private_data) { struct locals *l = (struct locals *) private_data; pid_t child; @@ -66,7 +66,7 @@ execute_and_read_po_output (const char *progname, /* Open a pipe to the C# execution engine. */ child = create_pipe_in (progname, prog_path, prog_argv, NULL, false, - true, true, fd); + true, true, fd); fp = fdopen (fd[0], "r"); if (fp == NULL) @@ -82,7 +82,7 @@ execute_and_read_po_output (const char *progname, wait_subprocess (child, progname, false, false, true, true, NULL); if (exitstatus != 0) error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"), - progname, exitstatus); + progname, exitstatus); return false; } @@ -119,9 +119,9 @@ read_resources_file (message_list_ty *mlp, const char *filename) xconcatenated_filename (gettextexedir, "msgunfmt.net", ".exe"); libdirs[0] = gettextlibdir; if (execute_csharp_program (assembly_path, libdirs, 1, - args, - verbose, false, - execute_and_read_po_output, &locals)) + args, + verbose, false, + execute_and_read_po_output, &locals)) /* An error message should already have been provided. */ exit (EXIT_FAILURE); diff --git a/gettext-tools/src/read-stringtable.c b/gettext-tools/src/read-stringtable.c index 9f2e55c30..27b886048 100644 --- a/gettext-tools/src/read-stringtable.c +++ b/gettext-tools/src/read-stringtable.c @@ -91,14 +91,14 @@ phase1_getc () if (c == EOF) { if (ferror (fp)) - { - const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while reading \"%s\""), - real_file_name), - errno_description)); - } + { + const char *errno_description = strerror (errno); + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("error while reading \"%s\""), + real_file_name), + errno_description)); + } return EOF; } @@ -149,38 +149,38 @@ phase2_getc () c0 = phase1_getc (); if (c0 == EOF) - return UEOF; + return UEOF; c1 = phase1_getc (); if (c1 == EOF) - { - phase1_ungetc (c0); - encoding = enc_iso8859_1; - } + { + phase1_ungetc (c0); + encoding = enc_iso8859_1; + } else if (c0 == 0xfe && c1 == 0xff) - encoding = enc_ucs2be; + encoding = enc_ucs2be; else if (c0 == 0xff && c1 == 0xfe) - encoding = enc_ucs2le; + encoding = enc_ucs2le; else - { - int c2; - - c2 = phase1_getc (); - if (c2 == EOF) - { - phase1_ungetc (c1); - phase1_ungetc (c0); - encoding = enc_iso8859_1; - } - else if (c0 == 0xef && c1 == 0xbb && c2 == 0xbf) - encoding = enc_utf8; - else - { - phase1_ungetc (c2); - phase1_ungetc (c1); - phase1_ungetc (c0); - encoding = enc_iso8859_1; - } - } + { + int c2; + + c2 = phase1_getc (); + if (c2 == EOF) + { + phase1_ungetc (c1); + phase1_ungetc (c0); + encoding = enc_iso8859_1; + } + else if (c0 == 0xef && c1 == 0xbb && c2 == 0xbf) + encoding = enc_utf8; + else + { + phase1_ungetc (c2); + phase1_ungetc (c1); + phase1_ungetc (c0); + encoding = enc_iso8859_1; + } + } } switch (encoding) @@ -188,106 +188,106 @@ phase2_getc () case enc_ucs2be: /* Read an UCS-2BE encoded character. */ { - int c0, c1; - - c0 = phase1_getc (); - if (c0 == EOF) - return UEOF; - c1 = phase1_getc (); - if (c1 == EOF) - return UEOF; - return (c0 << 8) + c1; + int c0, c1; + + c0 = phase1_getc (); + if (c0 == EOF) + return UEOF; + c1 = phase1_getc (); + if (c1 == EOF) + return UEOF; + return (c0 << 8) + c1; } case enc_ucs2le: /* Read an UCS-2LE encoded character. */ { - int c0, c1; - - c0 = phase1_getc (); - if (c0 == EOF) - return UEOF; - c1 = phase1_getc (); - if (c1 == EOF) - return UEOF; - return c0 + (c1 << 8); + int c0, c1; + + c0 = phase1_getc (); + if (c0 == EOF) + return UEOF; + c1 = phase1_getc (); + if (c1 == EOF) + return UEOF; + return c0 + (c1 << 8); } case enc_utf8: /* Read an UTF-8 encoded character. */ { - unsigned char buf[6]; - unsigned int count; - int c; - ucs4_t uc; - - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[0] = c; - count = 1; - - if (buf[0] >= 0xc0) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[1] = c; - count = 2; - - if (buf[0] >= 0xe0 - && ((buf[1] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[2] = c; - count = 3; - - if (buf[0] >= 0xf0 - && ((buf[2] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[3] = c; - count = 4; - - if (buf[0] >= 0xf8 - && ((buf[3] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[4] = c; - count = 5; - - if (buf[0] >= 0xfc - && ((buf[4] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[5] = c; - count = 6; - } - } - } - } - } - - u8_mbtouc (&uc, buf, count); - return uc; + unsigned char buf[6]; + unsigned int count; + int c; + ucs4_t uc; + + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[0] = c; + count = 1; + + if (buf[0] >= 0xc0) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[1] = c; + count = 2; + + if (buf[0] >= 0xe0 + && ((buf[1] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[2] = c; + count = 3; + + if (buf[0] >= 0xf0 + && ((buf[2] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[3] = c; + count = 4; + + if (buf[0] >= 0xf8 + && ((buf[3] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[4] = c; + count = 5; + + if (buf[0] >= 0xfc + && ((buf[4] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[5] = c; + count = 6; + } + } + } + } + } + + u8_mbtouc (&uc, buf, count); + return uc; } case enc_iso8859_1: /* Read an ISO-8859-1 encoded character. */ { - int c = phase1_getc (); + int c = phase1_getc (); - if (c == EOF) - return UEOF; - return c; + if (c == EOF) + return UEOF; + return c; } default: @@ -374,71 +374,71 @@ parse_escaped_string (const int *string, size_t length) for (;;) { if (string == string_limit) - return NULL; + return NULL; c = *string++; if (c == '"') - break; + break; if (c == '\\') - { - if (string == string_limit) - return NULL; - c = *string++; - if (c >= '0' && c <= '7') - { - unsigned int n = 0; - int j = 0; - for (;;) - { - n = n * 8 + (c - '0'); - if (++j == 3) - break; - if (string == string_limit) - break; - c = *string; - if (!(c >= '0' && c <= '7')) - break; - string++; - } - c = n; - } - else if (c == 'u' || c == 'U') - { - unsigned int n = 0; - int j; - for (j = 0; j < 4; j++) - { - if (string == string_limit) - break; - c = *string; - if (c >= '0' && c <= '9') - n = n * 16 + (c - '0'); - else if (c >= 'A' && c <= 'F') - n = n * 16 + (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - n = n * 16 + (c - 'a' + 10); - else - break; - string++; - } - c = n; - } - else - switch (c) - { - case 'a': c = '\a'; break; - case 'b': c = '\b'; break; - case 't': c = '\t'; break; - case 'r': c = '\r'; break; - case 'n': c = '\n'; break; - case 'v': c = '\v'; break; - case 'f': c = '\f'; break; - } - } + { + if (string == string_limit) + return NULL; + c = *string++; + if (c >= '0' && c <= '7') + { + unsigned int n = 0; + int j = 0; + for (;;) + { + n = n * 8 + (c - '0'); + if (++j == 3) + break; + if (string == string_limit) + break; + c = *string; + if (!(c >= '0' && c <= '7')) + break; + string++; + } + c = n; + } + else if (c == 'u' || c == 'U') + { + unsigned int n = 0; + int j; + for (j = 0; j < 4; j++) + { + if (string == string_limit) + break; + c = *string; + if (c >= '0' && c <= '9') + n = n * 16 + (c - '0'); + else if (c >= 'A' && c <= 'F') + n = n * 16 + (c - 'A' + 10); + else if (c >= 'a' && c <= 'f') + n = n * 16 + (c - 'a' + 10); + else + break; + string++; + } + c = n; + } + else + switch (c) + { + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 't': c = '\t'; break; + case 'r': c = '\r'; break; + case 'n': c = '\n'; break; + case 'v': c = '\v'; break; + case 'f': c = '\f'; break; + } + } if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax * sizeof (int)); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax * sizeof (int)); + } buffer[buflen++] = c; } @@ -520,7 +520,7 @@ comment_line_end (size_t chars_to_remove, bool test_for_fuzzy_msgstr) buflen -= chars_to_remove; /* Drop trailing white space, but not EOLs. */ while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; /* At special positions we interpret a comment of the form @@ -530,8 +530,8 @@ comment_line_end (size_t chars_to_remove, bool test_for_fuzzy_msgstr) if (test_for_fuzzy_msgstr && buflen > 2 && buffer[0] == '=' && buffer[1] == ' ' && (fuzzy_msgstr = - parse_escaped_string (buffer + 2, - buflen - (buffer[buflen - 1] == ';') - 2))) + parse_escaped_string (buffer + 2, + buflen - (buffer[buflen - 1] == ';') - 2))) return; line = conv_from_ucs4 (buffer, buflen); @@ -555,16 +555,16 @@ comment_line_end (size_t chars_to_remove, bool test_for_fuzzy_msgstr) char *endp; if (strlen (line) >= 6 && memcmp (line, "File: ", 6) == 0 - && (last_colon = strrchr (line + 6, ':')) != NULL - && *(last_colon + 1) != '\0' - && (number = strtoul (last_colon + 1, &endp, 10), *endp == '\0')) - { - /* A "File: :" type comment. */ - *last_colon = '\0'; - po_callback_comment_filepos (line + 6, number); - } + && (last_colon = strrchr (line + 6, ':')) != NULL + && *(last_colon + 1) != '\0' + && (number = strtoul (last_colon + 1, &endp, 10), *endp == '\0')) + { + /* A "File: :" type comment. */ + *last_colon = '\0'; + po_callback_comment_filepos (line + 6, number); + } else - po_callback_comment (line); + po_callback_comment (line); } } @@ -590,79 +590,79 @@ phase4_getc () case '*': /* C style comment. */ { - bool last_was_star; - size_t trailing_stars; - bool seen_newline; - - comment_start (); - last_was_star = false; - trailing_stars = 0; - seen_newline = false; - /* Drop additional stars at the beginning of the comment. */ - for (;;) - { - c = phase3_getc (); - if (c != '*') - break; - last_was_star = true; - } - phase3_ungetc (c); - for (;;) - { - c = phase3_getc (); - if (c == UEOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - switch (c) - { - case '\n': - seen_newline = true; - comment_line_end (1, false); - comment_start (); - last_was_star = false; - trailing_stars = 0; - continue; - - case '*': - last_was_star = true; - trailing_stars++; - continue; - - case '/': - if (last_was_star) - { - /* Drop additional stars at the end of the comment. */ - comment_line_end (trailing_stars + 1, - expect_fuzzy_msgstr_as_c_comment - && !seen_newline); - break; - } - /* FALLTHROUGH */ - - default: - last_was_star = false; - trailing_stars = 0; - continue; - } - break; - } - return ' '; + bool last_was_star; + size_t trailing_stars; + bool seen_newline; + + comment_start (); + last_was_star = false; + trailing_stars = 0; + seen_newline = false; + /* Drop additional stars at the beginning of the comment. */ + for (;;) + { + c = phase3_getc (); + if (c != '*') + break; + last_was_star = true; + } + phase3_ungetc (c); + for (;;) + { + c = phase3_getc (); + if (c == UEOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + switch (c) + { + case '\n': + seen_newline = true; + comment_line_end (1, false); + comment_start (); + last_was_star = false; + trailing_stars = 0; + continue; + + case '*': + last_was_star = true; + trailing_stars++; + continue; + + case '/': + if (last_was_star) + { + /* Drop additional stars at the end of the comment. */ + comment_line_end (trailing_stars + 1, + expect_fuzzy_msgstr_as_c_comment + && !seen_newline); + break; + } + /* FALLTHROUGH */ + + default: + last_was_star = false; + trailing_stars = 0; + continue; + } + break; + } + return ' '; } case '/': /* C++ style comment. */ comment_start (); for (;;) - { - c = phase3_getc (); - if (c == '\n' || c == UEOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - } + { + c = phase3_getc (); + if (c == '\n' || c == UEOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + } comment_line_end (0, expect_fuzzy_msgstr_as_cxx_comment); return '\n'; } @@ -680,7 +680,7 @@ static bool is_whitespace (int c) { return (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f' - || c == '\b'); + || c == '\b'); } /* Return true if a character needs quoting, i.e. cannot be used in unquoted @@ -729,94 +729,94 @@ read_string (lex_pos_ty *pos) { /* Read a string enclosed in double-quotes. */ for (;;) - { - c = phase3_getc (); - if (c == UEOF || c == '"') - break; - if (c == '\\') - { - c = phase3_getc (); - if (c == UEOF) - break; - if (c >= '0' && c <= '7') - { - unsigned int n = 0; - int j = 0; - for (;;) - { - n = n * 8 + (c - '0'); - if (++j == 3) - break; - c = phase3_getc (); - if (!(c >= '0' && c <= '7')) - { - phase3_ungetc (c); - break; - } - } - c = n; - } - else if (c == 'u' || c == 'U') - { - unsigned int n = 0; - int j; - for (j = 0; j < 4; j++) - { - c = phase3_getc (); - if (c >= '0' && c <= '9') - n = n * 16 + (c - '0'); - else if (c >= 'A' && c <= 'F') - n = n * 16 + (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - n = n * 16 + (c - 'a' + 10); - else - { - phase3_ungetc (c); - break; - } - } - c = n; - } - else - switch (c) - { - case 'a': c = '\a'; break; - case 'b': c = '\b'; break; - case 't': c = '\t'; break; - case 'r': c = '\r'; break; - case 'n': c = '\n'; break; - case 'v': c = '\v'; break; - case 'f': c = '\f'; break; - } - } - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax * sizeof (int)); - } - buffer[buflen++] = c; - } + { + c = phase3_getc (); + if (c == UEOF || c == '"') + break; + if (c == '\\') + { + c = phase3_getc (); + if (c == UEOF) + break; + if (c >= '0' && c <= '7') + { + unsigned int n = 0; + int j = 0; + for (;;) + { + n = n * 8 + (c - '0'); + if (++j == 3) + break; + c = phase3_getc (); + if (!(c >= '0' && c <= '7')) + { + phase3_ungetc (c); + break; + } + } + c = n; + } + else if (c == 'u' || c == 'U') + { + unsigned int n = 0; + int j; + for (j = 0; j < 4; j++) + { + c = phase3_getc (); + if (c >= '0' && c <= '9') + n = n * 16 + (c - '0'); + else if (c >= 'A' && c <= 'F') + n = n * 16 + (c - 'A' + 10); + else if (c >= 'a' && c <= 'f') + n = n * 16 + (c - 'a' + 10); + else + { + phase3_ungetc (c); + break; + } + } + c = n; + } + else + switch (c) + { + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 't': c = '\t'; break; + case 'r': c = '\r'; break; + case 'n': c = '\n'; break; + case 'v': c = '\v'; break; + case 'f': c = '\f'; break; + } + } + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax * sizeof (int)); + } + buffer[buflen++] = c; + } if (c == UEOF) - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, gram_pos.line_number, (size_t)(-1), false, - _("warning: unterminated string")); + po_xerror (PO_SEVERITY_ERROR, NULL, + real_file_name, gram_pos.line_number, (size_t)(-1), false, + _("warning: unterminated string")); } else { /* Read a token outside quotes. */ if (is_quotable (c)) - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, gram_pos.line_number, (size_t)(-1), false, - _("warning: syntax error")); + po_xerror (PO_SEVERITY_ERROR, NULL, + real_file_name, gram_pos.line_number, (size_t)(-1), false, + _("warning: syntax error")); for (; c != UEOF && !is_quotable (c); c = phase4_getc ()) - { - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax * sizeof (int)); - } - buffer[buflen++] = c; - } + { + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax * sizeof (int)); + } + buffer[buflen++] = c; + } } return conv_from_ucs4 (buffer, buflen); @@ -827,7 +827,7 @@ read_string (lex_pos_ty *pos) abstract_catalog_reader_class_ty methods. */ static void stringtable_parse (abstract_catalog_reader_ty *pop, FILE *file, - const char *real_filename, const char *logical_filename) + const char *real_filename, const char *logical_filename) { fp = file; real_file_name = real_filename; @@ -854,101 +854,101 @@ stringtable_parse (abstract_catalog_reader_ty *pop, FILE *file, /* Read the key and all the comments preceding it. */ msgid = read_string (&msgid_pos); if (msgid == NULL) - break; + break; special_comment_finish (); /* Skip whitespace. */ do - c = phase4_getc (); + c = phase4_getc (); while (is_whitespace (c)); /* Expect a '=' or ';'. */ if (c == UEOF) - { - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, gram_pos.line_number, (size_t)(-1), false, - _("warning: unterminated key/value pair")); - break; - } + { + po_xerror (PO_SEVERITY_ERROR, NULL, + real_file_name, gram_pos.line_number, (size_t)(-1), false, + _("warning: unterminated key/value pair")); + break; + } if (c == ';') - { - /* "key"; is an abbreviation for "key"=""; and does not - necessarily designate an untranslated entry. */ - msgstr = xstrdup (""); - msgstr_pos = msgid_pos; - po_callback_message (NULL, msgid, &msgid_pos, NULL, - msgstr, strlen (msgstr) + 1, &msgstr_pos, - NULL, NULL, NULL, - false, next_is_obsolete); - } + { + /* "key"; is an abbreviation for "key"=""; and does not + necessarily designate an untranslated entry. */ + msgstr = xstrdup (""); + msgstr_pos = msgid_pos; + po_callback_message (NULL, msgid, &msgid_pos, NULL, + msgstr, strlen (msgstr) + 1, &msgstr_pos, + NULL, NULL, NULL, + false, next_is_obsolete); + } else if (c == '=') - { - /* Read the value. */ - msgstr = read_string (&msgstr_pos); - if (msgstr == NULL) - { - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, gram_pos.line_number, (size_t)(-1), - false, _("warning: unterminated key/value pair")); - break; - } - - /* Skip whitespace. But for fuzzy key/value pairs, look for the - tentative msgstr in the form of a C style comment. */ - expect_fuzzy_msgstr_as_c_comment = next_is_fuzzy; - do - { - c = phase4_getc (); - if (fuzzy_msgstr != NULL) - expect_fuzzy_msgstr_as_c_comment = false; - } - while (is_whitespace (c)); - expect_fuzzy_msgstr_as_c_comment = false; - - /* Expect a ';'. */ - if (c == ';') - { - /* But for fuzzy key/value pairs, look for the tentative msgstr - in the form of a C++ style comment. */ - if (fuzzy_msgstr == NULL && next_is_fuzzy) - { - do - c = phase3_getc (); - while (c == ' '); - phase3_ungetc (c); - - expect_fuzzy_msgstr_as_cxx_comment = true; - c = phase4_getc (); - phase4_ungetc (c); - expect_fuzzy_msgstr_as_cxx_comment = false; - } - if (fuzzy_msgstr != NULL && strcmp (msgstr, msgid) == 0) - msgstr = fuzzy_msgstr; - - /* A key/value pair. */ - po_callback_message (NULL, msgid, &msgid_pos, NULL, - msgstr, strlen (msgstr) + 1, &msgstr_pos, - NULL, NULL, NULL, - false, next_is_obsolete); - } - else - { - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, gram_pos.line_number, (size_t)(-1), - false, _("\ + { + /* Read the value. */ + msgstr = read_string (&msgstr_pos); + if (msgstr == NULL) + { + po_xerror (PO_SEVERITY_ERROR, NULL, + real_file_name, gram_pos.line_number, (size_t)(-1), + false, _("warning: unterminated key/value pair")); + break; + } + + /* Skip whitespace. But for fuzzy key/value pairs, look for the + tentative msgstr in the form of a C style comment. */ + expect_fuzzy_msgstr_as_c_comment = next_is_fuzzy; + do + { + c = phase4_getc (); + if (fuzzy_msgstr != NULL) + expect_fuzzy_msgstr_as_c_comment = false; + } + while (is_whitespace (c)); + expect_fuzzy_msgstr_as_c_comment = false; + + /* Expect a ';'. */ + if (c == ';') + { + /* But for fuzzy key/value pairs, look for the tentative msgstr + in the form of a C++ style comment. */ + if (fuzzy_msgstr == NULL && next_is_fuzzy) + { + do + c = phase3_getc (); + while (c == ' '); + phase3_ungetc (c); + + expect_fuzzy_msgstr_as_cxx_comment = true; + c = phase4_getc (); + phase4_ungetc (c); + expect_fuzzy_msgstr_as_cxx_comment = false; + } + if (fuzzy_msgstr != NULL && strcmp (msgstr, msgid) == 0) + msgstr = fuzzy_msgstr; + + /* A key/value pair. */ + po_callback_message (NULL, msgid, &msgid_pos, NULL, + msgstr, strlen (msgstr) + 1, &msgstr_pos, + NULL, NULL, NULL, + false, next_is_obsolete); + } + else + { + po_xerror (PO_SEVERITY_ERROR, NULL, + real_file_name, gram_pos.line_number, (size_t)(-1), + false, _("\ warning: syntax error, expected ';' after string")); - break; - } - } + break; + } + } else - { - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, gram_pos.line_number, (size_t)(-1), false, - _("\ + { + po_xerror (PO_SEVERITY_ERROR, NULL, + real_file_name, gram_pos.line_number, (size_t)(-1), false, + _("\ warning: syntax error, expected '=' or ';' after string")); - break; - } + break; + } } fp = NULL; @@ -958,6 +958,6 @@ warning: syntax error, expected '=' or ';' after string")); const struct catalog_input_format input_format_stringtable = { - stringtable_parse, /* parse */ - true /* produces_utf8 */ + stringtable_parse, /* parse */ + true /* produces_utf8 */ }; diff --git a/gettext-tools/src/read-tcl.c b/gettext-tools/src/read-tcl.c index 3b99490b0..ac74d1407 100644 --- a/gettext-tools/src/read-tcl.c +++ b/gettext-tools/src/read-tcl.c @@ -80,8 +80,8 @@ msgdomain_read_tcl (const char *locale_name, const char *directory) *p = *p - 'A' + 'a'; else if (*p == '.') { - *p = '\0'; - break; + *p = '\0'; + break; } file_name = xconcatenated_filename (directory, frobbed_locale_name, ".msg"); @@ -103,7 +103,7 @@ msgdomain_read_tcl (const char *locale_name, const char *directory) /* Open a pipe to the Tcl interpreter. */ child = create_pipe_in ("tclsh", "tclsh", argv, DEV_NULL, false, true, true, - fd); + fd); fp = fdopen (fd[0], "r"); if (fp == NULL) @@ -120,12 +120,12 @@ msgdomain_read_tcl (const char *locale_name, const char *directory) if (exitstatus != 0) { if (exitstatus == 2) - /* Special exitcode provided by msgunfmt.tcl. */ - error (EXIT_FAILURE, ENOENT, - _("error while opening \"%s\" for reading"), file_name); + /* Special exitcode provided by msgunfmt.tcl. */ + error (EXIT_FAILURE, ENOENT, + _("error while opening \"%s\" for reading"), file_name); else - error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"), - "tclsh", exitstatus); + error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"), + "tclsh", exitstatus); } free (tclscript); @@ -137,20 +137,20 @@ msgdomain_read_tcl (const char *locale_name, const char *directory) size_t j; for (j = 0; j < mlp->nitems; j++) - if (is_header (mlp->item[j])) - { - /* Found the header entry. */ - if (j > 0) - { - message_ty *header = mlp->item[j]; - size_t i; - - for (i = j; i > 0; i--) - mlp->item[i] = mlp->item[i - 1]; - mlp->item[0] = header; - } - break; - } + if (is_header (mlp->item[j])) + { + /* Found the header entry. */ + if (j > 0) + { + message_ty *header = mlp->item[j]; + size_t i; + + for (i = j; i > 0; i--) + mlp->item[i] = mlp->item[i - 1]; + mlp->item[0] = header; + } + break; + } } return mdlp; diff --git a/gettext-tools/src/recode-sr-latin.c b/gettext-tools/src/recode-sr-latin.c index 268f16724..6f656949f 100644 --- a/gettext-tools/src/recode-sr-latin.c +++ b/gettext-tools/src/recode-sr-latin.c @@ -90,7 +90,7 @@ main (int argc, char *argv[]) while ((opt = getopt_long (argc, argv, "hV", long_options, NULL)) != EOF) switch (opt) { - case '\0': /* Long option. */ + case '\0': /* Long option. */ break; case 'h': do_help = true; @@ -112,13 +112,13 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2006-2007"); + "2006-2007"); printf (_("Written by %s and %s.\n"), - /* TRANSLATORS: This is a proper name. The last name is - (with Unicode escapes) "\u0160egan" or (with HTML entities) - "Šegan". */ - proper_name_utf8 ("Danilo Segan", "Danilo \305\240egan"), - proper_name ("Bruno Haible")); + /* TRANSLATORS: This is a proper name. The last name is + (with Unicode escapes) "\u0160egan" or (with HTML entities) + "Šegan". */ + proper_name_utf8 ("Danilo Segan", "Danilo \305\240egan"), + proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -141,7 +141,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { /* xgettext: no-wrap */ @@ -188,8 +188,8 @@ Informative output:\n")); struct linebuffer { - size_t size; /* Allocated. */ - size_t length; /* Used. */ + size_t size; /* Allocated. */ + size_t length; /* Used. */ char *buffer; }; @@ -216,27 +216,27 @@ read_linebuffer (struct linebuffer *lb, FILE *stream) char *end = lb->buffer + lb->size; for (;;) - { - int c = getc (stream); - if (c == EOF) - { - if (p == lb->buffer || ferror (stream)) - return NULL; - break; - } - if (p == end) - { - size_t oldsize = lb->size; /* = p - lb->buffer */ - size_t newsize = 2 * oldsize + 40; - lb->buffer = (char *) xrealloc (lb->buffer, newsize); - lb->size = newsize; - p = lb->buffer + oldsize; - end = lb->buffer + newsize; - } - *p++ = c; - if (c == '\n') - break; - } + { + int c = getc (stream); + if (c == EOF) + { + if (p == lb->buffer || ferror (stream)) + return NULL; + break; + } + if (p == end) + { + size_t oldsize = lb->size; /* = p - lb->buffer */ + size_t newsize = 2 * oldsize + 40; + lb->buffer = (char *) xrealloc (lb->buffer, newsize); + lb->size = newsize; + p = lb->buffer + oldsize; + end = lb->buffer + newsize; + } + *p++ = c; + if (c == '\n') + break; + } lb->length = p - lb->buffer; return lb; @@ -278,21 +278,21 @@ process (FILE *stream) # if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION if (strcmp (locale_code, "EUC-KR") != 0) # endif - { - conv_to_utf8 = iconv_open ("UTF-8", locale_code); - /* TODO: Maybe append //TRANSLIT here? */ - conv_from_utf8 = iconv_open (locale_code, "UTF-8"); - } + { + conv_to_utf8 = iconv_open ("UTF-8", locale_code); + /* TODO: Maybe append //TRANSLIT here? */ + conv_from_utf8 = iconv_open (locale_code, "UTF-8"); + } if (conv_to_utf8 == (iconv_t)(-1)) - error (EXIT_FAILURE, 0, _("\ + error (EXIT_FAILURE, 0, _("\ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(), \ and iconv() does not support this conversion."), - locale_code, "UTF-8", basename (program_name)); + locale_code, "UTF-8", basename (program_name)); if (conv_from_utf8 == (iconv_t)(-1)) - error (EXIT_FAILURE, 0, _("\ + error (EXIT_FAILURE, 0, _("\ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(), \ and iconv() does not support this conversion."), - "UTF-8", locale_code, basename (program_name)); + "UTF-8", locale_code, basename (program_name)); last_utf8_line = NULL; last_utf8_line_len = 0; last_backconv_line = NULL; @@ -301,7 +301,7 @@ and iconv() does not support this conversion."), error (EXIT_FAILURE, 0, _("\ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(). \ This version was built without iconv()."), - locale_code, "UTF-8", basename (program_name)); + locale_code, "UTF-8", basename (program_name)); #endif } @@ -318,36 +318,36 @@ This version was built without iconv()."), /* Read a line. */ if (read_linebuffer (&lb, stream) == NULL) - break; + break; line = lb.buffer; line_len = lb.length; /* read_linebuffer always returns a non-void result. */ if (line_len == 0) - abort (); + abort (); #if HAVE_ICONV /* Convert it to UTF-8. */ if (need_code_conversion) - { - char *utf8_line = last_utf8_line; - size_t utf8_line_len = last_utf8_line_len; - - if (xmem_cd_iconv (line, line_len, conv_to_utf8, - &utf8_line, &utf8_line_len) != 0) - error (EXIT_FAILURE, errno, - _("input is not valid in \"%s\" encoding"), - locale_code); - if (utf8_line != last_utf8_line) - { - if (last_utf8_line != NULL) - free (last_utf8_line); - last_utf8_line = utf8_line; - last_utf8_line_len = utf8_line_len; - } - - line = utf8_line; - line_len = utf8_line_len; - } + { + char *utf8_line = last_utf8_line; + size_t utf8_line_len = last_utf8_line_len; + + if (xmem_cd_iconv (line, line_len, conv_to_utf8, + &utf8_line, &utf8_line_len) != 0) + error (EXIT_FAILURE, errno, + _("input is not valid in \"%s\" encoding"), + locale_code); + if (utf8_line != last_utf8_line) + { + if (last_utf8_line != NULL) + free (last_utf8_line); + last_utf8_line = utf8_line; + last_utf8_line_len = utf8_line_len; + } + + line = utf8_line; + line_len = utf8_line_len; + } #endif /* Apply the filter. */ @@ -356,28 +356,28 @@ This version was built without iconv()."), #if HAVE_ICONV /* Convert it back to the original encoding. */ if (need_code_conversion) - { - char *backconv_line = last_backconv_line; - size_t backconv_line_len = last_backconv_line_len; - - if (xmem_cd_iconv (filtered_line, filtered_line_len, conv_from_utf8, - &backconv_line, &backconv_line_len) != 0) - error (EXIT_FAILURE, errno, - _("error while converting from \"%s\" encoding to \"%s\" encoding"), - "UTF-8", locale_code); - if (backconv_line != last_backconv_line) - { - if (last_backconv_line != NULL) - free (last_backconv_line); - last_backconv_line = backconv_line; - last_backconv_line_len = backconv_line_len; - } - - fwrite (backconv_line, 1, backconv_line_len, stdout); - } + { + char *backconv_line = last_backconv_line; + size_t backconv_line_len = last_backconv_line_len; + + if (xmem_cd_iconv (filtered_line, filtered_line_len, conv_from_utf8, + &backconv_line, &backconv_line_len) != 0) + error (EXIT_FAILURE, errno, + _("error while converting from \"%s\" encoding to \"%s\" encoding"), + "UTF-8", locale_code); + if (backconv_line != last_backconv_line) + { + if (last_backconv_line != NULL) + free (last_backconv_line); + last_backconv_line = backconv_line; + last_backconv_line_len = backconv_line_len; + } + + fwrite (backconv_line, 1, backconv_line_len, stdout); + } else #endif - fwrite (filtered_line, 1, filtered_line_len, stdout); + fwrite (filtered_line, 1, filtered_line_len, stdout); free (filtered_line); } diff --git a/gettext-tools/src/str-list.c b/gettext-tools/src/str-list.c index a63212cc4..3f929c2cf 100644 --- a/gettext-tools/src/str-list.c +++ b/gettext-tools/src/str-list.c @@ -91,8 +91,8 @@ string_list_append_unique (string_list_ty *slp, const char *s) { slp->nitems_max = slp->nitems_max * 2 + 4; slp->item = (const char **) xrealloc (slp->item, - slp->nitems_max - * sizeof (slp->item[0])); + slp->nitems_max + * sizeof (slp->item[0])); } /* Add a copy of the string to the end of the list. */ @@ -182,7 +182,7 @@ string_list_concat_destroy (string_list_ty *slp) the terminator. */ char * string_list_join (const string_list_ty *slp, const char *separator, - char terminator, bool drop_redundant_terminator) + char terminator, bool drop_redundant_terminator) { size_t separator_len = strlen (separator); size_t len; @@ -194,7 +194,7 @@ string_list_join (const string_list_ty *slp, const char *separator, for (j = 0; j < slp->nitems; ++j) { if (j > 0) - len += separator_len; + len += separator_len; len += strlen (slp->item[j]); } if (terminator) @@ -204,19 +204,19 @@ string_list_join (const string_list_ty *slp, const char *separator, for (j = 0; j < slp->nitems; ++j) { if (j > 0) - { - memcpy (result + pos, separator, separator_len); - pos += separator_len; - } + { + memcpy (result + pos, separator, separator_len); + pos += separator_len; + } len = strlen (slp->item[j]); memcpy (result + pos, slp->item[j], len); pos += len; } if (terminator && !(drop_redundant_terminator - && slp->nitems > 0 - && (len = strlen (slp->item[slp->nitems - 1])) > 0 - && slp->item[slp->nitems - 1][len - 1] == terminator)) + && slp->nitems > 0 + && (len = strlen (slp->item[slp->nitems - 1])) > 0 + && slp->item[slp->nitems - 1][len - 1] == terminator)) result[pos++] = terminator; result[pos] = '\0'; return result; diff --git a/gettext-tools/src/str-list.h b/gettext-tools/src/str-list.h index 2e879f48d..5b7b75d91 100644 --- a/gettext-tools/src/str-list.h +++ b/gettext-tools/src/str-list.h @@ -74,7 +74,7 @@ extern char *string_list_concat_destroy (string_list_ty *slp); drop_redundant_terminator is true and the last string already ends with the terminator. */ extern char *string_list_join (const string_list_ty *slp, const char *separator, - char terminator, bool drop_redundant_terminator); + char terminator, bool drop_redundant_terminator); /* Return 1 if s is contained in the list of strings, 0 otherwise. */ extern bool string_list_member (const string_list_ty *slp, const char *s); diff --git a/gettext-tools/src/urlget.c b/gettext-tools/src/urlget.c index 813925740..43feac818 100644 --- a/gettext-tools/src/urlget.c +++ b/gettext-tools/src/urlget.c @@ -119,15 +119,15 @@ main (int argc, char *argv[]) while ((optchar = getopt_long (argc, argv, "hqV", long_options, NULL)) != EOF) switch (optchar) { - case '\0': /* Long option. */ + case '\0': /* Long option. */ break; - case 'h': /* --help */ + case 'h': /* --help */ do_help = true; break; - case 'q': /* --quiet / --silent */ + case 'q': /* --quiet / --silent */ verbose = false; break; - case 'V': /* --version */ + case 'V': /* --version */ do_version = true; break; default: @@ -145,7 +145,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "2001-2003, 2005-2009"); + "2001-2003, 2005-2009"); printf (_("Written by %s.\n"), proper_name ("Bruno Haible")); exit (EXIT_SUCCESS); } @@ -170,7 +170,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -197,7 +197,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); @@ -214,24 +214,24 @@ cat_file (const char *src_filename) src_fd = open (src_filename, O_RDONLY | O_BINARY); if (src_fd < 0) error (EXIT_FAILURE, errno, _("error while opening \"%s\" for reading"), - src_filename); + src_filename); for (;;) { ssize_t n_read = read (src_fd, buf, buf_size); if (n_read < 0) - { + { #ifdef EINTR - if (errno == EINTR) - continue; + if (errno == EINTR) + continue; #endif - error (EXIT_FAILURE, errno, _("error reading \"%s\""), src_filename); - } + error (EXIT_FAILURE, errno, _("error reading \"%s\""), src_filename); + } if (n_read == 0) - break; + break; if (full_write (STDOUT_FILENO, buf, n_read) < n_read) - error (EXIT_FAILURE, errno, _("error writing stdout")); + error (EXIT_FAILURE, errno, _("error writing stdout")); } if (close (src_fd) < 0) @@ -243,14 +243,14 @@ static int java_exitcode; static bool execute_it (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data) + const char *prog_path, char **prog_argv, + void *private_data) { (void) private_data; java_exitcode = execute (progname, prog_path, prog_argv, true, true, false, false, true, - false, NULL); + false, NULL); /* Exit code 0 means success, 2 means timed out. */ return !(java_exitcode == 0 || java_exitcode == 2); } @@ -295,18 +295,18 @@ fetch (const char *url, const char *file) /* Fetch the URL's contents. */ java_exitcode = 127; if (!execute_java_class (class_name, &gettextjar, 1, true, gettextjexedir, - args, - false, true, - execute_it, NULL)) + args, + false, true, + execute_it, NULL)) { - if (verbose) - { - if (java_exitcode == 0) - fprintf (stderr, _(" done.\n")); - else if (java_exitcode == 2) - fprintf (stderr, _(" timed out.\n")); - } - return; + if (verbose) + { + if (java_exitcode == 0) + fprintf (stderr, _(" done.\n")); + else if (java_exitcode == 2) + fprintf (stderr, _(" timed out.\n")); + } + return; } } @@ -317,40 +317,40 @@ fetch (const char *url, const char *file) if (!wget_tested) { - /* Test for presence of wget: "wget --version > /dev/null" */ - char *argv[3]; - int exitstatus; - - argv[0] = "wget"; - argv[1] = "--version"; - argv[2] = NULL; - exitstatus = execute ("wget", "wget", argv, false, false, true, true, - true, false, NULL); - wget_present = (exitstatus == 0); - wget_tested = true; + /* Test for presence of wget: "wget --version > /dev/null" */ + char *argv[3]; + int exitstatus; + + argv[0] = "wget"; + argv[1] = "--version"; + argv[2] = NULL; + exitstatus = execute ("wget", "wget", argv, false, false, true, true, + true, false, NULL); + wget_present = (exitstatus == 0); + wget_tested = true; } if (wget_present) { - char *argv[8]; - int exitstatus; - - argv[0] = "wget"; - argv[1] = "-q"; - argv[2] = "-O"; argv[3] = "-"; - argv[4] = "-T"; argv[5] = "30"; - argv[6] = (char *) url; - argv[7] = NULL; - exitstatus = execute ("wget", "wget", argv, true, false, false, false, - true, false, NULL); - if (exitstatus != 127) - { - if (exitstatus != 0) - goto failed; - if (verbose) - fprintf (stderr, _(" done.\n")); - return; - } + char *argv[8]; + int exitstatus; + + argv[0] = "wget"; + argv[1] = "-q"; + argv[2] = "-O"; argv[3] = "-"; + argv[4] = "-T"; argv[5] = "30"; + argv[6] = (char *) url; + argv[7] = NULL; + exitstatus = execute ("wget", "wget", argv, true, false, false, false, + true, false, NULL); + if (exitstatus != 127) + { + if (exitstatus != 0) + goto failed; + if (verbose) + fprintf (stderr, _(" done.\n")); + return; + } } } @@ -361,38 +361,38 @@ fetch (const char *url, const char *file) if (!lynx_tested) { - /* Test for presence of lynx: "lynx --version > /dev/null" */ - char *argv[3]; - int exitstatus; - - argv[0] = "lynx"; - argv[1] = "--version"; - argv[2] = NULL; - exitstatus = execute ("lynx", "lynx", argv, false, false, true, true, - true, false, NULL); - lynx_present = (exitstatus == 0); - lynx_tested = true; + /* Test for presence of lynx: "lynx --version > /dev/null" */ + char *argv[3]; + int exitstatus; + + argv[0] = "lynx"; + argv[1] = "--version"; + argv[2] = NULL; + exitstatus = execute ("lynx", "lynx", argv, false, false, true, true, + true, false, NULL); + lynx_present = (exitstatus == 0); + lynx_tested = true; } if (lynx_present) { - char *argv[4]; - int exitstatus; - - argv[0] = "lynx"; - argv[1] = "-source"; - argv[2] = (char *) url; - argv[3] = NULL; - exitstatus = execute ("lynx", "lynx", argv, true, false, false, false, - true, false, NULL); - if (exitstatus != 127) - { - if (exitstatus != 0) - goto failed; - if (verbose) - fprintf (stderr, _(" done.\n")); - return; - } + char *argv[4]; + int exitstatus; + + argv[0] = "lynx"; + argv[1] = "-source"; + argv[2] = (char *) url; + argv[3] = NULL; + exitstatus = execute ("lynx", "lynx", argv, true, false, false, false, + true, false, NULL); + if (exitstatus != 127) + { + if (exitstatus != 0) + goto failed; + if (verbose) + fprintf (stderr, _(" done.\n")); + return; + } } } @@ -403,38 +403,38 @@ fetch (const char *url, const char *file) if (!curl_tested) { - /* Test for presence of curl: "curl --version > /dev/null" */ - char *argv[3]; - int exitstatus; - - argv[0] = "curl"; - argv[1] = "--version"; - argv[2] = NULL; - exitstatus = execute ("curl", "curl", argv, false, false, true, true, - true, false, NULL); - curl_present = (exitstatus == 0 || exitstatus == 2); - curl_tested = true; + /* Test for presence of curl: "curl --version > /dev/null" */ + char *argv[3]; + int exitstatus; + + argv[0] = "curl"; + argv[1] = "--version"; + argv[2] = NULL; + exitstatus = execute ("curl", "curl", argv, false, false, true, true, + true, false, NULL); + curl_present = (exitstatus == 0 || exitstatus == 2); + curl_tested = true; } if (curl_present) { - char *argv[4]; - int exitstatus; - - argv[0] = "curl"; - argv[1] = "--silent"; - argv[2] = (char *) url; - argv[3] = NULL; - exitstatus = execute ("curl", "curl", argv, true, false, false, false, - true, false, NULL); - if (exitstatus != 127) - { - if (exitstatus != 0) - goto failed; - if (verbose) - fprintf (stderr, _(" done.\n")); - return; - } + char *argv[4]; + int exitstatus; + + argv[0] = "curl"; + argv[1] = "--silent"; + argv[2] = (char *) url; + argv[3] = NULL; + exitstatus = execute ("curl", "curl", argv, true, false, false, false, + true, false, NULL); + if (exitstatus != 127) + { + if (exitstatus != 0) + goto failed; + if (verbose) + fprintf (stderr, _(" done.\n")); + return; + } } } diff --git a/gettext-tools/src/write-catalog.c b/gettext-tools/src/write-catalog.c index a0f0d565f..77e31603d 100644 --- a/gettext-tools/src/write-catalog.c +++ b/gettext-tools/src/write-catalog.c @@ -91,8 +91,8 @@ message_page_width_set (size_t n) void msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, - catalog_output_format_ty output_syntax, - bool force, bool debug) + catalog_output_format_ty output_syntax, + bool force, bool debug) { bool to_stdout; @@ -104,158 +104,158 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, size_t k; for (k = 0; k < mdlp->nitems; k++) - { - message_list_ty *mlp = mdlp->item[k]->messages; + { + message_list_ty *mlp = mdlp->item[k]->messages; - if (!(mlp->nitems == 0 - || (mlp->nitems == 1 && is_header (mlp->item[0])))) - { - found_nonempty = true; - break; - } - } + if (!(mlp->nitems == 0 + || (mlp->nitems == 1 && is_header (mlp->item[0])))) + { + found_nonempty = true; + break; + } + } if (!found_nonempty) - return; + return; } /* Check whether the output format can accomodate all messages. */ if (!output_syntax->supports_multiple_domains && mdlp->nitems > 1) { if (output_syntax->alternative_is_po) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, _("\ + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, _("\ Cannot output multiple translation domains into a single file with the specified output format. Try using PO file syntax instead.")); else - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, _("\ + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, _("\ Cannot output multiple translation domains into a single file with the specified output format.")); } else { if (!output_syntax->supports_contexts) - { - const lex_pos_ty *has_context; - size_t k; - - has_context = NULL; - for (k = 0; k < mdlp->nitems; k++) - { - message_list_ty *mlp = mdlp->item[k]->messages; - size_t j; - - for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - - if (mp->msgctxt != NULL) - { - has_context = &mp->pos; - break; - } - } - } - - if (has_context != NULL) - { - error_with_progname = false; - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, - has_context->file_name, has_context->line_number, - (size_t)(-1), false, _("\ + { + const lex_pos_ty *has_context; + size_t k; + + has_context = NULL; + for (k = 0; k < mdlp->nitems; k++) + { + message_list_ty *mlp = mdlp->item[k]->messages; + size_t j; + + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + + if (mp->msgctxt != NULL) + { + has_context = &mp->pos; + break; + } + } + } + + if (has_context != NULL) + { + error_with_progname = false; + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, + has_context->file_name, has_context->line_number, + (size_t)(-1), false, _("\ message catalog has context dependent translations, but the output format does not support them.")); - error_with_progname = true; - } - } + error_with_progname = true; + } + } if (!output_syntax->supports_plurals) - { - const lex_pos_ty *has_plural; - size_t k; - - has_plural = NULL; - for (k = 0; k < mdlp->nitems; k++) - { - message_list_ty *mlp = mdlp->item[k]->messages; - size_t j; - - for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - - if (mp->msgid_plural != NULL) - { - has_plural = &mp->pos; - break; - } - } - } - - if (has_plural != NULL) - { - error_with_progname = false; - if (output_syntax->alternative_is_java_class) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, - has_plural->file_name, has_plural->line_number, - (size_t)(-1), false, _("\ + { + const lex_pos_ty *has_plural; + size_t k; + + has_plural = NULL; + for (k = 0; k < mdlp->nitems; k++) + { + message_list_ty *mlp = mdlp->item[k]->messages; + size_t j; + + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + + if (mp->msgid_plural != NULL) + { + has_plural = &mp->pos; + break; + } + } + } + + if (has_plural != NULL) + { + error_with_progname = false; + if (output_syntax->alternative_is_java_class) + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, + has_plural->file_name, has_plural->line_number, + (size_t)(-1), false, _("\ message catalog has plural form translations, but the output format does not support them. Try generating a Java class using \"msgfmt --java\", instead of a properties file.")); - else - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, - has_plural->file_name, has_plural->line_number, - (size_t)(-1), false, _("\ + else + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, + has_plural->file_name, has_plural->line_number, + (size_t)(-1), false, _("\ message catalog has plural form translations, but the output format does not support them.")); - error_with_progname = true; - } - } + error_with_progname = true; + } + } } to_stdout = (filename == NULL || strcmp (filename, "-") == 0 - || strcmp (filename, "/dev/stdout") == 0); + || strcmp (filename, "/dev/stdout") == 0); #if ENABLE_COLOR if (output_syntax->supports_color && (color_mode == color_yes - || (color_mode == color_tty && to_stdout && isatty (STDOUT_FILENO)))) + || (color_mode == color_tty && to_stdout && isatty (STDOUT_FILENO)))) { int fd; ostream_t stream; /* Open the output file. */ if (!to_stdout) - { - fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, - /* 0666 in portable POSIX notation: */ - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); - if (fd < 0) - { - const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("cannot create output file \"%s\""), - filename), - errno_description)); - } - } + { + fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, + /* 0666 in portable POSIX notation: */ + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + if (fd < 0) + { + const char *errno_description = strerror (errno); + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("cannot create output file \"%s\""), + filename), + errno_description)); + } + } else - { - fd = STDOUT_FILENO; - filename = _("standard output"); - } + { + fd = STDOUT_FILENO; + filename = _("standard output"); + } style_file_prepare (); stream = term_styled_ostream_create (fd, filename, style_file_name); if (stream == NULL) - stream = fd_ostream_create (fd, filename, true); + stream = fd_ostream_create (fd, filename, true); output_syntax->print (mdlp, stream, page_width, debug); ostream_free (stream); /* Make sure nothing went wrong. */ if (close (fd) < 0) - { - const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while writing \"%s\" file"), - filename), - errno_description)); - } + { + const char *errno_description = strerror (errno); + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("error while writing \"%s\" file"), + filename), + errno_description)); + } } else #endif @@ -265,61 +265,61 @@ message catalog has plural form translations, but the output format does not sup /* Open the output file. */ if (!to_stdout) - { - fp = fopen (filename, "wb"); - if (fp == NULL) - { - const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("cannot create output file \"%s\""), - filename), - errno_description)); - } - } + { + fp = fopen (filename, "wb"); + if (fp == NULL) + { + const char *errno_description = strerror (errno); + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("cannot create output file \"%s\""), + filename), + errno_description)); + } + } else - { - fp = stdout; - filename = _("standard output"); - } + { + fp = stdout; + filename = _("standard output"); + } stream = file_ostream_create (fp); #if ENABLE_COLOR if (output_syntax->supports_color && color_mode == color_html) - { - html_styled_ostream_t html_stream; - - /* Convert mdlp to UTF-8 encoding. */ - if (mdlp->encoding != po_charset_utf8) - { - mdlp = msgdomain_list_copy (mdlp, 0); - mdlp = iconv_msgdomain_list (mdlp, po_charset_utf8, false, NULL); - } - - style_file_prepare (); - html_stream = html_styled_ostream_create (stream, style_file_name); - output_syntax->print (mdlp, html_stream, page_width, debug); - ostream_free (html_stream); - } + { + html_styled_ostream_t html_stream; + + /* Convert mdlp to UTF-8 encoding. */ + if (mdlp->encoding != po_charset_utf8) + { + mdlp = msgdomain_list_copy (mdlp, 0); + mdlp = iconv_msgdomain_list (mdlp, po_charset_utf8, false, NULL); + } + + style_file_prepare (); + html_stream = html_styled_ostream_create (stream, style_file_name); + output_syntax->print (mdlp, html_stream, page_width, debug); + ostream_free (html_stream); + } else #endif - { - output_syntax->print (mdlp, stream, page_width, debug); - } + { + output_syntax->print (mdlp, stream, page_width, debug); + } ostream_free (stream); /* Make sure nothing went wrong. */ if (fwriteerror (fp)) - { - const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while writing \"%s\" file"), - filename), - errno_description)); - } + { + const char *errno_description = strerror (errno); + po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("error while writing \"%s\" file"), + filename), + errno_description)); + } } } @@ -361,7 +361,7 @@ msgdomain_list_sort_by_msgid (msgdomain_list_ty *mdlp) message_list_ty *mlp = mdlp->item[k]->messages; if (mlp->nitems > 0) - qsort (mlp->item, mlp->nitems, sizeof (mlp->item[0]), cmp_by_msgid); + qsort (mlp->item, mlp->nitems, sizeof (mlp->item[0]), cmp_by_msgid); } } @@ -392,13 +392,13 @@ msgdomain_list_sort_filepos (msgdomain_list_ty *mdlp) message_list_ty *mlp = mdlp->item[k]->messages; for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; + { + message_ty *mp = mlp->item[j]; - if (mp->filepos_count > 0) - qsort (mp->filepos, mp->filepos_count, sizeof (mp->filepos[0]), - cmp_filepos); - } + if (mp->filepos_count > 0) + qsort (mp->filepos, mp->filepos_count, sizeof (mp->filepos[0]), + cmp_filepos); + } } } @@ -416,7 +416,7 @@ cmp_by_filepos (const void *va, const void *vb) if (a->filepos_count == 0) { if (b->filepos_count != 0) - return -1; + return -1; } if (b->filepos_count == 0) return 1; @@ -464,6 +464,6 @@ msgdomain_list_sort_by_filepos (msgdomain_list_ty *mdlp) message_list_ty *mlp = mdlp->item[k]->messages; if (mlp->nitems > 0) - qsort (mlp->item, mlp->nitems, sizeof (mlp->item[0]), cmp_by_filepos); + qsort (mlp->item, mlp->nitems, sizeof (mlp->item[0]), cmp_by_filepos); } } diff --git a/gettext-tools/src/write-catalog.h b/gettext-tools/src/write-catalog.h index 35ed6bec8..804592c46 100644 --- a/gettext-tools/src/write-catalog.h +++ b/gettext-tools/src/write-catalog.h @@ -72,9 +72,9 @@ extern void parameters set by the functions above. */ extern void msgdomain_list_print (msgdomain_list_ty *mdlp, - const char *filename, - catalog_output_format_ty output_syntax, - bool force, bool debug); + const char *filename, + catalog_output_format_ty output_syntax, + bool force, bool debug); /* Sort MDLP destructively according to the given criterion. */ extern void diff --git a/gettext-tools/src/write-csharp.c b/gettext-tools/src/write-csharp.c index e031e65a3..3e5795690 100644 --- a/gettext-tools/src/write-csharp.c +++ b/gettext-tools/src/write-csharp.c @@ -116,8 +116,8 @@ construct_class_name (const char *resource_name) { char c = *p; if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_') - || (p > resource_name && c >= '0' && c <= '9'))) - valid = false; + || (p > resource_name && c >= '0' && c <= '9'))) + valid = false; } if (valid) return xstrdup (resource_name); @@ -132,35 +132,35 @@ construct_class_name (const char *resource_name) b = class_name; memcpy (b, "__UESCAPED__", 12); b += 12; while (str < str_limit) - { - ucs4_t uc; - str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); - if (uc >= 0x10000) - { - *b++ = '_'; - *b++ = 'U'; - *b++ = hexdigit[(uc >> 28) & 0x0f]; - *b++ = hexdigit[(uc >> 24) & 0x0f]; - *b++ = hexdigit[(uc >> 20) & 0x0f]; - *b++ = hexdigit[(uc >> 16) & 0x0f]; - *b++ = hexdigit[(uc >> 12) & 0x0f]; - *b++ = hexdigit[(uc >> 8) & 0x0f]; - *b++ = hexdigit[(uc >> 4) & 0x0f]; - *b++ = hexdigit[uc & 0x0f]; - } - else if (!((uc >= 'A' && uc <= 'Z') || (uc >= 'a' && uc <= 'z') - || (uc >= '0' && uc <= '9'))) - { - *b++ = '_'; - *b++ = 'u'; - *b++ = hexdigit[(uc >> 12) & 0x0f]; - *b++ = hexdigit[(uc >> 8) & 0x0f]; - *b++ = hexdigit[(uc >> 4) & 0x0f]; - *b++ = hexdigit[uc & 0x0f]; - } - else - *b++ = uc; - } + { + ucs4_t uc; + str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); + if (uc >= 0x10000) + { + *b++ = '_'; + *b++ = 'U'; + *b++ = hexdigit[(uc >> 28) & 0x0f]; + *b++ = hexdigit[(uc >> 24) & 0x0f]; + *b++ = hexdigit[(uc >> 20) & 0x0f]; + *b++ = hexdigit[(uc >> 16) & 0x0f]; + *b++ = hexdigit[(uc >> 12) & 0x0f]; + *b++ = hexdigit[(uc >> 8) & 0x0f]; + *b++ = hexdigit[(uc >> 4) & 0x0f]; + *b++ = hexdigit[uc & 0x0f]; + } + else if (!((uc >= 'A' && uc <= 'Z') || (uc >= 'a' && uc <= 'z') + || (uc >= '0' && uc <= '9'))) + { + *b++ = '_'; + *b++ = 'u'; + *b++ = hexdigit[(uc >> 12) & 0x0f]; + *b++ = hexdigit[(uc >> 8) & 0x0f]; + *b++ = hexdigit[(uc >> 4) & 0x0f]; + *b++ = hexdigit[uc & 0x0f]; + } + else + *b++ = uc; + } *b++ = '\0'; return (char *) xrealloc (class_name, b - class_name); } @@ -180,37 +180,37 @@ write_csharp_string (FILE *stream, const char *str) ucs4_t uc; str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); if (uc == 0x0000) - fprintf (stream, "\\0"); + fprintf (stream, "\\0"); else if (uc == 0x0007) - fprintf (stream, "\\a"); + fprintf (stream, "\\a"); else if (uc == 0x0008) - fprintf (stream, "\\b"); + fprintf (stream, "\\b"); else if (uc == 0x0009) - fprintf (stream, "\\t"); + fprintf (stream, "\\t"); else if (uc == 0x000a) - fprintf (stream, "\\n"); + fprintf (stream, "\\n"); else if (uc == 0x000b) - fprintf (stream, "\\v"); + fprintf (stream, "\\v"); else if (uc == 0x000c) - fprintf (stream, "\\f"); + fprintf (stream, "\\f"); else if (uc == 0x000d) - fprintf (stream, "\\r"); + fprintf (stream, "\\r"); else if (uc == 0x0022) - fprintf (stream, "\\\""); + fprintf (stream, "\\\""); else if (uc == 0x005c) - fprintf (stream, "\\\\"); + fprintf (stream, "\\\\"); else if (uc >= 0x0020 && uc < 0x007f) - fprintf (stream, "%c", (int) uc); + fprintf (stream, "%c", (int) uc); else if (uc < 0x10000) - fprintf (stream, "\\u%c%c%c%c", - hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], - hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); + fprintf (stream, "\\u%c%c%c%c", + hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], + hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); else - fprintf (stream, "\\U%c%c%c%c%c%c%c%c", - hexdigit[(uc >> 28) & 0x0f], hexdigit[(uc >> 24) & 0x0f], - hexdigit[(uc >> 20) & 0x0f], hexdigit[(uc >> 16) & 0x0f], - hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], - hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); + fprintf (stream, "\\U%c%c%c%c%c%c%c%c", + hexdigit[(uc >> 28) & 0x0f], hexdigit[(uc >> 24) & 0x0f], + hexdigit[(uc >> 20) & 0x0f], hexdigit[(uc >> 16) & 0x0f], + hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], + hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); } fprintf (stream, "\""); } @@ -258,19 +258,19 @@ write_csharp_msgstr (FILE *stream, message_ty *mp) fprintf (stream, "new System.String[] { "); for (p = mp->msgstr, first = true; - p < mp->msgstr + mp->msgstr_len; - p += strlen (p) + 1, first = false) - { - if (!first) - fprintf (stream, ", "); - write_csharp_string (stream, p); - } + p < mp->msgstr + mp->msgstr_len; + p += strlen (p) + 1, first = false) + { + if (!first) + fprintf (stream, ", "); + write_csharp_string (stream, p); + } fprintf (stream, " }"); } else { if (mp->msgstr_len != strlen (mp->msgstr) + 1) - abort (); + abort (); write_csharp_string (stream, mp->msgstr); } @@ -305,7 +305,7 @@ is_expression_boolean (struct expression *exp) return (exp->val.num == 0 || exp->val.num == 1); case qmop: return is_expression_boolean (exp->val.args[1]) - && is_expression_boolean (exp->val.args[2]); + && is_expression_boolean (exp->val.args[2]); default: abort (); } @@ -323,170 +323,170 @@ write_csharp_expression (FILE *stream, const struct expression *exp, bool as_boo { /* Emit a C# expression of type 'bool'. */ switch (exp->operation) - { - case num: - fprintf (stream, "%s", exp->val.num ? "true" : "false"); - return; - case lnot: - fprintf (stream, "(!"); - write_csharp_expression (stream, exp->val.args[0], true); - fprintf (stream, ")"); - return; - case less_than: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " < "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case greater_than: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " > "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case less_or_equal: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " <= "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case greater_or_equal: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " >= "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case equal: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " == "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case not_equal: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " != "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case land: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], true); - fprintf (stream, " && "); - write_csharp_expression (stream, exp->val.args[1], true); - fprintf (stream, ")"); - return; - case lor: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], true); - fprintf (stream, " || "); - write_csharp_expression (stream, exp->val.args[1], true); - fprintf (stream, ")"); - return; - case qmop: - if (is_expression_boolean (exp->val.args[1]) - && is_expression_boolean (exp->val.args[2])) - { - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], true); - fprintf (stream, " ? "); - write_csharp_expression (stream, exp->val.args[1], true); - fprintf (stream, " : "); - write_csharp_expression (stream, exp->val.args[2], true); - fprintf (stream, ")"); - return; - } - /*FALLTHROUGH*/ - case var: - case mult: - case divide: - case module: - case plus: - case minus: - fprintf (stream, "("); - write_csharp_expression (stream, exp, false); - fprintf (stream, " != 0)"); - return; - default: - abort (); - } + { + case num: + fprintf (stream, "%s", exp->val.num ? "true" : "false"); + return; + case lnot: + fprintf (stream, "(!"); + write_csharp_expression (stream, exp->val.args[0], true); + fprintf (stream, ")"); + return; + case less_than: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " < "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case greater_than: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " > "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case less_or_equal: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " <= "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case greater_or_equal: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " >= "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case equal: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " == "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case not_equal: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " != "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case land: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], true); + fprintf (stream, " && "); + write_csharp_expression (stream, exp->val.args[1], true); + fprintf (stream, ")"); + return; + case lor: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], true); + fprintf (stream, " || "); + write_csharp_expression (stream, exp->val.args[1], true); + fprintf (stream, ")"); + return; + case qmop: + if (is_expression_boolean (exp->val.args[1]) + && is_expression_boolean (exp->val.args[2])) + { + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], true); + fprintf (stream, " ? "); + write_csharp_expression (stream, exp->val.args[1], true); + fprintf (stream, " : "); + write_csharp_expression (stream, exp->val.args[2], true); + fprintf (stream, ")"); + return; + } + /*FALLTHROUGH*/ + case var: + case mult: + case divide: + case module: + case plus: + case minus: + fprintf (stream, "("); + write_csharp_expression (stream, exp, false); + fprintf (stream, " != 0)"); + return; + default: + abort (); + } } else { /* Emit a C# expression of type 'long'. */ switch (exp->operation) - { - case var: - fprintf (stream, "n"); - return; - case num: - fprintf (stream, "%lu", exp->val.num); - return; - case mult: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " * "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case divide: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " / "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case module: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " %% "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case plus: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " + "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case minus: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], false); - fprintf (stream, " - "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case qmop: - fprintf (stream, "("); - write_csharp_expression (stream, exp->val.args[0], true); - fprintf (stream, " ? "); - write_csharp_expression (stream, exp->val.args[1], false); - fprintf (stream, " : "); - write_csharp_expression (stream, exp->val.args[2], false); - fprintf (stream, ")"); - return; - case lnot: - case less_than: - case greater_than: - case less_or_equal: - case greater_or_equal: - case equal: - case not_equal: - case land: - case lor: - fprintf (stream, "("); - write_csharp_expression (stream, exp, true); - fprintf (stream, " ? 1 : 0)"); - return; - default: - abort (); - } + { + case var: + fprintf (stream, "n"); + return; + case num: + fprintf (stream, "%lu", exp->val.num); + return; + case mult: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " * "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case divide: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " / "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case module: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " %% "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case plus: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " + "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case minus: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], false); + fprintf (stream, " - "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case qmop: + fprintf (stream, "("); + write_csharp_expression (stream, exp->val.args[0], true); + fprintf (stream, " ? "); + write_csharp_expression (stream, exp->val.args[1], false); + fprintf (stream, " : "); + write_csharp_expression (stream, exp->val.args[2], false); + fprintf (stream, ")"); + return; + case lnot: + case less_than: + case greater_than: + case less_or_equal: + case greater_or_equal: + case equal: + case not_equal: + case land: + case lor: + fprintf (stream, "("); + write_csharp_expression (stream, exp, true); + fprintf (stream, " ? 1 : 0)"); + return; + default: + abort (); + } } } @@ -504,7 +504,7 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam size_t j; fprintf (stream, - "/* Automatically generated by GNU msgfmt. Do not modify! */\n"); + "/* Automatically generated by GNU msgfmt. Do not modify! */\n"); /* We have to use a "using" statement here, to avoid a bug in the pnet-0.6.0 compiler. */ @@ -528,7 +528,7 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam else class_name_last_part = class_name; fprintf (stream, "public class %s : GettextResourceSet {\n", - class_name_last_part); + class_name_last_part); /* Determine whether there are plural messages. */ plurals = 0; @@ -565,14 +565,14 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam fprintf (stream, " public static System.Collections.Hashtable GetMsgidPluralTable () {\n"); fprintf (stream, " System.Collections.Hashtable t = new System.Collections.Hashtable();\n"); for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgid_plural != NULL) - { - fprintf (stream, " t.Add("); - write_csharp_msgid (stream, mlp->item[j]); - fprintf (stream, ","); - write_csharp_string (stream, mlp->item[j]->msgid_plural); - fprintf (stream, ");\n"); - } + if (mlp->item[j]->msgid_plural != NULL) + { + fprintf (stream, " t.Add("); + write_csharp_msgid (stream, mlp->item[j]); + fprintf (stream, ","); + write_csharp_string (stream, mlp->item[j]->msgid_plural); + fprintf (stream, ");\n"); + } fprintf (stream, " return t;\n"); fprintf (stream, " }\n"); } @@ -586,7 +586,7 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam header_entry = message_list_search (mlp, NULL, ""); extract_plural_expression (header_entry ? header_entry->msgstr : NULL, - &plural, &nplurals); + &plural, &nplurals); fprintf (stream, " protected override long PluralEval (long n) {\n"); fprintf (stream, " return "); @@ -606,8 +606,8 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam int msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding, - const char *resource_name, const char *locale_name, - const char *directory) + const char *resource_name, const char *locale_name, + const char *directory) { int retval; struct temp_dir *tmpdir; @@ -650,26 +650,26 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding, char *p; for (p = culture_name; *p != '\0'; p++) if (*p == '_') - *p = '-'; + *p = '-'; if (strncmp (culture_name, "sr-CS", 5) == 0) memcpy (culture_name, "sr-SP", 5); p = strchr (culture_name, '@'); if (p != NULL) { - if (strcmp (p, "@latin") == 0) - strcpy (p, "-Latn"); - else if (strcmp (p, "@cyrillic") == 0) - strcpy (p, "-Cyrl"); + if (strcmp (p, "@latin") == 0) + strcpy (p, "-Latn"); + else if (strcmp (p, "@cyrillic") == 0) + strcpy (p, "-Cyrl"); } if (strcmp (culture_name, "sr-SP") == 0) { - free (culture_name); - culture_name = xstrdup ("sr-SP-Latn"); + free (culture_name); + culture_name = xstrdup ("sr-SP-Latn"); } else if (strcmp (culture_name, "uz-UZ") == 0) { - free (culture_name); - culture_name = xstrdup ("uz-UZ-Latn"); + free (culture_name); + culture_name = xstrdup ("uz-UZ-Latn"); } } @@ -682,13 +682,13 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding, /* Try to create the output directory if it does not yet exist. */ if (stat (output_dir, &statbuf) < 0 && errno == ENOENT) if (mkdir (output_dir, S_IRUSR | S_IWUSR | S_IXUSR - | S_IRGRP | S_IWGRP | S_IXGRP - | S_IROTH | S_IWOTH | S_IXOTH) < 0) - { - error (0, errno, _("failed to create directory \"%s\""), output_dir); - free (output_dir); - goto quit2; - } + | S_IRGRP | S_IWGRP | S_IXGRP + | S_IROTH | S_IWOTH | S_IXOTH) < 0) + { + error (0, errno, _("failed to create directory \"%s\""), output_dir); + free (output_dir); + goto quit2; + } output_file = xconcatenated_filename (output_dir, resource_name, ".resources.dll"); @@ -707,7 +707,7 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding, sprintf (class_name, "%s_%s", class_name_part1, culture_name); for (p = class_name + strlen (class_name_part1) + 1; *p != '\0'; p++) if (*p == '-') - *p = '_'; + *p = '_'; free (class_name_part1); } @@ -745,12 +745,12 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding, libdirs[0] = gettextlibdir; libraries[0] = "GNU.Gettext"; if (compile_csharp_class (csharp_sources, 1, libdirs, 1, libraries, 1, - output_file, true, false, verbose > 0)) + output_file, true, false, verbose > 0)) { if (!verbose) - error (0, 0, _("compilation of C# class failed, please try --verbose")); + error (0, 0, _("compilation of C# class failed, please try --verbose")); else - error (0, 0, _("compilation of C# class failed")); + error (0, 0, _("compilation of C# class failed")); goto quit3; } diff --git a/gettext-tools/src/write-csharp.h b/gettext-tools/src/write-csharp.h index b7b964726..55b71fb94 100644 --- a/gettext-tools/src/write-csharp.h +++ b/gettext-tools/src/write-csharp.h @@ -27,9 +27,9 @@ Return 0 if ok, nonzero on error. */ extern int msgdomain_write_csharp (message_list_ty *mlp, - const char *canon_encoding, - const char *resource_name, - const char *locale_name, - const char *directory); + const char *canon_encoding, + const char *resource_name, + const char *locale_name, + const char *directory); #endif /* _WRITE_CSHARP_H */ diff --git a/gettext-tools/src/write-java.c b/gettext-tools/src/write-java.c index d6c76144e..bd5965abe 100644 --- a/gettext-tools/src/write-java.c +++ b/gettext-tools/src/write-java.c @@ -87,15 +87,15 @@ check_resource_name (const char *name) { /* First character, see Character.isJavaIdentifierStart. */ if (!(c_isalpha (*p) || (*p == '$') || (*p == '_'))) - return -1; + return -1; /* Following characters, see Character.isJavaIdentifierPart. */ do - p++; + p++; while (c_isalpha (*p) || (*p == '$') || (*p == '_') || c_isdigit (*p)); if (*p == '\0') - break; + break; if (*p != '.') - return -1; + return -1; p++; ndots++; } @@ -120,16 +120,16 @@ string_hashcode (const char *str) ucs4_t uc; str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); if (uc < 0x10000) - /* Single UCS-2 'char'. */ - hash = 31 * hash + uc; + /* Single UCS-2 'char'. */ + hash = 31 * hash + uc; else - { - /* UTF-16 surrogate: two 'char's. */ - ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); - ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); - hash = 31 * hash + uc1; - hash = 31 * hash + uc2; - } + { + /* UTF-16 surrogate: two 'char's. */ + ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); + ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); + hash = 31 * hash + uc1; + hash = 31 * hash + uc2; + } } return hash & 0x7fffffff; } @@ -195,97 +195,97 @@ compute_hashsize (message_list_ty *mlp, bool *collisionp) unsigned int score; /* Premature end of the loop if all future scores are known to be - larger than the already reached best_score. This relies on the - ascending loop and on the fact that score >= hashsize. */ + larger than the already reached best_score. This relies on the + ascending loop and on the fact that score >= hashsize. */ if (hashsize >= best_score) - break; + break; bitmap = XNMALLOC (hashsize, char); memset (bitmap, 0, hashsize); score = 0; for (j = 0; j < n; j++) - { - unsigned int idx = hashcodes[j] % hashsize; - - if (bitmap[idx] != 0) - { - /* Collision. Cannot deal with it if hashsize is even. */ - if ((hashsize % 2) == 0) - /* Try next hashsize. */ - goto bad_hashsize; - else - { - unsigned int idx0 = idx; - unsigned int incr = 1 + (hashcodes[j] % (hashsize - 2)); - score += 2; /* Big penalty for the additional division */ - do - { - score++; /* Small penalty for each loop round */ - idx += incr; - if (idx >= hashsize) - idx -= hashsize; - if (idx == idx0) - /* Searching for a hole, we performed a whole round - across the table. This happens particularly - frequently if gcd(hashsize,incr) > 1. Try next - hashsize. */ - goto bad_hashsize; - } - while (bitmap[idx] != 0); - } - } - bitmap[idx] = 1; - } + { + unsigned int idx = hashcodes[j] % hashsize; + + if (bitmap[idx] != 0) + { + /* Collision. Cannot deal with it if hashsize is even. */ + if ((hashsize % 2) == 0) + /* Try next hashsize. */ + goto bad_hashsize; + else + { + unsigned int idx0 = idx; + unsigned int incr = 1 + (hashcodes[j] % (hashsize - 2)); + score += 2; /* Big penalty for the additional division */ + do + { + score++; /* Small penalty for each loop round */ + idx += incr; + if (idx >= hashsize) + idx -= hashsize; + if (idx == idx0) + /* Searching for a hole, we performed a whole round + across the table. This happens particularly + frequently if gcd(hashsize,incr) > 1. Try next + hashsize. */ + goto bad_hashsize; + } + while (bitmap[idx] != 0); + } + } + bitmap[idx] = 1; + } /* Big hashsize also gives a penalty. */ score = XXS * score + hashsize; /* If for any incr between 1 and hashsize - 2, an whole round - (idx0, idx0 + incr, ...) is occupied, and the lookup function - must deal with collisions, then some inputs would lead to - an endless loop in the lookup function. */ + (idx0, idx0 + incr, ...) is occupied, and the lookup function + must deal with collisions, then some inputs would lead to + an endless loop in the lookup function. */ if (score > hashsize) - { - unsigned int incr; - - /* Since the set { idx0, idx0 + incr, ... } depends only on idx0 - and gcd(hashsize,incr), we only need to conside incr that - divides hashsize. */ - for (incr = 1; incr <= hashsize / 2; incr++) - if ((hashsize % incr) == 0) - { - unsigned int idx0; - - for (idx0 = 0; idx0 < incr; idx0++) - { - bool full = true; - unsigned int idx; - - for (idx = idx0; idx < hashsize; idx += incr) - if (bitmap[idx] == 0) - { - full = false; - break; - } - if (full) - /* A whole round is occupied. */ - goto bad_hashsize; - } - } - } + { + unsigned int incr; + + /* Since the set { idx0, idx0 + incr, ... } depends only on idx0 + and gcd(hashsize,incr), we only need to conside incr that + divides hashsize. */ + for (incr = 1; incr <= hashsize / 2; incr++) + if ((hashsize % incr) == 0) + { + unsigned int idx0; + + for (idx0 = 0; idx0 < incr; idx0++) + { + bool full = true; + unsigned int idx; + + for (idx = idx0; idx < hashsize; idx += incr) + if (bitmap[idx] == 0) + { + full = false; + break; + } + if (full) + /* A whole round is occupied. */ + goto bad_hashsize; + } + } + } if (false) - bad_hashsize: - score = UINT_MAX; + bad_hashsize: + score = UINT_MAX; free (bitmap); if (score < best_score) - { - best_score = score; - best_hashsize = hashsize; - } + { + best_score = score; + best_hashsize = hashsize; + } } if (best_hashsize == 0 || best_score < best_hashsize) abort (); @@ -304,7 +304,7 @@ static int compare_index (const void *pval1, const void *pval2) { return (int)((const struct table_item *) pval1)->index - - (int)((const struct table_item *) pval2)->index; + - (int)((const struct table_item *) pval2)->index; } /* Compute the list of messages and table indices, sorted according to the @@ -323,20 +323,20 @@ compute_table_items (message_list_ty *mlp, unsigned int hashsize) for (j = 0; j < n; j++) { unsigned int hashcode = - msgid_hashcode (mlp->item[j]->msgctxt, mlp->item[j]->msgid); + msgid_hashcode (mlp->item[j]->msgctxt, mlp->item[j]->msgid); unsigned int idx = hashcode % hashsize; if (bitmap[idx] != 0) - { - unsigned int incr = 1 + (hashcode % (hashsize - 2)); - do - { - idx += incr; - if (idx >= hashsize) - idx -= hashsize; - } - while (bitmap[idx] != 0); - } + { + unsigned int incr = 1 + (hashcode % (hashsize - 2)); + do + { + idx += incr; + if (idx >= hashsize) + idx -= hashsize; + } + while (bitmap[idx] != 0); + } bitmap[idx] = 1; arr[j].index = idx; @@ -364,35 +364,35 @@ write_java_string (FILE *stream, const char *str) ucs4_t uc; str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); if (uc < 0x10000) - { - /* Single UCS-2 'char'. */ - if (uc == 0x000a) - fprintf (stream, "\\n"); - else if (uc == 0x000d) - fprintf (stream, "\\r"); - else if (uc == 0x0022) - fprintf (stream, "\\\""); - else if (uc == 0x005c) - fprintf (stream, "\\\\"); - else if (uc >= 0x0020 && uc < 0x007f) - fprintf (stream, "%c", (int) uc); - else - fprintf (stream, "\\u%c%c%c%c", - hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], - hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); - } + { + /* Single UCS-2 'char'. */ + if (uc == 0x000a) + fprintf (stream, "\\n"); + else if (uc == 0x000d) + fprintf (stream, "\\r"); + else if (uc == 0x0022) + fprintf (stream, "\\\""); + else if (uc == 0x005c) + fprintf (stream, "\\\\"); + else if (uc >= 0x0020 && uc < 0x007f) + fprintf (stream, "%c", (int) uc); + else + fprintf (stream, "\\u%c%c%c%c", + hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], + hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); + } else - { - /* UTF-16 surrogate: two 'char's. */ - ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); - ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); - fprintf (stream, "\\u%c%c%c%c", - hexdigit[(uc1 >> 12) & 0x0f], hexdigit[(uc1 >> 8) & 0x0f], - hexdigit[(uc1 >> 4) & 0x0f], hexdigit[uc1 & 0x0f]); - fprintf (stream, "\\u%c%c%c%c", - hexdigit[(uc2 >> 12) & 0x0f], hexdigit[(uc2 >> 8) & 0x0f], - hexdigit[(uc2 >> 4) & 0x0f], hexdigit[uc2 & 0x0f]); - } + { + /* UTF-16 surrogate: two 'char's. */ + ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); + ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); + fprintf (stream, "\\u%c%c%c%c", + hexdigit[(uc1 >> 12) & 0x0f], hexdigit[(uc1 >> 8) & 0x0f], + hexdigit[(uc1 >> 4) & 0x0f], hexdigit[uc1 & 0x0f]); + fprintf (stream, "\\u%c%c%c%c", + hexdigit[(uc2 >> 12) & 0x0f], hexdigit[(uc2 >> 8) & 0x0f], + hexdigit[(uc2 >> 4) & 0x0f], hexdigit[uc2 & 0x0f]); + } } fprintf (stream, "\""); } @@ -440,19 +440,19 @@ write_java_msgstr (FILE *stream, message_ty *mp) fprintf (stream, "new java.lang.String[] { "); for (p = mp->msgstr, first = true; - p < mp->msgstr + mp->msgstr_len; - p += strlen (p) + 1, first = false) - { - if (!first) - fprintf (stream, ", "); - write_java_string (stream, p); - } + p < mp->msgstr + mp->msgstr_len; + p += strlen (p) + 1, first = false) + { + if (!first) + fprintf (stream, ", "); + write_java_string (stream, p); + } fprintf (stream, " }"); } else { if (mp->msgstr_len != strlen (mp->msgstr) + 1) - abort (); + abort (); write_java_string (stream, mp->msgstr); } @@ -476,7 +476,7 @@ write_lookup_code (FILE *stream, unsigned int hashsize, bool collisions) fprintf (stream, " return table[idx + 1];\n"); fprintf (stream, " }\n"); fprintf (stream, " int incr = ((hash_val %% %d) + 1) << 1;\n", - hashsize - 2); + hashsize - 2); fprintf (stream, " for (;;) {\n"); fprintf (stream, " idx += incr;\n"); fprintf (stream, " if (idx >= %d)\n", 2 * hashsize); @@ -526,7 +526,7 @@ is_expression_boolean (struct expression *exp) return (exp->val.num == 0 || exp->val.num == 1); case qmop: return is_expression_boolean (exp->val.args[1]) - && is_expression_boolean (exp->val.args[2]); + && is_expression_boolean (exp->val.args[2]); default: abort (); } @@ -544,170 +544,170 @@ write_java_expression (FILE *stream, const struct expression *exp, bool as_boole { /* Emit a Java expression of type 'boolean'. */ switch (exp->operation) - { - case num: - fprintf (stream, "%s", exp->val.num ? "true" : "false"); - return; - case lnot: - fprintf (stream, "(!"); - write_java_expression (stream, exp->val.args[0], true); - fprintf (stream, ")"); - return; - case less_than: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " < "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case greater_than: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " > "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case less_or_equal: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " <= "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case greater_or_equal: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " >= "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case equal: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " == "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case not_equal: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " != "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case land: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], true); - fprintf (stream, " && "); - write_java_expression (stream, exp->val.args[1], true); - fprintf (stream, ")"); - return; - case lor: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], true); - fprintf (stream, " || "); - write_java_expression (stream, exp->val.args[1], true); - fprintf (stream, ")"); - return; - case qmop: - if (is_expression_boolean (exp->val.args[1]) - && is_expression_boolean (exp->val.args[2])) - { - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], true); - fprintf (stream, " ? "); - write_java_expression (stream, exp->val.args[1], true); - fprintf (stream, " : "); - write_java_expression (stream, exp->val.args[2], true); - fprintf (stream, ")"); - return; - } - /*FALLTHROUGH*/ - case var: - case mult: - case divide: - case module: - case plus: - case minus: - fprintf (stream, "("); - write_java_expression (stream, exp, false); - fprintf (stream, " != 0)"); - return; - default: - abort (); - } + { + case num: + fprintf (stream, "%s", exp->val.num ? "true" : "false"); + return; + case lnot: + fprintf (stream, "(!"); + write_java_expression (stream, exp->val.args[0], true); + fprintf (stream, ")"); + return; + case less_than: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " < "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case greater_than: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " > "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case less_or_equal: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " <= "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case greater_or_equal: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " >= "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case equal: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " == "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case not_equal: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " != "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case land: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], true); + fprintf (stream, " && "); + write_java_expression (stream, exp->val.args[1], true); + fprintf (stream, ")"); + return; + case lor: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], true); + fprintf (stream, " || "); + write_java_expression (stream, exp->val.args[1], true); + fprintf (stream, ")"); + return; + case qmop: + if (is_expression_boolean (exp->val.args[1]) + && is_expression_boolean (exp->val.args[2])) + { + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], true); + fprintf (stream, " ? "); + write_java_expression (stream, exp->val.args[1], true); + fprintf (stream, " : "); + write_java_expression (stream, exp->val.args[2], true); + fprintf (stream, ")"); + return; + } + /*FALLTHROUGH*/ + case var: + case mult: + case divide: + case module: + case plus: + case minus: + fprintf (stream, "("); + write_java_expression (stream, exp, false); + fprintf (stream, " != 0)"); + return; + default: + abort (); + } } else { /* Emit a Java expression of type 'long'. */ switch (exp->operation) - { - case var: - fprintf (stream, "n"); - return; - case num: - fprintf (stream, "%lu", exp->val.num); - return; - case mult: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " * "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case divide: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " / "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case module: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " %% "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case plus: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " + "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case minus: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], false); - fprintf (stream, " - "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, ")"); - return; - case qmop: - fprintf (stream, "("); - write_java_expression (stream, exp->val.args[0], true); - fprintf (stream, " ? "); - write_java_expression (stream, exp->val.args[1], false); - fprintf (stream, " : "); - write_java_expression (stream, exp->val.args[2], false); - fprintf (stream, ")"); - return; - case lnot: - case less_than: - case greater_than: - case less_or_equal: - case greater_or_equal: - case equal: - case not_equal: - case land: - case lor: - fprintf (stream, "("); - write_java_expression (stream, exp, true); - fprintf (stream, " ? 1 : 0)"); - return; - default: - abort (); - } + { + case var: + fprintf (stream, "n"); + return; + case num: + fprintf (stream, "%lu", exp->val.num); + return; + case mult: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " * "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case divide: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " / "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case module: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " %% "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case plus: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " + "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case minus: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], false); + fprintf (stream, " - "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, ")"); + return; + case qmop: + fprintf (stream, "("); + write_java_expression (stream, exp->val.args[0], true); + fprintf (stream, " ? "); + write_java_expression (stream, exp->val.args[1], false); + fprintf (stream, " : "); + write_java_expression (stream, exp->val.args[2], false); + fprintf (stream, ")"); + return; + case lnot: + case less_than: + case greater_than: + case less_or_equal: + case greater_or_equal: + case equal: + case not_equal: + case land: + case lor: + fprintf (stream, "("); + write_java_expression (stream, exp, true); + fprintf (stream, " ? 1 : 0)"); + return; + default: + abort (); + } } } @@ -718,14 +718,14 @@ write_java_expression (FILE *stream, const struct expression *exp, bool as_boole or X.Y.String. */ static void write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp, - bool assume_java2) + bool assume_java2) { const char *last_dot; unsigned int plurals; size_t j; fprintf (stream, - "/* Automatically generated by GNU msgfmt. Do not modify! */\n"); + "/* Automatically generated by GNU msgfmt. Do not modify! */\n"); last_dot = strrchr (class_name, '.'); if (last_dot != NULL) { @@ -754,90 +754,90 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp, hashsize = compute_hashsize (mlp, &collisions); /* Determines which indices in the table contain a message. The others - are null. */ + are null. */ table_items = compute_table_items (mlp, hashsize); /* Emit the table of pairs (msgid, msgstr). If there are plurals, - it is of type Object[], otherwise of type String[]. We use a static - code block because that makes less code: The Java compilers also - generate code for the 'null' entries, which is dumb. */ + it is of type Object[], otherwise of type String[]. We use a static + code block because that makes less code: The Java compilers also + generate code for the 'null' entries, which is dumb. */ table_eltype = (plurals ? "java.lang.Object" : "java.lang.String"); fprintf (stream, " private static final %s[] table;\n", table_eltype); fprintf (stream, " static {\n"); fprintf (stream, " %s[] t = new %s[%d];\n", table_eltype, table_eltype, - 2 * hashsize); + 2 * hashsize); for (j = 0; j < mlp->nitems; j++) - { - struct table_item *ti = &table_items[j]; - - fprintf (stream, " t[%d] = ", 2 * ti->index); - write_java_msgid (stream, ti->mp); - fprintf (stream, ";\n"); - fprintf (stream, " t[%d] = ", 2 * ti->index + 1); - write_java_msgstr (stream, ti->mp); - fprintf (stream, ";\n"); - } + { + struct table_item *ti = &table_items[j]; + + fprintf (stream, " t[%d] = ", 2 * ti->index); + write_java_msgid (stream, ti->mp); + fprintf (stream, ";\n"); + fprintf (stream, " t[%d] = ", 2 * ti->index + 1); + write_java_msgstr (stream, ti->mp); + fprintf (stream, ";\n"); + } fprintf (stream, " table = t;\n"); fprintf (stream, " }\n"); /* Emit the msgid_plural strings. Only used by msgunfmt. */ if (plurals) - { - bool first; - fprintf (stream, " public static final java.lang.String[] get_msgid_plural_table () {\n"); - fprintf (stream, " return new java.lang.String[] { "); - first = true; - for (j = 0; j < mlp->nitems; j++) - { - struct table_item *ti = &table_items[j]; - if (ti->mp->msgid_plural != NULL) - { - if (!first) - fprintf (stream, ", "); - write_java_string (stream, ti->mp->msgid_plural); - first = false; - } - } - fprintf (stream, " };\n"); - fprintf (stream, " }\n"); - } + { + bool first; + fprintf (stream, " public static final java.lang.String[] get_msgid_plural_table () {\n"); + fprintf (stream, " return new java.lang.String[] { "); + first = true; + for (j = 0; j < mlp->nitems; j++) + { + struct table_item *ti = &table_items[j]; + if (ti->mp->msgid_plural != NULL) + { + if (!first) + fprintf (stream, ", "); + write_java_string (stream, ti->mp->msgid_plural); + first = false; + } + } + fprintf (stream, " };\n"); + fprintf (stream, " }\n"); + } if (plurals) - { - /* Emit the lookup function. It is a common subroutine for - handleGetObject and ngettext. */ - fprintf (stream, " public java.lang.Object lookup (java.lang.String msgid) {\n"); - write_lookup_code (stream, hashsize, collisions); - fprintf (stream, " }\n"); - } + { + /* Emit the lookup function. It is a common subroutine for + handleGetObject and ngettext. */ + fprintf (stream, " public java.lang.Object lookup (java.lang.String msgid) {\n"); + write_lookup_code (stream, hashsize, collisions); + fprintf (stream, " }\n"); + } /* Emit the handleGetObject function. It is declared abstract in - ResourceBundle. It implements a local version of gettext. */ + ResourceBundle. It implements a local version of gettext. */ fprintf (stream, " public java.lang.Object handleGetObject (java.lang.String msgid) throws java.util.MissingResourceException {\n"); if (plurals) - { - fprintf (stream, " java.lang.Object value = lookup(msgid);\n"); - fprintf (stream, " return (value instanceof java.lang.String[] ? ((java.lang.String[])value)[0] : value);\n"); - } + { + fprintf (stream, " java.lang.Object value = lookup(msgid);\n"); + fprintf (stream, " return (value instanceof java.lang.String[] ? ((java.lang.String[])value)[0] : value);\n"); + } else - write_lookup_code (stream, hashsize, collisions); + write_lookup_code (stream, hashsize, collisions); fprintf (stream, " }\n"); /* Emit the getKeys function. It is declared abstract in ResourceBundle. - The inner class is not avoidable. */ + The inner class is not avoidable. */ fprintf (stream, " public java.util.Enumeration getKeys () {\n"); fprintf (stream, " return\n"); fprintf (stream, " new java.util.Enumeration() {\n"); fprintf (stream, " private int idx = 0;\n"); fprintf (stream, " { while (idx < %d && table[idx] == null) idx += 2; }\n", - 2 * hashsize); + 2 * hashsize); fprintf (stream, " public boolean hasMoreElements () {\n"); fprintf (stream, " return (idx < %d);\n", 2 * hashsize); fprintf (stream, " }\n"); fprintf (stream, " public java.lang.Object nextElement () {\n"); fprintf (stream, " java.lang.Object key = table[idx];\n"); fprintf (stream, " do idx += 2; while (idx < %d && table[idx] == null);\n", - 2 * hashsize); + 2 * hashsize); fprintf (stream, " return key;\n"); fprintf (stream, " }\n"); fprintf (stream, " };\n"); @@ -846,63 +846,63 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp, else { /* Java 1.1.x uses a different hash function. If compatibility with - this Java version is required, the hash table must be built at run time, - not at compile time. */ + this Java version is required, the hash table must be built at run time, + not at compile time. */ fprintf (stream, " private static final java.util.Hashtable table;\n"); fprintf (stream, " static {\n"); fprintf (stream, " java.util.Hashtable t = new java.util.Hashtable();\n"); for (j = 0; j < mlp->nitems; j++) - { - fprintf (stream, " t.put("); - write_java_msgid (stream, mlp->item[j]); - fprintf (stream, ","); - write_java_msgstr (stream, mlp->item[j]); - fprintf (stream, ");\n"); - } + { + fprintf (stream, " t.put("); + write_java_msgid (stream, mlp->item[j]); + fprintf (stream, ","); + write_java_msgstr (stream, mlp->item[j]); + fprintf (stream, ");\n"); + } fprintf (stream, " table = t;\n"); fprintf (stream, " }\n"); /* Emit the msgid_plural strings. Only used by msgunfmt. */ if (plurals) - { - fprintf (stream, " public static final java.util.Hashtable get_msgid_plural_table () {\n"); - fprintf (stream, " java.util.Hashtable p = new java.util.Hashtable();\n"); - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgid_plural != NULL) - { - fprintf (stream, " p.put("); - write_java_msgid (stream, mlp->item[j]); - fprintf (stream, ","); - write_java_string (stream, mlp->item[j]->msgid_plural); - fprintf (stream, ");\n"); - } - fprintf (stream, " return p;\n"); - fprintf (stream, " }\n"); - } + { + fprintf (stream, " public static final java.util.Hashtable get_msgid_plural_table () {\n"); + fprintf (stream, " java.util.Hashtable p = new java.util.Hashtable();\n"); + for (j = 0; j < mlp->nitems; j++) + if (mlp->item[j]->msgid_plural != NULL) + { + fprintf (stream, " p.put("); + write_java_msgid (stream, mlp->item[j]); + fprintf (stream, ","); + write_java_string (stream, mlp->item[j]->msgid_plural); + fprintf (stream, ");\n"); + } + fprintf (stream, " return p;\n"); + fprintf (stream, " }\n"); + } if (plurals) - { - /* Emit the lookup function. It is a common subroutine for - handleGetObject and ngettext. */ - fprintf (stream, " public java.lang.Object lookup (java.lang.String msgid) {\n"); - fprintf (stream, " return table.get(msgid);\n"); - fprintf (stream, " }\n"); - } + { + /* Emit the lookup function. It is a common subroutine for + handleGetObject and ngettext. */ + fprintf (stream, " public java.lang.Object lookup (java.lang.String msgid) {\n"); + fprintf (stream, " return table.get(msgid);\n"); + fprintf (stream, " }\n"); + } /* Emit the handleGetObject function. It is declared abstract in - ResourceBundle. It implements a local version of gettext. */ + ResourceBundle. It implements a local version of gettext. */ fprintf (stream, " public java.lang.Object handleGetObject (java.lang.String msgid) throws java.util.MissingResourceException {\n"); if (plurals) - { - fprintf (stream, " java.lang.Object value = table.get(msgid);\n"); - fprintf (stream, " return (value instanceof java.lang.String[] ? ((java.lang.String[])value)[0] : value);\n"); - } + { + fprintf (stream, " java.lang.Object value = table.get(msgid);\n"); + fprintf (stream, " return (value instanceof java.lang.String[] ? ((java.lang.String[])value)[0] : value);\n"); + } else - fprintf (stream, " return table.get(msgid);\n"); + fprintf (stream, " return table.get(msgid);\n"); fprintf (stream, " }\n"); /* Emit the getKeys function. It is declared abstract in - ResourceBundle. */ + ResourceBundle. */ fprintf (stream, " public java.util.Enumeration getKeys () {\n"); fprintf (stream, " return table.keys();\n"); fprintf (stream, " }\n"); @@ -917,7 +917,7 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp, header_entry = message_list_search (mlp, NULL, ""); extract_plural_expression (header_entry ? header_entry->msgstr : NULL, - &plural, &nplurals); + &plural, &nplurals); fprintf (stream, " public static long pluralEval (long n) {\n"); fprintf (stream, " return "); @@ -937,9 +937,9 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp, int msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding, - const char *resource_name, const char *locale_name, - const char *directory, - bool assume_java2) + const char *resource_name, const char *locale_name, + const char *directory, + bool assume_java2) { int retval; struct temp_dir *tmpdir; @@ -991,22 +991,22 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding, p = resource_name; for (i = 0; i < ndots; i++) { - const char *q = strchr (p, '.'); - size_t n = q - p; - char *part = (char *) xmalloca (n + 1); - memcpy (part, p, n); - part[n] = '\0'; - subdirs[i] = xconcatenated_filename (last_dir, part, NULL); - freea (part); - last_dir = subdirs[i]; - p = q + 1; + const char *q = strchr (p, '.'); + size_t n = q - p; + char *part = (char *) xmalloca (n + 1); + memcpy (part, p, n); + part[n] = '\0'; + subdirs[i] = xconcatenated_filename (last_dir, part, NULL); + freea (part); + last_dir = subdirs[i]; + p = q + 1; } if (locale_name != NULL) { - char *suffix = xasprintf ("_%s.java", locale_name); - java_file_name = xconcatenated_filename (last_dir, p, suffix); - free (suffix); + char *suffix = xasprintf ("_%s.java", locale_name); + java_file_name = xconcatenated_filename (last_dir, p, suffix); + free (suffix); } else java_file_name = xconcatenated_filename (last_dir, p, ".java"); @@ -1020,13 +1020,13 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding, for (i = 0; i < ndots; i++) { - register_temp_subdir (tmpdir, subdirs[i]); - if (mkdir (subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR) < 0) - { - error (0, errno, _("failed to create \"%s\""), subdirs[i]); - unregister_temp_subdir (tmpdir, subdirs[i]); - goto quit3; - } + register_temp_subdir (tmpdir, subdirs[i]); + if (mkdir (subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR) < 0) + { + error (0, errno, _("failed to create \"%s\""), subdirs[i]); + unregister_temp_subdir (tmpdir, subdirs[i]); + goto quit3; + } } } @@ -1054,13 +1054,13 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding, which is in a temporary directory in our case. */ java_sources[0] = java_file_name; if (compile_java_class (java_sources, 1, NULL, 0, "1.3", "1.1", directory, - true, false, true, verbose > 0)) + true, false, true, verbose > 0)) { if (!verbose) - error (0, 0, _("\ + error (0, 0, _("\ compilation of Java class failed, please try --verbose or set $JAVAC")); else - error (0, 0, _("\ + error (0, 0, _("\ compilation of Java class failed, please try to set $JAVAC")); goto quit3; } diff --git a/gettext-tools/src/write-java.h b/gettext-tools/src/write-java.h index 54b7179fd..830aa75f7 100644 --- a/gettext-tools/src/write-java.h +++ b/gettext-tools/src/write-java.h @@ -29,10 +29,10 @@ Return 0 if ok, nonzero on error. */ extern int msgdomain_write_java (message_list_ty *mlp, - const char *canon_encoding, - const char *resource_name, - const char *locale_name, - const char *directory, - bool assume_java2); + const char *canon_encoding, + const char *resource_name, + const char *locale_name, + const char *directory, + bool assume_java2); #endif /* _WRITE_JAVA_H */ diff --git a/gettext-tools/src/write-mo.c b/gettext-tools/src/write-mo.c index 5eba1a31b..ce2741528 100644 --- a/gettext-tools/src/write-mo.c +++ b/gettext-tools/src/write-mo.c @@ -57,10 +57,10 @@ #ifndef roundup # if defined __GNUC__ && __GNUC__ >= 2 # define roundup(x, y) ({typeof(x) _x = (x); typeof(y) _y = (y); \ - ((_x + _y - 1) / _y) * _y; }) + ((_x + _y - 1) / _y) * _y; }) # else # define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) -# endif /* GNU CC2 */ +# endif /* GNU CC2 */ #endif /* roundup */ @@ -82,8 +82,8 @@ bool no_hash_table; 'struct pre_sysdep_message'. */ enum { - M_ID = 0, /* msgid - the original string */ - M_STR = 1 /* msgstr - the translated string */ + M_ID = 0, /* msgid - the original string */ + M_STR = 1 /* msgstr - the translated string */ }; /* An intermediate data structure representing a 'struct string_desc'. */ @@ -105,7 +105,7 @@ static int compare_id (const void *pval1, const void *pval2) { return strcmp (((struct pre_message *) pval1)->str[M_ID].pointer, - ((struct pre_message *) pval2)->str[M_ID].pointer); + ((struct pre_message *) pval2)->str[M_ID].pointer); } @@ -156,7 +156,7 @@ write_table (FILE *output_file, message_list_ty *mlp) int minor_revision; bool omit_hash_table; nls_uint32 hash_tab_size; - struct mo_file_header header; /* Header of the .mo file to be written. */ + struct mo_file_header header; /* Header of the .mo file to be written. */ size_t header_size; size_t offset; struct string_desc *orig_tab; @@ -189,10 +189,10 @@ write_table (FILE *output_file, message_list_ty *mlp) msgctlen = (mp->msgctxt != NULL ? strlen (mp->msgctxt) + 1 : 0); msgctid = XNMALLOC (msgctlen + strlen (mp->msgid) + 1, char); if (mp->msgctxt != NULL) - { - memcpy (msgctid, mp->msgctxt, msgctlen - 1); - msgctid[msgctlen - 1] = MSGCTXT_SEPARATOR; - } + { + memcpy (msgctid, mp->msgctxt, msgctlen - 1); + msgctid[msgctlen - 1] = MSGCTXT_SEPARATOR; + } strcpy (msgctid + msgctlen, mp->msgid); msgctid_arr[j] = msgctid; @@ -202,165 +202,165 @@ write_table (FILE *output_file, message_list_ty *mlp) nintervals[M_STR] = 0; /* Test if mp contains system dependent strings and thus - requires the use of the .mo file minor revision 1. */ + requires the use of the .mo file minor revision 1. */ if (possible_format_p (mp->is_format[format_c]) - || possible_format_p (mp->is_format[format_objc])) - { - /* Check whether msgid or msgstr contain ISO C 99 - format string directives. No need to check msgid_plural, because - it is not accessed by the [n]gettext() function family. */ - const char *p_end; - const char *p; - - get_sysdep_c_format_directives (mp->msgid, false, - &intervals[M_ID], &nintervals[M_ID]); - if (msgctlen > 0) - { - struct interval *id_intervals = intervals[M_ID]; - size_t id_nintervals = nintervals[M_ID]; - - if (id_nintervals > 0) - { - unsigned int i; - - for (i = 0; i < id_nintervals; i++) - { - id_intervals[i].startpos += msgctlen; - id_intervals[i].endpos += msgctlen; - } - } - } - - p_end = mp->msgstr + mp->msgstr_len; - for (p = mp->msgstr; p < p_end; p += strlen (p) + 1) - { - struct interval *part_intervals; - size_t part_nintervals; - - get_sysdep_c_format_directives (p, true, - &part_intervals, - &part_nintervals); - if (part_nintervals > 0) - { - size_t d = p - mp->msgstr; - unsigned int i; - - intervals[M_STR] = - (struct interval *) - xrealloc (intervals[M_STR], - (nintervals[M_STR] + part_nintervals) - * sizeof (struct interval)); - for (i = 0; i < part_nintervals; i++) - { - intervals[M_STR][nintervals[M_STR] + i].startpos = - d + part_intervals[i].startpos; - intervals[M_STR][nintervals[M_STR] + i].endpos = - d + part_intervals[i].endpos; - } - nintervals[M_STR] += part_nintervals; - } - } - } + || possible_format_p (mp->is_format[format_objc])) + { + /* Check whether msgid or msgstr contain ISO C 99 + format string directives. No need to check msgid_plural, because + it is not accessed by the [n]gettext() function family. */ + const char *p_end; + const char *p; + + get_sysdep_c_format_directives (mp->msgid, false, + &intervals[M_ID], &nintervals[M_ID]); + if (msgctlen > 0) + { + struct interval *id_intervals = intervals[M_ID]; + size_t id_nintervals = nintervals[M_ID]; + + if (id_nintervals > 0) + { + unsigned int i; + + for (i = 0; i < id_nintervals; i++) + { + id_intervals[i].startpos += msgctlen; + id_intervals[i].endpos += msgctlen; + } + } + } + + p_end = mp->msgstr + mp->msgstr_len; + for (p = mp->msgstr; p < p_end; p += strlen (p) + 1) + { + struct interval *part_intervals; + size_t part_nintervals; + + get_sysdep_c_format_directives (p, true, + &part_intervals, + &part_nintervals); + if (part_nintervals > 0) + { + size_t d = p - mp->msgstr; + unsigned int i; + + intervals[M_STR] = + (struct interval *) + xrealloc (intervals[M_STR], + (nintervals[M_STR] + part_nintervals) + * sizeof (struct interval)); + for (i = 0; i < part_nintervals; i++) + { + intervals[M_STR][nintervals[M_STR] + i].startpos = + d + part_intervals[i].startpos; + intervals[M_STR][nintervals[M_STR] + i].endpos = + d + part_intervals[i].endpos; + } + nintervals[M_STR] += part_nintervals; + } + } + } if (nintervals[M_ID] > 0 || nintervals[M_STR] > 0) - { - /* System dependent string pair. */ - for (m = 0; m < 2; m++) - { - struct pre_sysdep_string *pre = - (struct pre_sysdep_string *) - xmalloc (xsum (sizeof (struct pre_sysdep_string), - xtimes (nintervals[m], - sizeof (struct pre_segment_pair)))); - const char *str; - size_t str_len; - size_t lastpos; - unsigned int i; - - if (m == M_ID) - { - str = msgctid; /* concatenation of mp->msgctxt + mp->msgid */ - str_len = strlen (msgctid) + 1; - } - else - { - str = mp->msgstr; - str_len = mp->msgstr_len; - } - - lastpos = 0; - pre->segmentcount = nintervals[m]; - for (i = 0; i < nintervals[m]; i++) - { - size_t length; - const char *pointer; - size_t r; - - pre->segments[i].segptr = str + lastpos; - pre->segments[i].segsize = intervals[m][i].startpos - lastpos; - - length = intervals[m][i].endpos - intervals[m][i].startpos; - pointer = str + intervals[m][i].startpos; - if (length >= 2 - && pointer[0] == '<' && pointer[length - 1] == '>') - { - /* Skip the '<' and '>' markers. */ - length -= 2; - pointer += 1; - } - - for (r = 0; r < n_sysdep_segments; r++) - if (sysdep_segments[r].length == length - && memcmp (sysdep_segments[r].pointer, pointer, length) - == 0) - break; - if (r == n_sysdep_segments) - { - n_sysdep_segments++; - sysdep_segments = - (struct pre_sysdep_segment *) - xrealloc (sysdep_segments, - n_sysdep_segments - * sizeof (struct pre_sysdep_segment)); - sysdep_segments[r].length = length; - sysdep_segments[r].pointer = pointer; - } - - pre->segments[i].sysdepref = r; - - if (length == 1 && *pointer == 'I') - have_outdigits = true; - - lastpos = intervals[m][i].endpos; - } - pre->segments[i].segptr = str + lastpos; - pre->segments[i].segsize = str_len - lastpos; - pre->segments[i].sysdepref = SEGMENTS_END; - - sysdep_msg_arr[n_sysdep_strings].str[m] = pre; - } - - sysdep_msg_arr[n_sysdep_strings].id_plural = mp->msgid_plural; - sysdep_msg_arr[n_sysdep_strings].id_plural_len = - (mp->msgid_plural != NULL ? strlen (mp->msgid_plural) + 1 : 0); - n_sysdep_strings++; - } + { + /* System dependent string pair. */ + for (m = 0; m < 2; m++) + { + struct pre_sysdep_string *pre = + (struct pre_sysdep_string *) + xmalloc (xsum (sizeof (struct pre_sysdep_string), + xtimes (nintervals[m], + sizeof (struct pre_segment_pair)))); + const char *str; + size_t str_len; + size_t lastpos; + unsigned int i; + + if (m == M_ID) + { + str = msgctid; /* concatenation of mp->msgctxt + mp->msgid */ + str_len = strlen (msgctid) + 1; + } + else + { + str = mp->msgstr; + str_len = mp->msgstr_len; + } + + lastpos = 0; + pre->segmentcount = nintervals[m]; + for (i = 0; i < nintervals[m]; i++) + { + size_t length; + const char *pointer; + size_t r; + + pre->segments[i].segptr = str + lastpos; + pre->segments[i].segsize = intervals[m][i].startpos - lastpos; + + length = intervals[m][i].endpos - intervals[m][i].startpos; + pointer = str + intervals[m][i].startpos; + if (length >= 2 + && pointer[0] == '<' && pointer[length - 1] == '>') + { + /* Skip the '<' and '>' markers. */ + length -= 2; + pointer += 1; + } + + for (r = 0; r < n_sysdep_segments; r++) + if (sysdep_segments[r].length == length + && memcmp (sysdep_segments[r].pointer, pointer, length) + == 0) + break; + if (r == n_sysdep_segments) + { + n_sysdep_segments++; + sysdep_segments = + (struct pre_sysdep_segment *) + xrealloc (sysdep_segments, + n_sysdep_segments + * sizeof (struct pre_sysdep_segment)); + sysdep_segments[r].length = length; + sysdep_segments[r].pointer = pointer; + } + + pre->segments[i].sysdepref = r; + + if (length == 1 && *pointer == 'I') + have_outdigits = true; + + lastpos = intervals[m][i].endpos; + } + pre->segments[i].segptr = str + lastpos; + pre->segments[i].segsize = str_len - lastpos; + pre->segments[i].sysdepref = SEGMENTS_END; + + sysdep_msg_arr[n_sysdep_strings].str[m] = pre; + } + + sysdep_msg_arr[n_sysdep_strings].id_plural = mp->msgid_plural; + sysdep_msg_arr[n_sysdep_strings].id_plural_len = + (mp->msgid_plural != NULL ? strlen (mp->msgid_plural) + 1 : 0); + n_sysdep_strings++; + } else - { - /* Static string pair. */ - msg_arr[nstrings].str[M_ID].pointer = msgctid; - msg_arr[nstrings].str[M_ID].length = strlen (msgctid) + 1; - msg_arr[nstrings].str[M_STR].pointer = mp->msgstr; - msg_arr[nstrings].str[M_STR].length = mp->msgstr_len; - msg_arr[nstrings].id_plural = mp->msgid_plural; - msg_arr[nstrings].id_plural_len = - (mp->msgid_plural != NULL ? strlen (mp->msgid_plural) + 1 : 0); - nstrings++; - } + { + /* Static string pair. */ + msg_arr[nstrings].str[M_ID].pointer = msgctid; + msg_arr[nstrings].str[M_ID].length = strlen (msgctid) + 1; + msg_arr[nstrings].str[M_STR].pointer = mp->msgstr; + msg_arr[nstrings].str[M_STR].length = mp->msgstr_len; + msg_arr[nstrings].id_plural = mp->msgid_plural; + msg_arr[nstrings].id_plural_len = + (mp->msgid_plural != NULL ? strlen (mp->msgid_plural) + 1 : 0); + nstrings++; + } for (m = 0; m < 2; m++) - if (intervals[m] != NULL) - free (intervals[m]); + if (intervals[m] != NULL) + free (intervals[m]); } /* Sort the table according to original string. */ @@ -397,16 +397,16 @@ write_table (FILE *output_file, message_list_ty *mlp) If we now choose M to be the next prime bigger than 4 / 3 * N, we get the values - 4 and 1.85 resp. + 4 and 1.85 resp. Because unsuccessful searches are unlikely this is a good value. Formulas: [Knuth, The Art of Computer Programming, Volume 3, - Sorting and Searching, 1973, Addison Wesley] */ + Sorting and Searching, 1973, Addison Wesley] */ if (!omit_hash_table) { hash_tab_size = next_prime ((mlp->nitems * 4) / 3); /* Ensure M > 2. */ if (hash_tab_size <= 2) - hash_tab_size = 3; + hash_tab_size = 3; } else hash_tab_size = 0; @@ -467,10 +467,10 @@ write_table (FILE *output_file, message_list_ty *mlp) /* System dependent string descriptors. */ sysdep_tab_offset = offset; for (m = 0; m < 2; m++) - for (j = 0; j < n_sysdep_strings; j++) - offset += sizeof (struct sysdep_string) - + sysdep_msg_arr[j].str[m]->segmentcount - * sizeof (struct segment_pair); + for (j = 0; j < n_sysdep_strings; j++) + offset += sizeof (struct sysdep_string) + + sysdep_msg_arr[j].str[m]->segmentcount + * sizeof (struct segment_pair); } end_offset = offset; @@ -490,13 +490,13 @@ write_table (FILE *output_file, message_list_ty *mlp) BSWAP32 (header.hash_tab_size); BSWAP32 (header.hash_tab_offset); if (minor_revision >= 1) - { - BSWAP32 (header.n_sysdep_segments); - BSWAP32 (header.sysdep_segments_offset); - BSWAP32 (header.n_sysdep_strings); - BSWAP32 (header.orig_sysdep_tab_offset); - BSWAP32 (header.trans_sysdep_tab_offset); - } + { + BSWAP32 (header.n_sysdep_segments); + BSWAP32 (header.sysdep_segments_offset); + BSWAP32 (header.n_sysdep_strings); + BSWAP32 (header.orig_sysdep_tab_offset); + BSWAP32 (header.trans_sysdep_tab_offset); + } } fwrite (&header, header_size, 1, output_file); @@ -507,7 +507,7 @@ write_table (FILE *output_file, message_list_ty *mlp) { offset = roundup (offset, alignment); orig_tab[j].length = - msg_arr[j].str[M_ID].length + msg_arr[j].id_plural_len; + msg_arr[j].str[M_ID].length + msg_arr[j].id_plural_len; orig_tab[j].offset = offset; offset += orig_tab[j].length; /* Subtract 1 because of the terminating NUL. */ @@ -516,8 +516,8 @@ write_table (FILE *output_file, message_list_ty *mlp) if (byteswap) for (j = 0; j < nstrings; j++) { - BSWAP32 (orig_tab[j].length); - BSWAP32 (orig_tab[j].offset); + BSWAP32 (orig_tab[j].length); + BSWAP32 (orig_tab[j].offset); } fwrite (orig_tab, nstrings * sizeof (struct string_desc), 1, output_file); @@ -536,8 +536,8 @@ write_table (FILE *output_file, message_list_ty *mlp) if (byteswap) for (j = 0; j < nstrings; j++) { - BSWAP32 (trans_tab[j].length); - BSWAP32 (trans_tab[j].offset); + BSWAP32 (trans_tab[j].length); + BSWAP32 (trans_tab[j].offset); } fwrite (trans_tab, nstrings * sizeof (struct string_desc), 1, output_file); @@ -554,32 +554,32 @@ write_table (FILE *output_file, message_list_ty *mlp) memset (hash_tab, '\0', hash_tab_size * sizeof (nls_uint32)); /* Insert all value in the hash table, following the algorithm described - above. */ + above. */ for (j = 0; j < nstrings; j++) - { - nls_uint32 hash_val = hash_string (msg_arr[j].str[M_ID].pointer); - nls_uint32 idx = hash_val % hash_tab_size; - - if (hash_tab[idx] != 0) - { - /* We need the second hashing function. */ - nls_uint32 incr = 1 + (hash_val % (hash_tab_size - 2)); - - do - if (idx >= hash_tab_size - incr) - idx -= hash_tab_size - incr; - else - idx += incr; - while (hash_tab[idx] != 0); - } - - hash_tab[idx] = j + 1; - } + { + nls_uint32 hash_val = hash_string (msg_arr[j].str[M_ID].pointer); + nls_uint32 idx = hash_val % hash_tab_size; + + if (hash_tab[idx] != 0) + { + /* We need the second hashing function. */ + nls_uint32 incr = 1 + (hash_val % (hash_tab_size - 2)); + + do + if (idx >= hash_tab_size - incr) + idx -= hash_tab_size - incr; + else + idx += incr; + while (hash_tab[idx] != 0); + } + + hash_tab[idx] = j + 1; + } /* Write the hash table out. */ if (byteswap) - for (j = 0; j < hash_tab_size; j++) - BSWAP32 (hash_tab[j]); + for (j = 0; j < hash_tab_size; j++) + BSWAP32 (hash_tab[j]); fwrite (hash_tab, hash_tab_size * sizeof (nls_uint32), 1, output_file); free (hash_tab); @@ -595,25 +595,25 @@ write_table (FILE *output_file, message_list_ty *mlp) /* Here output_file is at position header.sysdep_segments_offset. */ sysdep_segments_tab = - XNMALLOC (n_sysdep_segments, struct sysdep_segment); + XNMALLOC (n_sysdep_segments, struct sysdep_segment); for (i = 0; i < n_sysdep_segments; i++) - { - offset = roundup (offset, alignment); - /* The "+ 1" accounts for the trailing NUL byte. */ - sysdep_segments_tab[i].length = sysdep_segments[i].length + 1; - sysdep_segments_tab[i].offset = offset; - offset += sysdep_segments_tab[i].length; - } + { + offset = roundup (offset, alignment); + /* The "+ 1" accounts for the trailing NUL byte. */ + sysdep_segments_tab[i].length = sysdep_segments[i].length + 1; + sysdep_segments_tab[i].offset = offset; + offset += sysdep_segments_tab[i].length; + } if (byteswap) - for (i = 0; i < n_sysdep_segments; i++) - { - BSWAP32 (sysdep_segments_tab[i].length); - BSWAP32 (sysdep_segments_tab[i].offset); - } + for (i = 0; i < n_sysdep_segments; i++) + { + BSWAP32 (sysdep_segments_tab[i].length); + BSWAP32 (sysdep_segments_tab[i].offset); + } fwrite (sysdep_segments_tab, - n_sysdep_segments * sizeof (struct sysdep_segment), 1, - output_file); + n_sysdep_segments * sizeof (struct sysdep_segment), 1, + output_file); free (sysdep_segments_tab); @@ -621,70 +621,70 @@ write_table (FILE *output_file, message_list_ty *mlp) stoffset = sysdep_tab_offset; for (m = 0; m < 2; m++) - { - /* Here output_file is at position - m == M_ID -> header.orig_sysdep_tab_offset, - m == M_STR -> header.trans_sysdep_tab_offset. */ - - for (j = 0; j < n_sysdep_strings; j++) - { - sysdep_tab[j] = stoffset; - stoffset += sizeof (struct sysdep_string) - + sysdep_msg_arr[j].str[m]->segmentcount - * sizeof (struct segment_pair); - } - /* Write the table for original/translated sysdep string offsets. */ - if (byteswap) - for (j = 0; j < n_sysdep_strings; j++) - BSWAP32 (sysdep_tab[j]); - fwrite (sysdep_tab, n_sysdep_strings * sizeof (nls_uint32), 1, - output_file); - } + { + /* Here output_file is at position + m == M_ID -> header.orig_sysdep_tab_offset, + m == M_STR -> header.trans_sysdep_tab_offset. */ + + for (j = 0; j < n_sysdep_strings; j++) + { + sysdep_tab[j] = stoffset; + stoffset += sizeof (struct sysdep_string) + + sysdep_msg_arr[j].str[m]->segmentcount + * sizeof (struct segment_pair); + } + /* Write the table for original/translated sysdep string offsets. */ + if (byteswap) + for (j = 0; j < n_sysdep_strings; j++) + BSWAP32 (sysdep_tab[j]); + fwrite (sysdep_tab, n_sysdep_strings * sizeof (nls_uint32), 1, + output_file); + } free (sysdep_tab); /* Here output_file is at position sysdep_tab_offset. */ for (m = 0; m < 2; m++) - for (j = 0; j < n_sysdep_strings; j++) - { - struct pre_sysdep_message *msg = &sysdep_msg_arr[j]; - struct pre_sysdep_string *pre = msg->str[m]; - struct sysdep_string *str = - (struct sysdep_string *) - xmalloca (sizeof (struct sysdep_string) - + pre->segmentcount * sizeof (struct segment_pair)); - unsigned int i; - - offset = roundup (offset, alignment); - str->offset = offset; - for (i = 0; i <= pre->segmentcount; i++) - { - str->segments[i].segsize = pre->segments[i].segsize; - str->segments[i].sysdepref = pre->segments[i].sysdepref; - offset += str->segments[i].segsize; - } - if (m == M_ID && msg->id_plural_len > 0) - { - str->segments[pre->segmentcount].segsize += msg->id_plural_len; - offset += msg->id_plural_len; - } - if (byteswap) - { - BSWAP32 (str->offset); - for (i = 0; i <= pre->segmentcount; i++) - { - BSWAP32 (str->segments[i].segsize); - BSWAP32 (str->segments[i].sysdepref); - } - } - fwrite (str, - sizeof (struct sysdep_string) - + pre->segmentcount * sizeof (struct segment_pair), - 1, output_file); - - freea (str); - } + for (j = 0; j < n_sysdep_strings; j++) + { + struct pre_sysdep_message *msg = &sysdep_msg_arr[j]; + struct pre_sysdep_string *pre = msg->str[m]; + struct sysdep_string *str = + (struct sysdep_string *) + xmalloca (sizeof (struct sysdep_string) + + pre->segmentcount * sizeof (struct segment_pair)); + unsigned int i; + + offset = roundup (offset, alignment); + str->offset = offset; + for (i = 0; i <= pre->segmentcount; i++) + { + str->segments[i].segsize = pre->segments[i].segsize; + str->segments[i].sysdepref = pre->segments[i].sysdepref; + offset += str->segments[i].segsize; + } + if (m == M_ID && msg->id_plural_len > 0) + { + str->segments[pre->segmentcount].segsize += msg->id_plural_len; + offset += msg->id_plural_len; + } + if (byteswap) + { + BSWAP32 (str->offset); + for (i = 0; i <= pre->segmentcount; i++) + { + BSWAP32 (str->segments[i].segsize); + BSWAP32 (str->segments[i].sysdepref); + } + } + fwrite (str, + sizeof (struct sysdep_string) + + pre->segmentcount * sizeof (struct segment_pair), + 1, output_file); + + freea (str); + } } /* Here output_file is at position end_offset. */ @@ -708,10 +708,10 @@ write_table (FILE *output_file, message_list_ty *mlp) offset = roundup (offset, alignment); fwrite (msg_arr[j].str[M_ID].pointer, msg_arr[j].str[M_ID].length, 1, - output_file); + output_file); if (msg_arr[j].id_plural_len > 0) - fwrite (msg_arr[j].id_plural, msg_arr[j].id_plural_len, 1, - output_file); + fwrite (msg_arr[j].id_plural, msg_arr[j].id_plural_len, 1, + output_file); offset += msg_arr[j].str[M_ID].length + msg_arr[j].id_plural_len; } @@ -722,7 +722,7 @@ write_table (FILE *output_file, message_list_ty *mlp) offset = roundup (offset, alignment); fwrite (msg_arr[j].str[M_STR].pointer, msg_arr[j].str[M_STR].length, 1, - output_file); + output_file); offset += msg_arr[j].str[M_STR].length; } @@ -731,40 +731,40 @@ write_table (FILE *output_file, message_list_ty *mlp) unsigned int i; for (i = 0; i < n_sysdep_segments; i++) - { - fwrite (null, roundup (offset, alignment) - offset, 1, output_file); - offset = roundup (offset, alignment); + { + fwrite (null, roundup (offset, alignment) - offset, 1, output_file); + offset = roundup (offset, alignment); - fwrite (sysdep_segments[i].pointer, sysdep_segments[i].length, 1, - output_file); - fwrite (null, 1, 1, output_file); - offset += sysdep_segments[i].length + 1; - } + fwrite (sysdep_segments[i].pointer, sysdep_segments[i].length, 1, + output_file); + fwrite (null, 1, 1, output_file); + offset += sysdep_segments[i].length + 1; + } for (m = 0; m < 2; m++) - for (j = 0; j < n_sysdep_strings; j++) - { - struct pre_sysdep_message *msg = &sysdep_msg_arr[j]; - struct pre_sysdep_string *pre = msg->str[m]; - - fwrite (null, roundup (offset, alignment) - offset, 1, - output_file); - offset = roundup (offset, alignment); - - for (i = 0; i <= pre->segmentcount; i++) - { - fwrite (pre->segments[i].segptr, pre->segments[i].segsize, 1, - output_file); - offset += pre->segments[i].segsize; - } - if (m == M_ID && msg->id_plural_len > 0) - { - fwrite (msg->id_plural, msg->id_plural_len, 1, output_file); - offset += msg->id_plural_len; - } - - free (pre); - } + for (j = 0; j < n_sysdep_strings; j++) + { + struct pre_sysdep_message *msg = &sysdep_msg_arr[j]; + struct pre_sysdep_string *pre = msg->str[m]; + + fwrite (null, roundup (offset, alignment) - offset, 1, + output_file); + offset = roundup (offset, alignment); + + for (i = 0; i <= pre->segmentcount; i++) + { + fwrite (pre->segments[i].segptr, pre->segments[i].segsize, 1, + output_file); + offset += pre->segments[i].segsize; + } + if (m == M_ID && msg->id_plural_len > 0) + { + fwrite (msg->id_plural, msg->id_plural_len, 1, output_file); + offset += msg->id_plural_len; + } + + free (pre); + } } freea (null); @@ -778,8 +778,8 @@ write_table (FILE *output_file, message_list_ty *mlp) int msgdomain_write_mo (message_list_ty *mlp, - const char *domain_name, - const char *file_name) + const char *domain_name, + const char *file_name) { FILE *output_file; @@ -787,30 +787,30 @@ msgdomain_write_mo (message_list_ty *mlp, if (mlp->nitems != 0) { if (strcmp (domain_name, "-") == 0) - { - output_file = stdout; - SET_BINARY (fileno (output_file)); - } + { + output_file = stdout; + SET_BINARY (fileno (output_file)); + } else - { - output_file = fopen (file_name, "wb"); - if (output_file == NULL) - { - error (0, errno, _("error while opening \"%s\" for writing"), - file_name); - return 1; - } - } + { + output_file = fopen (file_name, "wb"); + if (output_file == NULL) + { + error (0, errno, _("error while opening \"%s\" for writing"), + file_name); + return 1; + } + } if (output_file != NULL) - { - write_table (output_file, mlp); - - /* Make sure nothing went wrong. */ - if (fwriteerror (output_file)) - error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"), - file_name); - } + { + write_table (output_file, mlp); + + /* Make sure nothing went wrong. */ + if (fwriteerror (output_file)) + error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"), + file_name); + } } return 0; diff --git a/gettext-tools/src/write-mo.h b/gettext-tools/src/write-mo.h index 6bd036032..b1ea8ea7e 100644 --- a/gettext-tools/src/write-mo.h +++ b/gettext-tools/src/write-mo.h @@ -37,7 +37,7 @@ extern bool no_hash_table; Return 0 if ok, nonzero on error. */ extern int msgdomain_write_mo (message_list_ty *mlp, - const char *domain_name, - const char *file_name); + const char *domain_name, + const char *file_name); #endif /* _WRITE_MO_H */ diff --git a/gettext-tools/src/write-po.c b/gettext-tools/src/write-po.c index cfbb09f84..1434c2c70 100644 --- a/gettext-tools/src/write-po.c +++ b/gettext-tools/src/write-po.c @@ -68,7 +68,7 @@ const char * make_format_description_string (enum is_format is_format, const char *lang, - bool debug) + bool debug) { static char result[100]; @@ -76,10 +76,10 @@ make_format_description_string (enum is_format is_format, const char *lang, { case possible: if (debug) - { - sprintf (result, "possible-%s-format", lang); - break; - } + { + sprintf (result, "possible-%s-format", lang); + break; + } /* FALLTHROUGH */ case yes_according_to_context: case yes: @@ -249,29 +249,29 @@ message_print_comment (const message_ty *mp, ostream_t stream) begin_css_class (stream, class_translator_comment); for (j = 0; j < mp->comment->nitems; ++j) - { - const char *s = mp->comment->item[j]; - do - { - const char *e; - ostream_write_str (stream, "#"); - if (*s != '\0') - ostream_write_str (stream, " "); - e = strchr (s, '\n'); - if (e == NULL) - { - ostream_write_str (stream, s); - s = NULL; - } - else - { - ostream_write_mem (stream, s, e - s); - s = e + 1; - } - ostream_write_str (stream, "\n"); - } - while (s != NULL); - } + { + const char *s = mp->comment->item[j]; + do + { + const char *e; + ostream_write_str (stream, "#"); + if (*s != '\0') + ostream_write_str (stream, " "); + e = strchr (s, '\n'); + if (e == NULL) + { + ostream_write_str (stream, s); + s = NULL; + } + else + { + ostream_write_mem (stream, s, e - s); + s = e + 1; + } + ostream_write_str (stream, "\n"); + } + while (s != NULL); + } end_css_class (stream, class_translator_comment); } @@ -290,14 +290,14 @@ message_print_comment_dot (const message_ty *mp, ostream_t stream) begin_css_class (stream, class_extracted_comment); for (j = 0; j < mp->comment_dot->nitems; ++j) - { - const char *s = mp->comment_dot->item[j]; - ostream_write_str (stream, "#."); - if (*s != '\0') - ostream_write_str (stream, " "); - ostream_write_str (stream, s); - ostream_write_str (stream, "\n"); - } + { + const char *s = mp->comment_dot->item[j]; + ostream_write_str (stream, "#."); + if (*s != '\0') + ostream_write_str (stream, " "); + ostream_write_str (stream, s); + ostream_write_str (stream, "\n"); + } end_css_class (stream, class_extracted_comment); } @@ -308,74 +308,74 @@ message_print_comment_dot (const message_ty *mp, ostream_t stream) void message_print_comment_filepos (const message_ty *mp, ostream_t stream, - bool uniforum, size_t page_width) + bool uniforum, size_t page_width) { if (mp->filepos_count != 0) { begin_css_class (stream, class_reference_comment); if (uniforum) - { - size_t j; - - for (j = 0; j < mp->filepos_count; ++j) - { - lex_pos_ty *pp = &mp->filepos[j]; - const char *cp = pp->file_name; - char *str; - - while (cp[0] == '.' && cp[1] == '/') - cp += 2; - ostream_write_str (stream, "# "); - begin_css_class (stream, class_reference); - /* There are two Sun formats to choose from: SunOS and - Solaris. Use the Solaris form here. */ - str = xasprintf ("File: %s, line: %ld", - cp, (long) pp->line_number); - ostream_write_str (stream, str); - end_css_class (stream, class_reference); - ostream_write_str (stream, "\n"); - free (str); - } - } + { + size_t j; + + for (j = 0; j < mp->filepos_count; ++j) + { + lex_pos_ty *pp = &mp->filepos[j]; + const char *cp = pp->file_name; + char *str; + + while (cp[0] == '.' && cp[1] == '/') + cp += 2; + ostream_write_str (stream, "# "); + begin_css_class (stream, class_reference); + /* There are two Sun formats to choose from: SunOS and + Solaris. Use the Solaris form here. */ + str = xasprintf ("File: %s, line: %ld", + cp, (long) pp->line_number); + ostream_write_str (stream, str); + end_css_class (stream, class_reference); + ostream_write_str (stream, "\n"); + free (str); + } + } else - { - size_t column; - size_t j; - - ostream_write_str (stream, "#:"); - column = 2; - for (j = 0; j < mp->filepos_count; ++j) - { - lex_pos_ty *pp; - char buffer[21]; - const char *cp; - size_t len; - - pp = &mp->filepos[j]; - cp = pp->file_name; - while (cp[0] == '.' && cp[1] == '/') - cp += 2; - /* Some xgettext input formats, like RST, lack line numbers. */ - if (pp->line_number == (size_t)(-1)) - buffer[0] = '\0'; - else - sprintf (buffer, ":%ld", (long) pp->line_number); - len = strlen (cp) + strlen (buffer) + 1; - if (column > 2 && column + len >= page_width) - { - ostream_write_str (stream, "\n#:"); - column = 2; - } - ostream_write_str (stream, " "); - begin_css_class (stream, class_reference); - ostream_write_str (stream, cp); - ostream_write_str (stream, buffer); - end_css_class (stream, class_reference); - column += len; - } - ostream_write_str (stream, "\n"); - } + { + size_t column; + size_t j; + + ostream_write_str (stream, "#:"); + column = 2; + for (j = 0; j < mp->filepos_count; ++j) + { + lex_pos_ty *pp; + char buffer[21]; + const char *cp; + size_t len; + + pp = &mp->filepos[j]; + cp = pp->file_name; + while (cp[0] == '.' && cp[1] == '/') + cp += 2; + /* Some xgettext input formats, like RST, lack line numbers. */ + if (pp->line_number == (size_t)(-1)) + buffer[0] = '\0'; + else + sprintf (buffer, ":%ld", (long) pp->line_number); + len = strlen (cp) + strlen (buffer) + 1; + if (column > 2 && column + len >= page_width) + { + ostream_write_str (stream, "\n#:"); + column = 2; + } + ostream_write_str (stream, " "); + begin_css_class (stream, class_reference); + ostream_write_str (stream, cp); + ostream_write_str (stream, buffer); + end_css_class (stream, class_reference); + column += len; + } + ostream_write_str (stream, "\n"); + } end_css_class (stream, class_reference_comment); } @@ -401,63 +401,63 @@ message_print_comment_flags (const message_ty *mp, ostream_t stream, bool debug) ostream_write_str (stream, "#,"); /* We don't print the fuzzy flag if the msgstr is empty. This - might be introduced by the user but we want to normalize the - output. */ + might be introduced by the user but we want to normalize the + output. */ if (mp->is_fuzzy && mp->msgstr[0] != '\0') - { - ostream_write_str (stream, " "); - begin_css_class (stream, class_flag); - begin_css_class (stream, class_fuzzy_flag); - ostream_write_str (stream, "fuzzy"); - end_css_class (stream, class_fuzzy_flag); - end_css_class (stream, class_flag); - first_flag = false; - } + { + ostream_write_str (stream, " "); + begin_css_class (stream, class_flag); + begin_css_class (stream, class_fuzzy_flag); + ostream_write_str (stream, "fuzzy"); + end_css_class (stream, class_fuzzy_flag); + end_css_class (stream, class_flag); + first_flag = false; + } for (i = 0; i < NFORMATS; i++) - if (significant_format_p (mp->is_format[i])) - { - if (!first_flag) - ostream_write_str (stream, ","); - - ostream_write_str (stream, " "); - begin_css_class (stream, class_flag); - ostream_write_str (stream, - make_format_description_string (mp->is_format[i], - format_language[i], - debug)); - end_css_class (stream, class_flag); - first_flag = false; - } + if (significant_format_p (mp->is_format[i])) + { + if (!first_flag) + ostream_write_str (stream, ","); + + ostream_write_str (stream, " "); + begin_css_class (stream, class_flag); + ostream_write_str (stream, + make_format_description_string (mp->is_format[i], + format_language[i], + debug)); + end_css_class (stream, class_flag); + first_flag = false; + } if (has_range_p (mp->range)) - { - char *string; + { + char *string; - if (!first_flag) - ostream_write_str (stream, ","); + if (!first_flag) + ostream_write_str (stream, ","); - ostream_write_str (stream, " "); - begin_css_class (stream, class_flag); - string = make_range_description_string (mp->range); - ostream_write_str (stream, string); - free (string); - end_css_class (stream, class_flag); - first_flag = false; - } + ostream_write_str (stream, " "); + begin_css_class (stream, class_flag); + string = make_range_description_string (mp->range); + ostream_write_str (stream, string); + free (string); + end_css_class (stream, class_flag); + first_flag = false; + } if (mp->do_wrap == no) - { - if (!first_flag) - ostream_write_str (stream, ","); - - ostream_write_str (stream, " "); - begin_css_class (stream, class_flag); - ostream_write_str (stream, - make_c_width_description_string (mp->do_wrap)); - end_css_class (stream, class_flag); - first_flag = false; - } + { + if (!first_flag) + ostream_write_str (stream, ","); + + ostream_write_str (stream, " "); + begin_css_class (stream, class_flag); + ostream_write_str (stream, + make_c_width_description_string (mp->do_wrap)); + end_css_class (stream, class_flag); + first_flag = false; + } ostream_write_str (stream, "\n"); @@ -520,7 +520,7 @@ memcpy_small (void *dst, const void *src, size_t n) *q = *p; if (--n > 0) - do *++q = *++p; while (--n > 0); + do *++q = *++p; while (--n > 0); } } @@ -535,7 +535,7 @@ memset_small (void *dst, char c, size_t n) *p = c; if (--n > 0) - do *++p = c; while (--n > 0); + do *++p = c; while (--n > 0); } } @@ -579,19 +579,19 @@ wrap (const message_ty *mp, ostream_t stream, /* Avoid glibc-2.1 bug with EUC-KR. */ # if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION if (strcmp (canon_charset, "EUC-KR") == 0) - conv = (iconv_t)(-1); + conv = (iconv_t)(-1); else # endif /* Avoid Solaris 2.9 bug with GB2312, EUC-TW, BIG5, BIG5-HKSCS, GBK, - GB18030. */ + GB18030. */ # if defined __sun && !defined _LIBICONV_VERSION if ( strcmp (canon_charset, "GB2312") == 0 - || strcmp (canon_charset, "EUC-TW") == 0 - || strcmp (canon_charset, "BIG5") == 0 - || strcmp (canon_charset, "BIG5-HKSCS") == 0 - || strcmp (canon_charset, "GBK") == 0 - || strcmp (canon_charset, "GB18030") == 0) - conv = (iconv_t)(-1); + || strcmp (canon_charset, "EUC-TW") == 0 + || strcmp (canon_charset, "BIG5") == 0 + || strcmp (canon_charset, "BIG5-HKSCS") == 0 + || strcmp (canon_charset, "GBK") == 0 + || strcmp (canon_charset, "GB18030") == 0) + conv = (iconv_t)(-1); else # endif /* Use iconv() to parse multibyte characters. */ @@ -615,54 +615,54 @@ wrap (const message_ty *mp, ostream_t stream, if (value[0] != '\0') { bool is_msgstr = - (strlen (name) >= 6 && memcmp (name, "msgstr", 6) == 0); - /* or equivalent: = (css_class == class_msgstr) */ + (strlen (name) >= 6 && memcmp (name, "msgstr", 6) == 0); + /* or equivalent: = (css_class == class_msgstr) */ size_t i; for (i = 0; i < NFORMATS; i++) - if (possible_format_p (mp->is_format[i])) - { - size_t len = strlen (value); - struct formatstring_parser *parser = formatstring_parsers[i]; - char *invalid_reason = NULL; - void *descr; - const char *fdp; - const char *fd_end; - char *fdap; - - fmtdir = XCALLOC (len, char); - descr = parser->parse (value, is_msgstr, fmtdir, &invalid_reason); - if (descr != NULL) - parser->free (descr); - - /* Locate the FMTDIR_* bits and transform the array to an array - of attributes. */ - fmtdirattr = XCALLOC (len, char); - fd_end = fmtdir + len; - for (fdp = fmtdir, fdap = fmtdirattr; fdp < fd_end; fdp++, fdap++) - if (*fdp & FMTDIR_START) - { - const char *fdq; - for (fdq = fdp; fdq < fd_end; fdq++) - if (*fdq & (FMTDIR_END | FMTDIR_ERROR)) - break; - if (!(fdq < fd_end)) - /* The ->parse method has determined the start of a - formatstring directive but not stored a bit indicating - its end. It is a bug in the ->parse method. */ - abort (); - if (*fdq & FMTDIR_ERROR) - memset (fdap, ATTR_INVALID_FORMAT_DIRECTIVE, fdq - fdp + 1); - else - memset (fdap, ATTR_FORMAT_DIRECTIVE, fdq - fdp + 1); - fdap += fdq - fdp; - fdp = fdq; - } - else - *fdap = 0; - - break; - } + if (possible_format_p (mp->is_format[i])) + { + size_t len = strlen (value); + struct formatstring_parser *parser = formatstring_parsers[i]; + char *invalid_reason = NULL; + void *descr; + const char *fdp; + const char *fd_end; + char *fdap; + + fmtdir = XCALLOC (len, char); + descr = parser->parse (value, is_msgstr, fmtdir, &invalid_reason); + if (descr != NULL) + parser->free (descr); + + /* Locate the FMTDIR_* bits and transform the array to an array + of attributes. */ + fmtdirattr = XCALLOC (len, char); + fd_end = fmtdir + len; + for (fdp = fmtdir, fdap = fmtdirattr; fdp < fd_end; fdp++, fdap++) + if (*fdp & FMTDIR_START) + { + const char *fdq; + for (fdq = fdp; fdq < fd_end; fdq++) + if (*fdq & (FMTDIR_END | FMTDIR_ERROR)) + break; + if (!(fdq < fd_end)) + /* The ->parse method has determined the start of a + formatstring directive but not stored a bit indicating + its end. It is a bug in the ->parse method. */ + abort (); + if (*fdq & FMTDIR_ERROR) + memset (fdap, ATTR_INVALID_FORMAT_DIRECTIVE, fdq - fdp + 1); + else + memset (fdap, ATTR_FORMAT_DIRECTIVE, fdq - fdp + 1); + fdap += fdq - fdp; + fdp = fdq; + } + else + *fdap = 0; + + break; + } } /* Loop over the '\n' delimited portions of value. */ @@ -689,236 +689,236 @@ wrap (const message_ty *mp, ostream_t stream, size_t i; for (es = s; *es != '\0'; ) - if (*es++ == '\n') - break; + if (*es++ == '\n') + break; /* Expand escape sequences in each portion. */ for (ep = s, portion_len = 0; ep < es; ep++) - { - char c = *ep; - if (is_escape (c)) - portion_len += 2; - else if (escape && !c_isprint ((unsigned char) c)) - portion_len += 4; - else if (c == '\\' || c == '"') - portion_len += 2; - else - { + { + char c = *ep; + if (is_escape (c)) + portion_len += 2; + else if (escape && !c_isprint ((unsigned char) c)) + portion_len += 4; + else if (c == '\\' || c == '"') + portion_len += 2; + else + { #if HAVE_ICONV - if (conv != (iconv_t)(-1)) - { - /* Skip over a complete multi-byte character. Don't - interpret the second byte of a multi-byte character as - ASCII. This is needed for the BIG5, BIG5-HKSCS, GBK, - GB18030, SHIFT_JIS, JOHAB encodings. */ - char scratchbuf[64]; - const char *inptr = ep; - size_t insize; - char *outptr = &scratchbuf[0]; - size_t outsize = sizeof (scratchbuf); - size_t res; - - res = (size_t)(-1); - for (insize = 1; inptr + insize <= es; insize++) - { - res = iconv (conv, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - if (!(res == (size_t)(-1) && errno == EINVAL)) - break; - /* We expect that no input bytes have been consumed - so far. */ - if (inptr != ep) - abort (); - } - if (res == (size_t)(-1)) - { - if (errno == EILSEQ) - { - po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false, - _("invalid multibyte sequence")); - continue; - } - else - abort (); - } - insize = inptr - ep; - portion_len += insize; - ep += insize - 1; - } - else + if (conv != (iconv_t)(-1)) + { + /* Skip over a complete multi-byte character. Don't + interpret the second byte of a multi-byte character as + ASCII. This is needed for the BIG5, BIG5-HKSCS, GBK, + GB18030, SHIFT_JIS, JOHAB encodings. */ + char scratchbuf[64]; + const char *inptr = ep; + size_t insize; + char *outptr = &scratchbuf[0]; + size_t outsize = sizeof (scratchbuf); + size_t res; + + res = (size_t)(-1); + for (insize = 1; inptr + insize <= es; insize++) + { + res = iconv (conv, + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); + if (!(res == (size_t)(-1) && errno == EINVAL)) + break; + /* We expect that no input bytes have been consumed + so far. */ + if (inptr != ep) + abort (); + } + if (res == (size_t)(-1)) + { + if (errno == EILSEQ) + { + po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false, + _("invalid multibyte sequence")); + continue; + } + else + abort (); + } + insize = inptr - ep; + portion_len += insize; + ep += insize - 1; + } + else #endif - { - if (weird_cjk - /* Special handling of encodings with CJK structure. */ - && ep + 2 <= es - && (unsigned char) ep[0] >= 0x80 - && (unsigned char) ep[1] >= 0x30) - { - portion_len += 2; - ep += 1; - } - else - portion_len += 1; - } - } - } + { + if (weird_cjk + /* Special handling of encodings with CJK structure. */ + && ep + 2 <= es + && (unsigned char) ep[0] >= 0x80 + && (unsigned char) ep[1] >= 0x30) + { + portion_len += 2; + ep += 1; + } + else + portion_len += 1; + } + } + } portion = XNMALLOC (portion_len, char); overrides = XNMALLOC (portion_len, char); attributes = XNMALLOC (portion_len, char); for (ep = s, pp = portion, op = overrides, ap = attributes; ep < es; ep++) - { - char c = *ep; - char attr = (fmtdirattr != NULL ? fmtdirattr[ep - value] : 0); - char brk = UC_BREAK_UNDEFINED; - /* Don't break inside format directives. */ - if (attr == ATTR_FORMAT_DIRECTIVE - && (fmtdir[ep - value] & FMTDIR_START) == 0) - brk = UC_BREAK_PROHIBITED; - if (is_escape (c)) - { - switch (c) - { - case '\a': c = 'a'; break; - case '\b': c = 'b'; break; - case '\f': c = 'f'; break; - case '\n': c = 'n'; break; - case '\r': c = 'r'; break; - case '\t': c = 't'; break; - case '\v': c = 'v'; break; - default: abort (); - } - *pp++ = '\\'; - *pp++ = c; - *op++ = brk; - *op++ = UC_BREAK_PROHIBITED; - *ap++ = attr | ATTR_ESCAPE_SEQUENCE; - *ap++ = attr | ATTR_ESCAPE_SEQUENCE; - /* We warn about any use of escape sequences beside - '\n' and '\t'. */ - if (c != 'n' && c != 't') - { - char *error_message = - xasprintf (_("\ + { + char c = *ep; + char attr = (fmtdirattr != NULL ? fmtdirattr[ep - value] : 0); + char brk = UC_BREAK_UNDEFINED; + /* Don't break inside format directives. */ + if (attr == ATTR_FORMAT_DIRECTIVE + && (fmtdir[ep - value] & FMTDIR_START) == 0) + brk = UC_BREAK_PROHIBITED; + if (is_escape (c)) + { + switch (c) + { + case '\a': c = 'a'; break; + case '\b': c = 'b'; break; + case '\f': c = 'f'; break; + case '\n': c = 'n'; break; + case '\r': c = 'r'; break; + case '\t': c = 't'; break; + case '\v': c = 'v'; break; + default: abort (); + } + *pp++ = '\\'; + *pp++ = c; + *op++ = brk; + *op++ = UC_BREAK_PROHIBITED; + *ap++ = attr | ATTR_ESCAPE_SEQUENCE; + *ap++ = attr | ATTR_ESCAPE_SEQUENCE; + /* We warn about any use of escape sequences beside + '\n' and '\t'. */ + if (c != 'n' && c != 't') + { + char *error_message = + xasprintf (_("\ internationalized messages should not contain the `\\%c' escape sequence"), - c); - po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, false, - error_message); - free (error_message); - } - } - else if (escape && !c_isprint ((unsigned char) c)) - { - *pp++ = '\\'; - *pp++ = '0' + (((unsigned char) c >> 6) & 7); - *pp++ = '0' + (((unsigned char) c >> 3) & 7); - *pp++ = '0' + ((unsigned char) c & 7); - *op++ = brk; - *op++ = UC_BREAK_PROHIBITED; - *op++ = UC_BREAK_PROHIBITED; - *op++ = UC_BREAK_PROHIBITED; - *ap++ = attr | ATTR_ESCAPE_SEQUENCE; - *ap++ = attr | ATTR_ESCAPE_SEQUENCE; - *ap++ = attr | ATTR_ESCAPE_SEQUENCE; - *ap++ = attr | ATTR_ESCAPE_SEQUENCE; - } - else if (c == '\\' || c == '"') - { - *pp++ = '\\'; - *pp++ = c; - *op++ = brk; - *op++ = UC_BREAK_PROHIBITED; - *ap++ = attr | ATTR_ESCAPE_SEQUENCE; - *ap++ = attr | ATTR_ESCAPE_SEQUENCE; - } - else - { + c); + po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, false, + error_message); + free (error_message); + } + } + else if (escape && !c_isprint ((unsigned char) c)) + { + *pp++ = '\\'; + *pp++ = '0' + (((unsigned char) c >> 6) & 7); + *pp++ = '0' + (((unsigned char) c >> 3) & 7); + *pp++ = '0' + ((unsigned char) c & 7); + *op++ = brk; + *op++ = UC_BREAK_PROHIBITED; + *op++ = UC_BREAK_PROHIBITED; + *op++ = UC_BREAK_PROHIBITED; + *ap++ = attr | ATTR_ESCAPE_SEQUENCE; + *ap++ = attr | ATTR_ESCAPE_SEQUENCE; + *ap++ = attr | ATTR_ESCAPE_SEQUENCE; + *ap++ = attr | ATTR_ESCAPE_SEQUENCE; + } + else if (c == '\\' || c == '"') + { + *pp++ = '\\'; + *pp++ = c; + *op++ = brk; + *op++ = UC_BREAK_PROHIBITED; + *ap++ = attr | ATTR_ESCAPE_SEQUENCE; + *ap++ = attr | ATTR_ESCAPE_SEQUENCE; + } + else + { #if HAVE_ICONV - if (conv != (iconv_t)(-1)) - { - /* Copy a complete multi-byte character. Don't - interpret the second byte of a multi-byte character as - ASCII. This is needed for the BIG5, BIG5-HKSCS, GBK, - GB18030, SHIFT_JIS, JOHAB encodings. */ - char scratchbuf[64]; - const char *inptr = ep; - size_t insize; - char *outptr = &scratchbuf[0]; - size_t outsize = sizeof (scratchbuf); - size_t res; - - res = (size_t)(-1); - for (insize = 1; inptr + insize <= es; insize++) - { - res = iconv (conv, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - if (!(res == (size_t)(-1) && errno == EINVAL)) - break; - /* We expect that no input bytes have been consumed - so far. */ - if (inptr != ep) - abort (); - } - if (res == (size_t)(-1)) - { - if (errno == EILSEQ) - { - po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, - false, _("invalid multibyte sequence")); - continue; - } - else - abort (); - } - insize = inptr - ep; - memcpy_small (pp, ep, insize); - pp += insize; - *op = brk; - memset_small (op + 1, UC_BREAK_PROHIBITED, insize - 1); - op += insize; - memset_small (ap, attr, insize); - ap += insize; - ep += insize - 1; - } - else + if (conv != (iconv_t)(-1)) + { + /* Copy a complete multi-byte character. Don't + interpret the second byte of a multi-byte character as + ASCII. This is needed for the BIG5, BIG5-HKSCS, GBK, + GB18030, SHIFT_JIS, JOHAB encodings. */ + char scratchbuf[64]; + const char *inptr = ep; + size_t insize; + char *outptr = &scratchbuf[0]; + size_t outsize = sizeof (scratchbuf); + size_t res; + + res = (size_t)(-1); + for (insize = 1; inptr + insize <= es; insize++) + { + res = iconv (conv, + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); + if (!(res == (size_t)(-1) && errno == EINVAL)) + break; + /* We expect that no input bytes have been consumed + so far. */ + if (inptr != ep) + abort (); + } + if (res == (size_t)(-1)) + { + if (errno == EILSEQ) + { + po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, + false, _("invalid multibyte sequence")); + continue; + } + else + abort (); + } + insize = inptr - ep; + memcpy_small (pp, ep, insize); + pp += insize; + *op = brk; + memset_small (op + 1, UC_BREAK_PROHIBITED, insize - 1); + op += insize; + memset_small (ap, attr, insize); + ap += insize; + ep += insize - 1; + } + else #endif - { - if (weird_cjk - /* Special handling of encodings with CJK structure. */ - && ep + 2 <= es - && (unsigned char) c >= 0x80 - && (unsigned char) ep[1] >= 0x30) - { - *pp++ = c; - ep += 1; - *pp++ = *ep; - *op++ = brk; - *op++ = UC_BREAK_PROHIBITED; - *ap++ = attr; - *ap++ = attr; - } - else - { - *pp++ = c; - *op++ = brk; - *ap++ = attr; - } - } - } - } + { + if (weird_cjk + /* Special handling of encodings with CJK structure. */ + && ep + 2 <= es + && (unsigned char) c >= 0x80 + && (unsigned char) ep[1] >= 0x30) + { + *pp++ = c; + ep += 1; + *pp++ = *ep; + *op++ = brk; + *op++ = UC_BREAK_PROHIBITED; + *ap++ = attr; + *ap++ = attr; + } + else + { + *pp++ = c; + *op++ = brk; + *ap++ = attr; + } + } + } + } /* Don't break immediately before the "\n" at the end. */ if (es > s && es[-1] == '\n') - overrides[portion_len - 2] = UC_BREAK_PROHIBITED; + overrides[portion_len - 2] = UC_BREAK_PROHIBITED; linebreaks = XNMALLOC (portion_len, char); /* Subsequent lines after a break are all indented. - See INDENT-S. */ + See INDENT-S. */ startcol_after_break = (line_prefix ? strlen (line_prefix) : 0); if (indent) - startcol_after_break = (startcol_after_break + extra_indent + 8) & ~7; + startcol_after_break = (startcol_after_break + extra_indent + 8) & ~7; startcol_after_break++; /* The line width. Allow room for the closing quote character. */ @@ -928,22 +928,22 @@ internationalized messages should not contain the `\\%c' escape sequence"), recompute: /* The line starts with different things depending on whether it - is the first line, and if we are using the indented style. - See INDENT-F. */ + is the first line, and if we are using the indented style. + See INDENT-F. */ startcol = (line_prefix ? strlen (line_prefix) : 0); if (first_line) - { - startcol += strlen (name); - if (indent) - startcol = (startcol + extra_indent + 8) & ~7; - else - startcol++; - } + { + startcol += strlen (name); + if (indent) + startcol = (startcol + extra_indent + 8) & ~7; + else + startcol++; + } else - { - if (indent) - startcol = (startcol + extra_indent + 8) & ~7; - } + { + if (indent) + startcol = (startcol + extra_indent + 8) & ~7; + } /* Allow room for the opening quote character. */ startcol++; /* Adjust for indentation of subsequent lines. */ @@ -951,200 +951,200 @@ internationalized messages should not contain the `\\%c' escape sequence"), /* Do line breaking on the portion. */ ulc_width_linebreaks (portion, portion_len, width, startcol, 0, - overrides, canon_charset, linebreaks); + overrides, canon_charset, linebreaks); /* If this is the first line, and we are not using the indented - style, and the line would wrap, then use an empty first line - and restart. */ + style, and the line would wrap, then use an empty first line + and restart. */ if (first_line && !indent - && portion_len > 0 - && (*es != '\0' - || startcol > width - || memchr (linebreaks, UC_BREAK_POSSIBLE, portion_len) != NULL)) - { - if (line_prefix != NULL) - ostream_write_str (stream, line_prefix); - begin_css_class (stream, css_class); - begin_css_class (stream, class_keyword); - ostream_write_str (stream, name); - end_css_class (stream, class_keyword); - ostream_write_str (stream, " "); - begin_css_class (stream, class_string); - ostream_write_str (stream, "\"\""); - end_css_class (stream, class_string); - end_css_class (stream, css_class); - ostream_write_str (stream, "\n"); - first_line = false; - /* Recompute startcol and linebreaks. */ - goto recompute; - } + && portion_len > 0 + && (*es != '\0' + || startcol > width + || memchr (linebreaks, UC_BREAK_POSSIBLE, portion_len) != NULL)) + { + if (line_prefix != NULL) + ostream_write_str (stream, line_prefix); + begin_css_class (stream, css_class); + begin_css_class (stream, class_keyword); + ostream_write_str (stream, name); + end_css_class (stream, class_keyword); + ostream_write_str (stream, " "); + begin_css_class (stream, class_string); + ostream_write_str (stream, "\"\""); + end_css_class (stream, class_string); + end_css_class (stream, css_class); + ostream_write_str (stream, "\n"); + first_line = false; + /* Recompute startcol and linebreaks. */ + goto recompute; + } /* Print the beginning of the line. This will depend on whether - this is the first line, and if the indented style is being - used. INDENT-F. */ + this is the first line, and if the indented style is being + used. INDENT-F. */ { - int currcol = 0; - - if (line_prefix != NULL) - { - ostream_write_str (stream, line_prefix); - currcol = strlen (line_prefix); - } - begin_css_class (stream, css_class); - if (first_line) - { - begin_css_class (stream, class_keyword); - ostream_write_str (stream, name); - currcol += strlen (name); - end_css_class (stream, class_keyword); - if (indent) - { - if (extra_indent > 0) - ostream_write_mem (stream, " ", extra_indent); - currcol += extra_indent; - ostream_write_mem (stream, " ", 8 - (currcol & 7)); - currcol = (currcol + 8) & ~7; - } - else - { - ostream_write_str (stream, " "); - currcol++; - } - first_line = false; - } - else - { - if (indent) - { - if (extra_indent > 0) - ostream_write_mem (stream, " ", extra_indent); - currcol += extra_indent; - ostream_write_mem (stream, " ", 8 - (currcol & 7)); - currcol = (currcol + 8) & ~7; - } - } + int currcol = 0; + + if (line_prefix != NULL) + { + ostream_write_str (stream, line_prefix); + currcol = strlen (line_prefix); + } + begin_css_class (stream, css_class); + if (first_line) + { + begin_css_class (stream, class_keyword); + ostream_write_str (stream, name); + currcol += strlen (name); + end_css_class (stream, class_keyword); + if (indent) + { + if (extra_indent > 0) + ostream_write_mem (stream, " ", extra_indent); + currcol += extra_indent; + ostream_write_mem (stream, " ", 8 - (currcol & 7)); + currcol = (currcol + 8) & ~7; + } + else + { + ostream_write_str (stream, " "); + currcol++; + } + first_line = false; + } + else + { + if (indent) + { + if (extra_indent > 0) + ostream_write_mem (stream, " ", extra_indent); + currcol += extra_indent; + ostream_write_mem (stream, " ", 8 - (currcol & 7)); + currcol = (currcol + 8) & ~7; + } + } } /* Print the portion itself, with linebreaks where necessary. */ { - char currattr = 0; - - begin_css_class (stream, class_string); - ostream_write_str (stream, "\""); - begin_css_class (stream, class_text); - - for (i = 0; i < portion_len; i++) - { - if (linebreaks[i] == UC_BREAK_POSSIBLE) - { - int currcol; - - /* Change currattr so that it becomes 0. */ - if (currattr & ATTR_ESCAPE_SEQUENCE) - { - end_css_class (stream, class_escape_sequence); - currattr &= ~ATTR_ESCAPE_SEQUENCE; - } - if (currattr & ATTR_FORMAT_DIRECTIVE) - { - end_css_class (stream, class_format_directive); - currattr &= ~ATTR_FORMAT_DIRECTIVE; - } - else if (currattr & ATTR_INVALID_FORMAT_DIRECTIVE) - { - end_css_class (stream, class_invalid_format_directive); - currattr &= ~ATTR_INVALID_FORMAT_DIRECTIVE; - } - if (!(currattr == 0)) - abort (); - - end_css_class (stream, class_text); - ostream_write_str (stream, "\""); - end_css_class (stream, class_string); - end_css_class (stream, css_class); - ostream_write_str (stream, "\n"); - currcol = 0; - /* INDENT-S. */ - if (line_prefix != NULL) - { - ostream_write_str (stream, line_prefix); - currcol = strlen (line_prefix); - } - begin_css_class (stream, css_class); - if (indent) - { - ostream_write_mem (stream, " ", 8 - (currcol & 7)); - currcol = (currcol + 8) & ~7; - } - begin_css_class (stream, class_string); - ostream_write_str (stream, "\""); - begin_css_class (stream, class_text); - } - /* Change currattr so that it matches attributes[i]. */ - if (attributes[i] != currattr) - { - /* class_escape_sequence occurs inside class_format_directive - and class_invalid_format_directive, so clear it first. */ - if (currattr & ATTR_ESCAPE_SEQUENCE) - { - end_css_class (stream, class_escape_sequence); - currattr &= ~ATTR_ESCAPE_SEQUENCE; - } - if (~attributes[i] & currattr & ATTR_FORMAT_DIRECTIVE) - { - end_css_class (stream, class_format_directive); - currattr &= ~ATTR_FORMAT_DIRECTIVE; - } - else if (~attributes[i] & currattr & ATTR_INVALID_FORMAT_DIRECTIVE) - { - end_css_class (stream, class_invalid_format_directive); - currattr &= ~ATTR_INVALID_FORMAT_DIRECTIVE; - } - if (attributes[i] & ~currattr & ATTR_FORMAT_DIRECTIVE) - { - begin_css_class (stream, class_format_directive); - currattr |= ATTR_FORMAT_DIRECTIVE; - } - else if (attributes[i] & ~currattr & ATTR_INVALID_FORMAT_DIRECTIVE) - { - begin_css_class (stream, class_invalid_format_directive); - currattr |= ATTR_INVALID_FORMAT_DIRECTIVE; - } - /* class_escape_sequence occurs inside class_format_directive - and class_invalid_format_directive, so set it last. */ - if (attributes[i] & ~currattr & ATTR_ESCAPE_SEQUENCE) - { - begin_css_class (stream, class_escape_sequence); - currattr |= ATTR_ESCAPE_SEQUENCE; - } - } - ostream_write_mem (stream, &portion[i], 1); - } - - /* Change currattr so that it becomes 0. */ - if (currattr & ATTR_ESCAPE_SEQUENCE) - { - end_css_class (stream, class_escape_sequence); - currattr &= ~ATTR_ESCAPE_SEQUENCE; - } - if (currattr & ATTR_FORMAT_DIRECTIVE) - { - end_css_class (stream, class_format_directive); - currattr &= ~ATTR_FORMAT_DIRECTIVE; - } - else if (currattr & ATTR_INVALID_FORMAT_DIRECTIVE) - { - end_css_class (stream, class_invalid_format_directive); - currattr &= ~ATTR_INVALID_FORMAT_DIRECTIVE; - } - if (!(currattr == 0)) - abort (); - - end_css_class (stream, class_text); - ostream_write_str (stream, "\""); - end_css_class (stream, class_string); - end_css_class (stream, css_class); - ostream_write_str (stream, "\n"); + char currattr = 0; + + begin_css_class (stream, class_string); + ostream_write_str (stream, "\""); + begin_css_class (stream, class_text); + + for (i = 0; i < portion_len; i++) + { + if (linebreaks[i] == UC_BREAK_POSSIBLE) + { + int currcol; + + /* Change currattr so that it becomes 0. */ + if (currattr & ATTR_ESCAPE_SEQUENCE) + { + end_css_class (stream, class_escape_sequence); + currattr &= ~ATTR_ESCAPE_SEQUENCE; + } + if (currattr & ATTR_FORMAT_DIRECTIVE) + { + end_css_class (stream, class_format_directive); + currattr &= ~ATTR_FORMAT_DIRECTIVE; + } + else if (currattr & ATTR_INVALID_FORMAT_DIRECTIVE) + { + end_css_class (stream, class_invalid_format_directive); + currattr &= ~ATTR_INVALID_FORMAT_DIRECTIVE; + } + if (!(currattr == 0)) + abort (); + + end_css_class (stream, class_text); + ostream_write_str (stream, "\""); + end_css_class (stream, class_string); + end_css_class (stream, css_class); + ostream_write_str (stream, "\n"); + currcol = 0; + /* INDENT-S. */ + if (line_prefix != NULL) + { + ostream_write_str (stream, line_prefix); + currcol = strlen (line_prefix); + } + begin_css_class (stream, css_class); + if (indent) + { + ostream_write_mem (stream, " ", 8 - (currcol & 7)); + currcol = (currcol + 8) & ~7; + } + begin_css_class (stream, class_string); + ostream_write_str (stream, "\""); + begin_css_class (stream, class_text); + } + /* Change currattr so that it matches attributes[i]. */ + if (attributes[i] != currattr) + { + /* class_escape_sequence occurs inside class_format_directive + and class_invalid_format_directive, so clear it first. */ + if (currattr & ATTR_ESCAPE_SEQUENCE) + { + end_css_class (stream, class_escape_sequence); + currattr &= ~ATTR_ESCAPE_SEQUENCE; + } + if (~attributes[i] & currattr & ATTR_FORMAT_DIRECTIVE) + { + end_css_class (stream, class_format_directive); + currattr &= ~ATTR_FORMAT_DIRECTIVE; + } + else if (~attributes[i] & currattr & ATTR_INVALID_FORMAT_DIRECTIVE) + { + end_css_class (stream, class_invalid_format_directive); + currattr &= ~ATTR_INVALID_FORMAT_DIRECTIVE; + } + if (attributes[i] & ~currattr & ATTR_FORMAT_DIRECTIVE) + { + begin_css_class (stream, class_format_directive); + currattr |= ATTR_FORMAT_DIRECTIVE; + } + else if (attributes[i] & ~currattr & ATTR_INVALID_FORMAT_DIRECTIVE) + { + begin_css_class (stream, class_invalid_format_directive); + currattr |= ATTR_INVALID_FORMAT_DIRECTIVE; + } + /* class_escape_sequence occurs inside class_format_directive + and class_invalid_format_directive, so set it last. */ + if (attributes[i] & ~currattr & ATTR_ESCAPE_SEQUENCE) + { + begin_css_class (stream, class_escape_sequence); + currattr |= ATTR_ESCAPE_SEQUENCE; + } + } + ostream_write_mem (stream, &portion[i], 1); + } + + /* Change currattr so that it becomes 0. */ + if (currattr & ATTR_ESCAPE_SEQUENCE) + { + end_css_class (stream, class_escape_sequence); + currattr &= ~ATTR_ESCAPE_SEQUENCE; + } + if (currattr & ATTR_FORMAT_DIRECTIVE) + { + end_css_class (stream, class_format_directive); + currattr &= ~ATTR_FORMAT_DIRECTIVE; + } + else if (currattr & ATTR_INVALID_FORMAT_DIRECTIVE) + { + end_css_class (stream, class_invalid_format_directive); + currattr &= ~ATTR_INVALID_FORMAT_DIRECTIVE; + } + if (!(currattr == 0)) + abort (); + + end_css_class (stream, class_text); + ostream_write_str (stream, "\""); + end_css_class (stream, class_string); + end_css_class (stream, css_class); + ostream_write_str (stream, "\n"); } free (linebreaks); @@ -1185,17 +1185,17 @@ print_blank_line (ostream_t stream) static void message_print (const message_ty *mp, ostream_t stream, - const char *charset, size_t page_width, bool blank_line, - bool debug) + const char *charset, size_t page_width, bool blank_line, + bool debug) { int extra_indent; /* Separate messages with a blank line. Uniforum doesn't like blank lines, so use an empty comment (unless there already is one). */ if (blank_line && (!uniforum - || mp->comment == NULL - || mp->comment->nitems == 0 - || mp->comment->item[0][0] != '\0')) + || mp->comment == NULL + || mp->comment->nitems == 0 + || mp->comment->item[0][0] != '\0')) print_blank_line (stream); if (is_header (mp)) @@ -1228,18 +1228,18 @@ message_print (const message_ty *mp, ostream_t stream, begin_css_class (stream, class_previous_comment); if (mp->prev_msgctxt != NULL) wrap (mp, stream, "#| ", 0, class_previous, "msgctxt", mp->prev_msgctxt, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset); if (mp->prev_msgid != NULL) wrap (mp, stream, "#| ", 0, class_previous, "msgid", mp->prev_msgid, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset); if (mp->prev_msgid_plural != NULL) wrap (mp, stream, "#| ", 0, class_previous, "msgid_plural", - mp->prev_msgid_plural, mp->do_wrap, page_width, charset); + mp->prev_msgid_plural, mp->do_wrap, page_width, charset); end_css_class (stream, class_previous_comment); extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL - || mp->prev_msgid_plural != NULL - ? 3 - : 0); + || mp->prev_msgid_plural != NULL + ? 3 + : 0); end_css_class (stream, class_comment); @@ -1250,7 +1250,7 @@ message_print (const message_ty *mp, ostream_t stream, && po_charset_canonicalize (charset) != po_charset_utf8) { char *warning_message = - xasprintf (_("\ + xasprintf (_("\ The following msgctxt contains non-ASCII characters.\n\ This will cause problems to translators who use a character encoding\n\ different from yours. Consider using a pure ASCII msgctxt instead.\n\ @@ -1262,7 +1262,7 @@ different from yours. Consider using a pure ASCII msgctxt instead.\n\ && po_charset_canonicalize (charset) != po_charset_utf8) { char *warning_message = - xasprintf (_("\ + xasprintf (_("\ The following msgid contains non-ASCII characters.\n\ This will cause problems to translators who use a character encoding\n\ different from yours. Consider using a pure ASCII msgid instead.\n\ @@ -1272,16 +1272,16 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ } if (mp->msgctxt != NULL) wrap (mp, stream, NULL, extra_indent, class_msgid, "msgctxt", mp->msgctxt, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset); wrap (mp, stream, NULL, extra_indent, class_msgid, "msgid", mp->msgid, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset); if (mp->msgid_plural != NULL) wrap (mp, stream, NULL, extra_indent, class_msgid, "msgid_plural", - mp->msgid_plural, mp->do_wrap, page_width, charset); + mp->msgid_plural, mp->do_wrap, page_width, charset); if (mp->msgid_plural == NULL) wrap (mp, stream, NULL, extra_indent, class_msgstr, "msgstr", mp->msgstr, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset); else { char prefix_buf[20]; @@ -1289,13 +1289,13 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ const char *p; for (p = mp->msgstr, i = 0; - p < mp->msgstr + mp->msgstr_len; - p += strlen (p) + 1, i++) - { - sprintf (prefix_buf, "msgstr[%u]", i); - wrap (mp, stream, NULL, extra_indent, class_msgstr, prefix_buf, p, - mp->do_wrap, page_width, charset); - } + p < mp->msgstr + mp->msgstr_len; + p += strlen (p) + 1, i++) + { + sprintf (prefix_buf, "msgstr[%u]", i); + wrap (mp, stream, NULL, extra_indent, class_msgstr, prefix_buf, p, + mp->do_wrap, page_width, charset); + } } if (is_header (mp)) @@ -1311,7 +1311,7 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ static void message_print_obsolete (const message_ty *mp, ostream_t stream, - const char *charset, size_t page_width, bool blank_line) + const char *charset, size_t page_width, bool blank_line) { int extra_indent; @@ -1345,10 +1345,10 @@ message_print_obsolete (const message_ty *mp, ostream_t stream, ostream_write_str (stream, "#,"); if (mp->is_fuzzy) - { - ostream_write_str (stream, " fuzzy"); - first = false; - } + { + ostream_write_str (stream, " fuzzy"); + first = false; + } ostream_write_str (stream, "\n"); } @@ -1358,18 +1358,18 @@ message_print_obsolete (const message_ty *mp, ostream_t stream, begin_css_class (stream, class_previous_comment); if (mp->prev_msgctxt != NULL) wrap (mp, stream, "#~| ", 0, class_previous, "msgctxt", mp->prev_msgctxt, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset); if (mp->prev_msgid != NULL) wrap (mp, stream, "#~| ", 0, class_previous, "msgid", mp->prev_msgid, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset); if (mp->prev_msgid_plural != NULL) wrap (mp, stream, "#~| ", 0, class_previous, "msgid_plural", - mp->prev_msgid_plural, mp->do_wrap, page_width, charset); + mp->prev_msgid_plural, mp->do_wrap, page_width, charset); end_css_class (stream, class_previous_comment); extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL - || mp->prev_msgid_plural != NULL - ? 1 - : 0); + || mp->prev_msgid_plural != NULL + ? 1 + : 0); end_css_class (stream, class_comment); @@ -1379,7 +1379,7 @@ message_print_obsolete (const message_ty *mp, ostream_t stream, && po_charset_canonicalize (charset) != po_charset_utf8) { char *warning_message = - xasprintf (_("\ + xasprintf (_("\ The following msgctxt contains non-ASCII characters.\n\ This will cause problems to translators who use a character encoding\n\ different from yours. Consider using a pure ASCII msgctxt instead.\n\ @@ -1391,7 +1391,7 @@ different from yours. Consider using a pure ASCII msgctxt instead.\n\ && po_charset_canonicalize (charset) != po_charset_utf8) { char *warning_message = - xasprintf (_("\ + xasprintf (_("\ The following msgid contains non-ASCII characters.\n\ This will cause problems to translators who use a character encoding\n\ different from yours. Consider using a pure ASCII msgid instead.\n\ @@ -1401,16 +1401,16 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ } if (mp->msgctxt != NULL) wrap (mp, stream, "#~ ", extra_indent, class_msgid, "msgctxt", mp->msgctxt, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset); wrap (mp, stream, "#~ ", extra_indent, class_msgid, "msgid", mp->msgid, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset); if (mp->msgid_plural != NULL) wrap (mp, stream, "#~ ", extra_indent, class_msgid, "msgid_plural", - mp->msgid_plural, mp->do_wrap, page_width, charset); + mp->msgid_plural, mp->do_wrap, page_width, charset); if (mp->msgid_plural == NULL) wrap (mp, stream, "#~ ", extra_indent, class_msgstr, "msgstr", mp->msgstr, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset); else { char prefix_buf[20]; @@ -1418,13 +1418,13 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ const char *p; for (p = mp->msgstr, i = 0; - p < mp->msgstr + mp->msgstr_len; - p += strlen (p) + 1, i++) - { - sprintf (prefix_buf, "msgstr[%u]", i); - wrap (mp, stream, "#~ ", extra_indent, class_msgstr, prefix_buf, p, - mp->do_wrap, page_width, charset); - } + p < mp->msgstr + mp->msgstr_len; + p += strlen (p) + 1, i++) + { + sprintf (prefix_buf, "msgstr[%u]", i); + wrap (mp, stream, "#~ ", extra_indent, class_msgstr, prefix_buf, p, + mp->do_wrap, page_width, charset); + } } end_css_class (stream, class_obsolete); @@ -1433,7 +1433,7 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ static void msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream, - size_t page_width, bool debug) + size_t page_width, bool debug) { size_t j, k; bool blank_line; @@ -1448,82 +1448,82 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream, char *allocated_charset; /* If the first domain is the default, don't bother emitting - the domain name, because it is the default. */ + the domain name, because it is the default. */ if (!(k == 0 - && strcmp (mdlp->item[k]->domain, MESSAGE_DOMAIN_DEFAULT) == 0)) - { - if (blank_line) - print_blank_line (stream); - begin_css_class (stream, class_keyword); - ostream_write_str (stream, "domain"); - end_css_class (stream, class_keyword); - ostream_write_str (stream, " "); - begin_css_class (stream, class_string); - ostream_write_str (stream, "\""); - begin_css_class (stream, class_text); - ostream_write_str (stream, mdlp->item[k]->domain); - end_css_class (stream, class_text); - ostream_write_str (stream, "\""); - end_css_class (stream, class_string); - ostream_write_str (stream, "\n"); - blank_line = true; - } + && strcmp (mdlp->item[k]->domain, MESSAGE_DOMAIN_DEFAULT) == 0)) + { + if (blank_line) + print_blank_line (stream); + begin_css_class (stream, class_keyword); + ostream_write_str (stream, "domain"); + end_css_class (stream, class_keyword); + ostream_write_str (stream, " "); + begin_css_class (stream, class_string); + ostream_write_str (stream, "\""); + begin_css_class (stream, class_text); + ostream_write_str (stream, mdlp->item[k]->domain); + end_css_class (stream, class_text); + ostream_write_str (stream, "\""); + end_css_class (stream, class_string); + ostream_write_str (stream, "\n"); + blank_line = true; + } mlp = mdlp->item[k]->messages; /* Search the header entry. */ header = NULL; for (j = 0; j < mlp->nitems; ++j) - if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) - { - header = mlp->item[j]->msgstr; - break; - } + if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete) + { + header = mlp->item[j]->msgstr; + break; + } /* Extract the charset name. */ charset = "ASCII"; allocated_charset = NULL; if (header != NULL) - { - const char *charsetstr = c_strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - allocated_charset = (char *) xmalloca (len + 1); - memcpy (allocated_charset, charsetstr, len); - allocated_charset[len] = '\0'; - charset = allocated_charset; - - /* Treat the dummy default value as if it were absent. */ - if (strcmp (charset, "CHARSET") == 0) - charset = "ASCII"; - } - } + { + const char *charsetstr = c_strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + allocated_charset = (char *) xmalloca (len + 1); + memcpy (allocated_charset, charsetstr, len); + allocated_charset[len] = '\0'; + charset = allocated_charset; + + /* Treat the dummy default value as if it were absent. */ + if (strcmp (charset, "CHARSET") == 0) + charset = "ASCII"; + } + } /* Write out each of the messages for this domain. */ for (j = 0; j < mlp->nitems; ++j) - if (!mlp->item[j]->obsolete) - { - message_print (mlp->item[j], stream, charset, page_width, - blank_line, debug); - blank_line = true; - } + if (!mlp->item[j]->obsolete) + { + message_print (mlp->item[j], stream, charset, page_width, + blank_line, debug); + blank_line = true; + } /* Write out each of the obsolete messages for this domain. */ for (j = 0; j < mlp->nitems; ++j) - if (mlp->item[j]->obsolete) - { - message_print_obsolete (mlp->item[j], stream, charset, page_width, - blank_line); - blank_line = true; - } + if (mlp->item[j]->obsolete) + { + message_print_obsolete (mlp->item[j], stream, charset, page_width, + blank_line); + blank_line = true; + } if (allocated_charset != NULL) - freea (allocated_charset); + freea (allocated_charset); } } @@ -1531,13 +1531,13 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream, /* Describes a PO file in .po syntax. */ const struct catalog_output_format output_format_po = { - msgdomain_list_print_po, /* print */ - false, /* requires_utf8 */ - true, /* supports_color */ - true, /* supports_multiple_domains */ - true, /* supports_contexts */ - true, /* supports_plurals */ - true, /* sorts_obsoletes_to_end */ - false, /* alternative_is_po */ - false /* alternative_is_java_class */ + msgdomain_list_print_po, /* print */ + false, /* requires_utf8 */ + true, /* supports_color */ + true, /* supports_multiple_domains */ + true, /* supports_contexts */ + true, /* supports_plurals */ + true, /* sorts_obsoletes_to_end */ + false, /* alternative_is_po */ + false /* alternative_is_java_class */ }; diff --git a/gettext-tools/src/write-po.h b/gettext-tools/src/write-po.h index b832b005b..01875a555 100644 --- a/gettext-tools/src/write-po.h +++ b/gettext-tools/src/write-po.h @@ -33,7 +33,7 @@ extern "C" { /* These functions are used to output a #, flags line. */ extern const char * make_format_description_string (enum is_format is_format, - const char *lang, bool debug); + const char *lang, bool debug); extern bool significant_format_p (enum is_format is_format); @@ -47,10 +47,10 @@ extern void message_print_comment_dot (const message_ty *mp, ostream_t stream); extern void message_print_comment_filepos (const message_ty *mp, ostream_t stream, - bool uniforum, size_t page_width); + bool uniforum, size_t page_width); extern void message_print_comment_flags (const message_ty *mp, ostream_t stream, - bool debug); + bool debug); /* These functions set some parameters for use by 'output_format_po.print'. */ extern void diff --git a/gettext-tools/src/write-properties.c b/gettext-tools/src/write-properties.c index f53a7fc57..8b6dcee52 100644 --- a/gettext-tools/src/write-properties.c +++ b/gettext-tools/src/write-properties.c @@ -70,9 +70,9 @@ conv_to_java (const char *string) while (str < str_limit) { - ucs4_t uc; - str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); - length += (uc <= 0x007f ? 1 : uc < 0x10000 ? 6 : 12); + ucs4_t uc; + str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); + length += (uc <= 0x007f ? 1 : uc < 0x10000 ? 6 : 12); } } @@ -85,36 +85,36 @@ conv_to_java (const char *string) while (str < str_limit) { - ucs4_t uc; - str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); - if (uc <= 0x007f) - /* ASCII characters can be output literally. - We could treat non-ASCII ISO-8859-1 characters (0x0080..0x00FF) - the same way, but there is no point in doing this; Sun's - nativetoascii doesn't do it either. */ - *newstr++ = uc; - else if (uc < 0x10000) - { - /* Single UCS-2 'char' */ - sprintf (newstr, "\\u%c%c%c%c", - hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], - hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); - newstr += 6; - } - else - { - /* UTF-16 surrogate: two 'char's. */ - ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); - ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); - sprintf (newstr, "\\u%c%c%c%c", - hexdigit[(uc1 >> 12) & 0x0f], hexdigit[(uc1 >> 8) & 0x0f], - hexdigit[(uc1 >> 4) & 0x0f], hexdigit[uc1 & 0x0f]); - newstr += 6; - sprintf (newstr, "\\u%c%c%c%c", - hexdigit[(uc2 >> 12) & 0x0f], hexdigit[(uc2 >> 8) & 0x0f], - hexdigit[(uc2 >> 4) & 0x0f], hexdigit[uc2 & 0x0f]); - newstr += 6; - } + ucs4_t uc; + str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); + if (uc <= 0x007f) + /* ASCII characters can be output literally. + We could treat non-ASCII ISO-8859-1 characters (0x0080..0x00FF) + the same way, but there is no point in doing this; Sun's + nativetoascii doesn't do it either. */ + *newstr++ = uc; + else if (uc < 0x10000) + { + /* Single UCS-2 'char' */ + sprintf (newstr, "\\u%c%c%c%c", + hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], + hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); + newstr += 6; + } + else + { + /* UTF-16 surrogate: two 'char's. */ + ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); + ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); + sprintf (newstr, "\\u%c%c%c%c", + hexdigit[(uc1 >> 12) & 0x0f], hexdigit[(uc1 >> 8) & 0x0f], + hexdigit[(uc1 >> 4) & 0x0f], hexdigit[uc1 & 0x0f]); + newstr += 6; + sprintf (newstr, "\\u%c%c%c%c", + hexdigit[(uc2 >> 12) & 0x0f], hexdigit[(uc2 >> 8) & 0x0f], + hexdigit[(uc2 >> 4) & 0x0f], hexdigit[uc2 & 0x0f]); + newstr += 6; + } } *newstr = '\0'; } @@ -136,70 +136,70 @@ write_escaped_string (ostream_t stream, const char *str, bool in_key) str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); /* Whitespace must be escaped. */ if (uc == 0x0020 && (first || in_key)) - ostream_write_str (stream, "\\ "); + ostream_write_str (stream, "\\ "); else if (uc == 0x0009) - ostream_write_str (stream, "\\t"); + ostream_write_str (stream, "\\t"); else if (uc == 0x000a) - ostream_write_str (stream, "\\n"); + ostream_write_str (stream, "\\n"); else if (uc == 0x000d) - ostream_write_str (stream, "\\r"); + ostream_write_str (stream, "\\r"); else if (uc == 0x000c) - ostream_write_str (stream, "\\f"); + ostream_write_str (stream, "\\f"); else if (/* Backslash must be escaped. */ - uc == '\\' - /* Possible comment introducers must be escaped. */ - || uc == '#' || uc == '!' - /* Key terminators must be escaped. */ - || uc == '=' || uc == ':') - { - char seq[2]; - seq[0] = '\\'; - seq[1] = uc; - ostream_write_mem (stream, seq, 2); - } + uc == '\\' + /* Possible comment introducers must be escaped. */ + || uc == '#' || uc == '!' + /* Key terminators must be escaped. */ + || uc == '=' || uc == ':') + { + char seq[2]; + seq[0] = '\\'; + seq[1] = uc; + ostream_write_mem (stream, seq, 2); + } else if (uc >= 0x0020 && uc <= 0x007e) - { - /* ASCII characters can be output literally. - We could treat non-ASCII ISO-8859-1 characters (0x0080..0x00FF) - the same way, but there is no point in doing this; Sun's - nativetoascii doesn't do it either. */ - char seq[1]; - seq[0] = uc; - ostream_write_mem (stream, seq, 1); - } + { + /* ASCII characters can be output literally. + We could treat non-ASCII ISO-8859-1 characters (0x0080..0x00FF) + the same way, but there is no point in doing this; Sun's + nativetoascii doesn't do it either. */ + char seq[1]; + seq[0] = uc; + ostream_write_mem (stream, seq, 1); + } else if (uc < 0x10000) - { - /* Single UCS-2 'char' */ - char seq[6]; - seq[0] = '\\'; - seq[1] = 'u'; - seq[2] = hexdigit[(uc >> 12) & 0x0f]; - seq[3] = hexdigit[(uc >> 8) & 0x0f]; - seq[4] = hexdigit[(uc >> 4) & 0x0f]; - seq[5] = hexdigit[uc & 0x0f]; - ostream_write_mem (stream, seq, 6); - } + { + /* Single UCS-2 'char' */ + char seq[6]; + seq[0] = '\\'; + seq[1] = 'u'; + seq[2] = hexdigit[(uc >> 12) & 0x0f]; + seq[3] = hexdigit[(uc >> 8) & 0x0f]; + seq[4] = hexdigit[(uc >> 4) & 0x0f]; + seq[5] = hexdigit[uc & 0x0f]; + ostream_write_mem (stream, seq, 6); + } else - { - /* UTF-16 surrogate: two 'char's. */ - ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); - ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); - char seq[6]; - seq[0] = '\\'; - seq[1] = 'u'; - seq[2] = hexdigit[(uc1 >> 12) & 0x0f]; - seq[3] = hexdigit[(uc1 >> 8) & 0x0f]; - seq[4] = hexdigit[(uc1 >> 4) & 0x0f]; - seq[5] = hexdigit[uc1 & 0x0f]; - ostream_write_mem (stream, seq, 6); - seq[0] = '\\'; - seq[1] = 'u'; - seq[2] = hexdigit[(uc2 >> 12) & 0x0f]; - seq[3] = hexdigit[(uc2 >> 8) & 0x0f]; - seq[4] = hexdigit[(uc2 >> 4) & 0x0f]; - seq[5] = hexdigit[uc2 & 0x0f]; - ostream_write_mem (stream, seq, 6); - } + { + /* UTF-16 surrogate: two 'char's. */ + ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10); + ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff); + char seq[6]; + seq[0] = '\\'; + seq[1] = 'u'; + seq[2] = hexdigit[(uc1 >> 12) & 0x0f]; + seq[3] = hexdigit[(uc1 >> 8) & 0x0f]; + seq[4] = hexdigit[(uc1 >> 4) & 0x0f]; + seq[5] = hexdigit[uc1 & 0x0f]; + ostream_write_mem (stream, seq, 6); + seq[0] = '\\'; + seq[1] = 'u'; + seq[2] = hexdigit[(uc2 >> 12) & 0x0f]; + seq[3] = hexdigit[(uc2 >> 8) & 0x0f]; + seq[4] = hexdigit[(uc2 >> 4) & 0x0f]; + seq[5] = hexdigit[uc2 & 0x0f]; + ostream_write_mem (stream, seq, 6); + } first = false; } } @@ -207,7 +207,7 @@ write_escaped_string (ostream_t stream, const char *str, bool in_key) /* Writes a message to the stream. */ static void write_message (ostream_t stream, const message_ty *mp, - size_t page_width, bool debug) + size_t page_width, bool debug) { /* Print translator comment if available. */ message_print_comment (mp, stream); @@ -239,7 +239,7 @@ write_message (ostream_t stream, const message_ty *mp, /* Writes an entire message list to the stream. */ static void write_properties (ostream_t stream, message_list_ty *mlp, - const char *canon_encoding, size_t page_width, bool debug) + const char *canon_encoding, size_t page_width, bool debug) { bool blank_line; size_t j, i; @@ -251,11 +251,11 @@ write_properties (ostream_t stream, message_list_ty *mlp, message_ty *mp = mlp->item[j]; if (mp->comment != NULL) - for (i = 0; i < mp->comment->nitems; ++i) - mp->comment->item[i] = conv_to_java (mp->comment->item[i]); + for (i = 0; i < mp->comment->nitems; ++i) + mp->comment->item[i] = conv_to_java (mp->comment->item[i]); if (mp->comment_dot != NULL) - for (i = 0; i < mp->comment_dot->nitems; ++i) - mp->comment_dot->item[i] = conv_to_java (mp->comment_dot->item[i]); + for (i = 0; i < mp->comment_dot->nitems; ++i) + mp->comment_dot->item[i] = conv_to_java (mp->comment_dot->item[i]); } /* Loop through the messages. */ @@ -265,21 +265,21 @@ write_properties (ostream_t stream, message_list_ty *mlp, const message_ty *mp = mlp->item[j]; if (mp->msgid_plural == NULL && !mp->obsolete) - { - if (blank_line) - ostream_write_str (stream, "\n"); + { + if (blank_line) + ostream_write_str (stream, "\n"); - write_message (stream, mp, page_width, debug); + write_message (stream, mp, page_width, debug); - blank_line = true; - } + blank_line = true; + } } } /* Output the contents of a PO file in Java .properties syntax. */ static void msgdomain_list_print_properties (msgdomain_list_ty *mdlp, ostream_t stream, - size_t page_width, bool debug) + size_t page_width, bool debug) { message_list_ty *mlp; @@ -293,13 +293,13 @@ msgdomain_list_print_properties (msgdomain_list_ty *mdlp, ostream_t stream, /* Describes a PO file in Java .properties syntax. */ const struct catalog_output_format output_format_properties = { - msgdomain_list_print_properties, /* print */ - true, /* requires_utf8 */ - false, /* supports_color */ - false, /* supports_multiple_domains */ - false, /* supports_contexts */ - false, /* supports_plurals */ - false, /* sorts_obsoletes_to_end */ - true, /* alternative_is_po */ - true /* alternative_is_java_class */ + msgdomain_list_print_properties, /* print */ + true, /* requires_utf8 */ + false, /* supports_color */ + false, /* supports_multiple_domains */ + false, /* supports_contexts */ + false, /* supports_plurals */ + false, /* sorts_obsoletes_to_end */ + true, /* alternative_is_po */ + true /* alternative_is_java_class */ }; diff --git a/gettext-tools/src/write-qt.c b/gettext-tools/src/write-qt.c index d94e2dc48..50b96b754 100644 --- a/gettext-tools/src/write-qt.c +++ b/gettext-tools/src/write-qt.c @@ -266,7 +266,7 @@ append_base_string (struct obstack *mempool, const char *string) /* Add an UTF-16 encoded string to an obstack. */ static void append_unicode_string (struct obstack *mempool, const unsigned short *string, - size_t length) + size_t length) { append_u32 (mempool, length * 2); for (; length > 0; string++, length--) @@ -297,7 +297,7 @@ conv_to_iso_8859_1 (const char *string) str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); /* It has already been verified that the string fits in ISO-8859-1. */ if (!(uc < 0x100)) - abort (); + abort (); /* Store as ISO-8859-1. */ *q++ = (unsigned char) uc; } @@ -324,14 +324,14 @@ conv_to_utf16 (const char *string, size_t *sizep) ucs4_t uc; str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); if (uc < 0x10000) - /* UCS-2 character. */ - *q++ = (unsigned short) uc; + /* UCS-2 character. */ + *q++ = (unsigned short) uc; else - { - /* UTF-16 surrogate. */ - *q++ = 0xd800 + ((uc - 0x10000) >> 10); - *q++ = 0xdc00 + ((uc - 0x10000) & 0x3ff); - } + { + /* UTF-16 surrogate. */ + *q++ = 0xd800 + ((uc - 0x10000) >> 10); + *q++ = 0xdc00 + ((uc - 0x10000) & 0x3ff); + } } assert (q - result <= 2 * length); @@ -368,9 +368,9 @@ cmp_hashes (const void *va, const void *vb) unsigned int b_offset = peek_u32 (b + 4); if (a_offset != b_offset) - return (a_offset >= b_offset ? 1 : -1); + return (a_offset >= b_offset ? 1 : -1); else - return 0; + return 0; } } @@ -412,43 +412,43 @@ write_qm (FILE *output_file, message_list_ty *mlp) /* No need to emit the header entry, it's not needed at runtime. */ if (!is_header (mp)) - { - char *msgctxt_as_iso_8859_1 = - conv_to_iso_8859_1 (mp->msgctxt != NULL ? mp->msgctxt : ""); - char *msgid_as_iso_8859_1 = conv_to_iso_8859_1 (mp->msgid); - size_t msgstr_len; - unsigned short *msgstr_as_utf16 = - conv_to_utf16 (mp->msgstr, &msgstr_len); - unsigned int hashcode = string_hashcode (msgid_as_iso_8859_1); - unsigned int offset = obstack_object_size (&messages_pool); + { + char *msgctxt_as_iso_8859_1 = + conv_to_iso_8859_1 (mp->msgctxt != NULL ? mp->msgctxt : ""); + char *msgid_as_iso_8859_1 = conv_to_iso_8859_1 (mp->msgid); + size_t msgstr_len; + unsigned short *msgstr_as_utf16 = + conv_to_utf16 (mp->msgstr, &msgstr_len); + unsigned int hashcode = string_hashcode (msgid_as_iso_8859_1); + unsigned int offset = obstack_object_size (&messages_pool); - /* Add a record to the hashes section. */ - append_u32 (&hashes_pool, hashcode); - append_u32 (&hashes_pool, offset); + /* Add a record to the hashes section. */ + append_u32 (&hashes_pool, hashcode); + append_u32 (&hashes_pool, offset); - /* Add a record to the messages section. */ + /* Add a record to the messages section. */ - append_u8 (&messages_pool, 0x03); - append_unicode_string (&messages_pool, msgstr_as_utf16, msgstr_len); + append_u8 (&messages_pool, 0x03); + append_unicode_string (&messages_pool, msgstr_as_utf16, msgstr_len); - append_u8 (&messages_pool, 0x08); - append_base_string (&messages_pool, ""); + append_u8 (&messages_pool, 0x08); + append_base_string (&messages_pool, ""); - append_u8 (&messages_pool, 0x06); - append_base_string (&messages_pool, msgid_as_iso_8859_1); + append_u8 (&messages_pool, 0x06); + append_base_string (&messages_pool, msgid_as_iso_8859_1); - append_u8 (&messages_pool, 0x07); - append_base_string (&messages_pool, msgctxt_as_iso_8859_1); + append_u8 (&messages_pool, 0x07); + append_base_string (&messages_pool, msgctxt_as_iso_8859_1); - append_u8 (&messages_pool, 0x05); - append_u32 (&messages_pool, hashcode); + append_u8 (&messages_pool, 0x05); + append_u32 (&messages_pool, hashcode); - append_u8 (&messages_pool, 0x01); + append_u8 (&messages_pool, 0x01); - free (msgstr_as_utf16); - free (msgid_as_iso_8859_1); - free (msgctxt_as_iso_8859_1); - } + free (msgstr_as_utf16); + free (msgid_as_iso_8859_1); + free (msgctxt_as_iso_8859_1); + } } /* Sort the hashes section. */ @@ -463,11 +463,11 @@ write_qm (FILE *output_file, message_list_ty *mlp) /* Write the hashes section. */ write_section (output_file, 0x42, obstack_base (&hashes_pool), - obstack_object_size (&hashes_pool)); + obstack_object_size (&hashes_pool)); /* Write the messages section. */ write_section (output_file, 0x69, obstack_base (&messages_pool), - obstack_object_size (&messages_pool)); + obstack_object_size (&messages_pool)); /* Decide whether to write a contexts section. */ { @@ -475,166 +475,166 @@ write_qm (FILE *output_file, message_list_ty *mlp) for (j = 0; j < mlp->nitems; j++) { - message_ty *mp = mlp->item[j]; - - if (!is_header (mp)) - if (mp->msgctxt == NULL || mp->msgctxt[0] == '\0' - || strlen (mp->msgctxt) > 255) - { - can_write_contexts = false; - break; - } + message_ty *mp = mlp->item[j]; + + if (!is_header (mp)) + if (mp->msgctxt == NULL || mp->msgctxt[0] == '\0' + || strlen (mp->msgctxt) > 255) + { + can_write_contexts = false; + break; + } } if (can_write_contexts) { - hash_table all_contexts; - size_t num_contexts; - unsigned long table_size; - - /* Collect the contexts, removing duplicates. */ - hash_init (&all_contexts, 10); - for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - - if (!is_header (mp)) - hash_insert_entry (&all_contexts, - mp->msgctxt, strlen (mp->msgctxt) + 1, - NULL); - } - - /* Compute the number of different contexts. */ - num_contexts = all_contexts.size; - - /* Compute a suitable hash table size. */ - table_size = next_prime (num_contexts * 1.7); - if (table_size >= 0x10000) - table_size = 65521; - - /* Put the contexts into a hash table of size table_size. */ - { - struct list_cell { const char *context; struct list_cell *next; }; - struct list_cell *list_memory = - XNMALLOC (table_size, struct list_cell); - struct list_cell *freelist; - struct bucket { struct list_cell *head; struct list_cell **tail; }; - struct bucket *buckets = XNMALLOC (table_size, struct bucket); - size_t i; - - freelist = list_memory; - - for (i = 0; i < table_size; i++) - { - buckets[i].head = NULL; - buckets[i].tail = &buckets[i].head; - } - - { - void *iter; - const void *key; - size_t keylen; - void *null; - - iter = NULL; - while (hash_iterate (&all_contexts, &iter, &key, &keylen, &null) - == 0) - { - const char *context = (const char *)key; - i = string_hashcode (context) % table_size; - freelist->context = context; - freelist->next = NULL; - *buckets[i].tail = freelist; - buckets[i].tail = &freelist->next; - freelist++; - } - } - - /* Determine the total context pool size. */ - { - size_t pool_size; - - pool_size = 2; - for (i = 0; i < table_size; i++) - if (buckets[i].head != NULL) - { - const struct list_cell *p; - - for (p = buckets[i].head; p != NULL; p = p->next) - pool_size += 1 + strlen (p->context); - pool_size++; - if ((pool_size % 2) != 0) - pool_size++; - } - if (pool_size <= 0x20000) - { - /* Prepare the contexts section. */ - struct obstack contexts_pool; - size_t pool_offset; - - obstack_init (&contexts_pool); - - append_u16 (&contexts_pool, table_size); - pool_offset = 2; - for (i = 0; i < table_size; i++) - if (buckets[i].head != NULL) - { - const struct list_cell *p; - - append_u16 (&contexts_pool, pool_offset / 2); - for (p = buckets[i].head; p != NULL; p = p->next) - pool_offset += 1 + strlen (p->context); - pool_offset++; - if ((pool_offset % 2) != 0) - pool_offset++; - } - else - append_u16 (&contexts_pool, 0); - if (!(pool_offset == pool_size)) - abort (); - - append_u16 (&contexts_pool, 0); - pool_offset = 2; - for (i = 0; i < table_size; i++) - if (buckets[i].head != NULL) - { - const struct list_cell *p; - - for (p = buckets[i].head; p != NULL; p = p->next) - { - append_u8 (&contexts_pool, strlen (p->context)); - obstack_grow (&contexts_pool, - p->context, strlen (p->context)); - pool_offset += 1 + strlen (p->context); - } - append_u8 (&contexts_pool, 0); - pool_offset++; - if ((pool_offset % 2) != 0) - { - append_u8 (&contexts_pool, 0); - pool_offset++; - } - } - if (!(pool_offset == pool_size)) - abort (); - - if (!(obstack_object_size (&contexts_pool) - == 2 + 2 * table_size + pool_size)) - abort (); - - /* Write the contexts section. */ - write_section (output_file, 0x2f, obstack_base (&contexts_pool), - obstack_object_size (&contexts_pool)); - - obstack_free (&contexts_pool, NULL); - } - } - - free (buckets); - free (list_memory); - } - - hash_destroy (&all_contexts); + hash_table all_contexts; + size_t num_contexts; + unsigned long table_size; + + /* Collect the contexts, removing duplicates. */ + hash_init (&all_contexts, 10); + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + + if (!is_header (mp)) + hash_insert_entry (&all_contexts, + mp->msgctxt, strlen (mp->msgctxt) + 1, + NULL); + } + + /* Compute the number of different contexts. */ + num_contexts = all_contexts.size; + + /* Compute a suitable hash table size. */ + table_size = next_prime (num_contexts * 1.7); + if (table_size >= 0x10000) + table_size = 65521; + + /* Put the contexts into a hash table of size table_size. */ + { + struct list_cell { const char *context; struct list_cell *next; }; + struct list_cell *list_memory = + XNMALLOC (table_size, struct list_cell); + struct list_cell *freelist; + struct bucket { struct list_cell *head; struct list_cell **tail; }; + struct bucket *buckets = XNMALLOC (table_size, struct bucket); + size_t i; + + freelist = list_memory; + + for (i = 0; i < table_size; i++) + { + buckets[i].head = NULL; + buckets[i].tail = &buckets[i].head; + } + + { + void *iter; + const void *key; + size_t keylen; + void *null; + + iter = NULL; + while (hash_iterate (&all_contexts, &iter, &key, &keylen, &null) + == 0) + { + const char *context = (const char *)key; + i = string_hashcode (context) % table_size; + freelist->context = context; + freelist->next = NULL; + *buckets[i].tail = freelist; + buckets[i].tail = &freelist->next; + freelist++; + } + } + + /* Determine the total context pool size. */ + { + size_t pool_size; + + pool_size = 2; + for (i = 0; i < table_size; i++) + if (buckets[i].head != NULL) + { + const struct list_cell *p; + + for (p = buckets[i].head; p != NULL; p = p->next) + pool_size += 1 + strlen (p->context); + pool_size++; + if ((pool_size % 2) != 0) + pool_size++; + } + if (pool_size <= 0x20000) + { + /* Prepare the contexts section. */ + struct obstack contexts_pool; + size_t pool_offset; + + obstack_init (&contexts_pool); + + append_u16 (&contexts_pool, table_size); + pool_offset = 2; + for (i = 0; i < table_size; i++) + if (buckets[i].head != NULL) + { + const struct list_cell *p; + + append_u16 (&contexts_pool, pool_offset / 2); + for (p = buckets[i].head; p != NULL; p = p->next) + pool_offset += 1 + strlen (p->context); + pool_offset++; + if ((pool_offset % 2) != 0) + pool_offset++; + } + else + append_u16 (&contexts_pool, 0); + if (!(pool_offset == pool_size)) + abort (); + + append_u16 (&contexts_pool, 0); + pool_offset = 2; + for (i = 0; i < table_size; i++) + if (buckets[i].head != NULL) + { + const struct list_cell *p; + + for (p = buckets[i].head; p != NULL; p = p->next) + { + append_u8 (&contexts_pool, strlen (p->context)); + obstack_grow (&contexts_pool, + p->context, strlen (p->context)); + pool_offset += 1 + strlen (p->context); + } + append_u8 (&contexts_pool, 0); + pool_offset++; + if ((pool_offset % 2) != 0) + { + append_u8 (&contexts_pool, 0); + pool_offset++; + } + } + if (!(pool_offset == pool_size)) + abort (); + + if (!(obstack_object_size (&contexts_pool) + == 2 + 2 * table_size + pool_size)) + abort (); + + /* Write the contexts section. */ + write_section (output_file, 0x2f, obstack_base (&contexts_pool), + obstack_object_size (&contexts_pool)); + + obstack_free (&contexts_pool, NULL); + } + } + + free (buckets); + free (list_memory); + } + + hash_destroy (&all_contexts); } } @@ -645,7 +645,7 @@ write_qm (FILE *output_file, message_list_ty *mlp) int msgdomain_write_qt (message_list_ty *mlp, const char *canon_encoding, - const char *domain_name, const char *file_name) + const char *domain_name, const char *file_name) { FILE *output_file; @@ -654,21 +654,21 @@ msgdomain_write_qt (message_list_ty *mlp, const char *canon_encoding, { /* Determine whether mlp has plural entries. */ { - bool has_plural; - size_t j; - - has_plural = false; - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgid_plural != NULL) - has_plural = true; - if (has_plural) - { - multiline_error (xstrdup (""), - xstrdup (_("\ + bool has_plural; + size_t j; + + has_plural = false; + for (j = 0; j < mlp->nitems; j++) + if (mlp->item[j]->msgid_plural != NULL) + has_plural = true; + if (has_plural) + { + multiline_error (xstrdup (""), + xstrdup (_("\ message catalog has plural form translations\n\ but the Qt message catalog format doesn't support plural handling\n"))); - return 1; - } + return 1; + } } /* Convert the messages to Unicode. */ @@ -676,78 +676,78 @@ but the Qt message catalog format doesn't support plural handling\n"))); /* Determine whether mlp has non-ISO-8859-1 msgctxt entries. */ { - size_t j; - - for (j = 0; j < mlp->nitems; j++) - { - const char *string = mlp->item[j]->msgctxt; - - if (string != NULL) - { - /* An UTF-8 encoded string fits in ISO-8859-1 if and only if - all its bytes are < 0xc4. */ - for (; *string; string++) - if ((unsigned char) *string >= 0xc4) - { - multiline_error (xstrdup (""), - xstrdup (_("\ + size_t j; + + for (j = 0; j < mlp->nitems; j++) + { + const char *string = mlp->item[j]->msgctxt; + + if (string != NULL) + { + /* An UTF-8 encoded string fits in ISO-8859-1 if and only if + all its bytes are < 0xc4. */ + for (; *string; string++) + if ((unsigned char) *string >= 0xc4) + { + multiline_error (xstrdup (""), + xstrdup (_("\ message catalog has msgctxt strings containing characters outside ISO-8859-1\n\ but the Qt message catalog format supports Unicode only in the translated\n\ strings, not in the context strings\n"))); - return 1; - } - } - } + return 1; + } + } + } } /* Determine whether mlp has non-ISO-8859-1 msgid entries. */ { - size_t j; - - for (j = 0; j < mlp->nitems; j++) - { - const char *string = mlp->item[j]->msgid; - - /* An UTF-8 encoded string fits in ISO-8859-1 if and only if all - its bytes are < 0xc4. */ - for (; *string; string++) - if ((unsigned char) *string >= 0xc4) - { - multiline_error (xstrdup (""), - xstrdup (_("\ + size_t j; + + for (j = 0; j < mlp->nitems; j++) + { + const char *string = mlp->item[j]->msgid; + + /* An UTF-8 encoded string fits in ISO-8859-1 if and only if all + its bytes are < 0xc4. */ + for (; *string; string++) + if ((unsigned char) *string >= 0xc4) + { + multiline_error (xstrdup (""), + xstrdup (_("\ message catalog has msgid strings containing characters outside ISO-8859-1\n\ but the Qt message catalog format supports Unicode only in the translated\n\ strings, not in the untranslated strings\n"))); - return 1; - } - } + return 1; + } + } } if (strcmp (domain_name, "-") == 0) - { - output_file = stdout; - SET_BINARY (fileno (output_file)); - } + { + output_file = stdout; + SET_BINARY (fileno (output_file)); + } else - { - output_file = fopen (file_name, "wb"); - if (output_file == NULL) - { - error (0, errno, _("error while opening \"%s\" for writing"), - file_name); - return 1; - } - } + { + output_file = fopen (file_name, "wb"); + if (output_file == NULL) + { + error (0, errno, _("error while opening \"%s\" for writing"), + file_name); + return 1; + } + } if (output_file != NULL) - { - write_qm (output_file, mlp); - - /* Make sure nothing went wrong. */ - if (fwriteerror (output_file)) - error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"), - file_name); - } + { + write_qm (output_file, mlp); + + /* Make sure nothing went wrong. */ + if (fwriteerror (output_file)) + error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"), + file_name); + } } return 0; diff --git a/gettext-tools/src/write-qt.h b/gettext-tools/src/write-qt.h index ecfb54a02..2b36da202 100644 --- a/gettext-tools/src/write-qt.h +++ b/gettext-tools/src/write-qt.h @@ -25,6 +25,6 @@ Return 0 if ok, nonzero on error. */ extern int msgdomain_write_qt (message_list_ty *mlp, const char *canon_encoding, - const char *domain_name, const char *file_name); + const char *domain_name, const char *file_name); #endif /* _WRITE_QT_H */ diff --git a/gettext-tools/src/write-resources.c b/gettext-tools/src/write-resources.c index 378353270..002ae1cd6 100644 --- a/gettext-tools/src/write-resources.c +++ b/gettext-tools/src/write-resources.c @@ -59,8 +59,8 @@ struct locals static bool execute_writing_input (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data) + const char *prog_path, char **prog_argv, + void *private_data) { struct locals *l = (struct locals *) private_data; pid_t child; @@ -70,7 +70,7 @@ execute_writing_input (const char *progname, /* Open a pipe to the C# execution engine. */ child = create_pipe_out (progname, prog_path, prog_argv, NULL, false, - true, true, fd); + true, true, fd); fp = fdopen (fd[0], "wb"); if (fp == NULL) @@ -83,16 +83,16 @@ execute_writing_input (const char *progname, for (j = 0; j < mlp->nitems; j++) { - message_ty *mp = mlp->item[j]; + message_ty *mp = mlp->item[j]; - fwrite (mp->msgid, 1, strlen (mp->msgid) + 1, fp); - fwrite (mp->msgstr, 1, strlen (mp->msgstr) + 1, fp); + fwrite (mp->msgid, 1, strlen (mp->msgid) + 1, fp); + fwrite (mp->msgstr, 1, strlen (mp->msgstr) + 1, fp); } } if (fwriteerror (fp)) error (EXIT_FAILURE, 0, _("error while writing to %s subprocess"), - progname); + progname); /* Remove zombie process from process list, and retrieve exit status. */ /* He we can ignore SIGPIPE because WriteResource either writes to a file @@ -102,56 +102,56 @@ execute_writing_input (const char *progname, wait_subprocess (child, progname, true, false, true, true, NULL); if (exitstatus != 0) error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"), - progname, exitstatus); + progname, exitstatus); return false; } int msgdomain_write_csharp_resources (message_list_ty *mlp, - const char *canon_encoding, - const char *domain_name, - const char *file_name) + const char *canon_encoding, + const char *domain_name, + const char *file_name) { /* If no entry for this domain don't even create the file. */ if (mlp->nitems != 0) { /* Determine whether mlp has entries with context. */ { - bool has_context; - size_t j; - - has_context = false; - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgctxt != NULL) - has_context = true; - if (has_context) - { - multiline_error (xstrdup (""), - xstrdup (_("\ + bool has_context; + size_t j; + + has_context = false; + for (j = 0; j < mlp->nitems; j++) + if (mlp->item[j]->msgctxt != NULL) + has_context = true; + if (has_context) + { + multiline_error (xstrdup (""), + xstrdup (_("\ message catalog has context dependent translations\n\ but the C# .resources format doesn't support contexts\n"))); - return 1; - } + return 1; + } } /* Determine whether mlp has plural entries. */ { - bool has_plural; - size_t j; - - has_plural = false; - for (j = 0; j < mlp->nitems; j++) - if (mlp->item[j]->msgid_plural != NULL) - has_plural = true; - if (has_plural) - { - multiline_error (xstrdup (""), - xstrdup (_("\ + bool has_plural; + size_t j; + + has_plural = false; + for (j = 0; j < mlp->nitems; j++) + if (mlp->item[j]->msgid_plural != NULL) + has_plural = true; + if (has_plural) + { + multiline_error (xstrdup (""), + xstrdup (_("\ message catalog has plural form translations\n\ but the C# .resources format doesn't support plural handling\n"))); - return 1; - } + return 1; + } } /* Convert the messages to Unicode. */ @@ -159,34 +159,34 @@ but the C# .resources format doesn't support plural handling\n"))); /* Execute the WriteResource program. */ { - const char *args[2]; - const char *gettextexedir; - char *assembly_path; - struct locals locals; - - /* Prepare arguments. */ - args[0] = file_name; - args[1] = NULL; - - /* Make it possible to override the .exe location. This is - necessary for running the testsuite before "make install". */ - gettextexedir = getenv ("GETTEXTCSHARPEXEDIR"); - if (gettextexedir == NULL || gettextexedir[0] == '\0') - gettextexedir = relocate (LIBDIR "/gettext"); - - assembly_path = - xconcatenated_filename (gettextexedir, "msgfmt.net", ".exe"); - - locals.mlp = mlp; - - if (execute_csharp_program (assembly_path, NULL, 0, - args, - verbose > 0, false, - execute_writing_input, &locals)) - /* An error message should already have been provided. */ - exit (EXIT_FAILURE); - - free (assembly_path); + const char *args[2]; + const char *gettextexedir; + char *assembly_path; + struct locals locals; + + /* Prepare arguments. */ + args[0] = file_name; + args[1] = NULL; + + /* Make it possible to override the .exe location. This is + necessary for running the testsuite before "make install". */ + gettextexedir = getenv ("GETTEXTCSHARPEXEDIR"); + if (gettextexedir == NULL || gettextexedir[0] == '\0') + gettextexedir = relocate (LIBDIR "/gettext"); + + assembly_path = + xconcatenated_filename (gettextexedir, "msgfmt.net", ".exe"); + + locals.mlp = mlp; + + if (execute_csharp_program (assembly_path, NULL, 0, + args, + verbose > 0, false, + execute_writing_input, &locals)) + /* An error message should already have been provided. */ + exit (EXIT_FAILURE); + + free (assembly_path); } } diff --git a/gettext-tools/src/write-resources.h b/gettext-tools/src/write-resources.h index 53a193e98..7512f0fb8 100644 --- a/gettext-tools/src/write-resources.h +++ b/gettext-tools/src/write-resources.h @@ -24,8 +24,8 @@ Return 0 if ok, nonzero on error. */ extern int msgdomain_write_csharp_resources (message_list_ty *mlp, - const char *canon_encoding, - const char *domain_name, - const char *file_name); + const char *canon_encoding, + const char *domain_name, + const char *file_name); #endif /* _WRITE_RESOURCES_H */ diff --git a/gettext-tools/src/write-stringtable.c b/gettext-tools/src/write-stringtable.c index 43419426f..34e171f05 100644 --- a/gettext-tools/src/write-stringtable.c +++ b/gettext-tools/src/write-stringtable.c @@ -67,26 +67,26 @@ write_escaped_string (ostream_t stream, const char *str) unsigned char c = (unsigned char) *str++; if (c == '\t') - ostream_write_str (stream, "\\t"); + ostream_write_str (stream, "\\t"); else if (c == '\n') - ostream_write_str (stream, "\\n"); + ostream_write_str (stream, "\\n"); else if (c == '\r') - ostream_write_str (stream, "\\r"); + ostream_write_str (stream, "\\r"); else if (c == '\f') - ostream_write_str (stream, "\\f"); + ostream_write_str (stream, "\\f"); else if (c == '\\' || c == '"') - { - char seq[2]; - seq[0] = '\\'; - seq[1] = c; - ostream_write_mem (stream, seq, 2); - } + { + char seq[2]; + seq[0] = '\\'; + seq[1] = c; + ostream_write_mem (stream, seq, 2); + } else - { - char seq[1]; - seq[0] = c; - ostream_write_mem (stream, seq, 1); - } + { + char seq[1]; + seq[0] = c; + ostream_write_mem (stream, seq, 1); + } } ostream_write_str (stream, "\""); } @@ -94,7 +94,7 @@ write_escaped_string (ostream_t stream, const char *str) /* Writes a message to the stream. */ static void write_message (ostream_t stream, const message_ty *mp, - size_t page_width, bool debug) + size_t page_width, bool debug) { /* Print translator comment if available. */ if (mp->comment != NULL) @@ -102,41 +102,41 @@ write_message (ostream_t stream, const message_ty *mp, size_t j; for (j = 0; j < mp->comment->nitems; ++j) - { - const char *s = mp->comment->item[j]; - - /* Test whether it is safe to output the comment in C style, or - whether we need C++ style for it. */ - if (c_strstr (s, "*/") == NULL) - { - ostream_write_str (stream, "/*"); - if (*s != '\0' && *s != '\n') - ostream_write_str (stream, " "); - ostream_write_str (stream, s); - ostream_write_str (stream, " */\n"); - } - else - do - { - const char *e; - ostream_write_str (stream, "//"); - if (*s != '\0' && *s != '\n') - ostream_write_str (stream, " "); - e = strchr (s, '\n'); - if (e == NULL) - { - ostream_write_str (stream, s); - s = NULL; - } - else - { - ostream_write_mem (stream, s, e - s); - s = e + 1; - } - ostream_write_str (stream, "\n"); - } - while (s != NULL); - } + { + const char *s = mp->comment->item[j]; + + /* Test whether it is safe to output the comment in C style, or + whether we need C++ style for it. */ + if (c_strstr (s, "*/") == NULL) + { + ostream_write_str (stream, "/*"); + if (*s != '\0' && *s != '\n') + ostream_write_str (stream, " "); + ostream_write_str (stream, s); + ostream_write_str (stream, " */\n"); + } + else + do + { + const char *e; + ostream_write_str (stream, "//"); + if (*s != '\0' && *s != '\n') + ostream_write_str (stream, " "); + e = strchr (s, '\n'); + if (e == NULL) + { + ostream_write_str (stream, s); + s = NULL; + } + else + { + ostream_write_mem (stream, s, e - s); + s = e + 1; + } + ostream_write_str (stream, "\n"); + } + while (s != NULL); + } } /* Print xgettext extracted comments. */ @@ -145,45 +145,45 @@ write_message (ostream_t stream, const message_ty *mp, size_t j; for (j = 0; j < mp->comment_dot->nitems; ++j) - { - const char *s = mp->comment_dot->item[j]; - - /* Test whether it is safe to output the comment in C style, or - whether we need C++ style for it. */ - if (c_strstr (s, "*/") == NULL) - { - ostream_write_str (stream, "/* Comment: "); - ostream_write_str (stream, s); - ostream_write_str (stream, " */\n"); - } - else - { - bool first = true; - do - { - const char *e; - ostream_write_str (stream, "//"); - if (first || (*s != '\0' && *s != '\n')) - ostream_write_str (stream, " "); - if (first) - ostream_write_str (stream, "Comment: "); - e = strchr (s, '\n'); - if (e == NULL) - { - ostream_write_str (stream, s); - s = NULL; - } - else - { - ostream_write_mem (stream, s, e - s); - s = e + 1; - } - ostream_write_str (stream, "\n"); - first = false; - } - while (s != NULL); - } - } + { + const char *s = mp->comment_dot->item[j]; + + /* Test whether it is safe to output the comment in C style, or + whether we need C++ style for it. */ + if (c_strstr (s, "*/") == NULL) + { + ostream_write_str (stream, "/* Comment: "); + ostream_write_str (stream, s); + ostream_write_str (stream, " */\n"); + } + else + { + bool first = true; + do + { + const char *e; + ostream_write_str (stream, "//"); + if (first || (*s != '\0' && *s != '\n')) + ostream_write_str (stream, " "); + if (first) + ostream_write_str (stream, "Comment: "); + e = strchr (s, '\n'); + if (e == NULL) + { + ostream_write_str (stream, s); + s = NULL; + } + else + { + ostream_write_mem (stream, s, e - s); + s = e + 1; + } + ostream_write_str (stream, "\n"); + first = false; + } + while (s != NULL); + } + } } /* Print the file position comments. */ @@ -192,17 +192,17 @@ write_message (ostream_t stream, const message_ty *mp, size_t j; for (j = 0; j < mp->filepos_count; ++j) - { - lex_pos_ty *pp = &mp->filepos[j]; - const char *cp = pp->file_name; - char *str; - - while (cp[0] == '.' && cp[1] == '/') - cp += 2; - str = xasprintf ("/* File: %s:%ld */\n", cp, (long) pp->line_number); - ostream_write_str (stream, str); - free (str); - } + { + lex_pos_ty *pp = &mp->filepos[j]; + const char *cp = pp->file_name; + char *str; + + while (cp[0] == '.' && cp[1] == '/') + cp += 2; + str = xasprintf ("/* File: %s:%ld */\n", cp, (long) pp->line_number); + ostream_write_str (stream, str); + free (str); + } } /* Print flag information in special comment. */ @@ -214,14 +214,14 @@ write_message (ostream_t stream, const message_ty *mp, size_t i; for (i = 0; i < NFORMATS; i++) if (significant_format_p (mp->is_format[i])) - { - ostream_write_str (stream, "/* Flag: "); - ostream_write_str (stream, - make_format_description_string (mp->is_format[i], - format_language[i], - debug)); - ostream_write_str (stream, " */\n"); - } + { + ostream_write_str (stream, "/* Flag: "); + ostream_write_str (stream, + make_format_description_string (mp->is_format[i], + format_language[i], + debug)); + ostream_write_str (stream, " */\n"); + } } if (has_range_p (mp->range)) { @@ -240,32 +240,32 @@ write_message (ostream_t stream, const message_ty *mp, if (mp->msgstr[0] != '\0') { if (mp->is_fuzzy) - { - /* Output the msgid as value, so that at runtime the untranslated - string is returned. */ - write_escaped_string (stream, mp->msgid); - - /* Output the msgstr as a comment, so that at runtime - propertyListFromStringsFileFormat ignores it. */ - if (c_strstr (mp->msgstr, "*/") == NULL) - { - ostream_write_str (stream, " /* = "); - write_escaped_string (stream, mp->msgstr); - ostream_write_str (stream, " */"); - } - else - { - ostream_write_str (stream, "; // = "); - write_escaped_string (stream, mp->msgstr); - } - } + { + /* Output the msgid as value, so that at runtime the untranslated + string is returned. */ + write_escaped_string (stream, mp->msgid); + + /* Output the msgstr as a comment, so that at runtime + propertyListFromStringsFileFormat ignores it. */ + if (c_strstr (mp->msgstr, "*/") == NULL) + { + ostream_write_str (stream, " /* = "); + write_escaped_string (stream, mp->msgstr); + ostream_write_str (stream, " */"); + } + else + { + ostream_write_str (stream, "; // = "); + write_escaped_string (stream, mp->msgstr); + } + } else - write_escaped_string (stream, mp->msgstr); + write_escaped_string (stream, mp->msgstr); } else { /* Output the msgid as value, so that at runtime the untranslated - string is returned. */ + string is returned. */ write_escaped_string (stream, mp->msgid); } ostream_write_str (stream, ";"); @@ -276,7 +276,7 @@ write_message (ostream_t stream, const message_ty *mp, /* Writes an entire message list to the stream. */ static void write_stringtable (ostream_t stream, message_list_ty *mlp, - const char *canon_encoding, size_t page_width, bool debug) + const char *canon_encoding, size_t page_width, bool debug) { bool blank_line; size_t j; @@ -295,21 +295,21 @@ write_stringtable (ostream_t stream, message_list_ty *mlp, const message_ty *mp = mlp->item[j]; if (mp->msgid_plural == NULL) - { - if (blank_line) - ostream_write_str (stream, "\n"); + { + if (blank_line) + ostream_write_str (stream, "\n"); - write_message (stream, mp, page_width, debug); + write_message (stream, mp, page_width, debug); - blank_line = true; - } + blank_line = true; + } } } /* Output the contents of a PO file in .strings syntax. */ static void msgdomain_list_print_stringtable (msgdomain_list_ty *mdlp, ostream_t stream, - size_t page_width, bool debug) + size_t page_width, bool debug) { message_list_ty *mlp; @@ -323,13 +323,13 @@ msgdomain_list_print_stringtable (msgdomain_list_ty *mdlp, ostream_t stream, /* Describes a PO file in .strings syntax. */ const struct catalog_output_format output_format_stringtable = { - msgdomain_list_print_stringtable, /* print */ - true, /* requires_utf8 */ - false, /* supports_color */ - false, /* supports_multiple_domains */ - false, /* supports_contexts */ - false, /* supports_plurals */ - false, /* sorts_obsoletes_to_end */ - false, /* alternative_is_po */ - false /* alternative_is_java_class */ + msgdomain_list_print_stringtable, /* print */ + true, /* requires_utf8 */ + false, /* supports_color */ + false, /* supports_multiple_domains */ + false, /* supports_contexts */ + false, /* supports_plurals */ + false, /* sorts_obsoletes_to_end */ + false, /* alternative_is_po */ + false /* alternative_is_java_class */ }; diff --git a/gettext-tools/src/write-tcl.c b/gettext-tools/src/write-tcl.c index eca949fa8..db582c6f6 100644 --- a/gettext-tools/src/write-tcl.c +++ b/gettext-tools/src/write-tcl.c @@ -63,43 +63,43 @@ write_tcl_string (FILE *stream, const char *str) unsigned int count; count = u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str); if (uc < 0x10000) - { - /* Single UCS-2 'char'. */ - if (uc == 0x000a) - fprintf (stream, "\\n"); - else if (uc == 0x000d) - fprintf (stream, "\\r"); - else if (uc == 0x0022) - fprintf (stream, "\\\""); - else if (uc == 0x0024) - fprintf (stream, "\\$"); - else if (uc == 0x005b) - fprintf (stream, "\\["); - else if (uc == 0x005c) - fprintf (stream, "\\\\"); - else if (uc == 0x005d) - fprintf (stream, "\\]"); - /* No need to escape '{' and '}' because we don't have opening - braces outside the strings. */ + { + /* Single UCS-2 'char'. */ + if (uc == 0x000a) + fprintf (stream, "\\n"); + else if (uc == 0x000d) + fprintf (stream, "\\r"); + else if (uc == 0x0022) + fprintf (stream, "\\\""); + else if (uc == 0x0024) + fprintf (stream, "\\$"); + else if (uc == 0x005b) + fprintf (stream, "\\["); + else if (uc == 0x005c) + fprintf (stream, "\\\\"); + else if (uc == 0x005d) + fprintf (stream, "\\]"); + /* No need to escape '{' and '}' because we don't have opening + braces outside the strings. */ #if 0 - else if (uc == 0x007b) - fprintf (stream, "\\{"); - else if (uc == 0x007d) - fprintf (stream, "\\}"); + else if (uc == 0x007b) + fprintf (stream, "\\{"); + else if (uc == 0x007d) + fprintf (stream, "\\}"); #endif - else if (uc >= 0x0020 && uc < 0x007f) - fprintf (stream, "%c", (int) uc); - else - fprintf (stream, "\\u%c%c%c%c", - hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], - hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); - } + else if (uc >= 0x0020 && uc < 0x007f) + fprintf (stream, "%c", (int) uc); + else + fprintf (stream, "\\u%c%c%c%c", + hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f], + hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]); + } else - /* The \unnnn notation doesn't support characters >= 0x10000. - We output them as UTF-8 byte sequences and hope that either - the Tcl version reading them will be new enough or that the - user is using an UTF-8 locale. */ - fwrite (str, 1, count, stream); + /* The \unnnn notation doesn't support characters >= 0x10000. + We output them as UTF-8 byte sequences and hope that either + the Tcl version reading them will be new enough or that the + user is using an UTF-8 locale. */ + fwrite (str, 1, count, stream); str += count; } fprintf (stream, "\""); @@ -120,14 +120,14 @@ write_msg (FILE *output_file, message_list_ty *mlp, const char *locale_name) message_ty *mp = mlp->item[j]; if (is_header (mp)) - /* Tcl's msgcat unit ignores this, but msgunfmt needs it. */ - fprintf (output_file, "set ::msgcat::header "); + /* Tcl's msgcat unit ignores this, but msgunfmt needs it. */ + fprintf (output_file, "set ::msgcat::header "); else - { - fprintf (output_file, "::msgcat::mcset %s ", locale_name); - write_tcl_string (output_file, mp->msgid); - fprintf (output_file, " "); - } + { + fprintf (output_file, "::msgcat::mcset %s ", locale_name); + write_tcl_string (output_file, mp->msgid); + fprintf (output_file, " "); + } write_tcl_string (output_file, mp->msgstr); fprintf (output_file, "\n"); } @@ -135,8 +135,8 @@ write_msg (FILE *output_file, message_list_ty *mlp, const char *locale_name) int msgdomain_write_tcl (message_list_ty *mlp, const char *canon_encoding, - const char *locale_name, - const char *directory) + const char *locale_name, + const char *directory) { /* If no entry for this domain don't even create the file. */ if (mlp->nitems == 0) @@ -150,14 +150,14 @@ msgdomain_write_tcl (message_list_ty *mlp, const char *canon_encoding, has_context = false; for (j = 0; j < mlp->nitems; j++) if (mlp->item[j]->msgctxt != NULL) - has_context = true; + has_context = true; if (has_context) { - multiline_error (xstrdup (""), - xstrdup (_("\ + multiline_error (xstrdup (""), + xstrdup (_("\ message catalog has context dependent translations\n\ but the Tcl message catalog format doesn't support contexts\n"))); - return 1; + return 1; } } @@ -169,14 +169,14 @@ but the Tcl message catalog format doesn't support contexts\n"))); has_plural = false; for (j = 0; j < mlp->nitems; j++) if (mlp->item[j]->msgid_plural != NULL) - has_plural = true; + has_plural = true; if (has_plural) { - multiline_error (xstrdup (""), - xstrdup (_("\ + multiline_error (xstrdup (""), + xstrdup (_("\ message catalog has plural form translations\n\ but the Tcl message catalog format doesn't support plural handling\n"))); - return 1; + return 1; } } @@ -197,22 +197,22 @@ but the Tcl message catalog format doesn't support plural handling\n"))); memcpy (frobbed_locale_name, locale_name, len + 1); for (p = frobbed_locale_name; *p != '\0'; p++) if (*p >= 'A' && *p <= 'Z') - *p = *p - 'A' + 'a'; + *p = *p - 'A' + 'a'; else if (*p == '.') - { - *p = '\0'; - break; - } + { + *p = '\0'; + break; + } file_name = xconcatenated_filename (directory, frobbed_locale_name, ".msg"); output_file = fopen (file_name, "w"); if (output_file == NULL) { - error (0, errno, _("error while opening \"%s\" for writing"), - file_name); - freea (frobbed_locale_name); - return 1; + error (0, errno, _("error while opening \"%s\" for writing"), + file_name); + freea (frobbed_locale_name); + return 1; } write_msg (output_file, mlp, frobbed_locale_name); @@ -220,7 +220,7 @@ but the Tcl message catalog format doesn't support plural handling\n"))); /* Make sure nothing went wrong. */ if (fwriteerror (output_file)) error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"), - file_name); + file_name); freea (frobbed_locale_name); } diff --git a/gettext-tools/src/write-tcl.h b/gettext-tools/src/write-tcl.h index fbc062635..e6a3dce4c 100644 --- a/gettext-tools/src/write-tcl.h +++ b/gettext-tools/src/write-tcl.h @@ -26,7 +26,7 @@ Return 0 if ok, nonzero on error. */ extern int msgdomain_write_tcl (message_list_ty *mlp, const char *canon_encoding, - const char *locale_name, - const char *directory); + const char *locale_name, + const char *directory); #endif /* _WRITE_TCL_H */ diff --git a/gettext-tools/src/x-awk.c b/gettext-tools/src/x-awk.c index 307952bdd..6a6a9dc30 100644 --- a/gettext-tools/src/x-awk.c +++ b/gettext-tools/src/x-awk.c @@ -71,15 +71,15 @@ x_awk_keyword (const char *name) const char *colon; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid C identifier. - A colon means an invalid parse in split_keywordspec(). */ + A colon means an invalid parse in split_keywordspec(). */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); + insert_keyword_callshape (&keywords, name, end - name, &shape); } } @@ -91,7 +91,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_awk_keyword ("dcgettext"); x_awk_keyword ("dcngettext:1,2"); default_keywords = false; @@ -136,8 +136,8 @@ phase1_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_file_name); return EOF; } @@ -154,7 +154,7 @@ phase1_ungetc (int c) if (c != EOF) { if (c == '\n') - --line_number; + --line_number; ungetc (c, fp); } @@ -180,26 +180,26 @@ phase2_getc () buflen = 0; lineno = line_number; for (;;) - { - c = phase1_getc (); - if (c == '\n' || c == EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - { - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[buflen++] = c; - } - } + { + c = phase1_getc (); + if (c == '\n' || c == EOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + { + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[buflen++] = c; + } + } if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } buffer[buflen] = '\0'; savable_comment_add (buffer); last_comment_line = lineno; @@ -222,14 +222,14 @@ phase2_ungetc (int c) enum token_type_ty { token_type_eof, - token_type_lparen, /* ( */ - token_type_rparen, /* ) */ - token_type_comma, /* , */ - token_type_string, /* "abc" */ - token_type_i18nstring, /* _"abc" */ - token_type_symbol, /* symbol, number */ - token_type_semicolon, /* ; */ - token_type_other /* regexp, misc. operator */ + token_type_lparen, /* ( */ + token_type_rparen, /* ) */ + token_type_comma, /* , */ + token_type_string, /* "abc" */ + token_type_i18nstring, /* _"abc" */ + token_type_symbol, /* symbol, number */ + token_type_semicolon, /* ; */ + token_type_other /* regexp, misc. operator */ }; typedef enum token_type_ty token_type_ty; @@ -237,7 +237,7 @@ typedef struct token_ty token_ty; struct token_ty { token_type_ty type; - char *string; /* for token_type_{symbol,string,i18nstring} */ + char *string; /* for token_type_{symbol,string,i18nstring} */ int line_number; }; @@ -258,88 +258,88 @@ phase7_getc () c = phase1_getc (); if (c == EOF || c == '\n') - break; + break; if (c == '"') - return P7_QUOTES; + return P7_QUOTES; if (c != '\\') - return c; + return c; c = phase1_getc (); if (c == EOF) - break; + break; if (c != '\n') - switch (c) - { - case 'a': - return '\a'; - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - case 'v': - return '\v'; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': - { - int n = c - '0'; - - c = phase1_getc (); - if (c != EOF) - { - if (c >= '0' && c <= '7') - { - n = (n << 3) + (c - '0'); - c = phase1_getc (); - if (c != EOF) - { - if (c >= '0' && c <= '7') - n = (n << 3) + (c - '0'); - else - phase1_ungetc (c); - } - } - else - phase1_ungetc (c); - } - return (unsigned char) n; - } - case 'x': - { - int n = 0; - - for (;;) - { - c = phase1_getc (); - if (c == EOF) - break; - else if (c >= '0' && c <= '9') - n = (n << 4) + (c - '0'); - else if (c >= 'A' && c <= 'F') - n = (n << 4) + (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - n = (n << 4) + (c - 'a' + 10); - else - { - phase1_ungetc (c); - break; - } - } - return (unsigned char) n; - } - default: - return c; - } + switch (c) + { + case 'a': + return '\a'; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + case 'v': + return '\v'; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + { + int n = c - '0'; + + c = phase1_getc (); + if (c != EOF) + { + if (c >= '0' && c <= '7') + { + n = (n << 3) + (c - '0'); + c = phase1_getc (); + if (c != EOF) + { + if (c >= '0' && c <= '7') + n = (n << 3) + (c - '0'); + else + phase1_ungetc (c); + } + } + else + phase1_ungetc (c); + } + return (unsigned char) n; + } + case 'x': + { + int n = 0; + + for (;;) + { + c = phase1_getc (); + if (c == EOF) + break; + else if (c >= '0' && c <= '9') + n = (n << 4) + (c - '0'); + else if (c >= 'A' && c <= 'F') + n = (n << 4) + (c - 'A' + 10); + else if (c >= 'a' && c <= 'f') + n = (n << 4) + (c - 'a' + 10); + else + { + phase1_ungetc (c); + break; + } + } + return (unsigned char) n; + } + default: + return c; + } } phase1_ungetc (c); error_with_progname = false; error (0, 0, _("%s:%d: warning: unterminated string"), logical_file_name, - line_number); + line_number); error_with_progname = true; return P7_QUOTES; } @@ -389,273 +389,273 @@ x_awk_lex (token_ty *tp) c = phase2_getc (); switch (c) - { - case EOF: - tp->type = token_type_eof; - return; - - case '\n': - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - /* Newline is not allowed inside expressions. It usually - introduces a fresh statement. - FIXME: Newlines after any of ',' '{' '?' ':' '||' '&&' 'do' 'else' - does *not* introduce a fresh statement. */ - prefer_division_over_regexp = false; - /* FALLTHROUGH */ - case '\t': - case ' ': - /* Ignore whitespace and comments. */ - continue; - - case '\\': - /* Backslash ought to be immediately followed by a newline. */ - continue; - } + { + case EOF: + tp->type = token_type_eof; + return; + + case '\n': + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + /* Newline is not allowed inside expressions. It usually + introduces a fresh statement. + FIXME: Newlines after any of ',' '{' '?' ':' '||' '&&' 'do' 'else' + does *not* introduce a fresh statement. */ + prefer_division_over_regexp = false; + /* FALLTHROUGH */ + case '\t': + case ' ': + /* Ignore whitespace and comments. */ + continue; + + case '\\': + /* Backslash ought to be immediately followed by a newline. */ + continue; + } last_non_comment_line = tp->line_number; switch (c) - { - case '.': - { - int c2 = phase2_getc (); - phase2_ungetc (c2); - if (!(c2 >= '0' && c2 <= '9')) - { - - tp->type = token_type_other; - prefer_division_over_regexp = false; - return; - } - } - /* FALLTHROUGH */ - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - /* Symbol, or part of a number. */ - bufpos = 0; - for (;;) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase2_getc (); - switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - continue; - default: - if (bufpos == 1 && buffer[0] == '_' && c == '"') - { - tp->type = token_type_i18nstring; - goto case_string; - } - phase2_ungetc (c); - break; - } - break; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = '\0'; - tp->string = xstrdup (buffer); - tp->type = token_type_symbol; - /* Most identifiers can be variable names; after them we must - interpret '/' as division operator. But for awk's builtin - keywords we have three cases: - (a) Must interpret '/' as division operator. "length". - (b) Must interpret '/' as start of a regular expression. - "do", "exit", "print", "printf", "return". - (c) '/' after this keyword in invalid anyway. All others. - I used the following script for the distinction. - for k in $awk_keywords; do - echo; echo $k; awk "function foo () { $k / 10 }" < /dev/null - done - */ - if (strcmp (buffer, "do") == 0 - || strcmp (buffer, "exit") == 0 - || strcmp (buffer, "print") == 0 - || strcmp (buffer, "printf") == 0 - || strcmp (buffer, "return") == 0) - prefer_division_over_regexp = false; - else - prefer_division_over_regexp = true; - return; - - case '"': - tp->type = token_type_string; - case_string: - bufpos = 0; - for (;;) - { - c = phase7_getc (); - if (c == EOF || c == P7_QUOTES) - break; - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = '\0'; - tp->string = xstrdup (buffer); - prefer_division_over_regexp = true; - return; - - case '(': - tp->type = token_type_lparen; - prefer_division_over_regexp = false; - return; - - case ')': - tp->type = token_type_rparen; - prefer_division_over_regexp = true; - return; - - case ',': - tp->type = token_type_comma; - prefer_division_over_regexp = false; - return; - - case ';': - tp->type = token_type_semicolon; - prefer_division_over_regexp = false; - return; - - case ']': - tp->type = token_type_other; - prefer_division_over_regexp = true; - return; - - case '/': - if (!prefer_division_over_regexp) - { - /* Regular expression. - Counting brackets is non-trivial. [[] is balanced, and so is - [\]]. Also, /[/]/ is balanced and ends at the third slash. - Do not count [ or ] if either one is preceded by a \. - A '[' should be counted if - a) it is the first one so far (brackets == 0), or - b) it is the '[' in '[:'. - A ']' should be counted if not preceded by a \. - According to POSIX, []] is how you put a ] into a set. - Try to handle that too. - */ - int brackets = 0; - bool pos0 = true; /* true at start of regexp */ - bool pos1_open = false; /* true after [ at start of regexp */ - bool pos2_open_not = false; /* true after [^ at start of regexp */ - - for (;;) - { - c = phase1_getc (); - - if (c == EOF || c == '\n') - { - phase1_ungetc (c); - error_with_progname = false; - error (0, 0, _("%s:%d: warning: unterminated regular expression"), - logical_file_name, line_number); - error_with_progname = true; - break; - } - else if (c == '[') - { - if (brackets == 0) - brackets++; - else - { - c = phase1_getc (); - if (c == ':') - brackets++; - phase1_ungetc (c); - } - if (pos0) - { - pos0 = false; - pos1_open = true; - continue; - } - } - else if (c == ']') - { - if (!(pos1_open || pos2_open_not)) - brackets--; - } - else if (c == '^') - { - if (pos1_open) - { - pos1_open = false; - pos2_open_not = true; - continue; - } - } - else if (c == '\\') - { - c = phase1_getc (); - /* Backslash-newline is valid and ignored. */ - } - else if (c == '/') - { - if (brackets <= 0) - break; - } - - pos0 = false; - pos1_open = false; - pos2_open_not = false; - } - - tp->type = token_type_other; - prefer_division_over_regexp = false; - return; - } - /* FALLTHROUGH */ - - default: - /* We could carefully recognize each of the 2 and 3 character - operators, but it is not necessary, as we only need to recognize - gettext invocations. Don't bother. */ - tp->type = token_type_other; - prefer_division_over_regexp = false; - return; - } + { + case '.': + { + int c2 = phase2_getc (); + phase2_ungetc (c2); + if (!(c2 >= '0' && c2 <= '9')) + { + + tp->type = token_type_other; + prefer_division_over_regexp = false; + return; + } + } + /* FALLTHROUGH */ + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* Symbol, or part of a number. */ + bufpos = 0; + for (;;) + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase2_getc (); + switch (c) + { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + continue; + default: + if (bufpos == 1 && buffer[0] == '_' && c == '"') + { + tp->type = token_type_i18nstring; + goto case_string; + } + phase2_ungetc (c); + break; + } + break; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = '\0'; + tp->string = xstrdup (buffer); + tp->type = token_type_symbol; + /* Most identifiers can be variable names; after them we must + interpret '/' as division operator. But for awk's builtin + keywords we have three cases: + (a) Must interpret '/' as division operator. "length". + (b) Must interpret '/' as start of a regular expression. + "do", "exit", "print", "printf", "return". + (c) '/' after this keyword in invalid anyway. All others. + I used the following script for the distinction. + for k in $awk_keywords; do + echo; echo $k; awk "function foo () { $k / 10 }" < /dev/null + done + */ + if (strcmp (buffer, "do") == 0 + || strcmp (buffer, "exit") == 0 + || strcmp (buffer, "print") == 0 + || strcmp (buffer, "printf") == 0 + || strcmp (buffer, "return") == 0) + prefer_division_over_regexp = false; + else + prefer_division_over_regexp = true; + return; + + case '"': + tp->type = token_type_string; + case_string: + bufpos = 0; + for (;;) + { + c = phase7_getc (); + if (c == EOF || c == P7_QUOTES) + break; + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = '\0'; + tp->string = xstrdup (buffer); + prefer_division_over_regexp = true; + return; + + case '(': + tp->type = token_type_lparen; + prefer_division_over_regexp = false; + return; + + case ')': + tp->type = token_type_rparen; + prefer_division_over_regexp = true; + return; + + case ',': + tp->type = token_type_comma; + prefer_division_over_regexp = false; + return; + + case ';': + tp->type = token_type_semicolon; + prefer_division_over_regexp = false; + return; + + case ']': + tp->type = token_type_other; + prefer_division_over_regexp = true; + return; + + case '/': + if (!prefer_division_over_regexp) + { + /* Regular expression. + Counting brackets is non-trivial. [[] is balanced, and so is + [\]]. Also, /[/]/ is balanced and ends at the third slash. + Do not count [ or ] if either one is preceded by a \. + A '[' should be counted if + a) it is the first one so far (brackets == 0), or + b) it is the '[' in '[:'. + A ']' should be counted if not preceded by a \. + According to POSIX, []] is how you put a ] into a set. + Try to handle that too. + */ + int brackets = 0; + bool pos0 = true; /* true at start of regexp */ + bool pos1_open = false; /* true after [ at start of regexp */ + bool pos2_open_not = false; /* true after [^ at start of regexp */ + + for (;;) + { + c = phase1_getc (); + + if (c == EOF || c == '\n') + { + phase1_ungetc (c); + error_with_progname = false; + error (0, 0, _("%s:%d: warning: unterminated regular expression"), + logical_file_name, line_number); + error_with_progname = true; + break; + } + else if (c == '[') + { + if (brackets == 0) + brackets++; + else + { + c = phase1_getc (); + if (c == ':') + brackets++; + phase1_ungetc (c); + } + if (pos0) + { + pos0 = false; + pos1_open = true; + continue; + } + } + else if (c == ']') + { + if (!(pos1_open || pos2_open_not)) + brackets--; + } + else if (c == '^') + { + if (pos1_open) + { + pos1_open = false; + pos2_open_not = true; + continue; + } + } + else if (c == '\\') + { + c = phase1_getc (); + /* Backslash-newline is valid and ignored. */ + } + else if (c == '/') + { + if (brackets <= 0) + break; + } + + pos0 = false; + pos1_open = false; + pos2_open_not = false; + } + + tp->type = token_type_other; + prefer_division_over_regexp = false; + return; + } + /* FALLTHROUGH */ + + default: + /* We could carefully recognize each of the 2 and 3 character + operators, but it is not necessary, as we only need to recognize + gettext invocations. Don't bother. */ + tp->type = token_type_other; + prefer_division_over_regexp = false; + return; + } } } @@ -687,9 +687,9 @@ static flag_context_list_table_ty *flag_context_list_table; Return true upon eof, false upon closing parenthesis. */ static bool extract_parenthesized (message_list_ty *mlp, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - struct arglist_parser *argparser) + flag_context_ty outer_context, + flag_context_list_iterator_ty context_iter, + struct arglist_parser *argparser) { /* Current argument number. */ int arg = 1; @@ -706,7 +706,7 @@ extract_parenthesized (message_list_ty *mlp, /* Current context. */ flag_context_ty inner_context = inherited_context (outer_context, - flag_context_list_iterator_advance (&context_iter)); + flag_context_list_iterator_advance (&context_iter)); /* Start state is 0. */ state = 0; @@ -718,145 +718,145 @@ extract_parenthesized (message_list_ty *mlp, x_awk_lex (&token); if (next_is_argument && token.type != token_type_lparen) - { - /* An argument list starts, even though there is no '('. */ - context_iter = next_context_iter; - outer_context = inner_context; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - } + { + /* An argument list starts, even though there is no '('. */ + context_iter = next_context_iter; + outer_context = inner_context; + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + } switch (token.type) - { - case token_type_symbol: - { - void *keyword_value; - - if (hash_find_entry (&keywords, token.string, strlen (token.string), - &keyword_value) - == 0) - { - next_shapes = (const struct callshapes *) keyword_value; - state = 1; - } - else - state = 0; - } - next_is_argument = - (strcmp (token.string, "print") == 0 - || strcmp (token.string, "printf") == 0); - next_context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - token.string, strlen (token.string))); - free (token.string); - continue; - - case token_type_lparen: - if (extract_parenthesized (mlp, inner_context, next_context_iter, - arglist_parser_alloc (mlp, - state ? next_shapes : NULL))) - { - arglist_parser_done (argparser, arg); - return true; - } - next_is_argument = false; - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rparen: - arglist_parser_done (argparser, arg); - return false; - - case token_type_comma: - arg++; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_is_argument = false; - next_context_iter = passthrough_context_list_iterator; - state = 0; - continue; - - case token_type_string: - { - lex_pos_ty pos; - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - - if (extract_all) - remember_a_message (mlp, NULL, token.string, inner_context, &pos, - NULL, savable_comment); - else - arglist_parser_remember (argparser, arg, token.string, - inner_context, - pos.file_name, pos.line_number, - savable_comment); - } - next_is_argument = false; - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_i18nstring: - { - lex_pos_ty pos; - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - - remember_a_message (mlp, NULL, token.string, inner_context, &pos, - NULL, savable_comment); - } - next_is_argument = false; - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_semicolon: - /* An argument list ends, and a new statement begins. */ - /* FIXME: Should handle newline that acts as statement separator - in the same way. */ - /* FIXME: Instead of resetting outer_context here, it may be better - to recurse in the next_is_argument handling above, waiting for - the next semicolon or other statement terminator. */ - outer_context = null_context; - context_iter = null_context_list_iterator; - next_is_argument = false; - next_context_iter = passthrough_context_list_iterator; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - state = 0; - continue; - - case token_type_eof: - arglist_parser_done (argparser, arg); - return true; - - case token_type_other: - next_is_argument = false; - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - default: - abort (); - } + { + case token_type_symbol: + { + void *keyword_value; + + if (hash_find_entry (&keywords, token.string, strlen (token.string), + &keyword_value) + == 0) + { + next_shapes = (const struct callshapes *) keyword_value; + state = 1; + } + else + state = 0; + } + next_is_argument = + (strcmp (token.string, "print") == 0 + || strcmp (token.string, "printf") == 0); + next_context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + token.string, strlen (token.string))); + free (token.string); + continue; + + case token_type_lparen: + if (extract_parenthesized (mlp, inner_context, next_context_iter, + arglist_parser_alloc (mlp, + state ? next_shapes : NULL))) + { + arglist_parser_done (argparser, arg); + return true; + } + next_is_argument = false; + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_rparen: + arglist_parser_done (argparser, arg); + return false; + + case token_type_comma: + arg++; + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + next_is_argument = false; + next_context_iter = passthrough_context_list_iterator; + state = 0; + continue; + + case token_type_string: + { + lex_pos_ty pos; + pos.file_name = logical_file_name; + pos.line_number = token.line_number; + + if (extract_all) + remember_a_message (mlp, NULL, token.string, inner_context, &pos, + NULL, savable_comment); + else + arglist_parser_remember (argparser, arg, token.string, + inner_context, + pos.file_name, pos.line_number, + savable_comment); + } + next_is_argument = false; + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_i18nstring: + { + lex_pos_ty pos; + pos.file_name = logical_file_name; + pos.line_number = token.line_number; + + remember_a_message (mlp, NULL, token.string, inner_context, &pos, + NULL, savable_comment); + } + next_is_argument = false; + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_semicolon: + /* An argument list ends, and a new statement begins. */ + /* FIXME: Should handle newline that acts as statement separator + in the same way. */ + /* FIXME: Instead of resetting outer_context here, it may be better + to recurse in the next_is_argument handling above, waiting for + the next semicolon or other statement terminator. */ + outer_context = null_context; + context_iter = null_context_list_iterator; + next_is_argument = false; + next_context_iter = passthrough_context_list_iterator; + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + state = 0; + continue; + + case token_type_eof: + arglist_parser_done (argparser, arg); + return true; + + case token_type_other: + next_is_argument = false; + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + default: + abort (); + } } } void extract_awk (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { message_list_ty *mlp = mdlp->item[0]->messages; @@ -877,7 +877,7 @@ extract_awk (FILE *f, /* Eat tokens until eof is seen. When extract_parenthesized returns due to an unbalanced closing parenthesis, just restart it. */ while (!extract_parenthesized (mlp, null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) + arglist_parser_alloc (mlp, NULL))) ; fp = NULL; diff --git a/gettext-tools/src/x-awk.h b/gettext-tools/src/x-awk.h index 7f88697f8..6cfd33b7f 100644 --- a/gettext-tools/src/x-awk.h +++ b/gettext-tools/src/x-awk.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_AWK \ - { "awk", "awk" }, \ + { "awk", "awk" }, \ #define SCANNERS_AWK \ - { "awk", extract_awk, \ - &flag_table_awk, &formatstring_awk, NULL }, \ + { "awk", extract_awk, \ + &flag_table_awk, &formatstring_awk, NULL }, \ /* Scan an awk file and add its translatable strings to mdlp. */ extern void extract_awk (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); extern void x_awk_keyword (const char *keyword); extern void x_awk_extract_all (void); diff --git a/gettext-tools/src/x-c.c b/gettext-tools/src/x-c.c index 14a5b3682..08a40b5d8 100644 --- a/gettext-tools/src/x-c.c +++ b/gettext-tools/src/x-c.c @@ -117,15 +117,15 @@ add_keyword (const char *name, hash_table *keywords) const char *colon; if (keywords->table == NULL) - hash_init (keywords, 100); + hash_init (keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid C identifier. - A colon means an invalid parse in split_keywordspec(). */ + A colon means an invalid parse in split_keywordspec(). */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) - insert_keyword_callshape (keywords, name, end - name, &shape); + insert_keyword_callshape (keywords, name, end - name, &shape); } } @@ -149,7 +149,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_c_keyword ("gettext"); x_c_keyword ("dgettext:2"); x_c_keyword ("dcgettext:2"); @@ -177,10 +177,10 @@ init_keywords () x_objc_keyword ("npgettext:1c,2,3"); x_objc_keyword ("dnpgettext:2c,3,4"); x_objc_keyword ("dcnpgettext:2c,3,4"); - x_objc_keyword ("NSLocalizedString"); /* similar to gettext */ - x_objc_keyword ("_"); /* similar to gettext */ + x_objc_keyword ("NSLocalizedString"); /* similar to gettext */ + x_objc_keyword ("_"); /* similar to gettext */ x_objc_keyword ("NSLocalizedStaticString"); /* similar to gettext_noop */ - x_objc_keyword ("__"); /* similar to gettext_noop */ + x_objc_keyword ("__"); /* similar to gettext_noop */ default_keywords = false; } @@ -481,8 +481,8 @@ phase0_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_file_name); return EOF; } @@ -491,7 +491,7 @@ phase0_getc () int c1 = getc (fp); if (c1 != EOF && c1 != '\n') - ungetc (c1, fp); + ungetc (c1, fp); /* Seen line terminator CR or CR/LF. */ return '\n'; @@ -525,31 +525,31 @@ phase1_getc () { c = phase1_pushback[--phase1_pushback_length]; if (c == '\n') - ++line_number; + ++line_number; return c; } for (;;) { c = phase0_getc (); switch (c) - { - case '\n': - ++line_number; - return '\n'; - - case '\\': - c = phase0_getc (); - if (c != '\n') - { - phase0_ungetc (c); - return '\\'; - } - ++line_number; - break; - - default: - return c; - } + { + case '\n': + ++line_number; + return '\n'; + + case '\\': + c = phase0_getc (); + if (c != '\n') + { + phase0_ungetc (c); + return '\\'; + } + ++line_number; + break; + + default: + return c; + } } } @@ -569,7 +569,7 @@ phase1_ungetc (int c) default: if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); + abort (); phase1_pushback[phase1_pushback_length++] = c; break; } @@ -638,7 +638,7 @@ phase2_ungetc (int c) if (c != EOF) { if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); + abort (); phase2_pushback[phase2_pushback_length++] = c; } } @@ -661,13 +661,13 @@ phase3_getc () { int c = phase2_getc (); if (c != '\\') - return c; + return c; c = phase2_getc (); if (c != '\n') - { - phase2_ungetc (c); - return '\\'; - } + { + phase2_ungetc (c); + return '\\'; + } } } @@ -679,7 +679,7 @@ phase3_ungetc (int c) if (c != EOF) { if (phase3_pushback_length == SIZEOF (phase3_pushback)) - abort (); + abort (); phase3_pushback[phase3_pushback_length++] = c; } } @@ -713,7 +713,7 @@ comment_line_end (size_t chars_to_remove) { buflen -= chars_to_remove; while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { @@ -758,39 +758,39 @@ phase4_getc () comment_start (); last_was_star = false; for (;;) - { - c = phase3_getc (); - if (c == EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - switch (c) - { - case '\n': - comment_line_end (1); - comment_start (); - last_was_star = false; - continue; - - case '*': - last_was_star = true; - continue; - - case '/': - if (last_was_star) - { - comment_line_end (2); - break; - } - /* FALLTHROUGH */ - - default: - last_was_star = false; - continue; - } - break; - } + { + c = phase3_getc (); + if (c == EOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + switch (c) + { + case '\n': + comment_line_end (1); + comment_start (); + last_was_star = false; + continue; + + case '*': + last_was_star = true; + continue; + + case '/': + if (last_was_star) + { + comment_line_end (2); + break; + } + /* FALLTHROUGH */ + + default: + last_was_star = false; + continue; + } + break; + } last_comment_line = newline_count; return ' '; @@ -798,14 +798,14 @@ phase4_getc () /* C++ or ISO C 99 comment. */ comment_start (); for (;;) - { - c = phase3_getc (); - if (c == '\n' || c == EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - } + { + c = phase3_getc (); + if (c == '\n' || c == EOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + } comment_line_end (0); last_comment_line = newline_count; return '\n'; @@ -829,19 +829,19 @@ static bool objc_extensions; enum token_type_ty { - token_type_character_constant, /* 'x' */ + token_type_character_constant, /* 'x' */ token_type_eof, token_type_eoln, - token_type_hash, /* # */ - token_type_lparen, /* ( */ - token_type_rparen, /* ) */ - token_type_comma, /* , */ - token_type_colon, /* : */ - token_type_name, /* abc */ - token_type_number, /* 2.7 */ - token_type_string_literal, /* "abc" */ - token_type_symbol, /* < > = etc. */ - token_type_objc_special, /* @ */ + token_type_hash, /* # */ + token_type_lparen, /* ( */ + token_type_rparen, /* ) */ + token_type_comma, /* , */ + token_type_colon, /* : */ + token_type_name, /* abc */ + token_type_number, /* 2.7 */ + token_type_string_literal, /* "abc" */ + token_type_symbol, /* < > = etc. */ + token_type_objc_special, /* @ */ token_type_white_space }; typedef enum token_type_ty token_type_ty; @@ -850,9 +850,9 @@ typedef struct token_ty token_ty; struct token_ty { token_type_ty type; - char *string; /* for token_type_name, token_type_string_literal */ - refcounted_string_list_ty *comment; /* for token_type_string_literal, - token_type_objc_special */ + char *string; /* for token_type_name, token_type_string_literal */ + refcounted_string_list_ty *comment; /* for token_type_string_literal, + token_type_objc_special */ long number; int line_number; }; @@ -907,7 +907,7 @@ phase7_getc () { default: /* Unknown escape sequences really should be an error, but just - ignore them, and let the real compiler complain. */ + ignore them, and let the real compiler complain. */ phase3_ungetc (c); return '\\'; @@ -923,8 +923,8 @@ phase7_getc () return '\b'; /* The \e escape is preculiar to gcc, and assumes an ASCII - character set (or superset). We don't provide support for it - here. */ + character set (or superset). We don't provide support for it + here. */ case 'f': return '\f'; @@ -940,62 +940,62 @@ phase7_getc () case 'x': c = phase3_getc (); switch (c) - { - default: - phase3_ungetc (c); - phase3_ungetc ('x'); - return '\\'; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - break; - } + { + default: + phase3_ungetc (c); + phase3_ungetc ('x'); + return '\\'; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + break; + } n = 0; for (;;) - { - switch (c) - { - default: - phase3_ungetc (c); - return n; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = n * 16 + c - '0'; - break; - - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - n = n * 16 + 10 + c - 'A'; - break; - - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - n = n * 16 + 10 + c - 'a'; - break; - } - c = phase3_getc (); - } + { + switch (c) + { + default: + phase3_ungetc (c); + return n; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + n = n * 16 + c - '0'; + break; + + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + n = n * 16 + 10 + c - 'A'; + break; + + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + n = n * 16 + 10 + c - 'a'; + break; + } + c = phase3_getc (); + } return n; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': n = 0; for (j = 0; j < 3; ++j) - { - n = n * 8 + c - '0'; - c = phase3_getc (); - switch (c) - { - default: - break; - - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - continue; - } - break; - } + { + n = n * 8 + c - '0'; + c = phase3_getc (); + switch (c) + { + default: + break; + + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + continue; + } + break; + } phase3_ungetc (c); return n; } @@ -1059,21 +1059,21 @@ phase5_get (token_ty *tp) case '\f': case '\t': for (;;) - { - c = phase4_getc (); - switch (c) - { - case ' ': - case '\f': - case '\t': - continue; - - default: - phase4_ungetc (c); - break; - } - break; - } + { + c = phase4_getc (); + switch (c) + { + case ' ': + case '\f': + case '\t': + continue; + + default: + phase4_ungetc (c); + break; + } + break; + } tp->type = token_type_white_space; return; @@ -1088,42 +1088,42 @@ phase5_get (token_ty *tp) case 'v': case 'w': case 'x': case 'y': case 'z': bufpos = 0; for (;;) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase4_getc (); - switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - continue; - - default: - phase4_ungetc (c); - break; - } - break; - } + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase4_getc (); + switch (c) + { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + continue; + + default: + phase4_ungetc (c); + break; + } + break; + } if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } buffer[bufpos] = 0; tp->string = xstrdup (buffer); tp->type = token_type_name; @@ -1133,77 +1133,77 @@ phase5_get (token_ty *tp) c = phase4_getc (); phase4_ungetc (c); switch (c) - { - default: - tp->type = token_type_symbol; - return; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - c = '.'; - break; - } + { + default: + tp->type = token_type_symbol; + return; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + c = '.'; + break; + } /* FALLTHROUGH */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* The preprocessing number token is more "generous" than the C - number tokens. This is mostly due to token pasting (another - thing we can ignore here). */ + number tokens. This is mostly due to token pasting (another + thing we can ignore here). */ bufpos = 0; for (;;) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase4_getc (); - switch (c) - { - case 'e': - case 'E': - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase4_getc (); - if (c != '+' || c != '-') - { - phase4_ungetc (c); - break; - } - continue; - - case 'A': case 'B': case 'C': case 'D': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case 'a': case 'b': case 'c': case 'd': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case '.': - continue; - - default: - phase4_ungetc (c); - break; - } - break; - } + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase4_getc (); + switch (c) + { + case 'e': + case 'E': + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase4_getc (); + if (c != '+' || c != '-') + { + phase4_ungetc (c); + break; + } + continue; + + case 'A': case 'B': case 'C': case 'D': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case 'a': case 'b': case 'c': case 'd': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case '.': + continue; + + default: + phase4_ungetc (c); + break; + } + break; + } if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } buffer[bufpos] = 0; tp->type = token_type_number; tp->number = atol (buffer); @@ -1211,61 +1211,61 @@ phase5_get (token_ty *tp) case '\'': /* We could worry about the 'L' before wide character constants, - but ignoring it has no effect unless one of the keywords is - "L". Just pretend it won't happen. Also, we don't need to - remember the character constant. */ + but ignoring it has no effect unless one of the keywords is + "L". Just pretend it won't happen. Also, we don't need to + remember the character constant. */ for (;;) - { - c = phase7_getc (); - if (c == P7_NEWLINE) - { - error_with_progname = false; - error (0, 0, _("%s:%d: warning: unterminated character constant"), - logical_file_name, line_number - 1); - error_with_progname = true; - phase7_ungetc ('\n'); - break; - } - if (c == EOF || c == P7_QUOTE) - break; - } + { + c = phase7_getc (); + if (c == P7_NEWLINE) + { + error_with_progname = false; + error (0, 0, _("%s:%d: warning: unterminated character constant"), + logical_file_name, line_number - 1); + error_with_progname = true; + phase7_ungetc ('\n'); + break; + } + if (c == EOF || c == P7_QUOTE) + break; + } tp->type = token_type_character_constant; return; case '"': /* We could worry about the 'L' before wide string constants, - but since gettext's argument is not a wide character string, - let the compiler complain about the argument not matching the - prototype. Just pretend it won't happen. */ + but since gettext's argument is not a wide character string, + let the compiler complain about the argument not matching the + prototype. Just pretend it won't happen. */ bufpos = 0; for (;;) - { - c = phase7_getc (); - if (c == P7_NEWLINE) - { - error_with_progname = false; - error (0, 0, _("%s:%d: warning: unterminated string literal"), - logical_file_name, line_number - 1); - error_with_progname = true; - phase7_ungetc ('\n'); - break; - } - if (c == EOF || c == P7_QUOTES) - break; - if (c == P7_QUOTE) - c = '\''; - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - } + { + c = phase7_getc (); + if (c == P7_NEWLINE) + { + error_with_progname = false; + error (0, 0, _("%s:%d: warning: unterminated string literal"), + logical_file_name, line_number - 1); + error_with_progname = true; + phase7_ungetc ('\n'); + break; + } + if (c == EOF || c == P7_QUOTES) + break; + if (c == P7_QUOTE) + c = '\''; + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + } if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } buffer[bufpos] = 0; tp->type = token_type_string_literal; tp->string = xstrdup (buffer); @@ -1294,17 +1294,17 @@ phase5_get (token_ty *tp) case '@': if (objc_extensions) - { - tp->type = token_type_objc_special; - tp->comment = add_reference (savable_comment); - return; - } + { + tp->type = token_type_objc_special; + tp->comment = add_reference (savable_comment); + return; + } /* FALLTHROUGH */ default: /* We could carefully recognize each of the 2 and 3 character - operators, but it is not necessary, as we only need to recognize - gettext invocations. Don't bother. */ + operators, but it is not necessary, as we only need to recognize + gettext invocations. Don't bother. */ tp->type = token_type_symbol; return; } @@ -1318,7 +1318,7 @@ phase5_unget (token_ty *tp) if (tp->type != token_type_eof) { if (phase5_pushback_length == SIZEOF (phase5_pushback)) - abort (); + abort (); phase5_pushback[phase5_pushback_length++] = *tp; } } @@ -1331,7 +1331,7 @@ phase5_unget (token_ty *tp) static void phaseX_get (token_ty *tp) { - static bool middle; /* false at the beginning of a line, true otherwise. */ + static bool middle; /* false at the beginning of a line, true otherwise. */ phase5_get (tp); @@ -1340,28 +1340,28 @@ phaseX_get (token_ty *tp) else { if (middle) - { - /* Turn hash in the middle of a line into a plain symbol token. */ - if (tp->type == token_type_hash) - tp->type = token_type_symbol; - } + { + /* Turn hash in the middle of a line into a plain symbol token. */ + if (tp->type == token_type_hash) + tp->type = token_type_symbol; + } else - { - /* When we see leading whitespace followed by a hash sign, - discard the leading white space token. The hash is all - phase 6 is interested in. */ - if (tp->type == token_type_white_space) - { - token_ty next; - - phase5_get (&next); - if (next.type == token_type_hash) - *tp = next; - else - phase5_unget (&next); - } - middle = true; - } + { + /* When we see leading whitespace followed by a hash sign, + discard the leading white space token. The hash is all + phase 6 is interested in. */ + if (tp->type == token_type_white_space) + { + token_ty next; + + phase5_get (&next); + if (next.type == token_type_hash) + *tp = next; + else + phase5_unget (&next); + } + middle = true; + } } } @@ -1391,62 +1391,62 @@ phase6_get (token_ty *tp) for (;;) { /* Get the next token. If it is not a '#' at the beginning of a - line (ignoring whitespace), return immediately. */ + line (ignoring whitespace), return immediately. */ phaseX_get (tp); if (tp->type != token_type_hash) - return; + return; /* Accumulate the rest of the directive in a buffer, until the - "define" keyword is seen or until end of line. */ + "define" keyword is seen or until end of line. */ bufpos = 0; for (;;) - { - phaseX_get (tp); - if (tp->type == token_type_eoln || tp->type == token_type_eof) - break; - - /* Before the "define" keyword and inside other directives - white space is irrelevant. So just throw it away. */ - if (tp->type != token_type_white_space) - { - /* If it is a #define directive, return immediately, - thus treating the body of the #define directive like - normal input. */ - if (bufpos == 0 - && tp->type == token_type_name - && strcmp (tp->string, "define") == 0) - return; - - /* Accumulate. */ - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buf = xrealloc (buf, bufmax * sizeof (buf[0])); - } - buf[bufpos++] = *tp; - } - } + { + phaseX_get (tp); + if (tp->type == token_type_eoln || tp->type == token_type_eof) + break; + + /* Before the "define" keyword and inside other directives + white space is irrelevant. So just throw it away. */ + if (tp->type != token_type_white_space) + { + /* If it is a #define directive, return immediately, + thus treating the body of the #define directive like + normal input. */ + if (bufpos == 0 + && tp->type == token_type_name + && strcmp (tp->string, "define") == 0) + return; + + /* Accumulate. */ + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buf = xrealloc (buf, bufmax * sizeof (buf[0])); + } + buf[bufpos++] = *tp; + } + } /* If it is a #line directive, with no macros to expand, act on - it. Ignore all other directives. */ + it. Ignore all other directives. */ if (bufpos >= 3 && buf[0].type == token_type_name - && strcmp (buf[0].string, "line") == 0 - && buf[1].type == token_type_number - && buf[2].type == token_type_string_literal) - { - logical_file_name = xstrdup (buf[2].string); - line_number = buf[1].number; - } + && strcmp (buf[0].string, "line") == 0 + && buf[1].type == token_type_number + && buf[2].type == token_type_string_literal) + { + logical_file_name = xstrdup (buf[2].string); + line_number = buf[1].number; + } if (bufpos >= 2 && buf[0].type == token_type_number - && buf[1].type == token_type_string_literal) - { - logical_file_name = xstrdup (buf[1].string); - line_number = buf[0].number; - } + && buf[1].type == token_type_string_literal) + { + logical_file_name = xstrdup (buf[1].string); + line_number = buf[0].number; + } /* Release the storage held by the directive. */ for (j = 0; j < bufpos; ++j) - free_token (&buf[j]); + free_token (&buf[j]); /* We must reset the selected comments. */ savable_comment_reset (); @@ -1461,7 +1461,7 @@ phase6_unget (token_ty *tp) if (tp->type != token_type_eof) { if (phase6_pushback_length == SIZEOF (phase6_pushback)) - abort (); + abort (); phase6_pushback[phase6_pushback_length++] = *tp; } } @@ -1481,30 +1481,30 @@ is_inttypes_macro (const char *name) { name += 3; if (name[0] == 'd' || name[0] == 'i' || name[0] == 'o' || name[0] == 'u' - || name[0] == 'x' || name[0] == 'X') - { - name += 1; - if (name[0] == 'M' && name[1] == 'A' && name[2] == 'X' - && name[3] == '\0') - return true; - if (name[0] == 'P' && name[1] == 'T' && name[2] == 'R' - && name[3] == '\0') - return true; - if (name[0] == 'L' && name[1] == 'E' && name[2] == 'A' - && name[3] == 'S' && name[4] == 'T') - name += 5; - else if (name[0] == 'F' && name[1] == 'A' && name[2] == 'S' - && name[3] == 'T') - name += 4; - if (name[0] == '8' && name[1] == '\0') - return true; - if (name[0] == '1' && name[1] == '6' && name[2] == '\0') - return true; - if (name[0] == '3' && name[1] == '2' && name[2] == '\0') - return true; - if (name[0] == '6' && name[1] == '4' && name[2] == '\0') - return true; - } + || name[0] == 'x' || name[0] == 'X') + { + name += 1; + if (name[0] == 'M' && name[1] == 'A' && name[2] == 'X' + && name[3] == '\0') + return true; + if (name[0] == 'P' && name[1] == 'T' && name[2] == 'R' + && name[3] == '\0') + return true; + if (name[0] == 'L' && name[1] == 'E' && name[2] == 'A' + && name[3] == 'S' && name[4] == 'T') + name += 5; + else if (name[0] == 'F' && name[1] == 'A' && name[2] == 'S' + && name[3] == 'T') + name += 4; + if (name[0] == '8' && name[1] == '\0') + return true; + if (name[0] == '1' && name[1] == '6' && name[2] == '\0') + return true; + if (name[0] == '3' && name[1] == '2' && name[2] == '\0') + return true; + if (name[0] == '6' && name[1] == '4' && name[2] == '\0') + return true; + } } return false; } @@ -1541,22 +1541,22 @@ phase8b_get (token_ty *tp) phase8a_get (tp); if (tp->type == token_type_white_space) - continue; + continue; if (tp->type == token_type_eoln) - { - /* We have to track the last occurrence of a string. One - mode of xgettext allows to group an extracted message - with a comment for documentation. The rule which states - which comment is assumed to be grouped with the message - says it should immediately precede it. Our - interpretation: between the last line of the comment and - the line in which the keyword is found must be no line - with non-white space tokens. */ - ++newline_count; - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - continue; - } + { + /* We have to track the last occurrence of a string. One + mode of xgettext allows to group an extracted message + with a comment for documentation. The rule which states + which comment is assumed to be grouped with the message + says it should immediately precede it. Our + interpretation: between the last line of the comment and + the line in which the keyword is found must be no line + with non-white space tokens. */ + ++newline_count; + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + continue; + } break; } } @@ -1616,10 +1616,10 @@ phase8_get (token_ty *tp) phase8c_get (&tmp); if (tmp.type != token_type_string_literal) - { - phase8c_unget (&tmp); - return; - } + { + phase8c_unget (&tmp); + return; + } len = strlen (tp->string); tp->string = xrealloc (tp->string, len + strlen (tmp.string) + 1); strcpy (tp->string + len, tmp.string); @@ -1680,73 +1680,73 @@ x_c_lex (xgettext_token_ty *tp) phase8_get (&token); switch (token.type) - { - case token_type_eof: - tp->type = xgettext_token_type_eof; - return; - - case token_type_name: - last_non_comment_line = newline_count; - - if (hash_find_entry (objc_extensions ? &objc_keywords : &c_keywords, - token.string, strlen (token.string), - &keyword_value) - == 0) - { - tp->type = xgettext_token_type_keyword; - tp->shapes = (const struct callshapes *) keyword_value; - tp->pos.file_name = logical_file_name; - tp->pos.line_number = token.line_number; - } - else - tp->type = xgettext_token_type_symbol; - tp->string = token.string; - return; - - case token_type_lparen: - last_non_comment_line = newline_count; - - tp->type = xgettext_token_type_lparen; - return; - - case token_type_rparen: - last_non_comment_line = newline_count; - - tp->type = xgettext_token_type_rparen; - return; - - case token_type_comma: - last_non_comment_line = newline_count; - - tp->type = xgettext_token_type_comma; - return; - - case token_type_colon: - last_non_comment_line = newline_count; - - tp->type = xgettext_token_type_colon; - return; - - case token_type_string_literal: - last_non_comment_line = newline_count; - - tp->type = xgettext_token_type_string_literal; - tp->string = token.string; - tp->comment = token.comment; - tp->pos.file_name = logical_file_name; - tp->pos.line_number = token.line_number; - return; - - case token_type_objc_special: - drop_reference (token.comment); - /* FALLTHROUGH */ - - default: - last_non_comment_line = newline_count; - - tp->type = xgettext_token_type_other; - return; - } + { + case token_type_eof: + tp->type = xgettext_token_type_eof; + return; + + case token_type_name: + last_non_comment_line = newline_count; + + if (hash_find_entry (objc_extensions ? &objc_keywords : &c_keywords, + token.string, strlen (token.string), + &keyword_value) + == 0) + { + tp->type = xgettext_token_type_keyword; + tp->shapes = (const struct callshapes *) keyword_value; + tp->pos.file_name = logical_file_name; + tp->pos.line_number = token.line_number; + } + else + tp->type = xgettext_token_type_symbol; + tp->string = token.string; + return; + + case token_type_lparen: + last_non_comment_line = newline_count; + + tp->type = xgettext_token_type_lparen; + return; + + case token_type_rparen: + last_non_comment_line = newline_count; + + tp->type = xgettext_token_type_rparen; + return; + + case token_type_comma: + last_non_comment_line = newline_count; + + tp->type = xgettext_token_type_comma; + return; + + case token_type_colon: + last_non_comment_line = newline_count; + + tp->type = xgettext_token_type_colon; + return; + + case token_type_string_literal: + last_non_comment_line = newline_count; + + tp->type = xgettext_token_type_string_literal; + tp->string = token.string; + tp->comment = token.comment; + tp->pos.file_name = logical_file_name; + tp->pos.line_number = token.line_number; + return; + + case token_type_objc_special: + drop_reference (token.comment); + /* FALLTHROUGH */ + + default: + last_non_comment_line = newline_count; + + tp->type = xgettext_token_type_other; + return; + } } } @@ -1778,9 +1778,9 @@ static flag_context_list_table_ty *flag_context_list_table; Return true upon eof, false upon closing parenthesis. */ static bool extract_parenthesized (message_list_ty *mlp, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - struct arglist_parser *argparser) + flag_context_ty outer_context, + flag_context_list_iterator_ty context_iter, + struct arglist_parser *argparser) { /* Current argument number. */ int arg = 1; @@ -1798,7 +1798,7 @@ extract_parenthesized (message_list_ty *mlp, /* Current context. */ flag_context_ty inner_context = inherited_context (outer_context, - flag_context_list_iterator_advance (&context_iter)); + flag_context_list_iterator_advance (&context_iter)); /* Start state is 0. */ state = 0; @@ -1809,119 +1809,119 @@ extract_parenthesized (message_list_ty *mlp, x_c_lex (&token); switch (token.type) - { - case xgettext_token_type_keyword: - next_shapes = token.shapes; - state = 1; - goto keyword_or_symbol; - - case xgettext_token_type_symbol: - state = 0; - keyword_or_symbol: - next_context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - token.string, strlen (token.string))); - if (objc_extensions) - { - size_t token_string_len = strlen (token.string); - token.string = xrealloc (token.string, token_string_len + 2); - token.string[token_string_len] = ':'; - token.string[token_string_len + 1] = '\0'; - selectorcall_context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - token.string, token_string_len + 1)); - } - free (token.string); - continue; - - case xgettext_token_type_lparen: - if (extract_parenthesized (mlp, inner_context, next_context_iter, - arglist_parser_alloc (mlp, - state ? next_shapes : NULL))) - { - arglist_parser_done (argparser, arg); - return true; - } - next_context_iter = null_context_list_iterator; - selectorcall_context_iter = null_context_list_iterator; - state = 0; - continue; - - case xgettext_token_type_rparen: - arglist_parser_done (argparser, arg); - return false; - - case xgettext_token_type_comma: - arg++; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_context_iter = passthrough_context_list_iterator; - selectorcall_context_iter = passthrough_context_list_iterator; - state = 0; - continue; - - case xgettext_token_type_colon: - if (objc_extensions) - { - context_iter = selectorcall_context_iter; - inner_context = - inherited_context (inner_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_context_iter = passthrough_context_list_iterator; - selectorcall_context_iter = passthrough_context_list_iterator; - } - else - { - next_context_iter = null_context_list_iterator; - selectorcall_context_iter = null_context_list_iterator; - } - state = 0; - continue; - - case xgettext_token_type_string_literal: - if (extract_all) - remember_a_message (mlp, NULL, token.string, inner_context, - &token.pos, NULL, token.comment); - else - arglist_parser_remember (argparser, arg, token.string, - inner_context, - token.pos.file_name, token.pos.line_number, - token.comment); - drop_reference (token.comment); - next_context_iter = null_context_list_iterator; - selectorcall_context_iter = null_context_list_iterator; - state = 0; - continue; - - case xgettext_token_type_other: - next_context_iter = null_context_list_iterator; - selectorcall_context_iter = null_context_list_iterator; - state = 0; - continue; - - case xgettext_token_type_eof: - arglist_parser_done (argparser, arg); - return true; - - default: - abort (); - } + { + case xgettext_token_type_keyword: + next_shapes = token.shapes; + state = 1; + goto keyword_or_symbol; + + case xgettext_token_type_symbol: + state = 0; + keyword_or_symbol: + next_context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + token.string, strlen (token.string))); + if (objc_extensions) + { + size_t token_string_len = strlen (token.string); + token.string = xrealloc (token.string, token_string_len + 2); + token.string[token_string_len] = ':'; + token.string[token_string_len + 1] = '\0'; + selectorcall_context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + token.string, token_string_len + 1)); + } + free (token.string); + continue; + + case xgettext_token_type_lparen: + if (extract_parenthesized (mlp, inner_context, next_context_iter, + arglist_parser_alloc (mlp, + state ? next_shapes : NULL))) + { + arglist_parser_done (argparser, arg); + return true; + } + next_context_iter = null_context_list_iterator; + selectorcall_context_iter = null_context_list_iterator; + state = 0; + continue; + + case xgettext_token_type_rparen: + arglist_parser_done (argparser, arg); + return false; + + case xgettext_token_type_comma: + arg++; + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + next_context_iter = passthrough_context_list_iterator; + selectorcall_context_iter = passthrough_context_list_iterator; + state = 0; + continue; + + case xgettext_token_type_colon: + if (objc_extensions) + { + context_iter = selectorcall_context_iter; + inner_context = + inherited_context (inner_context, + flag_context_list_iterator_advance ( + &context_iter)); + next_context_iter = passthrough_context_list_iterator; + selectorcall_context_iter = passthrough_context_list_iterator; + } + else + { + next_context_iter = null_context_list_iterator; + selectorcall_context_iter = null_context_list_iterator; + } + state = 0; + continue; + + case xgettext_token_type_string_literal: + if (extract_all) + remember_a_message (mlp, NULL, token.string, inner_context, + &token.pos, NULL, token.comment); + else + arglist_parser_remember (argparser, arg, token.string, + inner_context, + token.pos.file_name, token.pos.line_number, + token.comment); + drop_reference (token.comment); + next_context_iter = null_context_list_iterator; + selectorcall_context_iter = null_context_list_iterator; + state = 0; + continue; + + case xgettext_token_type_other: + next_context_iter = null_context_list_iterator; + selectorcall_context_iter = null_context_list_iterator; + state = 0; + continue; + + case xgettext_token_type_eof: + arglist_parser_done (argparser, arg); + return true; + + default: + abort (); + } } } static void extract_whole_file (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { message_list_ty *mlp = mdlp->item[0]->messages; @@ -1941,7 +1941,7 @@ extract_whole_file (FILE *f, /* Eat tokens until eof is seen. When extract_parenthesized returns due to an unbalanced closing parenthesis, just restart it. */ while (!extract_parenthesized (mlp, null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) + arglist_parser_alloc (mlp, NULL))) ; /* Close scanner. */ @@ -1954,9 +1954,9 @@ extract_whole_file (FILE *f, void extract_c (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { objc_extensions = false; extract_whole_file (f, real_filename, logical_filename, flag_table, mdlp); @@ -1964,9 +1964,9 @@ extract_c (FILE *f, void extract_objc (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { objc_extensions = true; extract_whole_file (f, real_filename, logical_filename, flag_table, mdlp); diff --git a/gettext-tools/src/x-c.h b/gettext-tools/src/x-c.h index 749be6d2a..643345fa0 100644 --- a/gettext-tools/src/x-c.h +++ b/gettext-tools/src/x-c.h @@ -28,42 +28,42 @@ extern "C" { #define EXTENSIONS_C \ - { "c", "C" }, \ - { "h", "C" }, \ - { "C", "C++" }, \ - { "c++", "C++" }, \ - { "cc", "C++" }, \ - { "cxx", "C++" }, \ - { "cpp", "C++" }, \ - { "hh", "C++" }, \ - { "hxx", "C++" }, \ - { "hpp", "C++" }, \ - { "m", "ObjectiveC" }, \ + { "c", "C" }, \ + { "h", "C" }, \ + { "C", "C++" }, \ + { "c++", "C++" }, \ + { "cc", "C++" }, \ + { "cxx", "C++" }, \ + { "cpp", "C++" }, \ + { "hh", "C++" }, \ + { "hxx", "C++" }, \ + { "hpp", "C++" }, \ + { "m", "ObjectiveC" }, \ #define SCANNERS_C \ - { "C", extract_c, \ - &flag_table_c, \ - &formatstring_c, NULL }, \ - { "C++", extract_c, \ - &flag_table_c, \ - &formatstring_c, NULL }, \ - { "ObjectiveC", extract_objc, \ - &flag_table_objc, \ - &formatstring_c, &formatstring_objc }, \ - { "GCC-source", extract_c, \ - &flag_table_gcc_internal, \ - &formatstring_gcc_internal, &formatstring_gfc_internal }, \ + { "C", extract_c, \ + &flag_table_c, \ + &formatstring_c, NULL }, \ + { "C++", extract_c, \ + &flag_table_c, \ + &formatstring_c, NULL }, \ + { "ObjectiveC", extract_objc, \ + &flag_table_objc, \ + &formatstring_c, &formatstring_objc }, \ + { "GCC-source", extract_c, \ + &flag_table_gcc_internal, \ + &formatstring_gcc_internal, &formatstring_gfc_internal }, \ /* Scan a C/C++ file and add its translatable strings to mdlp. */ extern void extract_c (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); /* Scan an ObjectiveC file and add its translatable strings to mdlp. */ extern void extract_objc (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); /* Handling of options specific to this language. */ diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c index 45e54a0f1..aaf679429 100644 --- a/gettext-tools/src/x-csharp.c +++ b/gettext-tools/src/x-csharp.c @@ -79,16 +79,16 @@ x_csharp_keyword (const char *name) const char *colon; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid C# - identifier sequence with dots. - A colon means an invalid parse in split_keywordspec(). */ + identifier sequence with dots. + A colon means an invalid parse in split_keywordspec(). */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); + insert_keyword_callshape (&keywords, name, end - name, &shape); } } @@ -100,9 +100,9 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ - x_csharp_keyword ("GetString"); /* Resource{Manager,Set}.GetString */ - x_csharp_keyword ("GetPluralString:1,2"); /* GettextResource{Manager,Set}.GetPluralString */ + xgettext.texi! */ + x_csharp_keyword ("GetString"); /* Resource{Manager,Set}.GetString */ + x_csharp_keyword ("GetPluralString:1,2"); /* GettextResource{Manager,Set}.GetPluralString */ x_csharp_keyword ("GetParticularString:1c,2"); /* Resource{Manager,Set}.GetParticularString */ x_csharp_keyword ("GetParticularPluralString:1c,2,3"); /* Resource{Manager,Set}.GetParticularPluralString */ default_keywords = false; @@ -152,7 +152,7 @@ phase1_getc () { c = phase1_pushback[--phase1_pushback_length]; if (c == '\n') - ++line_number; + ++line_number; return c; } @@ -160,8 +160,8 @@ phase1_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_file_name); return EOF; } @@ -177,9 +177,9 @@ phase1_ungetc (int c) if (c != EOF) { if (c == '\n') - --line_number; + --line_number; if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); + abort (); phase1_pushback[phase1_pushback_length++] = c; } } @@ -213,141 +213,141 @@ phase2_getc () { int c = phase1_getc (); if (c == EOF) - return UEOF; + return UEOF; if (!c_isascii (c)) - { - multiline_error (xstrdup (""), - xasprintf ("%s\n%s\n", - non_ascii_error_message (lexical_context, - real_file_name, - line_number), - _("\ + { + multiline_error (xstrdup (""), + xasprintf ("%s\n%s\n", + non_ascii_error_message (lexical_context, + real_file_name, + line_number), + _("\ Please specify the source encoding through --from-code."))); - exit (EXIT_FAILURE); - } + exit (EXIT_FAILURE); + } return c; } else if (xgettext_current_source_encoding != po_charset_utf8) { #if HAVE_ICONV /* Use iconv on an increasing number of bytes. Read only as many bytes - through phase1_getc as needed. This is needed to give reasonable - interactive behaviour when fp is connected to an interactive tty. */ + through phase1_getc as needed. This is needed to give reasonable + interactive behaviour when fp is connected to an interactive tty. */ unsigned char buf[MAX_PHASE1_PUSHBACK]; size_t bufcount; int c = phase1_getc (); if (c == EOF) - return UEOF; + return UEOF; buf[0] = (unsigned char) c; bufcount = 1; for (;;) - { - unsigned char scratchbuf[6]; - const char *inptr = (const char *) &buf[0]; - size_t insize = bufcount; - char *outptr = (char *) &scratchbuf[0]; - size_t outsize = sizeof (scratchbuf); - - size_t res = iconv (xgettext_current_source_iconv, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - /* We expect that a character has been produced if and only if - some input bytes have been consumed. */ - if ((insize < bufcount) != (outsize < sizeof (scratchbuf))) - abort (); - if (outsize == sizeof (scratchbuf)) - { - /* No character has been produced. Must be an error. */ - if (res != (size_t)(-1)) - abort (); - - if (errno == EILSEQ) - { - /* An invalid multibyte sequence was encountered. */ - multiline_error (xstrdup (""), - xasprintf (_("\ + { + unsigned char scratchbuf[6]; + const char *inptr = (const char *) &buf[0]; + size_t insize = bufcount; + char *outptr = (char *) &scratchbuf[0]; + size_t outsize = sizeof (scratchbuf); + + size_t res = iconv (xgettext_current_source_iconv, + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); + /* We expect that a character has been produced if and only if + some input bytes have been consumed. */ + if ((insize < bufcount) != (outsize < sizeof (scratchbuf))) + abort (); + if (outsize == sizeof (scratchbuf)) + { + /* No character has been produced. Must be an error. */ + if (res != (size_t)(-1)) + abort (); + + if (errno == EILSEQ) + { + /* An invalid multibyte sequence was encountered. */ + multiline_error (xstrdup (""), + xasprintf (_("\ %s:%d: Invalid multibyte sequence.\n\ Please specify the correct source encoding through --from-code.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - else if (errno == EINVAL) - { - /* An incomplete multibyte character. */ - int c; - - if (bufcount == MAX_PHASE1_PUSHBACK) - { - /* An overlong incomplete multibyte sequence was - encountered. */ - multiline_error (xstrdup (""), - xasprintf (_("\ + real_file_name, line_number)); + exit (EXIT_FAILURE); + } + else if (errno == EINVAL) + { + /* An incomplete multibyte character. */ + int c; + + if (bufcount == MAX_PHASE1_PUSHBACK) + { + /* An overlong incomplete multibyte sequence was + encountered. */ + multiline_error (xstrdup (""), + xasprintf (_("\ %s:%d: Long incomplete multibyte sequence.\n\ Please specify the correct source encoding through --from-code.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - - /* Read one more byte and retry iconv. */ - c = phase1_getc (); - if (c == EOF) - { - multiline_error (xstrdup (""), - xasprintf (_("\ + real_file_name, line_number)); + exit (EXIT_FAILURE); + } + + /* Read one more byte and retry iconv. */ + c = phase1_getc (); + if (c == EOF) + { + multiline_error (xstrdup (""), + xasprintf (_("\ %s:%d: Incomplete multibyte sequence at end of file.\n\ Please specify the correct source encoding through --from-code.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - if (c == '\n') - { - multiline_error (xstrdup (""), - xasprintf (_("\ + real_file_name, line_number)); + exit (EXIT_FAILURE); + } + if (c == '\n') + { + multiline_error (xstrdup (""), + xasprintf (_("\ %s:%d: Incomplete multibyte sequence at end of line.\n\ Please specify the correct source encoding through --from-code.\n"), - real_file_name, line_number - 1)); - exit (EXIT_FAILURE); - } - buf[bufcount++] = (unsigned char) c; - } - else - error (EXIT_FAILURE, errno, _("%s:%d: iconv failure"), - real_file_name, line_number); - } - else - { - size_t outbytes = sizeof (scratchbuf) - outsize; - size_t bytes = bufcount - insize; - ucs4_t uc; - - /* We expect that one character has been produced. */ - if (bytes == 0) - abort (); - if (outbytes == 0) - abort (); - /* Push back the unused bytes. */ - while (insize > 0) - phase1_ungetc (buf[--insize]); - /* Convert the character from UTF-8 to UCS-4. */ - if (u8_mbtouc (&uc, scratchbuf, outbytes) < outbytes) - { - /* scratchbuf contains an out-of-range Unicode character - (> 0x10ffff). */ - multiline_error (xstrdup (""), - xasprintf (_("\ + real_file_name, line_number - 1)); + exit (EXIT_FAILURE); + } + buf[bufcount++] = (unsigned char) c; + } + else + error (EXIT_FAILURE, errno, _("%s:%d: iconv failure"), + real_file_name, line_number); + } + else + { + size_t outbytes = sizeof (scratchbuf) - outsize; + size_t bytes = bufcount - insize; + ucs4_t uc; + + /* We expect that one character has been produced. */ + if (bytes == 0) + abort (); + if (outbytes == 0) + abort (); + /* Push back the unused bytes. */ + while (insize > 0) + phase1_ungetc (buf[--insize]); + /* Convert the character from UTF-8 to UCS-4. */ + if (u8_mbtouc (&uc, scratchbuf, outbytes) < outbytes) + { + /* scratchbuf contains an out-of-range Unicode character + (> 0x10ffff). */ + multiline_error (xstrdup (""), + xasprintf (_("\ %s:%d: Invalid multibyte sequence.\n\ Please specify the source encoding through --from-code.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - return uc; - } - } + real_file_name, line_number)); + exit (EXIT_FAILURE); + } + return uc; + } + } #else /* If we don't have iconv(), the only supported values for - xgettext_global_source_encoding and thus also for - xgettext_current_source_encoding are ASCII and UTF-8. */ + xgettext_global_source_encoding and thus also for + xgettext_current_source_encoding are ASCII and UTF-8. */ abort (); #endif } @@ -361,64 +361,64 @@ Please specify the source encoding through --from-code.\n"), c = phase1_getc (); if (c == EOF) - return UEOF; + return UEOF; buf[0] = c; count = 1; if (buf[0] >= 0xc0) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[1] = c; - count = 2; - } + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[1] = c; + count = 2; + } if (buf[0] >= 0xe0 - && ((buf[1] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[2] = c; - count = 3; - } + && ((buf[1] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[2] = c; + count = 3; + } if (buf[0] >= 0xf0 - && ((buf[1] ^ 0x80) < 0x40) - && ((buf[2] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[3] = c; - count = 4; - } + && ((buf[1] ^ 0x80) < 0x40) + && ((buf[2] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[3] = c; + count = 4; + } if (buf[0] >= 0xf8 - && ((buf[1] ^ 0x80) < 0x40) - && ((buf[2] ^ 0x80) < 0x40) - && ((buf[3] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[4] = c; - count = 5; - } + && ((buf[1] ^ 0x80) < 0x40) + && ((buf[2] ^ 0x80) < 0x40) + && ((buf[3] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[4] = c; + count = 5; + } if (buf[0] >= 0xfc - && ((buf[1] ^ 0x80) < 0x40) - && ((buf[2] ^ 0x80) < 0x40) - && ((buf[3] ^ 0x80) < 0x40) - && ((buf[4] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[5] = c; - count = 6; - } + && ((buf[1] ^ 0x80) < 0x40) + && ((buf[2] ^ 0x80) < 0x40) + && ((buf[3] ^ 0x80) < 0x40) + && ((buf[4] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[5] = c; + count = 6; + } u8_mbtouc (&uc, buf, count); return uc; @@ -432,7 +432,7 @@ phase2_ungetc (int c) if (c != UEOF) { if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); + abort (); phase2_pushback[phase2_pushback_length++] = c; } } @@ -458,7 +458,7 @@ phase3_getc () { c = phase3_pushback[--phase3_pushback_length]; if (c == UNL) - ++logical_line_number; + ++logical_line_number; return c; } @@ -469,7 +469,7 @@ phase3_getc () int c1 = phase2_getc (); if (c1 != UEOF && c1 != 0x000a) - phase2_ungetc (c1); + phase2_ungetc (c1); /* Seen line terminator CR or CR/LF. */ ++logical_line_number; @@ -488,8 +488,8 @@ phase3_getc () int c1 = phase2_getc (); if (c1 == UEOF) - /* Seen U+001A right before the end of file. */ - return UEOF; + /* Seen U+001A right before the end of file. */ + return UEOF; phase2_ungetc (c1); } @@ -506,9 +506,9 @@ phase3_ungetc (int c) if (c != UEOF) { if (c == UNL) - --logical_line_number; + --logical_line_number; if (phase3_pushback_length == SIZEOF (phase3_pushback)) - abort (); + abort (); phase3_pushback[phase3_pushback_length++] = c; } } @@ -544,7 +544,7 @@ string_buffer_append_unicode_grow (struct string_buffer *bp, size_t count) { size_t new_allocated = 2 * bp->utf8_allocated + 10; if (new_allocated < bp->utf8_buflen + count) - new_allocated = bp->utf8_buflen + count; + new_allocated = bp->utf8_buflen + count; bp->utf8_allocated = new_allocated; bp->utf8_buffer = xrealloc (bp->utf8_buffer, new_allocated); } @@ -620,7 +620,7 @@ comment_line_end (size_t chars_to_remove) buflen -= chars_to_remove; while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; buffer[buflen] = '\0'; savable_comment_add (buffer); @@ -660,39 +660,39 @@ phase4_getc () comment_start (); last_was_star = false; for (;;) - { - c = phase3_getc (); - if (c == UEOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(comment_at_start () && (c == ' ' || c == '\t'))) - comment_add (c); - switch (c) - { - case UNL: - comment_line_end (1); - comment_start (); - last_was_star = false; - continue; - - case '*': - last_was_star = true; - continue; - - case '/': - if (last_was_star) - { - comment_line_end (2); - break; - } - /* FALLTHROUGH */ - - default: - last_was_star = false; - continue; - } - break; - } + { + c = phase3_getc (); + if (c == UEOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(comment_at_start () && (c == ' ' || c == '\t'))) + comment_add (c); + switch (c) + { + case UNL: + comment_line_end (1); + comment_start (); + last_was_star = false; + continue; + + case '*': + last_was_star = true; + continue; + + case '/': + if (last_was_star) + { + comment_line_end (2); + break; + } + /* FALLTHROUGH */ + + default: + last_was_star = false; + continue; + } + break; + } last_comment_line = logical_line_number; return ' '; @@ -701,14 +701,14 @@ phase4_getc () last_comment_line = logical_line_number; comment_start (); for (;;) - { - c = phase3_getc (); - if (c == UNL || c == UEOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(comment_at_start () && (c == ' ' || c == '\t'))) - comment_add (c); - } + { + c = phase3_getc (); + if (c == UNL || c == UEOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(comment_at_start () && (c == ' ' || c == '\t'))) + comment_add (c); + } phase3_ungetc (c); /* push back the newline, to decrement logical_line_number */ comment_line_end (0); phase3_getc (); /* read the newline again */ @@ -764,17 +764,17 @@ bitmap_lookup (const void *table, unsigned int uc) { int lookup1 = ((const int *) table)[1 + index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> 9) & 0x7f; - int lookup2 = ((const int *) table)[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc >> 5) & 0xf; - unsigned int lookup3 = ((const int *) table)[lookup2 + index3]; - - return (lookup3 >> (uc & 0x1f)) & 1; - } - } + { + unsigned int index2 = (uc >> 9) & 0x7f; + int lookup2 = ((const int *) table)[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc >> 5) & 0xf; + unsigned int lookup3 = ((const int *) table)[lookup2 + index3]; + + return (lookup3 >> (uc & 0x1f)) & 1; + } + } } return 0; } @@ -1273,9 +1273,9 @@ phase5_getc () if (c == '#') { /* Ignore the entire line containing the preprocessor directive - (including the // comment if it contains one). */ + (including the // comment if it contains one). */ do - c = phase3_getc (); + c = phase3_getc (); while (c != UEOF && c != UNL); return c; } @@ -1293,7 +1293,7 @@ phase5_ungetc (int c) if (c != UEOF) { if (phase5_pushback_length == SIZEOF (phase5_pushback)) - abort (); + abort (); phase5_pushback[phase5_pushback_length++] = c; } } @@ -1305,17 +1305,17 @@ phase5_ungetc (int c) enum token_type_ty { token_type_eof, - token_type_lparen, /* ( */ - token_type_rparen, /* ) */ - token_type_lbrace, /* { */ - token_type_rbrace, /* } */ - token_type_comma, /* , */ - token_type_dot, /* . */ - token_type_string_literal, /* "abc", @"abc" */ - token_type_number, /* 1.23 */ - token_type_symbol, /* identifier, keyword, null */ - token_type_plus, /* + */ - token_type_other /* character literal, misc. operator */ + token_type_lparen, /* ( */ + token_type_rparen, /* ) */ + token_type_lbrace, /* { */ + token_type_rbrace, /* } */ + token_type_comma, /* , */ + token_type_dot, /* . */ + token_type_string_literal, /* "abc", @"abc" */ + token_type_number, /* 1.23 */ + token_type_symbol, /* identifier, keyword, null */ + token_type_plus, /* + */ + token_type_other /* character literal, misc. operator */ }; typedef enum token_type_ty token_type_ty; @@ -1323,8 +1323,8 @@ typedef struct token_ty token_ty; struct token_ty { token_type_ty type; - char *string; /* for token_type_string_literal, token_type_symbol */ - refcounted_string_list_ty *comment; /* for token_type_string_literal */ + char *string; /* for token_type_string_literal, token_type_symbol */ + refcounted_string_list_ty *comment; /* for token_type_string_literal */ int line_number; int logical_line_number; }; @@ -1363,39 +1363,39 @@ do_getc_unicode_escaped (bool (*predicate) (int)) expect = (c == 'U' ? 8 : 4); n = 0; for (i = 0; i < expect; i++) - { - int c1 = phase3_getc (); - - if (c1 >= '0' && c1 <= '9') - n = (n << 4) + (c1 - '0'); - else if (c1 >= 'A' && c1 <= 'F') - n = (n << 4) + (c1 - 'A' + 10); - else if (c1 >= 'a' && c1 <= 'f') - n = (n << 4) + (c1 - 'a' + 10); - else - { - phase3_ungetc (c1); - while (--i >= 0) - phase3_ungetc (buf[i]); - phase3_ungetc (c); - return '\\'; - } - - buf[i] = c1; - } + { + int c1 = phase3_getc (); + + if (c1 >= '0' && c1 <= '9') + n = (n << 4) + (c1 - '0'); + else if (c1 >= 'A' && c1 <= 'F') + n = (n << 4) + (c1 - 'A' + 10); + else if (c1 >= 'a' && c1 <= 'f') + n = (n << 4) + (c1 - 'a' + 10); + else + { + phase3_ungetc (c1); + while (--i >= 0) + phase3_ungetc (buf[i]); + phase3_ungetc (c); + return '\\'; + } + + buf[i] = c1; + } if (n >= 0x110000) - { - error_with_progname = false; - error (0, 0, _("%s:%d: warning: invalid Unicode character"), - logical_file_name, line_number); - error_with_progname = true; - } + { + error_with_progname = false; + error (0, 0, _("%s:%d: warning: invalid Unicode character"), + logical_file_name, line_number); + error_with_progname = true; + } else if (predicate (n)) - return n; + return n; while (--i >= 0) - phase3_ungetc (buf[i]); + phase3_ungetc (buf[i]); } phase3_ungetc (c); return '\\'; @@ -1442,41 +1442,41 @@ do_getc_escaped () case 'x': c = phase3_getc (); switch (c) - { - default: - phase3_ungetc (c); - phase3_ungetc ('x'); - return '\\'; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - break; - } + { + default: + phase3_ungetc (c); + phase3_ungetc ('x'); + return '\\'; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + break; + } n = 0; for (i = 0;; i++) - { - switch (c) - { - default: - phase3_ungetc (c); - return n; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = n * 16 + c - '0'; - break; - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - n = n * 16 + 10 + c - 'A'; - break; - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - n = n * 16 + 10 + c - 'a'; - break; - } - if (i == 3) - break; - c = phase3_getc (); - } + { + switch (c) + { + default: + phase3_ungetc (c); + return n; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + n = n * 16 + c - '0'; + break; + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + n = n * 16 + 10 + c - 'A'; + break; + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + n = n * 16 + 10 + c - 'a'; + break; + } + if (i == 3) + break; + c = phase3_getc (); + } return n; case 'u': case 'U': phase3_ungetc (c); @@ -1500,22 +1500,22 @@ accumulate_escaped (struct string_buffer *literal, int delimiter) /* Use phase 3, because phase 4 elides comments. */ c = phase3_getc (); if (c == UEOF || c == delimiter) - break; + break; if (c == UNL) - { - phase3_ungetc (c); - error_with_progname = false; - if (delimiter == '\'') - error (0, 0, _("%s:%d: warning: unterminated character constant"), - logical_file_name, line_number); - else - error (0, 0, _("%s:%d: warning: unterminated string constant"), - logical_file_name, line_number); - error_with_progname = true; - break; - } + { + phase3_ungetc (c); + error_with_progname = false; + if (delimiter == '\'') + error (0, 0, _("%s:%d: warning: unterminated character constant"), + logical_file_name, line_number); + else + error (0, 0, _("%s:%d: warning: unterminated string constant"), + logical_file_name, line_number); + error_with_progname = true; + break; + } if (c == '\\') - c = do_getc_escaped (); + c = do_getc_escaped (); string_buffer_append_unicode (literal, c); } } @@ -1546,203 +1546,203 @@ phase6_get (token_ty *tp) c = phase5_getc (); if (c == UEOF) - { - tp->type = token_type_eof; - return; - } + { + tp->type = token_type_eof; + return; + } switch (c) - { - case UNL: - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - /* FALLTHROUGH */ - case ' ': - case '\t': - case '\f': - /* Ignore whitespace and comments. */ - continue; - } + { + case UNL: + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + /* FALLTHROUGH */ + case ' ': + case '\t': + case '\f': + /* Ignore whitespace and comments. */ + continue; + } last_non_comment_line = tp->logical_line_number; switch (c) - { - case '(': - tp->type = token_type_lparen; - return; - - case ')': - tp->type = token_type_rparen; - return; - - case '{': - tp->type = token_type_lbrace; - return; - - case '}': - tp->type = token_type_rbrace; - return; - - case ',': - tp->type = token_type_comma; - return; - - case '.': - c = phase4_getc (); - if (!(c >= '0' && c <= '9')) - { - phase4_ungetc (c); - tp->type = token_type_dot; - return; - } - /* FALLTHROUGH */ - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - { - /* Don't need to verify the complicated syntax of integers and - floating-point numbers. We assume a valid C# input. - The simplified syntax that we recognize as number is: any - sequence of alphanumeric characters, additionally '+' and '-' - immediately after 'e' or 'E' except in hexadecimal numbers. */ - bool hexadecimal = false; - - for (;;) - { - c = phase4_getc (); - if (c >= '0' && c <= '9') - continue; - if ((c >= 'A' && c <= 'Z') || (c >= 'a' &&c <= 'z')) - { - if (c == 'X' || c == 'x') - hexadecimal = true; - if ((c == 'E' || c == 'e') && !hexadecimal) - { - c = phase4_getc (); - if (!(c == '+' || c == '-')) - phase4_ungetc (c); - } - continue; - } - if (c == '.') - continue; - break; - } - phase4_ungetc (c); - tp->type = token_type_number; - return; - } - - case '"': - /* Regular string literal. */ - { - struct string_buffer literal; - - lexical_context = lc_string; - init_string_buffer (&literal); - accumulate_escaped (&literal, '"'); - tp->string = xstrdup (string_buffer_result (&literal)); - free_string_buffer (&literal); - tp->comment = add_reference (savable_comment); - lexical_context = lc_outside; - tp->type = token_type_string_literal; - return; - } - - case '\'': - /* Character literal. */ - { - struct string_buffer literal; - - init_string_buffer (&literal); - accumulate_escaped (&literal, '\''); - free_string_buffer (&literal); - tp->type = token_type_other; - return; - } - - case '+': - c = phase4_getc (); - if (c == '+') - /* Operator ++ */ - tp->type = token_type_other; - else if (c == '=') - /* Operator += */ - tp->type = token_type_other; - else - { - /* Operator + */ - phase4_ungetc (c); - tp->type = token_type_plus; - } - return; - - case '@': - c = phase4_getc (); - if (c == '"') - { - /* Verbatim string literal. */ - struct string_buffer literal; - - lexical_context = lc_string; - init_string_buffer (&literal); - for (;;) - { - /* Use phase 2, because phase 4 elides comments and phase 3 - mixes up the newline characters. */ - c = phase2_getc (); - if (c == UEOF) - break; - if (c == '"') - { - c = phase2_getc (); - if (c != '"') - { - phase2_ungetc (c); - break; - } - } - /* No special treatment of newline and backslash here. */ - string_buffer_append_unicode (&literal, c); - } - tp->string = xstrdup (string_buffer_result (&literal)); - free_string_buffer (&literal); - tp->comment = add_reference (savable_comment); - lexical_context = lc_outside; - tp->type = token_type_string_literal; - return; - } - /* FALLTHROUGH, so that @identifier is recognized. */ - - default: - if (c == '\\') - c = do_getc_unicode_escaped (is_identifier_start); - if (is_identifier_start (c)) - { - static struct string_buffer buffer; - buffer.utf8_buflen = 0; - for (;;) - { - string_buffer_append_unicode (&buffer, c); - c = phase4_getc (); - if (c == '\\') - c = do_getc_unicode_escaped (is_identifier_part); - if (!is_identifier_part (c)) - break; - } - phase4_ungetc (c); - tp->string = xstrdup (string_buffer_result (&buffer)); - tp->type = token_type_symbol; - return; - } - else - { - /* Misc. operator. */ - tp->type = token_type_other; - return; - } - } + { + case '(': + tp->type = token_type_lparen; + return; + + case ')': + tp->type = token_type_rparen; + return; + + case '{': + tp->type = token_type_lbrace; + return; + + case '}': + tp->type = token_type_rbrace; + return; + + case ',': + tp->type = token_type_comma; + return; + + case '.': + c = phase4_getc (); + if (!(c >= '0' && c <= '9')) + { + phase4_ungetc (c); + tp->type = token_type_dot; + return; + } + /* FALLTHROUGH */ + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + { + /* Don't need to verify the complicated syntax of integers and + floating-point numbers. We assume a valid C# input. + The simplified syntax that we recognize as number is: any + sequence of alphanumeric characters, additionally '+' and '-' + immediately after 'e' or 'E' except in hexadecimal numbers. */ + bool hexadecimal = false; + + for (;;) + { + c = phase4_getc (); + if (c >= '0' && c <= '9') + continue; + if ((c >= 'A' && c <= 'Z') || (c >= 'a' &&c <= 'z')) + { + if (c == 'X' || c == 'x') + hexadecimal = true; + if ((c == 'E' || c == 'e') && !hexadecimal) + { + c = phase4_getc (); + if (!(c == '+' || c == '-')) + phase4_ungetc (c); + } + continue; + } + if (c == '.') + continue; + break; + } + phase4_ungetc (c); + tp->type = token_type_number; + return; + } + + case '"': + /* Regular string literal. */ + { + struct string_buffer literal; + + lexical_context = lc_string; + init_string_buffer (&literal); + accumulate_escaped (&literal, '"'); + tp->string = xstrdup (string_buffer_result (&literal)); + free_string_buffer (&literal); + tp->comment = add_reference (savable_comment); + lexical_context = lc_outside; + tp->type = token_type_string_literal; + return; + } + + case '\'': + /* Character literal. */ + { + struct string_buffer literal; + + init_string_buffer (&literal); + accumulate_escaped (&literal, '\''); + free_string_buffer (&literal); + tp->type = token_type_other; + return; + } + + case '+': + c = phase4_getc (); + if (c == '+') + /* Operator ++ */ + tp->type = token_type_other; + else if (c == '=') + /* Operator += */ + tp->type = token_type_other; + else + { + /* Operator + */ + phase4_ungetc (c); + tp->type = token_type_plus; + } + return; + + case '@': + c = phase4_getc (); + if (c == '"') + { + /* Verbatim string literal. */ + struct string_buffer literal; + + lexical_context = lc_string; + init_string_buffer (&literal); + for (;;) + { + /* Use phase 2, because phase 4 elides comments and phase 3 + mixes up the newline characters. */ + c = phase2_getc (); + if (c == UEOF) + break; + if (c == '"') + { + c = phase2_getc (); + if (c != '"') + { + phase2_ungetc (c); + break; + } + } + /* No special treatment of newline and backslash here. */ + string_buffer_append_unicode (&literal, c); + } + tp->string = xstrdup (string_buffer_result (&literal)); + free_string_buffer (&literal); + tp->comment = add_reference (savable_comment); + lexical_context = lc_outside; + tp->type = token_type_string_literal; + return; + } + /* FALLTHROUGH, so that @identifier is recognized. */ + + default: + if (c == '\\') + c = do_getc_unicode_escaped (is_identifier_start); + if (is_identifier_start (c)) + { + static struct string_buffer buffer; + buffer.utf8_buflen = 0; + for (;;) + { + string_buffer_append_unicode (&buffer, c); + c = phase4_getc (); + if (c == '\\') + c = do_getc_unicode_escaped (is_identifier_part); + if (!is_identifier_part (c)) + break; + } + phase4_ungetc (c); + tp->string = xstrdup (string_buffer_result (&buffer)); + tp->type = token_type_symbol; + return; + } + else + { + /* Misc. operator. */ + tp->type = token_type_other; + return; + } + } } } @@ -1753,7 +1753,7 @@ phase6_unget (token_ty *tp) if (tp->type != token_type_eof) { if (phase6_pushback_length == SIZEOF (phase6_pushback)) - abort (); + abort (); phase6_pushback[phase6_pushback_length++] = *tp; } } @@ -1783,41 +1783,41 @@ phase7_get (token_ty *tp) size_t sum_len = strlen (sum); for (;;) - { - token_ty token2; - - phase6_get (&token2); - if (token2.type == token_type_plus) - { - token_ty token3; - - phase6_get (&token3); - if (token3.type == token_type_string_literal) - { - token_ty token_after; - - phase6_get (&token_after); - if (token_after.type != token_type_dot) - { - char *addend = token3.string; - size_t addend_len = strlen (addend); - - sum = (char *) xrealloc (sum, sum_len + addend_len + 1); - memcpy (sum + sum_len, addend, addend_len + 1); - sum_len += addend_len; - - phase6_unget (&token_after); - free_token (&token3); - free_token (&token2); - continue; - } - phase6_unget (&token_after); - } - phase6_unget (&token3); - } - phase6_unget (&token2); - break; - } + { + token_ty token2; + + phase6_get (&token2); + if (token2.type == token_type_plus) + { + token_ty token3; + + phase6_get (&token3); + if (token3.type == token_type_string_literal) + { + token_ty token_after; + + phase6_get (&token_after); + if (token_after.type != token_type_dot) + { + char *addend = token3.string; + size_t addend_len = strlen (addend); + + sum = (char *) xrealloc (sum, sum_len + addend_len + 1); + memcpy (sum + sum_len, addend, addend_len + 1); + sum_len += addend_len; + + phase6_unget (&token_after); + free_token (&token3); + free_token (&token2); + continue; + } + phase6_unget (&token_after); + } + phase6_unget (&token3); + } + phase6_unget (&token2); + break; + } tp->string = sum; } } @@ -1829,7 +1829,7 @@ phase7_unget (token_ty *tp) if (tp->type != token_type_eof) { if (phase7_pushback_length == SIZEOF (phase7_pushback)) - abort (); + abort (); phase7_pushback[phase7_pushback_length++] = *tp; } } @@ -1877,9 +1877,9 @@ static flag_context_list_table_ty *flag_context_list_table; Return true upon eof, false upon closing parenthesis or brace. */ static bool extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - struct arglist_parser *argparser) + flag_context_ty outer_context, + flag_context_list_iterator_ty context_iter, + struct arglist_parser *argparser) { /* Current argument number. */ int arg = 1; @@ -1893,7 +1893,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, /* Current context. */ flag_context_ty inner_context = inherited_context (outer_context, - flag_context_list_iterator_advance (&context_iter)); + flag_context_list_iterator_advance (&context_iter)); /* Start state is 0. */ state = 0; @@ -1904,219 +1904,219 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, x_csharp_lex (&token); switch (token.type) - { - case token_type_symbol: - { - /* Combine symbol1 . ... . symbolN to a single strings, so that - we can recognize static function calls like - GettextResource.gettext. The information present for - symbolI.....symbolN has precedence over the information for - symbolJ.....symbolN with J > I. */ - char *sum = token.string; - size_t sum_len = strlen (sum); - const char *dottedname; - flag_context_list_ty *context_list; - - for (;;) - { - token_ty token2; - - x_csharp_lex (&token2); - if (token2.type == token_type_dot) - { - token_ty token3; - - x_csharp_lex (&token3); - if (token3.type == token_type_symbol) - { - char *addend = token3.string; - size_t addend_len = strlen (addend); - - sum = - (char *) xrealloc (sum, sum_len + 1 + addend_len + 1); - sum[sum_len] = '.'; - memcpy (sum + sum_len + 1, addend, addend_len + 1); - sum_len += 1 + addend_len; - - free_token (&token3); - free_token (&token2); - continue; - } - x_csharp_unlex (&token3); - } - x_csharp_unlex (&token2); - break; - } - - for (dottedname = sum;;) - { - void *keyword_value; - - if (hash_find_entry (&keywords, dottedname, strlen (dottedname), - &keyword_value) - == 0) - { - next_shapes = (const struct callshapes *) keyword_value; - state = 1; - break; - } - - dottedname = strchr (dottedname, '.'); - if (dottedname == NULL) - { - state = 0; - break; - } - dottedname++; - } - - for (dottedname = sum;;) - { - context_list = - flag_context_list_table_lookup ( - flag_context_list_table, - dottedname, strlen (dottedname)); - if (context_list != NULL) - break; - - dottedname = strchr (dottedname, '.'); - if (dottedname == NULL) - break; - dottedname++; - } - next_context_iter = flag_context_list_iterator (context_list); - - free (sum); - continue; - } - - case token_type_lparen: - if (extract_parenthesized (mlp, token_type_rparen, - inner_context, next_context_iter, - arglist_parser_alloc (mlp, - state ? next_shapes : NULL))) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rparen: - if (terminator == token_type_rparen) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return false; - } - if (terminator == token_type_rbrace) - { - error_with_progname = false; - error (0, 0, - _("%s:%d: warning: ')' found where '}' was expected"), - logical_file_name, token.line_number); - error_with_progname = true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_lbrace: - if (extract_parenthesized (mlp, token_type_rbrace, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rbrace: - if (terminator == token_type_rbrace) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return false; - } - if (terminator == token_type_rparen) - { - error_with_progname = false; - error (0, 0, - _("%s:%d: warning: '}' found where ')' was expected"), - logical_file_name, token.line_number); - error_with_progname = true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_comma: - arg++; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_context_iter = passthrough_context_list_iterator; - state = 0; - continue; - - case token_type_string_literal: - { - lex_pos_ty pos; - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - - xgettext_current_source_encoding = po_charset_utf8; - if (extract_all) - remember_a_message (mlp, NULL, token.string, inner_context, - &pos, NULL, token.comment); - else - arglist_parser_remember (argparser, arg, token.string, - inner_context, - pos.file_name, pos.line_number, - token.comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; - } - drop_reference (token.comment); - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_eof: - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return true; - - case token_type_dot: - case token_type_number: - case token_type_plus: - case token_type_other: - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - default: - abort (); - } + { + case token_type_symbol: + { + /* Combine symbol1 . ... . symbolN to a single strings, so that + we can recognize static function calls like + GettextResource.gettext. The information present for + symbolI.....symbolN has precedence over the information for + symbolJ.....symbolN with J > I. */ + char *sum = token.string; + size_t sum_len = strlen (sum); + const char *dottedname; + flag_context_list_ty *context_list; + + for (;;) + { + token_ty token2; + + x_csharp_lex (&token2); + if (token2.type == token_type_dot) + { + token_ty token3; + + x_csharp_lex (&token3); + if (token3.type == token_type_symbol) + { + char *addend = token3.string; + size_t addend_len = strlen (addend); + + sum = + (char *) xrealloc (sum, sum_len + 1 + addend_len + 1); + sum[sum_len] = '.'; + memcpy (sum + sum_len + 1, addend, addend_len + 1); + sum_len += 1 + addend_len; + + free_token (&token3); + free_token (&token2); + continue; + } + x_csharp_unlex (&token3); + } + x_csharp_unlex (&token2); + break; + } + + for (dottedname = sum;;) + { + void *keyword_value; + + if (hash_find_entry (&keywords, dottedname, strlen (dottedname), + &keyword_value) + == 0) + { + next_shapes = (const struct callshapes *) keyword_value; + state = 1; + break; + } + + dottedname = strchr (dottedname, '.'); + if (dottedname == NULL) + { + state = 0; + break; + } + dottedname++; + } + + for (dottedname = sum;;) + { + context_list = + flag_context_list_table_lookup ( + flag_context_list_table, + dottedname, strlen (dottedname)); + if (context_list != NULL) + break; + + dottedname = strchr (dottedname, '.'); + if (dottedname == NULL) + break; + dottedname++; + } + next_context_iter = flag_context_list_iterator (context_list); + + free (sum); + continue; + } + + case token_type_lparen: + if (extract_parenthesized (mlp, token_type_rparen, + inner_context, next_context_iter, + arglist_parser_alloc (mlp, + state ? next_shapes : NULL))) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_rparen: + if (terminator == token_type_rparen) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return false; + } + if (terminator == token_type_rbrace) + { + error_with_progname = false; + error (0, 0, + _("%s:%d: warning: ')' found where '}' was expected"), + logical_file_name, token.line_number); + error_with_progname = true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_lbrace: + if (extract_parenthesized (mlp, token_type_rbrace, + null_context, null_context_list_iterator, + arglist_parser_alloc (mlp, NULL))) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_rbrace: + if (terminator == token_type_rbrace) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return false; + } + if (terminator == token_type_rparen) + { + error_with_progname = false; + error (0, 0, + _("%s:%d: warning: '}' found where ')' was expected"), + logical_file_name, token.line_number); + error_with_progname = true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_comma: + arg++; + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + next_context_iter = passthrough_context_list_iterator; + state = 0; + continue; + + case token_type_string_literal: + { + lex_pos_ty pos; + pos.file_name = logical_file_name; + pos.line_number = token.line_number; + + xgettext_current_source_encoding = po_charset_utf8; + if (extract_all) + remember_a_message (mlp, NULL, token.string, inner_context, + &pos, NULL, token.comment); + else + arglist_parser_remember (argparser, arg, token.string, + inner_context, + pos.file_name, pos.line_number, + token.comment); + xgettext_current_source_encoding = xgettext_global_source_encoding; + } + drop_reference (token.comment); + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_eof: + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return true; + + case token_type_dot: + case token_type_number: + case token_type_plus: + case token_type_other: + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + default: + abort (); + } } } void extract_csharp (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { message_list_ty *mlp = mdlp->item[0]->messages; @@ -2138,8 +2138,8 @@ extract_csharp (FILE *f, /* Eat tokens until eof is seen. When extract_parenthesized returns due to an unbalanced closing parenthesis, just restart it. */ while (!extract_parenthesized (mlp, token_type_eof, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) + null_context, null_context_list_iterator, + arglist_parser_alloc (mlp, NULL))) ; fp = NULL; diff --git a/gettext-tools/src/x-csharp.h b/gettext-tools/src/x-csharp.h index f2b7afb2c..9cfb1d8d8 100644 --- a/gettext-tools/src/x-csharp.h +++ b/gettext-tools/src/x-csharp.h @@ -28,16 +28,16 @@ extern "C" { #define EXTENSIONS_CSHARP \ - { "cs", "C#" }, \ + { "cs", "C#" }, \ #define SCANNERS_CSHARP \ - { "C#", extract_csharp, \ - &flag_table_csharp, &formatstring_csharp, NULL }, \ + { "C#", extract_csharp, \ + &flag_table_csharp, &formatstring_csharp, NULL }, \ extern void extract_csharp (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); extern void x_csharp_keyword (const char *keyword); extern void x_csharp_extract_all (void); diff --git a/gettext-tools/src/x-elisp.c b/gettext-tools/src/x-elisp.c index 1884ce506..50c3d55ad 100644 --- a/gettext-tools/src/x-elisp.c +++ b/gettext-tools/src/x-elisp.c @@ -86,15 +86,15 @@ x_elisp_keyword (const char *name) const char *colon; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid Lisp - symbol. */ + symbol. */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); + insert_keyword_callshape (&keywords, name, end - name, &shape); } } @@ -106,7 +106,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_elisp_keyword ("_"); default_keywords = false; } @@ -142,7 +142,7 @@ do_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("\ + error (EXIT_FAILURE, errno, _("\ error while reading \"%s\""), real_file_name); } else if (c == '\n') @@ -167,9 +167,9 @@ do_ungetc (int c) /* A token consists of a sequence of characters. */ struct token { - int allocated; /* number of allocated 'token_char's */ - int charcount; /* number of used 'token_char's */ - char *chars; /* the token's constituents */ + int allocated; /* number of allocated 'token_char's */ + int charcount; /* number of used 'token_char's */ + char *chars; /* the token's constituents */ }; /* Initialize a 'struct token'. */ @@ -231,7 +231,7 @@ is_float (const char *p) { state |= LEAD_INT; do - p++; + p++; while (*p >= '0' && *p <= '9'); } if (*p == '.') @@ -243,7 +243,7 @@ is_float (const char *p) { state |= TRAIL_INT; do - p++; + p++; while (*p >= '0' && *p <= '9'); } if (*p == 'e' || *p == 'E') @@ -251,28 +251,28 @@ is_float (const char *p) state |= E_CHAR; p++; if (*p == '+' || *p == '-') - p++; + p++; if (*p >= '0' && *p <= '9') - { - state |= EXP_INT; - do - p++; - while (*p >= '0' && *p <= '9'); - } + { + state |= EXP_INT; + do + p++; + while (*p >= '0' && *p <= '9'); + } else if (p[-1] == '+' - && ((p[0] == 'I' && p[1] == 'N' && p[2] == 'F') - || (p[0] == 'N' && p[1] == 'a' && p[2] == 'N'))) - { - state |= EXP_INT; - p += 3; - } + && ((p[0] == 'I' && p[1] == 'N' && p[2] == 'F') + || (p[0] == 'N' && p[1] == 'a' && p[2] == 'N'))) + { + state |= EXP_INT; + p += 3; + } } return (*p == '\0') - && (state == (LEAD_INT | DOT_CHAR | TRAIL_INT) - || state == (DOT_CHAR | TRAIL_INT) - || state == (LEAD_INT | E_CHAR | EXP_INT) - || state == (LEAD_INT | DOT_CHAR | TRAIL_INT | E_CHAR | EXP_INT) - || state == (DOT_CHAR | TRAIL_INT | E_CHAR | EXP_INT)); + && (state == (LEAD_INT | DOT_CHAR | TRAIL_INT) + || state == (DOT_CHAR | TRAIL_INT) + || state == (LEAD_INT | E_CHAR | EXP_INT) + || state == (LEAD_INT | DOT_CHAR | TRAIL_INT | E_CHAR | EXP_INT) + || state == (DOT_CHAR | TRAIL_INT | E_CHAR | EXP_INT)); } /* Read the next token. 'first' is the first character, which has already @@ -290,20 +290,20 @@ read_token (struct token *tp, int first) for (;; c = do_getc ()) { if (c == EOF) - break; + break; if (c <= ' ') /* FIXME: Assumes ASCII compatible encoding */ - break; + break; if (c == '\"' || c == '\'' || c == ';' || c == '(' || c == ')' - || c == '[' || c == ']' || c == '#') - break; + || c == '[' || c == ']' || c == '#') + break; if (c == '\\') - { - quoted = true; - c = do_getc (); - if (c == EOF) - /* Invalid, but be tolerant. */ - break; - } + { + quoted = true; + c = do_getc (); + if (c == EOF) + /* Invalid, but be tolerant. */ + break; + } grow_token (tp); tp->chars[tp->charcount++] = c; } @@ -353,7 +353,7 @@ comment_line_end (size_t chars_to_remove) { buflen -= chars_to_remove; while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { @@ -384,20 +384,20 @@ static message_list_ty *mlp; Other objects need not to be represented precisely. */ enum object_type { - t_symbol, /* symbol */ - t_string, /* string */ - t_other, /* other kind of real object */ - t_dot, /* '.' pseudo object */ - t_listclose, /* ')' pseudo object */ + t_symbol, /* symbol */ + t_string, /* string */ + t_other, /* other kind of real object */ + t_dot, /* '.' pseudo object */ + t_listclose, /* ')' pseudo object */ t_vectorclose,/* ']' pseudo object */ - t_eof /* EOF marker */ + t_eof /* EOF marker */ }; struct object { enum object_type type; - struct token *token; /* for t_symbol and t_string */ - int line_number_at_start; /* for t_string */ + struct token *token; /* for t_symbol and t_string */ + int line_number_at_start; /* for t_string */ }; /* Free the memory pointed to by a 'struct object'. */ @@ -465,39 +465,39 @@ do_getc_escaped (int c, bool in_string) case 'M': /* meta */ c = do_getc (); if (c == EOF) - return EOF; + return EOF; if (c != '-') - /* Invalid input. But be tolerant. */ - return c; + /* Invalid input. But be tolerant. */ + return c; c = do_getc (); if (c == EOF) - return EOF; + return EOF; if (c == '\\') - { - c = do_getc (); - if (c == EOF) - return EOF; - c = do_getc_escaped (c, false); - } + { + c = do_getc (); + if (c == EOF) + return EOF; + c = do_getc_escaped (c, false); + } return c | 0x80; case 'S': /* shift */ c = do_getc (); if (c == EOF) - return EOF; + return EOF; if (c != '-') - /* Invalid input. But be tolerant. */ - return c; + /* Invalid input. But be tolerant. */ + return c; c = do_getc (); if (c == EOF) - return EOF; + return EOF; if (c == '\\') - { - c = do_getc (); - if (c == EOF) - return EOF; - c = do_getc_escaped (c, false); - } + { + c = do_getc (); + if (c == EOF) + return EOF; + c = do_getc_escaped (c, false); + } return (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); case 'H': /* hyper */ @@ -505,50 +505,50 @@ do_getc_escaped (int c, bool in_string) case 's': /* super */ c = do_getc (); if (c == EOF) - return EOF; + return EOF; if (c != '-') - /* Invalid input. But be tolerant. */ - return c; + /* Invalid input. But be tolerant. */ + return c; c = do_getc (); if (c == EOF) - return EOF; + return EOF; if (c == '\\') - { - c = do_getc (); - if (c == EOF) - return EOF; - c = do_getc_escaped (c, false); - } + { + c = do_getc (); + if (c == EOF) + return EOF; + c = do_getc_escaped (c, false); + } return c; case 'C': /* ctrl */ c = do_getc (); if (c == EOF) - return EOF; + return EOF; if (c != '-') - /* Invalid input. But be tolerant. */ - return c; + /* Invalid input. But be tolerant. */ + return c; /*FALLTHROUGH*/ case '^': c = do_getc (); if (c == EOF) - return EOF; + return EOF; if (c == '\\') - { - c = do_getc (); - if (c == EOF) - return EOF; - c = do_getc_escaped (c, false); - } + { + c = do_getc (); + if (c == EOF) + return EOF; + c = do_getc_escaped (c, false); + } if (c == '?') - return 0x7F; + return 0x7F; if ((c & 0x5F) >= 0x41 && (c & 0x5F) <= 0x5A) - return c & 0x9F; + return c & 0x9F; if ((c & 0x7F) >= 0x40 && (c & 0x7F) <= 0x5F) - return c & 0x9F; + return c & 0x9F; #if 0 /* We cannot handle NUL bytes in strings. */ if (c == ' ') - return 0x00; + return 0x00; #endif return c; @@ -556,57 +556,57 @@ do_getc_escaped (int c, bool in_string) case '5': case '6': case '7': /* An octal escape, as in ANSI C. */ { - int n = c - '0'; - - c = do_getc (); - if (c != EOF) - { - if (c >= '0' && c <= '7') - { - n = (n << 3) + (c - '0'); - c = do_getc (); - if (c != EOF) - { - if (c >= '0' && c <= '7') - n = (n << 3) + (c - '0'); - else - do_ungetc (c); - } - } - else - do_ungetc (c); - } - return (unsigned char) n; + int n = c - '0'; + + c = do_getc (); + if (c != EOF) + { + if (c >= '0' && c <= '7') + { + n = (n << 3) + (c - '0'); + c = do_getc (); + if (c != EOF) + { + if (c >= '0' && c <= '7') + n = (n << 3) + (c - '0'); + else + do_ungetc (c); + } + } + else + do_ungetc (c); + } + return (unsigned char) n; } case 'x': /* A hexadecimal escape, as in ANSI C. */ { - int n = 0; - - for (;;) - { - c = do_getc (); - if (c == EOF) - break; - else if (c >= '0' && c <= '9') - n = (n << 4) + (c - '0'); - else if (c >= 'A' && c <= 'F') - n = (n << 4) + (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - n = (n << 4) + (c - 'a' + 10); - else - { - do_ungetc (c); - break; - } - } - return (unsigned char) n; + int n = 0; + + for (;;) + { + c = do_getc (); + if (c == EOF) + break; + else if (c >= '0' && c <= '9') + n = (n << 4) + (c - '0'); + else if (c >= 'A' && c <= 'F') + n = (n << 4) + (c - 'A' + 10); + else if (c >= 'a' && c <= 'f') + n = (n << 4) + (c - 'a' + 10); + else + { + do_ungetc (c); + break; + } + } + return (unsigned char) n; } default: /* Ignore Emacs multibyte character stuff. All the strings we are - interested in are ASCII strings. */ + interested in are ASCII strings. */ return c; } } @@ -616,7 +616,7 @@ do_getc_escaped (int c, bool in_string) backquote syntax and new backquote syntax. */ static void read_object (struct object *op, bool first_in_list, bool new_backquote_flag, - flag_context_ty outer_context) + flag_context_ty outer_context) { for (;;) { @@ -625,598 +625,598 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag, c = do_getc (); switch (c) - { - case EOF: - op->type = t_eof; - return; - - case '\n': - /* Comments assumed to be grouped with a message must immediately - precede it, with no non-whitespace token on a line between - both. */ - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - continue; - - case '(': - { - int arg = 0; /* Current argument number. */ - flag_context_list_iterator_ty context_iter; - const struct callshapes *shapes = NULL; - struct arglist_parser *argparser = NULL; - - for (;; arg++) - { - struct object inner; - flag_context_ty inner_context; - - if (arg == 0) - inner_context = null_context; - else - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - - read_object (&inner, arg == 0, new_backquote_flag, - inner_context); - - /* Recognize end of list. */ - if (inner.type == t_listclose) - { - op->type = t_other; - /* Don't bother converting "()" to "NIL". */ - last_non_comment_line = line_number; - if (argparser != NULL) - arglist_parser_done (argparser, arg); - return; - } - - /* Dots are not allowed in every position. ']' is not allowed. - But be tolerant. */ - - /* EOF inside list is illegal. But be tolerant. */ - if (inner.type == t_eof) - break; - - if (arg == 0) - { - /* This is the function position. */ - if (inner.type == t_symbol) - { - char *symbol_name = string_of_object (&inner); - void *keyword_value; - - if (hash_find_entry (&keywords, - symbol_name, strlen (symbol_name), - &keyword_value) - == 0) - shapes = (const struct callshapes *) keyword_value; - - argparser = arglist_parser_alloc (mlp, shapes); - - context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - symbol_name, strlen (symbol_name))); - - free (symbol_name); - } - else - context_iter = null_context_list_iterator; - } - else - { - /* These are the argument positions. */ - if (argparser != NULL && inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_object (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); - } - - free_object (&inner); - } - - if (argparser != NULL) - arglist_parser_done (argparser, arg); - } - op->type = t_other; - last_non_comment_line = line_number; - return; - - case ')': - /* Tell the caller about the end of list. - Unmatched closing parenthesis is illegal. But be tolerant. */ - op->type = t_listclose; - last_non_comment_line = line_number; - return; - - case '[': - { - for (;;) - { - struct object inner; - - read_object (&inner, false, new_backquote_flag, null_context); - - /* Recognize end of vector. */ - if (inner.type == t_vectorclose) - { - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - /* Dots and ')' are not allowed. But be tolerant. */ - - /* EOF inside vector is illegal. But be tolerant. */ - if (inner.type == t_eof) - break; - - free_object (&inner); - } - } - op->type = t_other; - last_non_comment_line = line_number; - return; - - case ']': - /* Tell the caller about the end of vector. - Unmatched closing bracket is illegal. But be tolerant. */ - op->type = t_vectorclose; - last_non_comment_line = line_number; - return; - - case '\'': - { - struct object inner; - - read_object (&inner, false, new_backquote_flag, null_context); - - /* Dots and EOF are not allowed here. But be tolerant. */ - - free_object (&inner); - - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '`': - if (first_in_list) - goto default_label; - { - struct object inner; - - read_object (&inner, false, true, null_context); - - /* Dots and EOF are not allowed here. But be tolerant. */ - - free_object (&inner); - - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case ',': - if (!new_backquote_flag) - goto default_label; - { - int c = do_getc (); - /* The ,@ handling inside lists is wrong anyway, because - ,@form expands to an unknown number of elements. */ - if (c != EOF && c != '@' && c != '.') - do_ungetc (c); - } - { - struct object inner; - - read_object (&inner, false, false, null_context); - - /* Dots and EOF are not allowed here. But be tolerant. */ - - free_object (&inner); - - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case ';': - { - bool all_semicolons = true; - - last_comment_line = line_number; - comment_start (); - for (;;) - { - int c = do_getc (); - if (c == EOF || c == '\n') - break; - if (c != ';') - all_semicolons = false; - if (!all_semicolons) - { - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - } - } - comment_line_end (0); - continue; - } - - case '"': - { - op->token = XMALLOC (struct token); - init_token (op->token); - op->line_number_at_start = line_number; - for (;;) - { - int c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - break; - if (c == '"') - break; - if (c == '\\') - { - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - break; - c = do_getc_escaped (c, true); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - break; - if (c == IGNORABLE_ESCAPE) - /* Ignore escaped newline and escaped space. */ - ; - else - { - grow_token (op->token); - op->token->chars[op->token->charcount++] = c; - } - } - else - { - grow_token (op->token); - op->token->chars[op->token->charcount++] = c; - } - } - op->type = t_string; - - if (extract_all) - { - lex_pos_ty pos; - - pos.file_name = logical_file_name; - pos.line_number = op->line_number_at_start; - remember_a_message (mlp, NULL, string_of_object (op), - null_context, &pos, NULL, savable_comment); - } - last_non_comment_line = line_number; - return; - } - - case '?': - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - else if (c == '\\') - { - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - else - { - c = do_getc_escaped (c, false); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - } - } - /* Impossible to deal with Emacs multibyte character stuff here. */ - op->type = t_other; - last_non_comment_line = line_number; - return; - - case '#': - /* Dispatch macro handling. */ - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - { - op->type = t_other; - return; - } - - switch (c) - { - case '^': - c = do_getc (); - if (c == '^') - c = do_getc (); - if (c == '[') - { - /* Read a char table, same syntax as a vector. */ - for (;;) - { - struct object inner; - - read_object (&inner, false, new_backquote_flag, - null_context); - - /* Recognize end of vector. */ - if (inner.type == t_vectorclose) - { - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - /* Dots and ')' are not allowed. But be tolerant. */ - - /* EOF inside vector is illegal. But be tolerant. */ - if (inner.type == t_eof) - break; - - free_object (&inner); - } - op->type = t_other; - last_non_comment_line = line_number; - return; - } - else - /* Invalid input. Be tolerant, no error message. */ - { - op->type = t_other; - if (c != EOF) - last_non_comment_line = line_number; - return; - } - - case '&': - /* Read a bit vector. */ - { - struct object length; - read_object (&length, first_in_list, new_backquote_flag, - null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&length); - } - c = do_getc (); - if (c == '"') - { - struct object string; - read_object (&string, first_in_list, new_backquote_flag, - null_context); - free_object (&string); - } - else - /* Invalid input. Be tolerant, no error message. */ - do_ungetc (c); - op->type = t_other; - last_non_comment_line = line_number; - return; - - case '[': - /* Read a compiled function, same syntax as a vector. */ - case '(': - /* Read a string with properties, same syntax as a list. */ - { - struct object inner; - do_ungetc (c); - read_object (&inner, false, new_backquote_flag, null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '@': - /* Read a comment consisting of a given number of bytes. */ - { - unsigned int nskip = 0; - - for (;;) - { - c = do_getc (); - if (!(c >= '0' && c <= '9')) - break; - nskip = 10 * nskip + (c - '0'); - } - if (c != EOF) - { - do_ungetc (c); - for (; nskip > 0; nskip--) - if (do_getc () == EOF) - break; - } - continue; - } - - case '$': - op->type = t_other; - last_non_comment_line = line_number; - return; - - case '\'': - case ':': - case 'S': case 's': /* XEmacs only */ - { - struct object inner; - read_object (&inner, false, new_backquote_flag, null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - /* Read Common Lisp style #n# or #n=. */ - for (;;) - { - c = do_getc (); - if (!(c >= '0' && c <= '9')) - break; - } - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - { - op->type = t_other; - return; - } - if (c == '=') - { - read_object (op, false, new_backquote_flag, outer_context); - last_non_comment_line = line_number; - return; - } - if (c == '#') - { - op->type = t_other; - last_non_comment_line = line_number; - return; - } - if (c == 'R' || c == 'r') - { - /* Read an integer. */ - c = do_getc (); - if (c == '+' || c == '-') - c = do_getc (); - for (; c != EOF; c = do_getc ()) - if (!c_isalnum (c)) - { - do_ungetc (c); - break; - } - op->type = t_other; - last_non_comment_line = line_number; - return; - } - /* Invalid input. Be tolerant, no error message. */ - op->type = t_other; - last_non_comment_line = line_number; - return; - - case 'X': case 'x': - case 'O': case 'o': - case 'B': case 'b': - { - /* Read an integer. */ - c = do_getc (); - if (c == '+' || c == '-') - c = do_getc (); - for (; c != EOF; c = do_getc ()) - if (!c_isalnum (c)) - { - do_ungetc (c); - break; - } - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '*': /* XEmacs only */ - { - /* Read a bit-vector. */ - do - c = do_getc (); - while (c == '0' || c == '1'); - if (c != EOF) - do_ungetc (c); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '+': /* XEmacs only */ - case '-': /* XEmacs only */ - /* Simply assume every feature expression is true. */ - { - struct object inner; - read_object (&inner, false, new_backquote_flag, null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - continue; - } - - default: - /* Invalid input. Be tolerant, no error message. */ - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - /*NOTREACHED*/ - abort (); - - case '.': - c = do_getc (); - if (c != EOF) - { - do_ungetc (c); - if (c <= ' ' /* FIXME: Assumes ASCII compatible encoding */ - || strchr ("\"'`,(", c) != NULL) - { - op->type = t_dot; - last_non_comment_line = line_number; - return; - } - } - c = '.'; - /*FALLTHROUGH*/ - default: - default_label: - if (c <= ' ') /* FIXME: Assumes ASCII compatible encoding */ - continue; - /* Read a token. */ - { - bool symbol; - - op->token = XMALLOC (struct token); - symbol = read_token (op->token, c); - if (symbol) - { - op->type = t_symbol; - last_non_comment_line = line_number; - return; - } - else - { - free_token (op->token); - free (op->token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - } - } + { + case EOF: + op->type = t_eof; + return; + + case '\n': + /* Comments assumed to be grouped with a message must immediately + precede it, with no non-whitespace token on a line between + both. */ + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + continue; + + case '(': + { + int arg = 0; /* Current argument number. */ + flag_context_list_iterator_ty context_iter; + const struct callshapes *shapes = NULL; + struct arglist_parser *argparser = NULL; + + for (;; arg++) + { + struct object inner; + flag_context_ty inner_context; + + if (arg == 0) + inner_context = null_context; + else + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + + read_object (&inner, arg == 0, new_backquote_flag, + inner_context); + + /* Recognize end of list. */ + if (inner.type == t_listclose) + { + op->type = t_other; + /* Don't bother converting "()" to "NIL". */ + last_non_comment_line = line_number; + if (argparser != NULL) + arglist_parser_done (argparser, arg); + return; + } + + /* Dots are not allowed in every position. ']' is not allowed. + But be tolerant. */ + + /* EOF inside list is illegal. But be tolerant. */ + if (inner.type == t_eof) + break; + + if (arg == 0) + { + /* This is the function position. */ + if (inner.type == t_symbol) + { + char *symbol_name = string_of_object (&inner); + void *keyword_value; + + if (hash_find_entry (&keywords, + symbol_name, strlen (symbol_name), + &keyword_value) + == 0) + shapes = (const struct callshapes *) keyword_value; + + argparser = arglist_parser_alloc (mlp, shapes); + + context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + symbol_name, strlen (symbol_name))); + + free (symbol_name); + } + else + context_iter = null_context_list_iterator; + } + else + { + /* These are the argument positions. */ + if (argparser != NULL && inner.type == t_string) + arglist_parser_remember (argparser, arg, + string_of_object (&inner), + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + } + + free_object (&inner); + } + + if (argparser != NULL) + arglist_parser_done (argparser, arg); + } + op->type = t_other; + last_non_comment_line = line_number; + return; + + case ')': + /* Tell the caller about the end of list. + Unmatched closing parenthesis is illegal. But be tolerant. */ + op->type = t_listclose; + last_non_comment_line = line_number; + return; + + case '[': + { + for (;;) + { + struct object inner; + + read_object (&inner, false, new_backquote_flag, null_context); + + /* Recognize end of vector. */ + if (inner.type == t_vectorclose) + { + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + /* Dots and ')' are not allowed. But be tolerant. */ + + /* EOF inside vector is illegal. But be tolerant. */ + if (inner.type == t_eof) + break; + + free_object (&inner); + } + } + op->type = t_other; + last_non_comment_line = line_number; + return; + + case ']': + /* Tell the caller about the end of vector. + Unmatched closing bracket is illegal. But be tolerant. */ + op->type = t_vectorclose; + last_non_comment_line = line_number; + return; + + case '\'': + { + struct object inner; + + read_object (&inner, false, new_backquote_flag, null_context); + + /* Dots and EOF are not allowed here. But be tolerant. */ + + free_object (&inner); + + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '`': + if (first_in_list) + goto default_label; + { + struct object inner; + + read_object (&inner, false, true, null_context); + + /* Dots and EOF are not allowed here. But be tolerant. */ + + free_object (&inner); + + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case ',': + if (!new_backquote_flag) + goto default_label; + { + int c = do_getc (); + /* The ,@ handling inside lists is wrong anyway, because + ,@form expands to an unknown number of elements. */ + if (c != EOF && c != '@' && c != '.') + do_ungetc (c); + } + { + struct object inner; + + read_object (&inner, false, false, null_context); + + /* Dots and EOF are not allowed here. But be tolerant. */ + + free_object (&inner); + + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case ';': + { + bool all_semicolons = true; + + last_comment_line = line_number; + comment_start (); + for (;;) + { + int c = do_getc (); + if (c == EOF || c == '\n') + break; + if (c != ';') + all_semicolons = false; + if (!all_semicolons) + { + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + } + } + comment_line_end (0); + continue; + } + + case '"': + { + op->token = XMALLOC (struct token); + init_token (op->token); + op->line_number_at_start = line_number; + for (;;) + { + int c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + break; + if (c == '"') + break; + if (c == '\\') + { + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + break; + c = do_getc_escaped (c, true); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + break; + if (c == IGNORABLE_ESCAPE) + /* Ignore escaped newline and escaped space. */ + ; + else + { + grow_token (op->token); + op->token->chars[op->token->charcount++] = c; + } + } + else + { + grow_token (op->token); + op->token->chars[op->token->charcount++] = c; + } + } + op->type = t_string; + + if (extract_all) + { + lex_pos_ty pos; + + pos.file_name = logical_file_name; + pos.line_number = op->line_number_at_start; + remember_a_message (mlp, NULL, string_of_object (op), + null_context, &pos, NULL, savable_comment); + } + last_non_comment_line = line_number; + return; + } + + case '?': + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + else if (c == '\\') + { + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + else + { + c = do_getc_escaped (c, false); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + } + } + /* Impossible to deal with Emacs multibyte character stuff here. */ + op->type = t_other; + last_non_comment_line = line_number; + return; + + case '#': + /* Dispatch macro handling. */ + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + { + op->type = t_other; + return; + } + + switch (c) + { + case '^': + c = do_getc (); + if (c == '^') + c = do_getc (); + if (c == '[') + { + /* Read a char table, same syntax as a vector. */ + for (;;) + { + struct object inner; + + read_object (&inner, false, new_backquote_flag, + null_context); + + /* Recognize end of vector. */ + if (inner.type == t_vectorclose) + { + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + /* Dots and ')' are not allowed. But be tolerant. */ + + /* EOF inside vector is illegal. But be tolerant. */ + if (inner.type == t_eof) + break; + + free_object (&inner); + } + op->type = t_other; + last_non_comment_line = line_number; + return; + } + else + /* Invalid input. Be tolerant, no error message. */ + { + op->type = t_other; + if (c != EOF) + last_non_comment_line = line_number; + return; + } + + case '&': + /* Read a bit vector. */ + { + struct object length; + read_object (&length, first_in_list, new_backquote_flag, + null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&length); + } + c = do_getc (); + if (c == '"') + { + struct object string; + read_object (&string, first_in_list, new_backquote_flag, + null_context); + free_object (&string); + } + else + /* Invalid input. Be tolerant, no error message. */ + do_ungetc (c); + op->type = t_other; + last_non_comment_line = line_number; + return; + + case '[': + /* Read a compiled function, same syntax as a vector. */ + case '(': + /* Read a string with properties, same syntax as a list. */ + { + struct object inner; + do_ungetc (c); + read_object (&inner, false, new_backquote_flag, null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '@': + /* Read a comment consisting of a given number of bytes. */ + { + unsigned int nskip = 0; + + for (;;) + { + c = do_getc (); + if (!(c >= '0' && c <= '9')) + break; + nskip = 10 * nskip + (c - '0'); + } + if (c != EOF) + { + do_ungetc (c); + for (; nskip > 0; nskip--) + if (do_getc () == EOF) + break; + } + continue; + } + + case '$': + op->type = t_other; + last_non_comment_line = line_number; + return; + + case '\'': + case ':': + case 'S': case 's': /* XEmacs only */ + { + struct object inner; + read_object (&inner, false, new_backquote_flag, null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* Read Common Lisp style #n# or #n=. */ + for (;;) + { + c = do_getc (); + if (!(c >= '0' && c <= '9')) + break; + } + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + { + op->type = t_other; + return; + } + if (c == '=') + { + read_object (op, false, new_backquote_flag, outer_context); + last_non_comment_line = line_number; + return; + } + if (c == '#') + { + op->type = t_other; + last_non_comment_line = line_number; + return; + } + if (c == 'R' || c == 'r') + { + /* Read an integer. */ + c = do_getc (); + if (c == '+' || c == '-') + c = do_getc (); + for (; c != EOF; c = do_getc ()) + if (!c_isalnum (c)) + { + do_ungetc (c); + break; + } + op->type = t_other; + last_non_comment_line = line_number; + return; + } + /* Invalid input. Be tolerant, no error message. */ + op->type = t_other; + last_non_comment_line = line_number; + return; + + case 'X': case 'x': + case 'O': case 'o': + case 'B': case 'b': + { + /* Read an integer. */ + c = do_getc (); + if (c == '+' || c == '-') + c = do_getc (); + for (; c != EOF; c = do_getc ()) + if (!c_isalnum (c)) + { + do_ungetc (c); + break; + } + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '*': /* XEmacs only */ + { + /* Read a bit-vector. */ + do + c = do_getc (); + while (c == '0' || c == '1'); + if (c != EOF) + do_ungetc (c); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '+': /* XEmacs only */ + case '-': /* XEmacs only */ + /* Simply assume every feature expression is true. */ + { + struct object inner; + read_object (&inner, false, new_backquote_flag, null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + continue; + } + + default: + /* Invalid input. Be tolerant, no error message. */ + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + /*NOTREACHED*/ + abort (); + + case '.': + c = do_getc (); + if (c != EOF) + { + do_ungetc (c); + if (c <= ' ' /* FIXME: Assumes ASCII compatible encoding */ + || strchr ("\"'`,(", c) != NULL) + { + op->type = t_dot; + last_non_comment_line = line_number; + return; + } + } + c = '.'; + /*FALLTHROUGH*/ + default: + default_label: + if (c <= ' ') /* FIXME: Assumes ASCII compatible encoding */ + continue; + /* Read a token. */ + { + bool symbol; + + op->token = XMALLOC (struct token); + symbol = read_token (op->token, c); + if (symbol) + { + op->type = t_symbol; + last_non_comment_line = line_number; + return; + } + else + { + free_token (op->token); + free (op->token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + } + } } } void extract_elisp (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { mlp = mdlp->item[0]->messages; @@ -1241,7 +1241,7 @@ extract_elisp (FILE *f, read_object (&toplevel_object, false, false, null_context); if (toplevel_object.type == t_eof) - break; + break; free_object (&toplevel_object); } diff --git a/gettext-tools/src/x-elisp.h b/gettext-tools/src/x-elisp.h index 4822440bc..b0f7123ab 100644 --- a/gettext-tools/src/x-elisp.h +++ b/gettext-tools/src/x-elisp.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_ELISP \ - { "el", "EmacsLisp" }, \ + { "el", "EmacsLisp" }, \ #define SCANNERS_ELISP \ - { "EmacsLisp", extract_elisp, \ - &flag_table_elisp, &formatstring_elisp, NULL }, \ + { "EmacsLisp", extract_elisp, \ + &flag_table_elisp, &formatstring_elisp, NULL }, \ /* Scan an Emacs Lisp file and add its translatable strings to mdlp. */ extern void extract_elisp (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); /* Handling of options specific to this language. */ diff --git a/gettext-tools/src/x-glade.c b/gettext-tools/src/x-glade.c index 31191f2a8..11f839706 100644 --- a/gettext-tools/src/x-glade.c +++ b/gettext-tools/src/x-glade.c @@ -80,7 +80,7 @@ x_glade_keyword (const char *name) else { if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); hash_insert_entry (&keywords, name, strlen (name), NULL); } @@ -94,7 +94,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_glade_keyword ("label"); x_glade_keyword ("title"); x_glade_keyword ("text"); @@ -146,11 +146,11 @@ is_XML_LARGE_SIZE_ABI (void) is_large = false; for (features = XML_GetFeatureList (); features->name != NULL; features++) - if (strcmp (features->name, "XML_LARGE_SIZE") == 0) - { - is_large = true; - break; - } + if (strcmp (features->name, "XML_LARGE_SIZE") == 0) + { + is_large = true; + break; + } tested = true; } @@ -241,23 +241,23 @@ get_XML_Size_ABI (void) if (!tested) { if (XML_ExpatVersionInfo () .major >= 2) - /* expat >= 2.0 -> XML_Size is 'int64_t' or 'long'. */ - { - const XML_Feature *features; - - abi = is_long; - for (features = XML_GetFeatureList (); - features->name != NULL; - features++) - if (strcmp (features->name, "XML_LARGE_SIZE") == 0) - { - abi = is_int64_t; - break; - } - } + /* expat >= 2.0 -> XML_Size is 'int64_t' or 'long'. */ + { + const XML_Feature *features; + + abi = is_long; + for (features = XML_GetFeatureList (); + features->name != NULL; + features++) + if (strcmp (features->name, "XML_LARGE_SIZE") == 0) + { + abi = is_int64_t; + break; + } + } else - /* expat < 2.0 -> XML_Size is 'int'. */ - abi = is_int; + /* expat < 2.0 -> XML_Size is 'int'. */ + abi = is_int; tested = true; } return abi; @@ -317,46 +317,46 @@ load_libexpat () /* Try to load libexpat-2.x. */ handle = dlopen ("libexpat.so.1", RTLD_LAZY); if (handle == NULL) - /* Try to load libexpat-1.x. */ - handle = dlopen ("libexpat.so.0", RTLD_LAZY); + /* Try to load libexpat-1.x. */ + handle = dlopen ("libexpat.so.0", RTLD_LAZY); if (handle != NULL - && (p_XML_ExpatVersionInfo = - (XML_Expat_Version (*) (void)) - dlsym (handle, "XML_ExpatVersionInfo")) != NULL - && (p_XML_GetFeatureList = - (const XML_Feature * (*) (void)) - dlsym (handle, "XML_GetFeatureList")) != NULL - && (p_XML_ParserCreate = - (XML_Parser (*) (const XML_Char *)) - dlsym (handle, "XML_ParserCreate")) != NULL - && (p_XML_SetElementHandler = - (void (*) (XML_Parser, XML_StartElementHandler, XML_EndElementHandler)) - dlsym (handle, "XML_SetElementHandler")) != NULL - && (p_XML_SetCharacterDataHandler = - (void (*) (XML_Parser, XML_CharacterDataHandler)) - dlsym (handle, "XML_SetCharacterDataHandler")) != NULL - && (p_XML_SetCommentHandler = - (void (*) (XML_Parser, XML_CommentHandler)) - dlsym (handle, "XML_SetCommentHandler")) != NULL - && (p_XML_Parse = - (int (*) (XML_Parser, const char *, int, int)) - dlsym (handle, "XML_Parse")) != NULL - && (p_XML_GetErrorCode = - (enum XML_Error (*) (XML_Parser)) - dlsym (handle, "XML_GetErrorCode")) != NULL - && (p_XML_GetCurrentLineNumber = - dlsym (handle, "XML_GetCurrentLineNumber")) != NULL - && (p_XML_GetCurrentColumnNumber = - dlsym (handle, "XML_GetCurrentColumnNumber")) != NULL - && (p_XML_ParserFree = - (void (*) (XML_Parser)) - dlsym (handle, "XML_ParserFree")) != NULL - && (p_XML_ErrorString = - (const XML_LChar * (*) (int)) - dlsym (handle, "XML_ErrorString")) != NULL) - libexpat_loaded = 1; + && (p_XML_ExpatVersionInfo = + (XML_Expat_Version (*) (void)) + dlsym (handle, "XML_ExpatVersionInfo")) != NULL + && (p_XML_GetFeatureList = + (const XML_Feature * (*) (void)) + dlsym (handle, "XML_GetFeatureList")) != NULL + && (p_XML_ParserCreate = + (XML_Parser (*) (const XML_Char *)) + dlsym (handle, "XML_ParserCreate")) != NULL + && (p_XML_SetElementHandler = + (void (*) (XML_Parser, XML_StartElementHandler, XML_EndElementHandler)) + dlsym (handle, "XML_SetElementHandler")) != NULL + && (p_XML_SetCharacterDataHandler = + (void (*) (XML_Parser, XML_CharacterDataHandler)) + dlsym (handle, "XML_SetCharacterDataHandler")) != NULL + && (p_XML_SetCommentHandler = + (void (*) (XML_Parser, XML_CommentHandler)) + dlsym (handle, "XML_SetCommentHandler")) != NULL + && (p_XML_Parse = + (int (*) (XML_Parser, const char *, int, int)) + dlsym (handle, "XML_Parse")) != NULL + && (p_XML_GetErrorCode = + (enum XML_Error (*) (XML_Parser)) + dlsym (handle, "XML_GetErrorCode")) != NULL + && (p_XML_GetCurrentLineNumber = + dlsym (handle, "XML_GetCurrentLineNumber")) != NULL + && (p_XML_GetCurrentColumnNumber = + dlsym (handle, "XML_GetCurrentColumnNumber")) != NULL + && (p_XML_ParserFree = + (void (*) (XML_Parser)) + dlsym (handle, "XML_ParserFree")) != NULL + && (p_XML_ErrorString = + (const XML_LChar * (*) (int)) + dlsym (handle, "XML_ErrorString")) != NULL) + libexpat_loaded = 1; else - libexpat_loaded = -1; + libexpat_loaded = -1; } return libexpat_loaded >= 0; } @@ -402,10 +402,10 @@ ensure_stack_size (size_t size) { stack_size = 2 * stack_size; if (stack_size < size) - stack_size = size; + stack_size = size; stack = - (struct element_state *) - xrealloc (stack, stack_size * sizeof (struct element_state)); + (struct element_state *) + xrealloc (stack, stack_size * sizeof (struct element_state)); } } @@ -414,7 +414,7 @@ static size_t stack_depth; /* Callback called when is seen. */ static void start_element_handler (void *userData, const char *name, - const char **attributes) + const char **attributes) { struct element_state *p; void *hash_result; @@ -446,42 +446,42 @@ start_element_handler (void *userData, const char *name, const char *extracted_comment = NULL; const char **attp = attributes; while (*attp != NULL) - { - if (strcmp (attp[0], "translatable") == 0) - has_translatable = (strcmp (attp[1], "yes") == 0); - else if (strcmp (attp[0], "comments") == 0) - extracted_comment = attp[1]; - attp += 2; - } + { + if (strcmp (attp[0], "translatable") == 0) + has_translatable = (strcmp (attp[1], "yes") == 0); + else if (strcmp (attp[0], "comments") == 0) + extracted_comment = attp[1]; + attp += 2; + } p->extract_string = has_translatable; p->extracted_comment = - (has_translatable && extracted_comment != NULL - ? xstrdup (extracted_comment) - : NULL); + (has_translatable && extracted_comment != NULL + ? xstrdup (extracted_comment) + : NULL); } if (!p->extract_string && strcmp (name, "atkaction") == 0) { const char **attp = attributes; while (*attp != NULL) - { - if (strcmp (attp[0], "description") == 0) - { - if (strcmp (attp[1], "") != 0) - { - lex_pos_ty pos; - - pos.file_name = logical_file_name; - pos.line_number = XML_GetCurrentLineNumber (parser); - - remember_a_message (mlp, NULL, xstrdup (attp[1]), - null_context, &pos, - NULL, savable_comment); - } - break; - } - attp += 2; - } + { + if (strcmp (attp[0], "description") == 0) + { + if (strcmp (attp[1], "") != 0) + { + lex_pos_ty pos; + + pos.file_name = logical_file_name; + pos.line_number = XML_GetCurrentLineNumber (parser); + + remember_a_message (mlp, NULL, xstrdup (attp[1]), + null_context, &pos, + NULL, savable_comment); + } + break; + } + attp += 2; + } } p->lineno = XML_GetCurrentLineNumber (parser); p->buffer = NULL; @@ -502,20 +502,20 @@ end_element_handler (void *userData, const char *name) { /* Don't extract the empty string. */ if (p->buflen > 0) - { - lex_pos_ty pos; + { + lex_pos_ty pos; - if (p->buflen == p->bufmax) - p->buffer = (char *) xrealloc (p->buffer, p->buflen + 1); - p->buffer[p->buflen] = '\0'; + if (p->buflen == p->bufmax) + p->buffer = (char *) xrealloc (p->buffer, p->buflen + 1); + p->buffer[p->buflen] = '\0'; - pos.file_name = logical_file_name; - pos.line_number = p->lineno; + pos.file_name = logical_file_name; + pos.line_number = p->lineno; - remember_a_message (mlp, NULL, p->buffer, null_context, &pos, - p->extracted_comment, savable_comment); - p->buffer = NULL; - } + remember_a_message (mlp, NULL, p->buffer, null_context, &pos, + p->extracted_comment, savable_comment); + p->buffer = NULL; + } } /* Free memory for this stack level. */ @@ -540,12 +540,12 @@ character_data_handler (void *userData, const char *s, int len) if (len > 0) { if (p->buflen + len > p->bufmax) - { - p->bufmax = 2 * p->bufmax; - if (p->bufmax < p->buflen + len) - p->bufmax = p->buflen + len; - p->buffer = (char *) xrealloc (p->buffer, p->bufmax); - } + { + p->bufmax = 2 * p->bufmax; + if (p->bufmax < p->buflen + len) + p->bufmax = p->buflen + len; + p->buffer = (char *) xrealloc (p->buffer, p->bufmax); + } memcpy (p->buffer + p->buflen, s, len); p->buflen += len; } @@ -564,9 +564,9 @@ comment_handler (void *userData, const char *data) for (p = copy; (q = strchr (p, '\n')) != NULL; p = q + 1) { while (p[0] == ' ' || p[0] == '\t') - p++; + p++; while (q > p && (q[-1] == ' ' || q[-1] == '\t')) - q--; + q--; *q = '\0'; savable_comment_add (p); } @@ -583,8 +583,8 @@ comment_handler (void *userData, const char *data) static void do_extract_glade (FILE *fp, - const char *real_filename, const char *logical_filename, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + msgdomain_list_ty *mdlp) { mlp = mdlp->item[0]->messages; @@ -611,26 +611,26 @@ do_extract_glade (FILE *fp, int count = fread (buf, 1, sizeof buf, fp); if (count == 0) - { - if (ferror (fp)) - error (EXIT_FAILURE, errno, _("\ + { + if (ferror (fp)) + error (EXIT_FAILURE, errno, _("\ error while reading \"%s\""), real_filename); - /* EOF reached. */ - break; - } + /* EOF reached. */ + break; + } if (XML_Parse (parser, buf, count, 0) == 0) - error (EXIT_FAILURE, 0, _("%s:%lu:%lu: %s"), logical_filename, - (unsigned long) XML_GetCurrentLineNumber (parser), - (unsigned long) XML_GetCurrentColumnNumber (parser) + 1, - XML_ErrorString (XML_GetErrorCode (parser))); + error (EXIT_FAILURE, 0, _("%s:%lu:%lu: %s"), logical_filename, + (unsigned long) XML_GetCurrentLineNumber (parser), + (unsigned long) XML_GetCurrentColumnNumber (parser) + 1, + XML_ErrorString (XML_GetErrorCode (parser))); } if (XML_Parse (parser, NULL, 0, 1) == 0) error (EXIT_FAILURE, 0, _("%s:%lu:%lu: %s"), logical_filename, - (unsigned long) XML_GetCurrentLineNumber (parser), - (unsigned long) XML_GetCurrentColumnNumber (parser) + 1, - XML_ErrorString (XML_GetErrorCode (parser))); + (unsigned long) XML_GetCurrentLineNumber (parser), + (unsigned long) XML_GetCurrentColumnNumber (parser) + 1, + XML_ErrorString (XML_GetErrorCode (parser))); XML_ParserFree (parser); @@ -643,9 +643,9 @@ error while reading \"%s\""), real_filename); void extract_glade (FILE *fp, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { #if DYNLOAD_LIBEXPAT || HAVE_LIBEXPAT if (LIBEXPAT_AVAILABLE ()) @@ -654,10 +654,10 @@ extract_glade (FILE *fp, #endif { multiline_error (xstrdup (""), - xasprintf (_("\ + xasprintf (_("\ Language \"glade\" is not supported. %s relies on expat.\n\ This version was built without expat.\n"), - basename (program_name))); + basename (program_name))); exit (EXIT_FAILURE); } } diff --git a/gettext-tools/src/x-glade.h b/gettext-tools/src/x-glade.h index 651b56a98..0af338507 100644 --- a/gettext-tools/src/x-glade.h +++ b/gettext-tools/src/x-glade.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_GLADE \ - { "glade", "glade" }, \ - { "glade2", "glade" }, \ + { "glade", "glade" }, \ + { "glade2", "glade" }, \ #define SCANNERS_GLADE \ - { "glade", extract_glade, NULL, NULL, NULL }, \ + { "glade", extract_glade, NULL, NULL, NULL }, \ /* Scan a glade XML file and add its translatable strings to mdlp. */ extern void extract_glade (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); /* Handling of options specific to this language. */ diff --git a/gettext-tools/src/x-java.c b/gettext-tools/src/x-java.c index 4ba9a7c92..58c1ad7a9 100644 --- a/gettext-tools/src/x-java.c +++ b/gettext-tools/src/x-java.c @@ -76,16 +76,16 @@ x_java_keyword (const char *name) const char *colon; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid Java - identifier sequence with dots. - A colon means an invalid parse in split_keywordspec(). */ + identifier sequence with dots. + A colon means an invalid parse in split_keywordspec(). */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); + insert_keyword_callshape (&keywords, name, end - name, &shape); } } @@ -97,7 +97,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_java_keyword ("GettextResource.gettext:2"); /* static method */ x_java_keyword ("GettextResource.ngettext:2,3"); /* static method */ x_java_keyword ("GettextResource.pgettext:2c,3"); /* static method */ @@ -106,7 +106,7 @@ init_keywords () x_java_keyword ("ngettext:1,2"); x_java_keyword ("pgettext:1c,2"); x_java_keyword ("npgettext:1c,2,3"); - x_java_keyword ("getString"); /* ResourceBundle.getString */ + x_java_keyword ("getString"); /* ResourceBundle.getString */ default_keywords = false; } } @@ -164,13 +164,13 @@ phase1_getc () { c = phase1_pushback[--phase1_pushback_length]; if (c >= MULTIPLE_U (0)) - { - if (c > MULTIPLE_U (1)) - phase1_pushback[phase1_pushback_length++] = c - 1; - return 'u'; - } + { + if (c > MULTIPLE_U (1)) + phase1_pushback[phase1_pushback_length++] = c - 1; + return 'u'; + } else - return c; + return c; } c = getc (fp); @@ -178,7 +178,7 @@ phase1_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("\ + error (EXIT_FAILURE, errno, _("\ error while reading \"%s\""), real_file_name); } @@ -192,23 +192,23 @@ phase1_ungetc (int c) if (c != EOF) { if (c == 'u') - { - if (phase1_pushback_length > 0 - && phase1_pushback[phase1_pushback_length - 1] >= MULTIPLE_U (0)) - phase1_pushback[phase1_pushback_length - 1]++; - else - { - if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); - phase1_pushback[phase1_pushback_length++] = MULTIPLE_U (1); - } - } + { + if (phase1_pushback_length > 0 + && phase1_pushback[phase1_pushback_length - 1] >= MULTIPLE_U (0)) + phase1_pushback[phase1_pushback_length - 1]++; + else + { + if (phase1_pushback_length == SIZEOF (phase1_pushback)) + abort (); + phase1_pushback[phase1_pushback_length++] = MULTIPLE_U (1); + } + } else - { - if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); - phase1_pushback[phase1_pushback_length++] = c; - } + { + if (phase1_pushback_length == SIZEOF (phase1_pushback)) + abort (); + phase1_pushback[phase1_pushback_length++] = c; + } } } @@ -254,46 +254,46 @@ phase2_getc () { c = phase1_getc (); if (c == 'u') - { - unsigned int u_count = 1; - unsigned char buf[4]; - unsigned int n; - int i; - - for (;;) - { - c = phase1_getc (); - if (c != 'u') - break; - u_count++; - } - phase1_ungetc (c); - - n = 0; - for (i = 0; i < 4; i++) - { - c = phase1_getc (); - - if (c >= '0' && c <= '9') - n = (n << 4) + (c - '0'); - else if (c >= 'A' && c <= 'F') - n = (n << 4) + (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - n = (n << 4) + (c - 'a' + 10); - else - { - phase1_ungetc (c); - while (--i >= 0) - phase1_ungetc (buf[i]); - for (; u_count > 0; u_count--) - phase1_ungetc ('u'); - return '\\'; - } - - buf[i] = c; - } - return UNICODE (n); - } + { + unsigned int u_count = 1; + unsigned char buf[4]; + unsigned int n; + int i; + + for (;;) + { + c = phase1_getc (); + if (c != 'u') + break; + u_count++; + } + phase1_ungetc (c); + + n = 0; + for (i = 0; i < 4; i++) + { + c = phase1_getc (); + + if (c >= '0' && c <= '9') + n = (n << 4) + (c - '0'); + else if (c >= 'A' && c <= 'F') + n = (n << 4) + (c - 'A' + 10); + else if (c >= 'a' && c <= 'f') + n = (n << 4) + (c - 'a' + 10); + else + { + phase1_ungetc (c); + while (--i >= 0) + phase1_ungetc (buf[i]); + for (; u_count > 0; u_count--) + phase1_ungetc ('u'); + return '\\'; + } + + buf[i] = c; + } + return UNICODE (n); + } phase1_ungetc (c); return '\\'; } @@ -307,7 +307,7 @@ phase2_ungetc (int c) if (c != P2_EOF) { if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); + abort (); phase2_pushback[phase2_pushback_length++] = c; } } @@ -329,7 +329,7 @@ phase3_getc () { c = phase3_pushback[--phase3_pushback_length]; if (c == '\n') - ++line_number; + ++line_number; return c; } @@ -341,27 +341,27 @@ phase3_getc () int c1 = phase2_getc (); if (RED (c1) != '\n') - phase2_ungetc (c1); + phase2_ungetc (c1); /* Seen line terminator CR or CR/LF. */ if (c == '\r' || c1 == '\n') - { - ++line_number; - return '\n'; - } + { + ++line_number; + return '\n'; + } else - return UNICODE ('\n'); + return UNICODE ('\n'); } else if (RED (c) == '\n') { /* Seen line terminator LF. */ if (c == '\n') - { - ++line_number; - return '\n'; - } + { + ++line_number; + return '\n'; + } else - return UNICODE ('\n'); + return UNICODE ('\n'); } return c; @@ -374,9 +374,9 @@ phase3_ungetc (int c) if (c != P2_EOF) { if (c == '\n') - --line_number; + --line_number; if (phase3_pushback_length == SIZEOF (phase3_pushback)) - abort (); + abort (); phase3_pushback[phase3_pushback_length++] = c; } } @@ -438,7 +438,7 @@ string_buffer_append_unicode_grow (struct string_buffer *bp, size_t count) { size_t new_allocated = 2 * bp->utf8_allocated + 10; if (new_allocated < bp->utf8_buflen + count) - new_allocated = bp->utf8_buflen + count; + new_allocated = bp->utf8_buflen + count; bp->utf8_allocated = new_allocated; bp->utf8_buffer = xrealloc (bp->utf8_buffer, new_allocated); } @@ -475,24 +475,24 @@ string_buffer_append_lone_surrogate (struct string_buffer *bp, unsigned int uc) half surrogates. But a half surrogate is invalid in UTF-8: - RFC 3629 says - "The definition of UTF-8 prohibits encoding character - numbers between U+D800 and U+DFFF". + "The definition of UTF-8 prohibits encoding character + numbers between U+D800 and U+DFFF". - Unicode 4.0 chapter 3 - - section 3.9, p.77, says - "Because surrogate code points are not Unicode scalar - values, any UTF-8 byte sequence that would otherwise - map to code points D800..DFFF is ill-formed." - and in table 3-6, p. 78, does not mention D800..DFFF. + + section 3.9, p.77, says + "Because surrogate code points are not Unicode scalar + values, any UTF-8 byte sequence that would otherwise + map to code points D800..DFFF is ill-formed." + and in table 3-6, p. 78, does not mention D800..DFFF. - The unicode.org FAQ question "How do I convert an unpaired - UTF-16 surrogate to UTF-8?" has the answer - "By representing such an unpaired surrogate on its own - as a 3-byte sequence, the resulting UTF-8 data stream - would become ill-formed." + UTF-16 surrogate to UTF-8?" has the answer + "By representing such an unpaired surrogate on its own + as a 3-byte sequence, the resulting UTF-8 data stream + would become ill-formed." So use U+FFFD instead. */ error_with_progname = false; error (0, 0, _("%s:%d: warning: lone surrogate U+%04X"), - logical_file_name, line_number, uc); + logical_file_name, line_number, uc); error_with_progname = true; string_buffer_append_unicode (bp, 0xfffd); } @@ -521,7 +521,7 @@ string_buffer_flush_curr_buffer (struct string_buffer *bp, int lineno) /* Convert from the source encoding to UTF-8. */ curr = from_current_source_encoding (bp->curr_buffer, bp->lcontext, - logical_file_name, lineno); + logical_file_name, lineno); /* Append it to bp->utf8_buffer. */ count = strlen (curr); @@ -530,7 +530,7 @@ string_buffer_flush_curr_buffer (struct string_buffer *bp, int lineno) bp->utf8_buflen += count; if (curr != bp->curr_buffer) - free (curr); + free (curr); bp->curr_buflen = 0; } } @@ -547,32 +547,32 @@ string_buffer_append (struct string_buffer *bp, int c) string_buffer_flush_curr_buffer (bp, line_number); /* Test whether this character and the previous one form a Unicode - surrogate character pair. */ + surrogate character pair. */ if (bp->utf16_surr != 0 - && (c >= UNICODE (0xdc00) && c < UNICODE (0xe000))) - { - unsigned short utf16buf[2]; - ucs4_t uc; - - utf16buf[0] = bp->utf16_surr; - utf16buf[1] = UTF16_VALUE (c); - if (u16_mbtouc (&uc, utf16buf, 2) != 2) - abort (); - - string_buffer_append_unicode (bp, uc); - bp->utf16_surr = 0; - } + && (c >= UNICODE (0xdc00) && c < UNICODE (0xe000))) + { + unsigned short utf16buf[2]; + ucs4_t uc; + + utf16buf[0] = bp->utf16_surr; + utf16buf[1] = UTF16_VALUE (c); + if (u16_mbtouc (&uc, utf16buf, 2) != 2) + abort (); + + string_buffer_append_unicode (bp, uc); + bp->utf16_surr = 0; + } else - { - string_buffer_flush_utf16_surr (bp); - - if (c >= UNICODE (0xd800) && c < UNICODE (0xdc00)) - bp->utf16_surr = UTF16_VALUE (c); - else if (c >= UNICODE (0xdc00) && c < UNICODE (0xe000)) - string_buffer_append_lone_surrogate (bp, UTF16_VALUE (c)); - else - string_buffer_append_unicode (bp, UTF16_VALUE (c)); - } + { + string_buffer_flush_utf16_surr (bp); + + if (c >= UNICODE (0xd800) && c < UNICODE (0xdc00)) + bp->utf16_surr = UTF16_VALUE (c); + else if (c >= UNICODE (0xdc00) && c < UNICODE (0xe000)) + string_buffer_append_lone_surrogate (bp, UTF16_VALUE (c)); + else + string_buffer_append_unicode (bp, UTF16_VALUE (c)); + } } else { @@ -582,10 +582,10 @@ string_buffer_append (struct string_buffer *bp, int c) string_buffer_flush_utf16_surr (bp); /* When a newline is seen, convert the accumulated multibyte sequence. - This ensures a correct line number in the error message in case of - a conversion error. The "- 1" is to account for the newline. */ + This ensures a correct line number in the error message in case of + a conversion error. The "- 1" is to account for the newline. */ if (c == '\n') - string_buffer_flush_curr_buffer (bp, line_number - 1); + string_buffer_flush_curr_buffer (bp, line_number - 1); string_buffer_append_byte (bp, (unsigned char) c); } @@ -634,7 +634,7 @@ static inline bool comment_at_start () { return (comment_buffer.utf8_buflen == 0 && comment_buffer.utf16_surr == 0 - && comment_buffer.curr_buflen == 0); + && comment_buffer.curr_buflen == 0); } static inline void @@ -651,7 +651,7 @@ comment_line_end (size_t chars_to_remove) buflen -= chars_to_remove; while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; buffer[buflen] = '\0'; savable_comment_add (buffer); @@ -689,39 +689,39 @@ phase4_getc () comment_start (); last_was_star = false; for (;;) - { - c = phase3_getc (); - if (c == P2_EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(comment_at_start () && (RED (c) == ' ' || RED (c) == '\t'))) - comment_add (c); - switch (RED (c)) - { - case '\n': - comment_line_end (1); - comment_start (); - last_was_star = false; - continue; - - case '*': - last_was_star = true; - continue; - - case '/': - if (last_was_star) - { - comment_line_end (2); - break; - } - /* FALLTHROUGH */ - - default: - last_was_star = false; - continue; - } - break; - } + { + c = phase3_getc (); + if (c == P2_EOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(comment_at_start () && (RED (c) == ' ' || RED (c) == '\t'))) + comment_add (c); + switch (RED (c)) + { + case '\n': + comment_line_end (1); + comment_start (); + last_was_star = false; + continue; + + case '*': + last_was_star = true; + continue; + + case '/': + if (last_was_star) + { + comment_line_end (2); + break; + } + /* FALLTHROUGH */ + + default: + last_was_star = false; + continue; + } + break; + } last_comment_line = line_number; return ' '; @@ -730,14 +730,14 @@ phase4_getc () last_comment_line = line_number; comment_start (); for (;;) - { - c = phase3_getc (); - if (RED (c) == '\n' || c == P2_EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(comment_at_start () && (RED (c) == ' ' || RED (c) == '\t'))) - comment_add (c); - } + { + c = phase3_getc (); + if (RED (c) == '\n' || c == P2_EOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(comment_at_start () && (RED (c) == ' ' || RED (c) == '\t'))) + comment_add (c); + } phase3_ungetc (c); /* push back the newline, to decrement line_number */ comment_line_end (0); phase3_getc (); /* read the newline again */ @@ -758,17 +758,17 @@ phase4_ungetc (int c) enum token_type_ty { token_type_eof, - token_type_lparen, /* ( */ - token_type_rparen, /* ) */ - token_type_lbrace, /* { */ - token_type_rbrace, /* } */ - token_type_comma, /* , */ - token_type_dot, /* . */ - token_type_string_literal, /* "abc" */ - token_type_number, /* 1.23 */ - token_type_symbol, /* identifier, keyword, null */ - token_type_plus, /* + */ - token_type_other /* character literal, misc. operator */ + token_type_lparen, /* ( */ + token_type_rparen, /* ) */ + token_type_lbrace, /* { */ + token_type_rbrace, /* } */ + token_type_comma, /* , */ + token_type_dot, /* . */ + token_type_string_literal, /* "abc" */ + token_type_number, /* 1.23 */ + token_type_symbol, /* identifier, keyword, null */ + token_type_plus, /* + */ + token_type_other /* character literal, misc. operator */ }; typedef enum token_type_ty token_type_ty; @@ -776,8 +776,8 @@ typedef struct token_ty token_ty; struct token_ty { token_type_ty type; - char *string; /* for token_type_string_literal, token_type_symbol */ - refcounted_string_list_ty *comment; /* for token_type_string_literal */ + char *string; /* for token_type_string_literal, token_type_symbol */ + refcounted_string_list_ty *comment; /* for token_type_string_literal */ int line_number; }; @@ -824,26 +824,26 @@ do_getc_escaped () case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { - int n = RED (c) - '0'; - bool maybe3digits = (n < 4); - - c = phase3_getc (); - if (RED (c) >= '0' && RED (c) <= '7') - { - n = (n << 3) + (RED (c) - '0'); - if (maybe3digits) - { - c = phase3_getc (); - if (RED (c) >= '0' && RED (c) <= '7') - n = (n << 3) + (RED (c) - '0'); - else - phase3_ungetc (c); - } - } - else - phase3_ungetc (c); - - return UNICODE (n); + int n = RED (c) - '0'; + bool maybe3digits = (n < 4); + + c = phase3_getc (); + if (RED (c) >= '0' && RED (c) <= '7') + { + n = (n << 3) + (RED (c) - '0'); + if (maybe3digits) + { + c = phase3_getc (); + if (RED (c) >= '0' && RED (c) <= '7') + n = (n << 3) + (RED (c) - '0'); + else + phase3_ungetc (c); + } + } + else + phase3_ungetc (c); + + return UNICODE (n); } default: /* Invalid escape sequence. */ @@ -863,22 +863,22 @@ accumulate_escaped (struct string_buffer *literal, int delimiter) /* Use phase 3, because phase 4 elides comments. */ c = phase3_getc (); if (c == P2_EOF || RED (c) == delimiter) - break; + break; if (RED (c) == '\n') - { - phase3_ungetc (c); - error_with_progname = false; - if (delimiter == '\'') - error (0, 0, _("%s:%d: warning: unterminated character constant"), - logical_file_name, line_number); - else - error (0, 0, _("%s:%d: warning: unterminated string constant"), - logical_file_name, line_number); - error_with_progname = true; - break; - } + { + phase3_ungetc (c); + error_with_progname = false; + if (delimiter == '\'') + error (0, 0, _("%s:%d: warning: unterminated character constant"), + logical_file_name, line_number); + else + error (0, 0, _("%s:%d: warning: unterminated string constant"), + logical_file_name, line_number); + error_with_progname = true; + break; + } if (RED (c) == '\\') - c = do_getc_escaped (); + c = do_getc_escaped (); string_buffer_append (literal, c); } } @@ -907,186 +907,186 @@ phase5_get (token_ty *tp) c = phase4_getc (); if (c == P2_EOF) - { - tp->type = token_type_eof; - return; - } + { + tp->type = token_type_eof; + return; + } switch (RED (c)) - { - case '\n': - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - /* FALLTHROUGH */ - case ' ': - case '\t': - case '\f': - /* Ignore whitespace and comments. */ - continue; - } + { + case '\n': + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + /* FALLTHROUGH */ + case ' ': + case '\t': + case '\f': + /* Ignore whitespace and comments. */ + continue; + } last_non_comment_line = tp->line_number; switch (RED (c)) - { - case '(': - tp->type = token_type_lparen; - return; - - case ')': - tp->type = token_type_rparen; - return; - - case '{': - tp->type = token_type_lbrace; - return; - - case '}': - tp->type = token_type_rbrace; - return; - - case ',': - tp->type = token_type_comma; - return; - - case '.': - c = phase4_getc (); - if (!(RED (c) >= '0' && RED (c) <= '9')) - { - phase4_ungetc (c); - tp->type = token_type_dot; - return; - } - /* FALLTHROUGH */ - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - { - /* Don't need to verify the complicated syntax of integers and - floating-point numbers. We assume a valid Java input. - The simplified syntax that we recognize as number is: any - sequence of alphanumeric characters, additionally '+' and '-' - immediately after 'e' or 'E' except in hexadecimal numbers. */ - bool hexadecimal = false; - - for (;;) - { - c = phase4_getc (); - if (RED (c) >= '0' && RED (c) <= '9') - continue; - if ((RED (c) >= 'A' && RED (c) <= 'Z') - || (RED (c) >= 'a' && RED (c) <= 'z')) - { - if (RED (c) == 'X' || RED (c) == 'x') - hexadecimal = true; - if ((RED (c) == 'E' || RED (c) == 'e') && !hexadecimal) - { - c = phase4_getc (); - if (!(RED (c) == '+' || RED (c) == '-')) - phase4_ungetc (c); - } - continue; - } - if (RED (c) == '.') - continue; - break; - } - phase4_ungetc (c); - tp->type = token_type_number; - return; - } - - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': - case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': - case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': - case 'V': case 'W': case 'X': case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': - case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': - case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': - case 'v': case 'w': case 'x': case 'y': case 'z': - /* Although Java allows identifiers containing many Unicode - characters, we recognize only identifiers consisting of ASCII - characters. This avoids conversion hassles w.r.t. the --keyword - arguments, and shouldn't be a big problem in practice. */ - { - static char *buffer; - static int bufmax; - int bufpos = 0; - for (;;) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = RED (c); - c = phase4_getc (); - if (!((RED (c) >= 'A' && RED (c) <= 'Z') - || (RED (c) >= 'a' && RED (c) <= 'z') - || (RED (c) >= '0' && RED (c) <= '9') - || RED (c) == '_')) - break; - } - phase4_ungetc (c); - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = '\0'; - tp->string = xstrdup (buffer); - tp->type = token_type_symbol; - return; - } - - case '"': - /* String literal. */ - { - struct string_buffer literal; - - init_string_buffer (&literal, lc_string); - accumulate_escaped (&literal, '"'); - tp->string = xstrdup (string_buffer_result (&literal)); - free_string_buffer (&literal); - tp->comment = add_reference (savable_comment); - tp->type = token_type_string_literal; - return; - } - - case '\'': - /* Character literal. */ - { - struct string_buffer literal; - - init_string_buffer (&literal, lc_outside); - accumulate_escaped (&literal, '\''); - free_string_buffer (&literal); - tp->type = token_type_other; - return; - } - - case '+': - c = phase4_getc (); - if (RED (c) == '+') - /* Operator ++ */ - tp->type = token_type_other; - else if (RED (c) == '=') - /* Operator += */ - tp->type = token_type_other; - else - { - /* Operator + */ - phase4_ungetc (c); - tp->type = token_type_plus; - } - return; - - default: - /* Misc. operator. */ - tp->type = token_type_other; - return; - } + { + case '(': + tp->type = token_type_lparen; + return; + + case ')': + tp->type = token_type_rparen; + return; + + case '{': + tp->type = token_type_lbrace; + return; + + case '}': + tp->type = token_type_rbrace; + return; + + case ',': + tp->type = token_type_comma; + return; + + case '.': + c = phase4_getc (); + if (!(RED (c) >= '0' && RED (c) <= '9')) + { + phase4_ungetc (c); + tp->type = token_type_dot; + return; + } + /* FALLTHROUGH */ + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + { + /* Don't need to verify the complicated syntax of integers and + floating-point numbers. We assume a valid Java input. + The simplified syntax that we recognize as number is: any + sequence of alphanumeric characters, additionally '+' and '-' + immediately after 'e' or 'E' except in hexadecimal numbers. */ + bool hexadecimal = false; + + for (;;) + { + c = phase4_getc (); + if (RED (c) >= '0' && RED (c) <= '9') + continue; + if ((RED (c) >= 'A' && RED (c) <= 'Z') + || (RED (c) >= 'a' && RED (c) <= 'z')) + { + if (RED (c) == 'X' || RED (c) == 'x') + hexadecimal = true; + if ((RED (c) == 'E' || RED (c) == 'e') && !hexadecimal) + { + c = phase4_getc (); + if (!(RED (c) == '+' || RED (c) == '-')) + phase4_ungetc (c); + } + continue; + } + if (RED (c) == '.') + continue; + break; + } + phase4_ungetc (c); + tp->type = token_type_number; + return; + } + + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': + case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': + case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': + case 'V': case 'W': case 'X': case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': + case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': + case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': + case 'v': case 'w': case 'x': case 'y': case 'z': + /* Although Java allows identifiers containing many Unicode + characters, we recognize only identifiers consisting of ASCII + characters. This avoids conversion hassles w.r.t. the --keyword + arguments, and shouldn't be a big problem in practice. */ + { + static char *buffer; + static int bufmax; + int bufpos = 0; + for (;;) + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = RED (c); + c = phase4_getc (); + if (!((RED (c) >= 'A' && RED (c) <= 'Z') + || (RED (c) >= 'a' && RED (c) <= 'z') + || (RED (c) >= '0' && RED (c) <= '9') + || RED (c) == '_')) + break; + } + phase4_ungetc (c); + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = '\0'; + tp->string = xstrdup (buffer); + tp->type = token_type_symbol; + return; + } + + case '"': + /* String literal. */ + { + struct string_buffer literal; + + init_string_buffer (&literal, lc_string); + accumulate_escaped (&literal, '"'); + tp->string = xstrdup (string_buffer_result (&literal)); + free_string_buffer (&literal); + tp->comment = add_reference (savable_comment); + tp->type = token_type_string_literal; + return; + } + + case '\'': + /* Character literal. */ + { + struct string_buffer literal; + + init_string_buffer (&literal, lc_outside); + accumulate_escaped (&literal, '\''); + free_string_buffer (&literal); + tp->type = token_type_other; + return; + } + + case '+': + c = phase4_getc (); + if (RED (c) == '+') + /* Operator ++ */ + tp->type = token_type_other; + else if (RED (c) == '=') + /* Operator += */ + tp->type = token_type_other; + else + { + /* Operator + */ + phase4_ungetc (c); + tp->type = token_type_plus; + } + return; + + default: + /* Misc. operator. */ + tp->type = token_type_other; + return; + } } } @@ -1097,7 +1097,7 @@ phase5_unget (token_ty *tp) if (tp->type != token_type_eof) { if (phase5_pushback_length == SIZEOF (phase5_pushback)) - abort (); + abort (); phase5_pushback[phase5_pushback_length++] = *tp; } } @@ -1131,41 +1131,41 @@ phase6_get (token_ty *tp) size_t sum_len = strlen (sum); for (;;) - { - token_ty token2; - - phase5_get (&token2); - if (token2.type == token_type_plus) - { - token_ty token3; - - phase5_get (&token3); - if (token3.type == token_type_string_literal) - { - token_ty token_after; - - phase5_get (&token_after); - if (token_after.type != token_type_dot) - { - char *addend = token3.string; - size_t addend_len = strlen (addend); - - sum = (char *) xrealloc (sum, sum_len + addend_len + 1); - memcpy (sum + sum_len, addend, addend_len + 1); - sum_len += addend_len; - - phase5_unget (&token_after); - free_token (&token3); - free_token (&token2); - continue; - } - phase5_unget (&token_after); - } - phase5_unget (&token3); - } - phase5_unget (&token2); - break; - } + { + token_ty token2; + + phase5_get (&token2); + if (token2.type == token_type_plus) + { + token_ty token3; + + phase5_get (&token3); + if (token3.type == token_type_string_literal) + { + token_ty token_after; + + phase5_get (&token_after); + if (token_after.type != token_type_dot) + { + char *addend = token3.string; + size_t addend_len = strlen (addend); + + sum = (char *) xrealloc (sum, sum_len + addend_len + 1); + memcpy (sum + sum_len, addend, addend_len + 1); + sum_len += addend_len; + + phase5_unget (&token_after); + free_token (&token3); + free_token (&token2); + continue; + } + phase5_unget (&token_after); + } + phase5_unget (&token3); + } + phase5_unget (&token2); + break; + } tp->string = sum; } phase6_last = tp->type; @@ -1178,7 +1178,7 @@ phase6_unget (token_ty *tp) if (tp->type != token_type_eof) { if (phase6_pushback_length == SIZEOF (phase6_pushback)) - abort (); + abort (); phase6_pushback[phase6_pushback_length++] = *tp; } } @@ -1226,9 +1226,9 @@ static flag_context_list_table_ty *flag_context_list_table; Return true upon eof, false upon closing parenthesis or brace. */ static bool extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - struct arglist_parser *argparser) + flag_context_ty outer_context, + flag_context_list_iterator_ty context_iter, + struct arglist_parser *argparser) { /* Current argument number. */ int arg = 1; @@ -1242,7 +1242,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, /* Current context. */ flag_context_ty inner_context = inherited_context (outer_context, - flag_context_list_iterator_advance (&context_iter)); + flag_context_list_iterator_advance (&context_iter)); /* Start state is 0. */ state = 0; @@ -1253,219 +1253,219 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, x_java_lex (&token); switch (token.type) - { - case token_type_symbol: - { - /* Combine symbol1 . ... . symbolN to a single strings, so that - we can recognize static function calls like - GettextResource.gettext. The information present for - symbolI.....symbolN has precedence over the information for - symbolJ.....symbolN with J > I. */ - char *sum = token.string; - size_t sum_len = strlen (sum); - const char *dottedname; - flag_context_list_ty *context_list; - - for (;;) - { - token_ty token2; - - x_java_lex (&token2); - if (token2.type == token_type_dot) - { - token_ty token3; - - x_java_lex (&token3); - if (token3.type == token_type_symbol) - { - char *addend = token3.string; - size_t addend_len = strlen (addend); - - sum = - (char *) xrealloc (sum, sum_len + 1 + addend_len + 1); - sum[sum_len] = '.'; - memcpy (sum + sum_len + 1, addend, addend_len + 1); - sum_len += 1 + addend_len; - - free_token (&token3); - free_token (&token2); - continue; - } - x_java_unlex (&token3); - } - x_java_unlex (&token2); - break; - } - - for (dottedname = sum;;) - { - void *keyword_value; - - if (hash_find_entry (&keywords, dottedname, strlen (dottedname), - &keyword_value) - == 0) - { - next_shapes = (const struct callshapes *) keyword_value; - state = 1; - break; - } - - dottedname = strchr (dottedname, '.'); - if (dottedname == NULL) - { - state = 0; - break; - } - dottedname++; - } - - for (dottedname = sum;;) - { - context_list = - flag_context_list_table_lookup ( - flag_context_list_table, - dottedname, strlen (dottedname)); - if (context_list != NULL) - break; - - dottedname = strchr (dottedname, '.'); - if (dottedname == NULL) - break; - dottedname++; - } - next_context_iter = flag_context_list_iterator (context_list); - - free (sum); - continue; - } - - case token_type_lparen: - if (extract_parenthesized (mlp, token_type_rparen, - inner_context, next_context_iter, - arglist_parser_alloc (mlp, - state ? next_shapes : NULL))) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rparen: - if (terminator == token_type_rparen) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return false; - } - if (terminator == token_type_rbrace) - { - error_with_progname = false; - error (0, 0, - _("%s:%d: warning: ')' found where '}' was expected"), - logical_file_name, token.line_number); - error_with_progname = true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_lbrace: - if (extract_parenthesized (mlp, token_type_rbrace, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rbrace: - if (terminator == token_type_rbrace) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return false; - } - if (terminator == token_type_rparen) - { - error_with_progname = false; - error (0, 0, - _("%s:%d: warning: '}' found where ')' was expected"), - logical_file_name, token.line_number); - error_with_progname = true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_comma: - arg++; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_context_iter = passthrough_context_list_iterator; - state = 0; - continue; - - case token_type_string_literal: - { - lex_pos_ty pos; - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - - xgettext_current_source_encoding = po_charset_utf8; - if (extract_all) - remember_a_message (mlp, NULL, token.string, inner_context, - &pos, NULL, token.comment); - else - arglist_parser_remember (argparser, arg, token.string, - inner_context, - pos.file_name, pos.line_number, - token.comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; - } - drop_reference (token.comment); - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_eof: - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return true; - - case token_type_dot: - case token_type_number: - case token_type_plus: - case token_type_other: - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - default: - abort (); - } + { + case token_type_symbol: + { + /* Combine symbol1 . ... . symbolN to a single strings, so that + we can recognize static function calls like + GettextResource.gettext. The information present for + symbolI.....symbolN has precedence over the information for + symbolJ.....symbolN with J > I. */ + char *sum = token.string; + size_t sum_len = strlen (sum); + const char *dottedname; + flag_context_list_ty *context_list; + + for (;;) + { + token_ty token2; + + x_java_lex (&token2); + if (token2.type == token_type_dot) + { + token_ty token3; + + x_java_lex (&token3); + if (token3.type == token_type_symbol) + { + char *addend = token3.string; + size_t addend_len = strlen (addend); + + sum = + (char *) xrealloc (sum, sum_len + 1 + addend_len + 1); + sum[sum_len] = '.'; + memcpy (sum + sum_len + 1, addend, addend_len + 1); + sum_len += 1 + addend_len; + + free_token (&token3); + free_token (&token2); + continue; + } + x_java_unlex (&token3); + } + x_java_unlex (&token2); + break; + } + + for (dottedname = sum;;) + { + void *keyword_value; + + if (hash_find_entry (&keywords, dottedname, strlen (dottedname), + &keyword_value) + == 0) + { + next_shapes = (const struct callshapes *) keyword_value; + state = 1; + break; + } + + dottedname = strchr (dottedname, '.'); + if (dottedname == NULL) + { + state = 0; + break; + } + dottedname++; + } + + for (dottedname = sum;;) + { + context_list = + flag_context_list_table_lookup ( + flag_context_list_table, + dottedname, strlen (dottedname)); + if (context_list != NULL) + break; + + dottedname = strchr (dottedname, '.'); + if (dottedname == NULL) + break; + dottedname++; + } + next_context_iter = flag_context_list_iterator (context_list); + + free (sum); + continue; + } + + case token_type_lparen: + if (extract_parenthesized (mlp, token_type_rparen, + inner_context, next_context_iter, + arglist_parser_alloc (mlp, + state ? next_shapes : NULL))) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_rparen: + if (terminator == token_type_rparen) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return false; + } + if (terminator == token_type_rbrace) + { + error_with_progname = false; + error (0, 0, + _("%s:%d: warning: ')' found where '}' was expected"), + logical_file_name, token.line_number); + error_with_progname = true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_lbrace: + if (extract_parenthesized (mlp, token_type_rbrace, + null_context, null_context_list_iterator, + arglist_parser_alloc (mlp, NULL))) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_rbrace: + if (terminator == token_type_rbrace) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return false; + } + if (terminator == token_type_rparen) + { + error_with_progname = false; + error (0, 0, + _("%s:%d: warning: '}' found where ')' was expected"), + logical_file_name, token.line_number); + error_with_progname = true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_comma: + arg++; + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + next_context_iter = passthrough_context_list_iterator; + state = 0; + continue; + + case token_type_string_literal: + { + lex_pos_ty pos; + pos.file_name = logical_file_name; + pos.line_number = token.line_number; + + xgettext_current_source_encoding = po_charset_utf8; + if (extract_all) + remember_a_message (mlp, NULL, token.string, inner_context, + &pos, NULL, token.comment); + else + arglist_parser_remember (argparser, arg, token.string, + inner_context, + pos.file_name, pos.line_number, + token.comment); + xgettext_current_source_encoding = xgettext_global_source_encoding; + } + drop_reference (token.comment); + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_eof: + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return true; + + case token_type_dot: + case token_type_number: + case token_type_plus: + case token_type_other: + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + default: + abort (); + } } } void extract_java (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { message_list_ty *mlp = mdlp->item[0]->messages; @@ -1486,8 +1486,8 @@ extract_java (FILE *f, /* Eat tokens until eof is seen. When extract_parenthesized returns due to an unbalanced closing parenthesis, just restart it. */ while (!extract_parenthesized (mlp, token_type_eof, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) + null_context, null_context_list_iterator, + arglist_parser_alloc (mlp, NULL))) ; fp = NULL; diff --git a/gettext-tools/src/x-java.h b/gettext-tools/src/x-java.h index 3fc08d4d0..31436c5e3 100644 --- a/gettext-tools/src/x-java.h +++ b/gettext-tools/src/x-java.h @@ -28,16 +28,16 @@ extern "C" { #define EXTENSIONS_JAVA \ - { "java", "Java" }, \ + { "java", "Java" }, \ #define SCANNERS_JAVA \ - { "Java", extract_java, \ - &flag_table_java, &formatstring_java, NULL }, \ + { "Java", extract_java, \ + &flag_table_java, &formatstring_java, NULL }, \ extern void extract_java (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); extern void x_java_keyword (const char *keyword); extern void x_java_extract_all (void); diff --git a/gettext-tools/src/x-librep.c b/gettext-tools/src/x-librep.c index 87b17e4cf..c91d22a0f 100644 --- a/gettext-tools/src/x-librep.c +++ b/gettext-tools/src/x-librep.c @@ -88,15 +88,15 @@ x_librep_keyword (const char *name) const char *colon; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid Lisp - symbol. */ + symbol. */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); + insert_keyword_callshape (&keywords, name, end - name, &shape); } } @@ -108,7 +108,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_librep_keyword ("_"); default_keywords = false; } @@ -144,7 +144,7 @@ do_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("\ + error (EXIT_FAILURE, errno, _("\ error while reading \"%s\""), real_file_name); } else if (c == '\n') @@ -169,9 +169,9 @@ do_ungetc (int c) /* A token consists of a sequence of characters. */ struct token { - int allocated; /* number of allocated 'token_char's */ - int charcount; /* number of used 'token_char's */ - char *chars; /* the token's constituents */ + int allocated; /* number of allocated 'token_char's */ + int charcount; /* number of used 'token_char's */ + char *chars; /* the token's constituents */ }; /* Initialize a 'struct token'. */ @@ -227,173 +227,173 @@ read_token (struct token *tp, const int *first) for (;; c = do_getc ()) { switch (c) - { - case EOF: - goto done; - - case ' ': case '\t': case '\n': case '\f': case '\r': - case '(': case ')': case '[': case ']': - case '\'': case '"': case ';': case ',': case '`': - goto done; - - case '\\': - radix = 0; - c = do_getc (); - if (c == EOF) - /* Invalid, but be tolerant. */ - break; - grow_token (tp); - tp->chars[tp->charcount++] = c; - break; - - case '|': - radix = 0; - for (;;) - { - c = do_getc (); - if (c == EOF || c == '|') - break; - grow_token (tp); - tp->chars[tp->charcount++] = c; - } - break; - - default: - if (radix != 0) - { - if (expecting_prefix) - { - switch (c) - { - case 'B': case 'b': - radix = 2; - break; - case 'O': case 'o': - radix = 8; - break; - case 'D': case 'd': - radix = 10; - break; - case 'X': case 'x': - radix = 16; - break; - case 'E': case 'e': - case 'I': case 'i': - break; - default: - radix = 0; - break; - } - expecting_prefix = false; - nfirst = tp->charcount + 1; - } - else if (tp->charcount == nfirst - && (c == '+' || c == '-' || c == '#')) - { - if (c == '#') - { - if (had_sign) - radix = 0; - else - expecting_prefix = true; - } - else - had_sign = true; - nfirst = tp->charcount + 1; - } - else - { - switch (radix) - { - case -1: - if (c == '.') - { - radix = 10; - exact = false; - } - else if (!(c >= '0' && c <= '9')) - radix = 0; - else if (c == '0') - radix = 1; - else - radix = 10; - break; - - case 1: - switch (c) - { - case 'X': case 'x': - radix = 16; - nfirst = tp->charcount + 1; - break; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': - radix = 8; - nfirst = tp->charcount; - break; - case '.': case 'E': case 'e': - radix = 10; - exact = false; - break; - case '/': - radix = 10; - rational = true; - break; - default: - radix = 0; - break; - } - break; - - default: - switch (c) - { - case '.': - if (exact && radix == 10 && !rational) - exact = false; - else - radix = 0; - break; - case '/': - if (exact && !rational) - rational = true; - else - radix = 0; - break; - case 'E': case 'e': - if (radix == 10) - { - if (!rational && !exponent) - { - exponent = true; - exact = false; - } - else - radix = 0; - break; - } - /*FALLTHROUGH*/ - default: - if (exponent && (c == '+' || c == '-')) - break; - if ((radix <= 10 - && !(c >= '0' && c <= '0' + radix - 1)) - || (radix == 16 && !c_isxdigit (c))) - radix = 0; - break; - } - break; - } - } - } - else - { - if (c == '#') - goto done; - } - grow_token (tp); - tp->chars[tp->charcount++] = c; - } + { + case EOF: + goto done; + + case ' ': case '\t': case '\n': case '\f': case '\r': + case '(': case ')': case '[': case ']': + case '\'': case '"': case ';': case ',': case '`': + goto done; + + case '\\': + radix = 0; + c = do_getc (); + if (c == EOF) + /* Invalid, but be tolerant. */ + break; + grow_token (tp); + tp->chars[tp->charcount++] = c; + break; + + case '|': + radix = 0; + for (;;) + { + c = do_getc (); + if (c == EOF || c == '|') + break; + grow_token (tp); + tp->chars[tp->charcount++] = c; + } + break; + + default: + if (radix != 0) + { + if (expecting_prefix) + { + switch (c) + { + case 'B': case 'b': + radix = 2; + break; + case 'O': case 'o': + radix = 8; + break; + case 'D': case 'd': + radix = 10; + break; + case 'X': case 'x': + radix = 16; + break; + case 'E': case 'e': + case 'I': case 'i': + break; + default: + radix = 0; + break; + } + expecting_prefix = false; + nfirst = tp->charcount + 1; + } + else if (tp->charcount == nfirst + && (c == '+' || c == '-' || c == '#')) + { + if (c == '#') + { + if (had_sign) + radix = 0; + else + expecting_prefix = true; + } + else + had_sign = true; + nfirst = tp->charcount + 1; + } + else + { + switch (radix) + { + case -1: + if (c == '.') + { + radix = 10; + exact = false; + } + else if (!(c >= '0' && c <= '9')) + radix = 0; + else if (c == '0') + radix = 1; + else + radix = 10; + break; + + case 1: + switch (c) + { + case 'X': case 'x': + radix = 16; + nfirst = tp->charcount + 1; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + radix = 8; + nfirst = tp->charcount; + break; + case '.': case 'E': case 'e': + radix = 10; + exact = false; + break; + case '/': + radix = 10; + rational = true; + break; + default: + radix = 0; + break; + } + break; + + default: + switch (c) + { + case '.': + if (exact && radix == 10 && !rational) + exact = false; + else + radix = 0; + break; + case '/': + if (exact && !rational) + rational = true; + else + radix = 0; + break; + case 'E': case 'e': + if (radix == 10) + { + if (!rational && !exponent) + { + exponent = true; + exact = false; + } + else + radix = 0; + break; + } + /*FALLTHROUGH*/ + default: + if (exponent && (c == '+' || c == '-')) + break; + if ((radix <= 10 + && !(c >= '0' && c <= '0' + radix - 1)) + || (radix == 16 && !c_isxdigit (c))) + radix = 0; + break; + } + break; + } + } + } + else + { + if (c == '#') + goto done; + } + grow_token (tp); + tp->chars[tp->charcount++] = c; + } } done: if (c != EOF) @@ -434,7 +434,7 @@ comment_line_end (size_t chars_to_remove) { buflen -= chars_to_remove; while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { @@ -465,19 +465,19 @@ static message_list_ty *mlp; Other objects need not to be represented precisely. */ enum object_type { - t_symbol, /* symbol */ - t_string, /* string */ - t_other, /* other kind of real object */ - t_dot, /* '.' pseudo object */ - t_close, /* ')' or ']' pseudo object */ - t_eof /* EOF marker */ + t_symbol, /* symbol */ + t_string, /* string */ + t_other, /* other kind of real object */ + t_dot, /* '.' pseudo object */ + t_close, /* ')' or ']' pseudo object */ + t_eof /* EOF marker */ }; struct object { enum object_type type; - struct token *token; /* for t_symbol and t_string */ - int line_number_at_start; /* for t_string */ + struct token *token; /* for t_symbol and t_string */ + int line_number_at_start; /* for t_string */ }; /* Free the memory pointed to by a 'struct object'. */ @@ -531,55 +531,55 @@ do_getc_escaped (int c) case '^': c = do_getc (); if (c == EOF) - return EOF; + return EOF; return c & 0x1f; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { - int n = c - '0'; - - c = do_getc (); - if (c != EOF) - { - if (c >= '0' && c <= '7') - { - n = (n << 3) + (c - '0'); - c = do_getc (); - if (c != EOF) - { - if (c >= '0' && c <= '7') - n = (n << 3) + (c - '0'); - else - do_ungetc (c); - } - } - else - do_ungetc (c); - } - return (unsigned char) n; + int n = c - '0'; + + c = do_getc (); + if (c != EOF) + { + if (c >= '0' && c <= '7') + { + n = (n << 3) + (c - '0'); + c = do_getc (); + if (c != EOF) + { + if (c >= '0' && c <= '7') + n = (n << 3) + (c - '0'); + else + do_ungetc (c); + } + } + else + do_ungetc (c); + } + return (unsigned char) n; } case 'x': { - int n = 0; - - for (;;) - { - c = do_getc (); - if (c == EOF) - break; - else if (c >= '0' && c <= '9') - n = (n << 4) + (c - '0'); - else if (c >= 'A' && c <= 'F') - n = (n << 4) + (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - n = (n << 4) + (c - 'a' + 10); - else - { - do_ungetc (c); - break; - } - } - return (unsigned char) n; + int n = 0; + + for (;;) + { + c = do_getc (); + if (c == EOF) + break; + else if (c >= '0' && c <= '9') + n = (n << 4) + (c - '0'); + else if (c >= 'A' && c <= 'F') + n = (n << 4) + (c - 'A' + 10); + else if (c >= 'a' && c <= 'f') + n = (n << 4) + (c - 'a' + 10); + else + { + do_ungetc (c); + break; + } + } + return (unsigned char) n; } default: return c; @@ -597,504 +597,504 @@ read_object (struct object *op, flag_context_ty outer_context) c = do_getc (); switch (c) - { - case EOF: - op->type = t_eof; - return; - - case '\n': - /* Comments assumed to be grouped with a message must immediately - precede it, with no non-whitespace token on a line between - both. */ - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - continue; - - case ' ': case '\t': case '\f': case '\r': - continue; - - case '(': - { - int arg = 0; /* Current argument number. */ - flag_context_list_iterator_ty context_iter; - const struct callshapes *shapes = NULL; - struct arglist_parser *argparser = NULL; - - for (;; arg++) - { - struct object inner; - flag_context_ty inner_context; - - if (arg == 0) - inner_context = null_context; - else - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - - read_object (&inner, inner_context); - - /* Recognize end of list. */ - if (inner.type == t_close) - { - op->type = t_other; - /* Don't bother converting "()" to "NIL". */ - last_non_comment_line = line_number; - if (argparser != NULL) - arglist_parser_done (argparser, arg); - return; - } - - /* Dots are not allowed in every position. - But be tolerant. */ - - /* EOF inside list is illegal. But be tolerant. */ - if (inner.type == t_eof) - break; - - if (arg == 0) - { - /* This is the function position. */ - if (inner.type == t_symbol) - { - char *symbol_name = string_of_object (&inner); - void *keyword_value; - - if (hash_find_entry (&keywords, - symbol_name, strlen (symbol_name), - &keyword_value) - == 0) - shapes = (const struct callshapes *) keyword_value; - - argparser = arglist_parser_alloc (mlp, shapes); - - context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - symbol_name, strlen (symbol_name))); - - free (symbol_name); - } - else - context_iter = null_context_list_iterator; - } - else - { - /* These are the argument positions. */ - if (argparser != NULL && inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_object (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); - } - - free_object (&inner); - } - - if (argparser != NULL) - arglist_parser_done (argparser, arg); - } - op->type = t_other; - last_non_comment_line = line_number; - return; - - case '[': - { - for (;;) - { - struct object inner; - - read_object (&inner, null_context); - - /* Recognize end of vector. */ - if (inner.type == t_close) - { - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - /* Dots are not allowed. But be tolerant. */ - - /* EOF inside vector is illegal. But be tolerant. */ - if (inner.type == t_eof) - break; - - free_object (&inner); - } - } - op->type = t_other; - last_non_comment_line = line_number; - return; - - case ')': case ']': - /* Tell the caller about the end of list or vector. - Unmatched closing parenthesis is illegal. But be tolerant. */ - op->type = t_close; - last_non_comment_line = line_number; - return; - - case ',': - { - int c = do_getc (); - /* The ,@ handling inside lists is wrong anyway, because - ,@form expands to an unknown number of elements. */ - if (c != EOF && c != '@') - do_ungetc (c); - } - /*FALLTHROUGH*/ - case '\'': - case '`': - { - struct object inner; - - read_object (&inner, null_context); - - /* Dots and EOF are not allowed here. But be tolerant. */ - - free_object (&inner); - - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case ';': - { - bool all_semicolons = true; - - last_comment_line = line_number; - comment_start (); - for (;;) - { - int c = do_getc (); - if (c == EOF || c == '\n' || c == '\f' || c == '\r') - break; - if (c != ';') - all_semicolons = false; - if (!all_semicolons) - { - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - } - } - comment_line_end (0); - continue; - } - - case '"': - { - op->token = XMALLOC (struct token); - init_token (op->token); - op->line_number_at_start = line_number; - for (;;) - { - int c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - break; - if (c == '"') - break; - if (c == '\\') - { - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - break; - if (c == '\n') - /* Ignore escaped newline. */ - ; - else - { - c = do_getc_escaped (c); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - break; - grow_token (op->token); - op->token->chars[op->token->charcount++] = c; - } - } - else - { - grow_token (op->token); - op->token->chars[op->token->charcount++] = c; - } - } - op->type = t_string; - - if (extract_all) - { - lex_pos_ty pos; - - pos.file_name = logical_file_name; - pos.line_number = op->line_number_at_start; - remember_a_message (mlp, NULL, string_of_object (op), - null_context, &pos, NULL, savable_comment); - } - last_non_comment_line = line_number; - return; - } - - case '?': - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - else if (c == '\\') - { - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - else - { - c = do_getc_escaped (c); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - } - } - op->type = t_other; - last_non_comment_line = line_number; - return; - - case '#': - /* Dispatch macro handling. */ - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - { - op->type = t_other; - return; - } - - switch (c) - { - case '!': - if (ftell (fp) == 2) - /* Skip comment until !# */ - { - c = do_getc (); - for (;;) - { - if (c == EOF) - break; - if (c == '!') - { - c = do_getc (); - if (c == EOF || c == '#') - break; - } - else - c = do_getc (); - } - if (c == EOF) - { - /* EOF not allowed here. But be tolerant. */ - op->type = t_eof; - return; - } - continue; - } - /*FALLTHROUGH*/ - case '\'': - case ':': - { - struct object inner; - read_object (&inner, null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '[': - case '(': - { - struct object inner; - do_ungetc (c); - read_object (&inner, null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '|': - { - int depth = 0; - - comment_start (); - c = do_getc (); - for (;;) - { - if (c == EOF) - break; - if (c == '|') - { - c = do_getc (); - if (c == EOF) - break; - if (c == '#') - { - if (depth == 0) - { - comment_line_end (0); - break; - } - depth--; - comment_add ('|'); - comment_add ('#'); - c = do_getc (); - } - else - comment_add ('|'); - } - else if (c == '#') - { - c = do_getc (); - if (c == EOF) - break; - comment_add ('#'); - if (c == '|') - { - depth++; - comment_add ('|'); - c = do_getc (); - } - } - else - { - /* We skip all leading white space. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - if (c == '\n') - { - comment_line_end (1); - comment_start (); - } - c = do_getc (); - } - } - if (c == EOF) - { - /* EOF not allowed here. But be tolerant. */ - op->type = t_eof; - return; - } - last_comment_line = line_number; - continue; - } - - case '\\': - { - struct token token; - int first = '\\'; - read_token (&token, &first); - free_token (&token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case 'T': case 't': - case 'F': case 'f': - op->type = t_other; - last_non_comment_line = line_number; - return; - - case 'B': case 'b': - case 'O': case 'o': - case 'D': case 'd': - case 'X': case 'x': - case 'E': case 'e': - case 'I': case 'i': - { - struct token token; - do_ungetc (c); - c = '#'; - read_token (&token, &c); - free_token (&token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - default: - /* Invalid input. Be tolerant, no error message. */ - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - /*NOTREACHED*/ - abort (); - - default: - /* Read a token. */ - { - bool symbol; - - op->token = XMALLOC (struct token); - symbol = read_token (op->token, &c); - if (op->token->charcount == 1 && op->token->chars[0] == '.') - { - free_token (op->token); - free (op->token); - op->type = t_dot; - last_non_comment_line = line_number; - return; - } - if (!symbol) - { - free_token (op->token); - free (op->token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - /* Distinguish between "foo" and "foo#bar". */ - c = do_getc (); - if (c == '#') - { - struct token second_token; - - free_token (op->token); - free (op->token); - read_token (&second_token, NULL); - free_token (&second_token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - else - { - if (c != EOF) - do_ungetc (c); - op->type = t_symbol; - last_non_comment_line = line_number; - return; - } - } - } + { + case EOF: + op->type = t_eof; + return; + + case '\n': + /* Comments assumed to be grouped with a message must immediately + precede it, with no non-whitespace token on a line between + both. */ + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + continue; + + case ' ': case '\t': case '\f': case '\r': + continue; + + case '(': + { + int arg = 0; /* Current argument number. */ + flag_context_list_iterator_ty context_iter; + const struct callshapes *shapes = NULL; + struct arglist_parser *argparser = NULL; + + for (;; arg++) + { + struct object inner; + flag_context_ty inner_context; + + if (arg == 0) + inner_context = null_context; + else + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + + read_object (&inner, inner_context); + + /* Recognize end of list. */ + if (inner.type == t_close) + { + op->type = t_other; + /* Don't bother converting "()" to "NIL". */ + last_non_comment_line = line_number; + if (argparser != NULL) + arglist_parser_done (argparser, arg); + return; + } + + /* Dots are not allowed in every position. + But be tolerant. */ + + /* EOF inside list is illegal. But be tolerant. */ + if (inner.type == t_eof) + break; + + if (arg == 0) + { + /* This is the function position. */ + if (inner.type == t_symbol) + { + char *symbol_name = string_of_object (&inner); + void *keyword_value; + + if (hash_find_entry (&keywords, + symbol_name, strlen (symbol_name), + &keyword_value) + == 0) + shapes = (const struct callshapes *) keyword_value; + + argparser = arglist_parser_alloc (mlp, shapes); + + context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + symbol_name, strlen (symbol_name))); + + free (symbol_name); + } + else + context_iter = null_context_list_iterator; + } + else + { + /* These are the argument positions. */ + if (argparser != NULL && inner.type == t_string) + arglist_parser_remember (argparser, arg, + string_of_object (&inner), + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + } + + free_object (&inner); + } + + if (argparser != NULL) + arglist_parser_done (argparser, arg); + } + op->type = t_other; + last_non_comment_line = line_number; + return; + + case '[': + { + for (;;) + { + struct object inner; + + read_object (&inner, null_context); + + /* Recognize end of vector. */ + if (inner.type == t_close) + { + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + /* Dots are not allowed. But be tolerant. */ + + /* EOF inside vector is illegal. But be tolerant. */ + if (inner.type == t_eof) + break; + + free_object (&inner); + } + } + op->type = t_other; + last_non_comment_line = line_number; + return; + + case ')': case ']': + /* Tell the caller about the end of list or vector. + Unmatched closing parenthesis is illegal. But be tolerant. */ + op->type = t_close; + last_non_comment_line = line_number; + return; + + case ',': + { + int c = do_getc (); + /* The ,@ handling inside lists is wrong anyway, because + ,@form expands to an unknown number of elements. */ + if (c != EOF && c != '@') + do_ungetc (c); + } + /*FALLTHROUGH*/ + case '\'': + case '`': + { + struct object inner; + + read_object (&inner, null_context); + + /* Dots and EOF are not allowed here. But be tolerant. */ + + free_object (&inner); + + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case ';': + { + bool all_semicolons = true; + + last_comment_line = line_number; + comment_start (); + for (;;) + { + int c = do_getc (); + if (c == EOF || c == '\n' || c == '\f' || c == '\r') + break; + if (c != ';') + all_semicolons = false; + if (!all_semicolons) + { + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + } + } + comment_line_end (0); + continue; + } + + case '"': + { + op->token = XMALLOC (struct token); + init_token (op->token); + op->line_number_at_start = line_number; + for (;;) + { + int c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + break; + if (c == '"') + break; + if (c == '\\') + { + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + break; + if (c == '\n') + /* Ignore escaped newline. */ + ; + else + { + c = do_getc_escaped (c); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + break; + grow_token (op->token); + op->token->chars[op->token->charcount++] = c; + } + } + else + { + grow_token (op->token); + op->token->chars[op->token->charcount++] = c; + } + } + op->type = t_string; + + if (extract_all) + { + lex_pos_ty pos; + + pos.file_name = logical_file_name; + pos.line_number = op->line_number_at_start; + remember_a_message (mlp, NULL, string_of_object (op), + null_context, &pos, NULL, savable_comment); + } + last_non_comment_line = line_number; + return; + } + + case '?': + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + else if (c == '\\') + { + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + else + { + c = do_getc_escaped (c); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + } + } + op->type = t_other; + last_non_comment_line = line_number; + return; + + case '#': + /* Dispatch macro handling. */ + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + { + op->type = t_other; + return; + } + + switch (c) + { + case '!': + if (ftell (fp) == 2) + /* Skip comment until !# */ + { + c = do_getc (); + for (;;) + { + if (c == EOF) + break; + if (c == '!') + { + c = do_getc (); + if (c == EOF || c == '#') + break; + } + else + c = do_getc (); + } + if (c == EOF) + { + /* EOF not allowed here. But be tolerant. */ + op->type = t_eof; + return; + } + continue; + } + /*FALLTHROUGH*/ + case '\'': + case ':': + { + struct object inner; + read_object (&inner, null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '[': + case '(': + { + struct object inner; + do_ungetc (c); + read_object (&inner, null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '|': + { + int depth = 0; + + comment_start (); + c = do_getc (); + for (;;) + { + if (c == EOF) + break; + if (c == '|') + { + c = do_getc (); + if (c == EOF) + break; + if (c == '#') + { + if (depth == 0) + { + comment_line_end (0); + break; + } + depth--; + comment_add ('|'); + comment_add ('#'); + c = do_getc (); + } + else + comment_add ('|'); + } + else if (c == '#') + { + c = do_getc (); + if (c == EOF) + break; + comment_add ('#'); + if (c == '|') + { + depth++; + comment_add ('|'); + c = do_getc (); + } + } + else + { + /* We skip all leading white space. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + if (c == '\n') + { + comment_line_end (1); + comment_start (); + } + c = do_getc (); + } + } + if (c == EOF) + { + /* EOF not allowed here. But be tolerant. */ + op->type = t_eof; + return; + } + last_comment_line = line_number; + continue; + } + + case '\\': + { + struct token token; + int first = '\\'; + read_token (&token, &first); + free_token (&token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case 'T': case 't': + case 'F': case 'f': + op->type = t_other; + last_non_comment_line = line_number; + return; + + case 'B': case 'b': + case 'O': case 'o': + case 'D': case 'd': + case 'X': case 'x': + case 'E': case 'e': + case 'I': case 'i': + { + struct token token; + do_ungetc (c); + c = '#'; + read_token (&token, &c); + free_token (&token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + default: + /* Invalid input. Be tolerant, no error message. */ + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + /*NOTREACHED*/ + abort (); + + default: + /* Read a token. */ + { + bool symbol; + + op->token = XMALLOC (struct token); + symbol = read_token (op->token, &c); + if (op->token->charcount == 1 && op->token->chars[0] == '.') + { + free_token (op->token); + free (op->token); + op->type = t_dot; + last_non_comment_line = line_number; + return; + } + if (!symbol) + { + free_token (op->token); + free (op->token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + /* Distinguish between "foo" and "foo#bar". */ + c = do_getc (); + if (c == '#') + { + struct token second_token; + + free_token (op->token); + free (op->token); + read_token (&second_token, NULL); + free_token (&second_token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + else + { + if (c != EOF) + do_ungetc (c); + op->type = t_symbol; + last_non_comment_line = line_number; + return; + } + } + } } } void extract_librep (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { mlp = mdlp->item[0]->messages; @@ -1119,7 +1119,7 @@ extract_librep (FILE *f, read_object (&toplevel_object, null_context); if (toplevel_object.type == t_eof) - break; + break; free_object (&toplevel_object); } diff --git a/gettext-tools/src/x-librep.h b/gettext-tools/src/x-librep.h index 4cd9c1198..8937d5177 100644 --- a/gettext-tools/src/x-librep.h +++ b/gettext-tools/src/x-librep.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_LIBREP \ - { "jl", "librep" }, \ + { "jl", "librep" }, \ #define SCANNERS_LIBREP \ - { "librep", extract_librep, \ - &flag_table_librep, &formatstring_librep, NULL }, \ + { "librep", extract_librep, \ + &flag_table_librep, &formatstring_librep, NULL }, \ /* Scan a librep file and add its translatable strings to mdlp. */ extern void extract_librep (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); /* Handling of options specific to this language. */ diff --git a/gettext-tools/src/x-lisp.c b/gettext-tools/src/x-lisp.c index d56722b51..20d88a253 100644 --- a/gettext-tools/src/x-lisp.c +++ b/gettext-tools/src/x-lisp.c @@ -132,29 +132,29 @@ x_lisp_keyword (const char *name) size_t i; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid Lisp symbol. - Extract the symbol name part. */ + Extract the symbol name part. */ colon = strchr (name, ':'); if (colon != NULL && colon < end) - { - name = colon + 1; - if (name < end && *name == ':') - name++; - colon = strchr (name, ':'); - if (colon != NULL && colon < end) - return; - } + { + name = colon + 1; + if (name < end && *name == ':') + name++; + colon = strchr (name, ':'); + if (colon != NULL && colon < end) + return; + } /* Uppercase it. */ len = end - name; symname = XNMALLOC (len, char); for (i = 0; i < len; i++) - symname[i] = - (name[i] >= 'a' && name[i] <= 'z' ? name[i] - 'a' + 'A' : name[i]); + symname[i] = + (name[i] >= 'a' && name[i] <= 'z' ? name[i] - 'a' + 'A' : name[i]); insert_keyword_callshape (&keywords, symname, len, &shape); } @@ -168,9 +168,9 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ - x_lisp_keyword ("gettext"); /* I18N:GETTEXT */ - x_lisp_keyword ("ngettext:1,2"); /* I18N:NGETTEXT */ + xgettext.texi! */ + x_lisp_keyword ("gettext"); /* I18N:GETTEXT */ + x_lisp_keyword ("ngettext:1,2"); /* I18N:NGETTEXT */ x_lisp_keyword ("gettext-noop"); default_keywords = false; } @@ -209,7 +209,7 @@ do_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("\ + error (EXIT_FAILURE, errno, _("\ error while reading \"%s\""), real_file_name); } else if (c == '\n') @@ -235,14 +235,14 @@ do_ungetc (int c) enum syntax_code { - syntax_illegal, /* non-printable, except whitespace */ - syntax_single_esc, /* '\' (single escape) */ - syntax_multi_esc, /* '|' (multiple escape) */ - syntax_constituent, /* everything else (constituent) */ - syntax_whitespace, /* TAB,LF,FF,CR,' ' (whitespace) */ - syntax_eof, /* EOF */ - syntax_t_macro, /* '()'"' (terminating macro) */ - syntax_nt_macro /* '#' (non-terminating macro) */ + syntax_illegal, /* non-printable, except whitespace */ + syntax_single_esc, /* '\' (single escape) */ + syntax_multi_esc, /* '|' (multiple escape) */ + syntax_constituent, /* everything else (constituent) */ + syntax_whitespace, /* TAB,LF,FF,CR,' ' (whitespace) */ + syntax_eof, /* EOF */ + syntax_t_macro, /* '()'"' (terminating macro) */ + syntax_nt_macro /* '#' (non-terminating macro) */ }; /* Returns the syntax code of a character. */ @@ -263,16 +263,16 @@ syntax_code_of (unsigned char c) return syntax_nt_macro; default: if (c < ' ' && c != '\b') - return syntax_illegal; + return syntax_illegal; else - return syntax_constituent; + return syntax_constituent; } } struct char_syntax { - int ch; /* character */ - enum syntax_code scode; /* syntax code */ + int ch; /* character */ + enum syntax_code scode; /* syntax code */ }; /* Returns the next character and its syntax code. */ @@ -292,19 +292,19 @@ read_char_syntax (struct char_syntax *p) enum attribute { - a_illg, /* invalid constituent */ - a_pack_m, /* ':' package marker */ - a_alpha, /* normal alphabetic */ - a_escaped, /* alphabetic but not subject to case conversion */ - a_ratio, /* '/' */ - a_dot, /* '.' */ - a_sign, /* '+-' */ - a_extens, /* '_^' extension characters */ - a_digit, /* '0123456789' */ + a_illg, /* invalid constituent */ + a_pack_m, /* ':' package marker */ + a_alpha, /* normal alphabetic */ + a_escaped, /* alphabetic but not subject to case conversion */ + a_ratio, /* '/' */ + a_dot, /* '.' */ + a_sign, /* '+-' */ + a_extens, /* '_^' extension characters */ + a_digit, /* '0123456789' */ a_letterdigit,/* 'A'-'Z','a'-'z' below base, except 'esfdlESFDL' */ - a_expodigit, /* 'esfdlESFDL' below base */ - a_letter, /* 'A'-'Z','a'-'z', except 'esfdlESFDL' */ - a_expo /* 'esfdlESFDL' */ + a_expodigit, /* 'esfdlESFDL' below base */ + a_letter, /* 'A'-'Z','a'-'z', except 'esfdlESFDL' */ + a_expo /* 'esfdlESFDL' */ }; #define is_letter_attribute(a) ((a) >= a_letter) @@ -347,17 +347,17 @@ attribute_of (unsigned char c) struct token_char { - unsigned char ch; /* character */ - unsigned char attribute; /* attribute */ + unsigned char ch; /* character */ + unsigned char attribute; /* attribute */ }; /* A token consists of a sequence of characters with associated attribute. */ struct token { - int allocated; /* number of allocated 'token_char's */ - int charcount; /* number of used 'token_char's */ - struct token_char *chars; /* the token's constituents */ - bool with_escape; /* whether single-escape or multiple escape occurs */ + int allocated; /* number of allocated 'token_char's */ + int charcount; /* number of used 'token_char's */ + struct token_char *chars; /* the token's constituents */ + bool with_escape; /* whether single-escape or multiple escape occurs */ }; /* Initialize a 'struct token'. */ @@ -408,69 +408,69 @@ read_token (struct token *tp, const struct char_syntax *first) for (;; read_char_syntax (&curr)) { switch (curr.scode) - { - case syntax_illegal: - /* Invalid input. Be tolerant, no error message. */ - do_ungetc (curr.ch); - return; - - case syntax_single_esc: - tp->with_escape = true; - read_char_syntax (&curr); - if (curr.scode == syntax_eof) - /* Invalid input. Be tolerant, no error message. */ - return; - grow_token (tp); - tp->chars[tp->charcount].ch = curr.ch; - tp->chars[tp->charcount].attribute = a_escaped; - tp->charcount++; - break; - - case syntax_multi_esc: - multiple_escape_flag = !multiple_escape_flag; - tp->with_escape = true; - break; - - case syntax_constituent: - case syntax_nt_macro: - grow_token (tp); - if (multiple_escape_flag) - { - tp->chars[tp->charcount].ch = curr.ch; - tp->chars[tp->charcount].attribute = a_escaped; - tp->charcount++; - } - else - { - tp->chars[tp->charcount].ch = curr.ch; - tp->chars[tp->charcount].attribute = attribute_of (curr.ch); - tp->charcount++; - } - break; - - case syntax_whitespace: - case syntax_t_macro: - if (multiple_escape_flag) - { - grow_token (tp); - tp->chars[tp->charcount].ch = curr.ch; - tp->chars[tp->charcount].attribute = a_escaped; - tp->charcount++; - } - else - { - if (curr.scode != syntax_whitespace || read_preserve_whitespace) - do_ungetc (curr.ch); - return; - } - break; - - case syntax_eof: - if (multiple_escape_flag) - /* Invalid input. Be tolerant, no error message. */ - ; - return; - } + { + case syntax_illegal: + /* Invalid input. Be tolerant, no error message. */ + do_ungetc (curr.ch); + return; + + case syntax_single_esc: + tp->with_escape = true; + read_char_syntax (&curr); + if (curr.scode == syntax_eof) + /* Invalid input. Be tolerant, no error message. */ + return; + grow_token (tp); + tp->chars[tp->charcount].ch = curr.ch; + tp->chars[tp->charcount].attribute = a_escaped; + tp->charcount++; + break; + + case syntax_multi_esc: + multiple_escape_flag = !multiple_escape_flag; + tp->with_escape = true; + break; + + case syntax_constituent: + case syntax_nt_macro: + grow_token (tp); + if (multiple_escape_flag) + { + tp->chars[tp->charcount].ch = curr.ch; + tp->chars[tp->charcount].attribute = a_escaped; + tp->charcount++; + } + else + { + tp->chars[tp->charcount].ch = curr.ch; + tp->chars[tp->charcount].attribute = attribute_of (curr.ch); + tp->charcount++; + } + break; + + case syntax_whitespace: + case syntax_t_macro: + if (multiple_escape_flag) + { + grow_token (tp); + tp->chars[tp->charcount].ch = curr.ch; + tp->chars[tp->charcount].attribute = a_escaped; + tp->charcount++; + } + else + { + if (curr.scode != syntax_whitespace || read_preserve_whitespace) + do_ungetc (curr.ch); + return; + } + break; + + case syntax_eof: + if (multiple_escape_flag) + /* Invalid input. Be tolerant, no error message. */ + ; + return; + } } } @@ -518,13 +518,13 @@ a_letter_to_digit (const struct token *tp, int base) for (i = 0; i < n; i++) if (is_letter_attribute (tp->chars[i].attribute)) { - int c = tp->chars[i].ch; + int c = tp->chars[i].ch; - if (c >= 'a') - c -= 'a' - 'A'; - if (c - 'A' + 10 < base) - tp->chars[i].attribute -= 2; /* a_letter -> a_letterdigit, - a_expo -> a_expodigit */ + if (c >= 'a') + c -= 'a' - 'A'; + if (c - 'A' + 10 < base) + tp->chars[i].attribute -= 2; /* a_letter -> a_letterdigit, + a_expo -> a_expodigit */ } } @@ -536,8 +536,8 @@ has_a_digit (const struct token *tp) for (i = 0; i < n; i++) if (tp->chars[i].attribute == a_digit - || tp->chars[i].attribute == a_letterdigit - || tp->chars[i].attribute == a_expodigit) + || tp->chars[i].attribute == a_letterdigit + || tp->chars[i].attribute == a_expodigit) return true; return false; } @@ -550,7 +550,7 @@ has_adjacent_letters (const struct token *tp) for (i = 1; i < n; i++) if (is_letter_attribute (tp->chars[i-1].attribute) - && is_letter_attribute (tp->chars[i].attribute)) + && is_letter_attribute (tp->chars[i].attribute)) return true; return false; } @@ -578,7 +578,7 @@ is_potential_number (const struct token *tp, int *basep) return false; if (!(tp->chars[0].attribute >= a_dot - && tp->chars[0].attribute <= a_expodigit)) + && tp->chars[0].attribute <= a_expodigit)) return false; if (tp->chars[tp->charcount - 1].attribute == a_sign) @@ -627,40 +627,40 @@ is_number (const struct token *tp, int *basep) */ { bool seen_a_ratio = false; - bool seen_a_digit = false; /* seen a digit in last digit block? */ + bool seen_a_digit = false; /* seen a digit in last digit block? */ struct token_char *ptr; for (ptr = ptr1;; ptr++) { - if (ptr >= ptr_limit) - { - if (!seen_a_digit) - break; - if (seen_a_ratio) - return n_ratio; - else - return n_integer; - } - if (ptr->attribute == a_digit - || ptr->attribute == a_letterdigit - || ptr->attribute == a_expodigit) - { - int c = ptr->ch; - - c = (c < 'A' ? c - '0' : c < 'a' ? c - 'A' + 10 : c - 'a' + 10); - if (c >= *basep) - break; - seen_a_digit = true; - } - else if (ptr->attribute == a_ratio) - { - if (seen_a_ratio || !seen_a_digit) - break; - seen_a_ratio = true; - seen_a_digit = false; - } - else - break; + if (ptr >= ptr_limit) + { + if (!seen_a_digit) + break; + if (seen_a_ratio) + return n_ratio; + else + return n_integer; + } + if (ptr->attribute == a_digit + || ptr->attribute == a_letterdigit + || ptr->attribute == a_expodigit) + { + int c = ptr->ch; + + c = (c < 'A' ? c - '0' : c < 'a' ? c - 'A' + 10 : c - 'a' + 10); + if (c >= *basep) + break; + seen_a_digit = true; + } + else if (ptr->attribute == a_ratio) + { + if (seen_a_ratio || !seen_a_digit) + break; + seen_a_ratio = true; + seen_a_digit = false; + } + else + break; } } @@ -682,40 +682,40 @@ is_number (const struct token *tp, int *basep) { bool seen_a_dot = false; bool seen_a_dot_with_leading_digits = false; - bool seen_a_digit = false; /* seen a digit in last digit block? */ + bool seen_a_digit = false; /* seen a digit in last digit block? */ struct token_char *ptr; for (ptr = ptr1;; ptr++) { - if (ptr >= ptr_limit) - { - /* no exponent */ - if (!seen_a_dot) - return n_none; - if (seen_a_digit) - return n_float; - if (seen_a_dot_with_leading_digits) - return n_integer; - else - return n_none; - } - if (ptr->attribute == a_digit) - { - seen_a_digit = true; - } - else if (ptr->attribute == a_dot) - { - if (seen_a_dot) - return n_none; - seen_a_dot = true; - if (seen_a_digit) - seen_a_dot_with_leading_digits = true; - seen_a_digit = false; - } - else if (ptr->attribute == a_expo || ptr->attribute == a_expodigit) - break; - else - return n_none; + if (ptr >= ptr_limit) + { + /* no exponent */ + if (!seen_a_dot) + return n_none; + if (seen_a_digit) + return n_float; + if (seen_a_dot_with_leading_digits) + return n_integer; + else + return n_none; + } + if (ptr->attribute == a_digit) + { + seen_a_digit = true; + } + else if (ptr->attribute == a_dot) + { + if (seen_a_dot) + return n_none; + seen_a_dot = true; + if (seen_a_digit) + seen_a_dot_with_leading_digits = true; + seen_a_digit = false; + } + else if (ptr->attribute == a_expo || ptr->attribute == a_expodigit) + break; + else + return n_none; } ptr++; if (!seen_a_dot_with_leading_digits || !seen_a_digit) @@ -727,11 +727,11 @@ is_number (const struct token *tp, int *basep) seen_a_digit = false; for (;; ptr++) { - if (ptr >= ptr_limit) - break; - if (ptr->attribute != a_digit) - return n_none; - seen_a_digit = true; + if (ptr >= ptr_limit) + break; + if (ptr->attribute != a_digit) + return n_none; + seen_a_digit = true; } if (!seen_a_digit) return n_none; @@ -751,9 +751,9 @@ upcase_token (struct token *tp) for (i = 0; i < n; i++) if (tp->chars[i].attribute != a_escaped) { - unsigned char c = tp->chars[i].ch; - if (c >= 'a' && c <= 'z') - tp->chars[i].ch = c - 'a' + 'A'; + unsigned char c = tp->chars[i].ch; + if (c >= 'a' && c <= 'z') + tp->chars[i].ch = c - 'a' + 'A'; } } @@ -766,9 +766,9 @@ downcase_token (struct token *tp) for (i = 0; i < n; i++) if (tp->chars[i].attribute != a_escaped) { - unsigned char c = tp->chars[i].ch; - if (c >= 'A' && c <= 'Z') - tp->chars[i].ch = c - 'A' + 'a'; + unsigned char c = tp->chars[i].ch; + if (c >= 'A' && c <= 'Z') + tp->chars[i].ch = c - 'A' + 'a'; } } @@ -793,27 +793,27 @@ case_convert_token (struct token *tp) case case_invert: { - bool seen_uppercase = false; - bool seen_lowercase = false; - for (i = 0; i < n; i++) - if (tp->chars[i].attribute != a_escaped) - { - unsigned char c = tp->chars[i].ch; - if (c >= 'a' && c <= 'z') - seen_lowercase = true; - if (c >= 'A' && c <= 'Z') - seen_uppercase = true; - } - if (seen_uppercase) - { - if (!seen_lowercase) - downcase_token (tp); - } - else - { - if (seen_lowercase) - upcase_token (tp); - } + bool seen_uppercase = false; + bool seen_lowercase = false; + for (i = 0; i < n; i++) + if (tp->chars[i].attribute != a_escaped) + { + unsigned char c = tp->chars[i].ch; + if (c >= 'a' && c <= 'z') + seen_lowercase = true; + if (c >= 'A' && c <= 'Z') + seen_uppercase = true; + } + if (seen_uppercase) + { + if (!seen_lowercase) + downcase_token (tp); + } + else + { + if (seen_lowercase) + upcase_token (tp); + } } break; } @@ -849,7 +849,7 @@ comment_line_end (size_t chars_to_remove) { buflen -= chars_to_remove; while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { @@ -880,19 +880,19 @@ static message_list_ty *mlp; Other objects need not to be represented precisely. */ enum object_type { - t_symbol, /* symbol */ - t_string, /* string */ - t_other, /* other kind of real object */ - t_dot, /* '.' pseudo object */ - t_close, /* ')' pseudo object */ - t_eof /* EOF marker */ + t_symbol, /* symbol */ + t_string, /* string */ + t_other, /* other kind of real object */ + t_dot, /* '.' pseudo object */ + t_close, /* ')' pseudo object */ + t_eof /* EOF marker */ }; struct object { enum object_type type; - struct token *token; /* for t_symbol and t_string */ - int line_number_at_start; /* for t_string */ + struct token *token; /* for t_symbol and t_string */ + int line_number_at_start; /* for t_string */ }; /* Free the memory pointed to by a 'struct object'. */ @@ -940,453 +940,453 @@ read_object (struct object *op, flag_context_ty outer_context) read_char_syntax (&curr); switch (curr.scode) - { - case syntax_eof: - op->type = t_eof; - return; - - case syntax_whitespace: - if (curr.ch == '\n') - /* Comments assumed to be grouped with a message must immediately - precede it, with no non-whitespace token on a line between - both. */ - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - continue; - - case syntax_illegal: - op->type = t_other; - return; - - case syntax_single_esc: - case syntax_multi_esc: - case syntax_constituent: - /* Start reading a token. */ - op->token = XMALLOC (struct token); - read_token (op->token, &curr); - last_non_comment_line = line_number; - - /* Interpret the token. */ - - /* Dots. */ - if (!op->token->with_escape - && op->token->charcount == 1 - && op->token->chars[0].attribute == a_dot) - { - free_token (op->token); - free (op->token); - op->type = t_dot; - return; - } - /* Tokens consisting entirely of dots are illegal, but be tolerant - here. */ - - /* Number. */ - { - int base = read_base; - - if (is_number (op->token, &base) != n_none) - { - free_token (op->token); - free (op->token); - op->type = t_other; - return; - } - } - - /* We interpret all other tokens as symbols (including 'reserved - tokens', i.e. potential numbers which are not numbers). */ - case_convert_token (op->token); - op->type = t_symbol; - return; - - case syntax_t_macro: - case syntax_nt_macro: - /* Read a macro. */ - switch (curr.ch) - { - case '(': - { - int arg = 0; /* Current argument number. */ - flag_context_list_iterator_ty context_iter; - const struct callshapes *shapes = NULL; - struct arglist_parser *argparser = NULL; - - for (;; arg++) - { - struct object inner; - flag_context_ty inner_context; - - if (arg == 0) - inner_context = null_context; - else - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - - read_object (&inner, inner_context); - - /* Recognize end of list. */ - if (inner.type == t_close) - { - op->type = t_other; - /* Don't bother converting "()" to "NIL". */ - last_non_comment_line = line_number; - if (argparser != NULL) - arglist_parser_done (argparser, arg); - return; - } - - /* Dots are not allowed in every position. - But be tolerant. */ - - /* EOF inside list is illegal. - But be tolerant. */ - if (inner.type == t_eof) - break; - - if (arg == 0) - { - /* This is the function position. */ - if (inner.type == t_symbol) - { - char *symbol_name = string_of_object (&inner); - int i; - int prefix_len; - void *keyword_value; - - /* Omit any package name. */ - i = inner.token->charcount; - while (i > 0 - && inner.token->chars[i-1].attribute != a_pack_m) - i--; - prefix_len = i; - - if (hash_find_entry (&keywords, - symbol_name + prefix_len, - strlen (symbol_name + prefix_len), - &keyword_value) - == 0) - shapes = (const struct callshapes *) keyword_value; - - argparser = arglist_parser_alloc (mlp, shapes); - - context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - symbol_name, strlen (symbol_name))); - - free (symbol_name); - } - else - context_iter = null_context_list_iterator; - } - else - { - /* These are the argument positions. */ - if (argparser != NULL && inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_object (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); - } - - free_object (&inner); - } - - if (argparser != NULL) - arglist_parser_done (argparser, arg); - } - op->type = t_other; - last_non_comment_line = line_number; - return; - - case ')': - /* Tell the caller about the end of list. - Unmatched closing parenthesis is illegal. - But be tolerant. */ - op->type = t_close; - last_non_comment_line = line_number; - return; - - case ',': - { - int c = do_getc (); - /* The ,@ handling inside lists is wrong anyway, because - ,@form expands to an unknown number of elements. */ - if (c != EOF && c != '@' && c != '.') - do_ungetc (c); - } - /*FALLTHROUGH*/ - case '\'': - case '`': - { - struct object inner; - - read_object (&inner, null_context); - - /* Dots and EOF are not allowed here. But be tolerant. */ - - free_object (&inner); - - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case ';': - { - bool all_semicolons = true; - - last_comment_line = line_number; - comment_start (); - for (;;) - { - int c = do_getc (); - if (c == EOF || c == '\n') - break; - if (c != ';') - all_semicolons = false; - if (!all_semicolons) - { - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - } - } - comment_line_end (0); - continue; - } - - case '"': - { - op->token = XMALLOC (struct token); - init_token (op->token); - op->line_number_at_start = line_number; - for (;;) - { - int c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - break; - if (c == '"') - break; - if (c == '\\') /* syntax_single_esc */ - { - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - break; - } - grow_token (op->token); - op->token->chars[op->token->charcount++].ch = c; - } - op->type = t_string; - - if (extract_all) - { - lex_pos_ty pos; - - pos.file_name = logical_file_name; - pos.line_number = op->line_number_at_start; - remember_a_message (mlp, NULL, string_of_object (op), - null_context, &pos, - NULL, savable_comment); - } - last_non_comment_line = line_number; - return; - } - - case '#': - /* Dispatch macro handling. */ - { - int c; - - for (;;) - { - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - { - op->type = t_other; - return; - } - if (!(c >= '0' && c <= '9')) - break; - } - - switch (c) - { - case '(': - case '"': - do_ungetc (c); - /*FALLTHROUGH*/ - case '\'': - case ':': - case '.': - case ',': - case 'A': case 'a': - case 'C': case 'c': - case 'P': case 'p': - case 'S': case 's': - { - struct object inner; - read_object (&inner, null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '|': - { - int depth = 0; - int c; - - comment_start (); - c = do_getc (); - for (;;) - { - if (c == EOF) - break; - if (c == '|') - { - c = do_getc (); - if (c == EOF) - break; - if (c == '#') - { - if (depth == 0) - { - comment_line_end (0); - break; - } - depth--; - comment_add ('|'); - comment_add ('#'); - c = do_getc (); - } - else - comment_add ('|'); - } - else if (c == '#') - { - c = do_getc (); - if (c == EOF) - break; - comment_add ('#'); - if (c == '|') - { - depth++; - comment_add ('|'); - c = do_getc (); - } - } - else - { - /* We skip all leading white space. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - if (c == '\n') - { - comment_line_end (1); - comment_start (); - } - c = do_getc (); - } - } - if (c == EOF) - { - /* EOF not allowed here. But be tolerant. */ - op->type = t_eof; - return; - } - last_comment_line = line_number; - continue; - } - - case '\\': - { - struct token token; - struct char_syntax first; - first.ch = '\\'; - first.scode = syntax_single_esc; - read_token (&token, &first); - free_token (&token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case 'B': case 'b': - case 'O': case 'o': - case 'X': case 'x': - case 'R': case 'r': - case '*': - { - struct token token; - read_token (&token, NULL); - free_token (&token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '=': - /* Ignore read labels. */ - continue; - - case '#': - /* Don't bother looking up the corresponding object. */ - op->type = t_other; - last_non_comment_line = line_number; - return; - - case '+': - case '-': - /* Simply assume every feature expression is true. */ - { - struct object inner; - read_object (&inner, null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - continue; - } - - default: - op->type = t_other; - last_non_comment_line = line_number; - return; - } - /*NOTREACHED*/ - abort (); - } - - default: - /*NOTREACHED*/ - abort (); - } - - default: - /*NOTREACHED*/ - abort (); - } + { + case syntax_eof: + op->type = t_eof; + return; + + case syntax_whitespace: + if (curr.ch == '\n') + /* Comments assumed to be grouped with a message must immediately + precede it, with no non-whitespace token on a line between + both. */ + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + continue; + + case syntax_illegal: + op->type = t_other; + return; + + case syntax_single_esc: + case syntax_multi_esc: + case syntax_constituent: + /* Start reading a token. */ + op->token = XMALLOC (struct token); + read_token (op->token, &curr); + last_non_comment_line = line_number; + + /* Interpret the token. */ + + /* Dots. */ + if (!op->token->with_escape + && op->token->charcount == 1 + && op->token->chars[0].attribute == a_dot) + { + free_token (op->token); + free (op->token); + op->type = t_dot; + return; + } + /* Tokens consisting entirely of dots are illegal, but be tolerant + here. */ + + /* Number. */ + { + int base = read_base; + + if (is_number (op->token, &base) != n_none) + { + free_token (op->token); + free (op->token); + op->type = t_other; + return; + } + } + + /* We interpret all other tokens as symbols (including 'reserved + tokens', i.e. potential numbers which are not numbers). */ + case_convert_token (op->token); + op->type = t_symbol; + return; + + case syntax_t_macro: + case syntax_nt_macro: + /* Read a macro. */ + switch (curr.ch) + { + case '(': + { + int arg = 0; /* Current argument number. */ + flag_context_list_iterator_ty context_iter; + const struct callshapes *shapes = NULL; + struct arglist_parser *argparser = NULL; + + for (;; arg++) + { + struct object inner; + flag_context_ty inner_context; + + if (arg == 0) + inner_context = null_context; + else + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + + read_object (&inner, inner_context); + + /* Recognize end of list. */ + if (inner.type == t_close) + { + op->type = t_other; + /* Don't bother converting "()" to "NIL". */ + last_non_comment_line = line_number; + if (argparser != NULL) + arglist_parser_done (argparser, arg); + return; + } + + /* Dots are not allowed in every position. + But be tolerant. */ + + /* EOF inside list is illegal. + But be tolerant. */ + if (inner.type == t_eof) + break; + + if (arg == 0) + { + /* This is the function position. */ + if (inner.type == t_symbol) + { + char *symbol_name = string_of_object (&inner); + int i; + int prefix_len; + void *keyword_value; + + /* Omit any package name. */ + i = inner.token->charcount; + while (i > 0 + && inner.token->chars[i-1].attribute != a_pack_m) + i--; + prefix_len = i; + + if (hash_find_entry (&keywords, + symbol_name + prefix_len, + strlen (symbol_name + prefix_len), + &keyword_value) + == 0) + shapes = (const struct callshapes *) keyword_value; + + argparser = arglist_parser_alloc (mlp, shapes); + + context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + symbol_name, strlen (symbol_name))); + + free (symbol_name); + } + else + context_iter = null_context_list_iterator; + } + else + { + /* These are the argument positions. */ + if (argparser != NULL && inner.type == t_string) + arglist_parser_remember (argparser, arg, + string_of_object (&inner), + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + } + + free_object (&inner); + } + + if (argparser != NULL) + arglist_parser_done (argparser, arg); + } + op->type = t_other; + last_non_comment_line = line_number; + return; + + case ')': + /* Tell the caller about the end of list. + Unmatched closing parenthesis is illegal. + But be tolerant. */ + op->type = t_close; + last_non_comment_line = line_number; + return; + + case ',': + { + int c = do_getc (); + /* The ,@ handling inside lists is wrong anyway, because + ,@form expands to an unknown number of elements. */ + if (c != EOF && c != '@' && c != '.') + do_ungetc (c); + } + /*FALLTHROUGH*/ + case '\'': + case '`': + { + struct object inner; + + read_object (&inner, null_context); + + /* Dots and EOF are not allowed here. But be tolerant. */ + + free_object (&inner); + + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case ';': + { + bool all_semicolons = true; + + last_comment_line = line_number; + comment_start (); + for (;;) + { + int c = do_getc (); + if (c == EOF || c == '\n') + break; + if (c != ';') + all_semicolons = false; + if (!all_semicolons) + { + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + } + } + comment_line_end (0); + continue; + } + + case '"': + { + op->token = XMALLOC (struct token); + init_token (op->token); + op->line_number_at_start = line_number; + for (;;) + { + int c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + break; + if (c == '"') + break; + if (c == '\\') /* syntax_single_esc */ + { + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + break; + } + grow_token (op->token); + op->token->chars[op->token->charcount++].ch = c; + } + op->type = t_string; + + if (extract_all) + { + lex_pos_ty pos; + + pos.file_name = logical_file_name; + pos.line_number = op->line_number_at_start; + remember_a_message (mlp, NULL, string_of_object (op), + null_context, &pos, + NULL, savable_comment); + } + last_non_comment_line = line_number; + return; + } + + case '#': + /* Dispatch macro handling. */ + { + int c; + + for (;;) + { + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + { + op->type = t_other; + return; + } + if (!(c >= '0' && c <= '9')) + break; + } + + switch (c) + { + case '(': + case '"': + do_ungetc (c); + /*FALLTHROUGH*/ + case '\'': + case ':': + case '.': + case ',': + case 'A': case 'a': + case 'C': case 'c': + case 'P': case 'p': + case 'S': case 's': + { + struct object inner; + read_object (&inner, null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '|': + { + int depth = 0; + int c; + + comment_start (); + c = do_getc (); + for (;;) + { + if (c == EOF) + break; + if (c == '|') + { + c = do_getc (); + if (c == EOF) + break; + if (c == '#') + { + if (depth == 0) + { + comment_line_end (0); + break; + } + depth--; + comment_add ('|'); + comment_add ('#'); + c = do_getc (); + } + else + comment_add ('|'); + } + else if (c == '#') + { + c = do_getc (); + if (c == EOF) + break; + comment_add ('#'); + if (c == '|') + { + depth++; + comment_add ('|'); + c = do_getc (); + } + } + else + { + /* We skip all leading white space. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + if (c == '\n') + { + comment_line_end (1); + comment_start (); + } + c = do_getc (); + } + } + if (c == EOF) + { + /* EOF not allowed here. But be tolerant. */ + op->type = t_eof; + return; + } + last_comment_line = line_number; + continue; + } + + case '\\': + { + struct token token; + struct char_syntax first; + first.ch = '\\'; + first.scode = syntax_single_esc; + read_token (&token, &first); + free_token (&token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case 'B': case 'b': + case 'O': case 'o': + case 'X': case 'x': + case 'R': case 'r': + case '*': + { + struct token token; + read_token (&token, NULL); + free_token (&token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '=': + /* Ignore read labels. */ + continue; + + case '#': + /* Don't bother looking up the corresponding object. */ + op->type = t_other; + last_non_comment_line = line_number; + return; + + case '+': + case '-': + /* Simply assume every feature expression is true. */ + { + struct object inner; + read_object (&inner, null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + continue; + } + + default: + op->type = t_other; + last_non_comment_line = line_number; + return; + } + /*NOTREACHED*/ + abort (); + } + + default: + /*NOTREACHED*/ + abort (); + } + + default: + /*NOTREACHED*/ + abort (); + } } } void extract_lisp (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { mlp = mdlp->item[0]->messages; @@ -1411,7 +1411,7 @@ extract_lisp (FILE *f, read_object (&toplevel_object, null_context); if (toplevel_object.type == t_eof) - break; + break; free_object (&toplevel_object); } diff --git a/gettext-tools/src/x-lisp.h b/gettext-tools/src/x-lisp.h index 158b53a6f..9988f6286 100644 --- a/gettext-tools/src/x-lisp.h +++ b/gettext-tools/src/x-lisp.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_LISP \ - { "lisp", "Lisp" }, \ + { "lisp", "Lisp" }, \ #define SCANNERS_LISP \ - { "Lisp", extract_lisp, \ - &flag_table_lisp, &formatstring_lisp, NULL }, \ + { "Lisp", extract_lisp, \ + &flag_table_lisp, &formatstring_lisp, NULL }, \ /* Scan a Lisp file and add its translatable strings to mdlp. */ extern void extract_lisp (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); /* Handling of options specific to this language. */ diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index 1830a108c..bc86739ad 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -79,15 +79,15 @@ x_perl_keyword (const char *name) const char *colon; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid C identifier. - A colon means an invalid parse in split_keywordspec(). */ + A colon means an invalid parse in split_keywordspec(). */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); + insert_keyword_callshape (&keywords, name, end - name, &shape); } } @@ -99,7 +99,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_perl_keyword ("gettext"); x_perl_keyword ("%gettext"); x_perl_keyword ("$gettext"); @@ -222,29 +222,29 @@ phase1_getc () linesize = getline (&linebuf, &linebuf_size, fp); if (linesize < 0) - { - if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); - end_of_file = true; - return EOF; - } + { + if (ferror (fp)) + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_file_name); + end_of_file = true; + return EOF; + } linepos = 0; ++line_number; /* Undosify. This is important for catching the end of <= 2 && linebuf[linesize - 1] == '\n' - && linebuf[linesize - 2] == '\r') - { - linebuf[linesize - 2] = '\n'; - linebuf[linesize - 1] = '\0'; - --linesize; - } + && linebuf[linesize - 2] == '\r') + { + linebuf[linesize - 2] = '\n'; + linebuf[linesize - 1] = '\0'; + --linesize; + } } return linebuf[linepos++]; @@ -257,9 +257,9 @@ phase1_ungetc (int c) if (c != EOF) { if (linepos == 0) - /* Attempt to ungetc across line boundary. Shouldn't happen. - No two phase1_ungetc calls are permitted in a row. */ - abort (); + /* Attempt to ungetc across line boundary. Shouldn't happen. + No two phase1_ungetc calls are permitted in a row. */ + abort (); --linepos; } @@ -296,78 +296,78 @@ get_here_document (const char *delimiter) bool chomp; if (read_bytes < 0) - { - if (ferror (fp)) - { - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); - } - else - { - error_with_progname = false; - error (EXIT_SUCCESS, 0, _("\ + { + if (ferror (fp)) + { + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_file_name); + } + else + { + error_with_progname = false; + error (EXIT_SUCCESS, 0, _("\ %s:%d: can't find string terminator \"%s\" anywhere before EOF"), - real_file_name, line_number, delimiter); - error_with_progname = true; + real_file_name, line_number, delimiter); + error_with_progname = true; - break; - } - } + break; + } + } ++here_eaten; /* Convert to UTF-8. */ my_line_utf8 = - from_current_source_encoding (my_linebuf, lc_string, logical_file_name, - line_number + here_eaten); + from_current_source_encoding (my_linebuf, lc_string, logical_file_name, + line_number + here_eaten); if (my_line_utf8 != my_linebuf) - { - if (strlen (my_line_utf8) >= my_linebuf_size) - { - my_linebuf_size = strlen (my_line_utf8) + 1; - my_linebuf = xrealloc (my_linebuf, my_linebuf_size); - } - strcpy (my_linebuf, my_line_utf8); - free (my_line_utf8); - } + { + if (strlen (my_line_utf8) >= my_linebuf_size) + { + my_linebuf_size = strlen (my_line_utf8) + 1; + my_linebuf = xrealloc (my_linebuf, my_linebuf_size); + } + strcpy (my_linebuf, my_line_utf8); + free (my_line_utf8); + } /* Undosify. This is important for catching the end of <= 2 && my_linebuf[read_bytes - 1] == '\n' - && my_linebuf[read_bytes - 2] == '\r') - { - my_linebuf[read_bytes - 2] = '\n'; - my_linebuf[read_bytes - 1] = '\0'; - --read_bytes; - } + && my_linebuf[read_bytes - 2] == '\r') + { + my_linebuf[read_bytes - 2] = '\n'; + my_linebuf[read_bytes - 1] = '\0'; + --read_bytes; + } /* Temporarily remove the trailing newline from my_linebuf. */ chomp = false; if (read_bytes >= 1 && my_linebuf[read_bytes - 1] == '\n') - { - chomp = true; - my_linebuf[read_bytes - 1] = '\0'; - } + { + chomp = true; + my_linebuf[read_bytes - 1] = '\0'; + } /* See whether this line terminates the here document. */ if (strcmp (my_linebuf, delimiter) == 0) - break; + break; /* Add back the trailing newline to my_linebuf. */ if (chomp) - my_linebuf[read_bytes - 1] = '\n'; + my_linebuf[read_bytes - 1] = '\n'; /* Ensure room for read_bytes + 1 bytes. */ if (bufpos + read_bytes >= bufmax) - { - do - bufmax = 2 * bufmax + 10; - while (bufpos + read_bytes >= bufmax); - buffer = xrealloc (buffer, bufmax); - } + { + do + bufmax = 2 * bufmax + 10; + while (bufpos + read_bytes >= bufmax); + buffer = xrealloc (buffer, bufmax); + } /* Append this line to the accumulator. */ strcpy (buffer + bufpos, my_linebuf); bufpos += read_bytes; @@ -390,21 +390,21 @@ skip_pod () linesize = getline (&linebuf, &linebuf_size, fp); if (linesize < 0) - { - if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); - return; - } + { + if (ferror (fp)) + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_file_name); + return; + } ++line_number; if (strncmp ("=cut", linebuf, 4) == 0) - { - /* Force reading of a new line on next call to phase1_getc(). */ - linepos = linesize; - return; - } + { + /* Force reading of a new line on next call to phase1_getc(). */ + linepos = linesize; + return; + } } } @@ -436,39 +436,39 @@ phase2_getc () lineno = line_number; /* Skip leading whitespace. */ for (;;) - { - c = phase1_getc (); - if (c == EOF) - break; - if (c != ' ' && c != '\t' && c != '\r' && c != '\f') - { - phase1_ungetc (c); - break; - } - } + { + c = phase1_getc (); + if (c == EOF) + break; + if (c != ' ' && c != '\t' && c != '\r' && c != '\f') + { + phase1_ungetc (c); + break; + } + } /* Accumulate the comment. */ for (;;) - { - c = phase1_getc (); - if (c == '\n' || c == EOF) - break; - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[buflen++] = c; - } + { + c = phase1_getc (); + if (c == '\n' || c == EOF) + break; + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[buflen++] = c; + } if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } buffer[buflen] = '\0'; /* Convert it to UTF-8. */ utf8_string = - from_current_source_encoding (buffer, lc_comment, logical_file_name, - lineno); + from_current_source_encoding (buffer, lc_comment, logical_file_name, + lineno); /* Save it until we encounter the corresponding string. */ savable_comment_add (utf8_string); last_comment_line = lineno; @@ -502,26 +502,26 @@ is_whitespace (int c) enum token_type_ty { token_type_eof, - token_type_lparen, /* ( */ - token_type_rparen, /* ) */ - token_type_comma, /* , */ - token_type_fat_comma, /* => */ - token_type_dereference, /* , */ + token_type_lparen, /* ( */ + token_type_rparen, /* ) */ + token_type_comma, /* , */ + token_type_fat_comma, /* => */ + token_type_dereference, /* , */ token_type_semicolon, /* ; */ token_type_lbrace, /* { */ token_type_rbrace, /* } */ token_type_lbracket, /* [ */ token_type_rbracket, /* ] */ - token_type_string, /* quote-like */ + token_type_string, /* quote-like */ token_type_named_op, /* if, unless, while, ... */ token_type_variable, /* $... */ - token_type_symbol, /* symbol, number */ - token_type_regex_op, /* s, tr, y, m. */ + token_type_symbol, /* symbol, number */ + token_type_regex_op, /* s, tr, y, m. */ token_type_dot, /* . */ - token_type_other, /* regexp, misc. operator */ + token_type_other, /* regexp, misc. operator */ /* The following are not really token types, but variants used by the parser. */ - token_type_keyword_symbol /* keyword symbol */ + token_type_keyword_symbol /* keyword symbol */ }; typedef enum token_type_ty token_type_ty; @@ -529,10 +529,10 @@ typedef enum token_type_ty token_type_ty; enum string_type_ty { string_type_verbatim, /* "<<'EOF'", "m'...'", "s'...''...'", - "tr/.../.../", "y/.../.../". */ + "tr/.../.../", "y/.../.../". */ string_type_q, /* "'..'", "q/.../". */ string_type_qq, /* '"..."', "`...`", "qq/.../", "qx/.../", - "". */ + "". */ string_type_qr /* Not supported. */ }; @@ -548,13 +548,13 @@ typedef struct token_ty token_ty; struct token_ty { token_type_ty type; - int sub_type; /* for token_type_string, token_type_symbol */ - char *string; /* for: in encoding: - token_type_named_op ASCII - token_type_string UTF-8 - token_type_symbol ASCII - token_type_variable global_source_encoding - */ + int sub_type; /* for token_type_string, token_type_symbol */ + char *string; /* for: in encoding: + token_type_named_op ASCII + token_type_string UTF-8 + token_type_symbol ASCII + token_type_variable global_source_encoding + */ refcounted_string_list_ty *comment; /* for token_type_string */ int line_number; }; @@ -672,61 +672,61 @@ extract_quotelike_pass1 (int delim) /* This round can produce 1 or 2 bytes. Ensure room for 2 bytes. */ if (bufpos + 2 > bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } if (c == counter_delim || c == EOF) - { - buffer[bufpos++] = counter_delim; /* will be stripped off later */ - buffer[bufpos++] = '\0'; + { + buffer[bufpos++] = counter_delim; /* will be stripped off later */ + buffer[bufpos++] = '\0'; #if DEBUG_PERL - fprintf (stderr, "PASS1: %s\n", buffer); + fprintf (stderr, "PASS1: %s\n", buffer); #endif - return buffer; - } + return buffer; + } if (nested && c == delim) - { - char *inner = extract_quotelike_pass1 (delim); - size_t len = strlen (inner); - - /* Ensure room for len + 1 bytes. */ - if (bufpos + len >= bufmax) - { - do - bufmax = 2 * bufmax + 10; - while (bufpos + len >= bufmax); - buffer = xrealloc (buffer, bufmax); - } - strcpy (buffer + bufpos, inner); - free (inner); - bufpos += len; - } + { + char *inner = extract_quotelike_pass1 (delim); + size_t len = strlen (inner); + + /* Ensure room for len + 1 bytes. */ + if (bufpos + len >= bufmax) + { + do + bufmax = 2 * bufmax + 10; + while (bufpos + len >= bufmax); + buffer = xrealloc (buffer, bufmax); + } + strcpy (buffer + bufpos, inner); + free (inner); + bufpos += len; + } else if (c == '\\') - { - c = phase1_getc (); - if (c == '\\') - { - buffer[bufpos++] = '\\'; - buffer[bufpos++] = '\\'; - } - else if (c == delim || c == counter_delim) - { - /* This is pass2 in Perl. */ - buffer[bufpos++] = c; - } - else - { - buffer[bufpos++] = '\\'; - phase1_ungetc (c); - } - } + { + c = phase1_getc (); + if (c == '\\') + { + buffer[bufpos++] = '\\'; + buffer[bufpos++] = '\\'; + } + else if (c == delim || c == counter_delim) + { + /* This is pass2 in Perl. */ + buffer[bufpos++] = c; + } + else + { + buffer[bufpos++] = '\\'; + phase1_ungetc (c); + } + } else - { - buffer[bufpos++] = c; - } + { + buffer[bufpos++] = c; + } } } @@ -738,7 +738,7 @@ extract_quotelike_pass1_utf8 (int delim) char *string = extract_quotelike_pass1 (delim); char *utf8_string = from_current_source_encoding (string, lc_string, logical_file_name, - line_number); + line_number); if (utf8_string != string) free (string); return utf8_string; @@ -762,15 +762,15 @@ static flag_context_list_table_ty *flag_context_list_table; /* Forward declaration of local functions. */ static void interpolate_keywords (message_list_ty *mlp, const char *string, - int lineno); + int lineno); static token_ty *x_perl_lex (message_list_ty *mlp); static void x_perl_unlex (token_ty *tp); static bool extract_balanced (message_list_ty *mlp, - token_type_ty delim, bool eat_delim, - bool comma_delim, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - int arg, struct arglist_parser *argparser); + token_type_ty delim, bool eat_delim, + bool comma_delim, + flag_context_ty outer_context, + flag_context_list_iterator_ty context_iter, + int arg, struct arglist_parser *argparser); /* Extract an unsigned hexadecimal number from STRING, considering at @@ -789,13 +789,13 @@ extract_hex (const char *string, size_t len, unsigned int *result) int number; if (c >= 'A' && c <= 'F') - number = c - 'A' + 10; + number = c - 'A' + 10; else if (c >= 'a' && c <= 'f') - number = c - 'a' + 10; + number = c - 'a' + 10; else if (c >= '0' && c <= '9') - number = c - '0'; + number = c - '0'; else - break; + break; *result <<= 4; *result |= number; @@ -820,9 +820,9 @@ extract_oct (const char *string, size_t len, unsigned int *result) int number; if (c >= '0' && c <= '7') - number = c - '0'; + number = c - '0'; else - break; + break; *result <<= 3; *result |= number; @@ -856,7 +856,7 @@ extract_quotelike (token_ty *tp, int delim) Return the resulting token in *tp; tp->type == token_type_regex_op. */ static void extract_triple_quotelike (message_list_ty *mlp, token_ty *tp, int delim, - bool interpolate) + bool interpolate) { char *string; @@ -870,14 +870,14 @@ extract_triple_quotelike (message_list_ty *mlp, token_ty *tp, int delim, if (delim == '(' || delim == '<' || delim == '{' || delim == '[') { /* The delimiter for the second string can be different, e.g. - s{SEARCH}{REPLACE} or s{SEARCH}/REPLACE/. See "man perlrequick". */ + s{SEARCH}{REPLACE} or s{SEARCH}/REPLACE/. See "man perlrequick". */ delim = phase1_getc (); while (is_whitespace (delim)) - { - /* The hash-sign is not a valid delimiter after whitespace, ergo - use phase2_getc() and not phase1_getc() now. */ - delim = phase2_getc (); - } + { + /* The hash-sign is not a valid delimiter after whitespace, ergo + use phase2_getc() and not phase1_getc() now. */ + delim = phase2_getc (); + } } string = extract_quotelike_pass1_utf8 (delim); if (interpolate) @@ -935,327 +935,327 @@ extract_quotelike_pass3 (token_ty *tp, int error_level) bool backslashed; /* Ensure room for 7 bytes, 6 (multi-)bytes plus a leading backslash - if \Q modifier is present. */ + if \Q modifier is present. */ if (bufpos + 7 > bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } if (tp->sub_type == string_type_q) - { - switch (*crs) - { - case '\\': - if (crs[1] == '\\') - { - crs += 2; - buffer[bufpos++] = '\\'; - break; - } - /* FALLTHROUGH */ - default: - buffer[bufpos++] = *crs++; - break; - } - continue; - } + { + switch (*crs) + { + case '\\': + if (crs[1] == '\\') + { + crs += 2; + buffer[bufpos++] = '\\'; + break; + } + /* FALLTHROUGH */ + default: + buffer[bufpos++] = *crs++; + break; + } + continue; + } /* We only get here for double-quoted strings or regular expressions. - Unescape escape sequences. */ + Unescape escape sequences. */ if (*crs == '\\') - { - switch (crs[1]) - { - case 't': - crs += 2; - buffer[bufpos++] = '\t'; - continue; - case 'n': - crs += 2; - buffer[bufpos++] = '\n'; - continue; - case 'r': - crs += 2; - buffer[bufpos++] = '\r'; - continue; - case 'f': - crs += 2; - buffer[bufpos++] = '\f'; - continue; - case 'b': - crs += 2; - buffer[bufpos++] = '\b'; - continue; - case 'a': - crs += 2; - buffer[bufpos++] = '\a'; - continue; - case 'e': - crs += 2; - buffer[bufpos++] = 0x1b; - continue; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - { - unsigned int oct_number; - int length; - - crs = extract_oct (crs + 1, 3, &oct_number); - - /* FIXME: If one of the variables UPPERCASE or LOWERCASE is - true, the character should be converted to its uppercase - resp. lowercase equivalent. I don't know if the necessary - facilities are already included in gettext. For US-Ascii - the conversion can be already be done, however. */ - if (uppercase && oct_number >= 'a' && oct_number <= 'z') - { - oct_number = oct_number - 'a' + 'A'; - } - else if (lowercase && oct_number >= 'A' && oct_number <= 'Z') - { - oct_number = oct_number - 'A' + 'a'; - } - - - /* Yes, octal escape sequences in the range 0x100..0x1ff are - valid. */ - length = u8_uctomb ((unsigned char *) (buffer + bufpos), - oct_number, 2); - if (length > 0) - bufpos += length; - } - continue; - case 'x': - { - unsigned int hex_number = 0; - int length; - - crs += 2; - if (*crs == '{') - { - const char *end = strchr (crs, '}'); - if (end == NULL) - { - error_with_progname = false; - error (error_level, 0, _("\ + { + switch (crs[1]) + { + case 't': + crs += 2; + buffer[bufpos++] = '\t'; + continue; + case 'n': + crs += 2; + buffer[bufpos++] = '\n'; + continue; + case 'r': + crs += 2; + buffer[bufpos++] = '\r'; + continue; + case 'f': + crs += 2; + buffer[bufpos++] = '\f'; + continue; + case 'b': + crs += 2; + buffer[bufpos++] = '\b'; + continue; + case 'a': + crs += 2; + buffer[bufpos++] = '\a'; + continue; + case 'e': + crs += 2; + buffer[bufpos++] = 0x1b; + continue; + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + { + unsigned int oct_number; + int length; + + crs = extract_oct (crs + 1, 3, &oct_number); + + /* FIXME: If one of the variables UPPERCASE or LOWERCASE is + true, the character should be converted to its uppercase + resp. lowercase equivalent. I don't know if the necessary + facilities are already included in gettext. For US-Ascii + the conversion can be already be done, however. */ + if (uppercase && oct_number >= 'a' && oct_number <= 'z') + { + oct_number = oct_number - 'a' + 'A'; + } + else if (lowercase && oct_number >= 'A' && oct_number <= 'Z') + { + oct_number = oct_number - 'A' + 'a'; + } + + + /* Yes, octal escape sequences in the range 0x100..0x1ff are + valid. */ + length = u8_uctomb ((unsigned char *) (buffer + bufpos), + oct_number, 2); + if (length > 0) + bufpos += length; + } + continue; + case 'x': + { + unsigned int hex_number = 0; + int length; + + crs += 2; + if (*crs == '{') + { + const char *end = strchr (crs, '}'); + if (end == NULL) + { + error_with_progname = false; + error (error_level, 0, _("\ %s:%d: missing right brace on \\x{HEXNUMBER}"), real_file_name, line_number); - error_with_progname = true; - ++crs; - continue; - } - else - { - ++crs; - (void) extract_hex (crs, end - crs, &hex_number); - crs = end + 1; - } - } - else - { - crs = extract_hex (crs, 2, &hex_number); - } - - /* FIXME: If one of the variables UPPERCASE or LOWERCASE is - true, the character should be converted to its uppercase - resp. lowercase equivalent. I don't know if the necessary - facilities are already included in gettext. For US-Ascii - the conversion can be already be done, however. */ - if (uppercase && hex_number >= 'a' && hex_number <= 'z') - { - hex_number = hex_number - 'a' + 'A'; - } - else if (lowercase && hex_number >= 'A' && hex_number <= 'Z') - { - hex_number = hex_number - 'A' + 'a'; - } - - length = u8_uctomb ((unsigned char *) (buffer + bufpos), - hex_number, 6); - - if (length > 0) - bufpos += length; - } - continue; - case 'c': - /* Perl's notion of control characters. */ - crs += 2; - if (*crs) - { - int the_char = (unsigned char) *crs; - if (the_char >= 'a' || the_char <= 'z') - the_char = the_char - 'a' + 'A'; - buffer[bufpos++] = the_char ^ 0x40; - } - continue; - case 'N': - crs += 2; - if (*crs == '{') - { - const char *end = strchr (crs + 1, '}'); - if (end != NULL) - { - char *name; - unsigned int unicode; - - name = XNMALLOC (end - (crs + 1) + 1, char); - memcpy (name, crs + 1, end - (crs + 1)); - name[end - (crs + 1)] = '\0'; - - unicode = unicode_name_character (name); - if (unicode != UNINAME_INVALID) - { - /* FIXME: Convert to upper/lowercase if the - corresponding flag is set to true. */ - int length = - u8_uctomb ((unsigned char *) (buffer + bufpos), - unicode, 6); - if (length > 0) - bufpos += length; - } - - free (name); - - crs = end + 1; - } - } - continue; - } - } + error_with_progname = true; + ++crs; + continue; + } + else + { + ++crs; + (void) extract_hex (crs, end - crs, &hex_number); + crs = end + 1; + } + } + else + { + crs = extract_hex (crs, 2, &hex_number); + } + + /* FIXME: If one of the variables UPPERCASE or LOWERCASE is + true, the character should be converted to its uppercase + resp. lowercase equivalent. I don't know if the necessary + facilities are already included in gettext. For US-Ascii + the conversion can be already be done, however. */ + if (uppercase && hex_number >= 'a' && hex_number <= 'z') + { + hex_number = hex_number - 'a' + 'A'; + } + else if (lowercase && hex_number >= 'A' && hex_number <= 'Z') + { + hex_number = hex_number - 'A' + 'a'; + } + + length = u8_uctomb ((unsigned char *) (buffer + bufpos), + hex_number, 6); + + if (length > 0) + bufpos += length; + } + continue; + case 'c': + /* Perl's notion of control characters. */ + crs += 2; + if (*crs) + { + int the_char = (unsigned char) *crs; + if (the_char >= 'a' || the_char <= 'z') + the_char = the_char - 'a' + 'A'; + buffer[bufpos++] = the_char ^ 0x40; + } + continue; + case 'N': + crs += 2; + if (*crs == '{') + { + const char *end = strchr (crs + 1, '}'); + if (end != NULL) + { + char *name; + unsigned int unicode; + + name = XNMALLOC (end - (crs + 1) + 1, char); + memcpy (name, crs + 1, end - (crs + 1)); + name[end - (crs + 1)] = '\0'; + + unicode = unicode_name_character (name); + if (unicode != UNINAME_INVALID) + { + /* FIXME: Convert to upper/lowercase if the + corresponding flag is set to true. */ + int length = + u8_uctomb ((unsigned char *) (buffer + bufpos), + unicode, 6); + if (length > 0) + bufpos += length; + } + + free (name); + + crs = end + 1; + } + } + continue; + } + } /* No escape sequence, go on. */ if (*crs == '\\') - { - ++crs; - switch (*crs) - { - case 'E': - uppercase = false; - lowercase = false; - quotemeta = false; - ++crs; - continue; - case 'L': - uppercase = false; - lowercase = true; - ++crs; - continue; - case 'U': - uppercase = true; - lowercase = false; - ++crs; - continue; - case 'Q': - quotemeta = true; - ++crs; - continue; - case 'l': - ++crs; - if (*crs >= 'A' && *crs <= 'Z') - { - buffer[bufpos++] = *crs - 'A' + 'a'; - } - else if ((unsigned char) *crs >= 0x80) - { - error_with_progname = false; - error (error_level, 0, _("\ + { + ++crs; + switch (*crs) + { + case 'E': + uppercase = false; + lowercase = false; + quotemeta = false; + ++crs; + continue; + case 'L': + uppercase = false; + lowercase = true; + ++crs; + continue; + case 'U': + uppercase = true; + lowercase = false; + ++crs; + continue; + case 'Q': + quotemeta = true; + ++crs; + continue; + case 'l': + ++crs; + if (*crs >= 'A' && *crs <= 'Z') + { + buffer[bufpos++] = *crs - 'A' + 'a'; + } + else if ((unsigned char) *crs >= 0x80) + { + error_with_progname = false; + error (error_level, 0, _("\ %s:%d: invalid interpolation (\"\\l\") of 8bit character \"%c\""), - real_file_name, line_number, *crs); - error_with_progname = true; - } - else - { - buffer[bufpos++] = *crs; - } - ++crs; - continue; - case 'u': - ++crs; - if (*crs >= 'a' && *crs <= 'z') - { - buffer[bufpos++] = *crs - 'a' + 'A'; - } - else if ((unsigned char) *crs >= 0x80) - { - error_with_progname = false; - error (error_level, 0, _("\ + real_file_name, line_number, *crs); + error_with_progname = true; + } + else + { + buffer[bufpos++] = *crs; + } + ++crs; + continue; + case 'u': + ++crs; + if (*crs >= 'a' && *crs <= 'z') + { + buffer[bufpos++] = *crs - 'a' + 'A'; + } + else if ((unsigned char) *crs >= 0x80) + { + error_with_progname = false; + error (error_level, 0, _("\ %s:%d: invalid interpolation (\"\\u\") of 8bit character \"%c\""), - real_file_name, line_number, *crs); - error_with_progname = true; - } - else - { - buffer[bufpos++] = *crs; - } - ++crs; - continue; - case '\\': - buffer[bufpos++] = *crs; - ++crs; - continue; - default: - backslashed = true; - break; - } - } + real_file_name, line_number, *crs); + error_with_progname = true; + } + else + { + buffer[bufpos++] = *crs; + } + ++crs; + continue; + case '\\': + buffer[bufpos++] = *crs; + ++crs; + continue; + default: + backslashed = true; + break; + } + } else - backslashed = false; + backslashed = false; if (quotemeta - && !((*crs >= 'A' && *crs <= 'Z') || (*crs >= 'A' && *crs <= 'z') - || (*crs >= '0' && *crs <= '9') || *crs == '_')) - { - buffer[bufpos++] = '\\'; - backslashed = true; - } + && !((*crs >= 'A' && *crs <= 'Z') || (*crs >= 'A' && *crs <= 'z') + || (*crs >= '0' && *crs <= '9') || *crs == '_')) + { + buffer[bufpos++] = '\\'; + backslashed = true; + } if (!backslashed && !extract_all && (*crs == '$' || *crs == '@')) - { - error_with_progname = false; - error (error_level, 0, _("\ + { + error_with_progname = false; + error (error_level, 0, _("\ %s:%d: invalid variable interpolation at \"%c\""), - real_file_name, line_number, *crs); - error_with_progname = true; - ++crs; - } + real_file_name, line_number, *crs); + error_with_progname = true; + ++crs; + } else if (lowercase) - { - if (*crs >= 'A' && *crs <= 'Z') - buffer[bufpos++] = *crs - 'A' + 'a'; - else if ((unsigned char) *crs >= 0x80) - { - error_with_progname = false; - error (error_level, 0, _("\ + { + if (*crs >= 'A' && *crs <= 'Z') + buffer[bufpos++] = *crs - 'A' + 'a'; + else if ((unsigned char) *crs >= 0x80) + { + error_with_progname = false; + error (error_level, 0, _("\ %s:%d: invalid interpolation (\"\\L\") of 8bit character \"%c\""), - real_file_name, line_number, *crs); - error_with_progname = true; - buffer[bufpos++] = *crs; - } - else - buffer[bufpos++] = *crs; - ++crs; - } + real_file_name, line_number, *crs); + error_with_progname = true; + buffer[bufpos++] = *crs; + } + else + buffer[bufpos++] = *crs; + ++crs; + } else if (uppercase) - { - if (*crs >= 'a' && *crs <= 'z') - buffer[bufpos++] = *crs - 'a' + 'A'; - else if ((unsigned char) *crs >= 0x80) - { - error_with_progname = false; - error (error_level, 0, _("\ + { + if (*crs >= 'a' && *crs <= 'z') + buffer[bufpos++] = *crs - 'a' + 'A'; + else if ((unsigned char) *crs >= 0x80) + { + error_with_progname = false; + error (error_level, 0, _("\ %s:%d: invalid interpolation (\"\\U\") of 8bit character \"%c\""), - real_file_name, line_number, *crs); - error_with_progname = true; - buffer[bufpos++] = *crs; - } - else - buffer[bufpos++] = *crs; - ++crs; - } + real_file_name, line_number, *crs); + error_with_progname = true; + buffer[bufpos++] = *crs; + } + else + buffer[bufpos++] = *crs; + ++crs; + } else - { - buffer[bufpos++] = *crs++; - } + { + buffer[bufpos++] = *crs++; + } } /* Ensure room for 1 more byte. */ @@ -1296,7 +1296,7 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) #if DEBUG_PERL fprintf (stderr, "%s:%d: extracting variable type '%c'\n", - real_file_name, line_number, first); + real_file_name, line_number, first); #endif /* @@ -1307,10 +1307,10 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) while (c == '$' || c == '*' || c == '#' || c == '@' || c == '%') { if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } buffer[bufpos++] = c; c = phase1_getc (); } @@ -1326,34 +1326,34 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) if (buffer[0] == '$') { if (bufpos == 1) - maybe_hash_value = true; + maybe_hash_value = true; else if (bufpos == 2 && buffer[1] == '$') - { - if (!(c == '{' - || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9') - || c == '_' || c == ':' || c == '\'' || c >= 0x80)) - { - /* Special variable $$ for pid. */ - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = '\0'; - tp->string = xstrdup (buffer); + { + if (!(c == '{' + || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') + || (c >= '0' && c <= '9') + || c == '_' || c == ':' || c == '\'' || c >= 0x80)) + { + /* Special variable $$ for pid. */ + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = '\0'; + tp->string = xstrdup (buffer); #if DEBUG_PERL - fprintf (stderr, "%s:%d: is PID ($$)\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: is PID ($$)\n", + real_file_name, line_number); #endif - phase1_ungetc (c); - return; - } + phase1_ungetc (c); + return; + } - maybe_hash_deref = true; - bufpos = 1; - } + maybe_hash_deref = true; + bufpos = 1; + } } /* @@ -1375,33 +1375,33 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) */ #if DEBUG_PERL fprintf (stderr, "%s:%d: braced {variable_name}\n", - real_file_name, line_number); + real_file_name, line_number); #endif if (extract_balanced (mlp, token_type_rbrace, true, false, - null_context, null_context_list_iterator, - 1, arglist_parser_alloc (mlp, NULL))) - { - tp->type = token_type_eof; - return; - } + null_context, null_context_list_iterator, + 1, arglist_parser_alloc (mlp, NULL))) + { + tp->type = token_type_eof; + return; + } buffer[bufpos++] = c; } else { while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9') - || c == '_' || c == ':' || c == '\'' || c >= 0x80) - { - ++varbody_length; - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase1_getc (); - } + || (c >= '0' && c <= '9') + || c == '_' || c == ':' || c == '\'' || c >= 0x80) + { + ++varbody_length; + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase1_getc (); + } phase1_ungetc (c); } @@ -1410,16 +1410,16 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) { c = phase1_getc (); if (c == EOF || is_whitespace (c)) - phase1_ungetc (c); /* Loser. */ + phase1_ungetc (c); /* Loser. */ else - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - } + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + } } if (bufpos >= bufmax) @@ -1433,7 +1433,7 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) #if DEBUG_PERL fprintf (stderr, "%s:%d: complete variable name: %s\n", - real_file_name, line_number, tp->string); + real_file_name, line_number, tp->string); #endif prefer_division_over_regexp = true; @@ -1456,138 +1456,138 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) int c; do - c = phase2_getc (); + c = phase2_getc (); while (is_whitespace (c)); if (c == '-') - { - int c2 = phase1_getc (); - - if (c2 == '>') - { - is_dereference = true; - - do - c = phase2_getc (); - while (is_whitespace (c)); - } - else if (c2 != '\n') - { - /* Discarding the newline is harmless here. The only - special character recognized after a minus is greater-than - for dereference. However, the sequence "-\n>" that we - treat incorrectly here, is a syntax error. */ - phase1_ungetc (c2); - } - } + { + int c2 = phase1_getc (); + + if (c2 == '>') + { + is_dereference = true; + + do + c = phase2_getc (); + while (is_whitespace (c)); + } + else if (c2 != '\n') + { + /* Discarding the newline is harmless here. The only + special character recognized after a minus is greater-than + for dereference. However, the sequence "-\n>" that we + treat incorrectly here, is a syntax error. */ + phase1_ungetc (c2); + } + } if (maybe_hash_value && is_dereference) - { + { #if DEBUG_PERL - fprintf (stderr, "%s:%d: first keys preceded by \"->\"\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: first keys preceded by \"->\"\n", + real_file_name, line_number); #endif - } + } else if (maybe_hash_value) - { - /* Fake it into a hash. */ - tp->string[0] = '%'; - } + { + /* Fake it into a hash. */ + tp->string[0] = '%'; + } /* Do NOT change that into else if (see above). */ if ((maybe_hash_value || maybe_hash_deref) && c == '{') - { - void *keyword_value; + { + void *keyword_value; #if DEBUG_PERL - fprintf (stderr, "%s:%d: first keys preceded by '{'\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: first keys preceded by '{'\n", + real_file_name, line_number); #endif - if (hash_find_entry (&keywords, tp->string, strlen (tp->string), - &keyword_value) == 0) - { - /* TODO: Shouldn't we use the shapes of the keyword, instead - of hardwiring argnum1 = 1 ? - const struct callshapes *shapes = - (const struct callshapes *) keyword_value; - */ - struct callshapes shapes; - shapes.keyword = tp->string; /* XXX storage duration? */ - shapes.keyword_len = strlen (tp->string); - shapes.nshapes = 1; - shapes.shapes[0].argnum1 = 1; - shapes.shapes[0].argnum2 = 0; - shapes.shapes[0].argnumc = 0; - shapes.shapes[0].argnum1_glib_context = false; - shapes.shapes[0].argnum2_glib_context = false; - shapes.shapes[0].argtotal = 0; - string_list_init (&shapes.shapes[0].xcomments); - - { - /* Extract a possible string from the key. Before proceeding - we check whether the open curly is followed by a symbol and - then by a right curly. */ - flag_context_list_iterator_ty context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - tp->string, strlen (tp->string))); - token_ty *t1 = x_perl_lex (mlp); + if (hash_find_entry (&keywords, tp->string, strlen (tp->string), + &keyword_value) == 0) + { + /* TODO: Shouldn't we use the shapes of the keyword, instead + of hardwiring argnum1 = 1 ? + const struct callshapes *shapes = + (const struct callshapes *) keyword_value; + */ + struct callshapes shapes; + shapes.keyword = tp->string; /* XXX storage duration? */ + shapes.keyword_len = strlen (tp->string); + shapes.nshapes = 1; + shapes.shapes[0].argnum1 = 1; + shapes.shapes[0].argnum2 = 0; + shapes.shapes[0].argnumc = 0; + shapes.shapes[0].argnum1_glib_context = false; + shapes.shapes[0].argnum2_glib_context = false; + shapes.shapes[0].argtotal = 0; + string_list_init (&shapes.shapes[0].xcomments); + + { + /* Extract a possible string from the key. Before proceeding + we check whether the open curly is followed by a symbol and + then by a right curly. */ + flag_context_list_iterator_ty context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + tp->string, strlen (tp->string))); + token_ty *t1 = x_perl_lex (mlp); #if DEBUG_PERL - fprintf (stderr, "%s:%d: extracting string key\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: extracting string key\n", + real_file_name, line_number); #endif - if (t1->type == token_type_symbol - || t1->type == token_type_named_op) - { - token_ty *t2 = x_perl_lex (mlp); - if (t2->type == token_type_rbrace) - { - flag_context_ty context; - lex_pos_ty pos; - - context = - inherited_context (null_context, - flag_context_list_iterator_advance ( - &context_iter)); - - pos.line_number = line_number; - pos.file_name = logical_file_name; - - xgettext_current_source_encoding = po_charset_utf8; - remember_a_message (mlp, NULL, xstrdup (t1->string), - context, &pos, NULL, savable_comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; - free_token (t2); - free_token (t1); - } - else - { - x_perl_unlex (t2); - } - } - else - { - x_perl_unlex (t1); - if (extract_balanced (mlp, token_type_rbrace, true, false, - null_context, context_iter, - 1, arglist_parser_alloc (mlp, &shapes))) - return; - } - } - } - else - { - phase2_ungetc (c); - } - } + if (t1->type == token_type_symbol + || t1->type == token_type_named_op) + { + token_ty *t2 = x_perl_lex (mlp); + if (t2->type == token_type_rbrace) + { + flag_context_ty context; + lex_pos_ty pos; + + context = + inherited_context (null_context, + flag_context_list_iterator_advance ( + &context_iter)); + + pos.line_number = line_number; + pos.file_name = logical_file_name; + + xgettext_current_source_encoding = po_charset_utf8; + remember_a_message (mlp, NULL, xstrdup (t1->string), + context, &pos, NULL, savable_comment); + xgettext_current_source_encoding = xgettext_global_source_encoding; + free_token (t2); + free_token (t1); + } + else + { + x_perl_unlex (t2); + } + } + else + { + x_perl_unlex (t1); + if (extract_balanced (mlp, token_type_rbrace, true, false, + null_context, context_iter, + 1, arglist_parser_alloc (mlp, &shapes))) + return; + } + } + } + else + { + phase2_ungetc (c); + } + } else - { - phase2_ungetc (c); - } + { + phase2_ungetc (c); + } } /* Now consume "->", "[...]", and "{...}". */ @@ -1597,55 +1597,55 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) int c2; switch (c) - { - case '{': + { + case '{': #if DEBUG_PERL - fprintf (stderr, "%s:%d: extracting balanced '{' after varname\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: extracting balanced '{' after varname\n", + real_file_name, line_number); #endif - extract_balanced (mlp, token_type_rbrace, true, false, - null_context, null_context_list_iterator, - 1, arglist_parser_alloc (mlp, NULL)); - break; + extract_balanced (mlp, token_type_rbrace, true, false, + null_context, null_context_list_iterator, + 1, arglist_parser_alloc (mlp, NULL)); + break; - case '[': + case '[': #if DEBUG_PERL - fprintf (stderr, "%s:%d: extracting balanced '[' after varname\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: extracting balanced '[' after varname\n", + real_file_name, line_number); #endif - extract_balanced (mlp, token_type_rbracket, true, false, - null_context, null_context_list_iterator, - 1, arglist_parser_alloc (mlp, NULL)); - break; - - case '-': - c2 = phase1_getc (); - if (c2 == '>') - { + extract_balanced (mlp, token_type_rbracket, true, false, + null_context, null_context_list_iterator, + 1, arglist_parser_alloc (mlp, NULL)); + break; + + case '-': + c2 = phase1_getc (); + if (c2 == '>') + { #if DEBUG_PERL - fprintf (stderr, "%s:%d: another \"->\" after varname\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: another \"->\" after varname\n", + real_file_name, line_number); #endif - break; - } - else if (c2 != '\n') - { - /* Discarding the newline is harmless here. The only - special character recognized after a minus is greater-than - for dereference. However, the sequence "-\n>" that we - treat incorrectly here, is a syntax error. */ - phase1_ungetc (c2); - } - /* FALLTHROUGH */ - - default: + break; + } + else if (c2 != '\n') + { + /* Discarding the newline is harmless here. The only + special character recognized after a minus is greater-than + for dereference. However, the sequence "-\n>" that we + treat incorrectly here, is a syntax error. */ + phase1_ungetc (c2); + } + /* FALLTHROUGH */ + + default: #if DEBUG_PERL - fprintf (stderr, "%s:%d: variable finished\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: variable finished\n", + real_file_name, line_number); #endif - phase2_ungetc (c); - return; - } + phase2_ungetc (c); + return; + } } } @@ -1717,288 +1717,288 @@ interpolate_keywords (message_list_ty *mlp, const char *string, int lineno) void *keyword_value; if (state == initial) - bufpos = 0; + bufpos = 0; if (c == '\n') - lineno++; + lineno++; if (bufpos + 1 >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } switch (state) - { - case initial: - switch (c) - { - case '\\': - c = (unsigned char) *string++; - if (c == '\0') - return; - break; - case '$': - buffer[bufpos++] = '$'; - maybe_hash_deref = false; - state = one_dollar; - break; - default: - break; - } - break; - case one_dollar: - switch (c) - { - case '$': - /* - * This is enough to make us believe later that we dereference - * a hash reference. - */ - maybe_hash_deref = true; - state = two_dollars; - break; - default: - if (c == '_' || c == ':' || c == '\'' || c >= 0x80 - || (c >= 'A' && c <= 'Z') - || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9')) - { - buffer[bufpos++] = c; - state = identifier; - } - else - state = initial; - break; - } - break; - case two_dollars: - if (c == '_' || c == ':' || c == '\'' || c >= 0x80 - || (c >= 'A' && c <= 'Z') - || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9')) - { - buffer[bufpos++] = c; - state = identifier; - } - else - state = initial; - break; - case identifier: - switch (c) - { - case '-': - if (hash_find_entry (&keywords, buffer, bufpos, &keyword_value) - == 0) - { - flag_context_list_iterator_ty context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - buffer, bufpos)); - context = - inherited_context (null_context, - flag_context_list_iterator_advance ( - &context_iter)); - state = minus; - } - else - state = initial; - break; - case '{': - if (!maybe_hash_deref) - buffer[0] = '%'; - if (hash_find_entry (&keywords, buffer, bufpos, &keyword_value) - == 0) - { - flag_context_list_iterator_ty context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - buffer, bufpos)); - context = - inherited_context (null_context, - flag_context_list_iterator_advance ( - &context_iter)); - state = wait_quote; - } - else - state = initial; - break; - default: - if (c == '_' || c == ':' || c == '\'' || c >= 0x80 - || (c >= 'A' && c <= 'Z') - || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9')) - { - buffer[bufpos++] = c; - } - else - state = initial; - break; - } - break; - case minus: - switch (c) - { - case '>': - state = wait_lbrace; - break; - default: - context = null_context; - state = initial; - break; - } - break; - case wait_lbrace: - switch (c) - { - case '{': - state = wait_quote; - break; - default: - context = null_context; - state = initial; - break; - } - break; - case wait_quote: - switch (c) - { - case_whitespace: - break; - case '\'': - pos.line_number = lineno; - bufpos = 0; - state = squote; - break; - case '"': - pos.line_number = lineno; - bufpos = 0; - state = dquote; - break; - default: - if (c == '_' || (c >= '0' && c <= '9') || c >= 0x80 - || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) - { - pos.line_number = lineno; - bufpos = 0; - buffer[bufpos++] = c; - state = barekey; - } - else - { - context = null_context; - state = initial; - } - break; - } - break; - case dquote: - switch (c) - { - case '"': - /* The resulting string has to be interpolated twice. */ - buffer[bufpos] = '\0'; - token.string = xstrdup (buffer); - extract_quotelike_pass3 (&token, EXIT_FAILURE); - /* The string can only shrink with interpolation (because - we ignore \Q). */ - if (!(strlen (token.string) <= bufpos)) - abort (); - strcpy (buffer, token.string); - free (token.string); - state = wait_rbrace; - break; - case '\\': - if (string[0] == '\"') - { - buffer[bufpos++] = string++[0]; - } - else if (string[0]) - { - buffer[bufpos++] = '\\'; - buffer[bufpos++] = string++[0]; - } - else - { - context = null_context; - state = initial; - } - break; - default: - buffer[bufpos++] = c; - break; - } - break; - case squote: - switch (c) - { - case '\'': - state = wait_rbrace; - break; - case '\\': - if (string[0] == '\'') - { - buffer[bufpos++] = string++[0]; - } - else if (string[0]) - { - buffer[bufpos++] = '\\'; - buffer[bufpos++] = string++[0]; - } - else - { - context = null_context; - state = initial; - } - break; - default: - buffer[bufpos++] = c; - break; - } - break; - case barekey: - if (c == '_' || (c >= '0' && c <= '9') || c >= 0x80 - || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) - { - buffer[bufpos++] = c; - break; - } - else if (is_whitespace (c)) - { - state = wait_rbrace; - break; - } - else if (c != '}') - { - context = null_context; - state = initial; - break; - } - /* Must be right brace. */ - /* FALLTHROUGH */ - case wait_rbrace: - switch (c) - { - case_whitespace: - break; - case '}': - buffer[bufpos] = '\0'; - token.string = xstrdup (buffer); - extract_quotelike_pass3 (&token, EXIT_FAILURE); - xgettext_current_source_encoding = po_charset_utf8; - remember_a_message (mlp, NULL, token.string, context, &pos, - NULL, savable_comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; - /* FALLTHROUGH */ - default: - context = null_context; - state = initial; - break; - } - break; - } + { + case initial: + switch (c) + { + case '\\': + c = (unsigned char) *string++; + if (c == '\0') + return; + break; + case '$': + buffer[bufpos++] = '$'; + maybe_hash_deref = false; + state = one_dollar; + break; + default: + break; + } + break; + case one_dollar: + switch (c) + { + case '$': + /* + * This is enough to make us believe later that we dereference + * a hash reference. + */ + maybe_hash_deref = true; + state = two_dollars; + break; + default: + if (c == '_' || c == ':' || c == '\'' || c >= 0x80 + || (c >= 'A' && c <= 'Z') + || (c >= 'a' && c <= 'z') + || (c >= '0' && c <= '9')) + { + buffer[bufpos++] = c; + state = identifier; + } + else + state = initial; + break; + } + break; + case two_dollars: + if (c == '_' || c == ':' || c == '\'' || c >= 0x80 + || (c >= 'A' && c <= 'Z') + || (c >= 'a' && c <= 'z') + || (c >= '0' && c <= '9')) + { + buffer[bufpos++] = c; + state = identifier; + } + else + state = initial; + break; + case identifier: + switch (c) + { + case '-': + if (hash_find_entry (&keywords, buffer, bufpos, &keyword_value) + == 0) + { + flag_context_list_iterator_ty context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + buffer, bufpos)); + context = + inherited_context (null_context, + flag_context_list_iterator_advance ( + &context_iter)); + state = minus; + } + else + state = initial; + break; + case '{': + if (!maybe_hash_deref) + buffer[0] = '%'; + if (hash_find_entry (&keywords, buffer, bufpos, &keyword_value) + == 0) + { + flag_context_list_iterator_ty context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + buffer, bufpos)); + context = + inherited_context (null_context, + flag_context_list_iterator_advance ( + &context_iter)); + state = wait_quote; + } + else + state = initial; + break; + default: + if (c == '_' || c == ':' || c == '\'' || c >= 0x80 + || (c >= 'A' && c <= 'Z') + || (c >= 'a' && c <= 'z') + || (c >= '0' && c <= '9')) + { + buffer[bufpos++] = c; + } + else + state = initial; + break; + } + break; + case minus: + switch (c) + { + case '>': + state = wait_lbrace; + break; + default: + context = null_context; + state = initial; + break; + } + break; + case wait_lbrace: + switch (c) + { + case '{': + state = wait_quote; + break; + default: + context = null_context; + state = initial; + break; + } + break; + case wait_quote: + switch (c) + { + case_whitespace: + break; + case '\'': + pos.line_number = lineno; + bufpos = 0; + state = squote; + break; + case '"': + pos.line_number = lineno; + bufpos = 0; + state = dquote; + break; + default: + if (c == '_' || (c >= '0' && c <= '9') || c >= 0x80 + || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) + { + pos.line_number = lineno; + bufpos = 0; + buffer[bufpos++] = c; + state = barekey; + } + else + { + context = null_context; + state = initial; + } + break; + } + break; + case dquote: + switch (c) + { + case '"': + /* The resulting string has to be interpolated twice. */ + buffer[bufpos] = '\0'; + token.string = xstrdup (buffer); + extract_quotelike_pass3 (&token, EXIT_FAILURE); + /* The string can only shrink with interpolation (because + we ignore \Q). */ + if (!(strlen (token.string) <= bufpos)) + abort (); + strcpy (buffer, token.string); + free (token.string); + state = wait_rbrace; + break; + case '\\': + if (string[0] == '\"') + { + buffer[bufpos++] = string++[0]; + } + else if (string[0]) + { + buffer[bufpos++] = '\\'; + buffer[bufpos++] = string++[0]; + } + else + { + context = null_context; + state = initial; + } + break; + default: + buffer[bufpos++] = c; + break; + } + break; + case squote: + switch (c) + { + case '\'': + state = wait_rbrace; + break; + case '\\': + if (string[0] == '\'') + { + buffer[bufpos++] = string++[0]; + } + else if (string[0]) + { + buffer[bufpos++] = '\\'; + buffer[bufpos++] = string++[0]; + } + else + { + context = null_context; + state = initial; + } + break; + default: + buffer[bufpos++] = c; + break; + } + break; + case barekey: + if (c == '_' || (c >= '0' && c <= '9') || c >= 0x80 + || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) + { + buffer[bufpos++] = c; + break; + } + else if (is_whitespace (c)) + { + state = wait_rbrace; + break; + } + else if (c != '}') + { + context = null_context; + state = initial; + break; + } + /* Must be right brace. */ + /* FALLTHROUGH */ + case wait_rbrace: + switch (c) + { + case_whitespace: + break; + case '}': + buffer[bufpos] = '\0'; + token.string = xstrdup (buffer); + extract_quotelike_pass3 (&token, EXIT_FAILURE); + xgettext_current_source_encoding = po_charset_utf8; + remember_a_message (mlp, NULL, token.string, context, &pos, + NULL, savable_comment); + xgettext_current_source_encoding = xgettext_global_source_encoding; + /* FALLTHROUGH */ + default: + context = null_context; + state = initial; + break; + } + break; + } } } @@ -2022,531 +2022,531 @@ x_perl_prelex (message_list_ty *mlp, token_ty *tp) tp->line_number = line_number; switch (c) - { - case EOF: - tp->type = token_type_eof; - return; - - case '\n': - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - /* FALLTHROUGH */ - case '\t': - case ' ': - /* Ignore whitespace. */ - continue; - - case '%': - case '@': - case '*': - case '$': - if (!extract_all) - { - extract_variable (mlp, tp, c); - prefer_division_over_regexp = true; - return; - } - break; - } + { + case EOF: + tp->type = token_type_eof; + return; + + case '\n': + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + /* FALLTHROUGH */ + case '\t': + case ' ': + /* Ignore whitespace. */ + continue; + + case '%': + case '@': + case '*': + case '$': + if (!extract_all) + { + extract_variable (mlp, tp, c); + prefer_division_over_regexp = true; + return; + } + break; + } last_non_comment_line = tp->line_number; switch (c) - { - case '.': - { - int c2 = phase1_getc (); - phase1_ungetc (c2); - if (c2 == '.') - { - tp->type = token_type_other; - prefer_division_over_regexp = false; - return; - } - else if (c2 >= '0' && c2 <= '9') - { - prefer_division_over_regexp = false; - } - else - { - tp->type = token_type_dot; - prefer_division_over_regexp = true; - return; - } - } - /* FALLTHROUGH */ - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - /* Symbol, or part of a number. */ - prefer_division_over_regexp = true; - bufpos = 0; - for (;;) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase1_getc (); - switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - continue; - - default: - phase1_ungetc (c); - break; - } - break; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = '\0'; - - if (strcmp (buffer, "__END__") == 0 - || strcmp (buffer, "__DATA__") == 0) - { - end_of_file = true; - tp->type = token_type_eof; - return; - } - else if (strcmp (buffer, "and") == 0 - || strcmp (buffer, "cmp") == 0 - || strcmp (buffer, "eq") == 0 - || strcmp (buffer, "if") == 0 - || strcmp (buffer, "ge") == 0 - || strcmp (buffer, "gt") == 0 - || strcmp (buffer, "le") == 0 - || strcmp (buffer, "lt") == 0 - || strcmp (buffer, "ne") == 0 - || strcmp (buffer, "not") == 0 - || strcmp (buffer, "or") == 0 - || strcmp (buffer, "unless") == 0 - || strcmp (buffer, "while") == 0 - || strcmp (buffer, "xor") == 0) - { - tp->type = token_type_named_op; - tp->string = xstrdup (buffer); - prefer_division_over_regexp = false; - return; - } - else if (strcmp (buffer, "s") == 0 - || strcmp (buffer, "y") == 0 - || strcmp (buffer, "tr") == 0) - { - int delim = phase1_getc (); - - while (is_whitespace (delim)) - delim = phase2_getc (); - - if (delim == EOF) - { - tp->type = token_type_eof; - return; - } - if ((delim >= '0' && delim <= '9') - || (delim >= 'A' && delim <= 'Z') - || (delim >= 'a' && delim <= 'z')) - { - /* False positive. */ - phase2_ungetc (delim); - tp->type = token_type_symbol; - tp->sub_type = symbol_type_none; - tp->string = xstrdup (buffer); - prefer_division_over_regexp = true; - return; - } - extract_triple_quotelike (mlp, tp, delim, - buffer[0] == 's' && delim != '\''); - - /* Eat the following modifiers. */ - do - c = phase1_getc (); - while (c >= 'a' && c <= 'z'); - phase1_ungetc (c); - return; - } - else if (strcmp (buffer, "m") == 0) - { - int delim = phase1_getc (); - - while (is_whitespace (delim)) - delim = phase2_getc (); - - if (delim == EOF) - { - tp->type = token_type_eof; - return; - } - if ((delim >= '0' && delim <= '9') - || (delim >= 'A' && delim <= 'Z') - || (delim >= 'a' && delim <= 'z')) - { - /* False positive. */ - phase2_ungetc (delim); - tp->type = token_type_symbol; - tp->sub_type = symbol_type_none; - tp->string = xstrdup (buffer); - prefer_division_over_regexp = true; - return; - } - extract_quotelike (tp, delim); - if (delim != '\'') - interpolate_keywords (mlp, tp->string, line_number); - free (tp->string); - drop_reference (tp->comment); - tp->type = token_type_regex_op; - prefer_division_over_regexp = true; - - /* Eat the following modifiers. */ - do - c = phase1_getc (); - while (c >= 'a' && c <= 'z'); - phase1_ungetc (c); - return; - } - else if (strcmp (buffer, "qq") == 0 - || strcmp (buffer, "q") == 0 - || strcmp (buffer, "qx") == 0 - || strcmp (buffer, "qw") == 0 - || strcmp (buffer, "qr") == 0) - { - /* The qw (...) construct is not really a string but we - can treat in the same manner and then pretend it is - a symbol. Rationale: Saying "qw (foo bar)" is the - same as "my @list = ('foo', 'bar'); @list;". */ - - int delim = phase1_getc (); - - while (is_whitespace (delim)) - delim = phase2_getc (); - - if (delim == EOF) - { - tp->type = token_type_eof; - return; - } - prefer_division_over_regexp = true; - - if ((delim >= '0' && delim <= '9') - || (delim >= 'A' && delim <= 'Z') - || (delim >= 'a' && delim <= 'z')) - { - /* False positive. */ - phase2_ungetc (delim); - tp->type = token_type_symbol; - tp->sub_type = symbol_type_none; - tp->string = xstrdup (buffer); - prefer_division_over_regexp = true; - return; - } - - extract_quotelike (tp, delim); - - switch (buffer[1]) - { - case 'q': - case 'x': - tp->type = token_type_string; - tp->sub_type = string_type_qq; - interpolate_keywords (mlp, tp->string, line_number); - break; - case 'r': - drop_reference (tp->comment); - tp->type = token_type_regex_op; - break; - case 'w': - drop_reference (tp->comment); - tp->type = token_type_symbol; - tp->sub_type = symbol_type_none; - break; - case '\0': - tp->type = token_type_string; - tp->sub_type = string_type_q; - break; - default: - abort (); - } - return; - } - else if (strcmp (buffer, "grep") == 0 - || strcmp (buffer, "split") == 0) - { - prefer_division_over_regexp = false; - } - tp->type = token_type_symbol; - tp->sub_type = (strcmp (buffer, "sub") == 0 - ? symbol_type_sub - : symbol_type_none); - tp->string = xstrdup (buffer); - return; - - case '"': - prefer_division_over_regexp = true; - extract_quotelike (tp, c); - tp->sub_type = string_type_qq; - interpolate_keywords (mlp, tp->string, line_number); - return; - - case '`': - prefer_division_over_regexp = true; - extract_quotelike (tp, c); - tp->sub_type = string_type_qq; - interpolate_keywords (mlp, tp->string, line_number); - return; - - case '\'': - prefer_division_over_regexp = true; - extract_quotelike (tp, c); - tp->sub_type = string_type_q; - return; - - case '(': - c = phase2_getc (); - if (c == ')') - /* Ignore empty list. */ - continue; - else - phase2_ungetc (c); - tp->type = token_type_lparen; - prefer_division_over_regexp = false; - return; - - case ')': - tp->type = token_type_rparen; - prefer_division_over_regexp = true; - return; - - case '{': - tp->type = token_type_lbrace; - prefer_division_over_regexp = false; - return; - - case '}': - tp->type = token_type_rbrace; - prefer_division_over_regexp = false; - return; - - case '[': - tp->type = token_type_lbracket; - prefer_division_over_regexp = false; - return; - - case ']': - tp->type = token_type_rbracket; - prefer_division_over_regexp = false; - return; - - case ';': - tp->type = token_type_semicolon; - prefer_division_over_regexp = false; - return; - - case ',': - tp->type = token_type_comma; - prefer_division_over_regexp = false; - return; - - case '=': - /* Check for fat comma. */ - c = phase1_getc (); - if (c == '>') - { - tp->type = token_type_fat_comma; - return; - } - else if (linepos == 2 - && (last_token == token_type_semicolon - || last_token == token_type_rbrace) - && ((c >= 'A' && c <='Z') - || (c >= 'a' && c <= 'z'))) - { + { + case '.': + { + int c2 = phase1_getc (); + phase1_ungetc (c2); + if (c2 == '.') + { + tp->type = token_type_other; + prefer_division_over_regexp = false; + return; + } + else if (c2 >= '0' && c2 <= '9') + { + prefer_division_over_regexp = false; + } + else + { + tp->type = token_type_dot; + prefer_division_over_regexp = true; + return; + } + } + /* FALLTHROUGH */ + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* Symbol, or part of a number. */ + prefer_division_over_regexp = true; + bufpos = 0; + for (;;) + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase1_getc (); + switch (c) + { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + continue; + + default: + phase1_ungetc (c); + break; + } + break; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = '\0'; + + if (strcmp (buffer, "__END__") == 0 + || strcmp (buffer, "__DATA__") == 0) + { + end_of_file = true; + tp->type = token_type_eof; + return; + } + else if (strcmp (buffer, "and") == 0 + || strcmp (buffer, "cmp") == 0 + || strcmp (buffer, "eq") == 0 + || strcmp (buffer, "if") == 0 + || strcmp (buffer, "ge") == 0 + || strcmp (buffer, "gt") == 0 + || strcmp (buffer, "le") == 0 + || strcmp (buffer, "lt") == 0 + || strcmp (buffer, "ne") == 0 + || strcmp (buffer, "not") == 0 + || strcmp (buffer, "or") == 0 + || strcmp (buffer, "unless") == 0 + || strcmp (buffer, "while") == 0 + || strcmp (buffer, "xor") == 0) + { + tp->type = token_type_named_op; + tp->string = xstrdup (buffer); + prefer_division_over_regexp = false; + return; + } + else if (strcmp (buffer, "s") == 0 + || strcmp (buffer, "y") == 0 + || strcmp (buffer, "tr") == 0) + { + int delim = phase1_getc (); + + while (is_whitespace (delim)) + delim = phase2_getc (); + + if (delim == EOF) + { + tp->type = token_type_eof; + return; + } + if ((delim >= '0' && delim <= '9') + || (delim >= 'A' && delim <= 'Z') + || (delim >= 'a' && delim <= 'z')) + { + /* False positive. */ + phase2_ungetc (delim); + tp->type = token_type_symbol; + tp->sub_type = symbol_type_none; + tp->string = xstrdup (buffer); + prefer_division_over_regexp = true; + return; + } + extract_triple_quotelike (mlp, tp, delim, + buffer[0] == 's' && delim != '\''); + + /* Eat the following modifiers. */ + do + c = phase1_getc (); + while (c >= 'a' && c <= 'z'); + phase1_ungetc (c); + return; + } + else if (strcmp (buffer, "m") == 0) + { + int delim = phase1_getc (); + + while (is_whitespace (delim)) + delim = phase2_getc (); + + if (delim == EOF) + { + tp->type = token_type_eof; + return; + } + if ((delim >= '0' && delim <= '9') + || (delim >= 'A' && delim <= 'Z') + || (delim >= 'a' && delim <= 'z')) + { + /* False positive. */ + phase2_ungetc (delim); + tp->type = token_type_symbol; + tp->sub_type = symbol_type_none; + tp->string = xstrdup (buffer); + prefer_division_over_regexp = true; + return; + } + extract_quotelike (tp, delim); + if (delim != '\'') + interpolate_keywords (mlp, tp->string, line_number); + free (tp->string); + drop_reference (tp->comment); + tp->type = token_type_regex_op; + prefer_division_over_regexp = true; + + /* Eat the following modifiers. */ + do + c = phase1_getc (); + while (c >= 'a' && c <= 'z'); + phase1_ungetc (c); + return; + } + else if (strcmp (buffer, "qq") == 0 + || strcmp (buffer, "q") == 0 + || strcmp (buffer, "qx") == 0 + || strcmp (buffer, "qw") == 0 + || strcmp (buffer, "qr") == 0) + { + /* The qw (...) construct is not really a string but we + can treat in the same manner and then pretend it is + a symbol. Rationale: Saying "qw (foo bar)" is the + same as "my @list = ('foo', 'bar'); @list;". */ + + int delim = phase1_getc (); + + while (is_whitespace (delim)) + delim = phase2_getc (); + + if (delim == EOF) + { + tp->type = token_type_eof; + return; + } + prefer_division_over_regexp = true; + + if ((delim >= '0' && delim <= '9') + || (delim >= 'A' && delim <= 'Z') + || (delim >= 'a' && delim <= 'z')) + { + /* False positive. */ + phase2_ungetc (delim); + tp->type = token_type_symbol; + tp->sub_type = symbol_type_none; + tp->string = xstrdup (buffer); + prefer_division_over_regexp = true; + return; + } + + extract_quotelike (tp, delim); + + switch (buffer[1]) + { + case 'q': + case 'x': + tp->type = token_type_string; + tp->sub_type = string_type_qq; + interpolate_keywords (mlp, tp->string, line_number); + break; + case 'r': + drop_reference (tp->comment); + tp->type = token_type_regex_op; + break; + case 'w': + drop_reference (tp->comment); + tp->type = token_type_symbol; + tp->sub_type = symbol_type_none; + break; + case '\0': + tp->type = token_type_string; + tp->sub_type = string_type_q; + break; + default: + abort (); + } + return; + } + else if (strcmp (buffer, "grep") == 0 + || strcmp (buffer, "split") == 0) + { + prefer_division_over_regexp = false; + } + tp->type = token_type_symbol; + tp->sub_type = (strcmp (buffer, "sub") == 0 + ? symbol_type_sub + : symbol_type_none); + tp->string = xstrdup (buffer); + return; + + case '"': + prefer_division_over_regexp = true; + extract_quotelike (tp, c); + tp->sub_type = string_type_qq; + interpolate_keywords (mlp, tp->string, line_number); + return; + + case '`': + prefer_division_over_regexp = true; + extract_quotelike (tp, c); + tp->sub_type = string_type_qq; + interpolate_keywords (mlp, tp->string, line_number); + return; + + case '\'': + prefer_division_over_regexp = true; + extract_quotelike (tp, c); + tp->sub_type = string_type_q; + return; + + case '(': + c = phase2_getc (); + if (c == ')') + /* Ignore empty list. */ + continue; + else + phase2_ungetc (c); + tp->type = token_type_lparen; + prefer_division_over_regexp = false; + return; + + case ')': + tp->type = token_type_rparen; + prefer_division_over_regexp = true; + return; + + case '{': + tp->type = token_type_lbrace; + prefer_division_over_regexp = false; + return; + + case '}': + tp->type = token_type_rbrace; + prefer_division_over_regexp = false; + return; + + case '[': + tp->type = token_type_lbracket; + prefer_division_over_regexp = false; + return; + + case ']': + tp->type = token_type_rbracket; + prefer_division_over_regexp = false; + return; + + case ';': + tp->type = token_type_semicolon; + prefer_division_over_regexp = false; + return; + + case ',': + tp->type = token_type_comma; + prefer_division_over_regexp = false; + return; + + case '=': + /* Check for fat comma. */ + c = phase1_getc (); + if (c == '>') + { + tp->type = token_type_fat_comma; + return; + } + else if (linepos == 2 + && (last_token == token_type_semicolon + || last_token == token_type_rbrace) + && ((c >= 'A' && c <='Z') + || (c >= 'a' && c <= 'z'))) + { #if DEBUG_PERL - fprintf (stderr, "%s:%d: start pod section\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: start pod section\n", + real_file_name, line_number); #endif - skip_pod (); + skip_pod (); #if DEBUG_PERL - fprintf (stderr, "%s:%d: end pod section\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: end pod section\n", + real_file_name, line_number); #endif - continue; - } - phase1_ungetc (c); - tp->type = token_type_other; - prefer_division_over_regexp = false; - return; - - case '<': - /* Check for <string); - free (tp->string); - tp->string = string; - tp->type = token_type_string; - tp->sub_type = string_type_verbatim; - tp->line_number = line_number + 1; - return; - } - else if (c == '"') - { - char *string; - extract_quotelike (tp, c); - string = get_here_document (tp->string); - free (tp->string); - tp->string = string; - tp->type = token_type_string; - tp->sub_type = string_type_qq; - tp->line_number = line_number + 1; - interpolate_keywords (mlp, tp->string, line_number + 1); - return; - } - else if ((c >= 'A' && c <= 'Z') - || (c >= 'a' && c <= 'z') - || c == '_') - { - bufpos = 0; - while ((c >= 'A' && c <= 'Z') - || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9') - || c == '_' || c >= 0x80) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase1_getc (); - } - if (c == EOF) - { - tp->type = token_type_eof; - return; - } - else - { - char *string; - phase1_ungetc (c); - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = '\0'; - string = get_here_document (buffer); - tp->string = string; - tp->type = token_type_string; - tp->sub_type = string_type_qq; - tp->comment = add_reference (savable_comment); - tp->line_number = line_number + 1; - interpolate_keywords (mlp, tp->string, line_number + 1); - return; - } - } - else - { - tp->type = token_type_other; - return; - } - } - else - { - phase1_ungetc (c); - tp->type = token_type_other; - } - return; /* End of case '>'. */ - - case '-': - /* Check for dereferencing operator. */ - c = phase1_getc (); - if (c == '>') - { - tp->type = token_type_dereference; - return; - } - else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) - { - /* One of the -X (filetest) functions. We play safe - and accept all alphabetical characters here. */ - tp->type = token_type_other; - return; - } - phase1_ungetc (c); - tp->type = token_type_other; - prefer_division_over_regexp = false; - return; - - case '/': - case '?': - if (!prefer_division_over_regexp) - { - extract_quotelike (tp, c); - interpolate_keywords (mlp, tp->string, line_number); - free (tp->string); - drop_reference (tp->comment); - tp->type = token_type_other; - prefer_division_over_regexp = true; - /* Eat the following modifiers. */ - do - c = phase1_getc (); - while (c >= 'a' && c <= 'z'); - phase1_ungetc (c); - return; - } - /* Recognize operator '//'. */ - if (c == '/') - { - c = phase1_getc (); - if (c != '/') - phase1_ungetc (c); - } - /* FALLTHROUGH */ - - default: - /* We could carefully recognize each of the 2 and 3 character - operators, but it is not necessary, except for the '//' operator, - as we only need to recognize gettext invocations. Don't - bother. */ - tp->type = token_type_other; - prefer_division_over_regexp = false; - return; - } + continue; + } + phase1_ungetc (c); + tp->type = token_type_other; + prefer_division_over_regexp = false; + return; + + case '<': + /* Check for <string); + free (tp->string); + tp->string = string; + tp->type = token_type_string; + tp->sub_type = string_type_verbatim; + tp->line_number = line_number + 1; + return; + } + else if (c == '"') + { + char *string; + extract_quotelike (tp, c); + string = get_here_document (tp->string); + free (tp->string); + tp->string = string; + tp->type = token_type_string; + tp->sub_type = string_type_qq; + tp->line_number = line_number + 1; + interpolate_keywords (mlp, tp->string, line_number + 1); + return; + } + else if ((c >= 'A' && c <= 'Z') + || (c >= 'a' && c <= 'z') + || c == '_') + { + bufpos = 0; + while ((c >= 'A' && c <= 'Z') + || (c >= 'a' && c <= 'z') + || (c >= '0' && c <= '9') + || c == '_' || c >= 0x80) + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase1_getc (); + } + if (c == EOF) + { + tp->type = token_type_eof; + return; + } + else + { + char *string; + phase1_ungetc (c); + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = '\0'; + string = get_here_document (buffer); + tp->string = string; + tp->type = token_type_string; + tp->sub_type = string_type_qq; + tp->comment = add_reference (savable_comment); + tp->line_number = line_number + 1; + interpolate_keywords (mlp, tp->string, line_number + 1); + return; + } + } + else + { + tp->type = token_type_other; + return; + } + } + else + { + phase1_ungetc (c); + tp->type = token_type_other; + } + return; /* End of case '>'. */ + + case '-': + /* Check for dereferencing operator. */ + c = phase1_getc (); + if (c == '>') + { + tp->type = token_type_dereference; + return; + } + else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) + { + /* One of the -X (filetest) functions. We play safe + and accept all alphabetical characters here. */ + tp->type = token_type_other; + return; + } + phase1_ungetc (c); + tp->type = token_type_other; + prefer_division_over_regexp = false; + return; + + case '/': + case '?': + if (!prefer_division_over_regexp) + { + extract_quotelike (tp, c); + interpolate_keywords (mlp, tp->string, line_number); + free (tp->string); + drop_reference (tp->comment); + tp->type = token_type_other; + prefer_division_over_regexp = true; + /* Eat the following modifiers. */ + do + c = phase1_getc (); + while (c >= 'a' && c <= 'z'); + phase1_ungetc (c); + return; + } + /* Recognize operator '//'. */ + if (c == '/') + { + c = phase1_getc (); + if (c != '/') + phase1_ungetc (c); + } + /* FALLTHROUGH */ + + default: + /* We could carefully recognize each of the 2 and 3 character + operators, but it is not necessary, except for the '//' operator, + as we only need to recognize gettext invocations. Don't + bother. */ + tp->type = token_type_other; + prefer_division_over_regexp = false; + return; + } } } @@ -2576,14 +2576,14 @@ token_stack_dump (token_stack_ty *stack) token_ty *token = stack->items[i]; fprintf (stderr, " [%s]\n", token2string (token)); switch (token->type) - { - case token_type_named_op: - case token_type_string: - case token_type_symbol: - case token_type_variable: - fprintf (stderr, " string: %s\n", token->string); - break; - } + { + case token_type_named_op: + case token_type_string: + case token_type_symbol: + case token_type_variable: + fprintf (stderr, " string: %s\n", token->string); + break; + } } fprintf (stderr, "END STACK DUMP\n"); return 0; @@ -2653,14 +2653,14 @@ x_perl_lex (message_list_ty *mlp) x_perl_prelex (mlp, tp); #if DEBUG_PERL fprintf (stderr, "%s:%d: x_perl_prelex returned %s\n", - real_file_name, line_number, token2string (tp)); + real_file_name, line_number, token2string (tp)); #endif } #if DEBUG_PERL else { fprintf (stderr, "%s:%d: %s recycled from stack\n", - real_file_name, line_number, token2string (tp)); + real_file_name, line_number, token2string (tp)); } #endif @@ -2673,74 +2673,74 @@ x_perl_lex (message_list_ty *mlp) token_ty *next = token_stack_peek (&token_stack); if (!next) - { + { #if DEBUG_PERL - fprintf (stderr, "%s:%d: pre-fetching next token\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: pre-fetching next token\n", + real_file_name, line_number); #endif - next = x_perl_lex (mlp); - x_perl_unlex (next); + next = x_perl_lex (mlp); + x_perl_unlex (next); #if DEBUG_PERL - fprintf (stderr, "%s:%d: unshifted next token\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: unshifted next token\n", + real_file_name, line_number); #endif - } + } #if DEBUG_PERL fprintf (stderr, "%s:%d: next token is %s\n", - real_file_name, line_number, token2string (next)); + real_file_name, line_number, token2string (next)); #endif if (next->type == token_type_fat_comma) - { - tp->type = token_type_string; - tp->sub_type = string_type_q; - tp->comment = add_reference (savable_comment); + { + tp->type = token_type_string; + tp->sub_type = string_type_q; + tp->comment = add_reference (savable_comment); #if DEBUG_PERL - fprintf (stderr, - "%s:%d: token %s mutated to token_type_string\n", - real_file_name, line_number, token2string (tp)); + fprintf (stderr, + "%s:%d: token %s mutated to token_type_string\n", + real_file_name, line_number, token2string (tp)); #endif - } + } else if (tp->type == token_type_symbol && tp->sub_type == symbol_type_sub - && next->type == token_type_symbol) + && next->type == token_type_symbol) { - /* Start of a function declaration or definition. Mark this - symbol as a function name, so that we can later eat up - possible prototype information. */ + /* Start of a function declaration or definition. Mark this + symbol as a function name, so that we can later eat up + possible prototype information. */ #if DEBUG_PERL - fprintf (stderr, "%s:%d: subroutine declaration/definition '%s'\n", - real_file_name, line_number, next->string); + fprintf (stderr, "%s:%d: subroutine declaration/definition '%s'\n", + real_file_name, line_number, next->string); #endif - next->sub_type = symbol_type_function; - } + next->sub_type = symbol_type_function; + } else if (tp->type == token_type_symbol - && (tp->sub_type == symbol_type_sub - || tp->sub_type == symbol_type_function) - && next->type == token_type_lparen) + && (tp->sub_type == symbol_type_sub + || tp->sub_type == symbol_type_function) + && next->type == token_type_lparen) { - /* For simplicity we simply consume everything up to the - closing parenthesis. Actually only a limited set of - characters is allowed inside parentheses but we leave - complaints to the interpreter and are prepared for - future extensions to the Perl syntax. */ - int c; + /* For simplicity we simply consume everything up to the + closing parenthesis. Actually only a limited set of + characters is allowed inside parentheses but we leave + complaints to the interpreter and are prepared for + future extensions to the Perl syntax. */ + int c; #if DEBUG_PERL - fprintf (stderr, "%s:%d: consuming prototype information\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: consuming prototype information\n", + real_file_name, line_number); #endif - do - { - c = phase1_getc (); + do + { + c = phase1_getc (); #if DEBUG_PERL - fprintf (stderr, " consuming character '%c'\n", c); + fprintf (stderr, " consuming character '%c'\n", c); #endif - } - while (c != EOF && c != ')'); - phase1_ungetc (c); - } + } + while (c != EOF && c != ')'); + phase1_ungetc (c); + } } return tp; @@ -2773,39 +2773,39 @@ collect_message (message_list_ty *mlp, token_ty *tp, int error_level) int c; do - c = phase2_getc (); + c = phase2_getc (); while (is_whitespace (c)); if (c != '.') - { - phase2_ungetc (c); - return string; - } + { + phase2_ungetc (c); + return string; + } do - c = phase2_getc (); + c = phase2_getc (); while (is_whitespace (c)); phase2_ungetc (c); if (c == '"' || c == '\'' || c == '`' - || (!prefer_division_over_regexp && (c == '/' || c == '?')) - || c == 'q') - { - token_ty *qstring = x_perl_lex (mlp); - if (qstring->type != token_type_string) - { - /* assert (qstring->type == token_type_symbol) */ - x_perl_unlex (qstring); - return string; - } - - extract_quotelike_pass3 (qstring, error_level); - len += strlen (qstring->string); - string = xrealloc (string, len); - strcat (string, qstring->string); - free_token (qstring); - } + || (!prefer_division_over_regexp && (c == '/' || c == '?')) + || c == 'q') + { + token_ty *qstring = x_perl_lex (mlp); + if (qstring->type != token_type_string) + { + /* assert (qstring->type == token_type_symbol) */ + x_perl_unlex (qstring); + return string; + } + + extract_quotelike_pass3 (qstring, error_level); + len += strlen (qstring->string); + string = xrealloc (string, len); + strcat (string, qstring->string); + free_token (qstring); + } } } @@ -2886,10 +2886,10 @@ collect_message (message_list_ty *mlp, token_ty *tp, int error_level) static bool extract_balanced (message_list_ty *mlp, - token_type_ty delim, bool eat_delim, bool comma_delim, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - int arg, struct arglist_parser *argparser) + token_type_ty delim, bool eat_delim, bool comma_delim, + flag_context_ty outer_context, + flag_context_list_iterator_ty context_iter, + int arg, struct arglist_parser *argparser) { /* Whether to implicitly assume the next tokens are arguments even without a '('. */ @@ -2908,7 +2908,7 @@ extract_balanced (message_list_ty *mlp, /* Current context. */ flag_context_ty inner_context = inherited_context (outer_context, - flag_context_list_iterator_advance (&context_iter)); + flag_context_list_iterator_advance (&context_iter)); #if DEBUG_PERL static int nesting_level = 0; @@ -2929,474 +2929,474 @@ extract_balanced (message_list_ty *mlp, last_token = tp->type; if (delim == tp->type) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - if (next_argparser != NULL) - free (next_argparser); + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + if (next_argparser != NULL) + free (next_argparser); #if DEBUG_PERL - fprintf (stderr, "%s:%d: extract_balanced finished (%d)\n", - logical_file_name, tp->line_number, --nesting_level); + fprintf (stderr, "%s:%d: extract_balanced finished (%d)\n", + logical_file_name, tp->line_number, --nesting_level); #endif - if (eat_delim) - free_token (tp); - else - /* Preserve the delimiter for the caller. */ - x_perl_unlex (tp); - return false; - } + if (eat_delim) + free_token (tp); + else + /* Preserve the delimiter for the caller. */ + x_perl_unlex (tp); + return false; + } if (comma_delim && tp->type == token_type_comma) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - if (next_argparser != NULL) - free (next_argparser); + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + if (next_argparser != NULL) + free (next_argparser); #if DEBUG_PERL - fprintf (stderr, "%s:%d: extract_balanced finished at comma (%d)\n", - logical_file_name, tp->line_number, --nesting_level); + fprintf (stderr, "%s:%d: extract_balanced finished at comma (%d)\n", + logical_file_name, tp->line_number, --nesting_level); #endif - x_perl_unlex (tp); - return false; - } - + x_perl_unlex (tp); + return false; + } + if (next_is_argument && tp->type != token_type_lparen) - { - /* An argument list starts, even though there is no '('. */ - bool next_comma_delim; - - x_perl_unlex (tp); - - if (next_shapes != NULL) - /* We know something about the function being called. Assume - that it consumes only one argument if no argument number or - total > 1 is specified. */ - { - size_t i; - - next_comma_delim = true; - for (i = 0; i < next_shapes->nshapes; i++) - { - const struct callshape *shape = &next_shapes->shapes[i]; - - if (shape->argnum1 > 1 - || shape->argnum2 > 1 - || shape->argnumc > 1 - || shape->argtotal > 1) - next_comma_delim = false; - } - } - else - /* We know nothing about the function being called. It could be - a function prototyped to take only one argument, or on the other - hand it could be prototyped to take more than one argument or an - arbitrary argument list or it could be unprototyped. Due to - the way the parser works, assuming the first case gives the - best results. */ - next_comma_delim = true; - - if (extract_balanced (mlp, delim, false, next_comma_delim, - inner_context, next_context_iter, - 1, next_argparser)) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return true; - } - - next_is_argument = false; - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - continue; - } + { + /* An argument list starts, even though there is no '('. */ + bool next_comma_delim; + + x_perl_unlex (tp); + + if (next_shapes != NULL) + /* We know something about the function being called. Assume + that it consumes only one argument if no argument number or + total > 1 is specified. */ + { + size_t i; + + next_comma_delim = true; + for (i = 0; i < next_shapes->nshapes; i++) + { + const struct callshape *shape = &next_shapes->shapes[i]; + + if (shape->argnum1 > 1 + || shape->argnum2 > 1 + || shape->argnumc > 1 + || shape->argtotal > 1) + next_comma_delim = false; + } + } + else + /* We know nothing about the function being called. It could be + a function prototyped to take only one argument, or on the other + hand it could be prototyped to take more than one argument or an + arbitrary argument list or it could be unprototyped. Due to + the way the parser works, assuming the first case gives the + best results. */ + next_comma_delim = true; + + if (extract_balanced (mlp, delim, false, next_comma_delim, + inner_context, next_context_iter, + 1, next_argparser)) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return true; + } + + next_is_argument = false; + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + continue; + } switch (tp->type) - { - case token_type_symbol: + { + case token_type_symbol: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type symbol (%d) \"%s\"\n", - logical_file_name, tp->line_number, nesting_level, - tp->string); + fprintf (stderr, "%s:%d: type symbol (%d) \"%s\"\n", + logical_file_name, tp->line_number, nesting_level, + tp->string); #endif - { - void *keyword_value; - - if (hash_find_entry (&keywords, tp->string, strlen (tp->string), - &keyword_value) == 0) - { - const struct callshapes *shapes = - (const struct callshapes *) keyword_value; - - last_token = token_type_keyword_symbol; - next_shapes = shapes; - next_argparser = arglist_parser_alloc (mlp, shapes); - } - else - { - next_shapes = NULL; - next_argparser = arglist_parser_alloc (mlp, NULL); - } - } - next_is_argument = true; - next_context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - tp->string, strlen (tp->string))); - break; - - case token_type_variable: + { + void *keyword_value; + + if (hash_find_entry (&keywords, tp->string, strlen (tp->string), + &keyword_value) == 0) + { + const struct callshapes *shapes = + (const struct callshapes *) keyword_value; + + last_token = token_type_keyword_symbol; + next_shapes = shapes; + next_argparser = arglist_parser_alloc (mlp, shapes); + } + else + { + next_shapes = NULL; + next_argparser = arglist_parser_alloc (mlp, NULL); + } + } + next_is_argument = true; + next_context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + tp->string, strlen (tp->string))); + break; + + case token_type_variable: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type variable (%d) \"%s\"\n", - logical_file_name, tp->line_number, nesting_level, tp->string); + fprintf (stderr, "%s:%d: type variable (%d) \"%s\"\n", + logical_file_name, tp->line_number, nesting_level, tp->string); #endif - prefer_division_over_regexp = true; - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - case token_type_lparen: + prefer_division_over_regexp = true; + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + case token_type_lparen: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type left parenthesis (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type left parenthesis (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - if (next_is_argument) - { - /* Parse the argument list of a function call. */ - if (extract_balanced (mlp, token_type_rparen, true, false, - inner_context, next_context_iter, - 1, next_argparser)) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - return true; - } - next_is_argument = false; - next_argparser = NULL; - } - else - { - /* Parse a parenthesized expression or comma expression. */ - if (extract_balanced (mlp, token_type_rparen, true, false, - inner_context, next_context_iter, - arg, arglist_parser_clone (argparser))) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - if (next_argparser != NULL) - free (next_argparser); - free_token (tp); - return true; - } - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - } - skip_until_comma = true; - next_context_iter = null_context_list_iterator; - break; - - case token_type_rparen: + if (next_is_argument) + { + /* Parse the argument list of a function call. */ + if (extract_balanced (mlp, token_type_rparen, true, false, + inner_context, next_context_iter, + 1, next_argparser)) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + return true; + } + next_is_argument = false; + next_argparser = NULL; + } + else + { + /* Parse a parenthesized expression or comma expression. */ + if (extract_balanced (mlp, token_type_rparen, true, false, + inner_context, next_context_iter, + arg, arglist_parser_clone (argparser))) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + if (next_argparser != NULL) + free (next_argparser); + free_token (tp); + return true; + } + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + } + skip_until_comma = true; + next_context_iter = null_context_list_iterator; + break; + + case token_type_rparen: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type right parenthesis (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type right parenthesis (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - skip_until_comma = true; - next_context_iter = null_context_list_iterator; - break; - - case token_type_comma: - case token_type_fat_comma: + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + skip_until_comma = true; + next_context_iter = null_context_list_iterator; + break; + + case token_type_comma: + case token_type_fat_comma: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type comma (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type comma (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - if (arglist_parser_decidedp (argparser, arg)) - { - /* We have missed the argument. */ - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - argparser = arglist_parser_alloc (mlp, NULL); - arg = 0; - } - arg++; + if (arglist_parser_decidedp (argparser, arg)) + { + /* We have missed the argument. */ + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + argparser = arglist_parser_alloc (mlp, NULL); + arg = 0; + } + arg++; #if DEBUG_PERL - fprintf (stderr, "%s:%d: arg: %d\n", - real_file_name, tp->line_number, arg); + fprintf (stderr, "%s:%d: arg: %d\n", + real_file_name, tp->line_number, arg); #endif - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - skip_until_comma = false; - next_context_iter = passthrough_context_list_iterator; - break; - - case token_type_string: + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + skip_until_comma = false; + next_context_iter = passthrough_context_list_iterator; + break; + + case token_type_string: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type string (%d): \"%s\"\n", - logical_file_name, tp->line_number, nesting_level, - tp->string); + fprintf (stderr, "%s:%d: type string (%d): \"%s\"\n", + logical_file_name, tp->line_number, nesting_level, + tp->string); #endif - if (extract_all) - { - char *string = collect_message (mlp, tp, EXIT_SUCCESS); - lex_pos_ty pos; - - pos.file_name = logical_file_name; - pos.line_number = tp->line_number; - xgettext_current_source_encoding = po_charset_utf8; - remember_a_message (mlp, NULL, string, inner_context, &pos, - NULL, tp->comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; - } - else if (!skip_until_comma) - { - /* Need to collect the complete string, with error checking, - only if the argument ARG is used in ARGPARSER. */ - bool must_collect = false; - { - size_t nalternatives = argparser->nalternatives; - size_t i; - - for (i = 0; i < nalternatives; i++) - { - struct partial_call *cp = &argparser->alternative[i]; - - if (arg == cp->argnumc - || arg == cp->argnum1 || arg == cp->argnum2) - must_collect = true; - } - } - - if (must_collect) - { - char *string = collect_message (mlp, tp, EXIT_FAILURE); - - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, - string, inner_context, - logical_file_name, tp->line_number, - tp->comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; - } - } - - if (arglist_parser_decidedp (argparser, arg)) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - argparser = arglist_parser_alloc (mlp, NULL); - } - - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - case token_type_eof: + if (extract_all) + { + char *string = collect_message (mlp, tp, EXIT_SUCCESS); + lex_pos_ty pos; + + pos.file_name = logical_file_name; + pos.line_number = tp->line_number; + xgettext_current_source_encoding = po_charset_utf8; + remember_a_message (mlp, NULL, string, inner_context, &pos, + NULL, tp->comment); + xgettext_current_source_encoding = xgettext_global_source_encoding; + } + else if (!skip_until_comma) + { + /* Need to collect the complete string, with error checking, + only if the argument ARG is used in ARGPARSER. */ + bool must_collect = false; + { + size_t nalternatives = argparser->nalternatives; + size_t i; + + for (i = 0; i < nalternatives; i++) + { + struct partial_call *cp = &argparser->alternative[i]; + + if (arg == cp->argnumc + || arg == cp->argnum1 || arg == cp->argnum2) + must_collect = true; + } + } + + if (must_collect) + { + char *string = collect_message (mlp, tp, EXIT_FAILURE); + + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_remember (argparser, arg, + string, inner_context, + logical_file_name, tp->line_number, + tp->comment); + xgettext_current_source_encoding = xgettext_global_source_encoding; + } + } + + if (arglist_parser_decidedp (argparser, arg)) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + argparser = arglist_parser_alloc (mlp, NULL); + } + + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + case token_type_eof: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type EOF (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type EOF (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - free_token (tp); - return true; - - case token_type_lbrace: + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + free_token (tp); + return true; + + case token_type_lbrace: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type lbrace (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type lbrace (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - if (extract_balanced (mlp, token_type_rbrace, true, false, - null_context, null_context_list_iterator, - 1, arglist_parser_alloc (mlp, NULL))) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - if (next_argparser != NULL) - free (next_argparser); - free_token (tp); - return true; - } - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - case token_type_rbrace: + if (extract_balanced (mlp, token_type_rbrace, true, false, + null_context, null_context_list_iterator, + 1, arglist_parser_alloc (mlp, NULL))) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + if (next_argparser != NULL) + free (next_argparser); + free_token (tp); + return true; + } + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + case token_type_rbrace: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type rbrace (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type rbrace (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - case token_type_lbracket: + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + case token_type_lbracket: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type lbracket (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type lbracket (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - if (extract_balanced (mlp, token_type_rbracket, true, false, - null_context, null_context_list_iterator, - 1, arglist_parser_alloc (mlp, NULL))) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - if (next_argparser != NULL) - free (next_argparser); - free_token (tp); - return true; - } - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - case token_type_rbracket: + if (extract_balanced (mlp, token_type_rbracket, true, false, + null_context, null_context_list_iterator, + 1, arglist_parser_alloc (mlp, NULL))) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + if (next_argparser != NULL) + free (next_argparser); + free_token (tp); + return true; + } + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + case token_type_rbracket: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type rbracket (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type rbracket (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - case token_type_semicolon: + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + case token_type_semicolon: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type semicolon (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type semicolon (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - /* The ultimate sign. */ - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; - argparser = arglist_parser_alloc (mlp, NULL); - - /* FIXME: Instead of resetting outer_context here, it may be better - to recurse in the next_is_argument handling above, waiting for - the next semicolon or other statement terminator. */ - outer_context = null_context; - context_iter = null_context_list_iterator; - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = passthrough_context_list_iterator; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - break; - - case token_type_dereference: + /* The ultimate sign. */ + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_global_source_encoding; + argparser = arglist_parser_alloc (mlp, NULL); + + /* FIXME: Instead of resetting outer_context here, it may be better + to recurse in the next_is_argument handling above, waiting for + the next semicolon or other statement terminator. */ + outer_context = null_context; + context_iter = null_context_list_iterator; + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = passthrough_context_list_iterator; + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + break; + + case token_type_dereference: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type dereference (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type dereference (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - case token_type_dot: + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + case token_type_dot: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type dot (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type dot (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - case token_type_named_op: + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + case token_type_named_op: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type named operator (%d): %s\n", - logical_file_name, tp->line_number, nesting_level, - tp->string); + fprintf (stderr, "%s:%d: type named operator (%d): %s\n", + logical_file_name, tp->line_number, nesting_level, + tp->string); #endif - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - case token_type_regex_op: + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + case token_type_regex_op: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type regex operator (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type regex operator (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - case token_type_other: + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + case token_type_other: #if DEBUG_PERL - fprintf (stderr, "%s:%d: type other (%d)\n", - logical_file_name, tp->line_number, nesting_level); + fprintf (stderr, "%s:%d: type other (%d)\n", + logical_file_name, tp->line_number, nesting_level); #endif - next_is_argument = false; - if (next_argparser != NULL) - free (next_argparser); - next_argparser = NULL; - next_context_iter = null_context_list_iterator; - break; - - default: - fprintf (stderr, "%s:%d: unknown token type %d\n", - real_file_name, tp->line_number, tp->type); - abort (); - } + next_is_argument = false; + if (next_argparser != NULL) + free (next_argparser); + next_argparser = NULL; + next_context_iter = null_context_list_iterator; + break; + + default: + fprintf (stderr, "%s:%d: unknown token type %d\n", + real_file_name, tp->line_number, tp->type); + abort (); + } free_token (tp); } @@ -3404,8 +3404,8 @@ extract_balanced (message_list_ty *mlp, void extract_perl (FILE *f, const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { message_list_ty *mlp = mdlp->item[0]->messages; @@ -3432,8 +3432,8 @@ extract_perl (FILE *f, const char *real_filename, const char *logical_filename, /* Eat tokens until eof is seen. When extract_balanced returns due to an unbalanced closing brace, just restart it. */ while (!extract_balanced (mlp, token_type_rbrace, true, false, - null_context, null_context_list_iterator, - 1, arglist_parser_alloc (mlp, NULL))) + null_context, null_context_list_iterator, + 1, arglist_parser_alloc (mlp, NULL))) ; fp = NULL; diff --git a/gettext-tools/src/x-perl.h b/gettext-tools/src/x-perl.h index 043121dc5..43ce4055e 100644 --- a/gettext-tools/src/x-perl.h +++ b/gettext-tools/src/x-perl.h @@ -28,20 +28,20 @@ extern "C" { #define EXTENSIONS_PERL \ - { "pl", "perl" }, \ - { "PL", "perl" }, \ - { "pm", "perl" }, \ - { "cgi", "perl" }, \ + { "pl", "perl" }, \ + { "PL", "perl" }, \ + { "pm", "perl" }, \ + { "cgi", "perl" }, \ #define SCANNERS_PERL \ - { "perl", extract_perl, \ - &flag_table_perl, &formatstring_perl, &formatstring_perl_brace }, \ + { "perl", extract_perl, \ + &flag_table_perl, &formatstring_perl, &formatstring_perl_brace }, \ /* Scan a Perl file and add its translatable strings to mdlp. */ extern void extract_perl (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); extern void x_perl_keyword (const char *keyword); extern void x_perl_extract_all (void); diff --git a/gettext-tools/src/x-php.c b/gettext-tools/src/x-php.c index 344c1c5c5..6f731444b 100644 --- a/gettext-tools/src/x-php.c +++ b/gettext-tools/src/x-php.c @@ -76,15 +76,15 @@ x_php_keyword (const char *name) const char *colon; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid C identifier. - A colon means an invalid parse in split_keywordspec(). */ + A colon means an invalid parse in split_keywordspec(). */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); + insert_keyword_callshape (&keywords, name, end - name, &shape); } } @@ -96,7 +96,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_php_keyword ("_"); x_php_keyword ("gettext"); x_php_keyword ("dgettext:2"); @@ -158,12 +158,12 @@ phase1_getc () c = getc (fp); if (c == EOF) - { - if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); - return EOF; - } + { + if (ferror (fp)) + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_file_name); + return EOF; + } } if (c == '\n') @@ -179,10 +179,10 @@ phase1_ungetc (int c) if (c != EOF) { if (c == '\n') - --line_number; + --line_number; if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); + abort (); phase1_pushback[phase1_pushback_length++] = c; } } @@ -199,237 +199,237 @@ skip_html () int c = phase1_getc (); if (c == EOF) - return; + return; if (c == '<') - { - int c2 = phase1_getc (); - - if (c2 == EOF) - break; - - if (c2 == '?') - { - /* - < script language = "php" > - < script language = 'php' > - are always recognized. */ - while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') - c2 = phase1_getc (); - if (c2 != 's' && c2 != 'S') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'c' && c2 != 'C') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'r' && c2 != 'R') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'i' && c2 != 'I') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'p' && c2 != 'P') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 't' && c2 != 'T') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (!(c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r')) - { - phase1_ungetc (c2); - continue; - } - do - c2 = phase1_getc (); - while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r'); - if (c2 != 'l' && c2 != 'L') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'a' && c2 != 'A') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'n' && c2 != 'N') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'g' && c2 != 'G') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'u' && c2 != 'U') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'a' && c2 != 'A') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'g' && c2 != 'G') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'e' && c2 != 'E') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') - c2 = phase1_getc (); - if (c2 != '=') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') - c2 = phase1_getc (); - if (c2 == '"') - { - c2 = phase1_getc (); - if (c2 != 'p') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'h') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'p') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != '"') - { - phase1_ungetc (c2); - continue; - } - } - else if (c2 == '\'') - { - c2 = phase1_getc (); - if (c2 != 'p') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'h') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'p') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != '\'') - { - phase1_ungetc (c2); - continue; - } - } - else - { - if (c2 != 'p') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'h') - { - phase1_ungetc (c2); - continue; - } - c2 = phase1_getc (); - if (c2 != 'p') - { - phase1_ungetc (c2); - continue; - } - } - c2 = phase1_getc (); - while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') - c2 = phase1_getc (); - if (c2 != '>') - { - phase1_ungetc (c2); - continue; - } - return; - } + { + int c2 = phase1_getc (); + + if (c2 == EOF) + break; + + if (c2 == '?') + { + /* + < script language = "php" > + < script language = 'php' > + are always recognized. */ + while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') + c2 = phase1_getc (); + if (c2 != 's' && c2 != 'S') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'c' && c2 != 'C') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'r' && c2 != 'R') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'i' && c2 != 'I') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'p' && c2 != 'P') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 't' && c2 != 'T') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (!(c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r')) + { + phase1_ungetc (c2); + continue; + } + do + c2 = phase1_getc (); + while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r'); + if (c2 != 'l' && c2 != 'L') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'a' && c2 != 'A') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'n' && c2 != 'N') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'g' && c2 != 'G') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'u' && c2 != 'U') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'a' && c2 != 'A') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'g' && c2 != 'G') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'e' && c2 != 'E') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') + c2 = phase1_getc (); + if (c2 != '=') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') + c2 = phase1_getc (); + if (c2 == '"') + { + c2 = phase1_getc (); + if (c2 != 'p') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'h') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'p') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != '"') + { + phase1_ungetc (c2); + continue; + } + } + else if (c2 == '\'') + { + c2 = phase1_getc (); + if (c2 != 'p') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'h') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'p') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != '\'') + { + phase1_ungetc (c2); + continue; + } + } + else + { + if (c2 != 'p') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'h') + { + phase1_ungetc (c2); + continue; + } + c2 = phase1_getc (); + if (c2 != 'p') + { + phase1_ungetc (c2); + continue; + } + } + c2 = phase1_getc (); + while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') + c2 = phase1_getc (); + if (c2 != '>') + { + phase1_ungetc (c2); + continue; + } + return; + } } } @@ -452,63 +452,63 @@ phase2_getc () case '?': case '%': { - int c2 = phase1_getc (); - if (c2 == '>') - { - /* ?> and %> terminate PHP mode and switch back to HTML mode. */ - skip_html (); - return ' '; - } - phase1_ungetc (c2); + int c2 = phase1_getc (); + if (c2 == '>') + { + /* ?> and %> terminate PHP mode and switch back to HTML mode. */ + skip_html (); + return ' '; + } + phase1_ungetc (c2); } break; case '<': { - int c2 = phase1_getc (); - - /* < / script > terminates PHP mode and switches back to HTML mode. */ - while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') - c2 = phase1_getc (); - if (c2 == '/') - { - do - c2 = phase1_getc (); - while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r'); - if (c2 == 's' || c2 == 'S') - { - c2 = phase1_getc (); - if (c2 == 'c' || c2 == 'C') - { - c2 = phase1_getc (); - if (c2 == 'r' || c2 == 'R') - { - c2 = phase1_getc (); - if (c2 == 'i' || c2 == 'I') - { - c2 = phase1_getc (); - if (c2 == 'p' || c2 == 'P') - { - c2 = phase1_getc (); - if (c2 == 't' || c2 == 'T') - { - do - c2 = phase1_getc (); - while (c2 == ' ' || c2 == '\t' - || c2 == '\n' || c2 == '\r'); - if (c2 == '>') - { - skip_html (); - return ' '; - } - } - } - } - } - } - } - } - phase1_ungetc (c2); + int c2 = phase1_getc (); + + /* < / script > terminates PHP mode and switches back to HTML mode. */ + while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') + c2 = phase1_getc (); + if (c2 == '/') + { + do + c2 = phase1_getc (); + while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r'); + if (c2 == 's' || c2 == 'S') + { + c2 = phase1_getc (); + if (c2 == 'c' || c2 == 'C') + { + c2 = phase1_getc (); + if (c2 == 'r' || c2 == 'R') + { + c2 = phase1_getc (); + if (c2 == 'i' || c2 == 'I') + { + c2 = phase1_getc (); + if (c2 == 'p' || c2 == 'P') + { + c2 = phase1_getc (); + if (c2 == 't' || c2 == 'T') + { + do + c2 = phase1_getc (); + while (c2 == ' ' || c2 == '\t' + || c2 == '\n' || c2 == '\r'); + if (c2 == '>') + { + skip_html (); + return ' '; + } + } + } + } + } + } + } + } + phase1_ungetc (c2); } break; } @@ -522,7 +522,7 @@ phase2_ungetc (int c) if (c != EOF) { if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); + abort (); phase2_pushback[phase2_pushback_length++] = c; } } @@ -558,7 +558,7 @@ comment_line_end (size_t chars_to_remove) { buflen -= chars_to_remove; while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { @@ -601,24 +601,24 @@ phase3_getc () comment_start (); lineno = line_number; for (;;) - { - c = phase1_getc (); - if (c == '\n' || c == EOF) - { - comment_line_end (0); - break; - } - if (last_was_qmark && c == '>') - { - comment_line_end (1); - skip_html (); - break; - } - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - last_was_qmark = (c == '?' || c == '%'); - } + { + c = phase1_getc (); + if (c == '\n' || c == EOF) + { + comment_line_end (0); + break; + } + if (last_was_qmark && c == '>') + { + comment_line_end (1); + skip_html (); + break; + } + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + last_was_qmark = (c == '?' || c == '%'); + } last_comment_line = lineno; return '\n'; } @@ -627,89 +627,89 @@ phase3_getc () c = phase1_getc (); switch (c) - { - default: - phase1_ungetc (c); - return '/'; - - case '*': - { - /* C comment. */ - bool last_was_star; - - comment_start (); - lineno = line_number; - last_was_star = false; - for (;;) - { - c = phase1_getc (); - if (c == EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (buflen == 0 && (c == ' ' || c == '\t')) - continue; - comment_add (c); - switch (c) - { - case '\n': - comment_line_end (1); - comment_start (); - lineno = line_number; - last_was_star = false; - continue; - - case '*': - last_was_star = true; - continue; - - case '/': - if (last_was_star) - { - comment_line_end (2); - break; - } - /* FALLTHROUGH */ - - default: - last_was_star = false; - continue; - } - break; - } - last_comment_line = lineno; - return ' '; - } - - case '/': - { - /* C++ comment. */ - bool last_was_qmark = false; - - comment_start (); - lineno = line_number; - for (;;) - { - c = phase1_getc (); - if (c == '\n' || c == EOF) - { - comment_line_end (0); - break; - } - if (last_was_qmark && c == '>') - { - comment_line_end (1); - skip_html (); - break; - } - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - last_was_qmark = (c == '?' || c == '%'); - } - last_comment_line = lineno; - return '\n'; - } - } + { + default: + phase1_ungetc (c); + return '/'; + + case '*': + { + /* C comment. */ + bool last_was_star; + + comment_start (); + lineno = line_number; + last_was_star = false; + for (;;) + { + c = phase1_getc (); + if (c == EOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (buflen == 0 && (c == ' ' || c == '\t')) + continue; + comment_add (c); + switch (c) + { + case '\n': + comment_line_end (1); + comment_start (); + lineno = line_number; + last_was_star = false; + continue; + + case '*': + last_was_star = true; + continue; + + case '/': + if (last_was_star) + { + comment_line_end (2); + break; + } + /* FALLTHROUGH */ + + default: + last_was_star = false; + continue; + } + break; + } + last_comment_line = lineno; + return ' '; + } + + case '/': + { + /* C++ comment. */ + bool last_was_qmark = false; + + comment_start (); + lineno = line_number; + for (;;) + { + c = phase1_getc (); + if (c == '\n' || c == EOF) + { + comment_line_end (0); + break; + } + if (last_was_qmark && c == '>') + { + comment_line_end (1); + skip_html (); + break; + } + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + last_was_qmark = (c == '?' || c == '%'); + } + last_comment_line = lineno; + return '\n'; + } + } } else return c; @@ -722,7 +722,7 @@ phase3_ungetc (int c) if (c != EOF) { if (phase3_pushback_length == SIZEOF (phase3_pushback)) - abort (); + abort (); phase3_pushback[phase3_pushback_length++] = c; } } @@ -735,17 +735,17 @@ phase3_ungetc (int c) enum token_type_ty { token_type_eof, - token_type_lparen, /* ( */ - token_type_rparen, /* ) */ - token_type_comma, /* , */ - token_type_lbracket, /* [ */ - token_type_rbracket, /* ] */ - token_type_dot, /* . */ - token_type_operator1, /* * / % ++ -- */ - token_type_operator2, /* + - ! ~ @ */ - token_type_string_literal, /* "abc" */ - token_type_symbol, /* symbol, number */ - token_type_other /* misc. operator */ + token_type_lparen, /* ( */ + token_type_rparen, /* ) */ + token_type_comma, /* , */ + token_type_lbracket, /* [ */ + token_type_rbracket, /* ] */ + token_type_dot, /* . */ + token_type_operator1, /* * / % ++ -- */ + token_type_operator2, /* + - ! ~ @ */ + token_type_string_literal, /* "abc" */ + token_type_symbol, /* symbol, number */ + token_type_other /* misc. operator */ }; typedef enum token_type_ty token_type_ty; @@ -753,8 +753,8 @@ typedef struct token_ty token_ty; struct token_ty { token_type_ty type; - char *string; /* for token_type_string_literal, token_type_symbol */ - refcounted_string_list_ty *comment; /* for token_type_string_literal */ + char *string; /* for token_type_string_literal, token_type_symbol */ + refcounted_string_list_ty *comment; /* for token_type_string_literal */ int line_number; }; @@ -795,507 +795,507 @@ phase4_get (token_ty *tp) tp->line_number = line_number; c = phase3_getc (); switch (c) - { - case EOF: - tp->type = token_type_eof; - return; - - case '\n': - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - /* FALLTHROUGH */ - case ' ': - case '\t': - case '\r': - /* Ignore whitespace. */ - continue; - } + { + case EOF: + tp->type = token_type_eof; + return; + + case '\n': + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + /* FALLTHROUGH */ + case ' ': + case '\t': + case '\r': + /* Ignore whitespace. */ + continue; + } last_non_comment_line = tp->line_number; switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': - case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': - case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': - case 'V': case 'W': case 'X': case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': - case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': - case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': - case 'v': case 'w': case 'x': case 'y': case 'z': - case 127: case 128: case 129: case 130: case 131: case 132: case 133: - case 134: case 135: case 136: case 137: case 138: case 139: case 140: - case 141: case 142: case 143: case 144: case 145: case 146: case 147: - case 148: case 149: case 150: case 151: case 152: case 153: case 154: - case 155: case 156: case 157: case 158: case 159: case 160: case 161: - case 162: case 163: case 164: case 165: case 166: case 167: case 168: - case 169: case 170: case 171: case 172: case 173: case 174: case 175: - case 176: case 177: case 178: case 179: case 180: case 181: case 182: - case 183: case 184: case 185: case 186: case 187: case 188: case 189: - case 190: case 191: case 192: case 193: case 194: case 195: case 196: - case 197: case 198: case 199: case 200: case 201: case 202: case 203: - case 204: case 205: case 206: case 207: case 208: case 209: case 210: - case 211: case 212: case 213: case 214: case 215: case 216: case 217: - case 218: case 219: case 220: case 221: case 222: case 223: case 224: - case 225: case 226: case 227: case 228: case 229: case 230: case 231: - case 232: case 233: case 234: case 235: case 236: case 237: case 238: - case 239: case 240: case 241: case 242: case 243: case 244: case 245: - case 246: case 247: case 248: case 249: case 250: case 251: case 252: - case 253: case 254: case 255: - bufpos = 0; - for (;;) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase1_getc (); - switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case 127: case 128: case 129: case 130: case 131: case 132: - case 133: case 134: case 135: case 136: case 137: case 138: - case 139: case 140: case 141: case 142: case 143: case 144: - case 145: case 146: case 147: case 148: case 149: case 150: - case 151: case 152: case 153: case 154: case 155: case 156: - case 157: case 158: case 159: case 160: case 161: case 162: - case 163: case 164: case 165: case 166: case 167: case 168: - case 169: case 170: case 171: case 172: case 173: case 174: - case 175: case 176: case 177: case 178: case 179: case 180: - case 181: case 182: case 183: case 184: case 185: case 186: - case 187: case 188: case 189: case 190: case 191: case 192: - case 193: case 194: case 195: case 196: case 197: case 198: - case 199: case 200: case 201: case 202: case 203: case 204: - case 205: case 206: case 207: case 208: case 209: case 210: - case 211: case 212: case 213: case 214: case 215: case 216: - case 217: case 218: case 219: case 220: case 221: case 222: - case 223: case 224: case 225: case 226: case 227: case 228: - case 229: case 230: case 231: case 232: case 233: case 234: - case 235: case 236: case 237: case 238: case 239: case 240: - case 241: case 242: case 243: case 244: case 245: case 246: - case 247: case 248: case 249: case 250: case 251: case 252: - case 253: case 254: case 255: - continue; - - default: - phase1_ungetc (c); - break; - } - break; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = 0; - tp->string = xstrdup (buffer); - tp->type = token_type_symbol; - return; - - case '\'': - /* Single-quoted string literal. */ - bufpos = 0; - for (;;) - { - c = phase1_getc (); - if (c == EOF || c == '\'') - break; - if (c == '\\') - { - c = phase1_getc (); - if (c != '\\' && c != '\'') - { - phase1_ungetc (c); - c = '\\'; - } - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = 0; - tp->type = token_type_string_literal; - tp->string = xstrdup (buffer); - tp->comment = add_reference (savable_comment); - return; - - case '"': - /* Double-quoted string literal. */ - tp->type = token_type_string_literal; - bufpos = 0; - for (;;) - { - c = phase1_getc (); - if (c == EOF || c == '"') - break; - if (c == '$') - { - c = phase1_getc (); - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') - || c == '_' || c == '{' || c >= 0x7f) - { - /* String with variables. */ - tp->type = token_type_other; - continue; - } - phase1_ungetc (c); - c = '$'; - } - if (c == '{') - { - c = phase1_getc (); - if (c == '$') - { - /* String with expressions. */ - tp->type = token_type_other; - continue; - } - phase1_ungetc (c); - c = '{'; - } - if (c == '\\') - { - int n, j; - - c = phase1_getc (); - switch (c) - { - case '"': - case '\\': - case '$': - break; - - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - n = 0; - for (j = 0; j < 3; ++j) - { - n = n * 8 + c - '0'; - c = phase1_getc (); - switch (c) - { - default: - break; - - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - continue; - } - break; - } - phase1_ungetc (c); - c = n; - break; - - case 'x': - n = 0; - for (j = 0; j < 2; ++j) - { - c = phase1_getc (); - switch (c) - { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = n * 16 + c - '0'; - break; - case 'A': case 'B': case 'C': case 'D': case 'E': - case 'F': - n = n * 16 + 10 + c - 'A'; - break; - case 'a': case 'b': case 'c': case 'd': case 'e': - case 'f': - n = n * 16 + 10 + c - 'a'; - break; - default: - phase1_ungetc (c); - c = 0; - break; - } - if (c == 0) - break; - } - if (j == 0) - { - phase1_ungetc ('x'); - c = '\\'; - } - else - c = n; - break; - - case 'n': - c = '\n'; - break; - case 't': - c = '\t'; - break; - case 'r': - c = '\r'; - break; - - default: - phase1_ungetc (c); - c = '\\'; - break; - } - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = 0; - if (tp->type == token_type_string_literal) - { - tp->string = xstrdup (buffer); - tp->comment = add_reference (savable_comment); - } - return; - - case '?': - case '%': - { - int c2 = phase1_getc (); - if (c2 == '>') - { - /* ?> and %> terminate PHP mode and switch back to HTML - mode. */ - skip_html (); - tp->type = token_type_other; - } - else - { - phase1_ungetc (c2); - tp->type = (c == '%' ? token_type_operator1 : token_type_other); - } - return; - } - - case '(': - tp->type = token_type_lparen; - return; - - case ')': - tp->type = token_type_rparen; - return; - - case ',': - tp->type = token_type_comma; - return; - - case '[': - tp->type = token_type_lbracket; - return; - - case ']': - tp->type = token_type_rbracket; - return; - - case '.': - tp->type = token_type_dot; - return; - - case '*': - case '/': - tp->type = token_type_operator1; - return; - - case '+': - case '-': - { - int c2 = phase1_getc (); - if (c2 == c) - /* ++ or -- */ - tp->type = token_type_operator1; - else - /* + or - */ - { - phase1_ungetc (c2); - tp->type = token_type_operator2; - } - return; - } - - case '!': - case '~': - case '@': - tp->type = token_type_operator2; - return; - - case '<': - { - int c2 = phase1_getc (); - if (c2 == '<') - { - int c3 = phase1_getc (); - if (c3 == '<') - { - /* Start of here document. - Parse whitespace, then label, then newline. */ - do - c = phase3_getc (); - while (c == ' ' || c == '\t' || c == '\n' || c == '\r'); - - bufpos = 0; - do - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase3_getc (); - } - while (c != EOF && c != '\n' && c != '\r'); - /* buffer[0..bufpos-1] now contains the label. */ - - /* Now skip the here document. */ - for (;;) - { - c = phase1_getc (); - if (c == EOF) - break; - if (c == '\n' || c == '\r') - { - int bufidx = 0; - - while (bufidx < bufpos) - { - c = phase1_getc (); - if (c == EOF) - break; - if (c != buffer[bufidx]) - { - phase1_ungetc (c); - break; - } - bufidx++; - } - if (bufidx == bufpos) - { - c = phase1_getc (); - if (c != ';') - phase1_ungetc (c); - c = phase1_getc (); - if (c == '\n' || c == '\r') - break; - } - } - } - - /* FIXME: Ideally we should turn the here document into a - string literal if it didn't contain $ substitution. And - we should also respect backslash escape sequences like - in double-quoted strings. */ - tp->type = token_type_other; - return; - } - phase1_ungetc (c3); - } - - /* < / script > terminates PHP mode and switches back to HTML - mode. */ - while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') - c2 = phase1_getc (); - if (c2 == '/') - { - do - c2 = phase1_getc (); - while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r'); - if (c2 == 's' || c2 == 'S') - { - c2 = phase1_getc (); - if (c2 == 'c' || c2 == 'C') - { - c2 = phase1_getc (); - if (c2 == 'r' || c2 == 'R') - { - c2 = phase1_getc (); - if (c2 == 'i' || c2 == 'I') - { - c2 = phase1_getc (); - if (c2 == 'p' || c2 == 'P') - { - c2 = phase1_getc (); - if (c2 == 't' || c2 == 'T') - { - do - c2 = phase1_getc (); - while (c2 == ' ' || c2 == '\t' - || c2 == '\n' || c2 == '\r'); - if (c2 == '>') - { - skip_html (); - } - else - phase1_ungetc (c2); - } - else - phase1_ungetc (c2); - } - else - phase1_ungetc (c2); - } - else - phase1_ungetc (c2); - } - else - phase1_ungetc (c2); - } - else - phase1_ungetc (c2); - } - else - phase1_ungetc (c2); - } - else - phase1_ungetc (c2); - - tp->type = token_type_other; - return; - } - - case '`': - /* Execution operator. */ - default: - /* We could carefully recognize each of the 2 and 3 character - operators, but it is not necessary, as we only need to recognize - gettext invocations. Don't bother. */ - tp->type = token_type_other; - return; - } + { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': + case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': + case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': + case 'V': case 'W': case 'X': case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': + case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': + case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': + case 'v': case 'w': case 'x': case 'y': case 'z': + case 127: case 128: case 129: case 130: case 131: case 132: case 133: + case 134: case 135: case 136: case 137: case 138: case 139: case 140: + case 141: case 142: case 143: case 144: case 145: case 146: case 147: + case 148: case 149: case 150: case 151: case 152: case 153: case 154: + case 155: case 156: case 157: case 158: case 159: case 160: case 161: + case 162: case 163: case 164: case 165: case 166: case 167: case 168: + case 169: case 170: case 171: case 172: case 173: case 174: case 175: + case 176: case 177: case 178: case 179: case 180: case 181: case 182: + case 183: case 184: case 185: case 186: case 187: case 188: case 189: + case 190: case 191: case 192: case 193: case 194: case 195: case 196: + case 197: case 198: case 199: case 200: case 201: case 202: case 203: + case 204: case 205: case 206: case 207: case 208: case 209: case 210: + case 211: case 212: case 213: case 214: case 215: case 216: case 217: + case 218: case 219: case 220: case 221: case 222: case 223: case 224: + case 225: case 226: case 227: case 228: case 229: case 230: case 231: + case 232: case 233: case 234: case 235: case 236: case 237: case 238: + case 239: case 240: case 241: case 242: case 243: case 244: case 245: + case 246: case 247: case 248: case 249: case 250: case 251: case 252: + case 253: case 254: case 255: + bufpos = 0; + for (;;) + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase1_getc (); + switch (c) + { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case 127: case 128: case 129: case 130: case 131: case 132: + case 133: case 134: case 135: case 136: case 137: case 138: + case 139: case 140: case 141: case 142: case 143: case 144: + case 145: case 146: case 147: case 148: case 149: case 150: + case 151: case 152: case 153: case 154: case 155: case 156: + case 157: case 158: case 159: case 160: case 161: case 162: + case 163: case 164: case 165: case 166: case 167: case 168: + case 169: case 170: case 171: case 172: case 173: case 174: + case 175: case 176: case 177: case 178: case 179: case 180: + case 181: case 182: case 183: case 184: case 185: case 186: + case 187: case 188: case 189: case 190: case 191: case 192: + case 193: case 194: case 195: case 196: case 197: case 198: + case 199: case 200: case 201: case 202: case 203: case 204: + case 205: case 206: case 207: case 208: case 209: case 210: + case 211: case 212: case 213: case 214: case 215: case 216: + case 217: case 218: case 219: case 220: case 221: case 222: + case 223: case 224: case 225: case 226: case 227: case 228: + case 229: case 230: case 231: case 232: case 233: case 234: + case 235: case 236: case 237: case 238: case 239: case 240: + case 241: case 242: case 243: case 244: case 245: case 246: + case 247: case 248: case 249: case 250: case 251: case 252: + case 253: case 254: case 255: + continue; + + default: + phase1_ungetc (c); + break; + } + break; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = 0; + tp->string = xstrdup (buffer); + tp->type = token_type_symbol; + return; + + case '\'': + /* Single-quoted string literal. */ + bufpos = 0; + for (;;) + { + c = phase1_getc (); + if (c == EOF || c == '\'') + break; + if (c == '\\') + { + c = phase1_getc (); + if (c != '\\' && c != '\'') + { + phase1_ungetc (c); + c = '\\'; + } + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = 0; + tp->type = token_type_string_literal; + tp->string = xstrdup (buffer); + tp->comment = add_reference (savable_comment); + return; + + case '"': + /* Double-quoted string literal. */ + tp->type = token_type_string_literal; + bufpos = 0; + for (;;) + { + c = phase1_getc (); + if (c == EOF || c == '"') + break; + if (c == '$') + { + c = phase1_getc (); + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') + || c == '_' || c == '{' || c >= 0x7f) + { + /* String with variables. */ + tp->type = token_type_other; + continue; + } + phase1_ungetc (c); + c = '$'; + } + if (c == '{') + { + c = phase1_getc (); + if (c == '$') + { + /* String with expressions. */ + tp->type = token_type_other; + continue; + } + phase1_ungetc (c); + c = '{'; + } + if (c == '\\') + { + int n, j; + + c = phase1_getc (); + switch (c) + { + case '"': + case '\\': + case '$': + break; + + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + n = 0; + for (j = 0; j < 3; ++j) + { + n = n * 8 + c - '0'; + c = phase1_getc (); + switch (c) + { + default: + break; + + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + continue; + } + break; + } + phase1_ungetc (c); + c = n; + break; + + case 'x': + n = 0; + for (j = 0; j < 2; ++j) + { + c = phase1_getc (); + switch (c) + { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + n = n * 16 + c - '0'; + break; + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': + n = n * 16 + 10 + c - 'A'; + break; + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': + n = n * 16 + 10 + c - 'a'; + break; + default: + phase1_ungetc (c); + c = 0; + break; + } + if (c == 0) + break; + } + if (j == 0) + { + phase1_ungetc ('x'); + c = '\\'; + } + else + c = n; + break; + + case 'n': + c = '\n'; + break; + case 't': + c = '\t'; + break; + case 'r': + c = '\r'; + break; + + default: + phase1_ungetc (c); + c = '\\'; + break; + } + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = 0; + if (tp->type == token_type_string_literal) + { + tp->string = xstrdup (buffer); + tp->comment = add_reference (savable_comment); + } + return; + + case '?': + case '%': + { + int c2 = phase1_getc (); + if (c2 == '>') + { + /* ?> and %> terminate PHP mode and switch back to HTML + mode. */ + skip_html (); + tp->type = token_type_other; + } + else + { + phase1_ungetc (c2); + tp->type = (c == '%' ? token_type_operator1 : token_type_other); + } + return; + } + + case '(': + tp->type = token_type_lparen; + return; + + case ')': + tp->type = token_type_rparen; + return; + + case ',': + tp->type = token_type_comma; + return; + + case '[': + tp->type = token_type_lbracket; + return; + + case ']': + tp->type = token_type_rbracket; + return; + + case '.': + tp->type = token_type_dot; + return; + + case '*': + case '/': + tp->type = token_type_operator1; + return; + + case '+': + case '-': + { + int c2 = phase1_getc (); + if (c2 == c) + /* ++ or -- */ + tp->type = token_type_operator1; + else + /* + or - */ + { + phase1_ungetc (c2); + tp->type = token_type_operator2; + } + return; + } + + case '!': + case '~': + case '@': + tp->type = token_type_operator2; + return; + + case '<': + { + int c2 = phase1_getc (); + if (c2 == '<') + { + int c3 = phase1_getc (); + if (c3 == '<') + { + /* Start of here document. + Parse whitespace, then label, then newline. */ + do + c = phase3_getc (); + while (c == ' ' || c == '\t' || c == '\n' || c == '\r'); + + bufpos = 0; + do + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase3_getc (); + } + while (c != EOF && c != '\n' && c != '\r'); + /* buffer[0..bufpos-1] now contains the label. */ + + /* Now skip the here document. */ + for (;;) + { + c = phase1_getc (); + if (c == EOF) + break; + if (c == '\n' || c == '\r') + { + int bufidx = 0; + + while (bufidx < bufpos) + { + c = phase1_getc (); + if (c == EOF) + break; + if (c != buffer[bufidx]) + { + phase1_ungetc (c); + break; + } + bufidx++; + } + if (bufidx == bufpos) + { + c = phase1_getc (); + if (c != ';') + phase1_ungetc (c); + c = phase1_getc (); + if (c == '\n' || c == '\r') + break; + } + } + } + + /* FIXME: Ideally we should turn the here document into a + string literal if it didn't contain $ substitution. And + we should also respect backslash escape sequences like + in double-quoted strings. */ + tp->type = token_type_other; + return; + } + phase1_ungetc (c3); + } + + /* < / script > terminates PHP mode and switches back to HTML + mode. */ + while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') + c2 = phase1_getc (); + if (c2 == '/') + { + do + c2 = phase1_getc (); + while (c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r'); + if (c2 == 's' || c2 == 'S') + { + c2 = phase1_getc (); + if (c2 == 'c' || c2 == 'C') + { + c2 = phase1_getc (); + if (c2 == 'r' || c2 == 'R') + { + c2 = phase1_getc (); + if (c2 == 'i' || c2 == 'I') + { + c2 = phase1_getc (); + if (c2 == 'p' || c2 == 'P') + { + c2 = phase1_getc (); + if (c2 == 't' || c2 == 'T') + { + do + c2 = phase1_getc (); + while (c2 == ' ' || c2 == '\t' + || c2 == '\n' || c2 == '\r'); + if (c2 == '>') + { + skip_html (); + } + else + phase1_ungetc (c2); + } + else + phase1_ungetc (c2); + } + else + phase1_ungetc (c2); + } + else + phase1_ungetc (c2); + } + else + phase1_ungetc (c2); + } + else + phase1_ungetc (c2); + } + else + phase1_ungetc (c2); + } + else + phase1_ungetc (c2); + + tp->type = token_type_other; + return; + } + + case '`': + /* Execution operator. */ + default: + /* We could carefully recognize each of the 2 and 3 character + operators, but it is not necessary, as we only need to recognize + gettext invocations. Don't bother. */ + tp->type = token_type_other; + return; + } } } @@ -1306,7 +1306,7 @@ phase4_unget (token_ty *tp) if (tp->type != token_type_eof) { if (phase4_pushback_length == SIZEOF (phase4_pushback)) - abort (); + abort (); phase4_pushback[phase4_pushback_length++] = *tp; } } @@ -1333,49 +1333,49 @@ x_php_lex (token_ty *tp) phase4_get (tp); if (tp->type == token_type_string_literal && !(phase5_last == token_type_dot - || phase5_last == token_type_operator1 - || phase5_last == token_type_operator2 - || phase5_last == token_type_rparen)) + || phase5_last == token_type_operator1 + || phase5_last == token_type_operator2 + || phase5_last == token_type_rparen)) { char *sum = tp->string; size_t sum_len = strlen (sum); for (;;) - { - token_ty token2; - - phase4_get (&token2); - if (token2.type == token_type_dot) - { - token_ty token3; - - phase4_get (&token3); - if (token3.type == token_type_string_literal) - { - token_ty token_after; - - phase4_get (&token_after); - if (token_after.type != token_type_operator1) - { - char *addend = token3.string; - size_t addend_len = strlen (addend); - - sum = (char *) xrealloc (sum, sum_len + addend_len + 1); - memcpy (sum + sum_len, addend, addend_len + 1); - sum_len += addend_len; - - phase4_unget (&token_after); - free_token (&token3); - free_token (&token2); - continue; - } - phase4_unget (&token_after); - } - phase4_unget (&token3); - } - phase4_unget (&token2); - break; - } + { + token_ty token2; + + phase4_get (&token2); + if (token2.type == token_type_dot) + { + token_ty token3; + + phase4_get (&token3); + if (token3.type == token_type_string_literal) + { + token_ty token_after; + + phase4_get (&token_after); + if (token_after.type != token_type_operator1) + { + char *addend = token3.string; + size_t addend_len = strlen (addend); + + sum = (char *) xrealloc (sum, sum_len + addend_len + 1); + memcpy (sum + sum_len, addend, addend_len + 1); + sum_len += addend_len; + + phase4_unget (&token_after); + free_token (&token3); + free_token (&token2); + continue; + } + phase4_unget (&token_after); + } + phase4_unget (&token3); + } + phase4_unget (&token2); + break; + } tp->string = sum; } phase5_last = tp->type; @@ -1411,10 +1411,10 @@ static flag_context_list_table_ty *flag_context_list_table; Return true upon eof, false upon closing parenthesis or bracket. */ static bool extract_balanced (message_list_ty *mlp, - token_type_ty delim, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - struct arglist_parser *argparser) + token_type_ty delim, + flag_context_ty outer_context, + flag_context_list_iterator_ty context_iter, + struct arglist_parser *argparser) { /* Current argument number. */ int arg = 1; @@ -1428,7 +1428,7 @@ extract_balanced (message_list_ty *mlp, /* Current context. */ flag_context_ty inner_context = inherited_context (outer_context, - flag_context_list_iterator_advance (&context_iter)); + flag_context_list_iterator_advance (&context_iter)); /* Start state is 0. */ state = 0; @@ -1439,128 +1439,128 @@ extract_balanced (message_list_ty *mlp, x_php_lex (&token); switch (token.type) - { - case token_type_symbol: - { - void *keyword_value; - - if (hash_find_entry (&keywords, token.string, strlen (token.string), - &keyword_value) - == 0) - { - next_shapes = (const struct callshapes *) keyword_value; - state = 1; - } - else - state = 0; - } - next_context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - token.string, strlen (token.string))); - free (token.string); - continue; - - case token_type_lparen: - if (extract_balanced (mlp, token_type_rparen, - inner_context, next_context_iter, - arglist_parser_alloc (mlp, - state ? next_shapes : NULL))) - { - arglist_parser_done (argparser, arg); - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rparen: - if (delim == token_type_rparen || delim == token_type_eof) - { - arglist_parser_done (argparser, arg); - return false; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_comma: - arg++; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_context_iter = passthrough_context_list_iterator; - state = 0; - continue; - - case token_type_lbracket: - if (extract_balanced (mlp, token_type_rbracket, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) - { - arglist_parser_done (argparser, arg); - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rbracket: - if (delim == token_type_rbracket || delim == token_type_eof) - { - arglist_parser_done (argparser, arg); - return false; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_string_literal: - { - lex_pos_ty pos; - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - - if (extract_all) - remember_a_message (mlp, NULL, token.string, inner_context, - &pos, NULL, token.comment); - else - arglist_parser_remember (argparser, arg, token.string, - inner_context, - pos.file_name, pos.line_number, - token.comment); - drop_reference (token.comment); - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_dot: - case token_type_operator1: - case token_type_operator2: - case token_type_other: - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_eof: - arglist_parser_done (argparser, arg); - return true; - - default: - abort (); - } + { + case token_type_symbol: + { + void *keyword_value; + + if (hash_find_entry (&keywords, token.string, strlen (token.string), + &keyword_value) + == 0) + { + next_shapes = (const struct callshapes *) keyword_value; + state = 1; + } + else + state = 0; + } + next_context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + token.string, strlen (token.string))); + free (token.string); + continue; + + case token_type_lparen: + if (extract_balanced (mlp, token_type_rparen, + inner_context, next_context_iter, + arglist_parser_alloc (mlp, + state ? next_shapes : NULL))) + { + arglist_parser_done (argparser, arg); + return true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_rparen: + if (delim == token_type_rparen || delim == token_type_eof) + { + arglist_parser_done (argparser, arg); + return false; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_comma: + arg++; + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + next_context_iter = passthrough_context_list_iterator; + state = 0; + continue; + + case token_type_lbracket: + if (extract_balanced (mlp, token_type_rbracket, + null_context, null_context_list_iterator, + arglist_parser_alloc (mlp, NULL))) + { + arglist_parser_done (argparser, arg); + return true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_rbracket: + if (delim == token_type_rbracket || delim == token_type_eof) + { + arglist_parser_done (argparser, arg); + return false; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_string_literal: + { + lex_pos_ty pos; + pos.file_name = logical_file_name; + pos.line_number = token.line_number; + + if (extract_all) + remember_a_message (mlp, NULL, token.string, inner_context, + &pos, NULL, token.comment); + else + arglist_parser_remember (argparser, arg, token.string, + inner_context, + pos.file_name, pos.line_number, + token.comment); + drop_reference (token.comment); + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_dot: + case token_type_operator1: + case token_type_operator2: + case token_type_other: + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_eof: + arglist_parser_done (argparser, arg); + return true; + + default: + abort (); + } } } void extract_php (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { message_list_ty *mlp = mdlp->item[0]->messages; @@ -1584,8 +1584,8 @@ extract_php (FILE *f, /* Eat tokens until eof is seen. When extract_balanced returns due to an unbalanced closing parenthesis, just restart it. */ while (!extract_balanced (mlp, token_type_eof, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) + null_context, null_context_list_iterator, + arglist_parser_alloc (mlp, NULL))) ; /* Close scanner. */ diff --git a/gettext-tools/src/x-php.h b/gettext-tools/src/x-php.h index aabf1b514..765f3f093 100644 --- a/gettext-tools/src/x-php.h +++ b/gettext-tools/src/x-php.h @@ -28,19 +28,19 @@ extern "C" { #define EXTENSIONS_PHP \ - { "php", "PHP" }, \ - { "php3", "PHP" }, \ - { "php4", "PHP" }, \ + { "php", "PHP" }, \ + { "php3", "PHP" }, \ + { "php4", "PHP" }, \ #define SCANNERS_PHP \ - { "PHP", extract_php, \ - &flag_table_php, &formatstring_php, NULL }, \ + { "PHP", extract_php, \ + &flag_table_php, &formatstring_php, NULL }, \ /* Scan a PHP file and add its translatable strings to mdlp. */ extern void extract_php (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); extern void x_php_keyword (const char *keyword); extern void x_php_extract_all (void); diff --git a/gettext-tools/src/x-po.c b/gettext-tools/src/x-po.c index 50876dd30..aecf59526 100644 --- a/gettext-tools/src/x-po.c +++ b/gettext-tools/src/x-po.c @@ -51,16 +51,16 @@ static char *header_charset; static void extract_add_message (default_catalog_reader_ty *this, - char *msgctxt, - char *msgid, - lex_pos_ty *msgid_pos, - char *msgid_plural, - char *msgstr, size_t msgstr_len, - lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, - char *prev_msgid_plural, - bool force_fuzzy, bool obsolete) + char *msgctxt, + char *msgid, + lex_pos_ty *msgid_pos, + char *msgid_plural, + char *msgstr, size_t msgstr_len, + lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, + char *prev_msgid_plural, + bool force_fuzzy, bool obsolete) { /* See whether we shall exclude this message. */ if (exclude != NULL && message_list_search (exclude, msgctxt, msgid) != NULL) @@ -73,46 +73,46 @@ extract_add_message (default_catalog_reader_ty *this, if (msgctxt == NULL && *msgid == '\0' && !xgettext_omit_header) { { - const char *charsetstr = strstr (msgstr, "charset="); - - if (charsetstr != NULL) - { - size_t len; - char *charset; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - charset = XNMALLOC (len + 1, char); - memcpy (charset, charsetstr, len); - charset[len] = '\0'; - - if (header_charset != NULL) - free (header_charset); - header_charset = charset; - } + const char *charsetstr = strstr (msgstr, "charset="); + + if (charsetstr != NULL) + { + size_t len; + char *charset; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + charset = XNMALLOC (len + 1, char); + memcpy (charset, charsetstr, len); + charset[len] = '\0'; + + if (header_charset != NULL) + free (header_charset); + header_charset = charset; + } } discard: if (msgctxt != NULL) - free (msgctxt); + free (msgctxt); free (msgid); if (msgid_plural != NULL) - free (msgid_plural); + free (msgid_plural); free (msgstr); if (prev_msgctxt != NULL) - free (prev_msgctxt); + free (prev_msgctxt); if (prev_msgid != NULL) - free (prev_msgid); + free (prev_msgid); if (prev_msgid_plural != NULL) - free (prev_msgid_plural); + free (prev_msgid_plural); return; } /* Invoke superclass method. */ default_add_message (this, msgctxt, msgid, msgid_pos, msgid_plural, - msgstr, msgstr_len, msgstr_pos, - prev_msgctxt, prev_msgid, prev_msgid_plural, - force_fuzzy, obsolete); + msgstr, msgstr_len, msgstr_pos, + prev_msgctxt, prev_msgid, prev_msgid_plural, + force_fuzzy, obsolete); } @@ -145,9 +145,9 @@ static default_catalog_reader_class_ty extract_methods = static void extract (FILE *fp, - const char *real_filename, const char *logical_filename, - catalog_input_format_ty input_syntax, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + catalog_input_format_ty input_syntax, + msgdomain_list_ty *mdlp) { default_catalog_reader_ty *pop; @@ -163,46 +163,46 @@ extract (FILE *fp, pop->mdlp = NULL; pop->mlp = mdlp->item[0]->messages; catalog_reader_parse ((abstract_catalog_reader_ty *) pop, fp, real_filename, - logical_filename, input_syntax); + logical_filename, input_syntax); catalog_reader_free ((abstract_catalog_reader_ty *) pop); if (header_charset != NULL) { if (!xgettext_omit_header) - { - /* Put the old charset into the freshly constructed header entry. */ - message_ty *mp = - message_list_search (mdlp->item[0]->messages, NULL, ""); - - if (mp != NULL && !mp->obsolete) - { - const char *header = mp->msgstr; - - if (header != NULL) - { - const char *charsetstr = strstr (header, "charset="); - - if (charsetstr != NULL) - { - size_t len, len1, len2, len3; - char *new_header; - - charsetstr += strlen ("charset="); - len = strcspn (charsetstr, " \t\n"); - - len1 = charsetstr - header; - len2 = strlen (header_charset); - len3 = (header + strlen (header)) - (charsetstr + len); - new_header = XNMALLOC (len1 + len2 + len3 + 1, char); - memcpy (new_header, header, len1); - memcpy (new_header + len1, header_charset, len2); - memcpy (new_header + len1 + len2, charsetstr + len, len3 + 1); - mp->msgstr = new_header; - mp->msgstr_len = len1 + len2 + len3 + 1; - } - } - } - } + { + /* Put the old charset into the freshly constructed header entry. */ + message_ty *mp = + message_list_search (mdlp->item[0]->messages, NULL, ""); + + if (mp != NULL && !mp->obsolete) + { + const char *header = mp->msgstr; + + if (header != NULL) + { + const char *charsetstr = strstr (header, "charset="); + + if (charsetstr != NULL) + { + size_t len, len1, len2, len3; + char *new_header; + + charsetstr += strlen ("charset="); + len = strcspn (charsetstr, " \t\n"); + + len1 = charsetstr - header; + len2 = strlen (header_charset); + len3 = (header + strlen (header)) - (charsetstr + len); + new_header = XNMALLOC (len1 + len2 + len3 + 1, char); + memcpy (new_header, header, len1); + memcpy (new_header + len1, header_charset, len2); + memcpy (new_header + len1 + len2, charsetstr + len, len3 + 1); + mp->msgstr = new_header; + mp->msgstr_len = len1 + len2 + len3 + 1; + } + } + } + } free (header_charset); } @@ -211,9 +211,9 @@ extract (FILE *fp, void extract_po (FILE *fp, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { extract (fp, real_filename, logical_filename, &input_format_po, mdlp); } @@ -221,21 +221,21 @@ extract_po (FILE *fp, void extract_properties (FILE *fp, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { extract (fp, real_filename, logical_filename, &input_format_properties, - mdlp); + mdlp); } void extract_stringtable (FILE *fp, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { extract (fp, real_filename, logical_filename, &input_format_stringtable, - mdlp); + mdlp); } diff --git a/gettext-tools/src/x-po.h b/gettext-tools/src/x-po.h index 3a2d053f1..eda1669a1 100644 --- a/gettext-tools/src/x-po.h +++ b/gettext-tools/src/x-po.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_PO \ - { "po", "PO" }, \ - { "pot", "PO" }, \ + { "po", "PO" }, \ + { "pot", "PO" }, \ #define SCANNERS_PO \ - { "PO", extract_po, NULL, NULL, NULL }, \ + { "PO", extract_po, NULL, NULL, NULL }, \ /* Scan a PO file and add its translatable strings to mdlp. */ extern void extract_po (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); #ifdef __cplusplus diff --git a/gettext-tools/src/x-properties.h b/gettext-tools/src/x-properties.h index 62c5b2723..b877ae4f7 100644 --- a/gettext-tools/src/x-properties.h +++ b/gettext-tools/src/x-properties.h @@ -28,16 +28,16 @@ extern "C" { #define EXTENSIONS_PROPERTIES \ - { "properties", "JavaProperties" }, \ + { "properties", "JavaProperties" }, \ #define SCANNERS_PROPERTIES \ - { "JavaProperties", extract_properties, NULL, NULL, NULL }, \ + { "JavaProperties", extract_properties, NULL, NULL, NULL }, \ /* Scan a JavaProperties file and add its translatable strings to mdlp. */ extern void extract_properties (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); #ifdef __cplusplus diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index 0b364575d..a6e84eb11 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -87,15 +87,15 @@ x_python_keyword (const char *name) const char *colon; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid C identifier. - A colon means an invalid parse in split_keywordspec(). */ + A colon means an invalid parse in split_keywordspec(). */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); + insert_keyword_callshape (&keywords, name, end - name, &shape); } } @@ -107,7 +107,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_python_keyword ("gettext"); x_python_keyword ("ugettext"); x_python_keyword ("dgettext:2"); @@ -169,12 +169,12 @@ phase1_getc () c = getc (fp); if (c == EOF) - { - if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); - return EOF; - } + { + if (ferror (fp)) + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_file_name); + return EOF; + } } if (c == '\n') @@ -190,10 +190,10 @@ phase1_ungetc (int c) if (c != EOF) { if (c == '\n') - --line_number; + --line_number; if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); + abort (); phase1_pushback[phase1_pushback_length++] = c; } } @@ -225,147 +225,147 @@ phase2_getc () { int c = phase1_getc (); if (c == EOF) - return UEOF; + return UEOF; if (!c_isascii (c)) - { - multiline_error (xstrdup (""), - xasprintf ("%s\n%s\n", - non_ascii_error_message (lexical_context, - real_file_name, - line_number), - _("\ + { + multiline_error (xstrdup (""), + xasprintf ("%s\n%s\n", + non_ascii_error_message (lexical_context, + real_file_name, + line_number), + _("\ Please specify the source encoding through --from-code or through a comment\n\ as specified in http://www.python.org/peps/pep-0263.html.\n"))); - exit (EXIT_FAILURE); - } + exit (EXIT_FAILURE); + } return c; } else if (xgettext_current_source_encoding != po_charset_utf8) { #if HAVE_ICONV /* Use iconv on an increasing number of bytes. Read only as many bytes - through phase1_getc as needed. This is needed to give reasonable - interactive behaviour when fp is connected to an interactive tty. */ + through phase1_getc as needed. This is needed to give reasonable + interactive behaviour when fp is connected to an interactive tty. */ unsigned char buf[MAX_PHASE1_PUSHBACK]; size_t bufcount; int c = phase1_getc (); if (c == EOF) - return UEOF; + return UEOF; buf[0] = (unsigned char) c; bufcount = 1; for (;;) - { - unsigned char scratchbuf[6]; - const char *inptr = (const char *) &buf[0]; - size_t insize = bufcount; - char *outptr = (char *) &scratchbuf[0]; - size_t outsize = sizeof (scratchbuf); - - size_t res = iconv (xgettext_current_source_iconv, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - /* We expect that a character has been produced if and only if - some input bytes have been consumed. */ - if ((insize < bufcount) != (outsize < sizeof (scratchbuf))) - abort (); - if (outsize == sizeof (scratchbuf)) - { - /* No character has been produced. Must be an error. */ - if (res != (size_t)(-1)) - abort (); - - if (errno == EILSEQ) - { - /* An invalid multibyte sequence was encountered. */ - multiline_error (xstrdup (""), - xasprintf (_("\ + { + unsigned char scratchbuf[6]; + const char *inptr = (const char *) &buf[0]; + size_t insize = bufcount; + char *outptr = (char *) &scratchbuf[0]; + size_t outsize = sizeof (scratchbuf); + + size_t res = iconv (xgettext_current_source_iconv, + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); + /* We expect that a character has been produced if and only if + some input bytes have been consumed. */ + if ((insize < bufcount) != (outsize < sizeof (scratchbuf))) + abort (); + if (outsize == sizeof (scratchbuf)) + { + /* No character has been produced. Must be an error. */ + if (res != (size_t)(-1)) + abort (); + + if (errno == EILSEQ) + { + /* An invalid multibyte sequence was encountered. */ + multiline_error (xstrdup (""), + xasprintf (_("\ %s:%d: Invalid multibyte sequence.\n\ Please specify the correct source encoding through --from-code or through a\n\ comment as specified in http://www.python.org/peps/pep-0263.html.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - else if (errno == EINVAL) - { - /* An incomplete multibyte character. */ - int c; - - if (bufcount == MAX_PHASE1_PUSHBACK) - { - /* An overlong incomplete multibyte sequence was - encountered. */ - multiline_error (xstrdup (""), - xasprintf (_("\ + real_file_name, line_number)); + exit (EXIT_FAILURE); + } + else if (errno == EINVAL) + { + /* An incomplete multibyte character. */ + int c; + + if (bufcount == MAX_PHASE1_PUSHBACK) + { + /* An overlong incomplete multibyte sequence was + encountered. */ + multiline_error (xstrdup (""), + xasprintf (_("\ %s:%d: Long incomplete multibyte sequence.\n\ Please specify the correct source encoding through --from-code or through a\n\ comment as specified in http://www.python.org/peps/pep-0263.html.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - - /* Read one more byte and retry iconv. */ - c = phase1_getc (); - if (c == EOF) - { - multiline_error (xstrdup (""), - xasprintf (_("\ + real_file_name, line_number)); + exit (EXIT_FAILURE); + } + + /* Read one more byte and retry iconv. */ + c = phase1_getc (); + if (c == EOF) + { + multiline_error (xstrdup (""), + xasprintf (_("\ %s:%d: Incomplete multibyte sequence at end of file.\n\ Please specify the correct source encoding through --from-code or through a\n\ comment as specified in http://www.python.org/peps/pep-0263.html.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - if (c == '\n') - { - multiline_error (xstrdup (""), - xasprintf (_("\ + real_file_name, line_number)); + exit (EXIT_FAILURE); + } + if (c == '\n') + { + multiline_error (xstrdup (""), + xasprintf (_("\ %s:%d: Incomplete multibyte sequence at end of line.\n\ Please specify the correct source encoding through --from-code or through a\n\ comment as specified in http://www.python.org/peps/pep-0263.html.\n"), - real_file_name, line_number - 1)); - exit (EXIT_FAILURE); - } - buf[bufcount++] = (unsigned char) c; - } - else - error (EXIT_FAILURE, errno, _("%s:%d: iconv failure"), - real_file_name, line_number); - } - else - { - size_t outbytes = sizeof (scratchbuf) - outsize; - size_t bytes = bufcount - insize; - ucs4_t uc; - - /* We expect that one character has been produced. */ - if (bytes == 0) - abort (); - if (outbytes == 0) - abort (); - /* Push back the unused bytes. */ - while (insize > 0) - phase1_ungetc (buf[--insize]); - /* Convert the character from UTF-8 to UCS-4. */ - if (u8_mbtouc (&uc, scratchbuf, outbytes) < outbytes) - { - /* scratchbuf contains an out-of-range Unicode character - (> 0x10ffff). */ - multiline_error (xstrdup (""), - xasprintf (_("\ + real_file_name, line_number - 1)); + exit (EXIT_FAILURE); + } + buf[bufcount++] = (unsigned char) c; + } + else + error (EXIT_FAILURE, errno, _("%s:%d: iconv failure"), + real_file_name, line_number); + } + else + { + size_t outbytes = sizeof (scratchbuf) - outsize; + size_t bytes = bufcount - insize; + ucs4_t uc; + + /* We expect that one character has been produced. */ + if (bytes == 0) + abort (); + if (outbytes == 0) + abort (); + /* Push back the unused bytes. */ + while (insize > 0) + phase1_ungetc (buf[--insize]); + /* Convert the character from UTF-8 to UCS-4. */ + if (u8_mbtouc (&uc, scratchbuf, outbytes) < outbytes) + { + /* scratchbuf contains an out-of-range Unicode character + (> 0x10ffff). */ + multiline_error (xstrdup (""), + xasprintf (_("\ %s:%d: Invalid multibyte sequence.\n\ Please specify the source encoding through --from-code or through a comment\n\ as specified in http://www.python.org/peps/pep-0263.html.\n"), - real_file_name, line_number)); - exit (EXIT_FAILURE); - } - return uc; - } - } + real_file_name, line_number)); + exit (EXIT_FAILURE); + } + return uc; + } + } #else /* If we don't have iconv(), the only supported values for - xgettext_global_source_encoding and thus also for - xgettext_current_source_encoding are ASCII and UTF-8. */ + xgettext_global_source_encoding and thus also for + xgettext_current_source_encoding are ASCII and UTF-8. */ abort (); #endif } @@ -379,64 +379,64 @@ as specified in http://www.python.org/peps/pep-0263.html.\n"), c = phase1_getc (); if (c == EOF) - return UEOF; + return UEOF; buf[0] = c; count = 1; if (buf[0] >= 0xc0) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[1] = c; - count = 2; - } + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[1] = c; + count = 2; + } if (buf[0] >= 0xe0 - && ((buf[1] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[2] = c; - count = 3; - } + && ((buf[1] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[2] = c; + count = 3; + } if (buf[0] >= 0xf0 - && ((buf[1] ^ 0x80) < 0x40) - && ((buf[2] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[3] = c; - count = 4; - } + && ((buf[1] ^ 0x80) < 0x40) + && ((buf[2] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[3] = c; + count = 4; + } if (buf[0] >= 0xf8 - && ((buf[1] ^ 0x80) < 0x40) - && ((buf[2] ^ 0x80) < 0x40) - && ((buf[3] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[4] = c; - count = 5; - } + && ((buf[1] ^ 0x80) < 0x40) + && ((buf[2] ^ 0x80) < 0x40) + && ((buf[3] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[4] = c; + count = 5; + } if (buf[0] >= 0xfc - && ((buf[1] ^ 0x80) < 0x40) - && ((buf[2] ^ 0x80) < 0x40) - && ((buf[3] ^ 0x80) < 0x40) - && ((buf[4] ^ 0x80) < 0x40)) - { - c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[5] = c; - count = 6; - } + && ((buf[1] ^ 0x80) < 0x40) + && ((buf[2] ^ 0x80) < 0x40) + && ((buf[3] ^ 0x80) < 0x40) + && ((buf[4] ^ 0x80) < 0x40)) + { + c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[5] = c; + count = 6; + } u8_mbtouc (&uc, buf, count); return uc; @@ -450,7 +450,7 @@ phase2_ungetc (int c) if (c != UEOF) { if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); + abort (); phase2_pushback[phase2_pushback_length++] = c; } } @@ -481,13 +481,13 @@ init_unicode_string_buffer (struct unicode_string_buffer *bp) /* Auxiliary function: Ensure count more bytes are available in bp->utf8. */ static inline void unicode_string_buffer_append_unicode_grow (struct unicode_string_buffer *bp, - size_t count) + size_t count) { if (bp->utf8_buflen + count > bp->utf8_allocated) { size_t new_allocated = 2 * bp->utf8_allocated + 10; if (new_allocated < bp->utf8_buflen + count) - new_allocated = bp->utf8_buflen + count; + new_allocated = bp->utf8_buflen + count; bp->utf8_allocated = new_allocated; bp->utf8_buffer = xrealloc (bp->utf8_buffer, new_allocated); } @@ -497,7 +497,7 @@ unicode_string_buffer_append_unicode_grow (struct unicode_string_buffer *bp, uc must be < 0x110000. */ static inline void unicode_string_buffer_append_unicode (struct unicode_string_buffer *bp, - unsigned int uc) + unsigned int uc) { unsigned char utf8buf[6]; int count = u8_uctomb (utf8buf, uc, 6); @@ -563,7 +563,7 @@ comment_line_end () size_t buflen = strlen (buffer); while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; buffer[buflen] = '\0'; savable_comment_add (buffer); @@ -614,23 +614,23 @@ set_current_file_source_encoding (const char *canon_encoding) /* Avoid glibc-2.1 bug with EUC-KR. */ # if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION if (strcmp (xgettext_current_file_source_encoding, "EUC-KR") == 0) - cd = (iconv_t)(-1); + cd = (iconv_t)(-1); else # endif cd = iconv_open (po_charset_utf8, xgettext_current_file_source_encoding); if (cd == (iconv_t)(-1)) - error_at_line (EXIT_FAILURE, 0, logical_file_name, line_number - 1, _("\ + error_at_line (EXIT_FAILURE, 0, logical_file_name, line_number - 1, _("\ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(), \ and iconv() does not support this conversion."), - xgettext_current_file_source_encoding, po_charset_utf8, - basename (program_name)); + xgettext_current_file_source_encoding, po_charset_utf8, + basename (program_name)); xgettext_current_file_source_iconv = cd; #else error_at_line (EXIT_FAILURE, 0, logical_file_name, line_number - 1, _("\ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(). \ This version was built without iconv()."), - xgettext_global_source_encoding, po_charset_utf8, - basename (program_name)); + xgettext_global_source_encoding, po_charset_utf8, + basename (program_name)); #endif } @@ -649,48 +649,48 @@ try_to_extract_coding (const char *comment) { p += 6; if (*p == ':' || *p == '=') - { - p++; - while (*p == ' ' || *p == '\t') - p++; - { - const char *encoding_start = p; - - while (c_isalnum (*p) || *p == '-' || *p == '_' || *p == '.') - p++; - { - const char *encoding_end = p; - - if (encoding_end > encoding_start) - { - /* Extract the encoding string. */ - size_t encoding_len = encoding_end - encoding_start; - char *encoding = XNMALLOC (encoding_len + 1, char); - - memcpy (encoding, encoding_start, encoding_len); - encoding[encoding_len] = '\0'; - - { - /* Canonicalize it. */ - const char *canon_encoding = po_charset_canonicalize (encoding); - if (canon_encoding == NULL) - { - error_at_line (0, 0, - logical_file_name, line_number - 1, _("\ + { + p++; + while (*p == ' ' || *p == '\t') + p++; + { + const char *encoding_start = p; + + while (c_isalnum (*p) || *p == '-' || *p == '_' || *p == '.') + p++; + { + const char *encoding_end = p; + + if (encoding_end > encoding_start) + { + /* Extract the encoding string. */ + size_t encoding_len = encoding_end - encoding_start; + char *encoding = XNMALLOC (encoding_len + 1, char); + + memcpy (encoding, encoding_start, encoding_len); + encoding[encoding_len] = '\0'; + + { + /* Canonicalize it. */ + const char *canon_encoding = po_charset_canonicalize (encoding); + if (canon_encoding == NULL) + { + error_at_line (0, 0, + logical_file_name, line_number - 1, _("\ Unknown encoding \"%s\". Proceeding with ASCII instead."), - encoding); - canon_encoding = po_charset_ascii; - } - - /* Activate it. */ - set_current_file_source_encoding (canon_encoding); - } - - free (encoding); - } - } - } - } + encoding); + canon_encoding = po_charset_ascii; + } + + /* Activate it. */ + set_current_file_source_encoding (canon_encoding); + } + + free (encoding); + } + } + } + } } } @@ -711,48 +711,48 @@ phase3_getc () { c = phase2_getc (); if (c == '\\') - { - c = phase2_getc (); - if (c != '\n') - { - phase2_ungetc (c); - /* This shouldn't happen usually, because "A backslash is - illegal elsewhere on a line outside a string literal." */ - return '\\'; - } - /* Eat backslash-newline. */ - continuation_or_nonblank_line = true; - } + { + c = phase2_getc (); + if (c != '\n') + { + phase2_ungetc (c); + /* This shouldn't happen usually, because "A backslash is + illegal elsewhere on a line outside a string literal." */ + return '\\'; + } + /* Eat backslash-newline. */ + continuation_or_nonblank_line = true; + } else if (c == '#') - { - /* Eat a comment. */ - const char *comment; - - last_comment_line = line_number; - comment_start (); - for (;;) - { - c = phase2_getc (); - if (c == UEOF || c == '\n') - break; - /* We skip all leading white space, but not EOLs. */ - if (!(comment_at_start () && (c == ' ' || c == '\t'))) - comment_add (c); - } - comment = comment_line_end (); - if (line_number - 1 <= 2 && !continuation_or_nonblank_line) - try_to_extract_coding (comment); - continuation_or_nonblank_line = false; - return c; - } + { + /* Eat a comment. */ + const char *comment; + + last_comment_line = line_number; + comment_start (); + for (;;) + { + c = phase2_getc (); + if (c == UEOF || c == '\n') + break; + /* We skip all leading white space, but not EOLs. */ + if (!(comment_at_start () && (c == ' ' || c == '\t'))) + comment_add (c); + } + comment = comment_line_end (); + if (line_number - 1 <= 2 && !continuation_or_nonblank_line) + try_to_extract_coding (comment); + continuation_or_nonblank_line = false; + return c; + } else - { - if (c == '\n') - continuation_or_nonblank_line = false; - else if (!(c == ' ' || c == '\t' || c == '\f')) - continuation_or_nonblank_line = true; - return c; - } + { + if (c == '\n') + continuation_or_nonblank_line = false; + else if (!(c == ' ' || c == '\t' || c == '\f')) + continuation_or_nonblank_line = true; + return c; + } } } @@ -836,7 +836,7 @@ mixed_string_buffer_append_unicode_grow (struct mixed_string_buffer *bp, size_t { size_t new_allocated = 2 * bp->utf8_allocated + 10; if (new_allocated < bp->utf8_buflen + count) - new_allocated = bp->utf8_buflen + count; + new_allocated = bp->utf8_buflen + count; bp->utf8_allocated = new_allocated; bp->utf8_buffer = xrealloc (bp->utf8_buffer, new_allocated); } @@ -884,7 +884,7 @@ mixed_string_buffer_flush_curr_buffer (struct mixed_string_buffer *bp, int linen /* Convert from the source encoding to UTF-8. */ curr = from_current_source_encoding (bp->curr_buffer, bp->lcontext, - logical_file_name, lineno); + logical_file_name, lineno); /* Append it to bp->utf8_buffer. */ count = strlen (curr); @@ -893,7 +893,7 @@ mixed_string_buffer_flush_curr_buffer (struct mixed_string_buffer *bp, int linen bp->utf8_buflen += count; if (curr != bp->curr_buffer) - free (curr); + free (curr); bp->curr_buflen = 0; } } @@ -910,35 +910,35 @@ mixed_string_buffer_append (struct mixed_string_buffer *bp, int c) mixed_string_buffer_flush_curr_buffer (bp, line_number); /* Test whether this character and the previous one form a Unicode - surrogate character pair. */ + surrogate character pair. */ if (bp->utf16_surr != 0 - && (c >= UNICODE (0xdc00) && c < UNICODE (0xe000))) - { - unsigned short utf16buf[2]; - ucs4_t uc; - - utf16buf[0] = bp->utf16_surr; - utf16buf[1] = UNICODE_VALUE (c); - if (u16_mbtouc (&uc, utf16buf, 2) != 2) - abort (); - - mixed_string_buffer_append_unicode (bp, uc); - bp->utf16_surr = 0; - } + && (c >= UNICODE (0xdc00) && c < UNICODE (0xe000))) + { + unsigned short utf16buf[2]; + ucs4_t uc; + + utf16buf[0] = bp->utf16_surr; + utf16buf[1] = UNICODE_VALUE (c); + if (u16_mbtouc (&uc, utf16buf, 2) != 2) + abort (); + + mixed_string_buffer_append_unicode (bp, uc); + bp->utf16_surr = 0; + } else - { - mixed_string_buffer_flush_utf16_surr (bp); - - if (c >= UNICODE (0xd800) && c < UNICODE (0xdc00)) - bp->utf16_surr = UNICODE_VALUE (c); - else if (c >= UNICODE (0xdc00) && c < UNICODE (0xe000)) - { - /* A half surrogate is invalid, therefore use U+FFFD instead. */ - mixed_string_buffer_append_unicode (bp, 0xfffd); - } - else - mixed_string_buffer_append_unicode (bp, UNICODE_VALUE (c)); - } + { + mixed_string_buffer_flush_utf16_surr (bp); + + if (c >= UNICODE (0xd800) && c < UNICODE (0xdc00)) + bp->utf16_surr = UNICODE_VALUE (c); + else if (c >= UNICODE (0xdc00) && c < UNICODE (0xe000)) + { + /* A half surrogate is invalid, therefore use U+FFFD instead. */ + mixed_string_buffer_append_unicode (bp, 0xfffd); + } + else + mixed_string_buffer_append_unicode (bp, UNICODE_VALUE (c)); + } } else { @@ -948,10 +948,10 @@ mixed_string_buffer_append (struct mixed_string_buffer *bp, int c) mixed_string_buffer_flush_utf16_surr (bp); /* When a newline is seen, convert the accumulated multibyte sequence. - This ensures a correct line number in the error message in case of - a conversion error. The "- 1" is to account for the newline. */ + This ensures a correct line number in the error message in case of + a conversion error. The "- 1" is to account for the newline. */ if (c == '\n') - mixed_string_buffer_flush_curr_buffer (bp, line_number - 1); + mixed_string_buffer_flush_curr_buffer (bp, line_number - 1); mixed_string_buffer_append_byte (bp, (unsigned char) c); } @@ -986,14 +986,14 @@ free_mixed_string_buffer (struct mixed_string_buffer *bp) enum token_type_ty { token_type_eof, - token_type_lparen, /* ( */ - token_type_rparen, /* ) */ - token_type_comma, /* , */ - token_type_lbracket, /* [ */ - token_type_rbracket, /* ] */ - token_type_string, /* "abc", 'abc', """abc""", '''abc''' */ - token_type_symbol, /* symbol, number */ - token_type_other /* misc. operator */ + token_type_lparen, /* ( */ + token_type_rparen, /* ) */ + token_type_comma, /* , */ + token_type_lbracket, /* [ */ + token_type_rbracket, /* ] */ + token_type_string, /* "abc", 'abc', """abc""", '''abc''' */ + token_type_symbol, /* symbol, number */ + token_type_other /* misc. operator */ }; typedef enum token_type_ty token_type_ty; @@ -1001,8 +1001,8 @@ typedef struct token_ty token_ty; struct token_ty { token_type_ty type; - char *string; /* for token_type_string, token_type_symbol */ - refcounted_string_list_ty *comment; /* for token_type_string */ + char *string; /* for token_type_string, token_type_symbol */ + refcounted_string_list_ty *comment; /* for token_type_string */ int line_number; }; @@ -1022,8 +1022,8 @@ struct token_ty static int phase7_getuc (int quote_char, - bool triple, bool interpret_ansic, bool interpret_unicode, - unsigned int *backslash_counter) + bool triple, bool interpret_ansic, bool interpret_unicode, + unsigned int *backslash_counter) { int c; @@ -1033,308 +1033,308 @@ phase7_getuc (int quote_char, c = phase2_getc (); if (c == UEOF) - return P7_EOF; + return P7_EOF; if (c == quote_char && (interpret_ansic || (*backslash_counter & 1) == 0)) - { - if (triple) - { - int c1 = phase2_getc (); - if (c1 == quote_char) - { - int c2 = phase2_getc (); - if (c2 == quote_char) - return P7_STRING_END; - phase2_ungetc (c2); - } - phase2_ungetc (c1); - return UNICODE (c); - } - else - return P7_STRING_END; - } + { + if (triple) + { + int c1 = phase2_getc (); + if (c1 == quote_char) + { + int c2 = phase2_getc (); + if (c2 == quote_char) + return P7_STRING_END; + phase2_ungetc (c2); + } + phase2_ungetc (c1); + return UNICODE (c); + } + else + return P7_STRING_END; + } if (c == '\n') - { - if (triple) - { - *backslash_counter = 0; - return UNICODE ('\n'); - } - /* In r"..." and ur"..." strings, newline is only allowed - immediately after an odd number of backslashes (although the - backslashes are not interpreted!). */ - if (!(interpret_ansic || (*backslash_counter & 1) == 0)) - { - *backslash_counter = 0; - return UNICODE ('\n'); - } - phase2_ungetc (c); - error_with_progname = false; - error (0, 0, _("%s:%d: warning: unterminated string"), - logical_file_name, line_number); - error_with_progname = true; - return P7_STRING_END; - } + { + if (triple) + { + *backslash_counter = 0; + return UNICODE ('\n'); + } + /* In r"..." and ur"..." strings, newline is only allowed + immediately after an odd number of backslashes (although the + backslashes are not interpreted!). */ + if (!(interpret_ansic || (*backslash_counter & 1) == 0)) + { + *backslash_counter = 0; + return UNICODE ('\n'); + } + phase2_ungetc (c); + error_with_progname = false; + error (0, 0, _("%s:%d: warning: unterminated string"), + logical_file_name, line_number); + error_with_progname = true; + return P7_STRING_END; + } if (c != '\\') - { - *backslash_counter = 0; - return UNICODE (c); - } + { + *backslash_counter = 0; + return UNICODE (c); + } /* Backslash handling. */ if (!interpret_ansic && !interpret_unicode) - { - ++*backslash_counter; - return UNICODE ('\\'); - } + { + ++*backslash_counter; + return UNICODE ('\\'); + } /* Dispatch according to the character following the backslash. */ c = phase2_getc (); if (c == UEOF) - { - ++*backslash_counter; - return UNICODE ('\\'); - } + { + ++*backslash_counter; + return UNICODE ('\\'); + } if (interpret_ansic) - switch (c) - { - case '\n': - continue; - case '\\': - ++*backslash_counter; - return UNICODE (c); - case '\'': case '"': - *backslash_counter = 0; - return UNICODE (c); - case 'a': - *backslash_counter = 0; - return UNICODE ('\a'); - case 'b': - *backslash_counter = 0; - return UNICODE ('\b'); - case 'f': - *backslash_counter = 0; - return UNICODE ('\f'); - case 'n': - *backslash_counter = 0; - return UNICODE ('\n'); - case 'r': - *backslash_counter = 0; - return UNICODE ('\r'); - case 't': - *backslash_counter = 0; - return UNICODE ('\t'); - case 'v': - *backslash_counter = 0; - return UNICODE ('\v'); - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': - { - int n = c - '0'; - - c = phase2_getc (); - if (c != UEOF) - { - if (c >= '0' && c <= '7') - { - n = (n << 3) + (c - '0'); - c = phase2_getc (); - if (c != UEOF) - { - if (c >= '0' && c <= '7') - n = (n << 3) + (c - '0'); - else - phase2_ungetc (c); - } - } - else - phase2_ungetc (c); - } - *backslash_counter = 0; - if (interpret_unicode) - return UNICODE (n); - else - return (unsigned char) n; - } - case 'x': - { - int c1 = phase2_getc (); - int n1; - - if (c1 >= '0' && c1 <= '9') - n1 = c1 - '0'; - else if (c1 >= 'A' && c1 <= 'F') - n1 = c1 - 'A' + 10; - else if (c1 >= 'a' && c1 <= 'f') - n1 = c1 - 'a' + 10; - else - n1 = -1; - - if (n1 >= 0) - { - int c2 = phase2_getc (); - int n2; - - if (c2 >= '0' && c2 <= '9') - n2 = c2 - '0'; - else if (c2 >= 'A' && c2 <= 'F') - n2 = c2 - 'A' + 10; - else if (c2 >= 'a' && c2 <= 'f') - n2 = c2 - 'a' + 10; - else - n2 = -1; - - if (n2 >= 0) - { - int n = (n1 << 4) + n2; - *backslash_counter = 0; - if (interpret_unicode) - return UNICODE (n); - else - return (unsigned char) n; - } - - phase2_ungetc (c2); - } - phase2_ungetc (c1); - phase2_ungetc (c); - ++*backslash_counter; - return UNICODE ('\\'); - } - } + switch (c) + { + case '\n': + continue; + case '\\': + ++*backslash_counter; + return UNICODE (c); + case '\'': case '"': + *backslash_counter = 0; + return UNICODE (c); + case 'a': + *backslash_counter = 0; + return UNICODE ('\a'); + case 'b': + *backslash_counter = 0; + return UNICODE ('\b'); + case 'f': + *backslash_counter = 0; + return UNICODE ('\f'); + case 'n': + *backslash_counter = 0; + return UNICODE ('\n'); + case 'r': + *backslash_counter = 0; + return UNICODE ('\r'); + case 't': + *backslash_counter = 0; + return UNICODE ('\t'); + case 'v': + *backslash_counter = 0; + return UNICODE ('\v'); + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + { + int n = c - '0'; + + c = phase2_getc (); + if (c != UEOF) + { + if (c >= '0' && c <= '7') + { + n = (n << 3) + (c - '0'); + c = phase2_getc (); + if (c != UEOF) + { + if (c >= '0' && c <= '7') + n = (n << 3) + (c - '0'); + else + phase2_ungetc (c); + } + } + else + phase2_ungetc (c); + } + *backslash_counter = 0; + if (interpret_unicode) + return UNICODE (n); + else + return (unsigned char) n; + } + case 'x': + { + int c1 = phase2_getc (); + int n1; + + if (c1 >= '0' && c1 <= '9') + n1 = c1 - '0'; + else if (c1 >= 'A' && c1 <= 'F') + n1 = c1 - 'A' + 10; + else if (c1 >= 'a' && c1 <= 'f') + n1 = c1 - 'a' + 10; + else + n1 = -1; + + if (n1 >= 0) + { + int c2 = phase2_getc (); + int n2; + + if (c2 >= '0' && c2 <= '9') + n2 = c2 - '0'; + else if (c2 >= 'A' && c2 <= 'F') + n2 = c2 - 'A' + 10; + else if (c2 >= 'a' && c2 <= 'f') + n2 = c2 - 'a' + 10; + else + n2 = -1; + + if (n2 >= 0) + { + int n = (n1 << 4) + n2; + *backslash_counter = 0; + if (interpret_unicode) + return UNICODE (n); + else + return (unsigned char) n; + } + + phase2_ungetc (c2); + } + phase2_ungetc (c1); + phase2_ungetc (c); + ++*backslash_counter; + return UNICODE ('\\'); + } + } if (interpret_unicode) - { - if (c == 'u') - { - unsigned char buf[4]; - unsigned int n = 0; - int i; - - for (i = 0; i < 4; i++) - { - int c1 = phase2_getc (); - - if (c1 >= '0' && c1 <= '9') - n = (n << 4) + (c1 - '0'); - else if (c1 >= 'A' && c1 <= 'F') - n = (n << 4) + (c1 - 'A' + 10); - else if (c1 >= 'a' && c1 <= 'f') - n = (n << 4) + (c1 - 'a' + 10); - else - { - phase2_ungetc (c1); - while (--i >= 0) - phase2_ungetc (buf[i]); - phase2_ungetc (c); - ++*backslash_counter; - return UNICODE ('\\'); - } - - buf[i] = c1; - } - *backslash_counter = 0; - return UNICODE (n); - } - - if (interpret_ansic) - { - if (c == 'U') - { - unsigned char buf[8]; - unsigned int n = 0; - int i; - - for (i = 0; i < 8; i++) - { - int c1 = phase2_getc (); - - if (c1 >= '0' && c1 <= '9') - n = (n << 4) + (c1 - '0'); - else if (c1 >= 'A' && c1 <= 'F') - n = (n << 4) + (c1 - 'A' + 10); - else if (c1 >= 'a' && c1 <= 'f') - n = (n << 4) + (c1 - 'a' + 10); - else - { - phase2_ungetc (c1); - while (--i >= 0) - phase2_ungetc (buf[i]); - phase2_ungetc (c); - ++*backslash_counter; - return UNICODE ('\\'); - } - - buf[i] = c1; - } - if (n < 0x110000) - { - *backslash_counter = 0; - return UNICODE (n); - } - - error_with_progname = false; - error (0, 0, _("%s:%d: warning: invalid Unicode character"), - logical_file_name, line_number); - error_with_progname = true; - - while (--i >= 0) - phase2_ungetc (buf[i]); - phase2_ungetc (c); - ++*backslash_counter; - return UNICODE ('\\'); - } - - if (c == 'N') - { - int c1 = phase2_getc (); - if (c1 == '{') - { - unsigned char buf[UNINAME_MAX + 1]; - int i; - unsigned int n; - - for (i = 0; i < UNINAME_MAX; i++) - { - int c2 = phase2_getc (); - if (!(c2 >= ' ' && c2 <= '~')) - { - phase2_ungetc (c2); - while (--i >= 0) - phase2_ungetc (buf[i]); - phase2_ungetc (c1); - phase2_ungetc (c); - ++*backslash_counter; - return UNICODE ('\\'); - } - if (c2 == '}') - break; - buf[i] = c2; - } - buf[i] = '\0'; - - n = unicode_name_character ((char *) buf); - if (n != UNINAME_INVALID) - { - *backslash_counter = 0; - return UNICODE (n); - } - - phase2_ungetc ('}'); - while (--i >= 0) - phase2_ungetc (buf[i]); - } - phase2_ungetc (c1); - phase2_ungetc (c); - ++*backslash_counter; - return UNICODE ('\\'); - } - } - } + { + if (c == 'u') + { + unsigned char buf[4]; + unsigned int n = 0; + int i; + + for (i = 0; i < 4; i++) + { + int c1 = phase2_getc (); + + if (c1 >= '0' && c1 <= '9') + n = (n << 4) + (c1 - '0'); + else if (c1 >= 'A' && c1 <= 'F') + n = (n << 4) + (c1 - 'A' + 10); + else if (c1 >= 'a' && c1 <= 'f') + n = (n << 4) + (c1 - 'a' + 10); + else + { + phase2_ungetc (c1); + while (--i >= 0) + phase2_ungetc (buf[i]); + phase2_ungetc (c); + ++*backslash_counter; + return UNICODE ('\\'); + } + + buf[i] = c1; + } + *backslash_counter = 0; + return UNICODE (n); + } + + if (interpret_ansic) + { + if (c == 'U') + { + unsigned char buf[8]; + unsigned int n = 0; + int i; + + for (i = 0; i < 8; i++) + { + int c1 = phase2_getc (); + + if (c1 >= '0' && c1 <= '9') + n = (n << 4) + (c1 - '0'); + else if (c1 >= 'A' && c1 <= 'F') + n = (n << 4) + (c1 - 'A' + 10); + else if (c1 >= 'a' && c1 <= 'f') + n = (n << 4) + (c1 - 'a' + 10); + else + { + phase2_ungetc (c1); + while (--i >= 0) + phase2_ungetc (buf[i]); + phase2_ungetc (c); + ++*backslash_counter; + return UNICODE ('\\'); + } + + buf[i] = c1; + } + if (n < 0x110000) + { + *backslash_counter = 0; + return UNICODE (n); + } + + error_with_progname = false; + error (0, 0, _("%s:%d: warning: invalid Unicode character"), + logical_file_name, line_number); + error_with_progname = true; + + while (--i >= 0) + phase2_ungetc (buf[i]); + phase2_ungetc (c); + ++*backslash_counter; + return UNICODE ('\\'); + } + + if (c == 'N') + { + int c1 = phase2_getc (); + if (c1 == '{') + { + unsigned char buf[UNINAME_MAX + 1]; + int i; + unsigned int n; + + for (i = 0; i < UNINAME_MAX; i++) + { + int c2 = phase2_getc (); + if (!(c2 >= ' ' && c2 <= '~')) + { + phase2_ungetc (c2); + while (--i >= 0) + phase2_ungetc (buf[i]); + phase2_ungetc (c1); + phase2_ungetc (c); + ++*backslash_counter; + return UNICODE ('\\'); + } + if (c2 == '}') + break; + buf[i] = c2; + } + buf[i] = '\0'; + + n = unicode_name_character ((char *) buf); + if (n != UNINAME_INVALID) + { + *backslash_counter = 0; + return UNICODE (n); + } + + phase2_ungetc ('}'); + while (--i >= 0) + phase2_ungetc (buf[i]); + } + phase2_ungetc (c1); + phase2_ungetc (c); + ++*backslash_counter; + return UNICODE ('\\'); + } + } + } phase2_ungetc (c); ++*backslash_counter; @@ -1369,237 +1369,237 @@ phase5_get (token_ty *tp) c = phase3_getc (); switch (c) - { - case UEOF: - tp->type = token_type_eof; - return; - - case ' ': - case '\t': - case '\f': - /* Ignore whitespace and comments. */ - continue; - - case '\n': - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - /* Ignore newline if and only if it is used for implicit line - joining. */ - if (open_pbb > 0) - continue; - tp->type = token_type_other; - return; - } + { + case UEOF: + tp->type = token_type_eof; + return; + + case ' ': + case '\t': + case '\f': + /* Ignore whitespace and comments. */ + continue; + + case '\n': + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + /* Ignore newline if and only if it is used for implicit line + joining. */ + if (open_pbb > 0) + continue; + tp->type = token_type_other; + return; + } last_non_comment_line = tp->line_number; switch (c) - { - case '.': - { - int c1 = phase3_getc (); - phase3_ungetc (c1); - if (!(c1 >= '0' && c1 <= '9')) - { - - tp->type = token_type_other; - return; - } - } - /* FALLTHROUGH */ - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': - case 'S': case 'T': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': - case 's': case 't': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - symbol: - /* Symbol, or part of a number. */ - { - static char *buffer; - static int bufmax; - int bufpos; - - bufpos = 0; - for (;;) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase3_getc (); - switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - continue; - default: - phase3_ungetc (c); - break; - } - break; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = '\0'; - tp->string = xstrdup (buffer); - tp->type = token_type_symbol; - return; - } - - /* Strings. */ - { - struct mixed_string_buffer literal; - int quote_char; - bool interpret_ansic; - bool interpret_unicode; - bool triple; - unsigned int backslash_counter; - - case 'R': case 'r': - { - int c1 = phase2_getc (); - if (c1 == '"' || c1 == '\'') - { - quote_char = c1; - interpret_ansic = false; - interpret_unicode = false; - goto string; - } - phase2_ungetc (c1); - goto symbol; - } - - case 'U': case 'u': - { - int c1 = phase2_getc (); - if (c1 == '"' || c1 == '\'') - { - quote_char = c1; - interpret_ansic = true; - interpret_unicode = true; - goto string; - } - if (c1 == 'R' || c1 == 'r') - { - int c2 = phase2_getc (); - if (c2 == '"' || c2 == '\'') - { - quote_char = c2; - interpret_ansic = false; - interpret_unicode = true; - goto string; - } - phase2_ungetc (c2); - } - phase2_ungetc (c1); - goto symbol; - } - - case '"': case '\'': - quote_char = c; - interpret_ansic = true; - interpret_unicode = false; - string: - triple = false; - lexical_context = lc_string; - { - int c1 = phase2_getc (); - if (c1 == quote_char) - { - int c2 = phase2_getc (); - if (c2 == quote_char) - triple = true; - else - { - phase2_ungetc (c2); - phase2_ungetc (c1); - } - } - else - phase2_ungetc (c1); - } - backslash_counter = 0; - /* Start accumulating the string. */ - init_mixed_string_buffer (&literal, lc_string); - for (;;) - { - int uc = phase7_getuc (quote_char, triple, interpret_ansic, - interpret_unicode, &backslash_counter); - - if (uc == P7_EOF || uc == P7_STRING_END) - break; - - if (IS_UNICODE (uc)) - assert (UNICODE_VALUE (uc) >= 0 - && UNICODE_VALUE (uc) < 0x110000); - - mixed_string_buffer_append (&literal, uc); - } - tp->string = xstrdup (mixed_string_buffer_result (&literal)); - free_mixed_string_buffer (&literal); - tp->comment = add_reference (savable_comment); - lexical_context = lc_outside; - tp->type = token_type_string; - return; - } - - case '(': - open_pbb++; - tp->type = token_type_lparen; - return; - - case ')': - if (open_pbb > 0) - open_pbb--; - tp->type = token_type_rparen; - return; - - case ',': - tp->type = token_type_comma; - return; - - case '[': case '{': - open_pbb++; - tp->type = (c == '[' ? token_type_lbracket : token_type_other); - return; - - case ']': case '}': - if (open_pbb > 0) - open_pbb--; - tp->type = (c == ']' ? token_type_rbracket : token_type_other); - return; - - default: - /* We could carefully recognize each of the 2 and 3 character - operators, but it is not necessary, as we only need to recognize - gettext invocations. Don't bother. */ - tp->type = token_type_other; - return; - } + { + case '.': + { + int c1 = phase3_getc (); + phase3_ungetc (c1); + if (!(c1 >= '0' && c1 <= '9')) + { + + tp->type = token_type_other; + return; + } + } + /* FALLTHROUGH */ + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': + case 'S': case 'T': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': + case 's': case 't': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + symbol: + /* Symbol, or part of a number. */ + { + static char *buffer; + static int bufmax; + int bufpos; + + bufpos = 0; + for (;;) + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase3_getc (); + switch (c) + { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + continue; + default: + phase3_ungetc (c); + break; + } + break; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = '\0'; + tp->string = xstrdup (buffer); + tp->type = token_type_symbol; + return; + } + + /* Strings. */ + { + struct mixed_string_buffer literal; + int quote_char; + bool interpret_ansic; + bool interpret_unicode; + bool triple; + unsigned int backslash_counter; + + case 'R': case 'r': + { + int c1 = phase2_getc (); + if (c1 == '"' || c1 == '\'') + { + quote_char = c1; + interpret_ansic = false; + interpret_unicode = false; + goto string; + } + phase2_ungetc (c1); + goto symbol; + } + + case 'U': case 'u': + { + int c1 = phase2_getc (); + if (c1 == '"' || c1 == '\'') + { + quote_char = c1; + interpret_ansic = true; + interpret_unicode = true; + goto string; + } + if (c1 == 'R' || c1 == 'r') + { + int c2 = phase2_getc (); + if (c2 == '"' || c2 == '\'') + { + quote_char = c2; + interpret_ansic = false; + interpret_unicode = true; + goto string; + } + phase2_ungetc (c2); + } + phase2_ungetc (c1); + goto symbol; + } + + case '"': case '\'': + quote_char = c; + interpret_ansic = true; + interpret_unicode = false; + string: + triple = false; + lexical_context = lc_string; + { + int c1 = phase2_getc (); + if (c1 == quote_char) + { + int c2 = phase2_getc (); + if (c2 == quote_char) + triple = true; + else + { + phase2_ungetc (c2); + phase2_ungetc (c1); + } + } + else + phase2_ungetc (c1); + } + backslash_counter = 0; + /* Start accumulating the string. */ + init_mixed_string_buffer (&literal, lc_string); + for (;;) + { + int uc = phase7_getuc (quote_char, triple, interpret_ansic, + interpret_unicode, &backslash_counter); + + if (uc == P7_EOF || uc == P7_STRING_END) + break; + + if (IS_UNICODE (uc)) + assert (UNICODE_VALUE (uc) >= 0 + && UNICODE_VALUE (uc) < 0x110000); + + mixed_string_buffer_append (&literal, uc); + } + tp->string = xstrdup (mixed_string_buffer_result (&literal)); + free_mixed_string_buffer (&literal); + tp->comment = add_reference (savable_comment); + lexical_context = lc_outside; + tp->type = token_type_string; + return; + } + + case '(': + open_pbb++; + tp->type = token_type_lparen; + return; + + case ')': + if (open_pbb > 0) + open_pbb--; + tp->type = token_type_rparen; + return; + + case ',': + tp->type = token_type_comma; + return; + + case '[': case '{': + open_pbb++; + tp->type = (c == '[' ? token_type_lbracket : token_type_other); + return; + + case ']': case '}': + if (open_pbb > 0) + open_pbb--; + tp->type = (c == ']' ? token_type_rbracket : token_type_other); + return; + + default: + /* We could carefully recognize each of the 2 and 3 character + operators, but it is not necessary, as we only need to recognize + gettext invocations. Don't bother. */ + tp->type = token_type_other; + return; + } } } @@ -1610,7 +1610,7 @@ phase5_unget (token_ty *tp) if (tp->type != token_type_eof) { if (phase5_pushback_length == SIZEOF (phase5_pushback)) - abort (); + abort (); phase5_pushback[phase5_pushback_length++] = *tp; } } @@ -1633,10 +1633,10 @@ x_python_lex (token_ty *tp) phase5_get (&tmp); if (tmp.type != token_type_string) - { - phase5_unget (&tmp); - return; - } + { + phase5_unget (&tmp); + return; + } len = strlen (tp->string); tp->string = xrealloc (tp->string, len + strlen (tmp.string) + 1); strcpy (tp->string + len, tmp.string); @@ -1674,10 +1674,10 @@ static flag_context_list_table_ty *flag_context_list_table; Return true upon eof, false upon closing parenthesis or bracket. */ static bool extract_balanced (message_list_ty *mlp, - token_type_ty delim, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - struct arglist_parser *argparser) + token_type_ty delim, + flag_context_ty outer_context, + flag_context_list_iterator_ty context_iter, + struct arglist_parser *argparser) { /* Current argument number. */ int arg = 1; @@ -1691,7 +1691,7 @@ extract_balanced (message_list_ty *mlp, /* Current context. */ flag_context_ty inner_context = inherited_context (outer_context, - flag_context_list_iterator_advance (&context_iter)); + flag_context_list_iterator_advance (&context_iter)); /* Start state is 0. */ state = 0; @@ -1702,137 +1702,137 @@ extract_balanced (message_list_ty *mlp, x_python_lex (&token); switch (token.type) - { - case token_type_symbol: - { - void *keyword_value; - - if (hash_find_entry (&keywords, token.string, strlen (token.string), - &keyword_value) - == 0) - { - next_shapes = (const struct callshapes *) keyword_value; - state = 1; - } - else - state = 0; - } - next_context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - token.string, strlen (token.string))); - free (token.string); - continue; - - case token_type_lparen: - if (extract_balanced (mlp, token_type_rparen, - inner_context, next_context_iter, - arglist_parser_alloc (mlp, - state ? next_shapes : NULL))) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rparen: - if (delim == token_type_rparen || delim == token_type_eof) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; - return false; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_comma: - arg++; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_context_iter = passthrough_context_list_iterator; - state = 0; - continue; - - case token_type_lbracket: - if (extract_balanced (mlp, token_type_rbracket, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; - return true; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rbracket: - if (delim == token_type_rbracket || delim == token_type_eof) - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; - return false; - } - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_string: - { - lex_pos_ty pos; - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - - xgettext_current_source_encoding = po_charset_utf8; - if (extract_all) - remember_a_message (mlp, NULL, token.string, inner_context, - &pos, NULL, token.comment); - else - arglist_parser_remember (argparser, arg, token.string, - inner_context, - pos.file_name, pos.line_number, - token.comment); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; - } - drop_reference (token.comment); - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_eof: - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; - return true; - - case token_type_other: - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - default: - abort (); - } + { + case token_type_symbol: + { + void *keyword_value; + + if (hash_find_entry (&keywords, token.string, strlen (token.string), + &keyword_value) + == 0) + { + next_shapes = (const struct callshapes *) keyword_value; + state = 1; + } + else + state = 0; + } + next_context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + token.string, strlen (token.string))); + free (token.string); + continue; + + case token_type_lparen: + if (extract_balanced (mlp, token_type_rparen, + inner_context, next_context_iter, + arglist_parser_alloc (mlp, + state ? next_shapes : NULL))) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_current_file_source_encoding; + return true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_rparen: + if (delim == token_type_rparen || delim == token_type_eof) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_current_file_source_encoding; + return false; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_comma: + arg++; + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + next_context_iter = passthrough_context_list_iterator; + state = 0; + continue; + + case token_type_lbracket: + if (extract_balanced (mlp, token_type_rbracket, + null_context, null_context_list_iterator, + arglist_parser_alloc (mlp, NULL))) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_current_file_source_encoding; + return true; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_rbracket: + if (delim == token_type_rbracket || delim == token_type_eof) + { + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_current_file_source_encoding; + return false; + } + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_string: + { + lex_pos_ty pos; + pos.file_name = logical_file_name; + pos.line_number = token.line_number; + + xgettext_current_source_encoding = po_charset_utf8; + if (extract_all) + remember_a_message (mlp, NULL, token.string, inner_context, + &pos, NULL, token.comment); + else + arglist_parser_remember (argparser, arg, token.string, + inner_context, + pos.file_name, pos.line_number, + token.comment); + xgettext_current_source_encoding = xgettext_current_file_source_encoding; + } + drop_reference (token.comment); + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_eof: + xgettext_current_source_encoding = po_charset_utf8; + arglist_parser_done (argparser, arg); + xgettext_current_source_encoding = xgettext_current_file_source_encoding; + return true; + + case token_type_other: + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + default: + abort (); + } } } void extract_python (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { message_list_ty *mlp = mdlp->item[0]->messages; @@ -1867,8 +1867,8 @@ extract_python (FILE *f, /* Eat tokens until eof is seen. When extract_balanced returns due to an unbalanced closing parenthesis, just restart it. */ while (!extract_balanced (mlp, token_type_eof, - null_context, null_context_list_iterator, - arglist_parser_alloc (mlp, NULL))) + null_context, null_context_list_iterator, + arglist_parser_alloc (mlp, NULL))) ; fp = NULL; diff --git a/gettext-tools/src/x-python.h b/gettext-tools/src/x-python.h index 2b4fbc847..14f8bc56e 100644 --- a/gettext-tools/src/x-python.h +++ b/gettext-tools/src/x-python.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_PYTHON \ - { "py", "Python" }, \ + { "py", "Python" }, \ #define SCANNERS_PYTHON \ - { "Python", extract_python, \ - &flag_table_python, &formatstring_python, NULL }, \ + { "Python", extract_python, \ + &flag_table_python, &formatstring_python, NULL }, \ /* Scan a Python file and add its translatable strings to mdlp. */ extern void extract_python (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); extern void x_python_keyword (const char *keyword); extern void x_python_extract_all (void); diff --git a/gettext-tools/src/x-rst.c b/gettext-tools/src/x-rst.c index c604941da..8b5a26af6 100644 --- a/gettext-tools/src/x-rst.c +++ b/gettext-tools/src/x-rst.c @@ -57,9 +57,9 @@ void extract_rst (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { static char *buffer; static int bufmax; @@ -77,143 +77,143 @@ extract_rst (FILE *f, c = getc (f); if (c == EOF) - break; + break; /* Ignore blank line. */ if (c == '\n') - { - line_number++; - continue; - } + { + line_number++; + continue; + } /* Ignore comment line. */ if (c == '#') - { - do - c = getc (f); - while (c != EOF && c != '\n'); - if (c == EOF) - break; - line_number++; - continue; - } + { + do + c = getc (f); + while (c != EOF && c != '\n'); + if (c == EOF) + break; + line_number++; + continue; + } /* Read ModuleName.ConstName. */ bufpos = 0; for (;;) - { - if (c == EOF || c == '\n') - { - error_with_progname = false; - error (EXIT_FAILURE, 0, _("%s:%d: invalid string definition"), - logical_filename, line_number); - error_with_progname = true; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - if (c == '=') - break; - buffer[bufpos++] = c; - c = getc (f); - if (c == EOF && ferror (f)) - goto bomb; - } + { + if (c == EOF || c == '\n') + { + error_with_progname = false; + error (EXIT_FAILURE, 0, _("%s:%d: invalid string definition"), + logical_filename, line_number); + error_with_progname = true; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + if (c == '=') + break; + buffer[bufpos++] = c; + c = getc (f); + if (c == EOF && ferror (f)) + goto bomb; + } buffer[bufpos] = '\0'; location = xstrdup (buffer); /* Read StringExpression. */ bufpos = 0; for (;;) - { - c = getc (f); - if (c == EOF) - break; - else if (c == '\n') - { - line_number++; - break; - } - else if (c == '\'') - { - for (;;) - { - c = getc (f); - /* Embedded single quotes like 'abc''def' don't occur. - See fpc-1.0.4/compiler/cresstr.pas. */ - if (c == EOF || c == '\n' || c == '\'') - break; - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - } - if (c == EOF) - break; - else if (c == '\n') - { - line_number++; - break; - } - } - else if (c == '#') - { - int n; - c = getc (f); - if (c == EOF && ferror (f)) - goto bomb; - if (c == EOF || !c_isdigit (c)) - { - error_with_progname = false; - error (EXIT_FAILURE, 0, _("%s:%d: missing number after #"), - logical_filename, line_number); - error_with_progname = true; - } - n = (c - '0'); - for (;;) - { - c = getc (f); - if (c == EOF || !c_isdigit (c)) - break; - n = n * 10 + (c - '0'); - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = (unsigned char) n; - if (c == EOF) - break; - ungetc (c, f); - } - else if (c == '+') - { - c = getc (f); - if (c == EOF) - break; - if (c == '\n') - line_number++; - else - ungetc (c, f); - } - else - { - error_with_progname = false; - error (EXIT_FAILURE, 0, _("%s:%d: invalid string expression"), - logical_filename, line_number); - error_with_progname = true; - } - } + { + c = getc (f); + if (c == EOF) + break; + else if (c == '\n') + { + line_number++; + break; + } + else if (c == '\'') + { + for (;;) + { + c = getc (f); + /* Embedded single quotes like 'abc''def' don't occur. + See fpc-1.0.4/compiler/cresstr.pas. */ + if (c == EOF || c == '\n' || c == '\'') + break; + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + } + if (c == EOF) + break; + else if (c == '\n') + { + line_number++; + break; + } + } + else if (c == '#') + { + int n; + c = getc (f); + if (c == EOF && ferror (f)) + goto bomb; + if (c == EOF || !c_isdigit (c)) + { + error_with_progname = false; + error (EXIT_FAILURE, 0, _("%s:%d: missing number after #"), + logical_filename, line_number); + error_with_progname = true; + } + n = (c - '0'); + for (;;) + { + c = getc (f); + if (c == EOF || !c_isdigit (c)) + break; + n = n * 10 + (c - '0'); + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = (unsigned char) n; + if (c == EOF) + break; + ungetc (c, f); + } + else if (c == '+') + { + c = getc (f); + if (c == EOF) + break; + if (c == '\n') + line_number++; + else + ungetc (c, f); + } + else + { + error_with_progname = false; + error (EXIT_FAILURE, 0, _("%s:%d: invalid string expression"), + logical_filename, line_number); + error_with_progname = true; + } + } if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } buffer[bufpos] = '\0'; msgid = xstrdup (buffer); @@ -224,13 +224,13 @@ extract_rst (FILE *f, /* Here c is the last read character: EOF or '\n'. */ if (c == EOF) - break; + break; } if (ferror (f)) { bomb: error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_filename); + real_filename); } } diff --git a/gettext-tools/src/x-rst.h b/gettext-tools/src/x-rst.h index 7f460ea85..dd214fc00 100644 --- a/gettext-tools/src/x-rst.h +++ b/gettext-tools/src/x-rst.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_RST \ - { "rst", "RST" }, \ + { "rst", "RST" }, \ #define SCANNERS_RST \ - { "RST", extract_rst, \ - NULL, &formatstring_pascal, NULL }, \ + { "RST", extract_rst, \ + NULL, &formatstring_pascal, NULL }, \ /* Scan an RST file and add its translatable strings to mdlp. */ extern void extract_rst (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); #ifdef __cplusplus diff --git a/gettext-tools/src/x-scheme.c b/gettext-tools/src/x-scheme.c index 1e108211d..168cb3706 100644 --- a/gettext-tools/src/x-scheme.c +++ b/gettext-tools/src/x-scheme.c @@ -98,22 +98,22 @@ x_scheme_keyword (const char *name) const char *colon; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid Lisp symbol. - Extract the symbol name part. */ + Extract the symbol name part. */ colon = strchr (name, ':'); if (colon != NULL && colon < end) - { - name = colon + 1; - if (name < end && *name == ':') - name++; - colon = strchr (name, ':'); - if (colon != NULL && colon < end) - return; - } + { + name = colon + 1; + if (name < end && *name == ':') + name++; + colon = strchr (name, ':'); + if (colon != NULL && colon < end) + return; + } insert_keyword_callshape (&keywords, name, end - name, &shape); } @@ -127,9 +127,9 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ - x_scheme_keyword ("gettext"); /* libguile/i18n.c */ - x_scheme_keyword ("ngettext:1,2"); /* libguile/i18n.c */ + xgettext.texi! */ + x_scheme_keyword ("gettext"); /* libguile/i18n.c */ + x_scheme_keyword ("ngettext:1,2"); /* libguile/i18n.c */ x_scheme_keyword ("gettext-noop"); default_keywords = false; } @@ -168,7 +168,7 @@ do_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("\ + error (EXIT_FAILURE, errno, _("\ error while reading \"%s\""), real_file_name); } else if (c == '\n') @@ -193,9 +193,9 @@ do_ungetc (int c) /* A token consists of a sequence of characters. */ struct token { - int allocated; /* number of allocated 'token_char's */ - int charcount; /* number of used 'token_char's */ - char *chars; /* the token's constituents */ + int allocated; /* number of allocated 'token_char's */ + int charcount; /* number of used 'token_char's */ + char *chars; /* the token's constituents */ }; /* Initialize a 'struct token'. */ @@ -240,13 +240,13 @@ read_token (struct token *tp, int first) int c = do_getc (); if (c == EOF) - break; + break; if (c == ' ' || c == '\r' || c == '\f' || c == '\t' || c == '\n' - || c == '"' || c == '(' || c == ')' || c == ';') - { - do_ungetc (c); - break; - } + || c == '"' || c == '(' || c == ')' || c == ';') + { + do_ungetc (c); + break; + } grow_token (tp); tp->chars[tp->charcount++] = c; } @@ -270,22 +270,22 @@ is_integer_syntax (const char *str, int len, int radix) { p++; if (p == p_end) - return false; + return false; } do { int c = *p++; if (c >= '0' && c <= '9') - c = c - '0'; + c = c - '0'; else if (c >= 'A' && c <= 'F') - c = c - 'A' + 10; + c = c - 'A' + 10; else if (c >= 'a' && c <= 'f') - c = c - 'a' + 10; + c = c - 'a' + 10; else - return false; + return false; if (c >= radix) - return false; + return false; } while (p < p_end); return true; @@ -326,11 +326,11 @@ is_other_number_syntax (const char *str, int len, int radix, bool unconstrained) { p++; if (p == p_end) - return false; + return false; seen_sign = true; /* Recognize complex number syntax: {'+'|'-'} 'i' */ if (unconstrained && (*p == 'I' || *p == 'i') && p + 1 == p_end) - return true; + return true; } /* Parse digits before dot or exponent or slash. */ seen_digits = false; @@ -339,23 +339,23 @@ is_other_number_syntax (const char *str, int len, int radix, bool unconstrained) int c = *p; if (c >= '0' && c <= '9') - c = c - '0'; + c = c - '0'; else if (c >= 'A' && c <= 'F') - { - if (c >= 'D' && radix == 10) /* exponent? */ - break; - c = c - 'A' + 10; - } + { + if (c >= 'D' && radix == 10) /* exponent? */ + break; + c = c - 'A' + 10; + } else if (c >= 'a' && c <= 'f') - { - if (c >= 'd' && radix == 10) /* exponent? */ - break; - c = c - 'a' + 10; - } + { + if (c >= 'd' && radix == 10) /* exponent? */ + break; + c = c - 'a' + 10; + } else - break; + break; if (c >= radix) - return false; + return false; seen_digits = true; p++; } @@ -366,104 +366,104 @@ is_other_number_syntax (const char *str, int len, int radix, bool unconstrained) { /* If we have no digits so far, we need a decimal point later. */ if (!seen_digits && !(*p == '.' && radix == 10)) - return false; + return false; /* Trailing '#' signs are equivalent to zeroes. */ while (p < p_end && *p == '#') - p++; + p++; if (p < p_end) - { - if (*p == '/') - { - /* Parse digits after the slash. */ - bool all_zeroes = true; - p++; - for (; p < p_end; p++) - { - int c = *p; - - if (c >= '0' && c <= '9') - c = c - '0'; - else if (c >= 'A' && c <= 'F') - c = c - 'A' + 10; - else if (c >= 'a' && c <= 'f') - c = c - 'a' + 10; - else - break; - if (c >= radix) - return false; - if (c != 0) - all_zeroes = false; - } - /* A zero denominator is not allowed. */ - if (all_zeroes) - return false; - /* Trailing '#' signs are equivalent to zeroes. */ - while (p < p_end && *p == '#') - p++; - } - else - { - if (*p == '.') - { - /* Decimal point notation. */ - if (radix != 10) - return false; - /* Parse digits after the decimal point. */ - p++; - for (; p < p_end; p++) - { - int c = *p; - - if (c >= '0' && c <= '9') - seen_digits = true; - else - break; - } - /* Digits are required before or after the decimal point. */ - if (!seen_digits) - return false; - /* Trailing '#' signs are equivalent to zeroes. */ - while (p < p_end && *p == '#') - p++; - } - if (p < p_end) - { - /* Parse exponent. */ - switch (*p) - { - case 'D': case 'd': - case 'E': case 'e': - case 'F': case 'f': - case 'L': case 'l': - case 'S': case 's': - if (radix != 10) - return false; - p++; - if (p == p_end) - return false; - if (*p == '+' || *p == '-') - { - p++; - if (p == p_end) - return false; - } - if (!(*p >= '0' && *p <= '9')) - return false; - for (;;) - { - p++; - if (p == p_end) - break; - if (!(*p >= '0' && *p <= '9')) - break; - } - break; - default: - break; - } - } - } - } + { + if (*p == '/') + { + /* Parse digits after the slash. */ + bool all_zeroes = true; + p++; + for (; p < p_end; p++) + { + int c = *p; + + if (c >= '0' && c <= '9') + c = c - '0'; + else if (c >= 'A' && c <= 'F') + c = c - 'A' + 10; + else if (c >= 'a' && c <= 'f') + c = c - 'a' + 10; + else + break; + if (c >= radix) + return false; + if (c != 0) + all_zeroes = false; + } + /* A zero denominator is not allowed. */ + if (all_zeroes) + return false; + /* Trailing '#' signs are equivalent to zeroes. */ + while (p < p_end && *p == '#') + p++; + } + else + { + if (*p == '.') + { + /* Decimal point notation. */ + if (radix != 10) + return false; + /* Parse digits after the decimal point. */ + p++; + for (; p < p_end; p++) + { + int c = *p; + + if (c >= '0' && c <= '9') + seen_digits = true; + else + break; + } + /* Digits are required before or after the decimal point. */ + if (!seen_digits) + return false; + /* Trailing '#' signs are equivalent to zeroes. */ + while (p < p_end && *p == '#') + p++; + } + if (p < p_end) + { + /* Parse exponent. */ + switch (*p) + { + case 'D': case 'd': + case 'E': case 'e': + case 'F': case 'f': + case 'L': case 'l': + case 'S': case 's': + if (radix != 10) + return false; + p++; + if (p == p_end) + return false; + if (*p == '+' || *p == '-') + { + p++; + if (p == p_end) + return false; + } + if (!(*p >= '0' && *p <= '9')) + return false; + for (;;) + { + p++; + if (p == p_end) + break; + if (!(*p >= '0' && *p <= '9')) + break; + } + break; + default: + break; + } + } + } + } } if (p == p_end) return true; @@ -472,21 +472,21 @@ is_other_number_syntax (const char *str, int len, int radix, bool unconstrained) { /* Recognize the syntax {'+'|'-'} REAL-NUMBER-WITHOUT-SIGN 'i' */ if (seen_sign && (*p == 'I' || *p == 'i') && p + 1 == p_end) - return true; + return true; /* Recognize the syntaxes - REAL-NUMBER {'+'|'-'} REAL-NUMBER-WITHOUT-SIGN 'i' - REAL-NUMBER {'+'|'-'} 'i' + REAL-NUMBER {'+'|'-'} REAL-NUMBER-WITHOUT-SIGN 'i' + REAL-NUMBER {'+'|'-'} 'i' */ if (*p == '+' || *p == '-') - return (p_end[-1] == 'I' || p_end[-1] == 'i') - && (p + 1 == p_end - 1 - || is_other_number_syntax (p, p_end - 1 - p, radix, false)); + return (p_end[-1] == 'I' || p_end[-1] == 'i') + && (p + 1 == p_end - 1 + || is_other_number_syntax (p, p_end - 1 - p, radix, false)); /* Recognize the syntax REAL-NUMBER '@' REAL-NUMBER */ if (*p == '@') - { - p++; - return is_other_number_syntax (p, p_end - p, radix, false); - } + { + p++; + return is_other_number_syntax (p, p_end - p, radix, false); + } } return false; } @@ -509,46 +509,46 @@ is_number (const struct token *tp) while (len >= 2 && *str == '#') { switch (str[1]) - { - case 'B': case 'b': - if (seen_radix_prefix) - return false; - radix = 2; - seen_radix_prefix = true; - break; - case 'O': case 'o': - if (seen_radix_prefix) - return false; - radix = 8; - seen_radix_prefix = true; - break; - case 'D': case 'd': - if (seen_radix_prefix) - return false; - radix = 10; - seen_radix_prefix = true; - break; - case 'X': case 'x': - if (seen_radix_prefix) - return false; - radix = 16; - seen_radix_prefix = true; - break; - case 'E': case 'e': - if (seen_exactness_prefix) - return false; - exactness = exact; - seen_exactness_prefix = true; - break; - case 'I': case 'i': - if (seen_exactness_prefix) - return false; - exactness = inexact; - seen_exactness_prefix = true; - break; - default: - return false; - } + { + case 'B': case 'b': + if (seen_radix_prefix) + return false; + radix = 2; + seen_radix_prefix = true; + break; + case 'O': case 'o': + if (seen_radix_prefix) + return false; + radix = 8; + seen_radix_prefix = true; + break; + case 'D': case 'd': + if (seen_radix_prefix) + return false; + radix = 10; + seen_radix_prefix = true; + break; + case 'X': case 'x': + if (seen_radix_prefix) + return false; + radix = 16; + seen_radix_prefix = true; + break; + case 'E': case 'e': + if (seen_exactness_prefix) + return false; + exactness = exact; + seen_exactness_prefix = true; + break; + case 'I': case 'i': + if (seen_exactness_prefix) + return false; + exactness = inexact; + seen_exactness_prefix = true; + break; + default: + return false; + } str += 2; len -= 2; } @@ -556,15 +556,15 @@ is_number (const struct token *tp) { /* Try to parse an integer. */ if (is_integer_syntax (str, len, 10)) - return true; + return true; /* FIXME: Other Scheme implementations support exact rational numbers - or exact complex numbers. */ + or exact complex numbers. */ } if (exactness != exact) { /* Try to parse a rational, floating-point or complex number. */ if (is_other_number_syntax (str, len, 10, true)) - return true; + return true; } return false; } @@ -599,7 +599,7 @@ comment_line_end (size_t chars_to_remove) { buflen -= chars_to_remove; while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { @@ -630,19 +630,19 @@ static message_list_ty *mlp; Other objects need not to be represented precisely. */ enum object_type { - t_symbol, /* symbol */ - t_string, /* string */ - t_other, /* other kind of real object */ - t_dot, /* '.' pseudo object */ - t_close, /* ')' pseudo object */ - t_eof /* EOF marker */ + t_symbol, /* symbol */ + t_string, /* string */ + t_other, /* other kind of real object */ + t_dot, /* '.' pseudo object */ + t_close, /* ')' pseudo object */ + t_eof /* EOF marker */ }; struct object { enum object_type type; - struct token *token; /* for t_symbol and t_string */ - int line_number_at_start; /* for t_string */ + struct token *token; /* for t_symbol and t_string */ + int line_number_at_start; /* for t_string */ }; /* Free the memory pointed to by a 'struct object'. */ @@ -684,506 +684,506 @@ read_object (struct object *op, flag_context_ty outer_context) int c = do_getc (); switch (c) - { - case EOF: - op->type = t_eof; - return; - - case ' ': case '\r': case '\f': case '\t': - continue; - - case '\n': - /* Comments assumed to be grouped with a message must immediately - precede it, with no non-whitespace token on a line between - both. */ - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - continue; - - case ';': - { - bool all_semicolons = true; - - last_comment_line = line_number; - comment_start (); - for (;;) - { - c = do_getc (); - if (c == EOF || c == '\n') - break; - if (c != ';') - all_semicolons = false; - if (!all_semicolons) - { - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - } - } - comment_line_end (0); - continue; - } - - case '(': - { - int arg = 0; /* Current argument number. */ - flag_context_list_iterator_ty context_iter; - const struct callshapes *shapes = NULL; - struct arglist_parser *argparser = NULL; - - for (;; arg++) - { - struct object inner; - flag_context_ty inner_context; - - if (arg == 0) - inner_context = null_context; - else - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - - read_object (&inner, inner_context); - - /* Recognize end of list. */ - if (inner.type == t_close) - { - op->type = t_other; - last_non_comment_line = line_number; - if (argparser != NULL) - arglist_parser_done (argparser, arg); - return; - } - - /* Dots are not allowed in every position. - But be tolerant. */ - - /* EOF inside list is illegal. - But be tolerant. */ - if (inner.type == t_eof) - break; - - if (arg == 0) - { - /* This is the function position. */ - if (inner.type == t_symbol) - { - char *symbol_name = string_of_object (&inner); - void *keyword_value; - - if (hash_find_entry (&keywords, - symbol_name, strlen (symbol_name), - &keyword_value) - == 0) - shapes = (const struct callshapes *) keyword_value; - - argparser = arglist_parser_alloc (mlp, shapes); - - context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - symbol_name, strlen (symbol_name))); - - free (symbol_name); - } - else - context_iter = null_context_list_iterator; - } - else - { - /* These are the argument positions. */ - if (argparser != NULL && inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_object (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); - } - - free_object (&inner); - } - if (argparser != NULL) - arglist_parser_done (argparser, arg); - } - op->type = t_other; - last_non_comment_line = line_number; - return; - - case ')': - /* Tell the caller about the end of list. - Unmatched closing parenthesis is illegal. - But be tolerant. */ - op->type = t_close; - last_non_comment_line = line_number; - return; - - case ',': - { - int c = do_getc (); - /* The ,@ handling inside lists is wrong anyway, because - ,@form expands to an unknown number of elements. */ - if (c != EOF && c != '@') - do_ungetc (c); - } - /*FALLTHROUGH*/ - case '\'': - case '`': - { - struct object inner; - - read_object (&inner, null_context); - - /* Dots and EOF are not allowed here. But be tolerant. */ - - free_object (&inner); - - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '#': - /* Dispatch macro handling. */ - { - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - { - op->type = t_other; - return; - } - - switch (c) - { - case '(': /* Vector */ - do_ungetc (c); - { - struct object inner; - read_object (&inner, null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case 'T': case 't': /* Boolean true */ - case 'F': case 'f': /* Boolean false */ - op->type = t_other; - last_non_comment_line = line_number; - return; - - case 'B': case 'b': - case 'O': case 'o': - case 'D': case 'd': - case 'X': case 'x': - case 'E': case 'e': - case 'I': case 'i': - { - struct token token; - do_ungetc (c); - read_token (&token, '#'); - if (is_number (&token)) - { - /* A number. */ - free_token (&token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - else - { - if (token.charcount == 2 - && (token.chars[1] == 'e' || token.chars[1] == 'i')) - { - c = do_getc (); - if (c != EOF) - do_ungetc (c); - if (c == '(') - /* Homogenous vector syntax, see arrays.scm. */ - case 'a': /* Vectors of char */ - case 'c': /* Vectors of complex */ - /*case 'e':*/ /* Vectors of long */ - case 'h': /* Vectors of short */ - /*case 'i':*/ /* Vectors of double-float */ - case 'l': /* Vectors of long long */ - case 's': /* Vectors of single-float */ - case 'u': /* Vectors of unsigned long */ - case 'y': /* Vectors of byte */ - { - struct object inner; - read_object (&inner, null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_token (&token); - free_object (&inner); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - } - /* Unknown # object. But be tolerant. */ - free_token (&token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - } - - case '!': - /* Block comment '#! ... \n!#\n'. We don't extract it - because it's only used to introduce scripts on Unix. */ - { - int last1 = 0; - int last2 = 0; - int last3 = 0; - - for (;;) - { - c = do_getc (); - if (c == EOF) - /* EOF is not allowed here. But be tolerant. */ - break; - if (last3 == '\n' && last2 == '!' && last1 == '#' - && c == '\n') - break; - last3 = last2; - last2 = last1; - last1 = c; - } - continue; - } - - case '*': - /* Bit vector. */ - { - struct token token; - read_token (&token, c); - /* The token should consists only of '0' and '1', except - for the initial '*'. But be tolerant. */ - free_token (&token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case '{': - /* Symbol with multiple escapes: #{...}# */ - { - op->token = XMALLOC (struct token); - - init_token (op->token); - - for (;;) - { - c = do_getc (); - - if (c == EOF) - break; - if (c == '\\') - { - c = do_getc (); - if (c == EOF) - break; - } - else if (c == '}') - { - c = do_getc (); - if (c == '#') - break; - if (c != EOF) - do_ungetc (c); - c = '}'; - } - grow_token (op->token); - op->token->chars[op->token->charcount++] = c; - } - - op->type = t_symbol; - last_non_comment_line = line_number; - return; - } - - case '\\': - /* Character. */ - { - struct token token; - c = do_getc (); - if (c != EOF) - { - read_token (&token, c); - free_token (&token); - } - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - case ':': /* Keyword. */ - case '&': /* Deprecated keyword, installed in optargs.scm. */ - { - struct token token; - read_token (&token, '-'); - free_token (&token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - /* The following are installed through read-hash-extend. */ - - /* arrays.scm */ - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - /* Multidimensional array syntax: #nx(...) where - n ::= DIGIT+ - x ::= {'a'|'b'|'c'|'e'|'i'|'s'|'u'} - */ - do - c = do_getc (); - while (c >= '0' && c <= '9'); - /* c should be one of {'a'|'b'|'c'|'e'|'i'|'s'|'u'}. - But be tolerant. */ - /*FALLTHROUGH*/ - case '\'': /* boot-9.scm */ - case '.': /* boot-9.scm */ - case ',': /* srfi-10.scm */ - { - struct object inner; - read_object (&inner, null_context); - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - default: - /* Unknown. */ - op->type = t_other; - last_non_comment_line = line_number; - return; - } - /*NOTREACHED*/ - abort (); - } - - case '"': - { - op->token = XMALLOC (struct token); - init_token (op->token); - op->line_number_at_start = line_number; - for (;;) - { - int c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - break; - if (c == '"') - break; - if (c == '\\') - { - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - break; - switch (c) - { - case '\n': - continue; - case '0': - c = '\0'; - break; - case 'a': - c = '\a'; - break; - case 'f': - c = '\f'; - break; - case 'n': - c = '\n'; - break; - case 'r': - c = '\r'; - break; - case 't': - c = '\t'; - break; - case 'v': - c = '\v'; - break; - default: - break; - } - } - grow_token (op->token); - op->token->chars[op->token->charcount++] = c; - } - op->type = t_string; - - if (extract_all) - { - lex_pos_ty pos; - - pos.file_name = logical_file_name; - pos.line_number = op->line_number_at_start; - remember_a_message (mlp, NULL, string_of_object (op), - null_context, &pos, NULL, savable_comment); - } - last_non_comment_line = line_number; - return; - } - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case '+': case '-': case '.': - /* Read a number or symbol token. */ - op->token = XMALLOC (struct token); - read_token (op->token, c); - if (op->token->charcount == 1 && op->token->chars[0] == '.') - { - free_token (op->token); - free (op->token); - op->type = t_dot; - } - else if (is_number (op->token)) - { - /* A number. */ - free_token (op->token); - free (op->token); - op->type = t_other; - } - else - { - /* A symbol. */ - op->type = t_symbol; - } - last_non_comment_line = line_number; - return; - - case ':': - default: - /* Read a symbol token. */ - op->token = XMALLOC (struct token); - read_token (op->token, c); - op->type = t_symbol; - last_non_comment_line = line_number; - return; - } + { + case EOF: + op->type = t_eof; + return; + + case ' ': case '\r': case '\f': case '\t': + continue; + + case '\n': + /* Comments assumed to be grouped with a message must immediately + precede it, with no non-whitespace token on a line between + both. */ + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + continue; + + case ';': + { + bool all_semicolons = true; + + last_comment_line = line_number; + comment_start (); + for (;;) + { + c = do_getc (); + if (c == EOF || c == '\n') + break; + if (c != ';') + all_semicolons = false; + if (!all_semicolons) + { + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + } + } + comment_line_end (0); + continue; + } + + case '(': + { + int arg = 0; /* Current argument number. */ + flag_context_list_iterator_ty context_iter; + const struct callshapes *shapes = NULL; + struct arglist_parser *argparser = NULL; + + for (;; arg++) + { + struct object inner; + flag_context_ty inner_context; + + if (arg == 0) + inner_context = null_context; + else + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + + read_object (&inner, inner_context); + + /* Recognize end of list. */ + if (inner.type == t_close) + { + op->type = t_other; + last_non_comment_line = line_number; + if (argparser != NULL) + arglist_parser_done (argparser, arg); + return; + } + + /* Dots are not allowed in every position. + But be tolerant. */ + + /* EOF inside list is illegal. + But be tolerant. */ + if (inner.type == t_eof) + break; + + if (arg == 0) + { + /* This is the function position. */ + if (inner.type == t_symbol) + { + char *symbol_name = string_of_object (&inner); + void *keyword_value; + + if (hash_find_entry (&keywords, + symbol_name, strlen (symbol_name), + &keyword_value) + == 0) + shapes = (const struct callshapes *) keyword_value; + + argparser = arglist_parser_alloc (mlp, shapes); + + context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + symbol_name, strlen (symbol_name))); + + free (symbol_name); + } + else + context_iter = null_context_list_iterator; + } + else + { + /* These are the argument positions. */ + if (argparser != NULL && inner.type == t_string) + arglist_parser_remember (argparser, arg, + string_of_object (&inner), + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + } + + free_object (&inner); + } + if (argparser != NULL) + arglist_parser_done (argparser, arg); + } + op->type = t_other; + last_non_comment_line = line_number; + return; + + case ')': + /* Tell the caller about the end of list. + Unmatched closing parenthesis is illegal. + But be tolerant. */ + op->type = t_close; + last_non_comment_line = line_number; + return; + + case ',': + { + int c = do_getc (); + /* The ,@ handling inside lists is wrong anyway, because + ,@form expands to an unknown number of elements. */ + if (c != EOF && c != '@') + do_ungetc (c); + } + /*FALLTHROUGH*/ + case '\'': + case '`': + { + struct object inner; + + read_object (&inner, null_context); + + /* Dots and EOF are not allowed here. But be tolerant. */ + + free_object (&inner); + + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '#': + /* Dispatch macro handling. */ + { + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + { + op->type = t_other; + return; + } + + switch (c) + { + case '(': /* Vector */ + do_ungetc (c); + { + struct object inner; + read_object (&inner, null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case 'T': case 't': /* Boolean true */ + case 'F': case 'f': /* Boolean false */ + op->type = t_other; + last_non_comment_line = line_number; + return; + + case 'B': case 'b': + case 'O': case 'o': + case 'D': case 'd': + case 'X': case 'x': + case 'E': case 'e': + case 'I': case 'i': + { + struct token token; + do_ungetc (c); + read_token (&token, '#'); + if (is_number (&token)) + { + /* A number. */ + free_token (&token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + else + { + if (token.charcount == 2 + && (token.chars[1] == 'e' || token.chars[1] == 'i')) + { + c = do_getc (); + if (c != EOF) + do_ungetc (c); + if (c == '(') + /* Homogenous vector syntax, see arrays.scm. */ + case 'a': /* Vectors of char */ + case 'c': /* Vectors of complex */ + /*case 'e':*/ /* Vectors of long */ + case 'h': /* Vectors of short */ + /*case 'i':*/ /* Vectors of double-float */ + case 'l': /* Vectors of long long */ + case 's': /* Vectors of single-float */ + case 'u': /* Vectors of unsigned long */ + case 'y': /* Vectors of byte */ + { + struct object inner; + read_object (&inner, null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_token (&token); + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + } + /* Unknown # object. But be tolerant. */ + free_token (&token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + } + + case '!': + /* Block comment '#! ... \n!#\n'. We don't extract it + because it's only used to introduce scripts on Unix. */ + { + int last1 = 0; + int last2 = 0; + int last3 = 0; + + for (;;) + { + c = do_getc (); + if (c == EOF) + /* EOF is not allowed here. But be tolerant. */ + break; + if (last3 == '\n' && last2 == '!' && last1 == '#' + && c == '\n') + break; + last3 = last2; + last2 = last1; + last1 = c; + } + continue; + } + + case '*': + /* Bit vector. */ + { + struct token token; + read_token (&token, c); + /* The token should consists only of '0' and '1', except + for the initial '*'. But be tolerant. */ + free_token (&token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '{': + /* Symbol with multiple escapes: #{...}# */ + { + op->token = XMALLOC (struct token); + + init_token (op->token); + + for (;;) + { + c = do_getc (); + + if (c == EOF) + break; + if (c == '\\') + { + c = do_getc (); + if (c == EOF) + break; + } + else if (c == '}') + { + c = do_getc (); + if (c == '#') + break; + if (c != EOF) + do_ungetc (c); + c = '}'; + } + grow_token (op->token); + op->token->chars[op->token->charcount++] = c; + } + + op->type = t_symbol; + last_non_comment_line = line_number; + return; + } + + case '\\': + /* Character. */ + { + struct token token; + c = do_getc (); + if (c != EOF) + { + read_token (&token, c); + free_token (&token); + } + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case ':': /* Keyword. */ + case '&': /* Deprecated keyword, installed in optargs.scm. */ + { + struct token token; + read_token (&token, '-'); + free_token (&token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + /* The following are installed through read-hash-extend. */ + + /* arrays.scm */ + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* Multidimensional array syntax: #nx(...) where + n ::= DIGIT+ + x ::= {'a'|'b'|'c'|'e'|'i'|'s'|'u'} + */ + do + c = do_getc (); + while (c >= '0' && c <= '9'); + /* c should be one of {'a'|'b'|'c'|'e'|'i'|'s'|'u'}. + But be tolerant. */ + /*FALLTHROUGH*/ + case '\'': /* boot-9.scm */ + case '.': /* boot-9.scm */ + case ',': /* srfi-10.scm */ + { + struct object inner; + read_object (&inner, null_context); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + default: + /* Unknown. */ + op->type = t_other; + last_non_comment_line = line_number; + return; + } + /*NOTREACHED*/ + abort (); + } + + case '"': + { + op->token = XMALLOC (struct token); + init_token (op->token); + op->line_number_at_start = line_number; + for (;;) + { + int c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + break; + if (c == '"') + break; + if (c == '\\') + { + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + break; + switch (c) + { + case '\n': + continue; + case '0': + c = '\0'; + break; + case 'a': + c = '\a'; + break; + case 'f': + c = '\f'; + break; + case 'n': + c = '\n'; + break; + case 'r': + c = '\r'; + break; + case 't': + c = '\t'; + break; + case 'v': + c = '\v'; + break; + default: + break; + } + } + grow_token (op->token); + op->token->chars[op->token->charcount++] = c; + } + op->type = t_string; + + if (extract_all) + { + lex_pos_ty pos; + + pos.file_name = logical_file_name; + pos.line_number = op->line_number_at_start; + remember_a_message (mlp, NULL, string_of_object (op), + null_context, &pos, NULL, savable_comment); + } + last_non_comment_line = line_number; + return; + } + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case '+': case '-': case '.': + /* Read a number or symbol token. */ + op->token = XMALLOC (struct token); + read_token (op->token, c); + if (op->token->charcount == 1 && op->token->chars[0] == '.') + { + free_token (op->token); + free (op->token); + op->type = t_dot; + } + else if (is_number (op->token)) + { + /* A number. */ + free_token (op->token); + free (op->token); + op->type = t_other; + } + else + { + /* A symbol. */ + op->type = t_symbol; + } + last_non_comment_line = line_number; + return; + + case ':': + default: + /* Read a symbol token. */ + op->token = XMALLOC (struct token); + read_token (op->token, c); + op->type = t_symbol; + last_non_comment_line = line_number; + return; + } } } void extract_scheme (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { mlp = mdlp->item[0]->messages; @@ -1208,7 +1208,7 @@ extract_scheme (FILE *f, read_object (&toplevel_object, null_context); if (toplevel_object.type == t_eof) - break; + break; free_object (&toplevel_object); } diff --git a/gettext-tools/src/x-scheme.h b/gettext-tools/src/x-scheme.h index 9089cf6b2..3eb100cc1 100644 --- a/gettext-tools/src/x-scheme.h +++ b/gettext-tools/src/x-scheme.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_SCHEME \ - { "scm", "Scheme" }, \ + { "scm", "Scheme" }, \ #define SCANNERS_SCHEME \ - { "Scheme", extract_scheme, \ - &flag_table_scheme, &formatstring_scheme, NULL }, \ + { "Scheme", extract_scheme, \ + &flag_table_scheme, &formatstring_scheme, NULL }, \ /* Scan a Scheme file and add its translatable strings to mdlp. */ extern void extract_scheme (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); /* Handling of options specific to this language. */ diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index 7cff65d3a..10a57e7c3 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -89,15 +89,15 @@ x_sh_keyword (const char *name) const char *colon; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid C identifier. - A colon means an invalid parse in split_keywordspec(). */ + A colon means an invalid parse in split_keywordspec(). */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) - insert_keyword_callshape (&keywords, name, end - name, &shape); + insert_keyword_callshape (&keywords, name, end - name, &shape); } } @@ -109,7 +109,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_sh_keyword ("gettext"); x_sh_keyword ("ngettext:1,2"); x_sh_keyword ("eval_gettext"); @@ -152,7 +152,7 @@ do_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("\ + error (EXIT_FAILURE, errno, _("\ error while reading \"%s\""), real_file_name); } else if (c == '\n') @@ -185,21 +185,21 @@ phase1_getc () { c = phase1_pushback[--phase1_pushback_length]; if (c == '\n') - ++line_number; + ++line_number; return c; } for (;;) { c = do_getc (); if (c != '\\') - return c; + return c; c = do_getc (); if (c != '\n') - { - if (c != EOF) - do_ungetc (c); - return '\\'; - } + { + if (c != EOF) + do_ungetc (c); + return '\\'; + } } } @@ -218,7 +218,7 @@ phase1_ungetc (int c) default: if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); + abort (); phase1_pushback[phase1_pushback_length++] = c; break; } @@ -231,9 +231,9 @@ phase1_ungetc (int c) /* A token consists of a sequence of characters. */ struct token { - int allocated; /* number of allocated 'token_char's */ - int charcount; /* number of used 'token_char's */ - char *chars; /* the token's constituents */ + int allocated; /* number of allocated 'token_char's */ + int charcount; /* number of used 'token_char's */ + char *chars; /* the token's constituents */ }; /* Initialize a 'struct token'. */ @@ -312,7 +312,7 @@ static inline void comment_line_end () { while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; if (buflen >= bufmax) { @@ -425,20 +425,20 @@ saw_closing_singlequote () represented precisely. */ enum word_type { - t_string, /* constant string */ - t_other, /* other string */ - t_separator, /* command separator: semicolon or newline */ - t_redirect, /* redirection: one of < > >| << <<- >> <> <& >& */ - t_backquote, /* closing '`' pseudo word */ - t_paren, /* closing ')' pseudo word */ - t_eof /* EOF marker */ + t_string, /* constant string */ + t_other, /* other string */ + t_separator, /* command separator: semicolon or newline */ + t_redirect, /* redirection: one of < > >| << <<- >> <> <& >& */ + t_backquote, /* closing '`' pseudo word */ + t_paren, /* closing ')' pseudo word */ + t_eof /* EOF marker */ }; struct word { enum word_type type; - struct token *token; /* for t_string */ - int line_number_at_start; /* for t_string */ + struct token *token; /* for t_string */ + int line_number_at_start; /* for t_string */ }; /* Free the memory pointed to by a 'struct word'. */ @@ -483,7 +483,7 @@ static inline bool is_operator_start (int c) { return (c == '|' || c == '&' || c == ';' || c == '<' || c == '>' - || c == '(' || c == ')'); + || c == '(' || c == ')'); } @@ -525,7 +525,7 @@ phase2_getc () { c = phase2_pushback[--phase2_pushback_length]; if (c == '\n') - ++line_number; + ++line_number; return c; } @@ -534,145 +534,145 @@ phase2_getc () return c; if (c == '\'') return ((open_doublequote - || (open_singlequote && open_singlequote_terminator != c)) - ? QUOTED (c) - : c); + || (open_singlequote && open_singlequote_terminator != c)) + ? QUOTED (c) + : c); if (open_singlequote) { if (c == open_singlequote_terminator) - return c; + return c; } else { if (c == '"' || c == '$') - return c; + return c; if (c == '`') - return (nested_backquotes > 0 ? CLOSING_BACKQUOTE : OPENING_BACKQUOTE); + return (nested_backquotes > 0 ? CLOSING_BACKQUOTE : OPENING_BACKQUOTE); } if (c == '\\') { /* Number of debackslahificication passes that are active at the - current point. */ + current point. */ unsigned int debackslahify = - nested_backquotes + (open_singlequote ? 0 : 1); + nested_backquotes + (open_singlequote ? 0 : 1); /* Normal number of backslashes that yield a single backslash in the - final output. */ + final output. */ unsigned int expected_count = - (unsigned int) 1 << debackslahify; + (unsigned int) 1 << debackslahify; /* Number of backslashes found. */ unsigned int count; for (count = 1; count < expected_count; count++) - { - c = phase1_getc (); - if (c != '\\') - break; - } + { + c = phase1_getc (); + if (c != '\\') + break; + } if (count == expected_count) - return '\\'; + return '\\'; /* The count of backslashes is > 0 and < expected_count, therefore the - result depends on c, the first character after the backslashes. - Note: The formulas below don't necessarily have a logic; they were - empirically determined such that 1. the xgettext-30 test succeeds, - 2. the behaviour for count == 0 would correspond to the one without - any baskslash. */ + result depends on c, the first character after the backslashes. + Note: The formulas below don't necessarily have a logic; they were + empirically determined such that 1. the xgettext-30 test succeeds, + 2. the behaviour for count == 0 would correspond to the one without + any baskslash. */ if (c == '\'') - { - if (!open_singlequote && count > (expected_count >> 1)) - { - phase1_ungetc (c); - return '\\'; - } - else - return ((open_doublequote - || (open_singlequote && open_singlequote_terminator != c)) - ? QUOTED (c) - : c); - } + { + if (!open_singlequote && count > (expected_count >> 1)) + { + phase1_ungetc (c); + return '\\'; + } + else + return ((open_doublequote + || (open_singlequote && open_singlequote_terminator != c)) + ? QUOTED (c) + : c); + } else if (c == '"') - { - /* Each debackslahificication pass converts \\ to \ and \" to "; - passes corresponding to `...` drop a lone " whereas passes - corresponding to "`...`" leave it alone. Therefore, the - minimum number of backslashes needed to get one double-quote - in the end is open_doublequotes_mask + 1. */ - if (open_singlequote) - { - if (count > open_doublequotes_mask) - { - phase1_ungetc (c); - return '\\'; - } - else - return (open_singlequote_terminator != c ? QUOTED (c) : c); - } - else - { - if (count > open_doublequotes_mask) - return QUOTED (c); - else - /* Some of the count values <= open_doublequotes_mask are - actually invalid here, but we assume a syntactically - correct input file anyway. */ - return c; - } - } + { + /* Each debackslahificication pass converts \\ to \ and \" to "; + passes corresponding to `...` drop a lone " whereas passes + corresponding to "`...`" leave it alone. Therefore, the + minimum number of backslashes needed to get one double-quote + in the end is open_doublequotes_mask + 1. */ + if (open_singlequote) + { + if (count > open_doublequotes_mask) + { + phase1_ungetc (c); + return '\\'; + } + else + return (open_singlequote_terminator != c ? QUOTED (c) : c); + } + else + { + if (count > open_doublequotes_mask) + return QUOTED (c); + else + /* Some of the count values <= open_doublequotes_mask are + actually invalid here, but we assume a syntactically + correct input file anyway. */ + return c; + } + } else if (c == '`') - { - /* FIXME: This code looks fishy. */ - if (count == expected_count - 1) - return c; - else - /* Some of the count values < expected_count - 1 are - actually invalid here, but we assume a syntactically - correct input file anyway. */ - if (nested_backquotes > 0 && !open_singlequote - && count >= (expected_count >> 2)) - return OPENING_BACKQUOTE; - else - return CLOSING_BACKQUOTE; - } + { + /* FIXME: This code looks fishy. */ + if (count == expected_count - 1) + return c; + else + /* Some of the count values < expected_count - 1 are + actually invalid here, but we assume a syntactically + correct input file anyway. */ + if (nested_backquotes > 0 && !open_singlequote + && count >= (expected_count >> 2)) + return OPENING_BACKQUOTE; + else + return CLOSING_BACKQUOTE; + } else if (c == '$') - { - if (open_singlequote) - return QUOTED (c); - if (count >= (expected_count >> 1)) - return QUOTED (c); - else - return c; - } + { + if (open_singlequote) + return QUOTED (c); + if (count >= (expected_count >> 1)) + return QUOTED (c); + else + return c; + } else - { - /* When not followed by a quoting character or backslash or dollar, - a backslash survives a debackslahificication pass unmodified. - Therefore each debackslahificication pass performs a - count := (count + 1) >> 1 - operation. Therefore the minimum number of backslashes needed - to get one backslash in the end is (expected_count >> 1) + 1. */ - if (open_doublequote || open_singlequote) - { - if (count > 0) - { - phase1_ungetc (c); - return '\\'; - } - else - return QUOTED (c); - } - else - { - if (count > (expected_count >> 1)) - { - phase1_ungetc (c); - return '\\'; - } - else if (count > 0) - return QUOTED (c); - else - return c; - } - } + { + /* When not followed by a quoting character or backslash or dollar, + a backslash survives a debackslahificication pass unmodified. + Therefore each debackslahificication pass performs a + count := (count + 1) >> 1 + operation. Therefore the minimum number of backslashes needed + to get one backslash in the end is (expected_count >> 1) + 1. */ + if (open_doublequote || open_singlequote) + { + if (count > 0) + { + phase1_ungetc (c); + return '\\'; + } + else + return QUOTED (c); + } + else + { + if (count > (expected_count >> 1)) + { + phase1_ungetc (c); + return '\\'; + } + else if (count > 0) + return QUOTED (c); + else + return c; + } + } } return (open_singlequote || open_doublequote ? QUOTED (c) : c); @@ -693,7 +693,7 @@ phase2_ungetc (int c) default: if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); + abort (); phase2_pushback[phase2_pushback_length++] = c; break; } @@ -706,7 +706,7 @@ static flag_context_list_table_ty *flag_context_list_table; /* Forward declaration of local functions. */ static enum word_type read_command_list (int looking_for, - flag_context_ty outer_context); + flag_context_ty outer_context); @@ -723,31 +723,31 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) { c = phase2_getc (); if (c == '#') - { - /* Skip a comment up to end of line. */ - last_comment_line = line_number; - comment_start (); - for (;;) - { - c = phase1_getc (); - if (c == EOF || c == '\n') - break; - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - } - comment_line_end (); - } + { + /* Skip a comment up to end of line. */ + last_comment_line = line_number; + comment_start (); + for (;;) + { + c = phase1_getc (); + if (c == EOF || c == '\n') + break; + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + } + comment_line_end (); + } if (c == '\n') - { - /* Comments assumed to be grouped with a message must immediately - precede it, with no non-whitespace token on a line between - both. */ - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - wp->type = t_separator; - return; - } + { + /* Comments assumed to be grouped with a message must immediately + precede it, with no non-whitespace token on a line between + both. */ + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + wp->type = t_separator; + return; + } } while (is_whitespace (c)); @@ -760,26 +760,26 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) if (c == '<' || c == '>') { /* Recognize the redirection operators < > >| << <<- >> <> <& >& - But <( and >) are handled below, not here. */ + But <( and >) are handled below, not here. */ int c2 = phase2_getc (); if (c2 != '(') - { - if ((c == '<' ? c2 == '<' : c2 == '|') || c2 == '>' || c2 == '&') - { - if (c == '<' && c2 == '<') - { - int c3 = phase2_getc (); - if (c3 != '-') - phase2_ungetc (c3); - } - } - else - phase2_ungetc (c2); - wp->type = t_redirect; - return; - } + { + if ((c == '<' ? c2 == '<' : c2 == '|') || c2 == '>' || c2 == '&') + { + if (c == '<' && c2 == '<') + { + int c3 = phase2_getc (); + if (c3 != '-') + phase2_ungetc (c3); + } + } + else + phase2_ungetc (c2); + wp->type = t_redirect; + return; + } else - phase2_ungetc (c2); + phase2_ungetc (c2); } if (looking_for == CLOSING_BACKQUOTE && c == CLOSING_BACKQUOTE) @@ -812,357 +812,357 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) for (;; c = phase2_getc ()) { if (c == EOF) - break; + break; if (all_unquoted_digits && (c == '<' || c == '>')) - { - /* Recognize the redirection operators < > >| << <<- >> <> <& >& - prefixed with a nonempty sequence of unquoted digits. */ - int c2 = phase2_getc (); - if ((c == '<' ? c2 == '<' : c2 == '|') || c2 == '>' || c2 == '&') - { - if (c == '<' && c2 == '<') - { - int c3 = phase2_getc (); - if (c3 != '-') - phase2_ungetc (c3); - } - } - else - phase2_ungetc (c2); - - wp->type = t_redirect; - free_token (wp->token); - free (wp->token); - - last_non_comment_line = line_number; - - return; - } + { + /* Recognize the redirection operators < > >| << <<- >> <> <& >& + prefixed with a nonempty sequence of unquoted digits. */ + int c2 = phase2_getc (); + if ((c == '<' ? c2 == '<' : c2 == '|') || c2 == '>' || c2 == '&') + { + if (c == '<' && c2 == '<') + { + int c3 = phase2_getc (); + if (c3 != '-') + phase2_ungetc (c3); + } + } + else + phase2_ungetc (c2); + + wp->type = t_redirect; + free_token (wp->token); + free (wp->token); + + last_non_comment_line = line_number; + + return; + } all_unquoted_digits = all_unquoted_digits && (c >= '0' && c <= '9'); if (c == '$') - { - int c2; - - /* An unquoted dollar indicates we are not inside '...'. */ - if (open_singlequote) - abort (); - /* After reading a dollar, we know that there is no pushed back - character from an earlier lookahead. */ - if (phase2_pushback_length > 0) - abort (); - /* Therefore we can use phase1 without interfering with phase2. - We need to recognize $( outside and inside double-quotes. - It would be incorrect to do - c2 = phase2_getc (); - if (c2 == '(' || c2 == QUOTED ('(')) - because that would also trigger for $\(. */ - c2 = phase1_getc (); - if (c2 == '(') - { - bool saved_open_doublequote; - int c3; - - phase1_ungetc (c2); - - /* The entire inner command or arithmetic expression is read - ignoring possible surrounding double-quotes. */ - saved_open_doublequote = open_doublequote; - open_doublequote = false; - - c2 = phase2_getc (); - if (c2 != '(') - abort (); - - c3 = phase2_getc (); - if (c3 == '(') - { - /* Arithmetic expression (Bash syntax). Skip until the - matching closing parenthesis. */ - unsigned int depth = 2; - - do - { - c = phase2_getc (); - if (c == '(') - depth++; - else if (c == ')') - if (--depth == 0) - break; - } - while (c != EOF); - } - else - { - /* Command substitution (Bash syntax). */ - phase2_ungetc (c3); - read_command_list (')', context); - } - - open_doublequote = saved_open_doublequote; - } - else - { - phase1_ungetc (c2); - c2 = phase2_getc (); - - if (c2 == '\'' && !open_singlequote) - { - /* Bash builtin for string with ANSI-C escape sequences. */ - saw_opening_singlequote (); - for (;;) - { - c = phase2_getc (); - if (c == EOF) - break; - if (c == '\'') - { - saw_closing_singlequote (); - break; - } - if (c == '\\') - { - c = phase2_getc (); - switch (c) - { - default: - phase2_ungetc (c); - c = '\\'; - break; - - case '\\': - break; - case '\'': - /* Don't call saw_closing_singlequote () - here. */ - break; - - case 'a': - c = '\a'; - break; - case 'b': - c = '\b'; - break; - case 'e': - c = 0x1b; /* ESC */ - break; - case 'f': - c = '\f'; - break; - case 'n': - c = '\n'; - break; - case 'r': - c = '\r'; - break; - case 't': - c = '\t'; - break; - case 'v': - c = '\v'; - break; - - case 'x': - c = phase2_getc (); - if ((c >= '0' && c <= '9') - || (c >= 'A' && c <= 'F') - || (c >= 'a' && c <= 'f')) - { - int n; - - if (c >= '0' && c <= '9') - n = c - '0'; - else if (c >= 'A' && c <= 'F') - n = 10 + c - 'A'; - else if (c >= 'a' && c <= 'f') - n = 10 + c - 'a'; - else - abort (); - - c = phase2_getc (); - if ((c >= '0' && c <= '9') - || (c >= 'A' && c <= 'F') - || (c >= 'a' && c <= 'f')) - { - if (c >= '0' && c <= '9') - n = n * 16 + c - '0'; - else if (c >= 'A' && c <= 'F') - n = n * 16 + 10 + c - 'A'; - else if (c >= 'a' && c <= 'f') - n = n * 16 + 10 + c - 'a'; - else - abort (); - } - else - phase2_ungetc (c); - - c = n; - } - else - { - phase2_ungetc (c); - phase2_ungetc ('x'); - c = '\\'; - } - break; - - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - { - int n = c - '0'; - - c = phase2_getc (); - if (c >= '0' && c <= '7') - { - n = n * 8 + c - '0'; - - c = phase2_getc (); - if (c >= '0' && c <= '7') - n = n * 8 + c - '0'; - else - phase2_ungetc (c); - } - else - phase2_ungetc (c); - - c = n; - } - break; - } - } - if (wp->type == t_string) - { - grow_token (wp->token); - wp->token->chars[wp->token->charcount++] = - (unsigned char) c; - } - } - /* The result is a literal string. Don't change wp->type. */ - continue; - } - else if (c2 == '"' && !open_doublequote) - { - /* Bash builtin for internationalized string. */ - lex_pos_ty pos; - struct token string; - - saw_opening_singlequote (); - open_singlequote_terminator = '"'; - pos.file_name = logical_file_name; - pos.line_number = line_number; - init_token (&string); - for (;;) - { - c = phase2_getc (); - if (c == EOF) - break; - if (c == '"') - { - saw_closing_singlequote (); - break; - } - grow_token (&string); - string.chars[string.charcount++] = (unsigned char) c; - } - remember_a_message (mlp, NULL, string_of_token (&string), - context, &pos, NULL, savable_comment); - free_token (&string); - - error_with_progname = false; - error (0, 0, _("%s:%lu: warning: the syntax $\"...\" is deprecated due to security reasons; use eval_gettext instead"), - pos.file_name, (unsigned long) pos.line_number); - error_with_progname = true; - - /* The result at runtime is not constant. Therefore we - change wp->type. */ - } - else - phase2_ungetc (c2); - } - wp->type = t_other; - continue; - } + { + int c2; + + /* An unquoted dollar indicates we are not inside '...'. */ + if (open_singlequote) + abort (); + /* After reading a dollar, we know that there is no pushed back + character from an earlier lookahead. */ + if (phase2_pushback_length > 0) + abort (); + /* Therefore we can use phase1 without interfering with phase2. + We need to recognize $( outside and inside double-quotes. + It would be incorrect to do + c2 = phase2_getc (); + if (c2 == '(' || c2 == QUOTED ('(')) + because that would also trigger for $\(. */ + c2 = phase1_getc (); + if (c2 == '(') + { + bool saved_open_doublequote; + int c3; + + phase1_ungetc (c2); + + /* The entire inner command or arithmetic expression is read + ignoring possible surrounding double-quotes. */ + saved_open_doublequote = open_doublequote; + open_doublequote = false; + + c2 = phase2_getc (); + if (c2 != '(') + abort (); + + c3 = phase2_getc (); + if (c3 == '(') + { + /* Arithmetic expression (Bash syntax). Skip until the + matching closing parenthesis. */ + unsigned int depth = 2; + + do + { + c = phase2_getc (); + if (c == '(') + depth++; + else if (c == ')') + if (--depth == 0) + break; + } + while (c != EOF); + } + else + { + /* Command substitution (Bash syntax). */ + phase2_ungetc (c3); + read_command_list (')', context); + } + + open_doublequote = saved_open_doublequote; + } + else + { + phase1_ungetc (c2); + c2 = phase2_getc (); + + if (c2 == '\'' && !open_singlequote) + { + /* Bash builtin for string with ANSI-C escape sequences. */ + saw_opening_singlequote (); + for (;;) + { + c = phase2_getc (); + if (c == EOF) + break; + if (c == '\'') + { + saw_closing_singlequote (); + break; + } + if (c == '\\') + { + c = phase2_getc (); + switch (c) + { + default: + phase2_ungetc (c); + c = '\\'; + break; + + case '\\': + break; + case '\'': + /* Don't call saw_closing_singlequote () + here. */ + break; + + case 'a': + c = '\a'; + break; + case 'b': + c = '\b'; + break; + case 'e': + c = 0x1b; /* ESC */ + break; + case 'f': + c = '\f'; + break; + case 'n': + c = '\n'; + break; + case 'r': + c = '\r'; + break; + case 't': + c = '\t'; + break; + case 'v': + c = '\v'; + break; + + case 'x': + c = phase2_getc (); + if ((c >= '0' && c <= '9') + || (c >= 'A' && c <= 'F') + || (c >= 'a' && c <= 'f')) + { + int n; + + if (c >= '0' && c <= '9') + n = c - '0'; + else if (c >= 'A' && c <= 'F') + n = 10 + c - 'A'; + else if (c >= 'a' && c <= 'f') + n = 10 + c - 'a'; + else + abort (); + + c = phase2_getc (); + if ((c >= '0' && c <= '9') + || (c >= 'A' && c <= 'F') + || (c >= 'a' && c <= 'f')) + { + if (c >= '0' && c <= '9') + n = n * 16 + c - '0'; + else if (c >= 'A' && c <= 'F') + n = n * 16 + 10 + c - 'A'; + else if (c >= 'a' && c <= 'f') + n = n * 16 + 10 + c - 'a'; + else + abort (); + } + else + phase2_ungetc (c); + + c = n; + } + else + { + phase2_ungetc (c); + phase2_ungetc ('x'); + c = '\\'; + } + break; + + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + { + int n = c - '0'; + + c = phase2_getc (); + if (c >= '0' && c <= '7') + { + n = n * 8 + c - '0'; + + c = phase2_getc (); + if (c >= '0' && c <= '7') + n = n * 8 + c - '0'; + else + phase2_ungetc (c); + } + else + phase2_ungetc (c); + + c = n; + } + break; + } + } + if (wp->type == t_string) + { + grow_token (wp->token); + wp->token->chars[wp->token->charcount++] = + (unsigned char) c; + } + } + /* The result is a literal string. Don't change wp->type. */ + continue; + } + else if (c2 == '"' && !open_doublequote) + { + /* Bash builtin for internationalized string. */ + lex_pos_ty pos; + struct token string; + + saw_opening_singlequote (); + open_singlequote_terminator = '"'; + pos.file_name = logical_file_name; + pos.line_number = line_number; + init_token (&string); + for (;;) + { + c = phase2_getc (); + if (c == EOF) + break; + if (c == '"') + { + saw_closing_singlequote (); + break; + } + grow_token (&string); + string.chars[string.charcount++] = (unsigned char) c; + } + remember_a_message (mlp, NULL, string_of_token (&string), + context, &pos, NULL, savable_comment); + free_token (&string); + + error_with_progname = false; + error (0, 0, _("%s:%lu: warning: the syntax $\"...\" is deprecated due to security reasons; use eval_gettext instead"), + pos.file_name, (unsigned long) pos.line_number); + error_with_progname = true; + + /* The result at runtime is not constant. Therefore we + change wp->type. */ + } + else + phase2_ungetc (c2); + } + wp->type = t_other; + continue; + } if (c == '\'') - { - if (!open_singlequote) - { - /* Handle an opening single quote. */ - saw_opening_singlequote (); - } - else - { - /* Handle a closing single quote. */ - saw_closing_singlequote (); - } - continue; - } + { + if (!open_singlequote) + { + /* Handle an opening single quote. */ + saw_opening_singlequote (); + } + else + { + /* Handle a closing single quote. */ + saw_closing_singlequote (); + } + continue; + } if (c == '"') - { - if (open_singlequote && open_singlequote_terminator == '"') - { - /* Handle a closing i18n quote. */ - saw_closing_singlequote (); - } - else if (!open_doublequote) - { - /* Handle an opening double quote. */ - saw_opening_doublequote (); - } - else - { - /* Handle a closing double quote. */ - saw_closing_doublequote (); - } - continue; - } + { + if (open_singlequote && open_singlequote_terminator == '"') + { + /* Handle a closing i18n quote. */ + saw_closing_singlequote (); + } + else if (!open_doublequote) + { + /* Handle an opening double quote. */ + saw_opening_doublequote (); + } + else + { + /* Handle a closing double quote. */ + saw_closing_doublequote (); + } + continue; + } if (c == OPENING_BACKQUOTE) - { - /* Handle an opening backquote. */ - saw_opening_backquote (); + { + /* Handle an opening backquote. */ + saw_opening_backquote (); - read_command_list (CLOSING_BACKQUOTE, context); + read_command_list (CLOSING_BACKQUOTE, context); - wp->type = t_other; - continue; - } + wp->type = t_other; + continue; + } if (c == CLOSING_BACKQUOTE) - break; + break; if (c == '<' || c == '>') - { - int c2; - - /* An unquoted c indicates we are not inside '...' nor "...". */ - if (open_singlequote || open_doublequote) - abort (); - - c2 = phase2_getc (); - if (c2 == '(') - { - /* Process substitution (Bash syntax). */ - read_command_list (')', context); - - wp->type = t_other; - continue; - } - else - phase2_ungetc (c2); - } + { + int c2; + + /* An unquoted c indicates we are not inside '...' nor "...". */ + if (open_singlequote || open_doublequote) + abort (); + + c2 = phase2_getc (); + if (c2 == '(') + { + /* Process substitution (Bash syntax). */ + read_command_list (')', context); + + wp->type = t_other; + continue; + } + else + phase2_ungetc (c2); + } if (!open_singlequote && !open_doublequote - && (is_whitespace (c) || is_operator_start (c))) - break; + && (is_whitespace (c) || is_operator_start (c))) + break; if (wp->type == t_string) - { - grow_token (wp->token); - wp->token->chars[wp->token->charcount++] = (unsigned char) c; - } + { + grow_token (wp->token); + wp->token->chars[wp->token->charcount++] = (unsigned char) c; + } } phase2_ungetc (c); @@ -1193,8 +1193,8 @@ read_command (int looking_for, flag_context_ty outer_context) like "$verbose" that may expand to nothing, and 2. it's a big effort to know where a command starts in a $(for ...) or $(case ...) compound command. */ - int arg = 0; /* Current argument number. */ - bool arg_of_redirect = false; /* True right after a redirection operator. */ + int arg = 0; /* Current argument number. */ + bool arg_of_redirect = false; /* True right after a redirection operator. */ flag_context_list_iterator_ty context_iter; const struct callshapes *shapes = NULL; struct arglist_parser *argparser = NULL; @@ -1205,101 +1205,101 @@ read_command (int looking_for, flag_context_ty outer_context) flag_context_ty inner_context; if (arg == 0) - inner_context = null_context; + inner_context = null_context; else - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); read_word (&inner, looking_for, inner_context); /* Recognize end of command. */ if (inner.type == t_separator - || inner.type == t_backquote || inner.type == t_paren - || inner.type == t_eof) - { - if (argparser != NULL) - arglist_parser_done (argparser, arg); - return inner.type; - } + || inner.type == t_backquote || inner.type == t_paren + || inner.type == t_eof) + { + if (argparser != NULL) + arglist_parser_done (argparser, arg); + return inner.type; + } if (extract_all) - { - if (inner.type == t_string) - { - lex_pos_ty pos; - - pos.file_name = logical_file_name; - pos.line_number = inner.line_number_at_start; - remember_a_message (mlp, NULL, string_of_word (&inner), - inner_context, &pos, NULL, savable_comment); - } - } + { + if (inner.type == t_string) + { + lex_pos_ty pos; + + pos.file_name = logical_file_name; + pos.line_number = inner.line_number_at_start; + remember_a_message (mlp, NULL, string_of_word (&inner), + inner_context, &pos, NULL, savable_comment); + } + } if (arg_of_redirect) - { - /* Ignore arguments of redirection operators. */ - arg_of_redirect = false; - } + { + /* Ignore arguments of redirection operators. */ + arg_of_redirect = false; + } else if (inner.type == t_redirect) - { - /* Ignore this word and the following one. */ - arg_of_redirect = true; - } + { + /* Ignore this word and the following one. */ + arg_of_redirect = true; + } else - { - if (argparser == NULL) - { - /* This is the function position. */ - arg = 0; - if (inner.type == t_string) - { - char *function_name = string_of_word (&inner); - void *keyword_value; - - if (hash_find_entry (&keywords, - function_name, strlen (function_name), - &keyword_value) - == 0) - shapes = (const struct callshapes *) keyword_value; - - argparser = arglist_parser_alloc (mlp, shapes); - - context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - function_name, strlen (function_name))); - - free (function_name); - } - else - context_iter = null_context_list_iterator; - } - else - { - /* These are the argument positions. */ - if (inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_word (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); - - if (arglist_parser_decidedp (argparser, arg)) - { - /* Stop looking for arguments of the last function_name. */ - /* FIXME: What about context_iter? */ - arglist_parser_done (argparser, arg); - shapes = NULL; - argparser = NULL; - } - } - - arg++; - } + { + if (argparser == NULL) + { + /* This is the function position. */ + arg = 0; + if (inner.type == t_string) + { + char *function_name = string_of_word (&inner); + void *keyword_value; + + if (hash_find_entry (&keywords, + function_name, strlen (function_name), + &keyword_value) + == 0) + shapes = (const struct callshapes *) keyword_value; + + argparser = arglist_parser_alloc (mlp, shapes); + + context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + function_name, strlen (function_name))); + + free (function_name); + } + else + context_iter = null_context_list_iterator; + } + else + { + /* These are the argument positions. */ + if (inner.type == t_string) + arglist_parser_remember (argparser, arg, + string_of_word (&inner), + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + + if (arglist_parser_decidedp (argparser, arg)) + { + /* Stop looking for arguments of the last function_name. */ + /* FIXME: What about context_iter? */ + arglist_parser_done (argparser, arg); + shapes = NULL; + argparser = NULL; + } + } + + arg++; + } free_word (&inner); } @@ -1319,16 +1319,16 @@ read_command_list (int looking_for, flag_context_ty outer_context) terminator = read_command (looking_for, outer_context); if (terminator != t_separator) - return terminator; + return terminator; } } void extract_sh (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { mlp = mdlp->item[0]->messages; diff --git a/gettext-tools/src/x-sh.h b/gettext-tools/src/x-sh.h index d7c857650..a07954e4d 100644 --- a/gettext-tools/src/x-sh.h +++ b/gettext-tools/src/x-sh.h @@ -28,18 +28,18 @@ extern "C" { #define EXTENSIONS_SH \ - { "sh", "Shell" }, \ - { "bash", "Shell" }, \ + { "sh", "Shell" }, \ + { "bash", "Shell" }, \ #define SCANNERS_SH \ - { "Shell", extract_sh, \ - &flag_table_sh, &formatstring_sh, NULL }, \ + { "Shell", extract_sh, \ + &flag_table_sh, &formatstring_sh, NULL }, \ /* Scan a shell script file and add its translatable strings to mdlp. */ extern void extract_sh (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); extern void x_sh_keyword (const char *keyword); extern void x_sh_extract_all (void); diff --git a/gettext-tools/src/x-smalltalk.c b/gettext-tools/src/x-smalltalk.c index 06acd5ab9..dbd0aa57e 100644 --- a/gettext-tools/src/x-smalltalk.c +++ b/gettext-tools/src/x-smalltalk.c @@ -88,8 +88,8 @@ phase1_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_file_name); return EOF; } @@ -106,7 +106,7 @@ phase1_ungetc (int c) if (c != EOF) { if (c == '\n') - --line_number; + --line_number; ungetc (c, fp); } @@ -140,7 +140,7 @@ static inline void comment_line_end () { while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; if (buflen >= bufmax) { @@ -164,10 +164,10 @@ static int last_non_comment_line; enum token_type_ty { token_type_eof, - token_type_uniq, /* # */ - token_type_symbol, /* symbol */ - token_type_string_literal, /* string, stringconst, symbolconst */ - token_type_other /* misc. operator */ + token_type_uniq, /* # */ + token_type_symbol, /* symbol */ + token_type_string_literal, /* string, stringconst, symbolconst */ + token_type_other /* misc. operator */ }; typedef enum token_type_ty token_type_ty; @@ -175,7 +175,7 @@ typedef struct token_ty token_ty; struct token_ty { token_type_ty type; - char *string; /* for token_type_string_literal, token_type_symbol */ + char *string; /* for token_type_string_literal, token_type_symbol */ int line_number; }; @@ -206,234 +206,234 @@ phase2_get (token_ty *tp) tp->line_number = line_number; c = phase1_getc (); switch (c) - { - case EOF: - tp->type = token_type_eof; - return; - - case '"': - { - /* Comment. */ - int lineno; - - comment_start (); - lineno = line_number; - for (;;) - { - c = phase1_getc (); - if (c == '"' || c == EOF) - break; - if (c == '\n') - { - comment_line_end (); - comment_start (); - } - else - { - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - } - } - comment_line_end (); - last_comment_line = lineno; - continue; - } - - case '\n': - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - /* FALLTHROUGH */ - case ' ': - case '\t': - case '\r': - /* Ignore whitespace. */ - continue; - } + { + case EOF: + tp->type = token_type_eof; + return; + + case '"': + { + /* Comment. */ + int lineno; + + comment_start (); + lineno = line_number; + for (;;) + { + c = phase1_getc (); + if (c == '"' || c == EOF) + break; + if (c == '\n') + { + comment_line_end (); + comment_start (); + } + else + { + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + } + } + comment_line_end (); + last_comment_line = lineno; + continue; + } + + case '\n': + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + /* FALLTHROUGH */ + case ' ': + case '\t': + case '\r': + /* Ignore whitespace. */ + continue; + } last_non_comment_line = tp->line_number; switch (c) - { - case '\'': - /* String literal. */ - bufpos = 0; - for (;;) - { - c = phase1_getc (); - if (c == EOF) - break; - if (c == '\'') - { - c = phase1_getc (); - if (c != '\'') - { - phase1_ungetc (c); - break; - } - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = 0; - tp->type = token_type_string_literal; - tp->string = xstrdup (buffer); - return; - - case '+': - case '-': - case '*': - case '/': - case '~': - case '|': - case ',': - case '<': - case '>': - case '=': - case '&': - case '@': - case '?': - case '%': - case '\\': - { - char *name; - int c2 = phase1_getc (); - switch (c2) - { - case '+': - case '-': - case '*': - case '/': - case '~': - case '|': - case ',': - case '<': - case '>': - case '=': - case '&': - case '@': - case '?': - case '%': - name = XNMALLOC (3, char); - name[0] = c; - name[1] = c2; - name[2] = '\0'; - tp->type = token_type_symbol; - tp->string = name; - return; - default: - phase1_ungetc (c2); - break; - } - name = XNMALLOC (2, char); - name[0] = c; - name[1] = '\0'; - tp->type = token_type_symbol; - tp->string = name; - return; - } - - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - /* Recognize id or id":"[id":"]* or id":"[id":"]*id. */ - bufpos = 0; - for (;;) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase1_getc (); - switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - continue; - case ':': - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase1_getc (); - switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - continue; - default: - phase1_ungetc (c); - break; - } - break; - default: - phase1_ungetc (c); - break; - } - break; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = '\0'; - tp->string = xstrdup (buffer); - tp->type = token_type_symbol; - return; - - case '#': - /* Uniquification operator. */ - tp->type = token_type_uniq; - return; - - case '$': - c = phase1_getc (); - tp->type = token_type_other; - return; - - default: - tp->type = token_type_other; - return; - } + { + case '\'': + /* String literal. */ + bufpos = 0; + for (;;) + { + c = phase1_getc (); + if (c == EOF) + break; + if (c == '\'') + { + c = phase1_getc (); + if (c != '\'') + { + phase1_ungetc (c); + break; + } + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = 0; + tp->type = token_type_string_literal; + tp->string = xstrdup (buffer); + return; + + case '+': + case '-': + case '*': + case '/': + case '~': + case '|': + case ',': + case '<': + case '>': + case '=': + case '&': + case '@': + case '?': + case '%': + case '\\': + { + char *name; + int c2 = phase1_getc (); + switch (c2) + { + case '+': + case '-': + case '*': + case '/': + case '~': + case '|': + case ',': + case '<': + case '>': + case '=': + case '&': + case '@': + case '?': + case '%': + name = XNMALLOC (3, char); + name[0] = c; + name[1] = c2; + name[2] = '\0'; + tp->type = token_type_symbol; + tp->string = name; + return; + default: + phase1_ungetc (c2); + break; + } + name = XNMALLOC (2, char); + name[0] = c; + name[1] = '\0'; + tp->type = token_type_symbol; + tp->string = name; + return; + } + + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + /* Recognize id or id":"[id":"]* or id":"[id":"]*id. */ + bufpos = 0; + for (;;) + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase1_getc (); + switch (c) + { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + continue; + case ':': + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase1_getc (); + switch (c) + { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + continue; + default: + phase1_ungetc (c); + break; + } + break; + default: + phase1_ungetc (c); + break; + } + break; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = '\0'; + tp->string = xstrdup (buffer); + tp->type = token_type_symbol; + return; + + case '#': + /* Uniquification operator. */ + tp->type = token_type_uniq; + return; + + case '$': + c = phase1_getc (); + tp->type = token_type_other; + return; + + default: + tp->type = token_type_other; + return; + } } } @@ -444,7 +444,7 @@ phase2_unget (token_ty *tp) if (tp->type != token_type_eof) { if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); + abort (); phase2_pushback[phase2_pushback_length++] = *tp; } } @@ -462,13 +462,13 @@ x_smalltalk_lex (token_ty *tp) phase2_get (&token2); if (token2.type == token_type_symbol - || token2.type == token_type_string_literal) - { - tp->type = token_type_string_literal; - tp->string = token2.string; - } + || token2.type == token_type_string_literal) + { + tp->type = token_type_string_literal; + tp->string = token2.string; + } else - phase2_unget (&token2); + phase2_unget (&token2); } } @@ -488,9 +488,9 @@ x_smalltalk_lex (token_ty *tp) void extract_smalltalk (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { message_list_ty *mlp = mdlp->item[0]->messages; @@ -520,72 +520,72 @@ extract_smalltalk (FILE *f, for (;;) { - token_ty token; - - x_smalltalk_lex (&token); - - switch (token.type) - { - case token_type_symbol: - state = (strcmp (token.string, "NLS") == 0 ? 1 : - strcmp (token.string, "?") == 0 && state == 1 ? 2 : - strcmp (token.string, "at:") == 0 && state == 1 ? 3 : - strcmp (token.string, "plural:") == 0 && state == 4 ? 5 : - 0); - free (token.string); - break; - - case token_type_string_literal: - if (state == 2) - { - lex_pos_ty pos; - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - remember_a_message (mlp, NULL, token.string, null_context, - &pos, NULL, savable_comment); - state = 0; - break; - } - if (state == 3) - { - lex_pos_ty pos; - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - plural_mp = remember_a_message (mlp, NULL, token.string, - null_context, &pos, - NULL, savable_comment); - state = 4; - break; - } - if (state == 5) - { - lex_pos_ty pos; - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - remember_a_message_plural (plural_mp, token.string, - null_context, &pos, - savable_comment); - state = 0; - break; - } - state = 0; - free (token.string); - break; - - case token_type_uniq: - case token_type_other: - state = 0; - break; - - case token_type_eof: - break; - - default: - abort (); - } - - if (token.type == token_type_eof) - break; + token_ty token; + + x_smalltalk_lex (&token); + + switch (token.type) + { + case token_type_symbol: + state = (strcmp (token.string, "NLS") == 0 ? 1 : + strcmp (token.string, "?") == 0 && state == 1 ? 2 : + strcmp (token.string, "at:") == 0 && state == 1 ? 3 : + strcmp (token.string, "plural:") == 0 && state == 4 ? 5 : + 0); + free (token.string); + break; + + case token_type_string_literal: + if (state == 2) + { + lex_pos_ty pos; + pos.file_name = logical_file_name; + pos.line_number = token.line_number; + remember_a_message (mlp, NULL, token.string, null_context, + &pos, NULL, savable_comment); + state = 0; + break; + } + if (state == 3) + { + lex_pos_ty pos; + pos.file_name = logical_file_name; + pos.line_number = token.line_number; + plural_mp = remember_a_message (mlp, NULL, token.string, + null_context, &pos, + NULL, savable_comment); + state = 4; + break; + } + if (state == 5) + { + lex_pos_ty pos; + pos.file_name = logical_file_name; + pos.line_number = token.line_number; + remember_a_message_plural (plural_mp, token.string, + null_context, &pos, + savable_comment); + state = 0; + break; + } + state = 0; + free (token.string); + break; + + case token_type_uniq: + case token_type_other: + state = 0; + break; + + case token_type_eof: + break; + + default: + abort (); + } + + if (token.type == token_type_eof) + break; } } diff --git a/gettext-tools/src/x-smalltalk.h b/gettext-tools/src/x-smalltalk.h index cdfdfd97f..def25ffed 100644 --- a/gettext-tools/src/x-smalltalk.h +++ b/gettext-tools/src/x-smalltalk.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_SMALLTALK \ - { "st", "Smalltalk" }, \ + { "st", "Smalltalk" }, \ #define SCANNERS_SMALLTALK \ - { "Smalltalk", extract_smalltalk, \ - NULL, &formatstring_smalltalk, NULL }, \ + { "Smalltalk", extract_smalltalk, \ + NULL, &formatstring_smalltalk, NULL }, \ /* Scan a Smalltalk file and add its translatable strings to mdlp. */ extern void extract_smalltalk (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); #ifdef __cplusplus diff --git a/gettext-tools/src/x-stringtable.h b/gettext-tools/src/x-stringtable.h index 67b39ed4a..c405c0cb3 100644 --- a/gettext-tools/src/x-stringtable.h +++ b/gettext-tools/src/x-stringtable.h @@ -28,16 +28,16 @@ extern "C" { #define EXTENSIONS_STRINGTABLE \ - { "strings", "NXStringTable" }, \ + { "strings", "NXStringTable" }, \ #define SCANNERS_STRINGTABLE \ - { "NXStringTable", extract_stringtable, NULL, NULL, NULL }, \ + { "NXStringTable", extract_stringtable, NULL, NULL, NULL }, \ /* Scan a JavaProperties file and add its translatable strings to mdlp. */ extern void extract_stringtable (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); #ifdef __cplusplus diff --git a/gettext-tools/src/x-tcl.c b/gettext-tools/src/x-tcl.c index e9c05e750..82bf19d81 100644 --- a/gettext-tools/src/x-tcl.c +++ b/gettext-tools/src/x-tcl.c @@ -90,14 +90,14 @@ x_tcl_keyword (const char *name) struct callshape shape; if (keywords.table == NULL) - hash_init (&keywords, 100); + hash_init (&keywords, 100); split_keywordspec (name, &end, &shape); /* The characters between name and end should form a valid Tcl - function name. A leading "::" is redundant. */ + function name. A leading "::" is redundant. */ if (end - name >= 2 && name[0] == ':' && name[1] == ':') - name += 2; + name += 2; insert_keyword_callshape (&keywords, name, end - name, &shape); } @@ -111,7 +111,7 @@ init_keywords () if (default_keywords) { /* When adding new keywords here, also update the documentation in - xgettext.texi! */ + xgettext.texi! */ x_tcl_keyword ("::msgcat::mc"); default_keywords = false; } @@ -147,7 +147,7 @@ do_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("\ + error (EXIT_FAILURE, errno, _("\ error while reading \"%s\""), real_file_name); } else if (c == '\n') @@ -184,7 +184,7 @@ phase1_getc () { c = phase1_pushback[--phase1_pushback_length]; if (c == '\n' || c == BS_NL) - ++line_number; + ++line_number; return c; } c = do_getc (); @@ -194,14 +194,14 @@ phase1_getc () if (c != '\n') { if (c != EOF) - do_ungetc (c); + do_ungetc (c); return '\\'; } for (;;) { c = do_getc (); if (!(c == ' ' || c == '\t')) - break; + break; } if (c != EOF) do_ungetc (c); @@ -224,7 +224,7 @@ phase1_ungetc (int c) default: if (phase1_pushback_length == SIZEOF (phase1_pushback)) - abort (); + abort (); phase1_pushback[phase1_pushback_length++] = c; break; } @@ -270,11 +270,11 @@ phase2_getc () { c = phase2_pushback[--phase2_pushback_length]; if (c == '\n' || c == BS_NL) - ++line_number; + ++line_number; else if (c == '{') - ++brace_depth; + ++brace_depth; else if (c == '}') - --brace_depth; + --brace_depth; return c; } c = phase1_getc (); @@ -283,7 +283,7 @@ phase2_getc () else if (c == '}') { if (--brace_depth == 0) - c = CL_BRACE; + c = CL_BRACE; } return c; } @@ -295,22 +295,22 @@ phase2_ungetc (int c) if (c != EOF) { switch (c) - { - case '\n': - case BS_NL: - --line_number; - break; - - case '{': - --brace_depth; - break; - - case '}': - ++brace_depth; - break; - } + { + case '\n': + case BS_NL: + --line_number; + break; + + case '{': + --brace_depth; + break; + + case '}': + ++brace_depth; + break; + } if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); + abort (); phase2_pushback[phase2_pushback_length++] = c; } } @@ -322,9 +322,9 @@ phase2_ungetc (int c) /* A token consists of a sequence of characters. */ struct token { - int allocated; /* number of allocated 'token_char's */ - int charcount; /* number of used 'token_char's */ - char *chars; /* the token's constituents */ + int allocated; /* number of allocated 'token_char's */ + int charcount; /* number of used 'token_char's */ + char *chars; /* the token's constituents */ }; /* Initialize a 'struct token'. */ @@ -383,7 +383,7 @@ static inline void comment_line_end () { while (buflen >= 1 - && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) + && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t')) --buflen; if (buflen >= bufmax) { @@ -414,19 +414,19 @@ static message_list_ty *mlp; string literals). Other words need not to be represented precisely. */ enum word_type { - t_string, /* constant string */ - t_other, /* other string */ - t_separator, /* command separator: semicolon or newline */ - t_bracket, /* ']' pseudo word */ - t_brace, /* '}' pseudo word */ - t_eof /* EOF marker */ + t_string, /* constant string */ + t_other, /* other string */ + t_separator, /* command separator: semicolon or newline */ + t_bracket, /* ']' pseudo word */ + t_brace, /* '}' pseudo word */ + t_eof /* EOF marker */ }; struct word { enum word_type type; - struct token *token; /* for t_string */ - int line_number_at_start; /* for t_string */ + struct token *token; /* for t_string */ + int line_number_at_start; /* for t_string */ }; /* Free the memory pointed to by a 'struct word'. */ @@ -489,70 +489,70 @@ do_getc_escaped () return '\v'; case 'x': { - int n = 0; - unsigned int i; - - for (i = 0;; i++) - { - c = phase1_getc (); - if (c == EOF || !c_isxdigit ((unsigned char) c)) - break; - - if (c >= '0' && c <= '9') - n = (n << 4) + (c - '0'); - else if (c >= 'A' && c <= 'F') - n = (n << 4) + (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - n = (n << 4) + (c - 'a' + 10); - } - phase1_ungetc (c); - return (i > 0 ? (unsigned char) n : 'x'); + int n = 0; + unsigned int i; + + for (i = 0;; i++) + { + c = phase1_getc (); + if (c == EOF || !c_isxdigit ((unsigned char) c)) + break; + + if (c >= '0' && c <= '9') + n = (n << 4) + (c - '0'); + else if (c >= 'A' && c <= 'F') + n = (n << 4) + (c - 'A' + 10); + else if (c >= 'a' && c <= 'f') + n = (n << 4) + (c - 'a' + 10); + } + phase1_ungetc (c); + return (i > 0 ? (unsigned char) n : 'x'); } case 'u': { - int n = 0; - unsigned int i; - - for (i = 0; i < 4; i++) - { - c = phase1_getc (); - if (c == EOF || !c_isxdigit ((unsigned char) c)) - break; - - if (c >= '0' && c <= '9') - n = (n << 4) + (c - '0'); - else if (c >= 'A' && c <= 'F') - n = (n << 4) + (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - n = (n << 4) + (c - 'a' + 10); - } - phase1_ungetc (c); - return (i > 0 ? n : 'u'); + int n = 0; + unsigned int i; + + for (i = 0; i < 4; i++) + { + c = phase1_getc (); + if (c == EOF || !c_isxdigit ((unsigned char) c)) + break; + + if (c >= '0' && c <= '9') + n = (n << 4) + (c - '0'); + else if (c >= 'A' && c <= 'F') + n = (n << 4) + (c - 'A' + 10); + else if (c >= 'a' && c <= 'f') + n = (n << 4) + (c - 'a' + 10); + } + phase1_ungetc (c); + return (i > 0 ? n : 'u'); } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { - int n = c - '0'; - - c = phase1_getc (); - if (c != EOF) - { - if (c >= '0' && c <= '7') - { - n = (n << 3) + (c - '0'); - c = phase1_getc (); - if (c != EOF) - { - if (c >= '0' && c <= '7') - n = (n << 3) + (c - '0'); - else - phase1_ungetc (c); - } - } - else - phase1_ungetc (c); - } - return (unsigned char) n; + int n = c - '0'; + + c = phase1_getc (); + if (c != EOF) + { + if (c >= '0' && c <= '7') + { + n = (n << 3) + (c - '0'); + c = phase1_getc (); + if (c != EOF) + { + if (c >= '0' && c <= '7') + n = (n << 3) + (c - '0'); + else + phase1_ungetc (c); + } + } + else + phase1_ungetc (c); + } + return (unsigned char) n; } default: /* Note: If c is non-ASCII, Tcl's behaviour is undefined here. */ @@ -563,22 +563,22 @@ do_getc_escaped () enum terminator { - te_space_separator, /* looking for space semicolon newline */ - te_space_separator_bracket, /* looking for space semicolon newline ']' */ - te_paren, /* looking for ')' */ - te_quote /* looking for '"' */ + te_space_separator, /* looking for space semicolon newline */ + te_space_separator_bracket, /* looking for space semicolon newline ']' */ + te_paren, /* looking for ')' */ + te_quote /* looking for '"' */ }; /* Forward declaration of local functions. */ static enum word_type read_command_list (int looking_for, - flag_context_ty outer_context); + flag_context_ty outer_context); /* Accumulate tokens into the given word. 'looking_for' denotes a parse terminator combination. Return the first character past the token. */ static int accumulate_word (struct word *wp, enum terminator looking_for, - flag_context_ty context) + flag_context_ty context) { int c; @@ -587,123 +587,123 @@ accumulate_word (struct word *wp, enum terminator looking_for, c = phase2_getc (); if (c == EOF || c == CL_BRACE) - return c; + return c; if ((looking_for == te_space_separator - || looking_for == te_space_separator_bracket) - && (c == ' ' || c == BS_NL - || c == '\t' || c == '\v' || c == '\f' || c == '\r' - || c == ';' || c == '\n')) - return c; + || looking_for == te_space_separator_bracket) + && (c == ' ' || c == BS_NL + || c == '\t' || c == '\v' || c == '\f' || c == '\r' + || c == ';' || c == '\n')) + return c; if (looking_for == te_space_separator_bracket && c == ']') - return c; + return c; if (looking_for == te_paren && c == ')') - return c; + return c; if (looking_for == te_quote && c == '"') - return c; + return c; if (c == '$') - { - /* Distinguish $varname, ${varname} and lone $. */ - c = phase2_getc (); - if (c == '{') - { - /* ${varname} */ - do - c = phase2_getc (); - while (c != EOF && c != '}'); - wp->type = t_other; - } - else - { - bool nonempty = false; - - for (; c != EOF && c != CL_BRACE; c = phase2_getc ()) - { - if (c_isalnum ((unsigned char) c) || (c == '_')) - { - nonempty = true; - continue; - } - if (c == ':') - { - c = phase2_getc (); - if (c == ':') - { - do - c = phase2_getc (); - while (c == ':'); - - phase2_ungetc (c); - nonempty = true; - continue; - } - phase2_ungetc (c); - c = ':'; - } - break; - } - if (c == '(') - { - /* $varname(index) */ - struct word index_word; - - index_word.type = t_other; - c = accumulate_word (&index_word, te_paren, null_context); - if (c != EOF && c != ')') - phase2_ungetc (c); - wp->type = t_other; - } - else - { - phase2_ungetc (c); - if (nonempty) - { - /* $varname */ - wp->type = t_other; - } - else - { - /* lone $ */ - if (wp->type == t_string) - { - grow_token (wp->token); - wp->token->chars[wp->token->charcount++] = '$'; - } - } - } - } - } + { + /* Distinguish $varname, ${varname} and lone $. */ + c = phase2_getc (); + if (c == '{') + { + /* ${varname} */ + do + c = phase2_getc (); + while (c != EOF && c != '}'); + wp->type = t_other; + } + else + { + bool nonempty = false; + + for (; c != EOF && c != CL_BRACE; c = phase2_getc ()) + { + if (c_isalnum ((unsigned char) c) || (c == '_')) + { + nonempty = true; + continue; + } + if (c == ':') + { + c = phase2_getc (); + if (c == ':') + { + do + c = phase2_getc (); + while (c == ':'); + + phase2_ungetc (c); + nonempty = true; + continue; + } + phase2_ungetc (c); + c = ':'; + } + break; + } + if (c == '(') + { + /* $varname(index) */ + struct word index_word; + + index_word.type = t_other; + c = accumulate_word (&index_word, te_paren, null_context); + if (c != EOF && c != ')') + phase2_ungetc (c); + wp->type = t_other; + } + else + { + phase2_ungetc (c); + if (nonempty) + { + /* $varname */ + wp->type = t_other; + } + else + { + /* lone $ */ + if (wp->type == t_string) + { + grow_token (wp->token); + wp->token->chars[wp->token->charcount++] = '$'; + } + } + } + } + } else if (c == '[') - { - read_command_list (']', context); - wp->type = t_other; - } + { + read_command_list (']', context); + wp->type = t_other; + } else if (c == '\\') - { - unsigned int uc; - unsigned char utf8buf[6]; - int count; - int i; - - uc = do_getc_escaped (); - assert (uc < 0x10000); - count = u8_uctomb (utf8buf, uc, 6); - assert (count > 0); - if (wp->type == t_string) - for (i = 0; i < count; i++) - { - grow_token (wp->token); - wp->token->chars[wp->token->charcount++] = utf8buf[i]; - } - } + { + unsigned int uc; + unsigned char utf8buf[6]; + int count; + int i; + + uc = do_getc_escaped (); + assert (uc < 0x10000); + count = u8_uctomb (utf8buf, uc, 6); + assert (count > 0); + if (wp->type == t_string) + for (i = 0; i < count; i++) + { + grow_token (wp->token); + wp->token->chars[wp->token->charcount++] = utf8buf[i]; + } + } else - { - if (wp->type == t_string) - { - grow_token (wp->token); - wp->token->chars[wp->token->charcount++] = (unsigned char) c; - } - } + { + if (wp->type == t_string) + { + grow_token (wp->token); + wp->token->chars[wp->token->charcount++] = (unsigned char) c; + } + } } } @@ -718,7 +718,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) do c = phase2_getc (); while (c == ' ' || c == BS_NL - || c == '\t' || c == '\v' || c == '\f' || c == '\r'); + || c == '\t' || c == '\v' || c == '\f' || c == '\r'); if (c == EOF) { @@ -736,9 +736,9 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) if (c == '\n') { /* Comments assumed to be grouped with a message must immediately - precede it, with no non-whitespace token on a line between both. */ + precede it, with no non-whitespace token on a line between both. */ if (last_non_comment_line > last_comment_line) - savable_comment_reset (); + savable_comment_reset (); wp->type = t_separator; return; } @@ -763,14 +763,14 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) enum word_type terminator; /* Start a new nested character group, which lasts until the next - balanced '}' (ignoring \} things). */ + balanced '}' (ignoring \} things). */ previous_depth = phase2_push () - 1; /* Interpret it as a command list. */ terminator = read_command_list ('\0', null_context); if (terminator == t_brace) - phase2_pop (previous_depth); + phase2_pop (previous_depth); wp->type = t_other; last_non_comment_line = line_number; @@ -786,18 +786,18 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) { c = accumulate_word (wp, te_quote, context); if (c != EOF && c != '"') - phase2_ungetc (c); + phase2_ungetc (c); } else { phase2_ungetc (c); c = accumulate_word (wp, - looking_for == ']' - ? te_space_separator_bracket - : te_space_separator, - context); + looking_for == ']' + ? te_space_separator_bracket + : te_space_separator, + context); if (c != EOF) - phase2_ungetc (c); + phase2_ungetc (c); } if (wp->type != t_string) @@ -824,120 +824,120 @@ read_command (int looking_for, flag_context_ty outer_context) c = phase2_getc (); if (c == ' ' || c == BS_NL - || c == '\t' || c == '\v' || c == '\f' || c == '\r') - continue; + || c == '\t' || c == '\v' || c == '\f' || c == '\r') + continue; if (c == '#') - { - /* Skip a comment up to end of line. */ - last_comment_line = line_number; - comment_start (); - for (;;) - { - c = phase2_getc (); - if (c == EOF || c == CL_BRACE || c == '\n') - break; - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - } - comment_line_end (); - continue; - } + { + /* Skip a comment up to end of line. */ + last_comment_line = line_number; + comment_start (); + for (;;) + { + c = phase2_getc (); + if (c == EOF || c == CL_BRACE || c == '\n') + break; + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + } + comment_line_end (); + continue; + } break; } phase2_ungetc (c); /* Read the words that make up the command. */ { - int arg = 0; /* Current argument number. */ + int arg = 0; /* Current argument number. */ flag_context_list_iterator_ty context_iter; const struct callshapes *shapes = NULL; struct arglist_parser *argparser = NULL; for (;; arg++) { - struct word inner; - flag_context_ty inner_context; - - if (arg == 0) - inner_context = null_context; - else - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - - read_word (&inner, looking_for, inner_context); - - /* Recognize end of command. */ - if (inner.type == t_separator || inner.type == t_bracket - || inner.type == t_brace || inner.type == t_eof) - { - if (argparser != NULL) - arglist_parser_done (argparser, arg); - return inner.type; - } - - if (extract_all) - { - if (inner.type == t_string) - { - lex_pos_ty pos; - - pos.file_name = logical_file_name; - pos.line_number = inner.line_number_at_start; - remember_a_message (mlp, NULL, string_of_word (&inner), - inner_context, &pos, - NULL, savable_comment); - } - } - - if (arg == 0) - { - /* This is the function position. */ - if (inner.type == t_string) - { - char *function_name = string_of_word (&inner); - char *stripped_name; - void *keyword_value; - - /* A leading "::" is redundant. */ - stripped_name = function_name; - if (function_name[0] == ':' && function_name[1] == ':') - stripped_name += 2; - - if (hash_find_entry (&keywords, - stripped_name, strlen (stripped_name), - &keyword_value) - == 0) - shapes = (const struct callshapes *) keyword_value; - - argparser = arglist_parser_alloc (mlp, shapes); - - context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - stripped_name, strlen (stripped_name))); - - free (function_name); - } - else - context_iter = null_context_list_iterator; - } - else - { - /* These are the argument positions. */ - if (argparser != NULL && inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_word (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); - } - - free_word (&inner); + struct word inner; + flag_context_ty inner_context; + + if (arg == 0) + inner_context = null_context; + else + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + + read_word (&inner, looking_for, inner_context); + + /* Recognize end of command. */ + if (inner.type == t_separator || inner.type == t_bracket + || inner.type == t_brace || inner.type == t_eof) + { + if (argparser != NULL) + arglist_parser_done (argparser, arg); + return inner.type; + } + + if (extract_all) + { + if (inner.type == t_string) + { + lex_pos_ty pos; + + pos.file_name = logical_file_name; + pos.line_number = inner.line_number_at_start; + remember_a_message (mlp, NULL, string_of_word (&inner), + inner_context, &pos, + NULL, savable_comment); + } + } + + if (arg == 0) + { + /* This is the function position. */ + if (inner.type == t_string) + { + char *function_name = string_of_word (&inner); + char *stripped_name; + void *keyword_value; + + /* A leading "::" is redundant. */ + stripped_name = function_name; + if (function_name[0] == ':' && function_name[1] == ':') + stripped_name += 2; + + if (hash_find_entry (&keywords, + stripped_name, strlen (stripped_name), + &keyword_value) + == 0) + shapes = (const struct callshapes *) keyword_value; + + argparser = arglist_parser_alloc (mlp, shapes); + + context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + stripped_name, strlen (stripped_name))); + + free (function_name); + } + else + context_iter = null_context_list_iterator; + } + else + { + /* These are the argument positions. */ + if (argparser != NULL && inner.type == t_string) + arglist_parser_remember (argparser, arg, + string_of_word (&inner), + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + } + + free_word (&inner); } } } @@ -956,16 +956,16 @@ read_command_list (int looking_for, flag_context_ty outer_context) terminator = read_command (looking_for, outer_context); if (terminator != t_separator) - return terminator; + return terminator; } } void extract_tcl (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { mlp = mdlp->item[0]->messages; diff --git a/gettext-tools/src/x-tcl.h b/gettext-tools/src/x-tcl.h index a68378520..aafe6a0f5 100644 --- a/gettext-tools/src/x-tcl.h +++ b/gettext-tools/src/x-tcl.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_TCL \ - { "tcl", "Tcl" }, \ + { "tcl", "Tcl" }, \ #define SCANNERS_TCL \ - { "Tcl", extract_tcl, \ - &flag_table_tcl, &formatstring_tcl, NULL }, \ + { "Tcl", extract_tcl, \ + &flag_table_tcl, &formatstring_tcl, NULL }, \ /* Scan a Tcl file and add its translatable strings to mdlp. */ extern void extract_tcl (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); /* Handling of options specific to this language. */ diff --git a/gettext-tools/src/x-ycp.c b/gettext-tools/src/x-ycp.c index a63d20d35..4e3b590dd 100644 --- a/gettext-tools/src/x-ycp.c +++ b/gettext-tools/src/x-ycp.c @@ -88,8 +88,8 @@ phase1_getc () if (c == EOF) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_file_name); + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_file_name); return EOF; } @@ -111,12 +111,12 @@ phase1_ungetc (int c) if (c != EOF) { if (c == '\n') - { - --line_number; - char_in_line = INT_MAX; - } + { + --line_number; + char_in_line = INT_MAX; + } else - --char_in_line; + --char_in_line; ungetc (c, fp); } @@ -149,40 +149,40 @@ phase2_getc () { /* Eat whitespace, to recognize ^[\t ]*# pattern. */ do - c = phase1_getc (); + c = phase1_getc (); while (c == '\t' || c == ' '); if (c == '#') - { - /* sh comment. */ - buflen = 0; - lineno = line_number; - for (;;) - { - c = phase1_getc (); - if (c == '\n' || c == EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - { - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[buflen++] = c; - } - } - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[buflen] = '\0'; - savable_comment_add (buffer); - last_comment_line = lineno; - return '\n'; - } + { + /* sh comment. */ + buflen = 0; + lineno = line_number; + for (;;) + { + c = phase1_getc (); + if (c == '\n' || c == EOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + { + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[buflen++] = c; + } + } + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[buflen] = '\0'; + savable_comment_add (buffer); + last_comment_line = lineno; + return '\n'; + } } else c = phase1_getc (); @@ -192,102 +192,102 @@ phase2_getc () c = phase1_getc (); switch (c) - { - default: - phase1_ungetc (c); - return '/'; - - case '*': - /* C comment. */ - buflen = 0; - lineno = line_number; - last_was_star = false; - for (;;) - { - c = phase1_getc (); - if (c == EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (buflen == 0 && (c == ' ' || c == '\t')) - continue; - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[buflen++] = c; - switch (c) - { - case '\n': - --buflen; - while (buflen >= 1 - && (buffer[buflen - 1] == ' ' - || buffer[buflen - 1] == '\t')) - --buflen; - buffer[buflen] = '\0'; - savable_comment_add (buffer); - buflen = 0; - lineno = line_number; - last_was_star = false; - continue; - - case '*': - last_was_star = true; - continue; - - case '/': - if (last_was_star) - { - buflen -= 2; - while (buflen >= 1 - && (buffer[buflen - 1] == ' ' - || buffer[buflen - 1] == '\t')) - --buflen; - buffer[buflen] = '\0'; - savable_comment_add (buffer); - break; - } - /* FALLTHROUGH */ - - default: - last_was_star = false; - continue; - } - break; - } - last_comment_line = lineno; - return ' '; - - case '/': - /* C++ comment. */ - buflen = 0; - lineno = line_number; - for (;;) - { - c = phase1_getc (); - if (c == '\n' || c == EOF) - break; - /* We skip all leading white space, but not EOLs. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - { - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[buflen++] = c; - } - } - if (buflen >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[buflen] = '\0'; - savable_comment_add (buffer); - last_comment_line = lineno; - return '\n'; - } + { + default: + phase1_ungetc (c); + return '/'; + + case '*': + /* C comment. */ + buflen = 0; + lineno = line_number; + last_was_star = false; + for (;;) + { + c = phase1_getc (); + if (c == EOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (buflen == 0 && (c == ' ' || c == '\t')) + continue; + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[buflen++] = c; + switch (c) + { + case '\n': + --buflen; + while (buflen >= 1 + && (buffer[buflen - 1] == ' ' + || buffer[buflen - 1] == '\t')) + --buflen; + buffer[buflen] = '\0'; + savable_comment_add (buffer); + buflen = 0; + lineno = line_number; + last_was_star = false; + continue; + + case '*': + last_was_star = true; + continue; + + case '/': + if (last_was_star) + { + buflen -= 2; + while (buflen >= 1 + && (buffer[buflen - 1] == ' ' + || buffer[buflen - 1] == '\t')) + --buflen; + buffer[buflen] = '\0'; + savable_comment_add (buffer); + break; + } + /* FALLTHROUGH */ + + default: + last_was_star = false; + continue; + } + break; + } + last_comment_line = lineno; + return ' '; + + case '/': + /* C++ comment. */ + buflen = 0; + lineno = line_number; + for (;;) + { + c = phase1_getc (); + if (c == '\n' || c == EOF) + break; + /* We skip all leading white space, but not EOLs. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + { + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[buflen++] = c; + } + } + if (buflen >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[buflen] = '\0'; + savable_comment_add (buffer); + last_comment_line = lineno; + return '\n'; + } } else return c; @@ -300,7 +300,7 @@ phase2_ungetc (int c) if (c != EOF) { if (phase2_pushback_length == SIZEOF (phase2_pushback)) - abort (); + abort (); phase2_pushback[phase2_pushback_length++] = c; } } @@ -312,13 +312,13 @@ phase2_ungetc (int c) enum token_type_ty { token_type_eof, - token_type_lparen, /* ( */ - token_type_rparen, /* ) */ - token_type_comma, /* , */ - token_type_i18n, /* _( */ - token_type_string_literal, /* "abc" */ - token_type_symbol, /* symbol, number */ - token_type_other /* misc. operator */ + token_type_lparen, /* ( */ + token_type_rparen, /* ) */ + token_type_comma, /* , */ + token_type_i18n, /* _( */ + token_type_string_literal, /* "abc" */ + token_type_symbol, /* symbol, number */ + token_type_other /* misc. operator */ }; typedef enum token_type_ty token_type_ty; @@ -326,8 +326,8 @@ typedef struct token_ty token_ty; struct token_ty { token_type_ty type; - char *string; /* for token_type_string_literal, token_type_symbol */ - refcounted_string_list_ty *comment; /* for token_type_string_literal */ + char *string; /* for token_type_string_literal, token_type_symbol */ + refcounted_string_list_ty *comment; /* for token_type_string_literal */ int line_number; }; @@ -348,58 +348,58 @@ phase7_getc () c = phase1_getc (); if (c == '"') - return P7_QUOTES; + return P7_QUOTES; if (c != '\\') - return c; + return c; c = phase1_getc (); if (c != '\n') - switch (c) - { - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - - /* FIXME: What is the octal escape syntax? - syntax.html says: [0] [0-7]+ - scanner.ll says: [0-7] [0-7] [0-7] - */ + switch (c) + { + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + + /* FIXME: What is the octal escape syntax? + syntax.html says: [0] [0-7]+ + scanner.ll says: [0-7] [0-7] [0-7] + */ #if 0 - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - { - int n, j; - - n = 0; - for (j = 0; j < 3; ++j) - { - n = n * 8 + c - '0'; - c = phase1_getc (); - switch (c) - { - default: - break; - - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - continue; - } - break; - } - phase1_ungetc (c); - return n; - } + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + { + int n, j; + + n = 0; + for (j = 0; j < 3; ++j) + { + n = n * 8 + c - '0'; + c = phase1_getc (); + switch (c) + { + default: + break; + + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + continue; + } + break; + } + phase1_ungetc (c); + return n; + } #endif - default: - return c; - } + default: + return c; + } } } @@ -439,131 +439,131 @@ phase5_get (token_ty *tp) c = phase2_getc (); switch (c) - { - case EOF: - tp->type = token_type_eof; - return; - - case '\n': - if (last_non_comment_line > last_comment_line) - savable_comment_reset (); - /* FALLTHROUGH */ - case '\r': - case '\t': - case ' ': - /* Ignore whitespace and comments. */ - continue; - } + { + case EOF: + tp->type = token_type_eof; + return; + + case '\n': + if (last_non_comment_line > last_comment_line) + savable_comment_reset (); + /* FALLTHROUGH */ + case '\r': + case '\t': + case ' ': + /* Ignore whitespace and comments. */ + continue; + } last_non_comment_line = tp->line_number; switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - /* Symbol, or part of a number. */ - bufpos = 0; - for (;;) - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase2_getc (); - switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': - case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': - case 'y': case 'z': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - continue; - default: - if (bufpos == 1 && buffer[0] == '_' && c == '(') - { - tp->type = token_type_i18n; - return; - } - phase2_ungetc (c); - break; - } - break; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = '\0'; - tp->string = xstrdup (buffer); - tp->type = token_type_symbol; - return; - - case '"': - bufpos = 0; - for (;;) - { - c = phase7_getc (); - if (c == EOF || c == P7_QUOTES) - break; - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = '\0'; - tp->string = xstrdup (buffer); - tp->type = token_type_string_literal; - tp->comment = add_reference (savable_comment); - return; - - case '(': - tp->type = token_type_lparen; - return; - - case ')': - tp->type = token_type_rparen; - return; - - case ',': - tp->type = token_type_comma; - return; - - default: - /* We could carefully recognize each of the 2 and 3 character - operators, but it is not necessary, as we only need to recognize - gettext invocations. Don't bother. */ - tp->type = token_type_other; - return; - } + { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* Symbol, or part of a number. */ + bufpos = 0; + for (;;) + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase2_getc (); + switch (c) + { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + continue; + default: + if (bufpos == 1 && buffer[0] == '_' && c == '(') + { + tp->type = token_type_i18n; + return; + } + phase2_ungetc (c); + break; + } + break; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = '\0'; + tp->string = xstrdup (buffer); + tp->type = token_type_symbol; + return; + + case '"': + bufpos = 0; + for (;;) + { + c = phase7_getc (); + if (c == EOF || c == P7_QUOTES) + break; + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + } + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos] = '\0'; + tp->string = xstrdup (buffer); + tp->type = token_type_string_literal; + tp->comment = add_reference (savable_comment); + return; + + case '(': + tp->type = token_type_lparen; + return; + + case ')': + tp->type = token_type_rparen; + return; + + case ',': + tp->type = token_type_comma; + return; + + default: + /* We could carefully recognize each of the 2 and 3 character + operators, but it is not necessary, as we only need to recognize + gettext invocations. Don't bother. */ + tp->type = token_type_other; + return; + } } } @@ -574,7 +574,7 @@ phase5_unget (token_ty *tp) if (tp->type != token_type_eof) { if (phase5_pushback_length == SIZEOF (phase5_pushback)) - abort (); + abort (); phase5_pushback[phase5_pushback_length++] = *tp; } } @@ -596,10 +596,10 @@ phase8_get (token_ty *tp) phase5_get (&tmp); if (tmp.type != token_type_string_literal) - { - phase5_unget (&tmp); - return; - } + { + phase5_unget (&tmp); + return; + } len = strlen (tp->string); tp->string = xrealloc (tp->string, len + strlen (tmp.string) + 1); strcpy (tp->string + len, tmp.string); @@ -635,19 +635,19 @@ static flag_context_list_table_ty *flag_context_list_table; Return true upon eof, false upon closing parenthesis. */ static bool extract_parenthesized (message_list_ty *mlp, - flag_context_ty outer_context, - flag_context_list_iterator_ty context_iter, - bool in_i18n) + flag_context_ty outer_context, + flag_context_list_iterator_ty context_iter, + bool in_i18n) { int state; /* 1 or 2 inside _( ... ), otherwise 0 */ - message_ty *plural_mp = NULL; /* defined only when in states 1 and 2 */ + message_ty *plural_mp = NULL; /* defined only when in states 1 and 2 */ /* Context iterator that will be used if the next token is a '('. */ flag_context_list_iterator_ty next_context_iter = passthrough_context_list_iterator; /* Current context. */ flag_context_ty inner_context = inherited_context (outer_context, - flag_context_list_iterator_advance (&context_iter)); + flag_context_list_iterator_advance (&context_iter)); /* Start state is 0 or 1. */ state = (in_i18n ? 1 : 0); @@ -657,106 +657,106 @@ extract_parenthesized (message_list_ty *mlp, token_ty token; if (in_i18n) - phase8_get (&token); + phase8_get (&token); else - phase5_get (&token); + phase5_get (&token); switch (token.type) - { - case token_type_i18n: - if (extract_parenthesized (mlp, inner_context, next_context_iter, - true)) - return true; - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_string_literal: - if (state == 1) - { - lex_pos_ty pos; - pos.file_name = logical_file_name; - pos.line_number = token.line_number; - - if (plural_mp == NULL) - { - /* Seen an msgid. */ - plural_mp = remember_a_message (mlp, NULL, token.string, - inner_context, &pos, - NULL, token.comment); - state = 2; - } - else - { - /* Seen an msgid_plural. */ - remember_a_message_plural (plural_mp, token.string, - inner_context, &pos, - token.comment); - state = 0; - } - drop_reference (token.comment); - } - else - { - free_token (&token); - state = 0; - } - next_context_iter = null_context_list_iterator; - continue; - - case token_type_symbol: - next_context_iter = - flag_context_list_iterator ( - flag_context_list_table_lookup ( - flag_context_list_table, - token.string, strlen (token.string))); - free_token (&token); - state = 0; - continue; - - case token_type_lparen: - if (extract_parenthesized (mlp, inner_context, next_context_iter, - false)) - return true; - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_rparen: - return false; - - case token_type_comma: - if (state == 2) - state = 1; - else - state = 0; - inner_context = - inherited_context (outer_context, - flag_context_list_iterator_advance ( - &context_iter)); - next_context_iter = passthrough_context_list_iterator; - continue; - - case token_type_other: - next_context_iter = null_context_list_iterator; - state = 0; - continue; - - case token_type_eof: - return true; - - default: - abort (); - } + { + case token_type_i18n: + if (extract_parenthesized (mlp, inner_context, next_context_iter, + true)) + return true; + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_string_literal: + if (state == 1) + { + lex_pos_ty pos; + pos.file_name = logical_file_name; + pos.line_number = token.line_number; + + if (plural_mp == NULL) + { + /* Seen an msgid. */ + plural_mp = remember_a_message (mlp, NULL, token.string, + inner_context, &pos, + NULL, token.comment); + state = 2; + } + else + { + /* Seen an msgid_plural. */ + remember_a_message_plural (plural_mp, token.string, + inner_context, &pos, + token.comment); + state = 0; + } + drop_reference (token.comment); + } + else + { + free_token (&token); + state = 0; + } + next_context_iter = null_context_list_iterator; + continue; + + case token_type_symbol: + next_context_iter = + flag_context_list_iterator ( + flag_context_list_table_lookup ( + flag_context_list_table, + token.string, strlen (token.string))); + free_token (&token); + state = 0; + continue; + + case token_type_lparen: + if (extract_parenthesized (mlp, inner_context, next_context_iter, + false)) + return true; + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_rparen: + return false; + + case token_type_comma: + if (state == 2) + state = 1; + else + state = 0; + inner_context = + inherited_context (outer_context, + flag_context_list_iterator_advance ( + &context_iter)); + next_context_iter = passthrough_context_list_iterator; + continue; + + case token_type_other: + next_context_iter = null_context_list_iterator; + state = 0; + continue; + + case token_type_eof: + return true; + + default: + abort (); + } } } void extract_ycp (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { message_list_ty *mlp = mdlp->item[0]->messages; @@ -774,7 +774,7 @@ extract_ycp (FILE *f, /* Eat tokens until eof is seen. When extract_parenthesized returns due to an unbalanced closing parenthesis, just restart it. */ while (!extract_parenthesized (mlp, null_context, null_context_list_iterator, - false)) + false)) ; fp = NULL; diff --git a/gettext-tools/src/x-ycp.h b/gettext-tools/src/x-ycp.h index 2b29a8681..01eaf6205 100644 --- a/gettext-tools/src/x-ycp.h +++ b/gettext-tools/src/x-ycp.h @@ -28,17 +28,17 @@ extern "C" { #define EXTENSIONS_YCP \ - { "ycp", "YCP" }, \ + { "ycp", "YCP" }, \ #define SCANNERS_YCP \ - { "YCP", extract_ycp, \ - &flag_table_ycp, &formatstring_ycp, NULL }, \ + { "YCP", extract_ycp, \ + &flag_table_ycp, &formatstring_ycp, NULL }, \ /* Scan an YCP file and add its translatable strings to mdlp. */ extern void extract_ycp (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); extern void init_flag_table_ycp (void); diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index 6356013b6..4ca1cdf56 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -241,9 +241,9 @@ static const struct option long_options[] = arguments designating the input stream and one message domain list argument in which to add the messages. */ typedef void (*extractor_func) (FILE *fp, const char *real_filename, - const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp); + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); typedef struct extractor_ty extractor_ty; struct extractor_ty @@ -259,12 +259,12 @@ struct extractor_ty /* Forward declaration of local functions. */ static void usage (int status) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ > 4) || __GNUC__ > 2) - __attribute__ ((noreturn)) + __attribute__ ((noreturn)) #endif ; static void read_exclusion_file (char *file_name); static void extract_from_file (const char *file_name, extractor_ty extractor, - msgdomain_list_ty *mdlp); + msgdomain_list_ty *mdlp); static message_ty *construct_header (void); static void finalize_header (msgdomain_list_ty *mdlp); static extractor_ty language_to_extractor (const char *name); @@ -330,198 +330,198 @@ main (int argc, char *argv[]) init_flag_table_php (); while ((optchar = getopt_long (argc, argv, - "ac::Cd:D:eEf:Fhijk::l:L:m::M::no:p:sTVw:x:", - long_options, NULL)) != EOF) + "ac::Cd:D:eEf:Fhijk::l:L:m::M::no:p:sTVw:x:", + long_options, NULL)) != EOF) switch (optchar) { - case '\0': /* Long option. */ - break; + case '\0': /* Long option. */ + break; case 'a': - x_c_extract_all (); - x_sh_extract_all (); - x_python_extract_all (); - x_lisp_extract_all (); - x_elisp_extract_all (); - x_librep_extract_all (); - x_scheme_extract_all (); - x_java_extract_all (); - x_csharp_extract_all (); - x_awk_extract_all (); - x_tcl_extract_all (); - x_perl_extract_all (); - x_php_extract_all (); - x_glade_extract_all (); - break; + x_c_extract_all (); + x_sh_extract_all (); + x_python_extract_all (); + x_lisp_extract_all (); + x_elisp_extract_all (); + x_librep_extract_all (); + x_scheme_extract_all (); + x_java_extract_all (); + x_csharp_extract_all (); + x_awk_extract_all (); + x_tcl_extract_all (); + x_perl_extract_all (); + x_php_extract_all (); + x_glade_extract_all (); + break; case 'c': - if (optarg == NULL) - { - add_all_comments = true; - comment_tag = NULL; - } - else - { - add_all_comments = false; - comment_tag = optarg; - /* We ignore leading white space. */ - while (isspace ((unsigned char) *comment_tag)) - ++comment_tag; - } - break; + if (optarg == NULL) + { + add_all_comments = true; + comment_tag = NULL; + } + else + { + add_all_comments = false; + comment_tag = optarg; + /* We ignore leading white space. */ + while (isspace ((unsigned char) *comment_tag)) + ++comment_tag; + } + break; case 'C': - language = "C++"; - break; + language = "C++"; + break; case 'd': - default_domain = optarg; - break; + default_domain = optarg; + break; case 'D': - dir_list_append (optarg); - break; + dir_list_append (optarg); + break; case 'e': - message_print_style_escape (false); - break; + message_print_style_escape (false); + break; case 'E': - message_print_style_escape (true); - break; + message_print_style_escape (true); + break; case 'f': - files_from = optarg; - break; + files_from = optarg; + break; case 'F': - sort_by_filepos = true; - break; + sort_by_filepos = true; + break; case 'h': - do_help = true; - break; + do_help = true; + break; case 'i': - message_print_style_indent (); - break; + message_print_style_indent (); + break; case 'j': - join_existing = true; - break; + join_existing = true; + break; case 'k': - if (optarg != NULL && *optarg == '\0') - /* Make "--keyword=" work like "--keyword" and "-k". */ - optarg = NULL; - x_c_keyword (optarg); - x_objc_keyword (optarg); - x_sh_keyword (optarg); - x_python_keyword (optarg); - x_lisp_keyword (optarg); - x_elisp_keyword (optarg); - x_librep_keyword (optarg); - x_scheme_keyword (optarg); - x_java_keyword (optarg); - x_csharp_keyword (optarg); - x_awk_keyword (optarg); - x_tcl_keyword (optarg); - x_perl_keyword (optarg); - x_php_keyword (optarg); - x_glade_keyword (optarg); - if (optarg == NULL) - no_default_keywords = true; - else - some_additional_keywords = true; - break; + if (optarg != NULL && *optarg == '\0') + /* Make "--keyword=" work like "--keyword" and "-k". */ + optarg = NULL; + x_c_keyword (optarg); + x_objc_keyword (optarg); + x_sh_keyword (optarg); + x_python_keyword (optarg); + x_lisp_keyword (optarg); + x_elisp_keyword (optarg); + x_librep_keyword (optarg); + x_scheme_keyword (optarg); + x_java_keyword (optarg); + x_csharp_keyword (optarg); + x_awk_keyword (optarg); + x_tcl_keyword (optarg); + x_perl_keyword (optarg); + x_php_keyword (optarg); + x_glade_keyword (optarg); + if (optarg == NULL) + no_default_keywords = true; + else + some_additional_keywords = true; + break; case 'l': - /* Accepted for backward compatibility with 0.10.35. */ - break; + /* Accepted for backward compatibility with 0.10.35. */ + break; case 'L': - language = optarg; - break; + language = optarg; + break; case 'm': - /* -m takes an optional argument. If none is given "" is assumed. */ - msgstr_prefix = optarg == NULL ? "" : optarg; - break; + /* -m takes an optional argument. If none is given "" is assumed. */ + msgstr_prefix = optarg == NULL ? "" : optarg; + break; case 'M': - /* -M takes an optional argument. If none is given "" is assumed. */ - msgstr_suffix = optarg == NULL ? "" : optarg; - break; + /* -M takes an optional argument. If none is given "" is assumed. */ + msgstr_suffix = optarg == NULL ? "" : optarg; + break; case 'n': - line_comment = 1; - break; + line_comment = 1; + break; case 'o': - output_file = optarg; - break; + output_file = optarg; + break; case 'p': - { - size_t len = strlen (optarg); - - if (output_dir != NULL) - free (output_dir); - - if (optarg[len - 1] == '/') - output_dir = xstrdup (optarg); - else - output_dir = xasprintf ("%s/", optarg); - } - break; + { + size_t len = strlen (optarg); + + if (output_dir != NULL) + free (output_dir); + + if (optarg[len - 1] == '/') + output_dir = xstrdup (optarg); + else + output_dir = xasprintf ("%s/", optarg); + } + break; case 's': - sort_by_msgid = true; - break; + sort_by_msgid = true; + break; case 'S': - message_print_style_uniforum (); - break; + message_print_style_uniforum (); + break; case 'T': - x_c_trigraphs (); - break; + x_c_trigraphs (); + break; case 'V': - do_version = true; - break; + do_version = true; + break; case 'w': - { - int value; - char *endp; - value = strtol (optarg, &endp, 10); - if (endp != optarg) - message_page_width_set (value); - } - break; + { + int value; + char *endp; + value = strtol (optarg, &endp, 10); + if (endp != optarg) + message_page_width_set (value); + } + break; case 'x': - read_exclusion_file (optarg); - break; - case CHAR_MAX + 1: /* --copyright-holder */ - copyright_holder = optarg; - break; - case CHAR_MAX + 2: /* --foreign-user */ - copyright_holder = ""; - break; - case CHAR_MAX + 3: /* --from-code */ - xgettext_global_source_encoding = po_charset_canonicalize (optarg); - if (xgettext_global_source_encoding == NULL) - xgettext_global_source_encoding = po_charset_ascii; - break; - case CHAR_MAX + 4: /* --no-wrap */ - message_page_width_ignore (); - break; - case CHAR_MAX + 5: /* --msgid-bugs-address */ - msgid_bugs_address = optarg; - break; - case CHAR_MAX + 6: /* --properties-output */ - output_syntax = &output_format_properties; - break; - case CHAR_MAX + 7: /* --stringtable-output */ - output_syntax = &output_format_stringtable; - break; - case CHAR_MAX + 8: /* --flag */ - xgettext_record_flag (optarg); - break; - case CHAR_MAX + 9: /* --qt */ - recognize_format_qt = true; - break; - case CHAR_MAX + 10: /* --kde */ - recognize_format_kde = true; - break; - case CHAR_MAX + 11: /* --boost */ - recognize_format_boost = true; - break; - case CHAR_MAX + 12: /* --package-name */ - package_name = optarg; - break; - case CHAR_MAX + 13: /* --package-version */ - package_version = optarg; - break; + read_exclusion_file (optarg); + break; + case CHAR_MAX + 1: /* --copyright-holder */ + copyright_holder = optarg; + break; + case CHAR_MAX + 2: /* --foreign-user */ + copyright_holder = ""; + break; + case CHAR_MAX + 3: /* --from-code */ + xgettext_global_source_encoding = po_charset_canonicalize (optarg); + if (xgettext_global_source_encoding == NULL) + xgettext_global_source_encoding = po_charset_ascii; + break; + case CHAR_MAX + 4: /* --no-wrap */ + message_page_width_ignore (); + break; + case CHAR_MAX + 5: /* --msgid-bugs-address */ + msgid_bugs_address = optarg; + break; + case CHAR_MAX + 6: /* --properties-output */ + output_syntax = &output_format_properties; + break; + case CHAR_MAX + 7: /* --stringtable-output */ + output_syntax = &output_format_stringtable; + break; + case CHAR_MAX + 8: /* --flag */ + xgettext_record_flag (optarg); + break; + case CHAR_MAX + 9: /* --qt */ + recognize_format_qt = true; + break; + case CHAR_MAX + 10: /* --kde */ + recognize_format_kde = true; + break; + case CHAR_MAX + 11: /* --boost */ + recognize_format_boost = true; + break; + case CHAR_MAX + 12: /* --package-name */ + package_name = optarg; + break; + case CHAR_MAX + 13: /* --package-version */ + package_version = optarg; + break; default: - usage (EXIT_FAILURE); - /* NOTREACHED */ + usage (EXIT_FAILURE); + /* NOTREACHED */ } /* Version information requested. */ @@ -534,7 +534,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "1995-1998, 2000-2009"); + "1995-1998, 2000-2009"); printf (_("Written by %s.\n"), proper_name ("Ulrich Drepper")); exit (EXIT_SUCCESS); } @@ -546,24 +546,24 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Verify selected options. */ if (!line_comment && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); + "--no-location", "--sort-by-file"); if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--sort-output", "--sort-by-file"); + "--sort-output", "--sort-by-file"); /* We cannot support both Qt and KDE, or Qt and Boost, or KDE and Boost format strings, because there are only two formatstring parsers per language, and formatstring_c is the first one for C++. */ if (recognize_format_qt && recognize_format_kde) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--qt", "--kde"); + "--qt", "--kde"); if (recognize_format_qt && recognize_format_boost) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--qt", "--boost"); + "--qt", "--boost"); if (recognize_format_kde && recognize_format_boost) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--kde", "--boost"); + "--kde", "--boost"); if (join_existing && strcmp (default_domain, "-") == 0) error (EXIT_FAILURE, 0, _("\ @@ -602,10 +602,10 @@ xgettext cannot work without keywords to look for")); if (output_file) { if (IS_ABSOLUTE_PATH (output_file) || strcmp (output_file, "-") == 0) - file_name = xstrdup (output_file); + file_name = xstrdup (output_file); else - /* Please do NOT add a .po suffix! */ - file_name = xconcatenated_filename (output_dir, output_file, NULL); + /* Please do NOT add a .po suffix! */ + file_name = xconcatenated_filename (output_dir, output_file, NULL); } else if (strcmp (default_domain, "-") == 0) file_name = "-"; @@ -632,23 +632,23 @@ xgettext cannot work without keywords to look for")); /* Avoid glibc-2.1 bug with EUC-KR. */ # if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION if (strcmp (xgettext_global_source_encoding, "EUC-KR") == 0) - cd = (iconv_t)(-1); + cd = (iconv_t)(-1); else # endif cd = iconv_open (po_charset_utf8, xgettext_global_source_encoding); if (cd == (iconv_t)(-1)) - error (EXIT_FAILURE, 0, _("\ + error (EXIT_FAILURE, 0, _("\ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(), \ and iconv() does not support this conversion."), - xgettext_global_source_encoding, po_charset_utf8, - basename (program_name)); + xgettext_global_source_encoding, po_charset_utf8, + basename (program_name)); xgettext_global_source_iconv = cd; #else error (EXIT_FAILURE, 0, _("\ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(). \ This version was built without iconv()."), - xgettext_global_source_encoding, po_charset_utf8, - basename (program_name)); + xgettext_global_source_encoding, po_charset_utf8, + basename (program_name)); #endif } @@ -664,13 +664,13 @@ This version was built without iconv()."), if (join_existing) { /* Temporarily reset the directory list to empty, because file_name - is an output file and therefore should not be searched for. */ + is an output file and therefore should not be searched for. */ void *saved_directory_list = dir_list_save_reset (); extractor_ty po_extractor = { extract_po, NULL, NULL, NULL }; extract_from_file (file_name, po_extractor, mdlp); if (!is_ascii_msgdomain_list (mdlp)) - mdlp = iconv_msgdomain_list (mdlp, "UTF-8", true, file_name); + mdlp = iconv_msgdomain_list (mdlp, "UTF-8", true, file_name); dir_list_restore (saved_directory_list); } @@ -684,44 +684,44 @@ This version was built without iconv()."), filename = file_list->item[i]; if (extractor.func) - this_file_extractor = extractor; + this_file_extractor = extractor; else - { - const char *base; - char *reduced; - const char *extension; - const char *language; - - base = strrchr (filename, '/'); - if (!base) - base = filename; - - reduced = xstrdup (base); - /* Remove a trailing ".in" - it's a generic suffix. */ - if (strlen (reduced) >= 3 - && memcmp (reduced + strlen (reduced) - 3, ".in", 3) == 0) - reduced[strlen (reduced) - 3] = '\0'; - - /* Work out what the file extension is. */ - extension = strrchr (reduced, '.'); - if (extension) - ++extension; - else - extension = ""; - - /* Derive the language from the extension, and the extractor - function from the language. */ - language = extension_to_language (extension); - if (language == NULL) - { - error (0, 0, _("\ + { + const char *base; + char *reduced; + const char *extension; + const char *language; + + base = strrchr (filename, '/'); + if (!base) + base = filename; + + reduced = xstrdup (base); + /* Remove a trailing ".in" - it's a generic suffix. */ + if (strlen (reduced) >= 3 + && memcmp (reduced + strlen (reduced) - 3, ".in", 3) == 0) + reduced[strlen (reduced) - 3] = '\0'; + + /* Work out what the file extension is. */ + extension = strrchr (reduced, '.'); + if (extension) + ++extension; + else + extension = ""; + + /* Derive the language from the extension, and the extractor + function from the language. */ + language = extension_to_language (extension); + if (language == NULL) + { + error (0, 0, _("\ warning: file `%s' extension `%s' is unknown; will try C"), filename, extension); - language = "C"; - } - this_file_extractor = language_to_extractor (language); + language = "C"; + } + this_file_extractor = language_to_extractor (language); - free (reduced); - } + free (reduced); + } /* Extract the strings from the file. */ extract_from_file (filename, this_file_extractor, mdlp); @@ -758,7 +758,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -931,7 +931,7 @@ Informative output:\n")); "Report translation bugs to <...>\n" with the address for translation bugs (typically your translation team's web or email address). */ fputs (_("Report bugs to .\n"), - stdout); + stdout); } exit (status); @@ -942,22 +942,22 @@ static void exclude_directive_domain (abstract_catalog_reader_ty *pop, char *name) { po_gram_error_at_line (&gram_pos, - _("this file may not contain domain directives")); + _("this file may not contain domain directives")); } static void exclude_directive_message (abstract_catalog_reader_ty *pop, - char *msgctxt, - char *msgid, - lex_pos_ty *msgid_pos, - char *msgid_plural, - char *msgstr, size_t msgstr_len, - lex_pos_ty *msgstr_pos, - char *prev_msgctxt, - char *prev_msgid, - char *prev_msgid_plural, - bool force_fuzzy, bool obsolete) + char *msgctxt, + char *msgid, + lex_pos_ty *msgid_pos, + char *msgid_plural, + char *msgstr, size_t msgstr_len, + lex_pos_ty *msgstr_pos, + char *prev_msgctxt, + char *prev_msgid, + char *prev_msgid_plural, + bool force_fuzzy, bool obsolete) { message_ty *mp; @@ -1020,7 +1020,7 @@ read_exclusion_file (char *filename) void split_keywordspec (const char *spec, - const char **endp, struct callshape *shapep) + const char **endp, struct callshape *shapep) { const char *p; int argnum1 = 0; @@ -1038,113 +1038,113 @@ split_keywordspec (const char *spec, while (p > spec) { if (isdigit ((unsigned char) p[-1]) - || ((p[-1] == 'c' || p[-1] == 'g' || p[-1] == 't') - && p - 1 > spec && isdigit ((unsigned char) p[-2]))) - { - bool contextp = (p[-1] == 'c'); - bool glibp = (p[-1] == 'g'); - bool totalp = (p[-1] == 't'); - - do - p--; - while (p > spec && isdigit ((unsigned char) p[-1])); - - if (p > spec && (p[-1] == ',' || p[-1] == ':')) - { - char *dummy; - int arg = strtol (p, &dummy, 10); - - if (contextp) - { - if (argnumc != 0) - /* Only one context argument can be given. */ - break; - argnumc = arg; - } - else if (totalp) - { - if (argtotal != 0) - /* Only one total number of arguments can be given. */ - break; - argtotal = arg; - } - else - { - if (argnum2 != 0) - /* At most two normal arguments can be given. */ - break; - argnum2 = argnum1; - argnum2_glib_context = argnum1_glib_context; - argnum1 = arg; - argnum1_glib_context = glibp; - } - } - else - break; - } + || ((p[-1] == 'c' || p[-1] == 'g' || p[-1] == 't') + && p - 1 > spec && isdigit ((unsigned char) p[-2]))) + { + bool contextp = (p[-1] == 'c'); + bool glibp = (p[-1] == 'g'); + bool totalp = (p[-1] == 't'); + + do + p--; + while (p > spec && isdigit ((unsigned char) p[-1])); + + if (p > spec && (p[-1] == ',' || p[-1] == ':')) + { + char *dummy; + int arg = strtol (p, &dummy, 10); + + if (contextp) + { + if (argnumc != 0) + /* Only one context argument can be given. */ + break; + argnumc = arg; + } + else if (totalp) + { + if (argtotal != 0) + /* Only one total number of arguments can be given. */ + break; + argtotal = arg; + } + else + { + if (argnum2 != 0) + /* At most two normal arguments can be given. */ + break; + argnum2 = argnum1; + argnum2_glib_context = argnum1_glib_context; + argnum1 = arg; + argnum1_glib_context = glibp; + } + } + else + break; + } else if (p[-1] == '"') - { - const char *xcomment_end; - - p--; - xcomment_end = p; - - while (p > spec && p[-1] != '"') - p--; - - if (p > spec /* && p[-1] == '"' */) - { - const char *xcomment_start; - - xcomment_start = p; - p--; - if (p > spec && (p[-1] == ',' || p[-1] == ':')) - { - size_t xcomment_len = xcomment_end - xcomment_start; - char *xcomment = XNMALLOC (xcomment_len + 1, char); - - memcpy (xcomment, xcomment_start, xcomment_len); - xcomment[xcomment_len] = '\0'; - string_list_append (&xcomments, xcomment); - } - else - break; - } - else - break; - } + { + const char *xcomment_end; + + p--; + xcomment_end = p; + + while (p > spec && p[-1] != '"') + p--; + + if (p > spec /* && p[-1] == '"' */) + { + const char *xcomment_start; + + xcomment_start = p; + p--; + if (p > spec && (p[-1] == ',' || p[-1] == ':')) + { + size_t xcomment_len = xcomment_end - xcomment_start; + char *xcomment = XNMALLOC (xcomment_len + 1, char); + + memcpy (xcomment, xcomment_start, xcomment_len); + xcomment[xcomment_len] = '\0'; + string_list_append (&xcomments, xcomment); + } + else + break; + } + else + break; + } else - break; + break; /* Here an element of the comma-separated list has been parsed. */ if (!(p > spec && (p[-1] == ',' || p[-1] == ':'))) - abort (); + abort (); p--; if (*p == ':') - { - size_t i; - - if (argnum1 == 0 && argnum2 == 0) - /* At least one non-context argument must be given. */ - break; - if (argnumc != 0 - && (argnum1_glib_context || argnum2_glib_context)) - /* Incompatible ways to specify the context. */ - break; - *endp = p; - shapep->argnum1 = (argnum1 > 0 ? argnum1 : 1); - shapep->argnum2 = argnum2; - shapep->argnumc = argnumc; - shapep->argnum1_glib_context = argnum1_glib_context; - shapep->argnum2_glib_context = argnum2_glib_context; - shapep->argtotal = argtotal; - /* Reverse the order of the xcomments. */ - string_list_init (&shapep->xcomments); - for (i = xcomments.nitems; i > 0; ) - string_list_append (&shapep->xcomments, xcomments.item[--i]); - string_list_destroy (&xcomments); - return; - } + { + size_t i; + + if (argnum1 == 0 && argnum2 == 0) + /* At least one non-context argument must be given. */ + break; + if (argnumc != 0 + && (argnum1_glib_context || argnum2_glib_context)) + /* Incompatible ways to specify the context. */ + break; + *endp = p; + shapep->argnum1 = (argnum1 > 0 ? argnum1 : 1); + shapep->argnum2 = argnum2; + shapep->argnumc = argnumc; + shapep->argnum1_glib_context = argnum1_glib_context; + shapep->argnum2_glib_context = argnum2_glib_context; + shapep->argtotal = argtotal; + /* Reverse the order of the xcomments. */ + string_list_init (&shapep->xcomments); + for (i = xcomments.nitems; i > 0; ) + string_list_append (&shapep->xcomments, xcomments.item[--i]); + string_list_destroy (&xcomments); + return; + } } /* Couldn't parse the desired syntax. */ @@ -1162,8 +1162,8 @@ split_keywordspec (const char *spec, void insert_keyword_callshape (hash_table *table, - const char *keyword, size_t keyword_len, - const struct callshape *shape) + const char *keyword, size_t keyword_len, + const struct callshape *shape) { void *old_value; @@ -1174,55 +1174,55 @@ insert_keyword_callshape (hash_table *table, shapes->nshapes = 1; shapes->shapes[0] = *shape; keyword = - (const char *) hash_insert_entry (table, keyword, keyword_len, shapes); + (const char *) hash_insert_entry (table, keyword, keyword_len, shapes); if (keyword == NULL) - abort (); + abort (); shapes->keyword = keyword; shapes->keyword_len = keyword_len; } else { /* Found a 'struct callshapes'. See whether it already contains the - desired shape. */ + desired shape. */ struct callshapes *old_shapes = (struct callshapes *) old_value; bool found; size_t i; found = false; for (i = 0; i < old_shapes->nshapes; i++) - if (old_shapes->shapes[i].argnum1 == shape->argnum1 - && old_shapes->shapes[i].argnum2 == shape->argnum2 - && old_shapes->shapes[i].argnumc == shape->argnumc - && old_shapes->shapes[i].argnum1_glib_context - == shape->argnum1_glib_context - && old_shapes->shapes[i].argnum2_glib_context - == shape->argnum2_glib_context - && old_shapes->shapes[i].argtotal == shape->argtotal) - { - old_shapes->shapes[i].xcomments = shape->xcomments; - found = true; - break; - } + if (old_shapes->shapes[i].argnum1 == shape->argnum1 + && old_shapes->shapes[i].argnum2 == shape->argnum2 + && old_shapes->shapes[i].argnumc == shape->argnumc + && old_shapes->shapes[i].argnum1_glib_context + == shape->argnum1_glib_context + && old_shapes->shapes[i].argnum2_glib_context + == shape->argnum2_glib_context + && old_shapes->shapes[i].argtotal == shape->argtotal) + { + old_shapes->shapes[i].xcomments = shape->xcomments; + found = true; + break; + } if (!found) - { - /* Replace the existing 'struct callshapes' with a new one. */ - struct callshapes *shapes = - (struct callshapes *) - xmalloc (xsum (sizeof (struct callshapes), - xtimes (old_shapes->nshapes, - sizeof (struct callshape)))); - - shapes->keyword = old_shapes->keyword; - shapes->keyword_len = old_shapes->keyword_len; - shapes->nshapes = old_shapes->nshapes + 1; - for (i = 0; i < old_shapes->nshapes; i++) - shapes->shapes[i] = old_shapes->shapes[i]; - shapes->shapes[i] = *shape; - if (hash_set_value (table, keyword, keyword_len, shapes)) - abort (); - free (old_shapes); - } + { + /* Replace the existing 'struct callshapes' with a new one. */ + struct callshapes *shapes = + (struct callshapes *) + xmalloc (xsum (sizeof (struct callshapes), + xtimes (old_shapes->nshapes, + sizeof (struct callshape)))); + + shapes->keyword = old_shapes->keyword; + shapes->keyword_len = old_shapes->keyword_len; + shapes->nshapes = old_shapes->nshapes + 1; + for (i = 0; i < old_shapes->nshapes; i++) + shapes->shapes[i] = old_shapes->shapes[i]; + shapes->shapes[i] = *shape; + if (hash_set_value (table, keyword, keyword_len, shapes)) + abort (); + free (old_shapes); + } } } @@ -1236,7 +1236,7 @@ flag_context_ty passthrough_context = { undecided, true, undecided, true }; flag_context_ty inherited_context (flag_context_ty outer_context, - flag_context_ty modifier_context) + flag_context_ty modifier_context) { flag_context_ty result = modifier_context; @@ -1298,10 +1298,10 @@ flag_context_list_iterator_advance (flag_context_list_iterator_ty *iter) /* Special casing of circular list. */ if (iter->head != iter->head->next) - { - iter->head = iter->head->next; - iter->argnum++; - } + { + iter->head = iter->head->next; + iter->argnum++; + } return result; } @@ -1315,7 +1315,7 @@ flag_context_list_iterator_advance (flag_context_list_iterator_ty *iter) flag_context_list_ty * flag_context_list_table_lookup (flag_context_list_table_ty *flag_table, - const void *key, size_t keylen) + const void *key, size_t keylen) { void *entry; @@ -1329,9 +1329,9 @@ flag_context_list_table_lookup (flag_context_list_table_ty *flag_table, static void flag_context_list_table_insert (flag_context_list_table_ty *table, - unsigned int index, - const char *name_start, const char *name_end, - int argnum, enum is_format value, bool pass) + unsigned int index, + const char *name_start, const char *name_end, + int argnum, enum is_format value, bool pass) { char *allocated_name = NULL; @@ -1343,9 +1343,9 @@ flag_context_list_table_insert (flag_context_list_table_ty *table, size_t i; for (i = 0; i < name_len; i++) - name[i] = (name_start[i] >= 'a' && name_start[i] <= 'z' - ? name_start[i] - 'a' + 'A' - : name_start[i]); + name[i] = (name_start[i] >= 'a' && name_start[i] <= 'z' + ? name_start[i] - 'a' + 'A' + : name_start[i]); name_start = name; name_end = name + name_len; } @@ -1353,8 +1353,8 @@ flag_context_list_table_insert (flag_context_list_table_ty *table, { /* Remove redundant "::" prefix. */ if (name_end - name_start > 2 - && name_start[0] == ':' && name_start[1] == ':') - name_start += 2; + && name_start[0] == ':' && name_start[1] == ':') + name_start += 2; } /* Insert the pair (VALUE, PASS) at INDEX in the element numbered ARGNUM @@ -1366,118 +1366,118 @@ flag_context_list_table_insert (flag_context_list_table_ty *table, if (hash_find_entry (table, name_start, name_end - name_start, &entry) != 0) { - /* Create new hash table entry. */ - flag_context_list_ty *list = XMALLOC (flag_context_list_ty); - list->argnum = argnum; - memset (&list->flags, '\0', sizeof (list->flags)); - switch (index) - { - case 0: - list->flags.is_format1 = value; - list->flags.pass_format1 = pass; - break; - case 1: - list->flags.is_format2 = value; - list->flags.pass_format2 = pass; - break; - case 2: - list->flags.is_format3 = value; - list->flags.pass_format3 = pass; - break; - default: - abort (); - } - list->next = NULL; - hash_insert_entry (table, name_start, name_end - name_start, list); + /* Create new hash table entry. */ + flag_context_list_ty *list = XMALLOC (flag_context_list_ty); + list->argnum = argnum; + memset (&list->flags, '\0', sizeof (list->flags)); + switch (index) + { + case 0: + list->flags.is_format1 = value; + list->flags.pass_format1 = pass; + break; + case 1: + list->flags.is_format2 = value; + list->flags.pass_format2 = pass; + break; + case 2: + list->flags.is_format3 = value; + list->flags.pass_format3 = pass; + break; + default: + abort (); + } + list->next = NULL; + hash_insert_entry (table, name_start, name_end - name_start, list); } else { - flag_context_list_ty *list = (flag_context_list_ty *)entry; - flag_context_list_ty **lastp = NULL; - /* Invariant: list == (lastp != NULL ? *lastp : entry). */ - - while (list != NULL && list->argnum < argnum) - { - lastp = &list->next; - list = *lastp; - } - if (list != NULL && list->argnum == argnum) - { - /* Add this flag to the current argument number. */ - switch (index) - { - case 0: - list->flags.is_format1 = value; - list->flags.pass_format1 = pass; - break; - case 1: - list->flags.is_format2 = value; - list->flags.pass_format2 = pass; - break; - case 2: - list->flags.is_format3 = value; - list->flags.pass_format3 = pass; - break; - default: - abort (); - } - } - else if (lastp != NULL) - { - /* Add a new list entry for this argument number. */ - list = XMALLOC (flag_context_list_ty); - list->argnum = argnum; - memset (&list->flags, '\0', sizeof (list->flags)); - switch (index) - { - case 0: - list->flags.is_format1 = value; - list->flags.pass_format1 = pass; - break; - case 1: - list->flags.is_format2 = value; - list->flags.pass_format2 = pass; - break; - case 2: - list->flags.is_format3 = value; - list->flags.pass_format3 = pass; - break; - default: - abort (); - } - list->next = *lastp; - *lastp = list; - } - else - { - /* Add a new list entry for this argument number, at the beginning - of the list. Since we don't have an API for replacing the - value of a key in the hash table, we have to copy the first - list element. */ - flag_context_list_ty *copy = XMALLOC (flag_context_list_ty); - *copy = *list; - - list->argnum = argnum; - memset (&list->flags, '\0', sizeof (list->flags)); - switch (index) - { - case 0: - list->flags.is_format1 = value; - list->flags.pass_format1 = pass; - break; - case 1: - list->flags.is_format2 = value; - list->flags.pass_format2 = pass; - break; - case 2: - list->flags.is_format3 = value; - list->flags.pass_format3 = pass; - break; - default: - abort (); - } - list->next = copy; - } + flag_context_list_ty *list = (flag_context_list_ty *)entry; + flag_context_list_ty **lastp = NULL; + /* Invariant: list == (lastp != NULL ? *lastp : entry). */ + + while (list != NULL && list->argnum < argnum) + { + lastp = &list->next; + list = *lastp; + } + if (list != NULL && list->argnum == argnum) + { + /* Add this flag to the current argument number. */ + switch (index) + { + case 0: + list->flags.is_format1 = value; + list->flags.pass_format1 = pass; + break; + case 1: + list->flags.is_format2 = value; + list->flags.pass_format2 = pass; + break; + case 2: + list->flags.is_format3 = value; + list->flags.pass_format3 = pass; + break; + default: + abort (); + } + } + else if (lastp != NULL) + { + /* Add a new list entry for this argument number. */ + list = XMALLOC (flag_context_list_ty); + list->argnum = argnum; + memset (&list->flags, '\0', sizeof (list->flags)); + switch (index) + { + case 0: + list->flags.is_format1 = value; + list->flags.pass_format1 = pass; + break; + case 1: + list->flags.is_format2 = value; + list->flags.pass_format2 = pass; + break; + case 2: + list->flags.is_format3 = value; + list->flags.pass_format3 = pass; + break; + default: + abort (); + } + list->next = *lastp; + *lastp = list; + } + else + { + /* Add a new list entry for this argument number, at the beginning + of the list. Since we don't have an API for replacing the + value of a key in the hash table, we have to copy the first + list element. */ + flag_context_list_ty *copy = XMALLOC (flag_context_list_ty); + *copy = *list; + + list->argnum = argnum; + memset (&list->flags, '\0', sizeof (list->flags)); + switch (index) + { + case 0: + list->flags.is_format1 = value; + list->flags.pass_format1 = pass; + break; + case 1: + list->flags.is_format2 = value; + list->flags.pass_format2 = pass; + break; + case 2: + list->flags.is_format3 = value; + list->flags.pass_format3 = pass; + break; + default: + abort (); + } + list->next = copy; + } } } @@ -1497,18 +1497,18 @@ xgettext_record_flag (const char *optionstring) for (colon2 = optionstring + strlen (optionstring); ; ) { if (colon2 == optionstring) - goto err; + goto err; colon2--; if (*colon2 == ':') - break; + break; } for (colon1 = colon2; ; ) { if (colon1 == optionstring) - goto err; + goto err; colon1--; if (*colon1 == ':') - break; + break; } { const char *name_start = optionstring; @@ -1527,7 +1527,7 @@ xgettext_record_flag (const char *optionstring) char *endp; argnum = strtol (argnum_start, &endp, 10); if (endp != argnum_end) - goto err; + goto err; } if (argnum <= 0) goto err; @@ -1538,192 +1538,192 @@ xgettext_record_flag (const char *optionstring) pass = false; if (strlen (flag) >= 5 && memcmp (flag, "pass-", 5) == 0) - { - pass = true; - flag += 5; - } + { + pass = true; + flag += 5; + } /* Unlike po_parse_comment_special(), we don't accept "fuzzy" or "wrap" - here - it has no sense. */ + here - it has no sense. */ if (strlen (flag) >= 7 - && memcmp (flag + strlen (flag) - 7, "-format", 7) == 0) - { - const char *p; - size_t n; - enum is_format value; - size_t type; - - p = flag; - n = strlen (flag) - 7; - - if (n >= 3 && memcmp (p, "no-", 3) == 0) - { - p += 3; - n -= 3; - value = no; - } - else if (n >= 9 && memcmp (p, "possible-", 9) == 0) - { - p += 9; - n -= 9; - value = possible; - } - else if (n >= 11 && memcmp (p, "impossible-", 11) == 0) - { - p += 11; - n -= 11; - value = impossible; - } - else - value = yes_according_to_context; - - for (type = 0; type < NFORMATS; type++) - if (strlen (format_language[type]) == n - && memcmp (format_language[type], p, n) == 0) - { - switch (type) - { - case format_c: - flag_context_list_table_insert (&flag_table_c, 0, - name_start, name_end, - argnum, value, pass); - flag_context_list_table_insert (&flag_table_cxx_qt, 0, - name_start, name_end, - argnum, value, pass); - flag_context_list_table_insert (&flag_table_cxx_kde, 0, - name_start, name_end, - argnum, value, pass); - flag_context_list_table_insert (&flag_table_cxx_boost, 0, - name_start, name_end, - argnum, value, pass); - flag_context_list_table_insert (&flag_table_objc, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_objc: - flag_context_list_table_insert (&flag_table_objc, 1, - name_start, name_end, - argnum, value, pass); - break; - case format_sh: - flag_context_list_table_insert (&flag_table_sh, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_python: - flag_context_list_table_insert (&flag_table_python, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_lisp: - flag_context_list_table_insert (&flag_table_lisp, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_elisp: - flag_context_list_table_insert (&flag_table_elisp, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_librep: - flag_context_list_table_insert (&flag_table_librep, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_scheme: - flag_context_list_table_insert (&flag_table_scheme, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_smalltalk: - break; - case format_java: - flag_context_list_table_insert (&flag_table_java, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_csharp: - flag_context_list_table_insert (&flag_table_csharp, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_awk: - flag_context_list_table_insert (&flag_table_awk, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_pascal: - break; - case format_ycp: - flag_context_list_table_insert (&flag_table_ycp, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_tcl: - flag_context_list_table_insert (&flag_table_tcl, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_perl: - flag_context_list_table_insert (&flag_table_perl, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_perl_brace: - flag_context_list_table_insert (&flag_table_perl, 1, - name_start, name_end, - argnum, value, pass); - break; - case format_php: - flag_context_list_table_insert (&flag_table_php, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_gcc_internal: - flag_context_list_table_insert (&flag_table_gcc_internal, 0, - name_start, name_end, - argnum, value, pass); - break; - case format_gfc_internal: - flag_context_list_table_insert (&flag_table_gcc_internal, 1, - name_start, name_end, - argnum, value, pass); - break; - case format_qt: - flag_context_list_table_insert (&flag_table_cxx_qt, 1, - name_start, name_end, - argnum, value, pass); - break; - case format_qt_plural: - flag_context_list_table_insert (&flag_table_cxx_qt, 2, - name_start, name_end, - argnum, value, pass); - break; - case format_kde: - flag_context_list_table_insert (&flag_table_cxx_kde, 1, - name_start, name_end, - argnum, value, pass); - break; - case format_boost: - flag_context_list_table_insert (&flag_table_cxx_boost, 1, - name_start, name_end, - argnum, value, pass); - break; - default: - abort (); - } - return; - } - /* If the flag is not among the valid values, the optionstring is - invalid. */ - } + && memcmp (flag + strlen (flag) - 7, "-format", 7) == 0) + { + const char *p; + size_t n; + enum is_format value; + size_t type; + + p = flag; + n = strlen (flag) - 7; + + if (n >= 3 && memcmp (p, "no-", 3) == 0) + { + p += 3; + n -= 3; + value = no; + } + else if (n >= 9 && memcmp (p, "possible-", 9) == 0) + { + p += 9; + n -= 9; + value = possible; + } + else if (n >= 11 && memcmp (p, "impossible-", 11) == 0) + { + p += 11; + n -= 11; + value = impossible; + } + else + value = yes_according_to_context; + + for (type = 0; type < NFORMATS; type++) + if (strlen (format_language[type]) == n + && memcmp (format_language[type], p, n) == 0) + { + switch (type) + { + case format_c: + flag_context_list_table_insert (&flag_table_c, 0, + name_start, name_end, + argnum, value, pass); + flag_context_list_table_insert (&flag_table_cxx_qt, 0, + name_start, name_end, + argnum, value, pass); + flag_context_list_table_insert (&flag_table_cxx_kde, 0, + name_start, name_end, + argnum, value, pass); + flag_context_list_table_insert (&flag_table_cxx_boost, 0, + name_start, name_end, + argnum, value, pass); + flag_context_list_table_insert (&flag_table_objc, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_objc: + flag_context_list_table_insert (&flag_table_objc, 1, + name_start, name_end, + argnum, value, pass); + break; + case format_sh: + flag_context_list_table_insert (&flag_table_sh, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_python: + flag_context_list_table_insert (&flag_table_python, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_lisp: + flag_context_list_table_insert (&flag_table_lisp, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_elisp: + flag_context_list_table_insert (&flag_table_elisp, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_librep: + flag_context_list_table_insert (&flag_table_librep, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_scheme: + flag_context_list_table_insert (&flag_table_scheme, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_smalltalk: + break; + case format_java: + flag_context_list_table_insert (&flag_table_java, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_csharp: + flag_context_list_table_insert (&flag_table_csharp, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_awk: + flag_context_list_table_insert (&flag_table_awk, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_pascal: + break; + case format_ycp: + flag_context_list_table_insert (&flag_table_ycp, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_tcl: + flag_context_list_table_insert (&flag_table_tcl, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_perl: + flag_context_list_table_insert (&flag_table_perl, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_perl_brace: + flag_context_list_table_insert (&flag_table_perl, 1, + name_start, name_end, + argnum, value, pass); + break; + case format_php: + flag_context_list_table_insert (&flag_table_php, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_gcc_internal: + flag_context_list_table_insert (&flag_table_gcc_internal, 0, + name_start, name_end, + argnum, value, pass); + break; + case format_gfc_internal: + flag_context_list_table_insert (&flag_table_gcc_internal, 1, + name_start, name_end, + argnum, value, pass); + break; + case format_qt: + flag_context_list_table_insert (&flag_table_cxx_qt, 1, + name_start, name_end, + argnum, value, pass); + break; + case format_qt_plural: + flag_context_list_table_insert (&flag_table_cxx_qt, 2, + name_start, name_end, + argnum, value, pass); + break; + case format_kde: + flag_context_list_table_insert (&flag_table_cxx_kde, 1, + name_start, name_end, + argnum, value, pass); + break; + case format_boost: + flag_context_list_table_insert (&flag_table_cxx_boost, 1, + name_start, name_end, + argnum, value, pass); + break; + default: + abort (); + } + return; + } + /* If the flag is not among the valid values, the optionstring is + invalid. */ + } } } err: error (EXIT_FAILURE, 0, _("\ A --flag argument doesn't have the ::[pass-] syntax: %s"), - optionstring); + optionstring); } @@ -1783,7 +1783,7 @@ savable_comment_add (const char *str) savable_comment->refcount = 1; string_list_init (&savable_comment->contents); for (i = 0; i < oldcontents->nitems; i++) - string_list_append (&savable_comment->contents, oldcontents->item[i]); + string_list_append (&savable_comment->contents, oldcontents->item[i]); } string_list_append (&savable_comment->contents, str); } @@ -1804,7 +1804,7 @@ savable_comment_to_xgettext_comment (refcounted_string_list_ty *rslp) size_t i; for (i = 0; i < rslp->contents.nitems; i++) - xgettext_comment_add (rslp->contents.item[i]); + xgettext_comment_add (rslp->contents.item[i]); } } @@ -1812,7 +1812,7 @@ savable_comment_to_xgettext_comment (refcounted_string_list_ty *rslp) static FILE * xgettext_open (const char *fn, - char **logical_file_name_p, char **real_file_name_p) + char **logical_file_name_p, char **real_file_name_p) { FILE *fp; char *new_name; @@ -1829,7 +1829,7 @@ xgettext_open (const char *fn, new_name = xstrdup (fn); fp = fopen (fn, "r"); if (fp == NULL) - error (EXIT_FAILURE, errno, _("\ + error (EXIT_FAILURE, errno, _("\ error while opening \"%s\" for reading"), fn); logical_file_name = xstrdup (new_name); } @@ -1838,30 +1838,30 @@ error while opening \"%s\" for reading"), fn); int j; for (j = 0; ; ++j) - { - const char *dir = dir_list_nth (j); + { + const char *dir = dir_list_nth (j); - if (dir == NULL) - error (EXIT_FAILURE, ENOENT, _("\ + if (dir == NULL) + error (EXIT_FAILURE, ENOENT, _("\ error while opening \"%s\" for reading"), fn); - new_name = xconcatenated_filename (dir, fn, NULL); + new_name = xconcatenated_filename (dir, fn, NULL); - fp = fopen (new_name, "r"); - if (fp != NULL) - break; + fp = fopen (new_name, "r"); + if (fp != NULL) + break; - if (errno != ENOENT) - error (EXIT_FAILURE, errno, _("\ + if (errno != ENOENT) + error (EXIT_FAILURE, errno, _("\ error while opening \"%s\" for reading"), new_name); - free (new_name); - } + free (new_name); + } /* Note that the NEW_NAME variable contains the actual file name - and the logical file name is what is reported by xgettext. In - this case NEW_NAME is set to the file which was found along the - directory search path, and LOGICAL_FILE_NAME is is set to the - file name which was searched for. */ + and the logical file name is what is reported by xgettext. In + this case NEW_NAME is set to the file which was found along the + directory search path, and LOGICAL_FILE_NAME is is set to the + file name which was searched for. */ logical_file_name = xstrdup (fn); } @@ -1880,7 +1880,7 @@ static struct formatstring_parser *current_formatstring_parser3; static void extract_from_file (const char *file_name, extractor_ty extractor, - msgdomain_list_ty *mdlp) + msgdomain_list_ty *mdlp) { char *logical_file_name; char *real_file_name; @@ -1897,7 +1897,7 @@ extract_from_file (const char *file_name, extractor_ty extractor, current_formatstring_parser2 = extractor.formatstring_parser2; current_formatstring_parser3 = extractor.formatstring_parser3; extractor.func (fp, real_file_name, logical_file_name, extractor.flag_table, - mdlp); + mdlp); if (fp != stdin) fclose (fp); @@ -1910,7 +1910,7 @@ extract_from_file (const char *file_name, extractor_ty extractor, /* Error message about non-ASCII character in a specific lexical context. */ char * non_ascii_error_message (lexical_context_ty lcontext, - const char *file_name, size_t line_number) + const char *file_name, size_t line_number) { char buffer[21]; char *errmsg; @@ -1924,16 +1924,16 @@ non_ascii_error_message (lexical_context_ty lcontext, { case lc_outside: errmsg = - xasprintf (_("Non-ASCII character at %s%s."), file_name, buffer); + xasprintf (_("Non-ASCII character at %s%s."), file_name, buffer); break; case lc_comment: errmsg = - xasprintf (_("Non-ASCII comment at or before %s%s."), - file_name, buffer); + xasprintf (_("Non-ASCII comment at or before %s%s."), + file_name, buffer); break; case lc_string: errmsg = - xasprintf (_("Non-ASCII string at %s%s."), file_name, buffer); + xasprintf (_("Non-ASCII string at %s%s."), file_name, buffer); break; default: abort (); @@ -1947,22 +1947,22 @@ non_ascii_error_message (lexical_context_ty lcontext, The file_name and line_number are only used for error message purposes. */ char * from_current_source_encoding (const char *string, - lexical_context_ty lcontext, - const char *file_name, size_t line_number) + lexical_context_ty lcontext, + const char *file_name, size_t line_number) { if (xgettext_current_source_encoding == po_charset_ascii) { if (!is_ascii_string (string)) - { - multiline_error (xstrdup (""), - xasprintf ("%s\n%s\n", - non_ascii_error_message (lcontext, - file_name, - line_number), - _("\ + { + multiline_error (xstrdup (""), + xasprintf ("%s\n%s\n", + non_ascii_error_message (lcontext, + file_name, + line_number), + _("\ Please specify the source encoding through --from-code."))); - exit (EXIT_FAILURE); - } + exit (EXIT_FAILURE); + } } else if (xgettext_current_source_encoding != po_charset_utf8) { @@ -1975,12 +1975,12 @@ Please specify the source encoding through --from-code."))); context.message = NULL; string = convert_string_directly (xgettext_current_source_iconv, string, - &context); + &context); #else /* If we don't have iconv(), the only supported values for - xgettext_global_source_encoding and thus also for - xgettext_current_source_encoding are ASCII and UTF-8. - convert_string_directly() should not be called in this case. */ + xgettext_global_source_encoding and thus also for + xgettext_current_source_encoding are ASCII and UTF-8. + convert_string_directly() should not be called in this case. */ abort (); #endif } @@ -1990,15 +1990,15 @@ Please specify the source encoding through --from-code."))); #define CONVERT_STRING(string, lcontext) \ string = from_current_source_encoding (string, lcontext, pos->file_name, \ - pos->line_number); + pos->line_number); /* Update the is_format[] flags depending on the information given in the context. */ static void set_format_flags_from_context (enum is_format is_format[NFORMATS], - flag_context_ty context, const char *string, - lex_pos_ty *pos, const char *pretty_msgstr) + flag_context_ty context, const char *string, + lex_pos_ty *pos, const char *pretty_msgstr) { size_t i; @@ -2007,60 +2007,60 @@ set_format_flags_from_context (enum is_format is_format[NFORMATS], || context.is_format3 != undecided) for (i = 0; i < NFORMATS; i++) { - if (is_format[i] == undecided) - { - if (formatstring_parsers[i] == current_formatstring_parser1 - && context.is_format1 != undecided) - is_format[i] = (enum is_format) context.is_format1; - if (formatstring_parsers[i] == current_formatstring_parser2 - && context.is_format2 != undecided) - is_format[i] = (enum is_format) context.is_format2; - if (formatstring_parsers[i] == current_formatstring_parser3 - && context.is_format3 != undecided) - is_format[i] = (enum is_format) context.is_format3; - } - if (possible_format_p (is_format[i])) - { - struct formatstring_parser *parser = formatstring_parsers[i]; - char *invalid_reason = NULL; - void *descr = parser->parse (string, false, NULL, &invalid_reason); - - if (descr != NULL) - parser->free (descr); - else - { - /* The string is not a valid format string. */ - if (is_format[i] != possible) - { - char buffer[21]; - - error_with_progname = false; - if (pos->line_number == (size_t)(-1)) - buffer[0] = '\0'; - else - sprintf (buffer, ":%ld", (long) pos->line_number); - multiline_warning (xasprintf (_("%s%s: warning: "), - pos->file_name, buffer), - xasprintf (is_format[i] == yes_according_to_context - ? _("Although being used in a format string position, the %s is not a valid %s format string. Reason: %s\n") - : _("Although declared as such, the %s is not a valid %s format string. Reason: %s\n"), - pretty_msgstr, - format_language_pretty[i], - invalid_reason)); - error_with_progname = true; - } - - is_format[i] = impossible; - free (invalid_reason); - } - } + if (is_format[i] == undecided) + { + if (formatstring_parsers[i] == current_formatstring_parser1 + && context.is_format1 != undecided) + is_format[i] = (enum is_format) context.is_format1; + if (formatstring_parsers[i] == current_formatstring_parser2 + && context.is_format2 != undecided) + is_format[i] = (enum is_format) context.is_format2; + if (formatstring_parsers[i] == current_formatstring_parser3 + && context.is_format3 != undecided) + is_format[i] = (enum is_format) context.is_format3; + } + if (possible_format_p (is_format[i])) + { + struct formatstring_parser *parser = formatstring_parsers[i]; + char *invalid_reason = NULL; + void *descr = parser->parse (string, false, NULL, &invalid_reason); + + if (descr != NULL) + parser->free (descr); + else + { + /* The string is not a valid format string. */ + if (is_format[i] != possible) + { + char buffer[21]; + + error_with_progname = false; + if (pos->line_number == (size_t)(-1)) + buffer[0] = '\0'; + else + sprintf (buffer, ":%ld", (long) pos->line_number); + multiline_warning (xasprintf (_("%s%s: warning: "), + pos->file_name, buffer), + xasprintf (is_format[i] == yes_according_to_context + ? _("Although being used in a format string position, the %s is not a valid %s format string. Reason: %s\n") + : _("Although declared as such, the %s is not a valid %s format string. Reason: %s\n"), + pretty_msgstr, + format_language_pretty[i], + invalid_reason)); + error_with_progname = true; + } + + is_format[i] = impossible; + free (invalid_reason); + } + } } } static void warn_format_string (enum is_format is_format[NFORMATS], const char *string, - lex_pos_ty *pos, const char *pretty_msgstr) + lex_pos_ty *pos, const char *pretty_msgstr) { if (possible_format_p (is_format[format_python]) && get_python_format_unnamed_arg_count (string) > 1) @@ -2073,8 +2073,8 @@ warn_format_string (enum is_format is_format[NFORMATS], const char *string, else sprintf (buffer, ":%ld", (long) pos->line_number); multiline_warning (xasprintf (_("%s%s: warning: "), - pos->file_name, buffer), - xasprintf (_("\ + pos->file_name, buffer), + xasprintf (_("\ '%s' format string with unnamed arguments cannot be properly localized:\n\ The translator cannot reorder the arguments.\n\ Please consider using a format string with named arguments,\n\ @@ -2087,9 +2087,9 @@ and a mapping instead of a tuple for the arguments.\n"), message_ty * remember_a_message (message_list_ty *mlp, char *msgctxt, char *msgid, - flag_context_ty context, lex_pos_ty *pos, - const char *extracted_comment, - refcounted_string_list_ty *comment) + flag_context_ty context, lex_pos_ty *pos, + const char *extracted_comment, + refcounted_string_list_ty *comment) { enum is_format is_format[NFORMATS]; struct argument_range range; @@ -2102,12 +2102,12 @@ remember_a_message (message_list_ty *mlp, char *msgctxt, char *msgid, if (exclude != NULL && message_list_search (exclude, msgctxt, msgid) != NULL) { /* Tell the lexer to reset its comment buffer, so that the next - message gets the correct comments. */ + message gets the correct comments. */ xgettext_comment_reset (); savable_comment_reset (); if (msgctxt != NULL) - free (msgctxt); + free (msgctxt); free (msgid); return NULL; @@ -2131,12 +2131,12 @@ remember_a_message (message_list_ty *mlp, char *msgctxt, char *msgid, error_with_progname = false; if (pos->line_number == (size_t)(-1)) - buffer[0] = '\0'; + buffer[0] = '\0'; else - sprintf (buffer, ":%ld", (long) pos->line_number); + sprintf (buffer, ":%ld", (long) pos->line_number); multiline_warning (xasprintf (_("%s%s: warning: "), pos->file_name, - buffer), - xstrdup (_("\ + buffer), + xstrdup (_("\ Empty msgid. It is reserved by GNU gettext:\n\ gettext(\"\") returns the header entry with\n\ meta information, not the empty string.\n"))); @@ -2148,24 +2148,24 @@ meta information, not the empty string.\n"))); if (mp != NULL) { if (msgctxt != NULL) - free (msgctxt); + free (msgctxt); free (msgid); for (i = 0; i < NFORMATS; i++) - is_format[i] = mp->is_format[i]; + is_format[i] = mp->is_format[i]; do_wrap = mp->do_wrap; } else { /* Construct the msgstr from the prefix and suffix, otherwise use the - empty string. */ + empty string. */ if (msgstr_prefix) - msgstr = xasprintf ("%s%s%s", msgstr_prefix, msgid, msgstr_suffix); + msgstr = xasprintf ("%s%s%s", msgstr_prefix, msgid, msgstr_suffix); else - msgstr = ""; + msgstr = ""; /* Allocate a new message and append the message to the list. */ mp = message_alloc (msgctxt, msgid, NULL, msgstr, strlen (msgstr) + 1, - pos); + pos); /* Do not free msgctxt and msgid. */ message_list_append (mlp, mp); } @@ -2189,60 +2189,60 @@ meta information, not the empty string.\n"))); add_all_remaining_comments = add_all_comments; for (j = 0; ; ++j) { - const char *s = xgettext_comment (j); - const char *t; - if (s == NULL) - break; - - CONVERT_STRING (s, lc_comment); - - /* To reduce the possibility of unwanted matches we do a two - step match: the line must contain `xgettext:' and one of - the possible format description strings. */ - if ((t = c_strstr (s, "xgettext:")) != NULL) - { - bool tmp_fuzzy; - enum is_format tmp_format[NFORMATS]; - struct argument_range tmp_range; - enum is_wrap tmp_wrap; - bool interesting; - - t += strlen ("xgettext:"); - - po_parse_comment_special (t, &tmp_fuzzy, tmp_format, &tmp_range, - &tmp_wrap); - - interesting = false; - for (i = 0; i < NFORMATS; i++) - if (tmp_format[i] != undecided) - { - is_format[i] = tmp_format[i]; - interesting = true; - } - if (has_range_p (tmp_range)) - { - range = tmp_range; - interesting = true; - } - if (tmp_wrap != undecided) - { - do_wrap = tmp_wrap; - interesting = true; - } - - /* If the "xgettext:" marker was followed by an interesting - keyword, and we updated our is_format/do_wrap variables, - we don't print the comment as a #. comment. */ - if (interesting) - continue; - } - /* When the comment tag is seen, it drags in not only the line - which it starts, but all remaining comment lines. */ - if (add_all_remaining_comments - || (add_all_remaining_comments = - (comment_tag != NULL - && strncmp (s, comment_tag, strlen (comment_tag)) == 0))) - message_comment_dot_append (mp, s); + const char *s = xgettext_comment (j); + const char *t; + if (s == NULL) + break; + + CONVERT_STRING (s, lc_comment); + + /* To reduce the possibility of unwanted matches we do a two + step match: the line must contain `xgettext:' and one of + the possible format description strings. */ + if ((t = c_strstr (s, "xgettext:")) != NULL) + { + bool tmp_fuzzy; + enum is_format tmp_format[NFORMATS]; + struct argument_range tmp_range; + enum is_wrap tmp_wrap; + bool interesting; + + t += strlen ("xgettext:"); + + po_parse_comment_special (t, &tmp_fuzzy, tmp_format, &tmp_range, + &tmp_wrap); + + interesting = false; + for (i = 0; i < NFORMATS; i++) + if (tmp_format[i] != undecided) + { + is_format[i] = tmp_format[i]; + interesting = true; + } + if (has_range_p (tmp_range)) + { + range = tmp_range; + interesting = true; + } + if (tmp_wrap != undecided) + { + do_wrap = tmp_wrap; + interesting = true; + } + + /* If the "xgettext:" marker was followed by an interesting + keyword, and we updated our is_format/do_wrap variables, + we don't print the comment as a #. comment. */ + if (interesting) + continue; + } + /* When the comment tag is seen, it drags in not only the line + which it starts, but all remaining comment lines. */ + if (add_all_remaining_comments + || (add_all_remaining_comments = + (comment_tag != NULL + && strncmp (s, comment_tag, strlen (comment_tag)) == 0))) + message_comment_dot_append (mp, s); } nitems_after = (mp->comment_dot != NULL ? mp->comment_dot->nitems : 0); @@ -2252,27 +2252,27 @@ meta information, not the empty string.\n"))); same message appears several times, each time with the same comment. */ if (nitems_before < nitems_after) { - size_t added = nitems_after - nitems_before; - - if (added <= nitems_before) - { - bool repeated = true; - - for (i = 0; i < added; i++) - if (strcmp (mp->comment_dot->item[nitems_before - added + i], - mp->comment_dot->item[nitems_before + i]) != 0) - { - repeated = false; - break; - } - - if (repeated) - { - for (i = 0; i < added; i++) - free ((char *) mp->comment_dot->item[nitems_before + i]); - mp->comment_dot->nitems = nitems_before; - } - } + size_t added = nitems_after - nitems_before; + + if (added <= nitems_before) + { + bool repeated = true; + + for (i = 0; i < added; i++) + if (strcmp (mp->comment_dot->item[nitems_before - added + i], + mp->comment_dot->item[nitems_before + i]) != 0) + { + repeated = false; + break; + } + + if (repeated) + { + for (i = 0; i < added; i++) + free ((char *) mp->comment_dot->item[nitems_before + i]); + mp->comment_dot->nitems = nitems_before; + } + } } } @@ -2281,66 +2281,66 @@ meta information, not the empty string.\n"))); for (i = 0; i < NFORMATS; i++) { if (is_format[i] == undecided - && (formatstring_parsers[i] == current_formatstring_parser1 - || formatstring_parsers[i] == current_formatstring_parser2 - || formatstring_parsers[i] == current_formatstring_parser3) - /* But avoid redundancy: objc-format is stronger than c-format. */ - && !(i == format_c && possible_format_p (is_format[format_objc])) - && !(i == format_objc && possible_format_p (is_format[format_c])) - /* Avoid flagging a string as c-format when it's known to be a - qt-format or qt-plural-format or kde-format or boost-format - string. */ - && !(i == format_c - && (possible_format_p (is_format[format_qt]) - || possible_format_p (is_format[format_qt_plural]) - || possible_format_p (is_format[format_kde]) - || possible_format_p (is_format[format_boost])))) - { - struct formatstring_parser *parser = formatstring_parsers[i]; - char *invalid_reason = NULL; - void *descr = parser->parse (mp->msgid, false, NULL, &invalid_reason); - - if (descr != NULL) - { - /* msgid is a valid format string. We mark only those msgids - as format strings which contain at least one format directive - and thus are format strings with a high probability. We - don't mark strings without directives as format strings, - because that would force the programmer to add - "xgettext: no-c-format" anywhere where a translator wishes - to use a percent sign. So, the msgfmt checking will not be - perfect. Oh well. */ - if (parser->get_number_of_directives (descr) > 0 - && !(parser->is_unlikely_intentional != NULL - && parser->is_unlikely_intentional (descr))) - is_format[i] = possible; - - parser->free (descr); - } - else - { - /* msgid is not a valid format string. */ - is_format[i] = impossible; - free (invalid_reason); - } - } + && (formatstring_parsers[i] == current_formatstring_parser1 + || formatstring_parsers[i] == current_formatstring_parser2 + || formatstring_parsers[i] == current_formatstring_parser3) + /* But avoid redundancy: objc-format is stronger than c-format. */ + && !(i == format_c && possible_format_p (is_format[format_objc])) + && !(i == format_objc && possible_format_p (is_format[format_c])) + /* Avoid flagging a string as c-format when it's known to be a + qt-format or qt-plural-format or kde-format or boost-format + string. */ + && !(i == format_c + && (possible_format_p (is_format[format_qt]) + || possible_format_p (is_format[format_qt_plural]) + || possible_format_p (is_format[format_kde]) + || possible_format_p (is_format[format_boost])))) + { + struct formatstring_parser *parser = formatstring_parsers[i]; + char *invalid_reason = NULL; + void *descr = parser->parse (mp->msgid, false, NULL, &invalid_reason); + + if (descr != NULL) + { + /* msgid is a valid format string. We mark only those msgids + as format strings which contain at least one format directive + and thus are format strings with a high probability. We + don't mark strings without directives as format strings, + because that would force the programmer to add + "xgettext: no-c-format" anywhere where a translator wishes + to use a percent sign. So, the msgfmt checking will not be + perfect. Oh well. */ + if (parser->get_number_of_directives (descr) > 0 + && !(parser->is_unlikely_intentional != NULL + && parser->is_unlikely_intentional (descr))) + is_format[i] = possible; + + parser->free (descr); + } + else + { + /* msgid is not a valid format string. */ + is_format[i] = impossible; + free (invalid_reason); + } + } mp->is_format[i] = is_format[i]; } if (has_range_p (range)) { if (has_range_p (mp->range)) - { - if (range.min < mp->range.min) - mp->range.min = range.min; - if (range.max > mp->range.max) - mp->range.max = range.max; - } + { + if (range.min < mp->range.min) + mp->range.min = range.min; + if (range.max > mp->range.max) + mp->range.max = range.max; + } else - mp->range = range; + mp->range = range; } - mp->do_wrap = do_wrap == no ? no : yes; /* By default we wrap. */ + mp->do_wrap = do_wrap == no ? no : yes; /* By default we wrap. */ /* Warn about the use of non-reorderable format strings when the programming language also provides reorderable format strings. */ @@ -2361,8 +2361,8 @@ meta information, not the empty string.\n"))); void remember_a_message_plural (message_ty *mp, char *string, - flag_context_ty context, lex_pos_ty *pos, - refcounted_string_list_ty *comment) + flag_context_ty context, lex_pos_ty *pos, + refcounted_string_list_ty *comment) { char *msgid_plural; char *msgstr1; @@ -2382,13 +2382,13 @@ remember_a_message_plural (message_ty *mp, char *string, mp->msgid_plural = msgid_plural; /* Construct the first plural form from the prefix and suffix, - otherwise use the empty string. The translator will have to - provide additional plural forms. */ + otherwise use the empty string. The translator will have to + provide additional plural forms. */ if (msgstr_prefix) - msgstr1 = - xasprintf ("%s%s%s", msgstr_prefix, msgid_plural, msgstr_suffix); + msgstr1 = + xasprintf ("%s%s%s", msgstr_prefix, msgid_plural, msgstr_suffix); else - msgstr1 = ""; + msgstr1 = ""; msgstr1_len = strlen (msgstr1) + 1; msgstr = XNMALLOC (mp->msgstr_len + msgstr1_len, char); memcpy (msgstr, mp->msgstr, mp->msgstr_len); @@ -2396,56 +2396,56 @@ remember_a_message_plural (message_ty *mp, char *string, mp->msgstr = msgstr; mp->msgstr_len = mp->msgstr_len + msgstr1_len; if (msgstr_prefix) - free (msgstr1); + free (msgstr1); /* Determine whether the context specifies that the msgid_plural is a - format string. */ + format string. */ set_format_flags_from_context (mp->is_format, context, mp->msgid_plural, - pos, "msgid_plural"); + pos, "msgid_plural"); /* If it is not already decided, through programmer comments or - the msgid, whether the msgid is a format string, examine the - msgid_plural. This is a heuristic. */ + the msgid, whether the msgid is a format string, examine the + msgid_plural. This is a heuristic. */ for (i = 0; i < NFORMATS; i++) - if ((formatstring_parsers[i] == current_formatstring_parser1 - || formatstring_parsers[i] == current_formatstring_parser2 - || formatstring_parsers[i] == current_formatstring_parser3) - && (mp->is_format[i] == undecided || mp->is_format[i] == possible) - /* But avoid redundancy: objc-format is stronger than c-format. */ - && !(i == format_c - && possible_format_p (mp->is_format[format_objc])) - && !(i == format_objc - && possible_format_p (mp->is_format[format_c])) - /* Avoid flagging a string as c-format when it's known to be a - qt-format or qt-plural-format or boost-format string. */ - && !(i == format_c - && (possible_format_p (mp->is_format[format_qt]) - || possible_format_p (mp->is_format[format_qt_plural]) - || possible_format_p (mp->is_format[format_kde]) - || possible_format_p (mp->is_format[format_boost])))) - { - struct formatstring_parser *parser = formatstring_parsers[i]; - char *invalid_reason = NULL; - void *descr = - parser->parse (mp->msgid_plural, false, NULL, &invalid_reason); - - if (descr != NULL) - { - /* Same heuristic as in remember_a_message. */ - if (parser->get_number_of_directives (descr) > 0 - && !(parser->is_unlikely_intentional != NULL - && parser->is_unlikely_intentional (descr))) - mp->is_format[i] = possible; - - parser->free (descr); - } - else - { - /* msgid_plural is not a valid format string. */ - mp->is_format[i] = impossible; - free (invalid_reason); - } - } + if ((formatstring_parsers[i] == current_formatstring_parser1 + || formatstring_parsers[i] == current_formatstring_parser2 + || formatstring_parsers[i] == current_formatstring_parser3) + && (mp->is_format[i] == undecided || mp->is_format[i] == possible) + /* But avoid redundancy: objc-format is stronger than c-format. */ + && !(i == format_c + && possible_format_p (mp->is_format[format_objc])) + && !(i == format_objc + && possible_format_p (mp->is_format[format_c])) + /* Avoid flagging a string as c-format when it's known to be a + qt-format or qt-plural-format or boost-format string. */ + && !(i == format_c + && (possible_format_p (mp->is_format[format_qt]) + || possible_format_p (mp->is_format[format_qt_plural]) + || possible_format_p (mp->is_format[format_kde]) + || possible_format_p (mp->is_format[format_boost])))) + { + struct formatstring_parser *parser = formatstring_parsers[i]; + char *invalid_reason = NULL; + void *descr = + parser->parse (mp->msgid_plural, false, NULL, &invalid_reason); + + if (descr != NULL) + { + /* Same heuristic as in remember_a_message. */ + if (parser->get_number_of_directives (descr) > 0 + && !(parser->is_unlikely_intentional != NULL + && parser->is_unlikely_intentional (descr))) + mp->is_format[i] = possible; + + parser->free (descr); + } + else + { + /* msgid_plural is not a valid format string. */ + mp->is_format[i] = impossible; + free (invalid_reason); + } + } /* Warn about the use of non-reorderable format strings when the programming language also provides reorderable format strings. */ @@ -2467,8 +2467,8 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes) if (shapes == NULL || shapes->nshapes == 0) { struct arglist_parser *ap = - (struct arglist_parser *) - xmalloc (offsetof (struct arglist_parser, alternative[0])); + (struct arglist_parser *) + xmalloc (offsetof (struct arglist_parser, alternative[0])); ap->mlp = mlp; ap->keyword = NULL; @@ -2480,10 +2480,10 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes) else { struct arglist_parser *ap = - (struct arglist_parser *) - xmalloc (xsum (sizeof (struct arglist_parser), - xtimes (shapes->nshapes - 1, - sizeof (struct partial_call)))); + (struct arglist_parser *) + xmalloc (xsum (sizeof (struct arglist_parser), + xtimes (shapes->nshapes - 1, + sizeof (struct partial_call)))); size_t i; ap->mlp = mlp; @@ -2491,29 +2491,29 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes) ap->keyword_len = shapes->keyword_len; ap->nalternatives = shapes->nshapes; for (i = 0; i < shapes->nshapes; i++) - { - ap->alternative[i].argnumc = shapes->shapes[i].argnumc; - ap->alternative[i].argnum1 = shapes->shapes[i].argnum1; - ap->alternative[i].argnum2 = shapes->shapes[i].argnum2; - ap->alternative[i].argnum1_glib_context = - shapes->shapes[i].argnum1_glib_context; - ap->alternative[i].argnum2_glib_context = - shapes->shapes[i].argnum2_glib_context; - ap->alternative[i].argtotal = shapes->shapes[i].argtotal; - ap->alternative[i].xcomments = shapes->shapes[i].xcomments; - ap->alternative[i].msgctxt = NULL; - ap->alternative[i].msgctxt_pos.file_name = NULL; - ap->alternative[i].msgctxt_pos.line_number = (size_t)(-1); - ap->alternative[i].msgid = NULL; - ap->alternative[i].msgid_context = null_context; - ap->alternative[i].msgid_pos.file_name = NULL; - ap->alternative[i].msgid_pos.line_number = (size_t)(-1); - ap->alternative[i].msgid_comment = NULL; - ap->alternative[i].msgid_plural = NULL; - ap->alternative[i].msgid_plural_context = null_context; - ap->alternative[i].msgid_plural_pos.file_name = NULL; - ap->alternative[i].msgid_plural_pos.line_number = (size_t)(-1); - } + { + ap->alternative[i].argnumc = shapes->shapes[i].argnumc; + ap->alternative[i].argnum1 = shapes->shapes[i].argnum1; + ap->alternative[i].argnum2 = shapes->shapes[i].argnum2; + ap->alternative[i].argnum1_glib_context = + shapes->shapes[i].argnum1_glib_context; + ap->alternative[i].argnum2_glib_context = + shapes->shapes[i].argnum2_glib_context; + ap->alternative[i].argtotal = shapes->shapes[i].argtotal; + ap->alternative[i].xcomments = shapes->shapes[i].xcomments; + ap->alternative[i].msgctxt = NULL; + ap->alternative[i].msgctxt_pos.file_name = NULL; + ap->alternative[i].msgctxt_pos.line_number = (size_t)(-1); + ap->alternative[i].msgid = NULL; + ap->alternative[i].msgid_context = null_context; + ap->alternative[i].msgid_pos.file_name = NULL; + ap->alternative[i].msgid_pos.line_number = (size_t)(-1); + ap->alternative[i].msgid_comment = NULL; + ap->alternative[i].msgid_plural = NULL; + ap->alternative[i].msgid_plural_context = null_context; + ap->alternative[i].msgid_plural_pos.file_name = NULL; + ap->alternative[i].msgid_plural_pos.line_number = (size_t)(-1); + } return ap; } @@ -2526,7 +2526,7 @@ arglist_parser_clone (struct arglist_parser *ap) struct arglist_parser *copy = (struct arglist_parser *) xmalloc (xsum (sizeof (struct arglist_parser) - sizeof (struct partial_call), - xtimes (ap->nalternatives, sizeof (struct partial_call)))); + xtimes (ap->nalternatives, sizeof (struct partial_call)))); size_t i; copy->mlp = ap->mlp; @@ -2552,7 +2552,7 @@ arglist_parser_clone (struct arglist_parser *ap) ccp->msgid_pos = cp->msgctxt_pos; ccp->msgid_comment = add_reference (cp->msgid_comment); ccp->msgid_plural = - (cp->msgid_plural != NULL ? xstrdup (cp->msgid_plural) : NULL); + (cp->msgid_plural != NULL ? xstrdup (cp->msgid_plural) : NULL); ccp->msgid_plural_context = cp->msgid_plural_context; ccp->msgid_plural_pos = cp->msgid_plural_pos; } @@ -2563,10 +2563,10 @@ arglist_parser_clone (struct arglist_parser *ap) void arglist_parser_remember (struct arglist_parser *ap, - int argnum, char *string, - flag_context_ty context, - char *file_name, size_t line_number, - refcounted_string_list_ty *comment) + int argnum, char *string, + flag_context_ty context, + char *file_name, size_t line_number, + refcounted_string_list_ty *comment) { bool stored_string = false; size_t nalternatives = ap->nalternatives; @@ -2579,38 +2579,38 @@ arglist_parser_remember (struct arglist_parser *ap, struct partial_call *cp = &ap->alternative[i]; if (argnum == cp->argnumc) - { - cp->msgctxt = string; - cp->msgctxt_pos.file_name = file_name; - cp->msgctxt_pos.line_number = line_number; - stored_string = true; - /* Mark msgctxt as done. */ - cp->argnumc = 0; - } + { + cp->msgctxt = string; + cp->msgctxt_pos.file_name = file_name; + cp->msgctxt_pos.line_number = line_number; + stored_string = true; + /* Mark msgctxt as done. */ + cp->argnumc = 0; + } else - { - if (argnum == cp->argnum1) - { - cp->msgid = string; - cp->msgid_context = context; - cp->msgid_pos.file_name = file_name; - cp->msgid_pos.line_number = line_number; - cp->msgid_comment = add_reference (comment); - stored_string = true; - /* Mark msgid as done. */ - cp->argnum1 = 0; - } - if (argnum == cp->argnum2) - { - cp->msgid_plural = string; - cp->msgid_plural_context = context; - cp->msgid_plural_pos.file_name = file_name; - cp->msgid_plural_pos.line_number = line_number; - stored_string = true; - /* Mark msgid_plural as done. */ - cp->argnum2 = 0; - } - } + { + if (argnum == cp->argnum1) + { + cp->msgid = string; + cp->msgid_context = context; + cp->msgid_pos.file_name = file_name; + cp->msgid_pos.line_number = line_number; + cp->msgid_comment = add_reference (comment); + stored_string = true; + /* Mark msgid as done. */ + cp->argnum1 = 0; + } + if (argnum == cp->argnum2) + { + cp->msgid_plural = string; + cp->msgid_plural_context = context; + cp->msgid_plural_pos.file_name = file_name; + cp->msgid_plural_pos.line_number = line_number; + stored_string = true; + /* Mark msgid_plural as done. */ + cp->argnum2 = 0; + } + } } /* Note: There is a memory leak here: When string was stored but is later not used by arglist_parser_done, we don't free it. */ @@ -2639,11 +2639,11 @@ arglist_parser_decidedp (struct arglist_parser *ap, int argnum) struct partial_call *cp = &ap->alternative[i]; if (!((cp->argnumc <= argnum - && cp->argnum1 <= argnum - && cp->argnum2 <= argnum) - || (cp->argtotal > 0 && cp->argtotal < argnum))) - /* cp is still undecided. */ - return false; + && cp->argnum1 <= argnum + && cp->argnum2 <= argnum) + || (cp->argtotal > 0 && cp->argtotal < argnum))) + /* cp is still undecided. */ + return false; } return true; } @@ -2662,8 +2662,8 @@ arglist_parser_done (struct arglist_parser *ap, int argnum) struct partial_call *cp = &ap->alternative[i]; if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 - && (cp->argtotal == 0 || cp->argtotal == argnum)) - ncomplete++; + && (cp->argtotal == 0 || cp->argtotal == argnum)) + ncomplete++; } if (ncomplete > 0) @@ -2672,259 +2672,259 @@ arglist_parser_done (struct arglist_parser *ap, int argnum) bool ambiguous = false; /* Find complete calls where msgctxt, msgid, msgid_plural are all - provided. */ + provided. */ for (i = 0; i < ap->nalternatives; i++) - { - struct partial_call *cp = &ap->alternative[i]; - - if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 - && (cp->argtotal == 0 || cp->argtotal == argnum) - && cp->msgctxt != NULL - && cp->msgid != NULL - && cp->msgid_plural != NULL) - { - if (best_cp != NULL) - { - ambiguous = true; - break; - } - best_cp = cp; - } - } + { + struct partial_call *cp = &ap->alternative[i]; + + if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 + && (cp->argtotal == 0 || cp->argtotal == argnum) + && cp->msgctxt != NULL + && cp->msgid != NULL + && cp->msgid_plural != NULL) + { + if (best_cp != NULL) + { + ambiguous = true; + break; + } + best_cp = cp; + } + } if (best_cp == NULL) - { - struct partial_call *best_cp1 = NULL; - struct partial_call *best_cp2 = NULL; - - /* Find complete calls where msgctxt, msgid are provided. */ - for (i = 0; i < ap->nalternatives; i++) - { - struct partial_call *cp = &ap->alternative[i]; - - if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 - && (cp->argtotal == 0 || cp->argtotal == argnum) - && cp->msgctxt != NULL - && cp->msgid != NULL) - { - if (best_cp1 != NULL) - { - ambiguous = true; - break; - } - best_cp1 = cp; - } - } - - /* Find complete calls where msgid, msgid_plural are provided. */ - for (i = 0; i < ap->nalternatives; i++) - { - struct partial_call *cp = &ap->alternative[i]; - - if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 - && (cp->argtotal == 0 || cp->argtotal == argnum) - && cp->msgid != NULL - && cp->msgid_plural != NULL) - { - if (best_cp2 != NULL) - { - ambiguous = true; - break; - } - best_cp2 = cp; - } - } - - if (best_cp1 != NULL) - best_cp = best_cp1; - if (best_cp2 != NULL) - { - if (best_cp != NULL) - ambiguous = true; - else - best_cp = best_cp2; - } - } + { + struct partial_call *best_cp1 = NULL; + struct partial_call *best_cp2 = NULL; + + /* Find complete calls where msgctxt, msgid are provided. */ + for (i = 0; i < ap->nalternatives; i++) + { + struct partial_call *cp = &ap->alternative[i]; + + if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 + && (cp->argtotal == 0 || cp->argtotal == argnum) + && cp->msgctxt != NULL + && cp->msgid != NULL) + { + if (best_cp1 != NULL) + { + ambiguous = true; + break; + } + best_cp1 = cp; + } + } + + /* Find complete calls where msgid, msgid_plural are provided. */ + for (i = 0; i < ap->nalternatives; i++) + { + struct partial_call *cp = &ap->alternative[i]; + + if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 + && (cp->argtotal == 0 || cp->argtotal == argnum) + && cp->msgid != NULL + && cp->msgid_plural != NULL) + { + if (best_cp2 != NULL) + { + ambiguous = true; + break; + } + best_cp2 = cp; + } + } + + if (best_cp1 != NULL) + best_cp = best_cp1; + if (best_cp2 != NULL) + { + if (best_cp != NULL) + ambiguous = true; + else + best_cp = best_cp2; + } + } if (best_cp == NULL) - { - /* Find complete calls where msgid is provided. */ - for (i = 0; i < ap->nalternatives; i++) - { - struct partial_call *cp = &ap->alternative[i]; - - if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 - && (cp->argtotal == 0 || cp->argtotal == argnum) - && cp->msgid != NULL) - { - if (best_cp != NULL) - { - ambiguous = true; - break; - } - best_cp = cp; - } - } - } + { + /* Find complete calls where msgid is provided. */ + for (i = 0; i < ap->nalternatives; i++) + { + struct partial_call *cp = &ap->alternative[i]; + + if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 + && (cp->argtotal == 0 || cp->argtotal == argnum) + && cp->msgid != NULL) + { + if (best_cp != NULL) + { + ambiguous = true; + break; + } + best_cp = cp; + } + } + } if (ambiguous) - { - error_with_progname = false; - error_at_line (0, 0, - best_cp->msgid_pos.file_name, - best_cp->msgid_pos.line_number, - _("ambiguous argument specification for keyword '%.*s'"), - (int) ap->keyword_len, ap->keyword); - error_with_progname = true; - } + { + error_with_progname = false; + error_at_line (0, 0, + best_cp->msgid_pos.file_name, + best_cp->msgid_pos.line_number, + _("ambiguous argument specification for keyword '%.*s'"), + (int) ap->keyword_len, ap->keyword); + error_with_progname = true; + } if (best_cp != NULL) - { - /* best_cp indicates the best found complete call. - Now call remember_a_message. */ - message_ty *mp; - - /* Split strings in the GNOME glib syntax "msgctxt|msgid". */ - if (best_cp->argnum1_glib_context || best_cp->argnum2_glib_context) - /* split_keywordspec should not allow the context to be specified - in two different ways. */ - if (best_cp->msgctxt != NULL) - abort (); - if (best_cp->argnum1_glib_context) - { - const char *separator = strchr (best_cp->msgid, '|'); - - if (separator == NULL) - { - error_with_progname = false; - error_at_line (0, 0, - best_cp->msgid_pos.file_name, - best_cp->msgid_pos.line_number, - _("warning: missing context for keyword '%.*s'"), - (int) ap->keyword_len, ap->keyword); - error_with_progname = true; - } - else - { - size_t ctxt_len = separator - best_cp->msgid; - char *ctxt = XNMALLOC (ctxt_len + 1, char); - - memcpy (ctxt, best_cp->msgid, ctxt_len); - ctxt[ctxt_len] = '\0'; - best_cp->msgctxt = ctxt; - best_cp->msgid = xstrdup (separator + 1); - } - } - if (best_cp->msgid_plural != NULL && best_cp->argnum2_glib_context) - { - const char *separator = strchr (best_cp->msgid_plural, '|'); - - if (separator == NULL) - { - error_with_progname = false; - error_at_line (0, 0, - best_cp->msgid_plural_pos.file_name, - best_cp->msgid_plural_pos.line_number, - _("warning: missing context for plural argument of keyword '%.*s'"), - (int) ap->keyword_len, ap->keyword); - error_with_progname = true; - } - else - { - size_t ctxt_len = separator - best_cp->msgid_plural; - char *ctxt = XNMALLOC (ctxt_len + 1, char); - - memcpy (ctxt, best_cp->msgid_plural, ctxt_len); - ctxt[ctxt_len] = '\0'; - if (best_cp->msgctxt == NULL) - best_cp->msgctxt = ctxt; - else - { - if (strcmp (ctxt, best_cp->msgctxt) != 0) - { - error_with_progname = false; - error_at_line (0, 0, - best_cp->msgid_plural_pos.file_name, - best_cp->msgid_plural_pos.line_number, - _("context mismatch between singular and plural form")); - error_with_progname = true; - } - free (ctxt); - } - best_cp->msgid_plural = xstrdup (separator + 1); - } - } - - { - flag_context_ty msgid_context = best_cp->msgid_context; - flag_context_ty msgid_plural_context = best_cp->msgid_plural_context; - - /* Special support for the 3-argument tr operator in Qt: - When --qt and --keyword=tr:1,1,2c,3t are specified, add to the - context the information that the argument is expeected to be a - qt-plural-format. */ - if (recognize_format_qt - && current_formatstring_parser3 == &formatstring_qt_plural - && best_cp->msgid_plural == best_cp->msgid) - { - msgid_context.is_format3 = yes_according_to_context; - msgid_plural_context.is_format3 = yes_according_to_context; - } - - mp = remember_a_message (ap->mlp, best_cp->msgctxt, best_cp->msgid, - msgid_context, - &best_cp->msgid_pos, - NULL, best_cp->msgid_comment); - if (best_cp->msgid_plural != NULL) - remember_a_message_plural (mp, best_cp->msgid_plural, - msgid_plural_context, - &best_cp->msgid_plural_pos, - NULL); - } - - if (best_cp->xcomments.nitems > 0) - { - /* Add best_cp->xcomments to mp->comment_dot, unless already - present. */ - size_t i; - - for (i = 0; i < best_cp->xcomments.nitems; i++) - { - const char *xcomment = best_cp->xcomments.item[i]; - bool found = false; - - if (mp->comment_dot != NULL) - { - size_t j; - - for (j = 0; j < mp->comment_dot->nitems; j++) - if (strcmp (xcomment, mp->comment_dot->item[j]) == 0) - { - found = true; - break; - } - } - if (!found) - message_comment_dot_append (mp, xcomment); - } - } - } + { + /* best_cp indicates the best found complete call. + Now call remember_a_message. */ + message_ty *mp; + + /* Split strings in the GNOME glib syntax "msgctxt|msgid". */ + if (best_cp->argnum1_glib_context || best_cp->argnum2_glib_context) + /* split_keywordspec should not allow the context to be specified + in two different ways. */ + if (best_cp->msgctxt != NULL) + abort (); + if (best_cp->argnum1_glib_context) + { + const char *separator = strchr (best_cp->msgid, '|'); + + if (separator == NULL) + { + error_with_progname = false; + error_at_line (0, 0, + best_cp->msgid_pos.file_name, + best_cp->msgid_pos.line_number, + _("warning: missing context for keyword '%.*s'"), + (int) ap->keyword_len, ap->keyword); + error_with_progname = true; + } + else + { + size_t ctxt_len = separator - best_cp->msgid; + char *ctxt = XNMALLOC (ctxt_len + 1, char); + + memcpy (ctxt, best_cp->msgid, ctxt_len); + ctxt[ctxt_len] = '\0'; + best_cp->msgctxt = ctxt; + best_cp->msgid = xstrdup (separator + 1); + } + } + if (best_cp->msgid_plural != NULL && best_cp->argnum2_glib_context) + { + const char *separator = strchr (best_cp->msgid_plural, '|'); + + if (separator == NULL) + { + error_with_progname = false; + error_at_line (0, 0, + best_cp->msgid_plural_pos.file_name, + best_cp->msgid_plural_pos.line_number, + _("warning: missing context for plural argument of keyword '%.*s'"), + (int) ap->keyword_len, ap->keyword); + error_with_progname = true; + } + else + { + size_t ctxt_len = separator - best_cp->msgid_plural; + char *ctxt = XNMALLOC (ctxt_len + 1, char); + + memcpy (ctxt, best_cp->msgid_plural, ctxt_len); + ctxt[ctxt_len] = '\0'; + if (best_cp->msgctxt == NULL) + best_cp->msgctxt = ctxt; + else + { + if (strcmp (ctxt, best_cp->msgctxt) != 0) + { + error_with_progname = false; + error_at_line (0, 0, + best_cp->msgid_plural_pos.file_name, + best_cp->msgid_plural_pos.line_number, + _("context mismatch between singular and plural form")); + error_with_progname = true; + } + free (ctxt); + } + best_cp->msgid_plural = xstrdup (separator + 1); + } + } + + { + flag_context_ty msgid_context = best_cp->msgid_context; + flag_context_ty msgid_plural_context = best_cp->msgid_plural_context; + + /* Special support for the 3-argument tr operator in Qt: + When --qt and --keyword=tr:1,1,2c,3t are specified, add to the + context the information that the argument is expeected to be a + qt-plural-format. */ + if (recognize_format_qt + && current_formatstring_parser3 == &formatstring_qt_plural + && best_cp->msgid_plural == best_cp->msgid) + { + msgid_context.is_format3 = yes_according_to_context; + msgid_plural_context.is_format3 = yes_according_to_context; + } + + mp = remember_a_message (ap->mlp, best_cp->msgctxt, best_cp->msgid, + msgid_context, + &best_cp->msgid_pos, + NULL, best_cp->msgid_comment); + if (best_cp->msgid_plural != NULL) + remember_a_message_plural (mp, best_cp->msgid_plural, + msgid_plural_context, + &best_cp->msgid_plural_pos, + NULL); + } + + if (best_cp->xcomments.nitems > 0) + { + /* Add best_cp->xcomments to mp->comment_dot, unless already + present. */ + size_t i; + + for (i = 0; i < best_cp->xcomments.nitems; i++) + { + const char *xcomment = best_cp->xcomments.item[i]; + bool found = false; + + if (mp->comment_dot != NULL) + { + size_t j; + + for (j = 0; j < mp->comment_dot->nitems; j++) + if (strcmp (xcomment, mp->comment_dot->item[j]) == 0) + { + found = true; + break; + } + } + if (!found) + message_comment_dot_append (mp, xcomment); + } + } + } } else { /* No complete call was parsed. */ /* Note: There is a memory leak here: When there is more than one - alternative, the same string can be stored in multiple alternatives, - and it's not easy to free all strings reliably. */ + alternative, the same string can be stored in multiple alternatives, + and it's not easy to free all strings reliably. */ if (ap->nalternatives == 1) - { - if (ap->alternative[0].msgctxt != NULL) - free (ap->alternative[0].msgctxt); - if (ap->alternative[0].msgid != NULL) - free (ap->alternative[0].msgid); - if (ap->alternative[0].msgid_plural != NULL) - free (ap->alternative[0].msgid_plural); - } + { + if (ap->alternative[0].msgctxt != NULL) + free (ap->alternative[0].msgctxt); + if (ap->alternative[0].msgid != NULL) + free (ap->alternative[0].msgid); + if (ap->alternative[0].msgid_plural != NULL) + free (ap->alternative[0].msgid_plural); + } } for (i = 0; i < ap->nalternatives; i++) @@ -2946,16 +2946,16 @@ construct_header () if (package_name != NULL) { if (package_version != NULL) - project_id_version = xasprintf ("%s %s", package_name, package_version); + project_id_version = xasprintf ("%s %s", package_name, package_version); else - project_id_version = xasprintf ("%s", package_name); + project_id_version = xasprintf ("%s", package_name); } else project_id_version = xstrdup ("PACKAGE VERSION"); if (msgid_bugs_address != NULL && msgid_bugs_address[0] == '\0') multiline_warning (xasprintf (_("warning: ")), - xstrdup (_("\ + xstrdup (_("\ The option --msgid-bugs-address was not specified.\n\ If you are using a `Makevars' file, please specify\n\ the MSGID_BUGS_ADDRESS variable there; otherwise please\n\ @@ -2976,23 +2976,23 @@ Language: \n\ MIME-Version: 1.0\n\ Content-Type: text/plain; charset=CHARSET\n\ Content-Transfer-Encoding: 8bit\n", - project_id_version, - msgid_bugs_address != NULL ? msgid_bugs_address : "", - timestring); + project_id_version, + msgid_bugs_address != NULL ? msgid_bugs_address : "", + timestring); free (timestring); free (project_id_version); mp = message_alloc (NULL, "", NULL, msgstr, strlen (msgstr) + 1, &pos); message_comment_append (mp, - copyright_holder[0] != '\0' - ? xasprintf ("\ + copyright_holder[0] != '\0' + ? xasprintf ("\ SOME DESCRIPTIVE TITLE.\n\ Copyright (C) YEAR %s\n\ This file is distributed under the same license as the PACKAGE package.\n\ FIRST AUTHOR , YEAR.\n", - copyright_holder) - : "\ + copyright_holder) + : "\ SOME DESCRIPTIVE TITLE.\n\ This file is put in the public domain.\n\ FIRST AUTHOR , YEAR.\n"); @@ -3014,47 +3014,47 @@ finalize_header (msgdomain_list_ty *mdlp) has_plural = false; for (i = 0; i < mdlp->nitems; i++) { - message_list_ty *mlp = mdlp->item[i]->messages; - - for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - - if (mp->msgid_plural != NULL) - { - has_plural = true; - break; - } - } - if (has_plural) - break; + message_list_ty *mlp = mdlp->item[i]->messages; + + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + + if (mp->msgid_plural != NULL) + { + has_plural = true; + break; + } + } + if (has_plural) + break; } if (has_plural) { - message_ty *header = - message_list_search (mdlp->item[0]->messages, NULL, ""); - if (header != NULL - && c_strstr (header->msgstr, "Plural-Forms:") == NULL) - { - size_t insertpos = strlen (header->msgstr); - const char *suffix; - size_t suffix_len; - char *new_msgstr; - - suffix = "\nPlural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"; - if (insertpos == 0 || header->msgstr[insertpos-1] == '\n') - suffix++; - suffix_len = strlen (suffix); - new_msgstr = XNMALLOC (header->msgstr_len + suffix_len, char); - memcpy (new_msgstr, header->msgstr, insertpos); - memcpy (new_msgstr + insertpos, suffix, suffix_len); - memcpy (new_msgstr + insertpos + suffix_len, - header->msgstr + insertpos, - header->msgstr_len - insertpos); - header->msgstr = new_msgstr; - header->msgstr_len = header->msgstr_len + suffix_len; - } + message_ty *header = + message_list_search (mdlp->item[0]->messages, NULL, ""); + if (header != NULL + && c_strstr (header->msgstr, "Plural-Forms:") == NULL) + { + size_t insertpos = strlen (header->msgstr); + const char *suffix; + size_t suffix_len; + char *new_msgstr; + + suffix = "\nPlural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"; + if (insertpos == 0 || header->msgstr[insertpos-1] == '\n') + suffix++; + suffix_len = strlen (suffix); + new_msgstr = XNMALLOC (header->msgstr_len + suffix_len, char); + memcpy (new_msgstr, header->msgstr, insertpos); + memcpy (new_msgstr + insertpos, suffix, suffix_len); + memcpy (new_msgstr + insertpos + suffix_len, + header->msgstr + insertpos, + header->msgstr_len - insertpos); + header->msgstr = new_msgstr; + header->msgstr_len = header->msgstr_len + suffix_len; + } } } @@ -3068,17 +3068,17 @@ finalize_header (msgdomain_list_ty *mdlp) for (i = 0; i < mdlp->nitems; i++) { - message_list_ty *mlp = mdlp->item[i]->messages; + message_list_ty *mlp = mdlp->item[i]->messages; - if (!is_ascii_message_list (mlp)) - has_nonascii = true; + if (!is_ascii_message_list (mlp)) + has_nonascii = true; } if (has_nonascii || output_syntax->requires_utf8) { - message_list_ty *mlp = mdlp->item[0]->messages; + message_list_ty *mlp = mdlp->item[0]->messages; - iconv_message_list (mlp, po_charset_utf8, po_charset_utf8, NULL); + iconv_message_list (mlp, po_charset_utf8, po_charset_utf8, NULL); } } } @@ -3132,37 +3132,37 @@ language_to_extractor (const char *name) for (tp = table; tp < ENDOF(table); ++tp) if (c_strcasecmp (name, tp->name) == 0) { - extractor_ty result; - - result.func = tp->func; - result.flag_table = tp->flag_table; - result.formatstring_parser1 = tp->formatstring_parser1; - result.formatstring_parser2 = tp->formatstring_parser2; - result.formatstring_parser3 = NULL; - - /* Handle --qt. It's preferrable to handle this facility here rather - than through an option --language=C++/Qt because the latter would - conflict with the language "C++" regarding the file extensions. */ - if (recognize_format_qt && strcmp (tp->name, "C++") == 0) - { - result.flag_table = &flag_table_cxx_qt; - result.formatstring_parser2 = &formatstring_qt; - result.formatstring_parser3 = &formatstring_qt_plural; - } - /* Likewise for --kde. */ - if (recognize_format_kde && strcmp (tp->name, "C++") == 0) - { - result.flag_table = &flag_table_cxx_kde; - result.formatstring_parser2 = &formatstring_kde; - } - /* Likewise for --boost. */ - if (recognize_format_boost && strcmp (tp->name, "C++") == 0) - { - result.flag_table = &flag_table_cxx_boost; - result.formatstring_parser2 = &formatstring_boost; - } - - return result; + extractor_ty result; + + result.func = tp->func; + result.flag_table = tp->flag_table; + result.formatstring_parser1 = tp->formatstring_parser1; + result.formatstring_parser2 = tp->formatstring_parser2; + result.formatstring_parser3 = NULL; + + /* Handle --qt. It's preferrable to handle this facility here rather + than through an option --language=C++/Qt because the latter would + conflict with the language "C++" regarding the file extensions. */ + if (recognize_format_qt && strcmp (tp->name, "C++") == 0) + { + result.flag_table = &flag_table_cxx_qt; + result.formatstring_parser2 = &formatstring_qt; + result.formatstring_parser3 = &formatstring_qt_plural; + } + /* Likewise for --kde. */ + if (recognize_format_kde && strcmp (tp->name, "C++") == 0) + { + result.flag_table = &flag_table_cxx_kde; + result.formatstring_parser2 = &formatstring_kde; + } + /* Likewise for --boost. */ + if (recognize_format_boost && strcmp (tp->name, "C++") == 0) + { + result.flag_table = &flag_table_cxx_boost; + result.formatstring_parser2 = &formatstring_boost; + } + + return result; } error (EXIT_FAILURE, 0, _("language `%s' unknown"), name); diff --git a/gettext-tools/src/xgettext.h b/gettext-tools/src/xgettext.h index 53c9ce87c..6b2c53577 100644 --- a/gettext-tools/src/xgettext.h +++ b/gettext-tools/src/xgettext.h @@ -61,7 +61,7 @@ struct callshape /* Split keyword spec into keyword, argnum1, argnum2, argnumc. */ extern void split_keywordspec (const char *spec, const char **endp, - struct callshape *shapep); + struct callshape *shapep); /* Set of alternative calling conventions for a given keyword. */ struct callshapes @@ -75,8 +75,8 @@ struct callshapes /* Insert a (keyword, callshape) pair into a hash table mapping keyword to 'struct callshapes *'. */ extern void insert_keyword_callshape (hash_table *table, - const char *keyword, size_t keyword_len, - const struct callshape *shape); + const char *keyword, size_t keyword_len, + const struct callshape *shape); /* Context representing some flags. */ @@ -102,15 +102,15 @@ extern flag_context_ty passthrough_context; The result will then also have all pass_format* flags = false. */ extern flag_context_ty inherited_context (flag_context_ty outer_context, - flag_context_ty modifier_context); + flag_context_ty modifier_context); /* Context representing some flags, for each possible argument number. This is a linked list, sorted according to the argument number. */ typedef struct flag_context_list_ty flag_context_list_ty; struct flag_context_list_ty { - int argnum; /* current argument number, > 0 */ - flag_context_ty flags; /* flags for current argument */ + int argnum; /* current argument number, > 0 */ + flag_context_ty flags; /* flags for current argument */ flag_context_list_ty *next; }; @@ -118,8 +118,8 @@ struct flag_context_list_ty typedef struct flag_context_list_iterator_ty flag_context_list_iterator_ty; struct flag_context_list_iterator_ty { - int argnum; /* current argument number, > 0 */ - const flag_context_list_ty* head; /* tail of list */ + int argnum; /* current argument number, > 0 */ + const flag_context_list_ty* head; /* tail of list */ }; extern flag_context_list_iterator_ty null_context_list_iterator; extern flag_context_list_iterator_ty passthrough_context_list_iterator; @@ -134,7 +134,7 @@ typedef hash_table /* char[] -> flag_context_list_ty * */ flag_context_list_table_ty; extern flag_context_list_ty * flag_context_list_table_lookup (flag_context_list_table_ty *flag_table, - const void *key, size_t keylen); + const void *key, size_t keylen); /* Record a flag in the appropriate backend's table. */ extern void xgettext_record_flag (const char *optionstring); @@ -150,8 +150,8 @@ typedef enum /* Error message about non-ASCII character in a specific lexical context. */ extern char *non_ascii_error_message (lexical_context_ty lcontext, - const char *file_name, - size_t line_number); + const char *file_name, + size_t line_number); /* Canonicalized encoding name for all input files. */ @@ -178,9 +178,9 @@ extern iconv_t xgettext_current_source_iconv; The lcontext, file_name and line_number are only used for error message purposes. */ extern char *from_current_source_encoding (const char *string, - lexical_context_ty lcontext, - const char *file_name, - size_t line_number); + lexical_context_ty lcontext, + const char *file_name, + size_t line_number); /* List of messages whose msgids must not be extracted, or NULL. @@ -224,12 +224,12 @@ drop_reference (refcounted_string_list_ty *rslp) if (rslp != NULL) { if (rslp->refcount > 1) - rslp->refcount--; + rslp->refcount--; else - { - string_list_destroy (&rslp->contents); - free (rslp); - } + { + string_list_destroy (&rslp->contents); + free (rslp); + } } } @@ -249,12 +249,12 @@ extern void savable_comment_reset (void); (then add_reference must be used when saving it, and drop_reference while dropping it). Clear savable_comment. */ extern message_ty *remember_a_message (message_list_ty *mlp, - char *msgctxt, - char *msgid, - flag_context_ty context, - lex_pos_ty *pos, - const char *extracted_comment, - refcounted_string_list_ty *comment); + char *msgctxt, + char *msgid, + flag_context_ty context, + lex_pos_ty *pos, + const char *extracted_comment, + refcounted_string_list_ty *comment); /* Add an msgid_plural to a message previously returned by remember_a_message. @@ -264,10 +264,10 @@ extern message_ty *remember_a_message (message_list_ty *mlp, (then add_reference must be used when saving it, and drop_reference while dropping it). Clear savable_comment. */ extern void remember_a_message_plural (message_ty *mp, - char *string, - flag_context_ty context, - lex_pos_ty *pos, - refcounted_string_list_ty *comment); + char *string, + flag_context_ty context, + lex_pos_ty *pos, + refcounted_string_list_ty *comment); /* Represents the progressive parsing of an argument list w.r.t. a single @@ -306,7 +306,7 @@ struct arglist_parser /* Creates a fresh arglist_parser recognizing calls. You can pass shapes = NULL for a parser not recognizing any calls. */ extern struct arglist_parser * arglist_parser_alloc (message_list_ty *mlp, - const struct callshapes *shapes); + const struct callshapes *shapes); /* Clones an arglist_parser. */ extern struct arglist_parser * arglist_parser_clone (struct arglist_parser *ap); /* Adds a string argument to an arglist_parser. ARGNUM must be > 0. @@ -316,10 +316,10 @@ extern struct arglist_parser * arglist_parser_clone (struct arglist_parser *ap); (then add_reference must be used when saving it, and drop_reference while dropping it). Clear savable_comment. */ extern void arglist_parser_remember (struct arglist_parser *ap, - int argnum, char *string, - flag_context_ty context, - char *file_name, size_t line_number, - refcounted_string_list_ty *comment); + int argnum, char *string, + flag_context_ty context, + char *file_name, size_t line_number, + refcounted_string_list_ty *comment); /* Tests whether an arglist_parser has is not waiting for more arguments after argument ARGNUM. */ extern bool arglist_parser_decidedp (struct arglist_parser *ap, int argnum); diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index b8507d6aa..16e613b63 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,7 @@ +2009-12-12 Bruno Haible + + * *.c: Untabify. + 2009-08-30 Bruno Haible Fix a test failure on Solaris. diff --git a/gettext-tools/tests/format-c-3-prg.c b/gettext-tools/tests/format-c-3-prg.c index e00bb6f19..ea8997edd 100644 --- a/gettext-tools/tests/format-c-3-prg.c +++ b/gettext-tools/tests/format-c-3-prg.c @@ -62,8 +62,8 @@ main (int argc, char *argv[]) c1 = "Vater von %"; c2 = " Kindern"; if (!(strlen (s) > strlen (c1) + strlen (c2) - && memcmp (s, c1, strlen (c1)) == 0 - && memcmp (s + strlen (s) - strlen (c2), c2, strlen (c2)) == 0)) + && memcmp (s, c1, strlen (c1)) == 0 + && memcmp (s + strlen (s) - strlen (c2), c2, strlen (c2)) == 0)) { fprintf (stderr, "String not translated.\n"); exit (1); diff --git a/gettext-tools/tests/format-c-4-prg.c b/gettext-tools/tests/format-c-4-prg.c index 069322eb9..007f853fc 100644 --- a/gettext-tools/tests/format-c-4-prg.c +++ b/gettext-tools/tests/format-c-4-prg.c @@ -62,8 +62,8 @@ main (int argc, char *argv[]) c1 = "Vater von %"; c2 = " Kindern"; if (!(strlen (s) > strlen (c1) + strlen (c2) - && memcmp (s, c1, strlen (c1)) == 0 - && memcmp (s + strlen (s) - strlen (c2), c2, strlen (c2)) == 0)) + && memcmp (s, c1, strlen (c1)) == 0 + && memcmp (s + strlen (s) - strlen (c2), c2, strlen (c2)) == 0)) { fprintf (stderr, "String not translated.\n"); exit (1); diff --git a/gettext-tools/tests/gettext-3-prg.c b/gettext-tools/tests/gettext-3-prg.c index 98595d8ac..b2369cc05 100644 --- a/gettext-tools/tests/gettext-3-prg.c +++ b/gettext-tools/tests/gettext-3-prg.c @@ -67,13 +67,13 @@ main (void) int j; if (setlocale (LC_ALL, lang[i]) == NULL) - setlocale (LC_ALL, "C"); + setlocale (LC_ALL, "C"); bindtextdomain ("tstlang", "."); for (j = 0; j < data_cnt; ++j) - printf ("%s - %s\n", strings[j].selection, - gettext (strings[j].description)); + printf ("%s - %s\n", strings[j].selection, + gettext (strings[j].description)); } return 0; diff --git a/gettext-tools/tests/gettext-8-prg.c b/gettext-tools/tests/gettext-8-prg.c index a5e151308..9510fca36 100644 --- a/gettext-tools/tests/gettext-8-prg.c +++ b/gettext-tools/tests/gettext-8-prg.c @@ -49,16 +49,16 @@ main () # ifdef RLIMIT_STACK if (getrlimit (RLIMIT_STACK, &limit) < 0) { - printf ("Skipping test: getrlimit does not work\n"); - return 77; + printf ("Skipping test: getrlimit does not work\n"); + return 77; } if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > n) limit.rlim_max = n; limit.rlim_cur = limit.rlim_max; if (setrlimit (RLIMIT_STACK, &limit) < 0) { - printf ("Skipping test: setrlimit does not work\n"); - return 77; + printf ("Skipping test: setrlimit does not work\n"); + return 77; } # endif } diff --git a/gettext-tools/tests/setlocale.c b/gettext-tools/tests/setlocale.c index 95ae0b2b2..7e4fdd846 100644 --- a/gettext-tools/tests/setlocale.c +++ b/gettext-tools/tests/setlocale.c @@ -106,58 +106,58 @@ setlocale (int category, SETLOCALE_CONST char *locale) strcpy (copy, locale); if (category == LC_ALL) - { - while ((facetp = facets) != NULL) - { - facets = facetp->next; - free (facetp->current_locale); - free (facetp); - } - if (current_locale != C_string) - free (current_locale); - current_locale = copy; - } + { + while ((facetp = facets) != NULL) + { + facets = facetp->next; + free (facetp->current_locale); + free (facetp); + } + if (current_locale != C_string) + free (current_locale); + current_locale = copy; + } else - { - for (facetp = facets; facetp != NULL; facetp = facetp->next) - if (category == facetp->category) - { - free (facetp->current_locale); - facetp->current_locale = copy; - break; - } - if (facetp == NULL) - { - facetp = (struct list *) malloc (sizeof (struct list)); - facetp->category = category; - facetp->current_locale = copy; - facetp->next = facets; - facets = facetp; - } - } + { + for (facetp = facets; facetp != NULL; facetp = facetp->next) + if (category == facetp->category) + { + free (facetp->current_locale); + facetp->current_locale = copy; + break; + } + if (facetp == NULL) + { + facetp = (struct list *) malloc (sizeof (struct list)); + facetp->category = category; + facetp->current_locale = copy; + facetp->next = facets; + facets = facetp; + } + } } retval = current_locale; for (facetp = facets; facetp != NULL; facetp = facetp->next) if (category == facetp->category) { - retval = facetp->current_locale; - break; + retval = facetp->current_locale; + break; } if (retval[0] == '\0') { retval = getenv ("LC_ALL"); if (retval == NULL || retval[0] == '\0') - { - retval = getenv (category_to_name (category)); - if (retval == NULL || retval[0] == '\0') - { - retval = getenv ("LANG"); - if (retval == NULL || retval[0] == '\0') - retval = "C"; - } - } + { + retval = getenv (category_to_name (category)); + if (retval == NULL || retval[0] == '\0') + { + retval = getenv ("LANG"); + if (retval == NULL || retval[0] == '\0') + retval = "C"; + } + } } return retval; } diff --git a/gettext-tools/tests/tstgettext.c b/gettext-tools/tests/tstgettext.c index 7b62d7926..2fe52ea90 100644 --- a/gettext-tools/tests/tstgettext.c +++ b/gettext-tools/tests/tstgettext.c @@ -102,10 +102,10 @@ main (int argc, char *argv[]) /* Parse command line options. */ while ((optchar = getopt_long (argc, argv, "+d:eEhnsV", long_options, NULL)) - != EOF) + != EOF) switch (optchar) { - case '\0': /* Long option. */ + case '\0': /* Long option. */ break; case 'd': domain = optarg; @@ -130,15 +130,15 @@ main (int argc, char *argv[]) break; case '=': { - /* Undocumented option --env sets an environment variable. */ - char *separator = strchr (optarg, '='); - if (separator != NULL) - { - *separator = '\0'; - xsetenv (optarg, separator + 1, 1); - environ_changed = true; - break; - } + /* Undocumented option --env sets an environment variable. */ + char *separator = strchr (optarg, '='); + if (separator != NULL) + { + *separator = '\0'; + xsetenv (optarg, separator + 1, 1); + environ_changed = true; + break; + } } /*FALLTHROUGH*/ default: @@ -161,7 +161,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "1995-1997, 2000-2006"); + "1995-1997, 2000-2006"); printf (_("Written by %s.\n"), proper_name ("Ulrich Drepper")); exit (EXIT_SUCCESS); } @@ -178,78 +178,78 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Get arguments. */ switch (argc - optind) - { - default: - error (EXIT_FAILURE, 0, _("too many arguments")); + { + default: + error (EXIT_FAILURE, 0, _("too many arguments")); - case 2: - domain = argv[optind++]; - /* FALLTHROUGH */ + case 2: + domain = argv[optind++]; + /* FALLTHROUGH */ - case 1: - break; + case 1: + break; - case 0: - error (EXIT_FAILURE, 0, _("missing arguments")); - } + case 0: + error (EXIT_FAILURE, 0, _("missing arguments")); + } msgid = argv[optind++]; /* Expand escape sequences if enabled. */ if (do_expand) - msgid = expand_escape (msgid); + msgid = expand_escape (msgid); /* If no domain name is given we don't translate. */ if (domain == NULL || domain[0] == '\0') - { - fputs (msgid, stdout); - } + { + fputs (msgid, stdout); + } else - { - /* Bind domain to appropriate directory. */ - if (domaindir != NULL && domaindir[0] != '\0') - bindtextdomain (domain, domaindir); - - /* Write out the result. */ - fputs (dgettext (domain, msgid), stdout); - } + { + /* Bind domain to appropriate directory. */ + if (domaindir != NULL && domaindir[0] != '\0') + bindtextdomain (domain, domaindir); + + /* Write out the result. */ + fputs (dgettext (domain, msgid), stdout); + } } else { if (optind < argc) - { - /* If no domain name is given we print the original string. - We mark this assigning NULL to domain. */ - if (domain == NULL || domain[0] == '\0') - domain = NULL; - else - /* Bind domain to appropriate directory. */ - if (domaindir != NULL && domaindir[0] != '\0') - bindtextdomain (domain, domaindir); - - /* We have to simulate `echo'. All arguments are strings. */ - do - { - msgid = argv[optind++]; - - /* Expand escape sequences if enabled. */ - if (do_expand) - msgid = expand_escape (msgid); - - /* Write out the result. */ - fputs (domain == NULL ? msgid : dgettext (domain, msgid), - stdout); - - /* We separate the arguments by a single ' '. */ - if (optind < argc) - fputc (' ', stdout); - } - while (optind < argc); - } + { + /* If no domain name is given we print the original string. + We mark this assigning NULL to domain. */ + if (domain == NULL || domain[0] == '\0') + domain = NULL; + else + /* Bind domain to appropriate directory. */ + if (domaindir != NULL && domaindir[0] != '\0') + bindtextdomain (domain, domaindir); + + /* We have to simulate `echo'. All arguments are strings. */ + do + { + msgid = argv[optind++]; + + /* Expand escape sequences if enabled. */ + if (do_expand) + msgid = expand_escape (msgid); + + /* Write out the result. */ + fputs (domain == NULL ? msgid : dgettext (domain, msgid), + stdout); + + /* We separate the arguments by a single ' '. */ + if (optind < argc) + fputc (' ', stdout); + } + while (optind < argc); + } /* If not otherwise told: add trailing newline. */ if (add_newline) - fputc ('\n', stdout); + fputc ('\n', stdout); } exit (EXIT_SUCCESS); @@ -262,7 +262,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { /* xgettext: no-wrap */ @@ -296,7 +296,7 @@ When used with the -s option the program behaves like the `echo' command.\n\ But it does not simply copy its arguments to stdout. Instead those messages\n\ found in the selected catalog are translated.\n\ Standard search directory: %s\n"), - getenv ("IN_HELP2MAN") == NULL ? LOCALEDIR : "@localedir@"); + getenv ("IN_HELP2MAN") == NULL ? LOCALEDIR : "@localedir@"); printf ("\n"); /* TRANSLATORS: The placeholder indicates the bug-reporting address for this package. Please add _another line_ saying @@ -319,14 +319,14 @@ expand_escape (const char *str) for (;;) { while (cp[0] != '\0' && cp[0] != '\\') - ++cp; + ++cp; if (cp[0] == '\0') - return str; + return str; /* Found a backslash. */ if (cp[1] == '\0') - return str; + return str; if (strchr ("abcfnrtv\\01234567", cp[1]) != NULL) - break; + break; ++cp; } @@ -339,69 +339,69 @@ expand_escape (const char *str) { /* Here cp[0] == '\\'. */ switch (*++cp) - { - case 'a': /* alert */ - *rp++ = '\a'; - ++cp; - break; - case 'b': /* backspace */ - *rp++ = '\b'; - ++cp; - break; - case 'c': /* suppress trailing newline */ - add_newline = false; - ++cp; - break; - case 'f': /* form feed */ - *rp++ = '\f'; - ++cp; - break; - case 'n': /* new line */ - *rp++ = '\n'; - ++cp; - break; - case 'r': /* carriage return */ - *rp++ = '\r'; - ++cp; - break; - case 't': /* horizontal tab */ - *rp++ = '\t'; - ++cp; - break; - case 'v': /* vertical tab */ - *rp++ = '\v'; - ++cp; - break; - case '\\': - *rp = '\\'; - ++cp; - break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - { - int ch = *cp++ - '0'; - - if (*cp >= '0' && *cp <= '7') - { - ch *= 8; - ch += *cp++ - '0'; - - if (*cp >= '0' && *cp <= '7') - { - ch *= 8; - ch += *cp++ - '0'; - } - } - *rp = ch; - } - break; - default: - *rp = '\\'; - break; - } + { + case 'a': /* alert */ + *rp++ = '\a'; + ++cp; + break; + case 'b': /* backspace */ + *rp++ = '\b'; + ++cp; + break; + case 'c': /* suppress trailing newline */ + add_newline = false; + ++cp; + break; + case 'f': /* form feed */ + *rp++ = '\f'; + ++cp; + break; + case 'n': /* new line */ + *rp++ = '\n'; + ++cp; + break; + case 'r': /* carriage return */ + *rp++ = '\r'; + ++cp; + break; + case 't': /* horizontal tab */ + *rp++ = '\t'; + ++cp; + break; + case 'v': /* vertical tab */ + *rp++ = '\v'; + ++cp; + break; + case '\\': + *rp = '\\'; + ++cp; + break; + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + { + int ch = *cp++ - '0'; + + if (*cp >= '0' && *cp <= '7') + { + ch *= 8; + ch += *cp++ - '0'; + + if (*cp >= '0' && *cp <= '7') + { + ch *= 8; + ch += *cp++ - '0'; + } + } + *rp = ch; + } + break; + default: + *rp = '\\'; + break; + } while (cp[0] != '\0' && cp[0] != '\\') - *rp++ = *cp++; + *rp++ = *cp++; } while (cp[0] != '\0'); diff --git a/gettext-tools/tests/tstngettext.c b/gettext-tools/tests/tstngettext.c index c34ea209d..8bf291398 100644 --- a/gettext-tools/tests/tstngettext.c +++ b/gettext-tools/tests/tstngettext.c @@ -90,10 +90,10 @@ main (int argc, char *argv[]) /* Parse command line options. */ while ((optchar = getopt_long (argc, argv, "+d:hV", long_options, NULL)) - != EOF) + != EOF) switch (optchar) { - case '\0': /* Long option. */ + case '\0': /* Long option. */ break; case 'd': domain = optarg; @@ -106,15 +106,15 @@ main (int argc, char *argv[]) break; case '=': { - /* Undocumented option --env sets an environment variable. */ - char *separator = strchr (optarg, '='); - if (separator != NULL) - { - *separator = '\0'; - xsetenv (optarg, separator + 1, 1); - environ_changed = true; - break; - } + /* Undocumented option --env sets an environment variable. */ + char *separator = strchr (optarg, '='); + if (separator != NULL) + { + *separator = '\0'; + xsetenv (optarg, separator + 1, 1); + environ_changed = true; + break; + } } /*FALLTHROUGH*/ default: @@ -137,7 +137,7 @@ License GPLv3+: GNU GPL version 3 or later \n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ "), - "1995-1997, 2000-2006"); + "1995-1997, 2000-2006"); printf (_("Written by %s.\n"), proper_name ("Ulrich Drepper")); exit (EXIT_SUCCESS); } @@ -170,25 +170,25 @@ There is NO WARRANTY, to the extent permitted by law.\n\ count = argv[optind++]; { - char *endp; - unsigned long tmp_val; - - errno = 0; - tmp_val = strtoul (count, &endp, 10); - if (errno == 0 && count[0] != '\0' && endp[0] == '\0') - n = tmp_val; - else - /* When COUNT is not valid, use plural. */ - n = 99; + char *endp; + unsigned long tmp_val; + + errno = 0; + tmp_val = strtoul (count, &endp, 10); + if (errno == 0 && count[0] != '\0' && endp[0] == '\0') + n = tmp_val; + else + /* When COUNT is not valid, use plural. */ + n = 99; } /* If no domain name is given we don't translate, and we use English - plural form handling. */ + plural form handling. */ if (domain == NULL) - fputs (n == 1 ? msgid : msgid_plural, stdout); + fputs (n == 1 ? msgid : msgid_plural, stdout); else - /* Write out the result. */ - fputs (dngettext (domain, msgid, msgid_plural, n), stdout); + /* Write out the result. */ + fputs (dngettext (domain, msgid, msgid_plural, n), stdout); } exit (EXIT_SUCCESS); @@ -201,7 +201,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { /* xgettext: no-wrap */ @@ -212,7 +212,7 @@ Usage: %s [OPTION] MSGID MSGID-PLURAL COUNT...\n\ -V, --version display version information and exit\n\ MSGID MSGID-PLURAL translate MSGID (singular) / MSGID-PLURAL (plural)\n\ COUNT choose singular/plural form based on this value\n"), - program_name); + program_name); /* xgettext: no-wrap */ printf (_("\ \n\ diff --git a/gettext-tools/woe32dll/export.h b/gettext-tools/woe32dll/export.h index 3e8a21fcf..640483214 100644 --- a/gettext-tools/woe32dll/export.h +++ b/gettext-tools/woe32dll/export.h @@ -95,12 +95,12 @@ /* Ensure that the variable x is exported from the library, and that a pseudo-variable IMP(x) is available. */ #define VARIABLE(x) \ - /* Export x without redefining x. This code was found by compiling a \ - snippet: \ - extern __declspec(dllexport) int x; int x = 42; */ \ - asm (".section .drectve\n"); \ - asm (".ascii \" -export:" #x ",data\"\n"); \ - asm (".data\n"); \ - /* Allocate a pseudo-variable IMP(x). */ \ - extern int x; \ + /* Export x without redefining x. This code was found by compiling a \ + snippet: \ + extern __declspec(dllexport) int x; int x = 42; */ \ + asm (".section .drectve\n"); \ + asm (".ascii \" -export:" #x ",data\"\n"); \ + asm (".data\n"); \ + /* Allocate a pseudo-variable IMP(x). */ \ + extern int x; \ void * IMP(x) = &x; diff --git a/gnulib-local/ChangeLog b/gnulib-local/ChangeLog index d4560a7f5..a070a3563 100644 --- a/gnulib-local/ChangeLog +++ b/gnulib-local/ChangeLog @@ -1,3 +1,9 @@ +2009-12-12 Bruno Haible + + * lib/*.h, lib/*.c: Untabify. + * m4/unionwait.m4: Untabify. + * tests/*.c: Untabify. + 2009-12-12 Bruno Haible * lib/fnmatch_loop.c.diff: Update after gnulib changed. diff --git a/gnulib-local/lib/addext.c b/gnulib-local/lib/addext.c index 9b893dbc5..fef2b9bfb 100644 --- a/gnulib-local/lib/addext.c +++ b/gnulib-local/lib/addext.c @@ -75,13 +75,13 @@ addext (char *filename, char const *ext, char e) /* Live within DOS's 8.3 limit. */ char *dot = strchr (s, '.'); if (dot) - { - slen -= dot + 1 - s; - s = dot + 1; - slen_max = 3; - } + { + slen -= dot + 1 - s; + s = dot + 1; + slen_max = 3; + } else - slen_max = 8; + slen_max = 8; extlen = 9; /* Don't use EXT. */ } @@ -90,7 +90,7 @@ addext (char *filename, char const *ext, char e) else { if (slen_max <= slen) - slen = slen_max - 1; + slen = slen_max - 1; s[slen] = e; s[slen + 1] = 0; } diff --git a/gnulib-local/lib/backupfile.c b/gnulib-local/lib/backupfile.c index 0a4e899f5..d8fb0b675 100644 --- a/gnulib-local/lib/backupfile.c +++ b/gnulib-local/lib/backupfile.c @@ -96,27 +96,27 @@ find_backup_file_name (const char *file, enum backup_type backup_type) backup_suffix_size_max = numbered_suffix_size_max; s = (char *) malloc (file_len + backup_suffix_size_max - + numbered_suffix_size_max); + + numbered_suffix_size_max); if (s) { strcpy (s, file); #if HAVE_DIR if (backup_type != simple) - { - int highest_backup; - size_t dir_len = basename (s) - s; - - strcpy (s + dir_len, "."); - highest_backup = max_backup_version (file + dir_len, s); - if (! (backup_type == numbered_existing && highest_backup == 0)) - { - char *numbered_suffix = s + (file_len + backup_suffix_size_max); - sprintf (numbered_suffix, ".~%d~", highest_backup + 1); - suffix = numbered_suffix; - } - strcpy (s, file); - } + { + int highest_backup; + size_t dir_len = basename (s) - s; + + strcpy (s + dir_len, "."); + highest_backup = max_backup_version (file + dir_len, s); + if (! (backup_type == numbered_existing && highest_backup == 0)) + { + char *numbered_suffix = s + (file_len + backup_suffix_size_max); + sprintf (numbered_suffix, ".~%d~", highest_backup + 1); + suffix = numbered_suffix; + } + strcpy (s, file); + } #endif /* HAVE_DIR */ addext (s, suffix, '~'); @@ -150,11 +150,11 @@ max_backup_version (const char *file, const char *dir) while ((dp = readdir (dirp)) != 0) { if (!REAL_DIR_ENTRY (dp) || strlen (dp->d_name) < file_name_length + 4) - continue; + continue; this_version = version_number (file, dp->d_name, file_name_length); if (this_version > highest_version) - highest_version = this_version; + highest_version = this_version; } if (closedir (dirp)) return 0; @@ -177,9 +177,9 @@ version_number (const char *base, const char *backup, size_t base_length) && backup[base_length + 1] == '~') { for (p = &backup[base_length + 2]; ISDIGIT (*p); ++p) - version = version * 10 + *p - '0'; + version = version * 10 + *p - '0'; if (p[0] != '~' || p[1]) - version = 0; + version = 0; } return version; } diff --git a/gnulib-local/lib/backupfile.h b/gnulib-local/lib/backupfile.h index a0c9cbf6c..e2c874387 100644 --- a/gnulib-local/lib/backupfile.h +++ b/gnulib-local/lib/backupfile.h @@ -39,16 +39,16 @@ enum backup_type numbered }; -# define VALID_BACKUP_TYPE(Type) \ - ((Type) == none \ - || (Type) == simple \ - || (Type) == numbered_existing \ +# define VALID_BACKUP_TYPE(Type) \ + ((Type) == none \ + || (Type) == simple \ + || (Type) == numbered_existing \ || (Type) == numbered) extern DLL_VARIABLE char const *simple_backup_suffix; extern char *find_backup_file_name (char const *file, - enum backup_type backup_type); + enum backup_type backup_type); extern enum backup_type get_version (char const *context, char const *arg); extern enum backup_type xget_version (char const *context, char const *arg); extern void addext (char *filename, char const *ext, char e); diff --git a/gnulib-local/lib/basename.c b/gnulib-local/lib/basename.c index d4256f855..76ed12149 100644 --- a/gnulib-local/lib/basename.c +++ b/gnulib-local/lib/basename.c @@ -66,9 +66,9 @@ basename (char const *name) for (p = name; *p; p++) { if (ISSLASH (*p)) - base = p + 1; + base = p + 1; else - all_slashes = 0; + all_slashes = 0; } /* If NAME is all slashes, arrange to return `/'. */ diff --git a/gnulib-local/lib/fd-ostream.oo.c b/gnulib-local/lib/fd-ostream.oo.c index 898cd9967..0c8978fdb 100644 --- a/gnulib-local/lib/fd-ostream.oo.c +++ b/gnulib-local/lib/fd-ostream.oo.c @@ -37,8 +37,8 @@ struct fd_ostream : struct ostream fields: int fd; char *filename; - char *buffer; /* A buffer, or NULL. */ - size_t avail; /* Number of bytes available in the buffer. */ + char *buffer; /* A buffer, or NULL. */ + size_t avail; /* Number of bytes available in the buffer. */ }; #define BUFSIZE 4096 @@ -51,74 +51,74 @@ fd_ostream::write_mem (fd_ostream_t stream, const void *data, size_t len) if (len > 0) { if (stream->buffer != NULL) - { - /* Buffered. */ - assert (stream->avail > 0); - #if 0 /* unoptimized */ - do - { - size_t n = (len <= stream->avail ? len : stream->avail); - if (n > 0) - { - memcpy (stream->buffer + BUFSIZE - stream->avail, data, n); - data = (char *) data + n; - stream->avail -= n; - len -= n; - } - if (stream->avail == 0) - { - if (full_write (stream->fd, stream->buffer, BUFSIZE) < BUFSIZE) - error (EXIT_FAILURE, errno, _("error writing to %s"), - stream->filename); - stream->avail = BUFSIZE; - } - } - while (len > 0); - #else /* optimized */ - if (len < stream->avail) - { - /* Move the data into the buffer. */ - memcpy (stream->buffer + BUFSIZE - stream->avail, data, len); - stream->avail -= len; - } - else - { - /* Split the data into: - - a first chunk, which is added to the buffer and output, - - a series of chunks of size BUFSIZE, which can be output - directly, without going through the buffer, and - - a last chunk, which is copied to the buffer. */ - size_t n = stream->avail; - memcpy (stream->buffer + BUFSIZE - stream->avail, data, n); - data = (char *) data + n; - len -= n; - if (full_write (stream->fd, stream->buffer, BUFSIZE) < BUFSIZE) - error (EXIT_FAILURE, errno, _("error writing to %s"), - stream->filename); - - while (len >= BUFSIZE) - { - if (full_write (stream->fd, data, BUFSIZE) < BUFSIZE) - error (EXIT_FAILURE, errno, _("error writing to %s"), - stream->filename); - data = (char *) data + BUFSIZE; - len -= BUFSIZE; - } - - if (len > 0) - memcpy (stream->buffer, data, len); - stream->avail = BUFSIZE - len; - } - #endif - assert (stream->avail > 0); - } + { + /* Buffered. */ + assert (stream->avail > 0); + #if 0 /* unoptimized */ + do + { + size_t n = (len <= stream->avail ? len : stream->avail); + if (n > 0) + { + memcpy (stream->buffer + BUFSIZE - stream->avail, data, n); + data = (char *) data + n; + stream->avail -= n; + len -= n; + } + if (stream->avail == 0) + { + if (full_write (stream->fd, stream->buffer, BUFSIZE) < BUFSIZE) + error (EXIT_FAILURE, errno, _("error writing to %s"), + stream->filename); + stream->avail = BUFSIZE; + } + } + while (len > 0); + #else /* optimized */ + if (len < stream->avail) + { + /* Move the data into the buffer. */ + memcpy (stream->buffer + BUFSIZE - stream->avail, data, len); + stream->avail -= len; + } + else + { + /* Split the data into: + - a first chunk, which is added to the buffer and output, + - a series of chunks of size BUFSIZE, which can be output + directly, without going through the buffer, and + - a last chunk, which is copied to the buffer. */ + size_t n = stream->avail; + memcpy (stream->buffer + BUFSIZE - stream->avail, data, n); + data = (char *) data + n; + len -= n; + if (full_write (stream->fd, stream->buffer, BUFSIZE) < BUFSIZE) + error (EXIT_FAILURE, errno, _("error writing to %s"), + stream->filename); + + while (len >= BUFSIZE) + { + if (full_write (stream->fd, data, BUFSIZE) < BUFSIZE) + error (EXIT_FAILURE, errno, _("error writing to %s"), + stream->filename); + data = (char *) data + BUFSIZE; + len -= BUFSIZE; + } + + if (len > 0) + memcpy (stream->buffer, data, len); + stream->avail = BUFSIZE - len; + } + #endif + assert (stream->avail > 0); + } else - { - /* Unbuffered. */ - if (full_write (stream->fd, data, len) < len) - error (EXIT_FAILURE, errno, _("error writing to %s"), - stream->filename); - } + { + /* Unbuffered. */ + if (full_write (stream->fd, data, len) < len) + error (EXIT_FAILURE, errno, _("error writing to %s"), + stream->filename); + } } } @@ -129,7 +129,7 @@ fd_ostream::flush (fd_ostream_t stream) { size_t filled = BUFSIZE - stream->avail; if (full_write (stream->fd, stream->buffer, filled) < filled) - error (EXIT_FAILURE, errno, _("error writing to %s"), stream->filename); + error (EXIT_FAILURE, errno, _("error writing to %s"), stream->filename); stream->avail = BUFSIZE; } } @@ -150,7 +150,7 @@ fd_ostream_create (int fd, const char *filename, bool buffered) fd_ostream_t stream = (struct fd_ostream_representation *) xmalloc (sizeof (struct fd_ostream_representation) - + (buffered ? BUFSIZE : 0)); + + (buffered ? BUFSIZE : 0)); stream->base.vtable = &fd_ostream_vtable; stream->fd = fd; @@ -158,7 +158,7 @@ fd_ostream_create (int fd, const char *filename, bool buffered) if (buffered) { stream->buffer = - (char *) (void *) stream + sizeof (struct fd_ostream_representation); + (char *) (void *) stream + sizeof (struct fd_ostream_representation); stream->avail = BUFSIZE; } else diff --git a/gnulib-local/lib/fd-ostream.oo.h b/gnulib-local/lib/fd-ostream.oo.h index e7bb77dd1..bd1f0b4bf 100644 --- a/gnulib-local/lib/fd-ostream.oo.h +++ b/gnulib-local/lib/fd-ostream.oo.h @@ -38,7 +38,7 @@ extern "C" { FILENAME is used only for error messages. Note that the resulting stream must be closed before FD can be closed. */ extern fd_ostream_t fd_ostream_create (int fd, const char *filename, - bool buffered); + bool buffered); #ifdef __cplusplus diff --git a/gnulib-local/lib/gettext.h b/gnulib-local/lib/gettext.h index 8a729ce2a..e591089ce 100644 --- a/gnulib-local/lib/gettext.h +++ b/gnulib-local/lib/gettext.h @@ -141,8 +141,8 @@ inline #endif static const char * pgettext_aux (const char *domain, - const char *msg_ctxt_id, const char *msgid, - int category) + const char *msg_ctxt_id, const char *msgid, + int category) { const char *translation = dcgettext (domain, msg_ctxt_id, category); if (translation == msg_ctxt_id) @@ -160,9 +160,9 @@ inline #endif static const char * npgettext_aux (const char *domain, - const char *msg_ctxt_id, const char *msgid, - const char *msgid_plural, unsigned long int n, - int category) + const char *msg_ctxt_id, const char *msgid, + const char *msgid_plural, unsigned long int n, + int category) { const char *translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); @@ -200,8 +200,8 @@ inline #endif static const char * dcpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - int category) + const char *msgctxt, const char *msgid, + int category) { size_t msgctxt_len = strlen (msgctxt) + 1; size_t msgid_len = strlen (msgid) + 1; @@ -223,10 +223,10 @@ dcpgettext_expr (const char *domain, translation = dcgettext (domain, msg_ctxt_id, category); #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS if (msg_ctxt_id != buf) - free (msg_ctxt_id); + free (msg_ctxt_id); #endif if (translation != msg_ctxt_id) - return translation; + return translation; } return msgid; } @@ -245,9 +245,9 @@ inline #endif static const char * dcnpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - const char *msgid_plural, unsigned long int n, - int category) + const char *msgctxt, const char *msgid, + const char *msgid_plural, unsigned long int n, + int category) { size_t msgctxt_len = strlen (msgctxt) + 1; size_t msgid_len = strlen (msgid) + 1; @@ -269,10 +269,10 @@ dcnpgettext_expr (const char *domain, translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS if (msg_ctxt_id != buf) - free (msg_ctxt_id); + free (msg_ctxt_id); #endif if (!(translation == msg_ctxt_id || translation == msgid_plural)) - return translation; + return translation; } return (n == 1 ? msgid : msgid_plural); } diff --git a/gnulib-local/lib/hash.c b/gnulib-local/lib/hash.c index 87eda8c05..1844724b4 100644 --- a/gnulib-local/lib/hash.c +++ b/gnulib-local/lib/hash.c @@ -138,15 +138,15 @@ compute_hashval (const void *key, size_t keylen) /* References: [Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986 - [Knuth] The Art of Computer Programming, part3 (6.4) */ + [Knuth] The Art of Computer Programming, part3 (6.4) */ /* Look up a given key in the hash table. Return the index of the entry, if present, or otherwise the index a free entry where it could be inserted. */ static size_t lookup (hash_table *htab, - const void *key, size_t keylen, - unsigned long int hval) + const void *key, size_t keylen, + unsigned long int hval) { unsigned long int hash; size_t idx; @@ -160,24 +160,24 @@ lookup (hash_table *htab, if (table[idx].used) { if (table[idx].used == hval && table[idx].keylen == keylen - && memcmp (table[idx].key, key, keylen) == 0) - return idx; + && memcmp (table[idx].key, key, keylen) == 0) + return idx; /* Second hash function as suggested in [Knuth]. */ hash = 1 + hval % (htab->size - 2); do - { - if (idx <= hash) - idx = htab->size + idx - hash; - else - idx -= hash; - - /* If entry is found use it. */ - if (table[idx].used == hval && table[idx].keylen == keylen - && memcmp (table[idx].key, key, keylen) == 0) - return idx; - } + { + if (idx <= hash) + idx = htab->size + idx - hash; + else + idx -= hash; + + /* If entry is found use it. */ + if (table[idx].used == hval && table[idx].keylen == keylen + && memcmp (table[idx].key, key, keylen) == 0) + return idx; + } while (table[idx].used); } return idx; @@ -188,7 +188,7 @@ lookup (hash_table *htab, If found, return 0 and set *RESULT to it. Otherwise return -1. */ int hash_find_entry (hash_table *htab, const void *key, size_t keylen, - void **result) + void **result) { hash_entry *table = htab->table; size_t idx = lookup (htab, key, keylen, compute_hashval (key, keylen)); @@ -206,8 +206,8 @@ hash_find_entry (hash_table *htab, const void *key, size_t keylen, IDX is known to be unused. */ static void insert_entry_2 (hash_table *htab, - const void *key, size_t keylen, - unsigned long int hval, size_t idx, void *data) + const void *key, size_t keylen, + unsigned long int hval, size_t idx, void *data) { hash_entry *table = htab->table; @@ -249,10 +249,10 @@ resize (hash_table *htab) for (idx = 1; idx <= old_size; ++idx) if (table[idx].used) insert_entry_2 (htab, table[idx].key, table[idx].keylen, - table[idx].used, - lookup (htab, table[idx].key, table[idx].keylen, - table[idx].used), - table[idx].data); + table[idx].used, + lookup (htab, table[idx].key, table[idx].keylen, + table[idx].used), + table[idx].data); free (table); } @@ -264,8 +264,8 @@ resize (hash_table *htab) given key. */ const void * hash_insert_entry (hash_table *htab, - const void *key, size_t keylen, - void *data) + const void *key, size_t keylen, + void *data) { unsigned long int hval = compute_hashval (key, keylen); hash_entry *table = htab->table; @@ -280,8 +280,8 @@ hash_insert_entry (hash_table *htab, void *keycopy = obstack_copy (&htab->mem_pool, key, keylen); insert_entry_2 (htab, keycopy, keylen, hval, idx, data); if (100 * htab->filled > 75 * htab->size) - /* Table is filled more than 75%. Resize the table. */ - resize (htab); + /* Table is filled more than 75%. Resize the table. */ + resize (htab); return keycopy; } } @@ -291,8 +291,8 @@ hash_insert_entry (hash_table *htab, Return 0. */ int hash_set_value (hash_table *htab, - const void *key, size_t keylen, - void *data) + const void *key, size_t keylen, + void *data) { unsigned long int hval = compute_hashval (key, keylen); hash_entry *table = htab->table; @@ -310,8 +310,8 @@ hash_set_value (hash_table *htab, void *keycopy = obstack_copy (&htab->mem_pool, key, keylen); insert_entry_2 (htab, keycopy, keylen, hval, idx, data); if (100 * htab->filled > 75 * htab->size) - /* Table is filled more than 75%. Resize the table. */ - resize (htab); + /* Table is filled more than 75%. Resize the table. */ + resize (htab); return 0; } } @@ -323,20 +323,20 @@ hash_set_value (hash_table *htab, Return 0 normally, -1 when the whole hash table has been traversed. */ int hash_iterate (hash_table *htab, void **ptr, const void **key, size_t *keylen, - void **data) + void **data) { hash_entry *curr; if (*ptr == NULL) { if (htab->first == NULL) - return -1; + return -1; curr = htab->first; } else { if (*ptr == htab->first) - return -1; + return -1; curr = (hash_entry *) *ptr; } curr = curr->next; @@ -356,21 +356,21 @@ hash_iterate (hash_table *htab, void **ptr, const void **key, size_t *keylen, Return 0 normally, -1 when the whole hash table has been traversed. */ int hash_iterate_modify (hash_table *htab, void **ptr, - const void **key, size_t *keylen, - void ***datap) + const void **key, size_t *keylen, + void ***datap) { hash_entry *curr; if (*ptr == NULL) { if (htab->first == NULL) - return -1; + return -1; curr = htab->first; } else { if (*ptr == htab->first) - return -1; + return -1; curr = (hash_entry *) *ptr; } curr = curr->next; diff --git a/gnulib-local/lib/hash.h b/gnulib-local/lib/hash.h index 9057f719a..299563d96 100644 --- a/gnulib-local/lib/hash.h +++ b/gnulib-local/lib/hash.h @@ -48,30 +48,30 @@ extern int hash_destroy (hash_table *htab); /* Look up the value of a key in the given table. If found, return 0 and set *RESULT to it. Otherwise return -1. */ extern int hash_find_entry (hash_table *htab, - const void *key, size_t keylen, - void **result); + const void *key, size_t keylen, + void **result); /* Try to insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table. Return non-NULL (more precisely, the address of the KEY inside the table's memory pool) if successful, or NULL if there is already an entry with the given key. */ extern const void * hash_insert_entry (hash_table *htab, - const void *key, size_t keylen, - void *data); + const void *key, size_t keylen, + void *data); /* Insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table. Return 0. */ extern int hash_set_value (hash_table *htab, - const void *key, size_t keylen, - void *data); + const void *key, size_t keylen, + void *data); /* Steps *PTR forward to the next used entry in the given hash table. *PTR should be initially set to NULL. Store information about the next entry in *KEY, *KEYLEN, *DATA. Return 0 normally, -1 when the whole hash table has been traversed. */ extern int hash_iterate (hash_table *htab, void **ptr, - const void **key, size_t *keylen, - void **data); + const void **key, size_t *keylen, + void **data); /* Steps *PTR forward to the next used entry in the given hash table. *PTR should be initially set to NULL. Store information about the next entry @@ -79,8 +79,8 @@ extern int hash_iterate (hash_table *htab, void **ptr, value; modifying **DATAP will modify the value of the entry. Return 0 normally, -1 when the whole hash table has been traversed. */ extern int hash_iterate_modify (hash_table *htab, void **ptr, - const void **key, size_t *keylen, - void ***datap); + const void **key, size_t *keylen, + void ***datap); /* Given SEED > 1, return the smallest odd prime number >= SEED. */ extern unsigned long int next_prime (unsigned long int seed); diff --git a/gnulib-local/lib/html-ostream.oo.c b/gnulib-local/lib/html-ostream.oo.c index 9cfe816bc..ffd39ff16 100644 --- a/gnulib-local/lib/html-ostream.oo.c +++ b/gnulib-local/lib/html-ostream.oo.c @@ -56,13 +56,13 @@ emit_pending_spans (html_ostream_t stream, bool shrink_stack) size_t i; for (i = stream->last_class_stack_size; i < stream->curr_class_stack_size; i++) - { - char *classname = (char *) gl_list_get_at (stream->class_stack, i); + { + char *classname = (char *) gl_list_get_at (stream->class_stack, i); - ostream_write_str (stream->destination, "destination, classname); - ostream_write_str (stream->destination, "\">"); - } + ostream_write_str (stream->destination, "destination, classname); + ostream_write_str (stream->destination, "\">"); + } stream->last_class_stack_size = stream->curr_class_stack_size; } else if (stream->curr_class_stack_size < stream->last_class_stack_size) @@ -70,18 +70,18 @@ emit_pending_spans (html_ostream_t stream, bool shrink_stack) size_t i = stream->last_class_stack_size; while (i > stream->curr_class_stack_size) - { - char *classname; - - --i; - classname = (char *) gl_list_get_at (stream->class_stack, i); - ostream_write_str (stream->destination, ""); - if (shrink_stack) - { - gl_list_remove_at (stream->class_stack, i); - free (classname); - } - } + { + char *classname; + + --i; + classname = (char *) gl_list_get_at (stream->class_stack, i); + ostream_write_str (stream->destination, ""); + if (shrink_stack) + { + gl_list_remove_at (stream->class_stack, i); + free (classname); + } + } stream->last_class_stack_size = stream->curr_class_stack_size; } } @@ -97,111 +97,111 @@ html_ostream::write_mem (html_ostream_t stream, const void *data, size_t len) inbufcount = stream->buflen; if (inbufcount > 0) - memcpy (inbuffer, stream->buf, inbufcount); + memcpy (inbuffer, stream->buf, inbufcount); for (;;) - { - /* At this point, inbuffer[0..inbufcount-1] is filled. */ - { - /* Combine the previous rest with a chunk of new input. */ - size_t n = - (len <= BUFFERSIZE - inbufcount ? len : BUFFERSIZE - inbufcount); - - if (n > 0) - { - memcpy (inbuffer + inbufcount, data, n); - data = (char *) data + n; - inbufcount += n; - len -= n; - } - } - { - /* Handle complete UTF-8 characters. */ - const char *inptr = inbuffer; - size_t insize = inbufcount; - - while (insize > 0) - { - unsigned char c0; - ucs4_t uc; - int nbytes; - - c0 = ((const unsigned char *) inptr)[0]; - if (insize < (c0 < 0xc0 ? 1 : c0 < 0xe0 ? 2 : c0 < 0xf0 ? 3 : - c0 < 0xf8 ? 4 : c0 < 0xfc ? 5 : 6)) - break; - - nbytes = u8_mbtouc (&uc, (const unsigned char *) inptr, insize); - - if (uc == '\n') - { - size_t prev_class_stack_size = stream->curr_class_stack_size; - stream->curr_class_stack_size = 0; - emit_pending_spans (stream, false); - ostream_write_str (stream->destination, "
"); - stream->curr_class_stack_size = prev_class_stack_size; - } - else - { - emit_pending_spans (stream, true); - - switch (uc) - { - case '"': - ostream_write_str (stream->destination, """); - break; - case '&': - ostream_write_str (stream->destination, "&"); - break; - case '<': - ostream_write_str (stream->destination, "<"); - break; - case '>': - /* Needed to avoid "]]>" in the output. */ - ostream_write_str (stream->destination, ">"); - break; - case ' ': - /* Needed because HTML viewers merge adjacent spaces - and drop spaces adjacent to
and similar. */ - ostream_write_str (stream->destination, " "); - break; - default: - if (uc >= 0x20 && uc < 0x7F) - { - /* Output ASCII characters as such. */ - char bytes[1]; - bytes[0] = uc; - ostream_write_mem (stream->destination, bytes, 1); - } - else - { - /* Output non-ASCII characters in #&nnn; - notation. */ - char bytes[32]; - sprintf (bytes, "&#%d;", (int) uc); - ostream_write_str (stream->destination, bytes); - } - break; - } - } - - inptr += nbytes; - insize -= nbytes; - } - /* Put back the unconverted part. */ - if (insize > BUFSIZE) - abort (); - if (len == 0) - { - if (insize > 0) - memcpy (stream->buf, inptr, insize); - stream->buflen = insize; - break; - } - if (insize > 0) - memmove (inbuffer, inptr, insize); - inbufcount = insize; - } - } + { + /* At this point, inbuffer[0..inbufcount-1] is filled. */ + { + /* Combine the previous rest with a chunk of new input. */ + size_t n = + (len <= BUFFERSIZE - inbufcount ? len : BUFFERSIZE - inbufcount); + + if (n > 0) + { + memcpy (inbuffer + inbufcount, data, n); + data = (char *) data + n; + inbufcount += n; + len -= n; + } + } + { + /* Handle complete UTF-8 characters. */ + const char *inptr = inbuffer; + size_t insize = inbufcount; + + while (insize > 0) + { + unsigned char c0; + ucs4_t uc; + int nbytes; + + c0 = ((const unsigned char *) inptr)[0]; + if (insize < (c0 < 0xc0 ? 1 : c0 < 0xe0 ? 2 : c0 < 0xf0 ? 3 : + c0 < 0xf8 ? 4 : c0 < 0xfc ? 5 : 6)) + break; + + nbytes = u8_mbtouc (&uc, (const unsigned char *) inptr, insize); + + if (uc == '\n') + { + size_t prev_class_stack_size = stream->curr_class_stack_size; + stream->curr_class_stack_size = 0; + emit_pending_spans (stream, false); + ostream_write_str (stream->destination, "
"); + stream->curr_class_stack_size = prev_class_stack_size; + } + else + { + emit_pending_spans (stream, true); + + switch (uc) + { + case '"': + ostream_write_str (stream->destination, """); + break; + case '&': + ostream_write_str (stream->destination, "&"); + break; + case '<': + ostream_write_str (stream->destination, "<"); + break; + case '>': + /* Needed to avoid "]]>" in the output. */ + ostream_write_str (stream->destination, ">"); + break; + case ' ': + /* Needed because HTML viewers merge adjacent spaces + and drop spaces adjacent to
and similar. */ + ostream_write_str (stream->destination, " "); + break; + default: + if (uc >= 0x20 && uc < 0x7F) + { + /* Output ASCII characters as such. */ + char bytes[1]; + bytes[0] = uc; + ostream_write_mem (stream->destination, bytes, 1); + } + else + { + /* Output non-ASCII characters in #&nnn; + notation. */ + char bytes[32]; + sprintf (bytes, "&#%d;", (int) uc); + ostream_write_str (stream->destination, bytes); + } + break; + } + } + + inptr += nbytes; + insize -= nbytes; + } + /* Put back the unconverted part. */ + if (insize > BUFSIZE) + abort (); + if (len == 0) + { + if (insize > 0) + memcpy (stream->buf, inptr, insize); + stream->buflen = insize; + break; + } + if (insize > 0) + memmove (inbuffer, inptr, insize); + inbufcount = insize; + } + } #undef BUFFERSIZE } } @@ -230,8 +230,8 @@ html_ostream::begin_span (html_ostream_t stream, const char *classname) { if (stream->last_class_stack_size > stream->curr_class_stack_size && strcmp ((char *) gl_list_get_at (stream->class_stack, - stream->curr_class_stack_size), - classname) != 0) + stream->curr_class_stack_size), + classname) != 0) emit_pending_spans (stream, true); /* Now either last_class_stack_size <= curr_class_stack_size @@ -242,7 +242,7 @@ html_ostream::begin_span (html_ostream_t stream, const char *classname) - in this case we only need to increment curr_class_stack_size. */ if (stream->last_class_stack_size <= stream->curr_class_stack_size) gl_list_add_at (stream->class_stack, stream->curr_class_stack_size, - xstrdup (classname)); + xstrdup (classname)); stream->curr_class_stack_size++; } @@ -250,9 +250,9 @@ static void html_ostream::end_span (html_ostream_t stream, const char *classname) { if (!(stream->curr_class_stack_size > 0 - && strcmp ((char *) gl_list_get_at (stream->class_stack, - stream->curr_class_stack_size - 1), - classname) == 0)) + && strcmp ((char *) gl_list_get_at (stream->class_stack, + stream->curr_class_stack_size - 1), + classname) == 0)) /* Improperly nested begin_span/end_span calls. */ abort (); stream->curr_class_stack_size--; diff --git a/gnulib-local/lib/html-styled-ostream.oo.c b/gnulib-local/lib/html-styled-ostream.oo.c index e29061d0f..2766ab09d 100644 --- a/gnulib-local/lib/html-styled-ostream.oo.c +++ b/gnulib-local/lib/html-styled-ostream.oo.c @@ -53,7 +53,7 @@ fields: static void html_styled_ostream::write_mem (html_styled_ostream_t stream, - const void *data, size_t len) + const void *data, size_t len) { html_ostream_write_mem (stream->html_destination, data, len); } @@ -76,14 +76,14 @@ html_styled_ostream::free (html_styled_ostream_t stream) static void html_styled_ostream::begin_use_class (html_styled_ostream_t stream, - const char *classname) + const char *classname) { html_ostream_begin_span (stream->html_destination, classname); } static void html_styled_ostream::end_use_class (html_styled_ostream_t stream, - const char *classname) + const char *classname) { html_ostream_end_span (stream->html_destination, classname); } @@ -112,44 +112,44 @@ html_styled_ostream_create (ostream_t destination, const char *css_filename) - special characters like < > & " are escaped in the \n"); + "\n"); } ostream_write_str (stream->destination, "\n"); ostream_write_str (stream->destination, "\n"); diff --git a/gnulib-local/lib/html-styled-ostream.oo.h b/gnulib-local/lib/html-styled-ostream.oo.h index c20083991..c28e0b92b 100644 --- a/gnulib-local/lib/html-styled-ostream.oo.h +++ b/gnulib-local/lib/html-styled-ostream.oo.h @@ -38,7 +38,7 @@ extern "C" { closed. */ extern html_styled_ostream_t html_styled_ostream_create (ostream_t destination, - const char *css_filename); + const char *css_filename); #ifdef __cplusplus diff --git a/gnulib-local/lib/iconv-ostream.oo.c b/gnulib-local/lib/iconv-ostream.oo.c index cf434b71b..653668563 100644 --- a/gnulib-local/lib/iconv-ostream.oo.c +++ b/gnulib-local/lib/iconv-ostream.oo.c @@ -69,70 +69,70 @@ iconv_ostream::write_mem (iconv_ostream_t stream, const void *data, size_t len) inbufcount = stream->buflen; if (inbufcount > 0) - memcpy (inbuffer, stream->buf, inbufcount); + memcpy (inbuffer, stream->buf, inbufcount); for (;;) - { - /* At this point, inbuffer[0..inbufcount-1] is filled. */ - { - /* Combine the previous rest with a chunk of new input. */ - size_t n = - (len <= BUFFERSIZE - inbufcount ? len : BUFFERSIZE - inbufcount); - - if (n > 0) - { - memcpy (inbuffer + inbufcount, data, n); - data = (char *) data + n; - inbufcount += n; - len -= n; - } - } - { - /* Attempt to convert the combined input. */ - char outbuffer[8*BUFFERSIZE]; - - const char *inptr = inbuffer; - size_t insize = inbufcount; - char *outptr = outbuffer; - size_t outsize = sizeof (outbuffer); - - size_t res = iconv (stream->cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - #if !defined _LIBICONV_VERSION && !defined __GLIBC__ - /* Irix iconv() inserts a NUL byte if it cannot convert. - NetBSD iconv() inserts a question mark if it cannot convert. - Only GNU libiconv and GNU libc are known to prefer to fail rather - than doing a lossy conversion. */ - if (res > 0) - { - errno = EILSEQ; - res = -1; - } - #endif - if (res == (size_t)(-1) && errno != EINVAL) - error (EXIT_FAILURE, 0, _("%s: cannot convert from %s to %s"), - "iconv_ostream", - stream->from_encoding, stream->to_encoding); - /* Output the converted part. */ - if (sizeof (outbuffer) - outsize > 0) - ostream_write_mem (stream->destination, - outbuffer, sizeof (outbuffer) - outsize); - /* Put back the unconverted part. */ - if (insize > BUFSIZE) - error (EXIT_FAILURE, 0, _("%s: shift sequence too long"), - "iconv_ostream"); - if (len == 0) - { - if (insize > 0) - memcpy (stream->buf, inptr, insize); - stream->buflen = insize; - break; - } - if (insize > 0) - memmove (inbuffer, inptr, insize); - inbufcount = insize; - } - } + { + /* At this point, inbuffer[0..inbufcount-1] is filled. */ + { + /* Combine the previous rest with a chunk of new input. */ + size_t n = + (len <= BUFFERSIZE - inbufcount ? len : BUFFERSIZE - inbufcount); + + if (n > 0) + { + memcpy (inbuffer + inbufcount, data, n); + data = (char *) data + n; + inbufcount += n; + len -= n; + } + } + { + /* Attempt to convert the combined input. */ + char outbuffer[8*BUFFERSIZE]; + + const char *inptr = inbuffer; + size_t insize = inbufcount; + char *outptr = outbuffer; + size_t outsize = sizeof (outbuffer); + + size_t res = iconv (stream->cd, + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); + #if !defined _LIBICONV_VERSION && !defined __GLIBC__ + /* Irix iconv() inserts a NUL byte if it cannot convert. + NetBSD iconv() inserts a question mark if it cannot convert. + Only GNU libiconv and GNU libc are known to prefer to fail rather + than doing a lossy conversion. */ + if (res > 0) + { + errno = EILSEQ; + res = -1; + } + #endif + if (res == (size_t)(-1) && errno != EINVAL) + error (EXIT_FAILURE, 0, _("%s: cannot convert from %s to %s"), + "iconv_ostream", + stream->from_encoding, stream->to_encoding); + /* Output the converted part. */ + if (sizeof (outbuffer) - outsize > 0) + ostream_write_mem (stream->destination, + outbuffer, sizeof (outbuffer) - outsize); + /* Put back the unconverted part. */ + if (insize > BUFSIZE) + error (EXIT_FAILURE, 0, _("%s: shift sequence too long"), + "iconv_ostream"); + if (len == 0) + { + if (insize > 0) + memcpy (stream->buf, inptr, insize); + stream->buflen = insize; + break; + } + if (insize > 0) + memmove (inbuffer, inptr, insize); + inbufcount = insize; + } + } #undef BUFFERSIZE } } @@ -160,11 +160,11 @@ iconv_ostream::free (iconv_ostream_t stream) size_t res = iconv (stream->cd, NULL, NULL, &outptr, &outsize); if (res == (size_t)(-1)) error (EXIT_FAILURE, 0, _("%s: cannot convert from %s to %s"), - "iconv_ostream", stream->from_encoding, stream->to_encoding); + "iconv_ostream", stream->from_encoding, stream->to_encoding); /* Output the converted part. */ if (sizeof (outbuffer) - outsize > 0) ostream_write_mem (stream->destination, - outbuffer, sizeof (outbuffer) - outsize); + outbuffer, sizeof (outbuffer) - outsize); } #endif @@ -178,7 +178,7 @@ iconv_ostream::free (iconv_ostream_t stream) iconv_ostream_t iconv_ostream_create (const char *from_encoding, const char *to_encoding, - ostream_t destination) + ostream_t destination) { iconv_ostream_t stream = XMALLOC (struct iconv_ostream_representation); @@ -198,15 +198,15 @@ iconv_ostream_create (const char *from_encoding, const char *to_encoding, if (stream->cd == (iconv_t)(-1)) { if (iconv_open ("UTF-8", from_encoding) == (iconv_t)(-1)) - error (EXIT_FAILURE, 0, _("%s does not support conversion from %s"), - "iconv", from_encoding); + error (EXIT_FAILURE, 0, _("%s does not support conversion from %s"), + "iconv", from_encoding); else if (iconv_open (to_encoding, "UTF-8") == (iconv_t)(-1)) - error (EXIT_FAILURE, 0, _("%s does not support conversion to %s"), - "iconv", to_encoding); + error (EXIT_FAILURE, 0, _("%s does not support conversion to %s"), + "iconv", to_encoding); else - error (EXIT_FAILURE, 0, - _("%s does not support conversion from %s to %s"), - "iconv", from_encoding, to_encoding); + error (EXIT_FAILURE, 0, + _("%s does not support conversion from %s to %s"), + "iconv", from_encoding, to_encoding); } stream->buflen = 0; diff --git a/gnulib-local/lib/iconv-ostream.oo.h b/gnulib-local/lib/iconv-ostream.oo.h index ad91a0a9d..de3c3b890 100644 --- a/gnulib-local/lib/iconv-ostream.oo.h +++ b/gnulib-local/lib/iconv-ostream.oo.h @@ -40,8 +40,8 @@ extern "C" { /* Create an output stream that converts from FROM_ENCODING to TO_ENCODING, writing the result to DESTINATION. */ extern iconv_ostream_t iconv_ostream_create (const char *from_encoding, - const char *to_encoding, - ostream_t destination); + const char *to_encoding, + ostream_t destination); #endif /* HAVE_ICONV */ diff --git a/gnulib-local/lib/memory-ostream.oo.c b/gnulib-local/lib/memory-ostream.oo.c index 1f96e290b..680cdeb48 100644 --- a/gnulib-local/lib/memory-ostream.oo.c +++ b/gnulib-local/lib/memory-ostream.oo.c @@ -33,31 +33,31 @@ struct memory_ostream : struct ostream { fields: - char *buffer; /* Buffer containing the accumulated output. */ - size_t buflen; /* Number of bytes stored so far. */ - size_t allocated; /* Allocated size of the buffer. */ + char *buffer; /* Buffer containing the accumulated output. */ + size_t buflen; /* Number of bytes stored so far. */ + size_t allocated; /* Allocated size of the buffer. */ }; /* Implementation of ostream_t methods. */ static void memory_ostream::write_mem (memory_ostream_t stream, - const void *data, size_t len) + const void *data, size_t len) { if (len > 0) { if (len > stream->allocated - stream->buflen) - { - size_t new_allocated = - xmax (xsum (stream->buflen, len), - xsum (stream->allocated, stream->allocated)); - if (size_overflow_p (new_allocated)) - error (EXIT_FAILURE, 0, - _("%s: too much output, buffer size overflow"), - "memory_ostream"); - stream->buffer = (char *) xrealloc (stream->buffer, new_allocated); - stream->allocated = new_allocated; - } + { + size_t new_allocated = + xmax (xsum (stream->buflen, len), + xsum (stream->allocated, stream->allocated)); + if (size_overflow_p (new_allocated)) + error (EXIT_FAILURE, 0, + _("%s: too much output, buffer size overflow"), + "memory_ostream"); + stream->buffer = (char *) xrealloc (stream->buffer, new_allocated); + stream->allocated = new_allocated; + } memcpy (stream->buffer + stream->buflen, data, len); stream->buflen += len; } @@ -79,7 +79,7 @@ memory_ostream::free (memory_ostream_t stream) void memory_ostream::contents (memory_ostream_t stream, - const void **bufp, size_t *buflenp) + const void **bufp, size_t *buflenp) { *bufp = stream->buffer; *buflenp = stream->buflen; diff --git a/gnulib-local/lib/term-ostream.oo.c b/gnulib-local/lib/term-ostream.oo.c index 3e2c950ce..6556e15e2 100644 --- a/gnulib-local/lib/term-ostream.oo.c +++ b/gnulib-local/lib/term-ostream.oo.c @@ -79,57 +79,57 @@ rgb_to_hsv (rgb_t c, hsv_t *result) if (r > g) { if (b > r) - { - /* b > r > g, so max = b, min = g */ - result->hue = 4.0f + (float) (r - g) / (float) (b - g); - result->saturation = 1.0f - (float) g / (float) b; - result->brightness = (float) b / 255.0f; - } + { + /* b > r > g, so max = b, min = g */ + result->hue = 4.0f + (float) (r - g) / (float) (b - g); + result->saturation = 1.0f - (float) g / (float) b; + result->brightness = (float) b / 255.0f; + } else if (b <= g) - { - /* r > g >= b, so max = r, min = b */ - result->hue = 0.0f + (float) (g - b) / (float) (r - b); - result->saturation = 1.0f - (float) b / (float) r; - result->brightness = (float) r / 255.0f; - } + { + /* r > g >= b, so max = r, min = b */ + result->hue = 0.0f + (float) (g - b) / (float) (r - b); + result->saturation = 1.0f - (float) b / (float) r; + result->brightness = (float) r / 255.0f; + } else - { - /* r >= b > g, so max = r, min = g */ - result->hue = 6.0f - (float) (b - g) / (float) (r - g); - result->saturation = 1.0f - (float) g / (float) r; - result->brightness = (float) r / 255.0f; - } + { + /* r >= b > g, so max = r, min = g */ + result->hue = 6.0f - (float) (b - g) / (float) (r - g); + result->saturation = 1.0f - (float) g / (float) r; + result->brightness = (float) r / 255.0f; + } } else { if (b > g) - { - /* b > g >= r, so max = b, min = r */ - result->hue = 4.0f - (float) (g - r) / (float) (b - r); - result->saturation = 1.0f - (float) r / (float) b; - result->brightness = (float) b / 255.0f; - } + { + /* b > g >= r, so max = b, min = r */ + result->hue = 4.0f - (float) (g - r) / (float) (b - r); + result->saturation = 1.0f - (float) r / (float) b; + result->brightness = (float) b / 255.0f; + } else if (b < r) - { - /* g >= r > b, so max = g, min = b */ - result->hue = 2.0f - (float) (r - b) / (float) (g - b); - result->saturation = 1.0f - (float) b / (float) g; - result->brightness = (float) g / 255.0f; - } + { + /* g >= r > b, so max = g, min = b */ + result->hue = 2.0f - (float) (r - b) / (float) (g - b); + result->saturation = 1.0f - (float) b / (float) g; + result->brightness = (float) g / 255.0f; + } else if (g > r) - { - /* g >= b >= r, g > r, so max = g, min = r */ - result->hue = 2.0f + (float) (b - r) / (float) (g - r); - result->saturation = 1.0f - (float) r / (float) g; - result->brightness = (float) g / 255.0f; - } + { + /* g >= b >= r, g > r, so max = g, min = r */ + result->hue = 2.0f + (float) (b - r) / (float) (g - r); + result->saturation = 1.0f - (float) r / (float) g; + result->brightness = (float) g / 255.0f; + } else - { - /* r = g = b. A grey color. */ - result->hue = 0; /* arbitrary */ - result->saturation = 0; - result->brightness = (float) r / 255.0f; - } + { + /* r = g = b. A grey color. */ + result->hue = 0; /* arbitrary */ + result->saturation = 0; + result->brightness = (float) r / 255.0f; + } } } @@ -143,11 +143,11 @@ color_distance (const hsv_t *color1, const hsv_t *color2) float angle1 = color1->hue * 1.04719755f; /* normalize to [0,2π] */ float angle2 = color2->hue * 1.04719755f; /* normalize to [0,2π] */ float delta_x = color1->saturation * cosf (angle1) - - color2->saturation * cosf (angle2); + - color2->saturation * cosf (angle2); float delta_y = color1->saturation * sinf (angle1) - - color2->saturation * sinf (angle2); + - color2->saturation * sinf (angle2); float delta_v = color1->brightness - - color2->brightness; + - color2->brightness; return delta_x * delta_x + delta_y * delta_y + delta_v * delta_v; #else @@ -156,11 +156,11 @@ color_distance (const hsv_t *color1, const hsv_t *color2) float delta_hue = (color1->hue >= color2->hue ? (color1->hue - color2->hue >= 3.0f - ? 6.0f + color2->hue - color1->hue - : color1->hue - color2->hue) + ? 6.0f + color2->hue - color1->hue + : color1->hue - color2->hue) : (color2->hue - color1->hue >= 3.0f - ? 6.0f + color1->hue - color2->hue - : color2->hue - color1->hue)); + ? 6.0f + color1->hue - color2->hue + : color2->hue - color1->hue)); float min_saturation = (color1->saturation < color2->saturation ? color1->saturation @@ -169,8 +169,8 @@ color_distance (const hsv_t *color1, const hsv_t *color2) float delta_brightness = color1->brightness - color2->brightness; return delta_hue * delta_hue * min_saturation - + delta_saturation * delta_saturation * 0.2f - + delta_brightness * delta_brightness * 0.8f; + + delta_saturation * delta_saturation * 0.2f + + delta_brightness * delta_brightness * 0.8f; #endif } @@ -198,14 +198,14 @@ nearest_color (rgb_t given, const rgb_t *table, unsigned int table_size) /* Avoid converting a color to grey, or fading out a color too much. */ if (i_hsv.saturation > given_hsv.saturation * 0.5f) - { - float distance = color_distance (&given_hsv, &i_hsv); - if (distance < best_distance) - { - best_index = i; - best_distance = distance; - } - } + { + float distance = color_distance (&given_hsv, &i_hsv); + if (distance < best_distance) + { + best_index = i; + best_distance = distance; + } + } } #if 0 /* Debugging code */ @@ -239,12 +239,12 @@ color_luminance (int r, int g, int b) /* The color model used by the terminal. */ typedef enum { - cm_monochrome, /* No colors. */ - cm_common8, /* Usual terminal with at least 8 colors. */ - cm_xterm8, /* TERM=xterm, with 8 colors. */ - cm_xterm16, /* TERM=xterm-16color, with 16 colors. */ - cm_xterm88, /* TERM=xterm-88color, with 88 colors. */ - cm_xterm256 /* TERM=xterm-256color, with 256 colors. */ + cm_monochrome, /* No colors. */ + cm_common8, /* Usual terminal with at least 8 colors. */ + cm_xterm8, /* TERM=xterm, with 8 colors. */ + cm_xterm16, /* TERM=xterm-16color, with 16 colors. */ + cm_xterm88, /* TERM=xterm-88color, with 88 colors. */ + cm_xterm256 /* TERM=xterm-256color, with 256 colors. */ } colormodel_t; /* ----------------------- cm_monochrome color model ----------------------- */ @@ -295,9 +295,9 @@ rgb_to_color_common8 (int r, int g, int b) /* Greyscale approximation. */ float luminance = color_luminance (r, g, b); if (luminance < 0.500f) - return 0; + return 0; else - return 7; + return 7; } else /* Color approximation. */ @@ -353,9 +353,9 @@ rgb_to_color_xterm8 (int r, int g, int b) /* Greyscale approximation. */ float luminance = color_luminance (r, g, b); if (luminance < 0.500f) - return 0; + return 0; else - return 7; + return 7; } else /* Color approximation. */ @@ -401,13 +401,13 @@ rgb_to_color_xterm16 (int r, int g, int b) /* Greyscale approximation. */ float luminance = color_luminance (r, g, b); if (luminance < 0.151f) - return 0; + return 0; else if (luminance < 0.600f) - return 8; + return 8; else if (luminance < 0.949f) - return 7; + return 7; else - return 15; + return 15; } else /* Color approximation. */ @@ -527,31 +527,31 @@ rgb_to_color_xterm88 (int r, int g, int b) /* Greyscale approximation. */ float luminance = color_luminance (r, g, b); if (luminance < 0.090f) - return 0; + return 0; else if (luminance < 0.241f) - return 80; + return 80; else if (luminance < 0.331f) - return 8; + return 8; else if (luminance < 0.406f) - return 81; + return 81; else if (luminance < 0.498f) - return 82; + return 82; else if (luminance < 0.585f) - return 37; + return 37; else if (luminance < 0.680f) - return 84; + return 84; else if (luminance < 0.764f) - return 85; + return 85; else if (luminance < 0.810f) - return 58; + return 58; else if (luminance < 0.857f) - return 86; + return 86; else if (luminance < 0.902f) - return 7; + return 7; else if (luminance < 0.953f) - return 87; + return 87; else - return 15; + return 15; } else /* Color approximation. */ @@ -839,71 +839,71 @@ rgb_to_color_xterm256 (int r, int g, int b) /* Greyscale approximation. */ float luminance = color_luminance (r, g, b); if (luminance < 0.015f) - return 0; + return 0; else if (luminance < 0.051f) - return 232; + return 232; else if (luminance < 0.090f) - return 233; + return 233; else if (luminance < 0.129f) - return 234; + return 234; else if (luminance < 0.157f) - return 235; + return 235; else if (luminance < 0.177f) - return 59; + return 59; else if (luminance < 0.207f) - return 236; + return 236; else if (luminance < 0.247f) - return 237; + return 237; else if (luminance < 0.284f) - return 238; + return 238; else if (luminance < 0.304f) - return 8; + return 8; else if (luminance < 0.319f) - return 239; + return 239; else if (luminance < 0.339f) - return 102; + return 102; else if (luminance < 0.364f) - return 240; + return 240; else if (luminance < 0.404f) - return 241; + return 241; else if (luminance < 0.443f) - return 242; + return 242; else if (luminance < 0.480f) - return 243; + return 243; else if (luminance < 0.500f) - return 145; + return 145; else if (luminance < 0.521f) - return 244; + return 244; else if (luminance < 0.560f) - return 245; + return 245; else if (luminance < 0.600f) - return 246; + return 246; else if (luminance < 0.639f) - return 247; + return 247; else if (luminance < 0.663f) - return 248; + return 248; else if (luminance < 0.682f) - return 188; + return 188; else if (luminance < 0.717f) - return 249; + return 249; else if (luminance < 0.756f) - return 250; + return 250; else if (luminance < 0.796f) - return 251; + return 251; else if (luminance < 0.823f) - return 252; + return 252; else if (luminance < 0.843f) - return 231; + return 231; else if (luminance < 0.874f) - return 253; + return 253; else if (luminance < 0.896f) - return 254; + return 254; else if (luminance < 0.915f) - return 7; + return 7; else if (luminance < 0.966f) - return 255; + return 255; else - return 15; + return 15; } else /* Color approximation. */ @@ -946,20 +946,20 @@ fields: char *filename; /* Values from the terminal type's terminfo/termcap description. See terminfo(5) for details. */ - /* terminfo termcap */ - int max_colors; /* colors Co */ - int no_color_video; /* ncv NC */ - char *set_a_foreground; /* setaf AF */ - char *set_foreground; /* setf Sf */ - char *set_a_background; /* setab AB */ - char *set_background; /* setb Sb */ - char *orig_pair; /* op op */ - char *enter_bold_mode; /* bold md */ - char *enter_italics_mode; /* sitm ZH */ - char *exit_italics_mode; /* ritm ZR */ - char *enter_underline_mode; /* smul us */ - char *exit_underline_mode; /* rmul ue */ - char *exit_attribute_mode; /* sgr0 me */ + /* terminfo termcap */ + int max_colors; /* colors Co */ + int no_color_video; /* ncv NC */ + char *set_a_foreground; /* setaf AF */ + char *set_foreground; /* setf Sf */ + char *set_a_background; /* setab AB */ + char *set_background; /* setb Sb */ + char *orig_pair; /* op op */ + char *enter_bold_mode; /* bold md */ + char *enter_italics_mode; /* sitm ZH */ + char *exit_italics_mode; /* ritm ZR */ + char *enter_underline_mode; /* smul us */ + char *exit_underline_mode; /* rmul ue */ + char *exit_attribute_mode; /* sgr0 me */ /* Inferred values. */ bool supports_foreground; bool supports_background; @@ -968,13 +968,13 @@ fields: bool supports_posture; bool supports_underline; /* Variable state. */ - char *buffer; /* Buffer for the current line. */ - attributes_t *attrbuffer; /* Buffer for the simplified attributes; same - length as buffer. */ - size_t buflen; /* Number of bytes stored so far. */ - size_t allocated; /* Allocated size of the buffer. */ - attributes_t curr_attr; /* Current attributes. */ - attributes_t simp_attr; /* Simplified current attributes. */ + char *buffer; /* Buffer for the current line. */ + attributes_t *attrbuffer; /* Buffer for the simplified attributes; same + length as buffer. */ + size_t buflen; /* Number of bytes stored so far. */ + size_t allocated; /* Allocated size of the buffer. */ + attributes_t curr_attr; /* Current attributes. */ + attributes_t simp_attr; /* Simplified current attributes. */ }; /* Simplify attributes, according to the terminal's capabilities. */ @@ -985,13 +985,13 @@ simplify_attributes (term_ostream_t stream, attributes_t attr) && stream->no_color_video > 0) { /* When colors and attributes can not be represented simultaneously, - we give preference to the color. */ + we give preference to the color. */ if (stream->no_color_video & 2) - /* Colors conflict with underlining. */ - attr.underline = UNDERLINE_OFF; + /* Colors conflict with underlining. */ + attr.underline = UNDERLINE_OFF; if (stream->no_color_video & 32) - /* Colors conflict with bold weight. */ - attr.weight = WEIGHT_NORMAL; + /* Colors conflict with bold weight. */ + attr.weight = WEIGHT_NORMAL; } if (!stream->supports_foreground) attr.color = COLOR_DEFAULT; @@ -1040,13 +1040,13 @@ restore (void) if (out_fd >= 0) { if (restore_colors != NULL) - tputs (restore_colors, 1, out_char_unchecked); + tputs (restore_colors, 1, out_char_unchecked); if (restore_weight != NULL) - tputs (restore_weight, 1, out_char_unchecked); + tputs (restore_weight, 1, out_char_unchecked); if (restore_posture != NULL) - tputs (restore_posture, 1, out_char_unchecked); + tputs (restore_posture, 1, out_char_unchecked); if (restore_underline != NULL) - tputs (restore_underline, 1, out_char_unchecked); + tputs (restore_underline, 1, out_char_unchecked); } } @@ -1079,7 +1079,7 @@ init_stopping_signal_set () sigemptyset (&stopping_signal_set); for (i = 0; i < num_stopping_signals; i++) - sigaddset (&stopping_signal_set, stopping_signals[i]); + sigaddset (&stopping_signal_set, stopping_signals[i]); stopping_signal_set_initialized = true; } @@ -1106,10 +1106,10 @@ static inline bool equal_attributes (attributes_t attr1, attributes_t attr2) { return (attr1.color == attr2.color - && attr1.bgcolor == attr2.bgcolor - && attr1.weight == attr2.weight - && attr1.posture == attr2.posture - && attr1.underline == attr2.underline); + && attr1.bgcolor == attr2.bgcolor + && attr1.weight == attr2.weight + && attr1.posture == attr2.posture + && attr1.underline == attr2.underline); } /* Signal error after full_write failed. */ @@ -1137,7 +1137,7 @@ out_char (int c) /* Output escape sequences to switch from OLD_ATTR to NEW_ATTR. */ static void out_attr_change (term_ostream_t stream, - attributes_t old_attr, attributes_t new_attr) + attributes_t old_attr, attributes_t new_attr) { bool cleared_attributes; @@ -1193,20 +1193,20 @@ out_attr_change (term_ostream_t stream, if ((old_attr.weight != WEIGHT_NORMAL && new_attr.weight == WEIGHT_NORMAL) || (old_attr.posture != POSTURE_NORMAL - && new_attr.posture == POSTURE_NORMAL - /* implies stream->exit_italics_mode == NULL */) + && new_attr.posture == POSTURE_NORMAL + /* implies stream->exit_italics_mode == NULL */) || (old_attr.underline != UNDERLINE_OFF - && new_attr.underline == UNDERLINE_OFF - /* implies stream->exit_underline_mode == NULL */)) + && new_attr.underline == UNDERLINE_OFF + /* implies stream->exit_underline_mode == NULL */)) { tputs (stream->exit_attribute_mode, 1, out_char); /* We don't know exactly what effects exit_attribute_mode has, but - this is the minimum effect: */ + this is the minimum effect: */ old_attr.weight = WEIGHT_NORMAL; if (stream->exit_italics_mode == NULL) - old_attr.posture = POSTURE_NORMAL; + old_attr.posture = POSTURE_NORMAL; if (stream->exit_underline_mode == NULL) - old_attr.underline = UNDERLINE_OFF; + old_attr.underline = UNDERLINE_OFF; cleared_attributes = true; } @@ -1217,87 +1217,87 @@ out_attr_change (term_ostream_t stream, assert (stream->supports_foreground); assert (new_attr.color != COLOR_DEFAULT); switch (stream->colormodel) - { - case cm_common8: - assert (new_attr.color >= 0 && new_attr.color < 8); - if (stream->set_a_foreground != NULL) - tputs (tparm (stream->set_a_foreground, - color_bgr (new_attr.color)), - 1, out_char); - else - tputs (tparm (stream->set_foreground, new_attr.color), - 1, out_char); - break; - /* When we are dealing with an xterm, there is no need to go through - tputs() because we know there is no padding and sleeping. */ - case cm_xterm8: - assert (new_attr.color >= 0 && new_attr.color < 8); - { - char bytes[5]; - bytes[0] = 0x1B; bytes[1] = '['; - bytes[2] = '3'; bytes[3] = '0' + new_attr.color; - bytes[4] = 'm'; - if (full_write (out_fd, bytes, 5) < 5) - out_error (); - } - break; - case cm_xterm16: - assert (new_attr.color >= 0 && new_attr.color < 16); - { - char bytes[5]; - bytes[0] = 0x1B; bytes[1] = '['; - if (new_attr.color < 8) - { - bytes[2] = '3'; bytes[3] = '0' + new_attr.color; - } - else - { - bytes[2] = '9'; bytes[3] = '0' + (new_attr.color - 8); - } - bytes[4] = 'm'; - if (full_write (out_fd, bytes, 5) < 5) - out_error (); - } - break; - case cm_xterm88: - assert (new_attr.color >= 0 && new_attr.color < 88); - { - char bytes[10]; - char *p; - bytes[0] = 0x1B; bytes[1] = '['; - bytes[2] = '3'; bytes[3] = '8'; bytes[4] = ';'; - bytes[5] = '5'; bytes[6] = ';'; - p = bytes + 7; - if (new_attr.color >= 10) - *p++ = '0' + (new_attr.color / 10); - *p++ = '0' + (new_attr.color % 10); - *p++ = 'm'; - if (full_write (out_fd, bytes, p - bytes) < p - bytes) - out_error (); - } - break; - case cm_xterm256: - assert (new_attr.color >= 0 && new_attr.color < 256); - { - char bytes[11]; - char *p; - bytes[0] = 0x1B; bytes[1] = '['; - bytes[2] = '3'; bytes[3] = '8'; bytes[4] = ';'; - bytes[5] = '5'; bytes[6] = ';'; - p = bytes + 7; - if (new_attr.color >= 100) - *p++ = '0' + (new_attr.color / 100); - if (new_attr.color >= 10) - *p++ = '0' + ((new_attr.color % 100) / 10); - *p++ = '0' + (new_attr.color % 10); - *p++ = 'm'; - if (full_write (out_fd, bytes, p - bytes) < p - bytes) - out_error (); - } - break; - default: - abort (); - } + { + case cm_common8: + assert (new_attr.color >= 0 && new_attr.color < 8); + if (stream->set_a_foreground != NULL) + tputs (tparm (stream->set_a_foreground, + color_bgr (new_attr.color)), + 1, out_char); + else + tputs (tparm (stream->set_foreground, new_attr.color), + 1, out_char); + break; + /* When we are dealing with an xterm, there is no need to go through + tputs() because we know there is no padding and sleeping. */ + case cm_xterm8: + assert (new_attr.color >= 0 && new_attr.color < 8); + { + char bytes[5]; + bytes[0] = 0x1B; bytes[1] = '['; + bytes[2] = '3'; bytes[3] = '0' + new_attr.color; + bytes[4] = 'm'; + if (full_write (out_fd, bytes, 5) < 5) + out_error (); + } + break; + case cm_xterm16: + assert (new_attr.color >= 0 && new_attr.color < 16); + { + char bytes[5]; + bytes[0] = 0x1B; bytes[1] = '['; + if (new_attr.color < 8) + { + bytes[2] = '3'; bytes[3] = '0' + new_attr.color; + } + else + { + bytes[2] = '9'; bytes[3] = '0' + (new_attr.color - 8); + } + bytes[4] = 'm'; + if (full_write (out_fd, bytes, 5) < 5) + out_error (); + } + break; + case cm_xterm88: + assert (new_attr.color >= 0 && new_attr.color < 88); + { + char bytes[10]; + char *p; + bytes[0] = 0x1B; bytes[1] = '['; + bytes[2] = '3'; bytes[3] = '8'; bytes[4] = ';'; + bytes[5] = '5'; bytes[6] = ';'; + p = bytes + 7; + if (new_attr.color >= 10) + *p++ = '0' + (new_attr.color / 10); + *p++ = '0' + (new_attr.color % 10); + *p++ = 'm'; + if (full_write (out_fd, bytes, p - bytes) < p - bytes) + out_error (); + } + break; + case cm_xterm256: + assert (new_attr.color >= 0 && new_attr.color < 256); + { + char bytes[11]; + char *p; + bytes[0] = 0x1B; bytes[1] = '['; + bytes[2] = '3'; bytes[3] = '8'; bytes[4] = ';'; + bytes[5] = '5'; bytes[6] = ';'; + p = bytes + 7; + if (new_attr.color >= 100) + *p++ = '0' + (new_attr.color / 100); + if (new_attr.color >= 10) + *p++ = '0' + ((new_attr.color % 100) / 10); + *p++ = '0' + (new_attr.color % 10); + *p++ = 'm'; + if (full_write (out_fd, bytes, p - bytes) < p - bytes) + out_error (); + } + break; + default: + abort (); + } } if (new_attr.bgcolor != old_attr.bgcolor || (cleared_attributes && new_attr.bgcolor != COLOR_DEFAULT)) @@ -1305,90 +1305,90 @@ out_attr_change (term_ostream_t stream, assert (stream->supports_background); assert (new_attr.bgcolor != COLOR_DEFAULT); switch (stream->colormodel) - { - case cm_common8: - assert (new_attr.bgcolor >= 0 && new_attr.bgcolor < 8); - if (stream->set_a_background != NULL) - tputs (tparm (stream->set_a_background, - color_bgr (new_attr.bgcolor)), - 1, out_char); - else - tputs (tparm (stream->set_background, new_attr.bgcolor), - 1, out_char); - break; - /* When we are dealing with an xterm, there is no need to go through - tputs() because we know there is no padding and sleeping. */ - case cm_xterm8: - assert (new_attr.bgcolor >= 0 && new_attr.bgcolor < 8); - { - char bytes[5]; - bytes[0] = 0x1B; bytes[1] = '['; - bytes[2] = '4'; bytes[3] = '0' + new_attr.bgcolor; - bytes[4] = 'm'; - if (full_write (out_fd, bytes, 5) < 5) - out_error (); - } - break; - case cm_xterm16: - assert (new_attr.bgcolor >= 0 && new_attr.bgcolor < 16); - { - char bytes[6]; - bytes[0] = 0x1B; bytes[1] = '['; - if (new_attr.bgcolor < 8) - { - bytes[2] = '4'; bytes[3] = '0' + new_attr.bgcolor; - bytes[4] = 'm'; - if (full_write (out_fd, bytes, 5) < 5) - out_error (); - } - else - { - bytes[2] = '1'; bytes[3] = '0'; - bytes[4] = '0' + (new_attr.bgcolor - 8); bytes[5] = 'm'; - if (full_write (out_fd, bytes, 6) < 6) - out_error (); - } - } - break; - case cm_xterm88: - assert (new_attr.bgcolor >= 0 && new_attr.bgcolor < 88); - { - char bytes[10]; - char *p; - bytes[0] = 0x1B; bytes[1] = '['; - bytes[2] = '4'; bytes[3] = '8'; bytes[4] = ';'; - bytes[5] = '5'; bytes[6] = ';'; - p = bytes + 7; - if (new_attr.bgcolor >= 10) - *p++ = '0' + (new_attr.bgcolor / 10); - *p++ = '0' + (new_attr.bgcolor % 10); - *p++ = 'm'; - if (full_write (out_fd, bytes, p - bytes) < p - bytes) - out_error (); - } - break; - case cm_xterm256: - assert (new_attr.bgcolor >= 0 && new_attr.bgcolor < 256); - { - char bytes[11]; - char *p; - bytes[0] = 0x1B; bytes[1] = '['; - bytes[2] = '4'; bytes[3] = '8'; bytes[4] = ';'; - bytes[5] = '5'; bytes[6] = ';'; - p = bytes + 7; - if (new_attr.bgcolor >= 100) - *p++ = '0' + (new_attr.bgcolor / 100); - if (new_attr.bgcolor >= 10) - *p++ = '0' + ((new_attr.bgcolor % 100) / 10); - *p++ = '0' + (new_attr.bgcolor % 10); - *p++ = 'm'; - if (full_write (out_fd, bytes, p - bytes) < p - bytes) - out_error (); - } - break; - default: - abort (); - } + { + case cm_common8: + assert (new_attr.bgcolor >= 0 && new_attr.bgcolor < 8); + if (stream->set_a_background != NULL) + tputs (tparm (stream->set_a_background, + color_bgr (new_attr.bgcolor)), + 1, out_char); + else + tputs (tparm (stream->set_background, new_attr.bgcolor), + 1, out_char); + break; + /* When we are dealing with an xterm, there is no need to go through + tputs() because we know there is no padding and sleeping. */ + case cm_xterm8: + assert (new_attr.bgcolor >= 0 && new_attr.bgcolor < 8); + { + char bytes[5]; + bytes[0] = 0x1B; bytes[1] = '['; + bytes[2] = '4'; bytes[3] = '0' + new_attr.bgcolor; + bytes[4] = 'm'; + if (full_write (out_fd, bytes, 5) < 5) + out_error (); + } + break; + case cm_xterm16: + assert (new_attr.bgcolor >= 0 && new_attr.bgcolor < 16); + { + char bytes[6]; + bytes[0] = 0x1B; bytes[1] = '['; + if (new_attr.bgcolor < 8) + { + bytes[2] = '4'; bytes[3] = '0' + new_attr.bgcolor; + bytes[4] = 'm'; + if (full_write (out_fd, bytes, 5) < 5) + out_error (); + } + else + { + bytes[2] = '1'; bytes[3] = '0'; + bytes[4] = '0' + (new_attr.bgcolor - 8); bytes[5] = 'm'; + if (full_write (out_fd, bytes, 6) < 6) + out_error (); + } + } + break; + case cm_xterm88: + assert (new_attr.bgcolor >= 0 && new_attr.bgcolor < 88); + { + char bytes[10]; + char *p; + bytes[0] = 0x1B; bytes[1] = '['; + bytes[2] = '4'; bytes[3] = '8'; bytes[4] = ';'; + bytes[5] = '5'; bytes[6] = ';'; + p = bytes + 7; + if (new_attr.bgcolor >= 10) + *p++ = '0' + (new_attr.bgcolor / 10); + *p++ = '0' + (new_attr.bgcolor % 10); + *p++ = 'm'; + if (full_write (out_fd, bytes, p - bytes) < p - bytes) + out_error (); + } + break; + case cm_xterm256: + assert (new_attr.bgcolor >= 0 && new_attr.bgcolor < 256); + { + char bytes[11]; + char *p; + bytes[0] = 0x1B; bytes[1] = '['; + bytes[2] = '4'; bytes[3] = '8'; bytes[4] = ';'; + bytes[5] = '5'; bytes[6] = ';'; + p = bytes + 7; + if (new_attr.bgcolor >= 100) + *p++ = '0' + (new_attr.bgcolor / 100); + if (new_attr.bgcolor >= 10) + *p++ = '0' + ((new_attr.bgcolor % 100) / 10); + *p++ = '0' + (new_attr.bgcolor % 10); + *p++ = 'm'; + if (full_write (out_fd, bytes, p - bytes) < p - bytes) + out_error (); + } + break; + default: + abort (); + } } if (new_attr.weight != old_attr.weight @@ -1452,7 +1452,7 @@ output_buffer (term_ostream_t stream) if (n > 0) { if (full_write (stream->fd, cp, n) < n) - error (EXIT_FAILURE, errno, _("error writing to %s"), stream->filename); + error (EXIT_FAILURE, errno, _("error writing to %s"), stream->filename); cp += n; ap += n; len -= n; @@ -1460,49 +1460,49 @@ output_buffer (term_ostream_t stream) if (len > 0) { /* Block fatal signals, so that a SIGINT or similar doesn't interrupt - us without the possibility of restoring the terminal's state. */ + us without the possibility of restoring the terminal's state. */ block_fatal_signals (); /* Likewise for SIGTSTP etc. */ block_stopping_signals (); /* Enable the exit handler for restoring the terminal's state. */ restore_colors = - (stream->supports_foreground || stream->supports_background - ? stream->orig_pair - : NULL); + (stream->supports_foreground || stream->supports_background + ? stream->orig_pair + : NULL); restore_weight = - (stream->supports_weight ? stream->exit_attribute_mode : NULL); + (stream->supports_weight ? stream->exit_attribute_mode : NULL); restore_posture = - (stream->supports_posture - ? (stream->exit_italics_mode != NULL - ? stream->exit_italics_mode - : stream->exit_attribute_mode) - : NULL); + (stream->supports_posture + ? (stream->exit_italics_mode != NULL + ? stream->exit_italics_mode + : stream->exit_attribute_mode) + : NULL); restore_underline = - (stream->supports_underline - ? (stream->exit_underline_mode != NULL - ? stream->exit_underline_mode - : stream->exit_attribute_mode) - : NULL); + (stream->supports_underline + ? (stream->exit_underline_mode != NULL + ? stream->exit_underline_mode + : stream->exit_attribute_mode) + : NULL); out_fd = stream->fd; out_filename = stream->filename; while (len > 0) - { - /* Activate the attributes in *ap. */ - out_attr_change (stream, attr, *ap); - attr = *ap; - /* See how many characters we can output without further attribute - changes. */ - for (n = 1; n < len && equal_attributes (ap[n], attr); n++) - ; - if (full_write (stream->fd, cp, n) < n) - error (EXIT_FAILURE, errno, _("error writing to %s"), - stream->filename); - cp += n; - ap += n; - len -= n; - } + { + /* Activate the attributes in *ap. */ + out_attr_change (stream, attr, *ap); + attr = *ap; + /* See how many characters we can output without further attribute + changes. */ + for (n = 1; n < len && equal_attributes (ap[n], attr); n++) + ; + if (full_write (stream->fd, cp, n) < n) + error (EXIT_FAILURE, errno, _("error writing to %s"), + stream->filename); + cp += n; + ap += n; + len -= n; + } /* Switch back to the default attributes. */ out_attr_change (stream, attr, default_attr); @@ -1554,42 +1554,42 @@ term_ostream::write_mem (term_ostream_t stream, const void *data, size_t len) /* Copy n bytes into the buffer. */ if (n > stream->allocated - stream->buflen) - { - size_t new_allocated = - xmax (xsum (stream->buflen, n), - xsum (stream->allocated, stream->allocated)); - if (size_overflow_p (new_allocated)) - error (EXIT_FAILURE, 0, - _("%s: too much output, buffer size overflow"), - "term_ostream"); - stream->buffer = (char *) xrealloc (stream->buffer, new_allocated); - stream->attrbuffer = - (attributes_t *) - xrealloc (stream->attrbuffer, - new_allocated * sizeof (attributes_t)); - stream->allocated = new_allocated; - } + { + size_t new_allocated = + xmax (xsum (stream->buflen, n), + xsum (stream->allocated, stream->allocated)); + if (size_overflow_p (new_allocated)) + error (EXIT_FAILURE, 0, + _("%s: too much output, buffer size overflow"), + "term_ostream"); + stream->buffer = (char *) xrealloc (stream->buffer, new_allocated); + stream->attrbuffer = + (attributes_t *) + xrealloc (stream->attrbuffer, + new_allocated * sizeof (attributes_t)); + stream->allocated = new_allocated; + } memcpy (stream->buffer + stream->buflen, cp, n); { - attributes_t attr = stream->simp_attr; - attributes_t *ap = stream->attrbuffer + stream->buflen; - attributes_t *ap_end = ap + n; - for (; ap < ap_end; ap++) - *ap = attr; + attributes_t attr = stream->simp_attr; + attributes_t *ap = stream->attrbuffer + stream->buflen; + attributes_t *ap_end = ap + n; + for (; ap < ap_end; ap++) + *ap = attr; } stream->buflen += n; if (newline != NULL) - { - output_buffer (stream); - if (full_write (stream->fd, "\n", 1) < 1) - error (EXIT_FAILURE, errno, _("error writing to %s"), - stream->filename); - cp += n + 1; /* cp = newline + 1; */ - len -= n + 1; - } + { + output_buffer (stream); + if (full_write (stream->fd, "\n", 1) < 1) + error (EXIT_FAILURE, errno, _("error writing to %s"), + stream->filename); + cp += n + 1; /* cp = newline + 1; */ + len -= n + 1; + } else - break; + break; } } @@ -1741,31 +1741,31 @@ term_ostream_create (int fd, const char *filename) if (term != NULL && term[0] != '\0') { /* When the terminfo function are available, we prefer them over the - termcap functions because - 1. they don't risk a buffer overflow, - 2. on OSF/1, for TERM=xterm, the tiget* functions provide access - to the number of colors and the color escape sequences, whereas - the tget* functions don't provide them. */ + termcap functions because + 1. they don't risk a buffer overflow, + 2. on OSF/1, for TERM=xterm, the tiget* functions provide access + to the number of colors and the color escape sequences, whereas + the tget* functions don't provide them. */ #if HAVE_TERMINFO int err = 1; if (setupterm (term, fd, &err) || err == 1) - { - /* Retrieve particular values depending on the terminal type. */ - stream->max_colors = tigetnum ("colors"); - stream->no_color_video = tigetnum ("ncv"); - stream->set_a_foreground = xstrdup0 (tigetstr ("setaf")); - stream->set_foreground = xstrdup0 (tigetstr ("setf")); - stream->set_a_background = xstrdup0 (tigetstr ("setab")); - stream->set_background = xstrdup0 (tigetstr ("setb")); - stream->orig_pair = xstrdup0 (tigetstr ("op")); - stream->enter_bold_mode = xstrdup0 (tigetstr ("bold")); - stream->enter_italics_mode = xstrdup0 (tigetstr ("sitm")); - stream->exit_italics_mode = xstrdup0 (tigetstr ("ritm")); - stream->enter_underline_mode = xstrdup0 (tigetstr ("smul")); - stream->exit_underline_mode = xstrdup0 (tigetstr ("rmul")); - stream->exit_attribute_mode = xstrdup0 (tigetstr ("sgr0")); - } + { + /* Retrieve particular values depending on the terminal type. */ + stream->max_colors = tigetnum ("colors"); + stream->no_color_video = tigetnum ("ncv"); + stream->set_a_foreground = xstrdup0 (tigetstr ("setaf")); + stream->set_foreground = xstrdup0 (tigetstr ("setf")); + stream->set_a_background = xstrdup0 (tigetstr ("setab")); + stream->set_background = xstrdup0 (tigetstr ("setb")); + stream->orig_pair = xstrdup0 (tigetstr ("op")); + stream->enter_bold_mode = xstrdup0 (tigetstr ("bold")); + stream->enter_italics_mode = xstrdup0 (tigetstr ("sitm")); + stream->exit_italics_mode = xstrdup0 (tigetstr ("ritm")); + stream->enter_underline_mode = xstrdup0 (tigetstr ("smul")); + stream->exit_underline_mode = xstrdup0 (tigetstr ("rmul")); + stream->exit_attribute_mode = xstrdup0 (tigetstr ("sgr0")); + } #elif HAVE_TERMCAP struct { char buf[1024]; char canary[4]; } termcapbuf; int retval; @@ -1774,64 +1774,64 @@ term_ostream_create (int fd, const char *filename) memcpy (termcapbuf.canary, "CnRy", 4); retval = tgetent (termcapbuf.buf, term); if (memcmp (termcapbuf.canary, "CnRy", 4) != 0) - /* Buffer overflow! */ - abort (); + /* Buffer overflow! */ + abort (); if (retval > 0) - { - struct { char buf[1024]; char canary[4]; } termentrybuf; - char *termentryptr; - - /* Prepare for calling tgetstr, being defensive against buffer - overflow. ncurses' tgetstr() supports a second argument NULL, - but NetBSD's tgetstr() doesn't. */ - memcpy (termentrybuf.canary, "CnRz", 4); - #define TEBP ((termentryptr = termentrybuf.buf), &termentryptr) - - /* Retrieve particular values depending on the terminal type. */ - stream->max_colors = tgetnum ("Co"); - stream->no_color_video = tgetnum ("NC"); - stream->set_a_foreground = xstrdup0 (tgetstr ("AF", TEBP)); - stream->set_foreground = xstrdup0 (tgetstr ("Sf", TEBP)); - stream->set_a_background = xstrdup0 (tgetstr ("AB", TEBP)); - stream->set_background = xstrdup0 (tgetstr ("Sb", TEBP)); - stream->orig_pair = xstrdup0 (tgetstr ("op", TEBP)); - stream->enter_bold_mode = xstrdup0 (tgetstr ("md", TEBP)); - stream->enter_italics_mode = xstrdup0 (tgetstr ("ZH", TEBP)); - stream->exit_italics_mode = xstrdup0 (tgetstr ("ZR", TEBP)); - stream->enter_underline_mode = xstrdup0 (tgetstr ("us", TEBP)); - stream->exit_underline_mode = xstrdup0 (tgetstr ("ue", TEBP)); - stream->exit_attribute_mode = xstrdup0 (tgetstr ("me", TEBP)); + { + struct { char buf[1024]; char canary[4]; } termentrybuf; + char *termentryptr; + + /* Prepare for calling tgetstr, being defensive against buffer + overflow. ncurses' tgetstr() supports a second argument NULL, + but NetBSD's tgetstr() doesn't. */ + memcpy (termentrybuf.canary, "CnRz", 4); + #define TEBP ((termentryptr = termentrybuf.buf), &termentryptr) + + /* Retrieve particular values depending on the terminal type. */ + stream->max_colors = tgetnum ("Co"); + stream->no_color_video = tgetnum ("NC"); + stream->set_a_foreground = xstrdup0 (tgetstr ("AF", TEBP)); + stream->set_foreground = xstrdup0 (tgetstr ("Sf", TEBP)); + stream->set_a_background = xstrdup0 (tgetstr ("AB", TEBP)); + stream->set_background = xstrdup0 (tgetstr ("Sb", TEBP)); + stream->orig_pair = xstrdup0 (tgetstr ("op", TEBP)); + stream->enter_bold_mode = xstrdup0 (tgetstr ("md", TEBP)); + stream->enter_italics_mode = xstrdup0 (tgetstr ("ZH", TEBP)); + stream->exit_italics_mode = xstrdup0 (tgetstr ("ZR", TEBP)); + stream->enter_underline_mode = xstrdup0 (tgetstr ("us", TEBP)); + stream->exit_underline_mode = xstrdup0 (tgetstr ("ue", TEBP)); + stream->exit_attribute_mode = xstrdup0 (tgetstr ("me", TEBP)); # ifdef __BEOS__ - /* The BeOS termcap entry for "beterm" is broken: For "AF" and "AB" - it contains balues in terminfo syntax but the system's tparam() - function understands only the termcap syntax. */ - if (stream->set_a_foreground != NULL - && strcmp (stream->set_a_foreground, "\033[3%p1%dm") == 0) - { - free (stream->set_a_foreground); - stream->set_a_foreground = xstrdup ("\033[3%dm"); - } - if (stream->set_a_background != NULL - && strcmp (stream->set_a_background, "\033[4%p1%dm") == 0) - { - free (stream->set_a_background); - stream->set_a_background = xstrdup ("\033[4%dm"); - } + /* The BeOS termcap entry for "beterm" is broken: For "AF" and "AB" + it contains balues in terminfo syntax but the system's tparam() + function understands only the termcap syntax. */ + if (stream->set_a_foreground != NULL + && strcmp (stream->set_a_foreground, "\033[3%p1%dm") == 0) + { + free (stream->set_a_foreground); + stream->set_a_foreground = xstrdup ("\033[3%dm"); + } + if (stream->set_a_background != NULL + && strcmp (stream->set_a_background, "\033[4%p1%dm") == 0) + { + free (stream->set_a_background); + stream->set_a_background = xstrdup ("\033[4%dm"); + } # endif - /* The termcap entry for cygwin is broken: It has no "ncv" value, - but bold and underline are actually rendered through colors. */ - if (strcmp (term, "cygwin") == 0) - stream->no_color_video |= 2 | 32; - - /* Done with tgetstr. Detect possible buffer overflow. */ - #undef TEBP - if (memcmp (termentrybuf.canary, "CnRz", 4) != 0) - /* Buffer overflow! */ - abort (); - } + /* The termcap entry for cygwin is broken: It has no "ncv" value, + but bold and underline are actually rendered through colors. */ + if (strcmp (term, "cygwin") == 0) + stream->no_color_video |= 2 | 32; + + /* Done with tgetstr. Detect possible buffer overflow. */ + #undef TEBP + if (memcmp (termentrybuf.canary, "CnRz", 4) != 0) + /* Buffer overflow! */ + abort (); + } #else /* Fallback code for platforms with neither the terminfo nor the termcap functions, such as mingw. @@ -1849,17 +1849,17 @@ term_ostream_create (int fd, const char *filename) #endif /* AIX 4.3.2, IRIX 6.5, HP-UX 11, Solaris 7..10 all lack the - description of color capabilities of "xterm" and "xterms" - in their terminfo database. But it is important to have - color in xterm. So we provide the color capabilities here. */ + description of color capabilities of "xterm" and "xterms" + in their terminfo database. But it is important to have + color in xterm. So we provide the color capabilities here. */ if (stream->max_colors <= 1 - && (strcmp (term, "xterm") == 0 || strcmp (term, "xterms") == 0)) - { - stream->max_colors = 8; - stream->set_a_foreground = xstrdup ("\033[3%p1%dm"); - stream->set_a_background = xstrdup ("\033[4%p1%dm"); - stream->orig_pair = xstrdup ("\033[39;49m"); - } + && (strcmp (term, "xterm") == 0 || strcmp (term, "xterms") == 0)) + { + stream->max_colors = 8; + stream->set_a_foreground = xstrdup ("\033[3%p1%dm"); + stream->set_a_background = xstrdup ("\033[4%p1%dm"); + stream->orig_pair = xstrdup ("\033[39;49m"); + } } /* Infer the capabilities. */ @@ -1874,28 +1874,28 @@ term_ostream_create (int fd, const char *filename) stream->colormodel = (stream->supports_foreground || stream->supports_background ? (term != NULL - && (/* Recognize xterm-16color, xterm-88color, xterm-256color. */ - (strlen (term) >= 5 && memcmp (term, "xterm", 5) == 0) - || /* Recognize rxvt-16color. */ - (strlen (term) >= 4 && memcmp (term, "rxvt", 7) == 0) - || /* Recognize konsole-16color. */ - (strlen (term) >= 7 && memcmp (term, "konsole", 7) == 0)) - ? (stream->max_colors == 256 ? cm_xterm256 : - stream->max_colors == 88 ? cm_xterm88 : - stream->max_colors == 16 ? cm_xterm16 : - cm_xterm8) - : cm_common8) + && (/* Recognize xterm-16color, xterm-88color, xterm-256color. */ + (strlen (term) >= 5 && memcmp (term, "xterm", 5) == 0) + || /* Recognize rxvt-16color. */ + (strlen (term) >= 4 && memcmp (term, "rxvt", 7) == 0) + || /* Recognize konsole-16color. */ + (strlen (term) >= 7 && memcmp (term, "konsole", 7) == 0)) + ? (stream->max_colors == 256 ? cm_xterm256 : + stream->max_colors == 88 ? cm_xterm88 : + stream->max_colors == 16 ? cm_xterm16 : + cm_xterm8) + : cm_common8) : cm_monochrome); stream->supports_weight = (stream->enter_bold_mode != NULL && stream->exit_attribute_mode != NULL); stream->supports_posture = (stream->enter_italics_mode != NULL && (stream->exit_italics_mode != NULL - || stream->exit_attribute_mode != NULL)); + || stream->exit_attribute_mode != NULL)); stream->supports_underline = (stream->enter_underline_mode != NULL && (stream->exit_underline_mode != NULL - || stream->exit_attribute_mode != NULL)); + || stream->exit_attribute_mode != NULL)); /* Initialize the buffer. */ stream->allocated = 120; @@ -1916,8 +1916,8 @@ term_ostream_create (int fd, const char *filename) static bool registered = false; if (!registered) { - atexit (restore); - registered = true; + atexit (restore); + registered = true; } } diff --git a/gnulib-local/lib/term-ostream.oo.h b/gnulib-local/lib/term-ostream.oo.h index acd40e7f4..1ace97bea 100644 --- a/gnulib-local/lib/term-ostream.oo.h +++ b/gnulib-local/lib/term-ostream.oo.h @@ -65,7 +65,7 @@ methods: /* Convert an RGB value (red, green, blue in [0..255]) to a color, valid for this stream only. */ term_color_t rgb_to_color (term_ostream_t stream, - int red, int green, int blue); + int red, int green, int blue); /* Get/set the text color. */ term_color_t get_color (term_ostream_t stream); @@ -86,7 +86,7 @@ methods: /* Get/set the text underline decoration. */ term_underline_t get_underline (term_ostream_t stream); void set_underline (term_ostream_t stream, - term_underline_t underline); + term_underline_t underline); }; diff --git a/gnulib-local/lib/term-styled-ostream.oo.c b/gnulib-local/lib/term-styled-ostream.oo.c index b9cbee58c..a08bf6558 100644 --- a/gnulib-local/lib/term-styled-ostream.oo.c +++ b/gnulib-local/lib/term-styled-ostream.oo.c @@ -84,7 +84,7 @@ fields: static void term_styled_ostream::write_mem (term_styled_ostream_t stream, - const void *data, size_t len) + const void *data, size_t len) { term_ostream_set_color (stream->destination, stream->curr_attr->color); term_ostream_set_bgcolor (stream->destination, stream->curr_attr->bgcolor); @@ -116,7 +116,7 @@ term_styled_ostream::free (term_styled_ostream_t stream) while (hash_iterate (&stream->cache, &ptr, &key, &keylen, &data) == 0) { - free (data); + free (data); } } hash_destroy (&stream->cache); @@ -177,9 +177,9 @@ crx_style_destroy (CRXStyle *a_style) /* An extended version of cr_sel_eng_get_matched_style. */ static enum CRStatus crx_sel_eng_get_matched_style (CRSelEng * a_this, CRCascade * a_cascade, - xmlNode * a_node, - CRXStyle * a_parent_style, CRXStyle ** a_style, - gboolean a_set_props_to_initial_values) + xmlNode * a_node, + CRXStyle * a_parent_style, CRXStyle ** a_style, + gboolean a_set_props_to_initial_values) { enum CRStatus status; CRPropList *props = NULL; @@ -188,7 +188,7 @@ crx_sel_eng_get_matched_style (CRSelEng * a_this, CRCascade * a_cascade, return CR_BAD_PARAM_ERROR; status = cr_sel_eng_get_matched_properties_from_cascade (a_this, a_cascade, - a_node, &props); + a_node, &props); if (!(status == CR_OK)) return status; @@ -197,69 +197,69 @@ crx_sel_eng_get_matched_style (CRSelEng * a_this, CRCascade * a_cascade, CRXStyle *style; if (!*a_style) - { - *a_style = crx_style_new (a_set_props_to_initial_values); - if (!*a_style) - return CR_ERROR; - } + { + *a_style = crx_style_new (a_set_props_to_initial_values); + if (!*a_style) + return CR_ERROR; + } else - { - if (a_set_props_to_initial_values) - { - cr_style_set_props_to_initial_values ((*a_style)->base); - (*a_style)->text_decoration = TEXT_DECORATION_NONE; - } - else - { - cr_style_set_props_to_default_values ((*a_style)->base); - (*a_style)->text_decoration = TEXT_DECORATION_INHERIT; - } - } + { + if (a_set_props_to_initial_values) + { + cr_style_set_props_to_initial_values ((*a_style)->base); + (*a_style)->text_decoration = TEXT_DECORATION_NONE; + } + else + { + cr_style_set_props_to_default_values ((*a_style)->base); + (*a_style)->text_decoration = TEXT_DECORATION_INHERIT; + } + } style = *a_style; style->parent_style = a_parent_style; style->base->parent_style = - (a_parent_style != NULL ? a_parent_style->base : NULL); + (a_parent_style != NULL ? a_parent_style->base : NULL); { - CRPropList *cur; - - for (cur = props; cur != NULL; cur = cr_prop_list_get_next (cur)) - { - CRDeclaration *decl = NULL; - - cr_prop_list_get_decl (cur, &decl); - cr_style_set_style_from_decl (style->base, decl); - if (decl != NULL - && decl->property != NULL - && decl->property->stryng != NULL - && decl->property->stryng->str != NULL) - { - if (strcmp (decl->property->stryng->str, "text-decoration") == 0 - && decl->value != NULL - && decl->value->type == TERM_IDENT - && decl->value->content.str != NULL) - { - const char *value = - cr_string_peek_raw_str (decl->value->content.str); - - if (value != NULL) - { - if (strcmp (value, "none") == 0) - style->text_decoration = TEXT_DECORATION_NONE; - else if (strcmp (value, "underline") == 0) - style->text_decoration = TEXT_DECORATION_UNDERLINE; - else if (strcmp (value, "overline") == 0) - style->text_decoration = TEXT_DECORATION_OVERLINE; - else if (strcmp (value, "line-through") == 0) - style->text_decoration = TEXT_DECORATION_LINE_THROUGH; - else if (strcmp (value, "blink") == 0) - style->text_decoration = TEXT_DECORATION_BLINK; - else if (strcmp (value, "inherit") == 0) - style->text_decoration = TEXT_DECORATION_INHERIT; - } - } - } - } + CRPropList *cur; + + for (cur = props; cur != NULL; cur = cr_prop_list_get_next (cur)) + { + CRDeclaration *decl = NULL; + + cr_prop_list_get_decl (cur, &decl); + cr_style_set_style_from_decl (style->base, decl); + if (decl != NULL + && decl->property != NULL + && decl->property->stryng != NULL + && decl->property->stryng->str != NULL) + { + if (strcmp (decl->property->stryng->str, "text-decoration") == 0 + && decl->value != NULL + && decl->value->type == TERM_IDENT + && decl->value->content.str != NULL) + { + const char *value = + cr_string_peek_raw_str (decl->value->content.str); + + if (value != NULL) + { + if (strcmp (value, "none") == 0) + style->text_decoration = TEXT_DECORATION_NONE; + else if (strcmp (value, "underline") == 0) + style->text_decoration = TEXT_DECORATION_UNDERLINE; + else if (strcmp (value, "overline") == 0) + style->text_decoration = TEXT_DECORATION_OVERLINE; + else if (strcmp (value, "line-through") == 0) + style->text_decoration = TEXT_DECORATION_LINE_THROUGH; + else if (strcmp (value, "blink") == 0) + style->text_decoration = TEXT_DECORATION_BLINK; + else if (strcmp (value, "inherit") == 0) + style->text_decoration = TEXT_DECORATION_INHERIT; + } + } + } + } } cr_prop_list_destroy (props); @@ -280,33 +280,33 @@ crx_sel_eng_get_matched_style (CRSelEng * a_this, CRCascade * a_cascade, static term_color_t style_compute_color_value (CRStyle *style, enum CRRgbProp which, - term_ostream_t stream) + term_ostream_t stream) { for (;;) { if (style == NULL) - return COLOR_DEFAULT; + return COLOR_DEFAULT; if (cr_rgb_is_set_to_inherit (&style->rgb_props[which].sv)) - style = style->parent_style; + style = style->parent_style; else if (cr_rgb_is_set_to_transparent (&style->rgb_props[which].sv)) - /* A transparent color occurs as default background color, set by - cr_style_set_props_to_default_values. */ - return COLOR_DEFAULT; + /* A transparent color occurs as default background color, set by + cr_style_set_props_to_default_values. */ + return COLOR_DEFAULT; else - { - CRRgb rgb; - int r; - int g; - int b; - - cr_rgb_copy (&rgb, &style->rgb_props[which].sv); - if (cr_rgb_compute_from_percentage (&rgb) != CR_OK) - abort (); - r = rgb.red & 0xff; - g = rgb.green & 0xff; - b = rgb.blue & 0xff; - return term_ostream_rgb_to_color (stream, r, g, b); - } + { + CRRgb rgb; + int r; + int g; + int b; + + cr_rgb_copy (&rgb, &style->rgb_props[which].sv); + if (cr_rgb_compute_from_percentage (&rgb) != CR_OK) + abort (); + r = rgb.red & 0xff; + g = rgb.green & 0xff; + b = rgb.blue & 0xff; + return term_ostream_rgb_to_color (stream, r, g, b); + } } } @@ -317,51 +317,51 @@ style_compute_font_weight_value (const CRStyle *style) for (;;) { if (style == NULL) - value += 4; + value += 4; else - switch (style->font_weight) - { - case FONT_WEIGHT_INHERIT: - style = style->parent_style; - continue; - case FONT_WEIGHT_BOLDER: - value += 1; - style = style->parent_style; - continue; - case FONT_WEIGHT_LIGHTER: - value -= 1; - style = style->parent_style; - continue; - case FONT_WEIGHT_100: - value += 1; - break; - case FONT_WEIGHT_200: - value += 2; - break; - case FONT_WEIGHT_300: - value += 3; - break; - case FONT_WEIGHT_400: case FONT_WEIGHT_NORMAL: - value += 4; - break; - case FONT_WEIGHT_500: - value += 5; - break; - case FONT_WEIGHT_600: - value += 6; - break; - case FONT_WEIGHT_700: case FONT_WEIGHT_BOLD: - value += 7; - break; - case FONT_WEIGHT_800: - value += 8; - break; - case FONT_WEIGHT_900: - value += 9; - break; - default: - abort (); - } + switch (style->font_weight) + { + case FONT_WEIGHT_INHERIT: + style = style->parent_style; + continue; + case FONT_WEIGHT_BOLDER: + value += 1; + style = style->parent_style; + continue; + case FONT_WEIGHT_LIGHTER: + value -= 1; + style = style->parent_style; + continue; + case FONT_WEIGHT_100: + value += 1; + break; + case FONT_WEIGHT_200: + value += 2; + break; + case FONT_WEIGHT_300: + value += 3; + break; + case FONT_WEIGHT_400: case FONT_WEIGHT_NORMAL: + value += 4; + break; + case FONT_WEIGHT_500: + value += 5; + break; + case FONT_WEIGHT_600: + value += 6; + break; + case FONT_WEIGHT_700: case FONT_WEIGHT_BOLD: + value += 7; + break; + case FONT_WEIGHT_800: + value += 8; + break; + case FONT_WEIGHT_900: + value += 9; + break; + default: + abort (); + } /* Value >= 600 -> WEIGHT_BOLD. Value <= 500 -> WEIGHT_NORMAL. */ return (value >= 6 ? WEIGHT_BOLD : WEIGHT_NORMAL); } @@ -373,20 +373,20 @@ style_compute_font_posture_value (const CRStyle *style) for (;;) { if (style == NULL) - return POSTURE_DEFAULT; + return POSTURE_DEFAULT; switch (style->font_style) - { - case FONT_STYLE_INHERIT: - style = style->parent_style; - break; - case FONT_STYLE_NORMAL: - return POSTURE_NORMAL; - case FONT_STYLE_ITALIC: - case FONT_STYLE_OBLIQUE: - return POSTURE_ITALIC; - default: - abort (); - } + { + case FONT_STYLE_INHERIT: + style = style->parent_style; + break; + case FONT_STYLE_NORMAL: + return POSTURE_NORMAL; + case FONT_STYLE_ITALIC: + case FONT_STYLE_OBLIQUE: + return POSTURE_ITALIC; + default: + abort (); + } } } @@ -396,22 +396,22 @@ style_compute_text_underline_value (const CRXStyle *style) for (;;) { if (style == NULL) - return UNDERLINE_DEFAULT; + return UNDERLINE_DEFAULT; switch (style->text_decoration) - { - case TEXT_DECORATION_INHERIT: - style = style->parent_style; - break; - case TEXT_DECORATION_NONE: - case TEXT_DECORATION_OVERLINE: - case TEXT_DECORATION_LINE_THROUGH: - case TEXT_DECORATION_BLINK: - return UNDERLINE_OFF; - case TEXT_DECORATION_UNDERLINE: - return UNDERLINE_ON; - default: - abort (); - } + { + case TEXT_DECORATION_INHERIT: + style = style->parent_style; + break; + case TEXT_DECORATION_NONE: + case TEXT_DECORATION_OVERLINE: + case TEXT_DECORATION_LINE_THROUGH: + case TEXT_DECORATION_BLINK: + return UNDERLINE_OFF; + case TEXT_DECORATION_UNDERLINE: + return UNDERLINE_ON; + default: + abort (); + } } } @@ -439,10 +439,10 @@ match (term_styled_ostream_t stream) xmlNodePtr child; if (!(*p_start == ' ')) - abort (); + abort (); p_start++; for (p = p_start; p < p_end && *p != ' '; p++) - ; + ; /* Temporarily replace the ' ' by '\0'. */ *p = '\0'; @@ -452,8 +452,8 @@ match (term_styled_ostream_t stream) *p = ' '; if (xmlAddChild (curr, child) == NULL) - /* Error! Shouldn't happen. */ - abort (); + /* Error! Shouldn't happen. */ + abort (); curr = child; p_start = p; @@ -470,17 +470,17 @@ match (term_styled_ostream_t stream) curr_style = NULL; if (crx_sel_eng_get_matched_style (stream->css_engine, - stream->css_document, - curr, - parent_style, &curr_style, - FALSE) != CR_OK) - abort (); + stream->css_document, + curr, + parent_style, &curr_style, + FALSE) != CR_OK) + abort (); if (curr_style == NULL) - /* No declarations matched this node. Inherit all values. */ - curr_style = parent_style; + /* No declarations matched this node. Inherit all values. */ + curr_style = parent_style; else - /* curr_style is a new style, inheriting from parent_style. */ - ; + /* curr_style is a new style, inheriting from parent_style. */ + ; } curr_style_base = (curr_style != NULL ? curr_style->base : NULL); @@ -488,10 +488,10 @@ match (term_styled_ostream_t stream) attr = XMALLOC (attributes_t); attr->color = style_compute_color_value (curr_style_base, RGB_PROP_COLOR, - stream->destination); + stream->destination); attr->bgcolor = style_compute_color_value (curr_style_base, RGB_PROP_BACKGROUND_COLOR, - stream->destination); + stream->destination); attr->weight = style_compute_font_weight_value (curr_style_base); attr->posture = style_compute_font_posture_value (curr_style_base); attr->underline = style_compute_text_underline_value (curr_style); @@ -518,15 +518,15 @@ match_and_cache (term_styled_ostream_t stream) { attributes_t *attr = match (stream); if (hash_insert_entry (&stream->cache, - stream->curr_classes, stream->curr_classes_length, - attr) == NULL) + stream->curr_classes, stream->curr_classes_length, + attr) == NULL) abort (); stream->curr_attr = attr; } static void term_styled_ostream::begin_use_class (term_styled_ostream_t stream, - const char *classname) + const char *classname) { size_t classname_len; char *p; @@ -543,7 +543,7 @@ term_styled_ostream::begin_use_class (term_styled_ostream_t stream, { size_t new_allocated = stream->curr_classes_length + 1 + classname_len + 1; if (new_allocated < 2 * stream->curr_classes_allocated) - new_allocated = 2 * stream->curr_classes_allocated; + new_allocated = 2 * stream->curr_classes_allocated; stream->curr_classes = xrealloc (stream->curr_classes, new_allocated); stream->curr_classes_allocated = new_allocated; @@ -555,8 +555,8 @@ term_styled_ostream::begin_use_class (term_styled_ostream_t stream, /* Uodate stream->curr_attr. */ if (hash_find_entry (&stream->cache, - stream->curr_classes, stream->curr_classes_length, - &found) < 0) + stream->curr_classes, stream->curr_classes_length, + &found) < 0) match_and_cache (stream); else stream->curr_attr = (attributes_t *) found; @@ -564,7 +564,7 @@ term_styled_ostream::begin_use_class (term_styled_ostream_t stream, static void term_styled_ostream::end_use_class (term_styled_ostream_t stream, - const char *classname) + const char *classname) { char *p_end; char *p_start; @@ -582,15 +582,15 @@ term_styled_ostream::end_use_class (term_styled_ostream_t stream, ; p_start = p + 1; if (!(p_end - p_start == strlen (classname) - && memcmp (p_start, classname, p_end - p_start) == 0)) + && memcmp (p_start, classname, p_end - p_start) == 0)) /* The match ing call to begin_use_class used a different classname. */ abort (); stream->curr_classes_length = p - stream->curr_classes; /* Update stream->curr_attr. */ if (hash_find_entry (&stream->cache, - stream->curr_classes, stream->curr_classes_length, - &found) < 0) + stream->curr_classes, stream->curr_classes_length, + &found) < 0) abort (); stream->curr_attr = (attributes_t *) found; } @@ -599,7 +599,7 @@ term_styled_ostream::end_use_class (term_styled_ostream_t stream, term_styled_ostream_t term_styled_ostream_create (int fd, const char *filename, - const char *css_filename) + const char *css_filename) { term_styled_ostream_t stream = XMALLOC (struct term_styled_ostream_representation); @@ -609,8 +609,8 @@ term_styled_ostream_create (int fd, const char *filename, stream->destination = term_ostream_create (fd, filename); if (cr_om_parser_simply_parse_file ((const guchar *) css_filename, - CR_UTF_8, /* CR_AUTO is not supported */ - &css_file_contents) != CR_OK) + CR_UTF_8, /* CR_AUTO is not supported */ + &css_file_contents) != CR_OK) { term_ostream_free (stream->destination); free (stream); diff --git a/gnulib-local/lib/term-styled-ostream.oo.h b/gnulib-local/lib/term-styled-ostream.oo.h index 8048e8d59..b890e3dfe 100644 --- a/gnulib-local/lib/term-styled-ostream.oo.h +++ b/gnulib-local/lib/term-styled-ostream.oo.h @@ -39,7 +39,7 @@ extern "C" { Return NULL upon failure. */ extern term_styled_ostream_t term_styled_ostream_create (int fd, const char *filename, - const char *css_filename); + const char *css_filename); #ifdef __cplusplus diff --git a/gnulib-local/lib/tparm.c b/gnulib-local/lib/tparm.c index b9497f371..3bedd41fa 100644 --- a/gnulib-local/lib/tparm.c +++ b/gnulib-local/lib/tparm.c @@ -31,14 +31,14 @@ static const char SCCSid[] = "@(#) mytinfo tparm.c 3.2 92/02/01 public domain, B #endif #ifndef MAX_PUSHED -#define MAX_PUSHED 32 +#define MAX_PUSHED 32 #endif -#define ARG 1 -#define NUM 2 +#define ARG 1 +#define NUM 2 -#define INTEGER 1 -#define STRING 2 +#define INTEGER 1 +#define STRING 2 #define MAX_LINE 640 @@ -96,19 +96,19 @@ getarg (int argnum, int type, void *p) if (argcnt > argnum) { if (arg_list[argnum].type != type) - return 1; + return 1; else if (type == STRING) - *(char **)p = arg_list[argnum].string; + *(char **)p = arg_list[argnum].string; else - *(int *)p = arg_list[argnum].integer; + *(int *)p = arg_list[argnum].integer; } else { arg_list[argcnt].type = type; if (type == STRING) - *(char **)p = arg_list[argcnt++].string = (char *) va_arg (tparm_args, char *); + *(char **)p = arg_list[argcnt++].string = (char *) va_arg (tparm_args, char *); else - *(int *)p = arg_list[argcnt++].integer = (int) va_arg (tparm_args, int); + *(int *)p = arg_list[argcnt++].integer = (int) va_arg (tparm_args, int); } return 0; } @@ -146,28 +146,28 @@ cvtchar (const char *sp, char *c) { case '\\': switch (*++sp) - { - case '\'': - case '$': - case '\\': - case '%': - *c = *sp; - return 2; - case '\0': - *c = '\\'; - return 1; - case '0': - if (sp[1] == '0' && sp[2] == '0') - { - *c = '\0'; - return 4; - } - *c = '\200'; /* '\0' ???? */ - return 2; - default: - *c = *sp; - return 2; - } + { + case '\'': + case '$': + case '\\': + case '%': + *c = *sp; + return 2; + case '\0': + *c = '\\'; + return 1; + case '0': + if (sp[1] == '0' && sp[2] == '0') + { + *c = '\0'; + return 4; + } + *c = '\200'; /* '\0' ???? */ + return 2; + default: + *c = *sp; + return 2; + } default: *c = *sp; return 1; @@ -193,57 +193,57 @@ cvtchar (const char *sp, char *c) Terminfo % codes: - %% output a '%' - %[[:][-+# ][width][.precision]][doxXs] - output pop according to the printf format - %c output pop as a char - %'c' push character constant c. - %{n} push decimal constant n. - %p[1-9] push paramter [1-9] - %g[a-z] push variable [a-z] - %P[a-z] put pop in variable [a-z] - %l push the length of pop (a string) - %+ add pop to pop and push the result - %- subtract pop from pop and push the result - %* multiply pop and pop and push the result - %& bitwise and pop and pop and push the result - %| bitwise or pop and pop and push the result - %^ bitwise xor pop and pop and push the result - %~ push the bitwise not of pop - %= compare if pop and pop are equal and push the result - %> compare if pop is less than pop and push the result - %< compare if pop is greater than pop and push the result - %A logical and pop and pop and push the result - %O logical or pop and pop and push the result - %! push the logical not of pop - %? condition %t if_true [%e if_false] %; - if condtion evaulates as true then evaluate if_true, - else evaluate if_false. elseif's can be done: - %? cond %t true [%e cond2 %t true2] ... [%e condN %t trueN] [%e false] %; - %i add one to parameters 1 and 2. (ANSI) + %% output a '%' + %[[:][-+# ][width][.precision]][doxXs] + output pop according to the printf format + %c output pop as a char + %'c' push character constant c. + %{n} push decimal constant n. + %p[1-9] push paramter [1-9] + %g[a-z] push variable [a-z] + %P[a-z] put pop in variable [a-z] + %l push the length of pop (a string) + %+ add pop to pop and push the result + %- subtract pop from pop and push the result + %* multiply pop and pop and push the result + %& bitwise and pop and pop and push the result + %| bitwise or pop and pop and push the result + %^ bitwise xor pop and pop and push the result + %~ push the bitwise not of pop + %= compare if pop and pop are equal and push the result + %> compare if pop is less than pop and push the result + %< compare if pop is greater than pop and push the result + %A logical and pop and pop and push the result + %O logical or pop and pop and push the result + %! push the logical not of pop + %? condition %t if_true [%e if_false] %; + if condtion evaulates as true then evaluate if_true, + else evaluate if_false. elseif's can be done: + %? cond %t true [%e cond2 %t true2] ... [%e condN %t trueN] [%e false] %; + %i add one to parameters 1 and 2. (ANSI) Termcap Codes: - %% output a % - %. output parameter as a character - %d output parameter as a decimal number - %2 output parameter in printf format %02d - %3 output parameter in printf format %03d - %+x add the character x to parameter and output it as a character -(UW) %-x subtract parameter FROM the character x and output it as a char -(UW) %ax add the character x to parameter -(GNU) %a[+*-/=][cp]x - GNU arithmetic. -(UW) %sx subtract parameter FROM the character x - %>xy if parameter > character x then add character y to parameter - %B convert to BCD (parameter = (parameter/10)*16 + parameter%16) - %D Delta Data encode (parameter = parameter - 2*(paramter%16)) - %i increment the first two parameters by one - %n xor the first two parameters by 0140 -(GNU) %m xor the first two parameters by 0177 - %r swap the first two parameters -(GNU) %b backup to previous parameter -(GNU) %f skip this parameter + %% output a % + %. output parameter as a character + %d output parameter as a decimal number + %2 output parameter in printf format %02d + %3 output parameter in printf format %03d + %+x add the character x to parameter and output it as a character +(UW) %-x subtract parameter FROM the character x and output it as a char +(UW) %ax add the character x to parameter +(GNU) %a[+*-/=][cp]x + GNU arithmetic. +(UW) %sx subtract parameter FROM the character x + %>xy if parameter > character x then add character y to parameter + %B convert to BCD (parameter = (parameter/10)*16 + parameter%16) + %D Delta Data encode (parameter = parameter - 2*(paramter%16)) + %i increment the first two parameters by one + %n xor the first two parameters by 0140 +(GNU) %m xor the first two parameters by 0177 + %r swap the first two parameters +(GNU) %b backup to previous parameter +(GNU) %f skip this parameter Note the two definitions of %a, the GNU defintion is used if the characters after the 'a' are valid, otherwise the UW definition is used. @@ -281,616 +281,616 @@ tparm (const char *str, ...) while (*sp != '\0') { switch (*sp) - { - case '\\': - if (scan_for) - { - if (*++sp != '\0') - sp++; - break; - } - *dp++ = *sp++; - if (*sp != '\0') - *dp++ = *sp++; - break; - case '%': - sp++; - if (scan_for) - { - if (*sp == scan_for && if_depth == scan_depth) - { - if (scan_for == ';') - if_depth--; - scan_for = 0; - } - else if (*sp == '?') - if_depth++; - else if (*sp == ';') - { - if (if_depth == 0) - return OOPS; - else - if_depth--; - } - sp++; - break; - } - fmt = NULL; - switch (*sp) - { - case '%': - *dp++ = *sp++; - break; - case '+': - if (!termcap) - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i += j; - if (pushnum (i)) - return OOPS; - sp++; - break; - } - /* FALLTHROUGH */ - case 'C': - if (*sp == 'C') - { - int i; - if (getarg (termcap - 1, INTEGER, &i)) - return OOPS; - if (i >= 96) - { - i /= 96; - if (i == '$') - *dp++ = '\\'; - *dp++ = i; - } - } - fmt = "%c"; - /* FALLTHROUGH */ - case 'a': - if (!termcap) - return OOPS; - { - int i; - if (getarg (termcap - 1, INTEGER, &i)) - return OOPS; - if (*++sp == '\0') - return OOPS; - if ((sp[1] == 'p' || sp[1] == 'c') - && sp[2] != '\0' && fmt == NULL) - { - /* GNU arithmetic parameter, what they really need is - terminfo. */ - int val; - int lc; - if (sp[1] == 'p' - && getarg (termcap - 1 + sp[2] - '@', INTEGER, &val)) - return OOPS; - if (sp[1] == 'c') - { - char c; - lc = cvtchar (sp + 2, &c) + 2; - /* Mask out 8th bit so \200 can be used for \0 as per - GNU docs. */ - val = c & 0177; - } - else - lc = 2; - switch (sp[0]) - { - case '=': - break; - case '+': - val = i + val; - break; - case '-': - val = i - val; - break; - case '*': - val = i * val; - break; - case '/': - val = i / val; - break; - default: - /* Not really GNU's %a after all... */ - { - char c; - lc = cvtchar (sp, &c); - val = c + i; - } - break; - } - arg_list[termcap - 1].integer = val; - sp += lc; - break; - } - { - char c; - sp += cvtchar (sp, &c); - arg_list[termcap - 1].integer = c + i; - } - } - if (fmt == NULL) - break; - sp--; - /* FALLTHROUGH */ - case '-': - if (!termcap) - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i -= j; - if (pushnum (i)) - return OOPS; - sp++; - break; - } - fmt = "%c"; - /* FALLTHROUGH */ - case 's': - if (termcap && (fmt == NULL || *sp == '-')) - { - int i; - if (getarg (termcap - 1, INTEGER, &i)) - return OOPS; - if (*++sp == '\0') - return OOPS; - { - char c; - sp += cvtchar (sp, &c); - arg_list[termcap - 1].integer = c - i; - } - if (fmt == NULL) - break; - sp--; - } - if (!termcap) - return OOPS; - /* FALLTHROUGH */ - case '.': - if (termcap && fmt == NULL) - fmt = "%c"; - /* FALLTHROUGH */ - case 'd': - if (termcap && fmt == NULL) - fmt = "%d"; - /* FALLTHROUGH */ - case '2': - if (termcap && fmt == NULL) - fmt = "%02d"; - /* FALLTHROUGH */ - case '3': - if (termcap && fmt == NULL) - fmt = "%03d"; - /* FALLTHROUGH */ - case ':': case ' ': case '#': case 'u': - case 'x': case 'X': case 'o': case 'c': - case '0': case '1': case '4': case '5': - case '6': case '7': case '8': case '9': - if (fmt == NULL) - { - if (termcap) - return OOPS; - if (*sp == ':') - sp++; - fmt = fmt_buf; - *fmt++ = '%'; - while (*sp != 's' && *sp != 'x' && *sp != 'X' && *sp != 'd' - && *sp != 'o' && *sp != 'c' && *sp != 'u') - { - if (*sp == '\0') - return OOPS; - *fmt++ = *sp++; - } - *fmt++ = *sp; - *fmt = '\0'; - fmt = fmt_buf; - } - { - char conv_char = fmt[strlen (fmt) - 1]; - if (conv_char == 's') - { - char *s; - if (popstring (&s)) - return OOPS; - sprintf (sbuf, fmt, s); - } - else - { - int i; - if (termcap) - { - if (getarg (termcap++ - 1, INTEGER, &i)) - return OOPS; - } - else - if (popnum (&i)) - return OOPS; - if (i == 0 && conv_char == 'c') - strcpy (sbuf, "\000"); - else - sprintf (sbuf, fmt, i); - } - } - sp++; - fmt = sbuf; - while (*fmt != '\0') - { - if (*fmt == '$') - *dp++ = '\\'; - *dp++ = *fmt++; - } - break; - case 'r': - { - int i; - if (!termcap || getarg (1, INTEGER, &i)) - return OOPS; - arg_list[1].integer = arg_list[0].integer; - arg_list[0].integer = i; - } - sp++; - break; - case 'i': - { - int i; - if (getarg (1, INTEGER, &i) || arg_list[0].type != INTEGER) - return OOPS; - } - arg_list[1].integer++; - arg_list[0].integer++; - sp++; - break; - case 'n': - { - int i; - if (!termcap || getarg (1, INTEGER, &i)) - return OOPS; - } - arg_list[0].integer ^= 0140; - arg_list[1].integer ^= 0140; - sp++; - break; - case '>': - if (!termcap) - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i = (i > j); - if (pushnum (i)) - return OOPS; - sp++; - break; - } - { - int i; - if (getarg (termcap-1, INTEGER, &i)) - return OOPS; - { - char c; - sp += cvtchar (sp, &c); - if (i > c) - { - sp += cvtchar (sp, &c); - arg_list[termcap-1].integer += c; - } - else - sp += cvtchar (sp, &c); - } - } - sp++; - break; - case 'B': - { - int i; - if (!termcap || getarg (termcap-1, INTEGER, &i)) - return OOPS; - arg_list[termcap-1].integer = 16 * (i / 10) + i % 10; - } - sp++; - break; - case 'D': - { - int i; - if (!termcap || getarg (termcap-1, INTEGER, &i)) - return OOPS; - arg_list[termcap-1].integer = i - 2 * (i % 16); - } - sp++; - break; - case 'p': - if (termcap > 1) - return OOPS; - if (*++sp == '\0') - return OOPS; - { - int i = (*sp == '0' ? 9 : *sp - '1'); - if (i < 0 || i > 9) - return OOPS; - if (pusharg (i)) - return OOPS; - } - termcap = 0; - sp++; - break; - case 'P': - if (termcap || *++sp == '\0') - return OOPS; - { - int i = *sp++ - 'a'; - if (i < 0 || i > 25) - return OOPS; - if (pos-- == 0) - return OOPS; - switch (vars[i].type = S[pos].type) - { - case ARG: - vars[i].argnum = S[pos].argnum; - break; - case NUM: - vars[i].value = S[pos].value; - break; - } - } - break; - case 'g': - if (termcap || *++sp == '\0') - return OOPS; - { - int i = *sp++ - 'a'; - if (i < 0 || i > 25) - return OOPS; - switch (vars[i].type) - { - case ARG: - if (pusharg (vars[i].argnum)) - return OOPS; - break; - case NUM: - if (pushnum (vars[i].value)) - return OOPS; - break; - } - } - break; - case '\'': - if (termcap > 1) - return OOPS; - if (*++sp == '\0') - return OOPS; - { - char c; - sp += cvtchar (sp, &c); - if (pushnum (c) || *sp++ != '\'') - return OOPS; - } - termcap = 0; - break; - case '{': - if (termcap > 1) - return OOPS; - { - int i; - i = 0; - sp++; - while (c_isdigit (*sp)) - i = 10 * i + *sp++ - '0'; - if (*sp++ != '}' || pushnum (i)) - return OOPS; - } - termcap = 0; - break; - case 'l': - { - int i; - char *s; - if (termcap || popstring (&s)) - return OOPS; - i = strlen (s); - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case '*': - { - int i, j; - if (termcap || popnum (&j) || popnum (&i)) - return OOPS; - i *= j; - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case '/': - { - int i, j; - if (termcap || popnum (&j) || popnum (&i)) - return OOPS; - i /= j; - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case 'm': - if (termcap) - { - int i; - if (getarg (1, INTEGER, &i)) - return OOPS; - arg_list[0].integer ^= 0177; - arg_list[1].integer ^= 0177; - sp++; - break; - } - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i %= j; - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case '&': - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i &= j; - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case '|': - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i |= j; - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case '^': - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i ^= j; - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case '=': - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i = (i == j); - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case '<': - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i = (i < j); - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case 'A': - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i = (i && j); - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case 'O': - { - int i, j; - if (popnum (&j) || popnum (&i)) - return OOPS; - i = (i || j); - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case '!': - { - int i; - if (popnum (&i)) - return OOPS; - i = !i; - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case '~': - { - int i; - if (popnum (&i)) - return OOPS; - i = ~i; - if (pushnum (i)) - return OOPS; - } - sp++; - break; - case '?': - if (termcap > 1) - return OOPS; - termcap = 0; - if_depth++; - sp++; - break; - case 't': - { - int i; - if (popnum (&i) || if_depth == 0) - return OOPS; - if (!i) - { - scan_for = 'e'; - scan_depth = if_depth; - } - } - sp++; - break; - case 'e': - if (if_depth == 0) - return OOPS; - scan_for = ';'; - scan_depth = if_depth; - sp++; - break; - case ';': - if (if_depth-- == 0) - return OOPS; - sp++; - break; - case 'b': - if (--termcap < 1) - return OOPS; - sp++; - break; - case 'f': - if (!termcap++) - return OOPS; - sp++; - break; - } - break; - default: - if (scan_for) - sp++; - else - *dp++ = *sp++; - break; - } + { + case '\\': + if (scan_for) + { + if (*++sp != '\0') + sp++; + break; + } + *dp++ = *sp++; + if (*sp != '\0') + *dp++ = *sp++; + break; + case '%': + sp++; + if (scan_for) + { + if (*sp == scan_for && if_depth == scan_depth) + { + if (scan_for == ';') + if_depth--; + scan_for = 0; + } + else if (*sp == '?') + if_depth++; + else if (*sp == ';') + { + if (if_depth == 0) + return OOPS; + else + if_depth--; + } + sp++; + break; + } + fmt = NULL; + switch (*sp) + { + case '%': + *dp++ = *sp++; + break; + case '+': + if (!termcap) + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i += j; + if (pushnum (i)) + return OOPS; + sp++; + break; + } + /* FALLTHROUGH */ + case 'C': + if (*sp == 'C') + { + int i; + if (getarg (termcap - 1, INTEGER, &i)) + return OOPS; + if (i >= 96) + { + i /= 96; + if (i == '$') + *dp++ = '\\'; + *dp++ = i; + } + } + fmt = "%c"; + /* FALLTHROUGH */ + case 'a': + if (!termcap) + return OOPS; + { + int i; + if (getarg (termcap - 1, INTEGER, &i)) + return OOPS; + if (*++sp == '\0') + return OOPS; + if ((sp[1] == 'p' || sp[1] == 'c') + && sp[2] != '\0' && fmt == NULL) + { + /* GNU arithmetic parameter, what they really need is + terminfo. */ + int val; + int lc; + if (sp[1] == 'p' + && getarg (termcap - 1 + sp[2] - '@', INTEGER, &val)) + return OOPS; + if (sp[1] == 'c') + { + char c; + lc = cvtchar (sp + 2, &c) + 2; + /* Mask out 8th bit so \200 can be used for \0 as per + GNU docs. */ + val = c & 0177; + } + else + lc = 2; + switch (sp[0]) + { + case '=': + break; + case '+': + val = i + val; + break; + case '-': + val = i - val; + break; + case '*': + val = i * val; + break; + case '/': + val = i / val; + break; + default: + /* Not really GNU's %a after all... */ + { + char c; + lc = cvtchar (sp, &c); + val = c + i; + } + break; + } + arg_list[termcap - 1].integer = val; + sp += lc; + break; + } + { + char c; + sp += cvtchar (sp, &c); + arg_list[termcap - 1].integer = c + i; + } + } + if (fmt == NULL) + break; + sp--; + /* FALLTHROUGH */ + case '-': + if (!termcap) + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i -= j; + if (pushnum (i)) + return OOPS; + sp++; + break; + } + fmt = "%c"; + /* FALLTHROUGH */ + case 's': + if (termcap && (fmt == NULL || *sp == '-')) + { + int i; + if (getarg (termcap - 1, INTEGER, &i)) + return OOPS; + if (*++sp == '\0') + return OOPS; + { + char c; + sp += cvtchar (sp, &c); + arg_list[termcap - 1].integer = c - i; + } + if (fmt == NULL) + break; + sp--; + } + if (!termcap) + return OOPS; + /* FALLTHROUGH */ + case '.': + if (termcap && fmt == NULL) + fmt = "%c"; + /* FALLTHROUGH */ + case 'd': + if (termcap && fmt == NULL) + fmt = "%d"; + /* FALLTHROUGH */ + case '2': + if (termcap && fmt == NULL) + fmt = "%02d"; + /* FALLTHROUGH */ + case '3': + if (termcap && fmt == NULL) + fmt = "%03d"; + /* FALLTHROUGH */ + case ':': case ' ': case '#': case 'u': + case 'x': case 'X': case 'o': case 'c': + case '0': case '1': case '4': case '5': + case '6': case '7': case '8': case '9': + if (fmt == NULL) + { + if (termcap) + return OOPS; + if (*sp == ':') + sp++; + fmt = fmt_buf; + *fmt++ = '%'; + while (*sp != 's' && *sp != 'x' && *sp != 'X' && *sp != 'd' + && *sp != 'o' && *sp != 'c' && *sp != 'u') + { + if (*sp == '\0') + return OOPS; + *fmt++ = *sp++; + } + *fmt++ = *sp; + *fmt = '\0'; + fmt = fmt_buf; + } + { + char conv_char = fmt[strlen (fmt) - 1]; + if (conv_char == 's') + { + char *s; + if (popstring (&s)) + return OOPS; + sprintf (sbuf, fmt, s); + } + else + { + int i; + if (termcap) + { + if (getarg (termcap++ - 1, INTEGER, &i)) + return OOPS; + } + else + if (popnum (&i)) + return OOPS; + if (i == 0 && conv_char == 'c') + strcpy (sbuf, "\000"); + else + sprintf (sbuf, fmt, i); + } + } + sp++; + fmt = sbuf; + while (*fmt != '\0') + { + if (*fmt == '$') + *dp++ = '\\'; + *dp++ = *fmt++; + } + break; + case 'r': + { + int i; + if (!termcap || getarg (1, INTEGER, &i)) + return OOPS; + arg_list[1].integer = arg_list[0].integer; + arg_list[0].integer = i; + } + sp++; + break; + case 'i': + { + int i; + if (getarg (1, INTEGER, &i) || arg_list[0].type != INTEGER) + return OOPS; + } + arg_list[1].integer++; + arg_list[0].integer++; + sp++; + break; + case 'n': + { + int i; + if (!termcap || getarg (1, INTEGER, &i)) + return OOPS; + } + arg_list[0].integer ^= 0140; + arg_list[1].integer ^= 0140; + sp++; + break; + case '>': + if (!termcap) + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i = (i > j); + if (pushnum (i)) + return OOPS; + sp++; + break; + } + { + int i; + if (getarg (termcap-1, INTEGER, &i)) + return OOPS; + { + char c; + sp += cvtchar (sp, &c); + if (i > c) + { + sp += cvtchar (sp, &c); + arg_list[termcap-1].integer += c; + } + else + sp += cvtchar (sp, &c); + } + } + sp++; + break; + case 'B': + { + int i; + if (!termcap || getarg (termcap-1, INTEGER, &i)) + return OOPS; + arg_list[termcap-1].integer = 16 * (i / 10) + i % 10; + } + sp++; + break; + case 'D': + { + int i; + if (!termcap || getarg (termcap-1, INTEGER, &i)) + return OOPS; + arg_list[termcap-1].integer = i - 2 * (i % 16); + } + sp++; + break; + case 'p': + if (termcap > 1) + return OOPS; + if (*++sp == '\0') + return OOPS; + { + int i = (*sp == '0' ? 9 : *sp - '1'); + if (i < 0 || i > 9) + return OOPS; + if (pusharg (i)) + return OOPS; + } + termcap = 0; + sp++; + break; + case 'P': + if (termcap || *++sp == '\0') + return OOPS; + { + int i = *sp++ - 'a'; + if (i < 0 || i > 25) + return OOPS; + if (pos-- == 0) + return OOPS; + switch (vars[i].type = S[pos].type) + { + case ARG: + vars[i].argnum = S[pos].argnum; + break; + case NUM: + vars[i].value = S[pos].value; + break; + } + } + break; + case 'g': + if (termcap || *++sp == '\0') + return OOPS; + { + int i = *sp++ - 'a'; + if (i < 0 || i > 25) + return OOPS; + switch (vars[i].type) + { + case ARG: + if (pusharg (vars[i].argnum)) + return OOPS; + break; + case NUM: + if (pushnum (vars[i].value)) + return OOPS; + break; + } + } + break; + case '\'': + if (termcap > 1) + return OOPS; + if (*++sp == '\0') + return OOPS; + { + char c; + sp += cvtchar (sp, &c); + if (pushnum (c) || *sp++ != '\'') + return OOPS; + } + termcap = 0; + break; + case '{': + if (termcap > 1) + return OOPS; + { + int i; + i = 0; + sp++; + while (c_isdigit (*sp)) + i = 10 * i + *sp++ - '0'; + if (*sp++ != '}' || pushnum (i)) + return OOPS; + } + termcap = 0; + break; + case 'l': + { + int i; + char *s; + if (termcap || popstring (&s)) + return OOPS; + i = strlen (s); + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case '*': + { + int i, j; + if (termcap || popnum (&j) || popnum (&i)) + return OOPS; + i *= j; + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case '/': + { + int i, j; + if (termcap || popnum (&j) || popnum (&i)) + return OOPS; + i /= j; + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case 'm': + if (termcap) + { + int i; + if (getarg (1, INTEGER, &i)) + return OOPS; + arg_list[0].integer ^= 0177; + arg_list[1].integer ^= 0177; + sp++; + break; + } + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i %= j; + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case '&': + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i &= j; + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case '|': + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i |= j; + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case '^': + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i ^= j; + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case '=': + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i = (i == j); + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case '<': + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i = (i < j); + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case 'A': + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i = (i && j); + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case 'O': + { + int i, j; + if (popnum (&j) || popnum (&i)) + return OOPS; + i = (i || j); + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case '!': + { + int i; + if (popnum (&i)) + return OOPS; + i = !i; + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case '~': + { + int i; + if (popnum (&i)) + return OOPS; + i = ~i; + if (pushnum (i)) + return OOPS; + } + sp++; + break; + case '?': + if (termcap > 1) + return OOPS; + termcap = 0; + if_depth++; + sp++; + break; + case 't': + { + int i; + if (popnum (&i) || if_depth == 0) + return OOPS; + if (!i) + { + scan_for = 'e'; + scan_depth = if_depth; + } + } + sp++; + break; + case 'e': + if (if_depth == 0) + return OOPS; + scan_for = ';'; + scan_depth = if_depth; + sp++; + break; + case ';': + if (if_depth-- == 0) + return OOPS; + sp++; + break; + case 'b': + if (--termcap < 1) + return OOPS; + sp++; + break; + case 'f': + if (!termcap++) + return OOPS; + sp++; + break; + } + break; + default: + if (scan_for) + sp++; + else + *dp++ = *sp++; + break; + } } va_end (tparm_args); *dp = '\0'; diff --git a/gnulib-local/lib/tputs.c b/gnulib-local/lib/tputs.c index 7bb041be1..beaea125c 100644 --- a/gnulib-local/lib/tputs.c +++ b/gnulib-local/lib/tputs.c @@ -36,7 +36,7 @@ tputs (const char *cp, int affcnt, int (*outcharfun) (int)) { cp++; while (c_isdigit (*cp)) - cp++; + cp++; } for (; *cp != '\0'; cp++) outcharfun (*cp); diff --git a/gnulib-local/lib/vasprintf.c b/gnulib-local/lib/vasprintf.c index 366bdef64..f825c4eb3 100644 --- a/gnulib-local/lib/vasprintf.c +++ b/gnulib-local/lib/vasprintf.c @@ -43,69 +43,69 @@ int_vasprintf (char **result, const char *format, va_list args) while (*p != '\0') { if (*p++ == '%') - { - while (strchr ("-+ #0", *p)) - ++p; - if (*p == '*') - { - ++p; - total_width += abs (va_arg (ap, int)); - } - else - total_width += strtoul (p, (char **) &p, 10); - if (*p == '.') - { - ++p; - if (*p == '*') - { - ++p; - total_width += abs (va_arg (ap, int)); - } - else - total_width += strtoul (p, (char **) &p, 10); - } - while (strchr ("hlLjtz", *p)) - ++p; - /* Should be big enough for any format specifier except %s - and floats. */ - total_width += 30; - switch (*p) - { - case 'd': - case 'i': - case 'o': - case 'u': - case 'x': - case 'X': - case 'c': - (void) va_arg (ap, int); - break; - case 'f': - case 'F': - { - double arg = va_arg (ap, double); - if (arg >= 1.0 || arg <= -1.0) - /* Since an ieee double can have an exponent of 307, we'll - make the buffer wide enough to cover the gross case. */ - total_width += 307; - } - break; - case 'e': - case 'E': - case 'g': - case 'G': - (void) va_arg (ap, double); - break; - case 's': - total_width += strlen (va_arg (ap, char *)); - break; - case 'p': - case 'n': - (void) va_arg (ap, char *); - break; - } - p++; - } + { + while (strchr ("-+ #0", *p)) + ++p; + if (*p == '*') + { + ++p; + total_width += abs (va_arg (ap, int)); + } + else + total_width += strtoul (p, (char **) &p, 10); + if (*p == '.') + { + ++p; + if (*p == '*') + { + ++p; + total_width += abs (va_arg (ap, int)); + } + else + total_width += strtoul (p, (char **) &p, 10); + } + while (strchr ("hlLjtz", *p)) + ++p; + /* Should be big enough for any format specifier except %s + and floats. */ + total_width += 30; + switch (*p) + { + case 'd': + case 'i': + case 'o': + case 'u': + case 'x': + case 'X': + case 'c': + (void) va_arg (ap, int); + break; + case 'f': + case 'F': + { + double arg = va_arg (ap, double); + if (arg >= 1.0 || arg <= -1.0) + /* Since an ieee double can have an exponent of 307, we'll + make the buffer wide enough to cover the gross case. */ + total_width += 307; + } + break; + case 'e': + case 'E': + case 'g': + case 'G': + (void) va_arg (ap, double); + break; + case 's': + total_width += strlen (va_arg (ap, char *)); + break; + case 'p': + case 'n': + (void) va_arg (ap, char *); + break; + } + p++; + } } va_end (ap); diff --git a/gnulib-local/lib/xalloc.h b/gnulib-local/lib/xalloc.h index e0d56fc16..1ad100944 100644 --- a/gnulib-local/lib/xalloc.h +++ b/gnulib-local/lib/xalloc.h @@ -84,8 +84,8 @@ extern void xalloc_die (void) known at compile-time. */ # define XNMALLOC(N,T) \ ((T *) (sizeof (T) == 1 \ - ? xmalloc (N) \ - : xnboundedmalloc(N, (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / sizeof (T), sizeof (T)))) + ? xmalloc (N) \ + : xnboundedmalloc(N, (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / sizeof (T), sizeof (T)))) static inline void * xnboundedmalloc (size_t n, size_t bound, size_t s) { diff --git a/gnulib-local/lib/xerror.c b/gnulib-local/lib/xerror.c index ee8297f0b..b803f4843 100644 --- a/gnulib-local/lib/xerror.c +++ b/gnulib-local/lib/xerror.c @@ -49,10 +49,10 @@ multiline_warning (char *prefix, char *message) { width = 0; if (error_with_progname) - { - fprintf (stderr, "%s: ", program_name); - width += mbswidth (program_name, 0) + 2; - } + { + fprintf (stderr, "%s: ", program_name); + width += mbswidth (program_name, 0) + 2; + } fputs (prefix, stderr); width += mbswidth (prefix, 0); free (prefix); @@ -64,16 +64,16 @@ multiline_warning (char *prefix, char *message) const char *np; for (i = width; i > 0; i--) - putc (' ', stderr); + putc (' ', stderr); after_indent: np = strchr (cp, '\n'); if (np == NULL || np[1] == '\0') - { - fputs (cp, stderr); - break; - } + { + fputs (cp, stderr); + break; + } np++; fwrite (cp, 1, np - cp, stderr); diff --git a/gnulib-local/lib/xgetcwd.c b/gnulib-local/lib/xgetcwd.c index 2a1acbd49..0b1016c55 100644 --- a/gnulib-local/lib/xgetcwd.c +++ b/gnulib-local/lib/xgetcwd.c @@ -58,7 +58,7 @@ xgetcwd () return NULL; path_max = (unsigned) PATH_MAX; - path_max += 2; /* The getcwd docs say to do this. */ + path_max += 2; /* The getcwd docs say to do this. */ for (;;) { @@ -67,14 +67,14 @@ xgetcwd () errno = 0; ret = getcwd (cwd, path_max); if (ret != NULL) - return ret; + return ret; if (errno != ERANGE) - { - int save_errno = errno; - free (cwd); - errno = save_errno; - return NULL; - } + { + int save_errno = errno; + free (cwd); + errno = save_errno; + return NULL; + } free (cwd); diff --git a/gnulib-local/m4/unionwait.m4 b/gnulib-local/m4/unionwait.m4 index 30a97efdb..ea3d4922b 100644 --- a/gnulib-local/m4/unionwait.m4 +++ b/gnulib-local/m4/unionwait.m4 @@ -13,7 +13,7 @@ AC_MSG_CHECKING(for union wait) AC_CACHE_VAL(gt_cv_union_wait, [dnl AC_TRY_LINK([#include #include ], - [union wait status; int pid; pid = wait (&status); + [union wait status; int pid; pid = wait (&status); #ifdef WEXITSTATUS /* Some POSIXoid systems have both the new-style macros and the old union wait type, and they do not work together. If union wait @@ -29,7 +29,7 @@ if (WEXITSTATUS (status) != 0) pid = -1; pid = waitpid (-1, &status, 0); #endif ], - [gt_cv_union_wait=yes], [gt_cv_union_wait=no])]) + [gt_cv_union_wait=yes], [gt_cv_union_wait=no])]) if test "$gt_cv_union_wait" = yes; then AC_DEFINE(HAVE_UNION_WAIT, 1, [Define if defines the 'union wait' type.]) diff --git a/gnulib-local/tests/test-moo-assign.c b/gnulib-local/tests/test-moo-assign.c index 079668b77..642bbe90e 100644 --- a/gnulib-local/tests/test-moo-assign.c +++ b/gnulib-local/tests/test-moo-assign.c @@ -12,21 +12,21 @@ void foo () root_t a1 = a; root_t a2 = b; root_t a3 = c; - sub1_t b1 = a; /* ERROR */ + sub1_t b1 = a; /* ERROR */ sub1_t b2 = b; sub1_t b3 = c; - sub2_t c1 = a; /* ERROR */ - sub2_t c2 = b; /* ERROR */ + sub2_t c1 = a; /* ERROR */ + sub2_t c2 = b; /* ERROR */ sub2_t c3 = c; /* Test assignments. */ a = a1; a = b1; a = c1; - b = a2; /* ERROR */ + b = a2; /* ERROR */ b = b2; b = c2; - c = a3; /* ERROR */ - c = b3; /* ERROR */ + c = a3; /* ERROR */ + c = b3; /* ERROR */ c = c3; } diff --git a/gnulib-local/tests/test-term-ostream.c b/gnulib-local/tests/test-term-ostream.c index e0a61ab32..b8bdbd70b 100644 --- a/gnulib-local/tests/test-term-ostream.c +++ b/gnulib-local/tests/test-term-ostream.c @@ -48,23 +48,23 @@ main () ostream_write_str (stream, name); ostream_write_mem (stream, " ", 7 - strlen (name)); for (col = 0; col <= 8; col++) - { - term_color_t row_color = colors[row].c; - term_color_t col_color = colors[col].c; + { + term_color_t row_color = colors[row].c; + term_color_t col_color = colors[col].c; - ostream_write_str (stream, "|"); - term_ostream_set_color (stream, row_color); - term_ostream_set_bgcolor (stream, col_color); - if (!(term_ostream_get_color (stream) == row_color - && term_ostream_get_bgcolor (stream) == col_color)) - abort (); - ostream_write_str (stream, " Words "); - term_ostream_set_color (stream, COLOR_DEFAULT); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - if (!(term_ostream_get_color (stream) == COLOR_DEFAULT - && term_ostream_get_bgcolor (stream) == COLOR_DEFAULT)) - abort (); - } + ostream_write_str (stream, "|"); + term_ostream_set_color (stream, row_color); + term_ostream_set_bgcolor (stream, col_color); + if (!(term_ostream_get_color (stream) == row_color + && term_ostream_get_bgcolor (stream) == col_color)) + abort (); + ostream_write_str (stream, " Words "); + term_ostream_set_color (stream, COLOR_DEFAULT); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + if (!(term_ostream_get_color (stream) == COLOR_DEFAULT + && term_ostream_get_bgcolor (stream) == COLOR_DEFAULT)) + abort (); + } ostream_write_str (stream, "\n"); } ostream_write_str (stream, "\n"); @@ -74,90 +74,90 @@ main () for (row = 0; row <= 17; row++) { for (col = 0; col <= 64; col++) - { - int r = 255; - int b = (int) (255.0f / 64.0f * col + 0.5f); - int g = b + (int) (row / 17.0f * (r - b) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int r = 255; + int b = (int) (255.0f / 64.0f * col + 0.5f); + int g = b + (int) (row / 17.0f * (r - b) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } /* Hue from 1 to 2. */ for (row = 17; row >= 0; row--) { for (col = 0; col <= 64; col++) - { - int g = 255; - int b = (int) (255.0f / 64.0f * col + 0.5f); - int r = b + (int) (row / 17.0f * (g - b) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int g = 255; + int b = (int) (255.0f / 64.0f * col + 0.5f); + int r = b + (int) (row / 17.0f * (g - b) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } /* Hue from 2 to 3. */ for (row = 0; row <= 17; row++) { for (col = 0; col <= 64; col++) - { - int g = 255; - int r = (int) (255.0f / 64.0f * col + 0.5f); - int b = r + (int) (row / 17.0f * (g - r) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int g = 255; + int r = (int) (255.0f / 64.0f * col + 0.5f); + int b = r + (int) (row / 17.0f * (g - r) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } /* Hue from 3 to 4. */ for (row = 17; row >= 0; row--) { for (col = 0; col <= 64; col++) - { - int b = 255; - int r = (int) (255.0f / 64.0f * col + 0.5f); - int g = r + (int) (row / 17.0f * (b - r) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int b = 255; + int r = (int) (255.0f / 64.0f * col + 0.5f); + int g = r + (int) (row / 17.0f * (b - r) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } /* Hue from 4 to 5. */ for (row = 0; row <= 17; row++) { for (col = 0; col <= 64; col++) - { - int b = 255; - int g = (int) (255.0f / 64.0f * col + 0.5f); - int r = g + (int) (row / 17.0f * (b - g) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int b = 255; + int g = (int) (255.0f / 64.0f * col + 0.5f); + int r = g + (int) (row / 17.0f * (b - g) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } /* Hue from 5 to 6. */ for (row = 17; row >= 0; row--) { for (col = 0; col <= 64; col++) - { - int r = 255; - int g = (int) (255.0f / 64.0f * col + 0.5f); - int b = g + (int) (row / 17.0f * (r - g) + 0.5f); - term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); - term_ostream_set_bgcolor (stream, c); - ostream_write_str (stream, " "); - term_ostream_set_bgcolor (stream, COLOR_DEFAULT); - } + { + int r = 255; + int g = (int) (255.0f / 64.0f * col + 0.5f); + int b = g + (int) (row / 17.0f * (r - g) + 0.5f); + term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); + term_ostream_set_bgcolor (stream, c); + ostream_write_str (stream, " "); + term_ostream_set_bgcolor (stream, COLOR_DEFAULT); + } ostream_write_str (stream, "\n"); } ostream_write_str (stream, "\n"); diff --git a/os2/README.OS2 b/os2/README.OS2 index 80487e42c..732942ef0 100644 --- a/os2/README.OS2 +++ b/os2/README.OS2 @@ -170,13 +170,13 @@ Contributors ============ Hung-Chi Chu - the original port of gettext (0.10.35) + the original port of gettext (0.10.35) Jun SAWATAISHI - some more work on it and submitted the patches to GNU team, although - they were not completely integrated. + some more work on it and submitted the patches to GNU team, although + they were not completely integrated. Andrew Zabolotny - Succeeded to remove almost all OS/2-specific #ifdef's from mainstream - source code, wrote the dedicated OS/2 makefile, wrote the iconv wrapper - around OS/2 Unicode API, added support for locale translations. + Succeeded to remove almost all OS/2-specific #ifdef's from mainstream + source code, wrote the dedicated OS/2 makefile, wrote the iconv wrapper + around OS/2 Unicode API, added support for locale translations. diff --git a/os2/iconv/iconv.c b/os2/iconv/iconv.c index ef31d2ba8..e906497d7 100644 --- a/os2/iconv/iconv.c +++ b/os2/iconv/iconv.c @@ -24,8 +24,8 @@ typedef struct _iconv_t { - UconvObject from; /* "From" conversion handle */ - UconvObject to; /* "To" conversion handle */ + UconvObject from; /* "From" conversion handle */ + UconvObject to; /* "To" conversion handle */ } *iconv_t; /* Tell "iconv.h" to not define iconv_t by itself. */