mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-31 02:48:31 +00:00
Unicode main for Windows qpdf.cc
This commit is contained in:
parent
c7fe2a9490
commit
429ffcf397
@ -22,10 +22,10 @@ endef
|
||||
|
||||
# --- Required rule definitions ---
|
||||
|
||||
# 1 2
|
||||
# Usage: $(call compile,src,includes)
|
||||
# 1 2 3
|
||||
# Usage: $(call compile,src,includes,xflags)
|
||||
define compile
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) \
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(3)\
|
||||
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
|
||||
$(foreach I,$(2),-I$(I)) \
|
||||
-c $(1) -o $(call src_to_obj,$(1))
|
||||
|
@ -37,10 +37,10 @@ endif
|
||||
|
||||
# --- Required rule definitions ---
|
||||
|
||||
# 1 2
|
||||
# Usage: $(call compile,src,includes)
|
||||
# 1 2 3
|
||||
# Usage: $(call compile,src,includes,xflags)
|
||||
define compile
|
||||
$(CXX) $(CXXFLAGS) \
|
||||
$(CXX) $(CXXFLAGS) $(3) \
|
||||
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
|
||||
$(foreach I,$(2),-I$(I)) \
|
||||
$(CPPFLAGS) \
|
||||
|
@ -15,10 +15,10 @@ endef
|
||||
|
||||
# --- Required rule definitions ---
|
||||
|
||||
# 1 2
|
||||
# Usage: $(call compile,src,includes)
|
||||
# 1 2 3
|
||||
# Usage: $(call compile,src,includes,xflags)
|
||||
define compile
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) \
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(3) \
|
||||
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
|
||||
$(foreach I,$(2),-I$(I)) \
|
||||
-c $(1) -o $(call src_to_obj,$(1))
|
||||
|
@ -24,10 +24,10 @@ clean::
|
||||
|
||||
# --- Required rule definitions ---
|
||||
|
||||
# 1 2
|
||||
# Usage: $(call compile,src,includes)
|
||||
# 1 2 3
|
||||
# Usage: $(call compile,src,includes,xflags)
|
||||
define compile
|
||||
cl -nologo -O2 -Zi -Gy -EHsc -MD -TP -GR $(CPPFLAGS) $(CXXFLAGS) \
|
||||
cl -nologo -O2 -Zi -Gy -EHsc -MD -TP -GR $(CPPFLAGS) $(CXXFLAGS) $(3) \
|
||||
$(foreach I,$(2),-I$(I)) \
|
||||
-c $(1) -Fo$(call src_to_obj,$(1))
|
||||
endef
|
||||
|
@ -18,6 +18,9 @@ TC_SRCS_qpdf = $(wildcard libqpdf/*.cc) $(wildcard qpdf/*.cc)
|
||||
|
||||
# -----
|
||||
|
||||
XCXXFLAGS_qpdf_qpdf := $(WINDOWS_WMAIN_COMPILE)
|
||||
XLDFLAGS_qpdf_qpdf := $(WINDOWS_WMAIN_LINK)
|
||||
|
||||
$(foreach B,$(BINS_qpdf),$(eval \
|
||||
OBJS_$(B) = $(call src_to_obj,qpdf/$(B).cc)))
|
||||
$(foreach B,$(CBINS_qpdf),$(eval \
|
||||
@ -29,7 +32,7 @@ endif
|
||||
|
||||
$(foreach B,$(BINS_qpdf),$(eval \
|
||||
$(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).cc ; \
|
||||
$(call compile,qpdf/$(B).cc,$(INCLUDES_qpdf))))
|
||||
$(call compile,qpdf/$(B).cc,$(INCLUDES_qpdf),$(XCXXFLAGS_qpdf_$(B)))))
|
||||
|
||||
$(foreach B,$(CBINS_qpdf),$(eval \
|
||||
$(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).c ; \
|
||||
@ -37,4 +40,4 @@ $(foreach B,$(CBINS_qpdf),$(eval \
|
||||
|
||||
$(foreach B,$(BINS_qpdf) $(CBINS_qpdf),$(eval \
|
||||
qpdf/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \
|
||||
$(call makebin,$(OBJS_$(B)),$$@,$(LDFLAGS_libqpdf) $(LDFLAGS),$(LIBS_libqpdf) $(LIBS))))
|
||||
$(call makebin,$(OBJS_$(B)),$$@,$(LDFLAGS_libqpdf) $(LDFLAGS) $(XLDFLAGS_qpdf_$(B)),$(LIBS_libqpdf) $(LIBS))))
|
||||
|
46
qpdf/qpdf.cc
46
qpdf/qpdf.cc
@ -4268,7 +4268,7 @@ static void write_outfile(QPDF& pdf, Options& o)
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int realmain(int argc, char* argv[])
|
||||
{
|
||||
whoami = QUtil::getWhoami(argv[0]);
|
||||
QUtil::setLineBuf(stdout);
|
||||
@ -4336,3 +4336,47 @@ int main(int argc, char* argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS_WMAIN
|
||||
|
||||
extern "C"
|
||||
int wmain(int argc, wchar_t* argv[])
|
||||
{
|
||||
// If wmain is supported, argv contains UTF-16-encoded strings
|
||||
// with a 16-bit wchar_t. Convert this to UTF-8-encoded strings
|
||||
// for compatibility with other systems. That way the rest of
|
||||
// qpdf.cc can just act like arguments are UTF-8.
|
||||
std::vector<PointerHolder<char> > utf8_argv;
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
std::string utf16;
|
||||
for (size_t j = 0; j < wcslen(argv[i]); ++j)
|
||||
{
|
||||
unsigned short codepoint = static_cast<unsigned short>(argv[i][j]);
|
||||
utf16.append(1, static_cast<unsigned char>(codepoint >> 8));
|
||||
utf16.append(1, static_cast<unsigned char>(codepoint & 0xff));
|
||||
}
|
||||
std::string utf8 = QUtil::utf16_to_utf8(utf16);
|
||||
utf8_argv.push_back(
|
||||
PointerHolder<char>(true, QUtil::copy_string(utf8.c_str())));
|
||||
}
|
||||
PointerHolder<char*> utf8_argv_ph =
|
||||
PointerHolder<char*>(true, new char*[1+utf8_argv.size()]);
|
||||
char** new_argv = utf8_argv_ph.getPointer();
|
||||
for (size_t i = 0; i < utf8_argv.size(); ++i)
|
||||
{
|
||||
new_argv[i] = utf8_argv.at(i).getPointer();
|
||||
}
|
||||
argc = static_cast<int>(utf8_argv.size());
|
||||
new_argv[argc] = 0;
|
||||
return realmain(argc, new_argv);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
return realmain(argc, argv);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user