Commit 420ffef8 authored by Matthew Burket's avatar Matthew Burket
Browse files

Work on main

parent f883da31
Loading
Loading
Loading
Loading
+55 −6
Original line number Diff line number Diff line
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "connect.h"

/// Main method for the program
///
/// \param argc
/// \param argv
/// \return
int main (int argc, char **argv) {
    int header_only = 0;
    int timeDelta = 0;
    char *cvalue = NULL;
    int index;
    int c;
    struct addrinfo *addressInfo;

int main(char **argv, int argc) {
    if (argc <= 1) {
        fprintf(stderr, "[–h] [–d <time-interval>] <URL");
        exit(EXIT_FAILURE);
    opterr = 0;

    // getopts section based on
    // https://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html#Example-of-Getopt
    while ((c = getopt(argc, argv, "hd:")) != -1)
        switch (c) {
            case 'h':
                header_only = 1;
                break;
            case 'd':
                timeDelta = 1;
                cvalue = optarg;
                break;
            case '?':
                if (optopt == 'd')
                    fprintf(stderr, "Option -%c requires an argument.\n", optopt);
                else if (isprint (optopt))
                    fprintf(stderr, "Unknown option `-%c'.\n", optopt);
                else
                    fprintf(stderr,
                            "Unknown option character `\\x%x'.\n",
                            optopt);
                return 1;
            default:
                abort();
        }


    printf("header_only = %d, timeDelta = %d, cvalue = %s\n",
           header_only, timeDelta, cvalue);

    for (index = optind; index < argc; index++)
        printf("Non-option argument %s\n", argv[index]);


    init_connection(argv[optind], 80, &addressInfo);
    int sockfd = establish_connect(addressInfo);

}
 No newline at end of file