示例#1
0
/* ****************************************************************************
*
* main -
*/
int main(int argC, char* argV[])
{
  char* fName = "main";

  paConfig("trace levels", "0-255");
  paConfig("help file",     "/users/kzangeli/systems/parseArgs/parseTest3.help");
  paConfig("log to file",   (void*) TRUE);

  paParse(NULL, argC, argV, 1, FALSE);

  lmVerbose = true;
  LM_V(("line with newlines ...\n 1\n2\n3\n4\n"));

  return 0;
}
/* ****************************************************************************
*
* main - 
*/
int main(int argC, char** argV)
{
  paConfig("usage and exit on any warning", (void*) true);
  paConfig("log to screen",                 (void*) "only errors");
  paConfig("log file line format",          (void*) "TYPE:DATE:EXEC-AUX/FILE[LINE](p.PID)(t.TID) FUNC: TEXT");
  paConfig("screen line format",            (void*) "TYPE@TIME  EXEC: TEXT");
  paConfig("log to file",                   (void*) true);
  paConfig("default value", "-logDir",      (void*) "/tmp");
  paConfig("man author",                    "Fermín Galán and Ken Zangelin");

  if (argC > 1)
  {
     if (strcmp(argV[1], "-t") == 0)
       paParse(paArgs, 3, argV, 3, false);
     else
       paParse(paArgs, 1, argV, 1, false);
  }
  else
    paParse(paArgs, 1, argV, 1, false);

  LM_M(("Init tests"));
  orionInit(exitFunction, orionUnitTestVersion, SemReadWriteOp, false);
  setupDatabase();

  LM_M(("Run all tests"));
  ::testing::InitGoogleMock(&argC, argV);
  return RUN_ALL_TESTS();
}
示例#3
0
int main(int argC, char* argV[])
{
	char* fName = "main";

	paConfig("prefix", "P2_");
	paConfig("log to file", "/tmp/");
	paConfig("msgs to stdout", (void*) FALSE);
	paParse(NULL, argC, argV, 1, FALSE);

	LM_V(("verbose message"));
	if (paResultString[0] != 0)
		printf("Got a paResultString:\n%s", paResultString);
	else if (paWarnings != 0)
	{
		int ix;

		printf("Got warnings:\n");
		for (ix = 0; ix < paWarnings; ix++)
			printf("Severity %02d: %s\n", paWarning[ix].severity, paWarning[ix].string);
		printf("\n");
	}

	return 0;
}
示例#4
0
/* ****************************************************************************
*
* main - 
*/
int main(int argC, char* argV[])
{
  paConfig("prefix", "LT_");

  paConfig("log to file", "/tmp/");
  paConfig("log file line format", "DEF");
  paConfig("log file time format", "DEF");
  paConfig("usage and exit on any warning", (void*) 1);

  paConfig("log to screen", "only errors");
  paConfig("screen line format", "TYPE:FUNC: TEXT");

  paParse(paArgs, argC, argV, 1, 0);

  pthread_t pid[10];
  for (int cIx = 0; cIx < 10; ++cIx)
    pthread_create(&pid[cIx], NULL, child, &cIx);

  for (int cIx = 0; cIx < 10; ++cIx)
    pthread_join(pid[cIx], NULL);

  //
  // FIXME P4: This test program should be a unit test
  //
  // Now, lets see if we have 10000 lines in the logfile
  // Actually, 4 lines is the header, so the total should be 1004 lines
  //
  int lines = lmLogLinesGet();

  if (lines == 10004)
    printf("OK\n");
  else
    printf("Error - log file has %d lines. Should have 1004\n", lines);

  return 0;
}
示例#5
0
/* ****************************************************************************
*
* paParse - parse the argument list
*
*/
int paParse
(
  PaArgument*  paList,
  int          argC,
  char*        argV[],
  int          level,
  bool         pid,
  const char*  extra
)
{
  char*  progNameCopy;
  int    ix;
  int    s;
  FILE*  fP;

  if (extra != NULL)
  {
    paExtraLogSuffix = strdup(extra);
  }

  memset(paResultString, 0, sizeof(paResultString));

  /* **************************************************** */
  /* Creating flat command line string paCommandLine      */
  /*                                                      */
  if (argC > 1)
  {
    strncpy(paCommandLine, argV[1], sizeof(paCommandLine));
    for (ix = 2; ix < argC; ix++)
    {
      if (sizeof(paCommandLine) - strlen(paCommandLine) > 1)
      {
        strncat(paCommandLine, " ", sizeof(paCommandLine) - strlen(paCommandLine) - 1);
      }
      else
      {
        break;
      }

      if (sizeof(paCommandLine) - strlen(paCommandLine) > 1)
      {
        strncat(paCommandLine, argV[ix], sizeof(paCommandLine) - strlen(paCommandLine) - 1);
      }
      else
      {
        break;
      }
    }
  }


  /* ********************************************************* */
  /* Calling paConfig just to make sure paConfigInit is called */
  /*                                                           */
  paConfig("make sure paConfigInit is called", 0);



  /* *************************** */
  /* Setting up the program name */
  /*                             */
  if (paProgName == NULL) /* hasn't been set with paConfig */
  {
    progNameCopy = strdup(argV[0]);
    progName     = strdup(paProgNameSet(argV[0], level, pid, extra));
    paProgName   = strdup(progName);
  }
  else
  {
    progNameCopy = strdup(paProgName);
    progName     = strdup(paProgName);
  }


  /* ************************************************* */
  /* The rcFileName must not have any '/' in its name. */
  /* it should be called (by default) .<progname>rc    */
  /* So, first we must get a progName without '/' ...  */
  /*                                                   */
  if (paRcFileName == NULL)
  {
    char rName[128];

    snprintf(rName, sizeof(rName), ".%src", paProgNameSet(progNameCopy, 1, false));
    paRcFileName = strdup(rName);
  }
  free(progNameCopy);


  /* ****************************************************** */
  /* Initializing all subsystems                            */
  /*                                                        */
  if ((s = paArgInit(paList)) == -1)
  {
    RETURN_ERROR("paArgInit error");
  }

  if ((s != -2) && ((s = paConfigActions(true)) == -1))
  {
    RETURN_ERROR("paConfigActions");
  }

  if ((s != -2) && ((s = paDefaultValues(paiList)) == -1))
    RETURN_ERROR("paDefaultValues");

#if 0
  // Orion doesn't use paRcFileParse ...
  if ((s != -2) && ((s = paRcFileParse()) == -1))
    RETURN_ERROR("paRcFileParse");
#endif

  if ((s != -2) && ((s = paEnvVals(paiList)) == -1))
  {
    RETURN_ERROR("paEnvVals");
  }

  if ((s != -2) && ((s = paOptionsParse(paiList, argV, argC)) == -1))
  {
    RETURN_ERROR("paOptionsParse");
  }

  if (paLogSetup() == -1)
  {
    RETURN_ERROR("paLogSetup error");
  }

  if ((s != -2) && ((s = paLimitCheck(paiList)) == -1))
  {
    RETURN_ERROR("paLimitCheck");
  }

  if ((s != -2) && ((s = paConfigActions(false)) == -1))
  {
    RETURN_ERROR("paConfigActions");
  }


  fP = NULL;
  if (paMsgsToStdout)
  {
    fP = stdout;
  }

  if (paMsgsToStderr)
  {
    fP = stderr;
  }

  if (paResultString[0] != 0)
  {
    if (fP != NULL)
    {
      fprintf(fP, "%s\n", paResultString);
    }
  }
  else if (paWarnings > 0)
  {
    int ix;

    if (fP != NULL)
    {
      // fprintf(fP, "\nEntire command line: '%s'\n\n", paCommandLine);

      for (ix = 0; ix < paWarnings; ix++)
      {
        fprintf(fP, "%s\n\n", paWarning[ix].string);
      }

      if (paUsageOnAnyWarning)
      {
        paUsage();
      }

      if (paResultString[0] != 0)
      {
        fprintf(fP, "%s\n", paResultString);
      }

      exit(1);
    }
    else
    {
      char s[64000];

      snprintf(paResultString, sizeof(paResultString), "\nEntire command line options: '%s'\n\n", paCommandLine);

      snprintf(s, sizeof(s), "--- %s warnings ---\n", progName);
      strncat(paResultString, s, sizeof(paResultString) - 1);

      for (ix = 0; ix < paWarnings; ix++)
      {
        snprintf(s, sizeof(s), "Severity % 2d: %s\n\n", paWarning[ix].severity, paWarning[ix].string);
        strncat(paResultString, s, sizeof(paResultString) - 1);
      }

      strncat(paResultString, "\n\n", sizeof(paResultString) - 1);

      if (paUsageOnAnyWarning)
      {
        printf("paUsageOnAnyWarning == true (2)\n");
        paUsage();
      }
    }
  }

  free(paiList);
  free(paRcFileName);
  free(paUsageProgName);

  return 0;
}