Esempio n. 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);
}
Esempio n. 2
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);
}
Esempio n. 3
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);
} 
Esempio n. 4
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);
}
Esempio n. 5
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);
} 
Esempio n. 6
0
int thl_crep(lua_State *L) {
	
	int i = lua_isstring(L, -1);  // make sure it's a string...
	if (i != 1) 
		return 4;
	const void * ptr = lua_tostring(L, -1);
	char * tptr = (char *) ptr;
	void * IPptr;				
	lua_pushstring(L, "lua_dfsanchor");  /* push key */
    lua_gettable(L, LUA_REGISTRYINDEX);  /* retrieve value */

	_anchor * anch = (_anchor *) lua_topointer(L, -1);
	//Process * proc = (Process *) anch -> reserved;
	
	int len = strlen(tptr);
	++len;                          // it's a string, so leave room for terminating null!
	int value = dfscrep(* anch, &IPptr, len, "A");  

	strcpy((char *) IPptr , tptr);

	lua_pushnumber(L, value);
	lua_pushlightuserdata(L, (void *) IPptr);
	return 2;
}