Syntax for Code Change Specifications

Black Hole

May contain traces of nut
I'm sure it means everything to those "in the know", and I realise the likes of the following is probably a dump from some kind of automatic differences process, but in detail - how does one interpret these lines, and how would one implement the specified changes (manually with a text editor, presumably)? EG (from https://hummy.tv/forum/threads/yout...com-or-other-video-platforms.8462/post-122500):
Code:
--- /mod/etc/init.d/S00swapper~
+++ /mod/etc/init.d/S00swapper
@@ -1,8 +1,7 @@
#!/bin/sh

-[ "`cat /etc/model`" = "HDR" ] || exit 0
-
swapfile=/mnt/hd3/.swap0
+[ "`cat /etc/model`" = "HD" ] && swapfile=/media/drive1/.swap0

case "$1" in
     start)

OK, so the first two lines are probably the 'before' and 'after' files. We then have some gobbledygook prefixed "@@". Then there are lines to remove prefixed "-" and lines to add prefixed "+", but the exact detail is not obvious without some guidance.

Besides implementing the changes in an editor, maybe there's a tool which can apply them automatically?

UPDATE: The syntax is documented in post 3 below, and a means to apply the described changes automatically (instead of yourself, with an editor) in post 2.
 
Last edited:
the following is probably a dump from some kind of automatic differences process
From "diff -u oldfile newfile"
how does one interpret these lines, and how would one implement the specified changes (manually with a text editor, presumably)?
Yes, a text editor. Basically, get rid of the lines which start with '-' and add those which start with '+'. The others are just for context.

Or you can copy the above to a temporary file e.g. /tmp/patch and then run e.g. patch -i /tmp/patch to do it automatically.
 
Thanks for that. The details are here (see section "Unified Mode"): https://www.computerhope.com/unix/udiff.htm

Output from command diff -u <file1> <file2> :

--- <file1>
+++ <file2>
[1..n]{change_description_block}

Where:

{change_description_block} =

{line_no_descriptor}​
<lines_displayed_for_context>​
-<line_present_in_file1_but_not_file2>​
+<line_present_in_file2_but_not_file1>​
<lines_displayed_for_context>​

{line_no_descriptor} =

@@ -<n1s>,<n1c> +<n2s>,<n2c> @@​

<n1s> = Starting line number in <file1> that the change description block applies to;
<n1c> = Number of lines in <file1> that the change description block applies to;
<n2s> = Starting line number in <file2> that the change description block applies to;
<n2c> = Number of lines in <file2> that the change description block applies to.

Note: Starting line numbers and line counts include the context lines.
 
Last edited:
What would be very nice, I think, is to have the relevant file open in an editor and be able to call in the patches file to have them applied on-screen. If this doesn't already exist, perhaps it would be nice to add to the WebIF file editor.
 
The trouble is that, in all probability, all your carefully crafted mods. will get wiped out the next time there's a WebIf update.
 
Back
Top