예제 #1
0
char * 
serializeTableContent(RM_TableData *rel)
{
  int i;
  VarString *result;
  RM_ScanHandle *sc = (RM_ScanHandle *) malloc(sizeof(RM_ScanHandle));
  Record *r = (Record *) malloc(sizeof(Record));
  MAKE_VARSTRING(result);

  for(i = 0; i < rel->schema->numAttr; i++)
    APPEND(result, "%s%s", (i != 0) ? ", " : "", rel->schema->attrNames[i]);

  startScan(rel, sc, NULL);
  
  while(next(sc, r) != RC_RM_NO_MORE_TUPLES) 
    {
    APPEND_STRING(result,serializeRecord(r, rel->schema));
    APPEND_STRING(result,"\n");
    }
  closeScan(sc);

  RETURN_STRING(result);
}
예제 #2
0
char* stringFromTableMaker(recordTableInfo* rec,
                StringRecordConverter* stringConverter) {
        char *data = NULL;
        tombStoneMarker* head = rec->tombStoneHead;
        while (head != NULL) {
                APPEND(stringConverter, "%i:%i%s ", head->recordID.page,
                                head->recordID.slot,
                                (head->nextDeletedRecord != NULL) ? ", " : "");
                head = head->nextDeletedRecord;
        }
        APPEND_STRING(stringConverter, ">\n");
        GET_STRING(data, stringConverter);
        return data;
}
char *
serializeValue(Value *val) {
	VarString *result;
	MAKE_VARSTRING(result);

	switch (val->dt) {
	case DT_INT:
		APPEND(result, "%i", val->v.intV);
		break;
	case DT_FLOAT:
		APPEND(result, "%f", val->v.floatV);
		break;
	case DT_STRING:
		APPEND(result, "%s", val->v.stringV);
		break;
	case DT_BOOL:
		APPEND_STRING(result, ((val->v.boolV) ? "true" : "false"));
		break;
	}

	RETURN_STRING(result);
}
예제 #4
0
char * 
serializeSchema(Schema *schema)
{
  int i;
  VarString *result;
  MAKE_VARSTRING(result);

  APPEND(result, "Schema with <%i> attributes (", schema->numAttr);

  for(i = 0; i < schema->numAttr; i++)
    {
      APPEND(result,"%s%s: ", (i != 0) ? ", ": "", schema->attrNames[i]);
      switch (schema->dataTypes[i])
	{
	case DT_INT:
	  APPEND_STRING(result, "INT");
	  break;
	case DT_FLOAT:
	  APPEND_STRING(result, "FLOAT");
	  break;
	case DT_STRING:
	  APPEND(result,"STRING[%i]", schema->typeLength[i]);
	  break;
	case DT_BOOL:
	  APPEND_STRING(result,"BOOL");
	  break;
	}
    }
  APPEND_STRING(result,")");

  APPEND_STRING(result," with keys: (");

  for(i = 0; i < schema->keySize; i++)
    APPEND(result, "%s%s", ((i != 0) ? ", ": ""), schema->attrNames[schema->keyAttrs[i]]); 

  APPEND_STRING(result,")\n");

  RETURN_STRING(result);
}
예제 #5
0
wxString COARfile::FormatChannelAlerts(
  const COARsample *pSample, 
  const CAlertViewStatus &viewStatus,
  const wxDateTime *pTime) const
{
  COmittedAlerts mapOmitted;
  wxString sRtn;
  wxString s;
  wxString sReview;
  wxString sTitle;
  vector<int> vn;
  vector<wxString> vs;

  const COARchannel *pChannel;
  size_t nChannelCount = m_heading.GetChannelCount();
  size_t i;
  size_t nLen = 0;
  const vector<int> *pvn;
  const COARchannelAlert *pcha;
  bool bOmit = !viewStatus.GetChannel();

  _FormatCommonAlerts(&mapOmitted, pSample,vs,nLen,viewStatus,pTime);

  for(i = 0; i < nChannelCount; i++)
  {
    pChannel = m_heading.GetChannel(i);
    pcha = pSample->GetChannelAlertsByChannel(pChannel->GetChannelNr());
    if(pcha != NULL)
    {
      pvn = pcha->GetMessageNumbers();
      if((pvn == NULL) || (!pvn->size()))
      {}
      else if(bOmit)
      {
        int nOmit = CountMessages(*pvn,pTime);
        mapOmitted.Add(CAlertViewStatus::CHANNEL,nOmit);
      }
      else
      {
        s = FormatMessages(*pvn,2,pTime);
        if(!s.IsEmpty())
        {
          sTitle.Printf(FORMAT_CH_NOTICE,pChannel->GetChannelNr());
          ADD_STRING(sTitle);
          ADD_STRINGE(s);
        }
      }
    }
  }

  if(!bOmit)
  {
    s = pSample->GetNotesChannelStr(pTime);
    if(CanEditArtifacts())
    {
      wxString sNeed;
      int nReview;
      int nAccept;
      GetReviewerCounts(&nReview,&nAccept,CLabReview::REVIEW_CHANNEL);
      sReview = pSample->FormatChannelReviewAcceptance(pTime);
      sNeed = CheckChannelStatus(pSample,nReview,nAccept,pTime);
      APPEND_STRING(sReview,sNeed);
    }
    ADD_REVIEW_CHANNEL_NOTES(sReview,s,2);
  }
  _JoinStrings(sRtn,vs,&mapOmitted,nLen);
  return sRtn;
}
예제 #6
0
void COARfile::_FormatCommonAlerts(
  COmittedAlerts *pOmitted,
  const COARsample *pSample,
  vector<wxString> &vs,
  size_t &nLen,
  const CAlertViewStatus &viewStatus,
  const wxDateTime *pTime,
  bool bReverse) const
{

  vector<int> vn;
  wxString s;
  wxString sTitle;
  wxString sNotes;
  wxString sReview;
  wxString sNeed;
  int i;
  int n;
  int nOmit;
  const int COUNT = 3;
  int nReview = 0;
  int nAccept = 0;
  bool bCanEditArtifacts = CanEditArtifacts();
  bool bHasDirMessages = HasDisplayedDirectoryMessages();
  bool bShowSomeDir =
    viewStatus.GetDirectory() || viewStatus.GetDirectoryLocus();
    
  for(i = 0; i < COUNT; i++)
  {
    s.Empty();
    sReview.Empty();
    sNotes.Empty();
    vn.clear();
    n = bReverse ? (COUNT - i - 1) : i;
    switch (n)
    {
    case 0:

      if(bCanEditArtifacts)
      {
        const COARnotes *pNotes = GetNotesDir(pTime);
        GetReviewerCounts(&nReview,&nAccept,CLabReview::REVIEW_DIR);
        sReview = FormatReviewAcceptance(pTime);
        sNotes = COARnotes::GetText(pNotes);
      }
      if(
        bHasDirMessages ||
        (!sNotes.IsEmpty()) || 
        (!sReview.IsEmpty())
        )
      {
        wxString sDirTitle(_T("Directory " COAR_NOTICE_DISPLAY ":"));
        const vector<COARbaseLocus *> *pbl = GetBaseLociAlerts();
        vector<COARbaseLocus *>::const_iterator itr;
        bool bTitleAdded = false;
        GetDirectoryMessages(&vn);
        if(vn.size())
        {
          if(viewStatus.GetDirectory())
          {
            s = FormatMessages(vn,2,pTime);
          }
          else
          {
            nOmit = CountMessages(vn,pTime);
            pOmitted->Add(
              CAlertViewStatus::DIRECTORY,nOmit);
          }
          vn.clear();
        }
        if(!s.IsEmpty())
        {
          ADD_STRING(sDirTitle);
          ADD_STRINGE(s);
          bTitleAdded = true;
        }
        for(itr = pbl->begin(); itr != pbl->end(); ++itr)
        {
          vn.clear();
          (*itr)->AppendMessagesToList(&vn);
          if(!vn.size())
          {}
          else if(!viewStatus.GetDirectoryLocus())
          {
            nOmit = CountMessages(vn,pTime);
            pOmitted->Add(CAlertViewStatus::DIRECTORY_LOCUS,nOmit);
          }
          else
          {
            s = FormatMessages(vn,4,pTime);
            if(!s.IsEmpty())
            {
              if(!bTitleAdded)
              {
                ADD_STRING(sDirTitle);
                bTitleAdded = true;
              }
              sTitle = (*itr)->GetLocusName();
              sTitle.Append(_T(" directory " COAR_NOTICE_DISPLAY ":"));
              FormatText(&sTitle,2);
              ADD_STRING(sTitle);
              ADD_STRINGE(s);
            }
          }
        }
        if(bShowSomeDir)
        {
          if(!bTitleAdded)
          {
            ADD_STRING(sDirTitle);
            bTitleAdded = true;
          }
          if(bCanEditArtifacts && bHasDirMessages)
          {
            sNeed = CheckDirStatus(nReview,nAccept,pTime);
            APPEND_STRING(sReview,sNeed);
          }
          ADD_REVIEW_NOTES(sReview,sNotes,2);
        }
      }
      break;
    case 1:
      pSample->AppendSampleAlerts(&vn);
      if(!viewStatus.GetSample())
      {
        nOmit = CountMessages(vn,pTime);
        pOmitted->Add(CAlertViewStatus::SAMPLE,nOmit);
      }
      else
      {
        if(vn.size())
        {
          s = FormatMessages(vn,2,pTime);
        }

        sNotes = pSample->GetNotesSampleStr(pTime);
        if(bCanEditArtifacts)
        {
          GetReviewerCounts(&nReview,&nAccept,CLabReview::REVIEW_SAMPLE);
          sReview = pSample->FormatSampleReviewAcceptance(pTime);
          sNeed = CheckSampleStatus(pSample,nReview,nAccept,pTime);
          APPEND_STRING(sReview,sNeed);
        }
        if(!s.IsEmpty() || !sNotes.IsEmpty() || !sReview.IsEmpty() )
        {
          sTitle = pSample->GetName();
          sTitle.Append(_T(" " COAR_NOTICE_DISPLAY ":"));
          ADD_STRING(sTitle);
          ADD_STRINGE(s);
          ADD_REVIEW_NOTES(sReview,sNotes,2);
        }
      }
      break;
    case 2:
      pSample->AppendILSAlerts(&vn);
      if(!viewStatus.GetILS())
      {
        nOmit = CountMessages(vn,pTime);
        pOmitted->Add(CAlertViewStatus::ILS,nOmit);
      }
      else
      {
        sNotes = pSample->GetNotesILSStr(pTime);
        nwxString::Trim(&sNotes);
        if(vn.size())
        {
          s = FormatMessages(vn,2,pTime);
          vn.clear();
        }
        if(bCanEditArtifacts)
        {
          GetReviewerCounts(&nReview,&nAccept,CLabReview::REVIEW_ILS);
          sReview = pSample->FormatILSReviewAcceptance(pTime);
          sNeed = CheckILSStatus(pSample,nReview,nAccept,pTime);
          APPEND_STRING(sReview,sNeed);
        }
        if(!s.IsEmpty() || !sNotes.IsEmpty() || !sReview.IsEmpty())
        {
          sTitle = _T("ILS channel " COAR_NOTICE_DISPLAY ":");
          ADD_STRING(sTitle);
          ADD_STRINGE(s);
          ADD_REVIEW_NOTES(sReview,sNotes,2);
        }
      }
      break;
    }
  }
}
예제 #7
0
파일: options.c 프로젝트: 0x0mar/skipfish
int read_config_file(const char *filename, int *_argc, char ***_argv) {

  FILE *fh;
  char line[MAX_LINE_LEN + 1];
  char *val, *ptr;
  u8 *tmp;
  u32 idx, i;

  APPEND_STRING(fargv, fargc, ck_strdup((u8*)*_argv[0]));

  fh = fopen(filename, "r");
  if (!fh) PFATAL("Unable to read config from: %s", filename);

  while (!feof(fh) && fargc < MAX_ARGS && fgets(line, MAX_LINE_LEN, fh)) {

    /* Skip comments and empty lines */
    if (line[0] == '\n' || line[0] == '\r' || line[0] == '#')
      continue;

    /* NULL terminate the key */
    idx = strcspn(line, " \t=");
    if (idx == strlen(line))
      FATAL("Config key error at line: %s", line);
    line[idx] = '\0';

    /* Find the beginning of the value. */
    val = line + (idx + 1);
    idx = strspn(val, " \t=");
    if (idx == strlen(val))
      FATAL("Config value error at line: %s", line);
    val = val + idx;

    /* Trim the unwanted characters from the value */
    ptr = val + (strlen(val) - 1);
    while(*ptr && *ptr < 0x21) {
      *ptr = 0;
      ptr--;
    }

    /* Done! Now we have a key/value pair. If the flag is set to 'false'
       we will disregard this line. If the value is 'true', we will set
       the flag without a value. In any other case, we will set the flag
       and value */

    if (val[0] == '\0')
      FATAL("Empty value in config line: %s", line);

    if (strcasecmp("false", val) == 0)
      continue;

    tmp = ck_alloc(strlen(line) + 3);
    sprintf((char*)tmp, "--%s", line);

    APPEND_STRING(fargv, fargc, tmp);
    if (strncasecmp("true", val, 3) != 0)
      APPEND_STRING(fargv, fargc, ck_strdup((u8*)val));

  }

  /* Copy arguments from command line into our array */
  for (i=1; i<*_argc && fargc < MAX_ARGS; ++i)
    APPEND_STRING(fargv, fargc, ck_strdup((u8*)(*_argv)[i]));

  /* Replace original flags */
  *_argc = fargc;
  *_argv = (char **)fargv;

  fclose(fh);
  return 0;
}