Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] Re: (PR#12643) Unify comments for gui specific client func
Home

[Freeciv-Dev] Re: (PR#12643) Unify comments for gui specific client func

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#12643) Unify comments for gui specific client functions
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Sun, 3 Apr 2005 06:47:07 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12643 >

On Fri, Mar 25, 2005 at 09:52:12AM -0800, Raimar Falke wrote:

The previous patch updated the gui-stub comments. This patch copies
these comments to all places where they are needed.

The script is also attached.

        Raimar

-- 
 email: i-freeciv-lists@xxxxxxxxxxxxx
  +#if defined(__alpha__) && defined(CONFIG_PCI)
  +       /*
  +        * The meaning of life, the universe, and everything. Plus
  +        * this makes the year come out right.
  +        */
  +       year -= 42;
  +#endif
    -- Patch for 1.3.2 (kernel/time.c) from Marcus Meissner

Attachment: sync_comments_with_stub1.diff.bz2
Description: Binary data

Attachment: header_copy.sh
Description: Bourne shell script

import sys,re

startpat='(?s).*\n(/[*]{30,80}\s*\n.*)$'
endpat='^(?s).*\n[*]{30,80}/\s*$'

class Entry:
    def __init__(self,groups):
        self.name,self.type,self.line,self.file,self.sig=groups
        self.descr=self.name+"("+self.file+":"+self.line+")"
        if self.sig.find("static")!=-1 and self.sig.find("inline")==-1:
            self.static=1
            self.descr="static "+self.descr
        else:
            self.static=0
    def is_c_function(self):
        if not re.search(r"^.*\.[ch]",self.file): return 0
        assert self.type in ["function","macro","class"],repr(self.type)
        return self.type=="function"

def classify(l):
    m={}
    for i in l:
        m[i]=0
    keys=m.keys()
    toname={}
    for i in range(len(keys)):
        toname[keys[i]]=chr(ord("A")+i)
    for i in l:
        m[i]+=1
    c={}
    for i in keys:
        c[toname[i]]=m[i]
    if 0:
        print l
        print m
        print toname
        print c
        assert 0
    return toname,c

def box(s):
    s=s.split("\n")
    s=map(lambda x:"  |%s%s|"%(x,' '*(76-len(x))),s)
    s="\n".join(s)
    t="  +"+"-"*76+"+\n"
    s=t+s+"\n"+t
    return s          

def new_comment(c):
    dots="*"*74
    return "/%s\n%s\n%s/\n"%(dots,c,dots)

functions={}

for line in sys.stdin.readlines():
    mo=re.search("^(\S*)\s+(\S*)\s+(\d*)\s+(\S*)\s(.*)$",line)
    assert mo
    entry=Entry(mo.groups())
    if not entry.is_c_function(): continue
    if entry.static: continue
    
    descr=entry.descr
    
    lines=open(entry.file).readlines()[:int(entry.line)]
    lines=map(lambda x:x.rstrip(),lines)
    # delete the line with the signature
    sig2=lines[-1]
    del lines[-1]

    lines="\n".join(lines).strip()
    while 1:
        found=0
        for i in ["void","static","GtkType","GType","gboolean",
                  "GtkWidget*","const", "char **","gint",
                  "struct city*"]:
            if lines.endswith(i):
                lines=lines[:-len(i)].strip()
                found=1
        if not found:
            break
    
    if not re.search(endpat,lines):
        entry.short_comment="none"
        l=lines.split("\n")[-1]
        if l in ["}","};"] or l[-1] in ";}" or l.endswith("*/") or l[0]=="#":
            pass
        else:
            #print descr+" has no comment"
            #print l
            #print
            pass
        continue

    mo=re.search(startpat,lines)
    assert mo
    raw_comment=mo.group(1)
    lines2=raw_comment.split("\n")[1:-1]
    if len(lines2)==1 and re.search("^\s*[.]*\s*$",lines2[0]):
        entry.short_comment="empty"
    else:
        entry.short_comment="real one"
        entry.comment="\n".join(lines2)
        
    if not functions.has_key(entry.name):
        functions[entry.name]=[]
    functions[entry.name].append(entry)

fnames=functions.keys()
fnames.sort()

for fname in fnames:
    fl=functions[fname]

    stub=None
    for e in fl:
        if e.file.find("gui-stub")!=-1:
            stub=e
            if stub.short_comment!="real one":
                print fname,stub.short_comment,stub.descr
                assert 0
            break
    if not stub: continue
    fl.remove(stub)

    todo=[]
    for e in fl:
        same=(e.short_comment=="real one" and stub.comment==e.comment)
        if same: continue
        todo.append(e)

    if not todo: continue

    print fname
    for e in todo:
        print "  ",e.file
        
        file=open(e.file)
        content=file.read()
        file.close()

        a,b=content.split(e.sig)
        a=a.rstrip()

        #print "old end of a",len(a),a[-50:]
        assert a.endswith("******/")

        a=a[:a.rfind("/*")]
        #print "new end of a",len(a),a[-50:]

        a=a+new_comment(stub.comment)

        newcontent=a+e.sig+b

        if newcontent!=content:
            print "    CHANGE in %s"%e.file
            file=open(e.file,"w")
            file.write(newcontent)
            file.close()
        else:
            print "    no change in %s"%e.file
        
        #assert 0

    print

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#12643) Unify comments for gui specific client functions, Raimar Falke <=