Add comments to mygrep, begin implementing the http client
This commit is contained in:
@@ -2,7 +2,7 @@ CC = gcc
|
||||
CFLAGS = -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_POSIX_C_SOURCE=200809L -g -c
|
||||
TARGET = mygrep
|
||||
|
||||
all: $(TARGET).c
|
||||
all: $(TARGET).c
|
||||
$(CC) $(CFLAGS) $(TARGET).c
|
||||
$(CC) $(TARGET).o -o $(TARGET)
|
||||
|
||||
|
@@ -1,3 +1,32 @@
|
||||
/**
|
||||
* @file mygrep.c
|
||||
* @author Ivaylo Ivanov 11777707
|
||||
* @date 03.11.2018
|
||||
*
|
||||
* @brief Main program module.
|
||||
*
|
||||
* A reduced variation of the Unix-command `grep`.
|
||||
* It reads in several files and prints all lines containing a keyword.
|
||||
*
|
||||
* SYNOPSIS
|
||||
* mygrep [-i] [-o outfile] keyword [file...]
|
||||
*
|
||||
* The program `mygrep` reads files line by line and for each line checks whether it contains the search
|
||||
* term keyword. The line is printed if it contains the keyword, otherwise it is not printed.
|
||||
* The program accepts lines of any length.
|
||||
*
|
||||
* If one or multiple input files are specified (given as positional arguments after keyword), then mygrep
|
||||
* reads each of them in the order they are given. If no input file is specified, the program reads from
|
||||
* `stdin`.
|
||||
*
|
||||
* If the option `-o` is given, the output is written to the specified file (outfile). Otherwise, the output is
|
||||
* written to `stdout`.
|
||||
*
|
||||
* If the option `-i` is given, the program does not differentiate between lower and upper case letters, i.e.
|
||||
* the search for the keyword in a line is case insensitive.
|
||||
*
|
||||
**/
|
||||
|
||||
#define _GNU_SOURCE ///< in order for strcasestr to work
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -85,11 +114,11 @@ static void print_usage(void) {
|
||||
|
||||
/**
|
||||
* @brief Function to check the number of arguments
|
||||
* @details Checks the number of arguments supplied to the command line.
|
||||
* @details Checks the number of arguments supplied to the command line.
|
||||
* If the arguments are less than the required or more than possible, it exits
|
||||
* @param argc Number of arguments obtained from the command line
|
||||
* @return none
|
||||
*
|
||||
* @return none
|
||||
*
|
||||
**/
|
||||
static void check_opts_number(int argc) {
|
||||
if(argc <= 1) {
|
||||
@@ -105,17 +134,17 @@ static void check_opts_number(int argc) {
|
||||
|
||||
/**
|
||||
* @brief Function to check whether or not a string is contained in another string
|
||||
* @details Checks whether or not a substring is contained in a line.
|
||||
* @details Checks whether or not a substring is contained in a line.
|
||||
* If it is there and no output file is passed, it will print the line to stdout
|
||||
* If it is there and an output file is passed, it will append the line to the end of the output file
|
||||
*
|
||||
*
|
||||
* @param
|
||||
* to_check: String to be checked against
|
||||
* to_find: String to search for
|
||||
* iflag: Whether or not to ignore the casing of the letters
|
||||
* ofile: The file to append the output to
|
||||
* @return none
|
||||
*
|
||||
*
|
||||
**/
|
||||
static void check_for_string(char *to_check, char *to_find, int iflag, char *ofile) {
|
||||
if(ofile == NULL) {
|
||||
|
Reference in New Issue
Block a user