Browse Source

Add plPrintf - a cstdio-directed version of plFormat

Michael Hansen 11 years ago
parent
commit
bf5623224c
  1. 4
      Sources/Plasma/Apps/plFileEncrypt/main.cpp
  2. 2
      Sources/Plasma/Apps/plFileSecure/main.cpp
  3. 2
      Sources/Plasma/Apps/plPageOptimizer/main.cpp
  4. 42
      Sources/Plasma/Apps/plPythonPack/main.cpp
  5. 13
      Sources/Plasma/CoreLib/plFormat.h

4
Sources/Plasma/Apps/plFileEncrypt/main.cpp

@ -108,12 +108,12 @@ void EncryptFiles(const plFileName& dir, const char* ext, bool encrypt)
{ {
if (encrypt) if (encrypt)
{ {
printf("encrypting: %s\n", iter->GetFileName().c_str()); plPrintf("encrypting: {}\n", iter->GetFileName());
plEncryptedStream::FileEncrypt(*iter); plEncryptedStream::FileEncrypt(*iter);
} }
else else
{ {
printf("decrypting: %s\n", iter->GetFileName().c_str()); plPrintf("decrypting: {}\n", iter->GetFileName());
plEncryptedStream::FileDecrypt(*iter); plEncryptedStream::FileDecrypt(*iter);
} }
} }

2
Sources/Plasma/Apps/plFileSecure/main.cpp

@ -110,7 +110,7 @@ void SecureFiles(const plFileName& dir, const plString& ext, uint32_t* key)
std::vector<plFileName> files = plFileSystem::ListDir(dir, ext.c_str()); std::vector<plFileName> files = plFileSystem::ListDir(dir, ext.c_str());
for (auto iter = files.begin(); iter != files.end(); ++iter) for (auto iter = files.begin(); iter != files.end(); ++iter)
{ {
printf("securing: %s\n", iter->GetFileName().c_str()); plPrintf("securing: {}\n", iter->GetFileName());
plSecureStream::FileEncrypt(*iter, key); plSecureStream::FileEncrypt(*iter, key);
} }
} }

2
Sources/Plasma/Apps/plPageOptimizer/main.cpp

@ -53,7 +53,7 @@ int main(int argc, char* argv[])
} }
plFileName filename = argv[1]; plFileName filename = argv[1];
printf("Optimizing %s...", filename.GetFileName().c_str()); plPrintf("Optimizing {}...", filename);
#ifndef _DEBUG #ifndef _DEBUG
try { try {

42
Sources/Plasma/Apps/plPythonPack/main.cpp

@ -84,11 +84,11 @@ void WritePythonFile(const plFileName &fileName, const plFileName &path, hsStrea
if (!pyStream.Open(filePath) || !glueStream.Open(glueFile)) if (!pyStream.Open(filePath) || !glueStream.Open(glueFile))
{ {
printf("Unable to open path %s, ", filePath.AsString().c_str()); plPrintf("Unable to open path {}, ", filePath);
return; return;
} }
printf("==Packing %s, ", fileName.AsString().c_str()); plPrintf("==Packing {}, ", fileName);
pyStream.FastFwd(); pyStream.FastFwd();
uint32_t pyFileSize = pyStream.GetPosition(); uint32_t pyFileSize = pyStream.GetPosition();
@ -168,20 +168,20 @@ void WritePythonFile(const plFileName &fileName, const plFileName &path, hsStrea
} }
pythonCode = PythonInterface::CompileString(code, fileName); pythonCode = PythonInterface::CompileString(code, fileName);
hsAssert(pythonCode,"Not sure why this didn't compile the second time???"); hsAssert(pythonCode,"Not sure why this didn't compile the second time???");
printf("an import file "); fputs("an import file ", stdout);
} }
else else
printf("a PythonFile modifier(tm) "); fputs("a PythonFile modifier(tm) ", stdout);
} }
else else
{ {
printf("......blast! Error during run-code!\n"); fputs("......blast! Error during run-code!\n", stdout);
char* errmsg; char* errmsg;
int chars_read = PythonInterface::getOutputAndReset(&errmsg); int chars_read = PythonInterface::getOutputAndReset(&errmsg);
if (chars_read > 0) if (chars_read > 0)
{ {
printf("%s\n", errmsg); plPrintf("{}\n", errmsg);
} }
} }
} }
@ -193,20 +193,20 @@ void WritePythonFile(const plFileName &fileName, const plFileName &path, hsStrea
char* pycode; char* pycode;
PythonInterface::DumpObject(pythonCode,&pycode,&size); PythonInterface::DumpObject(pythonCode,&pycode,&size);
printf("\n"); fputc('\n', stdout);
// print any message after each module // print any message after each module
char* errmsg; char* errmsg;
int chars_read = PythonInterface::getOutputAndReset(&errmsg); int chars_read = PythonInterface::getOutputAndReset(&errmsg);
if (chars_read > 0) if (chars_read > 0)
{ {
printf("%s\n", errmsg); plPrintf("{}\n", errmsg);
} }
s->WriteLE32(size); s->WriteLE32(size);
s->Write(size, pycode); s->Write(size, pycode);
} }
else else
{ {
printf("......blast! Compile error!\n"); fputs("......blast! Compile error!\n", stdout);
s->WriteLE32(0); s->WriteLE32(0);
PyErr_Print(); PyErr_Print();
@ -216,7 +216,7 @@ void WritePythonFile(const plFileName &fileName, const plFileName &path, hsStrea
int chars_read = PythonInterface::getOutputAndReset(&errmsg); int chars_read = PythonInterface::getOutputAndReset(&errmsg);
if (chars_read > 0) if (chars_read > 0)
{ {
printf("%s\n", errmsg); plPrintf("{}\n", errmsg);
} }
} }
@ -353,16 +353,16 @@ void FindPackages(std::vector<plFileName>& fileNames, std::vector<plFileName>& p
void PackDirectory(const plFileName& dir, const plFileName& rootPath, const plFileName& pakName, std::vector<plFileName>& extraDirs, bool packSysAndPlasma = false) void PackDirectory(const plFileName& dir, const plFileName& rootPath, const plFileName& pakName, std::vector<plFileName>& extraDirs, bool packSysAndPlasma = false)
{ {
printf("\nCreating %s using the contents of %s\n", pakName.AsString().c_str(), dir.AsString().c_str()); plPrintf("\nCreating {} using the contents of {}\n", pakName, dir);
printf("Changing working directory to %s\n", rootPath.AsString().c_str()); plPrintf("Changing working directory to {}\n", rootPath);
if (!plFileSystem::SetCWD(rootPath)) if (!plFileSystem::SetCWD(rootPath))
{ {
printf("ERROR: Directory change to %s failed for some reason\n", rootPath.AsString().c_str()); plPrintf("ERROR: Directory change to {} failed for some reason\n", rootPath);
printf("Unable to continue with the packing of this directory, aborting...\n"); fputs("Unable to continue with the packing of this directory, aborting...\n", stdout);
return; return;
} }
else else
printf("Directory changed to %s\n", rootPath.AsString().c_str()); plPrintf("Directory changed to {}\n", rootPath);
std::vector<plFileName> fileNames; std::vector<plFileName> fileNames;
std::vector<plFileName> pathNames; std::vector<plFileName> pathNames;
@ -371,7 +371,7 @@ void PackDirectory(const plFileName& dir, const plFileName& rootPath, const plFi
FindPackages(fileNames, pathNames, dir); FindPackages(fileNames, pathNames, dir);
if (packSysAndPlasma) if (packSysAndPlasma)
{ {
printf("Adding the system and plasma directories to this pack file\n"); fputs("Adding the system and plasma directories to this pack file\n", stdout);
plFileName tempPath; plFileName tempPath;
tempPath = plFileName::Join(dir, "system"); tempPath = plFileName::Join(dir, "system");
FindFiles(fileNames, pathNames, tempPath); FindFiles(fileNames, pathNames, tempPath);
@ -431,15 +431,15 @@ void PackDirectory(const plFileName& dir, const plFileName& rootPath, const plFi
void PrintUsage() void PrintUsage()
{ {
printf("Usage:\n"); fputs("Usage:\n", stdout);
printf("plPythonPack [directory to pack...]\n"); fputs("plPythonPack [directory to pack...]\n", stdout);
printf("NOTE: the directory to pack must have full system and plasma dirs and\n"); fputs("NOTE: the directory to pack must have full system and plasma dirs and\n", stdout);
printf(" must be a relative path to the current working directory\n"); fputs(" must be a relative path to the current working directory\n", stdout);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
printf("The Python Pack Utility\n"); fputs("The Python Pack Utility\n", stdout);
plFileName baseWorkingDir = plFileSystem::GetCWD(); plFileName baseWorkingDir = plFileSystem::GetCWD();

13
Sources/Plasma/CoreLib/plFormat.h

@ -251,4 +251,17 @@ plString plFormat(const char *fmt_str, _Type value, _Args... args)
return plFormat_Private::_IFormat(data, args...); return plFormat_Private::_IFormat(data, args...);
} }
template <typename _Type, typename... _Args>
void plPrintf(FILE *fd, const char *fmt_str, _Type value, _Args... args)
{
plString output = plFormat(fmt_str, value, args...);
fwrite(output.c_str(), sizeof(char), output.GetSize(), fd);
}
template <typename _Type, typename... _Args>
void plPrintf(const char *fmt_str, _Type value, _Args... args)
{
plPrintf(stdout, fmt_str, value, args...);
}
#endif // plFormat_Defined #endif // plFormat_Defined

Loading…
Cancel
Save