Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • What are the non interactive mode commands?

    In the putdocx, the sub command textblock begin changes the Stata behaviour. Stata considers first word of each new line as a command. However, in the above case, it considers all new lines as text. What goes behind the surface? What causes this behaviour in terms of some hidden settings?

  • #2
    I do not believe there is a hidden setting that enables this behavior; I think that putdocx textblock takes over reading the following lines until the textblock ends.

    It is much like having an input command in your do-file followed by data lines; Stata's command interpreter doesn't regain control until the end line terminates the input data.

    With that said, you may find the output of
    Code:
    help delimit
    informative.

    Comment


    • #3
      Thanks for your reply. I am still scratching my head around the following. When I set the trace on, there is no such thing in the trace as delimit or the text being processed inside putdocx or passed on to any mata routine. Some sort of magic show is here.

      [CODE]
      The code
      Code:
      putdocx begin
      set trace on
      putdocx textblock begin
      one
      two
      three
      found
      putdocx textblock end
      and its trace is
      Code:
      . putdocx begin
      
      . set trace on
      . putdocx textblock begin
      
        ---------------------------------------------------------------------------------------------------------------------------- begin putdocx ---
        - version 16.0
        - if `"`0'"' == `""' {
        = if `"textblock begin"' == `""' {
          di as err "subcommand required"
          exit 198
          }
        - local cmd `0'
        = local cmd textblock begin
        - gettoken do 0 : 0, parse(" ,")
        - local ldo = length("`do'")
        = local ldo = length("textblock")
        - if "`do'" == bsubstr("begin",1,max(5,`ldo')) {
        = if "textblock" == bsubstr("begin",1,max(5,9)) {
          docx_begin `0'
          exit
          }
        - else if "`do'" == bsubstr("paragraph",1,max(9,`ldo')) {
        = else if "textblock" == bsubstr("paragraph",1,max(9,9)) {
          docx_paragraph `0'
          exit
          }
        - else if "`do'" == bsubstr("text",1,max(4,`ldo')) {
        = else if "textblock" == bsubstr("text",1,max(4,9)) {
          docx_text `0'
          exit
          }
        - else if "`do'" == bsubstr("table",1,max(5,`ldo')) {
        = else if "textblock" == bsubstr("table",1,max(5,9)) {
          docx_table `0'
          exit
          }
        - else if "`do'" == bsubstr("image",1,max(5,`ldo')) {
        = else if "textblock" == bsubstr("image",1,max(5,9)) {
          docx_image `0'
          exit
          }
        - else if "`do'" == bsubstr("pagebreak",1,max(9,`ldo')) {
        = else if "textblock" == bsubstr("pagebreak",1,max(9,9)) {
          docx_pagebreak `0'
          exit
          }
        - else if "`do'" == bsubstr("describe",1,max(8,`ldo')) {
        = else if "textblock" == bsubstr("describe",1,max(8,9)) {
          docx_describe `0'
          exit
          }
        - else if "`do'" == bsubstr("save",1,max(4,`ldo')) {
        = else if "textblock" == bsubstr("save",1,max(4,9)) {
          local 0 `"using `0'"'
          docx_save `0'
          exit
          }
        - else if "`do'" == bsubstr("append",1,max(6,`ldo')) {
        = else if "textblock" == bsubstr("append",1,max(6,9)) {
          docx_append `0'
          exit
          }
        - else if "`do'" == bsubstr("clear",1,max(5,`ldo')) {
        = else if "textblock" == bsubstr("clear",1,max(5,9)) {
          docx_clear `0'
          exit
          }
        - else if "`do'" == bsubstr("sectionbreak",1,max(12,`ldo')) {
        = else if "textblock" == bsubstr("sectionbreak",1,max(12,9)) {
          docx_sectionbreak `0'
          exit
          }
        - else if "`do'" == bsubstr("textblock",1,max(9,`ldo')) {
        = else if "textblock" == bsubstr("textblock",1,max(9,9)) {
        - docx_textblock `0'
        = docx_textblock  begin
          ----------------------------------------------------------------------------------------------------------- begin putdocx.docx_textblock ---
          - syntax [anything] [, NOPARAmode PARAmode NOHARDbreak HARDbreak *]
          - mata: docx_is_valid()
          - local subcmd = strtrim("`anything'")
          = local subcmd = strtrim("begin")
          - local opts = ""
          - if "`noparamode'" != "" & "`paramode'" != "" {
          = if "" != "" & "" != "" {
            di as err "options paramode and noparamode may not be combined"
            exit 198
            }
          - if "`nohardbreak'" != "" & "`hardbreak'" != "" {
          = if "" != "" & "" != "" {
            di as err "options hardbreak and nohardbreak may not be combined"
            exit 198
            }
          - if "`noparamode'" == "noparamode" {
          = if "" == "noparamode" {
            local opts = "`opts' nonewparafornewlines"
            }
          - else if "`paramode'" != "" {
          = else if "" != "" {
            local opts = "`opts' newparafornewlines"
            }
          - if "`nohardbreak'" == "nohardbreak" {
          = if "" == "nohardbreak" {
            local opts = "`opts' nohardbreak"
            }
          - else if "`hardbreak'" != "" {
          = else if "" != "" {
            local opts = "`opts' hardbreak"
            }
          - if "`opts'" != "" {
          = if "" != "" {
            local opts = ", `opts'"
            }
          - if "`subcmd'" == "begin" {
          = if "begin" == "begin" {
          - if "`options'" != "" {
          = if "" != "" {
            docx_paragraph, `options'
            }
          - else {
          - docx_paragraph
            --------------------------------------------------------------------------------------------------------- begin putdocx.docx_paragraph ---
            - syntax [anything] [,style(string) font(string) halign(string) valign(string) SHADing(string) toheader(string) tofooter(string) *]
            - if `"`anything'"' != "" {
            = if `""' != "" {
              di as err "syntax error"
              exit 198
              }
            - mata: docx_is_valid()
            - local indents
            - local spacings
            - local addloc -1
            - local hfname ""
            - if !missing(`"`toheader'"') {
            = if !missing(`""') {
              local hfname `"`toheader'"'
              local addloc 2
              }
            - if !missing(`"`tofooter'"') {
            = if !missing(`""') {
              if `addloc' == -1 {
              local hfname `"`tofooter'"'
              local addloc 3
              }
              else {
              di as err "only one of {bf:toheader()} or {bf:tofooter()} is allowed"
              exit 198
              }
              }
            - if `addloc' == -1 {
            = if -1 == -1 {
            - local addloc 1
            - }
            - if `addloc' == 2 | `addloc' == 3 {
            = if 1 == 2 | 1 == 3 {
              mata: docx_validate_header_footer(`addloc', `"`hfname'"')
              }
            - local 0 `anything', `options'
            = local 0 ,
            - local 0 , `options'
            = local 0 ,
            - syntax ,[indent(passthru) spacing(passthru) *]
            - while !missing(`"`indent'`spacing'"') {
            = while !missing(`""') {
              if !missing(`"`indent'"') {
              local indents `indents' `indent'
              }
              if !missing(`"`spacing'"') {
              local spacings `spacings' `spacing'
              }
              local 0 , `options'
              syntax ,[indent(passthru) spacing(passthru) *]
              }
            - if `"`options'"' != "" {
            = if `""' != "" {
              di as err "option " `"{bf:`options'}"' " not allowed"
              exit 198
              }
            - mata: docx_add_paragraph_wrk(`"`style'"', `"`font'"', `"`halign'"', `"`valign'"', `"`shading'"', `"`indents'"', `"`spacings'"', `addloc'
      > , `"`hfname'"')
            = mata: docx_add_paragraph_wrk(`""', `""', `""', `""', `""', `""', `""', 1, `""')
            ----------------------------------------------------------------------------------------------------------- end putdocx.docx_paragraph ---
          - }
          - mata:docx_current_paragraph_valid()
          - _putdocx_textblock_add $ST__DOCX_ID `opts'
          = _putdocx_textblock_add 0
          - }
          ------------------------------------------------------------------------------------------------------------- end putdocx.docx_textblock ---
        - exit
        ------------------------------------------------------------------------------------------------------------------------------ end putdocx ---
      
      .

      Comment


      • #4
        From what your trace output shows I'd guess that the Mata docx_add_paragraph_wrk() function takes over responsibility for processing the lines following putdocx textblock begin. Again, no "hidden settings" - just low-level code that changes input processing.

        It is not obvious from your post #1 what your objective is. I thought perhaps your objective was to read commands that span multiple lines without using continuation characters. #delimit supports that.

        Comment


        • #5
          I wanted to understand this behavior where one can start a process and then keep on typing text without worrying about #delimte. Here is the code of the docx_add_paragraph_wrk function. As you can see, there is no account of the text typed by the user. The text from the do editor just vanishes in the air.
          Code:
          void docx_add_paragraph_wrk(`SS' style, `SS' font, `SS' halign, `SS' valign,
                          `SS' shading, `SS' indents, `SS' spacings, `RS' addloc,
                          `SS' hfname)
          {
              `RS'         doc_id, ret
              `SS'        sstyle
              
              (void) docx_paragraph_check_prop(style, font, halign, valign,
                               shading, indents, spacings)
          
              doc_id = strtoreal(st_global("ST__DOCX_ID"))
          
              if (style != "") {
                  sstyle = strtrim(style)
                  ret = _docx_paragraph_new_styledtext(doc_id, "", sstyle, addloc, hfname)
                  if (ret < 0) {
                      errprintf("failed to add paragraph\n")
                      exit(198)
                  }
                  ret = _docx_paragraph_add_text(doc_id, "")
                  if (ret < 0) {
                      errprintf("failed to add paragraph\n")
                      exit(198)
                  }
              }
              else {
                  ret = _docx_paragraph_new(doc_id, "", addloc, hfname)
                  if (ret < 0) {
                      errprintf("failed to add paragraph\n")
                      exit(198)
                  }
              }
              st_global("ST__DOCX_CUR_PARAGRAPH", "1")
              (void) docx_update(1)
              
              (void) docx_paragraph_set_wrk(font, halign, valign, shading,
                  indents, spacings)
          }
          and the other function called from within this function
          Code:
          void docx_paragraph_set_wrk(`SS' font, `SS' halign, `SS' valign,
                          `SS' shading, `SS' indents, `SS' spacings)
          {
              `RS'         doc_id, ret
              `FTI'        fti
              `SHI'         shi
              `SS'        cur_para
          
              doc_id = strtoreal(st_global("ST__DOCX_ID"))
              cur_para = st_global("ST__DOCX_CUR_PARAGRAPH")
              if (strtoreal(cur_para) != 1) {
                  errprintf("no active paragraph\n")
                  exit(198)
              }
              
              if (font != "") {
                  (void) docx_parse_font(font, fti, 2)
                  if (fti.name != "") {
                      ret = _docx_paragraph_set_font(doc_id, fti.name)
                      if (ret < 0) {
                          errprintf("failed to set paragraph font\n")
                          exit(198)
                      }
                  }
                  if (fti.size) {
                      ret = _docx_paragraph_set_textsize(doc_id, fti.size)
                      if (ret < 0) {
                      errprintf("failed to set paragraph font size\n")
                          exit(198)
                      }
                  }
                  if (fti.color != "") {
                      ret = _docx_paragraph_set_color(doc_id, fti.color)
                      if (ret < 0) {
                      errprintf("failed to set paragraph font color\n")
                          exit(198)
                      }
                  }
              }
          
              if (halign != "") {
                  halign = strtrim(halign)
                  if (halign=="justify" || halign=="justified") {
                      halign = "both"
                  }
                  ret = _docx_paragraph_set_halign(doc_id, halign)
                  if (ret < 0) {
                      errprintf("failed to set paragraph alignment\n")
                      exit(198)
                  }
              }
          
              if (valign != "") {
                  valign = strtrim(valign)
                  ret = _docx_paragraph_set_valign(doc_id, valign)
                  if (ret < 0) {
                      errprintf("failed to set paragraph alignment\n")
                      exit(198)
                  }
              }
          
              if (shading != "") {
                  (void) docx_parse_shading(shading, shi)
                  ret = _docx_paragraph_set_shading(doc_id, shi.bgcolor,
                      shi.fgcolor, shi.pattern)
                  if (ret < 0) {
                      errprintf("failed to set paragraph shading\n")
                      exit(198)
                  }
              }
          
              if (indents != "") {
                  (void) docx_paragraph_set_indent_wrk(doc_id, indents)
              }
          
              if (spacings != "") {
                  (void) docx_paragraph_set_spacing_wrk(doc_id, spacings)
              }
          }

          Comment


          • #6
            As you can see, there is no account of the text typed by the user. The text from the do editor just vanishes in the air.
            Perhaps it vanishes into the _docx_paragraph_new() function?

            Comment

            Working...
            X