Fossil

Check-in [413a33f2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixed short-form flag handling for th1 argv command in CLI mode. It now handles GET/POST params.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | th1-query-api
Files: files | file ages | folders
SHA1:413a33f20fc0614e4224eb1327feb092625114c1
User & Date: stephan 2012-07-14 21:36:06
Context
2012-07-14
22:38
Added strftime support to the th1 query API. check-in: 6e2f9edc user: stephan tags: th1-query-api
21:36
Fixed short-form flag handling for th1 argv command in CLI mode. It now handles GET/POST params. check-in: 413a33f2 user: stephan tags: th1-query-api
21:13
Refactored th1 argv_xxx to (argv xxx). Added th1_argv.wiki doc. check-in: 615ee717 user: stephan tags: th1-query-api
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/th_main.c.

593
594
595
596
597
598
599






600

601
602
603
604
605
606
607
...
622
623
624
625
626
627
628

629
630
631
632
633
634
635
...
651
652
653
654
655
656
657






658

659
660
661
662
663
664
665
...
682
683
684
685
686
687
688

689
690
691
692
693
694
695
...
710
711
712
713
714
715
716






717

718
719
720
721
722
723
724
  }

  if(0 == zLong[0]){
    return Th_WrongNumArgs2(interp,
                           argv[0], argl[0],
                           "longName ?shortName? ?defaultVal?");
  }






  zVal = find_option( zLong, zShort[0] ? zShort : NULL, 1 );

  if(!zVal){
    zVal = zDefault;
    if(!zVal){
      Th_ErrorMessage(interp, "Option not found and no default provided:", zLong, -1);
      return TH_ERROR;
    }
  }
................................................................................
static int argvFindOptionBoolCmd(
  Th_Interp *interp,
  void *p, 
  int argc, 
  const char **argv, 
  int *argl
){

  enum { BufLen = 100 };
  char zLong[BufLen] = {0};
  char zShort[BufLen] = {0};
  char aBuf[BufLen] = {0};
  int hasArg;
  char const * zVal = NULL;
  char const * zDefault = NULL;
................................................................................
  }

  if(0 == zLong[0]){
    return Th_WrongNumArgs2(interp,
                            argv[0], argl[0],
                           "longName ?shortName? ?defaultVal?");
  }






  zVal = find_option( zLong, zShort[0] ? zShort : NULL, 0 );

  if(zVal && !*zVal){
    zVal = "1";
  }
  if(!zVal){
    zVal = zDefault;
    if(!zVal){
      Th_ErrorMessage(interp, "Option not found and no default provided:", zLong, -1);
................................................................................
static int argvFindOptionIntCmd(
  Th_Interp *interp,
  void *p, 
  int argc, 
  const char **argv, 
  int *argl
){

  enum { BufLen = 100 };
  char zLong[BufLen] = {0};
  char zShort[BufLen] = {0};
  char aBuf[BufLen] = {0};
  int hasArg;
  char const * zVal = NULL;
  char const * zDefault = NULL;
................................................................................
  }

  if(0 == zLong[0]){
    return Th_WrongNumArgs2(interp,
                            argv[0], argl[0],
                           "longName ?shortName? ?defaultVal?");
  }






  zVal = find_option( zLong, zShort[0] ? zShort : NULL, 0 );

  if(!zVal){
    zVal = zDefault;
    if(!zVal){
      Th_ErrorMessage(interp, "Option not found and no default provided:", zLong, -1);
      return TH_ERROR;
    }
  }







>
>
>
>
>
>
|
>







 







>







 







>
>
>
>
>
>
|
>







 







>







 







>
>
>
>
>
>
|
>







593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
...
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
...
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
...
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
...
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
  }

  if(0 == zLong[0]){
    return Th_WrongNumArgs2(interp,
                           argv[0], argl[0],
                           "longName ?shortName? ?defaultVal?");
  }
  if(g.cgiOutput){
      zVal = cgi_parameter( zLong, NULL );
      if( !zVal && zShort[0] ){
          zVal = cgi_parameter( zShort, NULL );
      }
  }else{
      zVal = find_option( zLong, zShort[0] ? zShort : NULL, 1 );
  }
  if(!zVal){
    zVal = zDefault;
    if(!zVal){
      Th_ErrorMessage(interp, "Option not found and no default provided:", zLong, -1);
      return TH_ERROR;
    }
  }
................................................................................
static int argvFindOptionBoolCmd(
  Th_Interp *interp,
  void *p, 
  int argc, 
  const char **argv, 
  int *argl
){
  /* FIXME: refactor to re-use the code from getstr */
  enum { BufLen = 100 };
  char zLong[BufLen] = {0};
  char zShort[BufLen] = {0};
  char aBuf[BufLen] = {0};
  int hasArg;
  char const * zVal = NULL;
  char const * zDefault = NULL;
................................................................................
  }

  if(0 == zLong[0]){
    return Th_WrongNumArgs2(interp,
                            argv[0], argl[0],
                           "longName ?shortName? ?defaultVal?");
  }
  if(g.cgiOutput){
      zVal = cgi_parameter( zLong, NULL );
      if( !zVal && zShort[0] ){
          zVal = cgi_parameter( zShort, NULL );
      }
  }else{
      zVal = find_option( zLong, zShort[0] ? zShort : NULL, 0 );
  }
  if(zVal && !*zVal){
    zVal = "1";
  }
  if(!zVal){
    zVal = zDefault;
    if(!zVal){
      Th_ErrorMessage(interp, "Option not found and no default provided:", zLong, -1);
................................................................................
static int argvFindOptionIntCmd(
  Th_Interp *interp,
  void *p, 
  int argc, 
  const char **argv, 
  int *argl
){
  /* FIXME: refactor to re-use the code from getstr */
  enum { BufLen = 100 };
  char zLong[BufLen] = {0};
  char zShort[BufLen] = {0};
  char aBuf[BufLen] = {0};
  int hasArg;
  char const * zVal = NULL;
  char const * zDefault = NULL;
................................................................................
  }

  if(0 == zLong[0]){
    return Th_WrongNumArgs2(interp,
                            argv[0], argl[0],
                           "longName ?shortName? ?defaultVal?");
  }
  if(g.cgiOutput){
      zVal = cgi_parameter( zLong, NULL );
      if( !zVal && zShort[0] ){
          zVal = cgi_parameter( zShort, NULL );
      }
  }else{
      zVal = find_option( zLong, zShort[0] ? zShort : NULL, 1 );
  }
  if(!zVal){
    zVal = zDefault;
    if(!zVal){
      Th_ErrorMessage(interp, "Option not found and no default provided:", zLong, -1);
      return TH_ERROR;
    }
  }

Changes to www/th1_argv.wiki.

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49







50
51
52
53
54
55
56
<nowiki><pre>
set arg [argv at 3]
</pre></nowiki>


<h2>getstr</h2>

Searches for a CLI/GET/POST parameter. This function has some non-intuitive behaviour
inherited from fossil's internals: once a flag/parameter is fetched, it is removed
from the internal arguments list, meaning that this function will never
see it a second time.

<nowiki><pre>
set something [argv getstr "something" "S" "default"]
</pre></nowiki>

If no default value is provided, an error is triggered if the value is
not found.








<h2>getbool</h2>

Works almost like <tt>getstr</tt> but searches for boolean flags. CLI boolean flags
have no explicit value, and are "true" if the are set at all.

<nowiki><pre>







|
|
|
|







>
>
>
>
>
>
>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<nowiki><pre>
set arg [argv at 3]
</pre></nowiki>


<h2>getstr</h2>

Searches for a CLI/GET/POST parameter. In CLI this function has some
non-intuitive behaviour inherited from fossil's internals: once a
flag/parameter is fetched, it is removed from the internal arguments
list, meaning that this function will never see it a second time.

<nowiki><pre>
set something [argv getstr "something" "S" "default"]
</pre></nowiki>

If no default value is provided, an error is triggered if the value is
not found.

If you do not want to search for a short-form flag, set it to an empty
string.

BUG: flag checking does not work properly in CGI mode when using
upper-case flags (apparently due to historic special-case behaviour in
fossil for upper-case vars).

<h2>getbool</h2>

Works almost like <tt>getstr</tt> but searches for boolean flags. CLI boolean flags
have no explicit value, and are "true" if the are set at all.

<nowiki><pre>