Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -0,0 +1,34 @@
# syntax: GAWK -f MAD_LIBS.AWK
BEGIN {
print("enter story:")
}
{ story_arr[++nr] = $0
if ($0 ~ /^ *$/) {
exit
}
while ($0 ~ /[<>]/) {
L = index($0,"<")
R = index($0,">")
changes_arr[substr($0,L,R-L+1)] = ""
sub(/</,"",$0)
sub(/>/,"",$0)
}
}
END {
PROCINFO["sorted_in"] = "@ind_str_asc"
print("enter values for:")
for (i in changes_arr) { # prompt for replacement values
printf("%s ",i)
getline rec
sub(/ +$/,"",rec)
changes_arr[i] = rec
}
printf("\nrevised story:\n")
for (i=1; i<=nr; i++) { # print the story
for (j in changes_arr) {
gsub(j,changes_arr[j],story_arr[i])
}
printf("%s\n",story_arr[i])
}
exit(0)
}

View file

@ -0,0 +1,48 @@
#include <iostream>
#include <string>
using namespace std;
int main()
{
string story, input;
//Loop
while(true)
{
//Get a line from the user
getline(cin, input);
//If it's blank, break this loop
if(input == "\r")
break;
//Add the line to the story
story += input;
}
//While there is a '<' in the story
int begin;
while((begin = story.find("<")) != string::npos)
{
//Get the category from between '<' and '>'
int end = story.find(">");
string cat = story.substr(begin + 1, end - begin - 1);
//Ask the user for a replacement
cout << "Give me a " << cat << ": ";
cin >> input;
//While there's a matching category
//in the story
while((begin = story.find("<" + cat + ">")) != string::npos)
{
//Replace it with the user's replacement
story.replace(begin, cat.length()+2, input);
}
}
//Output the final story
cout << endl << story;
return 0;
}

View file

@ -0,0 +1,13 @@
FileSelectFile, filename, , %A_ScriptDir%, Select a Mad Libs template, *.txt
If ErrorLevel
ExitApp ; the user canceled the file selection
FileRead, contents, %filename%
pos := match := 0
While pos := RegExMatch(contents, "<[^>]+>", match, pos+strLen(match))
{
InputBox, repl, Mad Libs, Enter a replacement for %match%:
If ErrorLevel ; cancelled inputbox
ExitApp
StringReplace, contents, contents, %match%, %repl%, All
}
MsgBox % contents

View file

@ -0,0 +1,71 @@
(stringrange, stringsize): /* 2 Nov. 2013 */
Mad_Libs: procedure options (main);
declare (line, left, right) character (100) varying;
declare true bit(1) value ('1'b), false bit (1) value ('0'b);
declare name character (20) varying, seen_name bit (1) initial (false);
declare pronoun character (20) varying, seen_pronoun bit (1) initial (false);
declare noun character (20) varying, seen_noun bit (1) initial (false);
declare replaced_all bit (1);
declare in file input;
open file (in) title ('/MADLIBS.DAT,type(text),recsize(100)');
do forever;
get file (in) edit (line) (L);
if line = '' then leave;
do until (replaced_all);
replaced_all = true;
if index(line, '<name>') > 0 then
if seen_name then
do until (index(line, '<name>') = 0);
call split(line, '<name>', left, right);
line = left || name || right;
replaced_all = false;
end;
else
do;
put skip list ('Please type a name:');
get edit (name) (L);
seen_name = true; replaced_all = false;
end;
if index(line, '<he or she>') > 0 then
if seen_pronoun then
do until (index(line, '<he or she>') = 0);
call split(line, '<he or she>', left, right);
line = left || pronoun || right;
replaced_all = false;
end;
else
do;
put skip list ('Please type a pronoun (he or she):');
get edit (pronoun) (L);
seen_pronoun = true; replaced_all = false;
end;
if index(line, '<noun>') > 0 then
if seen_noun then
do until (index(line, '<noun>') = 0);
call split(line, '<noun>', left, right);
line = left || noun || right;
replaced_all = false;
end;
else
do;
put skip list ('Please type a noun:');
get edit (noun) (L);
seen_noun = true; replaced_all = false;
end;
end;
put skip list (line);
end;
split: procedure (line, text, Left, Right);
declare (line, text, left, right) character (*) varying;
declare i fixed binary;
i = index(line, text);
left = substr(line, 1, i-1);
right = substr(line, i+length(text), length(line) - (i + length(text)) + 1 );
end split;
end Mad_Libs;

View file

@ -0,0 +1,19 @@
#!/usr/bin/perl
use warnings;
use strict;
my $template = shift;
open my $IN, '<', $template or die $!;
my $story = do { local $/ ; <$IN> };
my %blanks;
undef $blanks{$_} for $story =~ m/<(.*?)>/g;
for my $blank (sort keys %blanks) {
print "$blank: ";
chomp (my $replacement = <>);
$blanks{$blank} = $replacement;
}
$story =~ s/<(.*?)>/$blanks{$1}/g;
print $story;