Im trying to use quite long define in my CLI program but i'm getting dosens of errors because of that.
This is my code.
#define OPERATION_MACRO(character) \
array<Byte>^ opRes = gcnew array<Byte>(args[0]->Length); \
for(int i=0;i<args[0]->Length;i++) \
{ \
double result=0; \
for(int k=0;k<args->Length;k++) \
{ \
result character##= args[k][i]; \
} \
graphicUtils::round(result); \
opRes[i] = result; \
} \
return opRes;
array<Byte>^ myInterpreter::mathOp(array< array<Byte>^ >^ args, Char opr)
{
switch(opr)
{
case '*':
OPERATION_MACRO(*)
case '/':
OPERATION_MACRO(/)
case '+':
OPERATION_MACRO(+)
case '-':
OPERATION_MACRO(-)
case '%':
OPERATION_MACRO(%)
case '^':
OPERATION_MACRO(^)
}
}
Is it because of different new line character in CLI compiler?
Related
I am looking at the output of the protoc --decode command and I cannot fathom the encoding used when it encounters bytes :
data {
image: "\377\330\377\340\000\020JFIF\000\001[…]\242\2634G\377\331"
}
The […] was added by me to shorten the output.
What encoding is this?
Edit
So based on Bruce's answer I wrote my own utility in order to generate sample data from a shell script :
public static void main(String[] parameters) throws IOException {
File binaryInput = new File(parameters[0]);
System.out.println("\""+TextFormat.escapeBytes(ByteString.readFrom(new FileInputStream(binaryInput)))+"\"");
}
}
that way I can call serialize my binaries and insert them in a text serialization of a protobuf before calling protoc --encode on it :
IMAGE=$(mktemp)
OUTPUT=$(mktemp)
BIN_INSTANCE=$(mktemp)
echo -n 'capture: ' > $IMAGE
java -cp "$HOME/.m2/repository/com/google/protobuf/protobuf-java/3.0.0/protobuf-java-3.0.0.jar:target/protobuf-generator-1.0.0-SNAPSHOT.jar" protobuf.BinarySerializer image.jpg >> $IMAGE
sed -e 's/{UUID}/'$(uuidgen)'/' template.protobuf > $OUTPUT
sed -i '/{IMAGE}/ {
r '$IMAGE'
d
}' $OUTPUT
cat $OUTPUT | protoc --encode=prototypesEvent.proto> $BIN_INSTANCE
with template.protobuf being :
uuid: "{UUID}"
image {
capture: "{IMAGE}"
}
I am presuming it is the samer as produced by java.
basically:
* between space (0x20) and tilde (0x7e) treat it as an ascii character
* if there is a shortcut (e.g. \n, \r, \ etc) use the shortcut
* otherwise escape the character (octal)
so in the above \377 is 1 byte: 377 octal or 255 in decimal.
"\377\330\377\340 = 255 216 255 224
You should be able to copy the string into a Java/C program and convert it to bytes
The Java code looks to be:
static String escapeBytes(final ByteSequence input) {
final StringBuilder builder = new StringBuilder(input.size());
for (int i = 0; i < input.size(); i++) {
final byte b = input.byteAt(i);
switch (b) {
// Java does not recognize \a or \v, apparently.
case 0x07: builder.append("\\a"); break;
case '\b': builder.append("\\b"); break;
case '\f': builder.append("\\f"); break;
case '\n': builder.append("\\n"); break;
case '\r': builder.append("\\r"); break;
case '\t': builder.append("\\t"); break;
case 0x0b: builder.append("\\v"); break;
case '\\': builder.append("\\\\"); break;
case '\'': builder.append("\\\'"); break;
case '"' : builder.append("\\\""); break;
default:
// Only ASCII characters between 0x20 (space) and 0x7e (tilde) are
// printable. Other byte values must be escaped.
if (b >= 0x20 && b <= 0x7e) {
builder.append((char) b);
} else {
builder.append('\\');
builder.append((char) ('0' + ((b >>> 6) & 3)));
builder.append((char) ('0' + ((b >>> 3) & 7)));
builder.append((char) ('0' + (b & 7)));
}
break;
}
}
return builder.toString();
}
taken from com.google.protobuf.TextFormatEscaper
While i'm trying to build gcc itself. İ faced with this strange error.
error was on aarch64.h
and also, i edited header code a bit before compilation
original header code:
#define PROFILE_HOOK(LABEL) \
{ \
rtx fun, lr; \
lr = get_hard_reg_initial_val (Pmode, LR_REGNUM); \
fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_NAME); \
emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lr, Pmode); \
}
İ changed it to:
#define PROFILE_HOOK(LABEL) \
{ \
rtx fun, lr; \
if (!flag_fentry)
{ //error: expected unqualified-id before.. this line**************
lr = get_hard_reg_initial_val (Pmode, LR_REGNUM); \
fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_NAME); \
emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lr, Pmode); \
} //error: expected unqualified-id before.... this line*************
}
and also i dont know if it makes any difference(color change) but before editing code, whole code looks purple. after editing code, lines below if (!flag_fentry) turned to black
im struggling with it for two days with no success
i really appreciate it if anyone help me.
thanx
regards
gcc -v:
gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13)
#define d_write_log_evolved(old_fmt, args...) \
do \
{ char new_fmt[2048] = {0}; \
time_t timep; \
struct tm *p; \
timep = time(&timep); \
p = localtime(&timep); \
sprintf(new_fmt, "%d-%d-%d %d:%d:%d [process %d][thread %lu]: ", \
(int)(1900+p->tm_year), \
(int)(1+p->tm_mon), \
(int)(p->tm_mday), \
(int)(p->tm_hour), \
(int)(p->tm_min), \
(int)(p->tm_sec), \
getpid(), \
pthread_self()); \
strcat(new_fmt, old_fmt); \
FILE *logfp = fopen(CCDAEMON_LOG, "a"); \
fprintf(logfp, new_fmt, ##args); \
fclose(logfp); \
} \
while (0)
d_write_log_evolved("[err] compile %s failed, thread will exit.\n", file);//here no warning.
d_write_log_evolved("socket() error, thread exit.\n"); //here have the warning.
When I pass some args to d_write_log_evolved(), then there's no warning reported, but without args, there always warning:warning: format not a string literal and no format arguments [-Wformat-security]
This really trouble me although program can be running properly.
BTW, there's no such warning under Scientific Linux.
Could you tell me how to eliminate this warning? Thanks!
PS. below is preprocessing result.
without agrs:
do { char new_fmt[2048] = {0}; time_t timep; struct tm *p; timep = time(&timep); p = localtime(&timep); sprintf(new_fmt, "%d-%d-%d %d:%d:%d [process %d][thread %lu]: ", (int)(1900+p->tm_year), (int)(1+p->tm_mon), (int)(p->tm_mday), (int)(p->tm_hour), (int)(p->tm_min), (int)(p->tm_sec), getpid(), pthread_self()); strcat(new_fmt, "socket() error, thread exit.\n"); FILE *logfp = fopen("/tmp/ccdcc.log", "a"); fprintf(logfp, new_fmt); fclose(logfp); } while (0);
with args:
do { char new_fmt[2048] = {0}; time_t timep; struct tm *p; timep = time(&timep); p = localtime(&timep); sprintf(new_fmt, "%d-%d-%d %d:%d:%d [process %d][thread %lu]: ", (int)(1900+p->tm_year), (int)(1+p->tm_mon), (int)(p->tm_mday), (int)(p->tm_hour), (int)(p->tm_min), (int)(p->tm_sec), getpid(), pthread_self()); strcat(new_fmt, "[ERR] send msg to client %s failed.\n"); FILE *logfp = fopen("/tmp/ccdcc.log", "a"); fprintf(logfp, new_fmt, inet_ntoa(host.sin_addr)); fclose(logfp); } while (0);
I'm encountering a problem when trying to pass a parameter through my program via the command line (eg. -w 1280 -h 1024) while attempting to utilize WinMain. I've looked through every topic I could find, and have created code that builds and runs, but the parameters are ignored completely!
My Code:
LPWSTR *szArgList;
int argCount;
szArgList = CommandLineToArgvW(GetCommandLineW(), &argCount);
for(int i = 1;i < argCount;i++)
{
if(i + 1 != argCount)
{
if(szArgList[i] == L"-w")
{
width = _wtoi(szArgList[i+1]);
}
else if(szArgList[i] == L"-h")
{
height = _wtoi(szArgList[i+1]);
}
}
}
MSG msg;
BOOL done=FALSE;
if(MessageBox(NULL,"Fullscreen?", "my window", MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=FALSE;
}
if(!CreateGLWindow("Window",width,height,16,fullscreen))
{
return 0;
}
I'm attempting to pass it as "window.exe -w 800 -h 600" (without quotes, of course)
Anything i'm missing within my sleep-depraved code?
szArgList[i] == L"-w"
szArgList[i] == L"-h"
C and C++ will compare by pointer instead of character. use strcmp.
have folowing code:
NPVariant type;
STRINGZ_TO_NPVARIANT("click", type);
and the xcode returns
"error: expected expression before 'uint32_t'"
anyone can give me a hand with this?
I ran into this as well. Based on this bug i found in the npapi project, i solved the problem by not using the macro, and using what it expands to instead, then applying what the patch shows.
http://code.google.com/p/npapi-headers/issues/detail?id=3
- NPString str = { _val, uint32_t(strlen(_val)) };
+ NPString str = { _val, (uint32_t)(strlen(_val)) };
Basically, wrap uint32_t in parenthesis, then gcc will compile it.
So the full replacement for the macro is
NPVariant type;
type.type = NPVariantType_String;
NPString str = { "click", (uint32_t)(strlen("click")) };
type.value.stringValue = str;
If you check what this macro resolves into you get:
NPVariant type;
type.type = NPVariantType_String;
NPString str = { "click", uint32_t(strlen("click")) };
type.value.stringValue = str;
At least this way one can understand what the error message refers to. I'm still not sure what the reason for the error is however - maybe your Xcode or gcc version is outdated. According to the documentation you need at least Xcode 2.5 and gcc 4.2.
in your npruntime.h find these two MACRO
#define STRINGZ_TO_NPVARIANT(_val, _v) \
NP_BEGIN_MACRO \
(_v).type = NPVariantType_String; \
NPString str = { _val, **(uint32_t)** strlen(_val) }; \
(_v).value.stringValue = str; \
NP_END_MACRO
#define STRINGN_TO_NPVARIANT(_val, _len, _v) \
NP_BEGIN_MACRO \
(_v).type = NPVariantType_String; \
NPString str = { _val, **(uint32_t)**_len }; \
(_v).value.stringValue = str; \
NP_END_MACRO
add (uint32_t) cast before strlen(_val) and _len