Search for Pattern using Java

hello friends,
I am trying to read a 'C' file and trying to look for all the lines in the 'C' cod, wherever a function call has happened. How could I do that ??
Thanks
ashu

import java.io.*;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.*;
class FileParser{
    Scanner sc;
    FileParser(String fileName)throws FileNotFoundException{
     sc = new Scanner(new File(fileName));
    void getFunctions(){
     //sc.findInLine("([a-zA-Z]+) (\p{Punct})");
     sc.findInLine("");
     MatchResult result = sc.match();
     //for (int i=1; i<=result.groupCount(); i++)
        // System.out.println(result.group(i));//typo in API
     //System.out.println(result.group(1));
     //System.out.println(result.group(2));
    void getLoops(){
     //Search for patterns FOR, WHILE, DO-WHILE
     sc.findInLine("void");
     MatchResult result = sc.match();
     for (int i=0; i<=result.groupCount(); i++)
         System.out.println(result.group(i));
     /*     sc.findInLine("main");
     result = sc.match();
     for (int i=0; i<=result.groupCount(); i++)
         System.out.println(result.group(i));
     sc.findInLine("void");
     result = sc.match();
     for (int i=0; i<=result.groupCount(); i++)
         System.out.println(result.group(i));
    //Search for pattern FOR
    void getForLoops(){
    //Search for pattern WHILE
    void getWhileLoops(){
    //Search for pattern DO-WHILE
    void getDoWhileLoops(){
    //Search for Union
    //Search for Struct
}I have added/deleted stuff to try all the different combinations. This class basically will have methods to ....
1) Get a List of Function Calls with Line# in 'C' code
2) Get a List of Loops with Line# in 'C' code
import java.io.*;
class TestScan{
    public static void main(String[] args)throws IOException{
     FileParser fp = new FileParser("main.c");
     //     fp.getFunctions();
     fp.getLoops();
}Message was edited by:
ashucool83

Similar Messages

  • Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this?  FYI...under settings i

    Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this?  FYI...under settings i

    If you are missing using google maps - try the Nokia map app called "here"

  • Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this? FYI...under settings i have it set at "Use new precise locations from my device."

    Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this? FYI...under settings i have it set at "Use new precise locations from my device."

    If you are missing using google maps - try the Nokia map app called "here"

  • Search for images using Keywords Problem.

    1) In LR4, Search for images using Keywords (click on arrow next to Keyword).
    2) Select image, export to PS6, save as Tif.
    3) Tif retains all Keywords when it appears in LR
    4) Despite that, image does not show up in the same 'Search for images using Keywords'.
    Can anyone help with this, it is frustrating me!

    V. 4.1
    Thanks, I will try, but it seems to be an inconsistent problem.
    Simon Fletcher
    Simon Fletcher Photography
    Woody's Nest
    Newton of Kinkell
    by Conon Bridge
    Ross-shire
    Scotland
    UK  IV7 8AS
    Tel: 01 349 864 830
    Web: www.simonfletcherphotography.co.uk
    Work:
    The Glass Scribe
    Tel: 01 349 867 088
    Email: [email protected]
    Web: www.glassscribe.com

  • We have a requirement to print the w2 forms for employees using java application, how can i implement this. Please give some suggestion.

    We have a requirement to print the w2 forms for employees using java application, how can i implement this. Please give some suggestion.

    Anyone any ideas to help please?

  • How to Modify Search for Leads using Date types in the Assgmnt Block Date

    Hello Experts,
    I have a requirement to modify the search for Leads using Dates in the Assignment Block Dates and using the Posting Date of the transaction.
    Any ideas?
    Thank you in advance,
    Justin

    If you look at the grants, you'll see that there are over 170 objects from the FLOWS_030000 granted to PUBLIC:
    SQL> select count(*) from dba_tab_privs where owner= 'FLOWS_030000' and grantee = 'PUBLIC';
    173
    If we were go grant these privileges to a role, called APEX_APP_RU, and grant this role to APEX_PUBLIC_USER and any schemas an application is linked to (Workspace to Schema), would that be a workable solution?
    The only problem I see right off hand that this might not work is that PUBLIC has synonyms created for the FLOWS_030000 objects. If we revoke the underlying privileges, because of the synonyms, this might not work.
    SQL> select COUNT(*) from dba_synonyms where table_owner = 'FLOWS_030000' and owner = 'PUBLIC';
    176
    Does anyone else have any ideas?

  • How to search for files using wildcards * and ?.

    Hi All,
    I've been searching the forum for a couple of hours now and have been unable to find a good example of how to search a directory (Windows OS) for a file using wildcards * and/or ?. Does anyone out there have a good example that they can share with me?
    Thanks

    Hi All,
    First of all I want to thank everyone for taking the time to respond to my question. All of your responses where greatly appreciated.
    I took the example code that was posted by rkconner, thanks rkconner, and modified it to allow me to search for files in a directory that contain * and/or ?. Yes, I said and/or! Meaning that you can use them both in the same file name, example: r??d*.t* would find readme.txt.
    I've posed my complete and thoroughly document code below. I hope it is very helpful to other as I have searched many forums and spent many hours today trying to resolve this problem.
    Enjoy
    * File Name: WildcardSearch.java
    * Date: Jan 9, 2004
    * This class will search all files in a directory using the
    * asterisk (*) and/or question mark (?) as wildcards which may be
    * used together in the same file name.  A File [] is returned containing
    * an array of all files found that match the wildcard specifications.
    * Command line example:
    * c:\>java WildcardSearch c:\windows s??t*.ini
    * New sWild: s.{1}.{1}t.*.ini
    * system.ini
    * Command line break down: Java Program = java WildcardSearch
    *                          Search Directory (arg[0]) = C:\Windows
    *                          Files To Search (arg[1]) = s??t*.ini
    * Note:  Some commands will not work from the command line for arg[1]
    *        such as *.*, however, this will work if you if it is passed
    *        within Java (hard coded)
    * @author kmportner
    import java.io.File;
    import java.io.FilenameFilter;
    public class WildcardSearch
         private static String sWild = "";
          * @param args - arg[0] = directory to search, arg[1] = wildcard name
         public static void main(String[] args)
              String sExtDir = args[0]; // directory to search
              sWild = args[1];   // wild card to use - example: s??t*.ini
              sWild = replaceWildcards(sWild);
              System.out.println("New sWild: " + sWild);
              File fileDir = new File(sExtDir);
              File[] arrFile = fileDir.listFiles(new FilenameFilter()
                   public boolean accept(File dir, String name)
                        return (name.toLowerCase().matches(sWild));
              for (int i = 0; i < arrFile.length; ++i)
                   System.out.println(arrFile.getName());
         }     // end main
         * Checks for * and ? in the wildcard variable and replaces them correct
         * pattern characters.
         * @param wild - Wildcard name containing * and ?
         * @return - String containing modified wildcard name
         private static String replaceWildcards(String wild)
              StringBuffer buffer = new StringBuffer();
              char [] chars = wild.toCharArray();
              for (int i = 0; i < chars.length; ++i)
                   if (chars[i] == '*')
                        buffer.append(".*");
                   else if (chars[i] == '?')
                        buffer.append(".{1}");
                   else
                        buffer.append(chars[i]);
              return buffer.toString();
         }     // end replaceWildcards method
    }     // end class

  • Any way to search for casts in java source code?

    Anyone know of a decent way to search your java source files to find all the casts?
    I ended up doing a simple text search for
         " = ("(quote marks not included) which works for my code because I am strict about writing my casts with spaces like
         String s = (String) iterator.next();Unfortunately, the above search has all kinds of problems with both false positives and negatives. It picks up lots of irrelevant lines like
         int index = (number > 0) ? 0 : 1;as well as misses casts that appear nested inside expressions like
         ((String) iter.next()).charAt(...)I suppose that one could do a regular expression search for any pair of open and close parens which bound non-blank text, but that would pick up even more non-cast expressions in typical java code.
    I think that the only way to properly do this is to have a tool which understands java syntax.
    Anyone know of an IDE which will do this? Does IntelliJ or Netbeans support this kind of search?
    In case you are wondering why I am interested in this, it is because I am refactoring some code to fully use generics, and searching for casts is one source of identifying candidates for genericity.

    cliffblob wrote:
    Better late than never?Yes!
    cliffblob wrote:
    ...The answer I found to ID unnecessary casts was, using Eclipse IDE, In compiler error and warning preferences to warn on unnecessary casts.Thanks for pointing IDEs out. I just opened IntelliJ, and going back to at least version 7.04 (maybe earlier) they have an inspection for "Redundant type cast".
    cliffblob wrote:
    I would still be interested to know if there is a way to identify casts in general in your source, perhaps now four years later there is a way?The only solutions that I can think of are either a complicated regex search, or you must use some tool like an IDE that understand Java syntax and can determine if a cast is happening.

  • Search Measurement field using Java APIs

    Hi All
    I have a measurement field in the repos, which has to be searched using Java APIs. Can you please put in the code to search a measurement field using Java APIs
    Thanks
    Suresh

    HI,
    I have the following environments.
    - SAP Portal 7.01 SP5
    - SAP MDM 7.1 SP3
    - SAP NWDS 7.01.05
    --> I created a Development Component of Type "External Library" and add all MDM Jars in library folder, created Public Parts for Compilation & Assembly with both Build Time & Run Time.
    --> Created a new Development Component of Type J2EE Server Component (Library) and add the above two Public Parts as used DCs with only Build Time. Deployed this project in Portal Server (I can see the MDM Jars files when i view the project in Visual Administrator)
    --> Created a new Development Component of Type WEBDYNPRO, and add the above J2EE Server Component DC as a Used DC with Build Time only. Add an entry under Library References for the above J2EE DC. Build the project and deployed in Portal. When i run the project, i get "NoClassDefFoundException".
    We downloaded MDMJ71003_13-10006189.zip from Service Marketplace in which u201Cmdm-api-7.1.03.62-java1.4.2.zipu201D has MDM Jars.
    Could any one please help me? Your help is really appreciated.
    Thanks
    Vijay Budati

  • Searching for songs using v1.2

    I just got v1.2 iPod software and I saw the Special Keynote video on Quicktime. Jobs mentioned the ability to search for a song inside the iPod while using it. How do you do that?

    Just an FYI... the 5.5 designation is not officially used by Apple.
    That is a classifaction made up by the user base and could potentially cause some confusion.
    Apple designates the new 5th Gen iPod models as (Late 2006), not 5.5.
    Identifying different iPod models

  • Searching for un-used files

    Our Marketing department is close to maxing out 5.5 TBs of disk on our Xraid. Is there a way to search on files that have not been read in "x" number of days (likely a search that would show files that have not read before a particular date)?
    I'm using the term "read" because we likely have many older files (image files) that have an older Created or Modified date, but are read for printing, PDF creation and collecting for print and will need to be retained. I just want to locate the files that have not been touched in 18 months, including read for creating a PDF or printing.

    If your volume is indexed via spotlight, you might be able to pull this off. I said might. You really must test this because you are asking for if the file is "Read." The challenge here is that I am not sure if Spotlight will update a file that is read as compared to a file that is opened. So test this first. But, in theory, this might point you in the right direction.
    First, create or collect a bunch of sample files. Then start investigating those files using the mdls command. For example, if I have files titled one.txt, two.mov, and three.doc, I might get a result similar to this when using mdls one.txt:
    kMDItemContentCreationDate = 2009-06-24 17:05:15 -0400
    kMDItemContentModificationDate = 2009-06-24 17:05:32 -0400
    kMDItemContentType = "dyn.ah62d4rv4ge80g55sq2"
    kMDItemContentTypeTree = (
    "public.data",
    "public.item"
    kMDItemDisplayName = "one.txt"
    kMDItemFSContentChangeDate = 2009-06-24 17:05:32 -0400
    kMDItemFSCreationDate = 2009-06-24 17:05:15 -0400
    kMDItemFSCreatorCode = ""
    kMDItemFSFinderFlags = 0
    kMDItemFSHasCustomIcon = 0
    kMDItemFSInvisible = 0
    kMDItemFSIsExtensionHidden = 0
    kMDItemFSIsStationery = 0
    kMDItemFSLabel = 0
    kMDItemFSName = "one.txt"
    kMDItemFSNodeCount = 0
    kMDItemFSOwnerGroupID = 20
    kMDItemFSOwnerUserID = 501
    kMDItemFSSize = 23
    kMDItemFSTypeCode = ""
    kMDItemKind = "Document"
    kMDItemLastUsedDate = 2009-06-27 08:39:44 -0400
    kMDItemUsedDates = (
    2009-06-24 00:00:00 -0400,
    2009-06-27 00:00:00 -0400
    Ok, so you have some attributes that are based on time displayed in the results (kMDItemContentCreationDate , kMDItemFSContentChangeDate, kMDItemContentModificationDate, kMDItemFSCreationDate, and kMDItemLastUsedDate). The one that may provide what you are looking for is kMDItemLastUsedDate. This attribute will update each time a file is opened. Here is where the "read" part of your question comes in. I am guessing you are supporting the creative industry, likely desktop publishing. You have documents that point to images. Many never change but are used all the time. That being the case, I did not test to see if kMDItemLastUsedDate updates on an InDesign place or collect. I will let you test that.
    If this works, then you can use mdfind to find files older than 7 days old. Here is how you do it:
    mdfind -onlyin /Path/to/data 'kMDItemLastUsedDate <= $time.today(-7)'
    The structure here is simple. Tell mdfind to look only in /Path/to/data (set this to your real path) and search for any file whose kMDItemLastUsedDate attribute is less than or equal to 7 days old (increase or decrease the number as needed).
    This will produce a list of files. With a little shell scripting you can take the list and then act on it. ie: move the files, archive them, etc.
    As mentioned, you need to test your specific condition. I am curious to know if a place or update links will trigger an update to kMDItemLastUsedDate.
    Hope this helps.
    Message was edited by: Strontium90

  • How to search for folders using jsp ( or any other way)?

    Hey All,
    It's my first time writing here and i hope i can get some help ... i have created a payroll system using java and jsp techniques and mysql as the database, i want to create a backup page that will let the use to choose the destination folder for the back up, the backup is basically a mysqldump command that will get the destination folder as an argument and create the sql file there. the problem is i couldn't find anyway to let the user browse his local machine and choose the folder , which in returns return the folder path to be used in mysqldump....
    I know that html have <input type=file> but it's used for selecting file not folder...
    can someone come up with a solution for me coz it's urgent and i have to finish the project by the end of this week.,.
    peace!

    Also you can use an OUTPUT clause ( need to modify your DML operations)
    create table itest ( i int identity not null primary key, j int not null unique )
    create table #new ( i int not null, j int not null)
    insert into itest (j)
    output inserted.i, inserted.j into #new
    select o.object_id from sys.objects as o
    select * from #new
    drop table #new, itest;
    go
    The example below shows code that uses OUTPUT clause in UPDATE and DELETE statements to insert rows into an audit table.
    create table t ( i int not null );
    create table t_audit ( old_i int not null, new_i int null );
    insert into t (i) values( 1 );
    insert into t (i) values( 2 );
    update t
       set i  = i + 1
    output deleted.i, inserted.i into t_audit
     where i = 1;
    delete from t
    output deleted.i, NULL into t_audit
     where i = 2;
    select * from t;
    select * from t_audit;
    drop table t, t_audit;
    go
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Search for customer using KNB1-ALTKN

    Hi All,
    I have my customers loaded in a new server with reference to old server, by mapping the olad customer under the field   KNB1-ALTKN, ( at company code data level).
    I use ECC 6.0 where i dont find this field when i search the customers using F4 in VD03, can this be amended so that i can search the new customers by keying in this previous customer number field, if so please let me know on the steps involved.
    Thanks & regards
    Ilango

    I hope you are aware that Table KNB1 is table Customer Master u2013 Company Code Data.
    1. Check the field KNB1-ALTKN in XD01/FD01 in company code data instead VD01.
    2. If the field is not available in XD01/FD01. Then check Account Groups with screen layout - select the Group - select company code data - select Account management - Previous account number, based on your requirement maintain the display of the field.
    Further you can user exit EXIT_SAPMF02D_001 for populating this field automatically.
    Regards
    JP

  • Search for row using BindingContainer

    my issue is create custom search field read user input
    then i want to use this input to iterate view object in JSF page
    to find matched record

    @https://community.oracle.com/people/Michael%20Shapira Your code does not work if the vo only has Inge record.
    @mbonga you should not iterate over all record in an iterator or vo. Think about what happens if your vo has 100000 rows. As each route gets read into memory you will see out off memory errors at some point. Then it's consuming time to read through all rows, and you can't be sure that you find the row. A better approach is to let the db search for the right row as this is what the db is optimized for. For this you can use a view criteria which returns the row you are looking for out null if the row isn't found.
    Timo

  • Does Firefox for Android use Java?

    Does it use Java? If so, how can Java be disabled or uninstalled?

    Oracle doe not make the Java plug-in for Android due to Oracle's lawsuit against Google which of course is the developer of Android.

Maybe you are looking for

  • Report Designer error i VS 2013 - "Data at the root level is invalid."

    Hi, I am trying to create rdlc file programmatically. Using Memory Table as dataset. Here is my code ' For each field in the resultset, add the name to an array listDim m_fields AsArrayList   m_fields = NewArrayList()   Dim i AsIntegerFor i = 0 To tb

  • Print quality issues

    Hello We are having print quality issue when printing PDF's to our Canon iR C2880/C3380 UFR II.  This was the most recent print driver from canons website which was download about 6 weeks ago. version 2.9.  At one time we were having other pring qual

  • Mac will not boot up - stuck in safe mode

    Hi, my mac recently froze so I decided to hard-reset it in order to re-boot it quickly.  After it turned off, I tried to restart it but it sat on the grey screen with the spinning circle for at least 15 minutes, so obviously something is wrong. I loo

  • Audigy midi sync tempo is

    Hi, I have audigy zs 2. I'm using Nuendo as midi master and I'm trying to sync other software to its midi clock. There are 2 issues: -I cannot seem to be able to transmit midi clock and mtc through the standard audigy midi port -Using Midi Yoke ports

  • Sounds on Curve 8310

    I recently purchased a curve 8310. How do I set up different sounds for alerting me when I have a text message or a voice mail or anything other than a phone call?