Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Coders! Looking for a quick script for language file  (Read 542 times)

nunix

  • Bay Watcher
    • View Profile
Coders! Looking for a quick script for language file
« on: March 25, 2008, 04:28:00 pm »

So been messing with entity modding, and I've put together a word list for a new language file.. but getting all the words into the new file looks kind of like a nightmare. =( They start on line 6 and end at line 2108...

Was hoping someone might be up for writing a couple of simple scripts (perl or something) that would do the following:

1) Strip out all the characters between the last : and ] in one of the language_ files (theoretically only need to do it once to generate a "clean" file, but if there are more words added later, this would solve having to do-over and redistribute. Probably works best if you just make a copy of one of the files, rename it language_new and strip out the header stuff, so you have only the T_WORD lines, starting at line 1 in the file)

2) Input in words from a second file into that space between the last : and ], just match up line-for-line, i.e. the characters in line 1 of wordlist.txt goes into T_WORD:ABBEY:<here>

Any takers? =D

Logged

Capntastic

  • Bay Watcher
  • Greetings, mortals!
    • View Profile
    • A review and literature weblog I never update
Re: Coders! Looking for a quick script for language file
« Reply #1 on: March 25, 2008, 05:09:00 pm »

You could do this pretty quickly by yourself using Python.   Or other languages, too.   But Python would be quick for you to pick up.
Logged

numerobis

  • Bay Watcher
    • View Profile
Re: Coders! Looking for a quick script for language file
« Reply #2 on: March 25, 2008, 11:33:00 pm »

Here's a perl script that does what you want, I think.  It prints to the screen; redirect to a file using the > operator.  Of course, it might delete every file on your hard drive *and* make the Nile run red with the blood of the first-borns, among other things.  But if you trust me (I already fixed a bug a second after posting):

code:
perl foo.pl raw/objects/language_DWARF.txt mywords > newlang_DWARF.txt


code:

#! /usr/local/bin/perl -w
use strict;

die "too few / too many args" unless @ARGV == 2;

my ($langfile, $replacefile) = @ARGV;

open(LANG, $langfile) or die "failed to open language file `$langfile': $!";
open(REP, $replacefile) or die "failed to open replacements `$replacefile': $!";

while(<LANG> ) {
 do { print $_; next; } unless /T_WORD/;

 my ($tword, $type, $original) = split/:/;
 my $newword = <REP>;
 die "no replacement for $type\n" unless defined $newword;
 chomp $newword;
 print "$tword:$type:$newword]\n";
}


[ March 26, 2008: Message edited by: benoit.hudson ]

[ March 26, 2008: Message edited by: benoit.hudson ]

Logged

nunix

  • Bay Watcher
    • View Profile
Re: Coders! Looking for a quick script for language file
« Reply #3 on: March 25, 2008, 11:59:00 pm »

Thanks, I'll give it a shot tomorrow (still working on finishing up my wordlist, 2102 entries is a lot o.O)
Logged

bartavelle

  • Bay Watcher
  • Coin coin!
    • View Profile
Re: Coders! Looking for a quick script for language file
« Reply #4 on: March 28, 2008, 10:59:00 am »

let's start golfing

code:
 perl -pe 's/:[^:]+]/:]/' language_DWARF.txt > language_DWARF.new  

Logged