]> pd.if.org Git - zpackage/blob - zpm-parse.c
check for repo update temp file
[zpackage] / zpm-parse.c
1 #define _POSIX_C_SOURCE 2
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <unistd.h>
5
6 #include "zpm.h"
7
8 int main(int ac, char **av) {
9         int rel;
10         char name[256];
11         char ver[256];
12         int i;
13         int found;
14         int pname = 0;
15         int pver = 0;
16         int prel = 0;
17         int printed = 0;
18         int opt;
19         int pdefault = 1;
20         int eval = 0;
21
22         while ((opt = getopt(ac, av, "nvrE")) != -1) {
23                 switch (opt) {
24                         case 'n': pdefault = 0; pname = 1; break;
25                         case 'v': pdefault = 0; pver = 1; break;
26                         case 'r': pdefault = 0; prel = 1; break;
27                         case 'E': eval = 1; break;
28                         default:
29                                   fprintf(stderr, "zpm parse [-nvrE] ...\n");
30                                   exit(EXIT_FAILURE);
31                                   break;
32                 }
33         }
34
35         pname = pname || pdefault;
36         pver = pver || pdefault;
37         prel = prel || pdefault;
38
39         /* TODO need to quote single quotes for eval'able output */
40         for (i=optind; i<ac; i++) {
41                 printed = 0;
42                 found = zpm_parse_package(av[i], name, ver, &rel);
43                 if (found >= 1 && pname) {
44                         if (eval) {
45                                 printf("name='%s'\n", name);
46                         } else {
47                                 printf("%s", name);
48                                 printed++;
49                         }
50                 }
51                 if (found >= 2 && pver) {
52                         if (eval) {
53                                 printf("version='%s'\n", ver);
54                         } else {
55                                 printf("%s%s", printed ? " " : "", ver);
56                                 printed++;
57                         }
58                 }
59                 if (found >= 3 && prel) {
60                         if (eval) {
61                                 printf("release='%d'\n", rel);
62                         } else {
63                                 printf("%s%d", printed ? " " : "", rel);
64                                 printed++;
65                         }
66                 }
67                 if (printed) {
68                         putchar('\n');
69                 }
70                 if (!found) {
71                         exit(EXIT_FAILURE);
72                 }
73         }
74         return 0;
75 }