Make mged 'tables' command not call system()BRL-CAD
Status: ClosedTime to complete: 48 hrs Mentors: SeanTags: C, quicksort

BRL-CAD's geometry editor (MGED) provides hundreds of functions that users can call on the command line. One of our oldest commands writes data out to text files and calls the unix "sort" command to sort a list of items.. That's really bad.

This task involves replacing the three calls to system() with a call to quicksort() or any other simple in-memory sorting mechanism.

Code:

  • src/libged/tables.c
Uploaded Work
File name/URLFile sizeDate submitted
Tables.tar.gz5.7 KBDecember 03 2012 10:34 UTC
Tables.tar.gz5.7 KBDecember 03 2012 10:44 UTC
https://sourceforge.net/tracker/?func=deta...n/aDecember 04 2012 06:03 UTC
Comments
Gmercer015on November 27 2012 18:18 UTCTask Claimed

I would like to work on this task.

Sean on November 27 2012 18:45 UTCTask Assigned

This task has been assigned to Gmercer015. You have 48 hours to complete this task, good luck!

Gmercer015on November 27 2012 20:20 UTCHours you'll be online mentoring

could you give me a general time of when you're usually available on IRC for helping? Appreciate it!

Harmanpreet Singh on November 28 2012 04:44 UTCAsk Questions

You just ask questions on IRC as well as here through comments, as there will be other mentors available to help you out.


Good Luck...!!

Gmercer015on November 28 2012 05:30 UTCChecking my work

I think i've come up with a solution for replacing the system commands, but im not sure if i am completely right. How can i reach this file using BRL-CAD to check that my solution has the same results as the old system commands? 

Sean on November 28 2012 05:38 UTCidents, regions, solids

Run "mged -c /path/to/some/file.g" and select "nu" -- it'll start a simple command console.  There are several example geometry files provided in the share/db directory that you can use for testing (look for moss.g for example).


Running the idents, regions, and solids commands will go through that ged_tables() function.


 

Gmercer015on November 28 2012 06:14 UTCRunning mged in console

I attempted to use the console mged but to no avail, i know i'm doing something wrong with the solids function call but im not sure what.




C:\Users\Grant\Documents\BRLCAD_F\binmged -c C:\Users\Grant\Documents\BRLCAD_F\


share\brlcad\7.22.0\db\moss.g


BRL-CAD Release 7.22.0  Geometry Editor (MGED)


    Thu, 05 Jul 2012 07:32:12 Eastern Daylight Time, Compilation 0


    robert.g.parker@ARLANBNB15095:C:/Program Files (x86)/BRL-CAD 7.22.0


 


attach (nu|wgl)[nu]? nu


mged solids


Usage: solids file object(s)


mged solids moss.g


Usage: solids file object(s)


 

Sean on November 28 2012 12:40 UTCneed a little tutorial

A .g file contains objects.  You simply guessed that one of the contained objects might be named the same as the file.  An okay guess, but obviously not fruitful.  You're missing basic knowledge attained through just about any one of our introductory bits of documentation (like the mged quick ref sheet).  Try the "tops", "ls", "tree", or "search" commands.  There's documentation on all of those and the rest should become apparant.  

Gmercer015on November 28 2012 18:49 UTCRead up on the tutorials

I read up and understood how to call those commands now, the only problem is im not using a unix OS so the sort command does nothing in windows 7. Do i need to download a Virtual Machine UNIX OS to see the results then? The command prompt just shows the sort command instead of doing anything


 


WARNING: sort failure detected


The process cannot access the file because it is being used by another process.


WARNING: cat failure detected


Summary written in: castle.g


Processed 0 Regions


sort --numeric --key=2, 2 --output /tmp/ord_id castle.g right here, just shows the command on win7


cat /tmp/ord_id castle.g


mged solids castle.g gatebot


/tmp/mged_discr: No such file or directory


mged sort


invalid command name "sort"


mged

Sean on November 28 2012 19:33 UTCprobably best

That would probably be the best/easiest way to test it.  Alternatively, you could install Cygwin, which provides the unix command-line tools for Windows.  It's going to be easiest to use the virtual machine image, though, since we've already set everything up.

Gmercer015on November 29 2012 04:23 UTCOut of time

Could i get this task extended please? I have an estimated 20 hours of flight travel time coming up in a couple hours and i would love to be able to finish this project while on vacation as i've put so much effort into solving this task, thanks!

Sean on November 29 2012 04:40 UTCDeadline extended

The deadline of the task has been extended with 3 days and 0 hours.

Sean on November 29 2012 04:42 UTCabsolutely

Safe travels!

Gmercer015on December 2 2012 12:45 UTCTime Extension

Could i receive another time extension please? I've spent to much time to let go of this project, i just need to finish this one up(only a little more, i promise!). The time difference is to far to be able to communicate with the mentors over here in japan so i hope it wouldnt be to much trouble asking my question here,


 


I finished up the qsort by second field, only problem is the file i have to sort. Will my file i need sorted include some statements without numbers? my function sorts the file considering there arent lines such as "Data results" or others that do not include any numbers.


 


what does


cat /tmp/ord_id  


followed by a call to bu_vls_strcat(cmd, argv[1]);


do? my guess is it coppies the contents of the tmp file back to argv[1]? I'm not completly sure though.


 


Thank you if you could extend the deadline, i really apprecaite it!

Harmanpreet Singh on December 2 2012 12:55 UTCDeadline extended

The deadline of the task has been extended with 1 days and 0 hours.

Gmercer015on December 2 2012 12:59 UTCDisregard my first question

I fixed the function to mimic the sort unix command exactly, never mind the question about my qsort! I couldn't find an edit button on my main post so i left this reply

Sean on December 3 2012 03:31 UTCskipping last system()

Mentors,


We discussed over IRC and agreed that he could skip the final system() call that doesn't involve sort (it calls cat).  We'll create a separate task for that.


 

Gmercer015on December 3 2012 10:43 UTCReady for review

The work on this task is ready to be reviewed.

Gmercer015on December 3 2012 10:45 UTCBoth files submitted are exactly the same

Sorry for the confusion, both files submitted are exactly the same. 

Melange on December 3 2012 18:53 UTCNo more Work can be submitted

Melange has detected that the deadline has passed and no more work can be submitted. The submitted work should be reviewed.

Sean on December 4 2012 05:14 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Sean on December 4 2012 05:16 UTCnot in patch format

So from our discussions and what you wrote in your changelog notes, this looks like it's probably good but it's not feasible to review it as-is.  Changes need to be submitted in patch format, otherwise they take far too long to review.  See these for help on making a patch:


http://brlcad.org/wiki/Patches


http://brlcad.org/wiki/Deuces (when you're done section)

Sean on December 4 2012 05:16 UTCDeadline extended

The deadline of the task has been extended with 1 days and 0 hours.

Sean on December 4 2012 05:20 UTCfyi

The follow-up task to fix the cat system() call is here, assuming someone doesn't claim it before you can fix up this patch:


http://www.google-melange.com/gci/task/view/google/gci2012/7966235


 

Gmercer015on December 4 2012 06:03 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 5 2012 03:52 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Sean on December 5 2012 03:52 UTCDeadline extended

The deadline of the task has been extended with 1 days and 0 hours.

Sean on December 5 2012 03:54 UTCthat's not a patch

So I see you created a new item on our patches tracker, but you didn't submit a *patch* file there (or here).  A patch file is a text file that includes only the changes you made to files.  The diff command will generate a patch file.  The "svn diff" command is even better.  Instead of providing entire modified .c files, you'll need to submit just your changes in patch format.  Those two URLs I provided explain that in more detail and even walk you through the process for how to create a patch.

Sean on December 5 2012 03:58 UTCby the way

For what it's worth, making a patch is a fundamental developer skill so it's definitely worth learning.  It's the way code changes are exchanged both throughout open source and professionally.

Gmercer015on December 5 2012 04:07 UTCSorry!

I'm terribly sorry, i thought i had uploaded the patch file! i must have accidently uploaded the text file, i read through the tutorial and created the patch file correctly it's still sitting here on my desktop(how embarassing!). Ill resubmit this now, thanks again for understanding.

Gmercer015on December 5 2012 04:14 UTCReady for review

The work on this task is ready to be reviewed.

Gmercer015on December 5 2012 04:16 UTCUpdated

updated sourceforge link with patch now, if for some reason the changelog.txt is needed it will still be in the compressed files aobe the link.

Sean on December 5 2012 04:29 UTCso close

That's looking a lot better!  The patch looks good but has several problems that make it unapplyable.  Does it compile for you?  I would assume you have, but you may have disabled or otherwise be ignoring warnings.  In particular, I noticed the use of // comments throughout, which will halt our compilation.


See our HACKING file for an overview of many code styling and convention issues.  For example, open scope curly braces should be on the same line as their statement, not the next line.  The only exception are function scopes which should be on the next line..  Your whitespace indentation falls apart near the end of the patch as well.


Those are the critical issues.  There are other problems like the hard-coded fixed buffer sizes, but those can be fixed in a subsequent GCI task.


Thanks again for all your efforts.  Hopefully you learned a few things and (more importantly) had or are having fun1  It looks like there were be several follow-on tasks related to this that you or someone else will be able to claim.


If you provide your full name, we'll credit you accordingly in our authorship documentation.

Sean on December 5 2012 04:29 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Gmercer015on December 5 2012 09:36 UTCReady for review

The work on this task is ready to be reviewed.

Gmercer015on December 5 2012 09:39 UTCCrossing my fingers

Im just thrilled to be able to help out in a legitamate open source project and actually finish something, so actually thank you! I updated the latest patch with what i searched through in the hacker file, changed functions to cross platform bu_func() and fixed commentings/style issues.


 

Gmercer015on December 5 2012 09:49 UTCName put on comment

I put my name on the tracker, but in the case you miss it, my full name is Grant Mercer, and that would awesome if im added to the authorship!

Melange on December 6 2012 06:03 UTCNo more Work can be submitted

Melange has detected that the deadline has passed and no more work can be submitted. The submitted work should be reviewed.

Sean on December 6 2012 06:11 UTCTask Closed

Congratulations, this task has been completed successfully.