home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / keybind / n_list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  2.4 KB  |  106 lines

  1. /*{{{}}}*/
  2. /*{{{  #includes*/
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7.  
  8. #define NAME_C
  9.  
  10. #include "keybind.h"
  11. /*}}}  */
  12.  
  13. /*{{{  type name_code*/
  14. typedef struct { char *name;char *code; } name_code;
  15. /*}}}  */
  16.  
  17. #include "autotoken.h"
  18.  
  19. /*{{{  cmp*/
  20. int cmp(const void *a, const void *b)
  21. {
  22.   return(strcmp(((name_code*)a)->name,((name_code*)b)->name));
  23. }
  24. /*}}}  */
  25. /*{{{  sort_and_print*/
  26. void sort_and_print(name_code *list,char *type,char *name,int use)
  27. {
  28.   size_t n;
  29.  
  30.   /*{{{  sort the names*/
  31.   { name_code *x;
  32.  
  33.     for (n=0,x=list;x->name;n++,x++);
  34.     qsort(list,n,sizeof(name_code),cmp);
  35.   }
  36.   /*}}}  */
  37.   /*{{{  print the list*/
  38.   printf("/*{{{  %s*/\n",name);
  39.   /*{{{  print sizes*/
  40.   { size_t x;
  41.  
  42.     printf("#define N_%s %d\n",name,n);
  43.     for (x=1;x<n;x=x<<1);
  44.     printf("#define S_%s %d\n",name,x>>1);
  45.   }
  46.   /*}}}  */
  47.   printf("public %s %s[]={\n",type,name);
  48.   /*{{{  print list of names/codes*/
  49.   for (;list->name;list++)
  50.      printf("  {(unsigned char*)\"%s\",%s%s},\n",list->name,list->code,use?",1":"");
  51.   /*}}}  */
  52.   printf("  {0,%s%s}\n};\n",list->code?list->code:"0",use?",0":"");
  53.   printf("/*}}}*/\n");
  54.   /*}}}  */
  55. }
  56. /*}}}  */
  57. /*{{{  main*/
  58. int main()
  59. {
  60.   printf("#ifndef MESSAGES_C\n");
  61.      /*{{{  handle constant names*/
  62.      printf("/*{{{  single names*/\n");
  63.      { name_code *x;
  64.  
  65.        for (x=singles;x->name;x++)
  66.           printf("public unsigned char const %s[]=\"%s\";\n",x->code,x->name);
  67.      }
  68.      printf("/*}}}*/\n");
  69.      /*}}}  */
  70.      /*{{{  handle keybindings table*/
  71.      sort_and_print(binding_names,"KEYNAME","bindings",1);
  72.      /*}}}  */
  73.      /*{{{  handle keyword table*/
  74.      sort_and_print(keytab_names,"keywords const","keytab",0);
  75.      /*}}}  */
  76.      /*{{{  handle asm-token table*/
  77.      sort_and_print(asm_token_names,"KEYNAME const","asm_token",1);
  78.      /*}}}  */
  79.   printf("#else\n");
  80.      /*{{{  handle string defines*/
  81.      printf("/*{{{  name defines*/\n");
  82.      { name_code *x;
  83.  
  84.        for (x=keytab_names;x->name;x++)
  85.            printf
  86.             ( "#ifndef %s_STR\n#  define %s_STR \"%s\"\n#endif\n",
  87.               x->code,
  88.               x->code,
  89.               x->name
  90.             );
  91.        for (x=singles;x->name;x++)
  92.            printf
  93.             ( "#ifndef %s_STR\n#  define %s_STR \"%s\"\n#endif\n",
  94.               x->code,
  95.               x->code,
  96.               x->name
  97.             );
  98.      }
  99.      printf("/*}}}*/\n");
  100.      /*}}}  */
  101.   printf("#endif\n");
  102.  
  103.   return(0);
  104. }
  105. /*}}}  */
  106.