Example #1
0
/*-------------------------------------------------------------------------*
 * PL_SET_TOP_LEVEL_STREAMS_2                                              *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Set_Top_Level_Streams_2(WamWord sora_in_word, WamWord sora_out_word)
{
  pl_stm_top_level_input = Pl_Get_Stream_Or_Alias(sora_in_word, STREAM_CHECK_INPUT);
  pl_stm_top_level_output = Pl_Get_Stream_Or_Alias(sora_out_word, STREAM_CHECK_OUTPUT);

  Pl_Reassign_Alias(pl_atom_top_level_input, pl_stm_top_level_input);
  Pl_Reassign_Alias(pl_atom_top_level_output, pl_stm_top_level_output);
}
Example #2
0
/*-------------------------------------------------------------------------*
 * PL_SET_DEBUGGER_STREAMS_2                                               *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Set_Debugger_Streams_2(WamWord sora_in_word, WamWord sora_out_word)
{
  pl_stm_debugger_input = Pl_Get_Stream_Or_Alias(sora_in_word, STREAM_CHECK_INPUT);
  pl_stm_debugger_output = Pl_Get_Stream_Or_Alias(sora_out_word, STREAM_CHECK_OUTPUT);

  Pl_Reassign_Alias(pl_atom_debugger_input, pl_stm_debugger_input);
  Pl_Reassign_Alias(pl_atom_debugger_output, pl_stm_debugger_output);
}
Example #3
0
/*-------------------------------------------------------------------------*
 * PL_ADD_STREAM_MIRROR_2                                                  *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Add_Stream_Mirror_2(WamWord sora_word, WamWord mirror_word)
{
  int stm;
  int m_stm;

  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  m_stm = Pl_Get_Stream_Or_Alias(mirror_word, STREAM_CHECK_OUTPUT);

  Pl_Add_Mirror_To_Stream(stm, m_stm);
}
Example #4
0
/*-------------------------------------------------------------------------*
 * PL_REMOVE_STREAM_MIRROR_2                                               *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_Remove_Stream_Mirror_2(WamWord sora_word, WamWord mirror_word)
{
  int stm;
  int m_stm;

  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  m_stm = Pl_Get_Stream_Or_Alias(mirror_word, STREAM_CHECK_EXIST);

  return Pl_Del_Mirror_From_Stream(stm, m_stm);
}
Example #5
0
/*-------------------------------------------------------------------------*
 * PL_FORMAT_3                                                             *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Format_3(WamWord sora_word, WamWord format_word, WamWord args_word)
{
  WamWord word, tag_mask;
  int stm;
  StmInf *pstm;
  char *str;
  char buff[2048];


  stm = (sora_word == NOT_A_WAM_WORD)
    ? pl_stm_output : Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_OUTPUT);
  pstm = pl_stm_tbl[stm];

  pl_last_output_sora = sora_word;
  Pl_Check_Stream_Type(stm, TRUE, FALSE);

  DEREF(format_word, word, tag_mask);

  if (tag_mask == TAG_ATM_MASK && word != NIL_WORD)
    str = pl_atom_tbl[UnTag_ATM(word)].name;
  else
    {
      strcpy(buff, Pl_Rd_Codes_Check(format_word));
      str = buff;
    }

  Format(pl_stm_tbl[stm], str, &args_word);
}
Example #6
0
/*-------------------------------------------------------------------------*
 * PL_STREAM_POSITION_2                                                    *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_Stream_Position_2(WamWord sora_word, WamWord position_word)
{
  WamWord word, tag_mask;
  WamWord p_word[4];
  PlLong p[4];
  int i;
  int stm;
  StmInf *pstm;


  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  Pl_Stream_Get_Position(pstm, p, p + 1, p + 2, p + 3);

  if (!Pl_Get_Structure(pl_atom_stream_position, 4, position_word))
  dom_error:
    Pl_Err_Domain(pl_domain_stream_position, position_word);

  for (i = 0; i < 4; i++)
    {
      p_word[i] = Pl_Unify_Variable();

      DEREF(p_word[i], word, tag_mask);
      if (tag_mask != TAG_REF_MASK && tag_mask != TAG_INT_MASK)
	goto dom_error;
    }

  for (i = 0; i < 4; i++)
    if (!Pl_Get_Integer(p[i], p_word[i]))
      return FALSE;

  return TRUE;
}
Example #7
0
/*-------------------------------------------------------------------------*
 * PL_SET_STREAM_TYPE_2                                                    *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Set_Stream_Type_2(WamWord sora_word, WamWord is_text_word)
{
  int stm;
  StmInf *pstm;
  int text;

  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  text = Pl_Rd_Integer_Check(is_text_word);
  if ((unsigned) text == pstm->prop.text)
    return;

  if (pstm->char_count)
    Pl_Err_Permission(pl_permission_operation_modify,
		      pl_permission_type_stream, sora_word);

  pstm->prop.text = text;
#if defined(_WIN32) || defined(__CYGWIN__)
  {
    FILE *f;

    f = Pl_Stdio_Desc_Of_Stream(stm);
    if (f == NULL)
      return;

    setmode(fileno(f), (text) ? O_TEXT : O_BINARY);
  }
#endif
}
Example #8
0
/*-------------------------------------------------------------------------*
 * PL_SET_STREAM_LINE_COLUMN_3                                             *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_Set_Stream_Line_Column_3(WamWord sora_word, WamWord line_word,
			    WamWord col_word)
{
  int stm;
  StmInf *pstm;
  PlLong line_count, line_pos;


  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  if (!pstm->prop.reposition)
    Pl_Err_Permission(pl_permission_operation_reposition,
		      pl_permission_type_stream, sora_word);

  if (!pstm->prop.text)
    Pl_Err_Permission(pl_permission_operation_reposition,
		      pl_permission_type_binary_stream, sora_word);


  line_count = Pl_Rd_Integer_Check(line_word) - 1;
  line_pos = Pl_Rd_Integer_Check(col_word) - 1;

  return line_count >= 0 && line_pos >= 0 &&
    Pl_Stream_Set_Position_LC(pstm, line_count, line_pos) == 0;
}
Example #9
0
/*-------------------------------------------------------------------------*
 * PL_SR_INIT_OPEN_2                                                       *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_SR_Init_Open_2(WamWord desc_word, WamWord out_sora_word)
{
  SRInf *sr;
  int desc;

  if (sr_tbl == NULL)		/* first allocation */
    {
      sr_tbl_size = 8;
      sr_last_used = -1;
      sr_tbl = (SRInf *) Calloc(sr_tbl_size, sizeof(SRInf));
    }

  for(desc = 0; desc < sr_tbl_size; desc++)
    if (!sr_tbl[desc].in_use)
      break;

  if (desc == sr_tbl_size)
    Pl_Extend_Array((char **) &sr_tbl, &sr_tbl_size, sizeof(SRInf), TRUE);

  if (desc > sr_last_used)
    sr_last_used = desc;

  sr = cur_sr = sr_tbl + desc;

  if (sr->file_top)		    /* to due a previous aborted sr_open/3 */
    {
      Free(sr->file_top);
      sr->file_top = NULL;
    }

  sr->mask = SYS_VAR_OPTION_MASK;

  sr->file_first = NULL;
  sr->file_last = NULL;
  sr->next_to_reread = NULL;	/* 1st read mode */

  sr->cur_l1 = sr->cur_l2 = 0;
  sr->char_count = 0;
  sr->line_count = 0;
  sr->error_count = 0;
  sr->warning_count = 0;

  if (pl_sys_var[1])
    {
      Pl_Get_Stream_Or_Alias(out_sora_word, STREAM_CHECK_VALID);
      sr->out_sora_word = out_sora_word;
    }
  else
    sr->out_sora_word = NOT_A_WAM_WORD;

  sr->direct_lst.first = NULL;
  sr->direct_lst.last = NULL;

  sr->module_lst = NULL;
  sr->cur_module = NULL;
  sr->interface = FALSE;

  Pl_Get_Integer(desc, desc_word);
}
Example #10
0
/*-------------------------------------------------------------------------*
 * PL_CLOSE_INPUT_TERM_STREAM_1                                            *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Close_Input_Term_Stream_1(WamWord sora_word)
{
  int stm;
  StmInf *pstm;
  StrSInf *str_stream;
  int type;

  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  type = pstm->prop.other;

  if (type < 1 || type > 3)
    Pl_Err_Domain(pl_domain_term_stream_or_alias, sora_word);

  if (pstm->prop.output)
    Pl_Err_Permission(pl_permission_operation_close,
		      pl_permission_type_stream, sora_word);

  if (type != TERM_STREAM_ATOM)
    {
      str_stream = (StrSInf *) (pstm->file);
      Free(str_stream->buff);
    }

  Pl_Delete_Str_Stream(stm);
}
Example #11
0
/*-------------------------------------------------------------------------*
 * PL_ADD_STREAM_ALIAS_2                                                   *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_Add_Stream_Alias_2(WamWord sora_word, WamWord alias_word)
{
  int stm;

  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);

  return Pl_Add_Alias_To_Stream(Pl_Rd_Atom_Check(alias_word), stm);
}
Example #12
0
/*-------------------------------------------------------------------------*
 * PL_AT_END_OF_STREAM_1                                                   *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_At_End_Of_Stream_1(WamWord sora_word)
{
  int stm;

  stm = (sora_word == NOT_A_WAM_WORD)
    ? pl_stm_input : Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_INPUT);

  return Pl_Stream_End_Of_Stream(pl_stm_tbl[stm]) != STREAM_EOF_NOT;
}
Example #13
0
/*-------------------------------------------------------------------------*
 * PL_SET_STREAM_BUFFERING_2                                               *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Set_Stream_Buffering_2(WamWord sora_word, WamWord buff_mode_word)
{
  int stm;
  StmInf *pstm;

  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  pstm->prop.buffering = Pl_Rd_Integer_Check(buff_mode_word);
  Pl_Set_Stream_Buffering(stm);
}
Example #14
0
/*-------------------------------------------------------------------------*
 * PL_FLUSH_OUTPUT_1                                                       *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Flush_Output_1(WamWord sora_word)
{
  int stm;


  stm = (sora_word == NOT_A_WAM_WORD)
    ? pl_stm_output : Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_OUTPUT);

  pl_last_output_sora = sora_word;

  Pl_Stream_Flush(pl_stm_tbl[stm]);
}
Example #15
0
/*-------------------------------------------------------------------------*
 * PL_CHARACTER_COUNT_2                                                    *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_Character_Count_2(WamWord sora_word, WamWord count_word)
{
  int stm;
  StmInf *pstm;
  PlLong offset, char_count, line_count, line_pos;

  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  Pl_Stream_Get_Position(pstm, &offset, &char_count, &line_count, &line_pos);

  return Pl_Un_Integer_Check(char_count, count_word);
}
Example #16
0
/*-------------------------------------------------------------------------*
 * PL_SET_STREAM_EOF_ACTION_2                                              *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Set_Stream_Eof_Action_2(WamWord sora_word, WamWord action_word)
{
  int stm;
  StmInf *pstm;

  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  if (pstm->prop.output)
    Pl_Err_Permission(pl_permission_operation_modify,
		      pl_permission_type_stream, sora_word);

  pstm->prop.eof_action = Pl_Rd_Integer_Check(action_word);
}
Example #17
0
/*-------------------------------------------------------------------------*
 * PL_LINE_POSITION_2                                                      *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_Line_Position_2(WamWord sora_word, WamWord count_word)
{
  int stm;
  StmInf *pstm;
  PlLong offset, char_count, line_count, line_pos;

  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  if (!pstm->prop.text)
    Pl_Err_Permission(pl_permission_operation_access,
		      pl_permission_type_binary_stream, sora_word);

  Pl_Stream_Get_Position(pstm, &offset, &char_count, &line_count, &line_pos);

  return Pl_Un_Integer_Check(line_pos, count_word);
}
Example #18
0
/*-------------------------------------------------------------------------*
 * PL_CLOSE_OUTPUT_TERM_STREAM_2                                           *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_Close_Output_Term_Stream_2(WamWord sora_word, WamWord sink_term_word)
{
  int stm;
  StmInf *pstm;
  int type;
  char *str;

  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  type = pstm->prop.other;

  if (type < 1 || type > 3)
    Pl_Err_Domain(pl_domain_term_stream_or_alias, sora_word);

  if (pstm->prop.input)
    Pl_Err_Permission(pl_permission_operation_close,
		      pl_permission_type_stream, sora_word);

  str = Pl_Term_Write_Str_Stream(stm);

  switch (SYS_VAR_OPTION_MASK)
    {
    case TERM_STREAM_ATOM:
      if (!Pl_Un_String_Check(str, sink_term_word))
	return FALSE;
      break;

    case TERM_STREAM_CHARS:
      if (!Pl_Un_Chars_Check(str, sink_term_word))
	return FALSE;
      break;

    case TERM_STREAM_CODES:
      if (!Pl_Un_Codes_Check(str, sink_term_word))
	return FALSE;
      break;

    }

  Pl_Delete_Str_Stream(stm);
  return TRUE;
}
Example #19
0
/*-------------------------------------------------------------------------*
 * PL_SEEK_4                                                               *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_Seek_4(WamWord sora_word, WamWord whence_word, WamWord offset_word,
	  WamWord new_loc_word)
{
  int stm;
  StmInf *pstm;
  int whence;
  PlLong offset;
  int atom;
  PlLong p[4];


  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  if (!pstm->prop.reposition)
    Pl_Err_Permission(pl_permission_operation_reposition,
		      pl_permission_type_stream, sora_word);

  if (pstm->prop.text)
    Pl_Err_Permission(pl_permission_operation_reposition,
		      pl_permission_type_text_stream, sora_word);

  atom = Pl_Rd_Atom_Check(whence_word);

  if (atom == pl_atom_bof)
    whence = SEEK_SET;
  else if (atom == pl_atom_current)
    whence = SEEK_CUR;
  else if (atom == pl_atom_eof)
    whence = SEEK_END;
  else
    Pl_Err_Domain(pl_domain_stream_seek_method, whence_word);

  offset = Pl_Rd_Integer_Check(offset_word);
  Pl_Check_For_Un_Integer(new_loc_word);

  if (Pl_Stream_Set_Position(pstm, whence, offset, offset, 0, 0) != 0)
    return FALSE;

  Pl_Stream_Get_Position(pstm, &offset, p + 1, p + 2, p + 3);

  return Pl_Get_Integer(offset, new_loc_word);
}
Example #20
0
/*-------------------------------------------------------------------------*
 * PL_SET_STREAM_POSITION_2                                                *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_Set_Stream_Position_2(WamWord sora_word, WamWord position_word)
{
  WamWord word, tag_mask;
  WamWord p_word[4];
  int p[4];
  int i;
  int stm;
  StmInf *pstm;


  stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  pstm = pl_stm_tbl[stm];

  if (!pstm->prop.reposition)
    Pl_Err_Permission(pl_permission_operation_reposition,
		      pl_permission_type_stream, sora_word);

  DEREF(position_word, word, tag_mask);
  if (tag_mask == TAG_REF_MASK)
    Pl_Err_Instantiation();

  if (!Pl_Get_Structure(pl_atom_stream_position, 4, position_word))
  dom_error:
    Pl_Err_Domain(pl_domain_stream_position, position_word);

  for (i = 0; i < 4; i++)
    {
      p_word[i] = Pl_Unify_Variable();

      DEREF(p_word[i], word, tag_mask);
      if (tag_mask == TAG_REF_MASK)
	Pl_Err_Instantiation();

      if (tag_mask != TAG_INT_MASK)
	goto dom_error;

      p[i] = UnTag_INT(word);
    }

  return Pl_Stream_Set_Position(pstm, SEEK_SET, p[0], p[1], p[2], p[3]) == 0;
}
Example #21
0
/*-------------------------------------------------------------------------*
 * PL_SR_OPEN_FILE_2                                                       *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_SR_Open_File_2(WamWord file_name_word, WamWord from_stream_word)
{
  SRInf *sr = cur_sr;
  int atom_file_name;
  int stm;
  SRFile *file;
  Bool from_stream = Pl_Rd_Boolean(from_stream_word);
  Bool master_file = (sr->file_top == NULL);
  StmInf *pstm, *pstm_tmp;

  if (sr->next_to_reread == NULL)
    {
      if (from_stream)
	{
	  stm = Pl_Get_Stream_Or_Alias(file_name_word, STREAM_CHECK_INPUT);
	  Pl_Check_Stream_Type(stm, TRUE, TRUE);
	  atom_file_name = pl_stm_tbl[stm]->atom_file_name;
	}
      else
	{
	  atom_file_name = Pl_Rd_Atom(file_name_word);
	  if (strcmp(pl_atom_tbl[atom_file_name].name, "user") == 0)
#if 0
	    stm = pl_stm_input;
#else
	  {
	    stm = Pl_Add_Stream(0, (long) 0, pl_stm_tbl[pl_stm_input]->prop,
		    NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	    *pl_stm_tbl[stm] = *pl_stm_tbl[pl_stm_input];
	  }
#endif
	  else
	    {
	      stm = Pl_Add_Stream_For_Stdio_File(pl_atom_tbl[atom_file_name].name,
					      STREAM_MODE_READ, TRUE);
	      if (stm < 0)
		{
		  if (errno == ENOENT || errno == ENOTDIR)
		    Pl_Err_Existence(pl_existence_source_sink, 
				     file_name_word);
		  else
		    Pl_Err_Permission(pl_permission_operation_open,
				      pl_permission_type_source_sink, 
				      file_name_word);
		}
	    }
	}
      pstm = pl_stm_tbl[stm];
      file = (SRFile *) Malloc(sizeof(SRFile));
      file->atom_file_name = atom_file_name;
      file->stm = stm;
      file->reposition = pstm->prop.reposition;
      if (!file->reposition)
	{
	  file->tmp_path = Pl_M_Tempnam(NULL, NULL);
	  file->tmp_stm = Pl_Add_Stream_For_Stdio_File(file->tmp_path,
						    STREAM_MODE_WRITE, TRUE);
	  if (file->tmp_stm < 0)
	    Pl_Fatal_Error("cannot create tmp file %s in %s:%d", file->tmp_path,
			__FILE__, __LINE__);

				/* try to be similar to original file */
	  pstm_tmp = pl_stm_tbl[file->tmp_stm];
	  pstm_tmp->atom_file_name = atom_file_name;
	  pstm_tmp->prop.eof_action = pstm->prop.eof_action;
	  if (pstm_tmp->prop.buffering != pstm->prop.buffering)
	    {
	      pstm_tmp->prop.buffering = pstm->prop.buffering;
	      Pl_Stdio_Set_Buffering((FILE *) pstm_tmp->file,
				  pstm_tmp->prop.buffering);
	    }
	  Pl_Add_Mirror_To_Stream(stm, file->tmp_stm);
	}
      else
	{
	  file->tmp_path = NULL;
	  file->tmp_stm = -1;
	}
      file->next = NULL;
      if (sr->file_first == NULL)
	sr->file_first = file;
      else
	sr->file_last->next = file;
      sr->file_last = file;
    }
Example #22
0
/*-------------------------------------------------------------------------*
 * PL_SET_INPUT_1                                                          *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Set_Input_1(WamWord sora_word)
{
  pl_stm_input = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_INPUT);
}
Example #23
0
/*-------------------------------------------------------------------------*
 * PL_SET_OUTPUT_1                                                         *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Set_Output_1(WamWord sora_word)
{
  pl_stm_output = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_OUTPUT);
}
Example #24
0
/*-------------------------------------------------------------------------*
 * PL_CHECK_VALID_MIRROR_1                                                 *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Check_Valid_Mirror_1(WamWord mirror_word)
{
  Pl_Get_Stream_Or_Alias(mirror_word, STREAM_CHECK_OUTPUT);
}
Example #25
0
/*-------------------------------------------------------------------------*
 * PL_CLOSE_1                                                              *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Close_1(WamWord sora_word)
{
  int stm = Pl_Get_Stream_Or_Alias(sora_word, STREAM_CHECK_EXIST);
  Pl_Close_Stm(stm, SYS_VAR_OPTION_MASK & 1);
}