Esempio n. 1
0
bool CFileListView::RemoveFileNode( FileInfo& Item, int nIndex )
{
	if(nIndex < 0 || nIndex >= (int)Item.Chlids.size())
		return false;

	FileInfo& ChildItem = Item.Chlids[nIndex];
	m_FileStack.push_back(&ChildItem);

	for (UInt32 i=0; i<ChildItem.Chlids.size();)
	{
		if(!RemoveFileNode(ChildItem, i))
			++i;
	}

	m_FileStack.pop_back();

	char szPath[MAX_PATH] = {0};
	if(GetCurrentFileName(nIndex, szPath, MAX_PATH))
	{
		if(ChildItem.nFileSize > 0)
			archive_remove_file(m_pArchive, szPath);
		Item.Chlids.erase(Item.Chlids.begin() + nIndex);

		return true;
	};

	return false;
}
Esempio n. 2
0
File *Parser::GetIncludedFile(sym_t preprocessor, const char *line, FILE **outf, bool& in_compiler_dir)
{
	bool quoted = true;
	CC_STRING ifpath, itoken, iline;
	File *retval = NULL;

	iline = ExpandLine(intab, true, line, errmsg);
	if(!errmsg.isnull())
		goto done;

	itoken = GetIncludeFileName(iline, quoted);
	iline.clear();
	if( itoken.isnull() ) {
		errmsg.Format("Invalid include preprocessor: %s", pline.from.c_str());
		goto done;
	}

	if(!rtc->get_include_file_path(itoken, GetCurrentFileName(), quoted, preprocessor == SSID_SHARP_INCLUDE_NEXT, ifpath, &in_compiler_dir)) {
		errmsg.Format("Cannot find include file \"%s\"", itoken.c_str());
		goto done;
	}

	RealFile *file;
	pline.to = pline.from;
	file = new RealFile;
	file->SetFileName(ifpath);
	retval = file;
	*outf = NULL;

	if(has_dep_file() && ! in_compiler_dir)
		AddDependency("  ", ifpath.c_str());
done:
	return retval;
}
Esempio n. 3
0
void CFileListView::ExtractSelect()
{
	UInt32 nIndex;
	FileInfo *info = NULL;
	char szPath[MAX_PATH];

	if(m_pArchive == NULL)
		return;

	nIndex = GetCurrentSelected();
	if(nIndex < m_FileStack.back()->Chlids.size())
		info = &(m_FileStack.back()->Chlids[nIndex]);

	if(info != NULL)
	{
		if(info->nFileSize > 0)
		{
			GetCurrentFileName(nIndex, szPath, MAX_PATH);
			ExtractFile(szPath);
		}
		else
		{
			BROWSEINFO bi; 
			bi.hwndOwner      = m_hWnd;
			bi.pidlRoot       = NULL;
			bi.pszDisplayName = NULL; 
			bi.lpszTitle      = TEXT("请选择文件夹"); 
			bi.ulFlags        = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
			bi.lpfn           = NULL; 
			bi.lParam         = 0;
			bi.iImage         = 0; 

			LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
			if (pidl == NULL)
				return;

			if (SHGetPathFromIDList(pidl, szPath))
				ExtractFolder(info, NULL, szPath);
		}
	}
}
Esempio n. 4
0
bool Parser::SM_Run()
{
	FILE *out_fp = included_files.top()->ofile;
	const char *pos;
	TRI_STATE result = TSV_0;
	const char *output = pline.from.c_str();
	sym_t preprocessor;
	CC_STRING expanded_line;

	do {
		pos = pline.parsed.c_str();
		preprocessor = GetPreprocessor(pos, &pos);
		if(preprocessor != pline.pp_id || (pline.content != -1 && pline.content + pline.parsed.c_str() != pos) ) {
			fprintf(stderr, "%s:%zu\n", dv_current_file, dv_current_line);
			fprintf(stderr, "  (%d) %s\n", pline.content, pline.parsed.c_str());
			fprintf(stderr, "  %d vs %d\n", preprocessor, pline.pp_id);
			exit(1);
		}
	} while(0);

	pos = pline.parsed.c_str() + pline.content;

	dv_current_file = GetCurrentFileName().c_str();
	dv_current_line = GetCurrentLineNumber();

//	GDB_TRAP2(strstr(dv_current_file,"makeint.h"), (dv_current_line==30));
//	GDB_TRAP2(strstr(dv_current_file,"/usr/include/features.h"), dv_current_line==131);
	switch(pline.pp_id) {
	case SSID_SHARP_IF:
		if( superior_conditional_value(true) != TSV_0 )
			result = (TRI_STATE) Compute(pos);
		goto handle_if_branch;

	case SSID_SHARP_IFNDEF:
		if( superior_conditional_value(true) != TSV_0 )
			result = (TRI_STATE) CheckSymbolDefined(pos, true, NULL);
		goto handle_if_branch;

	case SSID_SHARP_IFDEF:
		if( superior_conditional_value(true) != TSV_0 )
			result = (TRI_STATE) CheckSymbolDefined(pos, false, NULL);

handle_if_branch:
		if( result == TSV_X ) {
			if( gvar_preprocess_mode ) {
				if(errmsg.isnull())
					errmsg = "Error on processing conditional";
				goto done;
			}
		}

		conditionals.push(new CConditionalChain());

		upper_chain()->enter_if(result);
		upper_chain()->filename = dv_current_file;
		upper_chain()->line = dv_current_line;
		if(eval_current_conditional() != TSV_X)
			output = NULL;
		included_files.top()->add_if(result);
		break;

	case SSID_SHARP_ELIF:
		if( superior_conditional_value(false) == TSV_0 ) {
			included_files.top()->add_elif(false);
			goto done;
		}
		if( upper_chain()->has_true() ) {
			upper_chain()->enter_elif(TSV_0);
			included_files.top()->add_elif(false);
			goto done;
		}
		result = (TRI_STATE) Compute(pos);
		if( gvar_preprocess_mode && result == TSV_X)
			goto done;

		/*
		 *  Transformation on the condition of:
		 *
		 *  1) #if   0
		 *     #elif X --> #if   X
		 *
		 *  2) #elif X
		 *     #elif 1 --> #else
		 */
		if( eval_current_conditional() == TSV_0 ) {
			if(result == TSV_X) {
				pline.to = do_elif(1);
				output = pline.to.c_str();
			} else
				output = NULL;
		} else {
			if(result == TSV_1) {
				pline.to = do_elif(2);
				output = pline.to.c_str();
			} else if(result == TSV_0)
				output = NULL;
		}
		upper_chain()->enter_elif(result);
		included_files.top()->add_elif(result);
		break;

	case SSID_SHARP_ELSE:
		if( superior_conditional_value(false) == TSV_0 ) {
			included_files.top()->add_else(false);
			goto done;
		}
		result = upper_chain()->enter_else();
		included_files.top()->add_else(result);
		if( eval_current_conditional() != TSV_X )
			output = NULL;
		break;

	case SSID_SHARP_ENDIF:
		included_files.top()->add_endif();
		CConditionalChain *c;
		if( ! upper_chain()->keep_endif() )
			output = NULL;
		if( conditionals.size() == 0 ) {
			errmsg = "Unmatched #endif";
			goto done;
		}
		conditionals.pop(c);
		delete c;
		break;

	default:
		if(eval_current_conditional() == TSV_0)
			goto done;
		if(eval_current_conditional() == TSV_X)
			goto print_and_exit;

		switch(pline.pp_id) {
		  case SSID_SHARP_DEFINE:
			if(!do_define(pos))
				goto error_out;
			break;
		  case SSID_SHARP_UNDEF:
			handle_undef(intab, pos);
			break;
		  case SSID_SHARP_INCLUDE:
		  case SSID_SHARP_INCLUDE_NEXT:
			if( gvar_preprocess_mode )
				do_include(pline.pp_id, pos, &output);
			break;
		  default:
			if(gvar_expand_macros) {
				pos = pline.parsed.c_str();
				expanded_line = ExpandLine(intab, false, pos, errmsg);
				if(!errmsg.isnull())
					goto error_out;
				if(included_files.size() == 1) {
					expanded_line += '\n';
					output = expanded_line.c_str();
				}
			}
		}
	}

print_and_exit:
	if( out_fp != NULL && output != NULL )
		fprintf(out_fp, "%s", output);
done:
	pline.comment_start = -1;
	if(gvar_preprocess_mode && GetError()) {
		IncludedFile *tmp;
		CC_STRING pmsg, ts;
		while(included_files.size() > 0) {
			included_files.pop(tmp);
			ts.Format("  %s:%u\n", tmp->ifile->name.c_str(), tmp->ifile->line);
			pmsg += ts;
		}
		if( !pmsg.isnull() ) {
			errmsg = pmsg + errmsg;
		}
	}
	return gvar_preprocess_mode ? (GetError() == NULL) : true;

error_out:
	return false;
}
Esempio n. 5
0
/*  Parse the input file and update the global symbol table and macro table,
 *  output the stripped file contents to devices if OUTFILE is not nil.
 *
 *  Returns a pointer to the error messages on failure, or nil on success.
 */
bool Parser::DoFile(InternalTables *intab, size_t num_preprocessors, File *infile, ParserContext *ctx)
{
	bool ignored;
	FILE *out_fp;
	bool retval = false;
	CC_STRING bak_fname, out_fname;
	struct stat    stb;
	struct utimbuf utb;

	if(ctx) {
		ignored = ctx->check_ignore(infile->name);
		if( ignored && ! has_dep_file() )
			return true;
	} else
		ignored = false;

	if( stat(infile->name, &stb) == 0 ) {
		utb.actime  = stb.st_atime;
		utb.modtime = stb.st_mtime;
	}
	if( ! infile->Open() ) {
		errmsg.Format("Cannot open \"%s\" for reading\n");
		return false;
	}

	out_fp = NULL;

	if(ctx != NULL && ctx->outfile != ParserContext::OF_NULL ) {
		if( ctx->outfile == ParserContext::OF_STDOUT )
			out_fp = stdout;
		else {
#if SANITY_CHECK
			assert( ! ctx->baksuffix.isnull() );
#endif
			if( ctx->baksuffix[0] != ParserContext::MAGIC_CHAR )
				bak_fname = infile->name + ctx->baksuffix;
			else
				out_fname = infile->name;

			int fd;
			char tmp_outfile[32];
			strcpy(tmp_outfile, "@cl@-XXXXXX");
			fd = mkstemp(tmp_outfile);
			if( fd < 0 ) {
				errmsg.Format("Cannot open \"%s\" for writing\n", tmp_outfile);
				infile->Close();
				return false;
			}
			out_fp = fdopen(fd, "wb");
			out_fname = tmp_outfile;
		}
	}

	if(ctx == NULL)
		memset(writers, 0, sizeof(writers));
	else {
		writers[VCH_CL] = NULL;
		if(!ctx->of_array[VCH_DEP].isnull())
			writers[VCH_DEP] = gvar_file_writers[VCH_DEP];
		if(!ctx->of_array[VCH_CV].isnull())
			writers[VCH_CV] = gvar_file_writers[VCH_CV];
	}

	if( num_preprocessors >= COUNT_OF(Parser::preprocessors) )
		num_preprocessors  = COUNT_OF(Parser::preprocessors);
	Reset(intab, num_preprocessors, ctx);

	if(has_dep_file())
		AddDependency("", infile->name);

	PushIncludedFile(infile, out_fp, COUNT_OF(Parser::preprocessors), false, conditionals.size());

	if(ctx != NULL) {
		GetCmdLineIncludeFiles(ctx->imacro_files, 2);
		GetCmdLineIncludeFiles(ctx->include_files, COUNT_OF(preprocessors));
	}

	if( ! RunEngine(0) )
		goto error;

	SaveDepInfo(deptext);
	if( conditionals.size() != 0 )
		errmsg = "Unmatched #if";
	else
		retval = true;

error:
	if(!retval) {
		if(included_files.size() > 0) {
			CC_STRING tmp;
			tmp.Format("%s:%u:  %s\n%s\n", GetCurrentFileName().c_str(), GetCurrentLineNumber(), pline.from.c_str(), GetError());
			errmsg = tmp;
		}
		#if 0
		IncludedFile *ilevel;
		while(included_files.size() > 0) {
			ilevel = PopIncludedFile();
			if(infile != ilevel->ifile)
				delete ilevel;
		}
		#endif
	}

	if(out_fp != NULL && out_fp != stdout)
		fclose(out_fp);

	if( retval && ctx != NULL && ! ignored ) {
		CC_STRING semname;
		sem_t *sem;

		semname = MakeSemaName(infile->name);
		sem = sem_open(semname.c_str(), O_CREAT, 0666, 1);
		sem_wait(sem);

		if( ! bak_fname.isnull() )
			rename(infile->name, bak_fname);
		if( ! out_fname.isnull() ) {
			rename(out_fname, infile->name);
			utime(infile->name.c_str(), &utb);
		}

		sem_post(sem);
		sem_unlink(semname.c_str());
	} else if( ! out_fname.isnull() )
		unlink(out_fname.c_str());

	return retval;
}
Esempio n. 6
0
void ProcessEnum( void )
{
	PTEXT pLine = GetCurrentWord();
   char *text;
	// look for enum keyword....
	while( pLine )
	{
      text = GetText( pLine );
		if( TextIs( pLine, WIDE("enum") ) )
		{
			if( g.current_enum )
			{
				fprintf( stderr, WIDE("%s(%d): Syntax error enumeration within enum?\n")
                    , GetCurrentFileName(), GetCurrentLine() );
			}
			g.current_enum = Allocate( sizeof( ENUM_TABLE ) );
			g.current_enum->entries = NULL;
			g.current_enum->name = NULL;
			if( g.current_entry )
			{
				fprintf( stderr, WIDE("Coding error - uncommited enumeration value. Lost memory.\n") );
            g.current_entry = NULL;
			}
         g.flags.get_identifier = 1;
		}
		else
		{
			if( g.flags.get_identifier )
			{
				if( text[0] != '{' )
				{
					if( g.current_enum->name )
					{
						fprintf( stderr, WIDE("%s(%d): Error multiple identifers for enum\n")
								 , GetCurrentFileName(), GetCurrentLine() );
					}
					else
                  g.current_enum->name = SegDuplicate( pLine );
				}
				else
				{
					// well whether or not there was an identifier (name)
               // we're done getting it....
					g.flags.get_identifier = 0;
				}
			}
			else // collecting enumeration values...
			{
				if( text[0] == '}' )
				{
				}
				else if( text[0] == ',' )
				{
				}
				else if( text[0] == '=' )
				{
				}
            else if( g.current_entry )
				{
					if( text[0] == ',' )
					{
						if( !g.flags.current_value_set )
						{
                     if( g.current_enum->last_entry )
								g.current_entry->value = g.current_enum->last_entry->value + 1;
							else
								g.current_entry->value = 0;
						}
						if( g.current_enum->last_entry )
							g.current_enum->last_entry->next = g.current_entry;
						else
                     g.current_enum->entries = g.current_entry;
						g.current_enum->last_entry = g.current_entry;
                  g.current_entry = NULL;
					}
					else
					{
					}
				}
				else
				{
					if( text[0] == ',' )
					{
                  fprintf( stderr, WIDE("Error - unexpected comma sepeartor enumeration.\n") );
					}
					if( text[0] == '=' )
					{
                  fprintf( stderr, WIDE("Error - unexpected comma sepeartor enumeration.\n") );
					}
					g.current_entry = Allocate( sizeof( ENUM_ENTRY ) );
               g.flags.current_value_set = 0;
					g.current_entry->next = NULL;
					g.current_entry->name = SegDuplicate( pLine );
				}
			}
		}
      pLine = NEXTLINE( pLine );
	}
}