void R_ut_convert(const double *x, int *count, char * const *units_from, char * const *units_to, double *rv) { ut_unit *from, *to; cv_converter *conv; int one = 1; if (sys == NULL) { R_ut_init(&one); } ut_trim(*units_from, enc); ut_trim(*units_to, enc); from = ut_parse(sys, *units_from, enc); if (from == NULL) { handle_error("R_ut_convert"); return; } to = ut_parse(sys, *units_to, enc); if (from == NULL) { handle_error("R_ut_convert"); return; } conv = ut_get_converter(from, to); if (conv == NULL) { handle_error("R_ut_convert"); return; } cv_convert_doubles(conv, x, (size_t) *count, rv); // Cleanup cv_free(conv); ut_free(to); ut_free(from); return; }
void R_ut_are_convertible(char * const *ustring1, char * const *ustring2, int *convertible) { ut_unit *u1, *u2; int one = 1; if (sys == NULL) { R_ut_init(&one); } ut_trim(*ustring1, enc); ut_trim(*ustring2, enc); u1 = ut_parse(sys, *ustring1, enc); u2 = ut_parse(sys, *ustring2, enc); if (!(u1 && u2)) { handle_error("R_ut_are_convertible"); } if (ut_are_convertible(u1, u2) == 0) { *convertible = 0; } else { *convertible = 1; } ut_free(u1); ut_free(u2); return; }
/* * Prompt the user and get a specification. */ static int getSpec( const char* const prompt, char* const spec, const size_t size) { int nbytes = -1; /* failure */ if (fputs(prompt, stdout) == EOF) { errMsg("Couldn't write prompt: %s", strerror(errno)); } else if (fgets(spec, (int)size, stdin) == NULL) { putchar('\n'); if (feof(stdin)) { _exitStatus = EXIT_SUCCESS; } else { errMsg("Couldn't read from standard input: %s", strerror(errno)); } } else { /* * Trim any whitespace from the specification. */ (void)ut_trim(spec, _encoding); nbytes = (int)strlen(spec); } return nbytes; }
void R_ut_get_symbol(char * const *ustring, char **rstring) { ut_unit *u; char *trimmed; char *s; trimmed = ut_trim(*ustring, enc); u = ut_parse(sys, trimmed, enc); if (!u) { handle_error("R_ut_get_symbol"); } s = (char *) ut_get_symbol(u, enc); // FIXME: ut_get_symbol seems to allocate the string... does it need to be free-ed? if (s == NULL) return; else *rstring = s; return; }
void R_ut_is_parseable(char * const *units_string, int *parseable) { ut_unit *result; int one = 1; if (sys == NULL) { R_ut_init(&one); } ut_trim(*units_string, enc); result = ut_parse(sys, *units_string, enc); if (result == NULL) { *parseable = 0; } else { *parseable = 1; } ut_free(result); return; }
static int read_start_server_output (char *stdout_file, char *stderr_file, char *_dbmt_error) { FILE *fp, *fp2; char buf[1024]; char *strp; int retval = 0; if (access (stdout_file, F_OK) == 0) { fp = fopen (stdout_file, "r"); if (fp != NULL) { while (fgets (buf, sizeof (buf), fp) != NULL) { if (strncmp (buf, "++", 2) == 0) { if ((strp = strchr (buf, ':')) && strstr (strp, "fail")) { retval = -1; break; } } } fclose (fp); } } if (access (stderr_file, F_OK) == 0) { fp2 = fopen (stderr_file, "r"); if (fp2 != NULL) { int len = 0; while (fgets (buf, sizeof (buf), fp2) != NULL) { ut_trim (buf); len += (int) strlen (buf); if (len < (DBMT_ERROR_MSG_SIZE - 1)) { strcpy (_dbmt_error, buf); _dbmt_error += len; } else { strcpy_limit (_dbmt_error, buf, DBMT_ERROR_MSG_SIZE); strcpy_limit (_dbmt_error + DBMT_ERROR_MSG_SIZE - 4, "...", 4); break; } } if (len != 0 && retval != -1) { retval = 1; } fclose (fp2); } } return retval; }
bool NCaxisInitialize (int ncid, NCaxis_p axis, NCaxisType axisType, ut_system *utSystem) { int status; int varid; int ndims; size_t attlen, i; char text [NC_MAX_NAME + 1]; double interval; bool doUnits = true; switch (axis->AxisType = axisType) { case NCaxisX: if (((varid = NCfindVariableByAttribute (ncid,1,NCaxisStr,"x")) == CMfailed) && ((varid = NCfindVariableByAttribute (ncid,1,NCaxisStr,"X")) == CMfailed)) { CMmsgPrint (CMmsgAppError, "Missing x axis variable in NetCDF file!\n"); return (false); } break; case NCaxisY: if (((varid = NCfindVariableByAttribute (ncid,1,NCaxisStr,"y")) == CMfailed) && ((varid = NCfindVariableByAttribute (ncid,1,NCaxisStr,"Y")) == CMfailed)) { CMmsgPrint (CMmsgAppError, "Missing y axis variable in NetCDF file!\n"); return (false); } break; case NCaxisZ: if (((varid = NCfindVariableByAttribute (ncid,1,NCaxisStr,"z")) == CMfailed) && ((varid = NCfindVariableByAttribute (ncid,1,NCaxisStr,"Z")) == CMfailed)) { axis->Dimid = 0; if (((axis->Data = (double *) malloc (sizeof (double))) == (double *) NULL) || ((axis->Bounds = (double *) malloc (sizeof (double) * 2)) == (double *) NULL)) { CMmsgPrint (CMmsgSysError, "Memory allocation error in %s:%d!\n",__FILE__,__LINE__); return (false); } axis->N = 1; axis->Dimid = CMfailed; axis->Data [0] = axis->Bounds [0] = axis->Bounds [1] = 0.0; return (true); } break; case NCaxisTime: if (((varid = NCfindVariableByAttribute (ncid,1,NCaxisStr,"t")) == CMfailed) && ((varid = NCfindVariableByAttribute (ncid,1,NCaxisStr,"time")) == CMfailed)) { CMmsgPrint (CMmsgAppError, "Missing time axis variable in NetCDF file!\n"); return (false); } break; } if (((status = nc_inq_varndims (ncid,varid,&ndims)) != NC_NOERR) || (ndims != 1) || ((status = nc_inq_vardimid (ncid,varid,&(axis->Dimid))) != NC_NOERR) || ((status = nc_inq_dimlen (ncid,axis->Dimid,&(axis->N))) != NC_NOERR)) { CMmsgPrint (CMmsgAppError,"NetCDF variable dimension inquiring error \"%s\" in %s:%d!\n",nc_strerror (status),__FILE__,__LINE__); return (false); } if ((status = nc_inq_attlen (ncid,varid,NCaxisStr,&attlen)) == NC_NOERR) { if ((axis->Axis = (char *) malloc (attlen + 1)) == (char *) NULL) { CMmsgPrint (CMmsgSysError,"Memory allocation error in: %s:%d!\n",__FILE__,__LINE__); return (false); } if ((status = nc_get_att_text (ncid,varid,NCaxisStr,axis->Axis)) != NC_NOERR) { CMmsgPrint (CMmsgAppError,"NetCDF attribute inquiring error \"%s\" in %s:%d!\n",nc_strerror (status),__FILE__,__LINE__); return (false); } else axis->Axis [attlen] = '\0'; } if ((status = nc_inq_attlen (ncid,varid,NClongNameStr,&attlen)) == NC_NOERR) { if ((axis->LongName = (char *) malloc (attlen + 1)) == (char *) NULL) { CMmsgPrint (CMmsgSysError,"Memory allocation error in: %s:%d!\n",__FILE__,__LINE__); return (false); } if ((status = nc_get_att_text (ncid,varid,NClongNameStr,axis->LongName)) != NC_NOERR) { CMmsgPrint (CMmsgAppError,"NetCDF attribute inquiring error \"%s\" in %s:%d!\n",nc_strerror (status),__FILE__,__LINE__); return (false); } else axis->LongName [attlen] = '\0'; } if ((status = nc_inq_attlen (ncid,varid,NCstandardNameStr,&attlen)) == NC_NOERR) { if ((axis->StandardName = (char *) malloc (attlen + 1)) == (char *) NULL) { CMmsgPrint (CMmsgSysError,"Memory allocation error in: %s:%d!\n",__FILE__,__LINE__); return (false); } if ((status = nc_get_att_text (ncid,varid,NCstandardNameStr,axis->StandardName)) != NC_NOERR) { CMmsgPrint (CMmsgAppError,"NetCDF attribute inquiring error \"%s\" in %s:%d!\n",nc_strerror (status),__FILE__,__LINE__); return (false); } else axis->StandardName [attlen] = '\0'; } if (doUnits) { if ((status = nc_inq_attlen (ncid,varid,NCunitsStr,&attlen)) == NC_NOERR) { if (attlen > 0) { if ((status = nc_get_att_text (ncid,varid,NCunitsStr,text)) != NC_NOERR) { CMmsgPrint (CMmsgAppError,"NetCDF attribute inquiring error \"%s\" in %s:%d!\n",nc_strerror (status),__FILE__,__LINE__); return (false); } else text [attlen] = '\0'; if ((axis->Unit = ut_parse (utSystem, ut_trim (text, UT_ASCII), UT_ASCII)) == (ut_unit *) NULL) { switch (ut_get_status ()) { case UT_BAD_ARG: CMmsgPrint (CMmsgAppError, "System or string is NULL!\n"); break; case UT_SYNTAX: CMmsgPrint (CMmsgAppError, "String contained a syntax error!n"); break; case UT_UNKNOWN: CMmsgPrint (CMmsgAppError, "String contained an unknown identifier!\n"); break; default: CMmsgPrint (CMmsgSysError, "System error in %s:%d!n",__FILE__,__LINE__); } } } } } if (((status = nc_inq_attlen (ncid,varid,NCpositiveStr,&attlen)) == NC_NOERR) && (attlen < NC_MAX_NAME)) { if ((status = nc_get_att_text (ncid,varid,NCpositiveStr,text)) != NC_NOERR) { CMmsgPrint (CMmsgAppError,"NetCDF attribute inquiring error \"%s\" in %s:%d!\n",nc_strerror (status),__FILE__,__LINE__); return (false); } else text [attlen] = '\0'; axis->Direction = strcmp (text,NCpositiveUpStr) == 0 ? NCdirUp : NCdirDown; } else axis->Direction = NCdirUp; if (((axis->Data = (double *) malloc (axis->N * sizeof (double))) == (double *) NULL) || ((axis->Bounds = (double *) malloc (axis->N * sizeof (double) * 2)) == (double *) NULL)) { CMmsgPrint (CMmsgSysError,"Memory allocation error in: %s:%d!\n",__FILE__,__LINE__); return (false); } if ((status = nc_get_var_double (ncid,varid,axis->Data)) != NC_NOERR) { CMmsgPrint (CMmsgAppError,"NetCDF %s axis data loading error \"%s\" in %s:%d!\n",_NCaxisGetTypeString (axis->AxisType),nc_strerror (status),__FILE__,__LINE__); return (false); } if (((status = nc_inq_attlen (ncid,varid,NCboundsStr, &attlen)) == NC_NOERR) && (attlen < NC_MAX_NAME)) { if ((status = nc_get_att_text (ncid,varid,NCboundsStr,text)) != NC_NOERR) { CMmsgPrint (CMmsgAppError,"NetCDF bounds attribute inquiring error \"%s\" in %s:%d!\n",nc_strerror (status),__FILE__,__LINE__); return (false); } else text [attlen] = '\0'; if ((status = nc_inq_varid (ncid,text,&varid)) != NC_NOERR) { CMmsgPrint (CMmsgAppError,"NetCDF bounds variable inquery error \"%s\" in %s:%d!\n", nc_strerror (status),__FILE__,__LINE__); return (false); } if ((status = nc_get_var_double (ncid,varid,axis->Bounds)) != NC_NOERR) { CMmsgPrint (CMmsgAppError,"NetCDF %s axis bounds loading error \"%s\" in %s:%d!\n",_NCaxisGetTypeString (axis->AxisType),nc_strerror (status),__FILE__,__LINE__); return (false); } } else { for (i = 1;i < axis->N - 1; ++i) { axis->Bounds [i * 2] = (axis->Data [i] + axis->Data [i - 1]) / 2.0; axis->Bounds [i * 2 + 1] = (axis->Data [i + 1] + axis->Data [i]) / 2.0; } axis->Bounds [1] = axis->Bounds [2]; axis->Bounds [0] = axis->Data [0] - (axis->Bounds [1] - axis->Data [0]); axis->Bounds [i * 2] = axis->Bounds [(i - 1) * 2 + 1]; axis->Bounds [i * 2 + 1] = axis->Data [i] + (axis->Data [i] - axis->Bounds [i * 2]); } axis->IntervalMin = axis->Bounds [i * 2 + 1] - axis->Bounds [0]; axis->IntervalMax = 0.0; for (i = 0;i < axis->N; ++i) { interval = axis->Bounds [i * 2 + 1] - axis->Bounds [i * 2]; axis->IntervalMin = CMmathMinimum (axis->IntervalMin,interval); axis->IntervalMax = CMmathMaximum (axis->IntervalMax,interval); } axis->Regular = axis->N > 1 ? CMmathEqualValues (axis->IntervalMin,axis->IntervalMax) : true; return (true); }
int read_error_file (const char *err_file, char *err_buf, int err_buf_size) { FILE *fp; char buf[1024]; int msg_size = 0; char rm_prev_flag = 0; char is_debug = 0; size_t i; if (err_buf == NULL || err_file == NULL || err_file[0] == '\0' || err_buf_size == 0) { return 0; } memset (err_buf, 0, err_buf_size); fp = fopen (err_file, "r"); if (fp == NULL) { return 0; } while (1) { memset (buf, 0, sizeof (buf)); if (fgets (buf, sizeof (buf) - 1, fp) == NULL) { break; } for (i = 0; i < sizeof (buf) - 2; i++) { if (buf[i] == '\0') { if (buf[i + 1] == '\0') { break; } buf[i] = ' '; } } ut_trim (buf); if (buf[0] == '\0') { continue; } if (strncmp (buf, "---", 3) == 0 || strncmp (buf, "***", 3) == 0 || strncmp (buf, "<<<", 3) == 0 || strncmp (buf, "Time:", 5) == 0) { if (strstr (buf, "- DEBUG") != NULL) { is_debug = 1; } else { is_debug = 0; rm_prev_flag = 1; } continue; } /* ignore all the debug information, until find new line start with "---"|"***"|"<<<"|"Time:". */ if (is_debug != 0) { continue; } if (rm_prev_flag != 0) { msg_size = 0; } strcat (buf, "<end>"); if ((err_buf_size - msg_size - 1) > 0) { strncpy (err_buf + msg_size, buf, err_buf_size - msg_size - 1); } else { break; } msg_size += (int) strlen (buf); rm_prev_flag = 0; } err_buf[err_buf_size - 1] = '\0'; fclose (fp); return (msg_size > 0 ? -1 : 0); }
int read_csql_error_file (char *err_file, char *err_buf, int err_buf_size) { FILE *fp; char buf[1024]; int msg_size = 0; if (err_buf) { memset (err_buf, 0, err_buf_size); } if (err_file == NULL || err_file[0] == '\0') { return 0; } fp = fopen (err_file, "r"); if (fp == NULL) { return 0; } while (1) { memset (buf, 0, sizeof (buf)); if (fgets (buf, sizeof (buf) - 1, fp) == NULL) { break; } ut_trim (buf); if ((strncasecmp (buf, "ERROR", 5) == 0)) { if (err_buf != NULL) { snprintf (err_buf, err_buf_size - 1, "%s", buf + 6); } msg_size = (int) strlen (buf + 6); break; } else if (strstr (buf, "*** ERROR") != NULL) { memset (buf, 0, sizeof (buf)); if (fgets (buf, sizeof (buf) - 1, fp) == NULL) { break; } if (err_buf != NULL) { snprintf (err_buf, err_buf_size - 1, "%s", buf); } msg_size = (int) strlen (buf); break; } } fclose (fp); return (msg_size > 0 ? -1 : 0); }
void SpaceDbResultNewFormat::read_spacedb_output (FILE *fp) { char page_unit, log_page_unit, *p; double page_size, log_page_size_double; char str_buf[1024]; int db_page_size = 0, log_page_size = 0; int index = 0; while (fgets (str_buf, sizeof (str_buf), fp)) { ut_trim (str_buf); if (strncmp (str_buf, "Space", 5) == 0) { p = strstr (str_buf, "pagesize"); if (p) { sscanf (p, "pagesize %lf%c", &page_size, &page_unit); if ((db_page_size = _size_to_byte_by_unit (page_size, page_unit)) < 0) { goto spacedb_error; } set_page_size (db_page_size); } p = strstr (str_buf, "log pagesize:"); if (p) { sscanf (p, "log pagesize: %lf%c", &log_page_size_double, &log_page_unit); if ((log_page_size = _size_to_byte_by_unit (log_page_size_double, log_page_unit)) < 0) { goto spacedb_error; } set_log_page_size (log_page_size); } } if (strncmp (str_buf, "type", 4) == 0) { break; } } while (fgets (str_buf, sizeof (str_buf), fp)) { ut_trim (str_buf); if (strncmp (str_buf, "Space", 5) == 0) { break; } if (!is_valid_database_description (str_buf)) { break; } sscanf (str_buf, "%s %s DATA %d %d %d %d", databaseSpaceDescriptions[index].type, databaseSpaceDescriptions[index].purpose, &databaseSpaceDescriptions[index].volume_count, &databaseSpaceDescriptions[index].used_size, &databaseSpaceDescriptions[index].free_size, &databaseSpaceDescriptions[index].total_size); index++; } while (fgets (str_buf, sizeof (str_buf), fp)) { ut_trim (str_buf); if (strncmp (str_buf, "Detailed", 8) == 0) { break; } if (!is_valid_volume_description (str_buf)) { continue; } add_volume (str_buf); } while (fgets (str_buf, sizeof (str_buf), fp)) { ut_trim (str_buf); if (strncmp (str_buf, "data_type", 9) == 0) { break; } } index = 0; while (fgets (str_buf, sizeof (str_buf), fp)) { ut_trim (str_buf); if (!is_valid_file_description (str_buf)) { continue; } sscanf (str_buf, "%s %d %d %d %d %d\n", fileSpaceDescriptions[index].data_type, &fileSpaceDescriptions[index].file_count, &fileSpaceDescriptions[index].used_size, &fileSpaceDescriptions[index].file_table_size, &fileSpaceDescriptions[index].reserved_size, &fileSpaceDescriptions[index].total_size); index++; } fclose (fp); return; spacedb_error: fclose (fp); }
void SpaceDbResultOldFormat::read_spacedb_output (FILE *fp) { char str_buf[1024]; int db_page_size = 0, log_page_size = 0; while (fgets (str_buf, sizeof (str_buf), fp)) { char *tmp_p; ut_trim (str_buf); if (strncmp (str_buf, "Space", 5) == 0) { int matchs = 0; double page_size = 0.0; char page_unit = 'H'; /* * The log format looks like the following: * Space description for database 'demodb' with pagesize 16.0K. (log pagesize: 16.0K) */ tmp_p = strstr (str_buf, "pagesize"); if (tmp_p == NULL) { goto spacedb_error; } if ((matchs = sscanf (tmp_p, "pagesize %lf%c", &page_size, &page_unit)) != 2) { goto spacedb_error; } if ((db_page_size = _size_to_byte_by_unit (page_size, page_unit)) < 0) { goto spacedb_error; } tmp_p = strstr (str_buf, "log pagesize:"); if (tmp_p != NULL) { if ((matchs = sscanf (tmp_p, "log pagesize: %lf%c", &page_size, &page_unit)) != 2) { goto spacedb_error; } if ((log_page_size = _size_to_byte_by_unit (page_size, page_unit)) < 0) { goto spacedb_error; } } else { /* log pagesize default value */ log_page_size = 4096; } } else if (strncmp (str_buf, "Volid", 5) == 0) { break; } } while (fgets (str_buf, sizeof (str_buf), fp)) { ut_trim (str_buf); if (str_buf[0] == '\0' || str_buf[0] == '-') { continue; } if (strncmp (str_buf, "Volid", 5) == 0) { break; } if (strncmp (str_buf, "Space", 5) == 0) { continue; } if (add_volume (str_buf)) { continue; } } while (fgets (str_buf, sizeof (str_buf), fp)) { ut_trim (str_buf); if (str_buf[0] == '\0' || str_buf[0] == '-') { continue; } if (strncmp (str_buf, "Volid", 5) == 0) { break; } if (add_temporary_volume (str_buf)) { continue; } } set_page_size (db_page_size); set_log_page_size (log_page_size); fclose (fp); return; spacedb_error: fclose (fp); }
static int log_top (FILE * fp, char *filename) { char *linebuf = NULL; T_QUERY_INFO query_info_buf[MAX_SRV_HANDLE]; char client_msg_buf[CLIENT_MSG_BUF_SIZE]; char connect_msg_buf[CONNECT_MSG_BUF_SIZE]; T_STRING *cas_log_buf = NULL; T_STRING *sql_buf = NULL; T_STRING *linebuf_tstr = NULL; char prepare_buf[128]; int i; char *msg_p; int lineno = 0; char read_flag = 1; char cur_date[32]; for (i = 0; i < MAX_SRV_HANDLE; i++) query_info_init (&query_info_buf[i]); cas_log_buf = t_string_make (1); sql_buf = t_string_make (1); linebuf_tstr = t_string_make (1000); if (cas_log_buf == NULL || sql_buf == NULL || linebuf_tstr == NULL) { fprintf (stderr, "malloc error\n"); goto log_top_err; } memset (client_msg_buf, 0, sizeof (client_msg_buf)); memset (connect_msg_buf, 0, sizeof (connect_msg_buf)); t_string_clear (cas_log_buf); t_string_clear (sql_buf); memset (prepare_buf, 0, sizeof (prepare_buf)); while (1) { if (read_flag) { if (ut_get_line (fp, linebuf_tstr, &linebuf, &lineno) <= 0) { break; } } read_flag = 1; if (!IS_CAS_LOG_CMD (linebuf)) continue; if (strncmp (linebuf + 23, "END OF LOG", 10) == 0) { break; } GET_CUR_DATE_STR (cur_date, linebuf); GET_MSG_START_PTR (msg_p, linebuf); if (strncmp (msg_p, "execute", 7) == 0 || strncmp (msg_p, "execute_all", 11) == 0 || strncmp (msg_p, "execute_call", 12) == 0 || strncmp (msg_p, "execute_batch", 13) == 0) { int qi_idx; char *query_p; int end_block_flag = 0; /* * execute log format: * <execute_cmd> srv_h_id <handle_id> <query_string> * bind <bind_index> : <TYPE> <VALUE> * <execute_cmd> [error:]<res> tuple <tuple_count> time <runtime_msec> * <execute_cmd>: * execute, execute_all or execute_call * * ex) * execute srv_h_id 1 select 'a' from db_root * bind 1 : VARCHAR test str * execute 0 tuple 1 time 0.004 */ qi_idx = log_execute (query_info_buf, linebuf, &query_p); if (qi_idx < 0 || query_p == NULL) goto log_top_err; t_string_clear (sql_buf); t_string_clear (cas_log_buf); t_string_add (sql_buf, query_p, strlen (query_p)); t_string_add (cas_log_buf, linebuf, strlen (linebuf)); if (read_multi_line_sql (fp, linebuf_tstr, &linebuf, &lineno, sql_buf, cas_log_buf) < 0) { break; } if (read_bind_value (fp, linebuf_tstr, &linebuf, &lineno, cas_log_buf) < 0) { break; } GET_MSG_START_PTR (msg_p, linebuf); /* skip query_cancel */ if (strncmp (msg_p, "query_cancel", 12) == 0) { if (ut_get_line (fp, linebuf_tstr, &linebuf, &lineno) <= 0) { break; } } if (strncmp (msg_p, "execute", 7) != 0) { while (1) { if (ut_get_line (fp, linebuf_tstr, &linebuf, &lineno) <= 0) { break; } GET_MSG_START_PTR (msg_p, linebuf); if (strncmp (msg_p, "***", 3) == 0) { end_block_flag = 1; if (ut_get_line (fp, linebuf_tstr, &linebuf, &lineno) <= 0) { /* ut_get_line error, just break; */ break; } break; } } } if (end_block_flag == 1) { continue; } query_info_buf[qi_idx].sql = (char *) REALLOC (query_info_buf[qi_idx].sql, t_string_len (sql_buf) + 1); strcpy (query_info_buf[qi_idx].sql, ut_trim (t_string_str (sql_buf))); GET_MSG_START_PTR (msg_p, linebuf); GET_CUR_DATE_STR (cur_date, linebuf); if (log_top_mode == MODE_MAX_HANDLE) { if (qi_idx >= mode_max_handle_lower_bound) { if (query_info_add (&query_info_buf[qi_idx], qi_idx + 1, 0, filename, lineno, cur_date) < 0) goto log_top_err; } } else { int execute_res, runtime; if (read_execute_end_msg (msg_p, &execute_res, &runtime) < 0) { if (query_info_add_ne (&query_info_buf[qi_idx], cur_date) < 0) goto log_top_err; read_flag = 0; continue; } if (t_string_add (cas_log_buf, linebuf, strlen (linebuf)) < 0) { goto log_top_err; } query_info_buf[qi_idx].cas_log = (char *) REALLOC (query_info_buf[qi_idx].cas_log, t_string_len (cas_log_buf) + 1); memcpy (query_info_buf[qi_idx].cas_log, t_string_str (cas_log_buf), t_string_len (cas_log_buf)); query_info_buf[qi_idx].cas_log_len = t_string_len (cas_log_buf); if (query_info_add (&query_info_buf[qi_idx], runtime, execute_res, filename, lineno, cur_date) < 0) { goto log_top_err; } } } } for (i = 0; i < MAX_SRV_HANDLE; i++) query_info_clear (&query_info_buf[i]); t_string_free (cas_log_buf); t_string_free (sql_buf); t_string_free (linebuf_tstr); return 0; log_top_err: t_string_free (cas_log_buf); t_string_free (sql_buf); t_string_free (linebuf_tstr); return -1; }