[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] bad or missing line breaks in class library



I think it is a good Idea to do such fixes (also other formatting issues are there). I don't see what your patch will change in some of the cases. As long as it doesn't destroy anything, go ahead, maybe you can post a diff before?


I've seen many files with weird formatting because of line breaks that are either missing or incorrectly coded. So I just wrote a little code snippet to find them. Results are attached.

Specifically I was looking for lines with non-whitespace, followed by anything, followed by tab and close-brace, to match things like this:

Pdfsm : ListPattern {
	var >startState;
	*new { arg list, startState=0, repeats=1;
		^super.new( list, repeats ).startState_(startState)	}

... huh? Where'd the closing brace for *new go? Oh, it's tacked onto the end of the previous line.

But it ended up finding a lot of files where dozens of lines are read in as one line. Why a problem? It makes grep really nasty to use on some parts of the classlib.

If there are no objections, I'll try to figure out a way to fix them automatically. Thought I would ask because some of the most-affected files are in JITLib and crucial.

Thanks.
hjh

?

~top = "./SCClassLibrary/";
~regexp = "[^ \n\r\t].*\t}";
~threaded = true;

(
// depth-first, why not?
~searchDirectory = { |path|
	var	dirs = (path ++ "*/").pathMatch,
		files = (path ++ "*.sc").pathMatch;

	dirs.do({ |dir|
		~searchDirectory.(dir);
	});

	files.do({ |file|
		~searchFile.(file);
if(~threaded and: { thisThread.isKindOf(Routine) }) { 0.01.wait };
	});
};

~searchFile = { |path|
	var	file = File(path, "r"),
		line, lineCount = 0, needToPostPath = true;

	if(file.isOpen) {
		protect {
			while { (line = file.getLine(4096)).notNil } {
if("^//".matchRegexp(line).not and: { ~regexp.matchRegexp(line) }) {
					if(needToPostPath) {
						"\n%:\n".postf(path);
						needToPostPath = false;
					};
					"%: %\n".postf(lineCount, line);
				};
				lineCount = lineCount + 1;
			};

		} {
			file.close
		};
	} {
		"Failed to open %. Continuing.".format(path).warn;
	};
};
)

// test
~searchFile.(SCView.filenameSymbol.asString);

// run for real
{ ~searchDirectory.(~top); }.fork(AppClock);



: H. James Harkins
: jamshark70@xxxxxxxxxxxxxxxxx
: http://www.dewdrop-world.net
.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal."  -- Whitman


I've seen many files with weird formatting because of line breaks that are either missing or incorrectly coded. So I just wrote a little code snippet to find them. Results are attached.

Specifically I was looking for lines with non-whitespace, followed by anything, followed by tab and close-brace, to match things like this:

Pdfsm : ListPattern {
	var >startState;
	*new { arg list, startState=0, repeats=1;
		^super.new( list, repeats ).startState_(startState)	}

... huh? Where'd the closing brace for *new go? Oh, it's tacked onto the end of the previous line.

But it ended up finding a lot of files where dozens of lines are read in as one line. Why a problem? It makes grep really nasty to use on some parts of the classlib.

If there are no objections, I'll try to figure out a way to fix them automatically. Thought I would ask because some of the most-affected files are in JITLib and crucial.

Thanks.
hjh


Attachment converted: data:scan-bad-braces-result.txt (TEXT/ttxt) (00085172)

~top = "./SCClassLibrary/";
~regexp = "[^ \n\r\t].*\t}";
~threaded = true;

(
// depth-first, why not?
~searchDirectory = { |path|
	var	dirs = (path ++ "*/").pathMatch,
		files = (path ++ "*.sc").pathMatch;

	dirs.do({ |dir|
		~searchDirectory.(dir);
	});

	files.do({ |file|
		~searchFile.(file);
if(~threaded and: { thisThread.isKindOf(Routine) }) { 0.01.wait };
	});
};

~searchFile = { |path|
	var	file = File(path, "r"),
		line, lineCount = 0, needToPostPath = true;

	if(file.isOpen) {
		protect {
			while { (line = file.getLine(4096)).notNil } {
if("^//".matchRegexp(line).not and: { ~regexp.matchRegexp(line) }) {
					if(needToPostPath) {
						"\n%:\n".postf(path);
						needToPostPath = false;
					};
					"%: %\n".postf(lineCount, line);
				};
				lineCount = lineCount + 1;
			};

		} {
			file.close
		};
	} {
		"Failed to open %. Continuing.".format(path).warn;
	};
};
)

// test
~searchFile.(SCView.filenameSymbol.asString);

// run for real
{ ~searchDirectory.(~top); }.fork(AppClock);



: H. James Harkins
: <mailto:jamshark70@xxxxxxxxxxxxxxxxx>jamshark70@xxxxxxxxxxxxxxxxx
: <http://www.dewdrop-world.net>http://www.dewdrop-world.net
.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal."  -- Whitman


--





.

_______________________________________________
sc-dev mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-dev/
search: https://listarc.bham.ac.uk/lists/sc-dev/search/