[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

97.0. "quotes in .com files" by REX::MINOW () Thu Mar 07 1985 16:18

Does anyone have a good way to process quoted arguments in
.com files?  I.e., to be able to pass the string intact
to some other .com file.  For example, the attached .com
file uses nmail to send a series of files to a net address.
If the address is on ARPA or USENET, it must be given
in quotes.  Unfortunately, when the string is parsed,
quotes are deleted and the command fails.  (Note: VMS 3.7)

All help appreciated.

Martin.

$! send a wildcarded set of files to a destination using nmail
$! Two mandatory parameters:
$!	P1	file to send (argument to f$search())
$!	P2	destination (don't forget to quote arpa addresses)
$!
$	if "''P1'" .eqs. "" then inquire P1 "Wildcard filespec to send"
$	if "''P1'" .eqs. "" then exit
$	if "''P2'" .eqs. "" then inquire P2 "Destination (don't forget quotes)"
$	if "''P2'" .eqs. "" then exit
$ loop:	file = f$search("''P1'")
$	if file .eqs. "" then exit
$	nmail/notime 'file' "''P2'" "File ''file'"
$	goto loop
$!

T.RTitleUserPersonal
Name
DateLines
97.1WEBSTR::BEYERThu Mar 07 1985 17:5912
I've been known to search the parameter for lowercase and embedded
spaces to decide whether it needs quotes added back on.  Adding the
quotes is easy: MAIL/SUBJ="""''P2'"""

What I really need is a way to keep quotes embedded in a parameter 
from screwing up its use.  That is, if the user passes the string
"foo ""bar""", P2 is {foo "bar"} and the above turns into 
{MAIL/SUBJ="foo "bar""}, and mail bitches because it tried to parse 'bar'.

It would be a lot simpler if DCL didn't strip double quotes for you.

	HRB
97.2TURTLE::GILBERTThu Mar 07 1985 23:2710
(In my considered opinion) the DCL behaviour you describe is correct and
reasonable.  The problem is in how you're embedding the value of a string
within quotes; you should double any quotes that are in the string.  Sadly,
there's no easy way to do that from DCL.

This is a perfect example of where the ampersand (&) should be used, e.g.,
{MAIL/SUBJ=&P2}.  However, this doesn't seem to work correctly -- although
DCL doesn't complain, the quotes in P2 are removed.  But this may solve a
few problems.
					- Gilbert
97.3SPEEDY::BRETTThu Mar 07 1985 23:4920
Why did you put all those ''s in?   "Modern" DCL should be pretty well void
of := and of '.

For instance...

	if "''p1'" .eqs. ...

should be

	if p1 .eqs. ...



The best trick is how to define a symbol if it doesn't exist, but not change
it if it does.  I use

	MAKE_THIS_SYMBOL_EXIST[0,0] = 0


/Bevin
97.4REX::MINOWFri Mar 08 1985 14:397
Sounds like .3 trades "''p1'" for p1[0,0] = 0 -- an even trade, but
thanks for the hint.

Still no real solution?  -- note I'm using NMAIL, not MAIL -- if that
makes a difference.

Martin.
97.5WEBSTR::BEYERFri Mar 08 1985 14:599
I don't see how &P1 helps the problem any.  I pulled out the documentation
on it, and it seems to be just a delayed 'P1'.   What's really needed here
is a way get the literal sequence of characters typed for a parameter, 
complete with surrounding quotes and embedded double quotes.

.0 is probably like me.. I learned "''foo'" early on and the substitution 
rules for DCL were so persnickity I've done it exactly that way ever since.
	
	HRB
97.6VAXUUM::DYERFri Mar 08 1985 19:122
	The double-quote behavior in .COM files is an utter crock.
#6	<_Jym_>\
97.7TURTLE::GILBERTFri Mar 08 1985 22:1547
Consider the example:

	$! Does P1 contain a quote character?
	$!
	$ if f$locate("""",p1) .ge. f$length(p1) then write sys$output "Yes"

re .1 (HRB) and .6 (_Jym_)

	If DCL didn't strip double quotes for you, you may have trouble
	expressing the above example.  Or (depending on what alternate
	proposal you might use), you could have trouble with the following:

	$ x = "Please bullet the items with a ""+"" mark"
	$ x = "concatenate these " + "strings"
	$ if a .eqs. "" then if b .eqs. "foo" then goto label
	$ if a .eqs. """ then if b .eqs. ""foo" then goto label

	Many utilities ignore this problem.  For example, it's possible
	to create a CMS comment that will appear as two separate CMS commands
	in a CMS history (CMS automatically provides line breaks for these).
	The output of SHOW LOGICAL doesn't double quotes -- it's possible
	to create a logical name that is displayed ambiguously.  When Cobol
	extracts definitions from the CDD, producing Cobol source text, it
	*does* re-double the quotes for string literals (you *have* to get it
	right if the output is to be used by some nit-picky computer).

re .5 (HRB)

	I almost expected &P1 to do the trick.  It's a little different
	than a delayed 'P1'.  In the case of the mail example, if P2 is
	{foo "bar"}, then {MAIL/SUBJ=&P2} causes no DCL complaints, while
	a wide range of alternatives can or do cause errors.

	After seeing that {MAIL/SUBJ=&P2} gave no complaints, I was pleased,
	and expected to see {foo "bar"} in the subject line of the message.
	Unfortunately, the subject was given as {foo bar} -- how or why it
	managed to realize that P2 was a single entity, but failed to retain
	the embedded quotes, I don't know.  However, it *does* solve this
	particular problem (no DCL errors), if you're willing to forgive a
	few missing quotes from the subject of the message.

	Yes, what's needed is a way to get embedded quotes doubled again.
	It's a relatively simple matter to code a little loop to do this.
	A more convenient way to do this (perhaps another f$edit option)
	is desired.

					- Gilbert
97.8MAHLER::FISHERTue Mar 12 1985 19:278
RE .4		how to define a symbol if it doesn't exist, but
                not change it if it does.


$if f$type("symbol") .eqs. "" then symbol = "whatever"

Bye
Kay R. Fisher
97.9PARVAX::PFAUWed Mar 13 1985 21:413
What if you are running V3?

tom_p
97.10ELGAR::FISHERTue Mar 19 1985 12:5012
If it's a number - it's easy

symbol = 0'symbol'

!If it wasn't defined before - it is now.  
!It is was - it has the same value.
!I used this for debugging DCL

Debug = 0'Debug'

Bye
Kay R. Fisher
97.11RANI::LEICHTERJWed Mar 27 1985 00:2116
What's wrong with:

	$ symbol = "''symbol'"

(Yes, the result is always a string; if you are know you need an integer you
can always do something like what is suggested in .-1.)

Note that, in this particular case, "=" and ":=" are equivalent.  What you
should NOT do is:

	$ symbol := 'symbol'

Besides screwing around with case, spacing, and quotes, and trying to execute
any substrings of symbol that look like calls to lexicals, this can have unex-
pected results if symbol ends with a "-".
							-- Jerry
97.12EIFFEL::BRETTWed Mar 27 1985 14:5411
$ symbol = " "" ! What a comment "

then

$ symbol = "''symbol'"  becomes

	 = " " ! What a comment "

so the value of the symbol is not preserved.

/Bevin
97.13REX::MINOWWed Mar 27 1985 18:567
.12 brings us full circle back to my original question (if anyone cares):

HOW DO I PRESERVE QUOTES IN .COM FILES?

What kind of hackers are you?  It can't be that difficult.  (:-)

Martin.
97.14TOOLS::GILBERTWed Mar 27 1985 20:3331
$! send a wildcarded set of files to a destination using nmail
$! Two mandatory parameters:
$!	P1	file to send (argument to f$search())
$!	P2	destination (don't forget to quote arpa addresses)
$!
$	if P1 .eqs. "" then read sys$command P1 /prompt="Wildcard filespec to send: "
$	if P1 .eqs. "" then exit
$	if P2 .eqs. "" then read sys$command P2 /prompt="Destination (don't forget quotes): "
$	if P2 .eqs. "" then exit
$ loop:	file = f$search(P1)
$	if file .eqs. "" then exit
$
$	P0 = file
$	return = "goto 10$"
$	goto dq
$	10$: file = P0
$
$	P0 = P2
$	return = "goto 20$"
$	goto dq
$	20$: P2 = P0
$
$	nmail/notime  "''file'"  "''P2'"  "File ''file'"
$	goto loop
$
$ dq:	i = 0
$ dq1:	i = i + f$locate("""",f$extract(i,f$length(P0)-i,P0))
$	if i .ge. f$length(P0) then 'return
$	P0 = f$extract(0,i+1,P0) + f$extract(i,f$length(P0)-i,P0)
$	i = i + 2
$	goto dq1