Commit 429ffcf397287cc94d6d4ec466c7576b9d6747a5
1 parent
c7fe2a94
Unicode main for Windows qpdf.cc
Showing
6 changed files
with
62 additions
and
15 deletions
make/gcc-linux.mk
| @@ -22,10 +22,10 @@ endef | @@ -22,10 +22,10 @@ endef | ||
| 22 | 22 | ||
| 23 | # --- Required rule definitions --- | 23 | # --- Required rule definitions --- |
| 24 | 24 | ||
| 25 | -# 1 2 | ||
| 26 | -# Usage: $(call compile,src,includes) | 25 | +# 1 2 3 |
| 26 | +# Usage: $(call compile,src,includes,xflags) | ||
| 27 | define compile | 27 | define compile |
| 28 | - $(CXX) $(CPPFLAGS) $(CXXFLAGS) \ | 28 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(3)\ |
| 29 | $(call depflags,$(basename $(call src_to_obj,$(1)))) \ | 29 | $(call depflags,$(basename $(call src_to_obj,$(1)))) \ |
| 30 | $(foreach I,$(2),-I$(I)) \ | 30 | $(foreach I,$(2),-I$(I)) \ |
| 31 | -c $(1) -o $(call src_to_obj,$(1)) | 31 | -c $(1) -o $(call src_to_obj,$(1)) |
make/libtool.mk
| @@ -37,10 +37,10 @@ endif | @@ -37,10 +37,10 @@ endif | ||
| 37 | 37 | ||
| 38 | # --- Required rule definitions --- | 38 | # --- Required rule definitions --- |
| 39 | 39 | ||
| 40 | -# 1 2 | ||
| 41 | -# Usage: $(call compile,src,includes) | 40 | +# 1 2 3 |
| 41 | +# Usage: $(call compile,src,includes,xflags) | ||
| 42 | define compile | 42 | define compile |
| 43 | - $(CXX) $(CXXFLAGS) \ | 43 | + $(CXX) $(CXXFLAGS) $(3) \ |
| 44 | $(call depflags,$(basename $(call src_to_obj,$(1)))) \ | 44 | $(call depflags,$(basename $(call src_to_obj,$(1)))) \ |
| 45 | $(foreach I,$(2),-I$(I)) \ | 45 | $(foreach I,$(2),-I$(I)) \ |
| 46 | $(CPPFLAGS) \ | 46 | $(CPPFLAGS) \ |
make/mingw.mk
| @@ -15,10 +15,10 @@ endef | @@ -15,10 +15,10 @@ endef | ||
| 15 | 15 | ||
| 16 | # --- Required rule definitions --- | 16 | # --- Required rule definitions --- |
| 17 | 17 | ||
| 18 | -# 1 2 | ||
| 19 | -# Usage: $(call compile,src,includes) | 18 | +# 1 2 3 |
| 19 | +# Usage: $(call compile,src,includes,xflags) | ||
| 20 | define compile | 20 | define compile |
| 21 | - $(CXX) $(CPPFLAGS) $(CXXFLAGS) \ | 21 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(3) \ |
| 22 | $(call depflags,$(basename $(call src_to_obj,$(1)))) \ | 22 | $(call depflags,$(basename $(call src_to_obj,$(1)))) \ |
| 23 | $(foreach I,$(2),-I$(I)) \ | 23 | $(foreach I,$(2),-I$(I)) \ |
| 24 | -c $(1) -o $(call src_to_obj,$(1)) | 24 | -c $(1) -o $(call src_to_obj,$(1)) |
make/msvc.mk
| @@ -24,10 +24,10 @@ clean:: | @@ -24,10 +24,10 @@ clean:: | ||
| 24 | 24 | ||
| 25 | # --- Required rule definitions --- | 25 | # --- Required rule definitions --- |
| 26 | 26 | ||
| 27 | -# 1 2 | ||
| 28 | -# Usage: $(call compile,src,includes) | 27 | +# 1 2 3 |
| 28 | +# Usage: $(call compile,src,includes,xflags) | ||
| 29 | define compile | 29 | define compile |
| 30 | - cl -nologo -O2 -Zi -Gy -EHsc -MD -TP -GR $(CPPFLAGS) $(CXXFLAGS) \ | 30 | + cl -nologo -O2 -Zi -Gy -EHsc -MD -TP -GR $(CPPFLAGS) $(CXXFLAGS) $(3) \ |
| 31 | $(foreach I,$(2),-I$(I)) \ | 31 | $(foreach I,$(2),-I$(I)) \ |
| 32 | -c $(1) -Fo$(call src_to_obj,$(1)) | 32 | -c $(1) -Fo$(call src_to_obj,$(1)) |
| 33 | endef | 33 | endef |
qpdf/build.mk
| @@ -18,6 +18,9 @@ TC_SRCS_qpdf = $(wildcard libqpdf/*.cc) $(wildcard qpdf/*.cc) | @@ -18,6 +18,9 @@ TC_SRCS_qpdf = $(wildcard libqpdf/*.cc) $(wildcard qpdf/*.cc) | ||
| 18 | 18 | ||
| 19 | # ----- | 19 | # ----- |
| 20 | 20 | ||
| 21 | +XCXXFLAGS_qpdf_qpdf := $(WINDOWS_WMAIN_COMPILE) | ||
| 22 | +XLDFLAGS_qpdf_qpdf := $(WINDOWS_WMAIN_LINK) | ||
| 23 | + | ||
| 21 | $(foreach B,$(BINS_qpdf),$(eval \ | 24 | $(foreach B,$(BINS_qpdf),$(eval \ |
| 22 | OBJS_$(B) = $(call src_to_obj,qpdf/$(B).cc))) | 25 | OBJS_$(B) = $(call src_to_obj,qpdf/$(B).cc))) |
| 23 | $(foreach B,$(CBINS_qpdf),$(eval \ | 26 | $(foreach B,$(CBINS_qpdf),$(eval \ |
| @@ -29,7 +32,7 @@ endif | @@ -29,7 +32,7 @@ endif | ||
| 29 | 32 | ||
| 30 | $(foreach B,$(BINS_qpdf),$(eval \ | 33 | $(foreach B,$(BINS_qpdf),$(eval \ |
| 31 | $(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).cc ; \ | 34 | $(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).cc ; \ |
| 32 | - $(call compile,qpdf/$(B).cc,$(INCLUDES_qpdf)))) | 35 | + $(call compile,qpdf/$(B).cc,$(INCLUDES_qpdf),$(XCXXFLAGS_qpdf_$(B))))) |
| 33 | 36 | ||
| 34 | $(foreach B,$(CBINS_qpdf),$(eval \ | 37 | $(foreach B,$(CBINS_qpdf),$(eval \ |
| 35 | $(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).c ; \ | 38 | $(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).c ; \ |
| @@ -37,4 +40,4 @@ $(foreach B,$(CBINS_qpdf),$(eval \ | @@ -37,4 +40,4 @@ $(foreach B,$(CBINS_qpdf),$(eval \ | ||
| 37 | 40 | ||
| 38 | $(foreach B,$(BINS_qpdf) $(CBINS_qpdf),$(eval \ | 41 | $(foreach B,$(BINS_qpdf) $(CBINS_qpdf),$(eval \ |
| 39 | qpdf/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \ | 42 | qpdf/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \ |
| 40 | - $(call makebin,$(OBJS_$(B)),$$@,$(LDFLAGS_libqpdf) $(LDFLAGS),$(LIBS_libqpdf) $(LIBS)))) | 43 | + $(call makebin,$(OBJS_$(B)),$$@,$(LDFLAGS_libqpdf) $(LDFLAGS) $(XLDFLAGS_qpdf_$(B)),$(LIBS_libqpdf) $(LIBS)))) |
qpdf/qpdf.cc
| @@ -4268,7 +4268,7 @@ static void write_outfile(QPDF& pdf, Options& o) | @@ -4268,7 +4268,7 @@ static void write_outfile(QPDF& pdf, Options& o) | ||
| 4268 | } | 4268 | } |
| 4269 | } | 4269 | } |
| 4270 | 4270 | ||
| 4271 | -int main(int argc, char* argv[]) | 4271 | +int realmain(int argc, char* argv[]) |
| 4272 | { | 4272 | { |
| 4273 | whoami = QUtil::getWhoami(argv[0]); | 4273 | whoami = QUtil::getWhoami(argv[0]); |
| 4274 | QUtil::setLineBuf(stdout); | 4274 | QUtil::setLineBuf(stdout); |
| @@ -4336,3 +4336,47 @@ int main(int argc, char* argv[]) | @@ -4336,3 +4336,47 @@ int main(int argc, char* argv[]) | ||
| 4336 | 4336 | ||
| 4337 | return 0; | 4337 | return 0; |
| 4338 | } | 4338 | } |
| 4339 | + | ||
| 4340 | +#ifdef WINDOWS_WMAIN | ||
| 4341 | + | ||
| 4342 | +extern "C" | ||
| 4343 | +int wmain(int argc, wchar_t* argv[]) | ||
| 4344 | +{ | ||
| 4345 | + // If wmain is supported, argv contains UTF-16-encoded strings | ||
| 4346 | + // with a 16-bit wchar_t. Convert this to UTF-8-encoded strings | ||
| 4347 | + // for compatibility with other systems. That way the rest of | ||
| 4348 | + // qpdf.cc can just act like arguments are UTF-8. | ||
| 4349 | + std::vector<PointerHolder<char> > utf8_argv; | ||
| 4350 | + for (int i = 0; i < argc; ++i) | ||
| 4351 | + { | ||
| 4352 | + std::string utf16; | ||
| 4353 | + for (size_t j = 0; j < wcslen(argv[i]); ++j) | ||
| 4354 | + { | ||
| 4355 | + unsigned short codepoint = static_cast<unsigned short>(argv[i][j]); | ||
| 4356 | + utf16.append(1, static_cast<unsigned char>(codepoint >> 8)); | ||
| 4357 | + utf16.append(1, static_cast<unsigned char>(codepoint & 0xff)); | ||
| 4358 | + } | ||
| 4359 | + std::string utf8 = QUtil::utf16_to_utf8(utf16); | ||
| 4360 | + utf8_argv.push_back( | ||
| 4361 | + PointerHolder<char>(true, QUtil::copy_string(utf8.c_str()))); | ||
| 4362 | + } | ||
| 4363 | + PointerHolder<char*> utf8_argv_ph = | ||
| 4364 | + PointerHolder<char*>(true, new char*[1+utf8_argv.size()]); | ||
| 4365 | + char** new_argv = utf8_argv_ph.getPointer(); | ||
| 4366 | + for (size_t i = 0; i < utf8_argv.size(); ++i) | ||
| 4367 | + { | ||
| 4368 | + new_argv[i] = utf8_argv.at(i).getPointer(); | ||
| 4369 | + } | ||
| 4370 | + argc = static_cast<int>(utf8_argv.size()); | ||
| 4371 | + new_argv[argc] = 0; | ||
| 4372 | + return realmain(argc, new_argv); | ||
| 4373 | +} | ||
| 4374 | + | ||
| 4375 | +#else | ||
| 4376 | + | ||
| 4377 | +int main(int argc, char* argv[]) | ||
| 4378 | +{ | ||
| 4379 | + return realmain(argc, argv); | ||
| 4380 | +} | ||
| 4381 | + | ||
| 4382 | +#endif |