Smalltalk, take command line argument as filename - smalltalk

I am new to Smalltalk and am trying to figure out how to take in a command line argument as a filename. I've seen this following snippet online:
f := FileStream open: 'fileName' mode: FileStream read
But I want to know how to modify that based on a user's command line input for the fileName. The following is how this project would be compiled and ran:
gst file1.st file2.st file3.st file4.st -f mainFile.st readThisFile.dat addiotnalArg
So how can I pull the name of the user specified file in Smalltalk?

According to https://www.gnu.org/software/smalltalk/manual/gst.html#Invocation
you can access the command line arguments that are not interpreted by GNU Smalltalk itself with Smalltalk arguments. It will be an array that contains those arguments as Strings.
-a
--smalltalk-args
Treat all options afterward as arguments to be given to Smalltalk code retrievable with Smalltalk arguments, ignoring them as arguments to GNU Smalltalk itself.
[...]
-f
--file
The following two command lines are equivalent:
gst -f file args...
gst -q file -a args...
Since your readThisFile.dat is the first argument, you can access it with Smalltalk arguments at: 1 and put that into your FileStream constructor message:
f := FileStream open: (Smalltalk arguments at: 1) mode: FileStream read
You can also use first
f := FileStream open: Smalltalk arguments first mode: FileStream read.

Related

emacs verilog-mode local variables not parsed

I'm trying to set some Verilog-mode local variables in the SystemVerilog file itself such as:
// Local Variables:
// verilog-library-flags:("-y ../../../ip_lib/")
// verilog-typedef-regexp: ".*_t$"
// verilog-auto-reg-input-assigned-ignore-regexp: ".*")
// End:
And then I call emacs in command line to generate the code:
emacs --batch ./test.sv -f verilog-batch-auto
But that tells me it cannot find module that is supposed to be in ../../../ip_lib/
But then if I use:
emacs -q --eval='(progn (setq-default verilog-library-flags "-y ../../../ip_lib") (setq-default verilog-typedef-regexp ".*_t$"))' --batch ./test.sv -f verilog-batch-auto
it works. What is the issue ?
I don't use verilog, but glancing at your examples I can see that
(setq-default verilog-library-flags "-y ../../../ip_lib")
and
// verilog-library-flags:("-y ../../../ip_lib/")
are setting different types. The former is a string value, while the latter is a list value (containing a single item, being a string).
So that's presumably the issue.

Can we pass a command line argument to property file reader in jmeter

I have a config.property file that contains all the property values to be used in jmeter, so i am using property file reader plugin to read the property file, here the problem is i don't want to hard code the path to config.properties file in property file reader so i want it to pass as command line argument but it is not working
command i am executing is
.\jmeter -JPROPERTY_FILE=<file_location> -n -t <path_to_jmx> -l <path_to_jtl> -j <path_to_log>
In the File Path of Property File Reader, replace:
${PROPERTY_FILE}
By using __P function:
${__P(PROPERTY_FILE)}
Your mistake is that you’re using Variable syntax for a property.
See:
http://jmeter.apache.org/usermanual/functions.html#__P
http://jmeter.apache.org/usermanual/functions.html#functions
You should be using __P() function like ${__P(PROPERTY_FILE)} or even __property() function like ${__property(PROPERTY_FILE,PROPERTY_FILE)}. The latter one automatically stores the retrieved value into a JMeter Variable so you won't have to additionally declare it under User Defined Variables of the Test Plan
Instead of using custom plugins I would suggest going for built-in JMeter functionality, there is -q command-line argument which allows loading and arbitrary .properties file so you will not have to install the plugin, care about order of Configuration Elements, etc.

Julia passing arguments, reading the command line

I am trying to prompt the user of my .jl file to enter user entered multiple destinations.
Basically I need the user to give an input & an output. I know in java you would use a scanner, or accept arguments when it is compiled in the command line. I am fine with either option. From what I have found looking through the Julia Documentation I think I could accomplish the first way of assigning a variable to the readline function.
(String)in = (String)Readline(STDIN)
From my understanding the variable 'in' should now contain a String of the user's input. I am encountering an error, in that when I compile my .jl code, because my command prompt does not stop to read user input, and just finishes reading the .jl code.
The first item to note in the code in your question is:
(String)in = (String)Readline(STDIN)
Julia 1.0.0 now uses stdin instead of STDIN.
Next, the (String) typecasting is not something you need or want to do in Julia.
Thus your code could read (though we get an error):
julia> in = readline(stdin)
This is a test.
ERROR: cannot assign variable Base.in from module Main
So variable in is in conflict with a Julia Base.in variable. Just use a another variable name.
julia> response = readline(stdin)
This is a test.
"This is a test"
This code is now working, but it has no prompt. Your answer provides an example input function with a prompt which you defined like this:
julia> function input(prompt::AbstractString="")
print(prompt)
return chomp(readline())
end
input (generic function with 2 methods)
The chomp function removes a single trailing \n newline character from the input string. Docs here.
Example use of the function here:
julia> input_file = input("Please enter input file name: ")
Please enter input file name: Data.txt
"Data.txt"
julia> output_file = input("Please enter output file name: ")
Please enter output file name: Output.txt
"Output.txt"
Command Line Args Method
As the docs point out, to just print out the arguments given to a script, you can do something like this:
println("Arguments passed to ", PROGRAM_FILE, ":")
for arg in ARGS
println(arg)
end
Here is an example of above code running on the Windows command line:
c:\OS_Prompt>julia PrintArgs.jl Data.txt Output1.txt Output2.txt Output3.txt
Arguments passed to PrintArgs.jl:
Data.txt
Output1.txt
Output2.txt
Output3.txt
You can also print out the script file name as shown, PrintArgs.jl.
After searching & testing I found one solution and decided to reply to it here. I had to declare my own function to be able to get the program to accept user input.
function input(prompt::AbstractString="")
print(prompt)
return chomp(readline())
end
I am not sure what the chomp function does, but I know it works for what I was asking. I am still curious if you can do something in Julia similar to java and C String args[], in which you pass extra information while you are telling your command to run. Something like the following.
Julia testFile.jl goHere.txt lookHere.txt

GNU Make create file from template

I have a basic make experiment where I am trying to create a new file from a template with variable substitution, essentially:
GETCONFIG = $(shell ./test.sh getvalue $(1) app.config.sh)
DOCKERFILE := $(call GETCONFIG,DOCKERFILE)
DOCKERFILE_TEMP := $(call GETCONFIG,DOCKERFILE_TEMPLATE)
DOCKERFILE_TEMPLATE := $(shell cat `./test.sh getvalue DOCKERFILE_TEMPLATE app.config.sh`)
all:
echo $(DOCKERFILE_TEMP)
echo $(DOCKERFILE_TEMPLATE)
echo $(DOCKERFILE_TEMPLATE:{port}=80)
$(file > $(DOCKERFILE),$(DOCKERFILE_TEMPLATE:{port}=80))
My template file is quite basic:
FROM node:4.3
EXPOSE {port}
The output of the experiment is:
echo Dockerfile.template
Dockerfile.template
echo FROM node:4.3 EXPOSE {port}
FROM node:4.3 EXPOSE {port}
echo FROM node:4.3 EXPOSE 80
FROM node:4.3 EXPOSE 80
So, partial success, but both the last echo statement and the created file are all on one line - no line breaks from the template file. Also, you prob noticed I did not use GETCONFIG to set DOCKERFILE_TEMPLATE. Questions:
How do I preserve the new line char from the template file
How do I set DOCKERFILE_TEMPLATE using call GETCONFIG?
I also invite suggestions on "better" practices overall, but my focus of this post are the two questions above. Thank you.
You cannot preserve newlines with $(shell ...). It's like backticks in the shell in that respect. The documentation is quite clear:
The only processing make does on the result is to convert each newline
(or carriage-return / newline pair) to a single space. If there is a
trailing (carriage-return and) newline it will simply be removed.
I can't think of a way you can do this sort of processing with pure GNU make. But you already seem to be using various shell tools, so why not use a proper shell tool to do it such as sed?

OpenVMS - Add STRING to Filename via DCL

I have a number of files created by a program on our selling system that are produced in a format like the following:
CRY_SKI_14_EDI.LIS
CRY_SUM_14_EDI.LIS
THO_SKI_14_EDI.LIS
THO_LAK_14_EDI.LIS
CRY_SKI_IE_14_EDI.LIS
These files differ in numbers depending on the split of our product to different brandings. Is it possible to rename them all so that they read like the following:
CRY_SKI_14_EDI_DEMO.LIS
CRY_SUM_14_EDI_DEMO.LIS
THO_SKI_14_EDI_DEMO.LIS
THO_LAK_14_EDI_DEMO.LIS
CRY_SKI_IE_14_EDI_DEMO.LIS
I need the files to be correctly named prior to their FTP as a hardcoded file could potentially not exist due to the brand not being on sale and terminate the FTP which would prevent the other files following it from being transmitted to our FTP server.
The OpenVMS rename command is more handy (imho) than the windows or unix variants, because it can bulk change chuncks of the full file name. Such as 'name', 'type' or (sub)directory.
For example:
$ rename *.dat *.old
That's great but it will not change within the chunks (components) like the name part requested here.
For that, the classic DCL approach is a quick loop, either parsing directory output (Yuck!) or using F$SEARCH. For example:
$loop:
$ file = f$search("*EDI.LIS")
$ if file .eqs. "" then exit
$ name = f$parse(file,,,"name","syntax_only") ! grab name component from full name
$ rename/log 'file' 'name'_demo ! rename 'fills in the blanks'
$ goto loop
Personally I use PERL one-liners for this kind of work.
(and I test with -le using 'print' instead of 'rename' first. :-)
$ perl -e "for (<*edi.lis>) { $old = $_; s/_edi/_edi_demo/; rename $old,$_}"
Enjoy!
Hein