http://www.perlmonks.org?node_id=962122


in reply to S simple C checking script

Are you sure you are not over-extending the request of your friend?

Looking at the content is difficult:

The idea to compile the file to see if it runs will also lead to problems: Therefore I would just look at the extensions .c and .h (and possible additional relevant extensions for your domain).

HTH, Rata

Replies are listed 'Best First'.
Re^2: simple C checking script
by heatblazer (Scribe) on Mar 28, 2012 at 09:30 UTC

    OK, then a combined check.. with first pass to be for .c and .h then maybe a compile check... well it`s a very scratch of code I typed for 1-2 mins it came in my head, there can be more additions like using C`s -Wall or maybe valgrind too but it becames complicated by parsing valgrind and yes, C++ can be build with gcc, but since C++ is an additon of C... I don`t know why parsing a C file rather than C++, actually, it`s no trivial task if he intends to do it in complete. Matching .c and .h could output any code inside it, java, perl, c++... what is stopping you writing javascript in .c file?

      I fear you will never get a solution that extracts all c-files, and no others... no matter how hard you work.

      That's why you should spend more time with your friend first (as suggested by GrandFather):

      • how fault-tolerant should your solution be? (e.g. a 90%-detection-rate might be fine)
      • is it more desirable to have false positives (files wrongly classified being in C) of false negatives (C files that have been missed)?
      • what is the environment (how likely are people using "wrong" extensions, e.g. a perl-script in a .c-file)
      • how fast should your solution be? (e.g. is it acceptable to do a lot of plausi-checks on that hundreds of 20-MB-.cpp-files to ensure that none of them is in reality C?)
      In my experience, the time used to understand the use-case of your customer and to investigate with him where it is possible to "cut corners" is well invested. It will give you the possibility for easier solutions, and lead to higher customer satisfaction. And less change-requests afterwards ...

      HTH, Rata