|
From: Pascal B. <pb...@us...> - 2001-11-27 14:27:12
|
Update of /cvsroot/mpkg/mpkg/src
In directory usw-pr-cvs1:/tmp/cvs-serv17716/src
Modified Files:
dist.c
Log Message:
* dist.c (_get_line): Prefer this function to fgets, this one is
better optimize, and provide better debugging informations.
(get_line): Call _get_line.
Index: dist.c
===================================================================
RCS file: /cvsroot/mpkg/mpkg/src/dist.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** dist.c 2001/11/27 12:45:40 1.6
--- dist.c 2001/11/27 14:27:08 1.7
***************
*** 78,81 ****
--- 78,83 ----
#endif
+ #include <stdio.h>
+
/* That's could be better to delete this in the future. I prefere
create a header. */
***************
*** 203,208 ****
line++;
! LOGVERBOSE (printf (stderr, "Add dependency <%s>(%d).\n", temp->product,
! dist->num_depends));
/*
* Get the version strings, if any.
--- 205,210 ----
line++;
! LOGVERBOSE (printf (stderr, "Add dependency <%s>(%u).\n",
! (char *)temp->product, (int)dist->num_depends));
/*
* Get the version strings, if any.
***************
*** 1037,1040 ****
--- 1039,1064 ----
}
+ /* fgets is bogus, this function prevent against errors. */
+ static inline char *
+ _get_line (FILE *fp, char *buffer, int size)
+ {
+ register char c = 0;
+ register int fd = fileno(fp);
+ char *tmp = buffer;
+
+ /* Prevent against multiple modification. */
+ fflush (fp);
+
+ for (; read (fd, &c, 1) > 0 && c != '\n'; )
+ *(buffer++) = c;
+
+ *(buffer++) = '\n';
+ *buffer = '\0';
+
+ if (c == '\n')
+ return tmp;
+ return NULL;
+ }
+
/* Get a line from a file, filtering for uname lines. */
static char * /* O - String read or NULL at EOF */
***************
*** 1056,1061 ****
const char *var; /* Variable value */
! while (fgets (buffer, size, fp) != NULL)
! {
/* Skip comment and blank lines. */
if (buffer[0] == '#' || buffer[0] == '\n')
--- 1080,1085 ----
const char *var; /* Variable value */
! while (_get_line (fp, buffer, size) != NULL)
! {
/* Skip comment and blank lines. */
if (buffer[0] == '#' || buffer[0] == '\n')
***************
*** 1067,1070 ****
--- 1091,1095 ----
/* Yes, do filtering based on the OS (+version). */
*skip &= ~SKIP_SYSTEM;
+ LOGVERBOSE (fprintf (stderr, "Filtering %%system.\n"));
if (strcmp (buffer + 8, "all\n") != 0)
***************
*** 1131,1134 ****
--- 1156,1160 ----
/* Yes, do filtering based on the distribution format. */
*skip &= ~SKIP_FORMAT;
+ LOGVERBOSE (fprintf (stderr, "Filtering %%format.\n"));
if (strcmp (buffer + 8, "all\n") != 0)
***************
*** 1187,1190 ****
--- 1213,1218 ----
}
+ LOGVERBOSE (fprintf (stderr, "Substitute %%ifdef | %%elseifdef.\n"));
+
if (buffer[1] == 'e')
bufptr = buffer + 11;
***************
*** 1253,1256 ****
--- 1281,1286 ----
}
+ LOGVERBOSE (fprintf (stderr, "Substitute %%if | %%elseif.\n"));
+
if (buffer[1] == 'e')
bufptr = buffer + 8;
***************
*** 1341,1344 ****
--- 1371,1376 ----
}
+ LOGVERBOSE (fprintf (stderr, "Substitute %%else.\n"));
+
if (*skip & SKIP_IFSAT)
*skip |= SKIP_IF;
***************
*** 1360,1363 ****
--- 1392,1396 ----
}
+ LOGVERBOSE (fprintf (stderr, "Substitute %%endif.\n"));
*skip &= ~(SKIP_IF | SKIP_IFACTIVE | SKIP_IFSAT);
}
***************
*** 1370,1374 ****
return (buffer);
}
! }
return (NULL);
--- 1403,1407 ----
return (buffer);
}
! } /* End while */
return (NULL);
|