a68g-apropos.c

     
   1  //! @file a68g-apropos.c
   2  //! @author J. Marcel van der Veer
   3  
   4  //! @section Copyright
   5  //!
   6  //! This file is part of Algol68G - an Algol 68 compiler-interpreter.
   7  //! Copyright 2001-2024 J. Marcel van der Veer [algol68g@xs4all.nl].
   8  
   9  //! @section License
  10  //!
  11  //! This program is free software; you can redistribute it and/or modify it 
  12  //! under the terms of the GNU General Public License as published by the 
  13  //! Free Software Foundation; either version 3 of the License, or 
  14  //! (at your option) any later version.
  15  //!
  16  //! This program is distributed in the hope that it will be useful, but 
  17  //! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  18  //! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 
  19  //! more details. You should have received a copy of the GNU General Public 
  20  //! License along with this program. If not, see [http://www.gnu.org/licenses/].
  21  
  22  //! @section Synopsis
  23  //!
  24  //! Command line help.
  25  
  26  #include "a68g.h"
  27  #include "a68g-prelude.h"
  28  #include "a68g-mp.h"
  29  #include "a68g-genie.h"
  30  
  31  // Interactive help.
  32  
  33  typedef struct A68_INFO A68_INFO;
  34  
  35  struct A68_INFO
  36  {
  37    char *cat;
  38    char *term;
  39    char *def;
  40  };
  41  
  42  static A68_INFO info_text[] = {
  43    {"monitor", "breakpoint clear [all]", "clear breakpoints and watchpoint expression"},
  44    {"monitor", "breakpoint clear breakpoints", "clear breakpoints"},
  45    {"monitor", "breakpoint clear watchpoint", "clear watchpoint expression"},
  46    {"monitor", "breakpoint [list]", "list breakpoints"},
  47    {"monitor", "breakpoint \"n\" clear", "clear breakpoints in line \"n\""},
  48    {"monitor", "breakpoint \"n\" if \"expression\"", "break in line \"n\" when expression evaluates to true"},
  49    {"monitor", "breakpoint \"n\"", "set breakpoints in line \"n\""},
  50    {"monitor", "breakpoint watch \"expression\"", "break on watchpoint expression when it evaluates to true"},
  51    {"monitor", "calls [n]", "print \"n\" frames in the call stack (default n=3)"},
  52    {"monitor", "continue, resume", "continue execution"},
  53    {"monitor", "do \"command\", exec \"command\"", "pass \"command\" to the shell and print return code"},
  54    {"monitor", "elems [n]", "print first \"n\" elements of rows (default n=24)"},
  55    {"monitor", "evaluate \"expression\", x \"expression\"", "print result of \"expression\""},
  56    {"monitor", "examine \"n\"", "print value of symbols named \"n\" in the call stack"},
  57    {"monitor", "exit, hx, quit", "terminates the program"},
  58    {"monitor", "finish, out", "continue execution until current procedure incarnation is finished"},
  59    {"monitor", "frame 0", "set current stack frame to top of frame stack"},
  60    {"monitor", "frame \"n\"", "set current stack frame to \"n\""},
  61    {"monitor", "frame", "print contents of the current stack frame"},
  62    {"monitor", "heap \"n\"", "print contents of the heap with address not greater than \"n\""},
  63    {"monitor", "help [expression]", "print brief help text"},
  64    {"monitor", "ht", "halts typing to standard output"},
  65    {"monitor", "list [n]", "show \"n\" lines around the interrupted line (default n=10)"},
  66    {"monitor", "next", "continue execution to next interruptable unit (do not enter routine-texts)"},
  67    {"monitor", "prompt \"s\"", "set prompt to \"s\""},
  68    {"monitor", "rerun, restart", "restarts a program without resetting breakpoints"},
  69    {"monitor", "reset", "restarts a program and resets breakpoints"},
  70    {"monitor", "rt", "resumes typing to standard output"},
  71    {"monitor", "sizes", "print size of memory segments"},
  72    {"monitor", "stack [n]", "print \"n\" frames in the stack (default n=3)"},
  73    {"monitor", "step", "continue execution to next interruptable unit"},
  74    {"monitor", "until \"n\"", "continue execution until line number \"n\" is reached"},
  75    {"monitor", "where", "print the interrupted line"},
  76    {"monitor", "xref \"n\"", "give detailed information on source line \"n\""},
  77    {"options", "--assertions, --noassertions", "switch elaboration of assertions on or off"},
  78    {"options", "--backtrace, --nobacktrace", "switch stack backtracing in case of a runtime error"},
  79    {"options", "--boldstropping", "set stropping mode to bold stropping"},
  80    {"options", "--brackets", "consider [ .. ] and { .. } as equivalent to ( .. )"},
  81    {"options", "--check, --norun", "check syntax only, interpreter does not start"},
  82    {"options", "--clock", "report execution time excluding compilation time"},
  83    {"options", "--compile", "compile source file"},
  84    {"options", "--debug, --monitor", "start execution in the debugger and debug in case of runtime error"},
  85    {"options", "--echo string", "echo \"string\" to standard output"},
  86    {"options", "--execute unit", "execute algol 68 unit \"unit\""},
  87    {"options", "--exit, --", "ignore next options"},
  88    {"options", "--extensive", "make extensive listing"},
  89    {"options", "--file string", "accept string as generic filename"},
  90    {"options", "--frame \"number\"", "set frame stack size to \"number\""},
  91    {"options", "--handles \"number\"", "set handle space size to \"number\""},
  92    {"options", "--heap \"number\"", "set heap size to \"number\""},
  93    {"options", "--keep, --nokeep", "switch object file deletion off or on"},
  94    {"options", "--listing", "make concise listing"},
  95    {"options", "--moids", "make overview of moids in listing file"},
  96    {"options", "-O0, -O1, -O2, -O3", "switch compilation on and pass option to back-end C compiler"},
  97    {"options", "--optimise, --nooptimise", "switch compilation on or off"},
  98    {"options", "--pedantic", "equivalent to --warnings --portcheck"},
  99    {"options", "--portcheck, --noportcheck", "switch portability warnings on or off"},
 100    {"options", "--pragmats, --nopragmats", "switch elaboration of pragmat items on or off"},
 101    {"options", "--precision \"number\"", "set precision for long long modes to \"number\" significant digits"},
 102    {"options", "--preludelisting", "make a listing of preludes"},
 103    {"options", "--pretty-print", "pretty-print the source file"},
 104    {"options", "--print unit", "print value yielded by algol 68 unit \"unit\""},
 105    {"options", "--quiet", "suppresses all warning diagnostics"},
 106    {"options", "--quotestropping", "set stropping mode to quote stropping"},
 107    {"options", "--reductions", "print parser reductions"},
 108    {"options", "--run", "override --check/--norun options"},
 109    {"options", "--rerun", "run using already compiled code"},
 110    {"options", "--script", "set next option as source file name; pass further options to algol 68 program"},
 111    {"options", "--source, --nosource", "switch listing of source lines in listing file on or off"},
 112    {"options", "--stack \"number\"", "set expression stack size to \"number\""},
 113    {"options", "--statistics", "print statistics in listing file"},
 114    {"options", "--strict", "disable most extensions to Algol 68 syntax"},
 115    {"options", "--timelimit \"number\"", "interrupt the interpreter after \"number\" seconds"},
 116    {"options", "--trace, --notrace", "switch tracing of a running program on or off"},
 117    {"options", "--tree, --notree", "switch syntax tree listing in listing file on or off"},
 118    {"options", "--unused", "make an overview of unused tags in the listing file"},
 119    {"options", "--verbose", "inform on program actions"},
 120    {"options", "--version", "state version of the running copy"},
 121    {"options", "--warnings, --nowarnings", "switch warning diagnostics on or off"},
 122    {"options", "--xref, --noxref", "switch cross reference in the listing file on or off"},
 123    {NO_TEXT, NO_TEXT, NO_TEXT}
 124  };
 125  
 126  //! @brief Print_info.
 127  
 128  void print_info (FILE_T f, char *prompt, int k)
 129  {
 130    if (prompt != NO_TEXT) {
 131      ASSERT (a68_bufprt (A68 (output_line), SNPRINTF_SIZE, "%s %s: %s.", prompt, TERM (&info_text[k]), DEF (&info_text[k])) >= 0);
 132    } else {
 133      ASSERT (a68_bufprt (A68 (output_line), SNPRINTF_SIZE, "%s: %s.", TERM (&info_text[k]), DEF (&info_text[k])) >= 0);
 134    }
 135    WRITE (f, A68 (output_line));
 136    WRITELN (f, "");
 137  }
 138  
 139  //! @brief Apropos.
 140  
 141  void apropos (FILE_T f, char *prompt, char *item)
 142  {
 143    io_close_tty_line ();
 144    if (item == NO_TEXT) {
 145      for (int k = 0; CAT (&info_text[k]) != NO_TEXT; k++) {
 146        print_info (f, prompt, k);
 147      }
 148      return;
 149    }
 150    int n = 0;
 151    for (int k = 0; CAT (&info_text[k]) != NO_TEXT; k++) {
 152      if (grep_in_string (item, CAT (&info_text[k]), NO_INT, NO_INT) == 0) {
 153        print_info (f, prompt, k);
 154        n++;
 155      }
 156    }
 157    if (n > 0) {
 158      return;
 159    }
 160    for (int k = 0; CAT (&info_text[k]) != NO_TEXT; k++) {
 161      if (grep_in_string (item, TERM (&info_text[k]), NO_INT, NO_INT) == 0 || grep_in_string (item, DEF (&info_text[k]), NO_INT, NO_INT) == 0) {
 162        print_info (f, prompt, k);
 163      }
 164    }
 165  }