File: xmltohtml.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (531 lines) | stat: -rw-r--r-- 14,304 bytes parent folder | download
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
function xmltohtml(dirs,titles,xsl,step)

	//------------------------------------------------------------------------------------------
	// Copyright Enpc (Jean-Philippe Chancelier)
	//------------------------------------------------------------------------------------------
	// dirs is a set of directories 
	// for which html manuals are to be generated 
	// + and index and toc file 
	// titles are associated title strings (optional or [])
	// if dirs is not specified or [] then 
	// standard scilab man are assumed and titles 
	// are searched in %helps 
	// updated by HUYNH Olivier on the 9/03/2004
	//------------------------------------------------------------------------------------------

	curdir=pwd()
	
	help=utillib.help;
	
	//to load the subfunction change_old_man
	//this is required to produce the whatis.htm files
	//associated with old style manuals
	
	change_old_man()
	
	global LANGUAGE %helps
	select LANGUAGE 
		case 'eng' then H= 'Help chapter' 
		case 'fr'  then H= 'Chapitre de help'
	end
	
	//------------------------------------------------------------------------------------------
	// get man_dirs
	//------------------------------------------------------------------------------------------
	
	std= grep(%helps(:,1),SCI)
	
	//------------------------------------------------------------------------------------------
	//patch because scicos is not written in xml
	//------------------------------------------------------------------------------------------
	
	scs=grep(%helps(std,1),'scicos')
	if size(scs,'*')==1 then std(scs)=[],end
	
	man_dirs = basename(%helps(std,1));
	man_titles= %helps(std,2);
	if man_dirs == [] then 
		error('I cannot find man dirs');
		return 
	end
  
	[lhs,rhs]=argn(0) 
	
	if rhs > 4 then error(39),return; end
	if rhs <= 3 then step='all';end 
	if rhs <= 2 then xsl= 'html-rev.xsl'; end 
	if rhs <= 1 then titles= H + emptystr(dirs);end 
	if rhs <= 0 then dirs = man_dirs ;end 
	if titles==[] then titles= H+ emptystr(dirs);end 
	if dirs == [] then 
		dirs = 'SCI/man/'+LANGUAGE+'/'+man_dirs ;
		titles= man_titles;
	end
 
	//------------------------------------------------------------------------------------------
	// first build all the whatis 
	//------------------------------------------------------------------------------------------
	
	if step=='all' | step == 'whatis' then 
		for k=1:size(dirs,'*');
			mprintf('Creating whatis.htm in %s\n',dirs(k));
			dirs(k)=pathconvert(dirs(k),%f,%t)
			chdir(dirs(k));
			if titles(k) == H then 
				titles(k) = titles(k)+' ('+dirs(k)+')';
			end
			gener_whatis(titles(k))
			chdir('../')
		end
	end
  
	//------------------------------------------------------------------------------------------
	// the perform the  html generation
	//------------------------------------------------------------------------------------------
	
	if step=='all' | step == 'html' then 
		dirs=stripblanks(dirs)
		for k=1:size(dirs,'*');
			mprintf('Processing chapter %s\n',dirs(k));
			chdir(dirs(k));
			global %helps;
			nk=length(dirs(k))
			if or(part(dirs(k),nk)==['/','\']) then nk=nk-1,end
			if and(%helps<>part(dirs(k),1:nk)) then
				saved_helps=%helps;
				%helps=[%helps;'./',"Temp"];
				%helps=saved_helps;
			end
	
			xml = listfiles('*.xml');
			if xml <> [] then 
				for k1=1:size(xml,'*')  // loop on .xml files 
				xmlfiletohtml(xml(k1),xsl)
				end 
			end
			chdir('../')
		end
	end
	
	chdir(curdir)
	
	//------------------------------------------------------------------------------------------
	// now the index
	//------------------------------------------------------------------------------------------
	
	if step=='all' | step == 'index' then 
		mprintf('Creating index.htm \n');
		if rhs <= 0 then 
			gener_index() 
		else
			gener_index(dirs,titles)
		end
	end
	
	//------------------------------------------------------------------------------------------
	// now the contents
	//------------------------------------------------------------------------------------------
	
	if step=='all' | step == 'contents' then 
		mprintf('Creating contents.htm  \n');
		if rhs <= 0 then 
			gener_contents() 
		else
			gener_contents(dirs)
		end
	end
	
	//------------------------------------------------------------------------------------------
	// now help workshop (Only under Windows)
	//------------------------------------------------------------------------------------------
	
	if MSDOS then
		if step=='all' | step == 'hw' then 
			mprintf('Creating sciman.hh* \n');
			gener_hh(dirs,titles)
		end
	end

endfunction



function gener_whatis(title)

	//------------------------------------------------------------------------------------------
	// generate a whatis.htm file 
	// using *.xml man files
	//------------------------------------------------------------------------------------------
	
	[lhs,rhs]=argn(0); 
	
	lines(0);
	// look for .xml files
	xml = listfiles('*.xml');
	
	if MSDOS& xml<>[] then 
		// on MSDOS listfiles *.xml also 
		// returns *.xml* !!!!!
		ind = grep(xml,'xml2');
		xml(ind)=[];
	end
	
	if rhs == 1 then 
		whatis_title= title 
	else
		// find the title 
		ind=grep(%helps(:,1),getcwd());
		if ind<>[] then 
			whatis_title= %helps(ind(1),2)
		else
			whatis_title='Help chapter'
		end
	end
  
	head=["<html>"
		"<head>"
		"	<meta http-equiv=""Content-Type"" content=""text/html; charset=ISO-8859-1"">"
		"	<title>"+whatis_title+"</title>"
		"</head>"
		"<body bgcolor=""#FFFFFF"">"
		"<dl>"];
  
	l=0;
	line=[]
	for k1=1:size(xml,'*')  // loop on .xml files
		path=xml(k1);
		txt=mgetl(path);
		d=grep(txt,"<SHORT_DESCRIPTION");
		f=grep(txt,"</SHORT_DESCRIPTION");
		if d<>[] then 
			
			// Remove <VERB> and </VERB> tags
			
			txt = strsubst(txt,'<VERB>','');
			txt = strsubst(txt,'</VERB>','');
			
			// Loop on the lines of short description if necessary
			for k2=1:size(d,"*")
				tt="";
				for k3=d(k2):f(k2)
					tt=tt+txt(k3);
				end
				i=strindex(tt,"""");
				name=part(tt,i(1)+1:i(2)-1);
				i1=strindex(tt,">");
				i2=strindex(tt,"<");
				desc=stripblanks(part(tt,i1(1)+1:i2(2)-1));
				l=l+1; fname=part(path,[1:length(path)-4])+".htm";
				fname=strsubst(fname,'//','/');
				line(l)="<dd><A HREF="""+fname+""">"+name+"</A> - "+desc+"</dd>";
			end
		end
	end
	text = [head;gsort(line,'g','i');"</dl></body></html>"];
	
	mputl(text,"whatis.htm");
	
endfunction



function gener_index(dirs,txt)

	//------------------------------------------------------------------------------------------
	// use %helps to generate an index file 
	//------------------------------------------------------------------------------------------
	lines(0);
	find_links=find_links;
	sep="/";// if MSDOS then sep="\",end
	[lhs,rhs]=argn(0) 
	if rhs <= 0 then 
	        dirs=%helps(:,1)
		txt=%helps(:,2)
	end
  
	line=["<html>"
		"<head>"
		"	<meta http-equiv=""Content-Type"" content=""text/html; charset=ISO-8859-1"">"
		"	<title>Index</title>"
		"</head>"
		"<body bgcolor=""#FFFFFF"">"
		"<dl>"];
  
	l=size(line,'*')
	
	//------------------------------------------------------------------------------------------
	// check for whatis 
	//------------------------------------------------------------------------------------------

	for k=1:size(dirs,'*')
		w=dirs(k)+sep+"whatis.htm";
		if fileinfo(w)==[] then 
			error('file '+w+' not found');
			return 
		end 
		l=l+1;
		w=strsubst(w,'\','/');
		w=strsubst(w,'//','/');
		line(l)="<dd><A HREF="""+w+""">"+txt(k)+"</A></dd>"
	end
	line = [line;"</dl></body></html>"]
  
	mputl(line,"index.htm")
	
endfunction



function flag = gener_links()

	//------------------------------------------------------------------------------------------	
	// returns %t if new files were created
	//------------------------------------------------------------------------------------------
	
	lines(0);
	flag=%f
	
	// look for .xml files
	// look for .xml files
	
	xml = listfiles('*.xml');
	for k1=1:size(xml,'*')  // loop on .xml files
		path=xml(k1)
		//write(%io(2),path)
		if newest(path,strsubst(path,".xml",".htm"))==1 then
			find_links(path,path+"2")
			flag = %t
		end
	end
	
endfunction 



function gener_contents(dirs1)

	//------------------------------------------------------------------------------------------
	// contents.htm 
	//------------------------------------------------------------------------------------------
  
	[lhs,rhs]=argn(0) 
	if rhs <= 0 then 
		dirs = dirname(%helps(:,1));
		base = basename(%helps(:,1));
	else
		dirs = dirname(dirs1)
		base = basename(dirs1)
	end

	//------------------------------------------------------------------------------------------
	// help in the std man directory
	//------------------------------------------------------------------------------------------
	std= grep(dirs,SCI)
	n=size(dirs,'*')

	//------------------------------------------------------------------------------------------	
	// help in the non std man directory
	//------------------------------------------------------------------------------------------
	
	nstd=1:n;
	nstd(std)=[];
	
	full_whatis=[];
	full_whatis_name=[];

	if std<>[] then 
		for k=std
			d = dirs(k)+'/'+base(k);
			[fd,ierr]=mopen(d+"/whatis.htm","r");
			if ierr<>0 then
				warning(" whatis file missing in "+d+". Directory ignored")
			else
				whatis=mgetl(fd);mclose(fd);
				ind=grep(whatis,'</A>');
				whatis=whatis(ind);
				for k1=1:size(whatis,'*')
					lwhatis = whatis(k1);
					i=strindex(lwhatis,">"); j=strindex(lwhatis,"</A>");
					lkey=part(lwhatis,i(2)+1:j-1);
					full_whatis_name=[full_whatis_name;lkey];
				end
				whatis=strsubst(whatis,"HREF=""","HREF="""+base(k)+"/");
				whatis=strsubst(whatis,'//','/');
				full_whatis=[full_whatis;whatis];
			end 
		end
	end
  
	if nstd<>[] then 
		for k=nstd
			d = dirs(k)+'/'+base(k);
			[fd,ierr]=mopen(d+"/whatis.htm","r");
			if ierr<>0 then
				warning(" whatis file missing in "+d+". Directory ignored")
			else
				whatis=mgetl(fd);mclose(fd);
				ind=grep(whatis,'</A>');
				whatis=whatis(ind);
				for k1=1:size(whatis,'*')
					lwhatis = whatis(k1);
					i=strindex(lwhatis,">"); j=strindex(lwhatis,"</A>");
					lkey=part(lwhatis,i(2)+1:j-1);
					full_whatis_name=[full_whatis_name;lkey];
				end
				if dirs(k)<>'.' then 
					d=dirs(k)+'/'+base(k)+"/";
				else 
					d=base(k)+"/";
				end
				whatis=strsubst(whatis,"HREF=""","HREF="""+d);
				whatis=strsubst(whatis,'//','/');
				full_whatis=[full_whatis;whatis];
			end
		end
	end
	
	[sv,sk]=sort(full_whatis_name);
	full_whatis=full_whatis(sk);
	
	select LANGUAGE 
		case 'fr' then title =  "<H2>Fonctions Scilab</H2>";
		case 'eng' then title =  "<H2>Scilab functions</H2>";
	end
  
	full_whatis=["<html>"
		"<head>"
		"	<meta http-equiv=""Content-Type"" content=""text/html; charset=ISO-8859-1"">"
		"	<title>Scilab General Index</title>"
		"</head>"
		"<body bgcolor=""#FFFFFF"">";
		title;
		full_whatis;
		"</body></html>"
		];
	
	mputl(full_whatis,'contents.htm')
  
endfunction 



function gener_hh(dirs,titles)

	//------------------------------------------------------------------------------------------
	// Modified by Pierre MARECHAL
	// Scilab Team
	// Copyright INRIA
	// Date : 31/03/2005
	//------------------------------------------------------------------------------------------
	
	//------------------------------------------------------------------------------------------
	// first produce a scilab.hhk file 
	// (index file) 
	//------------------------------------------------------------------------------------------
	
	base = dirs 

	// help in the std man directory 
	n=size(dirs,'*')

	items=[];
	names=[];

	// just for the std directories 

	for k=1:n 
		// look for .xml files
		files = listfiles(base(k)+'/*.xml');
		if files<>[] then
			fbase = basename(files);
			name = strsubst(base(k)+"\"+fbase,"\\","/");
			items=[items;
				"            <LI><OBJECT type=""text/sitemap""><param name=""Local"" value=""" ...
				+ name +  ...
				".htm""><param name=""Name"" value="""+ fbase+"""></OBJECT>"];
			names=[names;files];
		end
	end
	
	[sv,sk]=sort(names);
	items=items(sk);
	
	full_index=[
		"<HTML>";
		"    <HEAD>";
		"    </HEAD>";
		"    <BODY>";
		"        <UL>";
		"            <LI><OBJECT type=""text/sitemap"">";
		"                     <param name=""Name"" value=""Scilab documentation"">";
		"                     </OBJECT>";
		"            <UL>";
		items;
		"            </UL>";
		"        </UL>"
		"    </BODY>";
		"</HTML>"];
		
	mputl(full_index,'sciman.hhk')

	//------------------------------------------------------------------------------------------
	// produce a scilab.hhc file 
	// (contents) 
	//------------------------------------------------------------------------------------------
    
	items = [];
	for k=1:n 
		name(k) = strsubst(base(k)+"\","\\","/");
		items=[items;
			"                <LI><OBJECT type=""text/sitemap"">";
			"                    <param name=""Local"" value="""+ name(k)+"whatis.htm"">";
			"                    <param name=""Name"" value="""+ titles(k)+""">";
			"                    <param name=""ImageNumber"" value=""11"">";
			"                    </OBJECT>"];
	end
	
	contents=[
		"<HTML>";
		"    <HEAD>";
		"    </HEAD>";
		"    <BODY>";
		"        <UL>";
		"            <LI><OBJECT type=""text/sitemap"">";
		"                     <param name=""Name"" value=""Scilab documentation"">";
		"                     </OBJECT>";
		"            <UL>";
		items;
		"            </UL>";
		"        </UL>"
		"    </BODY>";
		"</HTML>"];
		
	mputl(contents,'sciman.hhc')
	
	//------------------------------------------------------------------------------------------
	// produce a scilab.hhp file 
	//------------------------------------------------------------------------------------------
       
	head=["[OPTIONS]";
		"Compatibility=1.1";
		"Compiled file=sciman.chm";
		"Contents file=sciman.hhc";
		"Default Window=sciman";
		"Default topic=index.htm";
		"Display compile progress=No";
		"Full-text search=Yes";
		"Index file=sciman.hhk";
		"Language=0x409"; 
		"Title=Scilab Documentation";
		"";
		"[WINDOWS]";
		"sciman=""Scilab Documentation"",""sciman.hhc"",""sciman.hhk"",""index.htm"",""index.htm"",,,,,0x2520,220,0x384e,[84,16,784,504],,,,0,,,0";
		"";
		"[FILES]"];

	items=base+"*.htm";
       
	mputl([head;items],'sciman.hhp')  

endfunction