Question: / * Given a filename, figure out if it's a directory or text file. * If text file ( base case ) , scan it

/* Given a filename, figure out if it's a directory or text file.
* If text file (base case), scan it, incrementing word counts as you go.
* If directory, recurse.
* Otherwise, ignore
*/
void process_file(char *name, amap_t *m){
/******** YOUR CODE HERE ************/
/* What kind of file is it?
* Hint: use check_type()
*/
/* if FTYPE_REG: use count_words(). Note arg types expected by it.
* Hint: fdopen().
* Hint: account for what check_type() does with a regular file.
*/
/* if FTYPE_DIR: use opendir and readdir t0 get entries,
* and recursively process each.
/* if anything else, ignore it.*/
}
/*
* Driver for the scanning process.
* Process the files under the given name (process_file), recursively,
* incrementing count in the map for each word found in a text file.
* Then write the contents of the map to each reducer pipe, according to
* the first letter of the word (using the writepipes map).
* Then close all the write ends of the reducer pipes.
* Parameters:
* nprocs = # of scanners/reducers/pipes
* map = sorted map of words to counts
* startname = file/dir to process
* reducepipes = array of pipe fds to get counts to reducers
* THIS FUNCTION DOES NOT RETURN
*/
void scanner(int nprocs, amap_t *map, char *startname, pipe_t *reducepipes){
/************* YOUR CODE HERE *********************/
/* first call process_file() on the startname. */
/* Then write each (string,count) pair in the map to the appropriate
* reducer.
* Hint: use amap_getnext().
* Hint: whichpipe maps character #s ('a'=0,'b'=1, etc.) to reduce pipe #s.
* the first letter of the word (using the writepipes map).
* Parameters:
* nprocs = # of scanners/reducers/pipes
* map = sorted map of words to counts
* startname = file/dir to process
* reducepipes = array of pipe fds to get counts to reducers
* THIS FUNCTION DOES NOT RETURN
*/
void scanner(int nprocs, amap_t *map, char *startname, pipe_t *reducepipes){
/************* YOUR CODE HERE *********************/
/* first call process_file() on the startname. */
/* Then write each (string,count) pair in the map to the appropriate
* reducer.
* Hint: use amap_getnext().
* Hint: whichpipe maps character #s ('a'=0,'b'=1, etc.) to reduce pipe #s.
*/
/* Then close my write end of each reduce pipe. */
/* Then close my write end of each reduce pipe. */
exit(0); // all done!
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!