Пример #1
0
/* small permutation on the newmacro code... this takes a pointer to
   ** a distress structure and a pointer to a macro syntax string,
   ** and converts it into a line of text.
   **  9/1/93 - jn
 */
int makedistress (struct distress *dist, /* the info */
                   char *cry, 	/* the call for help! (output) -
                                   should be array */
                   char *pm)	/* macro to parse, used for distress and
                                   macro */
{
  char buf1[10 * MAXMACLEN];
  char *pbuf1;
  char buf2[10 * MAXMACLEN];
  char buf3[10 * MAXMACLEN];
  char tmp[10 * MAXMACLEN];
  int index = 0;
  int index2 = 0;
  int index3 = 0;
  int cap = 0;
  struct player *sender;
  struct player *j;
  struct planet *l;
  char c;
  char *macro;

  sender = &players[dist->sender];

  if (!(*pm))
    {
      cry[0] = '\0';
      return (0);
    }

  buf1[0] = '\0';
  pbuf1 = buf1;

  macro = pm;

  /* first step is to substitute variables */
  while (*pm)
    {
      if (*pm == '%')
	{
	  pm++;

	  if (!pm)
	      continue;

	  switch (c = *(pm++))
	    {
	    case ' ':
	      APPEND (pbuf1, " \0");
	      break;
	    case 'O':		/* push a 3 character team name into buf */
	      cap = 1;
	    case 'o':		/* push a 3 character team name into buf */
	      if (sender->p_team != ALLTEAM)
		APPEND_CAP (pbuf1, cap, teamshort[sender->p_team]);
	      cap = 0;
	      break;
	    case 'a':		/* push army number into buf */
	      APPEND_INT(pbuf1, dist->arms);
	      break;
	    case 'd':		/* push damage into buf */
	      APPEND_INT (pbuf1, dist->dam);
	      break;
	    case 's':		/* push shields into buf */
	      APPEND_INT (pbuf1, dist->shld);
	      break;
	    case 'f':		/* push fuel into buf */
	      APPEND_INT (pbuf1, dist->fuelp);
	      break;
	    case 'w':		/* push wtemp into buf */
	      APPEND_INT (pbuf1, dist->wtmp);
	      break;
	    case 'e':		/* push etemp into buf */
	      APPEND_INT (pbuf1, dist->etmp);
	      break;

	    case 'P':		/* push player id into buf */
	    case 'G':		/* push friendly player id into buf */
	    case 'H':		/* push enemy target player id into buf */

	    case 'p':		/* push player id into buf */
	    case 'g':		/* push friendly player id into buf */
	    case 'h':		/* push enemy target player id into buf */

	      switch (c)
		{
		case 'p':
		  j = &players[dist->tclose_j];
		  break;
		case 'g':
		  j = &players[dist->tclose_fr];
		  break;
		case 'h':
		  j = &players[dist->tclose_en];
		  break;
		case 'P':
		  j = &players[dist->close_j];
		  break;
		case 'G':
		  j = &players[dist->close_fr];
		  break;
		default:
		  j = &players[dist->close_en];
		  break;
		}
	      tmp[0] = j->p_mapchars[1];
	      tmp[1] = '\0';
	      APPEND (pbuf1, tmp);
	      break;

	    case 'n':		/* push planet armies into buf */
	      l = &planets[dist->tclose_pl];
	      APPEND_INT (pbuf1,
			  ((l->pl_info & sender->p_team) ? l->pl_armies : -1));
              break;
            case 'B':
              cap = 1;
	    case 'b':		/* push planet into buf */
	      l = &planets[dist->close_pl];
	      tmp[0] = l->pl_name[0] - 'A' + 'a';
	      tmp[1] = l->pl_name[1];
              tmp[2] = l->pl_name[2];
	      tmp[3] = '\0';
	      APPEND_CAP (pbuf1, cap, tmp);
	      cap = 0;
	      break;
	    case 'L':
	      cap = 1;
	    case 'l':		/* push planet into buf */
	      l = &planets[dist->tclose_pl];
	      tmp[0] = l->pl_name[0] - 'A' + 'a';
	      tmp[1] = l->pl_name[1];
	      tmp[2] = l->pl_name[2];
	      tmp[3] = '\0';
	      APPEND_CAP (pbuf1, cap, tmp);
	      cap = 0;
	      break;
	    case 'Z':		/* push a 3 character team name into buf */
	      cap = 1;
	    case 'z':		/* push a 3 character team name into buf */
	      l = &planets[dist->tclose_pl];
	      APPEND_CAP (pbuf1, cap, teamshort[l->pl_owner]);
	      cap = 0;
	      break;
	    case 't':		/* push a team character into buf */
	      l = &planets[dist->tclose_pl];
	      tmp[0] = teamlet[l->pl_owner];
	      tmp[1] = '\0';
	      APPEND (pbuf1, tmp);
	      break;
	    case 'T':		/* push my team into buf */
	      tmp[0] = teamlet[sender->p_team];
	      tmp[1] = '\0';
	      APPEND (pbuf1, tmp);
	      break;
	    case 'c':		/* push my id char into buf */
	      tmp[0] = sender->p_mapchars[1];
	      tmp[1] = '\0';
	      APPEND (pbuf1, tmp);
	      break;
	    case 'W':		/* push WTEMP flag into buf */
	      if (dist->wtmpflag)
		tmp[0] = '1';
	      else
		tmp[0] = '0';
	      tmp[1] = '\0';
	      APPEND (pbuf1, tmp);
	      break;
	    case 'E':		/* push ETEMP flag into buf */
	      if (dist->etempflag)
		tmp[0] = '1';
	      else
		tmp[0] = '0';
	      tmp[1] = '\0';
	      APPEND (pbuf1, tmp);
	      break;
            case 'K':
              cap = 1;
            case 'k':
              if (cap)
                j = &players[dist->tclose_en];
              else
                j = sender;
 
              if (j->p_ship.s_type == STARBASE)
#ifdef LTD_STATS
                sprintf (tmp, "%5.2f", (float) ltd_kills(j, LTD_SB));
#else
                sprintf (tmp, "%5.2f", (float) j->p_stats.st_sbkills);
#endif
              else
#ifdef LTD_STATS
                sprintf (tmp, "%5.2f", (float) ltd_kills(j, LTD_TOTAL));
#else
                sprintf (tmp, "%5.2f", (float) j->p_stats.st_kills +
                         j->p_stats.st_tkills);
#endif
              APPEND (pbuf1, tmp);
              break;

	    case 'U':		/* push player name into buf */
	      cap = 1;
	    case 'u':		/* push player name into buf */
	      j = &players[dist->tclose_en];
	      APPEND_CAP (pbuf1, cap, j->p_name);
	      cap = 0;
	      break;
	    case 'I':		/* my player name into buf */
	      cap = 1;
	    case 'i':		/* my player name into buf */
	      APPEND_CAP (pbuf1, cap, sender->p_name);
	      cap = 0;
	      break;
	    case 'S':		/* push ship type into buf */
              APPEND (pbuf1, shiptypes[sender->p_ship.s_type]);
	      break;
                 case 'v':      /* push average ping round trip time into buf */
                 case 'V':      /* push ping stdev into buf */
                 case 'y':      /* push packet loss into buf */
                   APPEND (pbuf1, "0\0");
            case 'M':           /* push capitalized lastMessage into buf */
            case 'm':           /* push lastMessage into buf */
                   break;
	    case '*':		/* push %} into buf */
	      APPEND (pbuf1, "%*\0");
	      break;
	    case '}':		/* push %} into buf */
	      APPEND (pbuf1, "%}\0");
	      break;
	    case '{':		/* push %{ into buf */
	      APPEND (pbuf1, "%{\0");
	      break;
	    case '!':		/* push %! into buf */
	      APPEND (pbuf1, "%!\0");
	      break;
	    case '?':		/* push %? into buf */
	      APPEND (pbuf1, "%?\0");
	      break;
	    case '%':		/* push %% into buf */
	      APPEND (pbuf1, "%%\0");
	      break;
	    default:
/* try to continue
** bad macro character is skipped entirely,
** the message will be parsed without whatever %. has occurred. - jn
*/
	      dist_error("Pass 1",macro,*pm-1);
	      break;     
	    }
	}
/* small permutation on the newmacro code... this takes a pointer to
   ** a distress structure and a pointer to a macro syntax string,
   ** and converts it into a line of text.
   **  9/1/93 - jn
    struct distress *dist;	the info
    char   *cry;		the call for help! (output) - should be array
    char   *pm;			macro to parse, used for distress and macro
 */
int
makedistress(struct distress *dist, char *cry, char *pm)
{
    char    buf1[10 * MAXMACLEN];
    char   *pbuf1;
    char    buf2[10 * MAXMACLEN];
    char    buf3[10 * MAXMACLEN];
    char    tmp[10 * MAXMACLEN];
    int     index1 = 0;
    int     index2 = 0;
    int     index3 = 0;
    int     cap = 0;
    struct player *sender;
    struct player *j;
    struct planet *l;
    extern int ping_tloss_sc;	/* total % loss 0--100, server to client */
    extern int ping_tloss_cs;	/* total % loss 0--100, client to server */
    extern int ping_av;		/* average rt */
    extern int ping_sd;		/* standard deviation */
    char    c;


    sender = &players[dist->sender];

    if (!(*pm)) {
	cry[0] = '\0';
	return (0);
    }
    buf1[0] = '\0';
    pbuf1 = buf1;

    /* first step is to substitute variables */
    while (*pm) {
	if (*pm == '%') {
	    pm++;

	    if (!pm)
		continue;

	    switch (c = *(pm++)) {
	    case ' ':
		APPEND(pbuf1, " \0");
		break;
	    case 'O':		/* push a 3 character team name into buf */
		cap = 1;
	    case 'o':		/* push a 3 character team name into buf */
		APPEND_CAP(pbuf1, cap, teaminfo[sender->p_teami].shortname);
		cap = 0;
		break;
	    case 'a':		/* push army number into buf */
		APPEND_INT(pbuf1, dist->arms);
		break;
	    case 'd':		/* push damage into buf */
		APPEND_INT(pbuf1, dist->dam);
		break;
	    case 's':		/* push shields into buf */
		APPEND_INT(pbuf1, dist->shld);
		break;
	    case 'f':		/* push fuel into buf */
		APPEND_INT(pbuf1, dist->fuelp);
		break;
	    case 'w':		/* push wtemp into buf */
		APPEND_INT(pbuf1, dist->wtmp);
		break;
	    case 'e':		/* push etemp into buf */
		APPEND_INT(pbuf1, dist->etmp);
		break;

	    case 'P':		/* push player id into buf */
	    case 'G':		/* push friendly player id into buf */
	    case 'H':		/* push enemy target player id into buf */

	    case 'p':		/* push player id into buf */
	    case 'g':		/* push friendly player id into buf */
	    case 'h':		/* push enemy target player id into buf */

		switch (c) {
		case 'p':
		    j = &players[dist->tclose_j];
		    break;
		case 'g':
		    j = &players[dist->tclose_fr];
		    break;
		case 'h':
		    j = &players[dist->tclose_en];
		    break;
		case 'P':
		    j = &players[dist->close_j];
		    break;
		case 'G':
		    j = &players[dist->close_fr];
		    break;
		default:
		    j = &players[dist->close_en];
		    break;
		}
		tmp[0] = j->p_mapchars[1];
		tmp[1] = '\0';
		APPEND(pbuf1, tmp);
		break;

	    case 'n':		/* push planet armies into buf */
		l = &planets[dist->tclose_pl];
		APPEND_INT(pbuf1,
			   ((l->pl_info & idx_to_mask(sender->p_teami))
			    ? l->pl_armies : -1));
		break;
	    case 'B':
		cap = 1;
	    case 'b':		/* push planet into buf */
		l = &planets[dist->close_pl];
		tmp[0] = l->pl_name[0] - 'A' + 'a';
		tmp[1] = l->pl_name[1];
		tmp[2] = l->pl_name[2];
		tmp[3] = '\0';
		APPEND_CAP(pbuf1, cap, tmp);
		cap = 0;
		break;
	    case 'L':
		cap = 1;
	    case 'l':		/* push planet into buf */
		l = &planets[dist->tclose_pl];
		tmp[0] = l->pl_name[0] - 'A' + 'a';
		tmp[1] = l->pl_name[1];
		tmp[2] = l->pl_name[2];
		tmp[3] = '\0';
		APPEND_CAP(pbuf1, cap, tmp);
		cap = 0;
		break;
	    case 'Z':		/* push a 3 character team name into buf */
		cap = 1;
	    case 'z':		/* push a 3 character team name into buf */
		l = &planets[dist->tclose_pl];
		APPEND_CAP(pbuf1, cap,
			   teaminfo[mask_to_idx(l->pl_owner)].shortname);
		cap = 0;
		break;
	    case 't':		/* push a team character into buf */
		l = &planets[dist->tclose_pl];
		tmp[0] = teaminfo[mask_to_idx(l->pl_owner)].letter;
		tmp[1] = '\0';
		APPEND(pbuf1, tmp);
		break;
	    case 'T':		/* push my team into buf */
		tmp[0] = teaminfo[sender->p_teami].letter;
		tmp[1] = '\0';
		APPEND(pbuf1, tmp);
		break;
	    case 'c':		/* push my id char into buf */
		tmp[0] = sender->p_mapchars[1];
		tmp[1] = '\0';
		APPEND(pbuf1, tmp);
		break;
	    case 'W':		/* push WTEMP flag into buf */
		if (dist->wtmpflag)
		    tmp[0] = '1';
		else
		    tmp[0] = '0';
		tmp[1] = '\0';
		APPEND(pbuf1, tmp);
		break;
	    case 'E':		/* push ETEMP flag into buf */
		if (dist->etempflag)
		    tmp[0] = '1';
		else
		    tmp[0] = '0';
		tmp[1] = '\0';
		APPEND(pbuf1, tmp);
		break;
	    case 'K':
		cap = 1;
	    case 'k':
		if (cap)
		    j = &players[dist->tclose_en];
		else
		    j = sender;

		if (j->p_ship->s_type == STARBASE)
		    sprintf(tmp, "%5.2f", j->p_stats.st_sbkills / 100.0);
		else
		    sprintf(tmp, "%5.2f", (j->p_stats.st_kills + j->p_stats.st_tkills) / 100.0);
		APPEND(pbuf1, tmp);
		break;

	    case 'U':		/* push player name into buf */
		cap = 1;
	    case 'u':		/* push player name into buf */
		j = &players[dist->tclose_en];
		APPEND_CAP(pbuf1, cap, j->p_name);
		cap = 0;
		break;
	    case 'I':		/* my player name into buf */
		cap = 1;
	    case 'i':		/* my player name into buf */
		APPEND_CAP(pbuf1, cap, sender->p_name);
		cap = 0;
		break;
	    case 'S':		/* push ship type into buf */
		*pbuf1++ = sender->p_ship->s_desig[0];
		*pbuf1++ = sender->p_ship->s_desig[1];
		break;
	    case 'M':		/* push capitalized lastMessage into buf */
		cap = 1;
	    case 'm':		/* push lastMessage into buf */
		APPEND_CAP(pbuf1, cap, lastMessage);
		cap = 0;
		break;

	    case 'v':		/* push average ping round trip time into buf */
		APPEND_INT(pbuf1, ping_av);
		break;

	    case 'V':		/* push ping stdev into buf */
		APPEND_INT(pbuf1, ping_sd);
		break;

	    case 'y':		/* push packet loss into buf */
		/* this is the weighting formula used be socket.c ntserv */
		APPEND_INT(pbuf1, (2 * ping_tloss_sc + ping_tloss_cs) / 3);
		break;
	    case '*':		/* push %} into buf */
		APPEND(pbuf1, "%*\0");
		break;
	    case '}':		/* push %} into buf */
		APPEND(pbuf1, "%}\0");
		break;
	    case '{':		/* push %{ into buf */
		APPEND(pbuf1, "%{\0");
		break;
	    case '!':		/* push %! into buf */
		APPEND(pbuf1, "%!\0");
		break;
	    case '?':		/* push %? into buf */
		APPEND(pbuf1, "%?\0");
		break;
	    case '%':		/* push %% into buf */
		APPEND(pbuf1, "%%\0");
		break;
	    default:
/* try to continue
** bad macro character is skipped entirely,
** the message will be parsed without whatever %. has occurred. - jn
*/
		warning("Bad Macro character in distress!");
		fprintf(stderr, "Unrecognizable special character in distress pass 1: %c\n", *(pm - 1));
		break;
	    }
	} else {
	    tmp[0] = *pm;
	    tmp[1] = '\0';
	    APPEND(pbuf1, tmp);
	    pm++;
	}

    }

    *pbuf1 = '\0';

    /* second step is to evaluate tests, buf1->buf2 */
    testmacro(buf1, buf2, &index1, &index2);
    buf2[index2] = '\0';

    if (index2 <= 0) {
	cry[0] = '\0';
	return (0);
    }
    index2 = 0;

    /* third step is to include conditional text, buf2->buf3 */
    condmacro(buf2, buf3, &index2, &index3, 1);

    if (index3 <= 0) {
	cry[0] = '\0';
	return (0);
    }
    buf3[index3] = '\0';

    cry[0] = '\0';
    strncat(cry, buf3, MSG_LEN);

    return (index3);
}
Пример #3
0
CProcessAnalysis::CProcessAnalysis(
  CDirEntry *pDirEntry, 
  const CVolume *pVolume,
  wxEvtHandler *parent, int nID) :
    CProcess(parent,nID),
    m_psExe(NULL),
    m_pDirEntry(pDirEntry)
{
#define END_LINE sStdin.Append(";\n")

#define APPEND_LINE(name,value) \
  sStdin.Append(name);          \
  sStdin.Append(wxS("="));      \
  sStdin.Append(value);         \
  END_LINE

#define FORMAT_INT(n) \
  s.Printf("%d",n)

#define APPEND_INT(name,n) \
  FORMAT_INT(n);           \
  APPEND_LINE(name,s)


  wxString sStdin;
  wxString s;
  const CParmOsiris *pParm = pDirEntry->GetParmOsiris();
  const ConfigDir *pDir = mainApp::GetConfig();
  
  sStdin.Alloc(4096);
  APPEND_LINE("InputDirectory",pParm->GetInputDirectory());      //  1
  APPEND_LINE("LadderDirectory",pDir->GetExeConfigPath());       //  2
  APPEND_LINE("ReportDirectory",pParm->GetOutputDirectory());    //  3
  APPEND_LINE("MarkerSetName",pParm->GetKitName());              //  4
  APPEND_LINE("LaneStandardName",pParm->GetLsName());            //  5
  APPEND_LINE("CriticalOutputLevel","15");                   //  6
  APPEND_INT("MinSampleRFU",pParm->GetMinRFU_Sample());          //  7
  APPEND_INT("MinLaneStandardRFU",pParm->GetMinRFU_ILS());       //  8
  APPEND_INT("MinLadderRFU",pParm->GetMinRFU_Ladder());          //  9
  APPEND_INT("MinInterlocusRFU",pParm->GetMinRFU_Interlocus());  // 10

  // channel data

  typedef struct 
  {
    const vector<int> *pan;
    const wxChar *ps;
  } CHANNEL_OVERRIDE;
  CHANNEL_OVERRIDE chanInfo[] =
  {
    { &pParm->GetChannelRFU(), wxS("AnalysisThresholdOverride") },
    { &pParm->GetChannelDetection(), wxS("DetectionThresholdOverride") }
  };
  const size_t nOVR = sizeof(chanInfo) / sizeof(chanInfo[0]);
  wxString sName;
  for (size_t ndx = 0; ndx < nOVR; ndx++)
  {
    const vector<int> *pan = chanInfo[ndx].pan;
    const wxChar *ps = chanInfo[ndx].ps;
    vector<int>::const_iterator itr;
    int nChannel;
    for(itr = pan->begin(), nChannel = 1;
        itr != pan->end();
        ++itr, ++nChannel)
    {
      if((*itr) > 0)
      {
        FORMAT_INT(nChannel);
        sName = ps;
        sName.Append(wxS(":"));
        sName.Append(s);
        APPEND_INT(sName,*itr);
      }
    }
  }

  // end channel data

  if(pParm->GetTimeStampSubDir())
  {
    const wxString &s = pDirEntry->GetTimeStamp();
    if(!s.IsEmpty())
    {
      APPEND_LINE("OutputSubdirectory",s);
    }
    else
    {
      wxASSERT_MSG(false,"Time stamp is empty");
    }
  }

  // the following may eventually be moved to CParmOsiris and
  //  CLabSettings::GetMinRFU() if it is added to the user interface

  int nMinLadderInterlocus = pParm->GetMinLadderInterlocusRFU();
//    pVolume->GetLabSettings()->GetThresholds()->GetRFUladder()->GetMinRFUinterlocus();
  int nMinDetection = pParm->GetSampleDetectionThreshold();
//    pVolume->GetLabSettings()->GetThresholds()->GetRFUsample()->GetMinDetection();
  if(nMinLadderInterlocus >= 0)
  {
    APPEND_INT("MinLadderInterlocusRFU",nMinLadderInterlocus);   // 11
  }
  if(nMinDetection >= 0)
  {
    APPEND_INT("SampleDetectionThreshold",nMinDetection);
  }
  s = pParm->GetDataAnalyzed() ? "A" : "R";
  APPEND_LINE("RawDataString",s);  // 11 or 12
  APPEND_LINE("LabSettings",pVolume->GetLabSettingsFileName());
  APPEND_LINE("StandardSettings",pVolume->GetStdSettingsFileName());
  APPEND_LINE("MessageBook",pDir->GetMessageBookFileName());
  const wxString &sOverride(pParm->GetAnalysisOverride());
  if(!sOverride.IsEmpty())
  {
    APPEND_LINE("override",sOverride);
  }

  END_LINE;

#undef APPEND_INT
#undef APPEND_LINE
#undef END_LINE

  //  finished building stdin for analysis program

  wxASSERT_MSG(sizeof(char) == 1,
      "sizeof(char) != 1, "
        "therefore this code needs to be changed");
  
  s = pDir->GetExePath();
  nwxFileUtil::EndWithSeparator(&s);
#ifdef __WXMSW__
  s += "TestAnalysisDirectoryLC.exe";
#else
  s += "TestAnalysisDirectoryLC";
#endif
  m_psExe = strdup(s.utf8_str());

  char *argv[] = { m_psExe, NULL  };
  m_dProgress = 0.0;
  Run(argv);
  wxOutputStream *pOut = GetOutputStream();
  wxASSERT_MSG(pOut != NULL,"Cannot get output stream for process");
  mainApp::LogMessage(sStdin);
  if(pOut != NULL)
  {
    const char *pChar = sStdin.ToUTF8();
    size_t nLen = sStdin.Len();
    size_t n;
    while(nLen > 0)
    {
      n = pOut->Write((void *)pChar,nLen).LastWrite();
      if(n)
      {
        pChar += n;
        nLen -= n;
      }
      else
      {
        nLen = 0;
        Cancel();
      }
    }
  }
}