cmp

en

This text is from my arcives. It may be out of date, but I thought it should be preserved.

cmp is a program, which compares files in two directories (or trees). That can be very useful, e.g. to examine in a backup, which files have been changed or rather are new.
With cmp it is also possible, to compare two files and display the differences (hex-dump).
With cmp and the device-handler (AmiNet:disk/misc/dev_hdl.lha) you can also compare disks/harddisks byte for byte.
Readme | Archive (67K Bytes)

Table of contents


Requirements AmigaOS 2.1 or better.

Installation Just copy the program and the documentation wherever you want.

Disclaimer
This software is subject to the "Standard Amiga FD-Software Copyright Note".
It is GIFTWARE/MAILWARE as defined in paragraph 4g/4b.
For more information please read "AFD-COPYRIGHT" (Version 1.4 or higher).
Usage Since V2.0 is cmp localized. All texts in this documentaion are the english ones. With the first two parameters you have to say cmp, what should be compared. The parameters can be:
  • two files: in this case the two files will be compared.
  • a file and a directory: in this case the file will be compared with a equal called file in the directory. From now on, this will be the same like the comparison of two files, in contrast to the comparison of two directories.
  • two directories or patterns: in this case all files (possibly matching the pattern) will be compared with equal called files in the 2nd directory and the other way round.
Notice: A file could not be compared with a pattern. A comparison can have one of the following results:
Q: The two files are equal.
L: The two files are different in length.
C: The two files have the same length, but they are different in contents.
D: The two files have different length and contents.
A: A file/directory in the directory (-tree) B does not exist in A.
B: A file/directory in the directory (-tree) A does not exist in B.
W: It was tried to compare a file with a directory (object wrong type).
E: Another error has occured, e.g. a read error.
S: A is a truncated version of B *L
T: B is a truncated version of A *L
O: File Comment mismatch *O
P: Protection-Bits mismatch *P
0: Errormessage 212: Object wrong type (A=DIR, B=FILE) *W
1: Errormessage 212: Object wrong type (A=FILE, B=DIR) *W
2: Errormessage 205: Object not found (A=DIR, B=-) *A
3: Errormessage 205: Object not found (A=FILE, B=-) *A
4: Errormessage 205: Object not found (A=-, B=DIR) *B
5: Errormessage 205: Object not found (A=-, B=FILE) *B
6: Errormessage 205: Object not found (A=NEWDIR) *N
7: Errormessage 205: Object not found (A=NEWFILE) *N
8: Errormessage 205: Object not found (B=NEWDIR) *N
9: Errormessage 205: Object not found (B=NEWFILE) *N

*L, *W, *A, *B = With the option DETAIL will be the results LWAB replaced by the more exact one ST012345. *N = New results, added by the options NEWDIR/NEWFILE. *O = New results, added by the option COMMENT. *P = New results, added by the option PROTBITS. If some of the new results are missing in the following text: They will be handled like the simple versions. And N will be handled like A/B. Only the most important parameters will be mentioned here, the detailed usage of the parameters is described on the following page. All parameters are written bold and BIG. For cmp is an extended help available: Call cmp (in a CLI) with parameter "?" and enter at the following request another "?". The output from cmp results like this:
If the two files should be compared in difference (C,D) and an output of the difference is desired, a hex-dump of the different lines will be displayed. The differences will be marked white ( example ). The hex-dump can be switched on/off with the option DUMP. For a comparison of two files, the hex-dump will be switched on by default.
A hex-dump can be aborted with CTRL-D, but the comparison will be continued.
If the option DUMP is switched off, the files, which have different length will not be compared whether they have different contents. Also see CHECKD. After the hex-dump-output (if switched on) the filename and the result will be displayed in plain text. The text is, depending on the result, one of the following:
Q: [no text]
L: Difference in length
C: Difference in contents
D: Difference in length&contents
A,B,W,E: The corresponding error messages (see above), since workbench 2.1 localized.

More results you'll find here . Notice: Two files with equal sizes and dates, will be shown by cmp as equal, and the contents will not be compared. Also see CHECKD. The output can be adjusted completely with the option LFORMAT to the wishes of the user. After completion of cmp the returncode will be set as follows:
0: All files are equal.
5: One or more files are different (LCDOP).
6: The file A is a truncated version of file B (S).
7: The file B is a truncated version of file A (T).
10: One or more files could not be found / are of wrong type (ABW).
15: Another error had occured (E).
20: A serious error occured / the comparison would be aborted.

The values 5-15 will be only set, if the output will be made (see SHOW). Also see NORC. After the comparison of directories a short statistic will be displayed. Also see NOSTAT. With the option SHOW you can specify, which messages should be displayed. With the option ABORT you can say cmp, on which results the comparison should be aborted. With the option ALL you can switch on, that cmp should recursively compare the two directories. Normally, links to directories will be completely ignored. For this, read HLINK and SLINK. For more detailes about the syntax of the options, please read the next page.
Parameters The syntax for the usage of cmp is:
cmp A/A,B/A,ALL/S,SHOW/K,ABORT/K,DUMP/N,CHECKD/S,ONLYA/S,HLINK/S,SLINK/S, LFORMAT/F,NOSTAT/S,NORC/S,DETAIL/S,NEWDIR/N,NEWFILE/S,REVADIR/S,REVBDIR/S, DUMPALL/S,SKIPFIRSTNBYTES=SKIP/K/N,COMMENT=COM/K/N
When you start cmp with parameter "?", the above shown syntaxline will be shown to you and you can still enter your parameters. If you enter at this moment another "?", the extended help will be displayed to you.
A/A The first file/directory/pattern (see usage).
B/A The second file/directory/pattern (see usage).
ALL/S The two directories will be compared recursively.
SHOW/K Which outputs should be made or rather should be suppressed. The (to be given) parameter is a string, which contains the outputs. The outputs will be specified with the results (QLCDABWE). The meaning of the individual results is described in the part usage. A leading "~" negates the input. By default, everything will be displayed.
ABORT/K On which results the comparison should be aborted. The details are corresponding to the details of SHOW. By default, it will be never aborted.
DUMP/N Whether a hex-dump should be displayed. In case of a positive number, max. DUMP different lines will be displayed. Equal lines will be never displayed. In case of a negative number, all different lines will be displayed. In case of zero, the hex-dump will be disabled. When comparing two files, DUMP will be set to -1, by default. Otherwise to 0.
A hex-dump can be aborted with CTRL-D, but the comparison will be continued.
CHECKD/S If two compared files are different in length, by default they will be not checked, whether they are different in contents (up to the length difference). Besides, files will not be checked, if they are of equal date and length. With this option you can activate this feature, which mostly makes no sense and only costs time. If the DUMP option is different from 0, it will be activated automatically.
ONLYA/S Normally, comparing two directories, all files (directories) in the 1st tree will be compared with the 2nd and the other way. If this option is activated, only the 1st directory will be searched and compared with the 2nd. Files/directories, which are in the 2nd directory but not in the 1st one, will not be displayed/searched.
HLINK/S With links it is possible to build a cyclic structure, which will be not recognized during a comparison, and will make cmp running in a loop forever. Because of this, normally cmp will not follow hardlinks to directories. Activating this option, it is possible to follow hardlinks to directories.
Links to files will be checked.
SLINK/S Like HLINK, whether softlinks to directories should be followed.
LFORMAT/F This is the probably most extensive option of cmp. With it, the look of the output can be changed. But not the look of the hex-dump. How it exactly works, you can read on the following page.
NOSTAT/S Switches off the statistics.
NORC/S If this option is enabled the resultcode is always 0, except of serious errors or user abort.
This option is intended for the usage of cmp in DOpus and ARexx scripts, because there may occur problems or undesired effects with a non-zero return code.
DETAIL/S With this option the results ABLW will be more detailed.
The new results for L: (And their also new RC-Codes.)
S: A is a truncated version of B
T: B is a truncated version of A
The new results for W:
0: Errormessage 212: Object wrong type (A=DIR, B=FILE)
1: Errormessage 212: Object wrong type (A=FILE, B=DIR)
The new results for AB:
2: Errormessage 205: Object not found (A=DIR, B=-)
3: Errormessage 205: Object not found (A=FILE, B=-)
4: Errormessage 205: Object not found (A=-, B=DIR)
5: Errormessage 205: Object not found (A=-, B=FILE)
NEWDIR/N Also directory structures, which doesn't exists in the other tree will be displayed. You have to specify a maximal depth. A depth of <= 0 will mean unlimited! This option is only useful together with ALL. There are new results (68) for this Option. ( see output )
An example for this option can be found here .
NEWFILE/S Displays also the files in the directories, added by NEWDIR.
There are new results (79) for this Option. ( see Output )
An example for this option can be found here .
REVADIR/S,REVBDIR/S With the options NEWDIR and NEWFILE normally the new directory will be displayed first, and then it's contents. With this option you can reverse it.
An example for this option can be found here .
DUMPALL/S All lines - not only different - will be displayed.
SKIPFIRSTNBYTES=SKIP/K/N The first N bytes of each file will be skipped. You'll receive an result L if the file is too short.
COMMENT=COM/K/N
  • COM<0: Only file comments will be compared. (no contents, ...)
  • COM>0: If two files are identical, the file comments will be checked.
  • COM=0: No comparison of the file comments. (default)

If COM is 1 or -1 the comparison is case insensitive, else it's case sensitive. In case of a mismatch the result O will be returned.
PROTBITS/S If switched on, protection bits mismatches are displayed.
Output The output can be changed by the option LFORMAT. The rest of the parameters will be automatically interpreted by cmp as LFORMAT. Therefore it is not necessary, to enter LFORMAT and it is also not necessary, to quote the option. The following options are supported in the output:
%n Name
%p Path (QLCD: relative to base, ABWE: absolute)
%t Path (QLCD: relative to base, ABWE: with a leading "A:"/"B:")
%P Path + Name (see %p)
%T Path + Name (see %t)
%e Error as text
%E Error as number
%r Result (QLCDABWE)
%R Path relative to base
%a Absolute path in A
%b Absolute path in B
%% "%"
*n, *N A new line will be inserted
*e, *E An ESC character will be inserted
** "*"

The results have the following error numbers/texts:
Q: 700 ""
L: 701 "Difference in length"
C: 702 "Difference in contents"
D: 703 "Difference in length&contents"
A: 704 Errormessage 205: Object not found
B: 705 Errormessage 205: Object not found
S: 706 "A is a truncated version of B"
T: 707 "B is a truncated version of A"
O: 708 "Difference in comment"
P: 709 "Difference in protection bits"
W: 212 Errormessage 212: Object wrong type
E: xxx Errormessage xxx
0: 800 Errormessage 212: Object wrong type (A=DIR, B=FILE)
1: 801 Errormessage 212: Object wrong type (A=FILE, B=DIR)
2: 802 Errormessage 205: Object not found (A=DIR, B=-)
3: 803 Errormessage 205: Object not found (A=FILE, B=-)
4: 804 Errormessage 205: Object not found (A=-, B=DIR)
5: 805 Errormessage 205: Object not found (A=-, B=FILE)
6: 806 Errormessage 205: Object not found (A=NEWDIR)
7: 807 Errormessage 205: Object not found (A=NEWFILE)
8: 808 Errormessage 205: Object not found (B=NEWDIR)
9: 809 Errormessage 205: Object not found (B=NEWFILE)

Like in C usual, it is possible to specify the options. This will be done by inserting format options between "%" and the option. A number says, how much characters long the option should be displayed. If the number is negative, the output is left justified, otherwise right. With a leading "!" as format option, the output will be truncated to the specified width of the following number. In case of %p,%t,%P,%T the output will be cut of left, using %n,%e right. In case of %E,%r this option will be ignored. History
2.0 2000-11-26
  • Added PROTBITS
  • cmp is now GIFTWARE/MAILWARE
  • Localized (now OS 2.1 is required)
  • German Catalog available
1.9 2000-10-08
  • Added COMMENT
  • Changed the doctument format to HTML
1.8 2000-02-11
  • Updated the documentation
1.7 2000-01-25
  • Improved DETAIL (S/T results)
1.6 -internal-
  • Added DETAIL, NEWDIR, NEWFILE, REVADIR, REVBDIR, DUMPALL, SKIPFIRSTNBYTES
1.5 1999-04-07
  • The 020-Version is now residentable (useful for EqFiles.rexx)
  • use "lha x -a" to extract the archive, or "protect cmp p add" to make it residentable
  • E-Mail/HomePage has changed!
1.4 1997-05-21
  • Outputs statistics when comparing directories
  • Option NOSTAT switches off the statistics
  • Added the option NORC
  • Removed two bugs in the 68000 version
1.3 1997-04-16
  • Removed a new bug
  • 68000 version added again (V1.2 was only 020+)
  • Colored the output a little bit more
  • Corrected the guide/readme
  • If two files are of equal sizes and dates, they will be shown as equal
1.2 1997-04-10
  • Fixed a little bug
  • Recompiled with StormC and the stormamiga.lib (smaller & faster)
1.1 1997-02-28
  • Improved the option DUMP
1.0 1997-02-18
  • First release


Tanks to Andreas Mayer-Gürr
for proof-reading, correction of the guide and beta testing Nils Goers
for an idea for the option DUMP Fulvio Peruggi
for some bug reports and the idea with the colors, beta testing, much more ideas and for proof-reading Matthias Henze
for the stormamiga.lib, which I'am using since V1.2 Simon N Goodwin
for the idea of the date comparison Henry Sopko
for 68000 beta testing Thomas Chen
for the idea of the comment/protection bits comparison Dump Example
DUMP: Disk.info                   Test.info                   
0010: 00000002 00000A40 .......@  00000002 0000099B ........
0018: 00000CBF 00000106 ...¿....  000001B6 00000017 ......
0020: 000003E9 00000A40 ...é...@  000003E9 0000099B ...é....
0028: 2C780004 2A4F226E ,x..*O"n  48E77EFE 24482400 Hç~þ$H$.
0030: 01144AA9 00AC6652 ..J©.¬fR  49F90000 00002C78 Iù....,x
0038: 41E9005C 2F084EAE Aé.\/.N®  000447F9 000005AC ..Gù...¬
Disk.info: Found 31 differences in contents&length until abort


Complex Example Here is a complex example, how to use cmp as an updater. The following ARexx script will modify the B-Tree that it is exactly like the A-Tree. Only all changed files will copied. It is an ARexx-Script, and it's (hopefully) a help. Without DETAIL it's not possible to distinguish between (missing/useless) dirs and files. More information at the end of the following listing. This is the listing of "update1.rexx".

/*
** Update only all neccesary files from dir A -> dir B
**                 ©1999/2000 ALeX Kazik
*/

/* IMPORTANT: the src/dst dir MUST end with a colon or slash and MUST NOT be empty! */

/* SOURCE directory */
src = 'a/'

/* DESTINATION directory */
dst = 'b/'

/* the script to create, and which will be executed */
script = 'T:script'

/* SKIP the first N bytes */
skip = 0

/* temporary file */
tmpfile = 'T:update.tmp'

/*
** The main-program
*/

ADDRESS COMMAND

cmp 'A="' || src || '" B="' || dst || '" all nostat norc skipfirstnbytes=' || SKIP ,
    || ' newdir=10 newfile revbdir detail lformat %r%R%n >"' || TMPFILE || '"'
IF RC >= 20 THEN DO
        SAY 'Error while executing cmp'
        EXIT RC
END

CALL OPEN(tmp, tmpfile, 'read')
CALL OPEN(scr, script, 'write')

eq = 0

DO UNTIL EOF(tmp)
  act = READCH(tmp, 1)
  file = READLN(tmp)
  IF act = '' THEN
    BREAK
  ELSE IF act = 'Q' THEN
    eq = eq + 1
  ELSE IF (act = 'A') | (act = '5') | (act = '9') THEN DO
    SAY 'File to remove: ' || file
    CALL WRITELN(scr, 'delete "' || dst || file || '" quiet')
  END
  ELSE IF (act = '4') | (act = '8') THEN DO
    SAY 'Dir to remove: ' || file
    CALL WRITELN(scr, 'delete "' || dst || file || '" quiet')
  END
  ELSE IF (act = 'B') | (act = '3') | (act = '7') THEN DO
    SAY 'New File: ' || file
    CALL WRITELN(scr, 'copy "' || src || file || '" "' || dst || file || '"')
  END
  ELSE IF (act = '2') | (act = '6') THEN DO
    SAY 'New Dir: ' || file
    CALL WRITELN(scr, 'makedir "' || dst || file || '"')
  END
  ELSE IF (act = 'E') | (act = '0') | (act = '1') THEN DO
    SAY 'Error/Warning at dir/file: ' || file
    EXIT 20
  END
  ELSE IF (act = 'L') | (act = 'C') | (act = 'D') | (act = 'S') | (act = 'T') THEN DO
    SAY 'File to Update: ' || file
    CALL WRITELN(scr, 'copy "' || src || file || '" "' || dst || file || '"')
  END
  ELSE DO
    SAY 'Unknown Symbol >' || act || '<'
    CALL CLOSE(tmp)
    CALL CLOSE(scr)
    EXIT 20
  END
END

SAY eq || ' Equal files.'

CALL CLOSE(tmp)
CALL CLOSE(scr)

/*
** executing the changes
*/

execute '"' || script || '"'

/*
** That's all.
*/

Ok. Did you now understand, for what I've created NEWDIR/NEWFILE? Not? Just remove DETAIL and examine the created files against those before... REVBDIR is used here, because the entries of a directory should be removed before the directory can be removed. This is only the simple version. The more powerful version can be found here: "update2.rexx". That version is also able to generate a FTP-Script, I use it to update my web-pages.

de

Dieser Text ist aus meinem Archiv. Er ist möglicherweise nicht mehr aktuell, aber ich dachte dass er erhalten werden sollte.

cmp ist ein Programm, welches Dateien in zwei Verzeichnissen (oder Bäumen) vergleicht. Dies kann sehr nützlich sein, um z.B. bei einem Backup zu untersuchen, welche Dateien sich geändert haben bzw. hinzugekommen sind. cmp ist auch in der Lage, zwei Dateien zu vergleichen und die Unterschiede darzustellen (Hex-Dump). Mit cmp und dem device-handler (AmiNet:disk/misc/dev_hdl.lha) können Sie auch Disketten und Festplatten Byte für Byte vergleichen.
Readme | Archive (67K Bytes)

Inhaltsverzeichnis


Systemvoraussetzung AmigaOS 2.1 oder höher.

Installation Kopieren Sie das Programm und die Dokumentation dahin, wo es Ihnen am liebsten ist.

Rechtliches
This software is subject to the "Standard Amiga FD-Software Copyright Note".
It is GIFTWARE/MAILWARE as defined in paragraph 4g/4b.
For more information please read "AFD-COPYRIGHT" (Version 1.4 or higher).
Benutzung Seit V2.0 ist cmp lokalisiert. Alle hier dargestellen texte, sind die englischen! Durch die ersten beiden Parameter muß cmp übergeben werden, was verglichen werden soll. Die Parameter können sein:
  • zwei Dateien: in diesem Fall werden die beiden Dateien verglichen.
  • eine Datei und ein Verzeichnis: in diesem Fall wird die Datei mit einer gleichnamigen Datei in dem Verzeichnis verglichen. Dies wird ab jetzt wie der Vergleich zweier Dateien angesehen, im Gegensatz zum Vergleich zweier Verzeichnisse.
  • zwei Verzeichnisse oder Pattern: in diesem Fall werden alle Dateien (evtl. auf die das Pattern paßt) mit gleichnamigen Dateien im zweiten Verzeichnis, und umgekehrt, verglichen.
Hinweis: Eine Datei kann nicht mit einem Pattern verglichen werden. Bei einem Vergleich können die folgenden Ereignisse eintreten:
Q: Die beiden Dateien sind gleich (equal).
L: Die beiden Dateien unterscheiden sich in der Länge (length).
C: Die beiden Dateien sind gleich lang, unterscheiden sich aber im Inhalt (contents).
D: Die beiden Dateien unterscheiden sich in Länge und Inhalt (different).
A: Eine Datei/Verzeichnis im Verzeichnis (-Baum) B gibt es nicht in A.
B: Eine Datei/Verzeichnis im Verzeichnis (-Baum) A gibt es nicht in B.
W: Es wurde versucht eine Datei mit einem Verzeichnis zu vergleichen (object wrong type).
E: Es trat ein sonstiger Fehler auf, z.B. ein Lesefehler (error).
S: Die Datei A ist eine verkürzte Version von Datei B (A is truncated). *L
T: Die Datei B ist eine verkürzte Version von Datei A (B is truncated). *L
O: Die Datei-Kommentare stimmen nicht überein (comment). *O
P: Die Protection-Bits stimmen nicht überein. *P
0: Fehlermeldung 212: Objekt ist nicht vom geforderten Typ (A=DIR, B=FILE) *W
1: Fehlermeldung 212: Objekt ist nicht vom geforderten Typ (A=FILE, B=DIR) *W
2: Fehlermeldung 205: Objekt nicht gefunden (A=DIR, B=-) *A
3: Fehlermeldung 205: Objekt nicht gefunden (A=FILE, B=-) *A
4: Fehlermeldung 205: Objekt nicht gefunden (A=-, B=DIR) *B
5: Fehlermeldung 205: Objekt nicht gefunden (A=-, B=FILE) *B
6: Fehlermeldung 205: Objekt nicht gefunden (A=NEWDIR) *N
7: Fehlermeldung 205: Objekt nicht gefunden (A=NEWFILE) *N
8: Fehlermeldung 205: Objekt nicht gefunden (B=NEWDIR) *N
9: Fehlermeldung 205: Objekt nicht gefunden (B=NEWFILE) *N

*L, *W, *A, *B = Durch die Aktivierung der Option DETAIL werden die Ergebnisse LWAB durch die präziseren ST012345 ersetzt. *N = Durch die Optionen NEWDIR/NEWFILE neu hinzugekommene Ereignisse. *O = Durch die Option COMMENT neu hinzugekommenes Ereignis. *P = Durch die Option PRTOBITS neu hinzugekommenes Ereignis. Wenn in folgenden Aufzählungen die neuen Optionen fehlen, werden sie wie ihre einfachere Variante gehandhabt. Wobei N wie A/B angesehen wird. Hier werden nun die wichtigsten Parameter angesprochen, die genaue Benutzung entnehmen Sie bitte der folgenden Seite. Alle Parameter sind fett und GROß geschrieben. Für cmp ist eine erweiterte Hilfe verfügbar: Rufen Sie cmp (in einem CLI) mit dem Parameter "?" auf und geben bei der folgenden Aufforderung noch ein "?" ein. Die Ausgabe von cmp ergibt sich wie folgt:
Wenn die beiden Dateien inhaltlich unterschieden werden sollen (C,D) und eine Ausgabe des Unterschiedes gewünscht wird, gibt ein Hex-Dump die unterschiedlichen Zeilen aus. Die Unterschiede werden weiß dargestellt ( Beispiel ). Dieser Hex-Dump kann durch die Option DUMP ein- und ausgeschaltet werden. Bei einem Vergleich zweier Dateien ist der Hex-Dump standardmäßig eingeschaltet.
Ein Hex-Dump kann mit CTRL-D abgebrochen werden, der Vergleich wird aber fortgesetzt.
Wenn die Option DUMP ausgeschaltet ist, werden die Dateien, die sich in der Länge unterscheiden nicht auf verschiedene Inhalte hin untersucht. Siehe auch CHECKD. Nach der Hex-Dump-Ausgabe (falls eingeschaltet) wird der Dateiname und das Ergebnis in Klartext ausgegeben. Der Text ist je nach Ergebnis einer der folgenden:
Q: [kein Text]
L: Difference in length
C: Difference in contents
D: Difference in length&contents
A,B,W,E: The corresponding error messages (see above), since workbench 2.1 localized.

Weitere Ereignisse finden Sie hier . Hinweis: Dateien die gleich lang sind und ein identisches Datum tragen, werden von cmp als gleich angesehen, und der Inhalt wird nicht untersucht. Siehe auch CHECKD. Die Ausgabe kann über die Option LFORMAT vollständig den Wünschen des Benutzers angepaßt werden. Nach Beendigung von cmp wird der Rückgabewert wie folgt gesetzt:
0: Alle Dateien sind gleich.
5: Eine oder mehrere Dateien sind unterschiedlich (LCDOP).
6: Die Datei A ist eine verkürzte Version von Datei B (S).
7: Die Datei B ist eine verkürzte Version von Datei A (T).
10: Eine oder mehrere Dateien wurden nicht gefunden / sind vom falschen Typ (ABW).
15: Ein sonstiger Fehler trat auf (E).
20: Ein schwerer Fehler trat auf / der Vergleich wurde abgebrochen.
Die Werte 5-15 werden nur gesetzt, wenn auch die Ausgabe gemacht wird (siehe SHOW). Siehe auch NORC. Nach einem Vergleich von Verzeichnissen wird eine kurze Statistik angezeigt. Siehe auch NOSTAT. Mit Hilfe der Option SHOW kann spezifiziert werden, welche Meldungen ausgegeben werden sollen. Durch die Option ABORT kann cmp mitgeteilt werden, bei welchen Ereignissen der Vergleich abgebrochen werden soll. Bei einem Vergleich zweier Verzeichnisse kann mit der Option ALL das rekursive Durchsuchen beider Verzeichnisbäume aktiviert werden. Normalerweise werden Links auf Verzeichnisse komplett ignoriert. Lesen Sie hierzu HLINK und SLINK. Die genaue Syntax der einzelnen Optionen entnehmen Sie bitte der folgenden Seite.
Parameter Die Syntax für die Benutzung von cmp ist:
cmp A/A,B/A,ALL/S,SHOW/K,ABORT/K,DUMP/N,CHECKD/S,ONLYA/S,HLINK/S,SLINK/S, LFORMAT/F,NOSTAT/S,NORC/S,DETAIL/S,NEWDIR/N,NEWFILE/S,REVADIR/S,REVBDIR/S, DUMPALL/S,SKIPFIRSTNBYTES=SKIP/K/N,COMMENT=COM/K/N
Rufen Sie cmp mit "?" als Parameter auf, bekommen Sie die obige Syntaxzeile angezeigt und können dann noch Ihre Parameter angeben. Wenn Sie an dieser Stelle noch ein "?" eingeben, bekommen Sie die erweiterte Hilfe angezeigt.
A/A Die erste Datei/Verzeichnis/Pattern (siehe Benutzung).
B/A Die zweite Datei/Verzeichnis/Pattern (siehe Benutzung).
ALL/S Die beiden Verzeichnisse werden rekursiv verglichen.
SHOW/K Welche Ausgaben gemacht werden bzw. unterdrückt werden sollen. Anzugeben ist ein String, der alle zu machenden Ausgaben enthält. Die Ausgaben werden durch das Ergebnis-Kürzel (QLCDABWE) spezifiziert. Die Bedeutung der einzelnen Kürzel ist im Kapitel Benutzung beschrieben. Ein vorangestelltes "~" negiert die Eingabe. Standardmäßig wird alles angezeigt.
ABORT/K Bei welchen Ergebnissen abgebrochen werden soll. Die Angaben entsprechen denen bei SHOW. Standardmäßig wird nie abgebrochen.
DUMP/N Ob ein Hex-Dump ausgegeben werden soll. Bei einer positiven Zahl werden max. DUMP unterschiedliche Zeilen ausgegeben. Gleiche Zeilen werden nie angezeigt. Durch die Angabe einer negativen Zahl werden alle Unterschiede ausgegeben. Bei Angabe von 0 wird der Hex-Dump ausgeschaltet. Bei einem Vergleich zweier Dateien ist die Standardeinstellung -1, sonst 0.
Ein Hex-Dump kann durch CTRL-D abgebrochen werden, der Vergleich wird aber fortgesetzt.
CHECKD/S Wenn zwei zu vergleichende Dateien eine unterschiedliche Länge haben, wird standardmäßig nicht untersucht, ob der Inhalt (bis zur Längendifferenz) gleich ist. Außerdem werden Dateien ebenfalls nicht untersucht, wenn Datum und Länge identisch sind. Mit dieser Option kann dies angeschaltet werden, macht aber meistens keinen Sinn und kostet nur Zeit. Diese Option wird automatisch aktiviert, wenn DUMP ungleich 0 ist.
ONLYA/S Im Normalfall werden bei einem Vergleich zweier Verzeichnisse alle Dateien (Verzeichnisse) in dem 1. Baum mit dem 2., und umgekehrt, verglichen. Bei eingeschalteter Option wird nur das 1. Verzeichnis durchsucht und mit dem 2. verglichen. Dateien/Verzeichnisse, die im 2. Verzeichnis auftauchen, aber nicht im 1., werden nicht angezeigt/durchsucht.
HLINK/S Da es durch Links möglich ist, eine zyklische Struktur zu erzeugen, die bei einem Vergleich nicht bemerkt wird, würde cmp im "Kreis" laufen, und nie enden. Deswegen werden Hardlinks auf Verzeichnisse normalerweise nicht verfolgt. Mit dieser Option kann das Verfolgen von Hardlinks auf Verzeichnisse aktiviert werden.
Links auf Dateien werden untersucht.
SLINK/S Wie HLINK, ob Softlinks auf Verzeichnisse verfolgt werden sollen.
LFORMAT/F Dies ist wohl die umfangreichste Option von cmp. Mit ihr kann das Aussehen der Ausgabe bestimmt werden. Allerdings nicht das Aussehen des Hex-Dumps. Wie dies genau funktioniert, lesen Sie auf der folgenden Seite.
NOSTAT/S Diese Option schaltet die Statistik aus.
NORC/S Wenn diese Option eingeschaltet ist, ist der Rückgabewert außer bei schweren Fehlern oder Benutzer-Abbruch, immer 0.
Diese Option ist speziell für die Benutzung von cmp in DOpus und ARexx-Skripts, da dort Probleme oder unerwünschte Effekte mit Rückgabewerten ungleich null auftreten können.
DETAIL/S Wenn diese Option angegeben wird, werden die Ergebnisse ABLW detailierter ausgegeben.
Hier die neuen Ereignisse für L: (Außerdem gibt es für diese beiden Fälle auch neue RC-Codes.)
S: Die Datei A ist eine verkürzte Version von Datei B (A is truncated).
T: Die Datei B ist eine verkürzte Version von Datei A (B is truncated).
Hier die neuen Ereignisse für W:
0: Fehlermeldung 212: Objekt ist nicht vom geforderten Typ (A=DIR, B=FILE)
1: Fehlermeldung 212: Objekt ist nicht vom geforderten Typ (A=FILE, B=DIR)
Hier die neuen Ereignisse für AB:
2: Fehlermeldung 205: Objekt nicht gefunden (A=DIR, B=-)
3: Fehlermeldung 205: Objekt nicht gefunden (A=FILE, B=-)
4: Fehlermeldung 205: Objekt nicht gefunden (A=-, B=DIR)
5: Fehlermeldung 205: Objekt nicht gefunden (A=-, B=FILE)
NEWDIR/N Es werden bis zur angegebenen Tiefe auch Verzeichnis-Strukturen, welche es im anderen Baum nicht gibt, ausgegeben. Nur sinvoll im Zusammenhang mit ALL. Eine Tiefe von <= 0 bedeutet unendlich! Hierfür gibt es neue Ereignisse ((68)). ( siehe Ausgabe )
Ein Beispiel für diese Option gibt es hier .
NEWFILE/S In den durch NEWDIR ausgegebenen Verzeichnissen werden auch Dateien ausgegeben. Hierfür gibt es neue Ereignisse ((79)). ( siehe Ausgabe )
Ein Beispiel für diese Option gibt es hier .
REVADIR/S, REVBDIR/S Normalerweise werden bei NEWDIR und NEWFILE zuerst das Verzeichnis und dann alle Einträge ausgegeben, hiermit wird dies umgedreht.
Ein Beispiel für diese Option gibt es hier .
DUMPALL/S Es werden nicht nur die unterschiedlichen Zeilen, sondern alle ausgegeben.
SKIPFIRSTNBYTES=SKIP/K/N Es werden die ersten N Bytes in jeder Datei übersprungen. Es wird das Ergebnis L ausgegeben, wenn die Datei zu kurz ist.
COMMENT=COM/K/N
  • COM<0: Es werden nur Datei-Kommentare untersucht. (keine Inhalte, ...)
  • COM>0: Es werden bei identischem Inhalt auch noch die Datei-Kommentare untersucht.
  • COM=0: Kein Vergleich der Datei-Kommentare. (Voreinstellung)

Wenn COM 1 bzw. -1 ist, wird groß/klein-Schreibung nicht beachtet, ansonsten schon. Im Fall einer Ungleichheit wird das Ergebnis O zurückgegeben.
PROTBITS/S Wenn angegeben werden unterschiede in den Protection-Bits auch ausgegeben.
Ausgabe Die Ausgabe kann durch die Option LFORMAT verändert werden. Der Rest der Parameter von cmp wird automatisch als LFORMAT interpretiert. Es ist also nicht nötig, LFORMAT anzugeben und es ist auch nicht nötig, den Parameter in Anführungszeichen einzufassen. Folgende Optionen werden in der Ausgabe unterstützt:
%n Name
%p Pfad (QLCD: ab Vergleich, ABWE: absolut)
%t Pfad (QLCD: ab Vergleich, ABWE: mit vorangestelltem "A:"/"B:")
%P Pfad + Name (siehe %p)
%T Pfad + Name (siehe %t)
%e Fehler als Text
%E Fehler als Nummer
%r Ergebnis (QLCDABWE)
%R Pfad ab Vergleich
%a Absoluter Pfad in A
%b Absoluter Pfad in B
%% "%"
*n, *N Eine neue Zeile wird eingefügt
*e, *E Ein ESC-Zeichen wird eingefügt
** "*"

Den Ergebnissen werden folgende Fehlernummern/Texte zugewiesen:
Q: 700 ""
L: 701 "Difference in length"
C: 702 "Difference in contents"
D: 703 "Difference in length&contents"
A: 704 Fehlermeldung 205: Objekt nicht gefunden
B: 705 Fehlermeldung 205: Objekt nicht gefunden
S: 706 "A is a truncated version of B"
T: 707 "B is a truncated version of A"
O: 708 "Difference in comment"
P: 709 "Difference in protection bits"
W: 212 Fehlermeldung 212: Objekt ist nicht vom geforderten Typ
E: xxx Fehlermeldung xxx
0: 800 Fehlermeldung 212: Objekt ist nicht vom geforderten Typ (A=DIR, B=FILE)
1: 801 Fehlermeldung 212: Objekt ist nicht vom geforderten Typ (A=FILE, B=DIR)
2: 802 Fehlermeldung 205: Objekt nicht gefunden (A=DIR, B=-)
3: 803 Fehlermeldung 205: Objekt nicht gefunden (A=FILE, B=-)
4: 804 Fehlermeldung 205: Objekt nicht gefunden (A=-, B=DIR)
5: 805 Fehlermeldung 205: Objekt nicht gefunden (A=-, B=FILE)
6: 806 Fehlermeldung 205: Objekt nicht gefunden (A=NEWDIR)
7: 807 Fehlermeldung 205: Objekt nicht gefunden (A=NEWFILE)
8: 808 Fehlermeldung 205: Objekt nicht gefunden (B=NEWDIR)
9: 809 Fehlermeldung 205: Objekt nicht gefunden (B=NEWFILE)

Wie in C üblich, können die Optionen noch spezifiziert werden. Dies geschieht durch das Einfügen von Format-Optionen zwischen "%" und der Option. Eine Zahl gibt an, wieviele Zeichen lang diese Option dargestellt werden soll. Wenn die Zahl negativ ist, erfolgt die Ausgabe linksbündig, sonst rechtsbündig. Mit der vorangestellten Format-Option "!" wird die Ausgabe auf die Breite der folgenden Zahl gekürzt. Im Falle von %p,%t,%P,%T wird links abgeschnitten, bei %n,%e rechts. Bei %E,%r wird diese Option ignoriert. History
2.0 2000-11-26
  • PROTBITS hinzugefügt
  • cmp is now GIFTWARE/MAILWARE
  • Lokalisiert (benötigt jetzt OS 2.1)
  • Deutscher Catalog verfügbar
1.9 2000-10-08
  • COMMENT hinzugefügt
  • Dokumentformat nach HTML gewechselt
1.8 2000-02-11
  • Dokumentation aktualisiert
1.7 2000-01-25
  • DETAIL (S/T Ergebnisse) verbessert
1.6 -internal-
  • DETAIL, NEWDIR, NEWFILE, REVADIR, REVBDIR, DUMPALL, SKIPFIRSTNBYTES hinzugefügt
1.5 1999-04-07
  • Die 020-Version ist nun resistentfähig (nützlich bei EqFiles.rexx)
  • Benutzen Sie "lha x -a" zum Entpacken des Archives, oder "protect cmp p add" um es resistentfähig zu machen
  • E-Mail/HomePage hat sich geändert!
1.4 1997-05-21
  • Ausgabe einer Statistik beim Vergleich zweier Verzeichnisse
  • Die Option NOSTAT schaltet die Statistik aus
  • Die Option NORC hinzugefügt
  • Zwei 68000er Fehler behoben
1.3 1997-04-16
  • Einen neu hinzugekommenen Bug behoben
  • 68000er Version wieder hinzugefügt (V1.2 war nur 020+)
  • Ausgabe noch etwas farbiger gemacht
  • Das Guide/Readme korrigiert
  • Wenn zwei Dateien gleich lang sind und das Datum identisch ist, werden sie als gleich angesehen
1.2 1997-04-10
  • Kleinen Bug behoben
  • Mit StormC und der stormamiga.lib rekompiliert (kleiner & schneller)
1.1 1997-02-28
  • Verbesserung der Option DUMP
1.0 1997-02-18
  • Erste Veröffentlichung


Danke an... Andreas Mayer-Gürr
für's Korrekturlesen des Guides und beta testing Nils Goers
für 'ne Idee für die Option DUMP Fulvio Peruggi
für einige Bug-Reports und die Idee mit der Farbe, beta testing, viele weitere Ideen und für's Korrekturlesen Matthias Henze
für die stormamiga.lib, welche ich seit V1.2 benutze Simon N Goodwin
für die Idee mit dem Datum-Vergleich Henry Sopko
für 68000er beta testing Thomas Chen
für die Idee mit dem Kommentar/Schutzbits-Vergleich Dump Example
DUMP: Disk.info                   Test.info                   
0010: 00000002 00000A40 .......@  00000002 0000099B ........
0018: 00000CBF 00000106 ...¿....  000001B6 00000017 ......
0020: 000003E9 00000A40 ...é...@  000003E9 0000099B ...é....
0028: 2C780004 2A4F226E ,x..*O"n  48E77EFE 24482400 Hç~þ$H$.
0030: 01144AA9 00AC6652 ..J©.¬fR  49F90000 00002C78 Iù....,x
0038: 41E9005C 2F084EAE Aé.\/.N®  000447F9 000005AC ..Gù...¬
Disk.info: Found 31 differences in contents&length until abort


Complex Example Here is a complex example, how to use cmp as an updater. The following ARexx script will modify the B-Tree that it is exactly like the A-Tree. Only all changed files will copied. It is an ARexx-Script, and it's (hopefully) a help. Without DETAIL it's not possible to distinguish between (missing/useless) dirs and files. More information at the end of the following listing. This is the listing of "update1.rexx".

/*
** Update only all neccesary files from dir A -> dir B
**                 ©1999/2000 ALeX Kazik
*/

/* IMPORTANT: the src/dst dir MUST end with a colon or slash and MUST NOT be empty! */

/* SOURCE directory */
src = 'a/'

/* DESTINATION directory */
dst = 'b/'

/* the script to create, and which will be executed */
script = 'T:script'

/* SKIP the first N bytes */
skip = 0

/* temporary file */
tmpfile = 'T:update.tmp'

/*
** The main-program
*/

ADDRESS COMMAND

cmp 'A="' || src || '" B="' || dst || '" all nostat norc skipfirstnbytes=' || SKIP ,
    || ' newdir=10 newfile revbdir detail lformat %r%R%n >"' || TMPFILE || '"'
IF RC >= 20 THEN DO
        SAY 'Error while executing cmp'
        EXIT RC
END

CALL OPEN(tmp, tmpfile, 'read')
CALL OPEN(scr, script, 'write')

eq = 0

DO UNTIL EOF(tmp)
  act = READCH(tmp, 1)
  file = READLN(tmp)
  IF act = '' THEN
    BREAK
  ELSE IF act = 'Q' THEN
    eq = eq + 1
  ELSE IF (act = 'A') | (act = '5') | (act = '9') THEN DO
    SAY 'File to remove: ' || file
    CALL WRITELN(scr, 'delete "' || dst || file || '" quiet')
  END
  ELSE IF (act = '4') | (act = '8') THEN DO
    SAY 'Dir to remove: ' || file
    CALL WRITELN(scr, 'delete "' || dst || file || '" quiet')
  END
  ELSE IF (act = 'B') | (act = '3') | (act = '7') THEN DO
    SAY 'New File: ' || file
    CALL WRITELN(scr, 'copy "' || src || file || '" "' || dst || file || '"')
  END
  ELSE IF (act = '2') | (act = '6') THEN DO
    SAY 'New Dir: ' || file
    CALL WRITELN(scr, 'makedir "' || dst || file || '"')
  END
  ELSE IF (act = 'E') | (act = '0') | (act = '1') THEN DO
    SAY 'Error/Warning at dir/file: ' || file
    EXIT 20
  END
  ELSE IF (act = 'L') | (act = 'C') | (act = 'D') | (act = 'S') | (act = 'T') THEN DO
    SAY 'File to Update: ' || file
    CALL WRITELN(scr, 'copy "' || src || file || '" "' || dst || file || '"')
  END
  ELSE DO
    SAY 'Unknown Symbol >' || act || '<'
    CALL CLOSE(tmp)
    CALL CLOSE(scr)
    EXIT 20
  END
END

SAY eq || ' Equal files.'

CALL CLOSE(tmp)
CALL CLOSE(scr)

/*
** executing the changes
*/

execute '"' || script || '"'

/*
** That's all.
*/

Ok. Did you now understand, for what I've created NEWDIR/NEWFILE? Not? Just remove DETAIL and examine the created files against those before... REVBDIR is used here, because the entries of a directory should be removed before the directory can be removed. This is only the simple version. The more powerful version can be found here: "update2.rexx". That version is also able to generate a FTP-Script, I use it to update my web-pages.

0 Responses to “cmp”


Comments are currently closed.