Ejemplo n.º 1
0
Archivo: include.c Proyecto: pdo/aldor
/*
 * Write included lines in a form suitable for re-inclusion.
 * The number of characters written is returned.
 */
int
inclWrite(FILE *file, SrcLineList sll)
{
	int      cc = 0;
	FileName slfile, curfile  = 0; /* Guarantee first line is #line ... */
	Length   slline, curline = 0;

	for ( ; sll; sll = cdr(sll)) {
		SrcLine sl = car(sll);

		if (sl->isSysCmd && sl->sysCmdHandled) continue;

		slfile = sposFile(sl->spos);
		slline = sposLine(sl->spos);
		if (curline != slline - 1 
		||  (curfile && !fnameEqual(curfile,slfile))) 
		{
			if ((curfile && fnameEqual(curfile, slfile)))
				cc += fprintf(file, "%cline %d\n",
					      DIRECTIVE_CHAR,
					      (int) slline);
			else {
				cc += fprintf(file, "%cline %d \"%s\"\n",
					      DIRECTIVE_CHAR,
					      (int) slline,
					      fnameUnparseStatic(slfile));
				curfile = slfile;
			}
		}
		curline = slline;
			
		cc += fprintf(file, "%*s%s", sl->indentation, "", sl->text);
	}
	return cc;
}
Ejemplo n.º 2
0
Archivo: include.c Proyecto: pdo/aldor
/*
 * Return a processed source line list for the next line of the file.
 * The source line list may have several entries if the line is an
 * includer directive or requires a continuation.
 */
SrcLineList
includeLine(FileName fn, FILE *fin, int *plineno, InclIsContinuedFun iscont)
{
	SrcLineList   r;

	inclBuffer          = bufNew();
	localAssertList     = globalAssertList;

	fileState.curDir    = osCurDirName();
	fileState.curFile   = strCopy(fnameUnparseStatic(fn));
	fileState.curFname  = fn;
	fileState.infile    = fin;
	fileState.fileCodes = 0;
	fileState.fileNames = 0;
	fileState.lineNumber= *plineno;

	ifState = NoIf;

	r = 0;
	inclLine(&r, iscont);
	r = listNReverse(SrcLine)(r);

	/* Leave the assert list and included files for the next call. */
	globalAssertList = localAssertList;

	bufFree(inclBuffer);
	/* strFree(fileState.curFile);	!!This is held on to by the srclines.*/
	listFree(Hash)  (fileState.fileCodes);
	listFree(String)(fileState.fileNames);

	*plineno       = fileState.lineNumber;
	inclFileLineNo = fileState.lineNumber;

	return r;
}
Ejemplo n.º 3
0
Archivo: include.c Proyecto: pdo/aldor
/* 
 * Return a processed source line list of the file contents.
 */
SrcLineList
includeFile(FileName fname)
{
	String	      fnameString;
	SrcLineList   r;

	inclSerialLineNo    = 0;
	fnameString         = strCopy(fnameUnparseStatic(fname));
	inclBuffer          = bufNew();
	includedFileCodes   = 0;
	localAssertList     = listCopy(String)(globalAssertList);

	fileState.curDir    = osCurDirName();
	fileState.fileCodes = 0;
	fileState.fileNames = 0;

	r = listNReverse(SrcLine)(
		inclFile(fnameString, false, true, &inclFileLineNo));

	strFree(fnameString);
	bufFree(inclBuffer);
	listFree(String)(localAssertList);
	listFree(Hash)(includedFileCodes);

	return r;
}
Ejemplo n.º 4
0
FILE   *
compFileError(FileName fn, IOMode mode)
{
	String	name = fnameUnparseStatic(fn);
	if (comsgOkBreakLoop())
		bloopMsgFPrintf(osStdout, ALDOR_F_CantOpenMode, name, mode);
	comsgFatal(NULL, ALDOR_F_CantOpenMode, name, mode);
	NotReached(return 0);
}
Ejemplo n.º 5
0
Archive
arRead(FileName fname)
{
	Archive		ar = arNew(fname, fileRbOpen(fname));

	arDEBUG(dbOut, "Opening archive \"%s\" for reading.\n",
		fnameUnparseStatic(fname));
	arRdFormat(ar);
	arRdTable(ar);

	return ar;
}
Ejemplo n.º 6
0
Archivo: include.c Proyecto: pdo/aldor
local SrcLineList
inclFile(String fname, Bool reincluding, Bool top, long *pnlines)
{
	Scope("inclFile");

	SrcLineList     sll;
	Hash            fhash;
	FileName        fn;
	FileState	o_fileState; 
	IfState		fluid(ifState);
	String		curdir;

	o_fileState 	     = fileState;     /* no fluid(struct) */
	ifState              = NoIf;
	fileState.lineNumber = 0;

	fn = inclFind(fname, fileState.curDir);

	if (fn != 0) {
		fileState.curDir   = strCopy(fnameDir(fn));
		fileState.curFile  = strCopy(fnameUnparseStatic(fn));
		fileState.curFname = fn;
	}
	curdir = fileState.curDir;

	if (fn == 0) {
		fileState = o_fileState;
		if (top) {
			comsgFatal(NULL, ALDOR_F_CantOpen, fname);
			NotReached(sll = 0);
		}
		else
			sll = inclError(ALDOR_F_CantOpen, fname);
	} 
	else {
		fhash = fileHash(fn);
		fname = strCopy (fnameUnparseStatic(fn));

		if (!reincluding && listMemq(Hash)(includedFileCodes, fhash)) {
			sll = listNil(SrcLine);
		}
		else if (listMemq(Hash)(fileState.fileCodes, fhash)) {
			String s = inclActiveFileChain
				(fileState.fileNames, "->");
			fileState = o_fileState;
			sll = inclError(ALDOR_E_InclInfinite, s);
			strFree(s);
		}
		else {
			includedFileCodes   =
			   listCons(Hash)  (fhash,includedFileCodes);
			fileState.fileCodes =
			   listCons(Hash)  (fhash,fileState.fileCodes);
			fileState.fileNames =
			   listCons(String)(fname,fileState.fileNames);
			fileState.infile    = fileRdOpen(fn);

			sll = inclFileContents();

			listFreeCons(Hash)  (fileState.fileCodes);
			listFreeCons(String)(fileState.fileNames);
			fclose(fileState.infile);
		}
		fnameFree(fn);
		strFree(curdir);
				 /*!! curFile is used in src lines */
		strFree(fname);
	}
	if (pnlines) *pnlines = fileState.lineNumber;
	fileState = o_fileState;
	Return(sll);
}