1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
################################################################################
#
# PROGRAM: ppdir.pl
#
################################################################################
#
# DESCRIPTION: Generate tokenizer code for C preprocessor directives
#
################################################################################
#
# $Project: /Convert-Binary-C $
# $Author: mhx $
# $Date: 2009/03/15 04:10:46 +0100 $
# $Revision: 5 $
# $Source: /ucpp/ppdir.pl $
#
################################################################################
#
# Copyright (c) 2004-2009 Marcus Holland-Moritz. All rights reserved.
# This program is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
################################################################################
use Devel::Tokenizer::C;
use strict;
my @PP = qw(
define
undef
if
ifdef
ifndef
else
elif
endif
include
include_next
pragma
error
line
assert
unassert
ident
);
my $file = shift;
my $enums = join "\n", map " PPDIR_\U$_\E,", @PP;
my $switch = Devel::Tokenizer::C->new(TokenFunc => sub { "return PPDIR_\U$_[0]\E;\n" },
TokenString => 'ppdir')
->add_tokens(@PP)->generate;
open OUT, ">$file" or die $!;
print OUT <<END;
static enum {
$enums
PPDIR_UNKNOWN
}
scan_pp_directive(const char *ppdir)
{
$switch
unknown:
return PPDIR_UNKNOWN;
}
END
close OUT;
|