~ubuntu-branches/ubuntu/karmic/dbacl/karmic

« back to all changes in this revision

Viewing changes to src/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Zak B. Elep
  • Date: 2006-03-26 22:35:35 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060326223535-bo3m96paoczzz59n
Tags: 1.12-1
* New upstream release
  + `dbacl -V' now exits with status 0.  (Closes: #339394)
* debian/rules:
  + Upstream now fixes TREC file permissions.  However some new scripts got
    added, so this time its a a+x fix instead of a-x.
* debian/patches:
  + Removed 10_slang2_conversion.patch from Clint, now merged upstream.
  + Updated 20_autotools_update.patch .

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <stdarg.h>
33
33
#include <sys/stat.h>
34
34
#include <fcntl.h>
 
35
#include <math.h>
35
36
#include "util.h"
36
37
 
 
38
/*@constant double M_LN2@*/
 
39
 
37
40
extern char *progname;
38
41
extern char *inputfile;
39
42
extern long inputline;
98
101
#endif
99
102
}
100
103
 
 
104
void cleanup_tempfiles() {
 
105
  if( cleanup.tempfile ) { 
 
106
    unlink(cleanup.tempfile);
 
107
    cleanup.tempfile = NULL;
 
108
  }
 
109
}
 
110
 
101
111
 
102
112
void set_iobuf_mode(FILE *input) {
103
113
  struct stat statinfo;
170
180
  return ((weight_t)d) / (order<<DIG_FACTOR);
171
181
}
172
182
 
 
183
double nats2bits(double score) {
 
184
  return score/M_LN2;
 
185
}
 
186
 
173
187
 
174
188
 
175
189
/***********************************************************
189
203
void sigsegv(int signum) {
190
204
  fprintf(stdout, "%s:error: segmentation fault at input line %ld of %s\n", 
191
205
          progname, inputline, inputfile);
192
 
  exit(0);
 
206
  cleanup_tempfiles();
 
207
  exit(1);
193
208
}
194
209
 
195
210
/* intercepts typical termination signals and tries to do the right thing */
238
253
    sigprocmask(SIG_BLOCK, &act.sa_mask, NULL);
239
254
    switch(sa_signal) {
240
255
    case SIGINT:
241
 
      if( cleanup.tempfile ) { 
242
 
        unlink(cleanup.tempfile);
243
 
      }
 
256
      cleanup_tempfiles();
244
257
      fprintf(stderr, 
245
258
              "%s:signal: caught interrupt request, exiting\n", progname);
246
259
      exit(1);
247
260
      break;
248
261
    case SIGPIPE:
249
262
      /* should we terminate, or should we ignore? */
250
 
      if( cleanup.tempfile ) { 
251
 
        unlink(cleanup.tempfile); 
252
 
      }
 
263
      cleanup_tempfiles();
253
264
      fprintf(stderr,
254
265
              "%s:error: broken pipe on output, exiting\n", progname);
255
266
      exit(1);
314
325
#endif
315
326
 
316
327
  if( etype == E_FATAL ) { 
317
 
    exit(0);
 
328
    cleanup_tempfiles();
 
329
    exit(1);
318
330
  }
319
331
}
320
332
 
367
379
        fprintf(stderr, 
368
380
                "error: not enough memory for input line (%d bytes)\n",
369
381
                textbuf_len);
370
 
        exit(0);
 
382
        cleanup_tempfiles();
 
383
        exit(1);
371
384
      }
372
385
 
373
386
      s = textbuf + textbuf_len - (k++);
415
428
              "error: not enough memory for wide character conversion "
416
429
              "(%ld bytes)\n",
417
430
              (long int)(wc_textbuf_len * sizeof(wchar_t)));
418
 
      exit(0);
 
431
      cleanup_tempfiles();
 
432
      exit(1);
419
433
    }
420
434
 
421
435
    MADVISE(wc_textbuf, sizeof(wchar_t) * wc_textbuf_len, MADV_SEQUENTIAL);