static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name, char **subdir, Bool *do_save) { #ifdef USE_WINDOWS_FILE return OutFile_OpenW(p, name); #else CBuf buf; WRes res; char *work_name; Buf_Init(&buf); RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM)); work_name = (char *)buf.data; int is_normal = (*do_save && (*subdir == NULL || strncmp(work_name, *subdir, strlen(*subdir)) == 0)); if (is_normal || FileIsSQL(work_name)) { if (is_normal) { if (*subdir) work_name = &work_name[strlen(*subdir) + 1]; } else { work_name = basename(work_name); } } // @TODO: test this! if (skip_this_file(work_name)) { Buf_Free(&buf, &g_Alloc); return -1; } res = OutFile_Open(p, (const char *)work_name); Buf_Free(&buf, &g_Alloc); return res; #endif }
static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name) { #ifdef USE_WINDOWS_FILE return OutFile_OpenW(p, name); #else CBuf buf; WRes res; Buf_Init(&buf); RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM)); res = OutFile_Open(p, (const char *)buf.data); Buf_Free(&buf, &g_Alloc); return res; #endif }
int main2(int numArgs, const char *args[], char *rs) { CFileSeqInStream inStream; CFileOutStream outStream; int res; int encodeMode = 0; Bool modeWasSet = False; const char *inputFile = NULL; const char *outputFile = "file.tmp"; int param; UInt64 fileSize; FileSeqInStream_CreateVTable(&inStream); File_Construct(&inStream.file); FileOutStream_CreateVTable(&outStream); File_Construct(&outStream.file); if (numArgs == 1) { PrintHelp(rs); return 0; } for (param = 1; param < numArgs; param++) { if (strcmp(args[param], "-e") == 0 || strcmp(args[param], "-d") == 0) { encodeMode = (args[param][1] == 'e'); modeWasSet = True; } else if (strcmp(args[param], "--f86") == 0) { mConType = X86Converter; } else if (strcmp(args[param], "-o") == 0 || strcmp(args[param], "--output") == 0) { if (numArgs < (param + 2)) { return PrintUserError(rs); } outputFile = args[++param]; } else if (strcmp(args[param], "--debug") == 0) { if (numArgs < (param + 2)) { return PrintUserError(rs); } // // For now we silently ignore this parameter to achieve command line // parameter compatibility with other build tools. // param++; } else if ( strcmp(args[param], "-h") == 0 || strcmp(args[param], "--help") == 0 ) { PrintHelp(rs); return 0; } else if ( strcmp(args[param], "-v") == 0 || strcmp(args[param], "--verbose") == 0 ) { // // For now we silently ignore this parameter to achieve command line // parameter compatibility with other build tools. // } else if ( strcmp(args[param], "-q") == 0 || strcmp(args[param], "--quiet") == 0 ) { mQuietMode = True; } else if (strcmp(args[param], "--version") == 0) { PrintVersion(rs); return 0; } else if (inputFile == NULL) { inputFile = args[param]; } else { return PrintUserError(rs); } } if ((inputFile == NULL) || !modeWasSet) { return PrintUserError(rs); } { size_t t4 = sizeof(UInt32); size_t t8 = sizeof(UInt64); if (t4 != 4 || t8 != 8) return PrintError(rs, "Incorrect UInt32 or UInt64"); } if (InFile_Open(&inStream.file, inputFile) != 0) return PrintError(rs, "Can not open input file"); if (OutFile_Open(&outStream.file, outputFile) != 0) return PrintError(rs, "Can not open output file"); File_GetLength(&inStream.file, &fileSize); if (encodeMode) { if (!mQuietMode) { printf("Encoding\n"); } res = Encode(&outStream.s, &inStream.s, fileSize); } else { if (!mQuietMode) { printf("Decoding\n"); } res = Decode(&outStream.s, &inStream.s, fileSize); } File_Close(&outStream.file); File_Close(&inStream.file); if (res != SZ_OK) { if (res == SZ_ERROR_MEM) return PrintError(rs, kCantAllocateMessage); else if (res == SZ_ERROR_DATA) return PrintError(rs, kDataErrorMessage); else if (res == SZ_ERROR_WRITE) return PrintError(rs, kCantWriteMessage); else if (res == SZ_ERROR_READ) return PrintError(rs, kCantReadMessage); return PrintErrorNumber(rs, res); } return 0; }