Skip to content

Instantly share code, notes, and snippets.

@wolf0403
Last active December 16, 2015 05:38
Show Gist options
  • Save wolf0403/5385439 to your computer and use it in GitHub Desktop.
Save wolf0403/5385439 to your computer and use it in GitHub Desktop.
No comments
#!/usr/bin/env python
import sys, re
from getopt import getopt
'''
Just too lazy figuring out egrep alone, so...
$ ./nocomment.py proc_line < md.c
proc_line (char *line, unsigned len, struct session_args *a) {
$ ./nocomment.py '.*proc_line' < md.c
proc_line (char *line, unsigned len, struct session_args *a) {
int n = proc_line (nextproc, linelen, a);
if (n < linelen) { // proc_line error
int n = proc_line (nextproc, len, a);
int n = proc_line (nextproc, linelen, a);
$ /usr/bin/grep proc_line md.c
proc_line (char *line, unsigned len, struct session_args *a) {
//_dumpnstr (line, len, "proc_line");
//_dumpnstr ("\nproc\n", 6, "proc_line");
//int n = proc_line (a->internal_buf, bufsz, a);
int n = proc_line (nextproc, linelen, a);
if (n < linelen) { // proc_line error
// proc_line next time
int n = proc_line (nextproc, len, a);
int n = proc_line (nextproc, linelen, a);
'''
opts, args = getopt(sys.argv[1:], 'n')
optn = filter (lambda t:t[0] == '-n', opts)
printlineno = len(optn) == 1
if len(args) > 0:
p = re.compile(args[0])
else:
p = re.compile('.*')
lineno = 0
for line in sys.stdin:
lineno += 1
#print lineno, line
l = line.strip()
if (not l.startswith ('//')) and p.match(line) is not None:
print lineno if printlineno else '', line,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment