Exemplo n.º 1
0
   /* 
    * run the program
    */
int main()
{
      // holds the directories in the path
   char path_dirs[ MAX_PATHS ][ MAX_PATH_LEN ];
      
   int num_dirs = parse_path( path_dirs );
   
   char line[ LINE_LEN ];
   command_t cmd;

      // get input
   print_prompt();
   read_cmd( line );
   parse_cmd( line, &cmd );

      // until we get a line that starts with exit or quit
   while( !cmd.argv[0] || 
          ( strcmp( cmd.argv[0], "quit" ) && 
            strcmp( cmd.argv[0], "exit" ) ) )
   {
      if( cmd.argv[0] )
         cmd.name = lookup_path( cmd.argv, path_dirs, num_dirs );

      if( cmd.name && cmd.argc > 0 )
      {
            // create the child
         pid_t child_pid = fork();
         if( child_pid < 0 )
            perror( "fork" );
         else if( child_pid == 0 ) // child
            execv( cmd.name, cmd.argv );
         else  // parent
         {
            if( !cmd.concurrent )
            {
               int status;
               waitpid( child_pid, &status, 0 );
            }
         }
      }

      cleanup_cmd( &cmd );
         
         // get input
      print_prompt();
      read_cmd( line );
      parse_cmd( line, &cmd );
   }

   return 0;
}
Exemplo n.º 2
0
 void handle_cmd(const boost::system::error_code& error) {
     if(!error) {
         if(isgraph(m_cmd_buf)) {
             std::cout << "Command " << m_cmd_buf << std::endl;
             switch(m_cmd_buf) {
             case 'a':
                 m_radar->power_on();
                 break;
             case 'q':
                 m_radar->power_off();
                 break;
             case 'w':
                 m_radar->set_range(0.25);
                 break;
             case 'e':
                 m_radar->set_range(0.50);
                 break;
             case 'r':
                 m_radar->set_range(1.00);
                 break;
             case 't':
                 m_radar->set_range(3.00);
                 break;
             case 'x':
                 m_radar->set_crosstalk(false);
                 break;
             case 'X':
                 m_radar->set_crosstalk(true);
                 break;
             case 'c':
                 m_radar->set_ftc(false);
                 break;
             case 'C':
                 m_radar->set_ftc(true);
                 break;
             case 's':
                 m_radar->set_gain(false);
                 break;
             case 'd':
                 m_radar->set_gain(true, 0);
                 break;
             case 'f':
                 m_radar->set_gain(true, 25);
                 break;
             case 'g':
                 m_radar->set_gain(true, 50);
                 break;
             case 'h':
                 m_radar->set_gain(true, 75);
                 break;
             case 'j':
                 m_radar->set_gain(true, 100);
                 break;
             default:
                 break;
             }
         }
         read_cmd();
     }
 }
Exemplo n.º 3
0
/*
 * Main procedure loops over user requests.
 */
int main()
{
  int	  i = 0 ;
  char	  c ; // Command Read From Input.

  // Open CD ROM Drive.
  if	( cd_init() < 0 )
	{
	  show_error( ERROR, cd_error ) ;
	  return 1;
  	}
	
  // Shows possible commands.
  show_usage();

  // While Not Quit.
  while ((c = read_cmd()) != 'q' )
	{

          if	(( i = valid_cmd( c )) == -1 )
		{
		  printf("Unrecognised command: `%c'\n", c ) ;
		}
	  else
		{
		  (*myCmdStruct[i].func)() ;
		}
    	}

  // Stop Device.
  cd_exit();
    
  return 0 ;
}
Exemplo n.º 4
0
void	user_loop(t_sh *shell)
{
  char	*lign;
  char	*prompt;
  t_fds	tmpfd;

  init_stdfd_t_def_val(&tmpfd, 0, 1, 2);
  prompt = recalc_prompt(shell);
  while ((lign = read_cmd(prompt, &(shell->param), &shell->history)) != NULL)
    {
      parseur_history(&lign, shell->history);
      add_history_after_line(lign, &shell->history);
      no_fg_jobs_status(shell);
      call_signal_func(shell, 0, NULL);
      wait_no_fg_grp(shell);
      shell->too_much_parsing = 0;
      check_and_load_backquote(&lign, shell);
      parse_user_cmd(shell, &lign, &tmpfd);
      if (MEXIT)
        return ;
      wait_no_fg_grp(shell);
      free(prompt);
      free(lign);
      prompt = recalc_prompt(shell);
    }
  free(prompt);
}
Exemplo n.º 5
0
int cd(const char* input, char* cmd, int i)
{
    /* Change to home directory */
    if (input[i] == '\0' || input[i] == '~')
    {
        char* home = getenv("HOME");
        if (!home)
        {
            perror("Failed to get home directory");
            return 0;
        }
        else if (chdir(home))
        {
            perror("Failed to change directory to HOME");
            return 0;
        }
    }
    /* Change to given directory */
    else
    {
        i = read_cmd(cmd, input, i);
        if (chdir(cmd))
        {
            perror("Failed to change directory");
            return 0;
        }
    }

    return 1;
}
Exemplo n.º 6
0
void srCmdLine::test_prompt( void )	{
	bool quit = false;
	bool verbose = false;
	int buffer_cap = 0;
	char *cmd_buffer = NULL;
	
	fprintf( stdout, "> " ); fflush( stdout );
	
	int buffer_use = 0;
	while( !quit ) {

		int in_mode = commandline_query( &cmd_buffer, &buffer_cap, &buffer_use, &buffer_pos, verbose );
		if( in_mode == STRING_MODE )	{
			char *cmd = read_cmd();

			if( LinWin_strcmp( cmd, "v" ) == 0 )	{
				verbose = true;
			}
			else
			if( LinWin_strcmp( cmd, "s" ) == 0 )	{
				verbose = false;
			}
			else
			if( LinWin_strcmp( cmd, "q" ) == 0 )	{
				quit = true;
			}
			// parse...

			if( !quit ) {
				fprintf( stdout, "> " );
				fflush( stdout );
			}
		}
	}
}
Exemplo n.º 7
0
void main(void)
{
  UCHAR cmd[0x8000];
  BOOL exitflag;

  log_init();

  hello();

  log(greeting);
  log("DosLogWrite address: %x\n", DosLogWrite);

  exitflag=FALSE;
  // Ok. Here we just in endless loop. Except for EXIT command.

  // create the global env. array
  env_create();

  while (!exitflag)
  {
    showpath();
    read_cmd (cmd);
    exitflag = parse_cmd (cmd);
  }

  // destroy the global env. array
  env_destroy();

  exit(0);
}
Exemplo n.º 8
0
char			*usr_cmd(int fd, t_history *histo, t_options options)
{
  struct termios	set;
  struct termios	unset;
  char			*str;
  char			*cmd;
  int			rev_c;
  int			histo_pl;

  (void)options;
  if (init_termios(&set, &unset) == -1 ||
      init_values(&histo_pl, &rev_c, &str, &cmd) == -1)
    return (unset_termios(&unset));
  show_cmd(str[0], fd, cmd, rev_c);
  while (str[0] != 10 || str[1] != 0 || str[2] != 0)
    {
      if (read_cmd(fd, &str, &cmd, &rev_c) == -1)
	return (unset_termios(&unset));
      if (histo_pl < length_of_history(histo) && chk_str(str, 27, 91, 65) == 0)
	if (take_cmd_from_history(++histo_pl, &rev_c, &cmd, histo) == -1)
	  return (unset_termios(&unset));
      if (histo_pl > 0 && chk_str(str, 27, 91, 66) == 0)
	if (take_cmd_from_history(--histo_pl, &rev_c, &cmd, histo) == -1)
	  return (unset_termios(&unset));
      show_cmd(str[0], fd, cmd, rev_c);
    }
  return (finish_usr_cmd(cmd, str, unset));
}
Exemplo n.º 9
0
int main() {
  ETERM *tuplep, *intp;
  ETERM *fnp, *argp;
  int res;
  byte buf[100];
  long allocated, freed;

  erl_init(NULL, 0);

  while (read_cmd(buf) > 0) {
    tuplep = erl_decode(buf);
    fnp    = erl_element(1, tuplep);
    argp   = erl_element(2, tuplep);
    
    if (strncmp(ERL_ATOM_PTR(fnp), "foo", 3) == 0) {
      res = foo(ERL_INT_VALUE(argp));
    } else if (strncmp(ERL_ATOM_PTR(fnp), "bar", 17) == 0) {
      res = bar(ERL_INT_VALUE(argp));
    }

    intp = erl_mk_int(res);
    erl_encode(intp, buf);
    write_cmd(buf, erl_term_len(intp));

    erl_free_compound(tuplep);
    erl_free_term(fnp);
    erl_free_term(argp);
    erl_free_term(intp);
  }
}
Exemplo n.º 10
0
int main(int argc, char** argv)
{
    int fn, arg1, arg2, result;
    byte buff[100];
    /* Part where serial port is initialized */
    while(read_cmd(buff) > 0)
    {
        fn = buff[0];
        if (fn == 1)
        {
            arg1 = buff[1];
            result = arg1*2;
        }
        else if (fn == 2)
        {
            arg1 = buff[1];
            arg2 = buff[2];
            result = arg1+arg2;
        }

        buff[0] = result;
        write_cmd(buff, 1);
    }

    return(0);
}
Exemplo n.º 11
0
int main() {
  int fn, arg1, arg2;
  byte buff[100];
  char *test_return="test-return";
  char *result;

  while (read_cmd(buff) > 0) 
  {
    fn = buff[0];
    
    if (fn == 1)
    {
      char *str = &buff[1];
      //char *result = process(str);
      fprintf(stderr, "Calling process from driver\n");
      result = process(str);
      //shit3("blah");
      int len = strlen(result);
      fprintf(stderr, "Calling process done!, writing: %s : %d\n", result, len);
      write_cmd(result, strlen(result));
      fprintf(stderr, "Calling to write done! Woo!\n");
    }
    else
    {
      fprintf(stderr, "link_drv: Unknown function: ~d", fn);
    }
  }
}
Exemplo n.º 12
0
int main() {
  int fn, arg1, arg2, result;
  byte buff[100];

  while (read_cmd(buff) > 0) {
    fn = buff[0];

    if (fn == 1) {
      arg1 = buff[1];
      arg2 = buff[2];
      result = sum(arg1, arg2);
    } else if (fn == 2) {
      arg1 = buff[1];
      result = twice(arg1);
    } else {
      exit(EXIT_FAILURE);
      return -1;
    }

    buff[0] = result;
    write_cmd(buff, 1);
  }

  return 0;
}
Exemplo n.º 13
0
Arquivo: cue.c Projeto: ThreeGe/mpv
struct cue_file *mp_parse_cue(struct bstr data)
{
    struct cue_file *f = talloc_zero(NULL, struct cue_file);
    f->tags = talloc_zero(f, struct mp_tags);

    data = skip_utf8_bom(data);

    char *filename = NULL;
    // Global metadata, and copied into new tracks.
    struct cue_track proto_track = {0};
    struct cue_track *cur_track = NULL;

    while (data.len) {
        struct bstr param;
        int cmd = read_cmd(&data, &param);
        switch (cmd) {
        case CUE_ERROR:
            talloc_free(f);
            return NULL;
        case CUE_TRACK: {
            MP_TARRAY_GROW(f, f->tracks, f->num_tracks);
            f->num_tracks += 1;
            cur_track = &f->tracks[f->num_tracks - 1];
            *cur_track = proto_track;
            cur_track->tags = talloc_zero(f, struct mp_tags);
            break;
        }
        case CUE_TITLE:
        case CUE_PERFORMER: {
            static const char *metanames[] = {
                [CUE_TITLE] = "title",
                [CUE_PERFORMER] = "performer",
            };
            struct mp_tags *tags = cur_track ? cur_track->tags : f->tags;
            mp_tags_set_bstr(tags, bstr0(metanames[cmd]), param);
            break;
        }
        case CUE_INDEX: {
            int type = read_int_2(&param);
            double time = read_time(&param);
            if (cur_track) {
                if (type == 1) {
                    cur_track->start = time;
                    cur_track->filename = filename;
                } else if (type == 0) {
                    cur_track->pregap_start = time;
                }
            }
            break;
        }
        case CUE_FILE:
            // NOTE: FILE comes before TRACK, so don't use cur_track->filename
            filename = read_quoted(f, &param);
            break;
        }
    }

    return f;
}
Exemplo n.º 14
0
int main(int argc, char *argv[])
{
    Cmd * c = NULL;
	void * buf = NULL;
    uint32_t buffer_limit = 131072; /* 128k */

	#ifdef _WIN32
		_setmode( _fileno( stdout ), _O_BINARY );
		_setmode( _fileno( stdin  ), _O_BINARY );
	#endif

    if (argc > 1) {
        buffer_limit = atol(argv[1]);
    }

    while (1) {
		c = read_cmd();
		if (c == NULL) {
			fprintf(stderr, "command read failed\n");
			exit(1);
		}

		if ((c->hdr.passwdlen > buffer_limit) || (c->hdr.saltlen > buffer_limit) || (c->hdr.buflen > buffer_limit)) {
			fprintf(stderr, "buffer limit exceeded\n");
			exit(1);
		}

		buf = calloc(1, c->hdr.buflen);
		if (buf == NULL) {
			fprintf(stderr, "buffer allocation for buf failed\n");
			exit(1);
		}

		if (crypto_scrypt((const uint8_t*)c->passwd, c->hdr.passwdlen,
						  (const uint8_t*)c->salt, c->hdr.saltlen,
						  c->hdr.N, c->hdr.r, c->hdr.p,
						  (uint8_t*)buf, c->hdr.buflen)) {
			fprintf(stderr, "crypto_scrypt failed\n");
			exit(1);
		}

		write_uint32(c->hdr.buflen);

		if (fwrite(buf, c->hdr.buflen, 1, stdout) != 1) {
			perror("fwrite buf");
			exit(1);
		}

		fflush(stdout);

		free(c);
		free(buf);

		c = NULL;
		buf = NULL;
	}
}
Exemplo n.º 15
0
/*-----------------------------------------------------------------
 * MAIN
 *----------------------------------------------------------------*/
int main(int argc, char *argv[])
{
    byte*     buf;
    int       size = BUF_SIZE;

    if (argc > 1) {
	test(argc, argv);
	return 0;
    }

    fprintf(stderr, "gssapi started\r\n");

    if ((buf = malloc(size)) == NULL)
	return -1;
    
    while ( (buf = read_cmd(buf, &size)) ) {
	int res = 0;
	int index = 0;
	int version, arity;
	char command[MAXATOMLEN];
	ei_x_buff result;
	port_func func;

	/* Ensure that we are receiving the binary term by reading and 
	 * stripping the version byte */
	EI(ei_decode_version(buf, &index, &version));
    
	/* Our marshalling spec is that we are expecting a tuple {Command, Arg1} */
	EI(ei_decode_tuple_header(buf, &index, &arity));
    
	EI(arity != 2);
    
	EI(ei_decode_atom(buf, &index, command));

	/* Prepare the output buffer that will hold {ok, Result} or {error, Reason} */
	EI(ei_x_new_with_version(&result) || ei_x_encode_tuple_header(&result, 2));
    
/* 	fprintf(stderr, "command: %s\r\n", command); */
	func = lookup_func(command);

	if (func) {
	    res = func(buf, index, &result);
	} else {
	    EI(ei_x_encode_atom(&result, "error") || ei_x_encode_atom(&result, "unsupported_command"));
	}

	write_cmd(&result);

	ei_x_free(&result);
    }

/* error: */
    fprintf(stderr, "No more command, exiting\r\n");

    return 0;
}
Exemplo n.º 16
0
int main(){
	int fn, arg0, arg1, res;
	byte buf[16];
	while(read_cmd(buf) >0){
		fn = buf[0];
		arg0 = ntohl(*((uint32_t*)(buf + 1)));
		arg1 = ntohl(*((uint32_t*)(buf + 1 + sizeof(uint32_t))));
		res = htonl(sum(arg0, arg1));
		write_cmd((byte*)&res, sizeof(uint32_t));
	}
}
Exemplo n.º 17
0
int main(){
  int result, i, len;
  byte buff[255];

  while (read_cmd(buff) > 0) {
    result = barcode_to_png(buff);
    
    buff[0] = result;
    write_cmd(buff, 1);
  }
}
Exemplo n.º 18
0
static void loop(void)
{
  byte buf[BUFSIZE];
  int retval = 0;
  do {
    if (read_cmd(buf) > 0)
      retval = process_command(buf);
    else
      retval = 0;
  } while (retval);
}
Exemplo n.º 19
0
int main()
{
  ETERM *tuplep;
  ETERM *fnp;
  ETERM *args;
  byte buf[100];
  const char* func_name;

#ifdef __WIN32__
  /* Attention Windows programmers: you need [to pay Serge Aleynikov a
   * beer because he's the one who figured out how to get this to work
   * on windows :)] explicitly set mode of stdin/stdout to binary or
   * else the port program won't work.
   */
  _setmode(_fileno(stdout), _O_BINARY);
  _setmode(_fileno(stdin), _O_BINARY);
#endif

  eNotify_init();
  erl_init(NULL, 0);

  while (read_cmd(buf) > 0) {
    tuplep = erl_decode(buf);
    fnp = erl_element(1, tuplep);

    func_name =  (const char*)ERL_ATOM_PTR(fnp);
    args = erl_element(2, tuplep);

    // MATCH FIRST! -> REMEMBER THAT!
    if (strncmp(func_name, "get_error_desc", 14) == 0)
      {
		local_get_error_desc(args);
      }
    else if (strncmp(func_name, "add_watch", 9) == 0)
      {
	local_add_watch(args);
      }
    else if (strncmp(func_name, "remove_watch", 12) == 0)
      {
	local_remove_watch(args);
      }
    else
      {
	byte buf[10];
	ETERM *nok = erl_mk_atom("undef"); // alloc nok
	erl_encode(nok, buf);
	write_cmd(buf, erl_term_len(nok));
	erl_free_term(nok); // free nok
      }
    erl_free_compound(tuplep);
    erl_free_term(fnp);
  }
  return 0;
}
Exemplo n.º 20
0
static int read_key(menu_t* menu,int c){
    char **str;
    for (str=mpriv->actions; str && *str; str++)
      if (c == (*str)[0]) {
        action = &(*str)[2];
        read_cmd(menu,MENU_CMD_ACTION);
        return 1;
      }
  if (menu_dflt_read_key(menu, c))
    return 1;
  return menu_list_jump_to_key(menu, c);
}
Exemplo n.º 21
0
static int
mpg_output(int fd)
{
	mpgreturn message;
	
	memset(&message, 0, sizeof(mpgreturn));
	if (read_cmd(fd, &message)) {
		show_playinfo(&message);
		return 1;
	}
	update_status();
	return 0;
}
Exemplo n.º 22
0
void *process_accept(void *ptsockcnfd)
{
	char cmd[MAXSIZE];
	int sockcnfd=*(int *)ptsockcnfd;
	printf("sockcnfd %d\n",sockcnfd);
	if(read_cmd(sockcnfd,cmd)!=NULL)
		printf("get cmd is %s\n",cmd);
	else{
		printf("nothing recive\n");
		close(sockcnfd);
		return NULL;
	}
	process_cmd(sockcnfd,cmd);
}
Exemplo n.º 23
0
 void handle()
 {
     if (!sending && !to_emit.empty())
     {
         sending = true;
         out = to_emit.back();
         to_emit.pop();
         out_pos = 0;
     }
     if (sending)
     {
         send();
         return;
     }
     if (!cmd_ready)
     {
         read_cmd();
     }
     if (cmd_ready)
     {
         std::cerr << "\t\t\t\tcmd == " << cmd << std::endl;
         int cmd_len = cmd_pos - 1;
         if (strncmp(cmd, LIST, LIST_LEN) == 0)
         {
             std::cerr << "\tcmd == list" << std::endl;
             sending = true;
             out = list;
             out_pos = 0;
             cmd_len = LIST_LEN;
         } else if (strncmp(cmd, SUB, SUB_LEN) == 0)
         {
             std::cerr << "\tcmd == sub" << std::endl;
             int cnt = sub();
             cmd_len = SUB_LEN + cnt;
         } else if (strncmp(cmd, UNSUB, UNSUB_LEN) == 0)
         {
             std::cerr << "\tcmd == unsub" << std::endl;
             int cnt = unsub();
             cmd_len = UNSUB_LEN + cnt;
         } else if (strncmp(cmd, EMIT, EMIT_LEN) == 0)
         {
             std::cerr << "\tcmd == emit" << std::endl;
             int cnt = emit();
             cmd_len = EMIT_LEN + cnt;
         }
         memmove(cmd, cmd + cmd_len + 1, cmd_pos - cmd_len - 1);
         cmd_pos -= cmd_len + 1;
         cmd_ready = false;
     }
 }
Exemplo n.º 24
0
int main(int argc, char* argv[])
{
   if(argc == 1) 
   {
      print_help();
      exit(EXIT_SUCCESS);
   }
   
   // Store all parameters in a vector
   std::vector<std::string> args;
   for(int i = 0; i < argc; i++)
   {
      args.push_back(argv[i]);
   }
   read_cmd(args);

   // Initialize device   
   std::cout << "Using platform: " << device.platform_name() << std::endl; 
   std::cout << "Setting to device ..." << target << std::endl;
   device.set(target);

   // Create compilation timer
   UCL_Timer timer;
   timer.init(device);
   timer.start();
   
   // Create program
   UCL_Program program(device);
   std::string log;
   int result = program.load(filename.c_str(), flags.c_str(), &log);
 
   // Check Compilation
   if(result != UCL_SUCCESS)
   {
      std::cerr << "Error: " << ucl_check(result) << " " << log << std::endl;
      exit(EXIT_FAILURE);
   }
   else
   {
      std::cout << "Compilation was successful" << std::endl;
      result = EXIT_SUCCESS;
   }
   
   // Stop compilation timer
   timer.stop();
   std::cout << timer.seconds() << " seconds." << std::endl;

   return result;
}
Exemplo n.º 25
0
Arquivo: cue.c Projeto: ThreeGe/mpv
// Check if the text in data is most likely CUE data. This is used by the
// demuxer code to check the file type.
// data is the start of the probed file, possibly cut off at a random point.
bool mp_probe_cue(struct bstr data)
{
    bool valid = false;
    data = skip_utf8_bom(data);
    for (;;) {
        enum cue_command cmd = read_cmd(&data, NULL);
        // End reached. Since the line was most likely cut off, don't use the
        // result of the last parsing call.
        if (data.len == 0)
            break;
        if (cmd == CUE_ERROR)
            return false;
        if (cmd != CUE_EMPTY)
            valid = true;
    }
    return valid;
}
Exemplo n.º 26
0
int main(int argc, char ** argv) {


    getcwd(CURRENT_DIR, MAX_INPUT_LEN);


    char * cmd, **cmds;
    char * logical_op;
    int logical_op_count;
    if (argc > 1) {
        for(int i=1; i< argc; i++) {
            if (argv[i][0] == '-') {
                switch(argv[i][1]) {
                case 'v':
                    printf("Wersja 0.0.1 - Marcin Puhacz\n");
                    break;
                case 'h':
                    printf("Tu będzie pomoc\n");
                    break;
                }
            }
        }
    } else {
        while (1) {

            signal(SIGINT, sigint_handler);
            signal(SIGPIPE, SIG_IGN);
            signal(SIGCHLD, sigchld_handler);

            print_prompt();
            cmd = read_cmd();
            if (strlen(cmd) > 0) {
                logical_op = malloc(100*sizeof(char));
                cmds = split_by_logical_operators(cmd, logical_op, &logical_op_count);
                prepare_cmds(cmds, logical_op, logical_op_count);
                free(cmds);
                free(logical_op);
            }
            free(cmd);
            fflush(stdin);

        }
    }

    return 0;
}
Exemplo n.º 27
0
Arquivo: port.c Projeto: sh4rkfin/misc
int main() {
  int fn, arg, res;
  byte buf[100];

  while (read_cmd(buf) > 0) {
    fn = buf[0];
    arg = buf[1];

    if (fn == 1) {
      res = foo(arg);
    } else if (fn == 2) {
      res = bar(arg);
    }

    buf[0] = res;
    write_cmd(buf, 1);
  }
}
Exemplo n.º 28
0
int main() {
  int num_threads = 200;
  pthread_t threads[num_threads];
  int active_thread_count = 0;

  byte buf[1000000];
  erl_init(NULL, 0);

  while (read_cmd(buf) > 0) {
    if(active_thread_count == num_threads){
      clear_active_threads(threads, active_thread_count);
      active_thread_count = 0;
    }
    handle_command(buf);
    active_thread_count = active_thread_count + 1;
  }
  clear_active_threads(threads, active_thread_count);

  return 0;
}
Exemplo n.º 29
0
int main(int argc, char **argv, char **env) {
    debug("int main(int argc, char **argv, char **env)");
    unsigned char buffer[PACKET_SIZE];
    #ifndef USE_GLOBAL
        Trie* trie = NULL
    #endif
    trie = trie_try_new(trie);
    for(;;) {
        /**
            Читаем сообщение из буфера,
            до тех пор пока можем их читать,
            и пока не получили неизвестную нам команду
        **/
        if (1 != read_cmd(buffer)){
            trie_free(trie);
            exit(1);
        }
        switch (*buffer) {
            case CMD_VERSION:
                /**
                    Запрос версии
                **/
                cmd_version();
                break;
            case CMD_APPLY_XSL:
                /**
                    Запрос на преобразование 
                **/
                cmd_apply_xsl(trie);
                break;
            default:
                /**
                    Неведомая фигня
                **/
                trie_free(trie);
                fprintf(stderr, "unknown command %c in adapter\n",
                        *buffer);
                exit(1);
        }
    }
}
Exemplo n.º 30
0
int reg_scan(int mq_id, int addr, int  reg_type, int reg_start, int reg_stop)
{
    int i; 
     int value;
     int retval; 

     for(i=reg_start;  i <= reg_stop; i++){
     	 retval = read_cmd(mq_id, addr, reg_type , i, MV_TYPE_SHORT, &value, 0);
	 switch(retval){
	   case 1:
	     printf("Read value %d at %d\n", value, i);
	     break;
	   default:
	     printf("Retval  %d at %d\n", retval, i);
	     break;	     
	 }
	 
     }

     return 0;
    
}