freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ft-devel] A line-joiner for broken PureC cpp (Re: splitting cpp-macro a


From: mpsuzuki
Subject: [ft-devel] A line-joiner for broken PureC cpp (Re: splitting cpp-macro arguments to multiple lines)
Date: Thu, 28 May 2009 11:52:25 +0900

Dear Werner,

Sorry for an old issue to work with broken AtariST PureC compiler.
When I had ever written the patch set for AtariST PureC,
this issue was only found in src/cache/ftcglyph.h. But now
this issue is found in multiple files (e.g. include/freetype/
internal/{autohint.h, ftdriver.h, ftobjs.h, ...}), so I think
now manual fix is not easy job.

So I will propose an inclusion of small conversion tool in
builds/atari (and makefile to convert source files, that joins
the splitted lines of the first token in the cpp macro definition.
It automatically changes the text like

        #define func( a,  \
                      b,  \
                      c ) \
                { ...     \
                  ... }

to PureC-ready format like

        #define func( a, b, c ) \
                { ...     \
                  ... }

As an interim report, I attached a tool written by Ruby.
I think the tool should be written by C or some scriptic
languages sed, awk or Python (Perl should be avoided,
because current FT2 package does not require it at all),
so I will propose officially when rewriting is finished.

Regards,
mpsuzuki

# I didn't want to write yet-another tokenizer to recognize
# cpp syntax, but I could not find appropriate library.
# I had to write it.

#-----------------------------------------------------------------

#!/usr/bin/env ruby

class Cpp_src_line
  attr_accessor(:logical_line, :break_pos)

  def initialize
    @logical_line = String.new
    @break_pos    = Array.new
  end

  def append_line( phys_line )
    filt_line      = phys_line.chomp.gsub( /\\$/, " " )
    @logical_line += filt_line
    break_pos.push( @logical_line.length - 1 )
  end

  def print_line()
    c0 = 0

    while( @break_pos.length > 1 )
      c1 = @break_pos.shift
      printf( "%s\n", @logical_line[c0..c1].gsub( / $/, "\\" ) )
      c0 = c1 + 1
    end

    printf( "%s\n", @address@hidden )
  end

  def shrink_spaces( pos )
    tail = @address@hidden( /^\s*/, " " )
    removed_length = ( @logical_line.length - pos ) - tail.length
    @logical_line = @logical_line[0..( pos - 1 )] + tail 
    @break_pos = @break_pos.compact.collect{ |i|
      if ( pos + removed_length < i )
        i = i - removed_length
      end
    }
    return removed_length
  end

  def delete_linebreaks_in_first_token
    if ( @logical_line =~ /^\s*#\s*define\s+[0-9A-Za-z_]+\(/ )
      tail = @logical_line
      tail = tail.sub( /^\s*#\s*define\s+[0-9A-Za-z_]+/, "" )

      paren_depth = 1
      i = @logical_line.length - tail.length + 1
      while ( i < @logical_line.length && paren_depth != 0 )
        if ( @logical_line[i,2] =~ /\s\s/ )
          self.shrink_spaces( i )
        elsif ( @logical_line[i,1] == "(" )
          paren_depth += 1
        elsif ( @logical_line[i,1] == ")" )
          paren_depth -= 1
        end
        # printf( "char=%s depth=%d\n", @logical_line[i..i], paren_depth )
        i += 1
      end

      # p @break_pos
      @break_pos = @break_pos.compact.delete_if{|j| j < i}
      # p @break_pos
    end
    self
  end

end



cppl = Cpp_src_line.new

while ( $stdin.gets )
  cppl.append_line( $_ )
  if ( $_ !~ /\\$/ )
    cppl.delete_linebreaks_in_first_token.print_line
    cppl = Cpp_src_line.new
  end
end

#-----------------------------------------------------------------



On Thu, 25 Dec 2008 17:25:47 +0900
address@hidden wrote:

>On Thu, 25 Dec 2008 08:53:42 +0100 (CET)
>Werner LEMBERG <address@hidden> wrote:
>>I see in the patch that you've changed
>>
>>  #define FTC_GCACHE_LOOKUP_CMP( cache, famcmp, nodecmp, hash,                
>> \
>>                                 gindex, query, node, error )                 
>> \
>>  ...
>>
>>to
>>
>>  #define FTC_GCACHE_LOOKUP_CMP( cache, famcmp, nodecmp, hash, gindex, query, 
>> node, error ) \
>>  ...
>>
>>(this is, all arguments of the macros are in a single line).  Why?
>
>Oh, exactly your guessing is correct, I'm sorry for the lack of
>detailed notice.
>
>>Is there a bug in the Atari preprocessor which enforces that?
>>In case my assumption is correct, please add a comment directly
>>to the macros which are affected by this change so that it
>>doesn't get reverted accidentally.
>
>I've not checked if C89 (or C99) permits to split the cpp-
>macro function's arguments to multiple lines (if permitted,
>please let me know), or this issue is simply the unreasonable
>restriction of AtariST/PureC compiler. Please wait.
>
>Maybe writing the comment to one header file is insufficient,
>other developer may want to split the arguments in other header
>files. If it's possible to write some tool to collect all
>arguments to single line (or, simple checker to detect the
>splitted arguments), I want to include it and write a document
>for AtariST, how to prepare the sources.
>
>Regards,
>mpsuzuki
>
>
>_______________________________________________
>Freetype-devel mailing list
>address@hidden
>http://lists.nongnu.org/mailman/listinfo/freetype-devel




reply via email to

[Prev in Thread] Current Thread [Next in Thread]