Example #1
0
/* assume A or B is a t_LIST */
static GEN
listconcat(GEN A, GEN B)
{
  long i, l1, lx;
  GEN L, z, L1, L2;

  if (typ(A) != t_LIST) {
    if (list_typ(B)!=t_LIST_RAW) pari_err_TYPE("listconcat",B);
    L2 = list_data(B);
    if (!L2) return mklistcopy(A);
    lx = lg(L2) + 1;
    z = listcreate();
    list_data(z) = L = cgetg(lx, t_VEC);
    for (i = 2; i < lx; i++) gel(L,i) = gcopy(gel(L2,i-1));
    gel(L,1) = gcopy(A); return z;
  } else if (typ(B) != t_LIST) {
    if (list_typ(A)!=t_LIST_RAW) pari_err_TYPE("listconcat",A);
    L1 = list_data(A);
    if (!L1) return mklistcopy(B);
    lx = lg(L1) + 1;
    z = listcreate();
    list_data(z) = L = cgetg(lx, t_VEC);
    for (i = 1; i < lx-1; i++) gel(L,i) = gcopy(gel(L1,i));
    gel(L,i) = gcopy(B); return z;
  }
  /* A, B both t_LISTs */
  if (list_typ(A)!=t_LIST_RAW) pari_err_TYPE("listconcat",A);
  if (list_typ(B)!=t_LIST_RAW) pari_err_TYPE("listconcat",B);
  L1 = list_data(A); if (!L1) return listcopy(B);
  L2 = list_data(B); if (!L2) return listcopy(A);

  l1 = lg(L1);
  lx = l1-1 + lg(L2);
  z = cgetg(3, t_LIST);
  z[1] = 0UL;
  list_data(z) = L = cgetg(lx, t_VEC);
  L2 -= l1-1;
  for (i=1; i<l1; i++) gel(L,i) = gclone(gel(L1,i));
  for (   ; i<lx; i++) gel(L,i) = gclone(gel(L2,i));
  return z;
}
Example #2
0
int main (){


    char string[MAX]; /// variavel que sera utilizada para ler a frase
    unsigned i, j, k,m, size; // variaveis para loops e size para pegar o tamanha do string corretamente.
    LIST* l = listcreate(); // inciia uma nova lista

    // lendo o texto ate o fim do arquivo 
    while (scanf("%s", string) != EOF){
    
            size    = (unsigned int) strlen(string); // seta o tamanho da string 
            m = 0; // se houver mais de um '['
            j = 0; // end = 0 home = 1
            k = 0; // contador de posições de uma palavra dentro de um [exemplo]
            for (i = 0; i < size; i++){
                if (string[i] == '[') {
                        j = 1;
                        k = 0;
                }
                if (string[i] == ']') j = 0;
                if (string[i] == '[' && qtlist(l) == 0) j = 0;                

                if (string[i] != '[' && string[i] != ']'){
                    if (j == 1 && qtlist(l) != 0){ 
                       if (k == 0) insertinit(l, string[i]);
                       else insertmeans(l, k, string[i]);
                       k++;
                    }else{
                        // j = 0 logo "end"
                          
                            insertfinal(l, string[i]);
                        
                        
                    }
                }
            }
    
            printlist(l);
            printf("\n");
            clearlist(l);
    }


    
    freelist(l);

    return 0;
}
Example #3
0
int main (int argc, char const * argv [])

{
	extern const unsigned char ct_unescape [];
	static char const * optv [] =
	{
		"print user/group names in alphabetcial order in columns",
		PUTOPTV_S_DIVINE,
		"c:e:gHnw:uRT",
		"c n\tcolumn count is (n) [" LITERAL (COUNT) "]",
		"w n\tscreen width is (n) [" LITERAL (WIDTH) "]",
		"e s\texpression is s [.+]",
		"g\tlist groupnames",
		"H\tregular expression help",
		"u\tlist usernames",
		"n\tnumber list items",
		"R\tregular expression help",
		"T\tescape sequence rules",
		(char *) (0)
	};
	LIST list;
	regexp * regex = (regexp *) (0);
	char const * expression = ".+";
	flag_t flags = (flag_t) (0);
	size_t count = COUNT;
	size_t width = WIDTH;
	bool index = false;
	int c;
	while (~ (c = getoptv (argc, argv, optv)))
	{
		switch (c)
		{
		case 'w':
			width = uintspec (optarg, 1, 132);
			break;
		case 'c':
			count = uintspec (optarg, 1, 16);
			break;
		case 'g':
			_setbits (flags, WHOM_B_GRP);
			break;
		case 'e':
			expression = optarg;
			break;
		case 'n':
			index = true;
			break;
		case 'u':
			_setbits (flags, WHOM_B_USR);
			break;
		case 'H':
			_setbits (flags, WHOM_B_SHW);
			break;
		case 'R':
			regexhelp ();
			exit (0);
		case 'T':
			chruescmap (ct_unescape, REGEX_C_ESC);
			exit (0);
		default: 
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if (_anyset (flags, (WHOM_B_SHW)))
	{
		regex = regexmake (expression);
		regexshow (regex);
		return (0);
	}
	if (_allclr (flags, (WHOM_B_USR | WHOM_B_GRP)))
	{
		_setbits (flags, (WHOM_B_USR | WHOM_B_GRP));
	}
	setpwent ();
	listcreate (& list, _LISTSIZE);
	regex = regexmake (expression);
	function (& list, regex, flags);
	regex = regexfree (regex);
	listcolumn (& list, stdout, width, count, index);
	listdelete (& list);
	endpwent ();
	exit (0);
}
Example #4
0
void function (char const * path, char * file, size_t width, size_t count, bool index, flag_t flags)

{
	DIR * dir;
	LIST list;
	listcreate (& list, _LISTSIZE);
	printf ("%s\n", path);
	if ((dir = opendir (path)))
	{
		struct dirent * dirent;
		struct stat statinfo;
		while (* file)
		{
			file++;
		}
		* file++ = PATH_C_EXTENDER;
		while ((dirent = readdir (dir)))
		{
			char const * sp = dirent->d_name;
			if (* sp == FILE_C_EXTENDER)
			{
				sp++;
			}
			if (* sp == FILE_C_EXTENDER)
			{
				sp++;
			}
			if (* sp == (char) (0))
			{
				continue;
			}
			strcpy (file, dirent->d_name);
			if (lstat (path, & statinfo))
			{
				error (0, errno, "%s", path);
				continue;
			}
			if (S_ISDIR (statinfo.st_mode))
			{
				if (flags & (FIND_B_DIR))
				{
					listinsert (& list, file);
				}
				continue;
			}
			if (S_ISLNK (statinfo.st_mode))
			{
				if (flags & (FIND_B_LNK))
				{
					listinsert (& list, file);
				}
				continue;
			}
			if (S_ISREG (statinfo.st_mode))
			{
				if (flags & (FIND_B_REG))
				{
					listinsert (& list, file);
				}
				continue;
			}
		}
		* -- file = (char) (0);
		closedir (dir);
	}
	listcolumn (& list, stderr, width, count, index);
	listdelete (& list);
	return;
}
Example #5
0
int main (int argc, char * argv [])

{
    LIST files;
    char filename [FILENAME_MAX];
    char const * paths [_LISTSIZE] =
    {
        getenv ("PWD"),
        (char const *) (0)
    };
    size_t path = 1;

#if CTAR_SEARCH

    /*
     * search argv for additional -Ipath and -I path argments, similar to
     * gcc compiler options; since we are not using getoptv() to parse the
     * command line, we scan argv[] and strip out these extra arguments;
     */

    int argn;
    int argx;
    for (argn = 1; argn < argc; argn++)
    {
        char const * sp = argv [argn];
        if (* sp++ != GETOPTV_C_OPTION)
        {
            continue;
        }
        if (* sp++ != 'I')
        {
            continue;
        }
        if (* sp == (char) (0))
        {
            for (argx = argn; argx < argc; argx++)
            {
                argv [argx] = argv [argx +  1];
            }
            sp = argv [argn];
            argc--;
        }
        paths [path++] = sp;
        for (argx = argn; argx < argc; argx++)
        {
            argv [argx] = argv [argx +  1];
        }
        argn--;
        argc--;
    }
    paths [path] = (char const *) (0);
    argv [argc] = (char *) (0);

#endif

    if (argc < 4)
    {
        printf ("%s [tar-options] archive program [-I path] [-I path] [...]\n", * argv);
        exit (1);
    }
    makepath (filename, getenv ("PWD"), argv [-- argc]);
    listcreate (& files, _LISTSIZE);
    listappend (& files, filename);
    if (ccollect (& files, paths))
    {
        error (1, 0, "%s: missing %d file(s)", files.table [0], files.error);
    }
    if ((args = (char **) (malloc ((argc +  files.count +  1) * sizeof (char *)))))
    {
        error (1, 0, "%s: out of memory", basename ((char *) (* argv)));
    }
    args [0] = PATH_TAR;
    for (argc = 1; argv [argc]; argc++)
    {
        args [argc] = argv [argc];
    }
    for (files.lower = files.start; files.lower < files.count; files.lower++)
    {
        args [argc++] = (char *) (files.table [files.lower]);
    }
    args [argc] = (char *) (0);
    execv (* args, args);
    error (1, errno, "can't execute %s", * args);
    exit (0);
}