Fossil

Diff
Login

Differences From Artifact [3b8b7f720b]:

To Artifact [c37d330497]:


787
788
789
790
791
792
793














794
795
796
797
798
799
800

801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819












820
821
822
823
824
825
826
827
828
829

830
831
832
833
834
835
836
/*
** Look for a command-line option.  If present, return a pointer.
** Return NULL if missing.
**
** hasArg==0 means the option is a flag.  It is either present or not.
** hasArg==1 means the option has an argument.  Return a pointer to the
** argument.














*/
const char *find_option(const char *zLong, const char *zShort, int hasArg){
  int i;
  int nLong;
  const char *zReturn = 0;
  assert( hasArg==0 || hasArg==1 );
  nLong = strlen(zLong);

  for(i=1; i<g.argc; i++){
    char *z;
    if (i+hasArg >= g.argc) break;
    z = g.argv[i];
    if( z[0]!='-' ) continue;
    z++;
    if( z[0]=='-' ){
      if( z[1]==0 ){
        remove_from_argv(i, 1);
        break;
      }
      z++;
    }
    if( strncmp(z,zLong,nLong)==0 ){
      if( hasArg && z[nLong]=='=' ){
        zReturn = &z[nLong+1];
        remove_from_argv(i, 1);
        break;
      }else if( z[nLong]==0 ){












        zReturn = g.argv[i+hasArg];
        remove_from_argv(i, 1+hasArg);
        break;
      }
    }else if( fossil_strcmp(z,zShort)==0 ){
      zReturn = g.argv[i+hasArg];
      remove_from_argv(i, 1+hasArg);
      break;
    }
  }

  return zReturn;
}

/*
** Verify that there are no unprocessed command-line options.  If
** Any remaining command-line argument begins with "-" print
** an error message and quit.







>
>
>
>
>
>
>
>
>
>
>
>
>
>



|



>


<
















>
>
>
>
>
>
>
>
>
>
>
>




<
<
<
<


>







787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817

818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849




850
851
852
853
854
855
856
857
858
859
/*
** Look for a command-line option.  If present, return a pointer.
** Return NULL if missing.
**
** hasArg==0 means the option is a flag.  It is either present or not.
** hasArg==1 means the option has an argument.  Return a pointer to the
** argument.
**
** Note that this function REMOVES any found entry from the args list,
** so calling this twice for the same var will cause NULL to be returned
** after the first time.
**
** zLong may not be NULL but zShort may be.
**
** Options are accepted in these forms, depending on the value of hasArg:
**
** hasArg=true:
**  -long VALUE
**  -long=VALUE
**  -short VALUE
**  -short=VALUE
*/
const char *find_option(const char *zLong, const char *zShort, int hasArg){
  int i;
  int nLong, nShort;
  const char *zReturn = 0;
  assert( hasArg==0 || hasArg==1 );
  nLong = strlen(zLong);
  nShort = zShort ? strlen(zShort) : 0;
  for(i=1; i<g.argc; i++){
    char *z;

    z = g.argv[i];
    if( z[0]!='-' ) continue;
    z++;
    if( z[0]=='-' ){
      if( z[1]==0 ){
        remove_from_argv(i, 1);
        break;
      }
      z++;
    }
    if( strncmp(z,zLong,nLong)==0 ){
      if( hasArg && z[nLong]=='=' ){
        zReturn = &z[nLong+1];
        remove_from_argv(i, 1);
        break;
      }else if( z[nLong]==0 ){
        if (i+hasArg >= g.argc) break;
        zReturn = g.argv[i+hasArg];
        remove_from_argv(i, 1+hasArg);
        break;
      }
    }else if( strncmp(z,zShort,nShort)==0 ){
      if( hasArg && z[nShort]=='=' ){
        zReturn = &z[nShort+1];
        remove_from_argv(i, 1);
        break;
      }else if( z[nShort]==0 ){
        if (i+hasArg >= g.argc) break;
        zReturn = g.argv[i+hasArg];
        remove_from_argv(i, 1+hasArg);
        break;
      }




    }
  }

  return zReturn;
}

/*
** Verify that there are no unprocessed command-line options.  If
** Any remaining command-line argument begins with "-" print
** an error message and quit.