"Fossies" - the Fresh Open Source Software Archive

Member "ncc-2.8/scripts/nccstrip2.py" (13 Oct 2008, 1311 Bytes) of package /linux/privat/old/ncc-2.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/env python
    2 
    3 # This file is installed and used automatically by ncc each time it
    4 # "links" nccout object files.
    5 
    6 import sys
    7 
    8 have = {}
    9 
   10 def getsub (line, set):
   11     global outlines
   12     TS = ''
   13     TL = [ line ]
   14     for j in instream:
   15         if j[0] not in set:
   16             break
   17     j = j[:-1]
   18     TS += j
   19     TL.append (j)
   20     if line in have:
   21     X = have [line]
   22     if type(X) == type (''):
   23         if X == TS:
   24         return
   25         have [line] = [X, TS]
   26     else:
   27         for k in have [line]:
   28             if k == TS:
   29             return
   30         have [line].append (TS)
   31     else:
   32     have [line] = TS
   33     outlines += len (TL)
   34     output ("\n".join (TL) + "\n")
   35 
   36 infile, outfile = sys.argv [1:]
   37 outlines = inlines = 0
   38 def readinput (infile):
   39     global inlines
   40     for l in infile:
   41         yield l
   42         inlines += 1
   43 
   44 instream = readinput (open (infile))
   45 if infile == outfile:
   46     replace = True
   47     outfile = "nccstriptmp"
   48 else:
   49     replace = False
   50 
   51 write = open (outfile, "w").write
   52 def output (x):
   53     global outlines
   54     outlines += 1
   55     write (x + "\n")
   56 
   57 for i in instream:
   58     if i [0] == '#':
   59     continue
   60     if i [0] == 'D':
   61     getsub (i[:-1], 'FgGsS')
   62     elif i [0] == 'P':
   63     getsub (i[:-1], 'YL')
   64     else:
   65     output (i[:-1])
   66 
   67 if inlines:
   68     print "nccstrip: -%.2f%%"% ((inlines - outlines) * 100.0 / inlines)
   69 if replace:
   70     import os
   71     os.rename ("nccstriptmp", infile)