Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: does this alias exist??

From: Eivind Eklund <eivind(at)dimaga.com>
Date: Tue Feb 18 1997 - 04:12:20 EST


At 01:55 PM 2/16/97 -0500, Aaron Bornstein wrote:
>On Sun, 16 Feb 1997, Eivind Eklund wrote:
>
>>
>> Do people want me to pick send back reports of the style-nits I've picked
>> from the patches, or just fix'n'commit?
>>
> I'd definitely like to see the style nits, could always use
>constructive criticism.

OK, for Battlestar:

  1. I removed the references to KERNEL, as they no longer served any function after fixing time to gtime.
  2. I undid the change from setbit to set_bit, and instead made the two different setbit()s compatible. This required changing from int to char 4 or 5 places, and a change of BITS from 8*sizeof(int) to 8.
  3. Fixed a split string in com5.c
  4. Fixed a split string in com1.c

The following nits were in the original patch:

  • battlestar/save.c.old Sat Feb 15 16:50:39 1997 +++ battlestar/save.c Sat Feb 15 21:07:19 1997 @@ -35,27 +35,33 @@ static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */
+#include 
+#include 
+#include                  /* MAXPATHLEN */
+#include 

 #include "externs.h"  

+void
 restore()
 {

        char *getenv();
        char *home;
-       char home1[100];
+       char home1[MAXPATHLEN];
        register int n;
        int tmp;
        register FILE *fp;
 
-       home = getenv("HOME");
-       strcpy(home1, home);
-       strcat(home1, "/Bstar");
+       if ( (home = getenv("HOME")) != NULL) 
            ^
+         sprintf(home1, "%.*s/Bstar", MAXPATHLEN - 7, home);
+       else return;

Extra space. In addition, this line of code is not in style with the rest of the sourcefile (the rest don't use NULL). I rewrote these 3 lines to

+       home = getenv("HOME");
+       if (home == 0)
+         return; 
+       sprintf(home1, "%.*s/Bstar", MAXPATHLEN - 7, home);

which follow the style of the source better.

        if ((fp = fopen(home1, "r")) == 0) {
                perror(home1);
                return;
        }
        fread(&WEIGHT, sizeof WEIGHT, 1, fp);
        fread(&CUMBER, sizeof CUMBER, 1, fp);
-       fread(&clock, sizeof clock, 1, fp);
+       fread(&gclock, sizeof gclock, 1, fp);
        fread(&tmp, sizeof tmp, 1, fp);
        location = tmp ? dayfile : nightfile;
        for (n = 1; n <= NUMOFROOMS; n++) {
@@ -68,7 +74,7 @@
        fread(notes, sizeof notes, 1, fp);
        fread(&direction, sizeof direction, 1, fp);
        fread(&position, sizeof position, 1, fp);
-       fread(&time, sizeof time, 1, fp);
+       fread(>ime, sizeof gtime, 1, fp);
        fread(&fuel, sizeof fuel, 1, fp);
        fread(&torps, sizeof torps, 1, fp);
        fread(&carrying, sizeof carrying, 1, fp);
@@ -90,26 +96,51 @@
        fread(&ego, sizeof ego, 1, fp);

 }  

+void
 save()
 {

+       struct stat sbuf;
        char *getenv();
        char *home;
-       char home1[100];
+       char home1[MAXPATHLEN];
        register int n;
-       int tmp;
+       int tmp, fd;
        FILE *fp;
 
-       home = getenv("HOME");
-       strcpy(home1, home);
Do you need help?X
- strcat(home1, "/Bstar"); - if ((fp = fopen(home1, "w")) == 0) { + if ( (home = getenv("HOME")) != NULL) + sprintf(home1, "%.*s/Bstar", MAXPATHLEN - 7, home); + else + return;

Same as above.

+       /* Try to open the file safely. */
+       if ( (stat(home1, &sbuf)) < 0) {                
+               fd = open(home1, O_WRONLY|O_CREAT|O_EXCL);
+               if (fd < 0) {
+                       fprintf(stderr, "Can't create %s\n", home1);
+                       return;
+               }
+       } else {
+               if (sbuf.st_nlink > 1) {
+                       fprintf(stderr, "No symlinks!\n");
+                       return;
+               }
+
+               fd = open(home1, O_WRONLY|O_EXCL);
+               if (fd < 0) {
+                       fprintf(stderr, "Can't open %s for writing\n", home1);
+                       return;
+               }
+       }
+
+       if ((fp = fdopen(fd, "w")) == 0) {
                perror(home1);
                return;
        }
+
        printf("Saved in %s.\n", home1);
        fwrite(&WEIGHT, sizeof WEIGHT, 1, fp);
        fwrite(&CUMBER, sizeof CUMBER, 1, fp);
-       fwrite(&clock, sizeof clock, 1, fp);
+       fwrite(&gclock, sizeof gclock, 1, fp);
        tmp = location == dayfile;
        fwrite(&tmp, sizeof tmp, 1, fp);
        for (n = 1; n <= NUMOFROOMS; n++) {
@@ -122,7 +153,7 @@
        fwrite(notes, sizeof notes, 1, fp);
        fwrite(&direction, sizeof direction, 1, fp);
        fwrite(&position, sizeof position, 1, fp);
-       fwrite(&time, sizeof time, 1, fp);
+       fwrite(>ime, sizeof gtime, 1, fp);
        fwrite(&fuel, sizeof fuel, 1, fp);
        fwrite(&torps, sizeof torps, 1, fp);
        fwrite(&carrying, sizeof carrying, 1, fp);
@@ -142,4 +173,5 @@
Can we help you?X
fwrite(&pleasure, sizeof pleasure, 1, fp); fwrite(&power, sizeof power, 1, fp); fwrite(&ego, sizeof ego, 1, fp);
+
Do you need more help?X

Whitespace-changes is generally considered a bad thing.

 }

If the changes I've done sound OK, can one of your review them before I put them in the tree?
(Sorry for the delay - thought I'd sent this message days ago.)

Eivind Eklund perhaps(at)yes.no http://maybe.yes.no/perhaps/ eivind(at)freebsd.org Received on Tue Feb 18 01:29:30 1997

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 12:41:03 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library