sanitize.pl revision 761a1c3761dc4e83a5d11765a42fab2970c5352b
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# Copyright (C) 1999, 2000 Internet Software Consortium.
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# Permission to use, copy, modify, and distribute this software for any
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# purpose with or without fee is hereby granted, provided that the above
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# copyright notice and this permission notice appear in all copies.
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
9e6de65c57eddc3790badaad3b9481aaaed18e03Brian Wellington# $Id: sanitize.pl,v 1.1 2000/07/26 18:47:43 mws Exp $
d09197467bbb156dccf0cbe72bb5c63480d5cfdcDavid Lawrence# Don't try and sanitize this file: NOMINUM_IGNORE
64ba6e4cc3a0ccf8c8c6349fa75b937ca9bad9a6Michael Graff# Go through the directory tree and make sure that all of the files are
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# In normal mode, check file, removing code between
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# #ifndef NOMINUM_PUBLIC
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# and the accompanying #else or #endif. Similarly, code in an #else
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# clause after an #ifndef test will be removed. The #else or #endif's
94231e22882a98a3805060b0a1322e96d8f57b41David Lawrence# must appear as:
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# #else /* NOMINUM_PUBLIC */
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# #endif /* NOMINUM_PUBLIC */
73d62a89f1493865c33c689b3ee3de91c74ad58eDavid Lawrence# Balance is tested.
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# Non-.c/.h files are tested for the existance of NOMINUM_PUBLIC anywhere
73d62a89f1493865c33c689b3ee3de91c74ad58eDavid Lawrence# in the file, and a warning is generated, unless the string
73d62a89f1493865c33c689b3ee3de91c74ad58eDavid Lawrence# NOMINUM_IGNORE appears before NOMINUM_PUBLIC.
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# ./sanitize.pl -c - Check syntax only, don't change anything
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# ./sanitize.pl -i - Reverse sense of sanitize.
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence# ./sanitize.pl - - Work as a pipe, sanitizing stdin to stdout.
33950f0a0262f4d49528c4adcf8be42807fa2576David Lawrence# ./sanitize.pl file - Sanitize the specified file.
1630fce031f7a3e33f0579e477a3e17d1993e1f9Bob Halley# 0 - Outside of test, include code
1630fce031f7a3e33f0579e477a3e17d1993e1f9Bob Halley# 1 - Inside NOMINUM_PUBLIC
0f5962ac3e4ef336faff68f1cb838505e64665e5David Lawrence# 2 - Inside !NOMINUM_PUBLIC
0f5962ac3e4ef336faff68f1cb838505e64665e5David Lawrence if (/^-c$/i) {
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence elsif (/^-i$/i) {
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence elsif (/^-$/i) {
da1eb108c623ef351c4275251e8a906138da85b9David Lawrence# elsif (/^-a$/i) {
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence elsif (/^-d$/i) {
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence unlink($_[1]);
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence if (/\#ifdef.+NOMINUM_PUBLIC/) {
0f5962ac3e4ef336faff68f1cb838505e64665e5David Lawrence "Found #ifdef without matching ".
0f5962ac3e4ef336faff68f1cb838505e64665e5David Lawrence "#endif.\n");
33950f0a0262f4d49528c4adcf8be42807fa2576David Lawrence unlink($_[1]);
ec80744ad68b97f15657b1fdf5591c30b559b57dDavid Lawrence elsif (/\#ifndef.+NOMINUM_PUBLIC/) {
ec80744ad68b97f15657b1fdf5591c30b559b57dDavid Lawrence "Found #ifndef without matching ".
ec80744ad68b97f15657b1fdf5591c30b559b57dDavid Lawrence "#endif.\n");
ec80744ad68b97f15657b1fdf5591c30b559b57dDavid Lawrence unlink($_[1]);
1630fce031f7a3e33f0579e477a3e17d1993e1f9Bob Halley elsif (/\#else.+NOMINUM_PUBLIC/) {
1630fce031f7a3e33f0579e477a3e17d1993e1f9Bob Halley "Found #else without matching ".
1630fce031f7a3e33f0579e477a3e17d1993e1f9Bob Halley "#if[n]def.\n");
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence unlink($_[1]);
1630fce031f7a3e33f0579e477a3e17d1993e1f9Bob Halley elsif (/\#endif.+NOMINUM_PUBLIC/) {
1630fce031f7a3e33f0579e477a3e17d1993e1f9Bob Halley "Found #else without matching ".
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence "#if[n]def.\n");
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence unlink($_[1]);
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence "Found NOMINUM_PUBLIC outside of ".
33950f0a0262f4d49528c4adcf8be42807fa2576David Lawrence "#ifdef/#else/#endif.\n");
5f50687f61057f7f0acb161d5803f4a48e40b3a8David Lawrence "File ended with unterminated test.\n");
73d62a89f1493865c33c689b3ee3de91c74ad58eDavid Lawrence rename($_[1], $_[0]) || die "Rename $_[1] to $_[0]:";