ErrnoError HttpClient::SendRequest(common::http::http_method method, const uri::Url& url, common::http::http_protocol protocol, const char* extra_header, bool is_keep_alive) { CHECK(protocol <= common::http::HP_1_1); if (!url.IsValid()) { return make_errno_error_inval(); } uri::Url::scheme sc = url.GetScheme(); if (!(sc == uri::Url::http || sc == uri::Url::https)) { return make_errno_error_inval(); } const std::string method_str = ConvertToString(method); time_t now = time(nullptr); char timebuf[100]; strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&now)); uri::Upath path = url.GetPath(); char header_data[1024] = {0}; int cur_pos = SNPrintf(header_data, sizeof(header_data), protocol == common::http::HP_2_0 ? "%s /%s " HTTP_2_0_PROTOCOL_NAME "\r\n" "Host: %s\r\n" "Date: %s\r\n" : "%s /%s " HTTP_1_1_PROTOCOL_NAME "\r\n" "Host: %s\r\n" "Date: %s\r\n", method_str, path.GetHpath(), url.GetHost(), timebuf); if (extra_header) { int exlen = SNPrintf(header_data + cur_pos, sizeof(header_data) - cur_pos, "%s\r\n", extra_header); cur_pos += exlen; } if (!is_keep_alive) { #define CONNECTION_CLOSE "Connection: close\r\n\r\n" const int last_len = sizeof(CONNECTION_CLOSE) - 1; memcpy(header_data + cur_pos, CONNECTION_CLOSE, last_len); cur_pos += last_len; } else { #define CONNECTION_KEEP_ALIVE "Keep-Alive: timeout=15, max=100\r\n\r\n" const int last_len = sizeof(CONNECTION_KEEP_ALIVE) - 1; memcpy(header_data + cur_pos, CONNECTION_KEEP_ALIVE, last_len); cur_pos += last_len; } DCHECK(strlen(header_data) == static_cast<size_t>(cur_pos)); size_t nwrite = 0; return Write(header_data, cur_pos, &nwrite); }
/** *************************************************************************************************** * \fn static int8_t cmd_serialnumber(Interp * interp, uint8_t argc, char *argv[]) *************************************************************************************************** */ static int8_t cmd_serialnumber(Interp * interp, uint8_t argc, char *argv[]) { if((argc == 3) && (strcmp(argv[1],"set") == 0)) { SNPrintf(gSerialNumber,array_size(gSerialNumber),argv[2]); DB_VarWrite(DBKEY_SERIALNUMBER,&gSerialNumber); } Interp_Printf_P(interp, "SerialNumber: \"%s\"\n",gSerialNumber); return 0; }
/** ****************************************************************************************** * Register shell command and process variable interface to Bert ****************************************************************************************** */ void Version_Init(void) { Interp_RegisterCmd(&versionCmd); Interp_RegisterCmd(&variantCmd); Interp_RegisterCmd(&serialnumberCmd); SNPrintf(gSerialNumber,array_size(gSerialNumber),"0000000000"); DB_VarInit(DBKEY_SERIALNUMBER,&gSerialNumber,"system.serialNr"); DB_VarInit(DBKEY_HWREV,&gHwRevision,"system.hwRevision"); DB_VarInit(DBKEY_VARIANT,&gVariant,"system.variant"); PVar_New(PVVersionSW_Get,NULL,NULL,0,"system.firmware"); PVar_New(PVVariantHW_Get,NULL,NULL,0,"system.variant"); PVar_New(PVHWRev_Get,NULL,NULL,0,"system.hwRevision"); }
static bool PVVariantHW_Get (void *cbData, uint32_t adId, char *bufP,uint16_t maxlen) { char *strVariant; if(gVariant == VARIANT_EML) { strVariant = "EML"; } else if(gVariant == VARIANT_MZ) { strVariant = "MZ"; } else { strVariant = "unknown"; } SNPrintf(bufP,maxlen,"\"%s\"",strVariant); //SNPrintf(bufP,maxlen,"%d",gVariant); return true; }
ErrnoError remove_directory(const std::string& path, bool is_recursive) { if (path.empty()) { return make_error_perror("remove_directory", EINVAL); } std::string pr_path = prepare_path(path); if (pr_path[pr_path.length() - 1] == get_separator<char>()) { pr_path[pr_path.length() - 1] = 0; } const char* pr_path_ptr = pr_path.c_str(); if (is_recursive) { DIR* dirp = opendir(pr_path_ptr); if (!dirp) { return ErrnoError(); } struct dirent* p; while ((p = readdir(dirp)) != nullptr) { /* Skip the names "." and ".." as we don't want to recurse on them. */ if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) { continue; } char pathBuffer[PATH_MAX] = {0}; SNPrintf(pathBuffer, sizeof(pathBuffer), "%s/%s", path, p->d_name); struct stat statbuf; if (!::stat(pathBuffer, &statbuf)) { if (S_ISDIR(statbuf.st_mode)) { ErrnoError err = remove_directory(pathBuffer, is_recursive); if (err) { closedir(dirp); return err; } } else { ErrnoError err = remove_file(pathBuffer); if (err) { closedir(dirp); return err; } } } } closedir(dirp); } return do_rmdir_directory(pr_path_ptr); }
ErrnoError HttpClient::SendError(common::http::http_protocol protocol, common::http::http_status status, const char* extra_header, const char* text, bool is_keep_alive, const HttpServerInfo& info) { CHECK(protocol <= common::http::HP_1_1); const std::string title = ConvertToString(status); char err_data[1024] = {0}; off_t err_len = SNPrintf(err_data, sizeof(err_data), HTML_PATTERN_ISISSSS7, status, title, status, title, text, info.server_url, info.server_name); ErrnoError err = SendHeaders(protocol, status, extra_header, "text/html", &err_len, nullptr, is_keep_alive, info); if (err) { DEBUG_MSG_ERROR(err, logging::LOG_LEVEL_ERR); } size_t nwrite = 0; err = Write(err_data, err_len, &nwrite); if (err) { DEBUG_MSG_ERROR(err, logging::LOG_LEVEL_ERR); } return err; }
int SetActiveGroup(struct ClassData * data, STRPTR YahooGroup ) { UBYTE buf[2048]; /* crea los nombres de fichero done luego se guardaran los mensages * y el index ( group.idx y group.db ) */ DBG_STRING(data->MailsFolder); DBG_STRING(YahooGroup); // this must be called with the semaphore locked ! if(data->subtask.task == NULL) { /* Si la subtask esta activa debe tener el control de * data->ActiveGroup, si no tiene que ser liberado */ ExpungeIndex(data, &(data->ActiveGroup)); } if(!(data->ActiveGroup = malloc(sizeof(struct GroupFolder)))) goto done; if(!(data->ActiveGroup->YahooGroup = strdup( YahooGroup ))) goto done; *buf = 0; data->LastError = ERR_OVERFLOW; if(AddPart( buf, data->MailsFolder, sizeof(buf)-1)) { if(AddPart( buf, data->ActiveGroup->YahooGroup, sizeof(buf)-1)) { STRPTR gfolder = NULL, db = NULL, idx = NULL; long buflen = strlen(buf) + MAX(strlen(IDX_EXT),strlen(DB_EXT)) + 2; data->LastError = ERR_NOMEM; if((gfolder = strdup( buf ))) { if((db = malloc( buflen ))) { if((idx = malloc( buflen ))) { free( data->ActiveGroup->index ); free( data->ActiveGroup->unixf ); free( data->ActiveGroup->folder); data->ActiveGroup->index = idx; data->ActiveGroup->unixf = db; data->ActiveGroup->folder = gfolder; SNPrintf(data->ActiveGroup->unixf, buflen-1, "%s%s", gfolder, DB_EXT ); SNPrintf(data->ActiveGroup->index, buflen-1, "%s%s", gfolder, IDX_EXT ); data->LastError = ERR_NOERROR; ClearReaderMail( data ); DBG_STRING(data->ActiveGroup->index); DBG_STRING(data->ActiveGroup->unixf); DBG_STRING(data->ActiveGroup->folder); } } } if( data->LastError != ERR_NOERROR ) { free( gfolder ); free( db ); free( idx ); } } } done: if( data->LastError != ERR_NOERROR ) { if( data->ActiveGroup ) { free( data->ActiveGroup->YahooGroup ); free( data->ActiveGroup ); data->ActiveGroup = NULL; } } return(data->LastError); }
static BOOL ami_print_readunit(CONST_STRPTR filename, char name[], uint32 namesize, int unitnum) { /* This is a modified version of a function from the OS4 SDK. * The README says "You can use it in your application", * no licence is specified. (c) 1999 Amiga Inc */ BPTR fp; BOOL ok; struct IFFHandle *iff; struct ContextNode *cn; struct PrefHeader phead; struct PrinterDeviceUnitPrefs pdev; SNPrintf(name,namesize,"Unit %ld",unitnum); fp = Open(filename, MODE_OLDFILE); if (fp) { iff = AllocIFF(); if (iff) { iff->iff_Stream = fp; InitIFFasDOS(iff); if (!OpenIFF(iff, IFFF_READ)) { if (!ParseIFF(iff, IFFPARSE_STEP)) { cn = CurrentChunk(iff); if (cn->cn_ID == ID_FORM && cn->cn_Type == ID_PREF) { if (!StopChunks(iff, IFFPrefChunks, IFFPrefChunkCnt)) { ok = TRUE; while (ok) { if (ParseIFF(iff, IFFPARSE_SCAN)) break; cn = CurrentChunk(iff); if (cn->cn_Type == ID_PREF) { switch (cn->cn_ID) { case ID_PRHD: if (ReadChunkBytes(iff, &phead, sizeof(struct PrefHeader)) != sizeof(struct PrefHeader)) { ok = FALSE; break; } if (phead.ph_Version != 0) { ok = FALSE; break; } break; case ID_PDEV: if (ReadChunkBytes(iff, &pdev, sizeof(pdev)) == sizeof(pdev)) { if (pdev.pd_UnitName[0]) strcpy(name,pdev.pd_UnitName); } break; default: break; } } } } } } CloseIFF(iff); } FreeIFF(iff); } Close(fp); } else return FALSE; return TRUE; }
int main(int argc, const boo::SystemChar** argv) #endif { logvisor::RegisterConsoleLogger(); std::vector<boo::SystemString> m_args; m_args.reserve(argc); double rate = NativeSampleRate; int chCount = 2; double volume = 1.0; for (int i = 1; i < argc; ++i) { #if _WIN32 if (!wcsncmp(argv[i], L"-r", 2)) { if (argv[i][2]) rate = wcstod(&argv[i][2], nullptr); else if (argc > (i + 1)) { rate = wcstod(argv[i + 1], nullptr); ++i; } } else if (!wcsncmp(argv[i], L"-c", 2)) { if (argv[i][2]) chCount = wcstoul(&argv[i][2], nullptr, 0); else if (argc > (i + 1)) { chCount = wcstoul(argv[i + 1], nullptr, 0); ++i; } } else if (!wcsncmp(argv[i], L"-v", 2)) { if (argv[i][2]) volume = wcstod(&argv[i][2], nullptr); else if (argc > (i + 1)) { volume = wcstod(argv[i + 1], nullptr); ++i; } } else m_args.push_back(argv[i]); #else if (!strncmp(argv[i], "-r", 2)) { if (argv[i][2]) rate = strtod(&argv[i][2], nullptr); else if (argc > (i + 1)) { rate = strtod(argv[i + 1], nullptr); ++i; } } else if (!strncmp(argv[i], "-c", 2)) { if (argv[i][2]) chCount = strtoul(&argv[i][2], nullptr, 0); else if (argc > (i + 1)) { chCount = strtoul(argv[i + 1], nullptr, 0); ++i; } } else if (!strncmp(argv[i], "-v", 2)) { if (argv[i][2]) volume = strtod(&argv[i][2], nullptr); else if (argc > (i + 1)) { volume = strtod(argv[i + 1], nullptr); ++i; } } else m_args.push_back(argv[i]); #endif } /* Load data */ if (m_args.size() < 1) { Log.report(logvisor::Error, "Usage: amuserender <group-file> [<songs-file>] [-r <sample-rate>] [-c <channel-count>] [-v <volume " "0.0-1.0>]"); return 1; } amuse::ContainerRegistry::Type cType = amuse::ContainerRegistry::DetectContainerType(m_args[0].c_str()); if (cType == amuse::ContainerRegistry::Type::Invalid) { Log.report(logvisor::Error, "invalid/no data at path argument"); return 1; } Log.report(logvisor::Info, _SYS_STR("Found '%s' Audio Group data"), amuse::ContainerRegistry::TypeToName(cType)); std::vector<std::pair<amuse::SystemString, amuse::IntrusiveAudioGroupData>> data = amuse::ContainerRegistry::LoadContainer(m_args[0].c_str()); if (data.empty()) { Log.report(logvisor::Error, "invalid/no data at path argument"); return 1; } int m_groupId = -1; int m_setupId = -1; const amuse::SystemString* m_groupName = nullptr; const amuse::SystemString* m_songName = nullptr; amuse::ContainerRegistry::SongData* m_arrData = nullptr; bool m_sfxGroup = false; std::list<amuse::AudioGroupProject> m_projs; std::map<int, std::pair<std::pair<amuse::SystemString, amuse::IntrusiveAudioGroupData>*, amuse::ObjToken<amuse::SongGroupIndex>>> allSongGroups; std::map<int, std::pair<std::pair<amuse::SystemString, amuse::IntrusiveAudioGroupData>*, amuse::ObjToken<amuse::SFXGroupIndex>>> allSFXGroups; size_t totalGroups = 0; for (auto& grp : data) { /* Load project to assemble group list */ m_projs.push_back(amuse::AudioGroupProject::CreateAudioGroupProject(grp.second)); amuse::AudioGroupProject& proj = m_projs.back(); totalGroups += proj.sfxGroups().size() + proj.songGroups().size(); for (auto it = proj.songGroups().begin(); it != proj.songGroups().end(); ++it) allSongGroups[it->first] = std::make_pair(&grp, it->second); for (auto it = proj.sfxGroups().begin(); it != proj.sfxGroups().end(); ++it) allSFXGroups[it->first] = std::make_pair(&grp, it->second); } /* Attempt loading song */ std::vector<std::pair<amuse::SystemString, amuse::ContainerRegistry::SongData>> songs; if (m_args.size() > 1) songs = amuse::ContainerRegistry::LoadSongs(m_args[1].c_str()); else songs = amuse::ContainerRegistry::LoadSongs(m_args[0].c_str()); if (songs.size()) { bool play = true; if (m_args.size() <= 1) { bool prompt = true; while (true) { if (prompt) { printf("Render Song? (Y/N): "); prompt = false; } char userSel; if (scanf("%c", &userSel) <= 0 || userSel == '\n') continue; userSel = tolower(userSel); if (userSel == 'n') play = false; else if (userSel != 'y') { prompt = true; continue; } break; } } if (play) { /* Get song selection from user */ if (songs.size() > 1) { /* Ask user to specify which song */ printf("Multiple Songs discovered:\n"); int idx = 0; for (const auto& pair : songs) { const amuse::ContainerRegistry::SongData& sngData = pair.second; int16_t grpId = sngData.m_groupId; int16_t setupId = sngData.m_setupId; if (sngData.m_groupId == -1 && sngData.m_setupId != -1) { for (const auto& pair : allSongGroups) { for (const auto& setup : pair.second.second->m_midiSetups) { if (setup.first == sngData.m_setupId) { grpId = pair.first; break; } } if (grpId != -1) break; } } amuse::Printf(_SYS_STR(" %d %s (Group %d, Setup %d)\n"), idx++, pair.first.c_str(), grpId, setupId); } int userSel = 0; printf("Enter Song Number: "); if (scanf("%d", &userSel) <= 0) { Log.report(logvisor::Error, "unable to parse prompt"); return 1; } if (userSel < songs.size()) { m_arrData = &songs[userSel].second; m_groupId = m_arrData->m_groupId; m_setupId = m_arrData->m_setupId; m_songName = &songs[userSel].first; } else { Log.report(logvisor::Error, "unable to find Song %d", userSel); return 1; } } else if (songs.size() == 1) { m_arrData = &songs[0].second; m_groupId = m_arrData->m_groupId; m_setupId = m_arrData->m_setupId; m_songName = &songs[0].first; } } } /* Get group selection via setup search */ if (m_groupId == -1 && m_setupId != -1) { for (const auto& pair : allSongGroups) { for (const auto& setup : pair.second.second->m_midiSetups) { if (setup.first == m_setupId) { m_groupId = pair.first; m_groupName = &pair.second.first->first; break; } } if (m_groupId != -1) break; } } /* Get group selection via user */ if (m_groupId != -1) { auto songSearch = allSongGroups.find(m_groupId); auto sfxSearch = allSFXGroups.find(m_groupId); if (songSearch != allSongGroups.end()) { m_sfxGroup = false; m_groupName = &songSearch->second.first->first; } else if (sfxSearch != allSFXGroups.end()) { m_sfxGroup = true; m_groupName = &sfxSearch->second.first->first; } else { Log.report(logvisor::Error, "unable to find Group %d", m_groupId); return 1; } } else if (totalGroups > 1) { /* Ask user to specify which group in project */ printf("Multiple Audio Groups discovered:\n"); for (const auto& pair : allSFXGroups) { amuse::Printf(_SYS_STR(" %d %s (SFXGroup) %" PRISize " sfx-entries\n"), pair.first, pair.second.first->first.c_str(), pair.second.second->m_sfxEntries.size()); } for (const auto& pair : allSongGroups) { amuse::Printf(_SYS_STR(" %d %s (SongGroup) %" PRISize " normal-pages, %" PRISize " drum-pages, %" PRISize " MIDI-setups\n"), pair.first, pair.second.first->first.c_str(), pair.second.second->m_normPages.size(), pair.second.second->m_drumPages.size(), pair.second.second->m_midiSetups.size()); } int userSel = 0; printf("Enter Group Number: "); if (scanf("%d", &userSel) <= 0) { Log.report(logvisor::Error, "unable to parse prompt"); return 1; } auto songSearch = allSongGroups.find(userSel); auto sfxSearch = allSFXGroups.find(userSel); if (songSearch != allSongGroups.end()) { m_groupId = userSel; m_groupName = &songSearch->second.first->first; m_sfxGroup = false; } else if (sfxSearch != allSFXGroups.end()) { m_groupId = userSel; m_groupName = &sfxSearch->second.first->first; m_sfxGroup = true; } else { Log.report(logvisor::Error, "unable to find Group %d", userSel); return 1; } } else if (totalGroups == 1) { /* Load one and only group */ if (allSongGroups.size()) { const auto& pair = *allSongGroups.cbegin(); m_groupId = pair.first; m_groupName = &pair.second.first->first; m_sfxGroup = false; } else { const auto& pair = *allSFXGroups.cbegin(); m_groupId = pair.first; m_groupName = &pair.second.first->first; m_sfxGroup = true; } } else { Log.report(logvisor::Error, "empty project"); return 1; } /* Make final group selection */ amuse::IntrusiveAudioGroupData* selData = nullptr; amuse::ObjToken<amuse::SongGroupIndex> songIndex; amuse::ObjToken<amuse::SFXGroupIndex> sfxIndex; auto songSearch = allSongGroups.find(m_groupId); if (songSearch != allSongGroups.end()) { selData = &songSearch->second.first->second; songIndex = songSearch->second.second; std::set<int> sortSetups; for (auto& pair : songIndex->m_midiSetups) sortSetups.insert(pair.first); if (m_setupId == -1) { /* Ask user to specify which group in project */ printf("Multiple MIDI Setups:\n"); for (int setup : sortSetups) printf(" %d\n", setup); int userSel = 0; printf("Enter Setup Number: "); if (scanf("%d", &userSel) <= 0) { Log.report(logvisor::Error, "unable to parse prompt"); return 1; } m_setupId = userSel; } if (sortSetups.find(m_setupId) == sortSetups.cend()) { Log.report(logvisor::Error, "unable to find setup %d", m_setupId); return 1; } } else { auto sfxSearch = allSFXGroups.find(m_groupId); if (sfxSearch != allSFXGroups.end()) { selData = &sfxSearch->second.first->second; sfxIndex = sfxSearch->second.second; } } if (!selData) { Log.report(logvisor::Error, "unable to select audio group data"); return 1; } if (m_sfxGroup) { Log.report(logvisor::Error, "amuserender is currently only able to render SongGroups"); return 1; } /* WAV out path */ amuse::SystemChar pathOut[1024]; SNPrintf(pathOut, 1024, _SYS_STR("%s-%s.wav"), m_groupName->c_str(), m_songName->c_str()); Log.report(logvisor::Info, _SYS_STR("Writing to %s"), pathOut); /* Build voice engine */ std::unique_ptr<boo::IAudioVoiceEngine> voxEngine = boo::NewWAVAudioVoiceEngine(pathOut, rate, chCount); amuse::BooBackendVoiceAllocator booBackend(*voxEngine); amuse::Engine engine(booBackend, amuse::AmplitudeMode::PerSample); engine.setVolume(float(amuse::clamp(0.0, volume, 1.0))); /* Load group into engine */ const amuse::AudioGroup* group = engine.addAudioGroup(*selData); if (!group) { Log.report(logvisor::Error, "unable to add audio group"); return 1; } /* Enter playback loop */ amuse::ObjToken<amuse::Sequencer> seq = engine.seqPlay(m_groupId, m_setupId, m_arrData->m_data.get(), false); size_t wroteFrames = 0; signal(SIGINT, SIGINTHandler); do { voxEngine->pumpAndMixVoices(); wroteFrames += voxEngine->get5MsFrames(); printf("\rFrame %" PRISize, wroteFrames); fflush(stdout); } while (!g_BreakLoop && (seq->state() == amuse::SequencerState::Playing || seq->getVoiceCount() != 0)); printf("\n"); return 0; }
ErrnoError HttpClient::SendHeaders(common::http::http_protocol protocol, common::http::http_status status, const char* extra_header, const char* mime_type, off_t* length, time_t* mod, bool is_keep_alive, const HttpServerInfo& info) { CHECK(protocol <= common::http::HP_1_1); const std::string title = ConvertToString(status); time_t now = time(nullptr); char timebuf[100]; strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&now)); char header_data[1024] = {0}; int cur_pos = SNPrintf(header_data, sizeof(header_data), protocol == common::http::HP_2_0 ? HTTP_2_0_PROTOCOL_NAME " %d %s\r\n" "Server: %s\r\n" "Date: %s\r\n" : HTTP_1_1_PROTOCOL_NAME " %d %s\r\n" "Server: %s\r\n" "Date: %s\r\n", status, title, info.server_name, timebuf); if (extra_header) { int exlen = SNPrintf(header_data + cur_pos, sizeof(header_data) - cur_pos, "%s\r\n", extra_header); cur_pos += exlen; } if (mime_type) { int mim_t = SNPrintf(header_data + cur_pos, sizeof(header_data) - cur_pos, "Content-Type: %s\r\n", mime_type); cur_pos += mim_t; } if (length) { int len = SNPrintf(header_data + cur_pos, sizeof(header_data) - cur_pos, "Content-Length: %" PRId32 "\r\n", *length); cur_pos += len; } if (mod) { strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(mod)); int mlen = SNPrintf(header_data + cur_pos, sizeof(header_data) - cur_pos, "Last-Modified: %s\r\n", timebuf); cur_pos += mlen; } if (!is_keep_alive) { #define CONNECTION_CLOSE "Connection: close\r\n\r\n" const int last_len = sizeof(CONNECTION_CLOSE) - 1; memcpy(header_data + cur_pos, CONNECTION_CLOSE, last_len); cur_pos += last_len; } else { #define CONNECTION_KEEP_ALIVE "Keep-Alive: timeout=15, max=100\r\n\r\n" const int last_len = sizeof(CONNECTION_KEEP_ALIVE) - 1; memcpy(header_data + cur_pos, CONNECTION_KEEP_ALIVE, last_len); cur_pos += last_len; } DCHECK(strlen(header_data) == static_cast<size_t>(cur_pos)); size_t nwrite = 0; return Write(header_data, cur_pos, &nwrite); }
int _7zArchive( STRPTR filename, int mode ) { CFileInStream archiveStream; CArchiveDatabaseEx db; SZ_RESULT res; ISzAlloc allocImp; ISzAlloc allocTempImp; archiveStream.File = Open( filename, MODE_OLDFILE); if (!archiveStream.File) { PrintError("Unable to open archive!"); goto done; } archiveStream.InStream.zRead = SzFileReadImp; archiveStream.InStream.zSeek = SzFileSeekImp; allocImp.Alloc = SzAlloc; allocImp.Free = SzFree; allocTempImp.Alloc = SzAllocTemp; allocTempImp.Free = SzFreeTemp; InitCrcTable(); SzArDbExInit(&db); res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp); if (res == SZ_OK) { if( G->CliUsage ) { ShowProgramInfo ( ); Printf("\n%s archive %s\n", (long)((mode == 1) ? "Listing":((mode == 2) ? "Testing":"Extracting")), (long) FilePart( filename )); } if ( mode == 1 ) // LIST mode { UInt32 i; if( G->CliUsage ) { Printf("\n%7s%9s%14s%7s%8s\n",(long)"Date",(long)"Time",(long)"Size",(long)"CRC",(long)"Name"); for( i = 0; i < 60 ; i++ ) PutStr("-"); PutStr("\n"); } for (i = 0; i < db.Database.NumFiles; i++) { CFileItem *f = db.Database.Files + i; if( G->CliUsage ) { UBYTE date[20]; ItemTime( f, date, sizeof(date), FALSE ); Printf("%s%11ld %08lx %s\n", (long)date, (long)f->Size, f->IsFileCRCDefined ? f->FileCRC:0, (long)f->Name); } else NListInsert((APTR) f ); } } else { UInt32 i; // if you need cache, use these 3 variables. // if you use external function, you can make these variable as static. UInt32 blockIndex = 0xFFFFFFFF; // it can have any value before first call (if outBuffer = 0) Byte *outBuffer = 0; // it must be 0 before first call for each new archive. size_t outBufferSize = 0; // it can have any value before first call (if outBuffer = 0) if( G->CliUsage ) PutStr("\n"); for (i = 0; i < db.Database.NumFiles; i++) { size_t offset; size_t outSizeProcessed; CFileItem *f = db.Database.Files + i; if( G->CliUsage ) { #if 0 if (f->IsDirectory) PutStr("Directory"); else Printf("%12s",(long)((mode == 2) ? "Testing":"Extracting")); Printf(" %s", (long)f->Name); #else if (!f->IsDirectory) Printf("%12s %s",(long)((mode == 2) ? "Testing":"Extracting"), (long)f->Name); #endif } else { STATIC UBYTE msg[256]; SNPrintf( msg, sizeof(msg)-1, "%12s %s", (mode == 2) ? "Testing":"Extracting", f->Name ); GaugeUpdate( msg, i*100/db.Database.NumFiles ); } if (f->IsDirectory) { // if( G->CliUsage ) // PutStr("\n"); continue; } res = SzExtract(&archiveStream.InStream, &db, i, &blockIndex, &outBuffer, &outBufferSize, &offset, &outSizeProcessed, &allocImp, &allocTempImp); if (res != SZ_OK) break; if ( mode == 3 ) // EXTRACT mode { BPTR outputHandle; UInt32 processedSize; MakeDir( f->Name ); // creates ALL Directories pointing to this file outputHandle = Open( f->Name, MODE_NEWFILE ); if (outputHandle == 0) { PrintError("Unable to open output file!"); res = SZE_FAIL; break; } processedSize = Write(outputHandle, outBuffer + offset, outSizeProcessed); if (processedSize != outSizeProcessed) { PrintError("Cannot write to output file!"); res = SZE_FAIL; break; } Close(outputHandle); SetFileTimeToFile( f ); } if( G->CliUsage ) PutStr("\n"); } allocImp.Free(outBuffer); } } SzArDbExFree(&db, allocImp.Free); Close(archiveStream.File); if (res == SZ_OK) { if( G->CliUsage ) Printf("\n%s\n", (long)"Everything is Ok"); else GaugeUpdate("Everything is Ok", 0 ); return 0; } #if 0 if (res == SZE_OUTOFMEMORY) PrintError("can not allocate memory"); else if( G->CliUsage ) Printf("\nERROR #%ld\n", res); #else PrintError(SzErrorString( res )); #endif if( ! G->CliUsage ) GaugeUpdate("error %ld procesing archive", res ); done: return 1; }
static bool PVHWRev_Get (void *cbData, uint32_t adId, char *bufP,uint16_t maxlen) { SNPrintf(bufP,maxlen,"%u",gHwRevision); return true; }
static bool PVVersionSW_Get (void *cbData, uint32_t adId, char *bufP,uint16_t maxlen) { SNPrintf(bufP,maxlen,"\"%s%02x%02x%02x\"",SWNAME,YEAR2,MONTH,DAY); return true; }
const char * System_GetVersion(void) { SNPrintf(gVersion,sizeof(gVersion) - 1,"%s%02x%02x%02x",SWNAME,YEAR2,MONTH,DAY); return gVersion; }