'grep' source code available? 
Author Message
 'grep' source code available?

Does anyone know if there is PB/DLL or PB/CC source code for a 'grep'
utility available free or at low cost?

I looked on the PB Web Site and at basicguru.com (the ABC stuff) and found
nothing.

What I am looking for is to provide the functionality of the Windows
Explorer "Find Files containing text..." 'advanced' option available under
Win 98SE  so I can find files when I work on an NT, Win95 or Win98 "First
Edition".

I suppose I could write it, but A) why re-invent the wheel and B) I'm sure
someone has a better 'grep' engine than my first effort would be.

Thanks,
--
Michael Mattias
Tal Systems
Racine WI USA



Mon, 17 Feb 2003 22:47:59 GMT  
 'grep' source code available?
There are lots of 'grep' programs out there, but most of the ones I
have seen are in C. :-)
--

Sun Valley Systems    http://www.sunvaley.com
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."
Quote:

> Does anyone know if there is PB/DLL or PB/CC source code for a 'grep'
> utility available free or at low cost?

> I looked on the PB Web Site and at basicguru.com (the ABC stuff) and found
> nothing.

> What I am looking for is to provide the functionality of the Windows
> Explorer "Find Files containing text..." 'advanced' option available under
> Win 98SE  so I can find files when I work on an NT, Win95 or Win98 "First
> Edition".

> I suppose I could write it, but A) why re-invent the wheel and B) I'm sure
> someone has a better 'grep' engine than my first effort would be.



Tue, 18 Feb 2003 19:48:35 GMT  
 'grep' source code available?
Thanks for thinking about it. I found the same thing.

Oh, well, I guess I can write one. It goes on the list AFTER I finish my
VSAM DASD space estimator (all I need to do there is clean up the
documentation) and my new ANSI EDI unwrapper/summary report program (finish
front end and clean up report).

I have some MS-DOS code I wrote which at least has the working recursion
logic (at which I am not good) to handle the subdirectories, so I won't have
to{*filter*}with that again.

For now, I have a DOS-based grep called 'fgrep' (an excellent piece of
freeware written by
Chris Dunford); I guess I can fire up a DOS prompt and use that until I get
around to it.

Or, if I really want a Windows front end badly, I guess I could do a cheap
and dirty PB/DLL/DDT dialog box, SHELL "fgrep.com options > filename"   and
then SHELL "notepad.exe filename"  to read the output.
(Sheesh, would this qualify as 'coyote-ugly' or what?!!!)

--
Michael Mattias
Tal Systems
Racine WI USA


Quote:
> There are lots of 'grep' programs out there, but most of the ones I
> have seen are in C. :-)


> > Does anyone know if there is PB/DLL or PB/CC source code for a 'grep'
> > utility available free or at low cost?



Wed, 19 Feb 2003 20:54:40 GMT  
 'grep' source code available?


Quote:
> Does anyone know if there is PB/DLL or PB/CC source code for a 'grep'
> utility available free or at low cost?

> I looked on the PB Web Site and at basicguru.com (the ABC stuff) and found
> nothing.

> What I am looking for is to provide the functionality of the Windows
> Explorer "Find Files containing text..." 'advanced' option available under
> Win 98SE  so I can find files when I work on an NT, Win95 or Win98 "First
> Edition".

> I suppose I could write it, but A) why re-invent the wheel and B) I'm sure
> someone has a better 'grep' engine than my first effort would be.

Only a "command line" type GREP utility.  I thought I had uploaded it to
the powerbasic FTP site before I left, but if not, I can email it to
you.

--Dave



Fri, 28 Feb 2003 05:32:25 GMT  
 'grep' source code available?
I *thought* at some point there was a "pbgrep" somewhere, but I wasn't sure
if that was DOS or PB/CC, and I could not find the code anywhere.

If you put it on the FTP site, I can download it; if you don't, I accept
your generous e-mail offer. (Let me know if it's OK to post the whole thing
(e.g., on the PB Web BBS) with source after I add the UI).

--
Michael Mattias
Tal Systems
Racine WI USA


Quote:


> > Does anyone know if there is PB/DLL or PB/CC source code for a 'grep'
> > utility available free or at low cost?

> > I looked on the PB Web Site and at basicguru.com (the ABC stuff) and
found
> > nothing.

> > What I am looking for is to provide the functionality of the Windows
> > Explorer "Find Files containing text..." 'advanced' option available
under
> > Win 98SE  so I can find files when I work on an NT, Win95 or Win98
"First
> > Edition".

> > I suppose I could write it, but A) why re-invent the wheel and B) I'm
sure
> > someone has a better 'grep' engine than my first effort would be.

> Only a "command line" type GREP utility.  I thought I had uploaded it to
> the PowerBASIC FTP site before I left, but if not, I can email it to
> you.

> --Dave



Fri, 28 Feb 2003 20:00:43 GMT  
 'grep' source code available?


Quote:
> I *thought* at some point there was a "pbgrep" somewhere, but I wasn't sure
> if that was DOS or PB/CC, and I could not find the code anywhere.

> If you put it on the FTP site, I can download it; if you don't, I accept
> your generous e-mail offer. (Let me know if it's OK to post the whole thing
> (e.g., on the PB Web BBS) with source after I add the UI).

I don't have access to the PowerBASIC FTP site any longer (as an admin,
anyway).  So I can't upload it.

I'll email it to you.  The code can be posted on the PowerBASIC site
since it belongs to them anyway.  <grin>

--Dave



Sun, 09 Mar 2003 03:00:00 GMT  
 'grep' source code available?
'=======================================================================
'
'  PowerBASIC Text Search  & Replace Utility.
'  Copyright (c) 1995-97 by PowerBASIC, Inc.  All Rights Reserved.
'
'=======================================================================

$CPU 8086                 ' program works on any CPU
$COMPILE EXE              ' compile to an EXE

$ERROR ALL OFF            ' turn off error handling

$STRING 8                 ' set largest string size at 8k
$STACK  16384             ' use a 16k stack

$OPTION CNTLBREAK OFF     ' don't allow Ctrl-Break to exit program

$INCLUDE "PB35.INC"       ' link PB35 library

DEFINT A-Z                ' default all variables to integers for
maximum
                          ' speed and minimum size

'---------------------[ Constants & Variables ]------------------------

SHARED Expression$, Replacement$, TotFiles, Pause, NameOnly, CurLine
SHARED LineNumbers, Quit, TotalMatches, TotalReplace, CaseSense, Literal
SHARED NoBackup, NoAsk

DIM Filename$(1:500)

TotFiles    = 0
Temp        = 0

Pause       = %TRUE
NameOnly    = %FALSE
Quit        = %FALSE
CaseSense   = %FALSE
Literal     = %FALSE
LineNumbers = %TRUE
CurLine     = 1

'-------------------------[ Main Program ]-----------------------------

'Turn on the cursor
LOCATE ,,1

'Display program banner and copyright info
PRINT "PBGREP v3.5 t Text Search & Replace Utility"
PRINT "Copyright (c) 1995-97 PowerBASIC, Inc.  All Rights Reserved."
PRINT ""

'Display help if invalid number of parameters, and exit
IF ArgC(COMMAND$) < 2 THEN
  PRINT "  Usage:  PBGREP filespec expression [replace] [options]"
  PRINT ""
  PRINT "  Where:  filespec      Filespec to search (can include
wildcards)."
  PRINT "          expression    Expression to locate in the filespec.
Enclose"
  PRINT "                        multiple words in quotes. Spaces are
assumed"
  PRINT "                        to mean any whitespace."
  PRINT "          replace       String to replace found expression
with."
  PRINT "                        Enclose multiple words in quotes.
Found"
  PRINT "                        expression is replaced with literal
string."
  PRINT "Options:  /B            Do not back up original files (when
replacing)."
  PRINT "          /C            Case sensitive search."
  PRINT "          /F            Display filenames only."
  PRINT "          /L            Do not display line numbers."
  PRINT "          /N            No Pause."
  PRINT "          /W            Do not treat spaces as whitespace."
  PRINT "          /Y            Do not confirm when replacing."
  PRINT
  END 1
END IF

'Get filespec
Filespec$ = UCASE$(ArgV$(1,COMMAND$))

'Build list of filenames
Temp$ = DIR$(Filespec$)
WHILE LEN(Temp$)
  INCR TotFiles
  Filename$(TotFiles) = Temp$
  Temp$ = DIR$
WEND

'if no valid filenames, display error and exit
IF TotFiles = 0 THEN
  PRINT "Invalid filespec: " + Filespec$
  END 1
END IF

'get search expression
Expression$ = TRIM$(ArgV$(2, COMMAND$), CHR$(34))

IF LEN(Expression$) = 0 THEN
  PRINT "No expression to search for!"
  END 1
END IF

'Parse command line parameters
FOR x = 3 TO ArgC(COMMAND$)
  Arg$ = ArgV$(x, COMMAND$)
  IF ASCII(Arg$) = 47 THEN
    Arg$ = RTRIM$(UCASE$(Arg$))
  END IF
  IF Arg$ = "/B" THEN
    NoBackup  = %TRUE
  ELSEIF Arg$ = "/C" THEN
    CaseSense = %TRUE
  ELSEIF Arg$ = "/F" THEN
    NameOnly = %TRUE
  ELSEIF Arg$ = "/L" THEN
    LineNumbers = %FALSE
  ELSEIF Arg$ = "/N" THEN
    Pause    = %FALSE
  ELSEIF Arg$ = "/W" THEN
    Literal = %TRUE
  ELSEIF Arg$ = "/Y" THEN
    NoAsk   = %TRUE
  ELSE
    IF x = 3 THEN
      Replacement$ = TRIM$(Arg$, CHR$(34))
    END IF
  END IF
NEXT x

IF CaseSense = %FALSE THEN
  Expression$ = UCASE$(Expression$)
END IF

IF LEN(Replacement$) THEN
  Pause = %FALSE
END IF

FOR x = 1 TO TotFiles
  ScanFile Filename$(x)
  IF Quit THEN
    INCR x
    EXIT FOR
  END IF
NEXT x

COLOR 14, 0
PRINT
PRINT "Found";TotalMatches;"total matches in";x-1;"scanned files.";
PRINT

END 0

'-------------------[ Local SUBs and FUNCTIONs ]-----------------------

SUB ScanFile(BYVAL Filename$)

  Bak$ = Filename$

  IF LEN(Replacement$) THEN
    Filename$ = MakeBAK(Filename$)
  END IF

  OPEN Filename$ FOR INPUT AS #1
  IF LEN(Replacement$) THEN
    OPEN Bak$ FOR OUTPUT AS #2
  END IF
    WHILE NOT EOF(1)
      LINE INPUT #1, Tmp$
      INCR LineNumber
      Where = MatchExpression(UCASE$(Tmp$), Length)
      IF Where THEN
        INCR Matches
        IF NameOnly = %FALSE THEN
          IF LineNumbers THEN
            PrintLine LTRIM$(STR$(LineNumber))+": "+Tmp$
          ELSE
            PrintLine Tmp$
          END IF
        END IF

        IF Where AND LEN(Replacement$) THEN
          I$ = ""
          IF ISFALSE NoAsk THEN
            COLOR 7,0
            PRINT "Replace with " + CHR$(34) + Replacement$ + CHR$(34) +
" (Y/N)? ";
            LOCATE ,,1
            DO
              SLEEP
              I$ = UCASE$(INKEY$)
            LOOP UNTIL INSTR("YN", I$) > 0
            PRINT I$
            LOCATE ,,0
          END IF
          IF ISFALSE(I$ = "N") THEN
            Tmp$ = LEFT$(Tmp$, Where - 1) + Replacement$ + MID$(Tmp$,
Where + Length)
          END IF
        END IF

        IF Quit THEN
          IF LEN(Replacement$) THEN
            PRINT# 2, Tmp$
            WHILE NOT EOF(1)
              LINE INPUT# 1, Tmp$
              PRINT# 2, Tmp$
            WEND
          END IF
          EXIT DO
        END IF
      END IF

      IF LEN(Replacement$) THEN
        PRINT# 2, Tmp$
      END IF

    WEND
  CLOSE 1, 2

  COLOR 14,0
  PrintLine "Found" + STR$(Matches) + " matching lines in " + Bak$
  COLOR 7,0

  INCR TotalMatches, Matches

END SUB

SUB PrintLine(BYVAL Text$)

  WHILE LEN(Text$) > 79
    Tmp$ = LEFT$(Text$, 79)
    GOSUB OutText
    Text$ = MID$(Text$, 80)
  WEND
  Tmp$ = Text$
  GOSUB OutText
  EXIT SUB

OutText:
  Where = MatchExpression(UCASE$(Tmp$), Length)
  baseloc% = 0
  WHILE Where
    PRINT LEFT$(Tmp$, (Where - 1));    'source up to target
    COLOR 0,7
    PRINT MID$(Tmp$, Where, Length);  'target
    COLOR 7,0
    Tmp$ = MID$(Tmp$, Where + Length)  'remaining source
    baseloc% = baseloc% + Where + Length - 1
    Where = MatchExpression(Tmp$, Length)
  WEND
  PRINT Tmp$

  INCR CurLine
  IF (CurLine = pbvScrnRows) AND (Pause = %TRUE) THEN
    COLOR 7,0
    PRINT "Press any key to continue or ESC to quit";
    SLEEP
    LOCATE ,1
    PRINT "                                        ";
    LOCATE ,1
    IF INKEY$ = CHR$(27) THEN
      Quit = %TRUE
    END IF
    CurLine = 1
  END IF
  RETURN

END SUB

FUNCTION MatchExpression(BYVAL Text$, Length)

  Length = 0

  IF Literal THEN
    Where = INSTR(Text$, Expression$)
    IF Where THEN
      Length = LEN(Expression$)
    END IF
  ELSE
    FirstChar$ = LEFT$(Expression$,1)
    Where = INSTR(Text$, FirstChar$)
    DO WHILE Where > 0
      ExpPos = 2
      TxtPos = Where + 1
      DO WHILE (ExpPos <= LEN(Expression$)) AND (TxtPos <= LEN(Text$))
        X$ = MID$(Expression$, ExpPos, 1)
        T$ = MID$(Text$, TxtPos, 1)
        IF X$ = " " THEN
          IF INSTR(CHR$(9,32), T$) = 0 THEN
            EXIT DO
          ELSE
            DO WHILE (TxtPos < LEN(Text$))
              INCR TxtPos
              T$ = MID$(Text$, TxtPos, 1)
            LOOP WHILE INSTR(CHR$(9,32), T$)
          END IF
          INCR ExpPos
          X$ = MID$(Expression$, ExpPos, 1)
        END IF
        IF X$ <> T$ THEN
          EXIT DO
        END IF
        INCR ExpPos
        INCR TxtPos
      LOOP
      IF ExpPos > LEN(Expression$) THEN
        Length = TxtPos - Where
        EXIT DO
      END IF
      Where = INSTR(Where+1, Text$, FirstChar$)
    LOOP

  END IF

  MatchExpression = Where

END FUNCTION



Sun, 09 Mar 2003 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Python's Source Code Available via CVS

2. Python's Source Code Available via CVS

3. Dos Source code for 'int13'

4. Tcl 'grep' equivalent

5. Digitalk's Team/V for Source Code Control

6. LINUX - Source Code Control with Perforce doesn't register

7. Documenting S'87 source code

8. $$$$$ for dBUG - S'87 source code debugger $$$$$

9. creating source code in C++ .NET for CIN's

10. source code for Ruby Dev's Guide

11. This source code don't run

12. HELP!I don't understand an assembly source code

 

 
Powered by phpBB® Forum Software