// File: sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_comment(char*)
int Interp::convert_comment(char *comment)       //!< string with comment
{
  enum
  { LC_SIZE = 256, EX_SIZE = 2*LC_SIZE};            // 256 from comment[256] in rs274ngc.hh
  char lc[LC_SIZE+1];
  char expanded[EX_SIZE+1];
  char MSG_STR[] = "msg,";

  //!!!KL add two -- debug => same as msg
  //!!!KL         -- print => goes to stderr
  char DEBUG_STR[] = "debug,";
  char PRINT_STR[] = "print,";
  char LOG_STR[] = "log,";
  char LOGOPEN_STR[] = "logopen,";
  char LOGCLOSE_STR[] = "logclose";
  int m, n, start;

  // step over leading white space in comment
  m = 0;
  while (isspace(comment[m]))
    m++;
  start = m;
  // copy lowercase comment to lc[]
  for (n = 0; n < LC_SIZE && comment[m] != 0; m++, n++) {
    lc[n] = tolower(comment[m]);
  }
  lc[n] = 0;                    // null terminate

  // compare with MSG, SYSTEM, DEBUG, PRINT
  if (startswith(lc, MSG_STR)) {
    MESSAGE(comment + start + strlen(MSG_STR));
    return INTERP_OK;
  }
  else if (startswith(lc, DEBUG_STR))
  {
      convert_param_comment(comment+start+strlen(DEBUG_STR), expanded,
                            EX_SIZE);
      MESSAGE(expanded);
      return INTERP_OK;
  }
  else if (startswith(lc, PRINT_STR)) 
  {
      convert_param_comment(comment+start+strlen(PRINT_STR), expanded,
                            EX_SIZE);
      fprintf(stdout, "%s\n", expanded);
      fflush(stdout);
      return INTERP_OK;
  }
  else if (startswith(lc, LOG_STR))
  {
      convert_param_comment(comment+start+strlen(LOG_STR), expanded,
                            EX_SIZE);
      LOG(expanded);
      return INTERP_OK;
  }
  else if (startswith(lc, LOGOPEN_STR))
  {
      LOGOPEN(comment + start + strlen(LOGOPEN_STR));
      return INTERP_OK;
  }
  else if (streq(lc, LOGCLOSE_STR))
  {
      LOGCLOSE();
      return INTERP_OK;
  }
  // else it's a real comment
  enqueue_COMMENT(comment + start);
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3a0, %rsp            # imm = 0x3A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x370(%rbp)
movl 0x5afc7(%rip), %eax     # 0x79c2b
movl %eax, -0x335(%rbp)
movb 0x5afbf(%rip), %al      # 0x79c2f
movb %al, -0x331(%rbp)
movl 0x5afb4(%rip), %eax     # 0x79c30
movl %eax, -0x33c(%rbp)
movw 0x5afab(%rip), %ax      # 0x79c34
movw %ax, -0x338(%rbp)
movb 0x5afa0(%rip), %al      # 0x79c36
movb %al, -0x336(%rbp)
movl 0x5af95(%rip), %eax     # 0x79c37
movl %eax, -0x343(%rbp)
movw 0x5af8c(%rip), %ax      # 0x79c3b
movw %ax, -0x33f(%rbp)
movb 0x5af81(%rip), %al      # 0x79c3d
movb %al, -0x33d(%rbp)
movl 0x5af76(%rip), %eax     # 0x79c3e
movl %eax, -0x348(%rbp)
movb 0x5af6e(%rip), %al      # 0x79c42
movb %al, -0x344(%rbp)
movq 0x5af62(%rip), %rax     # 0x79c43
movq %rax, -0x351(%rbp)
movb 0x5af5d(%rip), %al      # 0x79c4b
movb %al, -0x349(%rbp)
movq 0x5af51(%rip), %rax     # 0x79c4c
movq %rax, -0x35a(%rbp)
movb 0x5af4c(%rip), %al      # 0x79c54
movb %al, -0x352(%rbp)
movl $0x0, -0x360(%rbp)
movq -0x18(%rbp), %rax
movslq -0x360(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x10120
cmpl $0x0, %eax
je 0x1ed42
movl -0x360(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x360(%rbp)
jmp 0x1ed18
movl -0x360(%rbp), %eax
movl %eax, -0x368(%rbp)
movl $0x0, -0x364(%rbp)
xorl %eax, %eax
cmpl $0x100, -0x364(%rbp)    # imm = 0x100
movb %al, -0x371(%rbp)
jge 0x1ed87
movq -0x18(%rbp), %rax
movslq -0x360(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x371(%rbp)
movb -0x371(%rbp), %al
testb $0x1, %al
jne 0x1ed93
jmp 0x1edd7
movq -0x18(%rbp), %rax
movslq -0x360(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x11910
movb %al, %cl
movslq -0x364(%rbp), %rax
movb %cl, -0x120(%rbp,%rax)
movl -0x360(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x360(%rbp)
movl -0x364(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x364(%rbp)
jmp 0x1ed58
movslq -0x364(%rbp), %rax
movb $0x0, -0x120(%rbp,%rax)
leaq -0x120(%rbp), %rdi
leaq -0x335(%rbp), %rsi
callq 0x1f060
cmpl $0x0, %eax
je 0x1ee3a
movq -0x18(%rbp), %rax
movslq -0x368(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x380(%rbp)
leaq -0x335(%rbp), %rdi
callq 0x10740
movq -0x380(%rbp), %rdi
addq %rax, %rdi
callq 0x10fa0
movl $0x0, -0x4(%rbp)
jmp 0x1f050
leaq -0x120(%rbp), %rdi
leaq -0x33c(%rbp), %rsi
callq 0x1f060
cmpl $0x0, %eax
je 0x1eead
movq -0x18(%rbp), %rax
movslq -0x368(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x388(%rbp)
leaq -0x33c(%rbp), %rdi
callq 0x10740
movq -0x388(%rbp), %rsi
movq -0x370(%rbp), %rdi
addq %rax, %rsi
leaq -0x330(%rbp), %rdx
movl $0x200, %ecx            # imm = 0x200
callq 0x110d0
leaq -0x330(%rbp), %rdi
callq 0x10fa0
movl $0x0, -0x4(%rbp)
jmp 0x1f050
leaq -0x120(%rbp), %rdi
leaq -0x343(%rbp), %rsi
callq 0x1f060
cmpl $0x0, %eax
je 0x1ef42
movq -0x18(%rbp), %rax
movslq -0x368(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x390(%rbp)
leaq -0x343(%rbp), %rdi
callq 0x10740
movq -0x390(%rbp), %rsi
movq -0x370(%rbp), %rdi
addq %rax, %rsi
leaq -0x330(%rbp), %rdx
movl $0x200, %ecx            # imm = 0x200
callq 0x110d0
movq 0x68059(%rip), %rax     # 0x86f68
movq (%rax), %rdi
leaq -0x330(%rbp), %rdx
leaq 0x6000a(%rip), %rsi     # 0x7ef2a
movb $0x0, %al
callq 0x11890
movq 0x6803a(%rip), %rax     # 0x86f68
movq (%rax), %rdi
callq 0x11470
movl $0x0, -0x4(%rbp)
jmp 0x1f050
leaq -0x120(%rbp), %rdi
leaq -0x348(%rbp), %rsi
callq 0x1f060
cmpl $0x0, %eax
je 0x1efb5
movq -0x18(%rbp), %rax
movslq -0x368(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x398(%rbp)
leaq -0x348(%rbp), %rdi
callq 0x10740
movq -0x398(%rbp), %rsi
movq -0x370(%rbp), %rdi
addq %rax, %rsi
leaq -0x330(%rbp), %rdx
movl $0x200, %ecx            # imm = 0x200
callq 0x110d0
leaq -0x330(%rbp), %rdi
callq 0x10e40
movl $0x0, -0x4(%rbp)
jmp 0x1f050
leaq -0x120(%rbp), %rdi
leaq -0x351(%rbp), %rsi
callq 0x1f060
cmpl $0x0, %eax
je 0x1f006
movq -0x18(%rbp), %rax
movslq -0x368(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x3a0(%rbp)
leaq -0x351(%rbp), %rdi
callq 0x10740
movq -0x3a0(%rbp), %rdi
addq %rax, %rdi
callq 0x11850
movl $0x0, -0x4(%rbp)
jmp 0x1f050
leaq -0x120(%rbp), %rdi
leaq -0x35a(%rbp), %rsi
callq 0x1f0b0
cmpl $0x0, %eax
je 0x1f02c
callq 0x110f0
movl $0x0, -0x4(%rbp)
jmp 0x1f050
jmp 0x1f02e
jmp 0x1f030
jmp 0x1f032
jmp 0x1f034
jmp 0x1f036
movq -0x18(%rbp), %rdi
movslq -0x368(%rbp), %rax
addq %rax, %rdi
callq 0x11f00
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x3a0, %rsp            # imm = 0x3A0
popq %rbp
retq
nopl (%rax)