1#!/usr/bin/perl
2
3##############################################################################
4#
5# Project:  TwlSDK - code formatter-
6# File:     sdk_indent.pl
7#
8# Copyright 2003-2008 Nintendo. All rights reserved.
9#
10# These coded instructions, statements, and computer programs contain
11# proprietary information of Nintendo of America Inc. and/or Nintendo
12# Company Ltd., and are protected by Federal copyright law. They may
13# not be disclosed to third parties or copied or duplicated in any form,
14# in whole or in part, without the prior written consent of Nintendo.
15#
16# $Date:: 2008-10-20#$
17# $Rev: 9005 $
18# $Author: okubata_ryoma $
19##############################################################################
20
21foreach $filename (@ARGV) {
22  print STDERR "processing $filename\n";
23  open INFILE, "$filename" or die "cannot open infile $filename\n";
24  $intext = "";
25  while(<INFILE>) {
26    $intext .= $_;
27  }
28
29  close(INFILE);
30
31  next if ($intext =~ m/\Wasm\W/s); #Won't do anything if there is asm!
32  {
33    # intext processing section
34    $intext =~ s/extern\s+\"C\"[^{]*\{/extern \"C\";/s;   # extern "C" { brace is a nuisance
35    $intext =~ s/\#ifdef\s+__cplusplus\s+\}/\#ifdef __cplusplus\n\/* \} *\//s;
36  }
37
38  {
39    # open2 is strange, so we have to write it plainly
40    open OUTFILE, ">indent.tmp" or die "cannot open outfile indent.tmp\n";
41    print OUTFILE $intext;
42    close(OUTFILE);
43  }
44
45$tpdefs = "\
46-T BOOL -T f64 -T u64 -T s64 -T f32 -T u32 -T s32 -T u16 -T s16 -T u8 -T s8 \
47-T VecFx16 -T VecFx32 -T OS_Thread -T OS_Mutex -T OS_MessageQueue -T OS_Context \
48-T MtxFx44 -T MtxFx43 -T MtxFx33 -T MtxFx22 -T LockWord -T LockByte -T G3XMiscStatus \
49-T G3DLInfo -T G3BoxTestParam -T G2OamAttr -T G2OamAffine -T fxdiv_ -T fx64Tmp_ \
50-T G2ENUM_OAM_SHAPE";
51
52system "indent -bap -bbo -bli0 -bls -c60 -cd60 -cli0 -cp8 -nbfda -i4 -l120 -lc120 -lps -nbc -ncs -npsl -nsob -nut -npcs -nprs -saf -sai -saw -ss $tdefs indent.tmp";
53
54open INFILE2, "indent.tmp" or die "cannot open infile indent.tmp\n";
55
56$outtext = "";
57while(<INFILE2>) {
58  $outtext .= $_;
59}
60
61unlink("indent.tmp");
62unlink("indent.tmp~");
63
64close(INFILE2);
65
66{
67  # outtext process section
68  $outtext =~ s/extern\s+\"C\";/extern \"C\" \{/s;   # extern "C" { brace added
69  $outtext =~ s/\#ifdef\s+__cplusplus\s+\/\* \} \*\//\#ifdef __cplusplus\n\}/s;
70}
71
72open OUTFILE2, ">$filename" or die "cannot open outfile $filename\n";
73print OUTFILE2 $outtext;
74close(OUTFILE2);
75}
76