user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<main>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x628,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x2618(%rsp)
  xor    %eax,%eax
  mov    %rsi,%rbx
  cmp    $0x1,%edi
  jle    L35
  lea    0x40(%rsp),%r14
  mov    $0x1e00,%edx
  xor    %esi,%esi
  mov    %r14,%rdi
  mov    %r14,0x10(%rsp)
  lea    0x1e40(%rsp),%rbp
  call   <memset@plt>
  mov    0x8(%rbx),%rdi
  lea    D537(%rip),%rsi
  call   <fopen@plt>
  mov    %r14,0x28(%rsp)
  mov    %rbp,0x20(%rsp)
  mov    %rax,%rbx
  mov    %r14,%rax
  nopl   (%rax)
L91:
  mov    $0x2222,%r11d
  mov    $0x2222,%r12d
  movb   $0x0,0x2(%rax)
  add    $0x3c,%rax
  mov    $0x2222,%r13d
  mov    %r11w,-0x3c(%rax)
  mov    %r12w,-0x28(%rax)
  movb   $0x0,-0x26(%rax)
  mov    %r13w,-0x14(%rax)
  movb   $0x0,-0x12(%rax)
  cmp    %rbp,%rax
  jne    L91
  lea    0x1fd0(%rsp),%r12
  lea    D107(%rip),%r15
L5:
  lea    D174(%rip),%r13
  jmp    L132
L543:
  lea    D600(%rip),%rsi
  mov    %r12,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L621
L243:
  lea    D36(%rip),%rsi
  mov    %r12,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L142
L659:
  lea    D360(%rip),%rsi
  mov    %r12,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L523
L132:
  mov    %rbx,%rdi
  call   <feof@plt>
  test   %eax,%eax
  jne    L159
  mov    %rbx,%rdx
  mov    $0x190,%esi
  mov    %rbp,%rdi
  call   <fgets@plt>
  mov    %r15,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  mov    %r12,%rdx
  call   <sscanf@plt>
  lea    D198(%rip),%rsi
  mov    %r12,%rdi
  movb   $0x0,0x22f0(%rsp)
  movb   $0x0,0x2480(%rsp)
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L543
  lea    0x22f0(%rsp),%r9
  lea    0x3c(%rsp),%rcx
  mov    %r12,%rdx
  mov    %rbp,%rdi
  lea    0x2160(%rsp),%r8
  sub    $0x8,%rsp
  lea    D293(%rip),%rsi
  lea    0x2488(%rsp),%r14
  push   %r14
  mov    %r9,0x28(%rsp)
  mov    %r8,0x18(%rsp)
  call   <sscanf@plt>
  movslq 0x4c(%rsp),%rdx
  mov    0x20(%rsp),%rcx
  mov    %r13,%rsi
  mov    %rdx,%rax
  shl    $0x4,%rax
  sub    %rdx,%rax
  mov    0x18(%rsp),%rdx
  lea    (%rcx,%rax,4),%rdi
  xor    %eax,%eax
  call   <sprintf@plt>
  mov    0x28(%rsp),%r9
  lea    D186(%rip),%r8
  mov    %r8,%rsi
  mov    %r9,%rdi
  mov    %r9,0x18(%rsp)
  call   <strcmp@plt>
  pop    %r9
  pop    %r10
  test   %rax,%rax
  je     L543
  cmpb   $0x0,0x22f0(%rsp)
  mov    0x8(%rsp),%r9
  je     L543
  movslq 0x3c(%rsp),%rdx
  mov    0x10(%rsp),%rcx
  mov    %r13,%rsi
  mov    %rdx,%rax
  shl    $0x4,%rax
  sub    %rdx,%rax
  mov    %r9,%rdx
  lea    0x14(%rcx,%rax,4),%rdi
  xor    %eax,%eax
  call   <sprintf@plt>
  lea    D186(%rip),%r8
  mov    %r14,%rdi
  mov    %r8,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L543
  cmpb   $0x0,0x2480(%rsp)
  je     L543
  movslq 0x3c(%rsp),%rax
  mov    0x10(%rsp),%rcx
  mov    %r14,%rdx
  mov    %r13,%rsi
  imul   $0x3c,%rax,%rax
  lea    0x28(%rcx,%rax,1),%rdi
  xor    %eax,%eax
  call   <sprintf@plt>
  jmp    L543
  nopl   0x0(%rax)
L142:
  mov    %r12,%rcx
  mov    %r12,%rdx
  lea    0x3c(%rsp),%r8
  mov    %rbp,%rdi
  lea    0x2160(%rsp),%r14
  lea    D539(%rip),%rsi
  mov    %r14,%r9
  call   <sscanf@plt>
  movslq 0x3c(%rsp),%rdx
  mov    0x10(%rsp),%rcx
  mov    %r13,%rsi
  mov    %rdx,%rax
  shl    $0x4,%rax
  sub    %rdx,%rax
  mov    %r14,%rdx
  lea    0x14(%rcx,%rax,4),%rdi
  xor    %eax,%eax
  call   <sprintf@plt>
  jmp    L659
L621:
  mov    %r12,%rcx
  mov    %r12,%rdx
  lea    0x3c(%rsp),%r8
  mov    %rbp,%rdi
  lea    0x2160(%rsp),%r14
  lea    D539(%rip),%rsi
  mov    %r14,%r9
  call   <sscanf@plt>
  movslq 0x3c(%rsp),%rdx
  mov    0x10(%rsp),%rcx
  mov    %r13,%rsi
  mov    %rdx,%rax
  shl    $0x4,%rax
  sub    %rdx,%rax
  mov    %r14,%rdx
  lea    (%rcx,%rax,4),%rdi
  xor    %eax,%eax
  call   <sprintf@plt>
  jmp    L243
L159:
  mov    0x10(%rsp),%r14
  nopl   0x0(%rax)
L150:
  mov    %r14,%rbx
  xor    %r13d,%r13d
  jmp    L595
  nopl   0x0(%rax,%rax,1)
L494:
  movsbl (%rbx),%edi
  add    $0x1,%r13d
  add    $0x1,%rbx
  call   <toupper@plt>
  mov    %al,-0x1(%rbx)
L595:
  mov    %r14,%rdi
  call   <strlen@plt>
  cmp    %r13d,%eax
  jg     L494
  lea    0x14(%r14),%r15
  mov    %r14,%rbx
  xor    %r13d,%r13d
  jmp    L246
  nopl   0x0(%rax)
L117:
  movsbl 0x13(%rbx),%edi
  add    $0x1,%r13d
  call   <toupper@plt>
  mov    %al,0x13(%rbx)
L246:
  mov    %r15,%rdi
  add    $0x1,%rbx
  call   <strlen@plt>
  cmp    %r13d,%eax
  jg     L117
  lea    0x28(%r14),%r15
  mov    %r14,%rbx
  xor    %r13d,%r13d
  jmp    L341
  nopl   (%rax)
L289:
  movsbl 0x27(%rbx),%edi
  add    $0x1,%r13d
  call   <toupper@plt>
  mov    %al,0x27(%rbx)
L341:
  mov    %r15,%rdi
  add    $0x1,%rbx
  call   <strlen@plt>
  cmp    %r13d,%eax
  jg     L289
  add    $0x3c,%r14
  cmp    %rbp,%r14
  jne    L150
  mov    $0x61,%r13d
  lea    D134(%rip),%rbx
L514:
  lea    -0x20(%r13),%r14d
  mov    %rbx,%rsi
  mov    %r12,%rdi
  xor    %eax,%eax
  mov    %r14d,%edx
  call   <sprintf@plt>
  mov    0x10(%rsp),%r15
  jmp    L83
  cs nopw 0x0(%rax,%rax,1)
L165:
  add    $0x3c,%r15
  cmp    %rbp,%r15
  je     L15
L83:
  mov    %r12,%rsi
  mov    %r15,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L165
  mov    %r15,%rdi
  mov    %r13d,%edx
  mov    %rbx,%rsi
  call   <sprintf@plt>
  lea    0x14(%r15),%rdi
  mov    %r14d,%edx
  mov    %rbx,%rsi
  xor    %eax,%eax
  add    $0x3c,%r15
  call   <sprintf@plt>
  cmp    %rbp,%r15
  jne    L83
L15:
  add    $0x1,%r13d
  cmp    $0x7b,%r13d
  jne    L514
  mov    0x10(%rsp),%rax
  lea    0x54(%rsp),%rbx
  lea    D589(%rip),%r13
  lea    D308(%rip),%r12
  lea    D79(%rip),%r14
  add    $0x1e14,%rax
  lea    D91(%rip),%r15
  mov    %rax,0x8(%rsp)
  jmp    L63
  nopl   0x0(%rax)
L164:
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L443
L574:
  mov    %r14,%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L232
L604:
  mov    %r15,%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L180
L503:
  lea    D372(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L532
L322:
  lea    D582(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L122
L31:
  lea    D304(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L86
L608:
  lea    D5(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L454
L134:
  lea    D501(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L46
L273:
  lea    D144(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L413
L291:
  lea    D561(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L37
  add    $0x3c,%rbx
  cmp    0x8(%rsp),%rbx
  je     L563
L63:
  lea    -0x14(%rbx),%rbp
  mov    %r13,%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L164
  movabs $0x22545245534e4922,%rax
  movb   $0x0,0x8(%rbx)
  mov    %r12,%rsi
  mov    %rbp,%rdi
  mov    %rax,(%rbx)
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L574
L443:
  mov    $0x22,%r8d
  movl   $0x444e4522,(%rbx)
  mov    %r14,%rsi
  mov    %rbp,%rdi
  mov    %r8w,0x4(%rbx)
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L604
L232:
  mov    $0x224e,%edi
  movl   $0x574f4422,(%rbx)
  mov    %r15,%rsi
  mov    %di,0x4(%rbx)
  mov    %rbp,%rdi
  movb   $0x0,0x6(%rbx)
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L503
L180:
  movabs $0x574f444547415022,%rax
  mov    $0x224e,%esi
  movb   $0x0,0xa(%rbx)
  mov    %rax,(%rbx)
  mov    %si,0x8(%rbx)
  jmp    L503
  nopl   0x0(%rax,%rax,1)
L37:
  movabs $0x2245564f4d455222,%rax
  movb   $0x0,0x8(%rbx)
  add    $0x3c,%rbx
  mov    %rax,-0x3c(%rbx)
  cmp    0x8(%rsp),%rbx
  jne    L63
L563:
  mov    $0x80,%esi
  lea    D281(%rip),%rdi
  xor    %eax,%eax
  xor    %ebp,%ebp
  call   <printf@plt>
  mov    $0x14,%esi
  xor    %eax,%eax
  xor    %r14d,%r14d
  lea    D83(%rip),%rdi
  lea    D137(%rip),%r13
  call   <printf@plt>
  xor    %esi,%esi
  lea    D440(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0x1,%esi
  lea    D157(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0x2,%esi
  lea    D155(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0x3,%esi
  lea    D548(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D410(%rip),%rdi
  call   <puts@plt>
  mov    %r14d,0x8(%rsp)
  mov    0x20(%rsp),%r12
L618:
  mov    0x8(%rsp),%eax
  cmp    $0x1,%eax
  je     L197
  cmp    $0x2,%eax
  je     L315
  lea    D430(%rip),%rdi
  call   <puts@plt>
L292:
  lea    -0x1e00(%r12),%rbx
  xchg   %ax,%ax
L546:
  mov    %rbx,%rdi
  call   <strlen@plt>
  mov    $0x1,%edi
  mov    %eax,%esi
  call   <calloc@plt>
  lea    0x1(%rbx),%rsi
  mov    %rax,%r14
  mov    %rax,%rdi
  call   <strcpy@plt>
  mov    %r14,%rdi
  call   <strlen@plt>
  mov    %r14,%rdi
  cltq
  movb   $0x0,-0x1(%r14,%rax,1)
  call   <strlen@plt>
  test   %eax,%eax
  jle    L526
  mov    %ebp,%esi
  lea    0x1(%rbp),%r15d
  mov    %r14,%rdx
  mov    %r13,%rdi
  xor    %eax,%eax
  mov    %r15d,%ebp
  call   <printf@plt>
L526:
  mov    %r14,%rdi
  add    $0x3c,%rbx
  call   <free@plt>
  cmp    %r12,%rbx
  jne    L546
  addl   $0x1,0x8(%rsp)
  mov    0x8(%rsp),%eax
  lea    0x14(%rbx),%r12
  cmp    $0x3,%eax
  jne    L618
  mov    %ebp,%esi
  lea    D557(%rip),%rdi
  xor    %eax,%eax
  xor    %r12d,%r12d
  call   <printf@plt>
  lea    D159(%rip),%rdi
  lea    D382(%rip),%r14
  call   <puts@plt>
  mov    $0xa,%edi
  lea    D408(%rip),%r13
  call   <putchar@plt>
  lea    D332(%rip),%rdi
  call   <puts@plt>
  lea    D149(%rip),%r8
  xor    %eax,%eax
  lea    D121(%rip),%rcx
  lea    D21(%rip),%rdx
  lea    D526(%rip),%rsi
  lea    D334(%rip),%rdi
  call   <printf@plt>
  mov    0x10(%rsp),%rbp
  add    $0x28,%rbp
  nopw   0x0(%rax,%rax,1)
L175:
  mov    %r12d,%esi
  lea    D437(%rip),%rdi
  lea    -0x28(%rbp),%rbx
  xor    %eax,%eax
  call   <printf@plt>
L9:
  mov    %rbx,%rdi
  call   <strlen@plt>
  mov    $0x1,%edi
  mov    %eax,%esi
  call   <calloc@plt>
  lea    0x1(%rbx),%rsi
  mov    %rax,%r15
  mov    %rax,%rdi
  call   <strcpy@plt>
  mov    %r15,%rdi
  call   <strlen@plt>
  mov    %r15,%rdi
  cltq
  movb   $0x0,-0x1(%r15,%rax,1)
  call   <strlen@plt>
  test   %eax,%eax
  jle    L472
  xor    %eax,%eax
  mov    %r15,%rsi
  mov    %r14,%rdi
  call   <printf@plt>
  cmp    %rbx,%rbp
  je     L119
L332:
  mov    %r13,%rdi
  xor    %eax,%eax
  add    $0x14,%rbx
  call   <printf@plt>
  mov    %r15,%rdi
  call   <free@plt>
  jmp    L9
  xchg   %ax,%ax
L413:
  movabs $0x2250554547415022,%rax
  movb   $0x0,0x8(%rbx)
  mov    %rax,(%rbx)
  jmp    L291
  cs nopw 0x0(%rax,%rax,1)
L46:
  movl   $0x22505522,(%rbx)
  movb   $0x0,0x4(%rbx)
  jmp    L273
  nop
L454:
  mov    $0x2245,%eax
  movl   $0x4d4f4822,(%rbx)
  mov    %ax,0x4(%rbx)
  movb   $0x0,0x6(%rbx)
  jmp    L134
  nopl   0x0(%rax,%rax,1)
L86:
  movabs $0x22544847495222,%rax
  mov    %rax,(%rbx)
  jmp    L608
  nopw   0x0(%rax,%rax,1)
L122:
  mov    $0x2222,%edx
  movb   $0x0,0x2(%rbx)
  mov    %dx,(%rbx)
  jmp    L31
  nopl   0x0(%rax)
L532:
  mov    $0x2254,%ecx
  movl   $0x46454c22,(%rbx)
  mov    %cx,0x4(%rbx)
  movb   $0x0,0x6(%rbx)
  jmp    L322
L523:
  mov    %r12,%rcx
  mov    %r12,%rdx
  lea    0x3c(%rsp),%r8
  mov    %rbp,%rdi
  lea    0x2160(%rsp),%r13
  lea    D539(%rip),%rsi
  mov    %r13,%r9
  call   <sscanf@plt>
  movslq 0x3c(%rsp),%rdx
  mov    0x10(%rsp),%rcx
  lea    D174(%rip),%rsi
  mov    %rdx,%rax
  shl    $0x4,%rax
  sub    %rdx,%rax
  mov    %r13,%rdx
  lea    0x28(%rcx,%rax,4),%rdi
  xor    %eax,%eax
  call   <sprintf@plt>
  jmp    L5
  nopl   0x0(%rax)
L472:
  xor    %eax,%eax
  lea    D458(%rip),%rdi
  call   <printf@plt>
  cmp    %rbx,%rbp
  jne    L332
L119:
  mov    %r15,%rdi
  add    $0x1,%r12d
  add    $0x3c,%rbp
  call   <free@plt>
  lea    D602(%rip),%rdi
  call   <puts@plt>
  cmp    $0x80,%r12d
  jne    L175
  lea    D425(%rip),%rbp
  xor    %ebx,%ebx
  lea    D233(%rip),%r12
  mov    %rbp,%rdi
  call   <puts@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D551(%rip),%rdi
  call   <puts@plt>
  lea    D149(%rip),%r8
  xor    %eax,%eax
  lea    D121(%rip),%rcx
  lea    D21(%rip),%rdx
  lea    D526(%rip),%rsi
  lea    D334(%rip),%rdi
  call   <printf@plt>
  mov    0x28(%rsp),%r13
  nopl   (%rax)
L282:
  lea    0x14(%r13),%rcx
  lea    0x28(%r13),%r8
  mov    %r13,%rdx
  mov    %ebx,%esi
  mov    %r12,%rdi
  xor    %eax,%eax
  add    $0x1,%ebx
  add    $0x3c,%r13
  call   <printf@plt>
  cmp    $0x80,%ebx
  jne    L282
  mov    %rbp,%rdi
  call   <puts@plt>
L184:
  mov    0x2618(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L213
  add    $0x2628,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L315:
  lea    D403(%rip),%rdi
  call   <puts@plt>
  jmp    L292
L197:
  lea    D50(%rip),%rdi
  call   <puts@plt>
  jmp    L292
L35:
  mov    $0xa,%edi
  call   <putchar@plt>
  mov    (%rbx),%rsi
  lea    D42(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  mov    (%rbx),%rsi
  lea    D48(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D434(%rip),%rdi
  call   <puts@plt>
  jmp    L184
L213:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D537
datatype: string
name: unpack_data
arguments: tag: D107
datatype: string
name: unpack_data
arguments: tag: D174
datatype: string
name: unpack_data
arguments: tag: D600
datatype: string
name: unpack_data
arguments: tag: D36
datatype: string
name: unpack_data
arguments: tag: D360
datatype: string
name: unpack_data
arguments: tag: D198
datatype: string
name: unpack_data
arguments: tag: D293
datatype: string
name: unpack_data
arguments: tag: D186
datatype: string
name: unpack_data
arguments: tag: D539
datatype: string
name: unpack_data
arguments: tag: D134
datatype: string
name: unpack_data
arguments: tag: D589
datatype: string
name: unpack_data
arguments: tag: D308
datatype: string
name: unpack_data
arguments: tag: D79
datatype: string
name: unpack_data
arguments: tag: D91
datatype: string
name: unpack_data
arguments: tag: D372
datatype: string
name: unpack_data
arguments: tag: D582
datatype: string
name: unpack_data
arguments: tag: D304
datatype: string
name: unpack_data
arguments: tag: D5
datatype: string
name: unpack_data
arguments: tag: D501
datatype: string
name: unpack_data
arguments: tag: D144
datatype: string
name: unpack_data
arguments: tag: D561
datatype: string
name: unpack_data
arguments: tag: D281
datatype: string
name: unpack_data
arguments: tag: D83
datatype: string
name: unpack_data
arguments: tag: D137
datatype: string
name: unpack_data
arguments: tag: D440
datatype: string
name: unpack_data
arguments: tag: D157
datatype: string
name: unpack_data
arguments: tag: D155
datatype: string
name: unpack_data
arguments: tag: D548
datatype: string
name: unpack_data
arguments: tag: D410
datatype: string
name: unpack_data
arguments: tag: D430
datatype: string
name: unpack_data
arguments: tag: D557
datatype: string
name: unpack_data
arguments: tag: D159
datatype: string
name: unpack_data
arguments: tag: D382
datatype: string
name: unpack_data
arguments: tag: D408
datatype: string
name: unpack_data
arguments: tag: D332
datatype: string
name: unpack_data
arguments: tag: D149
datatype: string
name: unpack_data
arguments: tag: D121
datatype: string
name: unpack_data
arguments: tag: D21
datatype: string
name: unpack_data
arguments: tag: D526
datatype: string
name: unpack_data
arguments: tag: D334
datatype: string
name: unpack_data
arguments: tag: D437
datatype: string
name: unpack_data
arguments: tag: D458
datatype: string
name: unpack_data
arguments: tag: D602
datatype: string
name: unpack_data
arguments: tag: D425
datatype: string
name: unpack_data
arguments: tag: D233
datatype: string
name: unpack_data
arguments: tag: D551
datatype: string
name: unpack_data
arguments: tag: D403
datatype: string
name: unpack_data
arguments: tag: D50
datatype: string
name: unpack_data
arguments: tag: D42
datatype: string
name: unpack_data
arguments: tag: D48
datatype: string
name: unpack_data
arguments: tag: D434
datatype: string

tool: D537: rt

tool: D107: %s

tool: D174: "%s"

tool: D600: plain

tool: D36: shift

tool: D360: altgr

tool: D198: keycode

tool: D293: %s %d = %s %s %s

tool: D186: #

tool: D539: %s %s %d = %s

tool: D134: "%c"

tool: D589: "KP_0"

tool: D308: "KP_1"

tool: D79: "KP_2"

tool: D91: "KP_3"

tool: D372: "KP_4"

tool: D582: "KP_5"

tool: D304: "KP_6"

tool: D5: "KP_7"

tool: D501: "KP_8"

tool: D144: "KP_9"

tool: D561: "KP_PERIOD"

tool: D281: #define KEYCODE_KEYS	%d


tool: D83: #define KEYCODE_MAXNAMELEN	%d


tool: D137: /* %3d */  XYNTHK_%s,


tool: D440: #define KEYCODE_PLAIN	%d


tool: D157: #define KEYCODE_SHIFT	%d


tool: D155: #define KEYCODE_ALTGR	%d


tool: D548: #define KEYCODE_FLAGS	%d


tool: D410: typedef enum {

tool: D430: /* Plain */

tool: D557: /* %3d */  XYNTHK_CODES


tool: D159: } XYNTHK_CODE;

tool: D382: XYNTHK_%s

tool: D408: ,	

tool: D332: static XYNTHK_CODE kbd_keycodes_[KEYCODE_KEYS][KEYCODE_FLAGS][KEYCODE_MACNAMELEN] = {

tool: D149: altgr name 

tool: D121: shift name,

tool: D21: plain name,

tool: D526: keycode,

tool: D334: /*%10s %18s %18s %17s*/


tool: D437: /* %3d */  {

tool: D458: XYNTH_NOCODE

tool: D602: },

tool: D425: };

tool: D233: /* %3d */  {%18s,%18s,%18s},


tool: D551: static char kbd_keycodes[KEYCODE_KEYS][KEYCODE_FLAGS][KEYCODE_MAXNAMELEN] = {

tool: D403: /* ALTGR */

tool: D50: /* Shift */

tool: D42: %s is to prepare a hader file from a map file.


tool: D48: Ex:
	mkdir kbdmap
	files included in the us.map.gz are;
		compose.latin1
		euro1.map
		linux-keys-bare.inc
		linux-with-alt-and-altgr.inc
		qwerty-layout.inc
	copy all_of_them_and_the_us.map.gz to kbdmap
	gunzip us.map.gz
	cat * > usmap
	%s usmap > usmap.h



tool: D434: Alper Akcan, distchx@yahoo.com


assistant: ```c
int main(int argc, char *argv[]) {
  int i;
  int j;
  int k;
  FILE *mapfile;
  char codenames[128][3][20];
  int size = sizeof(codenames);
  char buf[400];
  char buf1[400];
  char buf2[400];
  char buf3[400];
  char buf4[400];
  int int1;
  if (argc < 2) {
    printf("\n");
    printf("%s is to prepare a hader file from a map file.\n", argv[0]);
    printf("\n");
    printf("Ex:\n"
           "\tmkdir kbdmap\n"
           "\tfiles included in the us.map.gz are;\n"
           "\t\tcompose.latin1\n"
           "\t\teuro1.map\n"
           "\t\tlinux-keys-bare.inc\n"
           "\t\tlinux-with-alt-and-altgr.inc\n"
           "\t\tqwerty-layout.inc\n"
           "\tcopy all_of_them_and_the_us.map.gz to kbdmap\n"
           "\tgunzip us.map.gz\n"
           "\tcat * > usmap\n"
           "\t%s usmap > usmap.h\n\n",
           argv[0]);
    printf("Alper Akcan, distchx@yahoo.com\n\n");
    return 0;
  }
  memset(codenames, 0, size);
  mapfile = fopen(argv[1], "rt");
  for (i = 0; i < 128; i++) {
    for (j = 0; j < 3; j++) {
      sprintf(codenames[i][j], "\"\"");
    }
  }
  while (!feof(mapfile)) {
    fgets(buf, 400, mapfile);
    sscanf(buf, "%s", buf1);
    buf3[0] = '\0';
    buf4[0] = '\0';
    if (strcmp(buf1, "keycode") == 0) {
      sscanf(buf, "%s %d = %s %s %s", buf1, &int1, buf2, buf3, buf4);
      sprintf(codenames[int1][0], "\"%s\"", buf2);
      if ((strcmp(buf3, "#") != 0) && (buf3[0] != '\0')) {
        sprintf(codenames[int1][1], "\"%s\"", buf3);
        if ((strcmp(buf4, "#") != 0) && (buf4[0] != '\0')) {
          sprintf(codenames[int1][2], "\"%s\"", buf4);
        }
      }
    }
    if (strcmp(buf1, "plain") == 0) {
      sscanf(buf, "%s %s %d = %s", buf1, buf1, &int1, buf2);
      sprintf(codenames[int1][0], "\"%s\"", buf2);
    }
    if (strcmp(buf1, "shift") == 0) {
      sscanf(buf, "%s %s %d = %s", buf1, buf1, &int1, buf2);
      sprintf(codenames[int1][1], "\"%s\"", buf2);
    }
    if (strcmp(buf1, "altgr") == 0) {
      sscanf(buf, "%s %s %d = %s", buf1, buf1, &int1, buf2);
      sprintf(codenames[int1][2], "\"%s\"", buf2);
    }
  }
  for (i = 0; i < 128; i++) {
    for (j = 0; j < strlen(codenames[i][0]); j++) {
      codenames[i][0][j] = toupper(codenames[i][0][j]);
    }
    for (j = 0; j < strlen(codenames[i][1]); j++) {
      codenames[i][1][j] = toupper(codenames[i][1][j]);
    }
    for (j = 0; j < strlen(codenames[i][2]); j++) {
      codenames[i][2][j] = toupper(codenames[i][2][j]);
    }
  }
  for (j = 65; j < 91; j++) {
    sprintf(buf1, "\"%c\"", j);
    for (i = 0; i < 128; i++) {
      if (strcmp(codenames[i][0], buf1) == 0) {
        sprintf(codenames[i][0], "\"%c\"", j + 32);
        sprintf(codenames[i][1], "\"%c\"", j);
      }
    }
  }
  for (i = 0; i < 128; i++) {
    if (strcmp(codenames[i][0], "\"KP_0\"") == 0) {
      sprintf(codenames[i][1], "\"INSERT\"");
    }
    if (strcmp(codenames[i][0], "\"KP_1\"") == 0) {
      sprintf(codenames[i][1], "\"END\"");
    }
    if (strcmp(codenames[i][0], "\"KP_2\"") == 0) {
      sprintf(codenames[i][1], "\"DOWN\"");
    }
    if (strcmp(codenames[i][0], "\"KP_3\"") == 0) {
      sprintf(codenames[i][1], "\"PAGEDOWN\"");
    }
    if (strcmp(codenames[i][0], "\"KP_4\"") == 0) {
      sprintf(codenames[i][1], "\"LEFT\"");
    }
    if (strcmp(codenames[i][0], "\"KP_5\"") == 0) {
      sprintf(codenames[i][1], "\"\"");
    }
    if (strcmp(codenames[i][0], "\"KP_6\"") == 0) {
      sprintf(codenames[i][1], "\"RIGHT\"");
    }
    if (strcmp(codenames[i][0], "\"KP_7\"") == 0) {
      sprintf(codenames[i][1], "\"HOME\"");
    }
    if (strcmp(codenames[i][0], "\"KP_8\"") == 0) {
      sprintf(codenames[i][1], "\"UP\"");
    }
    if (strcmp(codenames[i][0], "\"KP_9\"") == 0) {
      sprintf(codenames[i][1], "\"PAGEUP\"");
    }
    if (strcmp(codenames[i][0], "\"KP_PERIOD\"") == 0) {
      sprintf(codenames[i][1], "\"REMOVE\"");
    }
  }
  printf("#define KEYCODE_KEYS\t%d\n", 128);
  printf("#define KEYCODE_MAXNAMELEN\t%d\n", 20);
  printf("#define KEYCODE_PLAIN\t%d\n", 0);
  printf("#define KEYCODE_SHIFT\t%d\n", 1);
  printf("#define KEYCODE_ALTGR\t%d\n", 2);
  printf("#define KEYCODE_FLAGS\t%d\n", 3);
  printf("\n");
  printf("typedef enum {\n");
  k = 0;
  for (j = 0; j < 3; j++) {
    switch (j) {
    case 0:
      printf("/* Plain */\n");
      break;
    case 1:
      printf("/* Shift */\n");
      break;
    case 2:
      printf("/* ALTGR */\n");
      break;
    }
    for (i = 0; i < 128; i++) {
      char *name;
      name = (char *)calloc(sizeof(char), strlen(codenames[i][j]));
      sprintf(name, "%s", codenames[i][j] + 1);
      name[strlen(name) - 1] = '\0';
      if (strlen(name) > 0) {
        printf("/* %3d */  XYNTHK_%s,\n", k++, name);
      }
      free(name);
    }
  }
  printf("/* %3d */  XYNTHK_CODES\n", k);
  printf("} XYNTHK_CODE;\n");
  printf("\n");
  printf("static XYNTHK_CODE kbd_keycodes_[KEYCODE_KEYS][KEYCODE_FLAGS][KEYCODE_MACNAMELEN] = {\n");
  printf("/*%10s %18s %18s %17s*/\n", "keycode,", "plain name,", "shift name,", "altgr name ");
  for (i = 0; i < 128; i++) {
    printf("/* %3d */  {", i);
    for (j = 0; j < 3; j++) {
      char *name;
      name = (char *)calloc(sizeof(char), strlen(codenames[i][j]));
      sprintf(name, "%s", codenames[i][j] + 1);
      name[strlen(name) - 1] = '\0';
      if (strlen(name) > 0) {
        printf("XYNTHK_%s", name);
      } else {
        printf("XYNTH_NOCODE");
      }
      if (j < 2) {
        printf(",\t");
      }
      free(name);
    }
    printf("},\n");
  }
  printf("};\n");
  printf("\n");
  printf("static char kbd_keycodes[KEYCODE_KEYS][KEYCODE_FLAGS][KEYCODE_MAXNAMELEN] = {\n");
  printf("/*%10s %18s %18s %17s*/\n", "keycode,", "plain name,", "shift name,", "altgr name ");
  for (i = 0; i < 128; i++) {
    printf("/* %3d */  {%18s,%18s,%18s},\n", i, codenames[i][0], codenames[i][1], codenames[i][2]);
  }
  printf("};\n");
  return 0;
}
```