Back to index

tetex-bin  3.0
Defines | Functions
alephbis.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "alephd.h"

Go to the source code of this file.

Defines

#define EXTERN   extern
#define advance_cin

Functions

void runexternalocp P1C (string, external_ocp_name)

Define Documentation

#define advance_cin
Value:
if ((c_in = fgetc(out_file)) == -1) { \
                         fprintf(stderr, "File contains bad char\n"); \
                         goto end_of_while; \
                    }
#define EXTERN   extern

Definition at line 22 of file alephbis.c.


Function Documentation

void runexternalocp P1C ( string  ,
external_ocp_name   
)

Definition at line 33 of file alephbis.c.

{
  char *in_file_name;
  char *out_file_name;
  FILE *in_file;
  FILE *out_file;
  int in_file_fd;
  int out_file_fd;
  char command_line[400];
  int i;
  unsigned c;
  int c_in;
#ifdef WIN32
  char *tempenv;

#define null_string(s) ((s == NULL) || (*s == '\0'))

  tempenv = getenv("TMPDIR");
  if (null_string(tempenv))
    tempenv = getenv("TEMP");
  if (null_string(tempenv))
    tempenv = getenv("TMP");
  if (null_string(tempenv))
    tempenv = "c:/tmp";     /* "/tmp" is not good if we are on a CD-ROM */
  in_file_name = concat(tempenv, "/__aleph__in__XXXXXX");
  mktemp(in_file_name);
  in_file = fopen(in_file_name, FOPEN_WBIN_MODE);
#else

#if HAVE_MKSTEMP
  in_file_name = xstrdup("/tmp/__aleph__in__XXXXXX");
  in_file_fd = mkstemp(in_file_name);
  in_file = fdopen(in_file_fd, FOPEN_WBIN_MODE);
#else
#if HAVE_MKTEMP
  in_file_name = xstrdup("/tmp/__aleph__in__XXXXXX");
  mktemp(in_file_name);
#else
  in_file_name = xstrdup(tmpnam(NULL));
#endif /* HAVE_MKTEMP */
  in_file = fopen(in_file_name, FOPEN_WBIN_MODE);
#endif /* HAVE_MKSTEMP */

#endif /* WIN32 */

  if (in_file == NULL)
    fprintf(stderr, "aleph: error opening file: %s\n", strerror(errno));
  
  for (i=1; i<=otpinputend; i++) {
      c = otpinputbuf[i];
      if (c>0xffff) {
          fprintf(stderr, "Aleph does not currently support 31-bit chars\n");
          exit(1);
      }
      if (c>0x4000000) {
          fputc(0xfc | ((c>>30) & 0x1), in_file);
          fputc(0x80 | ((c>>24) & 0x3f), in_file);
          fputc(0x80 | ((c>>18) & 0x3f), in_file);
          fputc(0x80 | ((c>>12) & 0x3f), in_file);
          fputc(0x80 | ((c>>6) & 0x3f), in_file);
          fputc(0x80 | (c & 0x3f), in_file);
      } else if (c>0x200000) {
          fputc(0xf8 | ((c>>24) & 0x3), in_file);
          fputc(0x80 | ((c>>18) & 0x3f), in_file);
          fputc(0x80 | ((c>>12) & 0x3f), in_file);
          fputc(0x80 | ((c>>6) & 0x3f), in_file);
          fputc(0x80 | (c & 0x3f), in_file);
      } else if (c>0x10000) {
          fputc(0xf0 | ((c>>18) & 0x7), in_file);
          fputc(0x80 | ((c>>12) & 0x3f), in_file);
          fputc(0x80 | ((c>>6) & 0x3f), in_file);
          fputc(0x80 | (c & 0x3f), in_file);
      } else if (c>0x800) {
          fputc(0xe0 | ((c>>12) & 0xf), in_file);
          fputc(0x80 | ((c>>6) & 0x3f), in_file);
          fputc(0x80 | (c & 0x3f), in_file);
      } else if (c>0x80) {
          fputc(0xc0 | ((c>>6) & 0x1f), in_file);
          fputc(0x80 | (c & 0x3f), in_file);
      } else {
          fputc(c & 0x7f, in_file);
      }
  }
  fclose(in_file);
  
#define advance_cin if ((c_in = fgetc(out_file)) == -1) { \
                         fprintf(stderr, "File contains bad char\n"); \
                         goto end_of_while; \
                    }
                     
#ifdef WIN32
  out_file_name = concat(tempenv, "/__aleph__out__XXXXXX");
  mktemp(out_file_name);
  out_file = fopen(out_file_name, FOPEN_RBIN_MODE);
#else

#if HAVE_MKSTEMP
  out_file_name = xstrdup("/tmp/__aleph__out__XXXXXX");
  out_file_fd = mkstemp(out_file_name);
  out_file = fdopen(out_file_fd, FOPEN_RBIN_MODE);
#else
#if HAVE_MKTEMP
  out_file_name = xstrdup("/tmp/__aleph__out__XXXXXX");
  mktemp(out_file_name);
#else
  out_file_name = xstrdup(tmpnam(NULL));
#endif /* HAVE_MKTEMP */
  out_file = fopen(out_file_name, FOPEN_RBIN_MODE);
#endif /* HAVE_MKSTEMP */

#endif /* WIN32 */
 
  if (out_file == NULL)
    fprintf(stderr, "aleph: error opening file: %s\n", strerror(errno));
  
  sprintf(command_line, "%s <%s >%s\n",
          external_ocp_name+1, in_file_name, out_file_name);
  system(command_line);
  otpoutputend = 0;
  otpoutputbuf[otpoutputend] = 0;
  while ((c_in = fgetc(out_file)) != -1) {
     if (c_in>=0xfc) {
         c = (c_in & 0x1)   << 30;
         {advance_cin}
         c |= (c_in & 0x3f) << 24;
         {advance_cin}
         c |= (c_in & 0x3f) << 18;
         {advance_cin}
         c |= (c_in & 0x3f) << 12;
         {advance_cin}
         c |= (c_in & 0x3f) << 6;
         {advance_cin}
         c |= c_in & 0x3f;
     } else if (c_in>=0xf8) {
         c = (c_in & 0x3) << 24;
         {advance_cin}
         c |= (c_in & 0x3f) << 18;
         {advance_cin}
         c |= (c_in & 0x3f) << 12;
         {advance_cin}
         c |= (c_in & 0x3f) << 6;
         {advance_cin}
         c |= c_in & 0x3f;
     } else if (c_in>=0xf0) {
         c = (c_in & 0x7) << 18;
         {advance_cin}
         c |= (c_in & 0x3f) << 12;
         {advance_cin}
         c |= (c_in & 0x3f) << 6;
         {advance_cin}
         c |= c_in & 0x3f;
     } else if (c_in>=0xe0) {
         c = (c_in & 0xf) << 12;
         {advance_cin}
         c |= (c_in & 0x3f) << 6;
         {advance_cin}
         c |= c_in & 0x3f;
     } else if (c_in>=0x80) {
         c = (c_in & 0x1f) << 6;
         {advance_cin}
         c |= c_in & 0x3f;
     } else {
         c = c_in & 0x7f;
     }
     otpoutputbuf[++otpoutputend] = c;
  }

end_of_while:
  remove(in_file_name);
  remove(out_file_name);
}

Here is the call graph for this function: