MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / parse_opt

Method parse_opt

erpcgen/src/options.cpp:824–899  ·  view source on GitHub ↗

--------------------------------------------------------------------------- ^FUNCTION: Options::parse_opt - parse an option ^SYNOPSIS: int Options::parse_opt(iter, optarg) ^PARAMETERS: OptIter & iter -- option iterator const char * & optarg -- where to store any option-argument ^DESCRIPTION: Parse the next option in iter (advancing as necessary). Make sure we update the nextchar pointer along t

Source from the content-addressed store, hash-verified

822// It gets complicated -- follow the comments in the source.
823// ^^-------------------------------------------------------------------------
824int Options::parse_opt(OptIter &iter, const char *&optarg)
825{
826 listopt = NULLSTR; // reset the list pointer
827
828 if ((optvec == NULL) || (!*optvec))
829 return static_cast<signed>(Options::OptRC::ENDOPTS);
830
831 // Try to match a known option
832 OptionSpec optspec = match_opt(*(nextchar++), (optctrls & static_cast<signed>(Options::OptCtrl::ANYCASE)));
833
834 // Check for an unknown option
835 if (optspec.isNULL())
836 {
837 // See if this was a long-option in disguise
838 if (!(optctrls & static_cast<signed>(Options::OptCtrl::NOGUESSING)))
839 {
840 unsigned save_ctrls = optctrls;
841 const char *save_nextchar = nextchar;
842 nextchar -= 1;
843 optctrls |=
844 (static_cast<signed>(Options::OptCtrl::QUIET) | static_cast<signed>(Options::OptCtrl::NOGUESSING));
845 int optchar = parse_longopt(iter, optarg);
846 optctrls = save_ctrls;
847 if (optchar > 0)
848 {
849 return optchar;
850 }
851 else
852 {
853 nextchar = save_nextchar;
854 }
855 }
856 if (!(optctrls & static_cast<signed>(Options::OptCtrl::QUIET)))
857 {
858 cerr << cmdname << ": unknown option -" << *(nextchar - 1) << "." << endl;
859 }
860 optarg = (nextchar - 1); // record the bad option in optarg
861 return static_cast<signed>(Options::OptRC::BADCHAR);
862 }
863
864 // If no argument is taken, then leave now
865 if (optspec.isNoArg())
866 {
867 optarg = NULLSTR;
868 return optspec.OptChar();
869 }
870
871 // Check for argument in this arg
872 if (*nextchar)
873 {
874 optarg = nextchar; // the argument is right here
875 nextchar = NULLSTR; // we've exhausted this arg
876 if (optspec.isList())
877 listopt = optspec; // save the list-spec
878 return optspec.OptChar();
879 }
880
881 // Check for argument in next arg

Callers

nothing calls this directly

Calls 8

isOptionFunction · 0.85
isNULLMethod · 0.80
isNoArgMethod · 0.80
OptCharMethod · 0.80
currMethod · 0.80
isValRequiredMethod · 0.80
isListMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected