cvs commit: LFS/lfscmd/src env.c help.c lfscmd.c main.c string.c

timothy at linuxfromscratch.org timothy at linuxfromscratch.org
Fri May 9 21:23:05 PDT 2003


timothy     03/05/10 00:23:05

  Modified:    lfscmd   README
               lfscmd/src env.c help.c lfscmd.c main.c string.c
  Log:
  Attempted beautification of code and README. Added comments about future usage and a TODO.
  
  Revision  Changes    Path
  1.5       +14 -8     LFS/lfscmd/README
  
  Index: README
  ===================================================================
  RCS file: /home/cvsroot/LFS/lfscmd/README,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- README	9 May 2003 10:42:39 -0000	1.4
  +++ README	10 May 2003 04:23:05 -0000	1.5
  @@ -5,21 +5,27 @@
          lfscmd [options] [index.xml]
   
   DESCRIPTION
  -       lfscmd lfscmd extracts commands from the LFS and BLFS books. The commands may be printed, executed, or writ-
  -       ten to files. lfscmd can record the title of the current page and select pages which match a regular expres-
  -       sion.
  +       lfscmd lfscmd extracts commands from the LFS and BLFS
  +       books. The commands may be printed, executed, or written
  +       to files. lfscmd can record the title of the current page
  +       and select pages which match a regular expression.
   
  -       lfscmd  tries  to  conform  older  books  to the new command structure.  For instance, lfscmd removes double
  -       ampersands and disregards the space between command blocks.
  +       lfscmd  tries  to  conform  older  books  to the new
  +       command structure.  For instance, lfscmd removes double
  +       ampersands and disregards the space between command
  +       blocks.
   
          lfscmd might be used to:
   
  -       *      Reference the build instructions of one or more packages.
  +       *      Reference the build instructions of one or more
  +              packages.
   
  -       *      Determine the command changes between arbitrary versions of a  particular  package,  with  assistance
  +       *      Determine the command changes between arbitrary
  +              versions of a  particular  package, with assistance
                 from diff(1).
   
  -       *      Automate installation scripts by executing commands for one or more packages on the fly.
  +       *      Automate installation scripts by executing commands
  +              for one or more packages on the fly.
   
   OPTIONS
          -e     Execute commands.
  
  
  
  1.2       +1 -2      LFS/lfscmd/src/env.c
  
  Index: env.c
  ===================================================================
  RCS file: /home/cvsroot/LFS/lfscmd/src/env.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- env.c	9 May 2003 10:42:50 -0000	1.1
  +++ env.c	10 May 2003 04:23:05 -0000	1.2
  @@ -27,8 +27,7 @@
   	char *envptr, *env;
   	
   	envptr=getenv(varname);
  -	if (NULL == envptr)
  -		return(NULL);
  +	if (NULL == envptr) return(NULL);
   	else {
   		/* Out of memory */
   		if (NULL==(env = (char *) malloc((string_len(envptr)+1) * sizeof(char)) ))
  
  
  
  1.3       +2 -4      LFS/lfscmd/src/help.c
  
  Index: help.c
  ===================================================================
  RCS file: /home/cvsroot/LFS/lfscmd/src/help.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- help.c	3 Mar 2003 03:50:51 -0000	1.2
  +++ help.c	10 May 2003 04:23:05 -0000	1.3
  @@ -24,8 +24,7 @@
   
   void help (const char *prog)
   {
  -	fprintf(stderr,
  -"Usage: %s [options] index.xml\n\
  +fprintf(stderr, "Usage: %s [options] index.xml\n\
   Options:\n\
     -e\n\
        Execute commands.\n\
  @@ -36,8 +35,7 @@
     -t\n\
        Print titles (as comments).\n\
     -x\n\
  -     Make file output executable.\n",
  -prog);
  +     Make file output executable.\n", prog);
   
       exit(1);
   }
  
  
  
  1.4       +21 -35    LFS/lfscmd/src/lfscmd.c
  
  Index: lfscmd.c
  ===================================================================
  RCS file: /home/cvsroot/LFS/lfscmd/src/lfscmd.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- lfscmd.c	9 May 2003 10:42:50 -0000	1.3
  +++ lfscmd.c	10 May 2003 04:23:05 -0000	1.4
  @@ -66,7 +66,7 @@
             help(argv[0]);
       }
   
  -    /* Get xmlfile */
  +    /* Get xml file path */
       lfs.xmlfile = argv[optind];
   
       /* Validate arguments */
  @@ -79,13 +79,10 @@
       doc = xmlParseFile(lfs.xmlfile);
       node = xmlDocGetRootElement(doc);
   
  -    /* Check that document is well-formed */
  -    if (NULL == doc)
  -    error("Document not well-formed");
  -
  +    /* Check that the document is well-formed */
  +    if (NULL == doc) error("Document not well-formed");
       /* Check for an empty root element */
  -    if (NULL == node)
  -    error("Empty root element");
  +    if (NULL == node) error("Empty root element");
   
       return(lfscmd_parsexml(doc, node->children));
   }
  @@ -106,7 +103,6 @@
              lfs.sect = xmlNodeListGetString(doc, node->children, 1);
              lfs.status = 1;
           }
  -
           /* Determine filename by section id */
           else if (string_comp("part", node->name)
                || (string_len(node->name) >= 4
  @@ -115,20 +111,17 @@
                if (NULL != xmlGetProp(node, "id"))
                lfs.fname = xmlGetProp(node, "id");
           }
  -
           /* Display screen commands */
           else if (string_comp("screen", node->name)
  -             && string_comp("userinput", node->children->name)) {
  +              && string_comp("userinput", node->children->name)) {
   
                /* Match title or section with query */
                if (NULL != lfs.query) {
  -                if (! regexec(&reg, lfs.sect, 0, NULL, 0)
  -                   || ! regexec(&reg, lfs.fname, 0, NULL, 0))
  -
  -                   lfscmd_parse_screen(doc, node->children);
  +                if (!regexec(&reg, lfs.sect, 0, NULL, 0)
  +                 || !regexec(&reg, lfs.fname, 0, NULL, 0))
  +                 lfscmd_parse_screen(doc, node->children);
                }
  -             else
  -               lfscmd_parse_screen(doc, node->children);
  +             else lfscmd_parse_screen(doc, node->children);
           }
   
           /* Recursively traverse the tree */
  @@ -143,15 +136,12 @@
   int lfscmd_parse_screen (xmlDocPtr doc, xmlNodePtr node) {
       FILE *output = stdout;
   
  -    if (NULL == lfs.fname)
  -       lfs.fname = "unknown";
  -    if (NULL == lfs.sect)
  -       lfs.sect = "unknown";
  +    if (NULL == lfs.fname) lfs.fname = "unknown";
  +    if (NULL == lfs.sect)  lfs.sect  = "unknown";
   
       /* Append output to file */
  -    if (1 == lfs.file)
  -    output = write_file(lfs.fname, "a");
  -
  +    if (1 == lfs.file) output=write_file(lfs.fname, "a");
  +    
       /* Output new page title */
       if (1 == lfs.status && 1 == lfs.title) {
          fprintf(output, "\n\n### %s: %s ###\n", lfs.fname, lfs.sect);
  @@ -164,25 +154,23 @@
           /* Output content outside of "userinput" */
           if (string_comp("text", node->name)) {
               if (NULL != (lfs.cmd = node->content)) {
  -               if (1 == lfs.execute)
  -               system(lfs.cmd);
  -               else
  -               fprintf(output, "%s", lfs.cmd);
  +               if (1 == lfs.execute) system(lfs.cmd);
  +               else fprintf(output, "%s", lfs.cmd);
               }
           }
   
           /* Output commands */
  -        else if (string_comp("userinput", node->name)) {
  -
  +        else if (string_comp("userinput", node->name))
  +        {
               /* Strip double ampersands */
               if (NULL != (lfs.cmd = xmlNodeListGetString(doc, node->children, 1))) {
  +            
                  if (1 == lfs.execute)
  -               system(string_strip(lfs.cmd, "&&"));
  +                 system(string_strip(lfs.cmd, "&&"));
                  else
  -               fprintf(output, "%s", string_strip(lfs.cmd, "&&"));
  +                 fprintf(output, "%s", string_strip(lfs.cmd, "&&"));
               }
           }
  -
           node = node->next;
       }
   
  @@ -194,9 +182,7 @@
          fclose(output);
   
          /* Make file executable */
  -       if (1 == lfs.exe)
  -       chmod(lfs.fname, 00755);
  +       if (1 == lfs.exe) chmod(lfs.fname, 00755);
       }
  -
       return(1);
   }
  
  
  
  1.3       +5 -0      LFS/lfscmd/src/main.c
  
  Index: main.c
  ===================================================================
  RCS file: /home/cvsroot/LFS/lfscmd/src/main.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- main.c	2 Mar 2003 20:59:30 -0000	1.2
  +++ main.c	10 May 2003 04:23:05 -0000	1.3
  @@ -19,6 +19,11 @@
   
   #include "lfscmd.h"
   
  +/*
  +	In the future, symlinks will determine run mode.
  +	The default mode shall be docbook xml.
  +*/
  +
   int main (int argc, char **argv) {
       return(lfscmd(argc, argv));
   }
  
  
  
  1.3       +13 -13    LFS/lfscmd/src/string.c
  
  Index: string.c
  ===================================================================
  RCS file: /home/cvsroot/LFS/lfscmd/src/string.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- string.c	9 May 2003 10:42:50 -0000	1.2
  +++ string.c	10 May 2003 04:23:05 -0000	1.3
  @@ -40,12 +40,11 @@
   
   int string_cat (char *str1, const char *str2) {
       int c, d;
  -
       c = string_len(str1);
       d = 0;
   
       while ('\0' != str2[d])
  -    str1[c++] = str2[d++];
  +      str1[c++] = str2[d++];
   
       str1[c] = '\0';
       return(d);
  @@ -53,15 +52,11 @@
   
   int string_comp (const char *str1, const char *str2) {
       int len;
  -
       len = string_len(str1);
  -    if (len != string_len(str2))
  -    return(0);
  -
  -    for (; len > 0; len--) {
  -        if (str1[len] != str2[len])
  -	return(0);
  -    }
  +    
  +    if (len != string_len(str2)) return(0);
  +    for (; len > 0; len--)
  +		if (str1[len] != str2[len]) return(0);
   
       return(1);
   }
  @@ -69,12 +64,14 @@
   char *string_cpy (const char *str1) {
   	int c;
   	char *dest;
  -
  +	
  +    /* Allocate space for new string */
   	c = 0;
   	dest = malloc((string_len(str1)+1) * sizeof(char));
  +	
       while (*str1) {
  -		dest[c] = *str1++;
  -		c++;
  +	  dest[c] = *str1++;
  +	  c++;
   	}
   	
   	dest[c] = '\0';
  @@ -91,9 +88,11 @@
       int c, d;
       char *str;
   
  +    /* Allocate space for new string */
       str = malloc((end-start+1) * sizeof(char));
       d = 0;
   
  +    /* Record text from start to stop */
       for (c=start; c < end; c++)
       str[d++] = string[c];
   
  @@ -101,6 +100,7 @@
       return(str);
   }
   
  +/* TODO: This function is nasty; recode. */
   char *string_strip (const char *string, const char *strip) {
       char *str, *tmp;
       int len_stp, len_str;
  
  
  
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-book' in the subject header of the message



More information about the lfs-book mailing list