function processFile()

in flow/src/doc/jsdoc.js [72:204]


function processFile(f, fname, inputdir, out) {
	var s;
	var firstLine = true;
	indexFileArray[fname] = "";

    // write the header of the output file
	out.append('<jsdoc><fileName>' + fname + '</fileName>');
	//if (inputdir != null) {
	//  outstr = '<a name=\"_top_\"></a><pre><a href=\"' + indexFile + '\">Index Files</a> ';
	//  outstr += '<a href=\"' + indexFunction + '\">Index Functions</a></pre><hr>';
    //  out.append(outstr);
	//}

    // process the input file
    var lines = f.getLines();
	var comment = "";
    var x = 0;
	while ((s = lines[x++]) != null) {
      var m = s.match(/\/\*\*(.*)/);
	  if (m != null) {
		  // Found a comment start.
		  s = "*" + m[1];
		  do {
			m = s.match(/(.*)\*\//);
			if (m != null) {
			  // Found end of comment.
			  comment += m[1];
			  break;
			}
			// Strip leading whitespace and "*".
			comment += s.replace(/^\s*\*/, "");
			s = lines[x++];
		  } while (s != null);

    	  if (debug)
          print("Found comment " + comment);

		  if (firstLine) {
			// We have a comment for the whole file.
			out.append(processComment(comment,firstLine,fname));
			firstLine = false;
			comment = "";
			continue;
		  }
	  }
	  // match the beginning of the function
	  // NB we also match functions without a comment!
	  // if we have two comments one after another only the last one will be taken
	  m = s.match(/^\s*function\s+((\w+)|(\w+)(\s+))\(([^)]*)\)/);
	  if (m != null)
	  {
			// Found a function start
			var htmlText = processFunction(m[1], m[5], comment); // sjm changed from 2nd to 5th arg
            out.append(htmlText);

			// Save the text in a global variable, so we
			// can write out a table of contents first.
			functionDocArray[functionDocArray.length] = {name:m[1], text:htmlText};

			// Store the function also in the indexFunctionArray
			// so we can have a seperate file with the function table of contents
			if (indexFunctionArray[m[1]]) {
				//  print("ERROR: function: " + m[1] + " is defined more than once!");
				// Allow multiple files for a function
				with (indexFunctionArray[m[1]]) {
					filename = filename + "|" + fname;
					// print("filename = " + filename);
				}
			}
			else {
				indexFunctionArray[m[1]] = {filename:fname};
			}
			//reset comment
			comment = "";
		}
		// match a method being bound to a prototype
	  m = s.match(/^\s*(\w*)\.prototype\.(\w*)\s*=\s*function\s*\(([^)]*)\)/);
	  if (m != null)
	  {
			// Found a method being bound to a prototype.
			var htmlText = processPrototypeMethod(m[1], m[2], m[3], comment);

            out.append(htmlText);
            
			// Save the text in a global variable, so we
			// can write out a table of contents first.
			functionDocArray[functionDocArray.length] = {name:m[1]+".prototype."+m[2], text:htmlText};

			// Store the function also in the indexFunctionArray
			// so we can have a seperate file with the function table of contents
			if (indexFunctionArray[m[1]]) {
				//  print("ERROR: function: " + m[1] + " is defined more than once!");
				// Allow multiple files for a function
				with (indexFunctionArray[m[1]]) {
					filename = filename + "|" + fname;
					// print("filename = " + filename);
				}
			}
			else {
				indexFunctionArray[m[1]] = {filename:fname};
			}
			//reset comment
			comment = "";
		}


		firstLine = false;
	}
    
    /*
    // Write table of contents.
	for (var i=0; i < functionDocArray.length; i++) {
		with (functionDocArray[i]) {
			out.append('function <A HREF=#' + name +
				      '>' + name + '</A><BR>');
		}
	}
	out.append('<HR>');
    

	// Now write the saved function documentation.
	for (i=0; i < functionDocArray.length; i++) {
		with (functionDocArray[i]) {
			out.append('<A NAME=' + name + '>');
			out.append(text);
		}
	}
    */
	out.append('</jsdoc>');

	// Now clean up the doc array
	functionDocArray = [];
}