The C++ code has
int main(int argc, char* argv[])
and I want one of my arguments to be tab (ASCII character 9). How do I do this? (This is on a Windows 10).
In powershell: Type for this argument: quote, ALT + NUM 009 , quote. That's, type " then press and hold ALT then type 009 on the numeric pad then release ALT then type ".
This will be echoed like:
your-command arg1 "^I" arg2
Related
My objective is to take a character which represents to UK pound symbol and convert it to it's unicode equivalent in a string.
Here's my code and output so far from my test program:
#include <iostream>
#include <stdio.h>
int main()
{
char x = 163;
unsigned char ux = x;
const char *str = "\u00A3";
printf("x: %d\n", x);
printf("ux: %d %x\n", ux, ux);
printf("str: %s\n", str);
return 0;
}
Output
$ ./pound
x: -93
ux: 163 a3
str: £
My goal is to take the unsigned char 0xA3 and put it into a string representing the unicode UK pound representation: "\u00A3"
What exactly is your question? Anyway, you say you're writing C++, but you're using char* and printf and stdlib.h so you're really writing C, and base C does not support unicode. Remember that a char in C is not a "character" it's just a byte, and a char* is not an array of characters, it's an array of bytes. When you printf the "\u00A3" string in your sample program, you are not printing a unicode character, you are actually printing those literal bytes, and your terminal is helping you out and interpreting them as a unicode character. The fact that it correctly prints the £ character is just coincidence. You can see this for yourself. If you printf str[0] in your sample program you should just see the "\" character.
If you want to use unicode correctly in C you'll need to use a library. There are many to choose from and I haven't used any of them enough to recommend one. Or you'll need to use C++11 or newer and use std::wstring and friends. But what you are doing is not real unicode and will not work as you expect in the long run.
If I have a C-file opened and I highlight var1, the editor will automatically highlight all occurrences of var1.
int main()
{
int var1=0;
int var2 = var1 + 55;
return 0;
}
However, it will not highlight all instances of int in the same manner.
Furthermore, if I open a .s file - which is set as type Assembly Source File automatically by CDT - no occurrences will be marked.
In the following assembly file, I'd like occurrences of L97 to be marked when I highlight one occurrence for easy navigation.
...
b .L97
.L98:
ldr r0, .L99
mov r1, r4
bl printf
movs r0, #0
.L97:
pop {r2, r3, r4, pc}
.L100:
...
How do I enable mark occurrences for all text and in all file types?
In Notepad++, I opened a window, typed two lines of some random text abcd, double-clicked one of them and it automatically highlighted the other without me even setting a file-type.
Notepad++ marks the occurrences of strings, whereas Eclipse marks occurrences of variables.
In the following example, if the first var1 is selected, Eclipse marks only the occurrences of this variable, but neither identically named variables in a different scope nor the string var1 in a comment:
int main()
{
int var1=0;
int var2 = var1 + 55;
{
int var1 = 42; // var1
int var11 = 43;
}
return 0;
}
int foo()
{
int var1 = 44;
return var1;
}
To search and mark a string in one or more files, you can use file search: Search > File....
To jump to the next occurrences of a selected string press Ctrl+K.
You can't do this for any file type. Occurrence highlighting requires an editor which understands the syntax of the programming language you are editing (Java, C, C++, ....). You would need to find an Eclipse editor for the particular assembly code to get occurrence highlighting.
I'm trying to understand how to use the searchMemory() function in pykd extension for windbg.
The documentation says the following:
Function searchMemory
searchMemory( (long)arg1, (int)arg2, (list)arg3) -> int :
Search in virtual memory
C++ signature :
unsigned __int64 searchMemory(unsigned __int64,unsigned long,class boost::python::list)
searchMemory( (long)arg1, (int)arg2, (str)arg3) -> int :
Search in virtual memory
C++ signature :
unsigned __int64 searchMemory(unsigned __int64,unsigned long,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)
Does someone know what the arguments are and how should I use this function?
First, note that there are 2 overloads of the same method:
searchMemory( (long)arg1, (int)arg2, (list)arg3) -> int
and
searchMemory( (long)arg1, (int)arg2, (str)arg3) -> int
arg1 is the start address or offset at which to start the search,
arg2 is the length or amount of memory to search and
arg3 is the search term, which can be
a string (std::string) or
a list (of char)
the return value is an offset again, certainly the offset of the first occurrence, so to find the next occurrence, you have to search again
I have interpreted all this from the sources in pymemaccess.cpp [Codeplex] and never used it myself yet.
I'm neither very familiar with C++ nor with Python and even worse for the mapping between the two, but IMHO the std::string is a string of bytes and not Unicode characters, so you can put arbitraty bytes in there. It should also be suitable for ASCII search. But you might have to fiddle a bit for UTF-16 / UCS text. The same probably applies for the list of char, because it's not declared as wchar_t.
I made the following lex program to count the Number of words in a Textfile. A 'Word' for me is any string that starts with an alphabet and is followed by 0 or more occurrence of alphabets/numbers/_ .
%{
int words;
%}
%%
[a-zA-Z][a-zA-Z0-9_]* {words++; printf("%s %d\n",yytext,words);}
. ;
%%
int main(int argc, char* argv[])
{
if(argc == 2)
{
yyin = fopen(argv[1], "r");
yylex();
printf("No. of Words : %d\n",words);
fclose(yyin);
}
else
printf("Invalid No. of Arguments\n");
return 0;
}
The Problem is that for the following Textfile, I am getting the No. of Words : 13. I tried printing the yytext and it shows that it is taking 'manav' from '9manav' as a word even though it doesnot match my definition of a word.
I also tried including [0-9][a-zA-Z0-9_]* ; within my code but still shows the same output. I want to know why is this happening and possible ways to avoid it.
Textfile : -
the quick brown fox jumps right over the lazy dog cout for
9manav
-99-7-5 32 69 99 +1
First, the manav is perfectly matching your definition of word. The 9 in front of it is matched by the . rule. Remember, that white space is not special in lex.
You had the right idea by adding another rule [0-9][a-zA-Z0-9_]* ; but since the ruleset is ambiguous (there are several ways to match the input) order of the rules matters. It's a while I worked with lex but I think putting the new rule before the word rule should work.
I need to filter a 'reference number' of the form XX.XX, where X is any upper or lower-case letter or number (0-9). This is what I have came up with:
SCR_REF:
'Scr_Ref' ':' value=PROFILE
;
terminal PROFILE :
((CHAR|INT)(CHAR|INT)'.'(CHAR|INT)(CHAR|INT))
;
terminal CHAR returns ecore::EString : ('a'..'z'|'A'..'Z');
But his doesn't work in the generated editor. The following test entry:
Scr_Ref: 11.22
throws an error saying:
"no viable alternative at character '.' "
What I'm I doing wrong?
I think your problem is that you are using default INT in here. Both 11 and 22 is an integer by themselves. You need digits in here not Integer. Down here I made an example for you.
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
import"http://www.eclipse.org/emf/2002/Ecore" as ecore
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!' "val=" val= PROFILE;
terminal PROFILE :
((CHAR|DIGIT)(CHAR|DIGIT)'.'(CHAR|DIGIT)(CHAR|DIGIT))
;
terminal DIGIT:
('0'..'9')
;
terminal CHAR returns ecore::EString :
('a'..'z'|'A'..'Z')
;
Hope this helps.