diff two files ignoring some parts of the lines - debugging

Let's say I have two files produced from javap -v.
output will look something like this:
[...]
299: astore 15
301: aload 15
303: aload 18
305: if_acmpeq 367
308: aload 15
310: arraylength
311: istore 17
313: iload 17
315: ifeq 348
318: aload 15
320: iconst_2
321: laload
322: lstore 19
324: aload_1
325: getfield #49 // Field my/somewhere/Some.thing:J
328: lstore 21
330: lload 19
332: lload 21
334: land
335: lstore 19
[...]
If I diff this with another file, most of the linenumbers will have changed and show up as a "difference".
I COULD write a sript that removes them, but I still need them to see where my code is jumping to.
Similarly, that field / Field my/somewhere/Some.thing:J happens to have #49 is completely irrelevant.
At the same time, a changed register is relevant.
So is there a tool (preferably with a GUI, of course, as the files are quite large and context is helpful in figuring out what is going on) to diff two files while ignoring parts of the line without removing said parts?
The line number, at least. Could be as simple as "ignore everything up to the first :.
Ideally, of course, it would allow me to set more sophisticated exclusion checks, like "ignore integers if they are marked with an # or follow a word on the same line that is prefixed with either if, jsr or goto. But I don't expect there to be something as convenient.
UPDATE
Using asmtools jdis as suggested by #user882813 will result in an output like
astore 6;
aload 6;
aload 8;
if_acmpeq L795;
aload 6;
arraylength;
istore 7;
iload 7;
ifeq L781;
aload 6;
iload 4;
laload;
lstore 9;
aload_1;
getfield Field my/somehwere/Some.thing:"J";
lstore 11;
lload 9;
lload 11;
land;
lstore 9;
...
L795: stack_frame_type full;
locals_map ...
Which is a LOT better for diffing than the javap -v output.
(And personally, I quite like the inlined locals_map and stack_map.)
Still, the jump targets / labels (e.g. L795) all show up as false positives.
Additionally, the same now goes for try-catch block labels (e.g. t6).
try t6;
aload 4;
getfield Field Something.f:"Lparc/lang/Foo;";
checkcast class SpecialFoo;
endtry t6;
goto L495;
catch t6 java/lang/ClassCastException;
stack_frame_type full;
locals_map class Something, class parc/some/Thing, bogus, int, class Something$1, class SpecialFoo, class "[J", bogus, class "[J", bogus, bogus, bogus, bogus, null, null;
stack_map class java/lang/ClassCastException;
new class java/lang/Error;
dup;
ldc String "not SpecialFoo";
invokespecial Method java/lang/Error."<init>":"(Ljava/lang/String;)V";
athrow;
L495: stack_frame_type stack1;
stack_map class SpecialFoo;
nop;
So it would still be convenient if the tool could be configured to ignore the t<integer> and L<integer> parts of the lines.

Try to use asmtools jdis instead of javap.
asmtools jdis has more clean output.
For example, for simple HelloWorld application
class Hello {
public static void main(String... args) {
System.out.println("Hello, world!");
}
}
asmtools jdis output will be:
super class Hello
version 52:0
{
Method "<init>":"()V"
stack 1 locals 1
{
aload_0;
invokespecial Method java/lang/Object."<init>":"()V";
return;
}
public static varargs Method main:"([Ljava/lang/String;)V"
stack 2 locals 1
{
getstatic Field java/lang/System.out:"Ljava/io/PrintStream;";
ldc String "Hello, world!";
invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V";
return;
}
} // end Class Hello
JFYI, numbers in the front of instructions is not line numbers but bytecode instruction offsets.

Related

Reassigning non-absolute variables in OSX's assembler

The following assembler directives, when compiled with clang on OSX, produce an error:
.set link,0
test:
.int link
.set link,test
test2:
.int link
.set link,test2
The error:
$ clang test.s
test.s:7:13: error: invalid reassignment of non-absolute variable 'link'
.set link,test2
^
I want to use link in a macro as a variable that keeps track of the last defined word, to build a linked list (as in JONESFORTH).
As far as I know, you can't redefine normal symbols. The way I see it, you have two choices. Either you allocate a local label number to store your link address (as these can be redefined) or you use preprocessed assembly. For both cases, you probably want to use a macro to declare your nodes.
Example:
.macro declare_node list_id
.ifndef link_head_\list_id
link_head_\list_id : .int 0
.else
.int \list_id\()b-4
.endif
\list_id :
.endm
test:
declare_node 100
.int 42 # node data
test2:
declare_node 100
.int 314 # node data
test3:
declare_node 101
.int 173 # node data
test4:
declare_node 101
.int 141 # node data
Here, a numerical list id is used as the local label, so you can declare multiple lists.
I have the same problem (jonesforth). I have not found out why apples assembler doesn't allow to redefine symbols, but it is what it is.
I worked around this by manually passing the last defined word as an argument to the defword macro. It's ugly as hell, and error prone.
.macro defcode name, length, flags, name, link
.const_data
.balign 8
.globl name_\name
name_\name :
.quad \link // link
.byte \flags+\length // flags + length byte
.ascii \name // the name
.balign 8 // padding to next 8 byte boundary
.globl \name
\name :
.quad code_\name // codeword
.text
.balign 8
.globl code_\name
code_\name : // assembler code follows
.endmacro
Then call the macro like
defcode "BRANCH",6,0,BRANCH,name_TICK
...
NEXT
defcode "0BRANCH",7,0,ZBRANCH,name_BRANCH
...
NEXT
I'd be super excited to learn about better ways to handle it.

Need help to insert some text to my c++ file

I want to insert some text to my c++ file after certain line ( pattern ). The following is my file structure.
38 #include "stdlib.h"
39 #include "string.h"
40 #include "malloc.h"
41
...
324 void DMProcMon::threadManagerMonitorThread(DMProcMon* dmProcMon)
325 {
...
338 while (dmState == DVProcMon::Active &&
339 DmManService::getDCMRestartingFlag() == 0){
340 try{
342 setupTimerVerification(dmProcMon);
343 setupSignalVerification(dmProcMon);
344
....
360 }
I want to add code coverage macros using gcov. So basically what I need to achieve is
Add below text after all the #include statements.
45 #ifdef GCOV
46 extern "C"
47 void _gcov_flush();
48 #endif
Add the below text after the while statement in the threadManagerMonitorThread function
#ifdef GCOV
_gcov_flush();
#endif
So final code will loos like as below.
38 #include "stdlib.h"
39 #include "string.h"
40 #include "malloc.h"
41
45 #ifdef GCOV
46 _gcov_flush();
47 #endif
...
324 void DMProcMon::threadManagerMonitorThread(DMProcMon* dmProcMon)
325 {
...
338 while (dmState == DVProcMon::Active &&
339 DmManService::getDCMRestartingFlag() == 0){
340 try{
342 #ifdef GCOV
343 _gcov_flush();
344 #endif
346 setupTimerVerification(dmProcMon);
347 setupSignalVerification(dmProcMon);
348
....
360 }
What is the best way to do this. I would like to do this with either bash or pythyon.
Thanks
~S
You might use sed to insert a line after/before a line containing a certain pattern. See this: https://stackoverflow.com/a/11695086/2749648.
Also here is the explanation on how to insert a line after a block of code (this will help you with the #include block) but i am not sure on how to fix the while statement. If while statement is on a single line, it would be easy, but that is hard to guarantee.

Getting GCC to optimize hand assembly

In an attempt to make GCC not generate a load-modify-store operation every time I do |= or &=, I have defined the following macros:
#define bset(base, offset, mask) bmanip(set, base, offset, mask)
#define bclr(base, offset, mask) bmanip(clr, base, offset, mask)
#define bmanip(op, base, offset, mask) \
asm("pshx");\
asm("ldx " #base);\
asm("b" #op " " #offset ",x " #mask);\
asm("pulx")
And they work great; the disassembled binary is perfect.
The problem comes when I use more than one in sequence:
inline void spi_init()
{
bset(_io_ports, M6811_DDRD, 0x38);
bset(_io_ports, M6811_PORTD, 0x20);
bset(_io_ports, M6811_SPCR, (M6811_SPE | M6811_DWOM | M6811_MSTR));
}
This results in:
00002227 <spi_init>:
2227: 3c pshx
2228: fe 10 00 ldx 0x1000 <_io_ports>
222b: 1c 09 38 bset 0x9,x, #0x38
222e: 38 pulx
222f: 3c pshx
2230: fe 10 00 ldx 0x1000 <_io_ports>
2233: 1c 08 20 bset 0x8,x, #0x20
2236: 38 pulx
2237: 3c pshx
2238: fe 10 00 ldx 0x1000 <_io_ports>
223b: 1c 28 70 bset 0x28,x, #0x70
223e: 38 pulx
223f: 39 rts
Is there any way to get GCC (3.3.6-m68hc1x-20060122) to automatically optimize out the redundant stack operations?
gcc will always emit the assembly instructions you tell it to emit. So instead of explicitly writing code to load registers with the value you want to manipulate, you instead want to tell gcc to do this on your behalf. You can do this with register constraints.
Unfortunately the 6811 code generator doesn't seem to be a standard part of gcc --- I don't spot the documentation in the manual. So I can't point you at platform-specific bit of the docs. But the generic bit you need to read is here: http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Extended-Asm.html#Extended-Asm
The syntax is freaky, but the summary is:
asm("instructions" : outputs : inputs);
...where inputs and outputs are lists of constraints, which tell gcc what value to put where. The classic example is:
asm("fsinx %1,%0" : "=f" (result) : "f" (angle));
f indicates that the named value needs to go into a floating point register; = indicates it's an output; then the names of the registers are substituted into the instruction.
So, you'll probably want something like this:
asm("b" #op " " #offset ",%0 " #mask : "=Z" (i) : "0" (i));
...where i is a variable containing the value you want to modify. Z you'll need to look up in the 6811 gcc docs --- it's a constraint which represents a register which is valid for the asm instruction which is being generated. The 0 indicates that the input shares a register with output 0, and is used for read/write values.
Because you've told gcc what register you want i to be, it can integrate this knowledge into its register allocator and find the least-cost way to get i where you need it with the least amount of code. (Sometimes no additional code.)
gcc inline assembly is deeply contorted and weird, but pretty powerful. It's worth spending some time to thoroughly understand the constraint system to get the best use out of it.
(Incidentally, I don't know 6811 code, but have you forgotten to put the result of the op somewhere? I'd expect to see an stx to match the ldx.)
Update: Oh, I see what bset is doing now --- it's writing the result back to a memory location, right? That's still doable but it's a bit more painful. You need to tell gcc that you're modifying that memory location, so that it knows not to rely on any cached value. You'll need to have an output parameter with constraint m which represents that location. Check the docs.

System.Windows.Navigation.NavigationService.Navigate is throwing invalidoperationexception

Frame Image Function Offset
0 coredll.dll xxx_RaiseException 19
1 mscoree3_7.dll 436488
2 mscoree3_7.dll 386545
3 mscoree3_7.dll 540936
4 TransitionStub 0
5 System.Windows.Navigation.NavigationService.Navigate 1652
6 XXX.Components.pushScreen 172
7 XXX.pushHomeScr 996
8 XXX.update 1488
9 .__c__DisplayClass3._ResponseReady_b__0 700
10 mscoree3_7.dll 429164
11 mscoree3_7.dll 185803
12 mscoree3_7.dll 184423
13 System.Reflection.RuntimeMethodInfo.InternalInvoke 112
14 System.Reflection.RuntimeMethodInfo.InternalInvoke 1556
15 System.Reflection.MethodBase.Invoke 104
16 System.Delegate.DynamicInvokeOne 476
17 System.MulticastDelegate.DynamicInvokeImpl 84
18 System.Windows.Threading.DispatcherOperation.Invoke 80
19 System.Windows.Threading.Dispatcher.Dispatch 404
I am using the following code to push new page
Uri navigateUritemp = new Uri(url, UriKind.RelativeOrAbsolute);
if(scrObj.NavigationService.CurrentSource != navigateUritemp)
{
scrObj.NavigationService.Navigate(navigateUritemp);
}
It looks the following line is throwing invalidoperationexception
scrObj.NavigationService.Navigate(navigateUritemp);
can someone tell what is wrong in this code?
One common situation in which I've seen this InvalidOperationException happen is if multiple navigations are attempted simultaneously, or if a navigation attempt occurs while the app is not in the foreground.
This can happen, for example, if a user manages to hit an appbar button a second time while a slow navigation is occurring.
A quick search reveals others have seen the same sort of thing - e.g. http://www.nickharris.net/2011/01/windows-phone-7-navigation-is-not-allowed-when-the-task-is-not-in-the-foreground/
Try to use if (scrObj.NavigationService.CurrentSource.equals(navigateUritemp)) Maybe this will help. Are you getting this exception all the time?
Try to do the following:
Create a new project and remove the rest of your code and keep the code related to NavigationService.
Crate a folder (Name the folder something like homescreen)
Add 2 XAML pages (eg: Page1.xaml, Page2.xaml)
Test NavigationService code from MainPage.xaml
Try this:
NavigationService.Navigate(new Uri("/homescreen/Page1.xaml", UriKind.Relative));
or
NavigationService.Navigate(new Uri("/homescreen/Page2.xaml", UriKind.Relative));
if you are using UriKind.Relative make sure to specify the correct path, eg: if you use "homescreen/Page2.xaml" it want work, you have to use "/homescreen/Page2.xaml", " / " at the beginning of your path is like "root" or "~" in ASP.NET

Code Golf: Duplicate Character Removal in String

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
The challenge: The shortest code, by character count, that detects and removes duplicate characters in a String. Removal includes ALL instances of the duplicated character (so if you find 3 n's, all three have to go), and original character order needs to be preserved.
Example Input 1:
nbHHkRvrXbvkn
Example Output 1:
RrX
Example Input 2:
nbHHkRbvnrXbvkn
Example Output 2:
RrX
(the second example removes letters that occur three times; some solutions have failed to account for this)
(This is based on my other question where I needed the fastest way to do this in C#, but I think it makes good Code Golf across languages.)
LabVIEW 7.1
ONE character and that is the blue constant '1' in the block diagram.
I swear, the input was copy and paste ;-)
http://i25.tinypic.com/hvc4mp.png
http://i26.tinypic.com/5pnas.png
Perl
21 characters of perl, 31 to invoke, 36 total keystrokes (counting shift and final return):
perl -pe's/$1//gwhile/(.).*\1/'
Ruby — 61 53 51 56 35
61 chars, the ruler says. (Gives me an idea for another code golf...)
puts ((i=gets.split(''))-i.select{|c|i.to_s.count(c)<2}).join
+-------------------------------------------------------------------------+
|| | | | | | | | | | | | | | | |
|0 10 20 30 40 50 60 70 |
| |
+-------------------------------------------------------------------------+
gets.chars{|c|$><<c[$_.count(c)-1]}
... 35 by Nakilon
APL
23 characters:
(((1+ρx)-(ϕx)ιx)=xιx)/x
I'm an APL newbie (learned it yesterday), so be kind -- this is certainly not the most efficient way to do it. I'm ashamed I didn't beat Perl by very much.
Then again, maybe it says something when the most natural way for a newbie to solve this problem in APL was still more concise than any other solution in any language so far.
Python:
s=raw_input()
print filter(lambda c:s.count(c)<2,s)
This is a complete working program, reading from and writing to the console. The one-liner version can be directly used from the command line
python -c 's=raw_input();print filter(lambda c:s.count(c)<2,s)'
J (16 12 characters)
(~.{~[:I.1=#/.~)
Example:
(~.{~[:I.1=#/.~) 'nbHHkRvrXbvkn'
RrX
It only needs the parenthesis to be executed tacitly. If put in a verb, the actual code itself would be 14 characters.
There certainly are smarter ways to do this.
EDIT: The smarter way in question:
(~.#~1=#/.~) 'nbHHkRvrXbvkn'
RrX
12 characters, only 10 if set in a verb. I still hate the fact that it's going through the list twice, once to count (#/.) and another to return uniques (nub or ~.), but even nubcount, a standard verb in the 'misc' library does it twice.
Haskell
There's surely shorter ways to do this in Haskell, but:
Prelude Data.List> let h y=[x|x<-y,(<2).length$filter(==x)y]
Prelude Data.List> h "nbHHkRvrXbvkn"
"RrX"
Ignoring the let, since it's only required for function declarations in GHCi, we have h y=[x|x<-y,(<2).length$filter(==x)y], which is 37 characters (this ties the current "core" Python of "".join(c for c in s if s.count(c)<2), and it's virtually the same code anyway).
If you want to make a whole program out of it,
h y=[x|x<-y,(<2).length$filter(==x)y]
main=interact h
$ echo "nbHHkRvrXbvkn" | runghc tmp.hs
RrX
$ wc -c tmp.hs
54 tmp.hs
Or we can knock off one character this way:
main=interact(\y->[x|x<-y,(<2).length$filter(==x)y])
$ echo "nbHHkRvrXbvkn" | runghc tmp2.hs
RrX
$ wc -c tmp2.hs
53 tmp2.hs
It operates on all of stdin, not line-by-line, but that seems acceptable IMO.
C89 (106 characters)
This one uses a completely different method than my original answer. Interestingly, after writing it and then looking at another answer, I saw the methods were very similar. Credits to caf for coming up with this method before me.
b[256];l;x;main(c){while((c=getchar())>=0)b[c]=b[c]?1:--l;
for(;x-->l;)for(c=256;c;)b[--c]-x?0:putchar(c);}
On one line, it's 58+48 = 106 bytes.
C89 (173 characters)
This was my original answer. As said in the comments, it doesn't work too well...
#include<stdio.h>
main(l,s){char*b,*d;for(b=l=s=0;l==s;s+=fread(b+s,1,9,stdin))b=realloc(b,l+=9)
;d=b;for(l=0;l<s;++d)if(!memchr(b,*d,l)&!memchr(d+1,*d,s-l++-1))putchar(*d);}
On two lines, it's 17+1+78+77 = 173 bytes.
C#
65 Characters:
new String(h.Where(x=>h.IndexOf(x)==h.LastIndexOf(x)).ToArray());
67 Characters with reassignment:
h=new String(h.Where(x=>h.IndexOf(x)==h.LastIndexOf(x)).ToArray());
C#
new string(input.GroupBy(c => c).Where(g => g.Count() == 1).ToArray());
71 characters
PHP (136 characters)
<?PHP
function q($x){return $x<2;}echo implode(array_keys(array_filter(
array_count_values(str_split(stream_get_contents(STDIN))),'q')));
On one line, it's 5+1+65+65 = 136 bytes. Using PHP 5.3 you could save a few bytes making the function anonymous, but I can't test that now. Perhaps something like:
<?PHP
echo implode(array_keys(array_filter(array_count_values(str_split(
stream_get_contents(STDIN))),function($x){return $x<2;})));
That's 5+1+66+59 = 131 bytes.
another APL solution
As a dynamic function (18 charachters)
{(1+=/¨(ω∘∊¨ω))/ω}
line assuming that input is in variable x (16 characters):
(1+=/¨(x∘∊¨x))/x
VB.NET
For Each c In s : s = IIf(s.LastIndexOf(c) <> s.IndexOf(c), s.Replace(CStr(c), Nothing), s) : Next
Granted, VB is not the optimal language to try to save characters, but the line comes out to 98 characters.
PowerShell
61 characters. Where $s="nbHHkRvrXbvkn" and $a is the result.
$h=#{}
($c=[char[]]$s)|%{$h[$_]++}
$c|%{if($h[$_]-eq1){$a+=$_}}
Fully functioning parameterized script:
param($s)
$h=#{}
($c=[char[]]$s)|%{$h[$_]++}
$c|%{if($h[$_]-eq1){$a+=$_}}
$a
C: 83 89 93 99 101 characters
O(n2) time.
Limited to 999 characters.
Only works in 32-bit mode (due to not #include-ing <stdio.h> (costs 18 chars) making the return type of gets being interpreted as an int and chopping off half of the address bits).
Shows a friendly "warning: this program uses gets(), which is unsafe." on Macs.
.
main(){char s[999],*c=gets(s);for(;*c;c++)strchr(s,*c)-strrchr(s,*c)||putchar(*c);}
(and this similar 82-chars version takes input via the command line:
main(char*c,char**S){for(c=*++S;*c;c++)strchr(*S,*c)-strrchr(*S,*c)||putchar(*c);}
)
Golfscript(sym) - 15
.`{\{=}+,,(!}+,
+-------------------------------------------------------------------------+
|| | | | | | | | | | | | | | | |
|0 10 20 30 40 50 60 70 |
| |
+-------------------------------------------------------------------------+
Haskell
(just knocking a few characters off Mark Rushakoff's effort, I'd rather it was posted as a comment on his)
h y=[x|x<-y,[_]<-[filter(==x)y]]
which is better Haskell idiom but maybe harder to follow for non-Haskellers than this:
h y=[z|x<-y,[z]<-[filter(==x)y]]
Edit to add an explanation for hiena and others:
I'll assume you understand Mark's version, so I'll just cover the change. Mark's expression:
(<2).length $ filter (==x) y
filters y to get the list of elements that == x, finds the length of that list and makes sure it's less than two. (in fact it must be length one, but ==1 is longer than <2 ) My version:
[z] <- [filter(==x)y]
does the same filter, then puts the resulting list into a list as the only element. Now the arrow (meant to look like set inclusion!) says "for every element of the RHS list in turn, call that element [z]". [z] is the list containing the single element z, so the element "filter(==x)y" can only be called "[z]" if it contains exactly one element. Otherwise it gets discarded and is never used as a value of z. So the z's (which are returned on the left of the | in the list comprehension) are exactly the x's that make the filter return a list of length one.
That was my second version, my first version returns x instead of z - because they're the same anyway - and renames z to _ which is the Haskell symbol for "this value isn't going to be used so I'm not going to complicate my code by giving it a name".
Javascript 1.8
s.split('').filter(function (o,i,a) a.filter(function(p) o===p).length <2 ).join('');
or alternately- similar to the python example:
[s[c] for (c in s) if (s.split("").filter(function(p) s[c]===p).length <2)].join('');
TCL
123 chars. It might be possible to get it shorter, but this is good enough for me.
proc h {i {r {}}} {foreach c [split $i {}] {if {[llength [split $i $c]]==2} {set r $r$c}}
return $r}
puts [h [gets stdin]]
C
Full program in C, 141 bytes (counting newlines).
#include<stdio.h>
c,n[256],o,i=1;main(){for(;c-EOF;c=getchar())c-EOF?n[c]=n[c]?-1:o++:0;for(;i<o;i++)for(c=0;c<256;c++)n[c]-i?0:putchar(c);}
Scala
54 chars for the method body only, 66 with (statically typed) method declaration:
def s(s:String)=(""/:s)((a,b)=>if(s.filter(c=>c==b).size>1)a else a+b)
Ruby
63 chars.
puts (t=gets.split(//)).map{|i|t.count(i)>1?nil:i}.compact.join
VB.NET / LINQ
96 characters for complete working statement
Dim p=New String((From c In"nbHHkRvrXbvkn"Group c By c Into i=Count Where i=1 Select c).ToArray)
Complete working statement, with original string and the VB Specific "Pretty listing (reformatting of code" turned off, at 96 characters, non-working statement without original string at 84 characters.
(Please make sure your code works before answering. Thank you.)
C
(1st version: 112 characters; 2nd version: 107 characters)
k[256],o[100000],p,c;main(){while((c=getchar())!=-1)++k[o[p++]=c];for(c=0;c<p;c++)if(k[o[c]]==1)putchar(o[c]);}
That's
/* #include <stdio.h> */
/* int */ k[256], o[100000], p, c;
/* int */ main(/* void */) {
while((c=getchar()) != -1/*EOF*/) {
++k[o[p++] = /*(unsigned char)*/c];
}
for(c=0; c<p; c++) {
if(k[o[c]] == 1) {
putchar(o[c]);
}
}
/* return 0; */
}
Because getchar() returns int and putchar accepts int, the #include can 'safely' be removed.
Without the include, EOF is not defined, so I used -1 instead (and gained a char).
This program only works as intended for inputs with less than 100000 characters!
Version 2, with thanks to strager
107 characters
#ifdef NICE_LAYOUT
#include <stdio.h>
/* global variables are initialized to 0 */
int char_count[256]; /* k in the other layout */
int char_order[999999]; /* o ... */
int char_index; /* p */
int main(int ch_n_loop, char **dummy) /* c */
/* variable with 2 uses */
{
(void)dummy; /* make warning about unused variable go away */
while ((ch_n_loop = getchar()) >= 0) /* EOF is, by definition, negative */
{
++char_count[ ( char_order[char_index++] = ch_n_loop ) ];
/* assignment, and increment, inside the array index */
}
/* reuse ch_n_loop */
for (ch_n_loop = 0; ch_n_loop < char_index; ch_n_loop++) {
(char_count[char_order[ch_n_loop]] - 1) ? 0 : putchar(char_order[ch_n_loop]);
}
return 0;
}
#else
k[256],o[999999],p;main(c){while((c=getchar())>=0)++k[o[p++]=c];for(c=0;c<p;c++)k[o[c]]-1?0:putchar(o[c]);}
#endif
Javascript 1.6
s.match(/(.)(?=.*\1)/g).map(function(m){s=s.replace(RegExp(m,'g'),'')})
Shorter than the previously posted Javascript 1.8 solution (71 chars vs 85)
Assembler
Tested with WinXP DOS box (cmd.exe):
xchg cx,bp
std
mov al,2
rep stosb
inc cl
l0: ; to save a byte, I've encoded the instruction to exit the program into the
; low byte of the offset in the following instruction:
lea si,[di+01c3h]
push si
l1: mov dx,bp
mov ah,6
int 21h
jz l2
mov bl,al
shr byte ptr [di+bx],cl
jz l1
inc si
mov [si],bx
jmp l1
l2: pop si
l3: inc si
mov bl,[si]
cmp bl,bh
je l0+2
cmp [di+bx],cl
jne l3
mov dl,bl
mov ah,2
int 21h
jmp l3
Assembles to 53 bytes. Reads standard input and writes results to standard output, eg:
programname < input > output
PHP
118 characters actual code (plus 6 characters for the PHP block tag):
<?php
$s=trim(fgets(STDIN));$x='';while(strlen($s)){$t=str_replace($s[0],'',substr($s,1),$c);$x.=$c?'':$s[0];$s=$t;}echo$x;
C# (53 Characters)
Where s is your input string:
new string(s.Where(c=>s.Count(h=>h==c)<2).ToArray());
Or 59 with re-assignment:
var a=new string(s.Where(c=>s.Count(h=>h==c)<2).ToArray());
Haskell Pointfree
import Data.List
import Control.Monad
import Control.Arrow
main=interact$liftM2(\\)nub$ap(\\)nub
The whole program is 97 characters, but the real meat is just 23 characters. The rest is just imports and bringing the function into the IO monad. In ghci with the modules loaded it's just
(liftM2(\\)nub$ap(\\)nub) "nbHHkRvrXbvkn"
In even more ridiculous pointfree style (pointless style?):
main=interact$liftM2 ap liftM2 ap(\\)nub
It's a bit longer though at 26 chars for the function itself.
Shell/Coreutils, 37 Characters
fold -w1|sort|uniq -u|paste -s -d ''

Resources