changeset 402:2551e517b800

Expand comments.
author Rob Landley <rob@landley.net>
date Sat, 14 Jan 2012 23:28:15 -0600
parents bc435ea49b2c
children f6ffc6685a9e
files main.c
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Wed Dec 28 16:50:16 2011 -0600
+++ b/main.c	Sat Jan 14 23:28:15 2012 -0600
@@ -29,7 +29,7 @@
 {
 	int top, bottom, middle;
 
-	// If the name starts with "toybox", accept that as a match.  Otherwise
+	// If the name starts with "toybox" accept that as a match.  Otherwise
 	// skip the first entry, which is out of order.
 
 	if (!strncmp(name,"toybox",6)) return toy_list;
@@ -52,7 +52,8 @@
 
 // Figure out whether or not anything is using the option parsing logic,
 // because the compiler can't figure out whether or not to optimize it away
-// on its' own.
+// on its' own.  NEED_OPTIONS becomes a constant allowing if() to optimize
+// stuff out via dead code elimination.
 
 #undef NEWTOY
 #undef OLDTOY
@@ -62,6 +63,8 @@
 #include "generated/newtoys.h"
 0;  // Ends the opts || opts || opts...
 
+// Setup toybox global state for this command.
+
 void toy_init(struct toy_list *which, char *argv[])
 {
 	// Drop permissions for non-suid commands.
@@ -90,7 +93,8 @@
 	if (which->flags & TOYFLAG_UMASK) toys.old_umask = umask(0);
 }
 
-// Run a toy.
+// Like exec() but runs an internal toybox command instead of another file.
+// Only returns if it can't find the command, otherwise exit() when done.
 void toy_exec(char *argv[])
 {
 	struct toy_list *which;
@@ -102,6 +106,9 @@
 	exit(toys.exitval);
 }
 
+// Multiplexer command, first argument is command to run, rest are args to that.
+// If first argument starts with - output list of command install paths.
+
 void toybox_main(void)
 {
 	static char *toy_paths[]={"usr/","bin/","sbin/",0};
@@ -140,13 +147,15 @@
 	{
 		char *name;
 
-		// Figure out which applet to call.
+		// Trim path off of command name
 		name = rindex(argv[0], '/');
 		if (!name) name=argv[0];
 		else name++;
 		argv[0] = name;
 	}
 
+	// Call the multiplexer, adjusting this argv[] to be its' argv[1].
+	// (It will adjust it back before calling toy_exec().)
 	toys.argv = argv-1;
 	toybox_main();
 	return 0;