Beispiel #1
0
/* xsort - built-in function 'sort' */
LVAL xsort(void)
{
    LVAL sortlist();
    LVAL list,fcn;

    /* protect some pointers */
    xlstkcheck(2);
    xlsave(list);
    xlsave(fcn);

    /* get the list to sort and the comparison function */
    list = xlgalist();
    fcn = xlgetarg();
    xllastarg();

    /* sort the list */
    list = sortlist(list,fcn);

    if (list && (ntype(list) == FREE_NODE)) {
        stdputstr("error in sort 2");
    }

    /* restore the stack and return the sorted list */
    xlpopn(2);
    return (list);
}
Beispiel #2
0
/* sortlist - sort a list using quicksort */
LOCAL LVAL sortlist(LVAL list, LVAL fcn)
{
    LVAL gluelists();
    LVAL smaller,pivot,larger;
    
    /* protect some pointers */
    xlstkcheck(3);
    xlsave(smaller);
    xlsave(pivot);
    xlsave(larger);
    
    /* lists with zero or one element are already sorted */
    if (consp(list) && consp(cdr(list))) {
        pivot = list; list = cdr(list);
        splitlist(pivot,list,&smaller,&larger,fcn);
        smaller = sortlist(smaller,fcn);
        larger = sortlist(larger,fcn);
        list = gluelists(smaller,pivot,larger);
    }

    /* cleanup the stack and return the sorted list */
    xlpopn(3);
    return (list);
}
Beispiel #3
0
/* glob0 -- glob a list, (destructively) passing through entries we don't care about */
static List *glob0(List *list, StrList *quote) {
	List *result, **prevp, *expand1;
	
	for (result = NULL, prevp = &result; list != NULL; list = list->next, quote = quote->next) {
		char *str;
		if (
			quote->str == QUOTED
			|| !haswild(str = getstr(list->term), quote->str)
			|| (expand1 = glob1(str, quote->str)) == NULL
		) {
			*prevp = list;
			prevp = &list->next;
		} else {
			*prevp = sortlist(expand1);
			while (*prevp != NULL)
				prevp = &(*prevp)->next;
		}
	}
	return result;
}
Beispiel #4
0
t_ls	*sorta(t_ls *a, int *state)
{
	if (state[F] == 1)
		return (reverselist(a));
	else if (state[T] == 0 && state[R] == 0)
		sortlist(&a, classalpha);
	else if (state[T] == 0 && state[R] == 1)
		sortlist(&a, classalpharev);
	else if (state[T] == 1 && state[R] == 0 && state[U] == 1)
		sortlist(&a, classtimeaccess);
	else if (state[T] == 1 && state[R] == 1 && state[U] == 1)
		sortlist(&a, classtimeaccessr);
	else if (state[T] == 1 && state[R] == 0)
		sortlist(&a, classtime);
	else if (state[T] == 1 && state[R] == 1)
		sortlist(&a, classtimerev);
	return (a);
}
Beispiel #5
0
/* listvars -- return a list of all the (dynamic) variables */
extern List *listvars(Boolean internal) {
	Ref(List *, varlist, NULL);
	dictforall(vars, internal ? listinternal : listexternal, &varlist);
	varlist = sortlist(varlist);
	RefReturn(varlist);
}
Beispiel #6
0
int main()
{
    
    f1.open("/Users/robinmalhotra2/Desktop/csl201check.txt",std::ios::in|std::ios::out);
    
    f1.getline(s, 80, ' ');
        while (f1.good())
    {

        
        
        
       
        std::cout<<"addasd";
        if ((strlen(s)==1) && (s[0])<'9' && (s[0])>'0')
            
        {
            switch ((s[0]))
            {
                    
                case '1':
                    createandprintlist();
                    
                
                    break;
                    
                case '2':
                    sortlist();
                    break;
                    
                case '3':
                    nextinsert();
                    break;
                    
                case '4':
                    searchlist();
                    break;
                    
                case '5':
                    deletenext();
                    break;
                    
                case '6':
                    deduplicate();
                    break;
                    
                case '7':
                    mergesortthing();
                    break;
                    
                case '8':
                    credits();
                    break;
                    
                    
                    
                default:
                    break;
            }
        }
        
        
    }
    f1.close();
    
    
    
}
Beispiel #7
0
int main(int argc, char **argv)
{
   char *var;
   struct fileentry *fe;

   if(!osInit())
      exit(OS_EXIT_ERROR);

   if(argc > 1 &&
	  (strcmp(argv[1],"?")==0      ||
		strcmp(argv[1],"-h")==0     ||
		strcmp(argv[1],"--help")==0 ||
		strcmp(argv[1],"help")==0 ||
		strcmp(argv[1],"/h")==0     ||
		strcmp(argv[1],"/?")==0 ))
   {
      printargs(args);
      osEnd();
      exit(OS_EXIT_OK);
   }

   if(!parseargs(args,argc,argv))
   {
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   jbNewList(&list);

   /* get outbound dir */

   if((var=getenv("CMOUTBOUND")))
      cfg_Dir=var;

   else
      cfg_Dir=OS_CURRENT_DIR;

   if(args[ARG_DIRECTORY].data)
      cfg_Dir=(char *)args[ARG_DIRECTORY].data;

   /* Get zone */

   if((var=getenv("CMOUTBOUNDZONE")))
      cfg_Zone=atoi(var);

   else
      cfg_Zone=2;

   if(args[ARG_ZONE].data)
      cfg_Zone=atoi((char *)args[ARG_ZONE].data);

   /* Get pattern */

   strcpy(cfg_Pattern.Zone,"*");
   strcpy(cfg_Pattern.Net,"*");
   strcpy(cfg_Pattern.Node,"*");
   strcpy(cfg_Pattern.Point,"*");

   if(args[ARG_PATTERN].data)
   {
      if(!Parse4DPat((char *)args[ARG_PATTERN].data,&cfg_Pattern))
      {
         printf("Invalid node pattern \"%s\"\n",(char *)args[ARG_PATTERN].data);
         osEnd();
         exit(OS_EXIT_ERROR);
      }
   }

   /* Get verbose flag */

   cfg_Verbose=FALSE;

   if(args[ARG_VERBOSE].data)
      cfg_Verbose=TRUE;

   /* Real program starts here */

   printf("CrashListOut " VERSION "\n\n");

   scandir_dir = NULL;
   scandir_boss = NULL;

   if(!osScanDir(cfg_Dir,scandirfunc))
   {
		uint32_t err=osError();
      printf("Failed to scan directory %s\n",cfg_Dir);
		printf("Error: %s",osErrorMsg(err));		
      return(FALSE);
   }

   sortlist(&list);

   printf("%-8.8s %-17.17s %-16.16s %7.7s   %s\n\n",
      "Type","Node","Last Change","B/F","File");

   if(list.First)
   {
      for(fe=(struct fileentry *)list.First;fe;fe=fe->Next)
      {
         if(fe->type == TYPE_REQUEST) DisplayReq(fe);
         else if(fe->flow)            DisplayFlow(fe);
         else                         DisplayPkt(fe);
      }

      if(!cfg_Verbose) printf("\n");
      printf("Totally %s bytes in %u files to send, %u requests.\n",unit(TotalBytes),TotalFiles,TotalRequests);
   }
   else
   {
      printf("Outbound directory is empty.\n");
   }

   jbFreeList(&list);

   exit(OS_EXIT_OK);
}
Beispiel #8
0
Datei: ignore.c Projekt: aosm/cvs
/*
 * Process the current directory, looking for files not in ILIST and
 * not on the global ignore list for this directory.  If we find one,
 * call PROC passing it the name of the file and the update dir.
 * ENTRIES is the entries list, which is used to identify known
 * directories.  ENTRIES may be NULL, in which case we assume that any
 * directory with a CVS administration directory is known.
 */
void
ignore_files (List *ilist, List *entries, const char *update_dir,
              Ignore_proc proc)
{
    int subdirs;
    DIR *dirp;
    struct dirent *dp;
    struct stat sb;
    char *file;
    const char *xdir;
    List *files;
    Node *p;

    /* Set SUBDIRS if we have subdirectory information in ENTRIES.  */
    if (entries == NULL)
	subdirs = 0;
    else
    {
	struct stickydirtag *sdtp = entries->list->data;

	subdirs = sdtp == NULL || sdtp->subdirs;
    }

    /* we get called with update_dir set to "." sometimes... strip it */
    if (strcmp (update_dir, ".") == 0)
	xdir = "";
    else
	xdir = update_dir;

    dirp = CVS_OPENDIR (".");
    if (dirp == NULL)
    {
	error (0, errno, "cannot open current directory");
	return;
    }

    ign_add_file (CVSDOTIGNORE, 1);
    wrap_add_file (CVSDOTWRAPPER, 1);

    /* Make a list for the files.  */
    files = getlist ();

    while (errno = 0, (dp = CVS_READDIR (dirp)) != NULL)
    {
	file = dp->d_name;
	if (strcmp (file, ".") == 0 || strcmp (file, "..") == 0)
	    continue;
	if (findnode_fn (ilist, file) != NULL)
	    continue;
	if (subdirs)
	{
	    Node *node;

	    node = findnode_fn (entries, file);
	    if (node != NULL
		&& ((Entnode *) node->data)->type == ENT_SUBDIR)
	    {
		char *p;
		int dir;

		/* For consistency with past behaviour, we only ignore
		   this directory if there is a CVS subdirectory.
		   This will normally be the case, but the user may
		   have messed up the working directory somehow.  */
		p = Xasprintf ("%s/%s", file, CVSADM);
		dir = isdir (p);
		free (p);
		if (dir)
		    continue;
	    }
	}

	/* We could be ignoring FIFOs and other files which are neither
	   regular files nor directories here.  */
	if (ign_name (file))
	    continue;

	if (
#ifdef DT_DIR
	    dp->d_type != DT_UNKNOWN ||
#endif
	    lstat (file, &sb) != -1)
	{

	    if (
#ifdef DT_DIR
		dp->d_type == DT_DIR
		|| (dp->d_type == DT_UNKNOWN && S_ISDIR (sb.st_mode))
#else
		S_ISDIR (sb.st_mode)
#endif
		)
	    {
		if (!subdirs)
		{
		    char *temp = Xasprintf ("%s/%s", file, CVSADM);
		    if (isdir (temp))
		    {
			free (temp);
			continue;
		    }
		    free (temp);
		}
	    }
#ifdef S_ISLNK
	    else if (
#ifdef DT_DIR
		     dp->d_type == DT_LNK
		     || (dp->d_type == DT_UNKNOWN && S_ISLNK (sb.st_mode))
#else
		     S_ISLNK (sb.st_mode)
#endif
		     )
	    {
		continue;
	    }
#endif
	}

	p = getnode ();
	p->type = FILES;
	p->key = xstrdup (file);
	(void) addnode (files, p);
    }
    if (errno != 0)
	error (0, errno, "error reading current directory");
    (void) CVS_CLOSEDIR (dirp);

    sortlist (files, fsortcmp);
    for (p = files->list->next; p != files->list; p = p->next)
	(*proc) (p->key, xdir);
    dellist (&files);
}
Beispiel #9
0
void choose_file_menu(char* sdpath) {
    static char* headers[] = { "Choose item or press POWER to return",
			       "",
			       NULL };
    
    char path[PATH_MAX] = "";
    DIR *dir;
    struct dirent *de;
    int total = 0;
	int ftotal = 0;
	int dtotal = 0;
	int i;
	int j;
    char** flist;
	char** dlist;
    char** list; 
    if (ensure_root_path_mounted("SDCARD:") != 0) {
	LOGE ("Can't mount /sdcard\n");
	return;
    }

    dir = opendir(sdpath);
    if (dir == NULL) {
		LOGE("Couldn't open directory");
		LOGE("Please make sure it exists!");
		return;
    }
    //count the number of valid files:
    while ((de=readdir(dir)) != NULL) {
		if (de->d_type == DT_DIR && strcmp(de->d_name,".") != 0 && strcmp(de->d_name,"nandroid") != 0) {
				dtotal++;
		} else {
			if (strcmp(de->d_name+strlen(de->d_name)-4,".zip")==0) {
				ftotal++;
			}
			if (strcmp(de->d_name+strlen(de->d_name)-4,".tar")==0) {
				ftotal++;
			}
			if (strcmp(de->d_name+strlen(de->d_name)-4,".tgz")==0) {
				ftotal++;
			}
			if (strcmp(de->d_name+strlen(de->d_name)-7,"rec.img")==0) {
				ftotal++;
			}
			if (strcmp(de->d_name+strlen(de->d_name)-8,"boot.img")==0) {
				ftotal++;
			}
		}
	}
	total = ftotal + dtotal;
    if (total==0) {
		ui_print("\nNo valid files found!\n");
    } else {
		flist = (char**) malloc((ftotal+1)*sizeof(char*));
		flist[ftotal]=NULL;

		dlist = (char**) malloc((dtotal+1)*sizeof(char*));
		dlist[dtotal]=NULL;

		list = (char**) malloc((total+1)*sizeof(char*));
		list[total]=NULL;
	
		rewinddir(dir);

		i = 0; //dir iterator
		j = 0; //file iterator
		while ((de = readdir(dir)) != NULL) {
			//create dirs list
			if (de->d_type == DT_DIR && strcmp(de->d_name,".") != 0 && strcmp(de->d_name,"nandroid") != 0) {
				dlist[i] = (char*) malloc(strlen(sdpath)+strlen(de->d_name)+1);
				strcpy(dlist[i], sdpath);
				strcat(dlist[i], de->d_name);
				dlist[i] = (char*) malloc(strlen(de->d_name)+2); //need one extra byte for the termnitaing char
				strcat(de->d_name, "/\0"); //add "/" followed by terminating character since these are dirs
				strcpy(dlist[i], de->d_name);				
					i++;				
			}
			//create files list
			if ((de->d_type == DT_REG && (strcmp(de->d_name+strlen(de->d_name)-4,".zip")==0 || strcmp(de->d_name+strlen(de->d_name)-4,".tar")==0 || strcmp(de->d_name+strlen(de->d_name)-4,".tgz")==0 || strcmp(de->d_name+strlen(de->d_name)-7,"rec.img")==0 || strcmp(de->d_name+strlen(de->d_name)-8,"boot.img")==0))) {			
				flist[j] = (char*) malloc(strlen(sdpath)+strlen(de->d_name)+1);
				strcpy(flist[j], sdpath);
				strcat(flist[j], de->d_name);
				flist[j] = (char*) malloc(strlen(de->d_name)+1);
				strcpy(flist[j], de->d_name);				
					j++;		
			}
		}
		
		

		if (closedir(dir) <0) {
			LOGE("Failure closing directory\n");
			return;
		}
		//sort lists
		sortlist(flist, ftotal);
		sortlist(dlist, dtotal);
		
		//join the file and dir list, with dirs on top - thanks cvpcs
		i = 0;
		j = 0;
		int k;
		for(k = 0; k < total; k++) {
			if(i < dtotal) {
				list[k] = strdup(dlist[i++]);
			} else {
				list[k] = strdup(flist[j++]);
			}
		}
		
		int chosen_item = -1;
		while (chosen_item < 0) {
			chosen_item = get_menu_selection(headers, list, 1, chosen_item<0?0:chosen_item);
			if (chosen_item >= 0 && chosen_item != ITEM_BACK ) {
			
				char install_string[PATH_MAX]; //create real path from selection
				strcpy(install_string, sdpath);
				strcat(install_string, list[chosen_item]);
				
				if (opendir(install_string) == NULL) { //handle selection
					preinstall_menu(install_string);
				} else {						
					choose_file_menu(install_string);					
				}
				if (ui_key_pressed(32)) { //D = 32
					remove(install_string);
					ui_print(install_string);
					ui_print(" removed.");
					choose_file_menu(sdpath);
				}
			}
		} 
	}
}
int CreateRecentItemMenu(char *pszFileName, char *pszCommand, char *pszTitle, char *pszIcon, int nKeep, int nSort, bool bBeginEnd){
	static ItemList *KeepItemList;
	static ItemList *SortItemList;
	char szFilePath[MAX_PATH];
	char buf[MAX_PATH];
	ItemList *iln = (ItemList*)m_alloc(sizeof(ItemList));

	// make path (compliant with relative-path)
	make_bb_path(szFilePath, pszFileName);

	// Newer Item
	if (pszIcon && *pszIcon)
		_snprintf(buf, MAX_PATH, "\t[exec] (%s) {%s} <%s>", pszTitle, pszCommand, pszIcon);
	else
		_snprintf(buf, MAX_PATH, "\t[exec] (%s) {%s}", pszTitle, pszCommand);
	_strcpy(iln->szItem, buf);
	iln->nFrequency = 1;
	append_node(&KeepItemList, iln);

	int cnt_k = 0; // keep items counter
	int cnt_s = 0; // sort items counter
	if (FILE *fp = fopen(szFilePath, "r")){ // read Recent-menu
		while(fgets(buf, MAX_PATH, fp)){
			if (strstr(buf, "[end]"))
				break;
			else if (strstr(buf, "[exec]")){
				if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
				char *p0 = strchr(buf, '{'); // command
				char *p1 = strchr(buf, '}'); // end of command
				if (p0 && p1){
					UINT nFrequency = 0;
					if (char *p = strrchr(buf, '#')){
						nFrequency = atoi(p+1);
						while(*(p--) == ' '); // delete space of eol
						*p = '\0';
					}
					if (0 != strnicmp(pszCommand, p0+1 , p1 - p0 - 1)){ // ignore duplicated item
						ItemList *il = (ItemList*)m_alloc(sizeof(ItemList));
						_strcpy(il->szItem, buf);
						il->nFrequency = imin(nFrequency, UINT_MAX);
						if (cnt_k++ < nKeep - 1)
							append_node(&KeepItemList, il);
						else if (cnt_s++ < nSort)
							append_node(&SortItemList, il);
						else
							m_free(il);
					}
					else{ // if duplicate, increment freq
						iln->nFrequency += imin(nFrequency, UINT_MAX - 1);
					}
				}
			}
		}
		fclose(fp);
	}

	bool isSortList = listlen(SortItemList) != 0;
	bool isKeepList = listlen(KeepItemList) != 0;

	if (isSortList)
		SortItemList = sortlist(SortItemList);

	if (FILE *fp = fopen(szFilePath, "w")){ // write Recent-menu
		if (bBeginEnd)
			fprintf(fp, "[begin] (Recent Item)\n");

		// most recent item
		ItemList *p;
		dolist (p, KeepItemList){
			fprintf(fp, "%s #%u\n", p->szItem, p->nFrequency);
		}
		if (isKeepList && isSortList)
			fprintf(fp, "\t[separator]\n");
		dolist (p, SortItemList){
			fprintf(fp, "%s #%u\n", p->szItem, p->nFrequency);
		}
Beispiel #11
0
List *Find_Names (const char *repository, int which, int aflag, List **optentries, const char *virtual_repository)
{
    List *entries;
    List *files;
	const char *regex = NULL;

	if(!current_parsed_root->isremote)
		regex = lookup_regex(virtual_repository);

    /* make a list for the files */
    files = filelist = getlist ();

    /* look at entries (if necessary) */
    if (which & W_LOCAL)
    {
		/* parse the entries file (if it exists) */
		entries = Entries_Open (aflag, NULL);
		if (entries != NULL)
		{
			/* walk the entries file adding elements to the files list */
			(void) walklist (entries, add_entries_proc, NULL);

			/* if our caller wanted the entries list, return it; else free it */
			if (optentries != NULL)
				*optentries = entries;
			else
				Entries_Close (entries);
		}
    }

    if ((which & W_REPOS) && repository && !isreadable (CVSADM_ENTSTAT))
    {
		/* search the repository */
		if (find_rcs (repository, files, regex) != 0)
		{
			error (0, errno, "cannot open directory %s", fn_root(repository));
			goto error_exit;
		}

		/* search the attic too */
		{
			char *dir;
			dir = (char*)xmalloc (strlen (repository) + sizeof (CVSATTIC) + 10);
			(void) sprintf (dir, "%s/%s", repository, CVSATTIC);
			if (find_rcs (dir, files, regex) != 0
			&& !existence_error (errno))
			/* For now keep this a fatal error, seems less useful
			for access control than the case above.  */
			error (1, errno, "cannot open directory %s", fn_root(dir));
			xfree (dir);
		}

		if(find_virtual_rcs (virtual_repository, files) != 0)
		{
			error(1, errno, "find_virtual_rcs failed");
		}

		if(find_rename_rcs(virtual_repository, files) != 0)
		{
			error(1,errno, "find_renames failed");
		}
    }

	xfree(regex);

    /* sort the list into alphabetical order and return it */
    sortlist (files, fsortcmp);
    return (files);
 error_exit:
	xfree(regex);
    dellist (&files);
    return NULL;
}
Beispiel #12
0
/*
 * create a list of directories to traverse from the current directory
 */
List *Find_Directories (char *repository, int which, List *entries, const char *virtual_repository)
{
    List *dirlist;

	const char *regex = NULL;

	if(!current_parsed_root->isremote && virtual_repository)
		regex = lookup_regex(virtual_repository);

	/* make a list for the directories */
    dirlist = getlist ();

    /* find the local ones */
    if (which & W_LOCAL)
    {
	List *tmpentries;
	struct stickydirtag *sdtp;

	/* Look through the Entries file.  */

	if (entries != NULL)
	    tmpentries = entries;
	else if (isfile (CVSADM_ENT))
	    tmpentries = Entries_Open (0, NULL);
	else
	    tmpentries = NULL;

	if (tmpentries != NULL)
	    sdtp = (struct stickydirtag *) tmpentries->list->data;

	/* If we do have an entries list, then if sdtp is NULL, or if
           sdtp->subdirs is nonzero, all subdirectory information is
           recorded in the entries list.  */
	if (tmpentries != NULL && (sdtp == NULL || sdtp->subdirs))
	    walklist (tmpentries, add_subdir_proc, (void *) dirlist);
	else // FIXME: Should this not look for subdirectories anyway????
	{
	    /* This is an old working directory, in which subdirectory
               information is not recorded in the Entries file.  Find
               the subdirectories the hard way, and, if possible, add
               it to the Entries file for next time.  */

	    /* FIXME-maybe: find_dirs is bogus for this usage because
	       it skips CVSATTIC and CVSLCK directories--those names
	       should be special only in the repository.  However, in
	       the interests of not perturbing this code, we probably
	       should leave well enough alone unless we want to write
	       a sanity.sh test case (which would operate by manually
	       hacking on the CVS/Entries file).  */

	    if (find_dirs (".", dirlist, 1, tmpentries, regex) != 0)
		error (1, errno, "cannot open current directory");
	    if (tmpentries != NULL)
	    {
		if (! list_isempty (dirlist))
		    walklist (dirlist, register_subdir_proc,
			      (void *) tmpentries);
		else
		    Subdirs_Known (tmpentries);
	    }
	}

	if (entries == NULL && tmpentries != NULL)
	    Entries_Close (tmpentries);
    }
    /* look for sub-dirs in the repository */
    if ((which & W_REPOS) && repository)
    {
		/* search the repository */
		if (find_dirs (repository, dirlist, 0, entries, regex) != 0)
		{
			error (1, errno, "cannot open directory %s", fn_root(repository));
		}

		/* look for virtual directories */
		if (find_virtual_dirs (virtual_repository, dirlist) != 0)
		{
			error (1, errno, "cannot open virtual directory %s", repository);
		}
		if(find_rename_dirs(virtual_repository, dirlist) != 0)
		{
			error(1,errno, "find_renames failed");
		}
    }

	xfree(regex);
    /* sort the list into alphabetical order and return it */
    sortlist (dirlist, fsortcmp);
    return (dirlist);
}