Пример #1
0
int main(int argc, char *argv[]) {
    int opt;

    char *scriptfile, prompt[50];
    extern void my_interfaceparse(char *my_string);
    /*  YY_BUFFER_STATE flex_command; */
    stack_init();
    while ((opt = getopt(argc, argv, "e:f:hl:pqrsv")) != -1) {
        switch(opt) {
        case 'e':
            my_interfaceparse(optarg);
            break;
        case 'f':
            scriptfile = file_to_mem(optarg);
            if (scriptfile != NULL) {
                input_is_file = 1;
                my_interfaceparse(scriptfile);
            }
            exit(0);
        case 'h':
            print_help();
            exit(0);
        case 'l':
            scriptfile = file_to_mem(optarg);
            if (scriptfile != NULL) {
                input_is_file = 1;
                my_interfaceparse(scriptfile);
		xxfree(scriptfile);
            }
            break;
        case 'p':
            pipe_mode = 1;
            break;
        case 'q':
            quiet_mode = 1;
            break;
        case 'r':
            use_readline = 0;
            break;
        case 's':
	  exit(0);
        case 'v':
            printf("%s %i.%i.%i%s\n",argv[0],MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,STATUS_VERSION);
            exit(0);
        default:
            fprintf(stderr, "%s", usagestring);
            exit(EXIT_FAILURE);
        }
    }

    if (!pipe_mode && !quiet_mode) 
        printf("%s",disclaimer);
    rl_basic_word_break_characters = " >";

    rl_attempted_completion_function = my_completion;
    for(;;) {
        if (promptmode == PROMPT_MAIN)
            sprintf(prompt, "foma[%i]: ",stack_size());
        if (promptmode == PROMPT_A && apply_direction == AP_D)
            sprintf(prompt, "apply down> ");
        if (promptmode == PROMPT_A && apply_direction == AP_U)
            sprintf(prompt, "apply up> ");
        if (promptmode == PROMPT_A && apply_direction == AP_M)
            sprintf(prompt, "apply med> ");
        if (pipe_mode || quiet_mode)
            prompt[0] = '\0';

        command = rl_gets(prompt);

        if (command == NULL && promptmode == PROMPT_MAIN) {
            printf("\n");
            exit(0);
        }
        if (command == NULL && promptmode == PROMPT_A) {
            /* apply_clear(); */
            promptmode = PROMPT_MAIN;
            printf("\n");
            continue;
        }
        input_is_file = 0;
        my_interfaceparse(command);
    }
}
Пример #2
0
int system_copy_qson(IO_Structure *from,IO_Structure *to ) {
  machine_reset(get_ready_stmt());  // big deal, start fresh
  // if the source is memory format
  if(from->sa_family ==  AF_MEMORY) {
    if(to->sa_family== AF_FILE) {
      FILE *fd;
      fd= fopen((char *)to->addr, "w+");
      printf("File out %s\n",(char *)  to->addr);
      mem_to_file(fd,(int *) from->buff,AF_FILE);
      fflush(fd);
      fclose(fd);
    }  else if(to->sa_family== AF_CONSOLE) {
      mem_to_file(stdout,(int *) from->buff,AF_CONSOLE);
    } else if(to->sa_family== AF_TABLE){
      TABLE * table;
      init_table((char *) to->addr,1,&table);
      to->buff = (void*) table;
      mem_to_table(table,(int *) from->buff,AF_TABLE);
    } else if(to->sa_family== AF_INET)
      mem_to_net(to->fd,(int *) from->buff,Qson_IO);
    // If the source is a table
  }else if(from->sa_family== AF_TABLE ) {
     TABLE * table;
    if( (to->sa_family== AF_CONSOLE) || ( to->sa_family== AF_INET)) {
      printf("Table from %s\n",(char *)  from->addr);
      init_table((char *) from->addr,0,&table);
      to->buff = (void*) table;
      table_to_Json(table,to);
    }else if(to->sa_family== AF_TABLE)
      dup_table((char *) from->addr,(char *) to->addr);
    else if(to->sa_family== AF_MEMORY){
      init_table((char *) from->addr,0,&table);
      to->buff = (void *) table_to_mem(table);

    }
    // else this might be from the network
  } else if ((from->sa_family== AF_INET) || 
    (from->sa_family== AF_CONSOLE)|| (from->sa_family== AF_FILE) ) {
    if( to->sa_family== AF_TABLE) { 
      TABLE * table;
      DBG_printf("New Table  %s\n",(char *)  to->addr);
      init_table((char *) to->addr,1,&table);
      to->buff = (void*) table;
      if(from->format == Json_IO) 
        parser((char *) from->buff,table);    // Json from the net
      else if (from->format == Qson_IO)
        qson_to_table(table,(char *) to->buff,to->count);
    }
    // source is file
  }  else if(from->sa_family== AF_FILE) {
    if(to->sa_family== AF_MEMORY){
      FILE *fd;
      printf("File in %s\n",(char *)  from->addr);
      fd= fopen((char *) from->addr, "r");
      to->buff = file_to_mem(fd);
      fclose(fd);

    }
  }
  return 0;
}