예제 #1
0
void 
gen_faq_doc( const char *source_dir, const char *dest_dir, ASDocType doc_type )
{
	ASXMLInterpreterState state;
	char *faq_dir = NULL ;
	ASFlagType doc_class_mask = DOC_CLASS_None	;
	struct direntry  **list = NULL;
	int list_len, i ;

	faq_dir = make_file_name( source_dir, "FAQ" );

	if( !start_doc_file( dest_dir, "afterstep_faq", NULL, doc_type, 
						 "afterstep_faq", 
						 "AfterStep FAQ",
						 "This document is an ever growing set of questions, statements, ideas and complaints about AfterStep version 2.0", 
						 &state, doc_class_mask, DocClass_FAQ ) )	 
		return ;
	
	/* BODY *************************************************************************/
	set_flags( state.flags, ASXMLI_OrderSections );
	list_len = my_scandir ((char*)faq_dir, &list, ignore_dots, NULL);
	for (i = 0; i < list_len; i++)
	{	
		if ( !S_ISDIR (list[i]->d_mode) )
			convert_xml_file( faq_dir, list[i]->d_name, &state );
		free(list[i]);
	}
	if( list ) 
		free( list );   
	
	/* FOOTER ***********************************************************************/
	end_doc_file( &state );	 	
	
	free( faq_dir );
}
예제 #2
0
void CFileBrowser::recursiveDelete(const char* file)
{
	stat_struct statbuf;
	dirent_struct **namelist;
	int n;
	printf("Delete %s\n", file);
	if(my_lstat(file,&statbuf) == 0)
	{
		if(S_ISDIR(statbuf.st_mode))
		{
			n = my_scandir(file, &namelist, 0, my_alphasort);
			while(n--)
			{
				if(strcmp(namelist[n]->d_name, ".")!=0 && strcmp(namelist[n]->d_name, "..")!=0)
				{
					std::string fullname = (std::string)file + "/" + namelist[n]->d_name;
					recursiveDelete(fullname.c_str());
				}
				free(namelist[n]);
			}
			free(namelist);
			rmdir(file);
		}
		else
		{
			unlink(file);
		}
	}
	else
		perror(file);
}
예제 #3
0
/* assumes that tree->name and tree->path are already filled in */
void
dirtree_fill_from_dir (dirtree_t * tree)
{
	struct direntry **list;
	int           i, n;
	
	ASSERT_TREE(tree);
	n = my_scandir (tree->path, &list, no_dots_except_include, NULL);
	for (i = 0; i < n; i++)
	{
		dirtree_t    *t = dirtree_new ();

		t->name = mystrdup (list[i]->d_name);
		t->path = make_absolute (tree->path, t->name);
		if (S_ISDIR (list[i]->d_mode))
			t->flags |= DIRTREE_DIR;
		t->mtime = list[i]->d_mtime;

		dirtree_fill_from_dir (t);
		t->parent = tree;
		t->next = tree->child;
		tree->child = t;

		free (list[i]);
	}
	if (n > 0)
	{
		tree->flags |= DIRTREE_DIR;
		free (list);
	}
}
예제 #4
0
bool CFileBrowser::readDir(const std::string& dirname, CFileList* flist)
{
	dprintf(DEBUG_INFO, "CFileBrowser::readDir %s\n", dirname.c_str());
	
	stat_struct statbuf;
	dirent_struct **namelist;
	int n;

	n = my_scandir(dirname.c_str(), &namelist, 0, my_alphasort);
	if (n < 0)
	{
		perror(("Filebrowser scandir: " + dirname).c_str());
		return false;
	}
	
	for(int i = 0; i < n;i++)
	{
		CFile file;
		if(strcmp(namelist[i]->d_name, ".") != 0)
		{
			// name
			file.Name = dirname + namelist[i]->d_name;

			// stat
			if(my_stat((file.Name).c_str(),&statbuf) != 0)
				perror("stat error");
			else
			{
				file.Mode = statbuf.st_mode;
				file.Size = statbuf.st_size;
				file.Time = statbuf.st_mtime;
				
				flist->push_back(file);
			}
		}
		free(namelist[i]);
	}

	free(namelist);

	return true;
}
예제 #5
0
/* Returns 1 on success and 0 on failure */
int perl_init(void)
{
   char path[MAX_FDP_LEN+1];
   char *script_list[256];
   char *myargv[] = {"", NULL};
   int i, k, len;
   int sock;
   struct sockaddr_un remote_addr;
   char temp_nick[MAX_NICK_LEN+1];
   char temp_host[MAX_HOST_LEN+1];
   char *buf, *bufp;
   int spaces=0, entries=0;
   int l;
   int erret;
   int flags;
   
   memset(&remote_addr, 0, sizeof(struct sockaddr_un));

   /* First kill off scripts that is already running.  */
   remove_all(SCRIPT, 1, 1);
   
   /* Reads the script names in the script directory */
   snprintf(path, MAX_FDP_LEN, "%s/%s", config_dir, SCRIPT_DIR);
   i = my_scandir(path, script_list);
   
   if(i == 0)
     return 1;
   
   k = i-1;
   
   for(i = 0; i <= k; i++)
     {	
	myargv[1] = script_list[i];
	if((pid = fork()) == -1)
	  {	
	     logprintf(1, "Fork failed, exiting process\n");
	     logerror(1, errno);
	     quit = 1;
	     return 0;;
	  }
	
	/* If we are the parent */   
	if(pid > 0)
	  {
	     logprintf(3, "Forked new script parsing process for script %s, childs pid is %d and parents pid is %d\n", script_list[i], pid, getpid());
	     pid = getpid();
	  }
	
	/* And if we are the child */
	else
	  {
	     pid = -1;
	     
	     /* Close the listening sockets */
	     while(((erret =  close(listening_unx_socket)) != 0) && (errno == EINTR))
	       logprintf(1, "Error - In perl_init()/close(): Interrupted system call. Trying again.\n");
	     
	     if(erret != 0)
	       {		  
		  logprintf(1, "Error - In perl_init()/close(): ");
		  logerror(1, errno);
	       }
	     
	     while(((erret =  close(listening_udp_socket)) != 0) && (errno == EINTR))
	       logprintf(1, "Error - In perl_init()/close(): Interrupted system call. Trying again.\n");
	     
	     if(erret != 0)
	       {		  
		  logprintf(1, "Error - In perl_init()/close(): ");
		  logerror(1, errno);
	       }
	     
	     /* Set the alarm */
	     alarm(ALARM_TIME);
	     
	     /* And connect to parent process */
	     if((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
	       {		  
		  logprintf(1, "Error - In perl_init()/socket(): ");
		  logerror(1, errno);
		  free(script_list[i]);
		  exit(EXIT_FAILURE);
	       }
	     
	     remote_addr.sun_family = AF_UNIX;
	     strcpy(remote_addr.sun_path, un_sock_path);
	     len = strlen(remote_addr.sun_path) + sizeof(remote_addr.sun_family) + 1;
	     if(connect(sock, (struct sockaddr *)&remote_addr, len) == -1)
	       {	     
		  logprintf(1, "Error - In perl_init()/connect(): ");
		  logerror(1, errno);
		  free(script_list[i]);
		  exit(EXIT_FAILURE);
	       }
	     
	     if((flags = fcntl(sock, F_GETFL, 0)) < 0)
	       {
		  logprintf(1, "Error - In new_human_user()/in fcntl(): ");
		  logerror(1, errno);
		  close(sock);
		  return -1;
	       }
	     
	     /* Non blocking mode */
	     if(fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0)
	       {
		  logprintf(1, "Error - In new_human_user()/in fcntl(): ");
		  logerror(1, errno);
		  close(sock);
		  return -1;
	       }	     
	     
	     /* The parent process will be a special kind of user */
	     /* Allocate space for the new user. Since the process
	      * should be empty on users and no one is to be added, 
	      * we use non_human_user_list.  */

	     /* Allocate space for the new user */
	     if((non_human_user_list = malloc(sizeof(struct user_t))) == NULL)
	       {		  
		  logprintf(1, "Error - In parl_init()/malloc(): ");
		  logerror(1, errno);
		  quit = 1;
		  free(script_list[i]);
		  exit(EXIT_FAILURE);
	       }	     	     
	          	
	     non_human_user_list->sock = sock;	
	     non_human_user_list->rem = 0;	
	     non_human_user_list->type = SCRIPT;
	     non_human_user_list->buf = NULL;
	     non_human_user_list->outbuf = NULL;
	     non_human_user_list->next = NULL;
	     non_human_user_list->email = NULL;
	     non_human_user_list->desc = NULL;
	     memset(non_human_user_list->nick, 0, MAX_NICK_LEN+1);
	     sprintf(non_human_user_list->nick, "parent process");
	     sprintf(non_human_user_list->hostname, "parent_process");
	     send_to_user("$NewScript|", non_human_user_list);
	     
	     /* Remove all users.  */	    
	     remove_all(~SCRIPT, 0, 0);
	     
	     /* Initialize the perl interpreter for this process */
	     if((my_perl = perl_alloc()) == NULL) 
	       {	
		  logprintf(1, "perl_alloc() failed\n");
		  free(script_list[i]);
		  exit(EXIT_FAILURE);
	       }
	     
	     perl_construct(my_perl);
	     if(perl_parse(my_perl, xs_init, 2, myargv, NULL))
	       {
		  logprintf(1, "Parse of %s failed.\n", script_list[i]);
		  free(script_list[i]);
		  exit(EXIT_FAILURE);
	       }
	     
	     if(perl_run(my_perl))
	       {
		  logprintf(1, "Couldn't run perl script %s.\n", script_list[i]);
		  free(script_list[i]);
		  exit(EXIT_FAILURE);
	       }
	     
	     /* Run the scripts main sub if it exists.  */
	       {		  
		  dSP;
		  ENTER;
		  SAVETMPS;
		  PUSHMARK(SP);
		  PUTBACK;
		  call_pv("main", G_DISCARD|G_EVAL);
		  SPAGAIN;
		  PUTBACK;
		  FREETMPS;
		  LEAVE;   
	       }

	     free(script_list[i]);
	     
	     /* Get info of all users.  */
	     if(i == 0)
	       {				  		
		  sem_take(user_list_sem);
		  
		  /* Attach to the shared segment */
		  if((buf = (char *)shmat(get_user_list_shm_id(), NULL, 0))
		     == (char *)-1)
		    {		       
		       logprintf(1, "Error - In perl_init()/shmat(): ");
		       logerror(1, errno);
		       sem_give(user_list_sem);
		       quit = 1;
		       return -1;
		    }
		  
		  if(sscanf(buf, "%d %d", &spaces, &entries) != 2)
		    {		       
		       logprintf(1, "Error - In perl_init(): Couldn't get number of entries\n");
		       shmdt(buf);
		       sem_give(user_list_sem);
		       quit = 1;
		       return -1;
		    }		  		  
		  
		  bufp = buf + 30;
		  
		  for(l = 1; l <= spaces; l++)
		    {		       
		       if(*bufp != '\0')
			 {			    
			    sscanf(bufp, "%50s %120s", temp_nick, temp_host);
			    uprintf(non_human_user_list, 
				    "$GetINFO %s $Script|", temp_nick);
			 }		       
		       
		       bufp += USER_LIST_ENT_SIZE;
		    }
		  shmdt(buf);
		  sem_give(user_list_sem);		 
	       }	     
	     return 1;
	  }
	free(script_list[i]);
     }
   return 1;
}
예제 #6
0
void 
check_syntax_source( const char *source_dir, SyntaxDef *syntax, Bool module )
{
	int i ;
	char *syntax_dir = NULL ;
	char *obsolete_dir ;
	struct direntry  **list = NULL;
	int list_len ;

	if( syntax )
	{	
		if( get_hash_item( ProcessedSyntaxes, AS_HASHABLE(syntax), NULL ) == ASH_Success )
			return ;

		if( syntax->doc_path != NULL && syntax->doc_path[0] != '\0' )
			syntax_dir = make_file_name (source_dir, syntax->doc_path); 
	}
	if( syntax_dir == NULL ) 
		syntax_dir = mystrdup( source_dir );
	
	obsolete_dir = make_file_name (syntax_dir, "obsolete" );
	
	if( CheckDir(syntax_dir) != 0 )
		if( !make_doc_dir( syntax_dir ) ) 
		{
			free( syntax_dir );
			return;
		}

	if( syntax ) 
	{	
		add_hash_item( ProcessedSyntaxes, AS_HASHABLE(syntax), NULL );   

		/* pass one: lets see which of the existing files have no related options : */
		list_len = my_scandir ((char*)syntax_dir, &list, ignore_dots, NULL);
		for (i = 0; i < list_len; i++)
		{	
			int k ;
			if (!S_ISDIR (list[i]->d_mode))
			{	
				char *name = list[i]->d_name ;
				show_progress( "checking \"%s\" ... ", name );
				if( name[0] != '_' ) 
				{	
					for (k = 0; syntax->terms[k].keyword; k++)
						if( mystrcasecmp(name, syntax->terms[k].keyword ) == 0 ) 
							break;
					if( syntax->terms[k].keyword == NULL || get_flags( syntax->terms[k].flags, TF_OBSOLETE) ) 
					{
						/* obsolete option - move it away */
						char *obsolete_fname = make_file_name (obsolete_dir, name );
						char *fname = make_file_name (syntax_dir, name );
						Bool no_dir = False ;
						if( CheckDir(obsolete_dir) != 0 )
							no_dir = !make_doc_dir( obsolete_dir ) ;
						if( !no_dir )
						{
							copy_file (fname, obsolete_fname);
							show_progress( "Option \"%s\" is obsolete - moving away!", name );
							unlink(fname);
						}
						free( fname );
						free( obsolete_fname ); 
					}	 
				}
			}		
			free( list[i] );
		}
		if( list )
			free (list);
		/* pass two: lets see which options are missing : */
		for (i = 0; syntax->terms[i].keyword; i++)
		{	
			if( !get_flags( syntax->terms[i].flags, TF_OBSOLETE) )
			{	
				SyntaxDef *sub_syntax = syntax->terms[i].sub_syntax ; 
				if( sub_syntax == pPopupFuncSyntax ) 
					sub_syntax = pFuncSyntax ;
				if (sub_syntax)
					check_syntax_source( source_dir, sub_syntax, False );
				if( isalnum( syntax->terms[i].keyword[0] ) )					
					check_option_source( syntax_dir, syntax->terms[i].keyword, sub_syntax, module?syntax->doc_path:NULL ) ;
			}
		}
		for (i = module?0:1; StandardSourceEntries[i] != NULL ; ++i)
			check_option_source( syntax_dir, StandardSourceEntries[i], NULL, module?syntax->doc_path:NULL ) ;
		if( module ) 
		{
			check_option_source( syntax_dir, BaseOptionsEntry, NULL, syntax->doc_path ) ;
			check_option_source( syntax_dir, MyStylesOptionsEntry, NULL, syntax->doc_path ) ;
		}	 
	}else
		generate_main_source( syntax_dir );

	free( obsolete_dir );
	free( syntax_dir );
}