summaryrefslogtreecommitdiff
path: root/systems/os2/emtex-contrib/texit/texit.cmd
blob: 0de3e9786ef126a2c750e3379797e4f9bf55b688 (plain)
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
/*
OS/2 script doing a kind of 'make' on a TeX file. First the TeX
source if TeXed until the .aux-file stays constant. Then, if
the -p option is provided, the postscript file is generated.
No action is taken, when the file to create is more recent than
the corresponding source from which it is to create.
NOTE: The argument must be given without extension!

Syntax: texit [-p] <Texfilename-without-extension>

The -p option tells texit, that the resulting DVI file should be
processed by dvips afterwards.

First get out the basename of the file and the path where it is located
*/

call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
TMP='c:\tmp'
postscript=0
current_dir=directory()
parse arg arguments
parse var arguments options rest
if options='-p' then
do
   postscript=1
   parse var arguments options arguments
end

do while \ (arguments='')
   parse var arguments filename1 arguments
   filename=stream(filename1'.TeX','c','query exists')
   if (filename='') then
      filename=stream(filename1,'c','query exists')
   if \ (filename='') then
   do
      bn=left(filespec("name",filename),length(filespec("name",filename))-4)
      path=filespec("drive",filename)filespec("path",filename)
      path=left(path,length(path)-1)
      call directory path
   end
   else
      bn='qwoeiruz'     /* avoid the file being found */
   /* Check, if TeXing is necessary. */
   if exists(bn'.TeX') then
   do
      if exists(bn'.dvi') & get_date(bn'.dvi')>get_date(bn'.TeX') then
	 say 'texit: TeX started despite DVI file newer than TeX file...'

      do until \ index_changed
	 index_changed=0
	 if exists(bn'.idx') then
	    'copy 'bn'.idx 'TMP' >nul'
	 do until \ diff(bn'.aux', TMP'\'bn'.aux')
	    /* First copy .aux and .idx file to allow finding differences later on */
	    if exists(bn'.aux') then
	       'copy 'bn'.aux 'TMP'\'bn'.aux >nul'
	    'call gblatex 'bn'.TeX'
	 end

	 /* Now clean up the copied .aux-file */
	 if exists(TMP'\'bn'.aux') then
	    call SysFileDelete TMP'\'bn'.aux'

	 /* At this point in each case a preliminary stable dvi-file has been
	    built. Now look, if an index file (bn.idx) has been generated.
	    The condition for checking, if the .idx-file has been generated
	    is its date. If it's more recent than the bn.TeX file, then it is
	    considered generated. */

	 if diff(bn'.idx', TMP'\'bn'.idx') | (exists(bn'.idx') & \ exists(bn'.ind')) then
	 do
	 /* If the .idx-files differ, make the .ind-file using makeindex and
	    rerun latex in order to insert this new index into the .dvi-file
	 */
	    index_changed = 1
	    'makeindx 'bn
	 end
      end  /* of do until \ indexchanged */

      /* Clean up the copied .idx-file */
      if exists(TMP'\'bn'.idx') then
	 call SysFileDelete TMP'\'bn'.idx'

      /* Now look at postscript option: */
      if postscript then
	 'call dvips 'bn
   end   /* if .TeX-File exists */
   else
      say 'texit: TeX-File not found!'
end
call directory current_dir
exit

/* *********************************************************************** */
diff: procedure;
/* *********************************************************************** */
   parse arg f1, f2
   /* If the names are equal, or both files do not exists,
      then the files are identical. They are considered different, if only
      one of the files does not exist. */
   if f1=f2 then
      return 0
   else if exists(f1) & \ exists(f2) then
      return 1
   else if exists(f2) & \ exists(f1) then
      return 1
   else if \ exists(f1) & \ exists(f2) then
      return 0
   else if \ (stream(f1,'c','query size')=stream(f2,'c','query size')) then
      return 1
   else
   do
      linein(f1,,0)
      linein(f2,,0)
      do while lines(f1) & lines(f2)
	 l1=linein(f1)
	 l2=linein(f2)
	 if \ (l1=l2) then 
	 do
	    call stream f1, 'c', 'close'
	    call stream f2, 'c', 'close'
	    return 1
	 end
      end
      call stream f1, 'c', 'close'
      call stream f2, 'c', 'close'
      return 0
   end

/* *********************************************************************** */
exists: procedure;
/* *********************************************************************** */
   parse arg filename
   st=stream(filename,'c','query exists')
   if st='' then
      return 0
   else
      return 1

/* *********************************************************************** */
get_date: procedure;
/* *********************************************************************** */
   /* Returns the date of the file passed as argument in the format
      YY/MM/DD/HH/MM */
   parse arg filename
   call SysFileTree filename, ft, tf
   file_date=left(ft.1,14)
   return file_date