Changeset - r23190:13eb619c6d49
[Not reviewed]
master
0 1 0
glx - 6 years ago 2019-01-08 02:36:47
glx@openttd.org
Fix: keep the line ending when generating widget enums with bash/gawk on windows
1 file changed with 10 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/script/api/generate_widget.awk
Show inline comments
 
@@ -21,12 +21,14 @@
 
#
 

	
 
BEGIN {
 
	skiptillend = 0;
 
}
 

	
 
{ CR = (match($0, "\\r$") > 0 ? "\r" : "") }
 

	
 
/@enum/ {
 
	print;
 
	add_indent = gensub("[^	]*", "", "g");
 
	sub(".*@enum *", "");
 
	enum = $1;
 
	pattern = $2;
 
@@ -39,13 +41,13 @@ BEGIN {
 
	count = asort(filearray);
 
	for (i = 1; i <= count; i++) {
 
		active = 0;
 
		active_comment = 0;
 
		comment = "";
 
		file = filearray[i];
 
		print add_indent "/* automatically generated from " file " */"
 
		print add_indent "/* automatically generated from " file " */" CR
 
		while ((getline < file) > 0) {
 
			sub(rm_indent, "");
 

	
 
			# Remember possible doxygen comment before enum declaration
 
			if ((active == 0) && (match($0, "/\\*\\*") > 0)) {
 
				comment = add_indent $0;
 
@@ -62,41 +64,40 @@ BEGIN {
 
				if (active_comment > 0) print comment;
 
				active_comment = 0;
 
				comment = "";
 
			}
 

	
 
			# Forget doxygen comment, if no enum follows
 
			if (active_comment == 2 && $0 != "") {
 
			if (active_comment == 2 && $0 != "" CR) {
 
				active_comment = 0;
 
				comment = "";
 
			}
 
			if (active_comment == 1 && match($0, "\\*/") > 0) active_comment = 2;
 

	
 
			if (active != 0) {
 
				if (match($0, "^	*[A-Za-z0-9_]* *[,=]") > 0) {
 
					# Transform enum values
 
					sub(" *=[^,]*", "");
 
					sub(" *//", " //");
 

	
 
					match($0, "^(	*)([A-Za-z0-9_]+),(.*)", parts);
 
					enumwidth - length(parts[2])
 

	
 
					if (parts[3] == "") {
 
						printf "%s%s%-45s= ::%s\n", add_indent, parts[1], parts[2], (parts[2] ",")
 
					if (parts[3] == "" CR) {
 
						printf "%s%s%-45s= ::%s\n", add_indent, parts[1], parts[2], (parts[2] "," CR)
 
					} else {
 
						printf "%s%s%-45s= ::%-45s%s\n", add_indent, parts[1], parts[2], (parts[2] ","), parts[3];
 
						printf "%s%s%-45s= ::%-45s%s\n", add_indent, parts[1], parts[2], (parts[2] ","), (parts[3]);
 
					}
 
				} else if ($0 == "") {
 
					print "";
 
				} else if ($0 == "" CR) {
 
					print "" CR;
 
				} else {
 
					print add_indent $0;
 
				}
 
			}
 

	
 
			if (match($0, "^	*\\};") > 0) {
 
				if (active != 0) print "";
 
				if (active != 0) print "" CR;
 
				active = 0;
 
			}
 
		}
 
		close(file);
 
	}
 

	
0 comments (0 inline, 0 general)