Make tables.c not call system(cat ...)BRL-CAD
Status: ClosedTime to complete: 48 hrs Mentors: SeanTags: C, file i/o, concatenated ouptut

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 "cat" command to append output to a file ... That's really bad.

This task involves replacing the three calls to system() with a call to appropriate file I/O calls or any other similar mechanism.

Code:

  • src/libged/tables.c
Uploaded Work
File name/URLFile sizeDate submitted
tables.c12.9 KBDecember 06 2012 04:04 UTC
tables.patch955 bytesDecember 07 2012 05:22 UTC
tables.patch973 bytesDecember 07 2012 13:29 UTC
tables2.patch973 bytesDecember 07 2012 13:30 UTC
tables.patch1.2 KBDecember 09 2012 01:41 UTC
tables3.patch1.2 KBDecember 09 2012 01:42 UTC
tables4.patch1.3 KBDecember 10 2012 03:57 UTC
tables5patch1.3 KBDecember 11 2012 00:36 UTC
Comments
javamonnon December 4 2012 13:16 UTCTask Claimed

I would like to work on this task.

Andrei Popescu on December 4 2012 13:41 UTCTask Assigned

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

javamonnon December 5 2012 04:29 UTCA few questions...

First of all, where is the third system() call? I can find the two in the  ged tables method but I cant seem to locate the third. Secondly, only one of these calls to system are a "cat" command, the other is a sort command. I'm assuming that I only replace the call with the cat command, but please correct me if I'm wrong.  The submitted file will be the full tables.c with the appropriate changes made, right?


Thanks for the help,


Daniel

javamonnon December 6 2012 03:43 UTCI was looking at old code...

So I was looking at the code posted online which is apparently out of date. I fired up the vm and found the third call to system. My question still stands as far as if I'm replacing all three, or just the system("cat ...") command. I'm not sure how I would implement the sort command so I will work on just the cat for now. Let me know if I should do otherwise.

javamonnon December 6 2012 04:04 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 6 2012 06:58 UTConly the third

Yes, this task is for just that last system() call.  There was another GCI task, already completed, that fixed the two sort ones.


If you're using the vm, make sure you run "svn update" to get the latest sources.


Submitting the whole file is nfg.  You need to submit a proper patch file. See http://brlcad.org/wiki/Patches or the Deuces page or a slew or help around the web for instruction on creating a patch file.  Patches are the proper way to exchange changes to code, professionally and especially throughout Open Source.


 

Sean on December 6 2012 06:58 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.

javamonnon December 6 2012 13:12 UTCExtension?

Could I possibly get an extension on this task? I'm at school now but I'll be able to fix whats wrong and submit a patch as soon as I get home. 


Thanks, 


Daniel

Daniel Rossberg on December 6 2012 13:31 UTCDeadline extended

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

javamonnon December 7 2012 05:22 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 7 2012 06:00 UTCfew problems

I noticed a few problems that need to be fixed with the patch:



  1. don't remove the blank line after the common.h include

  2. using double-quotes (e.g., #include "header") is bad-form for system headers

  3. should be bio.h instead of stdio.h and come after all of the sytems headers

  4. the explicit null termination is not needed (not your fault, that dumbness was already there)

  5. you must check that fopen() completed successfully before using the return value.


 

Sean on December 7 2012 06:00 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.

javamonnon December 7 2012 13:30 UTCReady for review

The work on this task is ready to be reviewed.

Melange on December 7 2012 13:56 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 7 2012 17:25 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 7 2012 17:28 UTCI'm guessing

I'm guessing that you haven't actually tried to compile your patch.  Please re-review and test whether this actually works.  Upon further inspection, I don't think your code is equivalent to what the system() call was doing.  You're appending the name of the file, which the original code was not doing.


 

Sean on December 7 2012 17:28 UTCDeadline extended

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

javamonnon December 9 2012 01:42 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 9 2012 05:26 UTCDeadline extended

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

Sean on December 9 2012 05:26 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 9 2012 05:46 UTCimplementation needs work

Javamonn, the implementation looks like it should be equivalent, but there are a few problems.  Instead of scanning the file twice using a function we wrap and using a c99 array allocation that we don't allow, try using our bu_mapped_file interface.  bu_mapped_file_open() then you can read from the mappedfile-buf, write the data out, and then close the mapped file.  See bu.h for API help and src/libged/red.c for an example of the interface being used.

javamonnon December 10 2012 03:58 UTCReady for review

The work on this task is ready to be reviewed.

javamonnon December 10 2012 04:01 UTCHopefully...

Hopefully tables4 is alright. That bu_mapped_file struct is pretty handy. To my understanding, I still had to open the file to write to in the normal fasion, correct? Unless you have another struct I would rather use, since bu_mapped_file is read only. Let me know if there are any other issues.


Thanks,


Daniel

Sean on December 11 2012 02:35 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on December 11 2012 02:55 UTCexcellent

Very nicely done.  I hope you take on some of our other coding tasks!  This clears up a bad coding call that's been in there for a very long time.. :)


Thanks for making it better!