~ubuntu-branches/debian/sid/tex4ht/sid

« back to all changes in this revision

Viewing changes to temp/htcmd.c

  • Committer: Bazaar Package Importer
  • Author(s): Kapil Hari Paranjape
  • Date: 2005-04-05 14:14:41 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050405141441-x4dojdgz3frkfyet
Tags: 20050402.1817-1
* New upstream release (2005-04-02-18:17). Closes: #299934.
* See README.src, README.validate, README.Debian and copyright
  for information on minor changes.
* This upload fixes a some .htf files. Closes: #295109.
* Updated the description to reflect recent changes.
* Fixed some typos in src/tex4ht-mkht.tex and consequently
  in the mk4ht script.
* Updated the man page to include mk4ht. 
* Updated the description of options for the scripts in the man page.
  Put more information in the man page about the way the system works.
  Closes: #219348, #219347.
* Added debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/**********************************************************/
 
3
/* htcmd.c                               2004-12-16-16:20 */
 
4
/* Copyright (C) 1996--2004    Eitan M. Gurari            */
 
5
/*                                                        */
 
6
/* This work may be distributed and/or modified under the */
 
7
/* conditions of the LaTeX Project Public License, either */
 
8
/* version 1.3 of this license or (at your option) any    */
 
9
/* later version. The latest version of this license is   */
 
10
/* in                                                     */
 
11
/*   http://www.latex-project.org/lppl.txt                */
 
12
/* and version 1.3 or later is part of all distributions  */
 
13
/* of LaTeX version 2003/12/01 or later.                  */
 
14
/*                                                        */
 
15
/* This work has the LPPL maintenance status "maintained".*/
 
16
/*                                                        */
 
17
/* This Current Maintainer of this work                   */
 
18
/* is Eitan M. Gurari.                                    */
 
19
/*                                                        */
 
20
/* However, you are allowed to modify this program        */
 
21
/* without changing its name, if you modify its           */
 
22
/* signature. Changes to the signature can be             */
 
23
/* introduced with a directive of the form                */
 
24
/*      #define PLATFORM "signature"                      */
 
25
/*                                                        */
 
26
/*                             gurari@cse.ohio-state.edu  */
 
27
/*                 http://www.cse.ohio-state.edu/~gurari  */
 
28
/**********************************************************/
 
29
 
 
30
/* **********************************************
 
31
    Compiler options                            *
 
32
    (uncommented | command line)                *
 
33
------------------------------------------------*
 
34
        Clasic C (CC)             default
 
35
#define ANSI                      ansi-c, c++
 
36
#define DOS_C
 
37
#define HAVE_STRING_H             <string.h>
 
38
#define HAVE_DIRENT_H             <dirent.h>
 
39
#define HAVE_SYS_NDIR_H           <sys/ndir.h>
 
40
#define HAVE_SYS_DIR_H            <sys/dir.h>
 
41
#define HAVE_NDIR_H               <ndir.h>
 
42
#define HAVE_IO_H                 <io.h>
 
43
#define HAVE_UNISTD_H             <unistd.h>
 
44
#define WIN32
 
45
#define KPATHSEA
 
46
#define SYSTEM_FUNCTION_OK
 
47
#define CDECL                    ..........
 
48
#define BCC32                    bordland c++
 
49
 
 
50
*************************************************
 
51
    Tex4ht variables                            *
 
52
    (uncommented | command line)                *
 
53
----------------------------------------------- */
 
54
 
 
55
/* ******************************************** */
 
56
 
 
57
 
 
58
#ifdef BCC32
 
59
#define WIN32
 
60
#define ANSI
 
61
#define HAVE_IO_H
 
62
#define HAVE_STRING_H
 
63
#define PLATFORM "ms-win32"
 
64
#endif
 
65
 
 
66
 
 
67
 
 
68
#ifdef BCC
 
69
#define DOS_C
 
70
#define ANSI
 
71
#define HAVE_IO_H
 
72
#define PLATFORM "ms-dos"
 
73
#endif
 
74
 
 
75
 
 
76
 
 
77
#ifdef __DJGPP__
 
78
#define DOS_WIN32
 
79
#define ANSI
 
80
#endif
 
81
 
 
82
 
 
83
#ifdef DOS_C
 
84
#define DOS
 
85
#endif
 
86
#ifdef DOS
 
87
#define DOS_WIN32
 
88
#ifndef HAVE_STRING_H
 
89
#define HAVE_STRING_H
 
90
#endif
 
91
#endif
 
92
#ifdef WIN32
 
93
#define DOS_WIN32
 
94
#endif
 
95
 
 
96
#ifdef DOS_WIN32
 
97
#define STRUCT_DIRENT
 
98
#endif
 
99
 
 
100
 
 
101
 
 
102
#ifdef KPATHSEA
 
103
#ifdef WIN32
 
104
#define KWIN32
 
105
#endif
 
106
#endif
 
107
 
 
108
 
 
109
 
 
110
#include <signal.h>
 
111
 
 
112
 
 
113
#include <stdio.h>   
 
114
#include <stdlib.h>  
 
115
 
 
116
 
 
117
#ifdef HAVE_STRING_H
 
118
#include <string.h>
 
119
#endif
 
120
 
 
121
 
 
122
#ifdef HAVE_DIRENT_H
 
123
 
 
124
#include <dirent.h>
 
125
 
 
126
 
 
127
#else
 
128
#ifndef STRUCT_DIRENT
 
129
#define STRUCT_DIRECT
 
130
#endif
 
131
 
 
132
#ifdef HAVE_SYS_NDIR_H
 
133
#include <sys/ndir.h>
 
134
#endif
 
135
#ifdef HAVE_SYS_DIR_H
 
136
#include <sys/dir.h>
 
137
#endif
 
138
#ifdef HAVE_NDIR_H
 
139
#include <ndir.h>
 
140
#endif
 
141
 
 
142
 
 
143
#endif
 
144
 
 
145
 
 
146
 
 
147
 
 
148
#ifndef __DJGPP__
 
149
 
 
150
#ifndef F_OK
 
151
#ifdef DOS_WIN32
 
152
#define  F_OK 0               
 
153
#endif
 
154
#ifndef KPATHSEA
 
155
#ifndef DOS_WIN32
 
156
#define HAVE_UNISTD_H
 
157
#endif
 
158
#endif
 
159
#endif
 
160
#ifdef HAVE_IO_H
 
161
#include <io.h>
 
162
#endif
 
163
#ifndef KPATHSEA
 
164
#ifdef HAVE_UNISTD_H
 
165
#include <unistd.h>
 
166
#endif
 
167
#endif
 
168
 
 
169
 
 
170
#endif
 
171
 
 
172
 
 
173
#ifdef KPATHSEA
 
174
#include <kpathsea/config.h>
 
175
#include <kpathsea/c-errno.h>
 
176
#include <kpathsea/c-ctype.h>
 
177
#include <kpathsea/c-fopen.h>
 
178
#include <kpathsea/c-pathmx.h>
 
179
#include <kpathsea/proginit.h>
 
180
#include <kpathsea/tex-file.h>
 
181
#include <kpathsea/tex-make.h>
 
182
#include <signal.h>
 
183
#if !defined(_AMIGA) && !defined(WIN32)
 
184
#include <sys/time.h>
 
185
#endif
 
186
#include <fcntl.h>
 
187
#include <setjmp.h>
 
188
#endif 
 
189
 
 
190
#ifdef __DJGPP__
 
191
 
 
192
#ifndef F_OK
 
193
#ifdef DOS_WIN32
 
194
#define  F_OK 0               
 
195
#endif
 
196
#ifndef KPATHSEA
 
197
#ifndef DOS_WIN32
 
198
#define HAVE_UNISTD_H
 
199
#endif
 
200
#endif
 
201
#endif
 
202
#ifdef HAVE_IO_H
 
203
#include <io.h>
 
204
#endif
 
205
#ifndef KPATHSEA
 
206
#ifdef HAVE_UNISTD_H
 
207
#include <unistd.h>
 
208
#endif
 
209
#endif
 
210
 
 
211
 
 
212
#endif
 
213
 
 
214
 
 
215
 
 
216
 
 
217
 
 
218
 
 
219
#ifdef DOS
 
220
#define PROTOTYP
 
221
#endif
 
222
#ifdef ANSI
 
223
#define PROTOTYP
 
224
#endif
 
225
#ifdef KWIN32
 
226
#define PROTOTYP
 
227
#endif
 
228
 
 
229
 
 
230
#ifdef KPATHSEA
 
231
#ifdef WIN32
 
232
#undef CDECL
 
233
#define CDECL                     __cdecl
 
234
#else
 
235
#define CDECL
 
236
#endif
 
237
#endif
 
238
 
 
239
 
 
240
#if defined(DOS_WIN32) || defined(__MSDOS__)
 
241
#define READ_BIN_FLAGS "rb"
 
242
#define READ_TEXT_FLAGS "r"
 
243
#define WRITE_BIN_FLAGS "wb"
 
244
#define WRITE_TEXT_FLAGS "w"
 
245
#else
 
246
#define READ_BIN_FLAGS "r"
 
247
#define READ_TEXT_FLAGS "r"
 
248
#define WRITE_BIN_FLAGS "w"
 
249
#define WRITE_TEXT_FLAGS "w"
 
250
#endif
 
251
 
 
252
 
 
253
 
 
254
#define Q_CHAR char
 
255
#define U_CHAR char
 
256
#define C_CHAR char
 
257
#define Q_NULL (Q_CHAR *) 0
 
258
#define U_NULL (U_CHAR *) 0
 
259
#define C_NULL (C_CHAR *) 0
 
260
 
 
261
 
 
262
#define IGNORED void
 
263
 
 
264
 
 
265
#ifndef EXIT_FAILURE
 
266
#define EXIT_FAILURE 1
 
267
#endif
 
268
 
 
269
 
 
270
#ifdef PROTOTYP
 
271
#define VOID void
 
272
#define ARG_I(x) x
 
273
#define ARG_II(x,y) x,y
 
274
#define ARG_III(x,y,z) x,y,z
 
275
#define ARG_IV(x,y,z,w) x,y,z,w
 
276
#define ARG_V(x,y,z,w,u) x,y,z,w,u
 
277
#else
 
278
#define VOID
 
279
#define ARG_I(x)
 
280
#define ARG_II(x,y)
 
281
#define ARG_III(x,y,z)
 
282
#define ARG_IV(x,y,z,w)
 
283
#define ARG_V(x,y,z,w,u)
 
284
#endif
 
285
 
 
286
 
 
287
struct sys_call_rec{
 
288
  Q_CHAR * filter;
 
289
  struct sys_call_rec *next;
 
290
};
 
291
 
 
292
 
 
293
struct script_struct{
 
294
  Q_CHAR *command;
 
295
  struct script_struct *next;
 
296
};
 
297
 
 
298
 
 
299
#define NULL_SCRIPT (struct script_struct *) 0
 
300
 
 
301
 
 
302
#ifndef TRUE
 
303
#define TRUE 1
 
304
#endif
 
305
#ifndef FALSE
 
306
#define FALSE 0
 
307
#endif
 
308
#ifndef BOOL
 
309
#define BOOL int
 
310
#endif
 
311
 
 
312
 
 
313
#define bad_arg            err_arg(0)
 
314
#define bad_mem             err_i(1)
 
315
 
 
316
 
 
317
#define eq_str(x,y) (!strcmp(x,y))
 
318
 
 
319
 
 
320
 
 
321
static BOOL system_yes;
 
322
 
 
323
 
 
324
static int system_return;
 
325
 
 
326
 
 
327
static C_CHAR *warn_err_mssg[]={ 
 
328
"\n---------------------------------------------------------------\n\
 
329
htcmd optional-flag command-line\n\n\
 
330
   optional-flag:\n\
 
331
        -slash     translate '/' into '\\'\n\
 
332
        -dslash    translate '/' into '\\\\'\n\n\
 
333
Example: \n\
 
334
   htcmd t4ht name -d/WWW/temp/ -etex4ht-32.env -m644\n\
 
335
---------------------------------------------------------------\n"
 
336
 
 
337
 "" };
 
338
 
 
339
 
 
340
 
 
341
static void
 
342
 
 
343
#ifdef CDECL
 
344
CDECL
 
345
#endif
 
346
 
 
347
 
 
348
sig_err(ARG_I(int));
 
349
 
 
350
 
 
351
static void err_i( ARG_I(int) );
 
352
 
 
353
 
 
354
static void err_arg( ARG_I(int) );
 
355
 
 
356
 
 
357
static void call_sys(ARG_I(Q_CHAR *));
 
358
 
 
359
 
 
360
static void strct( ARG_II(C_CHAR *, C_CHAR *) );
 
361
 
 
362
 
 
363
 
 
364
 
 
365
static void
 
366
 
 
367
#ifdef CDECL
 
368
CDECL
 
369
#endif
 
370
 
 
371
 
 
372
sig_err
 
373
#ifdef ANSI
 
374
#define SEP ,
 
375
(  int s
 
376
)
 
377
#undef SEP
 
378
#else
 
379
#define SEP ;
 
380
(s)  int s
 
381
;
 
382
#undef SEP
 
383
#endif
 
384
{
 
385
  (void) signal(s,SIG_IGN);  
 
386
  switch( s ){
 
387
#ifdef SIGSEGV
 
388
    case SIGSEGV: err_i(2);
 
389
#endif
 
390
    case SIGFPE : err_i(3);
 
391
#if defined(SIGINT) && !defined(WIN32)
 
392
    case SIGINT : err_i(4);
 
393
#endif
 
394
  }
 
395
  
 
396
#ifdef __DJGPP__
 
397
  if (s != SIGINT && s != SIGQUIT)
 
398
    exit(EXIT_FAILURE);
 
399
#endif
 
400
 
 
401
 
 
402
}
 
403
 
 
404
 
 
405
 
 
406
static void err_i
 
407
#ifdef ANSI
 
408
#define SEP ,
 
409
(      int  n
 
410
 
 
411
)
 
412
#undef SEP
 
413
#else
 
414
#define SEP ;
 
415
(n)      int  n
 
416
 
 
417
;
 
418
#undef SEP
 
419
#endif
 
420
{  (IGNORED) fprintf(stderr,"--- error --- ");
 
421
   (IGNORED) fprintf(stderr, warn_err_mssg[n]);
 
422
   exit(EXIT_FAILURE);
 
423
}
 
424
 
 
425
 
 
426
 
 
427
static void err_arg
 
428
#ifdef ANSI
 
429
#define SEP ,
 
430
(      int  n
 
431
 
 
432
)
 
433
#undef SEP
 
434
#else
 
435
#define SEP ;
 
436
(n)      int  n
 
437
 
 
438
;
 
439
#undef SEP
 
440
#endif
 
441
{  (IGNORED) fprintf(stderr,"--- error --- ");
 
442
   (IGNORED) fprintf(stderr, warn_err_mssg[n]);
 
443
   exit(EXIT_FAILURE);
 
444
}
 
445
 
 
446
 
 
447
 
 
448
static void call_sys
 
449
#ifdef ANSI
 
450
#define SEP ,
 
451
(  Q_CHAR * command
 
452
)
 
453
#undef SEP
 
454
#else
 
455
#define SEP ;
 
456
(command)  Q_CHAR * command
 
457
;
 
458
#undef SEP
 
459
#endif
 
460
{
 
461
   if( *command ){
 
462
      (IGNORED) printf("htcmd calls: %s\n", command);
 
463
      system_return = system_yes?  (int) system(command) : -1;
 
464
      (IGNORED) printf("%shtcmd returns: %d\n",
 
465
            system_return? "--- Warning --- " : "", system_return );
 
466
   }
 
467
}
 
468
 
 
469
 
 
470
 
 
471
static void strct
 
472
#ifdef ANSI
 
473
#define SEP ,
 
474
(
 
475
     Q_CHAR * str1 SEP 
 
476
     Q_CHAR * str2
 
477
 
 
478
)
 
479
#undef SEP
 
480
#else
 
481
#define SEP ;
 
482
( str1, str2 )
 
483
     Q_CHAR * str1 SEP 
 
484
     Q_CHAR * str2
 
485
 
 
486
;
 
487
#undef SEP
 
488
#endif
 
489
{   Q_CHAR * ch;
 
490
   ch = str1 + (int) strlen(str1);
 
491
   (IGNORED) strcpy( ch, str2 );
 
492
}
 
493
 
 
494
 
 
495
 
 
496
int 
 
497
#ifdef CDECL
 
498
CDECL
 
499
#endif
 
500
 
 
501
 main
 
502
#ifdef ANSI
 
503
#define SEP ,
 
504
(
 
505
       int  argc SEP 
 
506
       Q_CHAR **argv
 
507
)
 
508
#undef SEP
 
509
#else
 
510
#define SEP ;
 
511
(argc, argv)
 
512
       int  argc SEP 
 
513
       Q_CHAR **argv
 
514
;
 
515
#undef SEP
 
516
#endif
 
517
 
518
int i;
 
519
BOOL slash, dslash;
 
520
char *in_command, *command, *p, *q;
 
521
 
 
522
 
 
523
   
 
524
 
 
525
#ifdef SIGSEGV
 
526
  (void) signal(SIGSEGV,sig_err);
 
527
#endif
 
528
  (void) signal(SIGFPE,sig_err);
 
529
#ifdef KWIN32
 
530
  
 
531
SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
 
532
 
 
533
 
 
534
#else
 
535
#ifdef SIGINT
 
536
  (void) signal(SIGINT,sig_err);    
 
537
#endif
 
538
#endif
 
539
 
 
540
 
 
541
#ifdef PLATFORM
 
542
   (IGNORED) printf("htcmd.c (2004-12-16-16:20 %s)\n",PLATFORM);
 
543
#else
 
544
   (IGNORED) printf("htcmd.c (2004-12-16-16:20)\n");
 
545
#endif
 
546
  
 
547
{                   C_CHAR   *yes = NULL;
 
548
  system_yes = (
 
549
#ifdef SYSTEM_FUNCTION_OK
 
550
0
 
551
#else
 
552
system( yes ) != 0
 
553
#endif
 
554
 
 
555
);
 
556
}
 
557
 
 
558
 
 
559
  
 
560
  in_command = (char *) malloc(1024);
 
561
  command = (char *) malloc(1024);
 
562
  in_command[0] = '\0';
 
563
  
 
564
  if( argc == 1 ){ bad_arg; }
 
565
  slash = eq_str(argv[1],"-slash") ;
 
566
  dslash = eq_str(argv[1],"-dslash") ;
 
567
  for(i=1+slash+dslash; i<argc; i++){
 
568
     (IGNORED) printf("%s ", argv[i]);
 
569
     (IGNORED) strct(in_command,argv[i]);
 
570
     (IGNORED) strct(in_command," ");
 
571
  }
 
572
  (IGNORED) printf("\n");
 
573
 
 
574
 
 
575
  
 
576
p = in_command;
 
577
q = command;
 
578
do{
 
579
  if( (*p != '"' ) && (*p != '\'' ) && (*p != '`' ) ){
 
580
    if(slash && (*p == '/')) {
 
581
      *(q++) = '\\';
 
582
    }
 
583
    else if(dslash && (*p == '/')) {
 
584
      *(q++) = '\\';
 
585
      *(q++) = '\\';
 
586
    }
 
587
    else { *(q++) =  *p;  }
 
588
  }
 
589
} while (*(p++) != '\0');
 
590
(IGNORED) call_sys(command);
 
591
 
 
592
 
 
593
   return 0;
 
594
}
 
595
 
 
596