Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/parseargs.cfa

    r3f1d9b5 r7f389a5c  
    33// #include <stdio.h>
    44// #include <stdlib.h>
    5 #include <errno.h>
    65#include <string.h>
    7 #include <unistd.h>
    86extern "C" {
    97        #include <getopt.h>
    10         #include <sys/ioctl.h>
    118
    129        struct FILE;
     
    1411        extern FILE * stdout;
    1512
    16         extern int fileno(FILE *stream);
    17 
    1813        extern int fprintf ( FILE * stream, const char * format, ... );
    19 
    20         extern          long long int strtoll (const char* str, char** endptr, int base);
    21         extern unsigned long long int strtoull(const char* str, char** endptr, int base);
    22 }
    23 
    24 #include <common.hfa>
    25 #include <limits.hfa>
    26 
    27 void printopt(FILE * out, int width, int max, char sn, const char * ln, const char * help) {
    28         int hwidth = max - (11 + width);
    29         if(hwidth <= 0) hwidth = max;
    30 
    31         fprintf(out, "  -%c, --%-*s   %.*s\n", sn, width, ln, hwidth, help);
    32         for() {
    33                 help += min(strlen(help), hwidth);
    34                 if('\0' == *help) break;
    35                 fprintf(out, "%*s%.*s\n", width + 11, "", hwidth, help);
    36         }
     14        extern long long int strtoll (const char* str, char** endptr, int base);
    3715}
    3816
     
    4725        struct option optarr[opt_count + 2];
    4826        int width = 0;
    49         int max_width = 1_000_000;
    5027        {
    5128                int idx = 0;
     
    11693        }
    11794
    118         USAGE:;
    119         int outfd = fileno(out);
    120         if(isatty(outfd)) {
    121                 struct winsize size;
    122                 int ret = ioctl(outfd, TIOCGWINSZ, &size);
    123                 if(ret < 0) abort( "ioctl error: (%d) %s\n", (int)errno, strerror(errno) );
    124                 max_width = size.ws_col;
    125         }
    126 
    127         fprintf(out, "Usage:\n  %s %s\n", argv[0], usage);
     95        USAGE:
     96        fprintf(out, "%s\n", usage);
    12897
    12998        for(i; opt_count) {
    130                 printopt(out, width, max_width, options[i].short_name, options[i].long_name, options[i].help);
     99                fprintf(out, "  -%c, --%-*s   %s\n", options[i].short_name, width, options[i].long_name, options[i].help);
    131100        }
    132101        fprintf(out, "  -%c, --%-*s   %s\n", 'h', width, "help", "print this help message");
     
    163132}
    164133
    165 bool parse(const char * arg, unsigned & value) {
    166         char * end;
    167         unsigned long long int r = strtoull(arg, &end, 10);
    168         if(*end != '\0') return false;
    169         if(r > (unsigned)MAX) return false;
    170 
    171         value = r;
    172         return true;
    173 }
    174 
    175 bool parse(const char * arg, size_t & value) {
    176         char * end;
    177         unsigned long long int r = strtoull(arg, &end, 10);
    178         if(*end != '\0') return false;
    179         if(r > (size_t)MAX) return false;
    180 
    181         value = r;
    182         return true;
    183 }
    184 
    185134bool parse(const char * arg, int & value) {
    186135        char * end;
Note: See TracChangeset for help on using the changeset viewer.