[BACK]Return to mmain.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/Attic/mmain.c between version 1.1 and 1.2

version 1.1, 2009/02/22 22:58:39 version 1.2, 2009/02/23 07:09:13
Line 42  struct mmain {
Line 42  struct mmain {
         struct mdoc      *mdoc;         /* Active parser. */          struct mdoc      *mdoc;         /* Active parser. */
         char             *buf;          /* Input buffer. */          char             *buf;          /* Input buffer. */
         u_long            bufsz;        /* Input buffer size. */          u_long            bufsz;        /* Input buffer size. */
         char              in[MAXPATHLEN]; /* Input file name. */          char             *in;           /* Input file name. */
         int               fdin;         /* Input file desc. */          int               fdin;         /* Input file desc. */
 };  };
   
Line 60  extern int    getsubopt(char **, char *const *, char *
Line 60  extern int    getsubopt(char **, char *const *, char *
 #endif  #endif
   
   
   /*
    * Print our and our caller's usage message.
    */
 void  void
 mmain_usage(const char *help)  mmain_usage(const char *help)
 {  {
Line 69  mmain_usage(const char *help)
Line 72  mmain_usage(const char *help)
 }  }
   
   
   /*
    * Allocate the convenience library and initialise some values.
    */
 struct mmain *  struct mmain *
 mmain_alloc(void)  mmain_alloc(void)
 {  {
Line 77  mmain_alloc(void)
Line 83  mmain_alloc(void)
         if (NULL == (p = calloc(1, sizeof(struct mmain))))          if (NULL == (p = calloc(1, sizeof(struct mmain))))
                 err(1, "malloc");                  err(1, "malloc");
   
         (void)strlcpy(p->in, "-", MAXPATHLEN);          p->in = "-";
         p->fdin = STDIN_FILENO;          p->fdin = STDIN_FILENO;
   
         return(p);          return(p);
 }  }
   
   
   /*
    * Parse command-line options.  Accepts a small (<28 char) opstring "u"
    * parameter (e.g. "ho:") or NULL, a corresponding "help" string (e.g.
    * "[-h] [-o output]" or NULL, a callback function for parsed arguments
    * and an opaque pointer argument for that function.
    */
 int  int
 mmain_isopt(int c)  mmain_getopt(struct mmain *p, int argc, char *argv[],
                   const char *help, const char *u, void *arg,
                   int (*getopt_cb)(void *, int, const char *))
 {  {
           int              c;
         switch (c) {          char             opts[32]; /* XXX */
         case ('v'):          size_t           sz;
                 /* FALLTHROUGH */  
         case ('W'):  
                 return(1);  
         default:  
                 break;  
         }  
         return(0);  
 }  
   
           extern int       optind;
           extern int       optreset;
   
 int          sz = strlcpy(opts, "vW:", 32);
 mmain_getopt(struct mmain *p, int argc,          assert(sz < 32);
                 char *argv[], const char *help)  
 {  
         int              c;  
   
         while (-1 != (c = getopt(argc, argv, ":vW:")))          if (u) {
                   sz = strlcat(opts, u, 32);
                   assert(sz < 32);
           }
   
           /* LINTED */
           while (-1 != (c = getopt(argc, argv, opts)))
                 switch (c) {                  switch (c) {
                 case ('v'):                  case ('v'):
                         p->dbg++;                          p->dbg++;
Line 116  mmain_getopt(struct mmain *p, int argc,
Line 127  mmain_getopt(struct mmain *p, int argc,
                                 return(0);                                  return(0);
                         break;                          break;
                 case ('?'):                  case ('?'):
                         break;  
                 default:  
                         mmain_usage(help);                          mmain_usage(help);
                         return(0);                          return(0);
                   default:
                           assert(getopt_cb);
                           if ((*getopt_cb)(arg, c, optarg))
                                   break;
                           return(0);
                 }                  }
   
         argv += optind;          argv += optind;
         argc -= optind;          if ((argc -= optind) > 0)
                   p->in = *argv++;
   
         if (0 == argc)          return(1);
                 return(1);  
   
         if (strlcpy(p->in, *argv++, MAXPATHLEN) < MAXPATHLEN)  
                 return(1);  
   
         warnx("filename too long");  
         return(0);  
 }  }
   
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

CVSweb