Giter VIP home page Giter VIP logo

removeccomments's Introduction

behavior

  1. C style comment that span multi-line or occupy entire line gets zeroed out.
  2. C style comment in the middle of a line remain unchanged. eg, void init(/* do initialization */) {...}
  3. C++ style comment that occupy entire line gets zeroed out.
  4. C string literal being respected, via checking " and \".
  5. handles line-continuation. If previous line ending with \, current line is part of previous line.
  6. line number remain the same. Zeroed out lines or part of line become empty.

testing & profiling

I tested with two largest cpython source code that contains many comments. Below is sorted output of:

cd ~/code/cpython && wc $(find . -regex '.*\.[hc]\(pp\)?') | sort -g
 14075    38036   370246 ./Modules/posixmodule.c
 15702    47118   465001 ./Objects/unicodeobject.c
 28377   421265  2100240 ./Modules/unicodename_db.h
556670  2125917 19079596 total     3.8.0a0 2018-11-30

in this case it do the job correctly and fast, 2-5 faster than gcc

time gcc -fpreprocessed -dD -E Modules/unicodeobject.c > res.c 2>/dev/null
    # https://stackoverflow.com/questions/2394017/remove-comments-from-c-c-code
time ./removeccomments < Modules/unicodeobject.c > result.c

install

gcc -O3 removeccomments.c -o dest_path_name

usage

/path/to/removeccomments < input_file > output_file

summary

  • this program correctly remove comments in C source code, handling C string literal and line-continuation.

  • do not add or delete lines, only empty lines that are comment. Output of diff old new is minimal.

removeccomments's People

Contributors

qeatzy avatar

Watchers

 avatar

Forkers

artsra

removeccomments's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.