ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Pablo Rodriguez <oinos@gmx.es>
To: ntg-context@ntg.nl
Subject: Re: slashes in paths (Lua code)
Date: Thu, 1 Jun 2017 18:13:19 +0200	[thread overview]
Message-ID: <aa7f4539-6859-0125-e2fe-7d5cdd9ed0a7@gmx.es> (raw)
In-Reply-To: <e4eb930f-d454-9b44-af42-c4a5ba416b16@wxs.nl>

On 05/31/2017 10:00 PM, Hans Hagen wrote:
> On 5/31/2017 8:51 PM, Pablo Rodriguez wrote:
>> Dear list,
>>
>> I need to add checksums to files I attach to PDF documents.
>> [...]
>> Directories are a problem here. I mean, \shatwo{Desktop/i-context.pdf}
>> cannot work in Windows.
>>
>> Which would be the way to make it work in Windows?

Many thanks for your code, Hans.

Pablo

> \starttext
>      \startluacode
>      local function sha(cmd,name)
>          local f = io.popen(string.format("%s -b %q",cmd,name),"rb")
>          if f then
>              local s = f:read("*a")
>              f:close()
>           -- s = string.longtostring(s)
>              return string.match(s,"%s*([A-Fa-f0-9]+)")
>          end
>      end
> 
>      function document.sha256(name)
>          local ok = sha("sha256sum",name)
>          if ok then
>              context(ok)
>          end
>      end
> 
>      function document.sha512(name)
>          local ok = sha("sha512sum",name)
>          if ok then
>              context(ok)
>          end
>      end
> \stopluacode
> 
> \def\shatwo #1{\ctxlua{document.sha256("#1")}}
> \def\shafive#1{\ctxlua{document.sha512("#1")}}
> 
> \shafive{fd.pdf}
> \shafive{foo/fd.pdf}
> 
> \stoptext


-- 
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2017-06-01 16:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31 18:51 Pablo Rodriguez
2017-05-31 20:00 ` Hans Hagen
2017-06-01 16:13   ` Pablo Rodriguez [this message]
2017-06-01  3:47 Akira Kakuto
2017-06-01 16:26 ` Pablo Rodriguez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa7f4539-6859-0125-e2fe-7d5cdd9ed0a7@gmx.es \
    --to=oinos@gmx.es \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).