/* * Write the SSL/TLS certificate after asking the user to accept/reject it. */ int write_cert(X509 *cert) { FILE *fd; char c, buf[64]; char *certf; do { printf("(R)eject, accept (t)emporarily or " "accept (p)ermanently? "); if (fgets(buf, sizeof(buf), stdin) == NULL) return -1; c = tolower((int)(*buf)); } while (c != 'r' && c != 't' && c != 'p'); if (c == 'r') return -1; else if (c == 't') return 0; certf = get_filepath("certificates"); create_file(certf, S_IRUSR | S_IWUSR); fd = fopen(certf, "a"); xfree(certf); if (fd == NULL) return -1; PEM_write_X509(fd, cert); fclose(fd); return 0; }
//--------------------------------------------------------------------------------------- wxImage ArtProvider::get_image(const wxArtID& id, const wxArtClient& client, const wxSize& size) { wxFileName oFilename = get_filepath(id, client, size); //LOMSE_LOG_INFO(str(boost::format("Art: Filepath='%s'") // % oFilename.GetFullPath().wx_str() )); if (oFilename.GetFullPath() == "null") { wxBitmap oBitmap(null_xpm); return oBitmap.ConvertToImage(); } wxImage image; if (image.LoadFile(oFilename.GetFullPath(), wxBITMAP_TYPE_PNG)) return image; else { // if file not found we need to return something. Otherwise, for tool bars // and other objects a crash will be produced LOMSE_LOG_ERROR(str(boost::format("File %s not found. Error icon returned") % oFilename.GetFullPath().wx_str() )); wxBitmap oBitmap(error_16_xpm); return oBitmap.ConvertToImage(); } }
void test_sss_openat_cloexec_success(void **state) { int fd; int ret; int ret_flag; int expec_flag; int dir_fd; int flags = O_RDWR; char path[PATH_MAX] = {'\0'}; char *basec; const char *relativepath; dir_fd = dirfd((DIR *)*state); basec = strdup(get_filepath(path)); assert_non_null(basec); relativepath = basename(basec); fd = sss_openat_cloexec(dir_fd, relativepath, flags, &ret); free(basec); assert_true(fd != -1); ret_flag = fcntl(fd, F_GETFD, 0); expec_flag = FD_CLOEXEC; assert_true(ret_flag & expec_flag); close(fd); unlink(path); }
/* gnc_csv_load_file int gnc_csv_load_file (GncCsvParseData* parse_data, const char* filename,// C: 1 Local: 0:0:0 */ static void test_gnc_csv_load_file (Fixture *fixture, gconstpointer pData) { char *file1 = get_filepath ("notexist.csv", FALSE); char *file2 = get_filepath ("sample1.csv", TRUE); GError *the_error = NULL; int resultcode = 0; /* Test loading of a non-existing file */ resultcode = gnc_csv_load_file (fixture->parse_data, file1, &the_error); g_assert ((the_error->domain == GNC_CSV_IMP_ERROR) && (the_error->code == GNC_CSV_IMP_ERROR_OPEN)); /* Test loading of a valid csv file */ resultcode = gnc_csv_load_file (fixture->parse_data, file2, &the_error); g_assert (resultcode == 0); }
/** Update the include path * * @return include filepaths * * The include path are the directories, in which all includes will be * searched for. */ const std::vector<std::string>& KeyFile::get_include_dirs(bool _update) { if (!_update) return include_dirs; // lets take the long way ... std::set<std::string> new_include_dirs; // dir of file std::string directory = ""; auto my_filepath = get_filepath(); size_t pos = my_filepath.find_last_of("/\\"); if (pos != std::string::npos) directory = my_filepath.substr(0, pos) + "/"; if (!directory.empty()) new_include_dirs.insert(directory); // update for (auto& kw : include_path_keywords) { auto kw_inc_path = std::static_pointer_cast<IncludePathKeyword>(kw); bool is_relative_dir = kw_inc_path->is_relative(); // append for (const auto& dirpath : kw_inc_path->get_include_dirs()) { if (is_relative_dir) new_include_dirs.insert(join_path(directory, dirpath)); else new_include_dirs.insert(dirpath); } } // check also the includes for (auto& include_kw : include_keywords) for (auto& include_kf : include_kw->get_includes()) { auto paths = include_kf->get_include_dirs(true); new_include_dirs.insert(paths.begin(), paths.end()); } #ifdef QD_DEBUG std::cout << "Include dirs:\n"; for (const auto& entry : include_dirs) std::cout << entry << '\n'; #endif include_dirs = std::vector<std::string>(new_include_dirs.begin(), new_include_dirs.end()); return include_dirs; }
static void setup_one_file( Fixture *fixture, gconstpointer pData ) { const gchar *filename = (const gchar*) pData; char *filepath = get_filepath (filename, TRUE); GError *the_error = NULL; int resultcode = 0; fixture->parse_data = gnc_csv_new_parse_data (); resultcode = gnc_csv_load_file (fixture->parse_data, filepath, &the_error); g_assert (resultcode == 0); g_free(filepath); }
TEST_F (GncTokenizerTest, load_file_existing) { auto file = get_filepath ("sample1.csv"); auto expected_contents = std::string( "Date,Num,Description,Notes,Account,Deposit,Withdrawal,Balance\n" "05/01/15,45,Acme Inc.,,Miscellaneous,,\"1,100.00\",\n"); ASSERT_NO_THROW (fw_tok->load_file (file)) << "File " << file << " not found. Perhaps you should set the SRCDIR environment variable to point to its containing directory ?"; ASSERT_NO_THROW (csv_tok->load_file (file)) << "File " << file << " not found. Perhaps you should set the SRCDIR environment variable to point to its containing directory ?"; EXPECT_EQ(expected_contents, get_utf8_contents (fw_tok)); EXPECT_EQ(expected_contents, get_utf8_contents (csv_tok)); }
TEST_F (GncTokenizerTest, tokenize_from_csv_file) { auto file = get_filepath ("sample1.csv"); auto expected_contents = std::string( "Date,Num,Description,Notes,Account,Deposit,Withdrawal,Balance\n" "05/01/15,45,Acme Inc.,,Miscellaneous,,\"1,100.00\",\n"); csv_tok->load_file (file); csv_tok->tokenize(); auto tokens = csv_tok->get_tokens(); EXPECT_EQ(2ul, tokens.size()); EXPECT_EQ(8ul, tokens[0].size()); EXPECT_EQ(8ul, tokens[1].size()); EXPECT_EQ(std::string("Date"), tokens.at(0).at(0)); EXPECT_EQ(std::string("1,100.00"), tokens.at(1).at(6)); }
/* * Check if the SSL/TLS certificate exists in the certificates file. */ int check_cert(X509 *pcert, unsigned char *pmd, unsigned int *pmdlen) { int r; FILE *fd; char *certf; X509 *cert; unsigned char md[EVP_MAX_MD_SIZE]; unsigned int mdlen; r = 0; cert = NULL; certf = get_filepath("certificates"); if (!exists_file(certf)) { xfree(certf); return 0; } fd = fopen(certf, "r"); xfree(certf); if (fd == NULL) return -1; while ((cert = PEM_read_X509(fd, &cert, NULL, NULL)) != NULL) { if (X509_subject_name_cmp(cert, pcert) != 0 || X509_issuer_and_serial_cmp(cert, pcert) != 0) continue; if (!X509_digest(cert, EVP_md5(), md, &mdlen) || *pmdlen != mdlen) continue; if (memcmp(pmd, md, mdlen) != 0) { r = -1; break; } r = 1; break; } fclose(fd); X509_free(cert); return r; }
/* * Store the SSL/TLS certificate after asking the user to accept/reject it. */ int store_cert(X509 *cert) { FILE *fd; char c, buf[LINE_MAX]; char *certf; char *s; do { printf("(R)eject, accept (t)emporarily or " "accept (p)ermanently? "); if (fgets(buf, LINE_MAX, stdin) == NULL) return -1; c = tolower((int)(*buf)); } while (c != 'r' && c != 't' && c != 'p'); if (c == 'r') return -1; else if (c == 't') return 0; certf = get_filepath("certificates"); create_file(certf, S_IRUSR | S_IWUSR); fd = fopen(certf, "a"); xfree(certf); if (fd == NULL) return -1; s = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0); fprintf(fd, "Subject: %s\n", s); xfree(s); s = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0); fprintf(fd, "Issuer: %s\n", s); xfree(s); s = get_serial(cert); fprintf(fd, "Serial: %s\n", s); xfree(s); PEM_write_X509(fd, cert); fprintf(fd, "\n"); fclose(fd); return 0; }
void test_sss_open_cloexec_success(void **state) { int fd; int ret; int ret_flag; int expec_flag; int flags = O_RDWR; char path[PATH_MAX] = {'\0'}; fd = sss_open_cloexec(get_filepath(path), flags, &ret); assert_true(fd != -1); ret_flag = fcntl(fd, F_GETFD, 0); expec_flag = FD_CLOEXEC; assert_true(ret_flag & expec_flag); close(fd); unlink(path); }
int main(int argc, char *argv[]) { get_filepath(); fio.read_game(game_data); soundManager.init_audio_system(); if (graphLib.initGraphics() != true) { printf("ERROR intializing graphic\n"); return -1; } sceneShow show; show.show_scene(0); input.wait_keypress(); return 1; }
void test_qofsession_aqb_kvp( void ) { /* load the accounts from the users datafile */ /* but first, check to make sure we've got a session going. */ QofBackendError io_err; char *file1 = get_filepath("file-book.gnucash"); char *file2 = get_filepath("file-book-hbcislot.gnucash"); if (1) { // A file with no content at all, but a valid XML file QofSession *new_session = qof_session_new (); char *newfile = g_strdup_printf("file://%s", file1); qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE); io_err = qof_session_get_error (new_session); //printf("io_err1 = %d\n", io_err); g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist g_assert(io_err != ERR_BACKEND_LOCKED); g_assert(io_err == 0); qof_session_load (new_session, NULL); io_err = qof_session_get_error (new_session); //printf("io_err2 = %d\n", io_err); g_assert(io_err == 0); g_free(newfile); g_free(file1); gnc_hook_run(HOOK_BOOK_CLOSED, new_session); //qof_session_destroy(new_session); // tries to delete the LCK file but it wasn't created in the first place } if (1) { // A file with no content except for the book_template_list kvp // slot QofSession *new_session = qof_session_new (); char *newfile = g_strdup_printf("file://%s", file2); qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE); io_err = qof_session_get_error (new_session); //printf("io_err1 = %d\n", io_err); g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist g_assert(io_err != ERR_BACKEND_LOCKED); g_assert(io_err == 0); qof_session_load (new_session, NULL); io_err = qof_session_get_error (new_session); //printf("io_err2 = %d\n", io_err); g_assert(io_err == 0); { GList *templ_list; GncABTransTempl *templ; QofBook *book = qof_session_get_book(new_session); const char* ORIGINAL_NAME = "Some Name"; const char* CHANGED_NAME = "Some Changed Name"; templ_list = gnc_ab_trans_templ_list_new_from_book (book); g_assert_cmpint(g_list_length(templ_list), ==, 1); templ = templ_list->data; //Raise the edit level so that we can check that it's marked dirty. qof_instance_increase_editlevel(QOF_INSTANCE(book)); g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, ORIGINAL_NAME); // ok, name from file is here // Now we change the name into something else and verify it can be saved gnc_ab_trans_templ_set_name(templ, CHANGED_NAME); { g_assert(!qof_instance_get_dirty(QOF_INSTANCE(book))); // not yet dirty // Here we save the changed kvp gnc_ab_set_book_template_list(book, templ_list); g_assert(qof_instance_get_dirty(QOF_INSTANCE(book))); // yup, now dirty gnc_ab_trans_templ_list_free(templ_list); } { templ_list = gnc_ab_trans_templ_list_new_from_book (book); g_assert_cmpint(g_list_length(templ_list), ==, 1); templ = templ_list->data; g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, CHANGED_NAME); // ok, the change has been saved! gnc_ab_trans_templ_list_free(templ_list); } } { // Check the kvp slots of a aqbanking-enabled account QofBook *book = qof_session_get_book(new_session); Account* account = gnc_book_get_root_account(book); GDate retrieved_date, original_date; gchar buff[MAX_DATE_LENGTH]; g_assert(account); // The interesting test case here: Can we read the correct date // from the xml file? if (1) { Timespec retrieved_ts = gnc_ab_get_account_trans_retrieval(account); g_test_message("retrieved_ts=%s\n", gnc_print_date(retrieved_ts)); //printf("Time=%s\n", gnc_print_date(retrieved_ts)); retrieved_date = timespec_to_gdate(retrieved_ts); g_date_set_dmy(&original_date, 29, 8, 2014); g_assert_cmpint(g_date_compare(&retrieved_date, &original_date), ==, 0); } // A lower-level test here: Can we write and read again the // trans_retrieval date? This wouldn't need this particular // Account, just a general Account object. if (0) { Timespec original_ts = timespec_now(), retrieved_ts; // Check whether the "ab-trans-retrieval" property of Account // is written and read again correctly. gnc_ab_set_account_trans_retrieval(account, original_ts); retrieved_ts = gnc_ab_get_account_trans_retrieval(account); // printf("original_ts=%s = %d retrieved_ts=%s = %d\n", // gnc_print_date(original_ts), original_ts.tv_sec, // gnc_print_date(retrieved_ts), retrieved_ts.tv_sec); original_date = timespec_to_gdate(original_ts); retrieved_date = timespec_to_gdate(retrieved_ts); qof_print_gdate (buff, sizeof (buff), &original_date); //printf("original_date=%s\n", buff); qof_print_gdate (buff, sizeof (buff), &retrieved_date); //printf("retrieved_date=%s\n", buff); // Is the retrieved date identical to the one written g_assert_cmpint(g_date_compare(&retrieved_date, &original_date), ==, 0); }
static void create_filepath(char *filepath, size_t len, char *channel, char *suffix) { if(!get_filepath(filepath, len, striplower(channel), suffix)) { fputs("ii: path to irc directory too long\n", stderr); exit(EXIT_FAILURE); } }
void rtsp_string::deal_string(std::string& info) { deal_info.type = ERRORTYPE; const char* decode_p = info.c_str(); unsigned i,pos = 0; for (i = 0;i < info.size(); i++) { if (i < info.size() - 5 && decode_p[i] == ' ' && decode_p[i + 1] == 'r' && decode_p[i + 2] == 't' && decode_p[i + 3] == 's' && decode_p[i + 4] == 'p' && decode_p[i + 5] == ':') { pos = i;break; } } if(i > info.size() - 5) return ; for (i = 0;i < pos; i++) { switch(decode_p[i]) { case 'O': if (decode_p[i + 1] == 'P' && decode_p[i + 2] == 'T' && decode_p[i + 3] == 'I' && decode_p[i + 4] == 'O' && decode_p[i + 5] == 'N' && decode_p[i + 6] == 'S') { //OPTIONS deal_info.type = OPTIONS; } break; case 'D': if (decode_p[i + 1] == 'E' && decode_p[i + 2] == 'S' && decode_p[i + 3] == 'C' && decode_p[i + 4] == 'R' && decode_p[i + 5] == 'I' && decode_p[i + 6] == 'B' && decode_p[i + 7] == 'E') { //DESCRIBE deal_info.type = DESCRIBE; } break; case 'S': if (decode_p[i + 1] == 'E' && decode_p[i + 2] == 'T' && decode_p[i + 3] == 'U' && decode_p[i + 4] == 'P') { //SETUP deal_info.type = SETUP; } break; case 'T': if (decode_p[i + 2] == 'E' && decode_p[i + 3] == 'A' && decode_p[i + 4] == 'R' && decode_p[i + 5] == 'D' && decode_p[i + 6] == 'O' && decode_p[i + 7] == 'W' && decode_p[i + 8] == 'N') { deal_info.type = TEARDOWN; } break; case 'P': if (decode_p[i + 1] == 'L' && decode_p[i + 2] == 'A' && decode_p[i + 3] == 'Y') { deal_info.type = PLAY; } else if (decode_p[i + 1] == 'A' && decode_p[i + 1] == 'U' && decode_p[i + 2] == 'S' && decode_p[i + 3] == 'E') { deal_info.type = PAUSE; } break; default: continue; } } if (deal_info.type == ERRORTYPE) return; pos = get_addr(info, pos + 8); if (!pos) return; pos = get_filepath(info, pos); if (!pos) return; pos = get_cseq(info, pos); if (!pos) return; }
/* * IMAPFilter: an IMAP mail filtering utility. */ int main(int argc, char *argv[]) { int c; char *cafile = NULL, *capath = NULL; setlocale(LC_CTYPE, ""); opts.verbose = 0; opts.interactive = 0; opts.log = NULL; opts.config = NULL; opts.oneline = NULL; opts.debug = NULL; opts.truststore = NULL; if (exists_dir("/etc/ssl/certs")) opts.truststore = "/etc/ssl/certs"; else if (exists_file("/etc/ssl/cert.pem")) opts.truststore = "/etc/ssl/cert.pem"; env.home = NULL; env.pathmax = -1; while ((c = getopt(argc, argv, "Vc:d:e:il:t:v?")) != -1) { switch (c) { case 'V': version(); /* NOTREACHED */ break; case 'c': opts.config = optarg; break; case 'd': opts.debug = optarg; break; case 'e': opts.oneline = optarg; break; case 'i': opts.interactive = 1; break; case 'l': opts.log = optarg; break; case 't': opts.truststore = optarg; break; case 'v': opts.verbose = 1; break; case '?': default: usage(); /* NOTREACHED */ break; } } get_pathmax(); open_debug(); create_homedir(); catch_signals(); open_log(); if (opts.config == NULL) opts.config = get_filepath("config.lua"); buffer_init(&ibuf, INPUT_BUF); buffer_init(&obuf, OUTPUT_BUF); buffer_init(&nbuf, NAMESPACE_BUF); buffer_init(&cbuf, CONVERSION_BUF); regexp_compile(responses); SSL_library_init(); SSL_load_error_strings(); ssl3ctx = SSL_CTX_new(SSLv3_client_method()); ssl23ctx = SSL_CTX_new(SSLv23_client_method()); tls1ctx = SSL_CTX_new(TLSv1_client_method()); #if OPENSSL_VERSION_NUMBER >= 0x01000100fL tls11ctx = SSL_CTX_new(TLSv1_1_client_method()); tls12ctx = SSL_CTX_new(TLSv1_2_client_method()); #endif if (exists_dir(opts.truststore)) capath = opts.truststore; else if (exists_file(opts.truststore)) cafile = opts.truststore; SSL_CTX_load_verify_locations(ssl3ctx, cafile, capath); SSL_CTX_load_verify_locations(ssl23ctx, cafile, capath); SSL_CTX_load_verify_locations(tls1ctx, cafile, capath); #if OPENSSL_VERSION_NUMBER >= 0x01000100fL SSL_CTX_load_verify_locations(tls11ctx, cafile, capath); SSL_CTX_load_verify_locations(tls12ctx, cafile, capath); #endif start_lua(); #if LUA_VERSION_NUM < 502 { list *l; session *s; l = sessions; while (l != NULL) { s = l->data; l = l->next; request_logout(s); } } #endif stop_lua(); SSL_CTX_free(ssl3ctx); SSL_CTX_free(ssl23ctx); SSL_CTX_free(tls1ctx); #if OPENSSL_VERSION_NUMBER >= 0x01000100fL SSL_CTX_free(tls11ctx); SSL_CTX_free(tls12ctx); #endif ERR_free_strings(); regexp_free(responses); buffer_free(&ibuf); buffer_free(&obuf); buffer_free(&nbuf); buffer_free(&cbuf); xfree(env.home); close_log(); close_debug(); exit(0); }
/** Parse a keyfile * * @param _load_mesh : whether the mesh shall loaded * @return success : whether loading the data was successful * * The parameter can be used to prevent the loading of the mesh, * even though we use parse_mesh. We need this for includes. */ bool KeyFile::load(bool _load_mesh) { // read file auto my_filepath = resolve_include_filepath(get_filepath()); std::vector<char> char_buffer = read_binary_file(my_filepath); has_linebreak_at_eof = char_buffer.back() == '\n'; #ifdef QD_DEBUG std::cout << "done." << std::endl; #endif // init parallel worker if master file // if (parent_kf == this) // _wq.init_workers(1); // convert buffer into blocks size_t iLine = 0; std::string last_keyword; std::vector<std::string> line_buffer; std::vector<std::string> line_buffer_tmp; bool found_pgp_section = false; std::string line; auto string_buffer = std::string(char_buffer.begin(), char_buffer.end()); std::stringstream st(string_buffer); // for (; std::getline(st, line); ++iLine) { for (; std::getline(st, line); ++iLine) { if (line.find("-----BEGIN PGP") != std::string::npos) { found_pgp_section = true; #ifdef QD_DEBUG std::cout << "Found PGP Section\n"; #endif } // remove windows file ending ... I hate it ... if (line.size() != 0 && line.back() == '\r') line.pop_back(); // new keyword if (line[0] == '*' || found_pgp_section) { if (!line_buffer.empty() && !last_keyword.empty()) { // transfer possible header for following keyword (see function) transfer_comment_header(line_buffer, line_buffer_tmp); // get type auto kw_type = Keyword::determine_keyword_type(last_keyword); #ifdef QD_DEBUG std::cout << last_keyword << " -> "; switch (kw_type) { case (Keyword::KeywordType::NODE): std::cout << "NODE\n"; break; case (Keyword::KeywordType::ELEMENT): std::cout << "ELEMENT\n"; break; case (Keyword::KeywordType::PART): std::cout << "PART\n"; break; case (Keyword::KeywordType::GENERIC): std::cout << "GENERIC\n"; break; case (Keyword::KeywordType::INCLUDE): std::cout << "INCLUDE\n"; break; case (Keyword::KeywordType::INCLUDE_PATH): std::cout << "INCLUDE_PATH\n"; break; } #endif auto kw = create_keyword(line_buffer, kw_type, iLine - line_buffer.size() - line_buffer_tmp.size() + 1); if (kw) keywords[kw->get_keyword_name()].push_back(kw); // transfer cropped data line_buffer = line_buffer_tmp; } // we always trim keywords trim_right(line); last_keyword = line; } // IF:line[0] == '*' // Encrypted Sections // // Extracts encrypted section here and places it in a line in the // line buffer. An encrypted section is treated like a keyword. if (found_pgp_section) { found_pgp_section = false; // get stream position const auto stream_position = st.tellg(); const auto end_position = string_buffer.find("-----END PGP", stream_position); if (end_position == std::string::npos) throw( std::runtime_error("Could not find \"-----END PGP MESSAGE-----\" for " "corresponding \"-----BEGIN PGP MESSAGE-----\" ")); // set stream position behind encrypted section st.seekg(end_position); // extract encrypted stuff line += '\n'; line += std::string(char_buffer.begin() + stream_position, char_buffer.begin() + end_position); // print_string_as_hex(line); if (line.back() == '\n') line.pop_back(); if (line.back() == '\r') line.pop_back(); } // we stupidly add every line to the buffer line_buffer.push_back(line); } // for:line // allocate last block if (!line_buffer.empty() && !last_keyword.empty()) { auto kw = create_keyword(line_buffer, Keyword::determine_keyword_type(last_keyword), iLine - line_buffer.size() + 1); if (kw) keywords[kw->get_keyword_name()].push_back(kw); } // only load files above *END! const auto end_kw_position = get_end_keyword_position(); // includes if (load_includes) { // update include dirs get_include_dirs(true); // do the thing for (auto& include_kw : include_keywords) { if (include_kw->get_position() < end_kw_position) // Note: prevent loading the mesh here include_kw->load(false); } } // wait for threads to finish preloading // _wq.wait_for_completion(); // Wait for completion // while (work_queue.size() != 0) { // work_queue.front().wait(); // work_queue.pop(); // } // load mesh if requested if (parse_mesh && _load_mesh) { // load nodes load_nodes(); // load parts load_parts(); // load elements load_elements(); } return true; }
int main(int argc, char *argv[]) #endif { #ifdef PSP SetupCallbacks(); scePowerSetClockFrequency(333, 333, 166); #endif for (int i=0; i<FLAG_COUNT; i++) { GAME_FLAGS[i] = false; } UNUSED(argc); string argvString = ""; #ifndef WII argvString = string(argv[0]); #else if (!fatInitDefault()) { printf("fatInitDefault ERROR #1"); std::fflush(stdout); timer.delay(500); exit(-1); } #endif get_filepath(); // fallback in case getcwd returns null if (FILEPATH.size() == 0) { std::cout << "Could not read path, fallback to using argv" << std::endl; FILEPATH = argvString.substr(0, argvString.size()-EXEC_NAME.size()); } std::cout << "main - argvString: '" << argvString << "', FILEPATH: '" << FILEPATH << "'" << std::endl; std::fflush(stdout); #ifdef PLAYSTATION2 std::cout << "PS2.DEBUG #1" << std::endl; std::fflush(stdout); #ifndef PS2LINK SifIopReset(NULL, 0); // clean previous loading of irx by apps like ulaunchElf. Comment this line to get cout on ps2link #endif printf("DEBUG.PS2 #1.1\n"); /* SP193: Being creative (Do something while waiting for the slow IOP to be reset). =D */ int main_id = GetThreadId(); ChangeThreadPriority(main_id, 72); std::cout << "PS2.DEBUG #1.1" << std::endl; std::fflush(stdout); printf("DEBUG.PS2 #1.2\n"); #ifndef PS2LINK while(SifIopSync()) { std::cout << "PS2.SifIopSync()" << std::endl; } #endif /* Initialize and connect to all SIF services on the IOP. */ SifInitRpc(0); SifInitIopHeap(); SifLoadFileInit(); fioInit(); printf("DEBUG.PS2 #1.3\n"); /* Apply the SBV LMB patch to allow modules to be loaded from a buffer in EE RAM. */ sbv_patch_enable_lmb(); // --- DEBUG --- // //FILEPATH = "cdfs:/"; // --- DEBUG --- // std::cout << "PS2.DEBUG #2" << std::endl; std::fflush(stdout); if (FILEPATH.find("mass:") != std::string::npos) { printf("DEBUG.PS2 #1.4\n"); std::cout << "PS2.DEBUG Load USB" << std::endl; std::fflush(stdout); PS2_load_USB(); } if (FILEPATH.find("cdfs") != std::string::npos || FILEPATH.find("cdrom") != std::string::npos) { printf("DEBUG.PS2 #1.5\n"); std::cout << "PS2.DEBUG Load CDROM" << std::endl; std::fflush(stdout); FILEPATH = "cdfs:"; PS2_load_CDROM(); } printf("DEBUG.PS2 #2\n"); std::cout << "PS2.DEBUG #3" << std::endl; std::fflush(stdout); #endif // check command-line paramethers if (argc > 1) { for (int i=1; i<argc; i++) { std::string temp_argv(argv[i]); if (temp_argv == "--fullscreen") { } else if (temp_argv == "--quickload") { GAME_FLAGS[FLAG_QUICKLOAD] = true; } else if (temp_argv == "--invencible") { // player have infinite HP GAME_FLAGS[FLAG_INVENCIBLE] = true; } else if (temp_argv == "--allweapons") { // player have all weapons available even if GAME_FLAGS[FLAG_ALLWEAPONS] = true; } else if (temp_argv == "--infinitejump") { // player can jump again and again GAME_FLAGS[FLAG_INFINITE_JUMP] = true; } } } std::cout << "PS2.DEBUG #7" << std::endl; std::fflush(stdout); //fio.check_conversion(); fio.read_game(game_data); //GAME_FLAGS[FLAG_INFINITE_HP] = true; // DEBUG gameControl.get_drop_item_ids(); soundManager.init_audio_system(); // PS2 version have to load config AFTER SDL_Init due to SDK issues #ifdef LINUX SAVEPATH = std::string(getenv("HOME")) + "/.rockbot/"; mkdir(SAVEPATH.c_str(), 0777); //std::cout << "SAVEPATH: " << SAVEPATH << ", mkdir-res: " << res << ", errno: " << errno << std::endl; #elif WIN32 SAVEPATH = std::string(getenv("APPDATA")) + "/rockbot"; std::cout << "SAVEPATH: " << SAVEPATH << std::endl; _mkdir(SAVEPATH.c_str()); #else SAVEPATH = FILEPATH; #endif #ifndef PLAYSTATION2 fio.load_config(game_config); #endif // INIT GRAPHICS if (graphLib.initGraphics() != true) { printf("ERROR intializing graphic\n"); return -1; } // define SAVEPATH #ifdef PLAYSTATION2 PS2_load_MC(); SAVEPATH = "mc0:Rockbot/"; if (fioMkdir(SAVEPATH.c_str()) < 0) { std::cout << "main - warning: could not create '" << SAVEPATH << "' folder" << std::endl; std::fflush(stdout); /// @TODO - check if directory exists } else { std::cout << "Folder '" << SAVEPATH << "' created" << std::endl; std::fflush(stdout); } #endif have_save = fio.save_exists(); #ifndef DEBUG_OUTPUT // redirect output to null std::string cout_file = "/dev/null"; std::ofstream out(cout_file.c_str()); std::cout.rdbuf(out.rdbuf()); #else // --- REDIRECT STDOUT TO A FILE --- // #if defined(PSP) || defined(WII) || defined(ANDROID) || defined(DINGUX) || defined(PLAYSTATION2) //std::string cout_file = SAVEPATH + "/stdout.txt"; std::string cout_file = FILEPATH + "/stdout.txt"; std::streambuf *coutbuf = std::cout.rdbuf(); std::ofstream out(cout_file.c_str()); std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt! #endif #endif graphLib.preload(); #ifdef PLAYSTATION2 fio.load_config(game_config); PS2_create_save_icons(); #endif draw_lib.preload(); gameControl.currentStage = APEBOT; // INIT GAME if (GAME_FLAGS[FLAG_QUICKLOAD] == false) { if (gameControl.showIntro() == false) { std::cout << "ERROR SHOWING INTRO" << std::endl; return 0; } } else { gameControl.quick_load_game(); //ending end_obj; //end_obj.start(); //return 1; } input.clean(); input.p1_input[BTN_START] = 0; input.waitTime(200); input.clean(); bool run_game = true; while (run_game) { #if !defined(PSP) && !defined(DINGUX) timer.start_ticker(); #endif #ifdef PLAYSTATION2 RotateThreadReadyQueue(_MIXER_THREAD_PRIORITY); #endif gameControl.showGame(); #ifdef DEBUG_SHOW_FPS gameControl.fps_count(); #endif draw_lib.update_screen(); if (input.p1_input[BTN_QUIT] == 1) { //std::cout << "LEAVE #3" << std::endl; std::fflush(stdout); gameControl.leave_game(); } unsigned int now_ticks = timer.get_ticks(); if (now_ticks < (1000 / FRAMES_PER_SECOND)) { timer.delay((1000 / FRAMES_PER_SECOND) - now_ticks); } } /// @TODO: sdl quit sub-systems #ifdef PSP sceKernelExitGame(); return 0; #else SDL_Quit(); #endif return 1; }
/* * IMAPFilter: an IMAP mail filtering utility. */ int main(int argc, char *argv[]) { int c; setlocale(LC_CTYPE, ""); opts.verbose = 0; opts.interactive = 0; opts.log = NULL; opts.config = NULL; opts.oneline = NULL; opts.debug = NULL; env.home = NULL; env.pathmax = -1; while ((c = getopt(argc, argv, "Vc:d:e:il:v?")) != -1) { switch (c) { case 'V': version(); /* NOTREACHED */ break; case 'c': opts.config = optarg; break; case 'd': opts.debug = optarg; break; case 'e': opts.oneline = optarg; break; case 'i': opts.interactive = 1; break; case 'l': opts.log = optarg; break; case 'v': opts.verbose = 1; break; case '?': default: usage(); /* NOTREACHED */ break; } } get_pathmax(); open_debug(); create_homedir(); catch_signals(); open_log(); if (opts.config == NULL) opts.config = get_filepath("config.lua"); buffer_init(&ibuf, INPUT_BUF); buffer_init(&obuf, OUTPUT_BUF); buffer_init(&nbuf, NAMESPACE_BUF); buffer_init(&cbuf, CONVERSION_BUF); regexp_compile(responses); SSL_library_init(); SSL_load_error_strings(); start_lua(); #if LUA_VERSION_NUM < 502 { list *l; session *s; l = sessions; while (l != NULL) { s = l->data; l = l->next; request_logout(s); } } #endif stop_lua(); ERR_free_strings(); regexp_free(responses); buffer_free(&ibuf); buffer_free(&obuf); buffer_free(&nbuf); buffer_free(&cbuf); xfree(env.home); close_log(); close_debug(); exit(0); }