Ejemplo n.º 1
0
int SLprep_set_comment (SLprep_Type *pt, SLFUTURE_CONST char *start, SLFUTURE_CONST char *stop)
{
   if ((pt == NULL) || (start == NULL))
     return -1;

   if (NULL == (start = SLang_create_slstring (start)))
     return -1;

   if (stop == NULL)
     stop = "";

   if (NULL == (stop = SLang_create_slstring (stop)))
     {
	SLang_free_slstring ((char *) start);
	return -1;
     }

   if (pt->comment_start != NULL)
     SLang_free_slstring ((char *) pt->comment_start);
   pt->comment_start = start;
   pt->comment_start_len = strlen (start);

   if (pt->comment_stop != NULL)
     SLang_free_slstring ((char *) pt->comment_stop);
   pt->comment_stop = stop;

   return 0;
}
Ejemplo n.º 2
0
static int sl_report_function (Isis_Fit_Statistic_Type *s, void *pfp, double stat, unsigned int npts, unsigned int nvpars) /*{{{*/
{
   FILE *fp = (FILE *)pfp;
   char *str;

   if (s == NULL || s->sl_report == NULL)
     return -1;

   SLang_start_arg_list ();
   if ((-1 == SLang_push_double (stat))
       || (-1 == SLang_push_integer ((int) npts))
       || (-1 == SLang_push_integer ((int) nvpars)))
     return -1;
   SLang_end_arg_list ();

   if (-1 == SLexecute_function ((SLang_Name_Type *)s->sl_report))
     return -1;

   if (-1 == SLang_pop_slstring (&str))
     return -1;

   if (EOF == fputs (str, fp))
     {
        SLang_free_slstring (str);
        return -1;
     }
   SLang_free_slstring (str);
   return 0;
}
Ejemplo n.º 3
0
static void sl_base64_decode (void){
  char* input, *in;
  BIO* bmem,* b64;
  SLang_BString_Type* output;
  int i, outlen;
  char nl[]="\n";
  
  if (SLang_Num_Function_Args != 1 ||
      SLang_pop_slstring(&in) == -1 ){
    return; }

  /* For some reason, the input is required to have a newline at the
     end, doesn't matter how many, so tack one on here*/
  input = SLang_concat_slstrings(in,nl);
  SLang_free_slstring(in);

  unsigned char* buff = (char*)malloc((int)strlen(input)+1);
  memset(buff,0,(int)strlen(input));

  b64  = BIO_new(BIO_f_base64());
  bmem = BIO_new_mem_buf(input,(int)strlen(input));
  bmem = BIO_push(b64,bmem);
  outlen = BIO_read(bmem,buff,(int)strlen(input));
  BIO_free_all(bmem);

  output = SLbstring_create(buff, outlen);

  SLang_push_bstring(output);
  SLang_free_slstring(input);
  SLbstring_free(output);
  free(buff);
}
Ejemplo n.º 4
0
static int connect_af_unix (Socket_Type *s, int nargs)
{
   struct sockaddr_un addr;
   char *file;

   if (nargs != 1)
     {
	SLang_verror (SL_NumArgs_Error, "This socket expects a filename");
	return -1;
     }
   if (-1 == SLang_pop_slstring (&file))
     return -1;

   if (strlen (file) >= sizeof(addr.sun_path))
     {
	SLang_verror (SL_InvalidParm_Error, "filename too long for PF_UNIX socket");
	SLang_free_slstring (file);
	return -1;
     }

   memset ((char *)&addr, 0, sizeof (struct sockaddr_un));
   addr.sun_family = AF_UNIX;
   strcpy (addr.sun_path, file);       /* \0 terminated */

   SLang_free_slstring (file);
   return perform_connect (s->fd, (struct sockaddr *)&addr, sizeof (addr), 1);
}
Ejemplo n.º 5
0
SLang_Name_Type *SLang_pop_function (void)
{
   SLang_Ref_Type *ref;
   SLang_Name_Type *f;

   if (SLang_peek_at_stack () == SLANG_STRING_TYPE)
     {
	char *name;
	
	if (-1 == SLang_pop_slstring (&name))
	  return NULL;
	
	if (NULL == (f = SLang_get_function (name)))
	  {
	     _pSLang_verror (SL_UNDEFINED_NAME, "Function %s does not exist", name);
	     SLang_free_slstring (name);
	     return NULL;
	  }
	SLang_free_slstring (name);
	return f;
     }

   if (-1 == SLang_pop_ref (&ref))
     return NULL;

   f = SLang_get_fun_from_ref (ref);
   SLang_free_ref (ref);
   return f;
}
Ejemplo n.º 6
0
static void sl_ssl_client (void){
  // create an ssl object and return the memory managed type back to
  // SLang. It needs the file descriptor of the object upon which
  // communication will occur, and the protocol to use.
  //
  SSL_CTX *ctx;
  SSL *ssl;
  int proto, cret;
  SLang_MMT_Type *mmt, *sslmmt;
  SLsslctx_Type *slctx;
  char *cadir=NULL, *cafile=NULL;  

  if (SLang_Num_Function_Args == 3)
    if (SLang_pop_slstring(&cadir) == -1)
      return;

  if (SLang_Num_Function_Args > 1)
    if (SLANG_NULL_TYPE==SLang_peek_at_stack())
      SLdo_pop();
    else if (SLang_pop_slstring(&cafile) == -1)
      goto free;
      
  if (SLang_pop_integer(&proto) == -1)
    goto free;

  if (proto==SSL_PROTO_SSL2)
    ctx = SSL_CTX_new(SSLv23_client_method());
  else if (proto==SSL_PROTO_SSL3)
    ctx = SSL_CTX_new(SSLv3_client_method());
  else if (proto==SSL_PROTO_TLS1)
    ctx = SSL_CTX_new(TLSv1_client_method());
  else if (proto==SSL_PROTO_ANY)
    ctx = SSL_CTX_new(SSLv23_client_method());
  
  cret = SSL_CTX_load_verify_locations(ctx, cafile, cadir);

  if (cret == 0 && SLang_Num_Function_Args > 1){
    SLang_verror(SL_APPLICATION_ERROR, "Failed to load CA file or path");
    goto free;
  }

  slctx = (SLsslctx_Type *)malloc(sizeof(SLsslctx_Type));
  slctx->is_server = 0;
  slctx->ctx = (void *)ctx;

  sslmmt = SLang_create_mmt(SLsslctx_Type_Id, (VOID_STAR) slctx);

  if (0!=SLang_push_mmt(sslmmt))
    SLang_free_mmt(sslmmt);

 free:
  if (NULL!=cadir)
    SLang_free_slstring(cadir);
  if (NULL!=cafile)
    SLang_free_slstring(cafile);
}
Ejemplo n.º 7
0
void SLprep_delete (SLprep_Type *pt)
{
   if (pt == NULL)
     return;

   /* NULLs ok */
   SLang_free_slstring ((char *)pt->comment_start);
   SLang_free_slstring ((char *)pt->comment_stop);
   SLang_free_slstring ((char *)pt->prefix);

   SLfree ((char *) pt);
}
Ejemplo n.º 8
0
static void free_this_exception (Exception_Type *e)
{
   if (e == NULL)
     return;
   
   if (e->name != NULL)
     SLang_free_slstring ((char *) e->name);

   if (e->description != NULL)
     SLang_free_slstring ((char *) e->description);

   SLfree ((char *)e);
}
Ejemplo n.º 9
0
/* this will be called with use_current_queue set to 0 if the catch block
 * was processed with no error.  If an error occurs processing the catch
 * block, then that error will take precedence over the one triggering the
 * catch block.  However, if the original error is rethrown, then this routine
 * will still be called with use_current_queue non-zero since all the caller
 * knows is that an error occured and cannot tell if it was a rethrow.
 */
int _pSLang_pop_error_context (int use_current_queue)
{
   Error_Context_Type *e;

   e = Error_Context;
   if (e == NULL)
     return -1;

   Error_Context = e->next;

   if ((use_current_queue == 0) || (e->rethrow))
     {
	(void) _pSLerr_set_error_queue (e->err_queue);
	_pSLerr_delete_error_queue (Error_Message_Queue);
	Error_Message_Queue = e->err_queue;
	free_thrown_object ();
	if (e->object_was_thrown)
	  {
	     Object_Thrownp = &Object_Thrown;
	     Object_Thrown = e->object_thrown;
	  }
     }
   else
     {
	_pSLerr_delete_error_queue (e->err_queue);
	if (e->object_was_thrown)
	  SLang_free_object (&e->object_thrown);
     }

   if (_pSLang_Error == 0)
     {
	if (e->err_cleared == 0)
	  {
	     SLang_free_slstring ((char *)File_With_Error);
	     SLang_free_slstring ((char *)Function_With_Error);
	     File_With_Error = e->file; e->file = NULL;
	     Function_With_Error = e->function; e->function = NULL;
	     Linenum_With_Error = e->linenum;
	     (void) SLang_set_error (e->err);
	  }
     }

   if (_pSLang_Error == SL_UserBreak_Error)
     SLKeyBoard_Quit = 1;

   SLang_free_slstring ((char *) e->file);
   SLang_free_slstring ((char *) e->function);

   SLfree ((char *) e);
   return 0;
}
Ejemplo n.º 10
0
   /* {SO_PEERCRED, NULL, get_peercred_sockopt}, */
# endif
# ifdef SO_RCVTIMEO
   {SO_RCVTIMEO, set_timeval_sockopt, get_timeval_sockopt},
# endif
# ifdef SO_SNDTIMEO
   {SO_SNDTIMEO, set_timeval_sockopt, get_timeval_sockopt},
# endif
# ifdef SO_LINGER
   {SO_LINGER, set_linger_sockopt, get_linger_sockopt},
# endif

   {-1, NULL, NULL}
};
#endif				       /* SOL_SOCKET */

#if defined(IP_ADD_MEMBERSHIP) /* either add or drop same args */
static int set_multicast_sockopt (Socket_Type *s, int level, int option)
{
   struct ip_mreq group;
   char *multi;
   char *local = NULL;
   Host_Addr_Info_Type *multi_info = NULL;
   Host_Addr_Info_Type *local_info = NULL;
   int ret = -1;

   if (-1 == SLang_pop_slstring(&multi))
     return -1;

   if (5 == SLang_Num_Function_Args)
     {
	if (-1 == SLang_pop_slstring(&local))
	  {
	     SLang_free_slstring (multi);
	     return -1;
	  }
     }

   if (NULL == (multi_info = get_host_addr_info (multi)))
     goto free_and_return;

   if (local != NULL)
     {
	if (NULL == (local_info = get_host_addr_info (local)))
	  goto free_and_return;

	memcpy ((char *) &group.imr_interface.s_addr, local_info->h_addr_list[0], local_info->h_length);
     }
   else
     {
	group.imr_interface.s_addr = INADDR_ANY;
     }
   memcpy ((char *) &group.imr_multiaddr.s_addr, multi_info->h_addr_list[0], multi_info->h_length);

   ret = do_setsockopt (s->fd, level, option, (void *)&group, sizeof(group));

free_and_return:

   SLang_free_slstring(multi);
   if (NULL != local)
     SLang_free_slstring(local);
   free_host_addr_info (multi_info);
   if (NULL != local_info)
     free_host_addr_info (local_info);

   return ret;
}
Ejemplo n.º 11
0
static int connect_af_inet (Socket_Type *s, int nargs)
{
   struct sockaddr_in s_in;
   int port;
   char *host;
   Host_Addr_Info_Type *hinfo;
   unsigned int i;

   if (-1 == pop_host_port ("connect", nargs, &host, &port))
     return -1;

   if (NULL == (hinfo = get_host_addr_info (host)))
     {
	SLang_free_slstring (host);
	return -1;
     }

   if (hinfo->h_addrtype != AF_INET)
     {
# ifdef AF_INET6
	if (hinfo->h_addrtype == AF_INET6)
	  SLang_verror (SL_NOT_IMPLEMENTED, "AF_INET6 not implemented");
	else
# endif
	  SLang_verror (SocketError, "Unknown socket family for host %s", host);
	SLang_free_slstring (host);
	free_host_addr_info (hinfo);
	return -1;
     }

   memset ((char *) &s_in, 0, sizeof(s_in));
   s_in.sin_family = hinfo->h_addrtype;
   s_in.sin_port = htons((unsigned short) port);

   for (i = 0; i < hinfo->num; i++)
     {
	memcpy ((char *) &s_in.sin_addr, hinfo->h_addr_list[i], hinfo->h_length);
	if (-1 == perform_connect (s->fd, (struct sockaddr *)&s_in, sizeof (s_in), 0))
	  continue;

	free_host_addr_info (hinfo);
	SLang_free_slstring (host);
	return 0;
     }
   throw_errno_error ("connect", errno);
   free_host_addr_info (hinfo);
   SLang_free_slstring (host);
   return -1;
}
Ejemplo n.º 12
0
int _pSLerr_throw (void)
{
   int e;
   int nargs = SLang_Num_Function_Args;
   char *msg = NULL;

   free_thrown_object ();

   switch (nargs)
     {
      case 3:
	if (-1 == SLang_pop (&Object_Thrown))
	  return -1;
	Object_Thrownp = &Object_Thrown;
	/* drop */
      case 2:
	if (-1 == SLang_pop_slstring (&msg))
	  {
	     free_thrown_object ();
	     return -1;
	  }
      case 1:
	/* drop */
	if (-1 == _pSLerr_pop_exception (&e))
	  {
	     SLang_free_slstring (msg);/* NULL ok */
	     free_thrown_object ();
	     return -1;
	  }
	break;

      case 0:			       /* rethrow */
	return rethrow_error ();

      default:
	_pSLang_verror (SL_NumArgs_Error, "expecting: throw error [, optional-message [, optional-arg]]");
	return -1;
     }

   if (msg != NULL)
     {
	_pSLang_verror (e, "%s", msg);
	SLang_free_slstring (msg);
     }
   else
     SLang_set_error (e);

   return 0;
}
Ejemplo n.º 13
0
void SLrline_close (SLrline_Type *rli)
{
   if (rli == NULL)
     return;
   
   if (rli->name != NULL)
     {
	char hookname[1024];
	SLrline_Type *arli = Active_Rline_Info;
	Active_Rline_Info = rli;
	SLsnprintf (hookname, sizeof(hookname), "%s_rline_close_hook", rli->name);
	if (0 == SLang_run_hooks (hookname, 0))
	  (void) SLang_run_hooks ("rline_close_hook", 1, rli->name);
	Active_Rline_Info = arli;
	SLang_free_slstring (rli->name);
     }

   free_history (rli->root);
   free_history_item (rli->saved_line);
   SLang_free_function (rli->list_completions_callback);
   SLang_free_function (rli->completion_callback);
   SLfree ((char *)rli->prompt);
   SLfree ((char *)rli->buf);
   SLfree ((char *)rli);
}
Ejemplo n.º 14
0
void SLbstring_free (SLang_BString_Type *b)
{
   if (b == NULL)
     return;

   if (b->num_refs > 1)
     {
	b->num_refs -= 1;
	return;
     }

   switch (b->ptr_type)
     {
      case 0:
      case IS_NOT_TO_BE_FREED:
      default:
	break;

      case IS_SLSTRING:
	SLang_free_slstring ((char *)b->v.ptr);
	break;

      case IS_MALLOCED:
	SLfree ((char *)b->v.ptr);
	break;
     }

   SLfree ((char *) b);
}
Ejemplo n.º 15
0
int _SLns_set_namespace_name (SLang_NameSpace_Type *t, char *name)
{
   SLang_NameSpace_Type *t1;
   
   t1 = _SLns_find_namespace (name);
   if (t == t1)
     return 0;			       /* already has this name */

   if (t1 == NULL)
     t1 = t;
   
   if ((t != t1) || (*name == 0))
     {
	SLang_verror (SL_INTRINSIC_ERROR, "Namespace \"%s\" already exists",
		      name);
	return -1;
     }

   if (t->namespace_name != NULL)
     {
	SLang_verror (SL_INTRINSIC_ERROR, "An attempt was made to redefine namespace from \"%s\" to \"%s\"\n",
		      t->namespace_name, name);
	return -1;
     }

   if (NULL == (name = SLang_create_slstring (name)))
     return -1;

   SLang_free_slstring (t->namespace_name);   /* NULL ok */
   t->namespace_name = name;
   
   return 0;
}
Ejemplo n.º 16
0
static void slang_to_pcre (char *pattern)
{
   /* NULL ok in code below */
   pattern = _slang_to_pcre (pattern);
   (void) SLang_push_string (pattern);
   SLang_free_slstring (pattern);
}
Ejemplo n.º 17
0
static void read_image (int flipped)
{
   int color_type;
   char *file;
   SLang_Ref_Type *ref = NULL;
   SLang_Array_Type *at;

   if ((SLang_Num_Function_Args == 2)
       && (-1 == SLang_pop_ref (&ref)))
     return;

   if (-1 == SLang_pop_slstring (&file))
     {
	file = NULL;
	goto free_return;
     }

   if (NULL == (at = read_image_internal (file, flipped, &color_type)))
     goto free_return;

   if ((ref != NULL)
       && (-1 == SLang_assign_to_ref (ref, SLANG_INT_TYPE, &color_type)))
     {
	SLang_free_array (at);
	goto free_return;
     }

   (void) SLang_push_array (at, 1);

   free_return:
   SLang_free_slstring (file);
   if (ref != NULL)
     SLang_free_ref (ref);
}
Ejemplo n.º 18
0
static void atoll_intrin (void)
{
   char *s;
   SLang_Array_Type *ats;
   SLang_Array_Type *ati;
   long long *ip;
   char **strp, **strpmax;

   if (-1 == pop_array_or_string (_pSLANG_LLONG_TYPE, &s, &ats, &ati))
     return;

   if (s != NULL)
     {
	(void) SLang_push_long_long (ATOLL_FUN(s));
	SLang_free_slstring (s);
	return;
     }

   strp = (char **) ats->data;
   strpmax = strp + ats->num_elements;
   ip = (long long *) ati->data;

   while (strp < strpmax)
     {
	if (*strp == NULL)
	  *ip++ = 0;
	else
	  *ip++ = ATOLL_FUN (*strp);
	strp++;
     }
   SLang_free_array (ats);
   (void) SLang_push_array (ati, 1);
}
Ejemplo n.º 19
0
static void intrin_atof (void)
{
   char *s;
   SLang_Array_Type *ats;
   SLang_Array_Type *ati;
   double *ip;
   char **strp, **strpmax;

   if (-1 == pop_array_or_string (SLANG_DOUBLE_TYPE, &s, &ats, &ati))
     return;

   if (s != NULL)
     {
	(void) SLang_push_double(_pSLang_atof(s));
	SLang_free_slstring (s);
	return;
     }

   strp = (char **) ats->data;
   strpmax = strp + ats->num_elements;
   ip = (double *) ati->data;
	
   while (strp < strpmax)
     {
	if (*strp == NULL)
	  *ip++ = _pSLang_NaN;
	else
	  *ip++ = _pSLang_atof (*strp);
	strp++;
     }
   SLang_free_array (ats);
   (void) SLang_push_array (ati, 1);
}
Ejemplo n.º 20
0
static void atoi_intrin (void)
{
   char *s;
   SLang_Array_Type *ats;
   SLang_Array_Type *ati;
   int *ip;
   char **strp, **strpmax;

   if (-1 == pop_array_or_string (SLANG_INT_TYPE, &s, &ats, &ati))
     return;

   if (s != NULL)
     {
	(void) SLang_push_integer (atoi (s));
	SLang_free_slstring (s);
	return;
     }

   strp = (char **) ats->data;
   strpmax = strp + ats->num_elements;
   ip = (int *) ati->data;
	
   while (strp < strpmax)
     {
	if (*strp == NULL)
	  *ip++ = 0;
	else
	  *ip++ = atoi (*strp);
	strp++;
     }
   SLang_free_array (ats);
   (void) SLang_push_array (ati, 1);
}
Ejemplo n.º 21
0
SLrline_Type *SLrline_open2 (SLFUTURE_CONST char *name, unsigned int width, unsigned int flags)
{
   SLrline_Type *rli;
   SLrline_Type *arli;
   char hookname [1024];

   if (NULL == (rli = SLrline_open (width, flags)))
     return NULL;

   if (NULL != rli->name)
     SLang_free_slstring (rli->name);
   if (NULL == (rli->name = SLang_create_slstring (name)))
     {
	SLrline_close (rli);
	return NULL;
     }

   arli = Active_Rline_Info;
   Active_Rline_Info = rli;
   SLsnprintf (hookname, sizeof(hookname), "%s_rline_open_hook", name);
   if (0 == SLang_run_hooks (hookname, 0))
     (void) SLang_run_hooks ("rline_open_hook", 1, name);
   Active_Rline_Info = arli;
   return rli;
}
Ejemplo n.º 22
0
void _pSLpack (void)
{
   SLang_BString_Type *bs;
   char *fmt;
   int nitems;

   check_native_byte_order ();

   nitems = SLang_Num_Function_Args;
   if (nitems <= 0)
     {
	_pSLang_verror (SL_SYNTAX_ERROR,
		      "pack: not enough arguments");
	return;
     }

   if ((-1 == SLreverse_stack (nitems))
       || (-1 == SLang_pop_slstring (&fmt)))
     bs = NULL;
   else
     {
	bs = pack_according_to_format (fmt, (unsigned int)nitems - 1);
	SLang_free_slstring (fmt);
     }

   SLang_push_bstring (bs);
   SLbstring_free (bs);
}
Ejemplo n.º 23
0
static int exec_what (int what, int has_envp)
{
   SLang_Array_Type *at_argv = NULL;
   SLang_Array_Type *at_envp = NULL;
   char **argv = NULL, **envp = NULL;
   char *path = NULL;
   int status = -1;

   if (has_envp)
     {
	if (NULL == (envp = pop_argv (&at_envp)))
	  goto free_and_return;
     }
     
   if (NULL == (argv = pop_argv (&at_argv)))
     goto free_and_return;

   if (-1 == SLang_pop_slstring (&path))
     goto free_and_return;

   status = call_what (what, path, argv, envp);

free_and_return:

   if (path != NULL) SLang_free_slstring (path);
   if (argv != NULL) SLfree ((char *)argv);
   if (at_argv != NULL) SLang_free_array (at_argv);
   if (envp != NULL) SLfree ((char *)envp);
   if (at_envp != NULL) SLang_free_array (at_envp);
   return status;
}
Ejemplo n.º 24
0
static void rline_setkey_intrinsic (char *keyseq)
{
   char *str;
   SLkeymap_Type *kmap;

   if (NULL == (kmap = get_keymap ()))
     return;

   if (SLang_peek_at_stack () == SLANG_REF_TYPE)
     {
	SLang_Name_Type *nt;
	
	if (NULL == (nt = SLang_pop_function ()))
	  return;

	(void) SLkm_define_slkey (keyseq, nt, kmap);
	return;
     }
   
   if (-1 == SLang_pop_slstring (&str))
     return;
   
   (void) SLang_define_key (keyseq, str, kmap);
   SLang_free_slstring (str);
}
Ejemplo n.º 25
0
/* Usage: s1 = accept (s [,&host,&port]); */
static Socket_Type *accept_af_inet (Socket_Type *s, unsigned int nrefs, SLang_Ref_Type **refs)
{
   struct sockaddr_in s_in;
   Socket_Type *s1;
   unsigned int addr_len;

   if ((nrefs != 0) && (nrefs != 2))
     {
	SLang_verror (SL_NumArgs_Error, "accept (sock [,&host,&port])");
	return NULL;
     }

   addr_len = sizeof (struct sockaddr_in);
   s1 = perform_accept (s, (struct sockaddr *)&s_in, &addr_len);

   if ((s1 == NULL) || (nrefs == 0))
     return s1;

   if (nrefs == 2)
     {
	char *host;
	char host_ip[32];  /* aaa.bbb.ccc.ddd */
	unsigned char *bytes = (unsigned char *)&s_in.sin_addr;
	int port = ntohs (s_in.sin_port);
	sprintf (host_ip, "%d.%d.%d.%d",
		 (int)bytes[0],(int)bytes[1],(int)bytes[2],(int)bytes[3]);

	if (NULL == (host = SLang_create_slstring (host_ip)))
	  {
	     free_socket (s1);
	     return NULL;
	  }
	if (-1 == SLang_assign_to_ref (refs[0], SLANG_STRING_TYPE, (VOID_STAR)&host))
	  {
	     SLang_free_slstring (host);
	     free_socket (s1);
	     return NULL;
	  }
	SLang_free_slstring (host);
	if (-1 == SLang_assign_to_ref (refs[1], SLANG_INT_TYPE, &port))
	  {
	     free_socket (s1);
	     return NULL;
	  }
     }
   return s1;
}
Ejemplo n.º 26
0
static void posix_open (void)
{
   char *file;
   int mode, flags;
   SLFile_FD_Type *f;

   switch (SLang_Num_Function_Args)
     {
      case 3:
	if (-1 == pop_string_int_int (&file, &flags, &mode))
	  {
	     SLang_push_null ();
	     return;
	  }
	break;

      case 2:
      default:
	if (-1 == pop_string_int (&file, &flags))
	  return;
	mode = 0777;
	break;
     }

   f = SLfile_create_fd (file, -1);
   if (f == NULL)
     {
	SLang_free_slstring (file);
	SLang_push_null ();
	return;
     }
   SLang_free_slstring (file);

   while (-1 == (f->fd = open (f->name, flags, mode)))
     {
	if (is_interrupt (errno, 1))
	  continue;

	SLfile_free_fd (f);
	SLang_push_null ();
	return;
     }

   if (-1 == SLfile_push_fd (f))
     SLang_push_null ();
   SLfile_free_fd (f);
}
Ejemplo n.º 27
0
int SLrline_init (SLFUTURE_CONST char *appname, SLFUTURE_CONST char *user_initfile, SLFUTURE_CONST char *sys_initfile)
{
#ifdef __WIN32__
   char *home_dir = getenv ("USERPROFILE");
#else
# ifdef VMS
   char *home_dir = "SYS$LOGIN:"******"HOME");
# endif
#endif
   char *file = NULL;
   int status;
   static char *appname_malloced;

   if (sys_initfile == NULL)
     sys_initfile = SLRLINE_SYS_INIT_FILE;
   if (user_initfile == NULL)
     user_initfile = SLRLINE_USER_INIT_FILE;
   
   if (appname == NULL)
     appname = "Unknown";

   if (NULL == (appname_malloced = SLmake_string (appname)))
     return -1;

   if (-1 == SLadd_intrinsic_variable ("__RL_APP__", &appname_malloced, SLANG_STRING_TYPE, 1))
     return -1;

   if (-1 == SLadd_intrin_fun_table (Intrinsics, NULL))
     return -1;

   if (-1 == init_keymap ())
     return -1;

   if (user_initfile != NULL)
     {
	file = SLpath_find_file_in_path (home_dir, user_initfile);
	if (file != NULL)
	  {
	     status = SLns_load_file (file, NULL);
	     SLfree (file);
	     return status;
	  }
     }

   if (sys_initfile != NULL)
     {
	file = _pSLpath_find_file (sys_initfile, 0);
	if (file != NULL)
	  {
	     status = SLns_load_file (file, NULL);
	     SLang_free_slstring (file);
	     return status;
	  }
     }

   return 0;
}
Ejemplo n.º 28
0
Archivo: sltest.c Proyecto: parke/slang
static void check_intrin_string_qualifier (char *name, char *def)
{
   char *s;
   if (-1 == SLang_get_string_qualifier (name, &s, def))
     return;
   SLang_push_string (s);
   SLang_free_slstring (s);
}
Ejemplo n.º 29
0
static int set_user_info (char **what, char *value)
{
   if (NULL == (value = SLang_create_slstring (value)))
     return -1;
   SLang_free_slstring (*what);   /* NULL ok */
   *what = value;
   return 0;
}
Ejemplo n.º 30
0
static void free_error_msg (Error_Message_Type *m)
{
   if (m == NULL)
     return;
   if (m->msg != NULL)
     SLang_free_slstring (m->msg);
   SLfree ((char *)m);
}