Ejemplo n.º 1
0
LoggerAction* loggerActionNew(char const* toolName_)
{
  LoggerAction* act = (LoggerAction*) malloc(sizeof(LoggerAction));
  if (!act)
  {
    return NULL;
  }

  loggerFileInitFromPath(&act->output, "./_noobj");
  loggerVectorInit(&act->arguments);
  loggerVectorInit(&act->sources);
  strcpy(act->toolName, toolName_);

  return act;
}
Ejemplo n.º 2
0
/**
 * Processes an command line argument for a GCC like command.
 *
 * @param state_ the current state of the parser.
 * @param arg_ the current command line argument.
 * @param action the current action.
 * @return the new state.
 */
static GccArgsState processArgument(
  GccArgsState state_,
  const char* arg_,
  LoggerAction* action_)
{
  char argToAdd[PATH_MAX];
  strcpy(argToAdd, arg_);

  if (state_ == InOutputArg)
  {
    if (!loggerMakePathAbs(arg_, argToAdd, 0))
    {
      strcpy(argToAdd, arg_);
    }

    loggerFileInitFromPath(&action_->output, argToAdd);
    state_ = Normal;
  }
  else if (strcmp(arg_, "-o") == 0)
  {
    state_ = InOutputArg;
  }
  else if (arg_[0] == '-' && (arg_[1] == 'I' || arg_[1] == 'L') && arg_[2])
  {
    /* This is a -I or -L option with a path */
    char fullPath[PATH_MAX];
    if (loggerMakePathAbs(arg_ + 2, fullPath, 0))
    {
      argToAdd[2] = 0;
      strcat(argToAdd, fullPath);
    }
  }
  else
  {
    char fullPath[PATH_MAX];
    if (loggerMakePathAbs(argToAdd, fullPath, 1))
    {
      char* ext = loggerGetFileExt(fullPath, 1);
      if (ext)
      {
        int i;
        for (i = 0; srcExts[i]; ++i)
        {
          if (strcmp(srcExts[i], ext) == 0)
          {
            strcpy(argToAdd, fullPath);
            loggerVectorAddUnique(&action_->sources,  loggerStrDup(fullPath),
              (LoggerCmpFuc) &strcmp);
            break;
          }
        }
      }

      free(ext);
    }
  }

  if (argToAdd[0])
  {
    loggerVectorAdd(&action_->arguments, loggerStrDup(argToAdd));
  }

  return state_;
}
Ejemplo n.º 3
0
/**
 * Processes an command line argument for a GCC like command.
 *
 * @param state_ the current state of the parser.
 * @param arg_ the current command line argument.
 * @param action the current action.
 * @return the new state.
 */
static GccArgsState processArgument(
  GccArgsState state_,
  const char* arg_,
  LoggerAction* action_)
{
  char argToAdd[PATH_MAX];
  strcpy(argToAdd, arg_);

  if (state_ == InOutputArg)
  {
    if (!loggerMakePathAbs(arg_, argToAdd, 0))
    {
      strcpy(argToAdd, arg_);
    }

    loggerFileInitFromPath(&action_->output, argToAdd);
    state_ = Normal;
  }
  else if (strcmp(arg_, "-o") == 0)
  {
    state_ = InOutputArg;
  }
  else if (arg_[0] == '-' && ((arg_[1] == 'W' && (arg_[2] == 'l' || arg_[2] == 'p')) || arg_[1] == 'M'))
  {
    /* This is a -Wl linker option
     *  -Wl,-Map,output.map
     *  or a -Wp prepocessor option
     *  -Wp,option
     *  also matches for options like -Wpedantic
     *  handled here to skip for matching source files in
     *  these arguments
     */
    strcpy(argToAdd, arg_);
  }
  else if (arg_[0] == '-' && arg_[1] == 'D')
  {
    /*  Match for macro definition -D
     *  handled here to skip for matching source files in
     *  these arguments
     */
    strcpy(argToAdd, arg_);
  }
  else if (arg_[0] == '-' && (arg_[1] == 'I' || arg_[1] == 'L') && arg_[2])
  {
    /* This is a -I or -L option with a path */
    char fullPath[PATH_MAX];
    if (loggerMakePathAbs(arg_ + 2, fullPath, 0))
    {
      argToAdd[2] = 0;
      strcat(argToAdd, fullPath);
    }
  }
  else
  {
    char fullPath[PATH_MAX];
    if (loggerMakePathAbs(argToAdd, fullPath, 1))
    {
      char* ext = loggerGetFileExt(fullPath, 1);
      if (ext)
      {
        int i;
        for (i = 0; srcExts[i]; ++i)
        {
          if (strcmp(srcExts[i], ext) == 0)
          {
            strcpy(argToAdd, fullPath);
            loggerVectorAddUnique(&action_->sources,  loggerStrDup(fullPath),
              (LoggerCmpFuc) &strcmp);
            break;
          }
        }
      }

      free(ext);
    }
  }

  if (argToAdd[0])
  {
    loggerVectorAdd(&action_->arguments, loggerStrDup(argToAdd));
  }

  return state_;
}
Ejemplo n.º 4
0
int loggerJavacParserCollectActions(
  const char* prog_,
  const char* toolName_,
  const char* const argv_[],
  LoggerVector* actions_)
{
  ParserData data;
  size_t i;

  assert(prog_ == prog_); /* suppress unused variable */

  data.hasSourcePath = 0;
  data.state = Normal;
  loggerVectorInit(&data.commonArgs);
  loggerVectorInit(&data.sources);
  memset(data.classdir, 0, sizeof(data.classdir));

  loggerVectorAdd(&data.commonArgs, loggerStrDup(toolName_));

  for (i = 1; argv_[i]; ++i)
  {
    if (argv_[i][0] == '@')
    {
      size_t j;
      LoggerVector fargs;

      loggerVectorInit(&fargs);
      
      readArgumentsFromFile(argv_[i] + 1, &fargs);
      for (j = 0; j < fargs.size; ++j)
      {
        processArg((const char*) fargs.data[j], &data);
      }

      loggerVectorClear(&fargs);
    }
    else
    {
      processArg(argv_[i], &data);
    }
  }

  if (!data.hasSourcePath)
  {
    char workdir[PATH_MAX];
    if (loggerMakePathAbs(".", workdir, 0))
    {
      loggerVectorAdd(&data.commonArgs, loggerStrDup("-sourcepath"));
      loggerVectorAdd(&data.commonArgs, loggerStrDup(workdir));
    }
  }

  for (i = 0; i < data.sources.size; ++i)
  {
    char outputFile[PATH_MAX];
    const char* src = (char*) data.sources.data[i];
    LoggerAction* action = loggerActionNew(toolName_);
    if (!action)
    {
      continue;
    }

    loggerVectorAddFrom(&action->arguments, &data.commonArgs,
      NULL, (LoggerDupFuc) &loggerStrDup);
    loggerVectorAdd(&action->arguments, loggerStrDup(src));
    loggerVectorAdd(&action->sources, loggerStrDup(src));

    if (data.classdir[0] != 0)
    {
      char* fname = loggerGetFileName(src, 1);
      strcpy(outputFile, data.classdir);
      strcat(outputFile, "/");
      strcat(outputFile, fname);
      strcat(outputFile, ".class");
      free(fname);
    }
    else
    {
      char* path = loggerGetFilePathWithoutExt(src);
      strcpy(outputFile, path);
      strcat(outputFile, ".class");
      free(path);
    }

    loggerFileInitFromPath(&action->output, outputFile);
    loggerVectorAdd(actions_, action);
  }

  loggerVectorClear(&data.commonArgs);
  loggerVectorClear(&data.sources);

  return 1;
}