void do_parens(void)
{
   LOG_FUNC_ENTRY();

   if (cpd.settings[UO_mod_full_paren_if_bool].b)
   {
      chunk_t *pc = chunk_get_head();
      while ((pc = chunk_get_next_ncnl(pc)) != nullptr)
      {
         if (  pc->type != CT_SPAREN_OPEN
            || (  pc->parent_type != CT_IF
               && pc->parent_type != CT_ELSEIF
               && pc->parent_type != CT_SWITCH))
         {
            continue;
         }

         // Grab the close sparen
         chunk_t *pclose = chunk_get_next_type(pc, CT_SPAREN_CLOSE, pc->level, scope_e::PREPROC);
         if (pclose != nullptr)
         {
            check_bool_parens(pc, pclose, 0);
            pc = pclose;
         }
      }
   }
}
Beispiel #2
0
void set_chunk_real(chunk_t *pc, c_token_t token, log_sev_t what, const char *str)
{
   LOG_FUNC_ENTRY();

   c_token_t *where;
   c_token_t *type;
   c_token_t *parent_type;

   switch (what)
   {
   case (LSETTYP): where = &pc->type;
      type               = &token;
      parent_type        = &pc->parent_type;
      break;

   case (LSETPAR): where = &pc->parent_type;
      type               = &pc->type;
      parent_type        = &token;
      break;

   default:
      return;
   }

   if ((pc != NULL) && (*where != token))
   {
      LOG_FMT(what, "%s: %zu:%zu '%s' %s:%s => %s:%s",
              str, pc->orig_line, pc->orig_col, pc->text(),
              get_token_name(pc->type), get_token_name(pc->parent_type),
              get_token_name(*type), get_token_name(*parent_type));
      log_func_stack_inline(what);
      *where = token;
   }
}
Beispiel #3
0
chunk_t *pawn_add_vsemi_after(chunk_t *pc)
{
   LOG_FUNC_ENTRY();
   if ((pc->type == CT_VSEMICOLON) ||
       (pc->type == CT_SEMICOLON))
   {
      return(pc);
   }

   chunk_t *next = chunk_get_next_nc(pc);
   if ((next != NULL) &&
       ((next->type == CT_VSEMICOLON) ||
        (next->type == CT_SEMICOLON)))
   {
      return(pc);
   }
   chunk_t chunk;

   chunk             = *pc;
   chunk.type        = CT_VSEMICOLON;
   chunk.str         = cpd.settings[UO_mod_pawn_semicolon].b ? ";" : "";
   chunk.column     += pc->len();
   chunk.parent_type = CT_NONE;

   LOG_FMT(LPVSEMI, "%s: Added VSEMI on line %lu, prev='%s' [%s]\n",
           __func__, pc->orig_line, pc->text(),
           get_token_name(pc->type));

   return(chunk_add_after(&chunk, pc));
}
Beispiel #4
0
/**
 * Does a scan of level 0 BEFORE stuff in combine.cpp is called.
 * At this point, VSemis have been added only in VBraces.
 * Otherwise, all level info is correct, except for unbraced functions.
 *
 * We are looking for unbraced functions.
 */
void pawn_prescan(void)
{
   LOG_FUNC_ENTRY();

   /* Start at the beginning and step through the entire file, and clean up
    * any questionable stuff
    */

   chunk_t *pc;
   bool    did_nl = true;

   pc = chunk_get_head();
   while (pc != NULL)
   {
      if (did_nl && (pc->type != CT_PREPROC) &&
          !chunk_is_newline(pc) && (pc->level == 0))
      {
         /* pc now points to the start of a line */
         pc = pawn_process_line(pc);
      }
      /* note that continued lines are ignored */
      if (pc != NULL)
      {
         did_nl = (pc->type == CT_NEWLINE);
      }

      pc = chunk_get_next_nc(pc);
   }
}
Beispiel #5
0
static void mod_case_brace(void)
{
   LOG_FUNC_ENTRY();

   chunk_t *pc = chunk_get_head();
   while (pc != NULL)
   {
      chunk_t *next = chunk_get_next_ncnl(pc, CNAV_PREPROC);
      if (next == NULL)
      {
         return;
      }

      if ((cpd.settings[UO_mod_case_brace].a == AV_REMOVE) &&
          (pc->type == CT_BRACE_OPEN) &&
          (pc->parent_type == CT_CASE))
      {
         pc = mod_case_brace_remove(pc);
      }
      else if ((cpd.settings[UO_mod_case_brace].a & AV_ADD) &&
               (pc->type == CT_CASE_COLON) &&
               (next->type != CT_BRACE_OPEN) &&
               (next->type != CT_BRACE_CLOSE) &&
               (next->type != CT_CASE))
      {
         pc = mod_case_brace_add(pc);
      }
      else
      {
         pc = chunk_get_next_ncnl(pc, CNAV_PREPROC);
      }
   }
}
Beispiel #6
0
// -----------------------------------------------------------------------------
// CATBase::IsBinaryLogFile
// -----------------------------------------------------------------------------
bool CATBase::IsBinaryLogFile( string sFile )
{
	LOG_FUNC_ENTRY("CATBase::IsDataFile");
	// Check that sFile not empty
	if ( sFile.empty() || sFile.length() < 1 )
		return false;

	// Temporary line char array.
	char cLineFromFile[MAX_LINE_LENGTH];
	//Open file
	ifstream in( sFile.c_str() );

	//File open ok?
	if( !in.good() )
		return false;

	//Read all lines
	in.getline( cLineFromFile, MAX_LINE_LENGTH );

	string sLineFromFile( cLineFromFile );
	in.close();

	if( sLineFromFile.find( "ATOOL_BINARY_FILE_VERSION" ) != string::npos )
		return true;
	else
		return false;
}
Beispiel #7
0
void do_parens(void)
{
    LOG_FUNC_ENTRY();
    chunk_t *pc;
    chunk_t *pclose;

    if (cpd.settings[UO_mod_full_paren_if_bool].b)
    {
        pc = chunk_get_head();
        while ((pc = chunk_get_next_ncnl(pc)) != NULL)
        {
            if ((pc->type != CT_SPAREN_OPEN) ||
                    ((pc->parent_type != CT_IF) &&
                     (pc->parent_type != CT_ELSEIF) &&
                     (pc->parent_type != CT_SWITCH)))
            {
                continue;
            }

            /* Grab the close sparen */
            pclose = chunk_get_next_type(pc, CT_SPAREN_CLOSE, pc->level, CNAV_PREPROC);
            if (pclose != NULL)
            {
                check_bool_parens(pc, pclose, 0);
                pc = pclose;
            }
        }
    }
}
Beispiel #8
0
/**
 * Adds a comment after the ref chunk
 * Returns the added chunk or NULL
 */
chunk_t *insert_comment_after(chunk_t *ref, c_token_t cmt_type,
                              const unc_text &cmt_text)
{
   LOG_FUNC_ENTRY();

   chunk_t new_cmt = *ref;
   new_cmt.prev  = NULL;
   new_cmt.next  = NULL;
   new_cmt.flags = (ref->flags & PCF_COPY_FLAGS);
   new_cmt.type  = cmt_type;
   new_cmt.str.clear();
   if (cmt_type == CT_COMMENT_CPP)
   {
      new_cmt.str.append("// ");
      new_cmt.str.append(cmt_text);
   }
   else
   {
      if (ref->type == CT_PP_ELSE)
      {  // make test c/ 02501 stable
         new_cmt.str.append(" ");
      }
      new_cmt.str.append("/* ");
      new_cmt.str.append(cmt_text);
      new_cmt.str.append(" */");
   }
   /* TODO: expand comment type to cover other comment styles? */

   new_cmt.column   = ref->column + ref->len() + 1;
   new_cmt.orig_col = new_cmt.column;

   return(chunk_add_after(&new_cmt, ref));
}
Beispiel #9
0
static void append_tag_name(unc_text &txt, chunk_t *pc)
{
   LOG_FUNC_ENTRY();
   chunk_t *tmp = pc;

   /* step backwards over all a::b stuff */
   while ((tmp = chunk_get_prev_ncnl(tmp)) != NULL)
   {
      if ((tmp->type != CT_DC_MEMBER) && (tmp->type != CT_MEMBER))
      {
         break;
      }
      tmp = chunk_get_prev_ncnl(tmp);
      pc  = tmp;
      if (!chunk_is_word(tmp))
      {
         break;
      }
   }

   txt += pc->str;
   while ((pc = chunk_get_next_ncnl(pc)) != NULL)
   {
      if ((pc->type != CT_DC_MEMBER) && (pc->type != CT_MEMBER))
      {
         break;
      }
      txt += pc->str;
      pc   = chunk_get_next_ncnl(pc);
      if (pc)
      {
         txt += pc->str;
      }
   }
}
Beispiel #10
0
static void examine_braces(void)
{
   LOG_FUNC_ENTRY();

   chunk_t *pc = chunk_get_tail();
   while (pc != NULL)
   {
      chunk_t *prev = chunk_get_prev_type(pc, CT_BRACE_OPEN, -1);
      if ((pc->type == CT_BRACE_OPEN) &&
          ((pc->flags & PCF_IN_PREPROC) == 0))
      {
         if ((((pc->parent_type == CT_IF) ||
               (pc->parent_type == CT_ELSE) ||
               (pc->parent_type == CT_ELSEIF)) &&
              ((cpd.settings[UO_mod_full_brace_if].a) == AV_REMOVE)) ||
             ((pc->parent_type == CT_DO) &&
              ((cpd.settings[UO_mod_full_brace_do].a) == AV_REMOVE)) ||
             ((pc->parent_type == CT_FOR) &&
              ((cpd.settings[UO_mod_full_brace_for].a) == AV_REMOVE)) ||
             ((pc->parent_type == CT_USING_STMT) &&
              ((cpd.settings[UO_mod_full_brace_using].a) == AV_REMOVE)) ||
             ((pc->parent_type == CT_WHILE) &&
              ((cpd.settings[UO_mod_full_brace_while].a) == AV_REMOVE)))
         {
            examine_brace(pc);
         }
      }
      pc = prev;
   }
}
Beispiel #11
0
/**
 * We are on a level 0 function proto of def
 */
static chunk_t *pawn_mark_function0(chunk_t *start, chunk_t *fcn)
{
   LOG_FUNC_ENTRY();
   chunk_t *last;

   /* handle prototypes */
   if (start == fcn)
   {
      last = chunk_get_next_type(fcn, CT_PAREN_CLOSE, fcn->level);
      last = chunk_get_next(last);
      if ((last != NULL) && (last->type == CT_SEMICOLON))
      {
         LOG_FMT(LPFUNC, "%s: %lu] '%s' proto due to semicolon\n",
                 __func__, fcn->orig_line, fcn->text());
         set_chunk_type(fcn, CT_FUNC_PROTO);
         return(last);
      }
   }
   else
   {
      if ((start->type == CT_FORWARD) ||
          (start->type == CT_NATIVE))
      {
         LOG_FMT(LPFUNC, "%s: %lu] '%s' [%s] proto due to %s\n",
                 __func__, fcn->orig_line, fcn->text(),
                 get_token_name(fcn->type),
                 get_token_name(start->type));
         set_chunk_type(fcn, CT_FUNC_PROTO);
         return(chunk_get_next_nc(fcn));
      }
   }

   /* Not a prototype, so it must be a function def */
   return(pawn_process_func_def(fcn));
}
Beispiel #12
0
/**
 * Splits the parameters at every comma that is at the fparen level.
 *
 * @param start   the offending token
 */
static void split_fcn_params_full(chunk_t *start)
{
   LOG_FUNC_ENTRY();
   LOG_FMT(LSPLIT, "%s", __func__);

   chunk_t *fpo;
   chunk_t *pc;

   /* Find the opening fparen */
   fpo = start;
   while (((fpo = chunk_get_prev(fpo)) != NULL) &&
          (fpo->type != CT_FPAREN_OPEN))
   {
      /* do nothing */
   }

   /* Now break after every comma */
   pc = fpo;
   while ((pc = chunk_get_next_ncnl(pc)) != NULL)
   {
      if (pc->level <= fpo->level)
      {
         break;
      }
      if ((pc->level == (fpo->level + 1)) && (pc->type == CT_COMMA))
      {
         split_before_chunk(chunk_get_next(pc));
      }
   }
}
Beispiel #13
0
/**
 * pc is a CT_WHILE.
 * Scan backwards to see if we find a brace/vbrace with the parent set to CT_DO
 */
static bool maybe_while_of_do(chunk_t *pc)
{
    LOG_FUNC_ENTRY();
    chunk_t *prev;

    prev = chunk_get_prev_ncnl(pc);
    if ((prev == NULL) || !(prev->flags & PCF_IN_PREPROC))
    {
        return(false);
    }

    /* Find the chunk before the preprocessor */
    while ((prev != NULL) && (prev->flags & PCF_IN_PREPROC))
    {
        prev = chunk_get_prev_ncnl(prev);
    }

    if ((prev != NULL) &&
            (prev->parent_type == CT_DO) &&
            ((prev->type == CT_VBRACE_CLOSE) ||
             (prev->type == CT_BRACE_CLOSE)))
    {
        return(true);
    }
    return(false);
}
Beispiel #14
0
static bool maybe_while_of_do(chunk_t *pc)
{
   LOG_FUNC_ENTRY();
   chunk_t *prev;

   prev = chunk_get_prev_ncnl(pc);
   if (prev == nullptr || !(prev->flags & PCF_IN_PREPROC))
   {
      return(false);
   }

   // Find the chunk before the preprocessor
   while (prev != nullptr && (prev->flags & PCF_IN_PREPROC))
   {
      prev = chunk_get_prev_ncnl(prev);
   }

   if (  prev != nullptr
      && prev->parent_type == CT_DO
      && (prev->type == CT_VBRACE_CLOSE || prev->type == CT_BRACE_CLOSE))
   {
      return(true);
   }
   return(false);
}
Beispiel #15
0
static size_t preproc_start(parse_frame_t *frm, chunk_t *pc)
{
   LOG_FUNC_ENTRY();
   chunk_t *next;
   size_t  pp_level = cpd.pp_level;

   // Get the type of preprocessor and handle it
   next = chunk_get_next_ncnl(pc);
   if (next != nullptr)
   {
      cpd.in_preproc = next->type;

      // If we are in a define, push the frame stack.
      if (cpd.in_preproc == CT_PP_DEFINE)
      {
         pf_push(frm);

         // a preproc body starts a new, blank frame
         memset(frm, 0, sizeof(*frm));
         frm->level       = 1;
         frm->brace_level = 1;

         // TODO: not sure about the next 3 lines
         frm->pse_tos                 = 1;
         frm->pse[frm->pse_tos].type  = CT_PP_DEFINE;
         frm->pse[frm->pse_tos].stage = brace_stage_e::NONE;
      }
      else
      {
         // Check for #if, #else, #endif, etc
         pp_level = pf_check(frm, pc);
      }
   }
   return(pp_level);
}
Beispiel #16
0
static void print_stack(log_sev_t logsev, const char *str,
                        struct parse_frame *frm, chunk_t *pc)
{
    (void)pc;
    LOG_FUNC_ENTRY();
    if (log_sev_on(logsev))
    {
        int idx;

        log_fmt(logsev, "%8.8s", str);

        for (idx = 1; idx <= frm->pse_tos; idx++)
        {
            if (frm->pse[idx].stage != BS_NONE)
            {
                LOG_FMT(logsev, " [%s - %d]", get_token_name(frm->pse[idx].type),
                        frm->pse[idx].stage);
            }
            else
            {
                LOG_FMT(logsev, " [%s]", get_token_name(frm->pse[idx].type));
            }
        }
        log_fmt(logsev, "\n");
    }
}
int
Util_EncodeBase64(const void* src, size_t srcLen, char** dst_out, size_t* dstLen_out,
        VPL_BOOL addNewlines, VPL_BOOL urlSafe)
{
    size_t encodedBufLen;
    LOG_FUNC_ENTRY(LOG_LEVEL_DEBUG);
    
    if (dst_out == NULL) {
        return UTIL_ERR_INVALID;
    }
    if (addNewlines) {
        encodedBufLen = VPL_BASE64_ENCODED_BUF_LEN(srcLen);
    } else {
        encodedBufLen = VPL_BASE64_ENCODED_SINGLE_LINE_BUF_LEN(srcLen);
    }
    *dst_out = malloc(encodedBufLen);
    if (*dst_out == NULL) {
        if (dstLen_out != NULL) {
            *dstLen_out = 0;
        }
        return UTIL_ERR_NO_MEM;
    }
    VPL_EncodeBase64(src, srcLen, *dst_out, &encodedBufLen, addNewlines, urlSafe);
    // Subtract one for the null-terminator.
    if (dstLen_out != NULL) {
        *dstLen_out = (encodedBufLen - 1);
    }
    return GVM_OK;
}
bool CATDbgHelper::AddressToFunction( CATMemoryAddress* result )
{
	LOG_FUNC_ENTRY("CATDbgHelper::AddressToFunction");
	bool bFound = false;
	// If map file read use it and return.
	if ( m_bMap )
	{
		ULONG uCountedA = result->GetOffSetFromModuleStart();
		for ( vector<MAP_FUNC_INFO>::iterator it = m_vMapFileFuncList.begin() ; it != m_vMapFileFuncList.end() ; it++ )
		{
			// Check is this the symbol where address is.
			unsigned long iStart = it->iAddress;
			unsigned long iEnd = it->iAddress + it->iFuncLength;
			if ( uCountedA >= iStart 
				&& uCountedA < iEnd )
			{
				result->SetAddressToLineState( CATMemoryAddress::SYMBOL );
				result->SetFunctionName( it->sMangledName );
				bFound = true;
				break;
			}
		}
	}
	return bFound;
}
Beispiel #19
0
/**
 * Turns certain virtual semicolons invisible.
 *  - after a close brace with a parent of switch, case, else, if
 */
void pawn_scrub_vsemi(void)
{
   LOG_FUNC_ENTRY();
   if (!cpd.settings[UO_mod_pawn_semicolon].b)
   {
      return;
   }

   chunk_t *pc;
   chunk_t *prev;

   for (pc = chunk_get_head(); pc != NULL; pc = chunk_get_next(pc))
   {
      if (pc->type != CT_VSEMICOLON)
      {
         continue;
      }
      prev = chunk_get_prev_ncnl(pc);
      if ((prev != NULL) && (prev->type == CT_BRACE_CLOSE))
      {
         if ((prev->parent_type == CT_IF) ||
             (prev->parent_type == CT_ELSE) ||
             (prev->parent_type == CT_SWITCH) ||
             (prev->parent_type == CT_CASE) ||
             (prev->parent_type == CT_WHILE_OF_DO))
         {
            pc->str.clear();
         }
      }
   }
}
Beispiel #20
0
/**
 * We are in a virtual brace and hit a newline.
 * If this should end the vbrace, then insert a VSEMICOLON and return that.
 *
 * @param pc   The newline (CT_NEWLINE)
 * @return     Either the newline or the newly inserted virtual semicolon
 */
chunk_t *pawn_check_vsemicolon(chunk_t *pc)
{
   LOG_FUNC_ENTRY();
   chunk_t *vb_open;
   chunk_t *prev;

   /* Grab the open VBrace */
   vb_open = chunk_get_prev_type(pc, CT_VBRACE_OPEN, -1);

   /**
    * Grab the item before the newline
    * Don't do anything if:
    *  - the only thing previous is the V-Brace open
    *  - in a preprocessor
    *  - level > (vb_open->level + 1) -- ie, in () or []
    *  - it is something that needs a continuation
    *    + arith, assign, bool, comma, compare
    */
   prev = chunk_get_prev_ncnl(pc);
   if ((prev == NULL) ||
       (prev == vb_open) ||
       (prev->flags & PCF_IN_PREPROC) ||
       pawn_continued(prev, vb_open->level + 1))
   {
      if (prev != NULL)
      {
         LOG_FMT(LPVSEMI, "%s:  no  VSEMI on line %lu, prev='%s' [%s]\n",
                 __func__, prev->orig_line, prev->text(), get_token_name(prev->type));
      }
      return(pc);
   }

   return(pawn_add_vsemi_after(prev));
}
Beispiel #21
0
void do_code_width(void)
{
   LOG_FUNC_ENTRY();
   LOG_FMT(LSPLIT, "%s(%d)\n", __func__, __LINE__);

   for (chunk_t *pc = chunk_get_head(); pc != nullptr; pc = chunk_get_next(pc))
   {
      if (  !chunk_is_newline(pc)
         && !chunk_is_comment(pc)
         && pc->type != CT_SPACE
         && is_past_width(pc))
      {
         if (  pc->type == CT_VBRACE_CLOSE // don't break if a vbrace close
            && chunk_is_last_on_line(*pc)) // is the last chunk on its line
         {
            continue;
         }

         bool split_OK = split_line(pc);
         if (split_OK)
         {
            LOG_FMT(LSPLIT, "%s(%d): on orig_line=%zu, orig_col=%zu, for %s\n",
                    __func__, __LINE__, pc->orig_line, pc->orig_col, pc->text());
         }
         else
         {
            LOG_FMT(LSPLIT, "%s(%d): Bailed on orig_line=%zu, orig_col=%zu, for %s\n",
                    __func__, __LINE__, pc->orig_line, pc->orig_col, pc->text());
            break;
         }
      }
   }
}
Beispiel #22
0
// -----------------------------------------------------------------------------
// CATBase::GetEpocRoot( string& sEpocRoot )
// -----------------------------------------------------------------------------
bool CATBase::GetEpocRoot( string& sEpocRoot )
{
	LOG_FUNC_ENTRY( "CATBase::GetEpocRoot" );
	bool bRet = true;
	//Find EPOCROOT from environment variable
	char* pEpocRoot = getenv ("EPOCROOT");
	if( pEpocRoot == NULL )
	{
		const char pDevicesPath[] = "C:\\Program Files\\Common Files\\Symbian\\devices.xml";
		CATParseXML parser;
		//Find EPOCROOT from devices
		sEpocRoot = parser.GetEpocRootPathFromXML(pDevicesPath);
		if( sEpocRoot.empty() )
		{
			printf("EPOCROOT not set to environment variables.\n");
			bRet = false;
		}
	}
	else
	{
		sEpocRoot.append( pEpocRoot );
		LOG_STRING( "EpocRoot :" << sEpocRoot );
	}
	//Remove trailing slash
	if ( sEpocRoot.size() > 1 && sEpocRoot[ sEpocRoot.length()-1 ] == '\\' )
		sEpocRoot.resize( sEpocRoot.length()-1 );
	return bRet;
}
Beispiel #23
0
static void split_fcn_params_full(chunk_t *start)
{
   LOG_FUNC_ENTRY();
   LOG_FMT(LSPLIT, "%s(%d): %s\n", __func__, __LINE__, start->text());

   // Find the opening function parenthesis
   chunk_t *fpo = start;
   LOG_FMT(LSPLIT, "  %s(%d): Find the opening function parenthesis\n", __func__, __LINE__);
   while ((fpo = chunk_get_prev(fpo)) != nullptr)
   {
      LOG_FMT(LSPLIT, "%s(%d): %s, orig_col is %zu, level is %zu\n",
              __func__, __LINE__, fpo->text(), fpo->orig_col, fpo->level);
      if (fpo->type == CT_FPAREN_OPEN && (fpo->level == start->level - 1))
      {
         break;  // opening parenthesis found. Issue #1020
      }
   }

   // Now break after every comma
   chunk_t *pc = fpo;
   while ((pc = chunk_get_next_ncnl(pc)) != nullptr)
   {
      if (pc->level <= fpo->level)
      {
         break;
      }
      if ((pc->level == (fpo->level + 1)) && pc->type == CT_COMMA)
      {
         split_before_chunk(chunk_get_next(pc));
      }
   }
}
Beispiel #24
0
static bool should_add_braces(chunk_t *vbopen)
{
   LOG_FUNC_ENTRY();
   size_t nl_max = cpd.settings[UO_mod_full_brace_nl].u;
   if (nl_max == 0)
   {
      return(false);
   }

   LOG_FMT(LBRDEL, "%s: start on %zu : ", __func__, vbopen->orig_line);
   chunk_t *pc;
   size_t  nl_count = 0;

   for (pc = chunk_get_next_nc(vbopen, CNAV_PREPROC);
        (pc != NULL) && (pc->level > vbopen->level);
        pc = chunk_get_next_nc(pc, CNAV_PREPROC))
   {
      if (chunk_is_newline(pc))
      {
         nl_count += pc->nl_count;
      }
   }
   if ((pc != NULL) && (nl_count > nl_max) && (vbopen->pp_level == pc->pp_level))
   {
      LOG_FMT(LBRDEL, " exceeded %zu newlines\n", nl_max);
      return(true);
   }
   return(false);
}
Beispiel #25
0
/**
 * Functions prototypes and definitions can only appear in level 0.
 *
 * Function prototypes start with "native", "forward", or are just a function
 * with a trailing semicolon instead of a open brace (or something else)
 *
 * somefunc(params)              <-- def
 * stock somefunc(params)        <-- def
 * somefunc(params);             <-- proto
 * forward somefunc(params)      <-- proto
 * native somefunc[rect](params) <-- proto
 *
 * Functions start with 'stock', 'static', 'public', or '@' (on level 0)
 *
 * Variable definitions start with 'stock', 'static', 'new', or 'public'.
 */
static chunk_t *pawn_process_line(chunk_t *start)
{
   LOG_FUNC_ENTRY();
   chunk_t *pc;
   chunk_t *fcn = NULL;

   //LOG_FMT(LSYS, "%s: %d - %s\n", __func__,
   //        start->orig_line, start->text());

   if ((start->type == CT_NEW) ||
       chunk_is_str(start, "const", 5))
   {
      return(pawn_process_variable(start));
   }

   /* if a open paren is found before an assign, then this is a function */
   if (start->type == CT_WORD)
   {
      fcn = start;
   }
   pc = start;
   while (((pc = chunk_get_next_nc(pc)) != NULL) &&
          !chunk_is_str(pc, "(", 1) &&
          (pc->type != CT_ASSIGN) &&
          (pc->type != CT_NEWLINE))
   {
      if ((pc->level == 0) &&
          ((pc->type == CT_FUNCTION) ||
           (pc->type == CT_WORD) ||
           (pc->type == CT_OPERATOR_VAL)))
      {
         fcn = pc;
      }
   }

   if (pc != NULL)
   {
      if (pc->type == CT_ASSIGN)
      {
         return(pawn_process_variable(pc));
      }
   }

   if (fcn != NULL)
   {
      //LOG_FMT(LSYS, "FUNCTION: %s\n", fcn->text());
      return(pawn_mark_function0(start, fcn));
   }

   if (start->type == CT_ENUM)
   {
      pc = chunk_get_next_type(start, CT_BRACE_CLOSE, start->level);
      return(pc);
   }

   //LOG_FMT(LSYS, "%s: Don't understand line %d, starting with '%s' [%s]\n",
   //        __func__, start->orig_line, start->text(), get_token_name(start->type));
   return(start);
} // pawn_process_line
CATDbgHelper::CATDbgHelper()
{
	LOG_FUNC_ENTRY("CATDbgHelper::CDbgHelper");
	// Set the some "default" base address.
	m_BaseAddress = 0x2;
	m_bMap = false;
	m_pBinaryFile = NULL;
}
Beispiel #27
0
// -----------------------------------------------------------------------------
// CATBase::CreateTempPath
// Creates temporary directory path for given mmp file
// -----------------------------------------------------------------------------
string CATBase::CreateTempPath(const string& sMmpFileWithPath)
{
	LOG_FUNC_ENTRY("CATBase::CreateTempPath");
	string sTempPath = GetPathOrFileName( false, sMmpFileWithPath );
	sTempPath.append( AT_TEMP_DIR );
	sTempPath.append( "\\" );
	return sTempPath;
}
Beispiel #28
0
/*
 * the value of after determines:
 *   true:  insert_vbrace_close_after(pc, frm)
 *   false: insert_vbrace_open_before(pc, frm)
 */
static chunk_t *insert_vbrace(chunk_t *pc, bool after,
                              struct parse_frame *frm)
{
    LOG_FUNC_ENTRY();
    chunk_t chunk;
    chunk_t *rv;
    chunk_t *ref;

    chunk.orig_line   = pc->orig_line;
    chunk.parent_type = frm->pse[frm->pse_tos].type;
    chunk.level       = frm->level;
    chunk.brace_level = frm->brace_level;
    chunk.flags       = pc->flags & PCF_COPY_FLAGS;
    chunk.str         = "";
    if (after)
    {
        chunk.type = CT_VBRACE_CLOSE;
        rv         = chunk_add_after(&chunk, pc);
    }
    else
    {
        ref = chunk_get_prev(pc);
        if ((ref->flags & PCF_IN_PREPROC) == 0)
        {
            chunk.flags &= ~PCF_IN_PREPROC;
        }

        while (chunk_is_newline(ref) || chunk_is_comment(ref))
        {
            ref->level++;
            ref->brace_level++;
            ref = chunk_get_prev(ref);
        }

        /* Don't back into a preprocessor */
        if (((pc->flags & PCF_IN_PREPROC) == 0) &&
                (ref->flags & PCF_IN_PREPROC))
        {
            if (ref->type == CT_PREPROC_BODY)
            {
                do
                {
                    ref = chunk_get_prev(ref);
                } while ((ref != NULL) && (ref->flags & PCF_IN_PREPROC));
            }
            else
            {
                ref = chunk_get_next(ref);
            }
        }

        chunk.orig_line = ref->orig_line;
        chunk.column    = ref->column + ref->len() + 1;
        chunk.type      = CT_VBRACE_OPEN;
        rv              = chunk_add_after(&chunk, ref);
    }
    return(rv);
} // insert_vbrace
Beispiel #29
0
static void remove_semicolon(chunk_t *pc)
{
   LOG_FUNC_ENTRY();
   LOG_FMT(LDELSEMI, "%s: Removed semicolon at line %lu, col %lu",
           __func__, pc->orig_line, pc->orig_col);
   log_func_stack_inline(LDELSEMI);
   /* TODO: do we want to shift stuff back a column? */
   chunk_del(pc);
}
Beispiel #30
0
bool CATBase::IsFileReadOnly( const char* pFilename )
{
	LOG_FUNC_ENTRY("CATBase::IsFileReadOnly");
	DWORD dwRet = GetFileAttributes( pFilename );
	if( dwRet == INVALID_FILE_ATTRIBUTES )
		return false;
	if( dwRet & FILE_ATTRIBUTE_READONLY )
		return true;
	return false;
}