Esempio n. 1
0
wbBool wbSolution(wbArg_t arg, void *data, int rows, int columns,
                  int depth) {
  char *type;
  wbBool res;
  char *expectedOutputFile;
  char *outputFile;
  stringstream ss;

  expectedOutputFile = wbArg_getExpectedOutputFile(arg);
  outputFile         = wbArg_getOutputFile(arg);
  type               = wbArg_getType(arg);

  wbAssert(type != NULL);
  wbAssert(expectedOutputFile != NULL);
  wbAssert(outputFile != NULL);

  res = wbSolution(expectedOutputFile, outputFile, type, data, rows,
                   columns, depth);

  if (WB_USE_JSON11) {
    json11::Json json;
    if (res) {
      json = json11::Json::object{{"correctq", true},
                                  {"message", "The solution is correct"}};
    } else {
      json = json11::Json::object{{"correctq", false},
                                  {"message", _solution_correctQ}};
    }

#ifdef wbLogger_printOnLog
    if (wbLogger_printOnLog) {
      json11::Json e =
          json11::Json::object{{"type", "solution"}, {"data", json}};
      std::cout << e.dump() << std::endl;
    }
#endif /* wbLogger_printOnLog */

    solutionJSON = wbString_duplicate(json.string_value());
  } else {
    if (res) {
      ss << "{\n";
      ss << wbString_quote("correctq") << ": true,\n";
      ss << wbString_quote("message") << ": "
         << wbString_quote("Solution is correct.") << "\n";
      ss << "}";
    } else {
      ss << "{\n";
      ss << wbString_quote("correctq") << ": false,\n";
      ss << wbString_quote("message") << ": "
         << wbString_quote(_solution_correctQ) << "\n";
      ss << "}";
    }
    solutionJSON = wbString_duplicate(ss.str());
  }

  return res;
}
Esempio n. 2
0
static inline wbExport_t wbExport_open(const char *file, wbExportKind_t kind) {
  wbExport_t exprt;

  if (file == NULL) {
    wbLog(ERROR, "Go NULL for file value.");
    wbExit();
  }

  wbExport_setFile(exprt, NULL);
  wbExport_setKind(exprt, kind);

  if (kind == wbExportKind_raw) {
    wbExportRaw_t raw = wbExportRaw_new();
    wbExportRaw_setFile(raw, file);
    wbExport_setRaw(exprt, raw);
  } else if (kind == wbExportKind_tsv || kind == wbExportKind_csv) {
    wbExportCSV_t csv = wbExportCSV_new();
    if (kind == wbExportKind_csv) {
      wbExportCSV_setSeperator(csv, ',');
    } else {
      wbExportCSV_setSeperator(csv, '\t');
    }
    wbExportCSV_setFile(csv, file);
    wbExport_setCSV(exprt, csv);
  } else if (kind == wbExportKind_ppm) {
    wbExport_setFile(exprt, wbString_duplicate(file));
  } else {
    wbLog(ERROR, "Invalid export type.");
    wbExit();
  }

  return exprt;
}
Esempio n. 3
0
static inline char * lineStrip(const char * line) {
    char * sl = wbString_duplicate(line);
    char * iter = sl;
    size_t slen = strlen(line);

    iter += slen - 1;
    while (*iter == '\0' || *iter == '\r' || *iter == '\t' || *iter == '\n' || *iter == ' ') {
        *iter-- = '\0';
    }
    return sl;
}
Esempio n. 4
0
wbFile_t wbFile_open(const char * fileName, const char * mode) {
    FILE * handle;
    wbFile_t file;

    if (fileName == NULL) {
        return NULL;
    }

    handle = fopen(fileName, mode);
    if (handle == NULL) {
        wbLog(ERROR, "Failed to open ", file, " in mode ", mode);
        return NULL;
    }

    file = wbFile_new();
    wbFile_setFileName(file, wbString_duplicate(fileName));
    wbFile_setMode(file, wbString_duplicate(mode));
    wbFile_setFileHandle(file, handle);

    return file;
}
Esempio n. 5
0
static inline wbLogEntry_t
wbLogEntry_initialize(wbLogLevel_t level, string msg, const char *file,
                      const char *fun, int line) {
  wbLogEntry_t elem;

  elem = wbLogEntry_new();

  wbLogEntry_setLevel(elem, level);

  wbLogEntry_setMessage(elem, wbString_duplicate(msg));

  wbLogEntry_setLine(elem, line);
  wbLogEntry_setFile(elem, file);
  wbLogEntry_setFunction(elem, fun);

  return elem;
}
Esempio n. 6
0
char *wbFile_extension(const char *file) {
  char *extension;
  char *extensionLower;
  char *end;
  size_t len;

  len = strlen(file);
  end = (char *)&file[len - 1];
  while (*end != '.') {
    end--;
  }
  if (*end == '.') {
    end++;
  }

  extension = wbString_duplicate(end);
  extensionLower = wbString_toLower(extension);
  wbDelete(extension);

  return extensionLower;
}
Esempio n. 7
0
static char *parseString(char *arg) { return wbString_duplicate(arg); }