Advertisement
Guest User

Options.c

a guest
Sep 10th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. /* Utility function to extract option flags from the command line.  */
  2.  
  3. #include "Everything.h"
  4. #include <stdarg.h>
  5.  
  6. DWORD Options (int argc, LPCTSTR argv [], LPCTSTR OptStr, ...)
  7.  
  8. /* argv is the command line.
  9.     The options, if any, start with a '-' in argv[1], argv[2], ...
  10.     OptStr is a text string containing all possible options,
  11.     in one-to-one correspondence with the addresses of Boolean variables
  12.     in the variable argument list (...).
  13.     These flags are set if and only if the corresponding option
  14.     character occurs in argv [1], argv [2], ...
  15.     The return value is the argv index of the first argument beyond the options. */
  16.  
  17. {
  18.     va_list pFlagList;
  19.     LPBOOL pFlag;
  20.     int iFlag = 0, iArg;
  21.  
  22.     va_start (pFlagList, OptStr);
  23.  
  24.     while ((pFlag = va_arg (pFlagList, LPBOOL)) != NULL
  25.                 && iFlag < (int)_tcslen (OptStr)) {
  26.         *pFlag = FALSE;
  27.         for (iArg = 1; !(*pFlag) && iArg < argc && argv [iArg] [0] == _T('-'); iArg++)
  28.             *pFlag = _memtchr (argv [iArg], OptStr [iFlag],
  29.                     _tcslen (argv [iArg])) != NULL;
  30.         iFlag++;
  31.     }
  32.  
  33.     va_end (pFlagList);
  34.  
  35.     for (iArg = 1; iArg < argc && argv [iArg] [0] == _T('-'); iArg++);
  36.  
  37.     return iArg;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement