[sane-devel] [PATCH 1/2] use getopt()

Matteo Croce matteo at openwrt.org
Sat Sep 12 15:35:33 UTC 2015


Sorry about that, I'll fix in a new version, also what do you think
about a nicer help string like:
"Usage: %s [-a username] [-d n] [-s n] [-h]\n"

The main issue is that it seems that under OS/2 the socket handle is
passed as an extra argument, what to do?
Handle the extra argument only if HAVE_OS2_H is defined?

BTW is OS/2 still used? The Sane OS/2 mailing list is gone, and the
latest binary was built on 2012.

2015-09-12 8:50 GMT+02:00 Olaf Meeuwissen <paddy-hack at member.fsf.org>:
> Hi Matteo,
>
> I reviewed this patch and it looks *mostly* okay.  The only place where
> I think you dropped the ball a bit is in the command-line option error
> handling.  The original code outputs a usage message when it finds the
> help option as well as when it encounters anything unexpected.  It also
> returns a suitable exit value whereas your code does not.
>
> Could you fix that?
>
> Matteo Croce writes:
>
>> [snip]
>> @@ -3274,35 +3275,26 @@ main (int argc, char *argv[])
>>    numchildren = 0;
>>    run_mode = SANED_RUN_INETD;
>>
>> -  if (argc >= 2)
>> -    {
>> -      if (strncmp (argv[1], "-a", 2) == 0)
>> -     run_mode = SANED_RUN_ALONE;
>> -      else if (strncmp (argv[1], "-d", 2) == 0)
>> -     {
>> -       run_mode = SANED_RUN_DEBUG;
>> -       log_to_syslog = SANE_FALSE;
>> -     }
>> -      else if (strncmp (argv[1], "-s", 2) == 0)
>> -     run_mode = SANED_RUN_DEBUG;
>> -      else
>> -        {
>> -          printf ("Usage: saned [ -a [ username ] | -d [ n ] | -s [ n ] ] | -h\n");
>> -          if ((strncmp (argv[1], "-h", 2) == 0) ||
>> -               (strncmp (argv[1], "--help", 6) == 0))
>> -            exit (EXIT_SUCCESS);
>> -          else
>> -            exit (EXIT_FAILURE);
>> -        }
>> +  while((c = getopt(argc, argv, "a:d:s:h")) != -1)
>> +  {
>> +    switch(c) {
>> +    case 'a':
>> +      run_mode = SANED_RUN_ALONE;
>> +      user = optarg;
>> +      break;
>> +    case 'd':
>> +      log_to_syslog = SANE_FALSE;
>> +    case 's':
>> +      run_mode = SANED_RUN_DEBUG;
>> +      debug = atoi(optarg);
>> +      break;
>> +    case 'h':
>> +      printf ("Usage: %s [ -a [ username ] | -d [ n ] | -s [ n ] ] | -h\n", argv[0]);
>> +      return;
>>      }
>> -
>> +  }
>>    if (run_mode == SANED_RUN_DEBUG)
>> -    {
>> -      if (argv[1][2])
>> -     debug = atoi (argv[1] + 2);
>> -
>>        DBG (DBG_WARN, "main: starting debug mode (level %d)\n", debug);
>> -    }
>>
>>    if (log_to_syslog)
>>      openlog ("saned", LOG_PID | LOG_CONS, LOG_DAEMON);
>> @@ -3342,11 +3334,15 @@ main (int argc, char *argv[])
>>
>>    if ((run_mode == SANED_RUN_ALONE) || (run_mode == SANED_RUN_DEBUG))
>>      {
>> -      run_standalone(argc, argv);
>> +      run_standalone(user);
>>      }
>>    else
>>      {
>> -      run_inetd(argc, argv);
>> +#ifdef HAVE_OS2_H
>> +      run_inetd(argv[1]);
>> +#else
>> +      run_inetd();
>> +#endif
>>      }
>>
>>    DBG (DBG_WARN, "saned exiting\n");
>> --
>> 2.1.4
>
> --
> Sent with my mu4e



-- 
Matteo Croce
OpenWrt Developer
  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 CHAOS CALMER
 -----------------------------------------------------
  * 1 1/2 oz Gin            Shake with a glassful
  * 1/4 oz Triple Sec       of broken ice and pour
  * 3/4 oz Lime Juice       unstrained into a goblet.
  * 1 1/2 oz Orange Juice
  * 1 tsp. Grenadine Syrup
 -----------------------------------------------------



More information about the sane-devel mailing list