⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 这个C++程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			}		}		// Add line of code as normal, it must be short (could be the last part from above)		cppOut << currentCode << "\n";		// If indext flag is set, add a brace and indent		if ( indentNext != 0 ) {			cppOut << indentation( indent ) + "{" << "\n";			indent++;		}	}//end-of-for-loop	if ( insideComment ) {				cppOut << "*/" << "\n";	}		outFile.close();	return true;}QString swapConditionals(QString code){	QString myCode = code;	for ( int ii = 0; ii < _CondLength; ii++ ) {			myCode = myCode.replace( FortranCond[ii], CppCond[ii], FALSE );	}	return myCode;}QString swapVariables(QString code, int replace){	QString myCode = code;	for ( int ii = 0; ii < _ReservedLength; ii++ ) {			if ( replace )			myCode.replace( FortranReserved[ii], CppReserved[ii], FALSE );		else			myCode.replace( FortranReserved[ii], "", FALSE );	}	return myCode;}void swapKeywords(QString &code){	//for ( int ii = 0; ii < _CppKeywordLength; ii++ ) {	//	//	if ( code.contains( CppKeywords[ii] ) )	//		code.replace( CppKeywords[ii], CppKeywords[ii].upper() );	//}	// version 1.1 fix - doesn't work all that well, may bypass this function in the future	for ( int ii = 0; ii < _CppKeywordLength; ii++ ) {			if ( code.contains( " " + CppKeywords[ii] + " " ) )			code.replace( CppKeywords[ii], CppKeywords[ii].upper() );	}}FortranType determineFortranType( QString fullLine, QString &code, QString &label, bool &isCont ){	isCont			= false;	code			= "";	label			= "";	QString line	= fullLine;	// Convert tabs into spaces first	line.replace( "\t", "      " );	int length		= line.length();	if ( length == 0 ) {		return eBlank;	}	// Is it a comment?	if ( line[0] == 'c' || line[0] == 'C' || line[0] == '*' ) {				if ( length > 2 )			code = line.right( length - 2 );		return eComment;	}	// Does this have the special # character	if ( line[0] == '#' ) {			code = line;		if ( line.find( "include", 0, FALSE ) == 1 )			return eInclude;		else if ( line.find( "define", 0, FALSE ) == 1 )			return eDefine;		else if ( line.find( "ifdef", 0, FALSE ) == 1 )			return eIfDef;		else if ( line.find( "endif", 0, FALSE ) == 1 )			return eEndDef;		else			return eUnknown;	}	QString reserved, cont;		// Pull the six reserved characters off and get continuation character and the code	reserved	= line.left( 6 );	cont		= line.mid( 5, 1 );	code		= line.right( length-6 ).stripWhiteSpace();	// Is this a continuation line, process it as one	if ( ( cont != "0" && cont != " " ) || reserved[0] == '&' ) {		isCont = true;		if ( reserved[0] == '&' ) {			reserved = "";			label = "";			return eCode;		}				if ( cont != "0" ) {			reserved = reserved.left( 5 );		}	}	// Get label if any	label = reserved.stripWhiteSpace();	if ( isCont )		return eCode;	if ( code.find( "program", 0, FALSE ) == 0 ) {		return eBeginProgram;	} else if ( code.find( "subroutine", 0, FALSE ) == 0 ) {		return eSubroutine;	} else if ( code.find( "parameter", 0, FALSE ) == 0 ) {		return eParameter;	} else if ( code.find( "write", 0, FALSE ) == 0 ) {		return eWrite;	} else if ( code.find( "read", 0, FALSE ) == 0 ) {		return eRead;	} else if ( code.find( "open", 0, FALSE ) == 0 ) {		return eOpen;	} else if ( code.find( "close", 0, FALSE ) == 0 ) {		return eClose;	} else if ( code.find( "data", 0, FALSE ) == 0 ) {		return eData;	} else if ( code.find( "print", 0, FALSE ) == 0 ) {		return ePrint;	} else if ( code.find( "format", 0, FALSE ) == 0 ) {		return eFormat;	} else if ( code.find( "equivalence", 0, FALSE ) == 0 ) {		return eEquivalence;	} else if ( code.find( "implicit", 0, FALSE ) == 0 ) {		return eImplicit;	} else if ( code.find( "intrinsic", 0, FALSE ) == 0 ) {		return eIntrinsic;	} else if ( code.find( "pointer", 0, FALSE ) == 0 ) {		return ePointer;	} else if ( code.find( "structure", 0, FALSE ) == 0 ) {		return eStructure;	} else if ( code.find( "endstructure", 0, FALSE ) == 0 ) {		return eEndStructure;	} else if ( code.find( "union", 0, FALSE ) == 0 ) {		return eUnion;	} else if ( code.find( "endunion", 0, FALSE ) == 0 ) {		return eEndUnion;	} else if ( code.find( "block", 0, FALSE ) == 0 ) {		return eBlock;// version 1.1 addition	} else if ( code.find( "common", 0, FALSE ) == 0 ) {		return eCommon;// version 1.1 addition	} else if ( code.find( "external", 0, FALSE ) == 0 ) {		return eExternal;// version 1.1 addition	} else if ( code.find( "if", 0, FALSE ) == 0 ) {		return eIf;	} else if ( code.find( "elseif", 0, FALSE ) == 0 ) {		return eElseIf;	} else if ( code.find( "else", 0, FALSE ) == 0 ) {		return eElse;	} else if ( code.find( "endif", 0, FALSE ) == 0 ) {		return eEndIf;	} else if ( code.find( "end if", 0, FALSE ) == 0 ) {		return eEndIf;// version 1.1 addition	} else if ( code.find( "do while", 0, FALSE ) == 0 ) {		return eDoWhile;	} else if ( code.find( "do", 0, FALSE ) == 0 ) {		return eDo;	} else if ( code.find( "enddo", 0, FALSE ) == 0 ) {		return eEndDo;	} else if ( code.find( "end do", 0, FALSE ) == 0 ) {		return eEndDo;// version 1.1 addition	} else if ( code.find( "continue", 0, FALSE ) == 0 ) {		return eContinue;	} else if ( code.find( "return", 0, FALSE ) == 0 ) {		return eReturn;	} else if ( code.find( "call", 0, FALSE ) == 0 ) {		return eCall;	} else if ( code.find( "goto", 0, FALSE ) == 0 ) {		return eGoto;	} else if ( code.find( "go to", 0, FALSE ) == 0 ) {//optional go to		return eGoto;	} else if ( code.find( "parameter", 0, FALSE ) == 0 ) {		return eParameter;	} else if ( code.find( "end", 0, FALSE ) == 0 ) {//must put this below endif		return eEndProgram;	} else if ( code.isEmpty() && !label.isEmpty() ) {		return eLabel;	} else if ( code.isEmpty() ) {		return eBlank;	}	// Is this a Fortran variable?	for ( int ii = 0; ii < _ReservedLength; ii++ ) {			if ( code.find( FortranReserved[ii], 0, FALSE ) == 0 )			return eVariable;	}	// Must be code at this point	return eCode;}QString indentation(int indent){	QString indentString = "";	for ( int ii = 1; ii <= indent*_IndentLength; ii++ )		indentString += INDENTCHAR;	return indentString;}QString processDo(QString doLoop){	//example string: do 20 i = 1,10 can become Cpp => for ( i = 0; i < 10; i++ )	doLoop.replace( "do", "", FALSE );	QStringList parts = QStringList::split( "=", doLoop, FALSE );	if ( parts.size() != 2 && parts[1].find( "," ) > 0 )		return "for ( )";	QString variable = parts[0].stripWhiteSpace().simplifyWhiteSpace();	int space = variable.find( " " );	variable = variable.right( variable.length() - space - 1 );	QString indexStart, indexEnd;	parts = QStringList::split( ",", parts[1], FALSE );	indexStart = parts[0].stripWhiteSpace();	indexEnd   = parts[1].stripWhiteSpace();	QString forStatement;	if ( _AutoDecIndex ) {		int start = indexStart.toInt();		forStatement.sprintf( "for ( %s = %d%s %s < %s%s %s++ )", 			variable.ascii(),			start - 1,			ENDCHAR.ascii(),			variable.ascii(),			indexEnd.ascii(),			ENDCHAR.ascii(),			variable.ascii() );	} else {		forStatement.sprintf( "for ( %s = %s%s %s <= %s%s %s++ )", 			variable.ascii(),			indexStart.ascii(),			ENDCHAR.ascii(),			variable.ascii(),			indexEnd.ascii(),			ENDCHAR.ascii(),			variable.ascii() );	}	return forStatement;}QString breakApart(QString code, QString &remain){	QString myCode = code;	remain = "";	int loc;	loc = location( ')', myCode );	if ( loc == -1 || loc > _MaxLineLength ) {			loc = location( ',', myCode );		if ( loc == -1 || loc > _MaxLineLength ) {					loc = location( ' ', myCode );			if ( loc == -1 || loc > _MaxLineLength ) {				loc = _MaxLineLength - 5;//force a cut off			}		}	}	remain = myCode.right( myCode.length() - loc - 1 ).stripWhiteSpace();	QString s = myCode.left( loc + 1 );	return s;}int location(QChar myChar, QString codeSection){	int length = codeSection.length();	int ii = _MaxLineLength - 15;	if ( ii < 0 )		ii = 0;	for ( ; ii < length; ii++ ) {			if ( myChar == codeSection[ii] )			return ii;	}	return -1;}QString cleanCode(QString cleanData){	QString newData = "";	for ( uint ii = 0; ii < cleanData.length(); ii ++ ) {		QChar left  = 'X';		QChar pos   = cleanData.ascii()[ii];		QChar right = 'X';		if ( ii > 0 )			left    = cleanData.ascii()[ii-1];		if ( ii < cleanData.length() )			right   = cleanData.ascii()[ii+1];		if ( pos == '(' ) {			if ( right != ' ' )				newData += QString(pos) + " ";			else				newData += pos;		} else if ( pos == ')' ) {			if ( left != ' ' )				newData += " " + QString(pos);			else				newData += pos;		} else if ( pos == ',' ) {			if ( right != ' ' )				newData += QString(pos) + " ";			else				newData += pos;		} else {			newData += pos;		}	}	newData.replace( "(  )", "()" );	return newData;}bool loadInfoFile(const QString &fileName){	bool fileOk = false;	if ( QFile::exists( fileName ) ) {		QFile file( fileName );		if ( file.open(IO_ReadOnly) ) {			QTextStream in(&file);			while ( !in.atEnd() ) {				QString line = in.readLine();				line = line.stripWhiteSpace();				if ( line.length() > 1 && line[0] != '#' ) {					// Break string from equals					QStringList parts = QStringList::split( "=", line, FALSE ) ;					if ( parts.size() == 2 ) {						QString infoName = parts[0].stripWhiteSpace() ;						QString infoData = parts[1].stripWhiteSpace() ;						// Version						if ( infoName == "Version" ) { // do nothing for now						}						else if ( infoName == "EndOfStatement" ) {							ENDCHAR = processString( infoData );						} else if ( infoName == "GotoLabel" ) {							LABEL = processString( infoData );						} else if ( infoName == "IndentString" ) {							INDENTCHAR = processString( infoData );						} else if ( infoName == "IndentLength" ) {							_IndentLength = infoData.toInt();						} else if ( infoName == "AutoDecIndex" ) {							_AutoDecIndex = infoData.toInt();						} else if ( infoName == "MaxLineLength" ) {							_MaxLineLength = infoData.toInt();						} else if ( infoName == "FileHeader" ) {														line = "";							while ( line != infoData && !in.atEnd() ) {								line = in.readLine();								if ( line.length() > 1 && line[0] == '#' )									continue;								fileHeader << line;							}						} else if ( infoName == "ProgramHeader" ) {														line = "";							while ( line != infoData && !in.atEnd() ) {								line = in.readLine();								if ( line.length() > 1 && line[0] == '#' )									continue;								programHeader << line;							}						} else {							qDebug( "Ignoring info file command " + infoName +" = " + infoData );						}					}				}			}			file.close();			fileOk = true;		}	}	return fileOk;}QString processString(QString& data){	return data.mid( 1, data.length() - 2 );}QString makeIntoCppFile(QString fileName){	QFileInfo fi( fileName );	return fi.dirPath() + "/" + fi.baseName( TRUE ) + ".cpp";}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -