Search for patterns in source code

This is a discussion on Search for patterns in source code within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I am using Visual Studio 6.0 and code is in C/C++. Commercial software with over 2000 source files scattered all ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    13

    Search for patterns in source code

    I am using Visual Studio 6.0 and code is in C/C++. Commercial software with over 2000 source files scattered all over. Trying to get a handle on doing some estimates on various tasks.

    Is there a way in VS6.0 that allows one to do "Find In Files..." with some complex search criteria?

    For example, I would like to search for lines in files that contains the string "alloc" or "malloc" or "calloc" or "realloc" which does NOT contain the string "sizeof". Is there a way to do this?

    I also would like to have a line count (how many lines are there in all these files when the search pattern matches), and a file count (how many files do these lines occured in).

    If they can be configures to ignore lines that preceeds with "//" or in the middle of a /*...*/ block or even inside of a #if 0 ... #endif even better.

    This is just one example, I need to do dozens of different searches to make an assessment on how bad the code is and decide whether we hack/patch or refactor or whatever.

    Also we use CVS source code control which creates a admin directory with duplicate code that will double the count, is there a way to "include subfolder" but not to include subfolders of a specific name?

    Thanks,

    MC

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    For example, I would like to search for lines in files that contains the string "alloc" or "malloc" or "calloc" or "realloc" which does NOT contain the string "sizeof". Is there a way to do this?
    Try grep or perl or something similar.

    I also would like to have a line count (how many lines are there in all these files when the search pattern matches), and a file count (how many files do these lines occured in).
    I'm pretty sure you can do that with grep/perl.

    If they can be configures to ignore lines that preceeds with "//" or in the middle of a /*...*/ block or even inside of a #if 0 ... #endif even better.
    That's easy, too, in perl.

    is there a way to "include subfolder" but not to include subfolders of a specific name?
    You should be able to manage that, too.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    13
    There is no way to do this within VS6? One benefit of doing it in that environment is I can pull up files selectively from the search results.

  4. #4
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    In my VS.NET's "Find In Files...," you could select whether to use Regular Expression. Consult the VS6 help file if you could do the same thing.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a program that prints it's own source code???
    By chottachatri in forum C++ Programming
    Replies: 38
    Last Post: 03-28-2008, 07:06 PM
  2. Replies: 4
    Last Post: 01-18-2008, 06:05 PM
  3. Documenting Source Code
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 01-04-2008, 11:18 AM
  4. DxEngine source code
    By Sang-drax in forum Game Programming
    Replies: 5
    Last Post: 06-26-2003, 05:50 PM
  5. Lines from Unix's source code have been copied into the heart of Linux????
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 05-19-2003, 03:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21