home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / reactivekbd / part01 / command_line.c next >
Encoding:
C/C++ Source or Header  |  1989-10-16  |  5.7 KB  |  213 lines

  1. #define ZERO_FREQ_FILE "/.rk.zero_freq"
  2. #define PRIME_FILE "/.rk.log_file"
  3. #define KEY_FILE "/.rk.keys"
  4.  
  5. #include "file+rk.h"
  6. #include "rk_button.h"
  7. #include "sys/file.h"
  8. #include <stdio.h>
  9.  
  10. print_help()
  11. {
  12.     printf("RK command line arguments:\n");
  13.  
  14.     printf("    -b <buffers>    The number of buffers used by rk to save previous\n");
  15.     printf("             commands used by 'previous_line'. Default: 60.\n\n");
  16.  
  17.     printf("    -e <length>    The maximum length of predictions at the end of the\n");
  18.     printf("            line. Default: 40.\n\n");
  19.  
  20.  
  21.     printf("    -f <count>    The maximum frequency count for any given context\n");
  22.     printf("            Default: 128\n\n");
  23.  
  24.     printf("    -i <length>    The maximum length of predictions in the middle of\n");
  25.     printf("            the line. Default: 8.\n\n");
  26.  
  27.     printf("    -k <keys file>    The file to read key bindings from.\n");
  28.     printf("            Default:$HOME/.rk.keys\n\n");
  29.  
  30.     printf("    -n <nodes>    The amount of memory to allocate initially to speed\n");
  31.     printf("            up creation of nodes.  After this memory is used up,\n");
  32.     printf("            more will be allocated, but this will be slower.\n");
  33.     printf("            Default: 64*1024 nodes.\n\n");
  34.  
  35.     printf("    -o <order>    This argument controls how deep a tree will be built\n");
  36.     printf("            by rk inorder to make predictions.  As order\n");
  37.     printf("            increases, the accuracy of predictions increases,\n");
  38.     printf("            but the speed decreases. Default: 8.\n\n");
  39.     printf("    -p <prime file>    The file used to prime the Reactive Keyboard.\n");
  40.     printf("            Default:$HOME/.rk.log_file.\n\n");
  41.  
  42.  
  43.     printf("    -s <startup>    The maximum number of characters to be read from the\n");
  44.     printf("             prime file at startup. Default: 16*1024.\n\n");
  45.  
  46.     printf("    -z <zero freq>    The zero frequency file name.\n");
  47.     printf("            Default:$HOME/.rk.zero_freq\n\n");
  48.  
  49.     printf("    -A    Toggle add_space_mode\n");
  50.     printf("    -E    Toggle eol_only mode.\n");
  51.     printf("    -L    Toggle eol_longer mode.\n");
  52.     printf("    -N    Toggle truncate at newline mode.\n");
  53.     printf("    -P    Toggle predictions on/off.\n");
  54.     printf("    -S    Toggle show_eol_mode.\n");
  55.     printf("    -g    Make this not a login shell.\n");
  56.     printf("    -h    Print this help.\n");
  57.     printf("    -l    Toggle lisp mode.\n");
  58.     printf("    -m    Start up silently.\n");
  59.     printf("    -v    Print Version.\n");
  60.  
  61. }
  62.  
  63. print_version()
  64. {
  65.     char            tbuf[128];
  66.     printf("RK_Button Version:%s.\n", RK_VERSION);
  67. }
  68.  
  69. extern ED_STRUCT editor_data;
  70.  
  71.  
  72. get_command_line_arguments(argc,argv)
  73. int argc;
  74. char *argv[];
  75. {
  76.     extern int optind;
  77.     extern char *optarg;
  78.     int i;
  79.  
  80.     extern num_buffers;
  81.     extern char *zero_freq_file;
  82.     static char z_freq_buf[256];
  83.     extern char *prime_file;
  84.     static char prime_buf[256];
  85.     extern char *key_file;
  86.     static char key_buf[256];
  87.     extern    max_len;
  88.     extern    max_eol;
  89.     extern    maxk;
  90.     extern    maxprime;
  91.     extern  max_freq;
  92.     extern  max_nodes;
  93.     extern  char silent;
  94.     extern  char login;
  95.     extern  char pred_mode,
  96.              pred_on_display,
  97.              lisp_mode,
  98.              nl_truncate_mode,
  99.              eol_only_mode,
  100.              eol_longer_mode,
  101.                  add_space_mode,
  102.              show_eol_mode;
  103.     
  104.     zero_freq_file=prime_file=key_file=NULL;
  105.  
  106.     while ((i = getopt(argc, argv,"b:e:f:i:k:n:o:p:s:z:AELNPSghlmv")) 
  107.                 != EOF) {
  108.         switch( i ) {
  109.         case 'b': num_buffers=atoi(optarg)+1;
  110.             if(num_buffers<1)
  111.                 abortit("-b:Buffers must be larger than 1.\n",-1);
  112.             break;
  113.             /* 1.. MAXINT*/
  114.         case 'e': max_eol=atoi(optarg);
  115.             if((max_eol<1)||(max_eol>132))
  116.                 abortit("-e:End of line length must be between 1 and 132.\n",-1);
  117.             break;
  118.             /* 1..132 */
  119.         case 'f': max_freq=atoi(optarg);
  120.             if((max_freq<3)||(max_freq>255))
  121.                 abortit("-f:Maximum Frequency must be between 3 and 255.\n",-1);
  122.             break;
  123.         case 'i': max_len=atoi(optarg);
  124.             if((max_len<1)||(max_len>132))
  125.                 abortit("-i:Inline Length must be between 1 and 132.\n",-1);
  126.             break;
  127.             /* 1..132 */
  128.         case 'k':
  129.             if( key_file ) {
  130.                 fprintf(stderr,"%s: Too many -k options\n",argv[0]);
  131.                 abortit("",1);
  132.             }
  133.             key_file=optarg;
  134.             /* check for existance */
  135.             if(access(key_file,R_OK)){
  136.                 perror(key_file);
  137.                 abortit("",-1);
  138.             }        
  139.              break;
  140.         case 'n': max_nodes=atoi(optarg);
  141.             if(max_nodes<0)
  142.                 abortit("-n:Number of nodes must be positive.\n",-1);
  143.             break;                
  144.         case 'o': maxk=atoi(optarg);
  145.             if((maxk<3)||(maxk>TOP_K)){
  146.                 fprintf(stderr,"-o: Order must be between 3 and %d.\n",TOP_K);
  147.                 abortit("",-1);
  148.             }
  149.             break;
  150.         case 'p':
  151.              if( prime_file ) {
  152.                 fprintf(stderr, "%s: Too many -p options\n",argv[0]);
  153.                 abortit("",1);
  154.             }
  155.             prime_file=optarg;
  156.             /* check for existance */
  157.             if(access(prime_file,(R_OK|W_OK))){
  158.                 perror(prime_file);
  159.                 abortit("",-1);
  160.             }        
  161.             break;
  162.         case 's': maxprime=atoi(optarg); break;
  163.  
  164.         case 'z': 
  165.              if( zero_freq_file ) {
  166.                 fprintf(stderr, "%s: Too many -z options\n",argv[0]);
  167.                 abortit("",1);
  168.             }
  169.             zero_freq_file=optarg;
  170.             /* check for existance */
  171.             if(access(zero_freq_file,(R_OK|W_OK))){
  172.                 perror(zero_freq_file);
  173.                 abortit("",-1);
  174.             }        
  175.             break;
  176.         case 'A': add_space_mode=!add_space_mode;    break;
  177.         case 'E': eol_only_mode=!eol_only_mode;        break;
  178.         case 'L': eol_longer_mode=!eol_longer_mode;    break;
  179.         case 'N': nl_truncate_mode=!nl_truncate_mode;    break;
  180.         case 'P': pred_mode=!pred_mode;            break;
  181.         case 'S': show_eol_mode=!show_eol_mode;        break;
  182.         case 'g': login=!login;             break;
  183.         case 'h': print_help();    abortit("",0);        break;
  184.         case 'l': lisp_mode=!lisp_mode;            break;
  185.         case 'm': silent=1;                break;
  186.         case 'v': print_version();abortit("",0);    break;
  187.         
  188.  
  189.         default:
  190.             fprintf(stderr,"\r%s: Use -h for help\r\n", argv[0]);
  191.             abortit("",-1);
  192.         }
  193.     
  194.     }
  195.     
  196.     if(zero_freq_file==NULL){
  197.         strcpy(z_freq_buf, getenv("HOME"));
  198.         strcat(z_freq_buf, ZERO_FREQ_FILE );
  199.         zero_freq_file=z_freq_buf;
  200.     }
  201.     if(prime_file==NULL){
  202.         strcpy(prime_buf, getenv("HOME"));
  203.         strcat(prime_buf, PRIME_FILE );
  204.         prime_file=prime_buf;
  205.     }
  206.     if(key_file==NULL){
  207.         strcpy(key_buf, getenv("HOME"));
  208.         strcat(key_buf, KEY_FILE );
  209.         key_file=key_buf;
  210.     }
  211.  
  212. }
  213.