Esempio n. 1
0
Bool delete_macro_associated_string_id(PCL5Context *pcl5_ctxt)
{
  MacroInfo *macro_info ;
  HQASSERT(pcl5_ctxt != NULL, "pcl5_ctxt is NULL") ;
  macro_info = get_macro_info(pcl5_ctxt) ;
  HQASSERT(macro_info != NULL, "macro_info is NULL") ;

  if (is_string_macro(macro_info, FALSE)) {
    uint8 *string ;
    int32 length ;
    string = macro_info->macro_string_id.buf ;
    length = macro_info->macro_string_id.length ;

    pcl5_string_id_cache_remove(pcl5_ctxt->resource_caches.string_macro,
                                pcl5_ctxt->resource_caches.macro,
                                string, length, TRUE) ;
  } else {
    pcl5_resource_numeric_id macro_numeric_id = macro_info->macro_numeric_id ;

    pcl5_id_cache_remove(pcl5_ctxt->resource_caches.macro,
                         macro_numeric_id, TRUE) ;
  }

  return TRUE ;
}
Esempio n. 2
0
Bool associate_macro_string_id(PCL5Context *pcl5_ctxt, uint8 *string, int32 length)
{
  MacroInfo *macro_info ;
  pcl5_macro *macro ;

  HQASSERT(pcl5_ctxt != NULL, "pcl5_ctxt is NULL") ;
  macro_info = get_macro_info(pcl5_ctxt) ;
  HQASSERT(macro_info != NULL, "macro_info is NULL") ;
  HQASSERT(string != NULL, "string is NULL") ;
  HQASSERT(length > 0, "length is not greater than zero") ;

  if ((macro = pcl5_string_id_cache_get_macro(pcl5_ctxt->resource_caches.string_macro, string, length)) != NULL) {
    if (is_string_macro(macro_info, FALSE)) {
      uint8 *string ;
      int32 length ;
      string = macro_info->macro_string_id.buf ;
      length = macro_info->macro_string_id.length ;

      if (! pcl5_string_id_cache_insert_aliased_macro(pcl5_ctxt->resource_caches.string_macro,
                                                      pcl5_ctxt->resource_caches.macro,
                                                      macro, string, length))
        return FALSE ;
    } else {
      pcl5_resource_numeric_id macro_numeric_id = macro_info->macro_numeric_id ;

      if (! pcl5_id_cache_insert_aliased_macro(pcl5_ctxt->resource_caches.macro, macro, macro_numeric_id))
        return FALSE ;
    }
  }

  return TRUE ;
}
Esempio n. 3
0
optional<std::string> to_string(expr const & e) {
    if (is_string_macro(e)) {
        return optional<std::string>(to_string_macro(e).get_value());
    } else {
        std::string tmp;
        if (to_string_core(e, tmp)) {
            return optional<std::string>(tmp);
        } else {
            return optional<std::string>();
        }
    }
}
Esempio n. 4
0
void set_macro_permanent(PCL5Context *pcl5_ctxt, MacroInfo *macro_info, Bool permanent)
{
  if (is_string_macro(macro_info, FALSE)) {
    uint8 *string ;
    int32 length ;
    string = macro_info->macro_string_id.buf ;
    length = macro_info->macro_string_id.length ;
    pcl5_string_id_cache_set_permanent(pcl5_ctxt->resource_caches.string_macro, string, length, permanent) ;
  } else {
    pcl5_resource_numeric_id macro_numeric_id = macro_info->macro_numeric_id ;
    pcl5_id_cache_set_permanent(pcl5_ctxt->resource_caches.macro, macro_numeric_id, permanent) ;
  }
}
Esempio n. 5
0
bool to_string_core(expr const & e, std::string & r) {
    if (e == *g_empty || e == *g_list_nil_char) {
        return true;
    } else if (is_string_macro(e)) {
        r = to_string_macro(e).get_value();
        return true;
    } else {
        buffer<expr> args;
        expr const & fn = get_app_args(e, args);
        if (fn == *g_str && args.size() == 2) {
            return to_string_core(args[1], r) && append_char(args[0], r);
        } else if (fn == *g_list_cons && args.size() == 3 && args[0] == *g_char) {
            return to_string_core(args[2], r) && append_char(args[1], r);
        } else {
            return false;
        }
    }
}
Esempio n. 6
0
void remove_macro_definition(PCL5Context *pcl5_ctxt, MacroInfo *macro_info)
{
  HQASSERT(pcl5_ctxt != NULL, "pcl5_ctxt is NULL") ;
  HQASSERT(macro_info != NULL, "macro_info is NULL") ;

  if (is_string_macro(macro_info, FALSE)) {
    uint8 *string ;
    int32 length ;
    string = macro_info->macro_string_id.buf ;
    length = macro_info->macro_string_id.length ;

    pcl5_string_id_cache_remove(pcl5_ctxt->resource_caches.string_macro,
                                pcl5_ctxt->resource_caches.macro,
                                string, length, FALSE) ;

  } else {
    pcl5_resource_numeric_id macro_numeric_id = macro_info->macro_numeric_id ;

    pcl5_id_cache_remove(pcl5_ctxt->resource_caches.macro,
                         macro_numeric_id, FALSE) ;
    pcl5_id_cache_kill_zombies(pcl5_ctxt->resource_caches.macro) ;
  }
}
Esempio n. 7
0
optional<expr> expand_string_macro(expr const & e) {
    if (!is_string_macro(e)) return none_expr();
    return some_expr(from_string_core(to_string_macro(e).get_value()));
}
Esempio n. 8
0
string_macro const & to_string_macro(expr const & e) {
    lean_assert(is_string_macro(e));
    return *static_cast<string_macro const *>(macro_def(e).raw());
}
Esempio n. 9
0
static
Bool open_macro_stream_for_read(PCL5Context *pcl5_ctxt, MacroInfo *macro_info,
                                FILELIST** readstream, Bool overlay)
{
  pcl5_macro *zee_macro ;
  PCL5MacroStorage *macro ;
  PCL5MacroReadInstance *read_instance ;
  int32 i;
  int32 readstream_id ;

  HQASSERT(pcl5_ctxt != NULL, "pcl5_ctxt is NULL") ;
  HQASSERT(macro_info != NULL, "macro_info is NULL") ;

  HQASSERT(readstream != NULL, "readstream is NULL") ;
  HQASSERT(pcl5_macrodevice != NULL, "macro device is NULL") ;

  *readstream = NULL ;

  if (num_read_streams == MAX_MACRO_NEST_LEVEL)
    return FALSE ;

  if (is_string_macro(macro_info, overlay)) {
    uint8 *string ;
    int32 length ;

    if (overlay) {
      string = macro_info->overlay_macro_string_id.buf ;
      length = macro_info->overlay_macro_string_id.length ;
    } else {
      string = macro_info->macro_string_id.buf ;
      length = macro_info->macro_string_id.length ;
    }
    if ((zee_macro = pcl5_string_id_cache_get_macro(pcl5_ctxt->resource_caches.string_macro, string, length)) == NULL)
      return FALSE ;

  } else {
    pcl5_resource_numeric_id macro_numeric_id ;

    if (overlay) {
      macro_numeric_id = macro_info->overlay_macro_numeric_id ;
    } else {
      macro_numeric_id = macro_info->macro_numeric_id ;
    }

    if ((zee_macro = pcl5_id_cache_get_macro(pcl5_ctxt->resource_caches.macro, macro_numeric_id)) == NULL)
      return FALSE ;
  }

  macro = zee_macro->detail.private_data ;
  HQASSERT(macro != NULL, "macro is NULL") ;

  /* Find an empty slot. */
  for (i=0; i < MAX_MACRO_NEST_LEVEL; i++) {
    if (read_streams[i].read_id == STREAM_CLOSED)
      break ;
  }
  readstream_id = i ;

  HQASSERT(readstream_id < MAX_MACRO_NEST_LEVEL,
           "Something odd with finding an empty slot.") ;

  read_instance = &read_streams[readstream_id] ;

  HQASSERT(read_instance->read_stream.typetag == tag_LIMIT,
           "FILELIST has become corrupt.") ;

  read_instance->read_id = readstream_id ;
  read_instance->current_read_data_block = macro->first_data_block ;
  read_instance->read_pos = &(read_instance->current_read_data_block->data)[0] ;
  read_instance->total_remaining = macro->total_bytes ;
  read_instance->macro = macro ;

  init_filelist_struct(&(read_instance->read_stream),
                       NAME_AND_LENGTH("PCL5MacroFileList"),
                       REALFILE_FLAG | READ_FLAG | OPEN_FLAG,
                       readstream_id /* descriptor */,
                       &(read_instance->read_buf)[0] /* buf */,
                       MACRO_DATA_BLOCK_SIZE /* buf size */,
                       FileFillBuff, /* fillbuff */
                       FileFlushBufError, /* flushbuff */
                       FileInit, /* initfile */
                       FileClose, /* closefile */
                       FileDispose, /* disposefile */
                       FileBytes, /* bytesavail */
                       FileReset, /* resetfile */
                       FilePos, /* filepos */
                       FileSetPos, /* setfilepos */
                       FileFlushFile, /* flushfile */
                       FileEncodeError, /* filterencode */
                       FileDecodeError, /* filterdecode */
                       FileLastError, /* lasterror */
                       -1 /* filterstate */,
                       pcl5_macrodevice /* device */,
                       NULL /* underfile */,
                       NULL /* next */) ;

  *readstream = &(read_instance->read_stream) ;

  return TRUE ;
}
Esempio n. 10
0
Bool stop_macro_definition(PCL5Context *pcl5_ctxt, MacroInfo *macro_info)
{
  PCL5MacroStorage *macro ;
  uint8 ch ;
  int32 byte ;
  Bool found_1 = FALSE ;
  FILELIST *filter;

  UNUSED_PARAM(MacroInfo *, macro_info) ;

  HQASSERT(pcl5_ctxt != NULL, "pcl5_ctxt is NULL") ;
  HQASSERT(macro_info != NULL, "macro_info is NULL") ;

  /* If we are not recording a macro, ignore this command and move
     on. */
  if (! pcl5_recording_a_macro)
    return TRUE ;

  HQASSERT(macro_being_defined != NULL, "macro_being_defined is NULL") ;

#ifdef ASSERT_BUILD
  if (is_string_macro(macro_info, FALSE)) {
    uint8 *string ;
    int32 length ;
    string = macro_info->macro_string_id.buf ;
    length = macro_info->macro_string_id.length ;

    HQASSERT((macro_being_defined->detail.string_id.length == length &&
              HqMemCmp(macro_being_defined->detail.string_id.buf,
                       macro_being_defined->detail.string_id.length,
                       string, length) == 0),
             "macro_being_defined is invalid") ;
  }
  else {
    pcl5_resource_numeric_id macro_numeric_id = macro_info->macro_numeric_id ;
    HQASSERT(macro_being_defined->detail.numeric_id == macro_numeric_id,
             "macro_being_defined is invalid") ;
  }
#endif

  /* We would have recorded this command as part of the macro, so remove it.
   * ESC & f 1 X, ESC & f -1.5 X, or similar.
   *
   * N.B. It may be that we don't really need to remove this at all, and
   *      would manage to ignore it OK while running the macro, though
   *      it is perhaps neater to get rid of it.
   */
  macro = macro_being_defined->detail.private_data ;
  HQASSERT(macro != NULL, "macro is NULL") ;

  while (macro->total_bytes > 0) {
    /* N.B. It is not necessarily safe to look at the byte at write_pos,
     *      but should be OK to look at the one before.
     */
    ch = *(macro->write_pos - 1) ;

    if (ch == '1')
      found_1 = TRUE ;
    else if (found_1 && is_group_char(ch) && ch != 'f') {
      /* The parameter or group character is not 'f', so we must have a
       * combined escape sequence, such as ESC & f 1 s 1 X, which we need
       * to leave as ESC & f 1 s
       */
      break ;
    }

    pop_macro_byte(pcl5_ctxt) ;

    if (ch == ESCAPE)
      break ;
  }

  filter = pcl5_ctxt->flptr ;
  pcl5_ctxt->flptr = theIUnderFile(pcl5_ctxt->flptr) ;
  byte = 0 ;

  /* This is a real hack. We know that the buffer size on the macro
     recording filter is 1 byte in length and we always read one byte
     ahead (within filters) so that an UnGetc() can be done
     efficiently. Hence we need to always do an UnGetc() on the
     underlying file as the macro recording filter has consumed one
     byte too many (from its underlying file). Note that byte is not
     actually used by UnGetc() so we don't care what it is. We just
     set it to zero. */
  UnGetc(byte, pcl5_ctxt->flptr) ;

  /* This is where any finalisation on storing the macro should go. */

  pcl5_recording_a_macro = FALSE ;
  macro_being_defined = NULL ;

  SetIClosingFlag( filter ) ;
  (*theIMyDisposeFile(filter))(filter) ;
  ClearIClosingFlag( filter ) ;
  SetIEofFlag( filter ) ;

  return TRUE ;
}
Esempio n. 11
0
static Bool start_macro_definition(PCL5Context *pcl5_ctxt, MacroInfo *macro_info)
{
  pcl5_macro macro, *old_macro, *new_macro ;
  PCL5MacroStorage *private_macro_data ;
  FILELIST *filter;

  HQASSERT(pcl5_ctxt != NULL, "pcl5_ctxt is NULL") ;
  HQASSERT(macro_info != NULL, "macro_info is NULL") ;

  pcl5_recording_a_macro = TRUE ;

  if (! create_macro_storage(&private_macro_data))
    return FALSE ;

  if (is_string_macro(macro_info, FALSE)) {
    uint8 *string ;
    int32 length ;
    string = macro_info->macro_string_id.buf ;
    length = macro_info->macro_string_id.length ;

    /* Clobber the macro if it already exists. */
    if ((old_macro = pcl5_string_id_cache_get_macro(pcl5_ctxt->resource_caches.string_macro, string, length)) != NULL) {
      pcl5_string_id_cache_remove(pcl5_ctxt->resource_caches.string_macro,
                                  pcl5_ctxt->resource_caches.macro,
                                  string, length, FALSE) ;
    }

    macro.detail.resource_type = SW_PCL5_MACRO ;
    macro.detail.numeric_id = 0 ;
    macro.detail.string_id.buf = NULL ;
    macro.detail.string_id.length = 0 ;
    macro.detail.permanent = FALSE ;
    macro.detail.device = NULL ;
    macro.detail.private_data = private_macro_data ;
    macro.detail.PCL5FreePrivateData = free_private_data_callback ;

    if (! pcl5_string_id_cache_insert_macro(pcl5_ctxt->resource_caches.string_macro,
                                            pcl5_ctxt->resource_caches.macro,
                                            string, length, &macro, &new_macro)) {
      destroy_macro_storage(&private_macro_data) ;
      return FALSE ;
    }

  } else {
    pcl5_resource_numeric_id macro_numeric_id = macro_info->macro_numeric_id ;

    /* Clobber the macro if it already exists. */
    if ((old_macro = pcl5_id_cache_get_macro(pcl5_ctxt->resource_caches.macro, macro_numeric_id)) != NULL) {
      pcl5_id_cache_remove(pcl5_ctxt->resource_caches.macro,
                           macro_numeric_id, FALSE) ;
      pcl5_id_cache_kill_zombies(pcl5_ctxt->resource_caches.macro) ;
    }

    macro.detail.resource_type = SW_PCL5_MACRO ;
    macro.detail.numeric_id = macro_numeric_id ;
    macro.detail.permanent = FALSE ;
    macro.detail.device = NULL ;
    macro.detail.private_data = private_macro_data ;
    macro.detail.PCL5FreePrivateData = free_private_data_callback ;

    if (! pcl5_id_cache_insert_macro(pcl5_ctxt->resource_caches.macro, macro_numeric_id, &macro, &new_macro)) {
      destroy_macro_storage(&private_macro_data) ;
      return FALSE ;
    }
  }

  if (! filter_layer(pcl5_ctxt->flptr,
                     NAME_AND_LENGTH("PCL5MacroRecord"), NULL, &filter)) {
    destroy_macro_storage(&private_macro_data) ;
    return FALSE ;
  }

  pcl5_ctxt->flptr = filter ;

  macro_being_defined = new_macro ;

  return TRUE ;
}