예제 #1
0
void ChatLog::FillLastLineArray()
{
    int fd ( open(GetCurrentLogfilePath().mb_str(), O_RDONLY) );
    if ( fd < 0 )
    {
        wxLogError(_T("%s: failed to open log file."), __PRETTY_FUNCTION__);
        return;
    }
    size_t num_lines ( sett().GetAutoloadedChatlogLinesCount() );

    m_last_lines.Clear();
    m_last_lines.Alloc(num_lines);

    const wxChar* wc_EOL ( wxTextBuffer::GetEOL() );
    size_t eol_num_chars ( wxStrlen(wc_EOL) );
#ifndef WIN32
    char* eol ( static_cast<char*>( alloca(eol_num_chars) ) );
#else
    char* eol ( new char[eol_num_chars] );
#endif
    wxConvUTF8.WC2MB(eol, wc_EOL, eol_num_chars);

    size_t lines_added ( find_tail_sequences(fd, eol, eol_num_chars, num_lines, m_last_lines) );
    wxLogMessage(_T("ChatLog::FillLastLineArray: Loaded %lu lines from %s."), lines_added, GetCurrentLogfilePath().c_str());
    close(fd);

#ifdef WIN32
    delete[] eol;
#endif
}
예제 #2
0
static int16_t row_height(MenuIndex *cell_index) {
    return LINE_HEIGHT * num_lines(cell_index);
}
예제 #3
0
파일: compound.c 프로젝트: TimLand/datacl
// START FUNC DECL
int 
chk_comp_expr(
	      char *filename,
	      COMP_EXPR_TYPE **ptr_comp_expr,
	      int *ptr_n_comp_expr,
	      int *ptr_tbl_id,
	      TBL_REC_TYPE *ptr_tbl_rec

	      )
// STOP FUNC DECL
{
  int status = 0;
  char tbl[MAX_LEN_TBL_NAME+1]; int tbl_id = -1; TBL_REC_TYPE tbl_rec; 

  char otbl[MAX_LEN_TBL_NAME+1];  int otbl_id = -1; TBL_REC_TYPE otbl_rec;
  char fld1[MAX_LEN_FLD_NAME+1];
  char scalar[MAX_LEN_SCALAR_EXPRESSION+1];
  char fld2[MAX_LEN_FLD_NAME+1];
  char fld3[MAX_LEN_FLD_NAME+1];
  char fld4[MAX_LEN_FLD_NAME+1];
  char qfn[MAX_OP_LEN+1]; // Q function to be performed
  char pure_op[MAX_OP_LEN+1]; 
  char env_var[BUFSZ+1]; 
  char op_spec[BUFSZ+1]; 

  long long nR = LLONG_MAX;
  size_t len_line = 1024;
  char *line = NULL;
  COMP_EXPR_TYPE *comp_expr = NULL;
  int n_comp_expr = 0;
  FILE *cfp = NULL;
  char *delim = "__@@__";
  FLD_TYPE f1_fldtype, f2_fldtype, f3_fldtype, jnk_fldtype;
  bool f1_has_null, f2_has_null, f3_has_null;
  bool jnk_bool;

  if ( ( filename == NULL ) || ( *filename == '\0' ) ) { go_BYE(-1); }
  status = num_lines(filename, &n_comp_expr); cBYE(status);
  if ( n_comp_expr <= 1 ) { go_BYE(-1); }
  if ( n_comp_expr > MAX_STATEMENTS_IN_COMP_EXPR ) { go_BYE(-1); }
  comp_expr = malloc(n_comp_expr * sizeof(COMP_EXPR_TYPE));
  return_if_malloc_failed(comp_expr);
  zero_comp_expr(comp_expr, n_comp_expr); 
  line = malloc(len_line * sizeof(char));
  return_if_malloc_failed(line);

  cfp = fopen(filename, "r");
  return_if_fopen_failed( cfp,  filename, "r");
  //----------------------------------------------
  zero_string(otbl,    MAX_LEN_TBL_NAME+1);
  zero_string(tbl,     MAX_LEN_TBL_NAME+1);
  zero_string(fld1,    MAX_LEN_FLD_NAME+1);
  zero_string(scalar,  MAX_LEN_SCALAR_EXPRESSION+1);
  zero_string(fld2,    MAX_LEN_FLD_NAME+1);
  zero_string(fld3,    MAX_LEN_FLD_NAME+1);
  zero_string(fld4,    MAX_LEN_FLD_NAME+1);
  zero_string(op_spec, BUFSZ+1);
  zero_string(env_var, BUFSZ+1);
  zero_string(qfn,     MAX_OP_LEN+1);
  zero_string(pure_op, MAX_OP_LEN+1);
  //----------------------------------------------
  for ( int lno = 0; lno < n_comp_expr ; lno++ ) {
    /* read each line of the file */
    ssize_t n = getline(&line, &len_line, cfp);
    if ( n <= 0 ) { break; }
    /* break line into parts */
    int colidx = 0;
    // Determine the Q operation to be performed
    status = read_nth_val(line, delim, colidx++, qfn, MAX_OP_LEN);
    status = proc_qfn(qfn, lno, comp_expr); cBYE(status);
    // Determine the table on which operation is to be performed
    /* tbl_id set first time and checked subsequently */
    if ( lno == 0 ) { 
      status = read_nth_val(line, delim, colidx++, tbl, MAX_LEN_TBL_NAME);
      status = is_tbl(tbl, &tbl_id, &tbl_rec); 
      if ( tbl_id < 0 ) { 
	fprintf(stderr, "Line %d. Table = [%s] not found \n", lno+1, tbl); 
      }
      nR = tbl_rec.nR;
    }
    else {
      int this_tbl_id = INT_MAX; TBL_REC_TYPE this_tbl_rec;
      char thistbl[MAX_LEN_TBL_NAME+1]; 
      zero_string(thistbl, MAX_LEN_TBL_NAME+1);
      status = read_nth_val(line, delim, colidx++, thistbl, MAX_LEN_TBL_NAME);
      status = is_tbl(thistbl, &this_tbl_id, &this_tbl_rec); 
      if ( this_tbl_id != tbl_id ) { 
	fprintf(stderr, "Line %d. Old table = %s, new table = %s \n",
		lno+1, tbl, thistbl);
	go_BYE(-1); 
      }
    }
    //----------------------------------------------
    if ( strcmp(qfn, "f1opf2") == 0 ) {
      status = read_nth_val(line, delim, colidx++, fld1, BUFSZ);
      status = proc_fld(tbl_id, nR, fld1, jnk_fldtype, jnk_bool, 
			lno, 0, 0, comp_expr, &f1_fldtype, &f1_has_null); 
      cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, op_spec, BUFSZ);
      status = proc_op_spec(op_spec, lno, comp_expr, pure_op); cBYE(status);
      //---------------------------------------------------
      status = get_type_op_fld(qfn, pure_op, f1_fldtype, undef_fldtype, 
			       op_spec, &f2_fldtype);
      cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, fld2, BUFSZ);
      // Important: f1 has    null values => f2 has    null values
      // Important: f1 has no null values => f2 has no null values
      f2_has_null = f1_has_null;
      status = proc_fld(tbl_id, nR, fld2, f2_fldtype, f2_has_null, 
			lno, 1, 1, comp_expr, &jnk_fldtype, &jnk_bool); 
      cBYE(status);
      //---------------------------------------------------
    }
    else if ( strcmp(qfn, "count") == 0 ) {
      status = read_nth_val(line, delim, colidx++, fld1, BUFSZ);
      status = proc_fld(tbl_id, nR, fld1, jnk_fldtype, jnk_bool, 
			lno, 0, 0, comp_expr, &f1_fldtype, &f1_has_null); 
      cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, fld2, BUFSZ);
      if ( *fld2 != '\0' ) { /* cfld can be empty */
	status = proc_fld(tbl_id, nR, fld2, jnk_fldtype, jnk_bool,
			  lno, 1, 0, comp_expr, &f2_fldtype, &f2_has_null);
	cBYE(status);
	if ( f2_fldtype != I1    ) { go_BYE(-1); }
	if ( f2_has_null == true ) { go_BYE(-1); }
      }
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, otbl, BUFSZ);
      status = is_tbl(otbl, &otbl_id, &otbl_rec); 
      if ( otbl_id < 0 ) { go_BYE(-1); }
      if ( otbl_id == tbl_id ) { go_BYE(-1); }
      long long onR =  otbl_rec.nR;
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, fld3, BUFSZ);
      status = proc_fld(otbl_id, onR, fld3, I8, false, 
			lno, 2, 1, comp_expr, &jnk_fldtype, &jnk_bool);
      cBYE(status);
      //---------------------------------------------------
    }
    else if ( strcmp(qfn, "countf") == 0 ) {
      status = read_nth_val(line, delim, colidx++, fld1, BUFSZ);
      status = proc_fld(tbl_id, nR, fld1, jnk_fldtype, jnk_bool, 
			lno, 0, 0, comp_expr, &f1_fldtype, &f1_has_null); 
      cBYE(status);
      if ( ( f1_fldtype != I4 ) && ( f1_fldtype != I8 ) ) { go_BYE(-1); }
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, fld2, BUFSZ);
      status = proc_fld(tbl_id, nR, fld2, jnk_fldtype, jnk_bool, 
			lno, 1, 0, comp_expr, &f2_fldtype, &f2_has_null); 
      cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, fld3, BUFSZ);
      if ( *fld3 != '\0' ) { /* cfld can be empty */
	status = proc_fld(tbl_id, nR, fld3, jnk_fldtype, jnk_bool,
			  lno, 2, 0, comp_expr, &f3_fldtype, &f3_has_null);
	cBYE(status);
	if ( f3_fldtype != I1    ) { go_BYE(-1); }
	if ( f3_has_null == true ) { go_BYE(-1); }
      }
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, otbl, BUFSZ);
      status = is_tbl(otbl, &otbl_id, &otbl_rec); 
      if ( otbl_id < 0 ) { go_BYE(-1); }
      if ( otbl_id == tbl_id ) { go_BYE(-1); }
      long long onR =  otbl_rec.nR;
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, fld4, BUFSZ);
      status = proc_fld(otbl_id, onR, fld4, I8, false, 
			lno, 3, 1, comp_expr, &jnk_fldtype, &jnk_bool);
      cBYE(status);
      //---------------------------------------------------
    }
    else if ( strcmp(qfn, "f1s1opf2") == 0 ) {
      status = read_nth_val(line, delim, colidx++, fld1, BUFSZ);
      status = proc_fld(tbl_id, nR, fld1, jnk_fldtype, jnk_bool, 
			lno, 0, 0, comp_expr, &f1_fldtype, &f1_has_null); 
      cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, scalar, BUFSZ);
      if ( *scalar == '\0' ) { go_BYE(-1); }
      status = proc_scalar(scalar, lno, comp_expr); cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, op_spec, BUFSZ);
      status = proc_op_spec(op_spec, lno, comp_expr, pure_op); cBYE(status);
      //---------------------------------------------------
      status = get_type_op_fld(qfn, pure_op, f1_fldtype, f1_fldtype, 
			       op_spec, &f2_fldtype); cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, fld2, BUFSZ);
      // Important: f1 has    null values => f2 has    null values
      // Important: f1 has no null values => f2 has no null values
      f2_has_null = f1_has_null;
      status = proc_fld(tbl_id, nR, fld2, f2_fldtype, f2_has_null, 
			lno, 1, 1, comp_expr, &jnk_fldtype, &jnk_bool); 
      if ( status < 0 ) { 
	fprintf(stderr, "fld1 = %s \n", fld1);
	fprintf(stderr, "fld2 = %s \n", fld2);
      }
      cBYE(status);
      //---------------------------------------------------
    }
    else if ( strcmp(qfn, "f1f2opf3") == 0 ) {
      status = read_nth_val(line, delim, colidx++, fld1, BUFSZ);
      status = proc_fld(tbl_id, nR, fld1, jnk_fldtype, jnk_bool, 
			lno, 0, 0, comp_expr, &f1_fldtype, &f1_has_null); 
      cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, fld2, BUFSZ);
      status = proc_fld(tbl_id, nR, fld2, jnk_fldtype, jnk_bool, 
			lno, 1, 0, comp_expr, &f2_fldtype, &f2_has_null); 
      cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, op_spec, BUFSZ);
      status = proc_op_spec(op_spec, lno, comp_expr, pure_op); cBYE(status);
      //---------------------------------------------------
      status = get_type_op_fld(qfn, pure_op, f1_fldtype, f2_fldtype, 
			       op_spec, &f3_fldtype);
      cBYE(status);
      if ( ( f1_has_null == true ) || ( f2_has_null == true ) )  {
	f3_has_null = true;
      }
      else {
	f3_has_null = false;
      }
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, fld3, BUFSZ);
      status = proc_fld(tbl_id, nR, fld3, f3_fldtype, f3_has_null,
			lno, 2, 1, comp_expr, &jnk_fldtype, &jnk_bool); 
      cBYE(status);
      //---------------------------------------------------
    }
    else if ( strcmp(qfn, "f1f2_to_s") == 0 ) {
      status = read_nth_val(line, delim, colidx++, fld1, BUFSZ);
      status = proc_fld(tbl_id, nR, fld1, jnk_fldtype, jnk_bool, lno, 
			0, 0, comp_expr, &f1_fldtype, &f1_has_null); 
      cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, fld2, BUFSZ);
      status = proc_fld(tbl_id, nR, fld2, jnk_fldtype, jnk_bool, lno, 
			1, 0, comp_expr, &f2_fldtype, &f2_has_null); 
      cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, op_spec, BUFSZ);
      status = proc_op_spec(op_spec, lno, comp_expr, pure_op); cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, env_var, BUFSZ);
      status = proc_env_var(env_var, lno, comp_expr); cBYE(status);
      //---------------------------------------------------
    }
    else if ( strcmp(qfn, "f_to_s") == 0 ) {
      status = read_nth_val(line, delim, colidx++, fld1, BUFSZ);
      status = proc_fld(tbl_id, nR, fld1, jnk_fldtype, jnk_bool, lno, 
			0, 0, comp_expr, &f1_fldtype, &f1_has_null); 
      cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, op_spec, BUFSZ);
      status = proc_op_spec(op_spec, lno, comp_expr, pure_op); cBYE(status);
      //---------------------------------------------------
      status = read_nth_val(line, delim, colidx++, env_var, BUFSZ);
      status = proc_env_var(env_var, lno, comp_expr); cBYE(status);
      //---------------------------------------------------
    }
    else {
      go_BYE(-1);
    }
  }
  if ( n_comp_expr <= 1 ) { go_BYE(-1); }
  *ptr_comp_expr   =  comp_expr;
  *ptr_n_comp_expr =  n_comp_expr;
  *ptr_tbl_id      = tbl_id;
  *ptr_tbl_rec     = tbl_rec;
 BYE:
  free_if_non_null(line);
  fclose_if_non_null(cfp);
  return status ;
}