Input-for-Mapped-Applications.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <html lang="en">
  2. <head>
  3. <title>Input for Mapped Applications - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="Parameter-Mode-Interface.html#Parameter-Mode-Interface" title="Parameter Mode Interface">
  9. <link rel="prev" href="Input-Data-Structure.html#Input-Data-Structure" title="Input Data Structure">
  10. <link rel="next" href="Output-From-Non_002dinteractive-Applications.html#Output-From-Non_002dinteractive-Applications" title="Output From Non-interactive Applications">
  11. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  12. <meta http-equiv="Content-Style-Type" content="text/css">
  13. <style type="text/css"><!--
  14. pre.display { font-family:inherit }
  15. pre.format { font-family:inherit }
  16. pre.smalldisplay { font-family:inherit; font-size:smaller }
  17. pre.smallformat { font-family:inherit; font-size:smaller }
  18. pre.smallexample { font-size:smaller }
  19. pre.smalllisp { font-size:smaller }
  20. span.sc { font-variant:small-caps }
  21. span.roman { font-family:serif; font-weight:normal; }
  22. span.sansserif { font-family:sans-serif; font-weight:normal; }
  23. --></style>
  24. </head>
  25. <body>
  26. <div class="node">
  27. <a name="Input-for-Mapped-Applications"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Output-From-Non_002dinteractive-Applications.html#Output-From-Non_002dinteractive-Applications">Output From Non-interactive Applications</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="Input-Data-Structure.html#Input-Data-Structure">Input Data Structure</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="Parameter-Mode-Interface.html#Parameter-Mode-Interface">Parameter Mode Interface</a>
  32. <hr>
  33. </div>
  34. <h4 class="subsection">2.6.2 Input for Mapped Applications</h4>
  35. <p>Applications invoked using the <samp><span class="option">--map-to-each-file</span></samp> option
  36. <a name="index-g_t_0040code_007bmap_002dto_002deach_002dfile_007d-command-line-option-219"></a>benefit from a slightly different interface than the one described
  37. above. As the purpose of this option is to save memory by loading only
  38. one file at a time, the application does not have access to all input
  39. files named on the command line simultaneously within the same data
  40. structure. Although the data structure is of the type already described,
  41. the <var>files</var> field is not a list of arbitrary length. Instead, it is
  42. a list containing exactly one item for an input file. If <kbd>-</kbd>
  43. is used as a command line parameter, indicating standard input, then
  44. <var>files</var> will have another item pertaining to standard
  45. input. In no event will it have other than one or two items.
  46. <p>The mapped application is expected to work by being applied individually
  47. to each of any number of separately constructed data structures, doing
  48. the same in each case as it would if that case were the only one. To make
  49. that possible, copies of the environment variables, the contents of standard
  50. input, and the list of application specific options are contained in the
  51. data structure used for every invocation.
  52. <p><a name="index-command-line-220"></a>The position numbers in the options are adjusted for each invocation to
  53. reflect the position of the particular input file associated with it.
  54. For example, in the following command
  55. <pre class="display"> <kbd>avram --map-to-each-file mapster.avm fa.txt --data fb.dat --code fc.o</kbd>
  56. </pre>
  57. <p class="noindent">the function in the virtual code file <samp><span class="file">mapster.avm</span></samp> would be
  58. applied to each of three data structures, corresponding to the commands
  59. <pre class="display"> <kbd>avram mapster.avm fa.txt --data --code</kbd>
  60. <kbd>avram mapster.avm --data fb.dat --code</kbd>
  61. <kbd>avram mapster.avm --data --code fc.o</kbd>
  62. </pre>
  63. <p class="noindent">If the relative positions of the options and filenames were important to
  64. the application, they could be reliably inferred from the position
  65. numbers. In the first case, they would be 1 and 2, implying that the
  66. file is in position 0. In the second case they would be 0 and 2,
  67. implying that the file is in position 1, and in the third case they
  68. would be 0 and 1, implying that the file is in position 2. (Of course,
  69. nothing compels an application to concern itself with the positions of
  70. its parameters, and the alternative might be preferable.)
  71. <p>For the most part, any application that can operate on one file at a
  72. time without needing information from any others can be executed more
  73. economically with the <samp><span class="option">--map-to-each-file</span></samp> option and few if any
  74. changes to the code. The effect will normally be analogous to the above
  75. example, subject to a few possible differences.
  76. <ul>
  77. <li>If an application is supposed to do something by default when
  78. there are no file parameters or only standard input, it won't work as a
  79. mapped application, because if there are no file parameters it won't be
  80. executed at all.
  81. <li>If a mapped application causes any output files to be generated, they
  82. may be written before other input files are read, possibly causing the
  83. input files to be overwritten if they have the same names, and causing
  84. subsequent invocations to use the overwritten versions. This behavior
  85. differs from that of loading all input files at the outset, which
  86. ensures the application seeing all of the original versions. The latter may be
  87. more convenient for maintaining a group of files in some sort of
  88. consistent state.
  89. <li>If an application causes standard output to be written along with
  90. output files, normally standard output is written last as a security
  91. measure against malicious code altering the <samp><span class="option">--ask-to-overwrite</span></samp>
  92. prompts by subtly clobbering the console. In a mapped application,
  93. standard output isn't always last because there may be more invocations
  94. to come.
  95. </ul>
  96. </body></html>