예제 #1
0
파일: ylc_del.c 프로젝트: TimLand/datacl
// START FUNC DECL
int ylc_del(
	    char *list
	    )
// STOP FUNC DECL
{
  int status = 0;
  bool b_is_list; int rc, list_id = -1, tbl_id = -1, xlist_id = -1;
  int num_in_list;
  char *zErrMsg = NULL;
  char *cum_fld = NULL; int cum_fld_id;
  char command[1024]; 

  if ( ( list == NULL ) || ( *list == '\0' ) ) { go_BYE(-1); }
  status = is_list(list, &b_is_list);
  if ( b_is_list == false ) { 
    fprintf(stderr, "List [%s] does not exist \n", list); return(status); 
  }
  status = get_list_id(list, &list_id, &tbl_id, &xlist_id); cBYE(status);
  if ( list_id <= 0 ) { go_BYE(-1); }
  // Delete xlist if any
  if ( xlist_id > 0 ) { 
    status = get_xlist_info(xlist_id, &cum_fld, &cum_fld_id);
    cBYE(status);
    status = del_fld(NULL, tbl_id, NULL, cum_fld_id, true); cBYE(status);

    zero_string(command, 1024);
    sprintf(command, "delete  from xlist where id = %d \n", xlist_id); 
    rc = sqlite3_exec(g_db, command, NULL, 0, &zErrMsg);
    if( rc != SQLITE_OK ){ handle_sqlite_error(); }
    // delete entries corresponding to this xlist 
    zero_string(command, 1024);
    sprintf(command, "delete  from flds_x_xlist where xlist_id = %d \n", xlist_id); 
    rc = sqlite3_exec(g_db, command, NULL, 0, &zErrMsg);
    if( rc != SQLITE_OK ){ handle_sqlite_error(); }
  }
  status = get_num_in_list(list_id, &num_in_list); cBYE(status);
  for ( int position = num_in_list; position > 0 ; position-- ) { 
    status = del_aux_fld_if_exists(tbl_id, list_id, position, "lmt_");
    cBYE(status);
    status = del_aux_fld_if_exists(tbl_id, list_id, position, "xcl_");
    cBYE(status);
    status = del_aux_fld_if_exists(tbl_id, list_id, position, "new_");
    cBYE(status);
  }

  zero_string(command, 1024);
  sprintf(command, "delete  from flds_x_list where list_id = %d \n", list_id); 
  rc = sqlite3_exec(g_db, command, NULL, 0, &zErrMsg);
  if( rc != SQLITE_OK ){ handle_sqlite_error(); }

  zero_string(command, 1024);
  sprintf(command, "delete  from list where name = '%s' \n", list); 
  rc = sqlite3_exec(g_db, command, NULL, 0, &zErrMsg);
  if( rc != SQLITE_OK ){ handle_sqlite_error(); }
  
 BYE:
  // TODO P3: free_if_non_null(zErrMsg);
  free_if_non_null(cum_fld);
  return(status);
}
예제 #2
0
// START FUNC DECL
int
del_xlist(
    int list_id,
	  int xlist_id
	  )
// STOP FUNC DECL
{
  int status = 0;
  char command[1024]; char *zErrMsg = NULL;

  zero_string(command, 1024); 
  sprintf(command, "update list set xlist_id = NULL where id = %d ", list_id);
  int rc = sqlite3_exec(g_db, command, NULL, 0, &zErrMsg);
  if ( rc ) { handle_sqlite_error(); }

  zero_string(command, 1024); 
  sprintf(command, "delete from xlist where id = %d ", xlist_id);
  rc = sqlite3_exec(g_db, command, NULL, 0, &zErrMsg);
  if ( rc ) { handle_sqlite_error(); }

BYE:
  // TODO P3 free_if_non_null(zErrMsg);

  return(status);
}
예제 #3
0
파일: compound.c 프로젝트: TimLand/datacl
// START FUNC DECL
void 
zero_comp_expr(
	       COMP_EXPR_TYPE *comp_expr, 
	       int n_comp_expr
	       )
// STOP FUNC DECL
{
  for ( int i = 0; i < n_comp_expr; i++ ) {
    comp_expr[i].op = undef_comp_expr;
    zero_string(comp_expr[i].scalar, MAX_LEN_SCALAR_EXPRESSION+1);
    zero_string(comp_expr[i].op_spec, MAX_LEN_SCALAR_EXPRESSION+1);
    zero_string(comp_expr[i].env_var, MAX_LEN_FLD_NAME+1);
    for ( int j = 0; j < 4; j++ ) { 
      zero_string(comp_expr[i].fld[j].name, MAX_LEN_FLD_NAME+1);
      comp_expr[i].fld[j].fld_id   = -1;
      comp_expr[i].fld[j].tbl_id   = -1;
      comp_expr[i].fld[j].nR       = -1;
      comp_expr[i].fld[j].is_temp  = -1;
      comp_expr[i].fld[j].is_write = -1;
      comp_expr[i].fld[j].is_first = 0;
      comp_expr[i].fld[j].fldtype  = undef_fldtype;
      comp_expr[i].fld[j].X        = NULL;
      comp_expr[i].fld[j].nX       = 0;
      comp_expr[i].fld[j].nn_X     = NULL;
      comp_expr[i].fld[j].nn_nX    = 0;
    }
  }
}
예제 #4
0
파일: aux_dld.c 프로젝트: subramon/Q
// START FUNC DECL
int
process_aux_info(
		 char *in_aux_info, 
		 bool *ptr_ignore_hdr, 
		 char *ptr_fld_sep, 
		 char *ptr_fld_open,
		 char *ptr_fld_close,
		 char *ptr_rec_delim
		 )
// STOP FUNC DECL
{
  int status = 0;
  char rec_delim = '\n'; // default
  char fld_sep   = ','; // default 
  char fld_open  = '"'; // default 
  char fld_close = '"'; // default 
  bool ignore_hdr = false;
  bool is_null; char aux_info[MAX_LEN]; zero_string(aux_info, MAX_LEN);

  if ( ( in_aux_info != NULL ) && ( *in_aux_info != '\0' ) ) {
    status = chk_aux_info(in_aux_info); cBYE(status);
    zero_string(aux_info, MAX_LEN);
    status = extract_S(in_aux_info, "ignore_hdr=[", "]", aux_info, MAX_LEN, &is_null);
    if ( is_null ) { 
      ignore_hdr = false;
    }
    else {
      if ( strcasecmp(aux_info, "true") == 0 ) { 
	ignore_hdr = true;
      }
      else if ( strcasecmp(aux_info, "false") == 0 ) { 
	ignore_hdr = false;
      }
      else {
	go_BYE(-1);
      }
    }
    //---------------------------------------------------------------
    zero_string(aux_info, MAX_LEN);
    status = extract_S(in_aux_info, "fld_sep=[", "]", aux_info, MAX_LEN, &is_null);
    if ( !is_null ) { status = conv_x(aux_info, &fld_sep); cBYE(status); }
    //---------------------------------------------------------------
    zero_string(aux_info, MAX_LEN);
    status = extract_S(in_aux_info, "fld_open=[", "]", aux_info, MAX_LEN, &is_null);
    if ( !is_null ) { status = conv_x(aux_info, &fld_open); cBYE(status); }
    //---------------------------------------------------------------
    zero_string(aux_info, MAX_LEN);
    status = extract_S(in_aux_info, "fld_close=[", "]", aux_info, MAX_LEN, &is_null);
    if ( !is_null ) { status = conv_x(aux_info, &fld_close); cBYE(status); }
    //---------------------------------------------------------------
  }
  *ptr_ignore_hdr = ignore_hdr;
  *ptr_fld_sep    = fld_sep;
  *ptr_fld_open   = fld_open;
  *ptr_fld_close  = fld_close;
  *ptr_rec_delim  = rec_delim;
 BYE:
  return status ;
}
예제 #5
0
int
main(
     int argc,
     char **argv
     )
{
  int status = 0;
  char *buffer = NULL;
  char filename[256];
  size_t bufsize = BUFSIZE;
  FILE *ifp = NULL, *ofp = NULL, *tfp = NULL;
  char *infile = NULL, *outfile = NULL, *tempfile = NULL;
  int nr, lno;

  if ( argc != 3 ) { 
    fprintf(stderr, "Usage is txt_sub <infile> <outfile> \n");
    go_BYE(-1);
  }
  infile = argv[1];
  outfile = argv[2];
  if ( *infile == '\0' ) { go_BYE(-1); }
  if ( *outfile == '\0' ) { go_BYE(-1); }
  if ( strcmp(infile, outfile)== 0 ) { go_BYE(-1); }

  buffer = (char *)malloc(bufsize * sizeof(char));
  return_if_malloc_failed(buffer);
  zero_string(buffer, bufsize);
  zero_string(filename, 256);

  ifp = fopen(infile, "r");
  return_if_fopen_failed(ifp, infile, "r");
  ofp = fopen(outfile, "w");
  return_if_fopen_failed(ofp, outfile, "w");

  for ( lno = 1; ; lno++ ) {
    zero_string_to_nullc(buffer);
    nr = getline(&buffer, &bufsize, ifp);
    if ( nr <= 0 ) { break; } 
    if ( ( strcasecmp(buffer, "%% INCLUDE") == 0 ) || 
         ( strcasecmp(buffer, "// INCLUDE") == 0 ) ) {
      status = open_temp_file(&tfp, &tempfile); cBYE(status);
      fclose_if_non_null(tfp);
      fprintf(ofp, "\\verbatiminput{%s}\n", tempfile);
      free_if_non_null(tempfile);
    }
    else { // copy from input to output 
      fprintf(ofp, "%s", buffer); 
     }
  }
  fclose_if_non_null(ifp);
  fclose_if_non_null(ofp);
 BYE:
  free_if_non_null(buffer);
  return(status);
}
예제 #6
0
파일: extract_S.c 프로젝트: TimLand/datacl
// START FUNC DECL
int
extract_F4(
    const char *X,
    const char *start_str,
    const char *stop_str,
    float *ptr_fval,
    bool *ptr_is_null
    )
// STOP FUNC DECL
{
  int status = 0;
#define BUFLEN 32
  char bufstr[BUFLEN];
  double dval;
  char *endptr;

  zero_string(bufstr, BUFLEN);
  status = extract_S(X, start_str, stop_str, bufstr, BUFLEN, ptr_is_null);
  cBYE(status);
  if ( *ptr_is_null ) { return status ; }
  dval = strtod(bufstr, &endptr);
  if ( *endptr != '\0' ) { *ptr_is_null = true; return status ; }
  if ( ( dval < FLT_MIN ) || ( dval > FLT_MAX ) ) { go_BYE(-1); }
  *ptr_fval = dval;
BYE:
  return status ;
}
예제 #7
0
// START FUNC DECL
int
set_fld_id_cnt(
		   int list_id, 
		   int pos, 
		   char *mode, 
		   int fld_id, 
		   char *fld,
		   long long cnt
		   )
// STOP FUNC DECL
{
  int status = 0;
  char command[1024];
  zero_string(command, 1024);
  int rc; char *zErrMsg = NULL;

  if ( mode == NULL ) { go_BYE(-1); }
  if ( ( fld == NULL ) || ( *fld == '\0' ) ) { go_BYE(-1); }
  chk_mode(mode);
  sprintf(command, "update flds_x_list set %sfld_id = %d, %sfld = '%s', %sfld_cnt = %lld where list_id = %d and position = %d ", 
	mode, fld_id, mode, fld, mode, cnt, list_id, pos);
  rc = sqlite3_exec(g_db, command, NULL, 0, &zErrMsg);
  if( rc != SQLITE_OK ) { handle_sqlite_error(); }
 BYE:
  return(status);
}
예제 #8
0
//
// START FUNC DECL
int
is_fld_in_list(
		   int list_id,
		   int fld_id,
		   bool *ptr_b_is_fld_in_list
		   )
// STOP FUNC DECL
{
  int status = 0;
  char command[1024]; int n;

  zero_string(command, 1024);
  if ( list_id <= 0 ) { go_BYE(-1); }
  if ( fld_id  <  0 ) { go_BYE(-1); }
  sprintf(command, "select count(*) from flds_x_list where list_id = %d and fld_id = %d \n", list_id, fld_id);
  status = db_get_num_rslts(g_db, command, &n);
  if ( n == 0 ) { 
    *ptr_b_is_fld_in_list = false; 
  } 
  else { 
    *ptr_b_is_fld_in_list = true; 
  } 
 BYE:
  return(status);
}
예제 #9
0
파일: aux_meta.c 프로젝트: subramon/Q
// START FUNC DECL
void
zero_ddir_rec(
	      DDIR_REC_TYPE *ptr_X
	      )
// STOP FUNC DECL
{
  zero_string(ptr_X->name, (MAX_LEN_DIR_NAME+1));
}
예제 #10
0
// START FUNC DECL
int
get_list_id(
	    char *list,
	    int *ptr_list_id,
	    int *ptr_tbl_id,
	    int *ptr_xlist_id
	    )
// STOP FUNC DECL
{
  int status = 0;
  bool b_is_list = false;
  char command[1024];

  if ( ( list == NULL ) || ( *list == '\0' ) )  { go_BYE(-1); }

  *ptr_list_id  = -1; 
  *ptr_tbl_id   = -1; 
  *ptr_xlist_id = -1; 

  status = is_list(list, &b_is_list); cBYE(status);
  if ( b_is_list == false ) { go_BYE(-1); }

  zero_string(command, 1024);
  sprintf(command, "select id from list where name = '%s'\n", list);
  status = db_get_ival(g_db, command, ptr_list_id); cBYE(status);
  if ( *ptr_list_id <= 0 ) { /* Nothing more to do */
    goto BYE;
  }
  sprintf(command, "select tbl_id from list where id = %d\n", *ptr_list_id);
  status = db_get_ival(g_db, command, ptr_tbl_id); cBYE(status);
  sprintf(command, "select xlist_id from list where id = %d\n", *ptr_list_id);
  status = db_get_ival(g_db, command, ptr_xlist_id); cBYE(status);
  // Determine whether there really is an xlist for this list
  int num_rslts;
  zero_string(command, 1024); 
  sprintf(command, "select count(*) from list where xlist_id is not NULL and id = %d ", *ptr_list_id);
  status = db_get_num_rslts(g_db, command, &num_rslts); cBYE(status);
  if ( num_rslts == 0 ) {
    *ptr_xlist_id = -1;
  }

 BYE:
  return(status);
}
예제 #11
0
// START FUNC DECL
int
g_mmap_meta_data(
    char *docroot,

    char **ptr_x_gpu_reg_X,
    size_t *ptr_x_gpu_reg_nX,
    GPU_REG_TYPE **ptr_x_gpu_reg,
    int *ptr_x_n_gpu_reg

)
// STOP FUNC DECL
{
    int status = 0;
    char cwd[MAX_LEN_DIR_NAME+1];

    char *l_gpu_reg_X = NULL;
    size_t l_gpu_reg_nX = 0;
    GPU_REG_TYPE *l_gpu_reg = NULL;
    int l_n_gpu_reg = 0;

    zero_string(cwd, MAX_LEN_DIR_NAME+1);
    if ( getcwd(cwd, MAX_LEN_DIR_NAME) == NULL ) {
        go_BYE(-1);
    }
    if ( ( docroot == NULL ) || ( *docroot == '\0' ) ) {
        go_BYE(-1);
    }
    status = chdir(docroot);
    cBYE(status);

    /*----------------------------------------------------------*/
    status = rs_mmap("docroot.gpu", &l_gpu_reg_X, &l_gpu_reg_nX, 1);
    cBYE(status);
    if ( l_gpu_reg_nX == 0 ) {
        go_BYE(-1);
    }
    l_n_gpu_reg = l_gpu_reg_nX / sizeof(GPU_REG_TYPE);
    if (  (l_gpu_reg_nX % sizeof(GPU_REG_TYPE) ) != 0 ) {
        go_BYE(-1);
    }
    l_gpu_reg = (GPU_REG_TYPE *)l_gpu_reg_X;
    status = chdir(cwd);
    cBYE(status);
    /*----------------------------------------------------------*/

    *ptr_x_gpu_reg_X = l_gpu_reg_X;
    *ptr_x_gpu_reg_nX = l_gpu_reg_nX;
    *ptr_x_gpu_reg = l_gpu_reg;
    *ptr_x_n_gpu_reg = l_n_gpu_reg;

    /*----------------------------------------------------------*/
BYE:
    return status ;
}
예제 #12
0
파일: aux_meta.c 프로젝트: subramon/Q
// START FUNC DECL
int chk_fld_info(
		 FLD_INFO_TYPE X
		 )
// STOP FUNC DECL
{
  int status = 0;
  short fld_id = -1; 
  short len_fld_id = -1, off_fld_id = -1, dict_fld_id = -1;
  char name1[MAX_LEN_FLD_NAME+1];

  zero_string(name1, MAX_LEN_FLD_NAME+1);
  fld_id = X.fld_id;
  status = chk_fld_meta(fld_id, -1); cBYE(status);
  chk_range(fld_id, 0, g_n_fld);
  switch ( X.mode ) { 
  case fk_fld_txt_lkp : 
    dict_fld_id = X.xxx.dict_fld_id;
    chk_range(dict_fld_id, 0, g_n_fld);
    if ( is_zero_fld_rec(g_flds[dict_fld_id]) ) { go_BYE(-1); }
    // TODO P2 THINK if ( g_tbls[dict_tbl_id].tbltype != txt_lkp ) { go_BYE(-1); }
    /* I thought you could not be self-referential but this is okay.
     * Consider the following case. You have a lookup table called
     * TCountry. You add a field called xidx by duplicating idx (the
     * index field). Now you sort xidx and you want to print it out.
     * xidx will have to point to this table itself 
    if ( g_flds[fld_id].tbl_id == dict_tbl_id ) { go_BYE(-1); }
    */
    break;
  case fk_fld_len : 
    len_fld_id = X.xxx.len_fld_id;
    chk_range(len_fld_id, 0, g_n_fld);
    if ( is_zero_fld_rec(g_flds[len_fld_id]) ) { go_BYE(-1); }
    if ( g_flds[len_fld_id].fldtype != I2 ) { go_BYE(-1); }
    strcpy(name1, ".len."); strcat(name1, g_flds[fld_id].name);
    if ( strcmp(name1, g_flds[len_fld_id].name) != 0 ) { go_BYE(-1); }
    if ( g_flds[fld_id].tbl_id != g_flds[len_fld_id].tbl_id ) { go_BYE(-1); }
    break;
  case fk_fld_off : 
    off_fld_id = X.xxx.off_fld_id;
    chk_range(off_fld_id, 0, g_n_fld);
    if ( is_zero_fld_rec(g_flds[off_fld_id]) ) { go_BYE(-1); }
    if ( g_flds[off_fld_id].fldtype != I8 ) { go_BYE(-1); }
    strcpy(name1, ".off."); strcat(name1, g_flds[fld_id].name);
    if ( strcmp(name1, g_flds[off_fld_id].name) != 0 ) { go_BYE(-1); }
    if ( g_flds[fld_id].tbl_id != g_flds[off_fld_id].tbl_id ) { go_BYE(-1); }
    break;
  default: 
    go_BYE(-1);
    break;
  }
 BYE:
  return status;
}
예제 #13
0
파일: count_ones.c 프로젝트: TimLand/datacl
int
  count_ones(
      char *tbl,
      char *fld,
      long long *ptr_new_fld_cnt
      )
  {
    int status = 0;
    char buf1[64],buf2[64]; char *endptr;
    zero_string(buf1, 64);
    zero_string(buf2, 64);

    status = ext_f_to_s(tbl, fld, "sum", buf1,  64); cBYE(status);
    status = read_nth_val(buf1, ':', 0, buf2, 64); cBYE(status);
    *ptr_fld_cnt = strtoll(buf2, &endptr, 10); 
    if ( *endptr != '\0' ) { go_BYE(-1); }
    if ( *ptr_fld_cnt == 0 ) {
      fprintf(stderr, "WARNING! Adding fld [%s] => count = 0\n", fld);
    }
BYE:
    return(status);
  }
예제 #14
0
파일: aux_meta.c 프로젝트: subramon/Q
// START FUNC DECL
int
pr_fld_meta(
	    int fld_id,
	    FLD_REC_TYPE X
	    )
// STOP FUNC DECL
{
  int status = 0;
  int dict_fld_id, len_fld_id, off_fld_id;
  fprintf(stdout, "tbl_id,%d\n", X.tbl_id);
  fprintf(stdout, "name,%s\n", X.name);
  fprintf(stdout, "fileno,%d\n", X.fileno);
  fprintf(stdout, "filesz,%llu\n", (unsigned long long)X.filesz);
  char str_fldtype[32]; zero_string(str_fldtype, 32);
  status = mk_str_fldtype(X.fldtype, str_fldtype); cBYE(status);
  fprintf(stdout, "fldtype,%s\n", str_fldtype); 

  char str_auxtype[32]; zero_string(str_auxtype, 32);
  status = mk_str_auxtype(X.auxtype, str_auxtype); cBYE(status);
  fprintf(stdout, "auxtype,%s\n", str_auxtype); 

  char str_srttype[32]; zero_string(str_srttype, 32);
  status = mk_str_srttype(X.srttype, str_srttype); cBYE(status);
  fprintf(stdout, "srttype,%s\n", str_srttype); 

  status = get_fld_info(fk_fld_txt_lkp, fld_id, &dict_fld_id); cBYE(status);
  fprintf(stdout, "dict_fld_id,%d\n", dict_fld_id);

  fprintf(stdout, "parent_id,%d\n", X.parent_id);
  fprintf(stdout, "nn_fld_id,%d\n", X.nn_fld_id);
  status = get_fld_info(fk_fld_len, fld_id, &len_fld_id); cBYE(status);
  fprintf(stdout, "len_fld_id,%d\n", len_fld_id);
  status = get_fld_info(fk_fld_off, fld_id, &off_fld_id); cBYE(status);
  fprintf(stdout, "off_fld_id,%d\n", off_fld_id);
  fprintf(stdout, "is_external,%d\n", X.is_external);
 BYE:
  return status ;
}
예제 #15
0
static int get_data(
		    char *docroot,
		    sqlite3 *db,
		    char *tbl,
		    char *fld,
		    long long *ptr_nR,
		    FLD_META_TYPE *ptr_fld_meta,
		    char **ptr_X,
		    size_t *ptr_nX,
		    FLD_META_TYPE *ptr_nn_fld_meta,
		    char **ptr_nn_X,
		    size_t *ptr_nn_nX,
		    long long *ptr_nn_nR
		    )
{
  int status = 0;
  int tbl_id, fld_id;
  bool exists;
  char *X = NULL;    size_t nX = 0;
  char *nn_X = NULL; size_t nn_nX = 0;
  char *endptr = NULL;
  char buffer[32];

  zero_string(buffer, 32);

  status = is_tbl_fld(docroot, db, tbl, fld, &tbl_id, &fld_id, &exists);
  cBYE(status);
  if ( !exists ) { go_BYE(-1); }
  status = internal_get_nR(db, tbl_id, ptr_nR);
  status = fld_meta(docroot, db, tbl, fld, -1, ptr_fld_meta);
  cBYE(status);
  status = rs_mmap(ptr_fld_meta->filename, &X, &nX, 0);
  cBYE(status);
  status = get_aux_field_if_it_exists(docroot, db, tbl, fld_id, 
				      "nn", ptr_nn_fld_meta, &nn_X, &nn_nX);
  if ( nn_X == NULL ) { 
    *ptr_nn_nR = *ptr_nR;
  }
  else {
    status = f_to_s(docroot, db, tbl, ptr_nn_fld_meta->name, "sum", buffer);
    cBYE(status);
    *ptr_nn_nR = strtol(buffer, &endptr, 10);
    if ( *endptr != '\0' ) { go_BYE(-1); }
    if ( *ptr_nn_nR <= 0 ) { go_BYE(-1); }
  }
  *ptr_X  = X;       *ptr_nX = nX;
  *ptr_nn_X  = nn_X; *ptr_nn_nX = nn_nX;
 BYE:
  return(status);
}
예제 #16
0
// START FUNC DECL
int
int_hash_string(
	    const char *original_in_string,
	    unsigned long long *ptr_hash
	    )
// STOP FUNC DECL
{
  int status = 0;
  char out_string[128];
  char *in_string = NULL;
  unsigned long long ull[128/8];
  unsigned long long ulltemp = 0;

  if ( original_in_string == NULL ) go_BYE(-1);
  if ( *original_in_string == '\0' ) { *ptr_hash = 0; return status ; }

  zero_string(out_string, 128);
  int L = strlen(original_in_string);
  L += 4;
  in_string = (char *)malloc(L * sizeof(char));
  return_if_malloc_failed(in_string);
  strcpy(in_string, original_in_string);
  my_MDString(in_string, out_string);

  /* START: Convert out_string to a long long */
  char *cptr = out_string;
  int cnt = 0;
  for (int i = 0; i < 128/8; i++ ) { ull[i] = 0; }

  for (int i = 0; i < 128/8; i++ ) { 
    ulltemp = 0;
    for ( int j = 0; j < 8; j++ ) {
      if ( *cptr == '\0' ) { break; }
      unsigned long long l1 = (unsigned long long)(*cptr++);
      ulltemp = ulltemp  | ( l1 << (j*8) );
      cnt++;
    }
    ull[i] = ulltemp;
  }
  ulltemp = ull[0];
  for (int i = 1; i < 128/8; i++ ) { 
    if ( ull[i] == 0 ) { break; }
    ulltemp = ulltemp ^ mix_I8(ull[i]);
  }
  *ptr_hash = ulltemp;
 BYE:
  free_if_non_null(in_string);
  return status ;
}
예제 #17
0
// START FUNC DECL
int
num_exclusions(
	       int xlist_id, 
	       int *ptr_num_in_xlist
	       )
// STOP FUNC DECL
{
  int status = 0;
  char command[1024];
  zero_string(command, 1024); 
  sprintf(command, "select count(*) from flds_x_xlist where xlist_id = %d", xlist_id); 
  status = db_get_num_rslts(g_db, command, ptr_num_in_xlist); cBYE(status);
 BYE:
  return(status);
}
예제 #18
0
// START FUNC DECL
int
get_xlist_info(
		   int xlist_id,
		   char **ptr_fld, 
		   int *ptr_fld_id
		   )
// STOP FUNC DECL
{
  int status = 0;
  char command[1024]; 
  if ( xlist_id < 0 ) { go_BYE(-1); }

  zero_string(command, 1024); 
  sprintf(command, "select cum_fld_id from xlist where id = %d", xlist_id);
  status = db_get_ival(g_db, command, ptr_fld_id);

  zero_string(command, 1024); 
  sprintf(command, "select cum_fld from xlist where id = %d", xlist_id);
  status = db_get_sval(g_db, command, ptr_fld);

 BYE:
  // TODO P3 free_if_non_null(zErrMsg);
  return(status);
}
예제 #19
0
// START FUNC DECL
int
g_init_meta_data(
    char *docroot
)
// STOP FUNC DECL
{
    int status = 0;
    char cwd[MAX_LEN_DIR_NAME+1];
    char   *gpu_reg_X = NULL;
    size_t gpu_reg_nX = 0;
    GPU_REG_TYPE *gpu_reg = NULL; /* hash table for flds */
    int n_gpu_reg = 0; /* sizeof above */


    if ( ( docroot == NULL ) || ( *docroot == '\0' ) ) {
        go_BYE(-1);
    }
    zero_string(cwd, MAX_LEN_DIR_NAME+1);
    if ( getcwd(cwd, MAX_LEN_DIR_NAME) == NULL ) {
        go_BYE(-1);
    }

    /*----------------------------------------------------------*/
    size_t filesz = G_GPU_REG_SIZE * sizeof(GPU_REG_TYPE);
    status = mk_file(cwd, docroot, "docroot.gpu", filesz);
    cBYE(status);
    status = chdir(docroot);
    cBYE(status);
    status = rs_mmap("docroot.gpu", &gpu_reg_X, &gpu_reg_nX, 1);
    cBYE(status);
    if ( gpu_reg_nX == 0 ) {
        go_BYE(-1);
    }
    n_gpu_reg = gpu_reg_nX / sizeof(GPU_REG_TYPE);
    if (  (gpu_reg_nX % sizeof(GPU_REG_TYPE) ) != 0 ) {
        go_BYE(-1);
    }
    gpu_reg = (GPU_REG_TYPE *)gpu_reg_X;
    status = chdir(cwd);
    cBYE(status);
    /*----------------------------------------------------------*/
    for ( int i = 0; i < n_gpu_reg; i++ ) {
        zero_gpu_reg(&(gpu_reg[i]));
    }
    /*----------------------------------------------------------*/
BYE:
    return status ;
}
예제 #20
0
파일: copy_tbl.c 프로젝트: TimLand/datacl
// START FUNC DECL
int
copy_tbl(
	 char *in_tbl,
	 char *out_tbl
	 )
// STOP FUNC DECL
{
  int status = 0;
  int in_tbl_id, out_tbl_id;
  TBL_REC_TYPE in_tbl_rec, out_tbl_rec;
  long long nR; char str_nR[32];
  int num_flds = 0; int fld_ids[MAX_NUM_FLDS_IN_TBL];

  //------------------------------------------------
  zero_string(str_nR, 32);
  if ( ( in_tbl == NULL ) || ( *in_tbl == '\0' ) ) { go_BYE(-1); }
  if ( ( out_tbl == NULL ) || ( *out_tbl == '\0' ) ) { go_BYE(-1); }
  if ( strcmp(in_tbl, out_tbl) == 0 ) { go_BYE(-1); }
  //------------------------------------------------
  status = is_tbl(in_tbl, &in_tbl_id, &in_tbl_rec); cBYE(status);
  chk_range(in_tbl_id, 0, g_n_tbl);
  status = del_tbl(out_tbl, -1); cBYE(status);
  nR = in_tbl_rec.nR;
  sprintf(str_nR, "%lld", nR);
  //------------------------------------------------
  // Make list of primary fields in in_tbl
  status = tbl_meta(in_tbl, false, fld_ids, &num_flds);
  //------------------------------------------------
  status = add_tbl(out_tbl, str_nR, &out_tbl_id, &out_tbl_rec); cBYE(status);
  for ( int i = 0; i < num_flds; i++ ) { 
    int fld_id; char *fldname = NULL;
    fld_id = fld_ids[i];
    FLD_REC_TYPE fld_rec = g_flds[fld_id];
    fldname = g_flds[fld_id].name;
    bool skip_fld = false;
    switch ( fld_rec.fldtype ) { 
      case I1 : case I2 : case I4 : case I8 : case F4 : case F8 : break;
      default : skip_fld = true; break;
    }
    if ( skip_fld == true ) { continue; }
    status = copy_fld(in_tbl, fldname, NULL, out_tbl);
    cBYE(status);
  }

 BYE:
  return status ;
}
예제 #21
0
// START FUNC DECL
int
is_fld_in_xlist(
    char *xfld, 
    int xlist_id, 
    bool *ptr_b_exists
    )
// STOP FUNC DECL
{
  int status = 0;
  int itemp; char command[1024]; zero_string(command, 1024); 
  sprintf(command, "select count(*) from flds_x_xlist where fld = '%s' and xlist_id = %d ", xfld, xlist_id);
  status = db_get_ival(g_db, command, &itemp); cBYE(status);
  if ( itemp > 1 ) { go_BYE(-1); }
  if ( itemp == 1 ) { *ptr_b_exists = true; } else { *ptr_b_exists = false; }
BYE:
  return(status);
}
예제 #22
0
파일: queue.c 프로젝트: hrwang1982/ndoutils
char* pop_from_queue() {
	struct queue_msg msg;
	char *buf;

	zero_string(msg.text, NDO_MAX_MSG_SIZE);

	if (msgrcv(queue_id, &msg, queue_buff_size, NDO_MSG_TYPE, MSG_NOERROR) < 0) {
		syslog(LOG_ERR,"Error: queue recv error.\n");
	}

	int size = strlen(msg.text);
	buf = (char*)calloc(size+1, sizeof(char));
	strncpy(buf, msg.text, size);
	buf[size] = '\0';

	return buf;
}
예제 #23
0
// -------------------------------------------------------------------
// START FUNC DECL
int
get_num_in_list(
		int list_id,
		int *ptr_n
		)
// STOP FUNC DECL
{
  int status = 0;
  char command[1024];
  zero_string(command, 1024);
  if ( list_id <= 0 ) { go_BYE(-1); }
  *ptr_n = -1;
  sprintf(command, "select count(*) from flds_x_list where list_id = %d\n", list_id);
  status = db_get_num_rslts(g_db, command, ptr_n); cBYE(status);
  if ( *ptr_n < 0 ) { go_BYE(-1); }
 BYE:
  return(status);
}
예제 #24
0
파일: tbl_meta.c 프로젝트: TimLand/datacl
// START FUNC DECL
int
tbl_meta(
	 char *tbl
	 )
// STOP FUNC DECL
{
  int status = 0;
  int tbl_id = -1; TBL_REC_TYPE tbl_rec;
  char str_fldtype[32];

  //------------------------------------------------
  zero_string(str_fldtype, 32);
  if ( ( tbl == NULL ) || ( *tbl == '\0' ) ) { go_BYE(-1); }
  get_rd_lock();
#include "meta_map.h"
  status = mmap_meta_data(g_docroot, 
			  &tbl_X, &tbl_nX, &tbls, &n_tbl, 
			  &ht_tbl_X, &ht_tbl_nX, &ht_tbl, &n_ht_tbl, 
			  &fld_X, &fld_nX, &flds, &n_fld, 
			  &ht_fld_X, &ht_fld_nX, &ht_fld, &n_ht_fld);
  cBYE(status);
  status = core_is_tbl(tbl, tbls, n_tbl, ht_tbl, n_ht_tbl, &tbl_id, &tbl_rec);
  cBYE(status);
  if ( tbl_id < 0 ) { 
    fprintf(stderr, "Table [%s] not found\n", tbl); 
    go_BYE(-1);
  }
  //------------------------------------------------
  for ( int i = 0; i < n_fld; i++ ) { 
    if ( flds[i].tbl_id == tbl_id ) { 
      fprintf(stdout, "%d,%s,\"", i, flds[i].name);
      pr_disp_name(stdout, flds[i].dispname);
      status = mk_str_fldtype(flds[i].fldtype, str_fldtype);
      fprintf(stdout, "\",%s\n", str_fldtype);
    }
  }

  //------------------------------------------------
 BYE:
  release_rd_lock();
  unmap_meta_data(tbl_X, tbl_nX, ht_tbl_X, ht_tbl_nX, 
		  fld_X, fld_nX, ht_fld_X, ht_fld_nX);
  return(status);
}
예제 #25
0
파일: queue.c 프로젝트: hrwang1982/ndoutils
void push_into_queue (char* buf) {
	struct queue_msg msg;
	int size;
	msg.type = NDO_MSG_TYPE;
	zero_string(msg.text, NDO_MAX_MSG_SIZE);
	struct timespec delay;
	int sleep_time;
	unsigned retrynum = 0;

	strncpy(msg.text, buf, NDO_MAX_MSG_SIZE-1);

	if (msgsnd(queue_id, &msg, queue_buff_size, IPC_NOWAIT) < 0) {
		if (EAGAIN == errno) {
			log_retry();
			/* added retry loop, data was being dropped if queue was full 5/22/2012 -MG */
			while((EAGAIN == errno) && ( retrynum++ < MAX_RETRIES)) {
					if(msgsnd(queue_id, &msg, queue_buff_size, IPC_NOWAIT)==0)
							break;
					#ifdef USE_NANOSLEEP
						delay.tv_sec=(time_t)sleep_time;
						delay.tv_nsec=(long)((sleep_time-(double)delay.tv_sec)*1000000000);
						nanosleep(&delay,NULL);
					#else
						delay.tv_sec=(time_t)sleep_time;
						if(delay.tv_sec==0L)
							delay.tv_sec=1;
							delay.tv_nsec=0L;
							sleep((unsigned int)delay.tv_sec);
					#endif 		
				}
				if (retrynum < MAX_RETRIES) {
					syslog(LOG_ERR,"Message sent to queue.\n");
					}
				else {
					syslog(LOG_ERR,"Error: max retries exceeded sending message to queue. Kernel queue parameters may neeed to be tuned. See README.\n");
				}
			}
		else {
			syslog(LOG_ERR,"Error: queue send error.\n");
			}
		}

}
예제 #26
0
// START FUNC DECL
int
get_fld_id(
	   int list_id, 
	   int position, 
	   char *mode,
	   int *ptr_fld_id
	   )
// STOP FUNC DECL
{
  int status = 0;
  char command[1024];
  zero_string(command, 1024);

  chk_mode(mode);
  sprintf(command, "select %sfld_id from  flds_x_list where list_id = %d and position = %d ", mode, list_id, position);
  status = db_get_ival(g_db, command, ptr_fld_id); cBYE(status);
 BYE:
  return(status);
}
예제 #27
0
// START FUNC DECL
int
update_xlist(
		  char *cum_fld, 
		  char *list,
		  int cum_fld_id
		  )
// STOP FUNC DECL
{
  int status = 0;
  char command[1024]; char *zErrMsg = NULL;
  zero_string(command, 1024); 

  sprintf(command, "update xlist set cum_fld = '%s', cum_fld_id = %d where list = '%s' ", cum_fld, cum_fld_id, list);
  int rc = sqlite3_exec(g_db, command, NULL, 0, &zErrMsg);
  if ( rc ) { handle_sqlite_error(); }
 BYE:
  // TODO P3: free_if_non_null(zErrMsg);
  return(status);
}
예제 #28
0
// START FUNC DECL
int
is_list(
	    char *list, 
	    bool *ptr_b_is_list
	    )
// STOP FUNC DECL
{
  int status = 0;
  char command[1024]; int n;

  *ptr_b_is_list = false;
  zero_string(command, 1024);
  if ( ( list == NULL ) || ( *list == '\0' ) )  { go_BYE(-1); }
  sprintf(command, "select count(*) from list where name = '%s'\n", list);
  status = db_get_num_rslts(g_db, command, &n);
  if ( n == 0 ) { *ptr_b_is_list = false; } else { *ptr_b_is_list = true; } 
 BYE:
  return(status);
}
예제 #29
0
파일: dateconv.c 프로젝트: TimLand/datacl
// START FUNC DECL
int
dateconv(
    char *in_X, /* input string */
    int *in_sz_X, /* size spec for input */
    long long nX, /* number of rows */
    char *date_format,
    int *in_output
    )
// STOP FUNC DECL
{
  int status = 0;
#define MAX_LEN_DATE 31
  char buffer[MAX_LEN_DATE+1];
  char *X = in_X;
  int *sz_X = in_sz_X;
  int *output = in_output;
  struct tm tm;
  int sz;

  zero_string(buffer, MAX_LEN_DATE+1);
  for ( long long i = 0; i < nX; i++ ) { 
    sz = *sz_X;
    if ( sz >= MAX_LEN_DATE ) { 
      fprintf(stderr, "String [%s] too long to be a date \n", X);
      go_BYE(-1);
    }
    if ( sz == 1 ) { /* null string */
      *output = 0;
    }
    else {
      strptime(X, date_format, &tm);
      *output = mktime(&tm);
    }
    // Move to next string 
    output++;
    sz_X++;
    X += sz;
  }

BYE:
  return(status);
}
예제 #30
0
// START FUNC DECL
int
get_fld_name(
	     int list_id, 
	     int position, 
	     char *mode,
	     char **ptr_fld
	     )
// STOP FUNC DECL
{
  int status = 0;
  char command[1024];
  zero_string(command, 1024);

  chk_mode(mode);
  sprintf(command, "select %sfld from  flds_x_list where list_id = %d and position = %d ", mode, list_id, position);
  status = db_get_sval(g_db, command, ptr_fld); cBYE(status);
  if ( strcmp(*ptr_fld, "(null)") == 0 ) {
    free_if_non_null(*ptr_fld);
  }
 BYE:
  return(status);
}