~ubuntu-branches/ubuntu/quantal/brltty/quantal-proposed

« back to all changes in this revision

Viewing changes to Programs/ctb_compile.c

  • Committer: Package Import Robot
  • Author(s): Luke Yelavich
  • Date: 2012-06-08 14:56:32 UTC
  • mfrom: (2.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20120608145632-xr5cg5x2is0mo8ng
Tags: 4.4-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Add brltty-setup, installed in both the udeb and the normal system.
  - Add initramfs integration to run brltty-setup if necessary before
    usplash starts.
  - Add ubiquity integration to propagate any brltty configuration to the
    target system.
  - Add udev rules and /lib/brltty/brltty.sh to the normal (non-udeb)
    package as well.
  - Enable brltty if /etc/default/brltty has RUN_BRLTTY=yes, which is set
    by the installer if brltty is configured; add a NEWS entry for
    upgraders.
  - Don't install /etc/brltty.conf in the package
  - Install udev rules with the same name (85-brltty.rules) in the udeb as
    in the deb.
  - Remove the dh-lisp build-dependency, remove the cl-brlapi package, and
    adjust the brltty package description accordingly. dh-lisp is not
    in main.
  - Build for all python versions (python 2.6), not just the current
    version.
  - Enable brltty at startup on the target system if the alternate installer
    is used.
  - Create separate rules file for the brltty deb, with the rules now
    pointing to a separate script
  - Add gbp.conf file for git buildpackage
  - Do not build the at-spi driver, the legacy at-spi stack is no longer in
    the archive.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * BRLTTY - A background process providing access to the console screen (when in
3
3
 *          text mode) for a blind person using a refreshable braille display.
4
4
 *
5
 
 * Copyright (C) 1995-2011 by The BRLTTY Developers.
 
5
 * Copyright (C) 1995-2012 by The BRLTTY Developers.
6
6
 *
7
7
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
8
8
 *
20
20
 
21
21
#include <stdio.h>
22
22
#include <string.h>
 
23
#include <errno.h>
23
24
 
 
25
#include "log.h"
24
26
#include "file.h"
25
27
#include "ctb.h"
26
28
#include "ctb_internal.h"
27
29
#include "datafile.h"
28
30
#include "dataarea.h"
29
31
#include "brldots.h"
 
32
#include "hostcmd.h"
30
33
 
31
34
typedef struct {
32
35
  unsigned char length;
637
640
  }
638
641
}
639
642
 
 
643
int
 
644
startContractionCommand (ContractionTable *table) {
 
645
  if (!table->data.external.commandStarted) {
 
646
    const char *command[] = {table->command, NULL};
 
647
    HostCommandOptions options;
 
648
 
 
649
    initializeHostCommandOptions(&options);
 
650
    options.asynchronous = 1;
 
651
    options.standardInput = &table->data.external.standardInput;
 
652
    options.standardOutput = &table->data.external.standardOutput;
 
653
 
 
654
    logMessage(LOG_DEBUG, "starting external contraction table: %s", table->command);
 
655
    if (runHostCommand(command, &options) != 0) return 0;
 
656
    logMessage(LOG_DEBUG, "external contraction table started: %s", table->command);
 
657
 
 
658
    table->data.external.commandStarted = 1;
 
659
  }
 
660
 
 
661
  return 1;
 
662
}
 
663
 
 
664
void
 
665
stopContractionCommand (ContractionTable *table) {
 
666
  if (table->data.external.commandStarted) {
 
667
    fclose(table->data.external.standardInput);
 
668
    fclose(table->data.external.standardOutput);
 
669
 
 
670
    logMessage(LOG_DEBUG, "external contraction table stopped: %s", table->command);
 
671
    table->data.external.commandStarted = 0;
 
672
  }
 
673
}
 
674
 
 
675
static void
 
676
initializeCommonFields (ContractionTable *table) {
 
677
  table->characters.array = NULL;
 
678
  table->characters.size = 0;
 
679
  table->characters.count = 0;
 
680
 
 
681
  table->cache.input.characters = NULL;
 
682
  table->cache.input.size = 0;
 
683
  table->cache.input.count = 0;
 
684
 
 
685
  table->cache.output.cells = NULL;
 
686
  table->cache.output.size = 0;
 
687
  table->cache.output.count = 0;
 
688
 
 
689
  table->cache.offsets.array = NULL;
 
690
  table->cache.offsets.size = 0;
 
691
  table->cache.offsets.count = 0;
 
692
}
 
693
 
640
694
ContractionTable *
641
695
compileContractionTable (const char *fileName) {
642
696
  ContractionTable *table = NULL;
643
697
 
 
698
  if (isHostCommand(fileName)) {
 
699
    if ((table = malloc(sizeof(*table)))) {
 
700
      memset(table, 0, sizeof(*table));
 
701
 
 
702
      if ((table->command = strdup(fileName))) {
 
703
        initializeCommonFields(table);
 
704
        table->data.external.commandStarted = 0;
 
705
 
 
706
        if (startContractionCommand(table)) {
 
707
          return table;
 
708
        }
 
709
 
 
710
        free(table->command);
 
711
      } else {
 
712
        logMallocError();
 
713
      }
 
714
 
 
715
      free(table);
 
716
    } else {
 
717
      logMallocError();
 
718
    }
 
719
 
 
720
    return NULL;
 
721
  }
 
722
 
644
723
  if (setGlobalTableVariables(CONTRACTION_TABLE_EXTENSION, CONTRACTION_SUBTABLE_EXTENSION)) {
645
724
    ContractionTableData ctd;
646
725
    memset(&ctd, 0, sizeof(ctd));
665
744
          if (processDataFile(fileName, processContractionTableLine, &ctd)) {
666
745
            if (saveCharacterTable(&ctd)) {
667
746
              if ((table = malloc(sizeof(*table)))) {
668
 
                table->header.fields = getContractionTableHeader(&ctd);
669
 
                table->size = getDataSize(ctd.area);
 
747
                initializeCommonFields(table);
 
748
                table->command = NULL;
 
749
 
 
750
                table->data.internal.header.fields = getContractionTableHeader(&ctd);
 
751
                table->data.internal.size = getDataSize(ctd.area);
670
752
                resetDataArea(ctd.area);
671
 
 
672
 
                table->characters = NULL;
673
 
                table->charactersSize = 0;
674
 
                table->characterCount = 0;
 
753
              } else {
 
754
                logMallocError();
675
755
              }
676
756
            }
677
757
          }
691
771
 
692
772
void
693
773
destroyContractionTable (ContractionTable *table) {
694
 
  if (table->characters) {
695
 
    free(table->characters);
696
 
    table->characters = NULL;
697
 
  }
698
 
 
699
 
  if (table->size) {
700
 
    free(table->header.fields);
 
774
  if (table->characters.array) {
 
775
    free(table->characters.array);
 
776
    table->characters.array = NULL;
 
777
  }
 
778
 
 
779
  if (table->cache.input.characters) {
 
780
    free(table->cache.input.characters);
 
781
    table->cache.input.characters = NULL;
 
782
  }
 
783
 
 
784
  if (table->cache.output.cells) {
 
785
    free(table->cache.output.cells);
 
786
    table->cache.output.cells = NULL;
 
787
  }
 
788
 
 
789
  if (table->cache.offsets.array) {
 
790
    free(table->cache.offsets.array);
 
791
    table->cache.offsets.array = NULL;
 
792
  }
 
793
 
 
794
  if (table->command) {
 
795
    stopContractionCommand(table);
 
796
    free(table->command);
701
797
    free(table);
 
798
  } else {
 
799
    if (table->data.internal.size) {
 
800
      free(table->data.internal.header.fields);
 
801
      free(table);
 
802
    }
702
803
  }
703
804
}
704
805
 
705
806
char *
706
807
ensureContractionTableExtension (const char *path) {
707
 
  return ensureExtension(path, CONTRACTION_TABLE_EXTENSION);
 
808
  return ensureFileExtension(path, CONTRACTION_TABLE_EXTENSION);
 
809
}
 
810
 
 
811
char *
 
812
makeContractionTablePath (const char *directory, const char *name) {
 
813
  return makeFilePath(directory, name, CONTRACTION_TABLE_EXTENSION);
708
814
}