r1608 - dev/concept/moongoo

neocool at linuxfromscratch.org neocool at linuxfromscratch.org
Tue Nov 30 16:02:07 PST 2004


Author: neocool
Date: 2004-11-30 17:02:07 -0700 (Tue, 30 Nov 2004)
New Revision: 1608

Modified:
   dev/concept/moongoo/alfs.c
   dev/concept/moongoo/alfs.h
   dev/concept/moongoo/book.c
   dev/concept/moongoo/moongoo.c
   dev/concept/moongoo/util.c
   dev/concept/moongoo/util.h
Log:
* Chapters
* Proper output
* Some bugs left though


Modified: dev/concept/moongoo/alfs.c
===================================================================
--- dev/concept/moongoo/alfs.c	2004-11-30 22:07:35 UTC (rev 1607)
+++ dev/concept/moongoo/alfs.c	2004-12-01 00:02:07 UTC (rev 1608)
@@ -29,8 +29,31 @@
 	
 	for (i=0;i<pkg.n;i++)
 		print_cmd(pkg.build[i]);
+	printf("\n");
 }		
 
+void print_chapter (chapter ch)
+{
+	int i;
+
+	term_set(RESET, RED, BLACK);
+	printf("%s\n", ch.name);
+	term_reset();
+	for (i=0;i<ch.n;i++)
+		print_pkg(ch.pkg[i]);
+}
+
+void print_profile (profile prof)
+{
+	int i;
+
+	term_set(RESET, BLUE, BLACK);
+	printf("%s %s\n", prof.name, prof.vers);
+	term_reset();
+	for (i=0;i<prof.n;i++)
+		print_chapter(prof.ch[i]);
+}
+
 void print_subtree (xmlNodePtr node)
 {
 	while (node)

Modified: dev/concept/moongoo/alfs.h
===================================================================
--- dev/concept/moongoo/alfs.h	2004-11-30 22:07:35 UTC (rev 1607)
+++ dev/concept/moongoo/alfs.h	2004-12-01 00:02:07 UTC (rev 1608)
@@ -19,30 +19,35 @@
 
 typedef struct
 {
-	char *cmd;
-	char **arg;
+	char *cmd, **arg;
 	int n;
 	role role;
 } command;
 
 typedef struct
 {
-	char *name;
-	char *vers;
+	char *name, *vers;
 	command *build;
 	int n;
 } package;
 
 typedef struct
 {
+	char *name, *ref;
 	package *pkg;
 	int n;
+} chapter;
+
+typedef struct
+{
+	char *name, *vers;
+	chapter *ch;
+	int n;
 } profile;
 
 typedef struct
 {
-	char *orig;
-	char *repl;
+	char *orig, *repl;
 } replaceable;
 
 extern xmlDocPtr doc;
@@ -52,6 +57,8 @@
 void print_subtree (xmlNodePtr node);
 void print_pkg (package pkg);
 void print_cmd (command cmd);
+void print_chapter (chapter ch);
+void print_profile (profile prof);
 
 void resolve_entities (xmlNodePtr node);
 void foreach (xmlNodePtr node, char *str, xml_handler_t func, void *data);

Modified: dev/concept/moongoo/book.c
===================================================================
--- dev/concept/moongoo/book.c	2004-11-30 22:07:35 UTC (rev 1607)
+++ dev/concept/moongoo/book.c	2004-12-01 00:02:07 UTC (rev 1608)
@@ -6,18 +6,19 @@
 #include <util.h>
 
 command *cmd;
+int num;
 profile *prof;
 replaceable *__r;
-int num;
 
 void t_sect1 (xmlNodePtr node, void *data);
 void process_cmd (char *line, xmlNodePtr node);
 void __t_userinput (xmlNodePtr node, void *data);
 command *t_userinput (xmlNodePtr node, int *n);
+void t_chapter (xmlNodePtr node);
 
 void t_sect1 (xmlNodePtr node, void *data)
 {
-	int i;
+	int i, j;
 	char *title, *tmp;
 		
 	title = find_value(node->children, "title");
@@ -28,19 +29,21 @@
 		return;
 	}
 
-	prof->pkg = realloc(prof->pkg, (++prof->n)*sizeof(package));
 	i = prof->n-1;
+	prof->ch[i].pkg = realloc(prof->ch[i].pkg, 
+			(++prof->ch[i].n)*sizeof(package));
+	j = prof->ch[i].n-1;
 	
 	tmp = strdog(lower_case(title), "version");
-	prof->pkg[i].vers = entity_val(tmp);
-	prof->pkg[i].name = strcut(title, 0, strlen(title)-
-		((prof->pkg[i].vers) ? 1 : 0));
-	prof->pkg[i].build = t_userinput(node->children, 
-		&prof->pkg[i].n);
+	prof->ch[i].pkg[j].vers = entity_val(tmp);
+	prof->ch[i].pkg[j].name = strcut(title, 0, strlen(title)-
+		((prof->ch[i].pkg[j].vers) ? 1 : 0));
+	prof->ch[i].pkg[j].build = t_userinput(node->children, 
+		&prof->ch[i].pkg[j].n);
 	free(tmp);
 
-	if (!prof->pkg[i].n)
-		prof->n--;
+	if (!prof->ch[i].pkg[i].n)
+		prof->ch[i].n--;
 }
 
 void process_cmd (char *line, xmlNodePtr node)
@@ -102,12 +105,46 @@
 	return cmd;
 }
 
+void t_chapter (xmlNodePtr node)
+{
+	int i = prof->n-1;
+	prof->ch[i].name = xmlGetProp(node, "xreflabel");
+	prof->ch[i].ref = xmlGetProp(node, "id");
+	prof->ch[i].pkg = NULL;
+	prof->ch[i].n = 0;
+	foreach(node->children, "sect1", (xml_handler_t)t_sect1, NULL);
+}
+
 profile *bookasprofile (xmlNodePtr node)
 {
+	xmlNodePtr info = find_node(node, "bookinfo");
 	__r = init_repl(MOO_XML);
+	
 	prof = (profile *)malloc(sizeof(profile));
-	prof->pkg = NULL;
+	prof->name = find_value(info, "title");
+	prof->vers = find_value(info, "subtitle");
+	prof->vers = strcut(prof->vers, strlen("Version"), strlen(prof->vers));
+	prof->ch = NULL;
 	prof->n = 0;
-	foreach(node, "sect1", (xml_handler_t)t_sect1, NULL);
+	
+	node = node->children;
+	while (node)
+	{
+		if (!strcmp(node->name, "part"))
+		{
+			xmlNodePtr cur = node->children;
+			while (cur)
+			{
+				if (!strcmp(cur->name, "chapter"))
+				{
+					prof->ch = realloc(prof->ch, (++prof->n)*sizeof(chapter));
+					t_chapter(cur);
+				}
+				cur=cur->next;
+			}
+		}
+		node=node->next;
+	}
+	
 	return prof;
 }

Modified: dev/concept/moongoo/moongoo.c
===================================================================
--- dev/concept/moongoo/moongoo.c	2004-11-30 22:07:35 UTC (rev 1607)
+++ dev/concept/moongoo/moongoo.c	2004-12-01 00:02:07 UTC (rev 1608)
@@ -8,7 +8,7 @@
 
 int main (int argc, char **argv)
 {
-	int i;
+	//int i;
 	xmlNodePtr cur;
 	profile *prof;
 
@@ -26,16 +26,7 @@
 	resolve_entities(cur);
 	
 	prof=bookasprofile(cur);
-	for (i=0;i<prof->n;i++)
-	{
-		package pkg = prof->pkg[i];
-		
-		//if (!strcmp(pkg.name, "Module-Init-Tools"))
-		//if (!strcmp(pkg.name, "Creating a file system"))
-		//if (!strcmp(pkg.name, "Linux"))
-		if (!strcmp(pkg.name, "Creating the /etc/fstab file"))
-			print_pkg(pkg);
-	}
+	print_profile(*prof);
 	
 	xmlFreeDoc(doc);
 	return 0;

Modified: dev/concept/moongoo/util.c
===================================================================
--- dev/concept/moongoo/util.c	2004-11-30 22:07:35 UTC (rev 1607)
+++ dev/concept/moongoo/util.c	2004-12-01 00:02:07 UTC (rev 1608)
@@ -291,3 +291,19 @@
 
 	return ret;
 }	
+
+void term_set (int attr, int fg, int bg)
+{
+	char cmd[13];
+
+	sprintf(cmd, "%c[%d;%d;%dm", 0x1B, attr, fg+30, bg+40);
+	printf(cmd);
+}
+
+void term_reset ()
+{
+	char cmd[13];
+
+	sprintf(cmd, "%c[m", 0x1B);
+	printf(cmd);
+}

Modified: dev/concept/moongoo/util.h
===================================================================
--- dev/concept/moongoo/util.h	2004-11-30 22:07:35 UTC (rev 1607)
+++ dev/concept/moongoo/util.h	2004-12-01 00:02:07 UTC (rev 1608)
@@ -3,6 +3,28 @@
 
 #include <stdbool.h>
 
+/* Attributes */
+#define RESET           0
+#define BRIGHT          1
+#define DIM             2
+#define UNDERLINE       3
+#define BLINK           4
+#define REVERSE         7
+#define HIDDEN          8
+
+/* Colors */
+#define BLACK           0
+#define RED             1
+#define GREEN           2
+#define YELLOW          3
+#define BLUE            4
+#define MAGENTA         5
+#define CYAN            6
+#define WHITE           7
+
+void term_set (int attr, int fg, int bg);
+void term_reset ();
+
 char *lower_case (char *str);
 char *strdog (char *str1, char *str2);
 char *chrep (char *str, char old, char new);




More information about the alfs-log mailing list