Challenge in finding listing class method and its number of code lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Challenge in finding listing class method and its number of code lines
# 1  
Old 08-22-2015
Challenge in count number of code line for every method inside list of files

there are about 300 objectivec .m files and I need to print each file name and its method and number of lines inside the method

there is a sample perl files that do perl brace matching
www_unix_com/shell-programming-and-scripting/145336-multiline-parenthesis-matching-e-g-sed-script-latex-doc.html

now I want to convert this to count number of lines in method
Code:
perl -0ne 's/\\emph{//g;$i=0;while(/./gs){$i-- if $& eq "{";$i++ if $& eq "}"; if ($i<1){print $&}else{$i=0}}' infile > outfile




============= Sample Input =================
Code:
#import "NSArray+ObjectiveSugar.h"
#import "NSMutableArray+ObjectiveSugar.h"
#import "NSString+ObjectiveSugar.h"

static NSString * const OSMinusString = @"-";

@implementation NSArray (ObjectiveSugar)

- (id)sample {
    if (self.count == 0) return nil;

    NSUInteger index = arc4random_uniform((u_int32_t)self.count);
    return self[index];
}

- (id)objectForKeyedSubscript:(id)key {
    if ([key isKindOfClass:[NSString class]])
        return [self subarrayWithRange:[self rangeFromString:key]];

    else if ([key isKindOfClass:[NSValue class]])
        return [self subarrayWithRange:[key rangeValue]];

    else
        [NSException raise:NSInvalidArgumentException format:@"expected NSString or NSValue argument, got %@ instead", [key class]];

    return nil;
}

- (NSRange)rangeFromString:(NSString *)string {
    NSRange range = NSRangeFromString(string);

    if ([string containsString:@"..."]) {
        range.length = isBackwardsRange(string) ? (self.count - 2) - range.length : range.length - range.location;

    } else if ([string containsString:@".."]) {
        range.length = isBackwardsRange(string) ? (self.count - 1) - range.length : range.length - range.location + 1;
    }

    return range;
}

=========== Sample Output==============
Code:
filename.m
- (id)sample -- 3 (line of code count)
- (id)objectForKeyedSubscript:(id)key -- 7 (line of code count)
- (NSRange)rangeFromString:(NSString *)string  -- 7 (line of code count)

Moderator's Comments:
Mod Comment Please use CODE tags (not ICODE tags) for full line and especially for multiline sample input, output, and code segments.

Last edited by Don Cragun; 08-22-2015 at 06:54 PM.. Reason: Change ICODE tags to CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python (seleniumrequests)Class, Constructor, Method Not Working

Newbie question. I created a class: class WP(seleniumrequests.PhantomJS): def __init__(self, wpurl='https://blah.org/download/release-archive/', bwppurl='https://blah.org/plugins/browse/popular/'): self.wp=wpurl ... (5 Replies)
Discussion started by: metallica1973
5 Replies

2. Shell Programming and Scripting

Finding if my IP address belongs in a Class C group

I need help with a tcl code. I have a variable "myIP" which reads IP address from socket. How do I use regex to find out if it belongs to a group for e.g., 50.65.75.240/28 or 50.65.75.128/25 etc. (2 Replies)
Discussion started by: ampak
2 Replies

3. Shell Programming and Scripting

How to replace a text containing new lines using sed or any other method?

Hi, i want to replace "Hi How are You when did you go to delhi" to "Hi How are you when did you come from delhi" in a file. Any idea how to do it? (2 Replies)
Discussion started by: abhitanshu
2 Replies

4. UNIX for Dummies Questions & Answers

Finding numbers in lines with strings and number and doing some manipulation

Hi, I want to write a script that does something like this: I have a file, in which in every line, there is a string of words, and followed by some space, a number. Now, I want to identify the line, which has the largest startFace number (say m=8118), take that number and add it to the... (2 Replies)
Discussion started by: super_commando
2 Replies

5. Shell Programming and Scripting

Automating a Challenge/Response Method.

Hi guys, I will need some help with a to automate a challenge/response sequence when I try to SCP files from a server to another. The scenario is like this : After selecting in a script the option to send files via scp (case switch): I get this output from linux term: The... (4 Replies)
Discussion started by: REX:)
4 Replies

6. Shell Programming and Scripting

How do I number my for loop outputs with this method?

Currently I am outputting users and I want to number them starting with 1... grep name list.txt | awk -F"=" '{ print $2 }' | while read user; do echo -e "1\t|$user" Currently I have: 1 | john 1 | amy 1 | max I want it to look like 1 | john 2 | amy 3 | max (2 Replies)
Discussion started by: etranman1
2 Replies

7. Shell Programming and Scripting

Finding lines matching the Pattern and their previous lines in a file

Hi, I am trying to locate the occurences of certain pattern like 'Possible network disconnect' in a text file. I can get the actual lines matching the pttern using: grep -w 'Possible network disconnect' file_name. But I am more interested in getting the timing of these events which are... (7 Replies)
Discussion started by: sagarparadkar
7 Replies

8. Shell Programming and Scripting

Reading n number of lines after finding string

I am trying to search a file for a value: "Top 30 reject reasons" and want the next 30 lines after that and output in a text file. If I knew the line number, I can use a combination of head and tail commands to get my results, but this doesn't seem to work when I don't have a line number. I... (2 Replies)
Discussion started by: oriqin
2 Replies

9. Shell Programming and Scripting

Removing lines from large files.. quickest method?

Hi I have some files that contain be anything up to 100k lines - eg. file100k I have another file called file5k and I need to produce filec which will contain everything in file100k minus what matches in file 5k.. ie. File100k contains 1FP 2FP 3FP File5k contains 2FP I would... (2 Replies)
Discussion started by: frustrated1
2 Replies

10. UNIX for Dummies Questions & Answers

ls command for listing the number of files

I've searched the man page for an option for the ls command to print the number of files in a directory. I'm moving files and folders around and thought a count of files would be a quick way to determine if I was missed one somewhere. Some "unix's" shells do this I think... maybe linux... ... (4 Replies)
Discussion started by: jimmyc
4 Replies
Login or Register to Ask a Question