Editing User:Ksuzee/Proposal

From BRL-CAD

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 6: Line 6:
  
 
= Detailed description =
 
= Detailed description =
I decided to choose this project, because, I am sure, I have enough knowledge in c/c++ for doing it. I've been working with it since 19.03.2012. Unfortunately, I have a lot of subjects (about 12) this year, so I don't have enough time for working with BRL-CAD and patches every day now. Nevertheless, after the 1-5 of May I will be absolutely free and ready to work hard.
+
I decided to choose this project, because, I am sure, I have enough knowledge in c/c++ for doing it. I've been working with it since 19.03.2012. Unfortunately I have a lot of subjects (about 12) this year, so I don't have enough time for working with BRL-CAD and patches every day. Nevertheless, after the 1-5 of May I will be absolutely free and ready to work hard.
 
== Proposes for reduction ==
 
== Proposes for reduction ==
 
BRL-CAD has quite useful Virtual Machine, which helped me to do my first steps with it. Mentor Sean helped me to become quite familiar with it. After several tests with "Simian" I understood that the work for reduction will be really huge. There are a lot of duplications (e.g. just copy-pasts). After testing I can propose such ideas:
 
BRL-CAD has quite useful Virtual Machine, which helped me to do my first steps with it. Mentor Sean helped me to become quite familiar with it. After several tests with "Simian" I understood that the work for reduction will be really huge. There are a lot of duplications (e.g. just copy-pasts). After testing I can propose such ideas:
  
 
*Duplication in one file.
 
*Duplication in one file.
Example:
+
  Example:
  
................
+
  int
if (!invert) {    
+
   bu_strcmp(const char *string1, const char *string2)
    for (line = file_height-1; line >= 0; line--) {     
+
  {
      unsigned char *op;       
+
    const char *s1 = "";
      vp = &vert_buf[line*3];     
+
    const char *s2 = "";
      op = &horiz_buf[(file_width*3)-1];
+
    /* "" and NULL are considered equivalent which helps prevent
      while (op > horiz_buf) {
+
    * strcmp() from crashing.
          *op-- = vp[2];
+
    */
          *op-- = vp[1];
+
     if (string1) s1 = string1;
          *op-- = *vp;
+
    if (string2) s2 = string2;
      }
+
    return strcmp(s1, s2);
      ret = write(1, horiz_buf, file_width*3);
+
  }
      if (ret < 0)
 
          perror("write");
 
    }
 
} else {
 
/* Inverted: top-to-bottom. Good with cat-fb */
 
     for (line=0; line < file_height; line++) {
 
      unsigned char *op;       
 
      vp = &vert_buf[line*3];    
 
      op = &horiz_buf[(file_width*3)-1];
 
      while (op > horiz_buf) {
 
          *op-- = vp[2];
 
          *op-- = vp[1];
 
          *op-- = *vp;
 
      }
 
      ret = write(1, horiz_buf, file_width*3);
 
      if (ret < 0)
 
          perror("write");
 
    }
 
}
 
  
..................
+
  int
 +
  bu_strncmp(const char *string1, const char *string2, size_t n)
 +
  {
 +
    /* the same body */
 +
    return strncmp(s1, s2, n);
 +
  }
  
This part is situated in file src/util/picbackgnd.c. We can see that the code in the first "for" is the same as in the second. So I propose to write the function with all necessary parameters which will contain this code:
+
  int
void
+
  bu_strcasecmp(const char *string1, const char *string2)
my_reduction (unsigned char *horiz_buf, unsigned char *vert_buf, unsigned char *vp, ssize_t ret, int line)
+
  {
{
+
    /* the same body */
    unsigned char *op;
+
    return strcasecmp(s1, s2);
    vp = &vert_buf[line*3];
+
  }
    op = &horiz_buf[(file_width*3)-1];
 
    while (op > horiz_buf) {
 
        *op-- = vp[2];
 
        *op-- = vp[1];
 
        *op-- = *vp;
 
    }
 
    ret = write(1, horiz_buf, file_width*3);
 
    if (ret < 0)
 
        perror("write");
 
}
 
  
The function call will have such view:
+
  int
 +
  bu_strncasecmp(const char *string1, const char *string2, size_t n)
 +
  {
 +
    /* the same body */
 +
    return strncasecmp(s1, s2, n);
 +
  }
  
..................
+
These functions are situated in file src/libbu/str.c. All these functions have the same bodies. So I propose to change these four functions and have function with such body:
  if (!invert) {
 
    for (line = file_height-1; line >= 0; line--)
 
        my_reduction(horiz_buf, vert_buf, vp, ret, line);
 
  } else {
 
    for (line=0; line < file_height; line++)
 
        my_reduction(horiz_buf, vert_buf, vp, ret, line);
 
  }
 
  
.................
+
  int
 +
  bu_strcmp(const char *string1, const char *string2, size_t n, unsigned char cases_cmp)
 +
  {
 +
    const char *s1 = "";
 +
    const char *s2 = "";
 +
    /* "" and NULL are considered equivalent which helps prevent
 +
    * strncmp() from crashing.
 +
    */
 +
    if (string1) s1 = string1;
 +
    if (string2) s2 = string2;
 +
    if (cases_cmp)
 +
      {
 +
  if (n == 0) return strncasecmp(s1, s2); return strncasecmp(s1, s2, n);
 +
      }
 +
    if (n == 0) return strcmp(s1, s2);
 +
    return strncmp(s1, s2, n);
 +
  }
  
We can see that the code would be more understandable and short
+
The next step is to find functions' calls and correct them
  
 
*Duplication in one directory but different files
 
*Duplication in one directory but different files
Line 98: Line 88:
  
 
= Development schedule =
 
= Development schedule =
*before 23.04 - continuing to get familiar with project  
+
*before 23.04 - continuing to get familiar with project
*23.04 - 21.05 - active communication with mentor(s), asking questions, getting ready for start  
+
*23.04 - 21.05 - active communication with mentor(s), asking questions, getting ready for start
*21.05 - 15.06 - coding. Complete reduction of the duplications that take place in one file.
+
*21.05 - 1.07 - coding. Working with the first part of the project
*15.06 - 3.07 - Reduction of as large as possible number of files that contains duplications (duplications in different files, the same directory). Writing some tests
+
*1.07 - 9.07 - bugs fixing, review to be ready for submitting
*3.07 - 9.07 - bugs fixing, review to be ready for submitting  
+
*9.07 - 13.07 - submitting  
*9.07 - 13.07 - submitting, some more review if it is necessary
+
*13.07 - 13.08 - coding the second part of the project
*13.07 - 23.07 - reduction of the reminder of duplication in different files and tests.
 
*23.07 - 13.08 - coding the last part of the project, removing duplications in files that contains in different directories, making necessary tests and libraries.
 
 
*13.08 - 20.08 - bugs fixing, review to be ready for submitting the final result
 
*13.08 - 20.08 - bugs fixing, review to be ready for submitting the final result
  

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)