一个python写的去c语言注释的小脚本详解编程语言

    #!/usr/bin/python   
       
    import sys   
       
    input = sys.argv[1]   
       
    fp = open(input,"r")   
       
    flag = 0   
    quote = 0    
       
       
    for line in fp:   
        myline = ""   
        length = len(line)   
        for index in range(length):   
            if flag == 0 and quote == 0 and line[index] == "/"":   
                quote = 1   
                myline += line[index]    
                continue   
            if flag == 0 and quote == 1 and line[index] == "/"":   
                quote = 0   
                myline += line[index]   
                continue   
            if quote != 1 and flag == 2 and line[index] == "/n":   
                flag = 0   
            if quote != 1 and flag == 0 and line[index] == "/" and line[index+1] == "*":   
                flag = 1   
            if quote != 1 and index > 0 and flag == 1 and line[index-1] == "/" and line[index-2] == "*":   
                flag = 0   
            if quote != 1 and flag == 0 and line[index] == "/" and line[index+1] == "/":   
                flag = 2   
            if flag == 1 or flag == 2:   
                continue   
            myline += line[index]   
        print myline,   
           
    fp.close()  

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/8457.html

(0)
上一篇 2021年7月18日
下一篇 2021年7月18日

相关推荐

发表回复

登录后才能评论