diff options
38 files changed, 582 insertions, 3957 deletions
diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt index d727edf55..359058de6 100644 --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -1,4 +1,4 @@ -*todo.txt* For Vim version 7.0aa. Last change: 2005 Jul 22 +*todo.txt* For Vim version 7.0aa. Last change: 2005 Jul 23 VIM REFERENCE MANUAL by Bram Moolenaar @@ -30,20 +30,12 @@ be worked on, but only if you sponsor Vim development. See |sponsor|. *known-bugs* -------------------- Known bugs and current work ----------------------- -Make a script to check message translations not to change the % items in -strings. - -Fixed Netrw plugin problems: -- when 'autochdir' is set the current dir is wrong (Salman Halim) -- "cd -" doesn't work. (Suresh Govindachar) -Send to Charles Campbell - Mac unicode patch (Da Woon Jung): - selecting proportional font breaks display - UTF-8 text causes display problems. Font replacement causes this. -Include new PHP indent script from John Wellesz? - http://www.vim.org/scripts/download_script.php?src_id=4330 +Win32: Use the free downloadable compiler 7.1. Figure out how to do debugging +(with Agide?) and describe it. (George Reilly) autoload: - Add a Vim script in $VIMRUNTIME/tools that takes a file with a list of @@ -56,29 +48,24 @@ autoload: helpfile doc/myscript.txt For the "helpfile" item ":helptags" is run. -Patch to alternate fold highlighting. (Anthony Iano-Fletcher, 2005 May 12) -More levels? - Awaiting response: - Win32: tearoff menu window should have a scrollbar when it's taller than the screen. - -mblen(NULL, 0) also in Vim 6.3? +- mblen(NULL, 0) also in Vim 6.3? Win32: Crash when pasting Simplified Chinese in utf-8. (rainux, 2005 June 20) PLANNED FOR VERSION 7.0: -- Support using "**" in filename for ":next", ":vimgrep", etc., so that a - directory tree can be searched. - REFACTORING: The main() function is very long. Move parts to separate functions, especially loops. Ideas from Walter Briscoe (2003 Apr 3, 2004 Feb 9). - Move the printing stuff to hardcopy.c. -- Improve the interface between the generic GUI code and the system-specific + Improve the interface between the generic GUI code and the system-specific code. Generic code handles text window with scrollbars, system-specific code menu, toolbar, etc. +- Support using "**" in filename for ":next", ":vimgrep", etc., so that a + directory tree can be searched. - Store messages to allow SCROLLING BACK for all commands. And other "less" like commands. - "INTELLISENSE". First cleanup the Insert-mode completion. diff --git a/src/Make_bc3.mak b/src/Make_bc3.mak index e48575051..207b861a8 100644 --- a/src/Make_bc3.mak +++ b/src/Make_bc3.mak @@ -65,6 +65,7 @@ EXE_dependencies = \ fileio.obj \ fold.obj \ getchar.obj \ + hardcopy.obj \ hashtable.obj \ main.obj \ mark.obj \ diff --git a/src/Make_bc5.mak b/src/Make_bc5.mak index 195d79f9c..99009c554 100644 --- a/src/Make_bc5.mak +++ b/src/Make_bc5.mak @@ -546,6 +546,7 @@ vimobj = \ $(OBJDIR)\fileio.obj \ $(OBJDIR)\fold.obj \ $(OBJDIR)\getchar.obj \ + $(OBJDIR)\hardcopy.obj \ $(OBJDIR)\hashtable.obj \ $(OBJDIR)\main.obj \ $(OBJDIR)\mark.obj \ diff --git a/src/Make_cyg.mak b/src/Make_cyg.mak index c7f833797..880f29234 100644 --- a/src/Make_cyg.mak +++ b/src/Make_cyg.mak @@ -1,6 +1,6 @@ # # Makefile for VIM on Win32, using Cygnus gcc -# Last updated by Dan Sharp. Last Change: 2005 Mar 21 +# Last updated by Dan Sharp. Last Change: 2005 Jul 23 # # Also read INSTALLpc.txt! # @@ -403,6 +403,7 @@ OBJ = \ $(OUTDIR)/fileio.o \ $(OUTDIR)/fold.o \ $(OUTDIR)/getchar.o \ + $(OUTDIR)/hardcopy.o \ $(OUTDIR)/hashtable.o \ $(OUTDIR)/main.o \ $(OUTDIR)/mark.o \ diff --git a/src/Make_dice.mak b/src/Make_dice.mak index c5fea5ee3..fe74f520e 100644 --- a/src/Make_dice.mak +++ b/src/Make_dice.mak @@ -40,6 +40,7 @@ SRC = \ fileio.c \ fold.c \ getchar.c \ + hardcopy.c \ hashtable.c \ main.c \ mark.c \ @@ -82,6 +83,7 @@ OBJ = o/buffer.o \ o/fileio.o \ o/fold.o \ o/getchar.o \ + o/hardcopy.o \ o/hashtable.o \ o/main.o \ o/mark.o \ @@ -157,6 +159,8 @@ o/fold.o: fold.c $(SYMS) o/getchar.o: getchar.c $(SYMS) +o/hardcopy.o: hardcopy.c $(SYMS) + o/hashtable.o: hashtable.c $(SYMS) o/main.o: main.c $(SYMS) diff --git a/src/Make_djg.mak b/src/Make_djg.mak index 0ba5140c5..fa4af40d3 100644 --- a/src/Make_djg.mak +++ b/src/Make_djg.mak @@ -33,6 +33,7 @@ OBJ = \ obj/fileio.o \ obj/fold.o \ obj/getchar.o \ + obj/hardcopy.o \ obj/hashtable.o \ obj/main.o \ obj/mark.o \ diff --git a/src/Make_ivc.mak b/src/Make_ivc.mak index 2ca070e68..44f58fb94 100644 --- a/src/Make_ivc.mak +++ b/src/Make_ivc.mak @@ -224,6 +224,7 @@ LINK32_OBJS= \ "$(INTDIR)/fileio.obj" \ "$(INTDIR)/fold.obj" \ "$(INTDIR)/getchar.obj" \ + "$(INTDIR)/hardcopy.obj" \ "$(INTDIR)/hashtable.obj" \ "$(INTDIR)/main.obj" \ "$(INTDIR)/mark.obj" \ @@ -378,6 +379,10 @@ SOURCE=.\getchar.c # End Source File # Begin Source File +SOURCE=.\hardcopy.c +# End Source File +# Begin Source File + SOURCE=.\hashtable.c # End Source File # Begin Source File diff --git a/src/Make_manx.mak b/src/Make_manx.mak index 5bb8e6b5e..52b9e4833 100644 --- a/src/Make_manx.mak +++ b/src/Make_manx.mak @@ -48,6 +48,7 @@ SRC = buffer.c \ fileio.c \ fold.c \ getchar.c \ + hardcopy.c \ hashtable.c \ main.c \ mark.c \ @@ -92,6 +93,7 @@ OBJ = obj/buffer.o \ obj/fileio.o \ obj/fold.o \ obj/getchar.o \ + obj/hardcopy.o \ obj/hashtable.o \ obj/main.o \ obj/mark.o \ @@ -134,6 +136,7 @@ PRO = proto/buffer.pro \ proto/fileio.pro \ proto/fold.pro \ proto/getchar.pro \ + proto/hardcopy.pro \ proto/hashtable.pro \ proto/main.pro \ proto/mark.pro \ @@ -249,6 +252,9 @@ obj/fold.o: fold.c obj/getchar.o: getchar.c $(CCSYM) $@ getchar.c +obj/hardcopy.o: hardcopy.c + $(CCSYM) $@ hardcopy.c + obj/hashtable.o: hashtable.c $(CCSYM) $@ hashtable.c diff --git a/src/Make_ming.mak b/src/Make_ming.mak index 690627335..9d78da56c 100644 --- a/src/Make_ming.mak +++ b/src/Make_ming.mak @@ -371,6 +371,7 @@ OBJ = \ $(OUTDIR)/fileio.o \ $(OUTDIR)/fold.o \ $(OUTDIR)/getchar.o \ + $(OUTDIR)/hardcopy.o \ $(OUTDIR)/hashtable.o \ $(OUTDIR)/main.o \ $(OUTDIR)/mark.o \ diff --git a/src/Make_morph.mak b/src/Make_morph.mak index 2c67dab5d..54422fead 100644 --- a/src/Make_morph.mak +++ b/src/Make_morph.mak @@ -38,6 +38,7 @@ SRC = buffer.c \ fileio.c \ fold.c \ getchar.c \ + hardcopy.c \ hashtable.c \ main.c \ mark.c \ diff --git a/src/Make_mpw.mak b/src/Make_mpw.mak index 4ee0e52ac..5be703a73 100644 --- a/src/Make_mpw.mak +++ b/src/Make_mpw.mak @@ -32,6 +32,7 @@ SrcFiles = ¶ :src:fileio.c ¶ :src:fold.c ¶ :src:getchar.c ¶ + :src:hardcopy.c ¶ :src:hashtable.c ¶ :src:gui.c ¶ :src:gui_mac.c ¶ @@ -84,6 +85,7 @@ ObjFiles-PPC = ¶ "{ObjDir}fileio.c.x" ¶ "{ObjDir}fold.c.x" ¶ "{ObjDir}getchar.c.x" ¶ + "{ObjDir}hardcopy.c.x" ¶ "{ObjDir}hashtable.c.x" ¶ "{ObjDir}gui.c.x" ¶ "{ObjDir}gui_mac.c.x" ¶ @@ -167,6 +169,7 @@ VIm ÄÄ {ObjFiles-PPC} {LibFiles-PPC} {¥MondoBuild¥} "{ObjDir}fileio.c.x" Ä :src:fileio.c "{ObjDir}fold.c.x" Ä :src:fold.c "{ObjDir}getchar.c.x" Ä :src:getchar.c +"{ObjDir}hardcopy.c.x" Ä :src:hardcopy.c "{ObjDir}hashtable.c.x" Ä :src:hashtable.c "{ObjDir}gui.c.x" Ä :src:gui.c "{ObjDir}gui_mac.c.x" Ä :src:gui_mac.c @@ -257,6 +260,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -339,6 +343,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -421,6 +426,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -503,6 +509,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -585,6 +592,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -668,6 +676,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -750,6 +759,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -832,6 +842,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -914,6 +925,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -996,6 +1008,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -1078,6 +1091,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -1160,6 +1174,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -1242,6 +1257,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -1366,6 +1382,89 @@ Dependencies Ä $OutOfDate :src:proto:if_perl.pro ¶ :src:proto:if_perlsfio.pro +:obj:hardcopy.c.x Ä ¶ + :src:hardcopy.c ¶ + :src:vim.h ¶ + :src:auto:config.h ¶ + :src:feature.h ¶ + :src:os_unix.h ¶ + :src:os_mac.h ¶ + :src:workshop.h ¶ + :src:ascii.h ¶ + :src:keymap.h ¶ + :src:term.h ¶ + :src:macros.h ¶ + :src:structs.h ¶ + :src:globals.h ¶ + :src:option.h ¶ + :src:ex_cmds.h ¶ + :src:proto.h ¶ + :src:integration.h ¶ + :src:wsdebug.h ¶ + :src:regexp.h ¶ + :src:gui.h ¶ + :src:farsi.h ¶ + :src:proto:os_unix.pro ¶ + :src:proto:os_mac.pro ¶ + :src:proto:buffer.pro ¶ + :src:proto:charset.pro ¶ + :src:proto:if_cscope.pro ¶ + :src:proto:diff.pro ¶ + :src:proto:digraph.pro ¶ + :src:proto:edit.pro ¶ + :src:proto:eval.pro ¶ + :src:proto:ex_cmds.pro ¶ + :src:proto:ex_cmds2.pro ¶ + :src:proto:ex_docmd.pro ¶ + :src:proto:ex_eval.pro ¶ + :src:proto:ex_getln.pro ¶ + :src:proto:fileio.pro ¶ + :src:proto:fold.pro ¶ + :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ + :src:proto:hashtable.pro ¶ + :src:proto:hangulin.pro ¶ + :src:proto:main.pro ¶ + :src:proto:mark.pro ¶ + :src:proto:memfile.pro ¶ + :src:proto:memline.pro ¶ + :src:proto:menu.pro ¶ + :src:proto:message.pro ¶ + :src:proto:misc1.pro ¶ + :src:proto:misc2.pro ¶ + :src:proto:move.pro ¶ + :src:proto:multibyte.pro ¶ + :src:proto:normal.pro ¶ + :src:proto:ops.pro ¶ + :src:proto:option.pro ¶ + :src:proto:quickfix.pro ¶ + :src:proto:regexp.pro ¶ + :src:proto:screen.pro ¶ + :src:proto:search.pro ¶ + :src:proto:spell.pro ¶ + :src:proto:syntax.pro ¶ + :src:proto:tag.pro ¶ + :src:proto:term.pro ¶ + :src:proto:termlib.pro ¶ + :src:proto:ui.pro ¶ + :src:proto:undo.pro ¶ + :src:proto:version.pro ¶ + :src:proto:window.pro ¶ + :src:proto:if_python.pro ¶ + :src:proto:if_tcl.pro ¶ + :src:proto:if_ruby.pro ¶ + :src:proto:gui.pro ¶ + :src:proto:pty.pro ¶ + :src:proto:gui_gtk.pro ¶ + :src:proto:gui_gtk_x11.pro ¶ + :src:proto:gui_motif.pro ¶ + :src:proto:gui_athena.pro ¶ + :src:proto:gui_mac.pro ¶ + :src:proto:gui_x11.pro ¶ + :src:proto:workshop.pro ¶ + :src:proto:if_perl.pro ¶ + :src:proto:if_perlsfio.pro + :obj:hashtable.c.x Ä ¶ :src:hashtable.c ¶ :src:vim.h ¶ @@ -1405,6 +1504,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -1487,6 +1587,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -1569,6 +1670,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -1677,6 +1779,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -1760,6 +1863,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -1842,6 +1946,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -1924,6 +2029,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2006,6 +2112,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2088,6 +2195,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2170,6 +2278,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2253,6 +2362,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2335,6 +2445,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2417,6 +2528,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2499,6 +2611,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2581,6 +2694,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2663,6 +2777,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2745,6 +2860,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2827,6 +2943,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2909,6 +3026,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -2991,6 +3109,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3073,6 +3192,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3155,6 +3275,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3237,6 +3358,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3319,6 +3441,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3401,6 +3524,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3483,6 +3607,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3565,6 +3690,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3648,6 +3774,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3729,6 +3856,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3811,6 +3939,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3894,6 +4023,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -3976,6 +4106,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ @@ -4058,6 +4189,7 @@ Dependencies Ä $OutOfDate :src:proto:fileio.pro ¶ :src:proto:fold.pro ¶ :src:proto:getchar.pro ¶ + :src:proto:hardcopy.pro ¶ :src:proto:hashtable.pro ¶ :src:proto:hangulin.pro ¶ :src:proto:main.pro ¶ diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak index 599767bb5..e4b344628 100644 --- a/src/Make_mvc.mak +++ b/src/Make_mvc.mak @@ -384,6 +384,7 @@ OBJ = \ $(OUTDIR)\fileio.obj \ $(OUTDIR)\fold.obj \ $(OUTDIR)\getchar.obj \ + $(OUTDIR)\hardcopy.obj \ $(OUTDIR)\hashtable.obj \ $(OUTDIR)\main.obj \ $(OUTDIR)\mark.obj \ @@ -817,6 +818,8 @@ $(OUTDIR)/fold.obj: $(OUTDIR) fold.c $(INCL) $(OUTDIR)/getchar.obj: $(OUTDIR) getchar.c $(INCL) +$(OUTDIR)/hardcopy.obj: $(OUTDIR) hardcopy.c $(INCL) + $(OUTDIR)/hashtable.obj: $(OUTDIR) hashtable.c $(INCL) $(OUTDIR)/gui.obj: $(OUTDIR) gui.c $(INCL) $(GUI_INCL) @@ -965,6 +968,7 @@ proto.h: \ proto/ex_getln.pro \ proto/fileio.pro \ proto/getchar.pro \ + proto/hardcopy.pro \ proto/hashtable.pro \ proto/main.pro \ proto/mark.pro \ diff --git a/src/Make_os2.mak b/src/Make_os2.mak index c18538ef8..2c4cdaf9e 100644 --- a/src/Make_os2.mak +++ b/src/Make_os2.mak @@ -53,6 +53,7 @@ OBJ = \ fileio.o \ fold.o \ getchar.o \ + hardcopy.o \ hashtable.o \ main.o \ mark.o \ @@ -124,6 +125,7 @@ ex_getln.o: ex_getln.c $(INCL) fileio.o: fileio.c $(INCL) fold.o: fold.c $(INCL) getchar.o: getchar.c $(INCL) +hardcopy.o: hardcopy.c $(INCL) hashtable.o: hashtable.c $(INCL) main.o: main.c $(INCL) mark.o: mark.c $(INCL) diff --git a/src/Make_ro.mak b/src/Make_ro.mak index 4297568ad..38e6324b0 100644 --- a/src/Make_ro.mak +++ b/src/Make_ro.mak @@ -12,7 +12,8 @@ TERMFLAG = -DUP_BC_PC_EXTERN ASMFLAGS = -throwback -objasm -gcc OBJS = o.buffer o.charset o.diff o.digraph o.edit o.eval o.ex_cmds o.ex_cmds2 \ - o.ex_docmd o.ex_eval o.ex_getln o.fileio o.fold o.getchar o.hashtable o.main o.mark o.mbyte \ + o.ex_docmd o.ex_eval o.ex_getln o.fileio o.fold o.getchar \ + o.hardcopy o.hashtable o.main o.mark o.mbyte \ o.memfile o.memline o.menu o.message o.misc1 o.misc2 o.move \ o.normal o.ops o.option o.quickfix o.regexp o.screen o.search \ o.spell o.syntax o.tag o.term o.termlib o.ui o.undo o.version \ @@ -65,6 +66,8 @@ o.fold: c.fold o.getchar: c.getchar +o.hardcopy: c.hardcopy + o.hashtable: c.hashtable o.gui: c.gui diff --git a/src/Make_sas.mak b/src/Make_sas.mak index 3e563f9a5..484f562ad 100644 --- a/src/Make_sas.mak +++ b/src/Make_sas.mak @@ -103,6 +103,7 @@ SRC = \ fileio.c \ fold.c \ getchar.c \ + hardcopy.c \ hashtable.c \ main.c \ mark.c \ @@ -146,6 +147,7 @@ OBJ = \ fileio.o \ fold.o \ getchar.o \ + hardcopy.o \ hashtable.o \ main.o \ mark.o \ @@ -189,6 +191,7 @@ PRO = \ proto/fileio.pro \ proto/fold.pro \ proto/getchar.pro \ + proto/hardcopy.pro \ proto/hashtable.pro \ proto/main.pro \ proto/mark.pro \ @@ -300,6 +303,8 @@ fold.o: fold.c proto/fold.pro: fold.c getchar.o: getchar.c proto/getchar.pro: getchar.c +hardcopy.o: hardcopy.c +proto/hardcopy.pro: hardcopy.c hashtable.o: hashtable.c proto/hashtable.pro: hashtable.c main.o: main.c diff --git a/src/Make_vms.mms b/src/Make_vms.mms index e44c83dc4..8b8346833 100644 --- a/src/Make_vms.mms +++ b/src/Make_vms.mms @@ -2,7 +2,7 @@ # Makefile for Vim on OpenVMS # # Maintainer: Zoltan Arpadffy <arpadffy@polarhome.com> -# Last change: 2005 Jul 12 +# Last change: 2005 Jul 23 # # This has script been tested on VMS 6.2 to 8.2 on DEC Alpha, VAX and IA64 # with MMS and MMK @@ -287,7 +287,7 @@ ALL_LIBS = $(LIBS) $(GUI_LIB_DIR) $(GUI_LIB) \ SRC = buffer.c charset.c diff.c digraph.c edit.c eval.c ex_cmds.c ex_cmds2.c \ ex_docmd.c ex_eval.c ex_getln.c if_xcmdsrv.c fileio.c fold.c getchar.c \ - hashtable.c, main.c mark.c menu.c mbyte.c memfile.c memline.c message.c misc1.c \ + hardcopy.c hashtable.c main.c mark.c menu.c mbyte.c memfile.c memline.c message.c misc1.c \ misc2.c move.c normal.c ops.c option.c quickfix.c regexp.c search.c \ spell.c syntax.c tag.c term.c termlib.c ui.c undo.c version.c screen.c \ window.c os_unix.c os_vms.c pathdef.c \ @@ -296,7 +296,7 @@ SRC = buffer.c charset.c diff.c digraph.c edit.c eval.c ex_cmds.c ex_cmds2.c \ OBJ = buffer.obj charset.obj diff.obj digraph.obj edit.obj eval.obj \ ex_cmds.obj ex_cmds2.obj ex_docmd.obj ex_eval.obj ex_getln.obj \ - if_xcmdsrv.obj fileio.obj fold.obj getchar.obj hashtable.obj main.obj mark.obj \ + if_xcmdsrv.obj fileio.obj fold.obj getchar.obj hardcopy.obj hashtable.obj main.obj mark.obj \ menu.obj memfile.obj memline.obj message.obj misc1.obj misc2.obj \ move.obj mbyte.obj normal.obj ops.obj option.obj quickfix.obj \ regexp.obj search.obj spell.obj syntax.obj tag.obj term.obj termlib.obj \ @@ -527,6 +527,10 @@ getchar.obj : getchar.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ globals.h farsi.h arabic.h +hardcopy.obj : hardcopy.c vim.h [.auto]config.h feature.h os_unix.h \ + ascii.h keymap.h term.h macros.h structs.h regexp.h \ + gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ + globals.h farsi.h arabic.h hashtable.obj : hashtable.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h gui_beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ diff --git a/src/Make_w16.mak b/src/Make_w16.mak index 303c66275..42d15470a 100644 --- a/src/Make_w16.mak +++ b/src/Make_w16.mak @@ -87,6 +87,7 @@ ObjFiles = \ $(INTDIR)\fileio.obj\ $(INTDIR)\fold.obj\ $(INTDIR)\getchar.obj\ + $(INTDIR)\hardcopy.obj\ $(INTDIR)\hashtable.obj\ $(INTDIR)\gui.obj\ $(INTDIR)\gui_w16.obj\ diff --git a/src/Makefile b/src/Makefile index cea05871a..83732a28a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1343,6 +1343,7 @@ BASIC_SRC = \ fileio.c \ fold.c \ getchar.c \ + hardcopy.c \ hashtable.c \ if_cscope.c \ if_xcmdsrv.c \ @@ -1411,6 +1412,7 @@ OBJ = \ objects/fileio.o \ objects/fold.o \ objects/getchar.o \ + objects/hardcopy.o \ objects/hashtable.o \ $(HANGULIN_OBJ) \ objects/if_cscope.o \ @@ -1468,6 +1470,7 @@ PRO_AUTO = \ fileio.pro \ fold.pro \ getchar.pro \ + hardcopy.pro \ hashtable.pro \ hangulin.pro \ if_cscope.pro \ @@ -1599,7 +1602,9 @@ xxd/xxd$(EXEEXT): xxd/xxd.c # Generate the converted .mo files separately, it's no problem if this fails. languages: @if test -n "$(MAKEMO)" -a -f $(PODIR)/Makefile; then \ - cd $(PODIR); CC="$(CC)" $(MAKE) prefix=$(DESTDIR)$(prefix); \ + cd $(PODIR); \ + CC="$(CC)" $(MAKE) check; \ + CC="$(CC)" $(MAKE) prefix=$(DESTDIR)$(prefix); \ fi -@if test -n "$(MAKEMO)" -a -f $(PODIR)/Makefile; then \ cd $(PODIR); CC="$(CC)" $(MAKE) prefix=$(DESTDIR)$(prefix) converted; \ @@ -2285,6 +2290,9 @@ objects/fold.o: fold.c objects/getchar.o: getchar.c $(CCC) -o $@ getchar.c +objects/hardcopy.o: hardcopy.c + $(CCC) -o $@ hardcopy.c + objects/hashtable.o: hashtable.c $(CCC) -o $@ hashtable.c @@ -2637,6 +2645,10 @@ objects/getchar.o: getchar.c vim.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h gui_beval.h proto/gui_beval.pro option.h ex_cmds.h proto.h \ globals.h farsi.h arabic.h +objects/hardcopy.o: hardcopy.c vim.h auto/config.h feature.h os_unix.h \ + auto/osdef.h ascii.h keymap.h term.h macros.h structs.h regexp.h \ + gui.h gui_beval.h proto/gui_beval.pro option.h ex_cmds.h proto.h \ + globals.h farsi.h arabic.h objects/hashtable.o: hashtable.c vim.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h gui_beval.h proto/gui_beval.pro option.h ex_cmds.h proto.h \ diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 923faf9bc..861fa8186 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -3627,3528 +3627,6 @@ ex_checktime(eap) } #endif -#if defined(FEAT_PRINTER) || defined(PROTO) -/* - * Printing code (Machine-independent.) - * To implement printing on a platform, the following functions must be - * defined: - * - * int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) - * Called once. Code should display printer dialogue (if appropriate) and - * determine printer font and margin settings. Reset has_color if the printer - * doesn't support colors at all. - * Returns FAIL to abort. - * - * int mch_print_begin(prt_settings_T *settings) - * Called to start the print job. - * Return FALSE to abort. - * - * int mch_print_begin_page(char_u *msg) - * Called at the start of each page. - * "msg" indicates the progress of the print job, can be NULL. - * Return FALSE to abort. - * - * int mch_print_end_page() - * Called at the end of each page. - * Return FALSE to abort. - * - * int mch_print_blank_page() - * Called to generate a blank page for collated, duplex, multiple copy - * document. Return FALSE to abort. - * - * void mch_print_end(prt_settings_T *psettings) - * Called at normal end of print job. - * - * void mch_print_cleanup() - * Called if print job ends normally or is abandoned. Free any memory, close - * devices and handles. Also called when mch_print_begin() fails, but not - * when mch_print_init() fails. - * - * void mch_print_set_font(int Bold, int Italic, int Underline); - * Called whenever the font style changes. - * - * void mch_print_set_bg(long bgcol); - * Called to set the background color for the following text. Parameter is an - * RGB value. - * - * void mch_print_set_fg(long fgcol); - * Called to set the foreground color for the following text. Parameter is an - * RGB value. - * - * mch_print_start_line(int margin, int page_line) - * Sets the current position at the start of line "page_line". - * If margin is TRUE start in the left margin (for header and line number). - * - * int mch_print_text_out(char_u *p, int len); - * Output one character of text p[len] at the current position. - * Return TRUE if there is no room for another character in the same line. - * - * Note that the generic code has no idea of margins. The machine code should - * simply make the page look smaller! The header and the line numbers are - * printed in the margin. - */ - -#ifdef FEAT_SYN_HL -static const long_u cterm_color_8[8] = -{ - (long_u)0x000000L, (long_u)0xff0000L, (long_u)0x00ff00L, (long_u)0xffff00L, - (long_u)0x0000ffL, (long_u)0xff00ffL, (long_u)0x00ffffL, (long_u)0xffffffL -}; - -static const long_u cterm_color_16[16] = -{ - (long_u)0x000000L, (long_u)0x0000c0L, (long_u)0x008000L, (long_u)0x004080L, - (long_u)0xc00000L, (long_u)0xc000c0L, (long_u)0x808000L, (long_u)0xc0c0c0L, - (long_u)0x808080L, (long_u)0x6060ffL, (long_u)0x00ff00L, (long_u)0x00ffffL, - (long_u)0xff8080L, (long_u)0xff40ffL, (long_u)0xffff00L, (long_u)0xffffffL -}; - -static int current_syn_id; -#endif - -#define PRCOLOR_BLACK (long_u)0 -#define PRCOLOR_WHITE (long_u)0xFFFFFFL - -static int curr_italic; -static int curr_bold; -static int curr_underline; -static long_u curr_bg; -static long_u curr_fg; -static int page_count; - -/* - * These values determine the print position on a page. - */ -typedef struct -{ - int lead_spaces; /* remaining spaces for a TAB */ - int print_pos; /* virtual column for computing TABs */ - colnr_T column; /* byte column */ - linenr_T file_line; /* line nr in the buffer */ - long_u bytes_printed; /* bytes printed so far */ - int ff; /* seen form feed character */ -} prt_pos_T; - -#ifdef FEAT_SYN_HL -static long_u darken_rgb __ARGS((long_u rgb)); -static long_u prt_get_term_color __ARGS((int colorindex)); -#endif -static void prt_set_fg __ARGS((long_u fg)); -static void prt_set_bg __ARGS((long_u bg)); -static void prt_set_font __ARGS((int bold, int italic, int underline)); -static void prt_line_number __ARGS((prt_settings_T *psettings, int page_line, linenr_T lnum)); -static void prt_header __ARGS((prt_settings_T *psettings, int pagenum, linenr_T lnum)); -static void prt_message __ARGS((char_u *s)); -static colnr_T hardcopy_line __ARGS((prt_settings_T *psettings, int page_line, prt_pos_T *ppos)); -static void prt_get_attr __ARGS((int hl_id, prt_text_attr_T* pattr, int modec)); - -#ifdef FEAT_SYN_HL -/* - * If using a dark background, the colors will probably be too bright to show - * up well on white paper, so reduce their brightness. - */ - static long_u -darken_rgb(rgb) - long_u rgb; -{ - return ((rgb >> 17) << 16) - + (((rgb & 0xff00) >> 9) << 8) - + ((rgb & 0xff) >> 1); -} - - static long_u -prt_get_term_color(colorindex) - int colorindex; -{ - /* TODO: Should check for xterm with 88 or 256 colors. */ - if (t_colors > 8) - return cterm_color_16[colorindex % 16]; - return cterm_color_8[colorindex % 8]; -} - - static void -prt_get_attr(hl_id, pattr, modec) - int hl_id; - prt_text_attr_T *pattr; - int modec; -{ - int colorindex; - long_u fg_color; - long_u bg_color; - char *color; - - pattr->bold = (highlight_has_attr(hl_id, HL_BOLD, modec) != NULL); - pattr->italic = (highlight_has_attr(hl_id, HL_ITALIC, modec) != NULL); - pattr->underline = (highlight_has_attr(hl_id, HL_UNDERLINE, modec) != NULL); - pattr->undercurl = (highlight_has_attr(hl_id, HL_UNDERCURL, modec) != NULL); - -# ifdef FEAT_GUI - if (gui.in_use) - { - bg_color = highlight_gui_color_rgb(hl_id, FALSE); - if (bg_color == PRCOLOR_BLACK) - bg_color = PRCOLOR_WHITE; - - fg_color = highlight_gui_color_rgb(hl_id, TRUE); - } - else -# endif - { - bg_color = PRCOLOR_WHITE; - - color = (char *)highlight_color(hl_id, (char_u *)"fg", modec); - if (color == NULL) - colorindex = 0; - else - colorindex = atoi(color); - - if (colorindex >= 0 && colorindex < t_colors) - fg_color = prt_get_term_color(colorindex); - else - fg_color = PRCOLOR_BLACK; - } - - if (fg_color == PRCOLOR_WHITE) - fg_color = PRCOLOR_BLACK; - else if (*p_bg == 'd') - fg_color = darken_rgb(fg_color); - - pattr->fg_color = fg_color; - pattr->bg_color = bg_color; -} -#endif /* FEAT_SYN_HL */ - - static void -prt_set_fg(fg) - long_u fg; -{ - if (fg != curr_fg) - { - curr_fg = fg; - mch_print_set_fg(fg); - } -} - - static void -prt_set_bg(bg) - long_u bg; -{ - if (bg != curr_bg) - { - curr_bg = bg; - mch_print_set_bg(bg); - } -} - - static void -prt_set_font(bold, italic, underline) - int bold; - int italic; - int underline; -{ - if (curr_bold != bold - || curr_italic != italic - || curr_underline != underline) - { - curr_underline = underline; - curr_italic = italic; - curr_bold = bold; - mch_print_set_font(bold, italic, underline); - } -} - -/* - * Print the line number in the left margin. - */ - static void -prt_line_number(psettings, page_line, lnum) - prt_settings_T *psettings; - int page_line; - linenr_T lnum; -{ - int i; - char_u tbuf[20]; - - prt_set_fg(psettings->number.fg_color); - prt_set_bg(psettings->number.bg_color); - prt_set_font(psettings->number.bold, psettings->number.italic, psettings->number.underline); - mch_print_start_line(TRUE, page_line); - - /* Leave two spaces between the number and the text; depends on - * PRINT_NUMBER_WIDTH. */ - sprintf((char *)tbuf, "%6ld", (long)lnum); - for (i = 0; i < 6; i++) - (void)mch_print_text_out(&tbuf[i], 1); - -#ifdef FEAT_SYN_HL - if (psettings->do_syntax) - /* Set colors for next character. */ - current_syn_id = -1; - else -#endif - { - /* Set colors and font back to normal. */ - prt_set_fg(PRCOLOR_BLACK); - prt_set_bg(PRCOLOR_WHITE); - prt_set_font(FALSE, FALSE, FALSE); - } -} - -static linenr_T printer_page_num; - - int -get_printer_page_num() -{ - return printer_page_num; -} - -/* - * Get the currently effective header height. - */ - int -prt_header_height() -{ - if (printer_opts[OPT_PRINT_HEADERHEIGHT].present) - return printer_opts[OPT_PRINT_HEADERHEIGHT].number; - return 2; -} - -/* - * Return TRUE if using a line number for printing. - */ - int -prt_use_number() -{ - return (printer_opts[OPT_PRINT_NUMBER].present - && TOLOWER_ASC(printer_opts[OPT_PRINT_NUMBER].string[0]) == 'y'); -} - -/* - * Return the unit used in a margin item in 'printoptions'. - * Returns PRT_UNIT_NONE if not recognized. - */ - int -prt_get_unit(idx) - int idx; -{ - int u = PRT_UNIT_NONE; - int i; - static char *(units[4]) = PRT_UNIT_NAMES; - - if (printer_opts[idx].present) - for (i = 0; i < 4; ++i) - if (STRNICMP(printer_opts[idx].string, units[i], 2) == 0) - { - u = i; - break; - } - return u; -} - -/* - * Print the page header. - */ -/*ARGSUSED*/ - static void -prt_header(psettings, pagenum, lnum) - prt_settings_T *psettings; - int pagenum; - linenr_T lnum; -{ - int width = psettings->chars_per_line; - int page_line; - char_u *tbuf; - char_u *p; -#ifdef FEAT_MBYTE - int l; -#endif - - /* Also use the space for the line number. */ - if (prt_use_number()) - width += PRINT_NUMBER_WIDTH; - - tbuf = alloc(width + IOSIZE); - if (tbuf == NULL) - return; - -#ifdef FEAT_STL_OPT - if (*p_header != NUL) - { - linenr_T tmp_lnum, tmp_topline, tmp_botline; - - /* - * Need to (temporarily) set current line number and first/last line - * number on the 'window'. Since we don't know how long the page is, - * set the first and current line number to the top line, and guess - * that the page length is 64. - */ - tmp_lnum = curwin->w_cursor.lnum; - tmp_topline = curwin->w_topline; - tmp_botline = curwin->w_botline; - curwin->w_cursor.lnum = lnum; - curwin->w_topline = lnum; - curwin->w_botline = lnum + 63; - printer_page_num = pagenum; - - build_stl_str_hl(curwin, tbuf, (size_t)(width + IOSIZE), - p_header, ' ', width, NULL); - - /* Reset line numbers */ - curwin->w_cursor.lnum = tmp_lnum; - curwin->w_topline = tmp_topline; - curwin->w_botline = tmp_botline; - } - else -#endif - sprintf((char *)tbuf, _("Page %d"), pagenum); - - prt_set_fg(PRCOLOR_BLACK); - prt_set_bg(PRCOLOR_WHITE); - prt_set_font(TRUE, FALSE, FALSE); - - /* Use a negative line number to indicate printing in the top margin. */ - page_line = 0 - prt_header_height(); - mch_print_start_line(TRUE, page_line); - for (p = tbuf; *p != NUL; ) - { - if (mch_print_text_out(p, -#ifdef FEAT_MBYTE - (l = (*mb_ptr2len_check)(p)) -#else - 1 -#endif - )) - { - ++page_line; - if (page_line >= 0) /* out of room in header */ - break; - mch_print_start_line(TRUE, page_line); - } -#ifdef FEAT_MBYTE - p += l; -#else - p++; -#endif - } - - vim_free(tbuf); - -#ifdef FEAT_SYN_HL - if (psettings->do_syntax) - /* Set colors for next character. */ - current_syn_id = -1; - else -#endif - { - /* Set colors and font back to normal. */ - prt_set_fg(PRCOLOR_BLACK); - prt_set_bg(PRCOLOR_WHITE); - prt_set_font(FALSE, FALSE, FALSE); - } -} - -/* - * Display a print status message. - */ - static void -prt_message(s) - char_u *s; -{ - screen_fill((int)Rows - 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0); - screen_puts(s, (int)Rows - 1, 0, hl_attr(HLF_R)); - out_flush(); -} - - void -ex_hardcopy(eap) - exarg_T *eap; -{ - linenr_T lnum; - int collated_copies, uncollated_copies; - prt_settings_T settings; - long_u bytes_to_print = 0; - int page_line; - int jobsplit; - int id; - - memset(&settings, 0, sizeof(prt_settings_T)); - settings.has_color = TRUE; - -# ifdef FEAT_POSTSCRIPT - if (*eap->arg == '>') - { - char_u *errormsg = NULL; - - /* Expand things like "%.ps". */ - if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL) - { - if (errormsg != NULL) - EMSG(errormsg); - return; - } - settings.outfile = skipwhite(eap->arg + 1); - } - else if (*eap->arg != NUL) - settings.arguments = eap->arg; -# endif - - /* - * Initialise for printing. Ask the user for settings, unless forceit is - * set. - * The mch_print_init() code should set up margins if applicable. (It may - * not be a real printer - for example the engine might generate HTML or - * PS.) - */ - if (mch_print_init(&settings, - curbuf->b_fname == NULL - ? (char_u *)buf_spname(curbuf) - : curbuf->b_sfname == NULL - ? curbuf->b_fname - : curbuf->b_sfname, - eap->forceit) == FAIL) - return; - -#ifdef FEAT_SYN_HL -# ifdef FEAT_GUI - if (gui.in_use) - settings.modec = 'g'; - else -# endif - if (t_colors > 1) - settings.modec = 'c'; - else - settings.modec = 't'; - - if (!syntax_present(curbuf)) - settings.do_syntax = FALSE; - else if (printer_opts[OPT_PRINT_SYNTAX].present - && TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) != 'a') - settings.do_syntax = - (TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) == 'y'); - else - settings.do_syntax = settings.has_color; -#endif - - /* Set up printing attributes for line numbers */ - settings.number.fg_color = PRCOLOR_BLACK; - settings.number.bg_color = PRCOLOR_WHITE; - settings.number.bold = FALSE; - settings.number.italic = TRUE; - settings.number.underline = FALSE; -#ifdef FEAT_SYN_HL - /* - * Syntax highlighting of line numbers. - */ - if (prt_use_number() && settings.do_syntax) - { - id = syn_name2id((char_u *)"LineNr"); - if (id > 0) - id = syn_get_final_id(id); - - prt_get_attr(id, &settings.number, settings.modec); - } -#endif /* FEAT_SYN_HL */ - - /* - * Estimate the total lines to be printed - */ - for (lnum = eap->line1; lnum <= eap->line2; lnum++) - bytes_to_print += (long_u)STRLEN(skipwhite(ml_get(lnum))); - if (bytes_to_print == 0) - { - MSG(_("No text to be printed")); - goto print_fail_no_begin; - } - - /* Set colors and font to normal. */ - curr_bg = (long_u)0xffffffffL; - curr_fg = (long_u)0xffffffffL; - curr_italic = MAYBE; - curr_bold = MAYBE; - curr_underline = MAYBE; - - prt_set_fg(PRCOLOR_BLACK); - prt_set_bg(PRCOLOR_WHITE); - prt_set_font(FALSE, FALSE, FALSE); -#ifdef FEAT_SYN_HL - current_syn_id = -1; -#endif - - jobsplit = (printer_opts[OPT_PRINT_JOBSPLIT].present - && TOLOWER_ASC(printer_opts[OPT_PRINT_JOBSPLIT].string[0]) == 'y'); - - if (!mch_print_begin(&settings)) - goto print_fail_no_begin; - - /* - * Loop over collated copies: 1 2 3, 1 2 3, ... - */ - page_count = 0; - for (collated_copies = 0; - collated_copies < settings.n_collated_copies; - collated_copies++) - { - prt_pos_T prtpos; /* current print position */ - prt_pos_T page_prtpos; /* print position at page start */ - int side; - - memset(&page_prtpos, 0, sizeof(prt_pos_T)); - page_prtpos.file_line = eap->line1; - prtpos = page_prtpos; - - if (jobsplit && collated_copies > 0) - { - /* Splitting jobs: Stop a previous job and start a new one. */ - mch_print_end(&settings); - if (!mch_print_begin(&settings)) - goto print_fail_no_begin; - } - - /* - * Loop over all pages in the print job: 1 2 3 ... - */ - for (page_count = 0; prtpos.file_line <= eap->line2; ++page_count) - { - /* - * Loop over uncollated copies: 1 1 1, 2 2 2, 3 3 3, ... - * For duplex: 12 12 12 34 34 34, ... - */ - for (uncollated_copies = 0; - uncollated_copies < settings.n_uncollated_copies; - uncollated_copies++) - { - /* Set the print position to the start of this page. */ - prtpos = page_prtpos; - - /* - * Do front and rear side of a page. - */ - for (side = 0; side <= settings.duplex; ++side) - { - /* - * Print one page. - */ - - /* Check for interrupt character every page. */ - ui_breakcheck(); - if (got_int || settings.user_abort) - goto print_fail; - - sprintf((char *)IObuff, _("Printing page %d (%d%%)"), - page_count + 1 + side, - prtpos.bytes_printed > 1000000 - ? (int)(prtpos.bytes_printed / - (bytes_to_print / 100)) - : (int)((prtpos.bytes_printed * 100) - / bytes_to_print)); - if (!mch_print_begin_page(IObuff)) - goto print_fail; - - if (settings.n_collated_copies > 1) - sprintf((char *)IObuff + STRLEN(IObuff), - _(" Copy %d of %d"), - collated_copies + 1, - settings.n_collated_copies); - prt_message(IObuff); - - /* - * Output header if required - */ - if (prt_header_height() > 0) - prt_header(&settings, page_count + 1 + side, - prtpos.file_line); - - for (page_line = 0; page_line < settings.lines_per_page; - ++page_line) - { - prtpos.column = hardcopy_line(&settings, - page_line, &prtpos); - if (prtpos.column == 0) - { - /* finished a file line */ - prtpos.bytes_printed += - STRLEN(skipwhite(ml_get(prtpos.file_line))); - if (++prtpos.file_line > eap->line2) - break; /* reached the end */ - } - else if (prtpos.ff) - { - /* Line had a formfeed in it - start new page but - * stay on the current line */ - break; - } - } - - if (!mch_print_end_page()) - goto print_fail; - if (prtpos.file_line > eap->line2) - break; /* reached the end */ - } - - /* - * Extra blank page for duplexing with odd number of pages and - * more copies to come. - */ - if (prtpos.file_line > eap->line2 && settings.duplex - && side == 0 - && uncollated_copies + 1 < settings.n_uncollated_copies) - { - if (!mch_print_blank_page()) - goto print_fail; - } - } - if (settings.duplex && prtpos.file_line <= eap->line2) - ++page_count; - - /* Remember the position where the next page starts. */ - page_prtpos = prtpos; - } - - vim_snprintf((char *)IObuff, IOSIZE, _("Printed: %s"), - settings.jobname); - prt_message(IObuff); - } - -print_fail: - if (got_int || settings.user_abort) - { - sprintf((char *)IObuff, "%s", _("Printing aborted")); - prt_message(IObuff); - } - mch_print_end(&settings); - -print_fail_no_begin: - mch_print_cleanup(); -} - -/* - * Print one page line. - * Return the next column to print, or zero if the line is finished. - */ - static colnr_T -hardcopy_line(psettings, page_line, ppos) - prt_settings_T *psettings; - int page_line; - prt_pos_T *ppos; -{ - colnr_T col; - char_u *line; - int need_break = FALSE; - int outputlen; - int tab_spaces; - long_u print_pos; -#ifdef FEAT_SYN_HL - prt_text_attr_T attr; - int id; -#endif - - if (ppos->column == 0 || ppos->ff) - { - print_pos = 0; - tab_spaces = 0; - if (!ppos->ff && prt_use_number()) - prt_line_number(psettings, page_line, ppos->file_line); - ppos->ff = FALSE; - } - else - { - /* left over from wrap halfway a tab */ - print_pos = ppos->print_pos; - tab_spaces = ppos->lead_spaces; - } - - mch_print_start_line(0, page_line); - line = ml_get(ppos->file_line); - - /* - * Loop over the columns until the end of the file line or right margin. - */ - for (col = ppos->column; line[col] != NUL && !need_break; col += outputlen) - { - outputlen = 1; -#ifdef FEAT_MBYTE - if (has_mbyte && (outputlen = (*mb_ptr2len_check)(line + col)) < 1) - outputlen = 1; -#endif -#ifdef FEAT_SYN_HL - /* - * syntax highlighting stuff. - */ - if (psettings->do_syntax) - { - id = syn_get_id(ppos->file_line, col, 1, NULL); - if (id > 0) - id = syn_get_final_id(id); - else - id = 0; - /* Get the line again, a multi-line regexp may invalidate it. */ - line = ml_get(ppos->file_line); - - if (id != current_syn_id) - { - current_syn_id = id; - prt_get_attr(id, &attr, psettings->modec); - prt_set_font(attr.bold, attr.italic, attr.underline); - prt_set_fg(attr.fg_color); - prt_set_bg(attr.bg_color); - } - } -#endif /* FEAT_SYN_HL */ - - /* - * Appropriately expand any tabs to spaces. - */ - if (line[col] == TAB || tab_spaces != 0) - { - if (tab_spaces == 0) - tab_spaces = curbuf->b_p_ts - (print_pos % curbuf->b_p_ts); - - while (tab_spaces > 0) - { - need_break = mch_print_text_out((char_u *)" ", 1); - print_pos++; - tab_spaces--; - if (need_break) - break; - } - /* Keep the TAB if we didn't finish it. */ - if (need_break && tab_spaces > 0) - break; - } - else if (line[col] == FF - && printer_opts[OPT_PRINT_FORMFEED].present - && TOLOWER_ASC(printer_opts[OPT_PRINT_FORMFEED].string[0]) - == 'y') - { - ppos->ff = TRUE; - need_break = 1; - } - else - { - need_break = mch_print_text_out(line + col, outputlen); -#ifdef FEAT_MBYTE - if (has_mbyte) - print_pos += (*mb_ptr2cells)(line + col); - else -#endif - print_pos++; - } - } - - ppos->lead_spaces = tab_spaces; - ppos->print_pos = print_pos; - - /* - * Start next line of file if we clip lines, or have reached end of the - * line, unless we are doing a formfeed. - */ - if (!ppos->ff - && (line[col] == NUL - || (printer_opts[OPT_PRINT_WRAP].present - && TOLOWER_ASC(printer_opts[OPT_PRINT_WRAP].string[0]) - == 'n'))) - return 0; - return col; -} - -# if defined(FEAT_POSTSCRIPT) || defined(PROTO) - -/* - * PS printer stuff. - * - * Sources of information to help maintain the PS printing code: - * - * 1. PostScript Language Reference, 3rd Edition, - * Addison-Wesley, 1999, ISBN 0-201-37922-8 - * 2. PostScript Language Program Design, - * Addison-Wesley, 1988, ISBN 0-201-14396-8 - * 3. PostScript Tutorial and Cookbook, - * Addison Wesley, 1985, ISBN 0-201-10179-3 - * 4. PostScript Language Document Structuring Conventions Specification, - * version 3.0, - * Adobe Technote 5001, 25th September 1992 - * 5. PostScript Printer Description File Format Specification, Version 4.3, - * Adobe technote 5003, 9th February 1996 - * 6. Adobe Font Metrics File Format Specification, Version 4.1, - * Adobe Technote 5007, 7th October 1998 - * 7. Adobe CMap and CIDFont Files Specification, Version 1.0, - * Adobe Technote 5014, 8th October 1996 - * 8. Adobe CJKV Character Collections and CMaps for CID-Keyed Fonts, - * Adoboe Technote 5094, 8th September, 2001 - * 9. CJKV Information Processing, 2nd Edition, - * O'Reilly, 2002, ISBN 1-56592-224-7 - * - * Some of these documents can be found in PDF form on Adobe's web site - - * http://www.adobe.com - */ - -#define NUM_ELEMENTS(arr) (sizeof(arr)/sizeof((arr)[0])) - -#define PRT_PS_DEFAULT_DPI (72) /* Default user space resolution */ -#define PRT_PS_DEFAULT_FONTSIZE (10) -#define PRT_PS_DEFAULT_BUFFER_SIZE (80) - -struct prt_mediasize_S -{ - char *name; - float width; /* width and height in points for portrait */ - float height; -}; - -#define PRT_MEDIASIZE_LEN (sizeof(prt_mediasize) / sizeof(struct prt_mediasize_S)) - -static struct prt_mediasize_S prt_mediasize[] = -{ - {"A4", 595.0, 842.0}, - {"letter", 612.0, 792.0}, - {"10x14", 720.0, 1008.0}, - {"A3", 842.0, 1191.0}, - {"A5", 420.0, 595.0}, - {"B4", 729.0, 1032.0}, - {"B5", 516.0, 729.0}, - {"executive", 522.0, 756.0}, - {"folio", 595.0, 935.0}, - {"ledger", 1224.0, 792.0}, /* Yes, it is wider than taller! */ - {"legal", 612.0, 1008.0}, - {"quarto", 610.0, 780.0}, - {"statement", 396.0, 612.0}, - {"tabloid", 792.0, 1224.0} -}; - -/* PS font names, must be in Roman, Bold, Italic, Bold-Italic order */ -struct prt_ps_font_S -{ - int wx; - int uline_offset; - int uline_width; - int bbox_min_y; - int bbox_max_y; - char *(ps_fontname[4]); -}; - -#define PRT_PS_FONT_ROMAN (0) -#define PRT_PS_FONT_BOLD (1) -#define PRT_PS_FONT_OBLIQUE (2) -#define PRT_PS_FONT_BOLDOBLIQUE (3) - -/* Standard font metrics for Courier family */ -static struct prt_ps_font_S prt_ps_courier_font = -{ - 600, - -100, 50, - -250, 805, - {"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"} -}; - -#ifdef FEAT_MBYTE -/* Generic font metrics for multi-byte fonts */ -static struct prt_ps_font_S prt_ps_mb_font = -{ - 1000, - -100, 50, - -250, 805, - {NULL, NULL, NULL, NULL} -}; -#endif - -/* Pointer to current font set being used */ -static struct prt_ps_font_S* prt_ps_font; - -/* Structures to map user named encoding and mapping to PS equivalents for - * building CID font name */ -struct prt_ps_encoding_S -{ - char *encoding; - char *cmap_encoding; - int needs_charset; -}; - -struct prt_ps_charset_S -{ - char *charset; - char *cmap_charset; - int has_charset; -}; - -#ifdef FEAT_MBYTE - -#define CS_JIS_C_1978 (0x01) -#define CS_JIS_X_1983 (0x02) -#define CS_JIS_X_1990 (0x04) -#define CS_NEC (0x08) -#define CS_MSWINDOWS (0x10) -#define CS_CP932 (0x20) -#define CS_KANJITALK6 (0x40) -#define CS_KANJITALK7 (0x80) - -/* Japanese encodings and charsets */ -static struct prt_ps_encoding_S j_encodings[] = -{ - {"iso-2022-jp", NULL, (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990| - CS_NEC)}, - {"euc-jp", "EUC", (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990)}, - {"sjis", "RKSJ", (CS_JIS_C_1978|CS_JIS_X_1983|CS_MSWINDOWS| - CS_KANJITALK6|CS_KANJITALK7)}, - {"cp932", "RKSJ", CS_JIS_X_1983}, - {"ucs-2", "UCS2", CS_JIS_X_1990}, - {"utf-8", "UTF8" , CS_JIS_X_1990} -}; -static struct prt_ps_charset_S j_charsets[] = -{ - {"JIS_C_1978", "78", CS_JIS_C_1978}, - {"JIS_X_1983", NULL, CS_JIS_X_1983}, - {"JIS_X_1990", "Hojo", CS_JIS_X_1990}, - {"NEC", "Ext", CS_NEC}, - {"MSWINDOWS", "90ms", CS_MSWINDOWS}, - {"CP932", "90ms", CS_JIS_X_1983}, - {"KANJITALK6", "83pv", CS_KANJITALK6}, - {"KANJITALK7", "90pv", CS_KANJITALK7} -}; - -#define CS_GB_2312_80 (0x01) -#define CS_GBT_12345_90 (0x02) -#define CS_GBK2K (0x04) -#define CS_SC_MAC (0x08) -#define CS_GBT_90_MAC (0x10) -#define CS_GBK (0x20) -#define CS_SC_ISO10646 (0x40) - -/* Simplified Chinese encodings and charsets */ -static struct prt_ps_encoding_S sc_encodings[] = -{ - {"iso-2022", NULL, (CS_GB_2312_80|CS_GBT_12345_90)}, - {"gb18030", NULL, CS_GBK2K}, - {"euc-cn", "EUC", (CS_GB_2312_80|CS_GBT_12345_90|CS_SC_MAC| - CS_GBT_90_MAC)}, - {"gbk", "EUC", CS_GBK}, - {"ucs-2", "UCS2", CS_SC_ISO10646}, - {"utf-8", "UTF8", CS_SC_ISO10646} -}; -static struct prt_ps_charset_S sc_charsets[] = -{ - {"GB_2312-80", "GB", CS_GB_2312_80}, - {"GBT_12345-90","GBT", CS_GBT_12345_90}, - {"MAC", "GBpc", CS_SC_MAC}, - {"GBT-90_MAC", "GBTpc", CS_GBT_90_MAC}, - {"GBK", "GBK", CS_GBK}, - {"GB18030", "GBK2K", CS_GBK2K}, - {"ISO10646", "UniGB", CS_SC_ISO10646} -}; - -#define CS_CNS_PLANE_1 (0x01) -#define CS_CNS_PLANE_2 (0x02) -#define CS_CNS_PLANE_1_2 (0x04) -#define CS_B5 (0x08) -#define CS_ETEN (0x10) -#define CS_HK_GCCS (0x20) -#define CS_HK_SCS (0x40) -#define CS_HK_SCS_ETEN (0x80) -#define CS_MTHKL (0x100) -#define CS_MTHKS (0x200) -#define CS_DLHKL (0x400) -#define CS_DLHKS (0x800) -#define CS_TC_ISO10646 (0x1000) - -/* Traditional Chinese encodings and charsets */ -static struct prt_ps_encoding_S tc_encodings[] = -{ - {"iso-2022", NULL, (CS_CNS_PLANE_1|CS_CNS_PLANE_2)}, - {"euc-tw", "EUC", CS_CNS_PLANE_1_2}, - {"big5", "B5", (CS_B5|CS_ETEN|CS_HK_GCCS|CS_HK_SCS| - CS_HK_SCS_ETEN|CS_MTHKL|CS_MTHKS|CS_DLHKL| - CS_DLHKS)}, - {"cp950", "B5", CS_B5}, - {"ucs-2", "UCS2", CS_TC_ISO10646}, - {"utf-8", "UTF8", CS_TC_ISO10646}, - {"utf-16", "UTF16", CS_TC_ISO10646}, - {"utf-32", "UTF32", CS_TC_ISO10646} -}; -static struct prt_ps_charset_S tc_charsets[] = -{ - {"CNS_1992_1", "CNS1", CS_CNS_PLANE_1}, - {"CNS_1992_2", "CNS2", CS_CNS_PLANE_2}, - {"CNS_1993", "CNS", CS_CNS_PLANE_1_2}, - {"BIG5", NULL, CS_B5}, - {"CP950", NULL, CS_B5}, - {"ETEN", "ETen", CS_ETEN}, - {"HK_GCCS", "HKgccs", CS_HK_GCCS}, - {"SCS", "HKscs", CS_HK_SCS}, - {"SCS_ETEN", "ETHK", CS_HK_SCS_ETEN}, - {"MTHKL", "HKm471", CS_MTHKL}, - {"MTHKS", "HKm314", CS_MTHKS}, - {"DLHKL", "HKdla", CS_DLHKL}, - {"DLHKS", "HKdlb", CS_DLHKS}, - {"ISO10646", "UniCNS", CS_TC_ISO10646} -}; - -#define CS_KR_X_1992 (0x01) -#define CS_KR_MAC (0x02) -#define CS_KR_X_1992_MS (0x04) -#define CS_KR_ISO10646 (0x08) - -/* Korean encodings and charsets */ -static struct prt_ps_encoding_S k_encodings[] = -{ - {"iso-2022-kr", NULL, CS_KR_X_1992}, - {"euc-kr", "EUC", (CS_KR_X_1992|CS_KR_MAC)}, - {"johab", "Johab", CS_KR_X_1992}, - {"cp1361", "Johab", CS_KR_X_1992}, - {"uhc", "UHC", CS_KR_X_1992_MS}, - {"cp949", "UHC", CS_KR_X_1992_MS}, - {"ucs-2", "UCS2", CS_KR_ISO10646}, - {"utf-8", "UTF8", CS_KR_ISO10646} -}; -static struct prt_ps_charset_S k_charsets[] = -{ - {"KS_X_1992", "KSC", CS_KR_X_1992}, - {"CP1361", "KSC", CS_KR_X_1992}, - {"MAC", "KSCpc", CS_KR_MAC}, - {"MSWINDOWS", "KSCms", CS_KR_X_1992_MS}, - {"CP949", "KSCms", CS_KR_X_1992_MS}, - {"WANSUNG", "KSCms", CS_KR_X_1992_MS}, - {"ISO10646", "UniKS", CS_KR_ISO10646} -}; - -/* Collections of encodings and charsets for multi-byte printing */ -struct prt_ps_mbfont_S -{ - int num_encodings; - struct prt_ps_encoding_S *encodings; - int num_charsets; - struct prt_ps_charset_S *charsets; - char *ascii_enc; - char *defcs; -}; - -static struct prt_ps_mbfont_S prt_ps_mbfonts[] = -{ - { - NUM_ELEMENTS(j_encodings), - j_encodings, - NUM_ELEMENTS(j_charsets), - j_charsets, - "jis_roman", - "JIS_X_1983" - }, - { - NUM_ELEMENTS(sc_encodings), - sc_encodings, - NUM_ELEMENTS(sc_charsets), - sc_charsets, - "gb_roman", - "GB_2312-80" - }, - { - NUM_ELEMENTS(tc_encodings), - tc_encodings, - NUM_ELEMENTS(tc_charsets), - tc_charsets, - "cns_roman", - "BIG5" - }, - { - NUM_ELEMENTS(k_encodings), - k_encodings, - NUM_ELEMENTS(k_charsets), - k_charsets, - "ks_roman", - "KS_X_1992" - } -}; -#endif /* FEAT_MBYTE */ - -struct prt_ps_resource_S -{ - char_u name[64]; - char_u filename[MAXPATHL + 1]; - int type; - char_u title[256]; - char_u version[256]; -}; - -/* Types of PS resource file currently used */ -#define PRT_RESOURCE_TYPE_PROCSET (0) -#define PRT_RESOURCE_TYPE_ENCODING (1) -#define PRT_RESOURCE_TYPE_CMAP (2) - -/* The PS prolog file version number has to match - if the prolog file is - * updated, increment the number in the file and here. Version checking was - * added as of VIM 6.2. - * The CID prolog file version number behaves as per PS prolog. - * Table of VIM and prolog versions: - * - * VIM Prolog CIDProlog - * 6.2 1.3 - * 7.0 1.4 1.0 - */ -#define PRT_PROLOG_VERSION ((char_u *)"1.4") -#define PRT_CID_PROLOG_VERSION ((char_u *)"1.0") - -/* String versions of PS resource types - indexed by constants above so don't - * re-order! - */ -static char *prt_resource_types[] = -{ - "procset", - "encoding", - "cmap" -}; - -/* Strings to look for in a PS resource file */ -#define PRT_RESOURCE_HEADER "%!PS-Adobe-" -#define PRT_RESOURCE_RESOURCE "Resource-" -#define PRT_RESOURCE_PROCSET "ProcSet" -#define PRT_RESOURCE_ENCODING "Encoding" -#define PRT_RESOURCE_CMAP "CMap" - - -/* Data for table based DSC comment recognition, easy to extend if VIM needs to - * read more comments. */ -#define PRT_DSC_MISC_TYPE (-1) -#define PRT_DSC_TITLE_TYPE (1) -#define PRT_DSC_VERSION_TYPE (2) -#define PRT_DSC_ENDCOMMENTS_TYPE (3) - -#define PRT_DSC_TITLE "%%Title:" -#define PRT_DSC_VERSION "%%Version:" -#define PRT_DSC_ENDCOMMENTS "%%EndComments:" - -struct prt_dsc_comment_S -{ - char *string; - int len; - int type; -}; - -struct prt_dsc_line_S -{ - int type; - char_u *string; - int len; -}; - - -#define SIZEOF_CSTR(s) (sizeof(s) - 1) -static struct prt_dsc_comment_S prt_dsc_table[] = -{ - {PRT_DSC_TITLE, SIZEOF_CSTR(PRT_DSC_TITLE), PRT_DSC_TITLE_TYPE}, - {PRT_DSC_VERSION, SIZEOF_CSTR(PRT_DSC_VERSION), - PRT_DSC_VERSION_TYPE}, - {PRT_DSC_ENDCOMMENTS, SIZEOF_CSTR(PRT_DSC_ENDCOMMENTS), - PRT_DSC_ENDCOMMENTS_TYPE} -}; - -static void prt_write_file_raw_len __ARGS((char_u *buffer, int bytes)); -static void prt_write_file __ARGS((char_u *buffer)); -static void prt_write_file_len __ARGS((char_u *buffer, int bytes)); -static void prt_write_string __ARGS((char *s)); -static void prt_write_int __ARGS((int i)); -static void prt_write_boolean __ARGS((int b)); -static void prt_def_font __ARGS((char *new_name, char *encoding, int height, char *font)); -static void prt_real_bits __ARGS((double real, int precision, int *pinteger, int *pfraction)); -static void prt_write_real __ARGS((double val, int prec)); -static void prt_def_var __ARGS((char *name, double value, int prec)); -static void prt_flush_buffer __ARGS((void)); -static void prt_resource_name __ARGS((char_u *filename, void *cookie)); -static int prt_find_resource __ARGS((char *name, struct prt_ps_resource_S *resource)); -static int prt_open_resource __ARGS((struct prt_ps_resource_S *resource)); -static int prt_check_resource __ARGS((struct prt_ps_resource_S *resource, char_u *version)); -static void prt_dsc_start __ARGS((void)); -static void prt_dsc_noarg __ARGS((char *comment)); -static void prt_dsc_textline __ARGS((char *comment, char *text)); -static void prt_dsc_text __ARGS((char *comment, char *text)); -static void prt_dsc_ints __ARGS((char *comment, int count, int *ints)); -static void prt_dsc_requirements __ARGS((int duplex, int tumble, int collate, int color, int num_copies)); -static void prt_dsc_docmedia __ARGS((char *paper_name, double width, double height, double weight, char *colour, char *type)); -static void prt_dsc_resources __ARGS((char *comment, char *type, char *strings)); -static void prt_dsc_font_resource __ARGS((char *resource, struct prt_ps_font_S *ps_font)); -static float to_device_units __ARGS((int idx, double physsize, int def_number)); -static void prt_page_margins __ARGS((double width, double height, double *left, double *right, double *top, double *bottom)); -static void prt_font_metrics __ARGS((int font_scale)); -static int prt_get_cpl __ARGS((void)); -static int prt_get_lpp __ARGS((void)); -static int prt_add_resource __ARGS((struct prt_ps_resource_S *resource)); -static int prt_resfile_next_line __ARGS((void)); -static int prt_resfile_strncmp __ARGS((int offset, char *string, int len)); -static int prt_resfile_skip_nonws __ARGS((int offset)); -static int prt_resfile_skip_ws __ARGS((int offset)); -static int prt_next_dsc __ARGS((struct prt_dsc_line_S *p_dsc_line)); -#ifdef FEAT_MBYTE -static int prt_build_cid_fontname __ARGS((int font, char_u *name, int name_len)); -static void prt_def_cidfont __ARGS((char *new_name, int height, char *cidfont)); -static void prt_dup_cidfont __ARGS((char *original_name, char *new_name)); -static int prt_match_encoding __ARGS((char *p_encoding, struct prt_ps_mbfont_S *p_cmap, struct prt_ps_encoding_S **pp_mbenc)); -static int prt_match_charset __ARGS((char *p_charset, struct prt_ps_mbfont_S *p_cmap, struct prt_ps_charset_S **pp_mbchar)); -#endif - -/* - * Variables for the output PostScript file. - */ -static FILE *prt_ps_fd; -static int prt_file_error; -static char_u *prt_ps_file_name = NULL; - -/* - * Various offsets and dimensions in default PostScript user space (points). - * Used for text positioning calculations - */ -static float prt_page_width; -static float prt_page_height; -static float prt_left_margin; -static float prt_right_margin; -static float prt_top_margin; -static float prt_bottom_margin; -static float prt_line_height; -static float prt_first_line_height; -static float prt_char_width; -static float prt_number_width; -static float prt_bgcol_offset; -static float prt_pos_x_moveto = 0.0; -static float prt_pos_y_moveto = 0.0; - -/* - * Various control variables used to decide when and how to change the - * PostScript graphics state. - */ -static int prt_need_moveto; -static int prt_do_moveto; -static int prt_need_font; -static int prt_font; -static int prt_need_underline; -static int prt_underline; -static int prt_do_underline; -static int prt_need_fgcol; -static int prt_fgcol; -static int prt_need_bgcol; -static int prt_do_bgcol; -static int prt_bgcol; -static int prt_new_bgcol; -static int prt_attribute_change; -static float prt_text_run; -static int prt_page_num; -static int prt_bufsiz; - -/* - * Variables controlling physical printing. - */ -static int prt_media; -static int prt_portrait; -static int prt_num_copies; -static int prt_duplex; -static int prt_tumble; -static int prt_collate; - -/* - * Buffers used when generating PostScript output - */ -static char_u prt_line_buffer[257]; -static garray_T prt_ps_buffer; - -# ifdef FEAT_MBYTE -static int prt_do_conv; -static vimconv_T prt_conv; - -static int prt_out_mbyte; -static int prt_custom_cmap; -static char prt_cmap[80]; -static int prt_use_courier; -static int prt_in_ascii; -static int prt_half_width; -static char *prt_ascii_encoding; -static char_u prt_hexchar[] = "0123456789abcdef"; -# endif - - static void -prt_write_file_raw_len(buffer, bytes) - char_u *buffer; - int bytes; -{ - if (!prt_file_error - && fwrite(buffer, sizeof(char_u), bytes, prt_ps_fd) - != (size_t)bytes) - { - EMSG(_("E455: Error writing to PostScript output file")); - prt_file_error = TRUE; - } -} - - static void -prt_write_file(buffer) - char_u *buffer; -{ - prt_write_file_len(buffer, STRLEN(buffer)); -} - - static void -prt_write_file_len(buffer, bytes) - char_u *buffer; - int bytes; -{ -#ifdef EBCDIC - ebcdic2ascii(buffer, bytes); -#endif - prt_write_file_raw_len(buffer, bytes); -} - -/* - * Write a string. - */ - static void -prt_write_string(s) - char *s; -{ - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), "%s", s); - prt_write_file(prt_line_buffer); -} - -/* - * Write an int and a space. - */ - static void -prt_write_int(i) - int i; -{ - sprintf((char *)prt_line_buffer, "%d ", i); - prt_write_file(prt_line_buffer); -} - -/* - * Write a boolean and a space. - */ - static void -prt_write_boolean(b) - int b; -{ - sprintf((char *)prt_line_buffer, "%s ", (b ? "T" : "F")); - prt_write_file(prt_line_buffer); -} - -/* - * Write PostScript to re-encode and define the font. - */ - static void -prt_def_font(new_name, encoding, height, font) - char *new_name; - char *encoding; - int height; - char *font; -{ - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "/_%s /VIM-%s /%s ref\n", new_name, encoding, font); - prt_write_file(prt_line_buffer); -#ifdef FEAT_MBYTE - if (prt_out_mbyte) - sprintf((char *)prt_line_buffer, "/%s %d %f /_%s sffs\n", - new_name, height, 500./prt_ps_courier_font.wx, new_name); - else -#endif - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "/%s %d /_%s ffs\n", new_name, height, new_name); - prt_write_file(prt_line_buffer); -} - -#ifdef FEAT_MBYTE -/* - * Write a line to define the CID font. - */ - static void -prt_def_cidfont(new_name, height, cidfont) - char *new_name; - int height; - char *cidfont; -{ - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "/_%s /%s[/%s] vim_composefont\n", new_name, prt_cmap, cidfont); - prt_write_file(prt_line_buffer); - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "/%s %d /_%s ffs\n", new_name, height, new_name); - prt_write_file(prt_line_buffer); -} - -/* - * Write a line to define a duplicate of a CID font - */ - static void -prt_dup_cidfont(original_name, new_name) - char *original_name; - char *new_name; -{ - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "/%s %s d\n", new_name, original_name); - prt_write_file(prt_line_buffer); -} -#endif - -/* - * Convert a real value into an integer and fractional part as integers, with - * the fractional part being in the range [0,10^precision). The fractional part - * is also rounded based on the precision + 1'th fractional digit. - */ - static void -prt_real_bits(real, precision, pinteger, pfraction) - double real; - int precision; - int *pinteger; - int *pfraction; -{ - int i; - int integer; - float fraction; - - integer = (int)real; - fraction = (float)(real - integer); - if (real < (double)integer) - fraction = -fraction; - for (i = 0; i < precision; i++) - fraction *= 10.0; - - *pinteger = integer; - *pfraction = (int)(fraction + 0.5); -} - -/* - * Write a real and a space. Save bytes if real value has no fractional part! - * We use prt_real_bits() as %f in sprintf uses the locale setting to decide - * what decimal point character to use, but PS always requires a '.'. - */ - static void -prt_write_real(val, prec) - double val; - int prec; -{ - int integer; - int fraction; - - prt_real_bits(val, prec, &integer, &fraction); - /* Emit integer part */ - sprintf((char *)prt_line_buffer, "%d", integer); - prt_write_file(prt_line_buffer); - /* Only emit fraction if necessary */ - if (fraction != 0) - { - /* Remove any trailing zeros */ - while ((fraction % 10) == 0) - { - prec--; - fraction /= 10; - } - /* Emit fraction left padded with zeros */ - sprintf((char *)prt_line_buffer, ".%0*d", prec, fraction); - prt_write_file(prt_line_buffer); - } - sprintf((char *)prt_line_buffer, " "); - prt_write_file(prt_line_buffer); -} - -/* - * Write a line to define a numeric variable. - */ - static void -prt_def_var(name, value, prec) - char *name; - double value; - int prec; -{ - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "/%s ", name); - prt_write_file(prt_line_buffer); - prt_write_real(value, prec); - sprintf((char *)prt_line_buffer, "d\n"); - prt_write_file(prt_line_buffer); -} - -/* Convert size from font space to user space at current font scale */ -#define PRT_PS_FONT_TO_USER(scale, size) ((size) * ((scale)/1000.0)) - - static void -prt_flush_buffer() -{ - if (prt_ps_buffer.ga_len > 0) - { - /* Any background color must be drawn first */ - if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE)) - { - int r, g, b; - - if (prt_do_moveto) - { - prt_write_real(prt_pos_x_moveto, 2); - prt_write_real(prt_pos_y_moveto, 2); - prt_write_string("m\n"); - prt_do_moveto = FALSE; - } - - /* Size of rect of background color on which text is printed */ - prt_write_real(prt_text_run, 2); - prt_write_real(prt_line_height, 2); - - /* Lastly add the color of the background */ - r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16; - g = ((unsigned)prt_new_bgcol & 0xff00) >> 8; - b = prt_new_bgcol & 0xff; - prt_write_real(r / 255.0, 3); - prt_write_real(g / 255.0, 3); - prt_write_real(b / 255.0, 3); - prt_write_string("bg\n"); - } - /* Draw underlines before the text as it makes it slightly easier to - * find the starting point. - */ - if (prt_do_underline) - { - if (prt_do_moveto) - { - prt_write_real(prt_pos_x_moveto, 2); - prt_write_real(prt_pos_y_moveto, 2); - prt_write_string("m\n"); - prt_do_moveto = FALSE; - } - - /* Underline length of text run */ - prt_write_real(prt_text_run, 2); - prt_write_string("ul\n"); - } - /* Draw the text - * Note: we write text out raw - EBCDIC conversion is handled in the - * PostScript world via the font encoding vector. */ -#ifdef FEAT_MBYTE - if (prt_out_mbyte) - prt_write_string("<"); - else -#endif - prt_write_string("("); - prt_write_file_raw_len(prt_ps_buffer.ga_data, prt_ps_buffer.ga_len); -#ifdef FEAT_MBYTE - if (prt_out_mbyte) - prt_write_string(">"); - else -#endif - prt_write_string(")"); - /* Add a moveto if need be and use the appropriate show procedure */ - if (prt_do_moveto) - { - prt_write_real(prt_pos_x_moveto, 2); - prt_write_real(prt_pos_y_moveto, 2); - /* moveto and a show */ - prt_write_string("ms\n"); - prt_do_moveto = FALSE; - } - else /* Simple show */ - prt_write_string("s\n"); - - ga_clear(&prt_ps_buffer); - ga_init2(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz); - } -} - - - static void -prt_resource_name(filename, cookie) - char_u *filename; - void *cookie; -{ - char_u *resource_filename = cookie; - - if (STRLEN(filename) >= MAXPATHL) - *resource_filename = NUL; - else - STRCPY(resource_filename, filename); -} - - static int -prt_find_resource(name, resource) - char *name; - struct prt_ps_resource_S *resource; -{ - char_u buffer[MAXPATHL + 1]; - - STRCPY(resource->name, name); - /* Look for named resource file in runtimepath */ - STRCPY(buffer, "print"); - add_pathsep(buffer); - STRCAT(buffer, name); - STRCAT(buffer, ".ps"); - resource->filename[0] = NUL; - return (do_in_runtimepath(buffer, FALSE, prt_resource_name, - resource->filename) - && resource->filename[0] != NUL); -} - -/* PS CR and LF characters have platform independent values */ -#define PSLF (0x0a) -#define PSCR (0x0d) - -/* Static buffer to read initial comments in a resource file, some can have a - * couple of KB of comments! */ -#define PRT_FILE_BUFFER_LEN (2048) -struct prt_resfile_buffer_S -{ - char_u buffer[PRT_FILE_BUFFER_LEN]; - int len; - int line_start; - int line_end; -}; - -static struct prt_resfile_buffer_S prt_resfile; - - static int -prt_resfile_next_line() -{ - int index; - - /* Move to start of next line and then find end of line */ - index = prt_resfile.line_end + 1; - while (index < prt_resfile.len) - { - if (prt_resfile.buffer[index] != PSLF && prt_resfile.buffer[index] - != PSCR) - break; - index++; - } - prt_resfile.line_start = index; - - while (index < prt_resfile.len) - { - if (prt_resfile.buffer[index] == PSLF || prt_resfile.buffer[index] - == PSCR) - break; - index++; - } - prt_resfile.line_end = index; - - return (index < prt_resfile.len); -} - - static int -prt_resfile_strncmp(offset, string, len) - int offset; - char *string; - int len; -{ - /* Force not equal if string is longer than remainder of line */ - if (len > (prt_resfile.line_end - (prt_resfile.line_start + offset))) - return 1; - - return STRNCMP(&prt_resfile.buffer[prt_resfile.line_start + offset], - string, len); -} - - static int -prt_resfile_skip_nonws(offset) - int offset; -{ - int index; - - index = prt_resfile.line_start + offset; - while (index < prt_resfile.line_end) - { - if (isspace(prt_resfile.buffer[index])) - return index - prt_resfile.line_start; - index++; - } - return -1; -} - - static int -prt_resfile_skip_ws(offset) - int offset; -{ - int index; - - index = prt_resfile.line_start + offset; - while (index < prt_resfile.line_end) - { - if (!isspace(prt_resfile.buffer[index])) - return index - prt_resfile.line_start; - index++; - } - return -1; -} - -/* prt_next_dsc() - returns detail on next DSC comment line found. Returns true - * if a DSC comment is found, else false */ - static int -prt_next_dsc(p_dsc_line) - struct prt_dsc_line_S *p_dsc_line; -{ - int comment; - int offset; - - /* Move to start of next line */ - if (!prt_resfile_next_line()) - return FALSE; - - /* DSC comments always start %% */ - if (prt_resfile_strncmp(0, "%%", 2) != 0) - return FALSE; - - /* Find type of DSC comment */ - for (comment = 0; comment < NUM_ELEMENTS(prt_dsc_table); comment++) - if (prt_resfile_strncmp(0, prt_dsc_table[comment].string, - prt_dsc_table[comment].len) == 0) - break; - - if (comment != NUM_ELEMENTS(prt_dsc_table)) - { - /* Return type of comment */ - p_dsc_line->type = prt_dsc_table[comment].type; - offset = prt_dsc_table[comment].len; - } - else - { - /* Unrecognised DSC comment, skip to ws after comment leader */ - p_dsc_line->type = PRT_DSC_MISC_TYPE; - offset = prt_resfile_skip_nonws(0); - if (offset == -1) - return FALSE; - } - - /* Skip ws to comment value */ - offset = prt_resfile_skip_ws(offset); - if (offset == -1) - return FALSE; - - p_dsc_line->string = &prt_resfile.buffer[prt_resfile.line_start + offset]; - p_dsc_line->len = prt_resfile.line_end - (prt_resfile.line_start + offset); - - return TRUE; -} - -/* Improved hand crafted parser to get the type, title, and version number of a - * PS resource file so the file details can be added to the DSC header comments. - */ - static int -prt_open_resource(resource) - struct prt_ps_resource_S *resource; -{ - int offset; - int seen_all; - int seen_title; - int seen_version; - FILE *fd_resource; - struct prt_dsc_line_S dsc_line; - - fd_resource = mch_fopen((char *)resource->filename, READBIN); - if (fd_resource == NULL) - { - EMSG2(_("E624: Can't open file \"%s\""), resource->filename); - return FALSE; - } - vim_memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN); - - /* Parse first line to ensure valid resource file */ - prt_resfile.len = fread((char *)prt_resfile.buffer, sizeof(char_u), - PRT_FILE_BUFFER_LEN, fd_resource); - if (ferror(fd_resource)) - { - EMSG2(_("E457: Can't read PostScript resource file \"%s\""), - resource->filename); - fclose(fd_resource); - return FALSE; - } - - prt_resfile.line_end = -1; - prt_resfile.line_start = 0; - if (!prt_resfile_next_line()) - return FALSE; - - offset = 0; - - if (prt_resfile_strncmp(offset, PRT_RESOURCE_HEADER, - STRLEN(PRT_RESOURCE_HEADER)) != 0) - { - EMSG2(_("E618: file \"%s\" is not a PostScript resource file"), - resource->filename); - fclose(fd_resource); - return FALSE; - } - - /* Skip over any version numbers and following ws */ - offset += STRLEN(PRT_RESOURCE_HEADER); - offset = prt_resfile_skip_nonws(offset); - if (offset == -1) - return FALSE; - offset = prt_resfile_skip_ws(offset); - if (offset == -1) - return FALSE; - - if (prt_resfile_strncmp(offset, PRT_RESOURCE_RESOURCE, - STRLEN(PRT_RESOURCE_RESOURCE)) != 0) - { - EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"), - resource->filename); - fclose(fd_resource); - return FALSE; - } - offset += STRLEN(PRT_RESOURCE_RESOURCE); - - /* Decide type of resource in the file */ - if (prt_resfile_strncmp(offset, PRT_RESOURCE_PROCSET, - STRLEN(PRT_RESOURCE_PROCSET)) == 0) - resource->type = PRT_RESOURCE_TYPE_PROCSET; - else if (prt_resfile_strncmp(offset, PRT_RESOURCE_ENCODING, - STRLEN(PRT_RESOURCE_ENCODING)) == 0) - resource->type = PRT_RESOURCE_TYPE_ENCODING; - else if (prt_resfile_strncmp(offset, PRT_RESOURCE_CMAP, - STRLEN(PRT_RESOURCE_CMAP)) == 0) - resource->type = PRT_RESOURCE_TYPE_CMAP; - else - { - EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"), - resource->filename); - fclose(fd_resource); - return FALSE; - } - - /* Look for title and version of resource */ - resource->title[0] = '\0'; - resource->version[0] = '\0'; - seen_title = FALSE; - seen_version = FALSE; - seen_all = FALSE; - while (!seen_all && prt_next_dsc(&dsc_line)) - { - switch (dsc_line.type) - { - case PRT_DSC_TITLE_TYPE: - vim_strncpy(resource->title, dsc_line.string, dsc_line.len); - seen_title = TRUE; - if (seen_version) - seen_all = TRUE; - break; - - case PRT_DSC_VERSION_TYPE: - vim_strncpy(resource->version, dsc_line.string, dsc_line.len); - seen_version = TRUE; - if (seen_title) - seen_all = TRUE; - break; - - case PRT_DSC_ENDCOMMENTS_TYPE: - /* Wont find title or resource after this comment, stop searching */ - seen_all = TRUE; - break; - - case PRT_DSC_MISC_TYPE: - /* Not interested in whatever comment this line had */ - break; - } - } - - if (!seen_title || !seen_version) - { - EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"), - resource->filename); - fclose(fd_resource); - return FALSE; - } - - fclose(fd_resource); - - return TRUE; -} - - static int -prt_check_resource(resource, version) - struct prt_ps_resource_S *resource; - char_u *version; -{ - /* Version number m.n should match, the revision number does not matter */ - if (STRNCMP(resource->version, version, STRLEN(version))) - { - EMSG2(_("E621: \"%s\" resource file has wrong version"), - resource->name); - return FALSE; - } - - /* Other checks to be added as needed */ - return TRUE; -} - - static void -prt_dsc_start() -{ - prt_write_string("%!PS-Adobe-3.0\n"); -} - - static void -prt_dsc_noarg(comment) - char *comment; -{ - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "%%%%%s\n", comment); - prt_write_file(prt_line_buffer); -} - - static void -prt_dsc_textline(comment, text) - char *comment; - char *text; -{ - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "%%%%%s: %s\n", comment, text); - prt_write_file(prt_line_buffer); -} - - static void -prt_dsc_text(comment, text) - char *comment; - char *text; -{ - /* TODO - should scan 'text' for any chars needing escaping! */ - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "%%%%%s: (%s)\n", comment, text); - prt_write_file(prt_line_buffer); -} - -#define prt_dsc_atend(c) prt_dsc_text((c), "atend") - - static void -prt_dsc_ints(comment, count, ints) - char *comment; - int count; - int *ints; -{ - int i; - - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "%%%%%s:", comment); - prt_write_file(prt_line_buffer); - - for (i = 0; i < count; i++) - { - sprintf((char *)prt_line_buffer, " %d", ints[i]); - prt_write_file(prt_line_buffer); - } - - prt_write_string("\n"); -} - - static void -prt_dsc_resources(comment, type, string) - char *comment; /* if NULL add to previous */ - char *type; - char *string; -{ - if (comment != NULL) - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "%%%%%s: %s", comment, type); - else - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "%%%%+ %s", type); - prt_write_file(prt_line_buffer); - - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - " %s\n", string); - prt_write_file(prt_line_buffer); -} - - static void -prt_dsc_font_resource(resource, ps_font) - char *resource; - struct prt_ps_font_S *ps_font; -{ - int i; - - prt_dsc_resources(resource, "font", - ps_font->ps_fontname[PRT_PS_FONT_ROMAN]); - for (i = PRT_PS_FONT_BOLD ; i <= PRT_PS_FONT_BOLDOBLIQUE ; i++) - if (ps_font->ps_fontname[i] != NULL) - prt_dsc_resources(NULL, "font", ps_font->ps_fontname[i]); -} - - static void -prt_dsc_requirements(duplex, tumble, collate, color, num_copies) - int duplex; - int tumble; - int collate; - int color; - int num_copies; -{ - /* Only output the comment if we need to. - * Note: tumble is ignored if we are not duplexing - */ - if (!(duplex || collate || color || (num_copies > 1))) - return; - - sprintf((char *)prt_line_buffer, "%%%%Requirements:"); - prt_write_file(prt_line_buffer); - - if (duplex) - { - prt_write_string(" duplex"); - if (tumble) - prt_write_string("(tumble)"); - } - if (collate) - prt_write_string(" collate"); - if (color) - prt_write_string(" color"); - if (num_copies > 1) - { - prt_write_string(" numcopies("); - /* Note: no space wanted so dont use prt_write_int() */ - sprintf((char *)prt_line_buffer, "%d", num_copies); - prt_write_file(prt_line_buffer); - prt_write_string(")"); - } - prt_write_string("\n"); -} - - static void -prt_dsc_docmedia(paper_name, width, height, weight, colour, type) - char *paper_name; - double width; - double height; - double weight; - char *colour; - char *type; -{ - vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), - "%%%%DocumentMedia: %s ", paper_name); - prt_write_file(prt_line_buffer); - prt_write_real(width, 2); - prt_write_real(height, 2); - prt_write_real(weight, 2); - if (colour == NULL) - prt_write_string("()"); - else - prt_write_string(colour); - prt_write_string(" "); - if (type == NULL) - prt_write_string("()"); - else - prt_write_string(type); - prt_write_string("\n"); -} - - void -mch_print_cleanup() -{ -#ifdef FEAT_MBYTE - if (prt_out_mbyte) - { - int i; - - /* Free off all CID font names created, but first clear duplicate - * pointers to the same string (when the same font is used for more than - * one style). - */ - for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) - { - if (prt_ps_mb_font.ps_fontname[i] != NULL) - vim_free(prt_ps_mb_font.ps_fontname[i]); - prt_ps_mb_font.ps_fontname[i] = NULL; - } - } - - if (prt_do_conv) - { - convert_setup(&prt_conv, NULL, NULL); - prt_do_conv = FALSE; - } -#endif - if (prt_ps_fd != NULL) - { - fclose(prt_ps_fd); - prt_ps_fd = NULL; - prt_file_error = FALSE; - } - if (prt_ps_file_name != NULL) - { - vim_free(prt_ps_file_name); - prt_ps_file_name = NULL; - } -} - - static float -to_device_units(idx, physsize, def_number) - int idx; - double physsize; - int def_number; -{ - float ret; - int u; - int nr; - - u = prt_get_unit(idx); - if (u == PRT_UNIT_NONE) - { - u = PRT_UNIT_PERC; - nr = def_number; - } - else - nr = printer_opts[idx].number; - - switch (u) - { - case PRT_UNIT_INCH: - ret = (float)(nr * PRT_PS_DEFAULT_DPI); - break; - case PRT_UNIT_MM: - ret = (float)(nr * PRT_PS_DEFAULT_DPI) / (float)25.4; - break; - case PRT_UNIT_POINT: - ret = (float)nr; - break; - case PRT_UNIT_PERC: - default: - ret = (float)(physsize * nr) / 100; - break; - } - - return ret; -} - -/* - * Calculate margins for given width and height from printoptions settings. - */ - static void -prt_page_margins(width, height, left, right, top, bottom) - double width; - double height; - double *left; - double *right; - double *top; - double *bottom; -{ - *left = to_device_units(OPT_PRINT_LEFT, width, 10); - *right = width - to_device_units(OPT_PRINT_RIGHT, width, 5); - *top = height - to_device_units(OPT_PRINT_TOP, height, 5); - *bottom = to_device_units(OPT_PRINT_BOT, height, 5); -} - - static void -prt_font_metrics(font_scale) - int font_scale; -{ - prt_line_height = (float)font_scale; - prt_char_width = (float)PRT_PS_FONT_TO_USER(font_scale, prt_ps_font->wx); -} - - - static int -prt_get_cpl() -{ - if (prt_use_number()) - { - prt_number_width = PRINT_NUMBER_WIDTH * prt_char_width; -#ifdef FEAT_MBYTE - /* If we are outputting multi-byte characters then line numbers will be - * printed with half width characters - */ - if (prt_out_mbyte) - prt_number_width /= 2; -#endif - prt_left_margin += prt_number_width; - } - else - prt_number_width = 0.0; - - return (int)((prt_right_margin - prt_left_margin) / prt_char_width); -} - -#ifdef FEAT_MBYTE - static int -prt_build_cid_fontname(font, name, name_len) - int font; - char_u *name; - int name_len; -{ - char *fontname; - - fontname = (char *)alloc(name_len + 1); - if (fontname == NULL) - return FALSE; - vim_strncpy((char_u *)fontname, name, name_len); - prt_ps_mb_font.ps_fontname[font] = fontname; - - return TRUE; -} -#endif - -/* - * Get number of lines of text that fit on a page (excluding the header). - */ - static int -prt_get_lpp() -{ - int lpp; - - /* - * Calculate offset to lower left corner of background rect based on actual - * font height (based on its bounding box) and the line height, handling the - * case where the font height can exceed the line height. - */ - prt_bgcol_offset = (float)PRT_PS_FONT_TO_USER(prt_line_height, - prt_ps_font->bbox_min_y); - if ((prt_ps_font->bbox_max_y - prt_ps_font->bbox_min_y) < 1000.0) - { - prt_bgcol_offset -= (float)PRT_PS_FONT_TO_USER(prt_line_height, - (1000.0 - (prt_ps_font->bbox_max_y - - prt_ps_font->bbox_min_y)) / 2); - } - - /* Get height for topmost line based on background rect offset. */ - prt_first_line_height = prt_line_height + prt_bgcol_offset; - - /* Calculate lpp */ - lpp = (int)((prt_top_margin - prt_bottom_margin) / prt_line_height); - - /* Adjust top margin if there is a header */ - prt_top_margin -= prt_line_height * prt_header_height(); - - return lpp - prt_header_height(); -} - -#ifdef FEAT_MBYTE - static int -prt_match_encoding(p_encoding, p_cmap, pp_mbenc) - char *p_encoding; - struct prt_ps_mbfont_S *p_cmap; - struct prt_ps_encoding_S **pp_mbenc; -{ - int mbenc; - int enc_len; - struct prt_ps_encoding_S *p_mbenc; - - *pp_mbenc = NULL; - /* Look for recognised encoding */ - enc_len = STRLEN(p_encoding); - p_mbenc = p_cmap->encodings; - for (mbenc = 0; mbenc < p_cmap->num_encodings; mbenc++) - { - if (STRNICMP(p_mbenc->encoding, p_encoding, enc_len) == 0) - { - *pp_mbenc = p_mbenc; - return TRUE; - } - p_mbenc++; - } - return FALSE; -} - - static int -prt_match_charset(p_charset, p_cmap, pp_mbchar) - char *p_charset; - struct prt_ps_mbfont_S *p_cmap; - struct prt_ps_charset_S **pp_mbchar; -{ - int mbchar; - int char_len; - struct prt_ps_charset_S *p_mbchar; - - /* Look for recognised character set, using default if one is not given */ - if (*p_charset == NUL) - p_charset = p_cmap->defcs; - char_len = STRLEN(p_charset); - p_mbchar = p_cmap->charsets; - for (mbchar = 0; mbchar < p_cmap->num_charsets; mbchar++) - { - if (STRNICMP(p_mbchar->charset, p_charset, char_len) == 0) - { - *pp_mbchar = p_mbchar; - return TRUE; - } - p_mbchar++; - } - return FALSE; -} -#endif - -/*ARGSUSED*/ - int -mch_print_init(psettings, jobname, forceit) - prt_settings_T *psettings; - char_u *jobname; - int forceit; -{ - int i; - char *paper_name; - int paper_strlen; - int fontsize; - char_u *p; - double left; - double right; - double top; - double bottom; -#ifdef FEAT_MBYTE - int cmap; - char_u *p_encoding; - struct prt_ps_encoding_S *p_mbenc; - struct prt_ps_encoding_S *p_mbenc_first; - struct prt_ps_charset_S *p_mbchar; -#endif - -#if 0 - /* - * TODO: - * If "forceit" is false: pop up a dialog to select: - * - printer name - * - copies - * - collated/uncollated - * - duplex off/long side/short side - * - paper size - * - portrait/landscape - * - font size - * - * If "forceit" is true: use the default printer and settings - */ - if (forceit) - s_pd.Flags |= PD_RETURNDEFAULT; -#endif - - /* - * Set up font and encoding. - */ -#ifdef FEAT_MBYTE - p_encoding = enc_skip(p_penc); - if (*p_encoding == NUL) - p_encoding = enc_skip(p_enc); - - /* Look for recognised multi-byte coding, and if the charset is recognised. - * This is to cope with the fact that various unicode encodings are - * supported in more than one of CJK. */ - p_mbenc = NULL; - p_mbenc_first = NULL; - p_mbchar = NULL; - for (cmap = 0; cmap < NUM_ELEMENTS(prt_ps_mbfonts); cmap++) - if (prt_match_encoding((char *)p_encoding, &prt_ps_mbfonts[cmap], - &p_mbenc)) - { - if (p_mbenc_first == NULL) - p_mbenc_first = p_mbenc; - if (prt_match_charset((char *)p_pmcs, &prt_ps_mbfonts[cmap], - &p_mbchar)) - break; - } - - /* Use first encoding matched if no charset matched */ - if (p_mbchar == NULL && p_mbenc_first != NULL) - p_mbenc = p_mbenc_first; - - prt_out_mbyte = (p_mbenc != NULL); - if (prt_out_mbyte) - { - /* Build CMap name - will be same for all multi-byte fonts used */ - prt_cmap[0] = NUL; - - prt_custom_cmap = prt_out_mbyte && p_mbchar == NULL; - - if (!prt_custom_cmap) - { - /* Check encoding and character set are compatible */ - if ((p_mbenc->needs_charset&p_mbchar->has_charset) == 0) - { - EMSG(_("E673: Incompatible multi-byte encoding and character set.")); - return FALSE; - } - - /* Add charset name if not empty */ - if (p_mbchar->cmap_charset != NULL) - { - vim_strncpy((char_u *)prt_cmap, - (char_u *)p_mbchar->cmap_charset, sizeof(prt_cmap) - 3); - STRCAT(prt_cmap, "-"); - } - } - else - { - /* Add custom CMap character set name */ - if (*p_pmcs == NUL) - { - EMSG(_("E674: printmbcharset cannot be empty with multi-byte encoding.")); - return FALSE; - } - vim_strncpy((char_u *)prt_cmap, p_pmcs, sizeof(prt_cmap) - 3); - STRCAT(prt_cmap, "-"); - } - - /* CMap name ends with (optional) encoding name and -H for horizontal */ - if (p_mbenc->cmap_encoding != NULL && STRLEN(prt_cmap) - + STRLEN(p_mbenc->cmap_encoding) + 3 < sizeof(prt_cmap)) - { - STRCAT(prt_cmap, p_mbenc->cmap_encoding); - STRCAT(prt_cmap, "-"); - } - STRCAT(prt_cmap, "H"); - - if (!mbfont_opts[OPT_MBFONT_REGULAR].present) - { - EMSG(_("E675: No default font specified for multi-byte printing.")); - return FALSE; - } - - /* Derive CID font names with fallbacks if not defined */ - if (!prt_build_cid_fontname(PRT_PS_FONT_ROMAN, - mbfont_opts[OPT_MBFONT_REGULAR].string, - mbfont_opts[OPT_MBFONT_REGULAR].strlen)) - return FALSE; - if (mbfont_opts[OPT_MBFONT_BOLD].present) - if (!prt_build_cid_fontname(PRT_PS_FONT_BOLD, - mbfont_opts[OPT_MBFONT_BOLD].string, - mbfont_opts[OPT_MBFONT_BOLD].strlen)) - return FALSE; - if (mbfont_opts[OPT_MBFONT_OBLIQUE].present) - if (!prt_build_cid_fontname(PRT_PS_FONT_OBLIQUE, - mbfont_opts[OPT_MBFONT_OBLIQUE].string, - mbfont_opts[OPT_MBFONT_OBLIQUE].strlen)) - return FALSE; - if (mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].present) - if (!prt_build_cid_fontname(PRT_PS_FONT_BOLDOBLIQUE, - mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].string, - mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen)) - return FALSE; - - /* Check if need to use Courier for ASCII code range, and if so pick up - * the encoding to use */ - prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present && - (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) == 'y'); - if (prt_use_courier) - { - /* Use national ASCII variant unless ASCII wanted */ - if (mbfont_opts[OPT_MBFONT_ASCII].present && - (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y')) - prt_ascii_encoding = "ascii"; - else - prt_ascii_encoding = prt_ps_mbfonts[cmap].ascii_enc; - } - - prt_ps_font = &prt_ps_mb_font; - } - else -#endif - { -#ifdef FEAT_MBYTE - prt_use_courier = FALSE; -#endif - prt_ps_font = &prt_ps_courier_font; - } - - /* - * Find the size of the paper and set the margins. - */ - prt_portrait = (!printer_opts[OPT_PRINT_PORTRAIT].present - || TOLOWER_ASC(printer_opts[OPT_PRINT_PORTRAIT].string[0]) == 'y'); - if (printer_opts[OPT_PRINT_PAPER].present) - { - paper_name = (char *)printer_opts[OPT_PRINT_PAPER].string; - paper_strlen = printer_opts[OPT_PRINT_PAPER].strlen; - } - else - { - paper_name = "A4"; - paper_strlen = 2; - } - for (i = 0; i < PRT_MEDIASIZE_LEN; ++i) - if (STRLEN(prt_mediasize[i].name) == (unsigned)paper_strlen - && STRNICMP(prt_mediasize[i].name, paper_name, - paper_strlen) == 0) - break; - if (i == PRT_MEDIASIZE_LEN) - i = 0; - prt_media = i; - - /* - * Set PS pagesize based on media dimensions and print orientation. - * Note: Media and page sizes have defined meanings in PostScript and should - * be kept distinct. Media is the paper (or transparency, or ...) that is - * printed on, whereas the page size is the area that the PostScript - * interpreter renders into. - */ - if (prt_portrait) - { - prt_page_width = prt_mediasize[i].width; - prt_page_height = prt_mediasize[i].height; - } - else - { - prt_page_width = prt_mediasize[i].height; - prt_page_height = prt_mediasize[i].width; - } - - /* - * Set PS page margins based on the PS pagesize, not the mediasize - this - * needs to be done before the cpl and lpp are calculated. - */ - prt_page_margins(prt_page_width, prt_page_height, &left, &right, &top, - &bottom); - prt_left_margin = (float)left; - prt_right_margin = (float)right; - prt_top_margin = (float)top; - prt_bottom_margin = (float)bottom; - - /* - * Set up the font size. - */ - fontsize = PRT_PS_DEFAULT_FONTSIZE; - for (p = p_pfn; (p = vim_strchr(p, ':')) != NULL; ++p) - if (p[1] == 'h' && VIM_ISDIGIT(p[2])) - fontsize = atoi((char *)p + 2); - prt_font_metrics(fontsize); - - /* - * Return the number of characters per line, and lines per page for the - * generic print code. - */ - psettings->chars_per_line = prt_get_cpl(); - psettings->lines_per_page = prt_get_lpp(); - - /* Catch margin settings that leave no space for output! */ - if (psettings->chars_per_line <= 0 || psettings->lines_per_page <= 0) - return FAIL; - - /* - * Sort out the number of copies to be printed. PS by default will do - * uncollated copies for you, so once we know how many uncollated copies are - * wanted cache it away and lie to the generic code that we only want one - * uncollated copy. - */ - psettings->n_collated_copies = 1; - psettings->n_uncollated_copies = 1; - prt_num_copies = 1; - prt_collate = (!printer_opts[OPT_PRINT_COLLATE].present - || TOLOWER_ASC(printer_opts[OPT_PRINT_COLLATE].string[0]) == 'y'); - if (prt_collate) - { - /* TODO: Get number of collated copies wanted. */ - psettings->n_collated_copies = 1; - } - else - { - /* TODO: Get number of uncollated copies wanted and update the cached - * count. - */ - prt_num_copies = 1; - } - - psettings->jobname = jobname; - - /* - * Set up printer duplex and tumble based on Duplex option setting - default - * is long sided duplex printing (i.e. no tumble). - */ - prt_duplex = TRUE; - prt_tumble = FALSE; - psettings->duplex = 1; - if (printer_opts[OPT_PRINT_DUPLEX].present) - { - if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "off", 3) == 0) - { - prt_duplex = FALSE; - psettings->duplex = 0; - } - else if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "short", 5) - == 0) - prt_tumble = TRUE; - } - - /* For now user abort not supported */ - psettings->user_abort = 0; - - /* If the user didn't specify a file name, use a temp file. */ - if (psettings->outfile == NULL) - { - prt_ps_file_name = vim_tempname('p'); - if (prt_ps_file_name == NULL) - { - EMSG(_(e_notmp)); - return FAIL; - } - prt_ps_fd = mch_fopen((char *)prt_ps_file_name, WRITEBIN); - } - else - { - p = expand_env_save(psettings->outfile); - if (p != NULL) - { - prt_ps_fd = mch_fopen((char *)p, WRITEBIN); - vim_free(p); - } - } - if (prt_ps_fd == NULL) - { - EMSG(_("E324: Can't open PostScript output file")); - mch_print_cleanup(); - return FAIL; - } - - prt_bufsiz = psettings->chars_per_line; -#ifdef FEAT_MBYTE - if (prt_out_mbyte) - prt_bufsiz *= 2; -#endif - ga_init2(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz); - - prt_page_num = 0; - - prt_attribute_change = FALSE; - prt_need_moveto = FALSE; - prt_need_font = FALSE; - prt_need_fgcol = FALSE; - prt_need_bgcol = FALSE; - prt_need_underline = FALSE; - - prt_file_error = FALSE; - - return OK; -} - - static int -prt_add_resource(resource) - struct prt_ps_resource_S *resource; -{ - FILE* fd_resource; - char_u resource_buffer[512]; - size_t bytes_read; - - fd_resource = mch_fopen((char *)resource->filename, READBIN); - if (fd_resource == NULL) - { - EMSG2(_("E456: Can't open file \"%s\""), resource->filename); - return FALSE; - } - prt_dsc_resources("BeginResource", prt_resource_types[resource->type], - (char *)resource->title); - - prt_dsc_textline("BeginDocument", (char *)resource->filename); - - for (;;) - { - bytes_read = fread((char *)resource_buffer, sizeof(char_u), - sizeof(resource_buffer), fd_resource); - if (ferror(fd_resource)) - { - EMSG2(_("E457: Can't read PostScript resource file \"%s\""), - resource->filename); - fclose(fd_resource); - return FALSE; - } - if (bytes_read == 0) - break; - prt_write_file_raw_len(resource_buffer, bytes_read); - if (prt_file_error) - { - fclose(fd_resource); - return FALSE; - } - } - fclose(fd_resource); - - prt_dsc_noarg("EndDocument"); - - prt_dsc_noarg("EndResource"); - - return TRUE; -} - - int -mch_print_begin(psettings) - prt_settings_T *psettings; -{ - time_t now; - int bbox[4]; - char *p_time; - double left; - double right; - double top; - double bottom; - struct prt_ps_resource_S res_prolog; - struct prt_ps_resource_S res_encoding; - char buffer[256]; - char_u *p_encoding; -#ifdef FEAT_MBYTE - struct prt_ps_resource_S res_cidfont; - struct prt_ps_resource_S res_cmap; -#endif - - /* - * PS DSC Header comments - no PS code! - */ - prt_dsc_start(); - prt_dsc_textline("Title", (char *)psettings->jobname); - if (!get_user_name((char_u *)buffer, 256)) - STRCPY(buffer, "Unknown"); - prt_dsc_textline("For", buffer); - prt_dsc_textline("Creator", VIM_VERSION_LONG); - /* Note: to ensure Clean8bit I don't think we can use LC_TIME */ - now = time(NULL); - p_time = ctime(&now); - /* Note: ctime() adds a \n so we have to remove it :-( */ - *(vim_strchr((char_u *)p_time, '\n')) = '\0'; - prt_dsc_textline("CreationDate", p_time); - prt_dsc_textline("DocumentData", "Clean8Bit"); - prt_dsc_textline("Orientation", "Portrait"); - prt_dsc_atend("Pages"); - prt_dsc_textline("PageOrder", "Ascend"); - /* The bbox does not change with orientation - it is always in the default - * user coordinate system! We have to recalculate right and bottom - * coordinates based on the font metrics for the bbox to be accurate. */ - prt_page_margins(prt_mediasize[prt_media].width, - prt_mediasize[prt_media].height, - &left, &right, &top, &bottom); - bbox[0] = (int)left; - if (prt_portrait) - { - /* In portrait printing the fixed point is the top left corner so we - * derive the bbox from that point. We have the expected cpl chars - * across the media and lpp lines down the media. - */ - bbox[1] = (int)(top - (psettings->lines_per_page + prt_header_height()) - * prt_line_height); - bbox[2] = (int)(left + psettings->chars_per_line * prt_char_width - + 0.5); - bbox[3] = (int)(top + 0.5); - } - else - { - /* In landscape printing the fixed point is the bottom left corner so we - * derive the bbox from that point. We have lpp chars across the media - * and cpl lines up the media. - */ - bbox[1] = (int)bottom; - bbox[2] = (int)(left + ((psettings->lines_per_page - + prt_header_height()) * prt_line_height) + 0.5); - bbox[3] = (int)(bottom + psettings->chars_per_line * prt_char_width - + 0.5); - } - prt_dsc_ints("BoundingBox", 4, bbox); - /* The media width and height does not change with landscape printing! */ - prt_dsc_docmedia(prt_mediasize[prt_media].name, - prt_mediasize[prt_media].width, - prt_mediasize[prt_media].height, - (double)0, NULL, NULL); - /* Define fonts needed */ -#ifdef FEAT_MBYTE - if (!prt_out_mbyte || prt_use_courier) -#endif - prt_dsc_font_resource("DocumentNeededResources", &prt_ps_courier_font); -#ifdef FEAT_MBYTE - if (prt_out_mbyte) - { - prt_dsc_font_resource((prt_use_courier ? NULL - : "DocumentNeededResources"), &prt_ps_mb_font); - if (!prt_custom_cmap) - prt_dsc_resources(NULL, "cmap", prt_cmap); - } -#endif - - /* Search for external resources VIM supplies */ - if (!prt_find_resource("prolog", &res_prolog)) - { - EMSG(_("E456: Can't find PostScript resource file \"prolog.ps\"")); - return FALSE; - } - if (!prt_open_resource(&res_prolog)) - return FALSE; - if (!prt_check_resource(&res_prolog, PRT_PROLOG_VERSION)) - return FALSE; -#ifdef FEAT_MBYTE - if (prt_out_mbyte) - { - /* Look for required version of multi-byte printing procset */ - if (!prt_find_resource("cidfont", &res_cidfont)) - { - EMSG(_("E456: Can't find PostScript resource file \"cidfont.ps\"")); - return FALSE; - } - if (!prt_open_resource(&res_cidfont)) - return FALSE; - if (!prt_check_resource(&res_cidfont, PRT_CID_PROLOG_VERSION)) - return FALSE; - } -#endif - - /* Find an encoding to use for printing. - * Check 'printencoding'. If not set or not found, then use 'encoding'. If - * that cannot be found then default to "latin1". - * Note: VIM specific encoding header is always skipped. - */ -#ifdef FEAT_MBYTE - if (!prt_out_mbyte) - { -#endif - p_encoding = enc_skip(p_penc); - if (*p_encoding == NUL - || !prt_find_resource((char *)p_encoding, &res_encoding)) - { - /* 'printencoding' not set or not supported - find alternate */ -#ifdef FEAT_MBYTE - int props; - - p_encoding = enc_skip(p_enc); - props = enc_canon_props(p_encoding); - if (!(props & ENC_8BIT) - || !prt_find_resource((char *)p_encoding, &res_encoding)) - /* 8-bit 'encoding' is not supported */ -#endif - { - /* Use latin1 as default printing encoding */ - p_encoding = (char_u *)"latin1"; - if (!prt_find_resource((char *)p_encoding, &res_encoding)) - { - EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), - p_encoding); - return FALSE; - } - } - } - if (!prt_open_resource(&res_encoding)) - return FALSE; - /* For the moment there are no checks on encoding resource files to - * perform */ -#ifdef FEAT_MBYTE - } - else - { - p_encoding = enc_skip(p_penc); - if (*p_encoding == NUL) - p_encoding = enc_skip(p_enc); - if (prt_use_courier) - { - /* Include ASCII range encoding vector */ - if (!prt_find_resource(prt_ascii_encoding, &res_encoding)) - { - EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), - prt_ascii_encoding); - return FALSE; - } - if (!prt_open_resource(&res_encoding)) - return FALSE; - /* For the moment there are no checks on encoding resource files to - * perform */ - } - } - - prt_conv.vc_type = CONV_NONE; - if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) { - /* Set up encoding conversion if required */ - if (FAIL == convert_setup(&prt_conv, p_enc, p_encoding)) - { - EMSG2(_("E620: Unable to convert to print encoding \"%s\""), - p_encoding); - return FALSE; - } - prt_do_conv = TRUE; - } - prt_do_conv = prt_conv.vc_type != CONV_NONE; - - if (prt_out_mbyte && prt_custom_cmap) - { - /* Find user supplied CMap */ - if (!prt_find_resource(prt_cmap, &res_cmap)) - { - EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), - prt_cmap); - return FALSE; - } - if (!prt_open_resource(&res_cmap)) - return FALSE; - } -#endif - - /* List resources supplied */ - STRCPY(buffer, res_prolog.title); - STRCAT(buffer, " "); - STRCAT(buffer, res_prolog.version); - prt_dsc_resources("DocumentSuppliedResources", "procset", buffer); -#ifdef FEAT_MBYTE - if (prt_out_mbyte) - { - STRCPY(buffer, res_cidfont.title); - STRCAT(buffer, " "); - STRCAT(buffer, res_cidfont.version); - prt_dsc_resources(NULL, "procset", buffer); - - if (prt_custom_cmap) - { - STRCPY(buffer, res_cmap.title); - STRCAT(buffer, " "); - STRCAT(buffer, res_cmap.version); - prt_dsc_resources(NULL, "cmap", buffer); - } - } - if (!prt_out_mbyte || prt_use_courier) -#endif - { - STRCPY(buffer, res_encoding.title); - STRCAT(buffer, " "); - STRCAT(buffer, res_encoding.version); - prt_dsc_resources(NULL, "encoding", buffer); - } - prt_dsc_requirements(prt_duplex, prt_tumble, prt_collate, -#ifdef FEAT_SYN_HL - psettings->do_syntax -#else - 0 -#endif - , prt_num_copies); - prt_dsc_noarg("EndComments"); - - /* - * PS Document page defaults - */ - prt_dsc_noarg("BeginDefaults"); - - /* List font resources most likely common to all pages */ -#ifdef FEAT_MBYTE - if (!prt_out_mbyte || prt_use_courier) -#endif - prt_dsc_font_resource("PageResources", &prt_ps_courier_font); -#ifdef FEAT_MBYTE - if (prt_out_mbyte) - { - prt_dsc_font_resource((prt_use_courier ? NULL : "PageResources"), - &prt_ps_mb_font); - if (!prt_custom_cmap) - prt_dsc_resources(NULL, "cmap", prt_cmap); - } -#endif - - /* Paper will be used for all pages */ - prt_dsc_textline("PageMedia", prt_mediasize[prt_media].name); - - prt_dsc_noarg("EndDefaults"); - - /* - * PS Document prolog inclusion - all required procsets. - */ - prt_dsc_noarg("BeginProlog"); - - /* Add required procsets - NOTE: order is important! */ - if (!prt_add_resource(&res_prolog)) - return FALSE; -#ifdef FEAT_MBYTE - if (prt_out_mbyte) - { - /* Add CID font procset, and any user supplied CMap */ - if (!prt_add_resource(&res_cidfont)) - return FALSE; - if (prt_custom_cmap && !prt_add_resource(&res_cmap)) - return FALSE; - } -#endif - -#ifdef FEAT_MBYTE - if (!prt_out_mbyte || prt_use_courier) -#endif - /* There will be only one Roman font encoding to be included in the PS - * file. */ - if (!prt_add_resource(&res_encoding)) - return FALSE; - - prt_dsc_noarg("EndProlog"); - - /* - * PS Document setup - must appear after the prolog - */ - prt_dsc_noarg("BeginSetup"); - - /* Device setup - page size and number of uncollated copies */ - prt_write_int((int)prt_mediasize[prt_media].width); - prt_write_int((int)prt_mediasize[prt_media].height); - prt_write_int(0); - prt_write_string("sps\n"); - prt_write_int(prt_num_copies); - prt_write_string("nc\n"); - prt_write_boolean(prt_duplex); - prt_write_boolean(prt_tumble); - prt_write_string("dt\n"); - prt_write_boolean(prt_collate); - prt_write_string("c\n"); - - /* Font resource inclusion and definition */ -#ifdef FEAT_MBYTE - if (!prt_out_mbyte || prt_use_courier) - { - /* When using Courier for ASCII range when printing multi-byte, need to - * pick up ASCII encoding to use with it. */ - if (prt_use_courier) - p_encoding = (char_u *)prt_ascii_encoding; -#endif - prt_dsc_resources("IncludeResource", "font", - prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); - prt_def_font("F0", (char *)p_encoding, (int)prt_line_height, - prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); - prt_dsc_resources("IncludeResource", "font", - prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLD]); - prt_def_font("F1", (char *)p_encoding, (int)prt_line_height, - prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLD]); - prt_dsc_resources("IncludeResource", "font", - prt_ps_courier_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); - prt_def_font("F2", (char *)p_encoding, (int)prt_line_height, - prt_ps_courier_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); - prt_dsc_resources("IncludeResource", "font", - prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); - prt_def_font("F3", (char *)p_encoding, (int)prt_line_height, - prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); -#ifdef FEAT_MBYTE - } - if (prt_out_mbyte) - { - /* Define the CID fonts to be used in the job. Typically CJKV fonts do - * not have an italic form being a western style, so where no font is - * defined for these faces VIM falls back to an existing face. - * Note: if using Courier for the ASCII range then the printout will - * have bold/italic/bolditalic regardless of the setting of printmbfont. - */ - prt_dsc_resources("IncludeResource", "font", - prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]); - if (!prt_custom_cmap) - prt_dsc_resources("IncludeResource", "cmap", prt_cmap); - prt_def_cidfont("CF0", (int)prt_line_height, - prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]); - - if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD] != NULL) - { - prt_dsc_resources("IncludeResource", "font", - prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]); - if (!prt_custom_cmap) - prt_dsc_resources("IncludeResource", "cmap", prt_cmap); - prt_def_cidfont("CF1", (int)prt_line_height, - prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]); - } - else - /* Use ROMAN for BOLD */ - prt_dup_cidfont("CF0", "CF1"); - - if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE] != NULL) - { - prt_dsc_resources("IncludeResource", "font", - prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); - if (!prt_custom_cmap) - prt_dsc_resources("IncludeResource", "cmap", prt_cmap); - prt_def_cidfont("CF2", (int)prt_line_height, - prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); - } - else - /* Use ROMAN for OBLIQUE */ - prt_dup_cidfont("CF0", "CF2"); - - if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE] != NULL) - { - prt_dsc_resources("IncludeResource", "font", - prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); - if (!prt_custom_cmap) - prt_dsc_resources("IncludeResource", "cmap", prt_cmap); - prt_def_cidfont("CF3", (int)prt_line_height, - prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); - } - else - /* Use BOLD for BOLDOBLIQUE */ - prt_dup_cidfont("CF1", "CF3"); - } -#endif - - /* Misc constant vars used for underlining and background rects */ - prt_def_var("UO", PRT_PS_FONT_TO_USER(prt_line_height, - prt_ps_font->uline_offset), 2); - prt_def_var("UW", PRT_PS_FONT_TO_USER(prt_line_height, - prt_ps_font->uline_width), 2); - prt_def_var("BO", prt_bgcol_offset, 2); - - prt_dsc_noarg("EndSetup"); - - /* Fail if any problems writing out to the PS file */ - return !prt_file_error; -} - - void -mch_print_end(psettings) - prt_settings_T *psettings; -{ - prt_dsc_noarg("Trailer"); - - /* - * Output any info we don't know in toto until we finish - */ - prt_dsc_ints("Pages", 1, &prt_page_num); - - prt_dsc_noarg("EOF"); - - /* Write CTRL-D to close serial communication link if used. - * NOTHING MUST BE WRITTEN AFTER THIS! */ - prt_write_file((char_u *)IF_EB("\004", "\067")); - - if (!prt_file_error && psettings->outfile == NULL - && !got_int && !psettings->user_abort) - { - /* Close the file first. */ - if (prt_ps_fd != NULL) - { - fclose(prt_ps_fd); - prt_ps_fd = NULL; - } - prt_message((char_u *)_("Sending to printer...")); - - /* Not printing to a file: use 'printexpr' to print the file. */ - if (eval_printexpr(prt_ps_file_name, psettings->arguments) == FAIL) - EMSG(_("E365: Failed to print PostScript file")); - else - prt_message((char_u *)_("Print job sent.")); - } - - mch_print_cleanup(); -} - - int -mch_print_end_page() -{ - prt_flush_buffer(); - - prt_write_string("re sp\n"); - - prt_dsc_noarg("PageTrailer"); - - return !prt_file_error; -} - -/*ARGSUSED*/ - int -mch_print_begin_page(str) - char_u *str; -{ - int page_num[2]; - - prt_page_num++; - - page_num[0] = page_num[1] = prt_page_num; - prt_dsc_ints("Page", 2, page_num); - - prt_dsc_noarg("BeginPageSetup"); - - prt_write_string("sv\n0 g\n"); -#ifdef FEAT_MBYTE - prt_in_ascii = !prt_out_mbyte; - if (prt_out_mbyte) - prt_write_string("CF0 sf\n"); - else -#endif - prt_write_string("F0 sf\n"); - prt_fgcol = PRCOLOR_BLACK; - prt_bgcol = PRCOLOR_WHITE; - prt_font = PRT_PS_FONT_ROMAN; - - /* Set up page transformation for landscape printing. */ - if (!prt_portrait) - { - prt_write_int(-((int)prt_mediasize[prt_media].width)); - prt_write_string("sl\n"); - } - - prt_dsc_noarg("EndPageSetup"); - - /* We have reset the font attributes, force setting them again. */ - curr_bg = (long_u)0xffffffff; - curr_fg = (long_u)0xffffffff; - curr_bold = MAYBE; - - return !prt_file_error; -} - - int -mch_print_blank_page() -{ - return (mch_print_begin_page(NULL) ? (mch_print_end_page()) : FALSE); -} - -static float prt_pos_x = 0; -static float prt_pos_y = 0; - - void -mch_print_start_line(margin, page_line) - int margin; - int page_line; -{ - prt_pos_x = prt_left_margin; - if (margin) - prt_pos_x -= prt_number_width; - - prt_pos_y = prt_top_margin - prt_first_line_height - - page_line * prt_line_height; - - prt_attribute_change = TRUE; - prt_need_moveto = TRUE; -#ifdef FEAT_MBYTE - prt_half_width = FALSE; -#endif -} - -/*ARGSUSED*/ - int -mch_print_text_out(p, len) - char_u *p; - int len; -{ - int need_break; - char_u ch; - char_u ch_buff[8]; - float char_width; - float next_pos; -#ifdef FEAT_MBYTE - int in_ascii; - int half_width; -#endif - - char_width = prt_char_width; - -#ifdef FEAT_MBYTE - /* Ideally VIM would create a rearranged CID font to combine a Roman and - * CJKV font to do what VIM is doing here - use a Roman font for characters - * in the ASCII range, and the origingal CID font for everything else. - * The problem is that GhostScript still (as of 8.13) does not support - * rearranged fonts even though they have been documented by Adobe for 7 - * years! If they ever do, a lot of this code will disappear. - */ - if (prt_use_courier) - { - in_ascii = (len == 1 && *p < 0x80); - if (prt_in_ascii) - { - if (!in_ascii) - { - /* No longer in ASCII range - need to switch font */ - prt_in_ascii = FALSE; - prt_need_font = TRUE; - prt_attribute_change = TRUE; - } - } - else if (in_ascii) - { - /* Now in ASCII range - need to switch font */ - prt_in_ascii = TRUE; - prt_need_font = TRUE; - prt_attribute_change = TRUE; - } - } - if (prt_out_mbyte) - { - half_width = ((*mb_ptr2cells)(p) == 1); - if (half_width) - char_width /= 2; - if (prt_half_width) - { - if (!half_width) - { - prt_half_width = FALSE; - prt_pos_x += prt_char_width/4; - prt_need_moveto = TRUE; - prt_attribute_change = TRUE; - } - } - else if (half_width) - { - prt_half_width = TRUE; - prt_pos_x += prt_char_width/4; - prt_need_moveto = TRUE; - prt_attribute_change = TRUE; - } - } -#endif - - /* Output any required changes to the graphics state, after flushing any - * text buffered so far. - */ - if (prt_attribute_change) - { - prt_flush_buffer(); - /* Reset count of number of chars that will be printed */ - prt_text_run = 0; - - if (prt_need_moveto) - { - prt_pos_x_moveto = prt_pos_x; - prt_pos_y_moveto = prt_pos_y; - prt_do_moveto = TRUE; - - prt_need_moveto = FALSE; - } - if (prt_need_font) - { -#ifdef FEAT_MBYTE - if (!prt_in_ascii) - prt_write_string("CF"); - else -#endif - prt_write_string("F"); - prt_write_int(prt_font); - prt_write_string("sf\n"); - prt_need_font = FALSE; - } - if (prt_need_fgcol) - { - int r, g, b; - r = ((unsigned)prt_fgcol & 0xff0000) >> 16; - g = ((unsigned)prt_fgcol & 0xff00) >> 8; - b = prt_fgcol & 0xff; - - prt_write_real(r / 255.0, 3); - if (r == g && g == b) - prt_write_string("g\n"); - else - { - prt_write_real(g / 255.0, 3); - prt_write_real(b / 255.0, 3); - prt_write_string("r\n"); - } - prt_need_fgcol = FALSE; - } - - if (prt_bgcol != PRCOLOR_WHITE) - { - prt_new_bgcol = prt_bgcol; - if (prt_need_bgcol) - prt_do_bgcol = TRUE; - } - else - prt_do_bgcol = FALSE; - prt_need_bgcol = FALSE; - - if (prt_need_underline) - prt_do_underline = prt_underline; - prt_need_underline = FALSE; - - prt_attribute_change = FALSE; - } - -#ifdef FEAT_MBYTE - if (prt_do_conv) - { - /* Convert from multi-byte to 8-bit encoding */ - p = string_convert(&prt_conv, p, &len); - if (p == NULL) - p = (char_u *)""; - } - - if (prt_out_mbyte) - { - /* Multi-byte character strings are represented more efficiently as hex - * strings when outputting clean 8 bit PS. - */ - do - { - ch = prt_hexchar[(unsigned)(*p) >> 4]; - ga_append(&prt_ps_buffer, ch); - ch = prt_hexchar[(*p) & 0xf]; - ga_append(&prt_ps_buffer, ch); - p++; - } - while (--len); - } - else -#endif - { - /* Add next character to buffer of characters to output. - * Note: One printed character may require several PS characters to - * represent it, but we only count them as one printed character. - */ - ch = *p; - if (ch < 32 || ch == '(' || ch == ')' || ch == '\\') - { - /* Convert non-printing characters to either their escape or octal - * sequence, ensures PS sent over a serial line does not interfere - * with the comms protocol. Note: For EBCDIC we need to write out - * the escape sequences as ASCII codes! - * Note 2: Char codes < 32 are identical in EBCDIC and ASCII AFAIK! - */ - ga_append(&prt_ps_buffer, IF_EB('\\', 0134)); - switch (ch) - { - case BS: ga_append(&prt_ps_buffer, IF_EB('b', 0142)); break; - case TAB: ga_append(&prt_ps_buffer, IF_EB('t', 0164)); break; - case NL: ga_append(&prt_ps_buffer, IF_EB('n', 0156)); break; - case FF: ga_append(&prt_ps_buffer, IF_EB('f', 0146)); break; - case CAR: ga_append(&prt_ps_buffer, IF_EB('r', 0162)); break; - case '(': ga_append(&prt_ps_buffer, IF_EB('(', 0050)); break; - case ')': ga_append(&prt_ps_buffer, IF_EB(')', 0051)); break; - case '\\': ga_append(&prt_ps_buffer, IF_EB('\\', 0134)); break; - - default: - sprintf((char *)ch_buff, "%03o", (unsigned int)ch); -#ifdef EBCDIC - ebcdic2ascii(ch_buff, 3); -#endif - ga_append(&prt_ps_buffer, ch_buff[0]); - ga_append(&prt_ps_buffer, ch_buff[1]); - ga_append(&prt_ps_buffer, ch_buff[2]); - break; - } - } - else - ga_append(&prt_ps_buffer, ch); - } - -#ifdef FEAT_MBYTE - /* Need to free any translated characters */ - if (prt_do_conv && (*p != NUL)) - vim_free(p); -#endif - - prt_text_run += char_width; - prt_pos_x += char_width; - - /* The downside of fp - use relative error on right margin check */ - next_pos = prt_pos_x + prt_char_width; - need_break = (next_pos > prt_right_margin) && - ((next_pos - prt_right_margin) > (prt_right_margin*1e-5)); - - if (need_break) - prt_flush_buffer(); - - return need_break; -} - - void -mch_print_set_font(iBold, iItalic, iUnderline) - int iBold; - int iItalic; - int iUnderline; -{ - int font = 0; - - if (iBold) - font |= 0x01; - if (iItalic) - font |= 0x02; - - if (font != prt_font) - { - prt_font = font; - prt_attribute_change = TRUE; - prt_need_font = TRUE; - } - if (prt_underline != iUnderline) - { - prt_underline = iUnderline; - prt_attribute_change = TRUE; - prt_need_underline = TRUE; - } -} - - void -mch_print_set_bg(bgcol) - long_u bgcol; -{ - prt_bgcol = bgcol; - prt_attribute_change = TRUE; - prt_need_bgcol = TRUE; -} - - void -mch_print_set_fg(fgcol) - long_u fgcol; -{ - if (fgcol != (long_u)prt_fgcol) - { - prt_fgcol = fgcol; - prt_attribute_change = TRUE; - prt_need_fgcol = TRUE; - } -} - -# endif /*FEAT_POSTSCRIPT*/ -#endif /*FEAT_PRINTER*/ - #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ && (defined(FEAT_EVAL) || defined(FEAT_MULTI_LANG)) static char *get_locale_val __ARGS((int what)); diff --git a/src/globals.h b/src/globals.h index 72310bd27..2c6d8e2ec 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1080,6 +1080,9 @@ extern cursorentry_T shape_table[SHAPE_IDX_COUNT]; #endif #ifdef FEAT_PRINTER +/* + * Printer stuff shared between hardcopy.c and machine-specific printing code. + */ # define OPT_PRINT_TOP 0 # define OPT_PRINT_BOT 1 # define OPT_PRINT_LEFT 2 @@ -1126,34 +1129,11 @@ EXTERN option_table_T printer_opts[OPT_PRINT_NUM_OPTIONS] # define PRT_UNIT_MM 2 # define PRT_UNIT_POINT 3 # define PRT_UNIT_NAMES {"pc", "in", "mm", "pt"} - -# ifdef FEAT_MBYTE -# define OPT_MBFONT_USECOURIER 0 -# define OPT_MBFONT_ASCII 1 -# define OPT_MBFONT_REGULAR 2 -# define OPT_MBFONT_BOLD 3 -# define OPT_MBFONT_OBLIQUE 4 -# define OPT_MBFONT_BOLDOBLIQUE 5 -# define OPT_MBFONT_NUM_OPTIONS 6 -# -EXTERN option_table_T mbfont_opts[OPT_MBFONT_NUM_OPTIONS] -# ifdef DO_INIT - = -{ - {"c", FALSE, 0, NULL, 0, FALSE}, - {"a", FALSE, 0, NULL, 0, FALSE}, - {"r", FALSE, 0, NULL, 0, FALSE}, - {"b", FALSE, 0, NULL, 0, FALSE}, - {"i", FALSE, 0, NULL, 0, FALSE}, - {"o", FALSE, 0, NULL, 0, FALSE}, -} -# endif -; -# endif #endif #ifdef FEAT_XCLIPBOARD -EXTERN char *xterm_display INIT(= NULL); /* xterm display name */ +EXTERN char *xterm_display INIT(= NULL); /* xterm display name; points + into argv[] */ EXTERN Display *xterm_dpy INIT(= NULL); /* xterm display pointer */ #endif #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) diff --git a/src/main.c b/src/main.c index 0f507e7a3..0e274adf5 100644 --- a/src/main.c +++ b/src/main.c @@ -29,6 +29,15 @@ # include <limits.h> #endif +/* Struct for various parameters passed between main() and other functions. */ +typedef struct +{ + int serverArg; /* TRUE when argument for a server */ + char_u *serverName_arg; /* cmdline arg for server name */ + int evim_mode; /* started as "evim" */ + char_u *use_vimrc; /* vimrc from -u option */ +} mparm_T; + #if defined(UNIX) || defined(VMS) static int file_owned __ARGS((char *fname)); #endif @@ -36,6 +45,9 @@ static void mainerr __ARGS((int, char_u *)); static void main_msg __ARGS((char *s)); static void usage __ARGS((void)); static int get_number_arg __ARGS((char_u *p, int *idx, int def)); +static void early_arg_scan __ARGS((int argc, char **argv, mparm_T *parmp)); +static void exe_pre_commands __ARGS((char_u **cmds, int cnt)); +static void source_startup_scripts __ARGS((mparm_T *parmp)); static void main_start_gui __ARGS((void)); #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) static void check_swap_exists_action __ARGS((void)); @@ -50,8 +62,6 @@ static char_u *serverMakeName __ARGS((char_u *arg, char *cmd)); static FILE *time_fd = NULL; #endif -#define FEAT_PRECOMMANDS - /* * Different types of error messages. */ @@ -95,7 +105,6 @@ main char_u *term = NULL; /* specified terminal name */ char_u *fname = NULL; /* file name from command line */ char_u *tagname = NULL; /* tag from -t option */ - char_u *use_vimrc = NULL; /* vimrc from -u option */ #ifdef FEAT_QUICKFIX char_u *use_ef = NULL; /* 'errorfile' from -q option */ #endif @@ -105,10 +114,8 @@ main int n_commands = 0; /* no. of commands from + or -c */ char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c option */ char_u cmds_tofree[MAX_ARG_CMDS]; /* commands that need free() */ -#ifdef FEAT_PRECOMMANDS - int p_commands = 0; /* no. of commands from --cmd */ + int n_pre_commands = 0; /* no. of commands from --cmd */ char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd option */ -#endif int no_swap_file = FALSE; /* "-n" option used */ int c; int i; @@ -135,7 +142,6 @@ main #ifdef FEAT_DIFF int diff_mode = FALSE; /* start with 'diff' set */ #endif - int evim_mode = FALSE; /* started as "evim" */ int stdout_isatty; /* is stdout a terminal? */ int input_isatty; /* is active input a terminal? */ #ifdef MSWIN @@ -144,13 +150,13 @@ main #ifdef FEAT_CLIENTSERVER char_u *serverStr = NULL; /* remote server command */ char_u *serverStrEnc = NULL; /* encoding of serverStr */ - char_u *serverName_arg = NULL; /* cmdline arg for server name */ - int serverArg = FALSE; /* TRUE when argument for a server */ char_u *servername = NULL; /* allocated name for our server */ #endif #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) int literal = FALSE; /* don't expand file names */ #endif + mparm_T params; /* various parameters passed between + * main() and other functions. */ /* * Do any system-specific initialisations. These can NOT use IObuff or @@ -158,6 +164,8 @@ main */ mch_early_init(); + vim_memset(¶ms, 0, sizeof(params)); + #ifdef FEAT_TCL vim_tcl_init(argv[0]); #endif @@ -198,7 +206,7 @@ main init_normal_cmds(); #if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC) - make_version(); + make_version(); /* Construct the long version string. */ #endif /* @@ -255,75 +263,13 @@ main gui.dofork = TRUE; /* default is to use fork() */ #endif -#if defined(FEAT_XCLIPBOARD) || defined(FEAT_CLIENTSERVER) /* - * Get the name of the display, before gui_prepare() removes it from - * argv[]. Used for the xterm-clipboard display. - * - * Also find the --server... arguments + * Do a first scan of the arguments in "argv[]": + * -display + * --server... + * --socketid */ - for (i = 1; i < argc; i++) - { - if (STRCMP(argv[i], "--") == 0) - break; -# ifdef FEAT_XCLIPBOARD - else if (STRICMP(argv[i], "-display") == 0 -# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) - || STRICMP(argv[i], "--display") == 0 -# endif - ) - { - if (i == argc - 1) - mainerr_arg_missing((char_u *)argv[i]); - xterm_display = argv[++i]; - } -# endif -# ifdef FEAT_CLIENTSERVER - else if (STRICMP(argv[i], "--servername") == 0) - { - if (i == argc - 1) - mainerr_arg_missing((char_u *)argv[i]); - serverName_arg = (char_u *)argv[++i]; - } - else if (STRICMP(argv[i], "--serverlist") == 0 - || STRICMP(argv[i], "--remote-send") == 0 - || STRICMP(argv[i], "--remote-expr") == 0 - || STRICMP(argv[i], "--remote") == 0 - || STRICMP(argv[i], "--remote-silent") == 0) - serverArg = TRUE; - else if (STRICMP(argv[i], "--remote-wait") == 0 - || STRICMP(argv[i], "--remote-wait-silent") == 0) - { - serverArg = TRUE; -#ifdef FEAT_GUI - /* don't fork() when starting the GUI to edit the files ourself */ - gui.dofork = FALSE; -#endif - } -# endif -# ifdef FEAT_GUI_GTK - else if (STRICMP(argv[i], "--socketid") == 0) - { - unsigned int socket_id; - int count; - - if (i == argc - 1) - mainerr_arg_missing((char_u *)argv[i]); - if (STRNICMP(argv[i+1], "0x", 2) == 0) - count = sscanf(&(argv[i + 1][2]), "%x", &socket_id); - else - count = sscanf(argv[i+1], "%u", &socket_id); - if (count != 1) - mainerr(ME_INVALID_ARG, (char_u *)argv[i]); - else - gtk_socket_id = socket_id; - i++; - } - else if (STRICMP(argv[i], "--echo-wid") == 0) - echo_wid_arg = TRUE; -# endif - } -#endif + early_arg_scan(argc, argv, ¶ms); #ifdef FEAT_SUN_WORKSHOP findYourself(argv[0]); @@ -376,7 +322,7 @@ main /* * Do the client-server stuff, unless "--servername ''" was used. */ - if (serverName_arg == NULL || *serverName_arg != NUL) + if (params.serverName_arg == NULL || *params.serverName_arg != NUL) { # ifdef WIN32 /* Initialise the client/server messaging infrastructure. */ @@ -388,9 +334,9 @@ main * exit Vim when it was successful. Otherwise it's executed further * on. Remember the encoding used here in "serverStrEnc". */ - if (serverArg) + if (params.serverArg) { - cmdsrv_main(&argc, argv, serverName_arg, &serverStr); + cmdsrv_main(&argc, argv, params.serverName_arg, &serverStr); # ifdef FEAT_MBYTE serverStrEnc = vim_strsave(p_enc); # endif @@ -399,7 +345,7 @@ main /* If we're still running, get the name to register ourselves. * On Win32 can register right now, for X11 need to setup the * clipboard first, it's further down. */ - servername = serverMakeName(serverName_arg, argv[0]); + servername = serverMakeName(params.serverName_arg, argv[0]); # ifdef WIN32 if (servername != NULL) { @@ -453,7 +399,7 @@ main #ifdef FEAT_GUI gui.starting = TRUE; #endif - evim_mode = TRUE; + params.evim_mode = TRUE; ++initstr; } @@ -588,13 +534,11 @@ main } else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) p_lpl = FALSE; -#ifdef FEAT_PRECOMMANDS else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) { want_argument = TRUE; argv_idx += 3; } -#endif #ifdef FEAT_CLIENTSERVER else if (STRNICMP(argv[0] + argv_idx, "serverlist", 10) == 0) ; /* already processed -- no arg */ @@ -724,7 +668,7 @@ main #ifdef FEAT_GUI gui.starting = TRUE; /* start GUI a bit later */ #endif - evim_mode = TRUE; + params.evim_mode = TRUE; break; case 'N': /* "-N" Nocompatible */ @@ -940,13 +884,11 @@ main commands[n_commands++] = (char_u *)argv[0]; break; -#ifdef FEAT_PRECOMMANDS case '-': /* "--cmd {command}" execute command */ - if (p_commands >= MAX_ARG_CMDS) + if (n_pre_commands >= MAX_ARG_CMDS) mainerr(ME_EXTRA_CMD, NULL); - pre_commands[p_commands++] = (char_u *)argv[0]; + pre_commands[n_pre_commands++] = (char_u *)argv[0]; break; -#endif /* case 'd': -d {device} is handled in mch_check_win() for the * Amiga */ @@ -1002,7 +944,7 @@ scripterror: break; case 'u': /* "-u {vimrc}" vim inits file */ - use_vimrc = (char_u *)argv[0]; + params.use_vimrc = (char_u *)argv[0]; break; case 'U': /* "-U {gvimrc}" gvim inits file */ @@ -1151,7 +1093,7 @@ scripterror: /* When running "evim" or "gvim -y" we need the menus, exit if we * don't have them. */ - if (evim_mode) + if (params.evim_mode) mch_exit(1); } # endif @@ -1365,176 +1307,17 @@ scripterror: init_highlight(TRUE, FALSE); /* set the default highlight groups */ TIME_MSG("init highlight"); -#ifdef CURSOR_SHAPE - parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */ -#endif -#ifdef FEAT_MOUSESHAPE - parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */ -#endif -#ifdef FEAT_PRINTER - parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS); -#endif #ifdef FEAT_EVAL /* Set the break level after the terminal is initialized. */ debug_break_level = use_debug_break_level; #endif -#ifdef FEAT_PRECOMMANDS - if (p_commands > 0) - { - curwin->w_cursor.lnum = 0; /* just in case.. */ - sourcing_name = (char_u *)_("pre-vimrc command line"); -# ifdef FEAT_EVAL - current_SID = SID_CMDARG; -# endif - for (i = 0; i < p_commands; ++i) - do_cmdline_cmd(pre_commands[i]); - sourcing_name = NULL; -# ifdef FEAT_EVAL - current_SID = 0; -# endif - } -#endif + /* Execute --cmd arguments. */ + exe_pre_commands(pre_commands, n_pre_commands); - /* - * For "evim" source evim.vim first of all, so that the user can overrule - * any things he doesn't like. - */ - if (evim_mode) - { - (void)do_source((char_u *)EVIM_FILE, FALSE, FALSE); - TIME_MSG("source evim file"); - } - - /* - * If -u option given, use only the initializations from that file and - * nothing else. - */ - if (use_vimrc != NULL) - { - if (STRCMP(use_vimrc, "NONE") == 0 || STRCMP(use_vimrc, "NORC") == 0) - { -#ifdef FEAT_GUI - if (use_gvimrc == NULL) /* don't load gvimrc either */ - use_gvimrc = use_vimrc; -#endif - if (use_vimrc[2] == 'N') - p_lpl = FALSE; /* don't load plugins either */ - } - else - { - if (do_source(use_vimrc, FALSE, FALSE) != OK) - EMSG2(_("E282: Cannot read from \"%s\""), use_vimrc); - } - } - else if (!silent_mode) - { -#ifdef AMIGA - struct Process *proc = (struct Process *)FindTask(0L); - APTR save_winptr = proc->pr_WindowPtr; - - /* Avoid a requester here for a volume that doesn't exist. */ - proc->pr_WindowPtr = (APTR)-1L; -#endif - - /* - * Get system wide defaults, if the file name is defined. - */ -#ifdef SYS_VIMRC_FILE - (void)do_source((char_u *)SYS_VIMRC_FILE, FALSE, FALSE); -#endif - - /* - * Try to read initialization commands from the following places: - * - environment variable VIMINIT - * - user vimrc file (s:.vimrc for Amiga, ~/.vimrc otherwise) - * - second user vimrc file ($VIM/.vimrc for Dos) - * - environment variable EXINIT - * - user exrc file (s:.exrc for Amiga, ~/.exrc otherwise) - * - second user exrc file ($VIM/.exrc for Dos) - * The first that exists is used, the rest is ignored. - */ - if (process_env((char_u *)"VIMINIT", TRUE) != OK) - { - if (do_source((char_u *)USR_VIMRC_FILE, TRUE, TRUE) == FAIL -#ifdef USR_VIMRC_FILE2 - && do_source((char_u *)USR_VIMRC_FILE2, TRUE, TRUE) == FAIL -#endif -#ifdef USR_VIMRC_FILE3 - && do_source((char_u *)USR_VIMRC_FILE3, TRUE, TRUE) == FAIL -#endif - && process_env((char_u *)"EXINIT", FALSE) == FAIL - && do_source((char_u *)USR_EXRC_FILE, FALSE, FALSE) == FAIL) - { -#ifdef USR_EXRC_FILE2 - (void)do_source((char_u *)USR_EXRC_FILE2, FALSE, FALSE); -#endif - } - } - - /* - * Read initialization commands from ".vimrc" or ".exrc" in current - * directory. This is only done if the 'exrc' option is set. - * Because of security reasons we disallow shell and write commands - * now, except for unix if the file is owned by the user or 'secure' - * option has been reset in environment of global ".exrc" or ".vimrc". - * Only do this if VIMRC_FILE is not the same as USR_VIMRC_FILE or - * SYS_VIMRC_FILE. - */ - if (p_exrc) - { -#if defined(UNIX) || defined(VMS) - /* If ".vimrc" file is not owned by user, set 'secure' mode. */ - if (!file_owned(VIMRC_FILE)) -#endif - secure = p_secure; - - i = FAIL; - if (fullpathcmp((char_u *)USR_VIMRC_FILE, - (char_u *)VIMRC_FILE, FALSE) != FPC_SAME -#ifdef USR_VIMRC_FILE2 - && fullpathcmp((char_u *)USR_VIMRC_FILE2, - (char_u *)VIMRC_FILE, FALSE) != FPC_SAME -#endif -#ifdef USR_VIMRC_FILE3 - && fullpathcmp((char_u *)USR_VIMRC_FILE3, - (char_u *)VIMRC_FILE, FALSE) != FPC_SAME -#endif -#ifdef SYS_VIMRC_FILE - && fullpathcmp((char_u *)SYS_VIMRC_FILE, - (char_u *)VIMRC_FILE, FALSE) != FPC_SAME -#endif - ) - i = do_source((char_u *)VIMRC_FILE, TRUE, TRUE); - - if (i == FAIL) - { -#if defined(UNIX) || defined(VMS) - /* if ".exrc" is not owned by user set 'secure' mode */ - if (!file_owned(EXRC_FILE)) - secure = p_secure; - else - secure = 0; -#endif - if ( fullpathcmp((char_u *)USR_EXRC_FILE, - (char_u *)EXRC_FILE, FALSE) != FPC_SAME -#ifdef USR_EXRC_FILE2 - && fullpathcmp((char_u *)USR_EXRC_FILE2, - (char_u *)EXRC_FILE, FALSE) != FPC_SAME -#endif - ) - (void)do_source((char_u *)EXRC_FILE, FALSE, FALSE); - } - } - if (secure == 2) - need_wait_return = TRUE; - secure = 0; -#ifdef AMIGA - proc->pr_WindowPtr = save_winptr; -#endif - } - TIME_MSG("sourcing vimrc file(s)"); + /* Source startup scripts. */ + source_startup_scripts(¶ms); #ifdef FEAT_EVAL /* @@ -1599,7 +1382,7 @@ scripterror: /* When running "evim" or "gvim -y" we need the menus, exit if we * don't have them. */ - if (!gui.in_use && evim_mode) + if (!gui.in_use && params.evim_mode) mch_exit(1); } #endif @@ -1690,7 +1473,7 @@ scripterror: # ifdef FEAT_GUI gui.in_use || # endif - serverName_arg != NULL)) + params.serverName_arg != NULL)) { (void)serverRegisterName(X_DISPLAY, servername); vim_free(servername); @@ -1778,8 +1561,7 @@ scripterror: #endif if (scroll_region) scroll_region_reset(); /* In case Rows changed */ - - scroll_start(); + scroll_start(); /* may scroll the screen to the right position */ /* * Don't clear the screen when starting in Ex mode, unless using the GUI. @@ -2439,6 +2221,262 @@ get_number_arg(p, idx, def) } /* + * Get the name of the display, before gui_prepare() removes it from + * argv[]. Used for the xterm-clipboard display. + * + * Also find the --server... arguments and --socketid + */ +/*ARGSUSED*/ + static void +early_arg_scan(argc, argv, parmp) + int argc; + char **argv; + mparm_T *parmp; +{ +#if defined(FEAT_XCLIPBOARD) || defined(FEAT_CLIENTSERVER) + int i; + + for (i = 1; i < argc; i++) + { + if (STRCMP(argv[i], "--") == 0) + break; +# ifdef FEAT_XCLIPBOARD + else if (STRICMP(argv[i], "-display") == 0 +# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) + || STRICMP(argv[i], "--display") == 0 +# endif + ) + { + if (i == argc - 1) + mainerr_arg_missing((char_u *)argv[i]); + xterm_display = argv[++i]; + } +# endif +# ifdef FEAT_CLIENTSERVER + else if (STRICMP(argv[i], "--servername") == 0) + { + if (i == argc - 1) + mainerr_arg_missing((char_u *)argv[i]); + parmp->serverName_arg = (char_u *)argv[++i]; + } + else if (STRICMP(argv[i], "--serverlist") == 0 + || STRICMP(argv[i], "--remote-send") == 0 + || STRICMP(argv[i], "--remote-expr") == 0 + || STRICMP(argv[i], "--remote") == 0 + || STRICMP(argv[i], "--remote-silent") == 0) + parmp->serverArg = TRUE; + else if (STRICMP(argv[i], "--remote-wait") == 0 + || STRICMP(argv[i], "--remote-wait-silent") == 0) + { + parmp->serverArg = TRUE; +#ifdef FEAT_GUI + /* don't fork() when starting the GUI to edit the files ourself */ + gui.dofork = FALSE; +#endif + } +# endif +# ifdef FEAT_GUI_GTK + else if (STRICMP(argv[i], "--socketid") == 0) + { + unsigned int socket_id; + int count; + + if (i == argc - 1) + mainerr_arg_missing((char_u *)argv[i]); + if (STRNICMP(argv[i+1], "0x", 2) == 0) + count = sscanf(&(argv[i + 1][2]), "%x", &socket_id); + else + count = sscanf(argv[i+1], "%u", &socket_id); + if (count != 1) + mainerr(ME_INVALID_ARG, (char_u *)argv[i]); + else + gtk_socket_id = socket_id; + i++; + } + else if (STRICMP(argv[i], "--echo-wid") == 0) + echo_wid_arg = TRUE; +# endif + } +#endif +} + +/* + * Execute the commands from --cmd arguments "cmds[cnt]". + */ + static void +exe_pre_commands(cmds, cnt) + char_u **cmds; + int cnt; +{ + int i; + + if (cnt > 0) + { + curwin->w_cursor.lnum = 0; /* just in case.. */ + sourcing_name = (char_u *)_("pre-vimrc command line"); +# ifdef FEAT_EVAL + current_SID = SID_CMDARG; +# endif + for (i = 0; i < cnt; ++i) + do_cmdline_cmd(cmds[i]); + sourcing_name = NULL; +# ifdef FEAT_EVAL + current_SID = 0; +# endif + TIME_MSG("--cmd commands"); + } +} + +/* + * Source startup scripts. + */ + static void +source_startup_scripts(parmp) + mparm_T *parmp; +{ + int i; + + /* + * For "evim" source evim.vim first of all, so that the user can overrule + * any things he doesn't like. + */ + if (parmp->evim_mode) + { + (void)do_source((char_u *)EVIM_FILE, FALSE, FALSE); + TIME_MSG("source evim file"); + } + + /* + * If -u option given, use only the initializations from that file and + * nothing else. + */ + if (parmp->use_vimrc != NULL) + { + if (STRCMP(parmp->use_vimrc, "NONE") == 0 || STRCMP(parmp->use_vimrc, "NORC") == 0) + { +#ifdef FEAT_GUI + if (use_gvimrc == NULL) /* don't load gvimrc either */ + use_gvimrc = parmp->use_vimrc; +#endif + if (parmp->use_vimrc[2] == 'N') + p_lpl = FALSE; /* don't load plugins either */ + } + else + { + if (do_source(parmp->use_vimrc, FALSE, FALSE) != OK) + EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc); + } + } + else if (!silent_mode) + { +#ifdef AMIGA + struct Process *proc = (struct Process *)FindTask(0L); + APTR save_winptr = proc->pr_WindowPtr; + + /* Avoid a requester here for a volume that doesn't exist. */ + proc->pr_WindowPtr = (APTR)-1L; +#endif + + /* + * Get system wide defaults, if the file name is defined. + */ +#ifdef SYS_VIMRC_FILE + (void)do_source((char_u *)SYS_VIMRC_FILE, FALSE, FALSE); +#endif + + /* + * Try to read initialization commands from the following places: + * - environment variable VIMINIT + * - user vimrc file (s:.vimrc for Amiga, ~/.vimrc otherwise) + * - second user vimrc file ($VIM/.vimrc for Dos) + * - environment variable EXINIT + * - user exrc file (s:.exrc for Amiga, ~/.exrc otherwise) + * - second user exrc file ($VIM/.exrc for Dos) + * The first that exists is used, the rest is ignored. + */ + if (process_env((char_u *)"VIMINIT", TRUE) != OK) + { + if (do_source((char_u *)USR_VIMRC_FILE, TRUE, TRUE) == FAIL +#ifdef USR_VIMRC_FILE2 + && do_source((char_u *)USR_VIMRC_FILE2, TRUE, TRUE) == FAIL +#endif +#ifdef USR_VIMRC_FILE3 + && do_source((char_u *)USR_VIMRC_FILE3, TRUE, TRUE) == FAIL +#endif + && process_env((char_u *)"EXINIT", FALSE) == FAIL + && do_source((char_u *)USR_EXRC_FILE, FALSE, FALSE) == FAIL) + { +#ifdef USR_EXRC_FILE2 + (void)do_source((char_u *)USR_EXRC_FILE2, FALSE, FALSE); +#endif + } + } + + /* + * Read initialization commands from ".vimrc" or ".exrc" in current + * directory. This is only done if the 'exrc' option is set. + * Because of security reasons we disallow shell and write commands + * now, except for unix if the file is owned by the user or 'secure' + * option has been reset in environment of global ".exrc" or ".vimrc". + * Only do this if VIMRC_FILE is not the same as USR_VIMRC_FILE or + * SYS_VIMRC_FILE. + */ + if (p_exrc) + { +#if defined(UNIX) || defined(VMS) + /* If ".vimrc" file is not owned by user, set 'secure' mode. */ + if (!file_owned(VIMRC_FILE)) +#endif + secure = p_secure; + + i = FAIL; + if (fullpathcmp((char_u *)USR_VIMRC_FILE, + (char_u *)VIMRC_FILE, FALSE) != FPC_SAME +#ifdef USR_VIMRC_FILE2 + && fullpathcmp((char_u *)USR_VIMRC_FILE2, + (char_u *)VIMRC_FILE, FALSE) != FPC_SAME +#endif +#ifdef USR_VIMRC_FILE3 + && fullpathcmp((char_u *)USR_VIMRC_FILE3, + (char_u *)VIMRC_FILE, FALSE) != FPC_SAME +#endif +#ifdef SYS_VIMRC_FILE + && fullpathcmp((char_u *)SYS_VIMRC_FILE, + (char_u *)VIMRC_FILE, FALSE) != FPC_SAME +#endif + ) + i = do_source((char_u *)VIMRC_FILE, TRUE, TRUE); + + if (i == FAIL) + { +#if defined(UNIX) || defined(VMS) + /* if ".exrc" is not owned by user set 'secure' mode */ + if (!file_owned(EXRC_FILE)) + secure = p_secure; + else + secure = 0; +#endif + if ( fullpathcmp((char_u *)USR_EXRC_FILE, + (char_u *)EXRC_FILE, FALSE) != FPC_SAME +#ifdef USR_EXRC_FILE2 + && fullpathcmp((char_u *)USR_EXRC_FILE2, + (char_u *)EXRC_FILE, FALSE) != FPC_SAME +#endif + ) + (void)do_source((char_u *)EXRC_FILE, FALSE, FALSE); + } + } + if (secure == 2) + need_wait_return = TRUE; + secure = 0; +#ifdef AMIGA + proc->pr_WindowPtr = save_winptr; +#endif + } + TIME_MSG("sourcing vimrc file(s)"); +} + +/* * Setup to start using the GUI. Exit with an error when not available. */ static void @@ -2656,9 +2694,7 @@ usage() main_msg(_("-O[N]\t\tLike -o but split vertically")); main_msg(_("+\t\t\tStart at end of file")); main_msg(_("+<lnum>\t\tStart at line <lnum>")); -#ifdef FEAT_PRECOMMANDS main_msg(_("--cmd <command>\tExecute <command> before loading any vimrc file")); -#endif main_msg(_("-c <command>\t\tExecute <command> after loading the first file")); main_msg(_("-S <session>\t\tSource file <session> after loading the first file")); main_msg(_("-s <scriptin>\tRead Normal mode commands from file <scriptin>")); diff --git a/src/misc2.c b/src/misc2.c index 8434ec611..db6642ee9 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -5557,80 +5557,6 @@ pathcmp(p, q, maxlen) } #endif -#if defined(FEAT_PRINTER) || defined(PROTO) -/* - * Parse a list of options in the form - * option:value,option:value,option:value - * - * "value" can start with a number which is parsed out, e.g. - * margin:12mm - * - * Returns error message for an illegal option, NULL otherwise. - * Only used for the printer at the moment... - */ - char_u * -parse_list_options(option_str, table, table_size) - char_u *option_str; - option_table_T *table; - int table_size; -{ - char_u *stringp; - char_u *colonp; - char_u *commap; - char_u *p; - int idx = 0; /* init for GCC */ - int len; - - for (idx = 0; idx < table_size; ++idx) - table[idx].present = FALSE; - - /* - * Repeat for all comma separated parts. - */ - stringp = option_str; - while (*stringp) - { - colonp = vim_strchr(stringp, ':'); - if (colonp == NULL) - return (char_u *)N_("E550: Missing colon"); - commap = vim_strchr(stringp, ','); - if (commap == NULL) - commap = option_str + STRLEN(option_str); - - len = (int)(colonp - stringp); - - for (idx = 0; idx < table_size; ++idx) - if (STRNICMP(stringp, table[idx].name, len) == 0) - break; - - if (idx == table_size) - return (char_u *)N_("E551: Illegal component"); - - p = colonp + 1; - table[idx].present = TRUE; - - if (table[idx].hasnum) - { - if (!VIM_ISDIGIT(*p)) - return (char_u *)N_("E552: digit expected"); - - table[idx].number = getdigits(&p); /*advances p*/ - } - - table[idx].string = p; - table[idx].strlen = (int)(commap - p); - - stringp = commap; - if (*stringp == ',') - ++stringp; - } - - return NULL; -} - - -#endif /*FEAT_PRINTER*/ - /* * The putenv() implementation below comes from the "screen" program. * Included with permission from Juergen Weigert. diff --git a/src/option.c b/src/option.c index 30341d60c..940c6e768 100644 --- a/src/option.c +++ b/src/option.c @@ -3269,6 +3269,16 @@ set_init_2() } } #endif + +#ifdef CURSOR_SHAPE + parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */ +#endif +#ifdef FEAT_MOUSESHAPE + parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */ +#endif +#ifdef FEAT_PRINTER + (void)parse_printoptions(); /* parse 'printoptions' default value */ +#endif } /* @@ -5598,13 +5608,10 @@ did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf, #ifdef FEAT_PRINTER else if (varp == &p_popt) - errmsg = parse_list_options(p_popt, printer_opts, - OPT_PRINT_NUM_OPTIONS); - + errmsg = parse_printoptions(); # if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT) else if (varp == &p_pmfn) - errmsg = parse_list_options(p_pmfn, mbfont_opts, - OPT_MBFONT_NUM_OPTIONS); + errmsg = parse_printmbfont(); # endif #endif diff --git a/src/os_mswin.c b/src/os_mswin.c index ce4420b33..6d043269d 100644 --- a/src/os_mswin.c +++ b/src/os_mswin.c @@ -2357,6 +2357,8 @@ mch_print_set_fg(unsigned long fgcol) #endif /*FEAT_PRINTER && !FEAT_POSTSCRIPT*/ + + #if defined(FEAT_SHORTCUT) || defined(PROTO) # include <shlobj.h> diff --git a/src/po/Makefile b/src/po/Makefile index 7320a605d..617d4f970 100644 --- a/src/po/Makefile +++ b/src/po/Makefile @@ -52,8 +52,49 @@ MOFILES = \ zh_TW.UTF-8.mo \ zh_TW.mo \ +CONVERTED = \ + cs.cp1250.mo \ + ja.sjis.mo \ + pl.cp1250.mo \ + ru.cp1251.mo \ + sk.cp1250.mo \ + uk.cp1251.mo \ + zh_CN.cp936.mo \ + +CHECKFILES = \ + af.ck \ + ca.ck \ + cs.ck \ + de.ck \ + en_GB.ck \ + es.ck \ + fr.ck \ + ga.ck \ + it.ck \ + ja.ck \ + ko.ck \ + no.ck \ + pl.ck \ + ru.ck \ + sk.ck \ + sv.ck \ + uk.ck \ + vi.ck \ + zh_CN.UTF-8.ck \ + zh_CN.ck \ + zh_TW.UTF-8.ck \ + zh_TW.ck \ + cs.cp1250.ck \ + ja.sjis.ck \ + pl.cp1250.ck \ + ru.cp1251.ck \ + sk.cp1250.ck \ + uk.cp1251.ck \ + zh_CN.cp936.ck \ + PACKAGE = vim SHELL = /bin/sh +VIM = ../vim # The OLD_PO_FILE_INPUT and OLD_PO_FILE_OUTPUT are for the new GNU gettext # tools 0.10.37, which use a slightly different .po file format that is not @@ -64,16 +105,22 @@ XGETTEXT = OLD_PO_FILE_INPUT=yes OLD_PO_FILE_OUTPUT=yes xgettext MSGMERGE = OLD_PO_FILE_INPUT=yes OLD_PO_FILE_OUTPUT=yes msgmerge .SUFFIXES: -.SUFFIXES: .po .mo .pot -.PHONY: all install uninstall check clean distclean $(LANGUAGES) +.SUFFIXES: .po .mo .pot .ck +.PHONY: all install uninstall prefixcheck check clean distclean $(LANGUAGES) .po.mo: $(MSGFMT) -o $@ $< +.po.ck: + $(VIM) -u NONE -e -S check.vim -c "if error == 0 | q | endif" -c cq $< + touch $@ + all: $(MOFILES) +check: $(CHECKFILES) + install: $(MOFILES) - @$(MAKE) check + @$(MAKE) prefixcheck for lang in $(LANGUAGES); do \ dir=$(LOCALEDIR)/$$lang/; \ if test ! -x "$$dir"; then \ @@ -90,21 +137,14 @@ install: $(MOFILES) done uninstall: - @$(MAKE) check + @$(MAKE) prefixcheck for cat in $(MOFILES); do \ cat=`basename $$cat`; \ lang=`echo $$cat | sed 's/\$(CATOBJEXT)$$//'`; \ rm -f $(LOCALEDIR)/$$lang/LC_MESSAGES/$(PACKAGE).mo; \ done -converted: \ - cs.cp1250.mo \ - ja.sjis.mo \ - pl.cp1250.mo \ - ru.cp1251.mo \ - sk.cp1250.mo \ - uk.cp1251.mo \ - zh_CN.cp936.mo \ +converted: $(CONVERTED) # Convert ja.po to create ja.sjis.po. Requires doubling backslashes in the # second byte. Don't depend on sjiscorr, it should only be compiled when @@ -154,7 +194,7 @@ uk.cp1251.po: uk.po iconv -f koi8-u -t cp1251 uk.po | \ sed -e 's/charset=koi8-u/charset=cp1251/' -e 's/# Original translations/# Generated from uk.po, DO NOT EDIT/' > uk.cp1251.po -check: +prefixcheck: @if test "x" = "x$(prefix)"; then \ echo "******************************************"; \ echo " please use make from the src directory "; \ @@ -163,7 +203,7 @@ check: fi clean: - rm -f core core.* *.old.po *.mo *.pot sjiscorr + rm -f core core.* *.old.po *.mo *.ck *.pot sjiscorr distclean: clean diff --git a/src/po/README.txt b/src/po/README.txt index b023ef364..30afd9e6a 100644 --- a/src/po/README.txt +++ b/src/po/README.txt @@ -99,6 +99,7 @@ language. (4) Check: + vim -S check.vim xx.po make xx.mo Look out for syntax errors and fix them. diff --git a/src/po/README_mingw.txt b/src/po/README_mingw.txt index 7ba98e607..267df246b 100644 --- a/src/po/README_mingw.txt +++ b/src/po/README_mingw.txt @@ -74,6 +74,7 @@ the same as in the Unix case, only the commands change): (4) Check: + vim -S check.vim xx.po make -f Make_ming.mak xx.mo Look out for syntax errors and fix them. diff --git a/src/po/cs.cp1250.po b/src/po/cs.cp1250.po index 04370dc07..99a45023c 100644 --- a/src/po/cs.cp1250.po +++ b/src/po/cs.cp1250.po @@ -2351,12 +2351,12 @@ msgstr "umístìní kurzoru mimo buffer" #: if_python.c:1824 #, c-format msgid "<window object (deleted) at %.8lX>" -msgstr "<objekt okna (smazán) na %8lX>" +msgstr "<objekt okna (smazán) na %.8lX>" #: if_python.c:1836 #, c-format msgid "<window object (unknown) at %.8lX>" -msgstr "<objekt okna (neznámý) na %8lX>" +msgstr "<objekt okna (neznámý) na %.8lX>" #: if_python.c:1838 #, c-format diff --git a/src/po/cs.po b/src/po/cs.po index e38c66527..d6e81d1f9 100644 --- a/src/po/cs.po +++ b/src/po/cs.po @@ -2351,12 +2351,12 @@ msgstr "umístìní kurzoru mimo buffer" #: if_python.c:1824 #, c-format msgid "<window object (deleted) at %.8lX>" -msgstr "<objekt okna (smazán) na %8lX>" +msgstr "<objekt okna (smazán) na %.8lX>" #: if_python.c:1836 #, c-format msgid "<window object (unknown) at %.8lX>" -msgstr "<objekt okna (neznámý) na %8lX>" +msgstr "<objekt okna (neznámý) na %.8lX>" #: if_python.c:1838 #, c-format diff --git a/src/po/uk.cp1251.po b/src/po/uk.cp1251.po index 5df9b18d5..0cab121d0 100644 --- a/src/po/uk.cp1251.po +++ b/src/po/uk.cp1251.po @@ -729,7 +729,7 @@ msgstr "ͳ÷îãî äðóêóâàòè" #: ex_cmds2.c:2913 msgid "Printing page %d (%d%%)" -msgstr "Äðóêóºòüñÿ ñòîð³íêà %d (%d)" +msgstr "Äðóêóºòüñÿ ñòîð³íêà %d (%d%%)" #: ex_cmds2.c:2922 #, c-format @@ -894,7 +894,7 @@ msgstr "E140: Âèêîðèñòîâóéòå ! äëÿ çàïèñó ÷àñòèíè áóôåðà" #: ex_cmds.c:2244 #, c-format msgid "Overwrite existing file \"%.*s\"?" -msgstr "Ïåðåçàïèñàòè ³ñíóþ÷èé ôàéë \"%*.s\"?" +msgstr "Ïåðåçàïèñàòè ³ñíóþ÷èé ôàéë \"%.*s\"?" #: ex_cmds.c:2315 #, c-format diff --git a/src/po/uk.po b/src/po/uk.po index f8223d3f2..92b3b2e42 100644 --- a/src/po/uk.po +++ b/src/po/uk.po @@ -729,7 +729,7 @@ msgstr "î¦ÞÏÇÏ ÄÒÕËÕ×ÁÔÉ" #: ex_cmds2.c:2913 msgid "Printing page %d (%d%%)" -msgstr "äÒÕËÕ¤ÔØÓÑ ÓÔÏÒ¦ÎËÁ %d (%d)" +msgstr "äÒÕËÕ¤ÔØÓÑ ÓÔÏÒ¦ÎËÁ %d (%d%%)" #: ex_cmds2.c:2922 #, c-format @@ -894,7 +894,7 @@ msgstr "E140: ÷ÉËÏÒÉÓÔÏ×ÕÊÔÅ ! ÄÌÑ ÚÁÐÉÓÕ ÞÁÓÔÉÎÉ ÂÕÆÅÒÁ" #: ex_cmds.c:2244 #, c-format msgid "Overwrite existing file \"%.*s\"?" -msgstr "ðÅÒÅÚÁÐÉÓÁÔÉ ¦ÓÎÕÀÞÉÊ ÆÁÊÌ \"%*.s\"?" +msgstr "ðÅÒÅÚÁÐÉÓÁÔÉ ¦ÓÎÕÀÞÉÊ ÆÁÊÌ \"%.*s\"?" #: ex_cmds.c:2315 #, c-format diff --git a/src/po/zh_CN.UTF-8.po b/src/po/zh_CN.UTF-8.po index 956a82a5c..b63416a7f 100644 --- a/src/po/zh_CN.UTF-8.po +++ b/src/po/zh_CN.UTF-8.po @@ -2118,7 +2118,7 @@ msgstr "E256: Hangul automata 错误" #: if_cscope.c:26 #, c-format msgid "Usage: cs[cope] %s" -msgstr "" +msgstr "Usage: cs[cope] %s" #: if_cscope.c:67 msgid "Add a new database" diff --git a/src/po/zh_CN.cp936.po b/src/po/zh_CN.cp936.po index 53e6cbcb3..4f9102f82 100644 --- a/src/po/zh_CN.cp936.po +++ b/src/po/zh_CN.cp936.po @@ -2118,7 +2118,7 @@ msgstr "E256: Hangul automata ´íÎó" #: if_cscope.c:26 #, c-format msgid "Usage: cs[cope] %s" -msgstr "" +msgstr "Usage: cs[cope] %s" #: if_cscope.c:67 msgid "Add a new database" diff --git a/src/po/zh_CN.po b/src/po/zh_CN.po index 28fb5ad05..a049eabe9 100644 --- a/src/po/zh_CN.po +++ b/src/po/zh_CN.po @@ -2118,7 +2118,7 @@ msgstr "E256: Hangul automata ´íÎó" #: if_cscope.c:26 #, c-format msgid "Usage: cs[cope] %s" -msgstr "" +msgstr "Usage: cs[cope] %s" #: if_cscope.c:67 msgid "Add a new database" diff --git a/src/proto.h b/src/proto.h index e24ebb48f..1102432af 100644 --- a/src/proto.h +++ b/src/proto.h @@ -92,6 +92,7 @@ extern int _stricoll __ARGS((char *a, char *b)); # ifdef FEAT_HANGULIN # include "hangulin.pro" # endif +# include "hardcopy.pro" # include "hashtable.pro" # include "main.pro" # include "mark.pro" diff --git a/src/proto/ex_cmds2.pro b/src/proto/ex_cmds2.pro index 35ccc203b..88fa352b7 100644 --- a/src/proto/ex_cmds2.pro +++ b/src/proto/ex_cmds2.pro @@ -75,23 +75,6 @@ void ex_finish __ARGS((exarg_T *eap)); void do_finish __ARGS((exarg_T *eap, int reanimate)); int source_finished __ARGS((char_u *(*getline)(int, void *, int), void *cookie)); void ex_checktime __ARGS((exarg_T *eap)); -int get_printer_page_num __ARGS((void)); -int prt_header_height __ARGS((void)); -int prt_use_number __ARGS((void)); -int prt_get_unit __ARGS((int idx)); -void ex_hardcopy __ARGS((exarg_T *eap)); -void mch_print_cleanup __ARGS((void)); -int mch_print_init __ARGS((prt_settings_T *psettings, char_u *jobname, int forceit)); -int mch_print_begin __ARGS((prt_settings_T *psettings)); -void mch_print_end __ARGS((prt_settings_T *psettings)); -int mch_print_end_page __ARGS((void)); -int mch_print_begin_page __ARGS((char_u *str)); -int mch_print_blank_page __ARGS((void)); -void mch_print_start_line __ARGS((int margin, int page_line)); -int mch_print_text_out __ARGS((char_u *p, int len)); -void mch_print_set_font __ARGS((int iBold, int iItalic, int iUnderline)); -void mch_print_set_bg __ARGS((long_u bgcol)); -void mch_print_set_fg __ARGS((long_u fgcol)); char_u *get_mess_lang __ARGS((void)); void set_lang_var __ARGS((void)); void ex_language __ARGS((exarg_T *eap)); diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro index 3f6e2edca..80d17892c 100644 --- a/src/proto/misc2.pro +++ b/src/proto/misc2.pro @@ -93,7 +93,6 @@ int vim_chdir __ARGS((char_u *new_dir)); int get_user_name __ARGS((char_u *buf, int len)); void sort_strings __ARGS((char_u **files, int count)); int pathcmp __ARGS((const char *p, const char *q, int maxlen)); -char_u *parse_list_options __ARGS((char_u *option_str, option_table_T *table, int table_size)); int filewritable __ARGS((char_u *fname)); int emsg3 __ARGS((char_u *s, char_u *a1, char_u *a2)); int emsgn __ARGS((char_u *s, long n)); diff --git a/src/version.h b/src/version.h index 3bbe8ec67..db1ba03bf 100644 --- a/src/version.h +++ b/src/version.h @@ -36,5 +36,5 @@ #define VIM_VERSION_NODOT "vim70aa" #define VIM_VERSION_SHORT "7.0aa" #define VIM_VERSION_MEDIUM "7.0aa ALPHA" -#define VIM_VERSION_LONG "VIM - Vi IMproved 7.0aa ALPHA (2005 Jul 22)" -#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.0aa ALPHA (2005 Jul 22, compiled " +#define VIM_VERSION_LONG "VIM - Vi IMproved 7.0aa ALPHA (2005 Jul 23)" +#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.0aa ALPHA (2005 Jul 23, compiled " |