Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Tiny BASIC Interpreter and Compiler Project
  3.  * Language Options Module
  4.  *
  5.  * Released as Public Domain by Damian Gareth Walker 2019
  6.  * Created: 18-Aug-2019
  7.  */
  8.  
  9.  
  10. /* included headers */
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include "options.h"
  15.  
  16.  
  17. /*
  18.  * Data Definitions
  19.  */
  20.  
  21.  
  22. /* private data */
  23. typedef struct {
  24.   LineNumberOption line_numbers; /* mandatory, implied, optional */
  25.   int line_limit; /* highest line number allowed */
  26.   CommentOption comments; /* enabled, disabled */
  27.   int gosub_limit; /* how many nested gosubs */
  28. } Private;
  29.  
  30. /* convenience variables */
  31. static LanguageOptions *this; /* object being worked on */
  32. static Private *data; /* the object's private data */
  33.  
  34.  
  35. /*
  36.  * Public Methods
  37.  */
  38.  
  39.  
  40. /*
  41.  * Set the line number option individually
  42.  * params:
  43.  *   LanguageOptions*    options        the options
  44.  *   LineNumberOption    line_numbers   line number option to set
  45.  */
  46. static void set_line_numbers (LanguageOptions *options,
  47.   LineNumberOption line_numbers) {
  48.   this = options;
  49.   data = this->data;
  50.   data->line_numbers = line_numbers;
  51. }
  52.  
  53. /*
  54.  * Set the line number limit individually
  55.  * params:
  56.  *   LanguageOptions*    options        the options
  57.  *   int                 line_limit     line number limit to set
  58.  */
  59. static void set_line_limit (LanguageOptions *options, int line_limit) {
  60.   this = options;
  61.   data = this->data;
  62.   data->line_limit = line_limit;
  63. }
  64.  
  65. /*
  66.  * Set the comments option individually
  67.  * params:
  68.  *   LanguageOptions*    options    the options
  69.  *   CommentOption       comments   comment option to set
  70.  */
  71. static void set_comments (LanguageOptions *options, CommentOption comments) {
  72.   this = options;
  73.   data = this->data;
  74.   data->comments = comments;
  75. }
  76.  
  77. /*
  78.  * Set the GOSUB stack limit
  79.  * params:
  80.  *   LanuageOptions*   options   the options
  81.  *   int               limit     the desired stack limit
  82.  */
  83. static void set_gosub_limit (LanguageOptions *options, int gosub_limit) {
  84.   this = options;
  85.   data = this->data;
  86.   data->gosub_limit = gosub_limit;
  87. }
  88.  
  89. /*
  90.  * Return the line number setting
  91.  * params:
  92.  *   LanguageOptions*   options   the options
  93.  * returns:
  94.  *   LineNumberOption             the line number setting
  95.  */
  96. static LineNumberOption get_line_numbers (LanguageOptions *options) {
  97.   this = options;
  98.   data = this->data;
  99.   return data->line_numbers;
  100. }
  101.  
  102. /*
  103.  * Return the line number limit
  104.  * params:
  105.  *   LanguageOptions*   options   the options
  106.  * returns:
  107.  *   int                          the line number setting
  108.  */
  109. static int get_line_limit (LanguageOptions *options) {
  110.   this = options;
  111.   data = this->data;
  112.   return data->line_limit;
  113. }
  114.  
  115. /*
  116.  * Return the comments setting
  117.  * params:
  118.  *   LanguageOptions*   options   the options
  119.  * returns:
  120.  *   CommentOption                the line number setting
  121.  */
  122. static CommentOption get_comments (LanguageOptions *options) {
  123.   this = options;
  124.   data = this->data;
  125.   return data->comments;
  126. }
  127.  
  128. /*
  129.  * Return the GOSUB stack limit setting
  130.  * params:
  131.  *   LanguageOptions*   options   the options
  132.  * returns:
  133.  *   int                          the current GOSUB stack limit
  134.  */
  135. static int get_gosub_limit (LanguageOptions *options) {
  136.   this = options;
  137.   data = this->data;
  138.   return data->gosub_limit;
  139. }
  140.  
  141. /*
  142.  * Destroy the settings object
  143.  * params:
  144.  *   LanguageOptions*   options   the options
  145.  */
  146. static void destroy (LanguageOptions *options) {
  147.   if (options) {
  148.     if (options->data)
  149.       free (options->data);
  150.     free (options);
  151.   }
  152. }
  153.  
  154. /*
  155.  * Constructor for language options
  156.  * returns:
  157.  *   LanguageOptions*   the new language options object
  158.  */
  159. LanguageOptions *new_LanguageOptions (void) {
  160.  
  161.   /* allocate memory */
  162.   this = malloc (sizeof (LanguageOptions));
  163.   data = this->data = malloc (sizeof (Private));
  164.  
  165.   /* initialise methods */
  166.   this->set_line_numbers = set_line_numbers;
  167.   this->set_line_limit = set_line_limit;
  168.   this->set_comments = set_comments;
  169.   this->set_gosub_limit = set_gosub_limit;
  170.   this->get_line_numbers = get_line_numbers;
  171.   this->get_line_limit = get_line_limit;
  172.   this->get_comments = get_comments;
  173.   this->get_gosub_limit = get_gosub_limit;
  174.   this->destroy = destroy;
  175.  
  176.   /* initialise properties */
  177.   data->line_numbers = LINE_NUMBERS_OPTIONAL;
  178.   data->line_limit = 32767;
  179.   data->comments = COMMENTS_ENABLED;
  180.   data->gosub_limit = 64;
  181.  
  182.   /* return the new object */
  183.   return this;
  184. }
  185.