示例#1
0
bool editor::process_params(int argc, char **argv)
{ 
  bool file_params = FALSE;
  
  if(argc > 1) {  
    int i;
    for(i = 0; i < argc; i++) {
      char *p_param = argv[i];
      
      if(!strcasecmp("-h",p_param) || !strcasecmp("--help",p_param)) {
        process_help();
        return(FALSE);
      } else if(!strcasecmp("-t",p_param)) {
        state.config.gui_enabled = FALSE;
      } else if(!strcasecmp("-g",p_param)) {
        state.config.gui_enabled = TRUE;
      } else if(i+1 == argc) {
        strncpy(state.config.script_file, p_param, MAX_FILENAME);
        file_params = TRUE;
      }
    }
  }
  
  if(!file_params) {
    process_help();
    return(FALSE);
  }
  
  return(TRUE);
}
示例#2
0
void process_command_connection(int con, int i2c_handle, bool verbose)
{
	char request[256];
	char *back;
	char response[256];

	struct line_reader reader;
	init_line_reader(&reader, read_from_socket, BUFFER_SIZE, &con);

	while (1) {

		int result = read_line(&reader, request, sizeof(request));
		if (result != 0) break;

		/* Get rid of any trailing \r or \n. */
		back = request + strlen(request) - 1;
		while (back >= request && (*back == '\n' || *back == '\r'))
			*(back--) = 0;

		if (verbose) printf("Request: %s\n", request);
		if (strncmp("ping", request, 4) == 0)
		{
			process_ping_command(request, response, sizeof(response));
		} 
		else if (strncmp("get", request, 3) == 0) {
			process_get_command(request, i2c_handle, response, sizeof(response));
		}
		else if (strncmp("set", request, 3) == 0) {
			process_set_command(request, i2c_handle, response, sizeof(response));
		}
		else if (strncmp("addpoll", request, 7) == 0) {
			process_add_poll_command(request, response, sizeof(response));
		}
		else if (strncmp("rmpoll", request, 5) == 0) {
			process_remove_poll_command(request, response, sizeof(response));
		}
		else if (strncmp("help", request, 4) == 0) {
			process_help(request, response, sizeof(response));
		}
		else 
		{
			fprintf(stderr, "ERROR: unknown command\n");
			strcpy(response, "ERROR\r\n");
		}

		if (verbose) printf("Response: %s", response);
		result = send(con, response, strlen(response), MSG_NOSIGNAL);
		if (result != strlen(response)) {
			fprintf(stderr, "ERROR: Error writing to socket\n");
			break;	
		}
	}

	close_reader(&reader);
}