configurator: HAVE_SECTION_START_STOP
[ccan] / ccan / bdelta / _info
1 #include <string.h>
2 #include "config.h"
3
4 /**
5  * bdelta - Generate and apply binary deltas
6  *
7  * This library takes two strings containing binary data, and produces a
8  * "patch" that can be applied to the first one to produce the second one.
9  * It can be used to save bandwidth and disk space when many texts differing
10  * by a small number of bytes need to be transmitted or stored.
11  *
12  * Patches produced by this version of the library can be applied using future
13  * versions, but not past versions.
14  *
15  * bdelta implements the algorithm described in
16  * An O(ND) Difference Algorithm and Its Variations by Eugene W. Myers.
17  * Because its memory usage and expected running time are O(N + D^2),
18  * it works well only when the strings differ by a small number of bytes.
19  * This implementation stops trying when the strings differ by more than
20  * 1000 bytes, and falls back to producing a patch that simply emits the new
21  * string.
22  *
23  * Thus, bdelta does not save any space when given two strings that differ by
24  * more than 1000 bytes.  This may be improved in a future version of the
25  * library.
26  *
27  * Example:
28  *      #include <ccan/bdelta/bdelta.h>
29  *      #include <stdio.h>
30  *      #include <stdlib.h>
31  *      #include <string.h>
32  *
33  *      static void gulp(const char *filename, void **data_out, size_t *size_out);
34  *
35  *      static int usage(const char *prog)
36  *      {
37  *              fprintf(
38  *                      stderr,
39  *                      "Usage: %s diff  <old> <new>    >  <patch>\n"
40  *                      "       %s patch <old> <patch>  >  <new>\n",
41  *                      prog, prog
42  *              );
43  *              return 1;
44  *      }
45  *
46  *      int main(int argc, char *argv[])
47  *      {
48  *              void *old, *new_, *patch;
49  *              size_t old_size, new_size, patch_size;
50  *              BDELTAcode rc;
51  *
52  *              if (argc != 4)
53  *                      return usage(argv[0]);
54  *
55  *              if (strcmp(argv[1], "diff") == 0) {
56  *                      gulp(argv[2], &old, &old_size);
57  *                      gulp(argv[3], &new_, &new_size);
58  *
59  *                      rc = bdelta_diff(old, old_size, new_, new_size, &patch, &patch_size);
60  *                      if (rc != BDELTA_OK) {
61  *                              bdelta_perror("bdelta_diff", rc);
62  *                              return 1;
63  *                      }
64  *
65  *                      if (fwrite(patch, 1, patch_size, stdout) != patch_size) {
66  *                              perror("stdout");
67  *                              return 1;
68  *                      }
69  *              } else if (strcmp(argv[1], "patch") == 0) {
70  *                      gulp(argv[2], &old, &old_size);
71  *                      gulp(argv[3], &patch, &patch_size);
72  *
73  *                      rc = bdelta_patch(old, old_size, patch, patch_size, &new_, &new_size);
74  *                      if (rc != BDELTA_OK) {
75  *                              bdelta_perror("bdelta_patch", rc);
76  *                              return 1;
77  *                      }
78  *
79  *                      if (fwrite(new_, 1, new_size, stdout) != new_size) {
80  *                              perror("stdout");
81  *                              return 1;
82  *                      }
83  *              } else {
84  *                      return usage(argv[0]);
85  *              }
86  *
87  *              free(old);
88  *              free(new_);
89  *              free(patch);
90  *              return 0;
91  *      }
92  *
93  *      static void gulp(const char *filename, void **data_out, size_t *size_out)
94  *      {
95  *              FILE *f = fopen(filename, "rb");
96  *              size_t size = 0;
97  *              size_t alloc = 16;
98  *              char *data = malloc(alloc);
99  *
100  *              if (f == NULL || data == NULL)
101  *                      goto error;
102  *
103  *              for (;;) {
104  *                      size += fread(data + size, 1, alloc - size, f);
105  *                      if (size < alloc) {
106  *                              if (!feof(f))
107  *                                      goto error;
108  *                              break;
109  *                      }
110  *                      data = realloc(data, alloc *= 2);
111  *                      if (data == NULL)
112  *                              goto error;
113  *              }
114  *
115  *              if (fclose(f) != 0)
116  *                      goto error;
117  *
118  *              *data_out = data;
119  *              *size_out = size;
120  *              return;
121  *
122  *      error:
123  *              perror(filename);
124  *              exit(EXIT_FAILURE);
125  *      }
126  *
127  * Author: Joey Adams <joeyadams3.14159@gmail.com>
128  * License: MIT
129  * Version: 0.1.1
130  */
131 int main(int argc, char *argv[])
132 {
133         /* Expect exactly one argument */
134         if (argc != 2)
135                 return 1;
136
137         if (strcmp(argv[1], "depends") == 0) {
138                 /* Nothing */
139                 return 0;
140         }
141
142         return 1;
143 }