コード例 #1
0
ファイル: main.c プロジェクト: pik694/project-I
void getData (int whatToDo){
    switch (whatToDo) {
        case 0:
            return;
            
        case 1:
            while (1){
                printf("Podaj punkt x : \n");
                if (scanf("%lf", &X) && (X > -1) && (X < 1)){
                    break;
                }
                inputError(errorX);
            }
            
        case 2:
            while (1){
                double currN;
                printf("Podaj dokladnosc n : \n");
                if (scanf("%lf", &currN) && (currN >= 0) && ((int)currN == currN)){
                    N = currN;
                    ALPHA = N + 1;
                    break;
                }
                inputError(errorN);
            }
            break;
        default:
            printf("wywolanie funkcji getData(int) z nieoczekiwanym parametrem\n");
            break;
    }
}
コード例 #2
0
    /**Creates an instance of a function
     * @param input :: An input string which defines the function and initial values for the parameters.
     * Parameters of different functions are separated by ';'. Parameters of the same function
     * are separated by ','. parameterName=value pairs are used to set a parameter value. For each function
     * "name" parameter must be set to a function name. E.g.
     * input = "name=LinearBackground,A0=0,A1=1; name = Gaussian, PeakCentre=10.,Sigma=1"
     * @return A pointer to the created function
     */
    IFitFunction* FunctionFactoryImpl::createInitialized(const std::string& input) const
    {
      //std::vector<std::string> ops;
      //ops.push_back(";");
      //ops.push_back(",");
      //ops.push_back("=");
      //ops.push_back("== < > <= >=");

      Expression expr;
      try
      {
        expr.parse(input);
      }
      catch(...)
      {
        inputError(input);
      }

      const Expression& e = expr.bracketsRemoved();

      if (e.name() == ";")
      {
        IFitFunction* fun = createComposite(e);
        if (!fun) inputError();
        return fun;
      }

      return createSimple(e);

    }
コード例 #3
0
ファイル: FunctionFactory.cpp プロジェクト: trnielsen/mantid
    /** 
     * Create a function from an expression.
     * @param expr :: The input expression
     * @param parentAttributes :: An output map filled with the attribute name & values of the parent function
     * @return A pointer to the created function
     */
    IFunction_sptr FunctionFactoryImpl::createSimple(const Expression& expr, std::map<std::string,std::string>& parentAttributes)const
    {
      if (expr.name() == "=" && expr.size() > 1)
      {
        return createFunction(expr.terms()[1].name());
      }

      if (expr.name() != "," || expr.size() == 0)
      {
        inputError(expr.str());
      }

      const std::vector<Expression>& terms = expr.terms();
      std::vector<Expression>::const_iterator term = terms.begin();

      if (term->name() != "=") inputError(expr.str());
      if (term->terms()[0].name() != "name" && term->terms()[0].name() != "composite")
      {
        throw std::invalid_argument("Function name must be defined before its parameters");
      }
      std::string fnName = term->terms()[1].name();

      IFunction_sptr fun = createFunction(fnName);
      for(++term;term!=terms.end();++term)
      {// loop over function's parameters/attributes
        if (term->name() != "=") inputError(expr.str());
        std::string parName = term->terms()[0].name();
        std::string parValue = term->terms()[1].str();
        if (fun->hasAttribute(parName))
        {// set attribute
          if (parValue.size() > 1 && parValue[0] == '"')
          {// remove the double quotes
            parValue = parValue.substr(1,parValue.size()-2);
          }
          IFunction::Attribute att = fun->getAttribute(parName);
          att.fromString(parValue);
          fun->setAttribute(parName,att);
        }
        else if (parName.size() >= 10 && parName.substr(0,10) == "constraint")
        {// or it can be a list of constraints
          addConstraints(fun,(*term)[1]);
        }
        else if (parName == "ties")
        {
          addTies(fun,(*term)[1]);
        }
        else if (!parName.empty() && parName[0] == '$')
        {
          parName.erase(0,1);
          parentAttributes[parName] = parValue;
        }
        else
        {// set initial parameter value
          fun->setParameter(parName,atof(parValue.c_str()));
        }
      }// for term

      fun->applyTies();
      return fun;
    }
コード例 #4
0
ファイル: main.c プロジェクト: matthewsedam/pi
int main(int argc, const char *argv[]) {
    unsigned long numberOfDigits = 100;
    if (argc == 2) {
        if (argv[1][0] == '-')
            inputError();
        char * endptr;
        numberOfDigits = strtol(argv[1], &endptr, 10);
        if (*endptr != '\0')
            inputError();
    } else
        inputError();
    if (numberOfDigits < 1)
        inputError();
    else if (numberOfDigits == 1) {
        printf("3\n");
        return 0;
    }
    long numberOfCPUs = sysconf(_SC_NPROCESSORS_ONLN);
    char * piString;
    if (numberOfCPUs > 1)
        piString = piChudnovskyMultiCore(numberOfDigits);
    else
        piString = piChudnovsky(numberOfDigits);
    printf("%.1s.%s\n", piString, piString + 1);
    free(piString);
    return 0;
}
コード例 #5
0
ファイル: FunctionFactory.cpp プロジェクト: mducle/mantid
/**Creates an instance of a function
 * @param input :: An input string which defines the function and initial values
 * for the parameters.
 * Parameters of different functions are separated by ';'. Parameters of the
 * same function
 * are separated by ','. parameterName=value pairs are used to set a parameter
 * value. For each function
 * "name" parameter must be set to a function name. E.g.
 * input = "name=LinearBackground,A0=0,A1=1; name = Gaussian,
 * PeakCentre=10.,Sigma=1"
 * @return A pointer to the created function
 */
IFunction_sptr
FunctionFactoryImpl::createInitialized(const std::string &input) const {
  Expression expr;
  try {
    expr.parse(input);
  } catch (...) {
    inputError(input);
  }

  const Expression &e = expr.bracketsRemoved();
  std::map<std::string, std::string> parentAttributes;
  if (e.name() == ";") {
    IFunction_sptr fun = createComposite(e, parentAttributes);
    if (!fun)
      inputError();
    return fun;
  }

  return createSimple(e, parentAttributes);
}
コード例 #6
0
ファイル: main.c プロジェクト: pik694/project-I
int menu(){
    double command;
    
    while (1) {
        printf("Co chcesz zrobić ? \n 1 - wprowadz dane \n 2 - zmien dokladnosc \n 0 - zakoncz program\n");
        if(scanf("%lf", &command) && (command == 0 || command == 1 || command == 2)){break;}
        inputError(errorMenu);
    }
    getData((int)command);
    
    return (int)command;
}
コード例 #7
0
DecisionCreationWidget::DecisionCreationWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DecisionCreationWidget)
{
    ui->setupUi(this);

    ui->pushButtonUpdateDecision->hide();
    updateIndex = -1;

    connect(this, SIGNAL(inputError(QString)),
            this, SLOT(on_inputError(QString)));
}
コード例 #8
0
 /**
   * Create a fitting function from a string.
   * @param input :: The input string, has a form of a function call: funName(attr1=val,param1=val,...,ties=(param3=2*param1,...),constraints=(p2>0,...))
   */
 IFitFunction* FunctionFactoryImpl::createFitFunction(const std::string& input) const
 {
   Expression expr;
   try
   {
     expr.parse(input);
   }
   catch(...)
   {
     inputError(input);
   }
   return createFitFunction(expr);
 }
コード例 #9
0
    /** 
     * Create a function from an expression.
     * @param expr :: The input expression
     * @return A pointer to the created function
     */
    IFitFunction* FunctionFactoryImpl::createSimple(const Expression& expr)const
    {
      if (expr.name() == "=" && expr.size() > 1)
      {
        return createFunction(expr.terms()[1].name());
      }

      if (expr.name() != "," || expr.size() == 0)
      {
        inputError(expr.str());
      }

      const std::vector<Expression>& terms = expr.terms();
      std::vector<Expression>::const_iterator term = terms.begin();

      if (term->name() != "=") inputError(expr.str());
      if (term->terms()[0].name() != "name" && term->terms()[0].name() != "composite")
      {
        throw std::invalid_argument("Function name must be defined before its parameters");
      }
      std::string fnName = term->terms()[1].name();

      IFitFunction* fun = createFunction(fnName);
      std::string wsName,wsParam;
      for(++term;term!=terms.end();++term)
      {// loop over function's parameters/attributes
        if (term->name() != "=") inputError(expr.str());
        std::string parName = term->terms()[0].name();
        std::string parValue = term->terms()[1].str();
        if (fun->hasAttribute(parName))
        {// set attribute
          if (parValue.size() > 1 && parValue[0] == '"')
          {// remove the double quotes
            parValue = parValue.substr(1,parValue.size()-2);
          }
          IFitFunction::Attribute att = fun->getAttribute(parName);
          att.fromString(parValue);
          fun->setAttribute(parName,att);
        }
        else if (parName.size() >= 10 && parName.substr(0,10) == "constraint")
        {// or it can be a list of constraints
          addConstraints(fun,(*term)[1]);
        }
        else if (parName == "ties")
        {
          addTies(fun,(*term)[1]);
        }
        else if (parName == "Workspace")
        {
          wsName = parValue;
        }
        else if (parName == "WSParam")
        {
          wsParam = parValue;
        }
        else
        {// set initial parameter value
          fun->setParameter(parName,atof(parValue.c_str()));
        }
      }// for term

      if (!wsName.empty())
      {
        Workspace_sptr ws = AnalysisDataService::Instance().retrieve(wsName);
        fun->setWorkspace(ws,wsParam);
      }

      return fun;
    }
コード例 #10
0
    /** 
     * Create a composite function from an expression.
     * @param expr :: The input expression
     * @return A pointer to the created function
     */
    CompositeFunction* FunctionFactoryImpl::createComposite(const Expression& expr)const
    {
      if (expr.name() != ";") inputError(expr.str());

      if (expr.size() == 0)
      {
        return 0;
      }

      const std::vector<Expression>& terms = expr.terms();
      std::vector<Expression>::const_iterator it = terms.begin();
      const Expression& term = it->bracketsRemoved();

      CompositeFunction* cfun = 0;
      std::string wsName,wsParam;
      if (term.name() == "=")
      {
        if (term.terms()[0].name() == "composite")
        {
          cfun = dynamic_cast<CompositeFunction*>(createFunction(term.terms()[1].name()));
          if (!cfun) inputError(expr.str());
          ++it;
        }
        else if (term.terms()[0].name() == "name")
        {
          cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunctionMW"));
          if (!cfun) inputError(expr.str());
        }
        else
        {
          inputError(expr.str());
        }
      }
      else if (term.name() == ",")
      {
        std::vector<Expression>::const_iterator firstTerm = term.terms().begin();
        if (firstTerm->name() == "=")
        {
          if (firstTerm->terms()[0].name() == "composite")
          {
            cfun = dynamic_cast<CompositeFunction*>(createSimple(term));
            if (!cfun) inputError(expr.str());
            ++it;
          }
          else if (firstTerm->terms()[0].name() == "name")
          {
            cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunctionMW"));
            if (!cfun) inputError(expr.str());
          }
          else
          {
            inputError(expr.str());
          }
        }
      }
      else if (term.name() == ";")
      {
        cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunctionMW"));
        if (!cfun) inputError(expr.str());
      }
      else
      {
        inputError(expr.str());
      }

      for(;it!=terms.end();++it)
      {
        const Expression& term = it->bracketsRemoved();
        IFitFunction* fun = NULL;
        if (term.name() == ";")
        {
          fun = createComposite(term);
          if (!fun) continue;
        }
        else
        {
          std::string parName = term[0].name();
          std::string parValue = term[1].str();
          if (term[0].name().size() >= 10 && term[0].name().substr(0,10) == "constraint")
          {
            addConstraints(cfun,term[1]);
            continue;
          }
          else if (term[0].name() == "ties")
          {
            addTies(cfun,term[1]);
            continue;
          }
          else if (parName == "Workspace")
          {
            wsName = parValue;
          }
          else if (parName == "WSParam")
          {
            wsParam = parValue;
          }
          else
          {
            fun = createSimple(term);
          }
        }
        cfun->addFunction(fun);
      }

      if (!wsName.empty())
      {
        Workspace_sptr ws = AnalysisDataService::Instance().retrieve(wsName);
        cfun->setWorkspace(ws,wsParam);
      }

      return cfun;
    }
コード例 #11
0
ファイル: FunctionFactory.cpp プロジェクト: mducle/mantid
/**
 * Create a composite function from an expression.
 * @param expr :: The input expression
 * @param parentAttributes :: An output map filled with the attribute name &
 * values of the parent function
 * @return A pointer to the created function
 */
CompositeFunction_sptr FunctionFactoryImpl::createComposite(
    const Expression &expr,
    std::map<std::string, std::string> &parentAttributes) const {
  if (expr.name() != ";")
    inputError(expr.str());

  if (expr.size() == 0) {
    return CompositeFunction_sptr();
  }

  const std::vector<Expression> &terms = expr.terms();
  auto it = terms.cbegin();
  const Expression &term = it->bracketsRemoved();

  CompositeFunction_sptr cfun;
  if (term.name() == "=") {
    if (term.terms()[0].name() == "composite") {
      cfun = boost::dynamic_pointer_cast<CompositeFunction>(
          createFunction(term.terms()[1].name()));
      if (!cfun)
        inputError(expr.str());
      ++it;
    } else if (term.terms()[0].name() == "name") {
      cfun = boost::dynamic_pointer_cast<CompositeFunction>(
          createFunction("CompositeFunction"));
      if (!cfun)
        inputError(expr.str());
    } else {
      inputError(expr.str());
    }
  } else if (term.name() == ",") {
    auto firstTerm = term.terms().cbegin();
    if (firstTerm->name() == "=") {
      if (firstTerm->terms()[0].name() == "composite") {
        cfun = boost::dynamic_pointer_cast<CompositeFunction>(
            createSimple(term, parentAttributes));
        if (!cfun)
          inputError(expr.str());
        ++it;
      } else if (firstTerm->terms()[0].name() == "name") {
        cfun = boost::dynamic_pointer_cast<CompositeFunction>(
            createFunction("CompositeFunction"));
        if (!cfun)
          inputError(expr.str());
      } else {
        inputError(expr.str());
      }
    }
  } else if (term.name() == ";") {
    cfun = boost::dynamic_pointer_cast<CompositeFunction>(
        createFunction("CompositeFunction"));
    if (!cfun)
      inputError(expr.str());
  } else {
    inputError(expr.str());
  }

  if (!cfun)
    inputError(expr.str());

  for (; it != terms.end(); ++it) {
    const Expression &term = it->bracketsRemoved();
    IFunction_sptr fun;
    std::map<std::string, std::string> pAttributes;
    if (term.name() == ";") {
      fun = createComposite(term, pAttributes);
      if (!fun)
        continue;
    } else {
      std::string parName = term[0].name();
      if (parName.size() >= 10 && parName.substr(0, 10) == "constraint") {
        addConstraints(cfun, term[1]);
        continue;
      } else if (parName == "ties") {
        addTies(cfun, term[1]);
        continue;
      } else {
        fun = createSimple(term, pAttributes);
      }
    }
    cfun->addFunction(fun);
    size_t i = cfun->nFunctions() - 1;
    for (auto &pAttribute : pAttributes) {
      // Apply parent attributes of the child function to this function. If this
      // function doesn't have those attributes, they get passed up the chain to
      // this function's parent.
      if (cfun->hasLocalAttribute(pAttribute.first)) {
        cfun->setLocalAttributeValue(i, pAttribute.first, pAttribute.second);
      } else {
        parentAttributes[pAttribute.first] = pAttribute.second;
      }
    }
  }

  if (cfun) {
    cfun->applyTies();
  }
  return cfun;
}
コード例 #12
0
json_spirit::Array DecisionCreationWidget::createDecisionArray()
{
    // Main branch ID
    QString branchID;
    if (ui->comboBoxBranch->currentText() == "Main") {
        branchID = "0f894a25c5e0318ee148fe54600ebbf50782f0a1df1eb2aab06321a8ccec270d";
    }

    // Grab user input from ui
    QString address = ui->lineEditOwnerAddr->text();
    QString prompt = ui->plainTextEditPrompt->toPlainText();
    int eventOverBy = ui->spinBoxEventOverBy->value();
    bool answerOptionality = false;
    if (ui->checkBoxVoteMandatory->isChecked()) {
        answerOptionality = false;
    } else {
        answerOptionality = true;
    }
    bool scaled = ui->radioButtonScaled->isChecked();
    double scaledMin = ui->doubleSpinBoxScaledMin->value();
    double scaledMax = ui->doubleSpinBoxScaledMax->value();

    bool error = false;

    // Perform basic checks and avoid wasting json calls
    if (branchID.isEmpty()) {
        emit inputError("You must select a branch!");
        error = true;
    }

    if (address.isEmpty()) {
        emit inputError("You must enter a valid Hivemind address!");
        error = true;
    }

    if (prompt.isEmpty()) {
        emit inputError("You must enter a valid prompt!");
        error = true;
    }

    if (eventOverBy == 0) {
        emit inputError("You must enter a valid ending date!");
        error = true;
    }

    if (scaled && (scaledMax == scaledMin)) {
        emit inputError("You must enter  valid scaled values!");
        error = true;
    }

    // Setup json_spirit array
    json_spirit::Array params;

    // Return empty array if there was an input error
    if (error) return params;

    // Add parameters to array
    params.push_back(address.toStdString());
    params.push_back(branchID.toStdString());
    params.push_back(prompt.toStdString());
    params.push_back(eventOverBy);
    params.push_back(answerOptionality);
    params.push_back(scaled);
    if (scaled) {
        params.push_back(scaledMin);
        params.push_back(scaledMax);
    }
    // Type of array
    params.push_back("decision");

    return params;
}
コード例 #13
0
ファイル: hdd.c プロジェクト: uyjulian/pfsshell
int _start(int argc, char **argv)
{
    int i, ret;
    char *input;
    int cacheSize = 3;
    apa_ps2time_t tm;
    ata_devinfo_t *hddInfo;

    printStartup();

    if ((input = strrchr(argv[0], '/')))
        input++;
    else
        input = argv[0];

    argc--;
    argv++;
    while (argc) {
        if (argv[0][0] != '-')
            break;
        if (strcmp("-o", argv[0]) == 0) {
            argc--;
            argv++;
            if (!argc)
                return inputError(input);
            i = strtol(argv[0], 0, 10);
            if (i - 1 < 32)
                apaMaxOpen = i;
        } else if (strcmp("-n", argv[0]) == 0) {
            argc--;
            argv++;
            if (!argc)
                return inputError(input);
            i = strtol(*argv, 0, 10);
            if (cacheSize < i)
                cacheSize = i;
        }
        argc--;
        argv++;
    }

    APA_PRINTF(APA_DRV_NAME ": max open = %d, %d buffers\n", apaMaxOpen, cacheSize);
    if (dev9RegisterShutdownCb(0, &hddShutdownCb) != 0) {
        APA_PRINTF(APA_DRV_NAME ": error: dev9 may not be resident.\n");
        return hddInitError();
    }

    if (apaGetTime(&tm) != 0) {
        APA_PRINTF(APA_DRV_NAME ": error: could not get date.\n");
        return hddInitError();
    }

    APA_PRINTF(APA_DRV_NAME ": %02d:%02d:%02d %02d/%02d/%d\n",
               tm.hour, tm.min, tm.sec, tm.month, tm.day, tm.year);
    for (i = 0; i < 2; i++) {
        if (!(hddInfo = ata_get_devinfo(i))) {
            APA_PRINTF(APA_DRV_NAME ": Error: ata initialization failed.\n");
            return hddInitError();
        }
        if (hddInfo->exists != 0 && hddInfo->has_packet == 0) {
            hddDevices[i].status--;
            hddDevices[i].totalLBA = hddInfo->total_sectors;
            hddDevices[i].partitionMaxSize = apaGetPartitionMax(hddInfo->total_sectors);
            if (unlockDrive(i) == 0)
                hddDevices[i].status--;
            APA_PRINTF(APA_DRV_NAME ": disk%d: 0x%08lx sectors, max 0x%08lx\n", i,
                       hddDevices[i].totalLBA, hddDevices[i].partitionMaxSize);
        }
    }
    hddFileSlots = apaAllocMem(apaMaxOpen * sizeof(hdd_file_slot_t));
    ret = (hddFileSlots == NULL) ? -ENOMEM : 0;
    if (ret != 0) {
        APA_PRINTF(APA_DRV_NAME ": error: file descriptor initialization failed.\n");
        return hddInitError();
    }

    memset(hddFileSlots, 0, apaMaxOpen * sizeof(hdd_file_slot_t));

    if (apaCacheInit(cacheSize) != 0) {
        APA_PRINTF(APA_DRV_NAME ": error: cache buffer initialization failed.\n");
        return hddInitError();
    }

    for (i = 0; i < 2; i++) {
        if (hddDevices[i].status < 2) {
            if (apaJournalRestore(i) != 0) {
                APA_PRINTF(APA_DRV_NAME ": error: log check failed.\n");
                return hddInitError();
            }
            if (apaGetFormat(i, &hddDevices[i].format))
                hddDevices[i].status--;
            APA_PRINTF(APA_DRV_NAME ": drive status %d, format version %08x\n",
                       hddDevices[i].status, hddDevices[i].format);
        }
    }
    DelDrv("hdd");
    if (AddDrv(&hddFioDev) == 0) {
#ifdef APA_OSD_VER
        APA_PRINTF(APA_DRV_NAME ": version %04x driver start. This is OSD version!\n", IRX_VER(APA_MODVER_MAJOR, APA_MODVER_MINOR));
#else
        APA_PRINTF(APA_DRV_NAME ": version %04x driver start.\n", IRX_VER(APA_MODVER_MAJOR, APA_MODVER_MINOR));
#endif
        return MODULE_RESIDENT_END;
    } else {
        APA_PRINTF(APA_DRV_NAME ": error: add device failed.\n");
        return hddInitError();
    }
}
コード例 #14
0
ファイル: FunctionFactory.cpp プロジェクト: trnielsen/mantid
    /** 
     * Create a composite function from an expression.
     * @param expr :: The input expression
     * @param parentAttributes :: An output map filled with the attribute name & values of the parent function
     * @return A pointer to the created function
     */
    CompositeFunction_sptr FunctionFactoryImpl::createComposite(const Expression& expr, std::map<std::string,std::string>& parentAttributes)const
    {
      if (expr.name() != ";") inputError(expr.str());

      if (expr.size() == 0)
      {
        return CompositeFunction_sptr();
      }

      const std::vector<Expression>& terms = expr.terms();
      std::vector<Expression>::const_iterator it = terms.begin();
      const Expression& term = it->bracketsRemoved();

      CompositeFunction_sptr cfun;
      if (term.name() == "=")
      {
        if (term.terms()[0].name() == "composite")
        {
          cfun = boost::dynamic_pointer_cast<CompositeFunction>(createFunction(term.terms()[1].name()));
          if (!cfun) inputError(expr.str());
          ++it;
        }
        else if (term.terms()[0].name() == "name")
        {
          cfun = boost::dynamic_pointer_cast<CompositeFunction>(createFunction("CompositeFunction"));
          if (!cfun) inputError(expr.str());
        }
        else
        {
          inputError(expr.str());
        }
      }
      else if (term.name() == ",")
      {
        std::vector<Expression>::const_iterator firstTerm = term.terms().begin();
        if (firstTerm->name() == "=")
        {
          if (firstTerm->terms()[0].name() == "composite")
          {
            cfun = boost::dynamic_pointer_cast<CompositeFunction>(createSimple(term,parentAttributes));
            if (!cfun) inputError(expr.str());
            ++it;
          }
          else if (firstTerm->terms()[0].name() == "name")
          {
            cfun = boost::dynamic_pointer_cast<CompositeFunction>(createFunction("CompositeFunction"));
            if (!cfun) inputError(expr.str());
          }
          else
          {
            inputError(expr.str());
          }
        }
      }
      else if (term.name() == ";")
      {
        cfun = boost::dynamic_pointer_cast<CompositeFunction>(createFunction("CompositeFunction"));
        if (!cfun) inputError(expr.str());
      }
      else
      {
        inputError(expr.str());
      }

      for(;it!=terms.end();++it)
      {
        const Expression& term = it->bracketsRemoved();
        IFunction_sptr fun;
        std::map<std::string,std::string> pAttributes;
        if (term.name() == ";")
        {
          fun = createComposite(term,pAttributes);
          if (!fun) continue;
        }
        else
        {
          std::string parName = term[0].name();
          if (parName.size() >= 10 && parName.substr(0,10) == "constraint")
          {
            addConstraints(cfun,term[1]);
            continue;
          }
          else if (parName == "ties")
          {
            addTies(cfun,term[1]);
            continue;
          }
          else
          {
            fun = createSimple(term,pAttributes);
          }
        }
        cfun->addFunction(fun);
        size_t i = cfun->nFunctions() - 1;
        for(auto att = pAttributes.begin(); att != pAttributes.end(); ++att)
        {
          cfun->setLocalAttributeValue(i,att->first,att->second);
        }
      }

      cfun->applyTies();
      return cfun;
    }
コード例 #15
0
ファイル: hdd.c プロジェクト: EvertonSilva/ps2sdk
int _start(int argc, char **argv)
{
	int 	i;
	char	*input;
	int		cacheSize=3;
	ps2time tm;
	t_shddInfo *hddInfo;

	printStartup();
	// decode MBR Magic
	for(i=0;i!=0x20;i++)
		mbrMagic[i]^='x';

	if((input=strrchr(argv[0], '/')))
		input++;
	else
		input=argv[0];

	argc--; argv++;
	while(argc)
	{
		if(argv[0][0] != '-') 
			break;
		if(strcmp("-o", argv[0])==0){
			argc--; argv++;
			if(!argc)
				return inputError(input);
			i=strtol(argv[0], 0, 10);
			if(i-1<32)
				maxOpen=i;
		}
		else if(strcmp("-n", argv[0])==0){
			argc--; argv++;
			if(!argc)
				return inputError(input);
			i=strtol(*argv, 0, 10);
			if(cacheSize<i)
				cacheSize=i;
		}
		argc--; argv++;
	}

	printf("ps2hdd: max open = %ld, %d buffers\n", maxOpen, cacheSize);
	getPs2Time(&tm);
	printf("ps2hdd: %02d:%02d:%02d %02d/%02d/%d\n",
		tm.hour, tm.min, tm.sec, tm.month, tm.day, tm.year);
	for(i=0;i < 2;i++)
	{
		if(!(hddInfo=atadInit((u16)i))){
			printf("ps2hdd: Error: ata initialization failed.\n");
			return 0;
		}
		if(hddInfo->exists!=0 && hddInfo->has_packet==0){
				hddDeviceBuf[i].status--;
				hddDeviceBuf[i].totalLBA=hddInfo->total_sectors;
				hddDeviceBuf[i].partitionMaxSize=apaGetPartitionMax(hddInfo->total_sectors);
				if(unlockDrive(i)==0)
					hddDeviceBuf[i].status--;
				printf("ps2hdd: disk%d: 0x%08lx sectors, max 0x%08lx\n", i,
					hddDeviceBuf[i].totalLBA, hddDeviceBuf[i].partitionMaxSize);
		}
	}
	fileSlots=allocMem(maxOpen*sizeof(hdd_file_slot_t));
	if(fileSlots)
		memset(fileSlots, 0, maxOpen*sizeof(hdd_file_slot_t));

	cacheInit(cacheSize);
	for(i=0;i < 2;i++)
	{
		if(hddDeviceBuf[i].status<2){
			if(journalResetore(i)!=0)
				return 1;
			if(apaGetFormat(i, (int *)&hddDeviceBuf[i].format))
				hddDeviceBuf[i].status--;
			printf("ps2hdd: drive status %ld, format version %08lx\n",
				hddDeviceBuf[i].status, hddDeviceBuf[i].format);
		}
	}
	DelDrv("hdd");
	if(AddDrv(&hddFioDev)==0)
	{
		printf("ps2hdd: driver start.\n");
		return 0;
	}
	return 1;
}
コード例 #16
0
ファイル: gtm_util.c プロジェクト: pavanvd/postgres-xl
int unregisterFromGtm(char *line)
{
	char *token;
	int rc;

	for(;GetToken();)
	{
		if (testToken("-n"))
		{
			if (!GetToken())
				return(inputError("No -n option value was found."));
			Free(myname);
			myname = Strdup(token);
			continue;
		}
		else if (testToken("-Z"))
		{
			if (!GetToken())
				return(inputError("No -Z option value was found."));
			if (testToken("gtm"))
			{
				nodetype = GTM_NODE_GTM;
				continue;
			}
			else if (testToken("gtm_proxy"))
			{
				nodetype = GTM_NODE_GTM_PROXY;
				break;
			}
			else if (testToken("gtm_proxy_postmaster"))
			{
				nodetype = GTM_NODE_GTM_PROXY_POSTMASTER;
				break;
			}
			else if (testToken("coordinator"))
			{
				nodetype = GTM_NODE_COORDINATOR;
				break;
			}
			else if (testToken("datanode"))
			{
				nodetype = GTM_NODE_DATANODE;
				break;
			}
			else
			{
				elog(ERROR, "ERROR: Invalid -Z option value, %s\n", token);
				return(-1);
			}
			continue;
		}
		else
			break;
	}
	if (nodetype == 0)
	{
		elog(ERROR, "ERROR: no node type was specified.\n");
		return(-1);
	}

	if (myname == NULL)
		myname = Strdup(DefaultName);
	
	if (!token)
	{
		fprintf(stderr,"%s: No command specified.\n", progname);
		exit(2);
	}
	if (!GetToken())
	{
		elog(ERROR, "ERROR: unregister: no node name was found to unregister.\n");
		return(-1);
	}
	nodename = Strdup(token);
	rc = process_unregister_command(nodetype, nodename);
	Free(nodename);
	return(rc);
}