Example #1
0
THRCOMP ThCopyNL(_anchor proc_anchor)
{
	void *ptr;
	void *ptr2;
	int value;
	long size;
	char *type;
	port_ent port_tab[2];

	value = dfsdfpt(proc_anchor, 2, port_tab,"IN","OUT");

	value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
	//while (value == 0) {
		value = dfscrep(proc_anchor, &ptr2, size, type);
		memcpy(ptr2,ptr,size);
		value = dfssend(proc_anchor, &ptr2, &port_tab[1], 0);  
		dfsdrop(proc_anchor, &ptr);
		if (value != 0) {
			dfsdrop(proc_anchor, &ptr);
			return(1);
		}
	//	value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
	//}

	return(0);
}
Example #2
0
THRCOMP ThConcatStr(_anchor proc_anchor)
{
	void *ptr;
	//void *ptr2;
	int value;
	long size;
	char *type;
	port_ent port_tab[2];

	value = dfsdfpt(proc_anchor, 2, port_tab,"IN","OUT");

	int no = dfselct(proc_anchor, &port_tab[0]);

	for (int i = 0; i < no; i++) {
		value = dfsrecv(proc_anchor, &ptr, &port_tab[0], i, &size, &type);
		while (value == 0) {

			value = dfssend(proc_anchor, &ptr, &port_tab[1], 0);  				
			value = dfsrecv(proc_anchor, &ptr, &port_tab[0], i, &size, &type);
		}

	}
	return(0);

}
Example #3
0
  THRCOMP thfilert(anchor proc_anchor)
{
  void *ptr;
  char fname[256];
  char *sp;
  char *sp2;
  char *ssp;
  int value;
  long size;
  char *type;

  unsigned long len;
  port_ent port_tab[2];
  FILE *fp;
  char buffer[256];

  value = dfsdfpt(proc_anchor, 2, port_tab,"OPT","OUT");
  value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
  memcpy(fname,ptr,size);
  fname[size] = '\0';
   if ((fp = fopen(fname,"r")) == NULL) {
	 sprintf(buffer, "Cannot open file %s", fname);
         dfsputs(proc_anchor,buffer);
	 return(8);
     }

  value = dfsdrop(proc_anchor, &ptr);
  ssp =(char *) malloc(32767);
  sp = ssp;
  while (1) {
    while (1) {
      sp2 = fgets (sp, 32765, fp);
      if (sp2 == NULL)
	break;
      sp = sp2;
      len = strlen(sp);
      sp = sp + len;
      if (*(sp - 1) == '\n') {
	 --sp;
	 break;
	 }
      }
    value = dfscrep(proc_anchor, &ptr, sp - ssp, "A");
    memcpy (ptr, ssp, sp - ssp);
    value = dfssend(proc_anchor, &ptr, &port_tab[1], 0);
    if (sp2 == NULL)
   	break;

    sp = ssp;
    }
  fclose(fp);
  free(ssp);
  return(0);
}
Example #4
0
THRCOMP thsockwt(anchor proc_anchor)
{
    void *ptr;
    char *dptr;
    int value, i;
    long size;
    char *type;
    char string[256];
    int ch;
    port_ent port_tab[3];
    FILE *fp;
    char buffer[256];

    /* We'll leave OPT there for now */

    value = dfsdfpt(proc_anchor, 3, port_tab,"OPT","IN","OUT");

    /*obtain filename parameter
    */
    value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
    memcpy(string,ptr,size);
    value = dfsdrop(proc_anchor, &ptr);
    string[size] = '\0';
    /*
     if ((fp = fopen(string,"wt")) == NULL) {
           sprintf(buffer, "Cannot open file %s", string);
           dfsputs(proc_anchor,buffer);
     return(8);
       }
     */

    i = socket(AF_INET, SOCK_STREAM, 0);

    value = dfsrecv(proc_anchor, &ptr, &port_tab[1], 0, &size, &type);
    while (value == 0)
    {
        dptr = (char *) ptr;
        for (i = 0; i < size; i++) {
            ch = (int) * (dptr + i);
            value = fputc(ch, fp);
        }
        value = fputc('\n',fp);

        value = dfssend(proc_anchor, &ptr, &port_tab[2], 0);
        if (value == 2)
            value = dfsdrop(proc_anchor, &ptr);
        value = dfsrecv(proc_anchor, &ptr, &port_tab[1], 0, &size, &type);
    }
    fclose(fp);
    return(0);
}
Example #5
0
  THRCOMP ThFileWt (_anchor proc_anchor) {
 
 
  void *ptr;
  char *dptr;
  int value, i;
  long size;
  char *type;
  char fname[256];
  int ch;
  port_ent port_tab[3];
  FILE *fp;
  //char buffer[256];
  

  value = dfsdfpt(proc_anchor, 3, port_tab,"OPT","IN","OUT");

/*obtain filename parameter
*/
  value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
  memcpy(fname,ptr,size);
  value = dfsdrop(proc_anchor, &ptr);
  fname[size] = '\0';
  #ifdef WIN32
    errno_t err;
    if( (err  = fopen_s( &fp, fname, "w" )) !=0 ) {
#else
    if ((f = fopen(fname, "w")) == NULL) {
#endif
        fprintf(stderr, "Cannot open file %s!\n", fname);
		return(8);
    }

    value = dfsrecv(proc_anchor, &ptr, &port_tab[1], 0, &size, &type);
    while (value == 0)
      {
      dptr = (char *) ptr;
      for (i = 0; i < size - 1; i++) {
         ch = (int) * (dptr + i);
         value = fputc(ch, fp);
        }
      value = fputc('\n',fp);

      value = dfssend(proc_anchor, &ptr, &port_tab[2], 0);
     if (value == 2)
	 value = dfsdrop(proc_anchor, &ptr);
      value = dfsrecv(proc_anchor, &ptr, &port_tab[1], 0, &size, &type);
      }
  fclose(fp);
  return(0);
}
Example #6
0
THRCOMP ThLua(_anchor proc_anchor)
{

	int value;	

	port_ent port_tab[1];

	value = dfsdfpt(proc_anchor, 1, port_tab, "PROG");

	char pgmname [100];
	void * ptr;
	long size;
	char *type;

	value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
	memcpy(pgmname,ptr,size);
	pgmname[size] = '\0';

	value = dfsdrop(proc_anchor, &ptr);

	lua_State *L = lua_open();

	luaL_openlibs (L);

	lua_pushstring(L, "lua_dfsanchor");  /* push key */
	lua_pushlightuserdata(L, (void *)&proc_anchor);  /* push address */

	lua_settable(L, LUA_REGISTRYINDEX);

	lua_register(L, "dfsrecv", thl_recv);
	lua_register(L, "dfsdrop", thl_drop);
	lua_register(L, "dfscrep", thl_crep);
	lua_register(L, "dfssend", thl_send);
	lua_register(L, "dfselct", thl_elct);
	lua_register(L, "dfsclos", thl_clos);
	lua_register(L, "dfsderef", thl_deref);

	lua_register(L, "myprint", myprint);

	int s = luaL_loadfile(L, pgmname);

    if ( s==0 ) {
      // execute Lua program
      s = lua_pcall(L, 0, LUA_MULTRET, 0);
    }
	report_errors(L, s);
	lua_close(L);
	return(0);
}
Example #7
0
  THRCOMP ThFileRd(_anchor proc_anchor) {
 
 
  void *ptr;
  char fname[256];
  char string[256];
  int value;
  long size;
  char *type;
  unsigned long len;
  port_ent port_tab[2];
  FILE *fp;
  //char buffer[256];

  value = dfsdfpt(proc_anchor, 2, port_tab,"OPT","OUT");

/* read in the filename and open the input file
*/
  value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
  memcpy(fname,ptr,size);
  fname[size] = '\0';
   
#ifdef WIN32
    errno_t err;
    if( (err  = fopen_s( &fp, fname, "r" )) !=0 ) {
#else
    if ((f = fopen(fname, "r")) == NULL) {
#endif
        fprintf(stderr, "Cannot open file %s!\n", fname);
		return(8);
    }
  value = dfsdrop(proc_anchor, &ptr);

/* read records from the input file and create entities from them.  If the
input records are longer than 256 bytes, they will be segmented and put out
as a series of 256 byte entities.
*/
  while ((fgets (string, 256, fp)) != NULL) {
      len = strlen(string);
      if (string[len - 1] == '\n')
	 len = len - 1;
      value = dfscrep(proc_anchor, &ptr, len,"A");
      memcpy (ptr, string, len);
      value = dfssend(proc_anchor, &ptr, &port_tab[1], 0);
      }
  fclose(fp);
  return(0);
} 
Example #8
0
THRCOMP  ThDrop(_anchor proc_anchor)
{
    void *ptr;
    int value;
    long size;
    char *type;
    port_ent port_tab[1];

    value = dfsdfpt(proc_anchor, 1, port_tab,"IN");
    value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
    while (value == 0) {
        value = dfsdrop(proc_anchor, &ptr);
        value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
    }
    return(0);
}
Example #9
0
  THRCOMP SELURLS(anchor proc_anchor)
{
  void *ptr;
  void *ptrn;
  char * p2;
  
  int value;
  long size;
  char *type;
  port_ent port_tab[3];
  
  
  
  /* ports: INT - list of interesting WikiNames    */ 
  /*        IN  - output of RecentChanges          */ 
  /*        OUT - list of lines to be diaplayed    */ 

 
  value = dfsdfpt(proc_anchor, 3, port_tab, "INT", "IN","OUT");

/* build list of interesting URLs                */
  

/* process input entities */
  value = dfsrecv(proc_anchor, &ptr, &port_tab[1], 0, &size, &type);
  while (value == 0) {
      getWikiName((char *) ptr, size);
      printf(WikiName);
      
      value = dfscrep(proc_anchor, &ptrn, size + strlen("<b>  ***  </b>") + 1, "B");
      strncpy((char *) ptrn, (char *) ptr, size);
      p2 = (char *) ptrn + size;

      if  (isitint) 
	  strcpy(p2, "<b>  ***  </b>" );
      else
	  strcpy(p2, "              " );
      value = dfssend(proc_anchor, &ptrn, &port_tab[2], 0);
      value = dfsdrop(proc_anchor, &ptr);
        
      value = dfsrecv(proc_anchor, &ptr, &port_tab[1], 0, &size, &type);
      }
    return(0);
}
Example #10
0
  THRCOMP ThGenIps(_anchor proc_anchor)
{
  void *ptr;
  char *p;
  char string[256];
  int value, i;
  long size, count;
  char *type;
  port_ent port_tab[3];
  //char buffer[256];

  value = dfsdfpt(proc_anchor, 3, port_tab,"COUNT","OUT","PREFIX");

  value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
  if (value > 0) {
     printf("THGENIPS: No number specified\n");
  //   dfsputs(proc_anchor, buffer);
     return(8);
     }
  memcpy(string,ptr,size);
  string[size] = '\0';
  count = atol(string);

  value = dfsdrop(proc_anchor, &ptr);

  strcpy(string, "Testing ");
  value = dfsrecv(proc_anchor, &ptr, &port_tab[2], 0, &size, &type);
  if (value == 0) {
     memcpy(string,ptr,size);
     string[size] = '\0';
     value = dfsdrop(proc_anchor, &ptr);
  }
 // dfstest(proc_anchor);
  for (i = 0; i < count; i++) {
      value = dfscrep(proc_anchor, &ptr, 32,"G");
      strcpy((char *) ptr, string);
      p = strchr((char *) ptr, '\0');
      _itoa(i, p, 10);
      value = dfssend(proc_anchor, &ptr, &port_tab[1], 0);
      }
  return(0);
} 
Example #11
0
  THRCOMP THASSIGN(anchor proc_anchor)
{
  void *ptr;
  void *optr;
  char *start_ptr, *length_ptr;
  int  value, i, length, start_pos, PARMOK;
  long size, value_int;
  char *type;
  port_ent port_tab[3];
  struct _instr
  {
     char string[1];
  };
  typedef struct _instr instr;

  struct _optstr
  {
     char string[1];
  };
  typedef struct _optstr optstr;

  instr *inptr;
  optstr *value_ptr, *format_ptr;

  value = dfsdfpt(proc_anchor, 3, port_tab, "VALUE", "IN", "OUT");

/* obtain input parameters VALUE, FORMAT, STARTPOS, LENGTH
*/
  PARMOK = 1;
  length = 4;
  start_pos = 0;
  value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
  if (value == 0)
    {
      value_ptr = (optstr *) strtok((char *)ptr, ",/. ;:");
      if (value_ptr != 0)
	{
	  format_ptr = (optstr *) strtok(0, ",/. ;:");
	  if (format_ptr != 0)
	    {
	      if (!strcmp((char *)format_ptr, "INT"))
                {
		  value_int = atol((char *) value_ptr);
		  value_ptr =(optstr *) &value_int;
	        }
	      start_ptr = strtok(0, ",/. ;:");
	      if (start_ptr != 0)
	        {
	          start_pos = atoi(start_ptr);
		  if (!strcmp((char *)format_ptr, "CHAR"))
		  {
		    length_ptr =  strtok(0, ",/. ;:");
	            if (length_ptr != 0)
		      length = atoi(length_ptr);
		  }
		}
	    }
	  else PARMOK = 0;
	}
      else PARMOK = 0;

      optr = ptr;
    }

/* process input entities
*/
  value = dfsrecv(proc_anchor, &ptr, &port_tab[1], 0, &size, &type);
  while (value == 0)
    {
      inptr = (instr *) ptr;
      if (PARMOK)
      {
        for (i = 0; i < length; i++)
	  {
	    inptr -> string[i + start_pos] = value_ptr -> string[i];
          }
      }
      value = dfssend(proc_anchor, &ptr, &port_tab[2], 0);
      if (value != 0)
	  value = dfsdrop(proc_anchor, &ptr);
      value = dfsrecv(proc_anchor, &ptr, &port_tab[1], 0, &size, &type);
    }
  value = dfsdrop(proc_anchor, &optr);
  return(0);
}
Example #12
0
THRCOMP ThSort (_anchor proc_anchor) {
	void *ptr;	
	void *dptrm, *dptr;
	char * cptrm, *cptr;
	int value, i;
	long size;
	char *type;
	port_ent port_tab[2];
	void** sort_tab;
	int count, lowest;
	bool first;
	bool finished = false;
	long m, n, k;

	sort_tab = new void*[2000];
	for (i = 0; i < 2000; i++)
		sort_tab[i] = 0;
	value = dfsdfpt(proc_anchor, 2, port_tab,"IN","OUT");
	i = 0;
	value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
	while (value == 0) {	  
		sort_tab[i] = (unsigned char *) ptr;
		i++;
		value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type);
	}
	count = i;
	value = dfstest(proc_anchor);	
	lowest = 0;
	for (;;) {
		finished = true;
		first = true;
		for (i = 0; i < count; i++) {
			if (sort_tab[i] != 0) {				
				finished = false;
				dptr = sort_tab[i];
				if (first) {
					dptrm = dptr;
					first = false;
					lowest = i;
					m = dfsgsize(proc_anchor, &dptrm);
				}				  
				else {
					n = dfsgsize(proc_anchor, &dptr);
					k = n;
					if (n > m)
						k = m;
					cptrm = (char *) dptrm;
					cptr = (char *) dptr;
					if (memcmp(dptrm, dptr, k) > 0) {
						dptrm = dptr;
						lowest = i;
					}
					else if (memcmp(dptrm, dptr, k) == 0 && m > n) {
						dptrm = dptr;
						lowest = i;
					}
				}
			}			
		}
		if (finished)
			break;
		ptr = sort_tab[lowest];
		sort_tab[lowest] = 0;
		value = dfssend(proc_anchor, &ptr, &port_tab[1], 0);
	}	 

	return(0);
}