Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

rgrep in linux ubuntu To compile, simply typing make will build everything you need: make Once compiled, the executable can be invoked as follows: ./rgrep

rgrep in linux ubuntu

To compile, simply typing make will build everything you need: make Once compiled, the executable can be invoked as follows: ./rgrep pattern your implementation should go inside the function rgrep_matches(), which returns true if and only if the string matches the pattern. You can add or use any helper functions or data structures as needed to solve this problem. The skeleton will automatically read each line of code from the input and runs it against the pattern. You job is to just identify whether each line matches.

I.e. fill in the rgrep_matches function in rgrep.c so that the file works like the unix utility grep.

***** rgrep.c

#include #define MAXSIZE 4096

/** * You can use this recommended helper function * Returns true if partial_line matches pattern, starting from * the first char of partial_line. */ int matches_leading(char *partial_line, char *pattern) { // Implement if desire

return 0; }

/** * You may assume that all strings are properly null terminated * and will not overrun the buffer set by MAXSIZE * * Implementation of the rgrep matcher function */ int rgrep_matches(char *line, char *pattern) {

// // Implement me //

return 0; }

int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: %s ", argv[0]); return 2; }

/* we're not going to worry about long lines */ char buf[MAXSIZE];

while (!feof(stdin) && !ferror(stdin)) { if (!fgets(buf, sizeof(buf), stdin)) { break; } if (rgrep_matches(buf, argv[1])) { fputs(buf, stdout); fflush(stdout); } }

if (ferror(stdin)) { perror(argv[0]); return 1; }

return 0; }

***** Makefile

# Your program must compile with 'make' # You must not change this file.

CC = gcc FLAGS = -std=c99 -O0 -Wall -Werror -g -pedantic

rgrep: $(CC) $(FLAGS) rgrep.c -o rgrep

clean: rm -rf rgrep *.dSYM

check: clean rgrep test "`echo "a b c" | ./rgrep 'a'`" = "a" test "`echo "a " | ./rgrep 'a'`" = "a" test "`echo "a" | ./rgrep '...'`" = "" test "`echo "abc" | ./rgrep '.b.'`" = "abc" test "`echo "h aaaaah" | ./rgrep 'a+h'`" = "aaaaah" test "`echo "h aaaaahhhhh" | ./rgrep 'aa+hh+'`" = "aaaaahhhhh" test "`echo "h aaaaahhhhh " | ./rgrep 'aa+hh+'`" = "aaaaahhhhh" test "`echo "a" | ./rgrep 'a?a'`" = "a" test "`echo "woot wot wat " | ./rgrep 'wo?t'`" = "wot" test "`echo "CCCCCCC C+ C++" | ./rgrep '.\+\+'`" = "C++" test "`echo "GG" | ./rgrep '.+'`" = "GG" test "`echo "woooooo_CSE31.jpg" | ./rgrep 'w.+_...31\.jpg'`" = "woooooo_CSE31.jpg" test "`echo "aab" | ./rgrep 'bb?'`" = "aab" test "`echo "aaab" | ./rgrep 'a+b'`" = "aaab" test "`echo "aaab" | ./rgrep 'a+ab'`" = "aaab" @echo "Passed sanity check."

***** short.txt

aa aah aahed aahing aahs aardwolf aardwolves aas aasvogel aasvogels abaci aback abacus abacuses zyme zymogens zymologies zymurgies zymurgy zzaabb sF1xxO? t.bO?T1 a2\W4pH DTJg2gQ qkp9H9M TMLBIPV Ih?Lutl bB0hy1w jYed9FK qQqMfDl .?as..\?

image text in transcribedimage text in transcribedimage text in transcribed

Project 1 Overview You may work with a partner for this project. Each of you will submit the following: *Completed rgrep.c *Any test files you used to check if your sohution is correct Name of your partner in the submission box (if any) Background grep is a UNIX utility that is used to parse or search through strings for a particular pattern. The strings can be either put in through the console or in text files. It is a very convenient way to look for basic patterns or ones with wildcards. It is fairly complicated to support the full character set that grep is capable of. So in this project, you will only implement a restricted grep, rgrep. Examples using the files in your project bundle are as follows. First you can see the contents of the basic test file short.txt. s cat short.txt aahing aardwolf aardwolves aasvogel aasvogels abaci aback abacus abacuses ymogens zymologies ymurgies zzaabb sE1xx0? a2W4p DTJg2g0 gkp9HSM Ih?Lutl bBOhyl jYed9E MED1 ?as..1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started