<commit_before>.HLL 'Tcl', 'tcl_group'
.namespace

.sub '&binary'
  .param pmc argv :slurpy

  .local pmc retval

  $I0 = argv
  unless $I0 goto no_args

  .local string subcommand_name
  subcommand_name = shift argv
  .local pmc subcommand_proc
  null subcommand_proc

  subcommand_proc = get_root_global ['_tcl'; 'helpers'; 'binary'], subcommand_name
  if_null subcommand_proc, bad_args
  .return subcommand_proc(argv)

bad_args:
  $S0 = 'bad option "'
  $S0 .= subcommand_name
  $S0 .= '": must be format or scan'

  tcl_error $S0

no_args:
  tcl_error 'wrong # args: should be "binary option ?arg ...?"'

.end

.HLL '_Tcl',''
.namespace [ 'helpers'; 'binary' ]

.macro getBinaryArg ()
  if argvIndex == argc goto out_of_args
  argString = argv[argvIndex]
  inc argvIndex
.endm

.sub 'format'
  .param pmc argv

  .local int argc
  .local pmc retval

  argc = argv
  unless argc goto bad_args

  .local pmc binary_types
  binary_types = get_root_global ['_tcl'], 'binary_types'

  .local string outputString,formatString
  outputString = binary:""
  formatString = shift argv

  # Loop over the chunks of the format string and generate the
  # appropriate types. format strings consist of repeated chunks of
  # type count? whitespace*
  .local int pos,formatString_len,argvIndex,argc,count,digit,tempCount
  .local string formatChar,argString
  pos = 0
  argvIndex = 0
  argc = argv
  # a count of -1 indicates that '*' was specified.
  # a count of -2 indicates that no count was specified.
  count = -2
  formatString_len = length formatString

format_loop:
  if pos == formatString_len goto end_format_loop
  formatChar = substr formatString,pos,1

  $I1 = exists binary_types[formatChar]
  unless $I1 goto bad_field_specifier 
  
  .local int num_pos
  num_pos = pos + 1
 
  $S0 = substr formatString, num_pos, 1
  if $S0 != '*' goto get_int_count
  count = -1
  pos = num_pos
  goto got_count

get_int_count:
  tempCount = 0
  ## XXX  countString = 0
count_loop:
  if num_pos == formatString_len goto count_loop_done 
  digit = ord formatString, num_pos
  if digit < 48 goto count_loop_done
  if digit > 57 goto count_loop_done
  digit -= 48 # ascii
  # XXXX
  tempCount = tempCount * 10
  tempCount += digit 
  inc num_pos
  if num_pos == formatString_len goto count_loop_done
  ## XXX digitString = substr formatString,pos,1
  if num_pos == formatString_len goto count_loop_done
  goto count_loop
count_loop_done:
  $I0 = num_pos - 1  
  if $I0 == pos goto got_default_count

  pos = num_pos 
  count = tempCount
  goto got_count

got_default_count:
  inc pos

got_count:

which_format:

  if formatChar == 'a' goto format_a
  if formatChar == 'A' goto format_A
  if formatChar == 'x' goto format_x

  .return (0)  # XXX Hack to avoid blowing up when using binary.
  tcl_error 'XXX This error should never occur: must be missing a field specifier implementation.'

format_a:
  .getBinaryArg()
  if count == -1 goto format_a_star
  if count >= 0 goto format_a_counted
  count = 1

format_a_counted:
  $I0 = length argString
  if $I0 < count goto format_a_padding
  $S0 = substr argString, 0, count
  outputString .= $S0
  goto format_done

format_a_padding:
  outputString .= argString
  count = count - $I0<commit_msg> r5099@avon:  cochrane | 2006-11-09 15:04:51 +0100  [tcl]: Added RT ticket #40761 to TODO item<commit_after>.HLL 'Tcl', 'tcl_group'
.namespace

.sub '&binary'
  .param pmc argv :slurpy

  .local pmc retval

  $I0 = argv
  unless $I0 goto no_args

  .local string subcommand_name
  subcommand_name = shift argv
  .local pmc subcommand_proc
  null subcommand_proc

  subcommand_proc = get_root_global ['_tcl'; 'helpers'; 'binary'], subcommand_name
  if_null subcommand_proc, bad_args
  .return subcommand_proc(argv)

bad_args:
  $S0 = 'bad option "'
  $S0 .= subcommand_name
  $S0 .= '": must be format or scan'

  tcl_error $S0

no_args:
  tcl_error 'wrong # args: should be "binary option ?arg ...?"'

.end

.HLL '_Tcl',''
.namespace [ 'helpers'; 'binary' ]

.macro getBinaryArg ()
  if argvIndex == argc goto out_of_args
  argString = argv[argvIndex]
  inc argvIndex
.endm

.sub 'format'
  .param pmc argv

  .local int argc
  .local pmc retval

  argc = argv
  unless argc goto bad_args

  .local pmc binary_types
  binary_types = get_root_global ['_tcl'], 'binary_types'

  .local string outputString,formatString
  outputString = binary:""
  formatString = shift argv

  # Loop over the chunks of the format string and generate the
  # appropriate types. format strings consist of repeated chunks of
  # type count? whitespace*
  .local int pos,formatString_len,argvIndex,argc,count,digit,tempCount
  .local string formatChar,argString
  pos = 0
  argvIndex = 0
  argc = argv
  # a count of -1 indicates that '*' was specified.
  # a count of -2 indicates that no count was specified.
  count = -2
  formatString_len = length formatString

format_loop:
  if pos == formatString_len goto end_format_loop
  formatChar = substr formatString,pos,1

  $I1 = exists binary_types[formatChar]
  unless $I1 goto bad_field_specifier 
  
  .local int num_pos
  num_pos = pos + 1
 
  $S0 = substr formatString, num_pos, 1
  if $S0 != '*' goto get_int_count
  count = -1
  pos = num_pos
  goto got_count

get_int_count:
  tempCount = 0
  ## XXX  countString = 0
count_loop:
  if num_pos == formatString_len goto count_loop_done 
  digit = ord formatString, num_pos
  if digit < 48 goto count_loop_done
  if digit > 57 goto count_loop_done
  digit -= 48 # ascii
  # XXXX
  tempCount = tempCount * 10
  tempCount += digit 
  inc num_pos
  if num_pos == formatString_len goto count_loop_done
  ## XXX digitString = substr formatString,pos,1
  if num_pos == formatString_len goto count_loop_done
  goto count_loop
count_loop_done:
  $I0 = num_pos - 1  
  if $I0 == pos goto got_default_count

  pos = num_pos 
  count = tempCount
  goto got_count

got_default_count:
  inc pos

got_count:

which_format:

  if formatChar == 'a' goto format_a
  if formatChar == 'A' goto format_A
  if formatChar == 'x' goto format_x

  .return (0)  # XXX Hack to avoid blowing up when using binary.
  tcl_error 'XXX (#40761): This error should never occur: must be missing a field specifier implementation.'

format_a:
  .getBinaryArg()
  if count == -1 goto format_a_star
  if count >= 0 goto format_a_counted
  count = 1

format_a_counted:
  $I0 = length argString
  if $I0 < count goto format_a_padding
  $S0 = substr argString, 0, count
  outputString .= $S0
  goto format_done

format_a_padding:
  outputString .= argString
  count = count - $I0
{'fraction_non_alphanumeric': 0.08245533669262482, 'fraction_numerical': 0.018018018018018018, 'mean_word_length': 3.619181946403385, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3299585', 'n_tokens_mistral': 2357, 'n_tokens_neox': 2252, 'n_words': 733}