IdEst – ID3 Editing and Scripting Tool (split by node):   Section:   Chapter:FastBack: Scripting   Up: format   FastForward: Backups   Contents: Table of ContentsIndex: Concept Index

10.3.1 How to Write Format Modules

The source for format module name must be saved in the file named name.scm located in the subdirectory idest/format somewhere in the Guile load path. It must begin with the following clause:

(define-module (idest format name))

The module must define and export the ‘idest-main’ function, whose calling convention and return type is the same as that in the usual idest scripts (see idest-main). For example, the following is a simplified version of the ‘framelist’ module (see framelist):

(define-module (idest format framelist))

(define frame-list '())

(define-public (idest-main name frames)
  (for-each
    (lambda (elt)
      (cond
       ((member (car elt) frame-list)
        (display (car elt))
        (newline))))
    frames))

If the module needs to process command line arguments, it may not do so in the main code, as the usual idest modules do. Instead, it should export a special function, ‘idest-init’, defined as:

(define-public (idest-init)
  ...)

This function analyzes the command line, removes the consumed modules options and returns. For example:

(define-public (idest-init)
  (let ((cmd (command-line)))
    (cond
     ((< (length cmd) 3)
      (error "usage: idest --format=framelist
             FRAME-LIST FILE...")
      (exit 1))
     (else
      (set! frame-list (string-split (list-ref cmd 1) #\,))
      (set-program-arguments
        (cons (car cmd) (list-tail cmd 2)))))))

The module should also export the symbol ‘description’, which should contain a string with a concise description of the module. This description will be shown in the --format=help output (see help format). For example:

(define-public description
  "display a list of frames defined in each file")

IdEst – ID3 Editing and Scripting Tool (split by node):   Section:   Chapter:FastBack: Scripting   Up: format   FastForward: Backups   Contents: Table of ContentsIndex: Concept Index