Merge A and B and keep all diffs - merge

So if file A is
1
2
3
4
and file B is
1
2
3
4a
I want the output to be
1
2
3
4
4a
I can manually do this in KDIFF3 but I want to automatically do this for all 4000+ diffs.

Perhaps use GNU diff with If-then-else (--ifdef=SIMPLE_MERGE) and then post process that result by removing the following lines:
#ifdef SIMPLE_MERGE
#ifndef SIMPLE_MERGE
#else /* SIMPLE_MERGE */
#endif /* SIMPLE_MERGE */
or use the line format options to define your own text to remove. See --old-line-format, --new-line-format, --unchanged-line-format

I spent around 3 hours going down different paths. The final solution takes about 5 minutes.
download diff.exe from Binaries found at
http://gnuwin32.sourceforge.net/packages/diffutils.htm
Rename each file so it is easy to reference A.lex B.lex
Since both files are identical I renamed one set of markers with added -cy
diff --text --ifdef=name a.lex b.lex > out2.txt
output looks like:
\_sh v3.0 724 English-Uzbek Dictionary
\lx ability
\cl N-05; related to: able
\cl J-09
\bk 5
\fr 4
\ph əbˈɪlɪti
\pd abilities
\ps noun
\sn 1
\sdw 09 cognition - nouns denoting cognitive processes and contents
\ss Sense 02: 03841132 ability, power - possession of the qualities (especially mental qualities) required to do something or get something done
\de a way to refer to the fact that you can do something
\xe The baby doesn't have the ability to hold her head up without help.
\xe I have confidence in my brother's ability to do the job.
#ifndef name
\du-cy бирор бир нарсани қила олишингизни англатиш йўли
\gu-cy қобилият
#else /* name */
\du biror bir narsani qila olishingizni anglatish yoʻli
\gu qobiliyat
#endif /* name */
\sn 2
\sdw 07 attribute - nouns denoting attributes of people and objects
\ss Sense 01: 03601639 ability - the quality of being able to perform; a quality that permits or facilitates achievement or accomplishment
\de the quality or skill that makes it possible for someone to do something successfully
\xe My friend's artistic ability is far greater than my own.
\xe The media has continually criticized his leadership abilities.
#ifndef name
\du-cy бирор бир нарсани яхши қилишга имконият берадиган фазилат ёки маҳорат
#else /* name */
\du biror bir narsani yaxshi qilishga imkoniyat beradigan fazilat yoki mahorat
#endif /* name */
\sn 3
\de a person's level of talent, skill or intelligence
\xe She is a student of average ability.
\xe There are doctors of all abilities at that hospital.
#ifndef name
\du-cy бирор бир кишининг маҳорати, қобилияти ёки ақл даражаси
#else /* name */
\du biror bir kishining mahorati, qobiliyati yoki aql darajasi
#endif /* name */
\sn 4
\se do something to the best of your ability
\de do something as well as you can
\xe Whatever you do, do it to the best of your ability.
#ifndef name
\du-cy бирор бир нарсани қўлингиздан келганича яхшироқ қилмоқ
#else /* name */
\du biror bir narsani qoʻlingizdan kelganicha yaxshiroq qilmoq
#endif /* name */
Do search and replace with nothing to remove unnecessary tags
#ifndef name
#else /* name */
#endif /* name */

Related

what is SAM LUN format in iscsi protocol?

When I read the source code of SPDK, there are two forms of fmt_lun in the function spdk_scsi_lun_id_fmt_to_int. What do these two forms mean? and fmt_lun complies with the SAM LUN format,what is SAM LUN format?
uint64_t
spdk_scsi_lun_id_int_to_fmt(int lun_id)
{
uint64_t fmt_lun, method;
if (SPDK_SCSI_DEV_MAX_LUN <= 0x0100) {
/* below 256 */
method = 0x00U;
fmt_lun = (method & 0x03U) << 62;
fmt_lun |= ((uint64_t)lun_id & 0x00ffU) << 48;
} else if (SPDK_SCSI_DEV_MAX_LUN <= 0x4000) {
/* below 16384 */
method = 0x01U;
fmt_lun = (method & 0x03U) << 62;
fmt_lun |= ((uint64_t)lun_id & 0x3fffU) << 48;
} else {
/* XXX */
fmt_lun = 0;
}
return fmt_lun;
}
You'll get the best answer to your question by going to the original specification. You can obtain a copy of the SCSI Architecture Model spec from t10.org here: https://www.t10.org/members/w_sam5.htm. That's the "SAM" from the SAM LUN format.
SCSI has had to adapt to numerous advancements in computing hardware over the years. Back in the mid-1980's, even if you could predict how storage would change over the decades, the protocol itself still needed to be useful on the comparatively tiny computers of the day. And, so you see a lot of this kind of thing in the SCSI world, like you have with LUN encoding. At some point in time, there became a need for more than 256 LUNs. Thankfully, the engineers had built in an addressing method field from the beginning. Naturally, the first method was 0. To maintain compatibility with existing systems, they created method 1, which allows for up to 16,384 LUNs.
SAM-5 defines four different addressing methods:
0: Peripheral device addressing method
1: Flat space addressing method
2: Logical unit addressing method
3: Extended logical unit addressing method
I've only seen the first two out in the wild, but I'm sure there are devices out there that use methods 2 and 3.

What initialises the contents of the STM32's USB BTABLE when the __HAL_RCC_USB_CLK_ENABLE() macro is executed in HAL_PCD_MspInit()?

I have used STM32CubeMX/IDE to generate a USB HID project for the STM32F3DISCOVERY board.
The USB BTABLE register is zero, indicating that the BTABLE is at the start of the Packet Memory Area.
(I zero the whole PMA at program start, to avoid stale values.)
Just before the execution of the __HAL_RCC_USB_CLK_ENABLE macro (in HAL_PCD_MspInit() in usbd_conf.c) the values of the BTABLE (at index zero onwards, in the PMA are:
After that macro is executed, the values are:
The macro expands to:
do { \
volatile uint32_t tmpreg; \
((((RCC_TypeDef *) ((0x40000000UL + 0x00020000UL) + 0x00001000UL))->APB1ENR) |= ((0x1UL << (23U))));\
/* Delay after an RCC peripheral clock enabling */ \
tmpreg = ((((RCC_TypeDef *) ((0x40000000UL + 0x00020000UL) + 0x00001000UL))->APB1ENR) & ((0x1UL << (23U))));\
(void)tmpreg; \
} while(0U)
How does this macro cause the BTABLE to be initialised?
(I need pma[12] to be 0x100 instead of 0x0 as I want to use endpoint 3 for the HID interface in a composite device. I am using this simple HID device to test the use of a different endpoint. Changing 0x81 to 0x83 in USBD_LL_Init() and #define HID_EPIN_ADDR are not sufficient to change the value of pma[12]. The incorrect TX pointer at pma[12] is used and corrupt data is observed in wireshark.)
Update:
If I add code to manually set pma[12] to 0x100:
HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd,
uint16_t ep_addr,
uint16_t ep_kind,
uint32_t pmaadress)
...
/* Here we check if the endpoint is single or double Buffer*/
if (ep_kind == PCD_SNG_BUF)
{
/* Single Buffer */
ep->doublebuffer = 0U;
/* Configure the PMA */
ep->pmaadress = (uint16_t)pmaadress;
// correct PMA BTABLE
uint32_t *btable = (uint32_t *) USB_PMAADDR; // Test this.
if (ep->is_in) {
btable[ep->num * 4] = pmaadress;
}
}
The value at pam[12] does get set, but it later gets overwritten:
__HAL_RCC_USB_CLK_ENABLE() enables clocks for the USB block. Before it is enabled, all peripheral locations are read as zeroes. After clock is enabled, the actual PMA content becomes visible, whatever was written there before reset or random garbage left after the power up. So executing __HAL_RCC_USB_CLK_ENABLE() has nothing to do with your problem.
I don't know where the TX buffer address for endpoint 3 gets overwritten, but I guess it is the Cube sets it when it decides to send data on the endpoint. I am not familiar with the Cube, does it have an API to send a USB packet?
Also, double-check that your pma array has the right definition. On F1 and I likely F3, there is a 2-byte value at each of the 32-bit location.
UPD: Sorry, I saw this question first, but your real problem is why TX addr gets overwritten or not set up correctly.

Fastest way to write sampler2D * 0 and sampler2D * 1 to add many together? (glsl/cg)

I would like to mix many sampler2Ds into one shader, without "if" conditions, using variable m1,m2,m3 equals to 0 / 1 for each sampler2D to say if it is active or not, and multiply by 1 the sampler2Ds active at one time.
I naively wrote this function to merge 15 sampler2D's:
//float4 blend function is a sampler2D function that "return tex2D (tex,uv);" at 3 different altitudes
color = blend (_TexTop *m1 + _TexTop2 *m2 + _TexTop3 *m3 + _TexTop4 *m4 + _TexTop5 *m5 ,
_TexMid *m1 + _TexMid2 *m2 + _TexMid3 *m3 + _TexMid4 *m4 + _TexMid5 *m5 ,
_TexBot *m1 + _TexBot2 *m2 + _TexBot3 *m3 + _TexBot4 *m4 + _TexBot5 *m5 ,
_StrataBlendWidth, _strataAltitudeOffset, _StrataMidbandWidth, IN.worldPos.y, IN.uv_TexTop);
Except obviously that doesnt work because it's not possible to add and multiply sampler2Ds. rarrgh!
What is the best way to rewrite the above line, to switch sampler2Ds on and off, using a 0-1 integer, without if conditions and dynaming branching?
Thankyou
Assuming that I've understood your question (I'm not sure), there's no way to selectively sample a texture based on a uniform paramater(mx) without branching.
Consider a couple of facts:
Branching on uniforms could not be always that expensive, since the value will be constant within the same drawcall (I guess it depends on the shader profile and the hardware, even if avoiding branches is a good rule of thumb).
If in the worst case you want to use all your sample (15 seems a quite big number though), then you might consider to always sample all of them.
I'm not sure on what's the practical use case for such a shader, btw a different approach could be compile different shader variants depending on the number of active samplers.
For example to compile 2 variants of a shader 1 with one sampler the other with 2 you could something like:
#pragma multi_compile ONE_SAMP TWO_SAMPLE
#ifdef ONE_SAMP
uniform sampler2D tex1;
#endif
#ifdef TWO_SAMP
uniform sampler2D tex1;
uniform sampler2D tex2;
#endif
...
#ifdef ONE_SAMP
fixed4 col1 = tex2D(tex1,uv);
#endif
#ifdef TWO_SAMP
fixed4 col1 = tex2D(tex1,uv);
fixed4 col2 = tex2D(tex2,uv);
#endif
Then set the active keyword by script or using a custom material editor.
EDIT
In my answer I've assumed that m1,m2 values are uniforms, otherwise if they are not there's really no way of dynamic sampling a texture without branching.

Progress 4GL - Enumerable.Take(TSource) Method in

Thanks in advance for looking at this question!
This is all in the context of a FOR EACH loop which can get quite lengthy - think 100,000 records - and I'm looking for a way to take n records from a position in that resultset e.g. start # 4000 & take the next 500 records.
I was looking around for keywords, in the ABL Reference, such as:
Position
LookAhead
RECID - Whether we can find a RECID at the nth position
Query Tuning
So far no luck. Any smarties out there with a hint?
Here is an example that I created against the sports database. The sports database is a sample database similar to the AdventureWorks database in SQL Server.
This should get you started:
def var v-query as char no-undo.
def var h as handle no-undo.
/* Here is where can set a dynamic query */
assign v-query = "for each orderline no-lock".
/* Create handle used for query */
create query h.
/* Set the table against the query so you can access it conveniently */
/* If you have other tables in your "for each", simply do a */
/* set-buffers on each table */
h:set-buffers(buffer orderline:handle).
/* Prepare Query */
h:query-prepare(v-query).
/* DO Open */
h:query-open.
/* Setup query to row 10 */
h:reposition-to-row(10).
LINE_LOOP:
repeat:
/* Read next row */
h:get-next.
/* Check if we are not past the end */
if h:query-off-end then leave LINE_LOOP.
/* Since we added orderline as a buffer we can now use it here */
disp orderline.ordernum
orderline.linenum
orderline.itemnum
orderline.price
orderline.qty.
end. /* repeat */
h:query-close.
FYI, the Progress Knowledge base and the PSDN have great samples and tutorials
other example - filling of dataset tables - BATCHING
DEFINE TEMP-TABLE ttOrder LIKE Order.
DEFINE DATASET dsOrder FOR ttOrder.
/* you can set a buffer object */
/*DEFINE DATA-SOURCE srcOrder FOR Order.*/
/* or you can set a query */
DEFINE QUERY qOrder FOR Order SCROLLING.
QUERY qOrder:QUERY-PREPARE ("FOR EACH Order").
DEFINE DATA-SOURCE srcOrder FOR QUERY qOrder.
BUFFER ttOrder:ATTACH-DATA-SOURCE( DATA-SOURCE srcOrder:HANDLE ).
/*The maximum number of ProDataSet temp-table rows to retrieve in each FILL operation.*/
BUFFER ttOrder:BATCH-SIZE = 10.
/* Empties the table before the FILL operation begins.
Without setting this attribute will next rows append to existing in temp-table */
BUFFER ttOrder:FILL-MODE = "EMPTY".
/* first time - result 1 - 10 */
DATASET dsOrder:FILL ().
FOR EACH ttOrder:
DISPLAY ttOrder.ordernum.
END.
/* set the startpoint to position 11 */
DATA-SOURCE srcOrder:RESTART-ROW = 11.
/* second time 11 - 20 */
DATASET dsOrder:FILL ().
FOR EACH ttOrder:
DISPLAY ttOrder.ordernum.
END.

Help with live-updating sound on the iPhone

My question is a little tricky, and I'm not exactly experienced (I might get some terms wrong), so here goes.
I'm declaring an instance of an object called "Singer". The instance is called "singer1". "singer1" produces an audio signal. Now, the following is the code where the specifics of the audio signal are determined:
OSStatus playbackCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
//Singer *me = (Singer *)inRefCon;
static int phase = 0;
for(UInt32 i = 0; i < ioData->mNumberBuffers; i++) {
int samples = ioData->mBuffers[i].mDataByteSize / sizeof(SInt16);
SInt16 values[samples];
float waves;
float volume=.5;
for(int j = 0; j < samples; j++) {
waves = 0;
waves += sin(kWaveform * 600 * phase)*volume;
waves += sin(kWaveform * 400 * phase)*volume;
waves += sin(kWaveform * 200 * phase)*volume;
waves += sin(kWaveform * 100 * phase)*volume;
waves *= 32500 / 4; // <--------- make sure to divide by how many waves you're stacking
values[j] = (SInt16)waves;
values[j] += values[j]<<16;
phase++;
}
memcpy(ioData->mBuffers[i].mData, values, samples * sizeof(SInt16));
}
return noErr;
}
99% of this is borrowed code, so I only have a basic understanding of how it works (I don't know about the OSStatus class or method or whatever this is. However, you see those 4 lines with 600, 400, 200 and 100 in them? Those determine the frequency. Now, what I want to do (for now) is insert my own variable in there in place of a constant, which I can change on a whim. This variable is called "fr1". "fr1" is declared in the header file, but if I try to compile I get an error about "fr1" being undeclared. Currently, my technique to fix this is the following: right beneath where I #import stuff, I add the line
fr1=0.0;//any number will work properly
This sort of works, as the code will compile and singer1.fr1 will actually change values if I tell it to. The problems are now this:A)even though this compiles and the tone specified will play (0.0 is no tone), I get the warnings "Data definition has no type or storage class" and "Type defaults to 'int' in declaration of 'fr1'". I bet this is because for some reason it's not seeing my previous declaration in the header file (as a float). However, again, if I leave this line out the code won't compile because "fr1 is undeclared". B)Just because I change the value of fr1 doesn't mean that singer1 will update the value stored inside the "playbackcallback" variable or whatever is in charge of updating the output buffers. Perhaps this can be fixed by coding differently? C)even if this did work, there is still a noticeable "gap" when pausing/playing the audio, which I need to eliminate. This might mean a complete overhaul of the code so that I can "dynamically" insert new values without disrupting anything. However, the reason I'm going through all this effort to post is because this method does exactly what I want (I can compute a value mathematically and it goes straight to the DAC, which means I can use it in the future to make triangle, square, etc waves easily). I have uploaded Singer.h and .m to pastebin for your veiwing pleasure, perhaps they will help. Sorry, I can't post 2 HTML tags so here are the full links.
(http://pastebin.com/ewhKW2Tk)
(http://pastebin.com/CNAT4gFv)
So, TL;DR, all I really want to do is be able to define the current equation/value of the 4 waves and re-define them very often without a gap in the sound.
Thanks. (And sorry if the post was confusing or got off track, which I'm pretty sure it did.)
My understanding is that your callback function is called every time the buffer needs to be re-filled. So changing fr1..fr4 will alter the waveform, but only when the buffer updates. You shouldn't need to stop and re-start the sound to get a change, but you will notice an abrupt shift in the timbre if you change your fr values. In order to get a smooth transition in timbre, you'd have to implement something that smoothly changes the fr values over time. Tweaking the buffer size will give you some control over how responsive the sound is to your changing fr values.
Your issue with fr being undefined is due to your callback being a straight c function. Your fr variables are declared as objective-c instance variables as part of your Singer object. They are not accessible by default.
take a look at this project, and see how he implements access to his instance variables from within his callback. Basically he passes a reference to his instance to the callback function, and then accesses instance variables through that.
https://github.com/youpy/dowoscillator
notice:
Sinewave *sineObject = inRefCon;
float freq = sineObject.frequency * 2 * M_PI / samplingRate;
and:
AURenderCallbackStruct input;
input.inputProc = RenderCallback;
input.inputProcRefCon = self;
Also, you'll want to move your callback function outside of your #implementation block, because it's not actually part of your Singer object.
You can see this all in action here: https://github.com/coryalder/SineWaver