ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* selecting lines with \typefile
@ 2002-07-25  8:44 Jens-Uwe Morawski
  2002-07-25  9:21 ` Hans Hagen
  0 siblings, 1 reply; 5+ messages in thread
From: Jens-Uwe Morawski @ 2002-07-25  8:44 UTC (permalink / raw)


Hi,

is there a way to select some lines from a file that
shall be printed verbatim.

The only command i can see is \typefile, but this prints
the whole file. I would like to say that only lines from
<start> upto <end> should be printed:
\typefile[start=<start>,end=<end>]{.name.}{.file.} or
\typefile[start=<start>,nlines=<number of lines>]{.name.}{.file.}

Is currently a way available to do this, or could this be implemented?

Thanks in advance.

Best,
  Jens


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

* Re: selecting lines with \typefile
  2002-07-25  8:44 selecting lines with \typefile Jens-Uwe Morawski
@ 2002-07-25  9:21 ` Hans Hagen
  2002-07-26  7:53   ` Wybo Dekker
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2002-07-25  9:21 UTC (permalink / raw)
  Cc: ntg-context

At 10:44 AM 7/25/2002 +0200, you wrote:

>Hi,
>
>is there a way to select some lines from a file that
>shall be printed verbatim.
>
>The only command i can see is \typefile, but this prints
>the whole file. I would like to say that only lines from
><start> upto <end> should be printed:
>\typefile[start=<start>,end=<end>]{.name.}{.file.} or
>\typefile[start=<start>,nlines=<number of lines>]{.name.}{.file.}
>
>Is currently a way available to do this, or could this be implemented?

quick hack:

\def\typefilelines#1#2#3%
   {\bgroup
    \doglobal\newcounter\currenttypefileline
    \let\saveddoflushverbatimline\doflushverbatimline
    \let\saveddoemptyverbatimline\doemptyverbatimline
    \def\checktypefileline##1%
      {\doglobal\increment\currenttypefileline\relax
       \ifnum\currenttypefileline<#2\else
       \ifnum\currenttypefileline>#3\else
         ##1%
       \fi\fi}%
    \def\doflushverbatimline
      {\checktypefileline\saveddoflushverbatimline}%
    \def\doemptyverbatimline
      {\checktypefileline\saveddoemptyverbatimline}%
    \typefile{#1}%
    \egroup}

\starttext \typefilelines{test.tex}{1}{4} \stoptext

now, this is not exactly nice, so you may test the following

===================

\unprotect

\def\processfilelinesverbatim#1#2#3%
   {\bgroup
    \doglobal\newcounter\currenttypefileline
    \let\saveddoflushverbatimline\doflushverbatimline
    \let\saveddoemptyverbatimline\doemptyverbatimline
    \def\checktypefileline##1%
      {\doglobal\increment\currenttypefileline\relax
       \ifnum\currenttypefileline<#2\else
       \ifnum\currenttypefileline>#3\else
         ##1%
       \fi\fi}%
    \def\doflushverbatimline
      {\checktypefileline\saveddoflushverbatimline}%
    \def\doemptyverbatimline
      {\checktypefileline\saveddoemptyverbatimline}%
    \processfileverbatim{#1}%
    \egroup}

\def\typefile
   {\dodoubleempty\dotypefile}

\def\dotypefile[#1][#2]#3%
   {\ifsecondargument
      \dodotypefile[#1][#2]{#3}%
    \else\iffirstargument
      \doifassignmentelse{#1}
        {\dodotypefile[\v!file][#1]{#3}}
        {\dodotypefile[#1][]{#3}}%
    \else
      \dodotypefile[\v!file][]{#3}%
    \fi\fi}

\def\dodotypefile[#1][#2]#3%
   {\getvalue{\??tp#1\c!voor}%
    \doiflocfileelse{#3}
      {\startopelkaar % includes \bgroup
       \getparameters[\??tp#1][\c!start=,\c!stop=,#2]%
       \doifinset{\getvalue{\??tp#1\c!optie}}
           {\v!commandos,\v!schuin,\v!normaal}
         {\setuptyping[#1][\c!optie=\v!geen]}%
       \doifvalue{\??tp#1\c!optie}\v!kleur
         {\expandafter\aftersplitstring#3\at.\to\prettyidentifier
          \letvalue{\??tp#1\c!optie}\prettyidentifier}%
       \initializetyping{#1}%
       \startverbatimcolor
       \makelocreadfilename{#3}%
       \doifelsevaluenothing{\??tp#1\c!start}
         {\processfileverbatim\readfilename}
         {\doifelsevaluenothing{\??tp#1\c!stop}
            {\processfileverbatim\readfilename}
            {\processfilelinesverbatim\readfilename
               {\getvalue{\??tp#1\c!start}}
               {\getvalue{\??tp#1\c!stop }}}}%
       \stopverbatimcolor
       \stopopelkaar}  % includes \egroup
      {\bgroup
       \expanded{\convertargument#3}\to\ascii
       \tttf[\makemessage\m!verbatims1\ascii]%
       \showmessage\m!verbatims1\ascii
       \egroup}%
    \getvalue{\??tp#1\c!na}}

\starttext \typefile[start=1,stop=4]{test} \stoptext

(so, from now on, typefile takes two optional args)

can you test this? If ok, it can go into the core

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------


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

* Re: selecting lines with \typefile
  2002-07-25  9:21 ` Hans Hagen
@ 2002-07-26  7:53   ` Wybo Dekker
  2002-07-26  8:33     ` Tobias Burnus
       [not found]     ` <Pine.LNX.4.44.0207261032370.25658-100000@warp9.physik.fu-b erlin.de>
  0 siblings, 2 replies; 5+ messages in thread
From: Wybo Dekker @ 2002-07-26  7:53 UTC (permalink / raw)


On Thu, 25 Jul 2002, Hans Hagen wrote:

> \starttext \typefile[start=1,stop=4]{test} \stoptext
>
> (so, from now on, typefile takes two optional args)

it would be nice to also have options for line numbering:

number=yes/no/n    % n=interval (mostly 1 or 5)
width=ndig         % no of digits
sep=string         % separator (say : or tab or --)

-- 
Wybo


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

* Re: selecting lines with \typefile
  2002-07-26  7:53   ` Wybo Dekker
@ 2002-07-26  8:33     ` Tobias Burnus
       [not found]     ` <Pine.LNX.4.44.0207261032370.25658-100000@warp9.physik.fu-b erlin.de>
  1 sibling, 0 replies; 5+ messages in thread
From: Tobias Burnus @ 2002-07-26  8:33 UTC (permalink / raw)
  Cc: ntg-context

Hi,

On Fri, 26 Jul 2002, Wybo Dekker wrote:
> > \starttext \typefile[start=1,stop=4]{test} \stoptext
> > (so, from now on, typefile takes two optional args)
> it would be nice to also have options for line numbering:
> number=yes/no/n    % n=interval (mostly 1 or 5)
> width=ndig         % no of digits
> sep=string         % separator (say : or tab or --)
And an option for the first line number. If one uses start=15 one my want
to start with 1 or with 15.

Tobias


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

* Re: selecting lines with \typefile
       [not found]     ` <Pine.LNX.4.44.0207261032370.25658-100000@warp9.physik.fu-b erlin.de>
@ 2002-07-26 22:35       ` Hans Hagen
  0 siblings, 0 replies; 5+ messages in thread
From: Hans Hagen @ 2002-07-26 22:35 UTC (permalink / raw)
  Cc: Wybo Dekker, ntg-context

At 10:33 AM 7/26/2002 +0200, Tobias Burnus wrote:
>Hi,
>
>On Fri, 26 Jul 2002, Wybo Dekker wrote:
> > > \starttext \typefile[start=1,stop=4]{test} \stoptext
> > > (so, from now on, typefile takes two optional args)
> > it would be nice to also have options for line numbering:
> > number=yes/no/n    % n=interval (mostly 1 or 5)
> > width=ndig         % no of digits
> > sep=string         % separator (say : or tab or --)
>And an option for the first line number. If one uses start=15 one my want
>to start with 1 or with 15.

i will implement two methods:

numbering=file (already there)
numbering=line (partly there)

the second one does what you want, i.e. it's hooked into the normal line 
numbering macros

Hans

-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------


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

end of thread, other threads:[~2002-07-26 22:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-25  8:44 selecting lines with \typefile Jens-Uwe Morawski
2002-07-25  9:21 ` Hans Hagen
2002-07-26  7:53   ` Wybo Dekker
2002-07-26  8:33     ` Tobias Burnus
     [not found]     ` <Pine.LNX.4.44.0207261032370.25658-100000@warp9.physik.fu-b erlin.de>
2002-07-26 22:35       ` Hans Hagen

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