I'm still debating whether embedded interpreters
was a good idea.

Meanwhile, consider this <words fail me>:

$ cat tinterp
#!/usr/bin/rpm -E -
%{lua:  print("lua:\tHello World!")}
%{perl: print "perl:\tHello World!\n"}
%{python:print "python:\tHello World!"}
%{ruby: puts "ruby:\tHello World!"}
%{tcl:  puts "tcl:\tHello World!"}
$ rpm -E tinterp
perl:   Hello World!
python: Hello World!
ruby:   Hello World!
tcl:    Hello World!
#!/usr/bin/rpm -E -
lua:    Hello World!
1
FIXME
FIXME


$

Obviously still some tweaks needed, as the output shows.
And the #!/usr/bin/rpm -E - attempted in this patch ain't close yet.

Still I dunno whether to laugh or cry ...

73 de Jeff

On Apr 11, 2009, at 3:33 PM, Jeff Johnson wrote:

 RPM Package Manager, CVS Repository
 http://rpm5.org/cvs/
____________________________________________________________________________

 Server: rpm5.org                         Name:   Jeff Johnson
 Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
 Module: rpm                              Date:   11-Apr-2009 21:33:35
 Branch: HEAD                             Handle: 2009041119333401

 Modified files:
   rpm                     CHANGES
   rpm/lib                 poptALL.c

 Log:
   - jbj: lua: revert -E /path/to/file.lua wrapping.

 Summary:
   Revision    Changes     Path
   1.2913      +1  -1      rpm/CHANGES
   2.124       +25 -94     rpm/lib/poptALL.c
____________________________________________________________________________

 patch -p0 <<'@@ .'
 Index: rpm/CHANGES
= = = = = = ======================================================================
 $ cvs diff -u -r1.2912 -r1.2913 CHANGES
 --- rpm/CHANGES        11 Apr 2009 14:47:12 -0000      1.2912
 +++ rpm/CHANGES        11 Apr 2009 19:33:34 -0000      1.2913
 @@ -1,5 +1,6 @@

  5.2a3 -> 5.2a4:
 +    - jbj: lua: revert -E /path/to/file.lua wrapping.
- jbj: popt: remove retrofits for popt < 1.14. use popt internal if needed. - jbj: ruby: wire-up %post -p <ruby>. arg1/arg2, persistent interp, todo++. - jbj: ruby: wire-up %{ruby:...}. the string result is bogus, todo++.
 @@ -15,7 +16,6 @@
- jbj: tcl: wire-up %post -p <tcl>. arg1/arg2, persistent interp, todo++.
      - jbj: tcl: wire-up %{tcl:...} with a string result.
      - jbj: tcl: add --with-tcl for embedding tcl.
- - jbj: lua: hack up --eval /path/to/file.lua to run scripts from a file. - jbj: mire: teardown for platpat on exit needs to be done in order.
      - jbj: rpmwget: move to tools.
- jbj: wire-up RPMTAG_FILEDIGESTALGO. wotta waste to pretend "compatible" ...
 @@ .
 patch -p0 <<'@@ .'
 Index: rpm/lib/poptALL.c
= = = = = = ======================================================================
 $ cvs diff -u -r2.123 -r2.124 poptALL.c
 --- rpm/lib/poptALL.c  11 Apr 2009 14:47:13 -0000      2.123
 +++ rpm/lib/poptALL.c  11 Apr 2009 19:33:35 -0000      2.124
 @@ -14,6 +14,7 @@
  const char *__localedir = LOCALEDIR;
  #endif

 +#define       _RPMIOB_INTERNAL
  #include <rpmio.h>
  #include <rpmiotypes.h>
  #include <fts.h>
 @@ -198,90 +199,34 @@
        exit(EXIT_FAILURE);
  }

 -#if !defined(POPT_READFILE_TRIMNEWLINES)      /* XXX popt < 1.15 */
 -#define       POPT_READFILE_TRIMNEWLINES      1
 +/* ========== all-rpm-modes popt args */

 -/**
 - * Read a file into a buffer.
 - * @param fn          file name
 - * @retval *bp                buffer (malloc'd)
 - * @retval *nbp               no. of bytes in buffer (including final NUL)
 - * @param flags               1 to trim escaped newlines
 - * return             0 on success
 - */
-static int poptReadFile(const char * fn, char ** bp, size_t * nbp, int flags)
 -      /*...@globals errno @*/
 -      /*...@modifies *bp, *nbp, errno @*/
 +static const char * rpmcliEvalSlurp(const char * arg)
 +      /*...@*/
  {
 -    int fdno;
 -    char * b = NULL;
 -    off_t nb = 0;
 -    char * s, * t, * se;
 -    int rc = POPT_ERROR_ERRNO;        /* assume failure */
 -
 -    fdno = open(fn, O_RDONLY);
 -    if (fdno < 0)
 -      goto exit;
 -
 -    if ((nb = lseek(fdno, 0, SEEK_END)) == (off_t)-1
 -     || lseek(fdno, 0, SEEK_SET) == (off_t)-1
 -     || (b = calloc(sizeof(*b), (size_t)nb + 1)) == NULL
 -     || read(fdno, (char *)b, (size_t)nb) != (ssize_t)nb)
 -    {
 -      int oerrno = errno;
 -      (void) close(fdno);
 -      errno = oerrno;
 -      goto exit;
 -    }
 -    if (close(fdno) == -1)
 -      goto exit;
 -    if (b == NULL) {
 -      rc = POPT_ERROR_MALLOC;
 -      goto exit;
 -    }
 -    rc = 0;
 -
 -   /* Trim out escaped newlines. */
 -/*...@-bitwisesigned@*/
 -    if (flags & POPT_READFILE_TRIMNEWLINES)
 -/*...@=bitwisesigned@*/
 -    {
 -      for (t = b, s = b, se = b + nb; *s && s < se; s++) {
 -          switch (*s) {
 -          case '\\':
 -              if (s[1] == '\n') {
 -                  s++;
 -                  continue;
 -              }
 -              /*...@fallthrough@*/
 -          default:
 -              *t++ = *s;
 -              /*...@switchbreak@*/ break;
 -          }
 -      }
 -      *t++ = '\0';
 -      nb = (off_t)(t - b);
 +    const char * pre = "";
 +    const char * post = "";
 +    rpmiob iob = NULL;
 +    const char * val = NULL;
 +    struct stat sb;
 +    int xx;
 +
 +    if (!strcmp(arg, "-")) {        /* Macros from stdin arg. */
 +      xx = rpmiobSlurp(arg, &iob);
 +    } else
 +    if ((arg[0] == '/' || strchr(arg, ' ') == NULL)
 +     && !Stat(arg, &sb)
 +     && S_ISREG(sb.st_mode)) {        /* Macros from a file arg. */
 +      xx = rpmiobSlurp(arg, &iob);
 +    } else {                  /* Macros from string arg. */
 +      iob = rpmiobAppend(rpmiobNew(strlen(arg)+1), arg, 0);
      }

  exit:
 -    if (rc == 0) {
 -      *bp = b;
 -      *nbp = (size_t) nb;
 -    } else {
 -/*...@-usedef@*/
 -      if (b)
 -          free(b);
 -/*...@=usedef@*/
 -      *bp = NULL;
 -      *nbp = 0;
 -    }
-/*...@-compdef -nullstate @*/ /* XXX cannot annotate char ** correctly */
 -    return rc;
 -/*...@=compdef =nullstate @*/
 +    val = rpmExpand(pre, iob->b, post, NULL);
 +    iob = rpmiobFree(iob);
 +    return val;
  }
 -#endif /* !defined(POPT_READFILE_TRIMNEWLINES) */
 -
 -/* ========== all-rpm-modes popt args */

  /**
   */
 @@ -337,24 +282,10 @@
        s = _free(s);
      } break;
      case 'E':
 -    { const char * val = NULL;
 -      size_t val_len = 0;
 -
  assert(arg != NULL);
        rpmcliConfigured();
 -      /* Read lua script from a file. */
 -      if (arg[0] == '/') {
 -          char * b = NULL;
 -          size_t nb = 0;
 -          int flags = 0;
 -          int rc = poptReadFile(arg, &b, &nb, flags);
 -          if (rc == 0 && b != NULL && nb > 0)
 -              val = rpmExpand("%{lua:", b, "}", NULL);
 -          b = _free(b);
 -      } else
 -          val = rpmExpand(arg, NULL);
 -      val_len = strlen(val);
 -      val_len = fwrite(val, val_len, 1, stdout);
 +    { const char * val = rpmcliEvalSlurp(arg);
 +      size_t val_len = fwrite(val, strlen(val), 1, stdout);
        if (val[val_len - 1] != '\n')
            fprintf(stdout, "\n");
        val = _free(val);
 @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-...@rpm5.org

______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
Developer Communication List                        rpm-devel@rpm5.org

Reply via email to