logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

main.go (1313B)


  1. // Package for taking a mapping of words to keys and outputing a
  2. // combo engine commpatible def
  3. package main
  4. import (
  5. "io/ioutil"
  6. "fmt"
  7. "encoding/json"
  8. "os"
  9. "sort"
  10. "strings"
  11. "hash/crc64"
  12. //"encoding/base64"
  13. )
  14. func main() {
  15. // Show Usage
  16. if len(os.Args) < 3 {
  17. fmt.Println("Usage: ./keymap-gen inputfile outfile")
  18. fmt.Println("Outputs dict in current dir")
  19. return
  20. }
  21. // Read the source
  22. data, err := ioutil.ReadFile(os.Args[1])
  23. if err != nil {
  24. panic(err)
  25. }
  26. // Unbundle Data
  27. var FullDict map[string]string
  28. var output []string
  29. json.Unmarshal(data, &FullDict)
  30. // Loop over entries and store
  31. for i,v := range FullDict {
  32. // This checks for colllisions, Generates hash
  33. hash := crc64.Checksum([]byte(v), crc64.MakeTable(crc64.ECMA))
  34. hashStr := fmt.Sprintf("txt_%x", hash)[:10]
  35. // Format keys into combo
  36. var keys string
  37. for _, k := range(v) {
  38. keys += fmt.Sprintf("KC_%v, ", string(k))
  39. }
  40. keys = keys[:len(keys)-2]
  41. // Append to output
  42. spacer := strings.Repeat(" ", 15-len(i))
  43. output = append(output, fmt.Sprintf("SUBS(%v, %v\"%v\", %v)\n", hashStr, spacer, i, keys))
  44. }
  45. sort.Slice(output, func (i,j int) bool {
  46. return strings.Count(output[i], " ") > strings.Count(output[j], " ")
  47. })
  48. ioutil.WriteFile(os.Args[2], []byte(strings.Join(output, "")), 0555)
  49. }