Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

write unsolved packages as: <package> -

  • Loading branch information...
commit 3a5b791c4882047f565497dd6a9930b6398588da 1 parent 12a77f1
@rtomayko authored
Showing with 66 additions and 11 deletions.
  1. +1 −1  Makefile
  2. +65 −10 rpg-solve-fast.c
View
2  Makefile
@@ -83,7 +83,7 @@ rpg-sh-setup: config.sh munge.rb
rpg: config.sh munge.rb
rpg-solve-fast: rpg-solve-fast.o strnatcmp.o
- printf "%13s %-30s" "[LD]" "$@"
+ printf "%13s %-30s" "[LINK]" "$@"
$(CC) $(CFLAGS) $(LDFLAGS) rpg-solve-fast.o strnatcmp.o -o $@
printf " OK\n"
View
75 rpg-solve-fast.c
@@ -16,6 +16,7 @@ enum OPER { lt, le, eq, ge, gt, st, err };
/* A package list entry. */
struct plent {
+ int found;
enum OPER oper;
char pack[100];
char vers[50];
@@ -101,6 +102,8 @@ plparse (FILE * stream)
while (1) {
lineno++;
pe = malloc(sizeof(struct plent));
+ pe->found = 0;
+ pe->next = NULL;
res = fscanf(stream, format, pe->pack, stroper, pe->vers);
if ( res == 3 ) {
@@ -110,12 +113,8 @@ plparse (FILE * stream)
break;
}
- pe->next = NULL;
- if ( ppe ) {
- ppe->next = pe;
- } else {
- pfe = pe;
- }
+ if ( ppe ) ppe->next = pe;
+ else pfe = pe;
ppe = pe;
}
@@ -123,6 +122,45 @@ plparse (FILE * stream)
return pfe;
}
+
+/* Mark all package list entries whose package name matches pack as found. */
+static inline void
+plmark (struct plent * pe, char * pack)
+{
+ int cmp;
+ for (; pe != NULL; pe = pe->next) {
+ cmp = strcmp(pe->pack, pack);
+ if (cmp == 0) {
+ pe->found = 1;
+ } else if (cmp < 0) {
+ continue;
+ } else {
+ break;
+ }
+ }
+}
+
+/* Remove entries marked as found from the list. */
+static struct plent *
+plpurge (struct plent * pe) {
+ struct plent * ptail = NULL,
+ * phead = NULL;
+
+ for (;pe != NULL; pe = pe->next) {
+ if ( pe->found ) continue;
+
+ if ( ptail )
+ ptail->next = pe;
+ else
+ phead = pe;
+
+ ptail = pe;
+ ptail->next = NULL;
+ }
+
+ return phead;
+}
+
/* Compare two versions. */
static inline int
verscmp(char const * v1, char const * v2)
@@ -184,10 +222,13 @@ pdxscan(FILE * stream, struct plent * pe)
if (pe == NULL) return;
}
- if (cmp == 0) {
- pvers = strsep(&pvers, " \n");
- if( pdxrun(ppack, pvers, pe) )
- printf("%s %s\n", ppack, pvers);
+ if (cmp > 0) continue;
+
+ pvers = strsep(&pvers, " \n");
+ if (pdxrun(ppack, pvers, pe)) {
+ if ( pe->found == 0 )
+ plmark(pe, ppack);
+ printf("%s %s\n", ppack, pvers);
}
}
}
@@ -199,10 +240,24 @@ int main (int argc, char *argv[])
int i;
for (i=1; i < argc; i++) {
+ if (pe == NULL)
+ break;
+
if ((fidx = fopen(argv[i], "r"))) {
pdxscan(fidx, pe);
fclose(fidx);
}
+
+ pe = plpurge(pe);
+ }
+
+ /* some packages were not found */
+ if ( pe ) {
+ while ( pe ) {
+ printf("%s -\n", pe->pack);
+ pe = pe->next;
+ }
+ return 1;
}
return 0;
Please sign in to comment.
Something went wrong with that request. Please try again.