Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: simple C checking script

by Ratazong (Prior)
on Mar 28, 2012 at 09:22 UTC ( #962122=note: print w/ replies, xml ) Need Help??


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:

  • not every C-file needs main()
  • not every C-file includes stdio.h
The idea to compile the file to see if it runs will also lead to problems:
  • what if it is a C-file, which however contains a syntax-error? Probably it should be listed nevertheless...
  • what if the C-file needs some non-standard compile options (and compiling fails if you don't provide them?)
  • what if it is a simple C++ - program/file, which however compiles with C?
Therefore I would just look at the extensions .c and .h (and possible additional relevant extensions for your domain).

HTH, Rata


Comment on Re: simple C checking script
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://962122]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-09-16 15:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (33 votes), past polls