3
0

diff.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini diff implementation for busybox, adapted from OpenBSD diff.
  4. *
  5. * Copyright (C) 2006 by Robert Sullivan <cogito.ergo.cogito@hotmail.com>
  6. * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
  7. *
  8. * Sponsored in part by the Defense Advanced Research Projects
  9. * Agency (DARPA) and Air Force Research Laboratory, Air Force
  10. * Materiel Command, USAF, under agreement number F39502-99-1-0512.
  11. *
  12. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  13. */
  14. #include "libbb.h"
  15. // #define FSIZE_MAX 32768
  16. /* NOINLINEs added to prevent gcc from merging too much into diffreg()
  17. * (it bites more than it can (efficiently) chew). */
  18. /*
  19. * Output flags
  20. */
  21. enum {
  22. /* Print a header/footer between files */
  23. /* D_HEADER = 1, - unused */
  24. /* Treat file as empty (/dev/null) */
  25. D_EMPTY1 = 2 * ENABLE_FEATURE_DIFF_DIR,
  26. D_EMPTY2 = 4 * ENABLE_FEATURE_DIFF_DIR,
  27. };
  28. /*
  29. * Status values for print_status() and diffreg() return values
  30. * Guide:
  31. * D_SAME - files are the same
  32. * D_DIFFER - files differ
  33. * D_BINARY - binary files differ
  34. * D_COMMON - subdirectory common to both dirs
  35. * D_ONLY - file only exists in one dir
  36. * D_ISDIR1 - path1 a dir, path2 a file
  37. * D_ISDIR2 - path1 a file, path2 a dir
  38. * D_ERROR - error occurred
  39. * D_SKIPPED1 - skipped path1 as it is a special file
  40. * D_SKIPPED2 - skipped path2 as it is a special file
  41. */
  42. #define D_SAME 0
  43. #define D_DIFFER (1 << 0)
  44. #define D_BINARY (1 << 1)
  45. #define D_COMMON (1 << 2)
  46. /*#define D_ONLY (1 << 3) - unused */
  47. #define D_ISDIR1 (1 << 4)
  48. #define D_ISDIR2 (1 << 5)
  49. #define D_ERROR (1 << 6)
  50. #define D_SKIPPED1 (1 << 7)
  51. #define D_SKIPPED2 (1 << 8)
  52. /* Command line options */
  53. #define FLAG_a (1 << 0)
  54. #define FLAG_b (1 << 1)
  55. #define FLAG_d (1 << 2)
  56. #define FLAG_i (1 << 3)
  57. #define FLAG_L (1 << 4)
  58. #define FLAG_N (1 << 5)
  59. #define FLAG_q (1 << 6)
  60. #define FLAG_r (1 << 7)
  61. #define FLAG_s (1 << 8)
  62. #define FLAG_S (1 << 9)
  63. #define FLAG_t (1 << 10)
  64. #define FLAG_T (1 << 11)
  65. #define FLAG_U (1 << 12)
  66. #define FLAG_w (1 << 13)
  67. struct cand {
  68. int x;
  69. int y;
  70. int pred;
  71. };
  72. struct line {
  73. int serial;
  74. int value;
  75. };
  76. /*
  77. * The following struct is used to record change information
  78. * doing a "context" or "unified" diff. (see routine "change" to
  79. * understand the highly mnemonic field names)
  80. */
  81. struct context_vec {
  82. int a; /* start line in old file */
  83. int b; /* end line in old file */
  84. int c; /* start line in new file */
  85. int d; /* end line in new file */
  86. };
  87. #define g_read_buf bb_common_bufsiz1
  88. struct globals {
  89. bool anychange;
  90. smallint exit_status;
  91. int opt_U_context;
  92. size_t max_context; /* size of context_vec_start */
  93. USE_FEATURE_DIFF_DIR(int dl_count;)
  94. USE_FEATURE_DIFF_DIR(char **dl;)
  95. char *opt_S_start;
  96. const char *label1;
  97. const char *label2;
  98. int *J; /* will be overlaid on class */
  99. int clen;
  100. int pref, suff; /* length of prefix and suffix */
  101. int nlen[2];
  102. int slen[2];
  103. int clistlen; /* the length of clist */
  104. struct cand *clist; /* merely a free storage pot for candidates */
  105. long *ixnew; /* will be overlaid on nfile[1] */
  106. long *ixold; /* will be overlaid on klist */
  107. struct line *nfile[2];
  108. struct line *sfile[2]; /* shortened by pruning common prefix/suffix */
  109. struct context_vec *context_vec_start;
  110. struct context_vec *context_vec_end;
  111. struct context_vec *context_vec_ptr;
  112. char *tempname1, *tempname2;
  113. struct stat stb1, stb2;
  114. };
  115. #define G (*ptr_to_globals)
  116. #define anychange (G.anychange )
  117. #define exit_status (G.exit_status )
  118. #define opt_U_context (G.opt_U_context )
  119. #define max_context (G.max_context )
  120. #define dl_count (G.dl_count )
  121. #define dl (G.dl )
  122. #define opt_S_start (G.opt_S_start )
  123. #define label1 (G.label1 )
  124. #define label2 (G.label2 )
  125. #define J (G.J )
  126. #define clen (G.clen )
  127. #define pref (G.pref )
  128. #define suff (G.suff )
  129. #define nlen (G.nlen )
  130. #define slen (G.slen )
  131. #define clistlen (G.clistlen )
  132. #define clist (G.clist )
  133. #define ixnew (G.ixnew )
  134. #define ixold (G.ixold )
  135. #define nfile (G.nfile )
  136. #define sfile (G.sfile )
  137. #define context_vec_start (G.context_vec_start )
  138. #define context_vec_end (G.context_vec_end )
  139. #define context_vec_ptr (G.context_vec_ptr )
  140. #define stb1 (G.stb1 )
  141. #define stb2 (G.stb2 )
  142. #define tempname1 (G.tempname1 )
  143. #define tempname2 (G.tempname2 )
  144. #define INIT_G() do { \
  145. SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
  146. opt_U_context = 3; \
  147. max_context = 64; \
  148. } while (0)
  149. #if ENABLE_FEATURE_DIFF_DIR
  150. static void print_only(const char *path, const char *entry)
  151. {
  152. printf("Only in %s: %s\n", path, entry);
  153. }
  154. #endif
  155. static void print_status(int val, char *_path1, char *_path2)
  156. {
  157. /*const char *const _entry = entry ? entry : "";*/
  158. /*char *const _path1 = entry ? concat_path_file(path1, _entry) : path1;*/
  159. /*char *const _path2 = entry ? concat_path_file(path2, _entry) : path2;*/
  160. switch (val) {
  161. /* case D_ONLY:
  162. print_only(path1, entry);
  163. break;
  164. */
  165. case D_COMMON:
  166. printf("Common subdirectories: %s and %s\n", _path1, _path2);
  167. break;
  168. case D_BINARY:
  169. printf("Binary files %s and %s differ\n", _path1, _path2);
  170. break;
  171. case D_DIFFER:
  172. if (option_mask32 & FLAG_q)
  173. printf("Files %s and %s differ\n", _path1, _path2);
  174. break;
  175. case D_SAME:
  176. if (option_mask32 & FLAG_s)
  177. printf("Files %s and %s are identical\n", _path1, _path2);
  178. break;
  179. case D_ISDIR1:
  180. printf("File %s is a %s while file %s is a %s\n",
  181. _path1, "directory", _path2, "regular file");
  182. break;
  183. case D_ISDIR2:
  184. printf("File %s is a %s while file %s is a %s\n",
  185. _path1, "regular file", _path2, "directory");
  186. break;
  187. case D_SKIPPED1:
  188. printf("File %s is not a regular file or directory and was skipped\n",
  189. _path1);
  190. break;
  191. case D_SKIPPED2:
  192. printf("File %s is not a regular file or directory and was skipped\n",
  193. _path2);
  194. break;
  195. }
  196. /*
  197. if (entry) {
  198. free(_path1);
  199. free(_path2);
  200. }
  201. */
  202. }
  203. /* Read line, return its nonzero hash. Return 0 if EOF.
  204. *
  205. * Hash function taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578.
  206. */
  207. static ALWAYS_INLINE int fiddle_sum(int sum, int t)
  208. {
  209. return sum * 127 + t;
  210. }
  211. static int readhash(FILE *fp)
  212. {
  213. int i, t, space;
  214. int sum;
  215. sum = 1;
  216. space = 0;
  217. i = 0;
  218. if (!(option_mask32 & (FLAG_b | FLAG_w))) {
  219. while ((t = getc(fp)) != '\n') {
  220. if (t == EOF) {
  221. if (i == 0)
  222. return 0;
  223. break;
  224. }
  225. sum = fiddle_sum(sum, t);
  226. i = 1;
  227. }
  228. } else {
  229. while (1) {
  230. switch (t = getc(fp)) {
  231. case '\t':
  232. case '\r':
  233. case '\v':
  234. case '\f':
  235. case ' ':
  236. space = 1;
  237. continue;
  238. default:
  239. if (space && !(option_mask32 & FLAG_w)) {
  240. i = 1;
  241. space = 0;
  242. }
  243. sum = fiddle_sum(sum, t);
  244. i = 1;
  245. continue;
  246. case EOF:
  247. if (i == 0)
  248. return 0;
  249. /* FALLTHROUGH */
  250. case '\n':
  251. break;
  252. }
  253. break;
  254. }
  255. }
  256. /*
  257. * There is a remote possibility that we end up with a zero sum.
  258. * Zero is used as an EOF marker, so return 1 instead.
  259. */
  260. return (sum == 0 ? 1 : sum);
  261. }
  262. /* Our diff implementation is using seek.
  263. * When we meet non-seekable file, we must make a temp copy.
  264. */
  265. static char *make_temp(FILE *f, struct stat *sb)
  266. {
  267. char *name;
  268. int fd;
  269. if (S_ISREG(sb->st_mode) || S_ISBLK(sb->st_mode))
  270. return NULL;
  271. name = xstrdup("/tmp/difXXXXXX");
  272. fd = mkstemp(name);
  273. if (fd < 0)
  274. bb_perror_msg_and_die("mkstemp");
  275. if (bb_copyfd_eof(fileno(f), fd) < 0) {
  276. clean_up:
  277. unlink(name);
  278. xfunc_die(); /* error message is printed by bb_copyfd_eof */
  279. }
  280. fstat(fd, sb);
  281. close(fd);
  282. if (freopen(name, "r+", f) == NULL) {
  283. bb_perror_msg("freopen");
  284. goto clean_up;
  285. }
  286. return name;
  287. }
  288. /*
  289. * Check to see if the given files differ.
  290. * Returns 0 if they are the same, 1 if different, and -1 on error.
  291. */
  292. static NOINLINE int files_differ(FILE *f1, FILE *f2)
  293. {
  294. size_t i, j;
  295. /* Prevent making copies for "/dev/null" (too common) */
  296. /* Deal with input from pipes etc */
  297. tempname1 = make_temp(f1, &stb1);
  298. tempname2 = make_temp(f2, &stb2);
  299. if (stb1.st_size != stb2.st_size) {
  300. return 1;
  301. }
  302. while (1) {
  303. i = fread(g_read_buf, 1, COMMON_BUFSIZE/2, f1);
  304. j = fread(g_read_buf + COMMON_BUFSIZE/2, 1, COMMON_BUFSIZE/2, f2);
  305. if (i != j)
  306. return 1;
  307. if (i == 0)
  308. return (ferror(f1) || ferror(f2)) ? -1 : 0;
  309. if (memcmp(g_read_buf,
  310. g_read_buf + COMMON_BUFSIZE/2, i) != 0)
  311. return 1;
  312. }
  313. }
  314. static void prepare(int i, FILE *fp /*, off_t filesize*/)
  315. {
  316. struct line *p;
  317. int h;
  318. size_t j, sz;
  319. rewind(fp);
  320. /*sz = (filesize <= FSIZE_MAX ? filesize : FSIZE_MAX) / 25;*/
  321. /*if (sz < 100)*/
  322. sz = 100;
  323. p = xmalloc((sz + 3) * sizeof(p[0]));
  324. j = 0;
  325. while ((h = readhash(fp)) != 0) { /* while not EOF */
  326. if (j == sz) {
  327. sz = sz * 3 / 2;
  328. p = xrealloc(p, (sz + 3) * sizeof(p[0]));
  329. }
  330. p[++j].value = h;
  331. }
  332. nlen[i] = j;
  333. nfile[i] = p;
  334. }
  335. static void prune(void)
  336. {
  337. int i, j;
  338. for (pref = 0; pref < nlen[0] && pref < nlen[1] &&
  339. nfile[0][pref + 1].value == nfile[1][pref + 1].value; pref++)
  340. continue;
  341. for (suff = 0; suff < nlen[0] - pref && suff < nlen[1] - pref &&
  342. nfile[0][nlen[0] - suff].value == nfile[1][nlen[1] - suff].value;
  343. suff++)
  344. continue;
  345. for (j = 0; j < 2; j++) {
  346. sfile[j] = nfile[j] + pref;
  347. slen[j] = nlen[j] - pref - suff;
  348. for (i = 0; i <= slen[j]; i++)
  349. sfile[j][i].serial = i;
  350. }
  351. }
  352. static void equiv(struct line *a, int n, struct line *b, int m, int *c)
  353. {
  354. int i, j;
  355. i = j = 1;
  356. while (i <= n && j <= m) {
  357. if (a[i].value < b[j].value)
  358. a[i++].value = 0;
  359. else if (a[i].value == b[j].value)
  360. a[i++].value = j;
  361. else
  362. j++;
  363. }
  364. while (i <= n)
  365. a[i++].value = 0;
  366. b[m + 1].value = 0;
  367. j = 0;
  368. while (++j <= m) {
  369. c[j] = -b[j].serial;
  370. while (b[j + 1].value == b[j].value) {
  371. j++;
  372. c[j] = b[j].serial;
  373. }
  374. }
  375. c[j] = -1;
  376. }
  377. static int isqrt(int n)
  378. {
  379. int y, x;
  380. if (n == 0)
  381. return 0;
  382. x = 1;
  383. do {
  384. y = x;
  385. x = n / x;
  386. x += y;
  387. x /= 2;
  388. } while ((x - y) > 1 || (x - y) < -1);
  389. return x;
  390. }
  391. static int newcand(int x, int y, int pred)
  392. {
  393. struct cand *q;
  394. if (clen == clistlen) {
  395. clistlen = clistlen * 11 / 10;
  396. clist = xrealloc(clist, clistlen * sizeof(struct cand));
  397. }
  398. q = clist + clen;
  399. q->x = x;
  400. q->y = y;
  401. q->pred = pred;
  402. return clen++;
  403. }
  404. static int search(int *c, int k, int y)
  405. {
  406. int i, j, l, t;
  407. if (clist[c[k]].y < y) /* quick look for typical case */
  408. return k + 1;
  409. i = 0;
  410. j = k + 1;
  411. while (1) {
  412. l = i + j;
  413. if ((l >>= 1) <= i)
  414. break;
  415. t = clist[c[l]].y;
  416. if (t > y)
  417. j = l;
  418. else if (t < y)
  419. i = l;
  420. else
  421. return l;
  422. }
  423. return l + 1;
  424. }
  425. static int stone(int *a, int n, int *b, int *c)
  426. {
  427. int i, k, y, j, l;
  428. int oldc, tc, oldl;
  429. unsigned int numtries;
  430. #if ENABLE_FEATURE_DIFF_MINIMAL
  431. const unsigned int bound =
  432. (option_mask32 & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n));
  433. #else
  434. const unsigned int bound = MAX(256, isqrt(n));
  435. #endif
  436. k = 0;
  437. c[0] = newcand(0, 0, 0);
  438. for (i = 1; i <= n; i++) {
  439. j = a[i];
  440. if (j == 0)
  441. continue;
  442. y = -b[j];
  443. oldl = 0;
  444. oldc = c[0];
  445. numtries = 0;
  446. do {
  447. if (y <= clist[oldc].y)
  448. continue;
  449. l = search(c, k, y);
  450. if (l != oldl + 1)
  451. oldc = c[l - 1];
  452. if (l <= k) {
  453. if (clist[c[l]].y <= y)
  454. continue;
  455. tc = c[l];
  456. c[l] = newcand(i, y, oldc);
  457. oldc = tc;
  458. oldl = l;
  459. numtries++;
  460. } else {
  461. c[l] = newcand(i, y, oldc);
  462. k++;
  463. break;
  464. }
  465. } while ((y = b[++j]) > 0 && numtries < bound);
  466. }
  467. return k;
  468. }
  469. static void unravel(int p)
  470. {
  471. struct cand *q;
  472. int i;
  473. for (i = 0; i <= nlen[0]; i++)
  474. J[i] = i <= pref ? i : i > nlen[0] - suff ? i + nlen[1] - nlen[0] : 0;
  475. for (q = clist + p; q->y != 0; q = clist + q->pred)
  476. J[q->x + pref] = q->y + pref;
  477. }
  478. static void unsort(struct line *f, int l, int *b)
  479. {
  480. int *a, i;
  481. a = xmalloc((l + 1) * sizeof(int));
  482. for (i = 1; i <= l; i++)
  483. a[f[i].serial] = f[i].value;
  484. for (i = 1; i <= l; i++)
  485. b[i] = a[i];
  486. free(a);
  487. }
  488. static int skipline(FILE *f)
  489. {
  490. int i, c;
  491. for (i = 1; (c = getc(f)) != '\n' && c != EOF; i++)
  492. continue;
  493. return i;
  494. }
  495. /*
  496. * Check does double duty:
  497. * 1. ferret out any fortuitous correspondences due
  498. * to confounding by hashing (which result in "jackpot")
  499. * 2. collect random access indexes to the two files
  500. */
  501. static NOINLINE void check(FILE *f1, FILE *f2)
  502. {
  503. int i, j, jackpot, c, d;
  504. long ctold, ctnew;
  505. rewind(f1);
  506. rewind(f2);
  507. j = 1;
  508. ixold[0] = ixnew[0] = 0;
  509. jackpot = 0;
  510. ctold = ctnew = 0;
  511. for (i = 1; i <= nlen[0]; i++) {
  512. if (J[i] == 0) {
  513. ixold[i] = ctold += skipline(f1);
  514. continue;
  515. }
  516. while (j < J[i]) {
  517. ixnew[j] = ctnew += skipline(f2);
  518. j++;
  519. }
  520. if (option_mask32 & (FLAG_b | FLAG_w | FLAG_i)) {
  521. while (1) {
  522. c = getc(f1);
  523. d = getc(f2);
  524. /*
  525. * GNU diff ignores a missing newline
  526. * in one file if bflag || wflag.
  527. */
  528. if ((option_mask32 & (FLAG_b | FLAG_w))
  529. && ((c == EOF && d == '\n') || (c == '\n' && d == EOF))
  530. ) {
  531. break;
  532. }
  533. ctold++;
  534. ctnew++;
  535. if ((option_mask32 & FLAG_b) && isspace(c) && isspace(d)) {
  536. do {
  537. if (c == '\n')
  538. break;
  539. ctold++;
  540. c = getc(f1);
  541. } while (isspace(c));
  542. do {
  543. if (d == '\n')
  544. break;
  545. ctnew++;
  546. d = getc(f2);
  547. } while (isspace(d));
  548. } else if (option_mask32 & FLAG_w) {
  549. while (isspace(c) && c != '\n') {
  550. c = getc(f1);
  551. ctold++;
  552. }
  553. while (isspace(d) && d != '\n') {
  554. d = getc(f2);
  555. ctnew++;
  556. }
  557. }
  558. if (c != d) {
  559. jackpot++;
  560. J[i] = 0;
  561. if (c != '\n' && c != EOF)
  562. ctold += skipline(f1);
  563. if (d != '\n' && c != EOF)
  564. ctnew += skipline(f2);
  565. break;
  566. }
  567. if (c == '\n' || c == EOF)
  568. break;
  569. }
  570. } else {
  571. while (1) {
  572. ctold++;
  573. ctnew++;
  574. c = getc(f1);
  575. d = getc(f2);
  576. if (c != d) {
  577. J[i] = 0;
  578. if (c != '\n' && c != EOF)
  579. ctold += skipline(f1);
  580. /* was buggy? "if (d != '\n' && c != EOF)" */
  581. if (d != '\n' && d != EOF)
  582. ctnew += skipline(f2);
  583. break;
  584. }
  585. if (c == '\n' || c == EOF)
  586. break;
  587. }
  588. }
  589. ixold[i] = ctold;
  590. ixnew[j] = ctnew;
  591. j++;
  592. }
  593. for (; j <= nlen[1]; j++)
  594. ixnew[j] = ctnew += skipline(f2);
  595. }
  596. /* shellsort CACM #201 */
  597. static void sort(struct line *a, int n)
  598. {
  599. struct line *ai, *aim, w;
  600. int j, m = 0, k;
  601. if (n == 0)
  602. return;
  603. for (j = 1; j <= n; j *= 2)
  604. m = 2 * j - 1;
  605. for (m /= 2; m != 0; m /= 2) {
  606. k = n - m;
  607. for (j = 1; j <= k; j++) {
  608. for (ai = &a[j]; ai > a; ai -= m) {
  609. aim = &ai[m];
  610. if (aim < ai)
  611. break; /* wraparound */
  612. if (aim->value > ai[0].value
  613. || (aim->value == ai[0].value && aim->serial > ai[0].serial)
  614. ) {
  615. break;
  616. }
  617. w.value = ai[0].value;
  618. ai[0].value = aim->value;
  619. aim->value = w.value;
  620. w.serial = ai[0].serial;
  621. ai[0].serial = aim->serial;
  622. aim->serial = w.serial;
  623. }
  624. }
  625. }
  626. }
  627. static void uni_range(int a, int b)
  628. {
  629. if (a < b)
  630. printf("%d,%d", a, b - a + 1);
  631. else if (a == b)
  632. printf("%d", b);
  633. else
  634. printf("%d,0", b);
  635. }
  636. static void fetch(long *f, int a, int b, FILE *lb, int ch)
  637. {
  638. int i, j, c, lastc, col, nc;
  639. if (a > b)
  640. return;
  641. for (i = a; i <= b; i++) {
  642. fseek(lb, f[i - 1], SEEK_SET);
  643. nc = f[i] - f[i - 1];
  644. if (ch != '\0') {
  645. putchar(ch);
  646. if (option_mask32 & FLAG_T)
  647. putchar('\t');
  648. }
  649. col = 0;
  650. for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
  651. c = getc(lb);
  652. if (c == EOF) {
  653. printf("\n\\ No newline at end of file\n");
  654. return;
  655. }
  656. if (c == '\t' && (option_mask32 & FLAG_t)) {
  657. do {
  658. putchar(' ');
  659. } while (++col & 7);
  660. } else {
  661. putchar(c);
  662. col++;
  663. }
  664. }
  665. }
  666. }
  667. #if ENABLE_FEATURE_DIFF_BINARY
  668. static int asciifile(FILE *f)
  669. {
  670. int i, cnt;
  671. if (option_mask32 & FLAG_a)
  672. return 1;
  673. rewind(f);
  674. cnt = fread(g_read_buf, 1, COMMON_BUFSIZE, f);
  675. for (i = 0; i < cnt; i++) {
  676. if (!isprint(g_read_buf[i])
  677. && !isspace(g_read_buf[i])
  678. ) {
  679. return 0;
  680. }
  681. }
  682. return 1;
  683. }
  684. #else
  685. #define asciifile(f) 1
  686. #endif
  687. /* dump accumulated "unified" diff changes */
  688. static void dump_unified_vec(FILE *f1, FILE *f2)
  689. {
  690. struct context_vec *cvp = context_vec_start;
  691. int lowa, upb, lowc, upd;
  692. int a, b, c, d;
  693. char ch;
  694. if (context_vec_start > context_vec_ptr)
  695. return;
  696. b = d = 0; /* gcc */
  697. lowa = MAX(1, cvp->a - opt_U_context);
  698. upb = MIN(nlen[0], context_vec_ptr->b + opt_U_context);
  699. lowc = MAX(1, cvp->c - opt_U_context);
  700. upd = MIN(nlen[1], context_vec_ptr->d + opt_U_context);
  701. printf("@@ -");
  702. uni_range(lowa, upb);
  703. printf(" +");
  704. uni_range(lowc, upd);
  705. printf(" @@\n");
  706. /*
  707. * Output changes in "unified" diff format--the old and new lines
  708. * are printed together.
  709. */
  710. for (; cvp <= context_vec_ptr; cvp++) {
  711. a = cvp->a;
  712. b = cvp->b;
  713. c = cvp->c;
  714. d = cvp->d;
  715. /*
  716. * c: both new and old changes
  717. * d: only changes in the old file
  718. * a: only changes in the new file
  719. */
  720. if (a <= b && c <= d)
  721. ch = 'c';
  722. else
  723. ch = (a <= b) ? 'd' : 'a';
  724. #if 0
  725. switch (ch) {
  726. case 'c':
  727. // fetch() seeks!
  728. fetch(ixold, lowa, a - 1, f1, ' ');
  729. fetch(ixold, a, b, f1, '-');
  730. fetch(ixnew, c, d, f2, '+');
  731. break;
  732. case 'd':
  733. fetch(ixold, lowa, a - 1, f1, ' ');
  734. fetch(ixold, a, b, f1, '-');
  735. break;
  736. case 'a':
  737. fetch(ixnew, lowc, c - 1, f2, ' ');
  738. fetch(ixnew, c, d, f2, '+');
  739. break;
  740. }
  741. #else
  742. if (ch == 'c' || ch == 'd') {
  743. fetch(ixold, lowa, a - 1, f1, ' ');
  744. fetch(ixold, a, b, f1, '-');
  745. }
  746. if (ch == 'a')
  747. fetch(ixnew, lowc, c - 1, f2, ' ');
  748. if (ch == 'c' || ch == 'a')
  749. fetch(ixnew, c, d, f2, '+');
  750. #endif
  751. lowa = b + 1;
  752. lowc = d + 1;
  753. }
  754. fetch(ixnew, d + 1, upd, f2, ' ');
  755. context_vec_ptr = context_vec_start - 1;
  756. }
  757. static void print_header(const char *file1, const char *file2)
  758. {
  759. if (label1)
  760. printf("--- %s\n", label1);
  761. else
  762. printf("--- %s\t%s", file1, ctime(&stb1.st_mtime));
  763. if (label2)
  764. printf("+++ %s\n", label2);
  765. else
  766. printf("+++ %s\t%s", file2, ctime(&stb2.st_mtime));
  767. }
  768. /*
  769. * Indicate that there is a difference between lines a and b of the from file
  770. * to get to lines c to d of the to file. If a is greater than b then there
  771. * are no lines in the from file involved and this means that there were
  772. * lines appended (beginning at b). If c is greater than d then there are
  773. * lines missing from the to file.
  774. */
  775. static void change(char *file1, FILE *f1, char *file2, FILE *f2,
  776. int a, int b, int c, int d)
  777. {
  778. if ((a > b && c > d) || (option_mask32 & FLAG_q)) {
  779. anychange = 1;
  780. return;
  781. }
  782. /*
  783. * Allocate change records as needed.
  784. */
  785. if (context_vec_ptr == context_vec_end - 1) {
  786. ptrdiff_t offset = context_vec_ptr - context_vec_start;
  787. max_context <<= 1;
  788. context_vec_start = xrealloc(context_vec_start,
  789. max_context * sizeof(struct context_vec));
  790. context_vec_end = context_vec_start + max_context;
  791. context_vec_ptr = context_vec_start + offset;
  792. }
  793. if (anychange == 0) {
  794. /*
  795. * Print the context/unidiff header first time through.
  796. */
  797. print_header(file1, file2);
  798. } else if (a > context_vec_ptr->b + (2 * opt_U_context) + 1
  799. && c > context_vec_ptr->d + (2 * opt_U_context) + 1
  800. ) {
  801. /*
  802. * If this change is more than 'context' lines from the
  803. * previous change, dump the record and reset it.
  804. */
  805. // dump_unified_vec() seeks!
  806. dump_unified_vec(f1, f2);
  807. }
  808. context_vec_ptr++;
  809. context_vec_ptr->a = a;
  810. context_vec_ptr->b = b;
  811. context_vec_ptr->c = c;
  812. context_vec_ptr->d = d;
  813. anychange = 1;
  814. }
  815. static void output(char *file1, FILE *f1, char *file2, FILE *f2)
  816. {
  817. /* Note that j0 and j1 can't be used as they are defined in math.h.
  818. * This also allows the rather amusing variable 'j00'... */
  819. int m, i0, i1, j00, j01;
  820. rewind(f1);
  821. rewind(f2);
  822. m = nlen[0];
  823. J[0] = 0;
  824. J[m + 1] = nlen[1] + 1;
  825. for (i0 = 1; i0 <= m; i0 = i1 + 1) {
  826. while (i0 <= m && J[i0] == J[i0 - 1] + 1)
  827. i0++;
  828. j00 = J[i0 - 1] + 1;
  829. i1 = i0 - 1;
  830. while (i1 < m && J[i1 + 1] == 0)
  831. i1++;
  832. j01 = J[i1 + 1] - 1;
  833. J[i1] = j01;
  834. // change() seeks!
  835. change(file1, f1, file2, f2, i0, i1, j00, j01);
  836. }
  837. if (m == 0) {
  838. // change() seeks!
  839. change(file1, f1, file2, f2, 1, 0, 1, nlen[1]);
  840. }
  841. if (anychange != 0 && !(option_mask32 & FLAG_q)) {
  842. // dump_unified_vec() seeks!
  843. dump_unified_vec(f1, f2);
  844. }
  845. }
  846. /*
  847. * The following code uses an algorithm due to Harold Stone,
  848. * which finds a pair of longest identical subsequences in
  849. * the two files.
  850. *
  851. * The major goal is to generate the match vector J.
  852. * J[i] is the index of the line in file1 corresponding
  853. * to line i in file0. J[i] = 0 if there is no
  854. * such line in file1.
  855. *
  856. * Lines are hashed so as to work in core. All potential
  857. * matches are located by sorting the lines of each file
  858. * on the hash (called "value"). In particular, this
  859. * collects the equivalence classes in file1 together.
  860. * Subroutine equiv replaces the value of each line in
  861. * file0 by the index of the first element of its
  862. * matching equivalence in (the reordered) file1.
  863. * To save space equiv squeezes file1 into a single
  864. * array member in which the equivalence classes
  865. * are simply concatenated, except that their first
  866. * members are flagged by changing sign.
  867. *
  868. * Next the indices that point into member are unsorted into
  869. * array class according to the original order of file0.
  870. *
  871. * The cleverness lies in routine stone. This marches
  872. * through the lines of file0, developing a vector klist
  873. * of "k-candidates". At step i a k-candidate is a matched
  874. * pair of lines x,y (x in file0, y in file1) such that
  875. * there is a common subsequence of length k
  876. * between the first i lines of file0 and the first y
  877. * lines of file1, but there is no such subsequence for
  878. * any smaller y. x is the earliest possible mate to y
  879. * that occurs in such a subsequence.
  880. *
  881. * Whenever any of the members of the equivalence class of
  882. * lines in file1 matable to a line in file0 has serial number
  883. * less than the y of some k-candidate, that k-candidate
  884. * with the smallest such y is replaced. The new
  885. * k-candidate is chained (via pred) to the current
  886. * k-1 candidate so that the actual subsequence can
  887. * be recovered. When a member has serial number greater
  888. * that the y of all k-candidates, the klist is extended.
  889. * At the end, the longest subsequence is pulled out
  890. * and placed in the array J by unravel
  891. *
  892. * With J in hand, the matches there recorded are
  893. * checked against reality to assure that no spurious
  894. * matches have crept in due to hashing. If they have,
  895. * they are broken, and "jackpot" is recorded--a harmless
  896. * matter except that a true match for a spuriously
  897. * mated line may now be unnecessarily reported as a change.
  898. *
  899. * Much of the complexity of the program comes simply
  900. * from trying to minimize core utilization and
  901. * maximize the range of doable problems by dynamically
  902. * allocating what is needed and reusing what is not.
  903. * The core requirements for problems larger than somewhat
  904. * are (in words) 2*length(file0) + length(file1) +
  905. * 3*(number of k-candidates installed), typically about
  906. * 6n words for files of length n.
  907. */
  908. /* NB: files can be not REGular. The only sure thing that they
  909. * are not both DIRectories. */
  910. static unsigned diffreg(char *file1, char *file2, int flags)
  911. {
  912. int *member; /* will be overlaid on nfile[1] */
  913. int *class; /* will be overlaid on nfile[0] */
  914. int *klist; /* will be overlaid on nfile[0] after class */
  915. FILE *f1;
  916. FILE *f2;
  917. unsigned rval;
  918. int i;
  919. anychange = 0;
  920. context_vec_ptr = context_vec_start - 1;
  921. tempname1 = tempname2 = NULL;
  922. /* Is any of them a directory? Then it's simple */
  923. if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode))
  924. return (S_ISDIR(stb1.st_mode) ? D_ISDIR1 : D_ISDIR2);
  925. /* None of them are directories */
  926. rval = D_SAME;
  927. if (flags & D_EMPTY1)
  928. /* can't be stdin, but xfopen_stdin() is smaller code */
  929. f1 = xfopen_stdin(bb_dev_null);
  930. else
  931. f1 = xfopen_stdin(file1);
  932. if (flags & D_EMPTY2)
  933. f2 = xfopen_stdin(bb_dev_null);
  934. else
  935. f2 = xfopen_stdin(file2);
  936. /* NB: if D_EMPTY1/2 is set, other file is always a regular file,
  937. * not pipe/fifo/chardev/etc - D_EMPTY is used by "diff -r" only,
  938. * and it never diffs non-ordinary files in subdirs. */
  939. if (!(flags & (D_EMPTY1 | D_EMPTY2))) {
  940. /* Quick check whether they are different */
  941. /* NB: copies non-REG files to tempfiles and fills tempname1/2 */
  942. i = files_differ(f1, f2);
  943. if (i != 1) { /* not different? */
  944. if (i != 0) /* error? */
  945. exit_status |= 2;
  946. goto closem;
  947. }
  948. }
  949. if (!asciifile(f1) || !asciifile(f2)) {
  950. rval = D_BINARY;
  951. exit_status |= 1;
  952. goto closem;
  953. }
  954. // Rewind inside!
  955. prepare(0, f1 /*, stb1.st_size*/);
  956. prepare(1, f2 /*, stb2.st_size*/);
  957. prune();
  958. sort(sfile[0], slen[0]);
  959. sort(sfile[1], slen[1]);
  960. member = (int *) nfile[1];
  961. equiv(sfile[0], slen[0], sfile[1], slen[1], member);
  962. member = xrealloc(member, (slen[1] + 2) * sizeof(int));
  963. class = (int *) nfile[0];
  964. unsort(sfile[0], slen[0], class);
  965. class = xrealloc(class, (slen[0] + 2) * sizeof(int));
  966. klist = xmalloc((slen[0] + 2) * sizeof(int));
  967. clen = 0;
  968. clistlen = 100;
  969. clist = xmalloc(clistlen * sizeof(struct cand));
  970. i = stone(class, slen[0], member, klist);
  971. free(member);
  972. free(class);
  973. J = xrealloc(J, (nlen[0] + 2) * sizeof(int));
  974. unravel(klist[i]);
  975. free(clist);
  976. free(klist);
  977. ixold = xrealloc(ixold, (nlen[0] + 2) * sizeof(long));
  978. ixnew = xrealloc(ixnew, (nlen[1] + 2) * sizeof(long));
  979. // Rewind inside!
  980. check(f1, f2);
  981. // Rewind inside!
  982. output(file1, f1, file2, f2);
  983. closem:
  984. if (anychange) {
  985. exit_status |= 1;
  986. if (rval == D_SAME)
  987. rval = D_DIFFER;
  988. }
  989. fclose_if_not_stdin(f1);
  990. fclose_if_not_stdin(f2);
  991. if (tempname1) {
  992. unlink(tempname1);
  993. free(tempname1);
  994. }
  995. if (tempname2) {
  996. unlink(tempname2);
  997. free(tempname2);
  998. }
  999. return rval;
  1000. }
  1001. #if ENABLE_FEATURE_DIFF_DIR
  1002. static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
  1003. {
  1004. int flags = 0; /*D_HEADER;*/
  1005. int val;
  1006. char *fullpath1 = NULL; /* if -N */
  1007. char *fullpath2 = NULL;
  1008. if (path1)
  1009. fullpath1 = concat_path_file(dir1, path1);
  1010. if (path2)
  1011. fullpath2 = concat_path_file(dir2, path2);
  1012. if (!fullpath1 || stat(fullpath1, &stb1) != 0) {
  1013. flags |= D_EMPTY1;
  1014. memset(&stb1, 0, sizeof(stb1));
  1015. if (path2) {
  1016. free(fullpath1);
  1017. fullpath1 = concat_path_file(dir1, path2);
  1018. }
  1019. }
  1020. if (!fullpath2 || stat(fullpath2, &stb2) != 0) {
  1021. flags |= D_EMPTY2;
  1022. memset(&stb2, 0, sizeof(stb2));
  1023. stb2.st_mode = stb1.st_mode;
  1024. if (path1) {
  1025. free(fullpath2);
  1026. fullpath2 = concat_path_file(dir2, path1);
  1027. }
  1028. }
  1029. if (stb1.st_mode == 0)
  1030. stb1.st_mode = stb2.st_mode;
  1031. if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
  1032. printf("Common subdirectories: %s and %s\n", fullpath1, fullpath2);
  1033. goto ret;
  1034. }
  1035. if (!S_ISREG(stb1.st_mode) && !S_ISDIR(stb1.st_mode))
  1036. val = D_SKIPPED1;
  1037. else if (!S_ISREG(stb2.st_mode) && !S_ISDIR(stb2.st_mode))
  1038. val = D_SKIPPED2;
  1039. else {
  1040. /* Both files are either REGular or DIRectories */
  1041. val = diffreg(fullpath1, fullpath2, flags);
  1042. }
  1043. print_status(val, fullpath1, fullpath2 /*, NULL*/);
  1044. ret:
  1045. free(fullpath1);
  1046. free(fullpath2);
  1047. }
  1048. #endif
  1049. #if ENABLE_FEATURE_DIFF_DIR
  1050. /* This function adds a filename to dl, the directory listing. */
  1051. static int add_to_dirlist(const char *filename,
  1052. struct stat *sb ATTRIBUTE_UNUSED,
  1053. void *userdata,
  1054. int depth ATTRIBUTE_UNUSED)
  1055. {
  1056. /* +2: with space for eventual trailing NULL */
  1057. dl = xrealloc(dl, (dl_count+2) * sizeof(dl[0]));
  1058. dl[dl_count] = xstrdup(filename + (int)(ptrdiff_t)userdata);
  1059. dl_count++;
  1060. return TRUE;
  1061. }
  1062. /* This returns a sorted directory listing. */
  1063. static char **get_recursive_dirlist(char *path)
  1064. {
  1065. dl_count = 0;
  1066. dl = xzalloc(sizeof(dl[0]));
  1067. /* We need to trim root directory prefix.
  1068. * Using void *userdata to specify its length,
  1069. * add_to_dirlist will remove it. */
  1070. if (option_mask32 & FLAG_r) {
  1071. recursive_action(path, ACTION_RECURSE|ACTION_FOLLOWLINKS,
  1072. add_to_dirlist, /* file_action */
  1073. NULL, /* dir_action */
  1074. (void*)(strlen(path) + 1),
  1075. 0);
  1076. } else {
  1077. DIR *dp;
  1078. struct dirent *ep;
  1079. dp = warn_opendir(path);
  1080. while ((ep = readdir(dp))) {
  1081. if (!strcmp(ep->d_name, "..") || LONE_CHAR(ep->d_name, '.'))
  1082. continue;
  1083. add_to_dirlist(ep->d_name, NULL, (void*)(int)0, 0);
  1084. }
  1085. closedir(dp);
  1086. }
  1087. /* Sort dl alphabetically. */
  1088. qsort_string_vector(dl, dl_count);
  1089. dl[dl_count] = NULL;
  1090. return dl;
  1091. }
  1092. static void diffdir(char *p1, char *p2)
  1093. {
  1094. char **dirlist1, **dirlist2;
  1095. char *dp1, *dp2;
  1096. int pos;
  1097. /* Check for trailing slashes. */
  1098. dp1 = last_char_is(p1, '/');
  1099. if (dp1 != NULL)
  1100. *dp1 = '\0';
  1101. dp2 = last_char_is(p2, '/');
  1102. if (dp2 != NULL)
  1103. *dp2 = '\0';
  1104. /* Get directory listings for p1 and p2. */
  1105. dirlist1 = get_recursive_dirlist(p1);
  1106. dirlist2 = get_recursive_dirlist(p2);
  1107. /* If -S was set, find the starting point. */
  1108. if (opt_S_start) {
  1109. while (*dirlist1 != NULL && strcmp(*dirlist1, opt_S_start) < 0)
  1110. dirlist1++;
  1111. while (*dirlist2 != NULL && strcmp(*dirlist2, opt_S_start) < 0)
  1112. dirlist2++;
  1113. if ((*dirlist1 == NULL) || (*dirlist2 == NULL))
  1114. bb_error_msg(bb_msg_invalid_arg, "NULL", "-S");
  1115. }
  1116. /* Now that both dirlist1 and dirlist2 contain sorted directory
  1117. * listings, we can start to go through dirlist1. If both listings
  1118. * contain the same file, then do a normal diff. Otherwise, behaviour
  1119. * is determined by whether the -N flag is set. */
  1120. while (*dirlist1 != NULL || *dirlist2 != NULL) {
  1121. dp1 = *dirlist1;
  1122. dp2 = *dirlist2;
  1123. pos = dp1 == NULL ? 1 : (dp2 == NULL ? -1 : strcmp(dp1, dp2));
  1124. if (pos == 0) {
  1125. do_diff(p1, dp1, p2, dp2);
  1126. dirlist1++;
  1127. dirlist2++;
  1128. } else if (pos < 0) {
  1129. if (option_mask32 & FLAG_N)
  1130. do_diff(p1, dp1, p2, NULL);
  1131. else
  1132. print_only(p1, dp1);
  1133. dirlist1++;
  1134. } else {
  1135. if (option_mask32 & FLAG_N)
  1136. do_diff(p1, NULL, p2, dp2);
  1137. else
  1138. print_only(p2, dp2);
  1139. dirlist2++;
  1140. }
  1141. }
  1142. }
  1143. #endif
  1144. int diff_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  1145. int diff_main(int argc ATTRIBUTE_UNUSED, char **argv)
  1146. {
  1147. int gotstdin = 0;
  1148. char *f1, *f2;
  1149. llist_t *L_arg = NULL;
  1150. INIT_G();
  1151. /* exactly 2 params; collect multiple -L <label>; -U N */
  1152. opt_complementary = "=2:L::U+";
  1153. getopt32(argv, "abdiL:NqrsS:tTU:wu"
  1154. "p" /* ignored (for compatibility) */,
  1155. &L_arg, &opt_S_start, &opt_U_context);
  1156. /*argc -= optind;*/
  1157. argv += optind;
  1158. while (L_arg) {
  1159. if (label1 && label2)
  1160. bb_show_usage();
  1161. if (label1) /* then label2 is NULL */
  1162. label2 = label1;
  1163. label1 = llist_pop(&L_arg);
  1164. }
  1165. /*
  1166. * Do sanity checks, fill in stb1 and stb2 and call the appropriate
  1167. * driver routine. Both drivers use the contents of stb1 and stb2.
  1168. */
  1169. f1 = argv[0];
  1170. f2 = argv[1];
  1171. if (LONE_DASH(f1)) {
  1172. fstat(STDIN_FILENO, &stb1);
  1173. gotstdin++;
  1174. } else
  1175. xstat(f1, &stb1);
  1176. if (LONE_DASH(f2)) {
  1177. fstat(STDIN_FILENO, &stb2);
  1178. gotstdin++;
  1179. } else
  1180. xstat(f2, &stb2);
  1181. if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode)))
  1182. bb_error_msg_and_die("can't compare stdin to a directory");
  1183. if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
  1184. #if ENABLE_FEATURE_DIFF_DIR
  1185. diffdir(f1, f2);
  1186. return exit_status;
  1187. #else
  1188. bb_error_msg_and_die("no support for directory comparison");
  1189. #endif
  1190. }
  1191. if (S_ISDIR(stb1.st_mode)) { /* "diff dir file" */
  1192. /* NB: "diff dir dir2/dir3/file" must become
  1193. * "diff dir/file dir2/dir3/file" */
  1194. char *slash = strrchr(f2, '/');
  1195. f1 = concat_path_file(f1, slash ? slash + 1 : f2);
  1196. xstat(f1, &stb1);
  1197. }
  1198. if (S_ISDIR(stb2.st_mode)) {
  1199. char *slash = strrchr(f1, '/');
  1200. f2 = concat_path_file(f2, slash ? slash + 1 : f1);
  1201. xstat(f2, &stb2);
  1202. }
  1203. /* diffreg can get non-regular files here,
  1204. * they are not both DIRestories */
  1205. print_status((gotstdin > 1 ? D_SAME : diffreg(f1, f2, 0)),
  1206. f1, f2 /*, NULL*/);
  1207. return exit_status;
  1208. }