www.vitenka.com | ToothyWiki | Vitenka | RecentChanges | Login | Webcomic

Macros are Evil.  Templates are painful.  By their powers combined, they are...
 #ifndef CompileTimeAssert?
    template<int> struct CompileTimeAssert?;
    template<> struct CompileTimeAssert?<true> {};
    #define JOIN_(a) a
    #define JOIN(a, b) JOIN_(a)JOIN_(b)
    #define CompileTimeAssert?(expr) typedef \
              CompileTimeAssert?<sizeof(CompileTimeAssert?<(expr)>)> \
              JOIN(CompileTimeAssert?, __LINE__)

Not mine originally, sadly.

DOH.  The files are included in the opposite order I thought they were.  It does indeed work the way I had it, but the other file has to do the defining.  Stupid stupid me.
AlexChurchill liked the way that your make utility tries to pronounce itself differently in his head to all the others :) gmake to me is "gee-make", wmake is "doble-you-make", but omake to me is "oh-mah-kay" ;)
For reference, I find myself pronouncing FanArt? / OutTakes? as oh-make.  --Vitenka

Yay.  I just bought a DVD burner from the store.  And after getting one that was broken (probable cause - bad eeprom data, it was returning a broken id string even) I got one...
That's got my code in.
Yay!  MSI? 16x+-R 8x+DL 8x+-RW is, in actuality, a dataref6 from Philips.  It does the 12x-burn-on-8x-disks thing.  And that's my code.  And so is the code to turn off CSS restrictions :)  --Vitenka

Ok actual tech support question.
My MotherBoard? is is complaining that my -5v ground is actually sitting at -6.2v  I told it "Shut up and boot anyway" and everything seems ok, but is this actually going to be a problem?  The power supply is a brand-new 360W ATX, it used to be a 300W ATS (whatever that is, it looks like an ATX to me) and started making funny noises so got yoinked.  I can't find anything online.  --Vitenka

I tend to check the [sci.electronics repair FAQ] for things like that. I remember coming across a reference in there implying that switching mode PSUs use one of the lines as reference for the rest, so faults rarely happen to one line in isolation and it's possible to get some *really* weird effect because of this, but can't find it right now :) I personally have yet to see a sub-450W ATX PSU that *isn't* flaky in one way or another. - MoonShadow
Didn't find anything.  I'd better check again.  --Vitenka

Anyone got a decent free directory and file compare tool?  An araxis clone would be perfect.  Three-way comparisons desired, but I can cope without.  --Vitenka
Never mind, work has supplied a SiteLicence? for Araxis.  Annoying that my web-trawl found only unusable junk, though.  --Vitenka

Whilst I'm filling up this page - something that took me ages to find.

XP Home, Samba, Samba 3, windows networking, share, howto.
Here is how to convince samba3 to talk to XP home.  Much googling did not reveal this information, so it's going here.  First of all, follow the basic stand alone server guide.  (For example [this one].  Now, take notice of two critically important things.  First, you need a 'hosts allow' line - setting which systems are allowed to talk to your host.  You NEED to set this to the LAN, otherwise everyone will be able to edit your files.  Then you absolutely positively must set 'wins server' to the IP ADDRESS of your XP box.

With this configuration, a win98 machine should be able to see it too, as long as it is set not to log in to any domains.  It may help to set the 98 server to use the same XP box for WINS resolution.

If you want seperate username/password pairs, rather than just 'everyone logs in as guest without a password' then.. well, screw you.  I had a hard enough time getting past the mess that is the net guides (half of which are written for samba2) to get this working.  If you get it working, please to tell me.

Note - it's very slow to transfer files.  But it does work - both on the 98 box and the XP box.

Quick CommandLine? based FindAndReplace? tool for a TextFile? under Windows?  --Vitenka (Req: Find first instance, replace with foo, find second instance, replace with bar - prefer read foo and bar from an external file)
Cygwin?, cat and sed. (It's what I use for similar tasks, and it does do the job very well - but it's a bit sledgehammer-like for this particular nut.) If foo and bar need to vary, I'd probably use perl. (Sorry, this isn't helping, is it?) --AC
MoonShadow would likewise use perl. Something like the quick hacky untested thing below should probably work.

#! perl -w
# usage: script.pl string-to-search-for < input-data > output-data
# First match will be replaced with first line of externalfile, second match with second ..
# No replacements will be made once we run out of lines in externalfile
use FileHandle;
my $fh = new FileHandle( '<externalfile' ) or die;
my @foobar = <$fh>;

my $searchstring = join(' ', @ARGV);
my $instcount = 0;

sub replace
  my($match) = @_;
  if($instcount <= $#foobar)
	  $foobar[$instcount] =~ s/[\n\r]//g;
    return $foobar[$instcount++];
  return $match;


Blegh.  I think I have perl (for win32) somewhere.  Ok, I'll be more specific.  I have two files of the form "<fieldname> <value1> <value2> ... " The fieldnames are NOT unique - so retaining order is important.  I'd like to take file2 and replace everything that has the same fieldnames as file1 with file1's lines, but retain all the intervening lines.
So something like, "A 1 2/n B 1 2/n A 3 4/n" merge-with "A 5 6/n A 7 8" becomes "A 5 6/n B 1 2/n A 7 8"  - this seems tailor made for sed, but I've never used sed so don't actually know.  The intention is that this operation would be an intermediate step in a batch file.  File1 is autogenerated and File2 can be hand altered into a more useful format, if that helps.  --Vitenka
HAving read the above script, that's not quite what I want - it looks like it'll replace (in the examples above) A with C, the problem being that the field names are fine, it's just the data of (some selected lines) that needs to change.  I'm not sure how to tweak $searchstring to select the whole line.  --Vitenka
No, I misunderstood your problem - what you originally wrote seemed to imply that given two files, one containing "... A ... A ... A ...." and another containing "B C", you wanted to end up with "... B ... C ... A ...". The following should do what you want (careful, replace file1 file2 and replace file2 file1 produce different outputs!) - MoonShadow

#! perl -w
($#ARGV == 2) or die('usage: merge.pl reference-file target-file output-file'."\n");

use FileHandle;
my %reference = ();

sub AddField
  my($name, $data) = @_;
	defined($reference{$name}) or $reference{$name} = [ ];
	$data =~ s/[\n\r]//g;
	push @{$reference{$name}}, $data;

sub GetField
  my($name, $defaultdata) = @_;
	$defaultdata =~ s/[\n\r]//g;
	(defined($reference{$name}) and ($#{$reference{$name}} > -1))
	  or return $defaultdata;

	return shift @{$reference{$name}};

my $file1 = new FileHandle( '<'.$ARGV[0] ) or die("Couldn't open $ARGV[0]\n");
my $file2 = new FileHandle( '<'.$ARGV[1] ) or die("Couldn't open $ARGV[1]\n");
my $output = new FileHandle( '>'.$ARGV[2] ) or die("Couldn't open $ARGV[2]\n");
  if(/^([^ ]+)( +.+)$/)
	  &AddField($1, $2);

  if(/^([^ ]+)( +.+)$/)
	  print $output $1 . &GetField($1, $2)."\n";
		print $output $_;

Sounds perfect.  Now I just need to work out how to get win32 perl working.  Thanks for the assist.  --Vitenka  (It's the perl bit, not the pipes, I worry about.  But the whole #!/bin/blah is a unix thing, it does nothing on win32 - which changes things a bit.)

For comparison, can we see the sed version?  Because I have a horrible feeling it's going to be something like: sed --replace file1 file2 --format "$1 $*"  (And if not, what language would give me such a simple description for this kind of thing?)  --Vitenka

Hm. Not sure you can do it simply in just sed. awk might be more appropriate, but you'll probably not end up with anything much simpler than the perl version above. There's a tool called join which does almost exactly what you want, except it'd require you to sort your files on fieldname. Still, I am no great expert in any of those. Alex? - MoonShadow
Um - can't do the sort, the output order is sort of required.  In case it helps, what we've got is a bunch of images catenated together and the file I want to edit contains descriptions of where in the file each one starts.  Spatterred through this we have data saying 'the following images form a set' and some metadata about that set - it's that metadata I want to replace (with the same new data each time) - but since this file is autogenerated along with the image-file, I can't just replace it with a static one.  (Compression changes the position within the cat)  The operation is mindboggling simple to do in (say) notepad.  Copy, Find, paste, copy, find, paste... It is unaesthetic that it takes more than a couple of lines of simple code to do it :)  --Vitenka

I think you can do it with sed. The way that would occur to me would be to prepare by first taking the entire input file and replacing every newline with some character known not to occur in the input data (via something like "tr '\n' '£'); then processing one or other of the files so that the "A"s become something else (say "Z"). Then the actual processing becomes a case of processing the reference file so that each line is a sed s command: so a reference file line of "A 5 6" becomes "s/£A[^£]*£/A 5 6/". Then feed the input file to sed using this reference file as a script. Finally turn all your Zs back to As.

So OTTOMH it would look like:
# Assumes 3 input arguments: reference-file target-file output-file
tmptargetfile = replacetmpa$$
tmpreffile = replacetmpb$$
cat $2 | tr '\n' '£' | sed 's#£STARTOFLINE#STARTOFUNPROCESSEDLINE#g;' > $tmptargetfile
sed -r 's#^(STARTOFLINE.*)$#s/£STARTOFLINE[^£]*£/&/#' $1 > $tmpreffile
sed -f $tmpreffile $tmptargetfile | sed 's#£STARTOFUNPROCESSEDLINE#£STARTOFLINE#g;' | tr '£' '\n' > $3

Or if you were really averse to temp files and newlines, the above could be rearranged into the one-line:
# Assumes 3 input arguments: reference-file target-file output-file
cat $2 | tr '\n' '£' | sed 's#£STARTOFLINE#STARTOFUNPROCESSEDLINE#g;' | sed -e "$(sed -r 's#^(STARTOFLINE.*)$#s/£STARTOFLINE[^£]*£/&/#' $1)" | sed 's#£STARTOFUNPROCESSEDLINE#£STARTOFLINE#g;' | tr '£' '\n' > $3

Um - the control file changes infrequently and is hand generated anyway - it might be easier to just write it out by hand rather than hand generating it?
Or, at least, then I might have a prayer of understanding a word of what you just wrote.  :)  --Vitenka

[Yes dammit, when I say 'shutdown' I mean it].  Settings for XP.
That is quite amazingly disturbing. --Admiral

SeeAlso: Vitenka/FirewallRules? and Vitenka/InstallingLinux?

www.vitenka.com | ToothyWiki | Vitenka | RecentChanges | Login | Webcomic
This page is read-only | View other revisions | Recently used referrers
Last edited July 27, 2007 9:13 pm (viewing revision 29, which is the newest) (diff)