parameters: (line, outfile)
docstring: Read a line of output/error from include-what-you use
          Turn clang errors into a form QT creator recognises
          Raise warnings for unneeded includes
docstring_summary: Read a line of output/error from include-what-you use
          Turn clang errors into a form QT creator recognises
          Raise warnings for unneeded includes
docstring_tokens: Read a line of output / error from include - what - you use Turn clang errors into a form QT creator recognises Raise warnings for unneeded includes
function: def process_next_line(line, outfile):
      """ Read a line of output/error from include-what-you use
          Turn clang errors into a form QT creator recognises
          Raise warnings for unneeded includes
      """
      global removing
      global includes
      global foundline
      global errors
      global added
      global adding
      line = line.rstrip()
      print >> outfile, line
  
      if line.endswith(' should remove these lines:'):
          adding = None
          removing = (line.split(' '))[0]
      elif line.endswith(' should add these lines:'):
          removing = None
          adding = (line.split(' '))[0]
      elif line == '' or line.startswith(' the full include-list'):
          adding = None
          removing = None
      elif adding:
          m = re.match(r'.*class (.*);', line)
          if m:
              added[m.group(1)].append((adding, line))
              lcadded[m.group(1).lower() + '.h'] = m.group(1)
          else:
              added[line].append((adding, line))
      elif removing:
          # Really we should stash these so that if we get a 'class xxx' in
          # the add lines we can print it here. also we could do the case
          # fixing.
          m = re.match(r'- #include [<"](.*)[">] +// lines (.*)-', line)
          if m:
              foundline = m.group(2)
              # Note: In this project at least we have a naming convention of
              # lower case filename and upper case classname.
              clname = m.group(1)
              if clname not in added:
                  if clname in lcadded:
                      clname = lcadded[clname]
              if clname in added:
                  for item in added[clname]:
                      if removing == item[0]:
                          messages[removing].append(
                              '%s(%s) : warning I0004: Replace include of %s'
                              ' with forward reference %s' % (
                                       removing, m.group(2), m.group(1), item[1]))
                  del added[clname]
              else:
                  messages[removing].append(
                      '%s(%s) : warning I0001: Unnecessary include of %s' % (
                                                removing, m.group(2), m.group(1)))
  
          else:
              m = re.match(r'- (.*) +// lines (.*)-', line)
              if m:
                  messages[removing].append(
                      '%s(%s) : warning I0002: Unnecessary forward ref of %s' % (
                                                removing, m.group(2), m.group(1)))
              else:
                  print '********* I got confused **********'
      elif line.startswith('In file included from'):
          line = re.sub(r'^(In file included from)(.*):(\d+):',
                        r'        \2(\3) : \1 here',
                        line)
          # Note; QT Creator seems to be unwilling to let you double click the
          # line to select the code in question if you get a string of these, not
          # sure why.
      elif ': note:' in line:
          line = '        ' + re.sub(r':(\d+):\d+: note:', r'(\1) : note:', line)
      else:
          # Replace clang :line:column: type: with ms (line) : type nnnn:
          line = re.sub(r':(\d+):\d+: ([^:]*):', r'(\1) : \2 I1234:', line)
          if ' : error I1234:' in line:
              errors = True
  
      print line
function_tokens: def process_next_line ( line , outfile ) : global removing global includes global foundline global errors global added global adding line = line . rstrip ( ) print >> outfile , line if line . endswith ( ' should remove these lines:' ) : adding = None removing = ( line . split ( ' ' ) ) [ 0 ] elif line . endswith ( ' should add these lines:' ) : removing = None adding = ( line . split ( ' ' ) ) [ 0 ] elif line == '' or line . startswith ( ' the full include-list' ) : adding = None removing = None elif adding : m = re . match ( r'.*class (.*);' , line ) if m : added [ m . group ( 1 ) ] . append ( ( adding , line ) ) lcadded [ m . group ( 1 ) . lower ( ) + '.h' ] = m . group ( 1 ) else : added [ line ] . append ( ( adding , line ) ) elif removing : # Really we should stash these so that if we get a 'class xxx' in # the add lines we can print it here. also we could do the case # fixing. m = re . match ( r'- #include [<"](.*)[">] +// lines (.*)-' , line ) if m : foundline = m . group ( 2 ) # Note: In this project at least we have a naming convention of # lower case filename and upper case classname. clname = m . group ( 1 ) if clname not in added : if clname in lcadded : clname = lcadded [ clname ] if clname in added : for item in added [ clname ] : if removing == item [ 0 ] : messages [ removing ] . append ( '%s(%s) : warning I0004: Replace include of %s' ' with forward reference %s' % ( removing , m . group ( 2 ) , m . group ( 1 ) , item [ 1 ] ) ) del added [ clname ] else : messages [ removing ] . append ( '%s(%s) : warning I0001: Unnecessary include of %s' % ( removing , m . group ( 2 ) , m . group ( 1 ) ) ) else : m = re . match ( r'- (.*) +// lines (.*)-' , line ) if m : messages [ removing ] . append ( '%s(%s) : warning I0002: Unnecessary forward ref of %s' % ( removing , m . group ( 2 ) , m . group ( 1 ) ) ) else : print '********* I got confused **********' elif line . startswith ( 'In file included from' ) : line = re . sub ( r'^(In file included from)(.*):(\d+):' , r'        \2(\3) : \1 here' , line ) # Note; QT Creator seems to be unwilling to let you double click the # line to select the code in question if you get a string of these, not # sure why. elif ': note:' in line : line = '        ' + re . sub ( r':(\d+):\d+: note:' , r'(\1) : note:' , line ) else : # Replace clang :line:column: type: with ms (line) : type nnnn: line = re . sub ( r':(\d+):\d+: ([^:]*):' , r'(\1) : \2 I1234:' , line ) if ' : error I1234:' in line : errors = True print line