-
Notifications
You must be signed in to change notification settings - Fork 0
/
Convert_bas.vb
3592 lines (3372 loc) · 178 KB
/
Convert_bas.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Option Strict Off
Option Explicit On
Imports atcUtility
Imports MapWinUtility
Imports MapWinUtility.Strings
Imports Microsoft.Office.Interop.Word
Imports System.Text
Module modConvert
'Copyright 2000-2008 by AQUA TERRA Consultants
'pBaseName (~) is the name of program being documented.
'File ~.txt contains list of source files (pProjectFileName)
'~.hlp will be created if converting to help (also optionally ~.cnt, ~.hpj)
'~.doc will be created if converting to printable
'~.hhp, ~.hhc, ~.ID -> ~.chm
Public pOutputFormat As outputType
Public Enum OutputType
tASCII = 0
tHTML = 1
tPRINT = 2
tHELP = 3
tHTMLHELP = 4
NONE = -999
End Enum
Private pWordBasic As Word.WordBasic
Private pWordApp As Microsoft.Office.Interop.Word.Application
Private Const mMaxLevels As Integer = 9 ' Do you really want sections nested deeper than this?
Private mContentsWindowName As String
Private mTargetWindowName As String
Private mTargetText As String
Private mSourceFilename As String
Private mSourceBaseDirectory As String
Private mSaveDirectory As String
Private mHelpSourceRTFName As String
Private mProjectFileEntrys As New Collection
Private mNextProjectFileIndex As Integer
Private mHeadingWord(8) As String
Private mHeadingText(mMaxLevels) As String
Private mHeadingFile(mMaxLevels) As String
Private mBeforeHTML As String
Private mContentsEntries(mMaxLevels) As Integer
Private mHeaderStyle(mMaxLevels) As String
Private mFooterStyle(mMaxLevels) As String
Private mBodyStyle(mMaxLevels) As String
Private mWordStyle(mMaxLevels) As Collection
Private mBodyTag As String
Private mStyleFile(mMaxLevels) As String
'Private mPromptForFiles As Boolean
Private mFirstHeaderInFile As Boolean
Private mNotFirstPrintFooter As Boolean
Private mNotFirstPrintHeader As Boolean
Private mTablePrintFormat As Integer
Private mTablePrintApply As Integer
Private mTableLines As Boolean
Private mInsertParagraphsAroundImages As Boolean
Private mBuildContents As Boolean
Private mBuildProject As Boolean
Private mFooterTimestamps As Boolean
Private mUpNext As Boolean
Private mBuildID As Boolean
Private mIDfile As Integer
Private mIDnum As Integer
Private mAliasSection As String
Private mHTMLContentsfile As Integer
Private mHTMLHelpProjectfile As Integer
Private mHTMLIndexfile As Integer
Private mSaveFilename As String
Private mInPre As Boolean
Private mAlreadyInitialized As Boolean
Private mLastHeadingLevel As Integer
Private mHeadingLevel As Integer
Private mBookLevel As Integer
Private mStyleLevel As Integer ', IconLevel%
Private mSectionLevelName(99) As String
Private Const mCuteButtons As Boolean = False
Private Const mMoveHeadings As Integer = 0
Private Const mMakeBoxyHeaders As Boolean = False
Private mLinkToImageFiles As Integer '0=store data in document, 1=link+store in doc 2=soft links, -1=do not process images (assigned in Init())
Public Const mAsterisks80 As String = "********************************************************************************"
Private Const mTensPlace As String = " 1 2 3 4 5 6 7 8"
Private Const mOnesPlace As String = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
Private Const mMaxSectionNameLen As Integer = 53
Private Const mTableType As String = "Table-type "
Private Const mTableTypeLength As Integer = 11
Private mWholeCardHeader As String
Private mWholeCardHeaderLength As Integer
Private mTotalTruncated As Integer
Private mTotalRepeated As Integer
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Integer, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer
Public Sub CreateHelpProject(ByRef aIDfileExists As Boolean)
Dim lSB As New StringBuilder
lSB.AppendLine("[OPTIONS]")
lSB.AppendLine("LCID=0x409 0x0 0x0 ; English (United States)")
lSB.AppendLine("REPORT=Yes")
lSB.AppendLine("CNT=" & pBaseName & ".cnt")
lSB.AppendLine("")
lSB.AppendLine("HLP=" & pBaseName & ".hlp")
lSB.AppendLine("")
lSB.AppendLine("[FILES]")
lSB.AppendLine(mHelpSourceRTFName)
lSB.AppendLine("")
If aIDfileExists Then
lSB.AppendLine("[MAP]")
lSB.AppendLine("#include <" & pBaseName & ".ID>")
lSB.AppendLine("")
End If
lSB.AppendLine("[WINDOWS]")
lSB.AppendLine("Main=" & Chr(34) & pBaseName & " Manual" & Chr(34) & ", , 60672, (r14876671), (r12632256), f2; ")
lSB.AppendLine("")
lSB.AppendLine("[CONFIG]")
lSB.AppendLine("BrowseButtons()")
SaveFileString(mSaveDirectory & pBaseName & ".hpj", lSB.ToString)
End Sub
Public Function HTMLRelativeFilename(ByRef aWinFilename As String, ByRef aWinStartPath As String) As String
HTMLRelativeFilename = ReplaceString(RelativeFilename(aWinFilename, aWinStartPath), "\", "/")
End Function
Private Sub OpenHTMLHelpProjectfile()
mHTMLHelpProjectfile = FreeFile()
FileOpen(mHTMLHelpProjectfile, mSaveDirectory & pBaseName & ".hhp", OpenMode.Output)
Print(mHTMLHelpProjectfile, "[OPTIONS]" & vbLf)
Print(mHTMLHelpProjectfile, "Auto Index=Yes" & vbLf)
Print(mHTMLHelpProjectfile, "Compatibility=1.1 Or later" & vbLf)
Print(mHTMLHelpProjectfile, "Compiled file=" & pBaseName & ".chm" & vbLf)
Print(mHTMLHelpProjectfile, "Contents file=" & pBaseName & ".hhc" & vbLf)
'Print #HTMLHelpProjectfile, "Default topic=Introduction.html"
Print(mHTMLHelpProjectfile, "Display compile progress=Yes" & vbLf)
Print(mHTMLHelpProjectfile, "Enhanced decompilation=Yes" & vbLf)
Print(mHTMLHelpProjectfile, "Full-text search=Yes" & vbLf)
Print(mHTMLHelpProjectfile, "Index file = " & pBaseName & ".hhk" & vbLf)
Print(mHTMLHelpProjectfile, "Language=0x409 English (United States)" & vbLf)
Print(mHTMLHelpProjectfile, "Title=" & pBaseName & " Manual" & vbLf & vbLf)
'Print #HTMLHelpProjectfile, ""
Print(mHTMLHelpProjectfile, "[Files]" & vbLf)
mAliasSection = vbLf & "[ALIAS]"
End Sub
Private Sub CheckStyle()
Dim lStartTagPos As Integer = mTargetText.ToLower.IndexOf("<style")
If lStartTagPos >= 0 Then
Dim lCloseTagPos As Integer = mTargetText.IndexOf(">", lStartTagPos)
If lCloseTagPos < lStartTagPos Then
Logger.Msg("Style tag not terminated in " & mSourceFilename)
Else
ReadStyleFile(Mid(mTargetText, lStartTagPos + 7, lCloseTagPos - lStartTagPos - 7), mHeadingLevel)
End If
ElseIf mHeadingLevel <= mStyleLevel Then
mStyleLevel -= 1
While mStyleFile(mStyleLevel).Length = 0
mStyleLevel -= 1
End While
ReadStyleFile("", mStyleLevel)
End If
End Sub
Private Sub ReadStyleFile(ByRef aStyleFilename As String, ByRef aHeadingLevel As Integer)
mBeforeHTML = ""
Dim lLevel As Integer
For lLevel = 1 To mMaxLevels
mWordStyle(lLevel) = Nothing
mWordStyle(lLevel) = New Collection
Next
If aStyleFilename.Length = 0 Then
aStyleFilename = mStyleFile(aHeadingLevel)
Else
If Not IO.File.Exists(aStyleFilename) Then
If IO.File.Exists(aStyleFilename & ".sty") Then
aStyleFilename = aStyleFilename & ".sty"
End If
End If
aStyleFilename = CurDir() & "\" & aStyleFilename
End If
If IO.File.Exists(aStyleFilename) Then
mStyleFile(aHeadingLevel) = aStyleFilename
mStyleLevel = aHeadingLevel
Dim lCurrSection As String = ""
For Each lLine As String In LinesInFile(aStyleFilename)
lLine = lLine.Trim
Dim lFirstChar As String = Left(lLine, 1)
Select Case lFirstChar
Case "#", ""
'skip comments and blank lines
Case "["
lCurrSection = LCase(Mid(lLine, 2, Len(lLine) - 2))
lLevel = 0
Case Else
If IsNumeric(lFirstChar) Then
lLevel = CShort(lFirstChar)
lLine = Mid(lLine, 2)
While IsNumeric(Left(lLine, 1))
lLevel = lLevel * 10 + CShort(Left(lLine, 1))
lLine = Mid(lLine, 2)
End While
While Left(lLine, 1) = " " Or Left(lLine, 1) = "="
lLine = Mid(lLine, 2)
End While
'UPGRADE_ISSUE: GoSub statement is not supported. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="C5A1A479-AB8B-4D40-AAF4-DB19A2E5E77F"'
Select Case lCurrSection
Case "beforehtml"
If lLevel = 0 Then
mBeforeHTML &= lLine & vbCrLf
End If
Case "printsection" : mWordStyle(lLevel).Add(lLine)
Case "top" : mHeaderStyle(lLevel) = lLine
Case "bottom" : mFooterStyle(lLevel) = lLine
Case "body"
If lLine.Length > 0 Then
mBodyStyle(lLevel) = "<body " & lLine & ">"
Else
mBodyStyle(lLevel) = "<body>"
End If
End Select
ElseIf lCurrSection = "printstart" Then
If pOutputFormat = OutputType.tPRINT Then WordCommand(lLine, 0)
Else
For lLevel = 0 To mMaxLevels
'UPGRADE_ISSUE: GoSub statement is not supported. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="C5A1A479-AB8B-4D40-AAF4-DB19A2E5E77F"'
Select Case lCurrSection
Case "beforehtml"
If lLevel = 0 Then
mBeforeHTML &= lLine & vbCrLf
End If
Case "printsection" : mWordStyle(lLevel).Add(lLine)
Case "top" : mHeaderStyle(lLevel) = lLine
Case "bottom" : mFooterStyle(lLevel) = lLine
Case "body"
If Len(lLine) > 0 Then
mBodyStyle(lLevel) = "<body " & lLine & ">"
Else
mBodyStyle(lLevel) = "<body>"
End If
End Select
Next lLevel
End If
End Select
Next
End If
End Sub
Private Sub WordCommand(ByVal aCommandToProcess As String, ByVal aLocalHeadingLevel As Integer)
System.Windows.Forms.Application.DoEvents()
Dim lArgument As String
Dim lValueString As String
Dim lValueInteger As Integer
Try
Dim lCommandToProcess As String = aCommandToProcess
Dim lCommand As String = StrSplit(lCommandToProcess, " ", """")
With pWordBasic
Select Case lCommand.ToLower
' Case "applystyle":
' If IsNumeric(lCommandToProcess) Then localHeadingLevel = CLng(lCommandToProcess)
' .EditBookmark "Hstart" & localHeadingLevel
' .EditGoTo "Hend" & localHeadingLevel
' .Insert vbCr & vbCr
' .EditGoTo "Hstart" & localHeadingLevel
' .ExtendSelection
' .EditGoTo "Hend" & localHeadingLevel
' .Style "ADheading" & localHeadingLevel
' .Cancel
' .CharRight
Case "borderbottom" : If IsNumeric(lCommandToProcess) Then .BorderBottom(CInt(lCommandToProcess))
Case "borderinside" : If IsNumeric(lCommandToProcess) Then .BorderInside(CInt(lCommandToProcess))
Case "borderleft" : If IsNumeric(lCommandToProcess) Then .BorderLeft(CInt(lCommandToProcess))
Case "borderlinestyle" '0=none, 1 to 6 increasing thickness, 7,8,9 double, 10 gray, 11 dashed
Select Case lCommandToProcess.Trim.ToLower
Case "0", "1", "2", "3", "4", "5", "6"
.BorderLineStyle(CInt(lCommandToProcess))
Case "none" : .BorderLineStyle(0)
Case "thin" : .BorderLineStyle(1)
Case "thick" : .BorderLineStyle(6)
Case "double" : .BorderLineStyle(7)
Case "doublethick" : .BorderLineStyle(9)
Case "dashed" : .BorderLineStyle(11)
Case Else
Logger.Msg("Unknown BorderLineStyle: " & lCommandToProcess, MsgBoxStyle.OkOnly, "AuthorDoc:WordCommand")
End Select
Case "bordernone" : If IsNumeric(lCommandToProcess) Then .BorderNone(CInt(lCommandToProcess))
Case "borderoutside" : If IsNumeric(lCommandToProcess) Then .BorderOutside(CInt(lCommandToProcess))
Case "borderright" : If IsNumeric(lCommandToProcess) Then .BorderRight(CInt(lCommandToProcess))
Case "bordertop" : If IsNumeric(lCommandToProcess) Then .BorderTop(CInt(lCommandToProcess))
Case "charleft" : .CharLeft()
Case "charright" : .CharRight()
Case "centerpara" : .CenterPara()
Case "editclear"
If IsNumeric(lCommandToProcess) Then
.EditClear(CInt(lCommandToProcess))
Else
.EditClear()
End If
Case "editselectall" : .EditSelectAll()
Case "filepagesetup"
While lCommandToProcess.Length > 0
lValueString = StrSplit(lCommandToProcess, ",", """")
lArgument = StrSplit(lValueString, ":=", """")
If IsNumeric(lValueString) Then
lValueInteger = CInt(lValueString)
Else
lValueInteger = 0
End If
Select Case lArgument.ToLower
Case "topmargin" : pWordBasic.FilePageSetup(TopMargin:=lValueString)
Case "bottommargin" : pWordBasic.FilePageSetup(BottomMargin:=lValueString)
Case "leftmargin" : pWordBasic.FilePageSetup(LeftMargin:=lValueString)
Case "rightmargin" : pWordBasic.FilePageSetup(RightMargin:=lValueString)
Case "headerdistance" : pWordBasic.FilePageSetup(HeaderDistance:=lValueString)
Case "facingpages" : pWordBasic.FilePageSetup(FacingPages:=lValueInteger)
Case "oddandevenpages" : pWordBasic.FilePageSetup(OddAndEvenPages:=lValueInteger)
End Select
End While
' Case "formatdefinestyleborders"
' While Len(lCommandToProcess) > 0
' lValueString = StrSplit(lCommandToProcess, ",", """")
' lArgument = StrSplit(lValueString, ":=", """")
' If IsNumeric(lValueString) Then
' lValueInteger = CInt(lValueString)
' Select Case LCase(lArgument)
' Case "topborder": .FormatDefineStyleBorders TopBorder:=lValueInteger
' Case "leftborder": .FormatDefineStyleBorders LeftBorder:=lValueInteger
' Case "bottomborder": .FormatDefineStyleBorders BottomBorder:=lValueInteger
' Case "rightborder": .FormatDefineStyleBorders RightBorder:=lValueInteger
' Case "horizborder": .FormatDefineStyleBorders HorizBorder:=lValueInteger
' Case "vertborder": .FormatDefineStyleBorders VertBorder:=lValueInteger
' Case "topcolor": .FormatDefineStyleBorders TopColor:=lValueInteger
' Case "leftcolor": .FormatDefineStyleBorders LeftColor:=lValueInteger
' Case "bottomcolor": .FormatDefineStyleBorders BottomColor:=lValueInteger
' Case "rightcolor": .FormatDefineStyleBorders RightColor:=lValueInteger
' Case "horizcolor": .FormatDefineStyleBorders HorizColor:=lValueInteger
' Case "vertcolor": .FormatDefineStyleBorders VertColor:=lValueInteger
' Case "foreground": .FormatDefineStyleBorders Foreground:=lValueInteger
' Case "background": .FormatDefineStyleBorders Background:=lValueInteger
' Case "shading": .FormatDefineStyleBorders Shading:=lValueInteger
' Case "fineshading": .FormatDefineStyleBorders FineShading:=lValueInteger
' End Select
' Else
' logger.msg "non-numeric value for " & lArgument & " in " & cmd, vbOKOnly, "AuthorDoc:WordCommand"
' End If
' Wend
Case "formatdefinestylefont"
While lCommandToProcess.Length > 0
lValueString = StrSplit(lCommandToProcess, ",", """")
lArgument = StrSplit(lValueString, ":=", """")
If lArgument.ToLower = "font" Then
.FormatDefineStyleFont(Font:=lValueString)
ElseIf IsNumeric(lValueString) Then
lValueInteger = CInt(lValueString)
Select Case lArgument.ToLower
Case "points" : .FormatDefineStyleFont(Points:=lValueInteger)
Case "underline" : .FormatDefineStyleFont(Underline:=lValueInteger)
Case "allcaps" : .FormatDefineStyleFont(AllCaps:=lValueInteger)
Case "kerning" : .FormatDefineStyleFont(Kerning:=lValueInteger)
Case "kerningmin" : .FormatDefineStyleFont(KerningMin:=lValueInteger)
Case "bold" : .FormatDefineStyleFont(Bold:=lValueInteger)
Case "italic" : .FormatDefineStyleFont(Italic:=lValueInteger)
Case "outline" : .FormatDefineStyleFont(Outline:=lValueInteger)
Case "shadow" : .FormatDefineStyleFont(Shadow:=lValueInteger)
Case "font"
End Select
End If
End While
' Case "formatdefinestylepara"
' While Len(lCommandToProcess) > 0
' lValueString = StrSplit(lCommandToProcess, ",", """")
' lArgument = StrSplit(lValueString, ":=", """")
' isnum = IsNumeric(lValueString)
' If isnum Then
' lValueInteger = CInt(lValueString)
' Select Case LCase(lArgument)
' Case "before": .FormatDefineStylePara Before:=lValueInteger
' Case "after": .FormatDefineStylePara After:=lValueInteger
' Case "keepwithnext": .FormatDefineStylePara KeepWithNext:=lValueInteger
' Case "alignment": .FormatDefineStylePara Alignment:=lValueInteger
' End Select
' Else
' logger.msg "non-numeric value for " & lArgument & " in " & cmd, vbOKOnly, "AuthorDoc:WordCommand"
' End If
' Wend
Case "formatfont"
While lCommandToProcess.Length > 0
lValueString = StrSplit(lCommandToProcess, ",", """")
lArgument = StrSplit(lValueString, ":=", """")
If LCase(lArgument) = "font" Then
.FormatFont(Font:=lValueString)
ElseIf Len(lValueString) = 0 Then
If IsNumeric(lArgument) Then .FormatFont(Points:=lArgument)
ElseIf IsNumeric(lValueString) Then
lValueInteger = CInt(lValueString)
Select Case LCase(lArgument)
Case "points" : .FormatFont(Points:=lValueInteger)
Case "underline" : .FormatFont(Underline:=lValueInteger)
Case "allcaps" : .FormatFont(AllCaps:=lValueInteger)
Case "kerning" : .FormatFont(Kerning:=lValueInteger)
Case "kerningmin" : .FormatFont(KerningMin:=lValueInteger)
Case "bold" : .FormatFont(Bold:=lValueInteger)
Case "italic" : .FormatFont(Italic:=lValueInteger)
Case "outline" : .FormatFont(Outline:=lValueInteger)
Case "shadow" : .FormatFont(Shadow:=lValueInteger)
End Select
Else
Logger.Msg("non-numeric value for " & lArgument & " in " & lCommand, MsgBoxStyle.OkOnly, "AuthorDoc:WordCommand")
End If
End While
Case "formatheaderfooterlink" : .FormatHeaderFooterLink()
Case "formatpagenumber"
While lCommandToProcess.Length > 0
lValueString = StrSplit(lCommandToProcess, ",", """")
lArgument = StrSplit(lValueString, ":=", """")
If LCase(lArgument) = "font" Then
.FormatFont(Font:=lValueString)
ElseIf Len(lValueString) = 0 Then
If IsNumeric(lArgument) Then .FormatFont(Points:=lArgument)
ElseIf IsNumeric(lValueString) Then
lValueInteger = CInt(lValueString)
Select Case LCase(lArgument)
Case "chapternumber" : .FormatPageNumber(ChapterNumber:=lValueInteger)
Case "numrestart" : .FormatPageNumber(NumRestart:=lValueInteger)
Case "numformat" : .FormatPageNumber(NumFormat:=lValueInteger)
Case "startingnum" : .FormatPageNumber(StartingNum:=lValueInteger)
Case "level" : .FormatPageNumber(Level:=lValueInteger)
Case "separator" : .FormatPageNumber(Separator:=lValueInteger)
End Select
Else
Logger.Msg("non-numeric value for " & lArgument & " in " & lCommand, MsgBoxStyle.OkOnly, "AuthorDoc:WordCommand")
End If
End While
Case "formatpara", "formatparagraph"
While lCommandToProcess.Length > 0
lValueString = StrSplit(lCommandToProcess, ",", """")
lArgument = StrSplit(lValueString, ":=", """")
If IsNumeric(lValueString) Then
lValueInteger = CInt(lValueString)
Select Case LCase(lArgument)
Case "before" : .FormatParagraph(Before:=lValueInteger)
Case "after" : .FormatParagraph(After:=lValueInteger)
Case "keepwithnext" : .FormatParagraph(KeepWithNext:=lValueInteger)
Case "alignment" : .FormatParagraph(Alignment:=lValueInteger)
End Select
Else
Logger.Msg("non-numeric value for " & lArgument & " in " & lCommand, MsgBoxStyle.OkOnly, "AuthorDoc:WordCommand")
End If
End While
' Case "formatstyle"
' lArgument = StrSplit(lCommandToProcess, ",", """")
' If lArgument = "Normal" Then 'Provide some good defaults in case they aren't explicit in the style file
' .FormatStyle lArgument, AddToTemplate:=1, Define:=1
' .FormatDefineStyleFont 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 1, 1, "Times New Roman", 0, 0, 0, 0
' .FormatDefineStylePara Chr$(34), Chr$(34), 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, Chr$(34)
' .FormatDefineStyleLang "English (US)", 1
' .FormatDefineStyleBorders 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1
' Else
' .FormatStyle lArgument, BasedOn:="Normal", AddToTemplate:=0, Define:=1
' .FormatStyle lArgument, Delete:=1
' .FormatStyle lArgument, BasedOn:="Normal", AddToTemplate:=0, Define:=1
' End If
Case "formattabs"
lArgument = StrSplit(lCommandToProcess, ",", """")
lValueString = StrSplit(lCommandToProcess, ",", """") '1=left, 2=right
If Not IsNumeric(lArgument) Then
Logger.Msg("non-numeric value for tab position in " & lCommand, MsgBoxStyle.OkOnly, "AuthorDoc:WordCommand")
ElseIf Not IsNumeric(lValueString) Then
Logger.Msg("non-numeric value for alignment in " & lCommand, MsgBoxStyle.OkOnly, "AuthorDoc:WordCommand")
Else
lValueInteger = CInt(lValueString)
.FormatTabs(lArgument & """", Align:=lValueInteger, Set:=1)
End If
Case "formattabsclear" : .FormatTabs(ClearAll:=1)
Case "gotoheaderfooter" : .GoToHeaderFooter()
Case "insert" : .Insert(ReplaceStyleString(lCommandToProcess, aLocalHeadingLevel))
Case "insertbreak"
Select Case LCase(Trim(lCommandToProcess))
'0 (zero) Page break, 1 Column break, 2 Next Page section break, 3 Continuous section break, 4 Even Page section break, 5 Odd Page section break, 6 Line break (newline character)
Case "0", "1", "2", "3", "4", "5", "6"
.InsertBreak(CInt(lCommandToProcess))
Case "page" : .InsertBreak(0)
Case "column" : .InsertBreak(1)
Case "pagesection" : .InsertBreak(2)
Case "contsection" : .InsertBreak(3)
Case "evenpagesection" : .InsertBreak(4)
Case "oddpagesection" : .InsertBreak(5)
Case "line" : .InsertBreak(6)
Case Else : Logger.Dbg("Unknown argument to InsertBreak: " & lCommandToProcess)
End Select
Case "insertdatetime"
If Len(Trim(lCommandToProcess)) > 0 Then
.InsertDateTime(lCommandToProcess, 0)
Else
.InsertDateTime(" hh:mm MMMM d, yyyy", 0)
End If
Case "insertfield" : .InsertField(lCommandToProcess)
Case "insertpagenumbers"
Dim lTypeVal As Integer = 1
Dim lPosVal As Integer = 1
Dim lFirstVal As Integer = 0
While lCommandToProcess.Length > 0
lValueString = StrSplit(lCommandToProcess, ",", """")
lArgument = StrSplit(lValueString, ":=", """")
If IsNumeric(lValueString) Then
lValueInteger = CInt(lValueString)
Select Case LCase(lArgument)
Case "type" : lTypeVal = lValueInteger
Case "position" : lPosVal = lValueInteger
Case "firstpage" : lFirstVal = lValueInteger
End Select
Else
Logger.Msg("non-numeric value for " & lArgument & " in " & lCommand, MsgBoxStyle.OkOnly, "AuthorDoc:WordCommand")
End If
End While
.InsertPageNumbers(Type:=lTypeVal, Position:=lPosVal, FirstPage:=lFirstVal)
Case "InsertParagraphsAroundImages"
Select Case lCommandToProcess.ToLower
Case "0", "false" : mInsertParagraphsAroundImages = False
Case "1", "true" : mInsertParagraphsAroundImages = True
End Select
Case "shownextheaderfooter"
.ShowNextHeaderFooter()
Case "startofdocument"
.StartOfDocument()
Case "tableprintapply"
If IsNumeric(lCommandToProcess) Then mTablePrintApply = CInt(lCommandToProcess)
Case "tableprintformat"
If IsNumeric(lCommandToProcess) Then mTablePrintFormat = CInt(lCommandToProcess)
Case "toggleheaderfooterlink"
.ToggleHeaderFooterLink()
Case "viewfooter"
pWordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageFooter ' .ViewFooter()
Case "viewheader"
pWordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader ' .ViewHeader()
Case "viewfooterandset"
ViewFooterAndSet(ReplaceStyleString(lCommandToProcess, aLocalHeadingLevel))
Case "viewheaderandset"
ViewHeaderAndSet(ReplaceStyleString(lCommandToProcess, aLocalHeadingLevel))
Case "viewnormal"
pWordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument '.ViewNormal()
Case "viewpage"
.ViewPage()
Case Else
Logger.Dbg("WordCommand not recognized: " & lCommand)
End Select
End With
Catch
Logger.Dbg("Error with Word command '" & aCommandToProcess & "'" & vbCr & Err.Description)
End Try
End Sub
Private Function ReplaceStyleString(ByRef aString As String, ByRef aLocalHeadingLevel As Integer) As String
Dim lReturnString As String = aString
lReturnString = lReturnString.Replace("<sectionname>", mHeadingText(aLocalHeadingLevel))
For lHeadingLevel As Integer = 1 To aLocalHeadingLevel
lReturnString = ReplaceString(lReturnString, "<sectionname " & lHeadingLevel & ">", mHeadingText(lHeadingLevel))
Next
lReturnString = ReplaceString(lReturnString, "vbTab", vbTab)
lReturnString = ReplaceString(lReturnString, "vbCr", vbCr)
lReturnString = ReplaceString(lReturnString, "vbLf", vbLf)
lReturnString = ReplaceString(lReturnString, "vbCrLf", vbCrLf)
Dim lSectionWord As String
Dim lSectionWordPos As Integer = lReturnString.IndexOf("<sectionword")
While lSectionWordPos > -1
Dim lSectionWordEndPos As Integer = lReturnString.IndexOf(">", lSectionWordPos + 12)
If lSectionWordEndPos = -1 Then
lSectionWordPos = 0
Else
lSectionWord = Trim(Mid(lReturnString, lSectionWordPos + 12, lSectionWordEndPos - lSectionWordPos - 12))
If IsNumeric(lSectionWord) Then
Dim wordnum As Integer = CInt(lSectionWord)
lSectionWord = mHeadingText(aLocalHeadingLevel)
While wordnum > 1
StrSplit(lSectionWord, " ", "")
End While
lSectionWord = StrSplit(lSectionWord, " ", "")
lReturnString = Left(lReturnString, lSectionWordPos - 1) & lSectionWord & Mid(lReturnString, lSectionWordEndPos + 1)
Else
lReturnString = Left(lReturnString, lSectionWordPos - 1) & mHeadingText(aLocalHeadingLevel) & Mid(lReturnString, lSectionWordEndPos + 1)
End If
lSectionWordPos = InStr(lSectionWordPos + 1, lReturnString, "<sectionword")
End If
End While
Return lReturnString
End Function
Public Sub Convert(ByRef aOutputAs As OutputType, _
ByRef aMakeContents As Boolean, ByRef aTimestamps As Boolean, _
ByRef aMakeUpNext As Boolean, ByRef aMakeID As Boolean, ByRef aMakeProject As Boolean)
Logger.StartToFile(CurDir() & "\log\authordoc.log", False, True)
Logger.Dbg("StartConvert " & aOutputAs)
pKeywords = New Collection
Init()
pOutputFormat = aOutputAs
mBuildContents = aMakeContents
mBuildProject = aMakeProject
mFooterTimestamps = aTimestamps
mUpNext = aMakeUpNext
mBuildID = aMakeID
frmConvert.CmDialog1Open.DefaultExt = "txt"
If IO.File.Exists(pProjectFileName) Then
'mPromptForFiles = False
mProjectFileEntrys.Clear()
For Each lLine As String In LinesInFile(pProjectFileName)
If lLine.Trim.Length > 0 Then
mProjectFileEntrys.Add(lLine)
End If
Next
mNextProjectFileIndex = 1
Else
Logger.Msg("Could not open project file " & pProjectFileName)
Exit Sub
End If
mSourceBaseDirectory = IO.Path.GetDirectoryName(pProjectFileName) & "\"
ChDriveDir(mSourceBaseDirectory)
mSaveDirectory = mSourceBaseDirectory & "Out\"
If Not IO.Directory.Exists(mSaveDirectory) Then
IO.Directory.CreateDirectory(mSaveDirectory)
End If
If mBuildProject Then
If pOutputFormat = OutputType.tHELP Then
CreateHelpProject(True)
ElseIf pOutputFormat = OutputType.tHTMLHELP Then
OpenHTMLHelpProjectfile()
ElseIf pOutputFormat = OutputType.tASCII Then
mHTMLHelpProjectfile = FreeFile()
FileOpen(mHTMLHelpProjectfile, mSaveDirectory & pBaseName & ".txt", OpenMode.Output)
End If
End If
If mBuildID Then
mIDfile = FreeFile()
FileOpen(mIDfile, mSaveDirectory & pBaseName & ".ID", OpenMode.Output)
mIDnum = 2
End If
InitContents()
'mPromptForFiles = False
Dim lLastSourceFilename As String = ""
mSourceFilename = NextSourceFilename()
If pOutputFormat = OutputType.tPRINT Or pOutputFormat = OutputType.tHELP Then
'pWordApp = New Microsoft.Office.Interop.Word.Application
'pWordBasic = pWordApp.WordBasic
pWordBasic = CreateObject("Word.Basic")
pWordApp = GetObject(, "Word.Application")
With pWordBasic
.AppShow()
'.ToolsOptionsView PicturePlaceHolders:=1
.ChDir(mSaveDirectory)
.FileNewDefault()
If pOutputFormat = OutputType.tPRINT Then
DefinePrintStyles()
.FileSaveAs(mSaveDirectory & pBaseName & ".doc", 0)
ElseIf pOutputFormat = OutputType.tHELP Then
.FilePageSetup(PageWidth:="12 in")
.FileSaveAs(mSaveDirectory & mHelpSourceRTFName, 6)
End If
mTargetWindowName = .WindowName
pWordApp.ActiveWindow.View.Type = WdViewType.wdPrintView 'ensures all commands available
.ChDir(mSourceBaseDirectory)
End With
End If
ReadStyleFile(pBaseName & ".sty", 0)
mLastHeadingLevel = 0
While mSourceFilename.Length > 0 AndAlso mSourceFilename <> lLastSourceFilename
OpeningFile:
Status("Opening " & mSourceFilename)
lLastSourceFilename = mSourceFilename
mFirstHeaderInFile = True
System.Windows.Forms.Application.DoEvents()
If pOutputFormat = OutputType.tPRINT Or pOutputFormat = OutputType.tHELP Then
With pWordBasic
.Activate(mTargetWindowName)
.ScreenUpdating(0) 'comment out to debug (show lots of updates)
.EditBookmark("CurrentFileStart")
Try
.Insert(WholeFileString(mSourceFilename))
Catch ex As Exception
GoTo FileNotFound
End Try
NumberHeaderTagsWithWord()
If mLinkToImageFiles >= 0 Then
.EditGoTo("CurrentFileStart")
TranslateIMGtags(PathNameOnly(AbsolutePath(mSourceFilename, CurDir)))
End If
.EndOfDocument()
.ScreenUpdating(1)
End With
ElseIf pOutputFormat = OutputType.tASCII Then
Dim i As Integer = FreeFile()
Try
FileOpen(i, mSourceFilename, OpenMode.Input) 'SourceBaseDirectory &
Catch ex As Exception
GoTo FileNotFound
End Try
While Not EOF(i) ' Loop until end of file.
ParseHSPFsourceLine(i)
End While
If mBuildProject And pKeywords.Count() > 0 Then
Print(mHTMLHelpProjectfile, vbCrLf & "[Keywords]" & vbCrLf)
For Each lKeyword As Object In pKeywords 'TODO: where do keywords come from?
'UPGRADE_WARNING: Couldn't resolve default property of object keyword. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
Print(mHTMLHelpProjectfile, lKeyword & vbCrLf)
Next lKeyword
End If
FileClose(i)
ElseIf pOutputFormat = OutputType.tHTML Or pOutputFormat = OutputType.tHTMLHELP Then
mTargetText = WholeFileString(mSourceBaseDirectory & mSourceFilename).Trim
TrimTargetText:
Select Case Left(mTargetText, 1)
Case vbCr, vbLf, vbTab, " "
mTargetText = Mid(mTargetText, 2)
GoTo TrimTargetText
End Select
If mTargetText.Length = 0 Then mTargetText = "<toc>"
Dim lDotPos As Integer = InStrRev(mSourceFilename, ".")
If lDotPos > 1 Then
mSaveFilename = Left(mSourceFilename, lDotPos - 1)
Else
mSaveFilename = mSourceFilename
End If
mSaveFilename = mSaveFilename & ".html"
If pOutputFormat = OutputType.tHTMLHELP Then
FormatTag("b", pOutputFormat)
FormatKeywordsHTMLHelp()
If mBuildProject Then Print(mHTMLHelpProjectfile, mSaveFilename & vbLf)
End If
NumberHeaderTags()
CheckStyle()
FormatHeadings(OutputType.tHTML, mSaveFilename)
TranslateButtons(pOutputFormat)
MakeLocalTOCs()
HREFsInsureExtension()
AbsoluteToRelative()
If pOutputFormat <> OutputType.tHELP AndAlso pOutputFormat <> OutputType.tPRINT Then
CopyImages()
End If
'FormatCardGraphic()
SaveInNewDir(mSaveDirectory & mSaveFilename)
End If
Status("Closing " & mSourceFilename)
OpenNextFile:
mSourceFilename = NextSourceFilename()
End While
If pOutputFormat = OutputType.tHTMLHELP And aMakeProject Then
Print(mHTMLHelpProjectfile, mAliasSection & vbLf)
Print(mHTMLHelpProjectfile, "[MAP]" & vbLf & "#include " & pBaseName & ".ID" & vbLf)
FileClose(mHTMLHelpProjectfile)
ElseIf pOutputFormat = OutputType.tASCII Then
FileClose(mIDfile)
FileClose(mHTMLHelpProjectfile)
End If
If (pOutputFormat = OutputType.tPRINT Or pOutputFormat = OutputType.tHELP) Then
With pWordBasic
Logger.Dbg("WordCount:" & pWordApp.ActiveDocument.Words.Count)
Dim lReplaceSelectionOption As Integer
.ToolsOptionsEdit((lReplaceSelectionOption)) 'save current value of this option
.ToolsOptionsEdit((1)) 'be sure option is on
.ScreenUpdating(0) 'comment out to debug (show lots of updates)
.Activate(mTargetWindowName)
ConvertTablesToWord()
Logger.Dbg("WordCount:" & pWordApp.ActiveDocument.Words.Count)
ConvertTagsToWord()
If aMakeContents Then
If pOutputFormat = OutputType.tHTMLHELP Or pOutputFormat = OutputType.tHTML Then
FinishHTMLHelpContents()
'ElseIf OutputFormat = tHTML Then
' .Activate ContentsWin
' .FileSaveAs Directory & "Contents.html", 2
' .FileClose 2
ElseIf pOutputFormat = OutputType.tPRINT Then
.Activate(mTargetWindowName)
.StartOfDocument()
.Insert("Contents" & vbCr & vbCr)
.InsertTableOfContents(0, 0, AddedStyles:="ADheading1,1,ADheading2,2,ADheading3,3,ADheading4,4,ADheading5,5,ADheading6,6", RightAlignPageNumbers:=1)
ElseIf mContentsWindowName.Length > 0 Then
.Activate(mContentsWindowName)
.FileSave()
.FileClose(2)
End If
End If
.ToolsOptionsEdit((lReplaceSelectionOption))
If Len(mTargetWindowName) > 0 Then
.Activate(mTargetWindowName)
Status("Saving file: " & mTargetWindowName)
.FileSave()
.FileClose(2)
End If
.ScreenUpdating(1)
.AppClose()
End With
ElseIf pOutputFormat = OutputType.tHTMLHELP Or pOutputFormat = OutputType.tHTML Then
FinishHTMLHelpContents()
End If
pWordBasic = Nothing
If mIDfile > -1 Then FileClose(mIDfile)
If mTotalTruncated > 0 Or mTotalRepeated > 0 Then
Logger.Msg("Total Truncated = " & mTotalTruncated & vbCr & "Total Repeated = " & mTotalRepeated)
End If
Status("Conversion Finished")
If pOutputFormat = OutputType.tHELP Then
ShellExecute(frmConvert.Handle.ToInt32, "Open", mSaveDirectory & pBaseName & ".hpj", vbNullString, vbNullString, 1) 'SW_SHOWNORMAL"
ElseIf pOutputFormat = OutputType.tHTMLHELP Then
ShellExecute(frmConvert.Handle.ToInt32, "Open", mSaveDirectory & pBaseName & ".hhp", vbNullString, vbNullString, 1) 'SW_SHOWNORMAL"
End If
Logger.Flush()
Exit Sub
FileNotFound:
If Logger.Msg("Error opening " & mSourceFilename & " (" & Err.Description & ")", MsgBoxStyle.RetryCancel, "Help Convert") = MsgBoxResult.Retry Then
GoTo OpeningFile
Else
GoTo OpenNextFile
End If
End Sub
Private Sub ParseHSPFsourceLine(ByRef inFile As Integer)
Dim buf As String
Dim SectionDir, SectionNum, SectionDirName, SectionName As String
Dim parsePos As Integer
Dim Lenbuf As Integer
Dim keyword As String
Dim a2, a, AllCapsStart As Integer
Static DirectoryLevels As Integer
Dim InHeader As Boolean
Dim v As Object
Static CurrentOutputDirectory As String
Static CurrentOutputFilename, ImageFilename As String
Dim dummy As String
Dim FileRepeat As Integer
DirectoryLevels = 0
buf = LineInput(inFile)
buf = ReplaceString(buf, "<", "<")
buf = ReplaceString(buf, ">", ">")
buf = ReplaceString(buf, "<pre>", "<pre>")
buf = ReplaceString(buf, "</pre>", "</pre>")
buf = ReplaceString(buf, "<ol>", "<ol>")
buf = ReplaceString(buf, "</ol>", "</ol>")
buf = ReplaceString(buf, "<li>", "<li>")
If IsNumeric(Left(buf, 1)) And Left(buf, 10) <> "1234567890" Then 'And Mid(buf, 3, 1) <> vbTab Then
If IsNumeric(Trim(buf)) Then 'This indicates an image rather than a section header
If Len(buf) > 3 Then GoTo NormalLine
keyword = CStr(CInt(Left(buf, 2)) * 2)
keyword = New String("0", 3 - Len(keyword)) & keyword
keyword = mSourceFilename & "_files\image" & keyword & ".png"
For parsePos = 1 To DirectoryLevels
keyword = "../" & keyword
Next
buf = "<p>" & "<img src=""" & keyword & """>"
Else
If Mid(buf, 2, 1) <> "." Then GoTo NormalLine
If Not IsNumeric(Mid(buf, 3, 1)) Then GoTo NormalLine
InHeader = True
If mIDfile > 0 Then
If mInPre Then Print(mIDfile, vbCrLf & "</pre>" & vbCrLf)
If pFileKeywords.Count() > 0 Then
For Each v In pFileKeywords
'UPGRADE_WARNING: Couldn't resolve default property of object v. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
PrintLine(mIDfile, "<keyword=" & v & ">" & vbCrLf)
Next v
End If
FileClose(mIDfile)
End If
mInPre = False
pFileKeywords = Nothing
pFileKeywords = New Collection
parsePos = InStr(buf, " ")
SectionNum = Left(buf, parsePos - 1)
SectionName = Trim(Mid(buf, parsePos + 1))
buf = LineInput(inFile)
SectionName = SectionName & " " & Trim(buf)
buf = ""
parsePos = InStr(SectionName, " -- ")
If parsePos > 0 Then
buf = Trim(Mid(SectionName, parsePos + 4))
SectionName = Trim(Left(SectionName, parsePos - 1))
If InStr(UCase(SectionName), "BLOCK") > 0 Then
SectionName = buf
buf = ""
End If
Else
parsePos = InStr(SectionName, "(")
If parsePos > 0 Then
buf = Trim(Mid(SectionName, parsePos))
SectionName = Trim(Left(SectionName, parsePos - 1))
End If
End If
If UCase(Left(SectionName, 7)) = "SECTION" Then SectionName = Mid(SectionName, 9)
If UCase(Left(SectionName, mTableTypeLength)) = UCase(mTableType) Then SectionName = Mid(SectionName, mTableTypeLength + 1)
buf = "<SecNum " & SectionNum & "> " & "<h>" & SectionName & "</h>" & vbCrLf & buf & vbCrLf
If Right(SectionNum, 2) = ".0" Then SectionNum = Left(SectionNum, Len(SectionNum) - 2)
SectionDir = ""
SectionDirName = ""
parsePos = InStr(SectionNum, ".")
If parsePos > 0 Then
DirectoryLevels = 1
parsePos = InStrRev(SectionNum, ".")
SectionDir = Left(SectionNum, parsePos - 1)
SectionDirName = mSectionLevelName(DirectoryLevels)
parsePos = InStr(SectionDir, ".")
While parsePos > 0
DirectoryLevels = DirectoryLevels + 1
SectionDir = Left(SectionDir, parsePos - 1) & "\" & Mid(SectionDir, parsePos + 1)
SectionDirName = SectionDirName & "\" & mSectionLevelName(DirectoryLevels)
parsePos = InStr(parsePos + 1, SectionDir, ".")
End While
SectionDir = SectionDir & "\"
SectionDirName = SectionDirName & "\"
End If
mIDfile = FreeFile
If Not IO.Directory.Exists(mSaveDirectory & SectionDirName) Then IO.Directory.CreateDirectory(mSaveDirectory & SectionDirName)
'Debug.Print
'Debug.Print SectionDir & SectionNum & ":" & CurrentOutputDirectory & CurrentOutputFilename
CurrentOutputDirectory = mSaveDirectory & SectionDirName 'SectionDir
dummy = MakeValidFilename(SectionName)
If Len(dummy) <= mMaxSectionNameLen Then
mSectionLevelName(DirectoryLevels + 1) = dummy
Else
mTotalTruncated = mTotalTruncated + 1
mSectionLevelName(DirectoryLevels + 1) = Trim(Left(dummy, 34) & Right(dummy, 1)) 'MakeValidFilename(buf)
Debug.Print("Truncated " & dummy & vbLf & "Shorter = " & mSectionLevelName(DirectoryLevels + 1))
End If
FileRepeat = 1
SetFilenameHere:
CurrentOutputFilename = mSectionLevelName(DirectoryLevels + 1) & ".txt" 'Mid(SectionNum, Len(SectionDir) + 1) & ".txt"
If Len(CurrentOutputDirectory & CurrentOutputFilename) > 255 Then
Logger.Msg("Path longer than 255 characters detected:" & vbCr & CurrentOutputDirectory & vbCr & CurrentOutputFilename)
End If
If IO.File.Exists(CurrentOutputDirectory & CurrentOutputFilename) Then
FileRepeat = FileRepeat + 1
mSectionLevelName(DirectoryLevels + 1) = mSectionLevelName(DirectoryLevels + 1) & FileRepeat
GoTo SetFilenameHere
End If
'Debug.Print Space(2 * DirectoryLevels) & "<li><a href=""Functional Description" & Mid(CurrentOutputDirectory, 21) & SectionLevelName(DirectoryLevels + 1) & """>" & dummy & "</a>"
If FileRepeat > 1 Then mTotalRepeated = mTotalRepeated + 1
FileOpen(mIDfile, CurrentOutputDirectory & CurrentOutputFilename, OpenMode.Output)
If mBuildProject Then PrintLine(mHTMLHelpProjectfile, Space(2 * DirectoryLevels) & mSectionLevelName(DirectoryLevels + 1)) 'Trim(Mid(buf, Len(SectionNum) + 1)) 'Mid(SectionNum, Len(SectionDir) + 1)
End If
Else
NormalLine:
If Trim(buf) <> "" Then
If Left(buf, 3) = "{{{" Then
ImageFilename = Mid(buf, 4, InStr(buf, "}}}") - 4) & ".png"
buf = "<p><img src=""" & ImageFilename & """>"
RetryImage:
Try
FileCopy(mSourceBaseDirectory & "png\" & ImageFilename, CurrentOutputDirectory & ImageFilename)
Catch
Select Case Logger.Msg("Missing Image: " & vbCr & ImageFilename, MsgBoxStyle.AbortRetryIgnore, "Missing")
Case MsgBoxResult.Retry : GoTo RetryImage
Case MsgBoxResult.Ignore
Case MsgBoxResult.Abort : Exit Sub
End Select
End Try
End If
buf = ReplaceString(buf, "[[[", "<br><figure>")
buf = ReplaceString(buf, "]]]", "</figure>")
If mInPre Then
If InStr(buf, "Explanation") > 0 Then
mInPre = False
buf = "</pre>" & vbCrLf & buf
End If
Else
If InStr(buf, "****************************************") > 0 Or InStr(buf, "----------------------------------------") > 0 Then
mInPre = True
buf = "<pre>" & vbCrLf & buf
End If