mirror of
				https://github.com/pragma-/pbot.git
				synced 2025-10-31 06:37:35 +01:00 
			
		
		
		
	Improvements to code-factoids
Most code languages now accept factoida arguments as command-line arguments; e.g., argc and argv in C/C++, args[] in Java, @ARGV in Perl, etc. No longer say "Same output" for code-factoids.
This commit is contained in:
		
							parent
							
								
									1ec94d6956
								
							
						
					
					
						commit
						e43d2ef144
					
				| @ -662,7 +662,7 @@ sub execute_code_factoid_using_vm { | ||||
|     $code = $self->expand_action_arguments($code, $arguments, $nick); | ||||
|   } | ||||
| 
 | ||||
|   my %h = (nick => $nick, channel => $from, lang => $lang, code => $code, arguments => $arguments); | ||||
|   my %h = (nick => $nick, channel => $from, lang => $lang, code => $code, arguments => $arguments, factoid => "$chan:$keyword"); | ||||
|   my $json = encode_json \%h; | ||||
|   $self->{pbot}->{factoids}->{factoidmodulelauncher}->execute_module($from, $tonick, $nick, $user, $host, 'code-factoid', $chan, $root_keyword, "compiler", $json, 0); | ||||
|   return ""; | ||||
|  | ||||
| @ -136,7 +136,7 @@ sub execute { | ||||
|       gdb $in, "set height 0\n"; | ||||
|       gdb $in, "set auto-solib-add off\n"; | ||||
|       gdb $in, "catch exec\n"; | ||||
|       gdb $in, "run < .input\n"; | ||||
|       gdb $in, "run @ARGV < .input\n"; | ||||
|       next; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -32,6 +32,7 @@ sub new { | ||||
|   $self->{code}        = $conf{code}; | ||||
|   $self->{max_history} = $conf{max_history} // 10000; | ||||
|   $self->{arguments}   = $conf{arguments}; | ||||
|   $self->{factoid}     = $conf{factoid}; | ||||
| 
 | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'echo Hello, world!'; | ||||
| @ -42,6 +43,9 @@ sub new { | ||||
|   $self->{lang}    =~ s/^\s+|\s+$//g if defined $self->{lang}; | ||||
|   $self->{code}    =~ s/^\s+|\s+$//g if defined $self->{code}; | ||||
| 
 | ||||
|   $self->{arguments} = quotemeta $self->{arguments}; | ||||
|   $self->{arguments} =~ s/\\ / /g; | ||||
| 
 | ||||
|   $self->initialize(%conf); | ||||
| 
 | ||||
|   return $self; | ||||
| @ -239,7 +243,7 @@ sub show_output { | ||||
|       } | ||||
|       close FILE; | ||||
| 
 | ||||
|       if(defined $last_output and $last_output eq $output) { | ||||
|       if((not $self->{factoid}) and defined $last_output and $last_output eq $output) { | ||||
|         print "Same output.\n"; | ||||
|         exit 0; | ||||
|       } | ||||
|  | ||||
| @ -18,6 +18,10 @@ sub initialize { | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'bash $options $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| 
 | ||||
|   $self->{cmdline_opening_comment} = ": <<'____CMDLINE____'\n"; | ||||
|   $self->{cmdline_closing_comment} = "____CMDLINE____\n"; | ||||
| 
 | ||||
|  | ||||
| @ -18,6 +18,10 @@ sub initialize { | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'clisp $options $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| 
 | ||||
|   $self->{sprunge_lexer}   = 'cl'; | ||||
| 
 | ||||
|   $self->{cmdline_opening_comment} = "#|=============== CMDLINE ===============\n"; | ||||
|  | ||||
| @ -16,7 +16,11 @@ sub initialize { | ||||
|   $self->{sourcefile}      = 'prog.go'; | ||||
|   $self->{execfile}        = 'prog'; | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'golang-go $options run $sourcefile'; | ||||
|   $self->{cmdline}         = 'go $options run $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| 1; | ||||
|  | ||||
| @ -18,6 +18,10 @@ sub initialize { | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'ghc -v0 $options -o $execfile $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| 
 | ||||
|   $self->{cmdline_opening_comment} = "{-|\n=============== CMDLINE ===============\n"; | ||||
|   $self->{cmdline_closing_comment} = "=============== CMDLINE ===============\n-}\n"; | ||||
| 
 | ||||
|  | ||||
| @ -18,6 +18,10 @@ sub initialize { | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'd8 $options $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| 
 | ||||
|   $self->{cmdline_opening_comment} = "/************* CMDLINE *************\n"; | ||||
|   $self->{cmdline_closing_comment} = "************** CMDLINE *************/\n"; | ||||
| 
 | ||||
|  | ||||
| @ -18,6 +18,10 @@ sub initialize { | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'ksh $options $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| 
 | ||||
|   $self->{cmdline_opening_comment} = ": <<'____CMDLINE____'\n"; | ||||
|   $self->{cmdline_closing_comment} = "____CMDLINE____\n"; | ||||
| 
 | ||||
|  | ||||
| @ -18,6 +18,10 @@ sub initialize { | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'lua $options $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| 
 | ||||
|   $self->{cmdline_opening_comment} = "--[[--------------- CMDLINE ---------------\n"; | ||||
|   $self->{cmdline_closing_comment} = "------------------- CMDLINE ---------------]]\n"; | ||||
| 
 | ||||
|  | ||||
| @ -19,6 +19,10 @@ sub initialize { | ||||
|   $self->{execfile}        = 'prog.pl'; | ||||
|   $self->{default_options} = '-w'; | ||||
|   $self->{cmdline}         = 'perl $options $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| sub preprocess_code { | ||||
| @ -26,8 +30,6 @@ sub preprocess_code { | ||||
|   $self->SUPER::preprocess_code; | ||||
| 
 | ||||
|   if (defined $self->{arguments}) { | ||||
|     my $qargs = quotemeta $self->{arguments}; | ||||
|     $qargs =~ s/\\ / /g; | ||||
|     my @args = shellwords($self->{arguments}); | ||||
|     my $prelude .= "\nmy \$arglen = " . (scalar @args) . ";\n"; | ||||
| 
 | ||||
|  | ||||
| @ -18,6 +18,10 @@ sub initialize { | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'python $options $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| 
 | ||||
|   $self->{cmdline_opening_comment} = "'''\n=============== CMDLINE ===============\n"; | ||||
|   $self->{cmdline_closing_comment} = "=============== CMDLINE ===============\n'''\n"; | ||||
| 
 | ||||
|  | ||||
| @ -18,6 +18,10 @@ sub initialize { | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'python3 $options $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| 
 | ||||
|   $self->{cmdline_opening_comment} = "'''\n=============== CMDLINE ===============\n"; | ||||
|   $self->{cmdline_closing_comment} = "=============== CMDLINE ===============\n'''\n"; | ||||
| 
 | ||||
|  | ||||
| @ -15,8 +15,6 @@ sub preprocess { | ||||
|   $self->SUPER::preprocess; | ||||
| 
 | ||||
|   if ($self->{cmdline} =~ m/--(?:version|analyze)/) { | ||||
|     $self->{output} =~ s/Ubuntu //; | ||||
|     $self->{output} =~ s/-\d+ubuntu\d+//; | ||||
|     $self->{done} = 1; | ||||
|   } | ||||
| } | ||||
| @ -33,7 +31,7 @@ sub postprocess { | ||||
|   } | ||||
| 
 | ||||
|   print "Executing gdb\n"; | ||||
|   my ($retval, $result) = $self->execute(60, "bash -c \"date -s \@$self->{date}; ulimit -t 5; compiler_watchdog.pl > .output\""); | ||||
|   my ($retval, $result) = $self->execute(60, "bash -c \"date -s \@$self->{date}; ulimit -t 5; compiler_watchdog.pl $self->{arguments} > .output\""); | ||||
| 
 | ||||
|   $result = ""; | ||||
|   open(FILE, '.output'); | ||||
|  | ||||
| @ -23,6 +23,8 @@ sub new { | ||||
|   $self->{cmdline}     = $conf{cmdline}; | ||||
|   $self->{input}       = $conf{input}; | ||||
|   $self->{date}        = $conf{date}; | ||||
|   $self->{arguments}   = $conf{arguments}; | ||||
|   $self->{factoid}     = $conf{factoid}; | ||||
| 
 | ||||
|   $self->initialize(%conf); | ||||
| 
 | ||||
| @ -104,6 +106,7 @@ sub execute { | ||||
|     my $pid = open(my $fh, '-|', "$cmdline 2>&1"); | ||||
| 
 | ||||
|     local $SIG{ALRM} = sub { print "Time out\n"; kill 'TERM', $pid; die "$result [Timed-out]\n"; }; | ||||
|     local $SIG{CHLD} = 'IGNORE'; | ||||
|     alarm($timeout); | ||||
| 
 | ||||
|     while(my $line = <$fh>) { | ||||
|  | ||||
| @ -32,7 +32,7 @@ sub postprocess { | ||||
|   print "Executing java\n"; | ||||
|   my $input_quoted = quotemeta $self->{input}; | ||||
|   $input_quoted =~ s/\\"/"'\\"'"/g; | ||||
|   my ($retval, $result) = $self->execute(60, "bash -c \"date -s \@$self->{date}; ulimit -t 5; echo $input_quoted | java prog > .output\""); | ||||
|   my ($retval, $result) = $self->execute(60, "bash -c \"date -s \@$self->{date}; ulimit -t 5; echo $input_quoted | java prog $self->{arguments} > .output\""); | ||||
| 
 | ||||
|   $result = ""; | ||||
|   open(FILE, '.output'); | ||||
|  | ||||
| @ -18,6 +18,10 @@ sub initialize { | ||||
|   $self->{default_options} = ''; | ||||
|   $self->{cmdline}         = 'sh $options $sourcefile'; | ||||
| 
 | ||||
|   if (length $self->{arguments}) { | ||||
|     $self->{cmdline} .= " $self->{arguments}"; | ||||
|   } | ||||
| 
 | ||||
|   $self->{cmdline_opening_comment} = ": <<'____CMDLINE____'\n"; | ||||
|   $self->{cmdline_closing_comment} = "____CMDLINE____\n"; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Pragmatic Software
						Pragmatic Software