Ejemplo n.º 1
0
int
parseKeyboardProperties (KeyboardProperties *properties, const char *string) {
  enum {
    KBD_PARM_TYPE,
    KBD_PARM_VENDOR,
    KBD_PARM_PRODUCT
  };

  static const char *const names[] = {"type", "vendor", "product", NULL};
  char **parameters = getParameters(names, NULL, string);
  int ok = 1;

  logParameters(names, parameters, "Keyboard Property");
  *properties = anyKeyboard;

  if (*parameters[KBD_PARM_TYPE]) {
    static const KeyboardType types[] = {KBD_TYPE_Any, KBD_TYPE_PS2, KBD_TYPE_USB, KBD_TYPE_Bluetooth};
    static const char *choices[] = {"any", "ps2", "usb", "bluetooth", NULL};
    unsigned int choice;

    if (validateChoice(&choice, parameters[KBD_PARM_TYPE], choices)) {
      properties->type = types[choice];
    } else {
      logMessage(LOG_WARNING, "invalid keyboard type: %s", parameters[KBD_PARM_TYPE]);
      ok = 0;
    }
  }

  if (*parameters[KBD_PARM_VENDOR]) {
    static const int minimum = 0;
    static const int maximum = 0XFFFF;
    int value;

    if (validateInteger(&value, parameters[KBD_PARM_VENDOR], &minimum, &maximum)) {
      properties->vendor = value;
    } else {
      logMessage(LOG_WARNING, "invalid keyboard vendor code: %s", parameters[KBD_PARM_VENDOR]);
      ok = 0;
    }
  }

  if (*parameters[KBD_PARM_PRODUCT]) {
    static const int minimum = 0;
    static const int maximum = 0XFFFF;
    int value;

    if (validateInteger(&value, parameters[KBD_PARM_PRODUCT], &minimum, &maximum)) {
      properties->product = value;
    } else {
      logMessage(LOG_WARNING, "invalid keyboard product code: %s", parameters[KBD_PARM_PRODUCT]);
      ok = 0;
    }
  }

  deallocateStrings(parameters);
  return ok;
}
Ejemplo n.º 2
0
int
parseTuneVolume (const char *setting) {
  if (setting && *setting) {
    static const int minimum = 0;
    static const int maximum = 100;
    int volume;

    if (!validateInteger(&volume, setting, &minimum, &maximum)) {
      logMessage(LOG_ERR, "%s: %s", "invalid volume percentage", setting);
      return 0;
    }

    switch (prefs.tuneDevice) {
      case tdPcm:
        prefs.pcmVolume = volume;
        break;

      case tdMidi:
        prefs.midiVolume = volume;
        break;

      case tdFm:
        prefs.fmVolume = volume;
        break;

      default:
        break;
    }
  }

  return 1;
}
Ejemplo n.º 3
0
static int
spk_construct (volatile SpeechSynthesizer *spk, char **parameters) {
  spk->setVolume = spk_setVolume;
  spk->setRate = spk_setRate;
  spk->setPitch = spk_setPitch;
  spk->setPunctuation = spk_setPunctuation;

  clearSettings();

  if (parameters[PARM_PORT] && *parameters[PARM_PORT]) {
    static const int minimumPort = 0X1;
    static const int maximumPort = 0XFFFF;
    int port = 0;

    if (validateInteger(&port, parameters[PARM_PORT], &minimumPort, &maximumPort)) {
      char number[0X10];
      snprintf(number, sizeof(number), "%d", port);
      setenv("SPEECHD_PORT", number, 1);
    } else {
      logMessage(LOG_WARNING, "%s: %s", "invalid port number", parameters[PARM_PORT]);
    }
  }

  if (parameters[PARM_MODULE] && *parameters[PARM_MODULE]) {
    moduleName = parameters[PARM_MODULE];
  }

  if (parameters[PARM_LANGUAGE] && *parameters[PARM_LANGUAGE]) {
    languageName = parameters[PARM_LANGUAGE];
  }

  if (parameters[PARM_VOICE] && *parameters[PARM_VOICE]) {
    static const SPDVoiceType voices[] = {
      SPD_MALE1, SPD_FEMALE1,
      SPD_MALE2, SPD_FEMALE2,
      SPD_MALE3, SPD_FEMALE3,
      SPD_CHILD_MALE, SPD_CHILD_FEMALE
    };

    static const char *choices[] = {
      "male1", "female1",
      "male2", "female2",
      "male3", "female3",
      "child_male", "child_female",
      NULL
    };

    unsigned int choice = 0;

    if (validateChoice(&choice, parameters[PARM_VOICE], choices)) {
      voiceType = voices[choice];
    } else {
      logMessage(LOG_WARNING, "%s: %s", "invalid voice type", parameters[PARM_VOICE]);
    }
  }

  return openConnection();
}
Ejemplo n.º 4
0
static int
spk_construct (volatile SpeechSynthesizer *spk, char **parameters) {
  int code;

  spk->setVolume = spk_setVolume;
  spk->setRate = spk_setRate;

  loadSynthesisLibrary();

  if ((speechQueue = newQueue(deallocateSpeechItem, NULL))) {
    if (mpChannelInitEx) {
      if (!(code = mpChannelInitEx(&speechChannel, NULL, NULL, NULL))) {
        memset(&speechParameters, 0, sizeof(speechParameters));
        speechParameters.nWriteWavHeader = 0;
        speechParameters.pfnWrite = writeSound;
        speechParameters.pWriteData = NULL;

        {
          const char *name = parameters[PARM_NAME];
          if (name && *name) {
            char tag[0X100];
            snprintf(tag, sizeof(tag), "<voice name=\"%s\"/>", name);
            enqueueTag(tag);
          }
        }

        {
          const char *pitch = parameters[PARM_PITCH];
          if (pitch && *pitch) {
            int setting = 0;
            static const int minimum = -10;
            static const int maximum = 10;
            if (validateInteger(&setting, pitch, &minimum, &maximum)) {
              char tag[0X100];
              snprintf(tag, sizeof(tag), "<pitch absmiddle=\"%d\"/>", setting);
              enqueueTag(tag);
            } else {
              logMessage(LOG_WARNING, "%s: %s", "invalid pitch specification", pitch);
            }
          }
        }

        return 1;
      } else {
        logSynthesisError(code, "channel initialization");
      }
    }
  } else {
    logMessage(LOG_ERR, "Cannot allocate speech queue.");
  }

  spk_destruct(spk);
  return 0;
}
Ejemplo n.º 5
0
END_OPTION_TABLE

static int
setRegion (
  int *offsetValue, const char *offsetOption, const char *offsetName,
  int *sizeValue, const char *sizeOption, int sizeLimit, const char *sizeName
) {
  if (*offsetOption) {
    {
      const int minimum = 0;
      const int maximum = sizeLimit - 1;
      if (!validateInteger(offsetValue, offsetOption, &minimum, &maximum)) {
        logMessage(LOG_ERR, "invalid %s: %s", offsetName, offsetOption);
        return 0;
      }
    }

    if (*sizeOption) {
      const int minimum = 1;
      const int maximum = sizeLimit - *offsetValue;
      if (!validateInteger(sizeValue, sizeOption, &minimum, &maximum)) {
        logMessage(LOG_ERR, "invalid %s: %s", sizeName, sizeOption);
        return 0;
      }
      return 1;
    }
  } else if (*sizeOption) {
    const int minimum = 1;
    const int maximum = sizeLimit;
    if (!validateInteger(sizeValue, sizeOption, &minimum, &maximum)) {
      logMessage(LOG_ERR, "invalid %s: %s", sizeName, sizeOption);
      return 0;
    }
    *offsetValue = (sizeLimit - *sizeValue) / 2;
    return 1;
  } else {
    *offsetValue = sizeLimit / 4;
  }
  if ((*sizeValue = sizeLimit - (*offsetValue * 2)) < 1) *sizeValue = 1;
  return 1;
}
/*!
 \fn validateData
 \return boolean - true, everything validated OK, false otherwise
 
 Validates data in this container. 
 */   
bool NmApiMailboxSettingsDataPrivate::validateData() const
{
    NM_FUNCTION;
    QHash<int, QVariant>::const_iterator i = mSettings->constBegin();
    while (i != mSettings->constEnd()) {
        
        bool validated = false;
        bool valid = false;        
        
        int key = i.key();
        QVariant val = i.value();
        
        ++i;
        
        valid = validateString(key ,val, validated);
        if (validated) {
            if (!valid){
                return valid;
            }
            continue;
        }
        
        valid = validateInteger(key ,val, validated);
        if (validated) {
            if (!valid){
                return valid;
            }
            continue;
        }
         
        valid = validateBool(key ,val, validated);
        if (validated) {
            if (!valid){
                return valid;
            }
            continue;
        } 
         
        valid = validateDateTime(key ,val, validated);
        if (validated) {
            if (!valid){
                return valid;
            }
            continue;
        }
     }
     return true;
}
Ejemplo n.º 7
0
static int
brl_construct (BrailleDisplay *brl, char **parameters, const char *device) {
  unsigned int ttyBaud = 9600;
  char *ttyType = "vt100";
  int windowLines = 1;
  int windowColumns = 40;

#ifdef HAVE_ICONV_H
  const char *characterSet = getLocaleCharset();
#endif /* HAVE_ICONV_H */

  if (!isSerialDevice(&device)) {
    unsupportedDevice(device);
    return 0;
  }

  {
    unsigned int baud = ttyBaud;
    if (serialValidateBaud(&baud, "TTY baud", parameters[PARM_BAUD], NULL))
      ttyBaud = baud;
  }

#ifdef USE_CURSES
  if (*parameters[PARM_TERM])
    ttyType = parameters[PARM_TERM];
#endif /* USE_CURSES */

  {
    static const int minimum = 1;
    static const int maximum = MAX_WINDOW_LINES;
    int lines = windowLines;
    if (validateInteger(&lines, parameters[PARM_LINES], &minimum, &maximum)) {
      windowLines = lines;
    } else {
      logMessage(LOG_WARNING, "%s: %s", "invalid line count", parameters[PARM_LINES]);
    }
  }

  {
    static const int minimum = 1;
    static const int maximum = MAX_WINDOW_COLUMNS;
    int columns = windowColumns;
    if (validateInteger(&columns, parameters[PARM_COLUMNS], &minimum, &maximum)) {
      windowColumns = columns;
    } else {
      logMessage(LOG_WARNING, "%s: %s", "invalid column count", parameters[PARM_COLUMNS]);
    }
  }

#ifdef HAVE_ICONV_H
  if (*parameters[PARM_CHARSET])
    characterSet = parameters[PARM_CHARSET];
#endif /* HAVE_ICONV_H */

  if (*parameters[PARM_LOCALE])
    classificationLocale = parameters[PARM_LOCALE];

#ifdef HAVE_ICONV_H
  if ((conversionDescriptor = iconv_open(characterSet, "WCHAR_T")) != (iconv_t)-1) {
#endif /* HAVE_ICONV_H */
    if ((ttyDevice = serialOpenDevice(device))) {
      if (serialRestartDevice(ttyDevice, ttyBaud)) {
#ifdef USE_CURSES
        if ((ttyStream = serialGetStream(ttyDevice))) {
          if ((ttyScreen = newterm(ttyType, ttyStream, ttyStream))) {
            cbreak();
            noecho();
            nonl();

            nodelay(stdscr, TRUE);
            intrflush(stdscr, FALSE);
            keypad(stdscr, TRUE);

            clear();
            refresh();
#endif /* USE_CURSES */

            brl->textColumns = windowColumns;
            brl->textRows = windowLines; 

            logMessage(LOG_INFO, "TTY: type=%s baud=%u size=%dx%d",
                       ttyType, ttyBaud, windowColumns, windowLines);
            return 1;
#ifdef USE_CURSES
          } else {
            logSystemError("newterm");
          }

          ttyStream = NULL;
        }
#endif /* USE_CURSES */
      }

      serialCloseDevice(ttyDevice);
      ttyDevice = NULL;
    }

#ifdef HAVE_ICONV_H
    iconv_close(conversionDescriptor);
  } else {
    logSystemError("iconv_open");
  }
  conversionDescriptor = NULL;
#endif /* HAVE_ICONV_H */

  return 0;
}
Ejemplo n.º 8
0
int
main (int argc, char *argv[]) {
  {
    static const OptionsDescriptor descriptor = {
      OPTION_TABLE(programOptions),
      .applicationName = "tunetest",
      .argumentsSummary = "{note duration} ..."
    };
    PROCESS_OPTIONS(descriptor, argc, argv);
  }

  resetPreferences();

  if (opt_tuneDevice && *opt_tuneDevice) {
    unsigned int device;

    if (!validateChoice(&device, opt_tuneDevice, deviceNames)) {
      logMessage(LOG_ERR, "%s: %s", "invalid tune device", opt_tuneDevice);
      return PROG_EXIT_SYNTAX;
    }

    prefs.tuneDevice = device;
  }

#ifdef HAVE_MIDI_SUPPORT
  if (opt_midiInstrument && *opt_midiInstrument) {
    unsigned char instrument;

    if (!validateInstrument(&instrument, opt_midiInstrument)) {
      logMessage(LOG_ERR, "%s: %s", "invalid musical instrument", opt_midiInstrument);
      return PROG_EXIT_SYNTAX;
    }

    prefs.midiInstrument = instrument;
  }
#endif /* HAVE_MIDI_SUPPORT */

  if (opt_outputVolume && *opt_outputVolume) {
    static const int minimum = 0;
    static const int maximum = 100;
    int volume;

    if (!validateInteger(&volume, opt_outputVolume, &minimum, &maximum)) {
      logMessage(LOG_ERR, "%s: %s", "invalid volume percentage", opt_outputVolume);
      return PROG_EXIT_SYNTAX;
    }

    switch (prefs.tuneDevice) {
      case tdPcm:
        prefs.pcmVolume = volume;
        break;

      case tdMidi:
        prefs.midiVolume = volume;
        break;

      case tdFm:
        prefs.fmVolume = volume;
        break;

      default:
        break;
    }
  }

  if (!argc) {
    logMessage(LOG_ERR, "missing tune.");
    return PROG_EXIT_SYNTAX;
  }

  if (argc % 2) {
    logMessage(LOG_ERR, "missing note duration.");
    return PROG_EXIT_SYNTAX;
  }

  {
    unsigned int count = argc / 2;
    TuneElement *elements = malloc((sizeof(*elements) * count) + 1);

    if (elements) {
      TuneElement *element = elements;

      while (argc) {
        int note;
        int duration;

        {
          static const int minimum = 0X01;
          static const int maximum = 0X7F;
          const char *argument = *argv++;
          if (!validateInteger(&note, argument, &minimum, &maximum)) {
            logMessage(LOG_ERR, "%s: %s", "invalid note number", argument);
            return PROG_EXIT_SYNTAX;
          }
          --argc;
        }

        {
          static const int minimum = 1;
          static const int maximum = 255;
          const char *argument = *argv++;
          if (!validateInteger(&duration, argument, &minimum, &maximum)) {
            logMessage(LOG_ERR, "%s: %s", "invalid note duration", argument);
            return PROG_EXIT_SYNTAX;
          }
          --argc;
        }

        {
          TuneElement te = TUNE_NOTE(duration, note);
          *(element++) = te;
        }
      }

      {
        TuneElement te = TUNE_STOP();
        *element = te;
      }
    } else {
      logMallocError();
      return PROG_EXIT_FATAL;
    }

    if (!setTuneDevice(prefs.tuneDevice)) {
      logMessage(LOG_ERR, "unsupported tune device: %s", deviceNames[prefs.tuneDevice]);
      return PROG_EXIT_SEMANTIC;
    }

    {
      playTune(elements);
      closeTuneDevice();
    }

    free(elements);
  }

  return PROG_EXIT_SUCCESS;
}
Ejemplo n.º 9
0
static int
spk_construct (volatile SpeechSynthesizer *spk, char **parameters) {
  theta_voice_search criteria;

  memset(&criteria, 0, sizeof(criteria));
  initializeTheta();

  spk->setVolume = spk_setVolume;
  spk->setRate = spk_setRate;

  if (*parameters[PARM_GENDER]) {
    const char *const choices[] = {"male", "female", "neuter", NULL};
    unsigned int choice;
    if (validateChoice(&choice, parameters[PARM_GENDER], choices)) {
      criteria.gender = (char *)choices[choice];
    } else {
      logMessage(LOG_WARNING, "%s: %s", "invalid gender specification", parameters[PARM_GENDER]);
    }
  }

  if (*parameters[PARM_LANGUAGE]) criteria.lang = parameters[PARM_LANGUAGE];

  if (*parameters[PARM_AGE]) {
    const char *word = parameters[PARM_AGE];
    int value;
    int younger;
    static const int minimumAge = 1;
    static const int maximumAge = 99;
    if ((younger = word[0] == '-') && word[1]) ++word;
    if (validateInteger(&value, word, &minimumAge, &maximumAge)) {
      if (younger) value = -value;
      criteria.age = value;
    } else {
      logMessage(LOG_WARNING, "%s: %s", "invalid age specification", word);
    }
  }

  {
    const char *name = parameters[PARM_NAME];
    if (name && (*name == '/')) {
      theta_voice_desc *descriptor = theta_try_voxdir(name, &criteria);
      if (descriptor) {
        loadVoice(descriptor);
        theta_free_voice_desc(descriptor);
      }
    } else {
      theta_voice_desc *descriptors = theta_enum_voices(theta_voxpath, &criteria);
      if (descriptors) {
        theta_voice_desc *descriptor;
        for (descriptor=descriptors; descriptor; descriptor=descriptor->next) {
          if (*name)
            if (strcasecmp(name, descriptor->human) != 0)
              continue;
          loadVoice(descriptor);
          if (voice) break;
        }
        theta_free_voicelist(descriptors);
      }
    }
  }

  if (voice) {
    {
      float pitch = 0.0;
      static const float minimumPitch = -2.0;
      static const float maximumPitch = 2.0;
      if (validateFloat(&pitch, parameters[PARM_PITCH], &minimumPitch, &maximumPitch)) {
        theta_set_pitch_shift(voice, pitch, NULL);
      } else {
        logMessage(LOG_WARNING, "%s: %s", "invalid pitch shift specification", parameters[PARM_PITCH]);
      }
    }

    logMessage(LOG_INFO, "Theta Engine: version %s", theta_version);
    return 1;
  }

  logMessage(LOG_WARNING, "No voices found.");
  return 0;
}
Ejemplo n.º 10
0
/* the braille display can be resized without reloading the driver */ 
static int brl_construct(BrailleDisplay *brl, char **parameters, const char *device)
{
#ifdef SendIdReq
  unsigned char ch = '?';
  int i;
#endif /* SendIdReq */
  int ds = BRAILLEDISPLAYSIZE;
  int promVersion = 4;
  unsigned int ttyBaud = 57600;
  if (*parameters[PARM_DISPSIZE]) {
    int dsmin=20, dsmax=40;
    if (!validateInteger(&ds, parameters[PARM_DISPSIZE], &dsmin, &dsmax))
      logMessage(LOG_WARNING, "%s: %s", "invalid braille display size", parameters[PARM_DISPSIZE]);
  }
  if (*parameters[PARM_PROMVER]) {
    int pvmin=3, pvmax=6;
    if (!validateInteger(&promVersion, parameters[PARM_PROMVER], &pvmin, &pvmax))
      logMessage(LOG_WARNING, "%s: %s", "invalid PROM version", parameters[PARM_PROMVER]);
  }
  if (*parameters[PARM_BAUD]) {
    unsigned int baud;
    if (serialValidateBaud(&baud, "TTY baud", parameters[PARM_BAUD], NULL)) {
      ttyBaud = baud;
    }
  }

  if (!isSerialDeviceIdentifier(&device)) {
    unsupportedDeviceIdentifier(device);
    return 0;
  }
  if (!(serialDevice = serialOpenDevice(device))) return 0;
  serialSetParity(serialDevice, SERIAL_PARITY_ODD);
  if (promVersion<4) serialSetFlowControl(serialDevice, SERIAL_FLOW_INPUT_CTS);
  serialRestartDevice(serialDevice,ttyBaud); 
#ifdef SendIdReq
  {
    brl_writePacket(brl,(unsigned char *) &ch,1); 
    i=5; 
    while (i>0) {
      if (brl_readPacket(brl,(unsigned char *) &terminfo,sizeof(terminfo))!=0) {
        if (terminfo.code=='?') {
          terminfo.f2[10] = '\0';
          break;
        }
      }
      i--;
    }
    if (i==0) {
      logMessage(LOG_WARNING,"Unable to identify terminal properly");  
      if (!brl->textColumns) brl->textColumns = BRAILLEDISPLAYSIZE;  
    } else {
      logMessage(LOG_INFO,"Braille terminal description:");
      logMessage(LOG_INFO,"   version=%c%c%c",terminfo.version[0],terminfo.version[1],terminfo.version[2]);
      logMessage(LOG_INFO,"   f1=%c",terminfo.f1);
      logMessage(LOG_INFO,"   size=%c%c",terminfo.size[0],terminfo.size[1]);
      logMessage(LOG_INFO,"   dongle=%c",terminfo.dongle);
      logMessage(LOG_INFO,"   clock=%c",terminfo.clock);
      logMessage(LOG_INFO,"   routing=%c",terminfo.routing);
      logMessage(LOG_INFO,"   flash=%c",terminfo.flash);
      logMessage(LOG_INFO,"   prog=%c",terminfo.prog);
      logMessage(LOG_INFO,"   lcd=%c",terminfo.lcd);
      logMessage(LOG_INFO,"   f2=%s",terminfo.f2);  
      if (brl->textColumns<=0)
        brl->textColumns = (terminfo.size[0]-'0')*10 + (terminfo.size[1]-'0');
    }
  }
#else /* SendIdReq */
  brl->textColumns = ds;
#endif /* SendIdReq */
  brl->textRows=1; 

  {
    /* The following table defines how internal brltty format is converted to */
    /* VisioBraille format. */
    /* The table is declared static so that it is in data segment and not */
    /* in the stack */ 
    static const TranslationTable outputTable = {
#include "brl-out.h"
    };
    setOutputTable(outputTable);
  }

  return 1;
}