How do I manually add the changes of a rejected patch? - diff

I have a bunch of rejected patches; I want to make sure I am reading them correctly. Here is the .rej file:
--- frameworks/base/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ frameworks/base/telephony/java/com/android/internal/telephony/ITelephony.aidl
## -304,5 +304,40 ##
* Sets minimum time in milli-seconds between onCellInfoChanged
*/
void setCellInfoListRate(int rateInMillis);
+
+ /**
+ * Returns the response APDU for a command APDU sent to a logical channel
+ */
+ String transmitIccLogicalChannel(int cla, int command, int channel,
+ int p1, int p2, int p3, String data);
+
+ /**
+ * Returns the response APDU for a command APDU sent to the basic channel
+ */
+ String transmitIccBasicChannel(int cla, int command,
+ int p1, int p2, int p3, String data);
+
+ /**
+ * Returns the channel id of the logical channel,
+ * Returns 0 on error.
+ */
+ int openIccLogicalChannel(String AID);
+
+ /**
+ * Return true if logical channel was closed successfully
+ */
+ boolean closeIccLogicalChannel(int channel);
+
+ /**
+ * Returns the error code of the last error occured.
+ * Currently only used for openIccLogicalChannel
+ */
+ int getLastError();
+
+ /**
+ * Returns the response APDU for a command APDU sent through SIM_IO
+ */
+ byte[] transmitIccSimIO(int fileID, int command,
+ int p1, int p2, int p3, String filePath);
}
Seems the patch utility creates an original file also. From looking at the original file I see that there is only one method implemented for the interface setCellInfoListRate, and that makes sense with what I understand about patch, diff, and what the .rej file is telling me. Seems I just have to add the lines with + sign next to them under the setCellInfoListRate interface. Would you agree? Am I missing something?

Regarding your question: Yes, the + lines are lines added by the patch. Removed lines would have a - in front.
Regarding the general problem, depending on how many patches you have, and depending on the amount of errors you get, one of the following could work for you:
If you have any chance to get the version on which a patch is based upon (e.g. from your CVS), apply the patch to this version. Then try your luck by comparing against the current version you have and incorporate the changes.
If it is only a few files out of a set of significantly more files to be patched (e.g. 1 out of 10) make a copy of the patch file, remove the changes that cause errors and apply the rest. Then try to apply the changes removed from the patch file in another way. This will work for few rejections, but becomes a PITA with large or lots of rejected patch sections.
Have the patch creator rebasing the patch (assumed it is someone else).

Related

How do you make an equation in swift with multiple variables? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am trying to make something and I am trying to use an equation in Swift. This is the equation:
((((((((((calculation.d/100)/2) * Int(0.98) * (sqrt(calculation.vbottle * 1005.967 * (calculation.psi + (calculation.psi * (calculation.vbottle - (calculation.vol/1000))/2)/2) * ((((calculation.d/100)/2) * Int(0.98) * (sqrt(calculation.vbottle * 1005.967 * (calculation.psi + (calculation.psi * (calculation.vbottle - (calculation.vol/1000))/2)/2) /1005.967 * (3.14159 * ((d / 100)/2) * ((d / 100)/2)))) - (((calculation.mempty/1000) + ((calculation.vol * 0.972)/1000))/2) * calculation.g) / (((calculation.mempty/1000) + ((calculation.vol * 0.972)/1000))/2)) * ((1005.967 * (calculation.vol / 1000000) / (((calculation.d/100)/2) * Int(0.98) * (sqrt(calculation.vbottle * 1005.967 * (calculation.psi + (calculation.psi * (calculation.vbottle - (calculation.vol/1000))/2)/2) * 6894.76))))) * 2) sin 2(calculation.theta) / calculation.g) * (1 - calculation.dc))
This might seem complicated but if you understand it, it isn't (for a computer). All the variables have been defined and the error message says:
Missing argument for parameter 'verbatim' in call and another error that says: Unterminated string literal
I am unsure why and whenever I google it up, an actual result never comes up and when one does, it's always about Playgrounds, not the actual Swift that is used to make apps and stuff.
EDIT:
Here is the reproducible example:
'''
//
// ContentView.swift
// MRE File
//
// Created by Go Peter on 2021/06/18.
//
import SwiftUI
struct Calculation {
var vbottle:Int = 2
var g:Int = Int(9.807)
var vol:Int = 250
var d:Int = 2
var theta:Int = 90
var psi:Int = 40
var mempty:Int = 70
}
struct ContentView: View {
var body: some View {
Text("\(((((((((((calculation.d/100)/2) * Int(0.98) * (sqrt(calculation.vbottle * 1005.967 * (calculation.psi + (calculation.psi * (calculation.vbottle - (calculation.vol/1000))/2)/2) * ((((calculation.d/100)/2) * Int(0.98) * (sqrt(calculation.vbottle * 1005.967 * (calculation.psi + (calculation.psi * (calculation.vbottle - (calculation.vol/1000))/2)/2) /1005.967 * (3.14159 * ((d / 100)/2) * ((d / 100)/2)))) - (((calculation.mempty/1000) + ((calculation.vol * 0.972)/1000))/2) * calculation.g) / (((calculation.mempty/1000) + ((calculation.vol * 0.972)/1000))/2)) * ((1005.967 * (calculation.vol / 1000000) / (((calculation.d/100)/2) * Int(0.98) * (sqrt(calculation.vbottle * 1005.967 * (calculation.psi + (calculation.psi * (calculation.vbottle - (calculation.vol/1000))/2)/2) * 6894.76))))) * 2) sin 2(calculation.theta) / calculation.g) * (1 - calculation.dc)))m")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
'''
There are a few errors I see:
You need a space in /1005.967 after the / operator -- there are likely other spots like this as well.
Near the end of the expression, you have a floating sin that doesn't have an operator before it and isn't followed with parenthesis at all
There are many spots where you refer to just d, but probably mean calculation.d
You have a mismatched number of open and closed parenthesis.
You don't actually have a Calculation property defined on your view, so there's nothing to do the calculations on yet.
Because I don't know the intent of some of this stuff, I can't actually fix it for you. But, I'd recommend trying to clean up the code a little -- at the least, it'll make it easier to debug.
To start, move this out of the interpolated String and into a computed property:
var calc : Int { //Int? -- see comment about this
//your calculation here
}
var body: some View {
Text("\(calc)m")
}
Then, I'd break the calculation up into much smaller expressions that are more readable and would let you find your errors more easily than trying to sift through so many parenthesis, etc. Even a computer can theoretically handle a long, tough-to-read expression, it makes it a challenging debugging issue for us humans.
I'd also be really surprised if you truly want Int for these properties. You have a bunch of spots where you're doing things like Int(0.98), which doesn't make sense, because it'll get rounded to 1. Perhaps you instead want to use Double or Float for everything? You'll see as you start breaking the instructions up and the compiler starts to find more errors once it can parse everything correctly that you're going to end up with type mismatches between things like Int and Double in the existing expressions.

Weird error while using constant properties in class

I am trying to save functions as variables inside a class so I can reach them in an ordered manner. However, whenever I try to pull any constant from the following class, I get the following error.
%FORMULAS Summary of this class goes here
% Detailed explanation goes here
properties (Constant)
%F.heatCapacityOfLiquid
t = #(z) z *2
end
properties (Constant)
enthalpyChange = #(constants, temperatureIn, temperatureOut)integral(#(temperature)(#(constants, temperature)...
constants(1)...
+ temperature * constants(2)...
+ temperature.^2 * constants(3)...
+ temperature.^3 * constants(4)), 0,10);
heatCapacityOfLiquid = #(constants, temperature) constants(1)...
+ temperature * constants(2)...
+ temperature.^2 * constants(3)...
+ temperature.^3 * constants(4);
end
end
ERROR
>> F.t
Invalid default value for property 'enthalpyChange' in class 'F':
Error: Invalid use of operator.

Parsing a fixed-length string with a delimiter

...where the delimiter might also be in the body.
I am working with an LCD display that has a protocol that uses the format below:
STX(1byte) + IDT(1byte) + Type(1byte) + CMD(3bytes) + [Value/Reply(1byte)] + ETX(1byte)
STX is 0x07, and ETX is 0x08. The IDT coming from the display could also be 0x08, which is causing me problems when trying to parse the response from the display. I didn't write the parsing routine, but am now tasked with making things work.
The original programmer's solution can be seen at https://gyazo.com/1fc74133e7109e5aa213f3f5878cc001. The problem is that when IDT is 0x08, the code just grabs the first 2 bytes in the response because 0x08 is the ETX as well as the IDT. I thought about using LastIndexOf, but the possibility exists that there would be more than one response from the display in the buffer. Any help is appreciated.
If every response from the display will contain the 8 bytes you described, then there is no need to use IndexOf to find the ETX terminator. You could do something like this:
internal override void processRXBuffer()
{
for ( int index = 0; (index + 8) <= RXData.Length; index += 8 )
{
string pCmd= RXData.Substring(index, 8);
if ( (pCmd[0] == '\x07') && (pCmd[7] == '\x08') )
{
// Looks like we have a valid response so process it
}
}
}

Matlab calling C function using mex

First of all, I never tried to call C code in a Matlab program - so it might just be a stupid mistake which I just can't figure out.
The C function is the following one and can be found on here, it is called durlevML.c and is part of the ARFIMA(p,d,q) estimator suite:
#include "mex.h"
#include "matrix.h"
#define square(p) ((p)*(p))
#define inv(q) (1/(q))
/* Durbin-Levinson algorithm for linear stationary AR(FI)MA(p,d,q) processes
Slightly altered for the maximum likelihood estimation
(C) György Inzelt 2011 */
void levinson_recur1(double* v,double* L, int N, double* gammas,int step)
{
int i,k;
if(step==0)
{
*(v + step) = *(gammas + step);
*(L + step) = 1;
for(k = step+1;k < N;++k)
{
*(L + k) = 0;
}
}
else if(step > 0 && step < N)
{
//phi_tt
*(L + step*N ) = (-1.00)* *(gammas + step);
if(step > 1)
{
for(i = 1;i < step ;++i)
{
*(L + step*N) -= *(L + (step-1)*N + (step -1) - i ) * *(gammas + step - i) ;
}
}
*(L +step*N) *= inv( *(v + step-1) );
//v_t
*(v + step) = *(v + step-1)*(1- square( *(L + step*N) ));
//phi_tj
for(i =1; i < step; ++i)
{
*(L + step*N + step - i) = *(L + (step-1)*N + (step -1) - i) + *(L + step*N ) * *(L + (step-1)*N + i -1 ) ;
}
//filling L with zeros and ones
*(L + step*N + step ) = 1;
if(step != N-1)
{
for(k = step*N +step+1 ;k < step*N + N ;++k)
{
*(L + k) =0;
}
}
}
if(step < N-1)
levinson_recur1(v,L,N,gammas,++step);
}
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int step=0;
int N;
double *gammas,*v,*L;
// getting the autocovariances
gammas = mxGetPr(prhs[0]);
N = mxGetM(prhs[0]);
// v
plhs[0] = mxCreateDoubleMatrix(0,0,mxREAL);
mxSetM(plhs[0],N);
mxSetN(plhs[0],1);
mxSetData(plhs[0], mxMalloc(sizeof(double)*N*1));
// L
plhs[1] = mxCreateDoubleMatrix(0,0,mxREAL);
mxSetM(plhs[1],square(N));
mxSetN(plhs[1],1);
mxSetData(plhs[1], mxMalloc(sizeof(double)*square(N)*1));
//
v = mxGetPr(plhs[0]);
L = mxGetPr(plhs[1]);
//
levinson_recur1(v, L, N,gammas,step);
//
return;
}
I have two problems now, the first one I already solved:
I got the following warning
Warning: You are using gcc version "4.6.3-1ubuntu5)". The version
currently supported with MEX is "4.4.6".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
mex: durlevML.c not a normal file or does not exist.
but following the solution by changing the corresponding entries and installing the gcc-4.4 the warning disappeared, but the second actual problem still persists, although I don't get any warning any longer I still get the error
mex: durlevML.c not a normal file or does not exist.
What can be the possible reason for this?
I am using
ubuntu 12.04
Matlab 2012b
gcc-4.6 but was able to bring Matlab to use gcc-4.4
The problem occurred while running the function arfima_test.m which calls the durlevML.c function, the relevant (I guess) part of this is
% compiling the C/MEX file
c = input('Would you like to compile the MEX source? (1/0)');
switch c
case(1)
mex durlevML.c
case(0)
end
My thanks go to Ander Biguri due to his the comment!
The solution was indeed very easy, the problem was that the C file durlevML.c was not properly linked, so the compiler couldn't find anything. So I had to add some information in arfima_test.m in the following way
mex durlevML.c <---------------- needs to be linked /home/....
The C code itself was alright with one smaller issue. My compiler - I used gcc-4.4 due to Matlab incompatibilities with newer ones - didn't recognize the comments // and always produced errors, so I had to change them to the long comment format /**/ which finally worked.
Besides this everything worked, as far as I can tell!

How to animate the command line?

I have always wondered how people update a previous line in a command line. a great example of this is when using the wget command in linux. It creates an ASCII loading bar of sorts that looks like this:
[======> ] 37%
and of course the loading bar moves and the percent changes, But it doesn't make a new line. I cannot figure out how to do this. Can someone point me in the right direction?
One way to do this is to repeatedly update the line of text with the current progress. For example:
def status(percent):
sys.stdout.write("%3d%%\r" % percent)
sys.stdout.flush()
Note that I used sys.stdout.write instead of print (this is Python) because print automatically prints "\r\n" (carriage-return new-line) at the end of each line. I just want the carriage-return which returns the cursor to the start of the line. Also, the flush() is necessary because by default, sys.stdout only flushes its output after a newline (or after its buffer gets full).
There are two ways I know of to do this:
Use the backspace escape character ('\b') to erase your line
Use the curses package, if your programming language of choice has bindings for it.
And a Google revealed ANSI Escape Codes, which appear to be a good way. For reference, here is a function in C++ to do this:
void DrawProgressBar(int len, double percent) {
cout << "\x1B[2K"; // Erase the entire current line.
cout << "\x1B[0E"; // Move to the beginning of the current line.
string progress;
for (int i = 0; i < len; ++i) {
if (i < static_cast<int>(len * percent)) {
progress += "=";
} else {
progress += " ";
}
}
cout << "[" << progress << "] " << (static_cast<int>(100 * percent)) << "%";
flush(cout); // Required.
}
The secret is to print only \r instead of \n or \r\n at the and of the line.
\r is called carriage return and it moves the cursor at the start of the line
\n is called line feed and it moves the cursor on the next line
In the console. If you only use \r you overwrite the previously written line.
So first write a line like the following:
[ ]
then add a sign for each tick
\r[= ]
\r[== ]
...
\r[==========]
and so on.
You can use 10 chars, each representing a 10%.
Also, if you want to display a message when finished, don't forget to also add enough white chars so that you overwrite the previously written equal signs like so:
\r[done ]
below is my answer,use the windows APIConsoles(Windows), coding of C.
/*
* file: ProgressBarConsole.cpp
* description: a console progress bar Demo
* author: lijian <hustlijian#gmail.com>
* version: 1.0
* date: 2012-12-06
*/
#include <stdio.h>
#include <windows.h>
HANDLE hOut;
CONSOLE_SCREEN_BUFFER_INFO bInfo;
char charProgress[80] =
{"================================================================"};
char spaceProgress = ' ';
/*
* show a progress in the [row] line
* row start from 0 to the end
*/
int ProgressBar(char *task, int row, int progress)
{
char str[100];
int len, barLen,progressLen;
COORD crStart, crCurr;
GetConsoleScreenBufferInfo(hOut, &bInfo);
crCurr = bInfo.dwCursorPosition; //the old position
len = bInfo.dwMaximumWindowSize.X;
barLen = len - 17;//minus the extra char
progressLen = (int)((progress/100.0)*barLen);
crStart.X = 0;
crStart.Y = row;
sprintf(str,"%-10s[%-.*s>%*c]%3d%%", task,progressLen,charProgress, barLen-progressLen,spaceProgress,50);
#if 0 //use stdand libary
SetConsoleCursorPosition(hOut, crStart);
printf("%s\n", str);
#else
WriteConsoleOutputCharacter(hOut, str, len,crStart,NULL);
#endif
SetConsoleCursorPosition(hOut, crCurr);
return 0;
}
int main(int argc, char* argv[])
{
int i;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hOut, &bInfo);
for (i=0;i<100;i++)
{
ProgressBar("test", 0, i);
Sleep(50);
}
return 0;
}
PowerShell has a Write-Progress cmdlet that creates an in-console progress bar that you can update and modify as your script runs.
Here is the answer for your question... (python)
def disp_status(timelapse, timeout):
if timelapse and timeout:
percent = 100 * (float(timelapse)/float(timeout))
sys.stdout.write("progress : ["+"*"*int(percent)+" "*(100-int(percent-1))+"]"+str(percent)+" %")
sys.stdout.flush()
stdout.write("\r \r")
As a follow up to Greg's answer, here is an extended version of his function that allows you to display multi-line messages; just pass in a list or tuple of the strings you want to display/refresh.
def status(msgs):
assert isinstance(msgs, (list, tuple))
sys.stdout.write(''.join(msg + '\n' for msg in msgs[:-1]) + msgs[-1] + ('\x1b[A' * (len(msgs) - 1)) + '\r')
sys.stdout.flush()
Note: I have only tested this using a linux terminal, so your mileage may vary on Windows-based systems.
If your using a scripting language you could use the "tput cup" command to get this done...
P.S. This is a Linux/Unix thing only as far as I know...