ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* slashes in paths (Lua code)
@ 2017-05-31 18:51 Pablo Rodriguez
  2017-05-31 20:00 ` Hans Hagen
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Rodriguez @ 2017-05-31 18:51 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Dear list,

I need to add checksums to files I attach to PDF documents.

Following the suggestion from https://stackoverflow.com/a/326715, I wrote:

    \starttext
    \startluacode
    function document.capture(cmd, raw)
        local f = assert(io.popen(cmd, 'r'))
        local s = assert(f:read('*a'))
        f:close()
        if raw then return s end
        s = string.gsub(s, '^%s+', '')
        s = string.gsub(s, '%s+$', '')
        s = string.gsub(s, '[\n\r]+', ' ')
        return s
    end

    function document.sha256(file)
        command_output= document.capture("sha256sum -b " .. file)
        context(command_output:sub(0,64))
    end

    function document.sha512(file)
        command_output= document.capture("sha512sum -b " .. file)
        context(command_output:sub(0,128))
    end
    \stopluacode

    \def\shatwo#1%
        {\ctxlua{document.sha256("#1")}}

    \def\shafive#1%
        {\ctxlua{document.sha512("#1")}}

    \shatwo{Desktop/i-context.pdf}

    \shafive{i-context.pdf}
    \stoptext

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 help,

Pablo
-- 
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread
* slashes in paths (Lua code)
@ 2017-06-01  3:47 Akira Kakuto
  2017-06-01 16:26 ` Pablo Rodriguez
  0 siblings, 1 reply; 5+ messages in thread
From: Akira Kakuto @ 2017-06-01  3:47 UTC (permalink / raw)
  To: ntg-context

> Directories are a problem here. I mean, 
> \shatwo{Desktop/i-context.pdf}
> cannot work in Windows.

Here both of your example and an example by Hans
worked fine on Windows.
Note that
\shatwo{Desktop/i-context.pdf}
works only if the current directory is your %USERPROFILE%.

Best,
Akira

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-01 16:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-31 18:51 slashes in paths (Lua code) Pablo Rodriguez
2017-05-31 20:00 ` Hans Hagen
2017-06-01 16:13   ` Pablo Rodriguez
2017-06-01  3:47 Akira Kakuto
2017-06-01 16:26 ` Pablo Rodriguez

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).