static void CheckReturnCode(SQLRETURN result, SQLSMALLINT expected, int line) { if (ReturnCode == expected && (expected != INVALID_RETURN || strcmp(OutString, "Invalid!") == 0) && (expected == INVALID_RETURN || strcmp(OutString, "This is bogus!") == 0)) return; printf("SpDateTest Output:\n"); printf(" Result = %d\n", (int) result); printf(" Return Code = %d\n", (int) ReturnCode); printf(" OutString = \"%s\"\n", OutString); MY_ERROR("Invalid ReturnCode"); }
static void CheckData(const char *s, int line) { char buf[80]; SQLLEN ind; SQLRETURN rc; rc = CHKGetData(1, SQL_C_CHAR, buf, sizeof(buf), &ind, "SE"); if (rc == SQL_ERROR) { buf[0] = 0; ind = 0; } if (strlen(s) != ind || strcmp(buf, s) != 0) MY_ERROR("Invalid result"); }
int main(int argc, char *argv[]) { int opt_c; char buf[FILENAME_MAX]; int rc = 1; me = strrchr(argv[0], '/'); if (me == NULL ) { me = argv[0]; } else { me++; } my_log_init(me); my_conf = my_conf_create(); if (!my_conf) { goto _MY_ERR_conf_create; } while ((opt_c = getopt(argc, argv, "C:L:Vh?")) != -1) switch (opt_c) { case 'C': my_conf->cfg_file = optarg; break; case 'L': my_conf->log_file = optarg; break; case 'P': my_conf->pid_file = optarg; break; case 'V': my_show_version(); rc = 0; goto _MY_EXIT; case '?': case 'h': my_show_usage(); rc = 0; goto _MY_EXIT; default: MY_ERROR("unknow argument '-%c'", (int)opt_c); my_show_usage(); rc = 1; goto _MY_EXIT; } my_conf->log_level = -1; if (my_conf->cfg_file == NULL) { snprintf(buf, sizeof(buf), "%s/%s.conf", MY_CFG_DIR, me); my_conf->cfg_file = strdup(buf); } if (my_conf_parse(my_conf) != 0) { goto _MY_ERR_conf_parse; } if (my_conf->log_file == NULL) { #ifdef MY_DEBUGGING my_conf->log_file = "stderr"; #else my_conf->log_file = "syslog"; #endif } if (my_conf->log_level < 0) { #ifdef MY_DEBUGGING my_conf->log_level = MY_LOG_DEBUG; #else my_conf->log_level = MY_LOG_NOTICE; #endif } if (my_conf->pid_file == NULL) { snprintf(buf, sizeof(buf), "%s/%s.pid", MY_RUN_DIR, me); my_conf->pid_file = strdup(buf); } if (my_log_open(my_conf->log_file, my_conf->log_level) != 0) { goto _MY_ERR_log_open; } my_log(MY_LOG_NOTICE, "started"); my_core = my_core_create(); if (!my_core) { goto _MY_ERR_core_create; } if (my_core_init(my_core, my_conf) != 0) { goto _MY_ERR_core_init; } signal(SIGINT, my_sig_handler); signal(SIGTERM, my_sig_handler); #ifdef MY_DEBUGGING my_conf_dump(my_conf); my_core_dump(my_core); #endif my_core_loop(my_core); my_core_destroy(my_core); my_log(MY_LOG_NOTICE, "ended"); my_log_close(); return 0; _MY_ERR_core_init: my_core_destroy(my_core); _MY_ERR_core_create: my_log_close(); _MY_ERR_log_open: _MY_ERR_conf_parse: _MY_EXIT: my_conf_destroy(my_conf); _MY_ERR_conf_create: return rc; }