示例#1
0
void symmetry_group_walker::show (int verbose) const {
        myprintf ("symmetry_group_walker: ");
        if (verbose >= 2)
                myprintf ("\n");
        for (size_t i = 0; i < (size_t)perms.size (); i++) {
                if (verbose >= 2) {
                        myprintf ("  block %ld: ", i);
                        print_perm (perms[i]);
                } else {
                        print_perm (perms[i], 100, false);
                        myprintf (" ");
                }
        }
        if (verbose == 1)
                myprintf ("\n");
}
示例#2
0
文件: main.c 项目: bernied/mutti
/*
 * Assumes the string is in a comma delimted format and has been "validated".
 */
void
str_to_permutation(char* str, uint32* permutation, bool print)
{
  char* p =str;
  char c = *p++;
  int i=1;
  uint32 v =0;

  while (c != '\0')
  {
    if (print) print_perm(stdout, permutation);
    if (c == ',')
    {
      check_permutation(permutation, i, v);
      permutation[i] = v;
      i++;
      v = 0;
    }
    else
    {
      v *= 10;
      v += c - '0';
    }

    c = *p++;
  }
  check_permutation(permutation, i, v);
  permutation[i] = v;
  if (print) print_perm(stdout, permutation);

  uint32* inv_perm = alloc_permutation(permutation[0], false);
  for (i=1; i <= permutation[0]; i++)
  {
    if (permutation[i] == 0) {
      error("Invalid permutation: one of the values has not been assigned.");
    }
    if (inv_perm[permutation[i]] != 0) {
      error("Invalid permutation: one of the values is repeating.");
    }
    inv_perm[permutation[i]] = i;
  }

  free(inv_perm);
}
示例#3
0
文件: stat.c 项目: zyxstar/exam_c
/* ./a.out path */
int main(int argc, char **argv)
{
	struct stat st;
	int ret;

	if (argc != 2) {
		fprintf(stderr, "argment...\n");
		return 1;
	}

	ret = stat(argv[1], &st);
	if (ret == -1) {
		perror(argv[1]);
		return 1;
	}

	printf("ino: %d\n", st.st_ino);

	//printf("mode: %x\n", st.st_mode);
	printf("mode: ");
	switch (st.st_mode & S_IFMT) {
	case S_IFSOCK:
		printf("s");
		break;
	case S_IFLNK:
		printf("l");
		break;
	case S_IFREG:
		printf("-");
		break;
	case S_IFBLK:
		printf("b");
		break;
	case S_IFDIR:
		printf("d");
		break;
	case S_IFCHR:
		printf("c");
		break;
	case S_IFIFO:
		printf("p");
		break;
	}
	print_perm(st.st_mode);
	printf("\n");

	printf("nlink: %d\n", st.st_nlink);
	printf("uid: %d, gid: %d\n", st.st_uid, st.st_gid);
	printf("rdev: %d\n", st.st_rdev);
	printf("size: %d\n", st.st_size);
	printf("atime: %d\n", st.st_atime);
	printf("mtime: %d\n", st.st_mtime);
	printf("ctime: %d\n", st.st_ctime);

	return 0;
}
示例#4
0
文件: main.c 项目: bernied/mutti
void
check_permutation(uint32* permutation, int i, uint32 v)
{
  if (permutation[i] != 0) {
    error("Invalid permutation: value has already been assigned.");
  }
  if (v > permutation[0]) {
    print_perm(stdout, permutation);
    error("Invalid permutation: value is larger then given permtuation size.");
  }
  if (v <= 0) {
    error("Invalid permutation: value is negative.");
  }
}
示例#5
0
文件: print_mode.c 项目: k6s/tek1
void			print_perms(mode_t *st_mode)
{
    print_perm(S_IRUSR & *st_mode, 'r');
    print_perm(S_IWUSR & *st_mode, 'w');
    if (S_ISUID & *st_mode)
        my_putchar('s');
    else
        print_perm(S_IXUSR & *st_mode, 'x');
    print_perm(S_IRGRP & *st_mode, 'r');
    print_perm(S_IWGRP & *st_mode, 'w');
    if (S_ISGID & *st_mode)
        my_putchar('s');
    else
        print_perm(S_IXGRP & *st_mode, 'x');
    print_perm(S_IROTH & *st_mode, 'r');
    print_perm(S_IWOTH & *st_mode, 'w');
    if (__S_ISVTX & *st_mode)
        my_putchar('t');
    else
        print_perm(S_IXOTH & *st_mode, 'x');
}
示例#6
0
文件: main.c 项目: bernied/mutti
void
graph_to_dot(uint32* graph, uint32* permutation, char* name, bool skat, bool hi)
{
  char file_name[100];
  uint32 size = permutation[0];

  sprintf(file_name, "%s.dot", name);
  FILE* fp = fopen(file_name, "w+");
  if (fp == NULL) {
    error("Unable to open file.\n");
  }

  fprintf(fp, "graph %s {\n", name);
  fprintf(fp, "  labelloc=\"t\";\n");
  fprintf(fp, "  label=\"");
  print_perm(fp, permutation);
  fprintf(fp, "\";");

  if (skat)
  {
    char* cards = hi ? CARDS_A_HI_8 : CARDS_A_LO_8;
    for (int i=0; i < size; i++)
    {
      if (cards[i] == '0') {
        fprintf(fp, "  %d [ label=\"10\" ];\n", i+1);
      }
      else {
        fprintf(fp, "  %d [ label=\"%c\" ];\n", i+1, cards[i]);
      }
    }
  }
  fprintf(fp, "\n\n");

  for (int i=0; i < size; i++)
  {
    for (int j=i; j < size; j++)
    {
      if (i != j && graph[LT(i, j)] != 0) {
        fprintf(fp, "  %d -- %d;\n", i+1, j+1);
      }
    }
  }
  fprintf(fp, "}\n");

  fclose(fp);
}
示例#7
0
文件: q5.c 项目: k4rtik/CSU230
int next_perm() {
	int k, j, r, s;

	k = n - 1;
	while (permutation[k] >= permutation[k+1]) k--;
	if (k == 0) return 0;
	else {
		j = n;
		while (permutation[k] >= permutation[j]) j--;
		swap(j, k);
		r = n; s = k+1;
		while (r > s) {
			swap(r, s);
			r--; s++;
		}
	}
	print_perm();
	return 1;
}
示例#8
0
文件: q5.c 项目: k4rtik/CSU230
int main ()
{
	int i=0;

	printf("Enter n: ");
	scanf("%d", &n);

	if  (n <= 0) return 1;

	printf("Enter the string: ");
	while (i <= n) permutation[i++] = getchar();

	printf("\n");
	sort(); //Sorting required for implementing lexicographic ordering method.
	print_perm();
	
	while(next_perm());
	printf("\n");
	return 0;
}
示例#9
0
void print_mapping(const void *vaStart, const void *vaEnd)
{
	pte_t *va_pte;
	physaddr_t pte_perm, pte;
	const void *vaddr = vaStart;
	while((char *)vaddr <= (char *)vaEnd)
	{
		va_pte = pgdir_walk( kern_pgdir, vaddr, 0);
		if(va_pte==NULL)
		{
			cprintf("\nNo Mapping for virtual address:%p",vaddr);
			vaddr = ((char *)PTE_ADDR(vaddr) + PGSIZE);
			continue;
		}
		pte = *va_pte;
		pte_perm = PGOFF(pte);
		pte = PTE_ADDR(pte);
		cprintf("\nvirtual address: %p Physical Page Address: %p Page Permission:%d ->",vaddr, pte, pte_perm);
		print_perm(pte_perm);
		vaddr = ((char *)PTE_ADDR(vaddr) + PGSIZE);	
	}
	cprintf("\n");
}
示例#10
0
static void interpret(char *name, char *val, int comma, int rtype)
{
	int type;

	while (*name == ' '||*name == '(')
		name++;


	/* Do some fixups */
	if (rtype == AUDIT_EXECVE && name[0] == 'a')
		type = T_ESCAPED;
	else if (rtype == AUDIT_AVC && strcmp(name, "saddr") == 0)
		type = -1;
	else if (strcmp(name, "acct") == 0) {
		// Remove trailing punctuation
		int len = strlen(val);
		if (val[len-1] == ':')
			val[len-1] = 0;

		if (val[0] == '"')
			type = T_ESCAPED;
		else if (is_hex_string(val))
			type = T_ESCAPED;
		else
			type = -1;
	} else
		type = audit_lookup_type(name);

	switch(type) {
		case T_UID:
			print_uid(val);
			break;
		case T_GID:
			print_gid(val);
			break;
		case T_SYSCALL:
			print_syscall(val);
			break;
		case T_ARCH:
			print_arch(val);
			break;
		case T_EXIT:
			print_exit(val);
			break;
		case T_ESCAPED:
			print_escaped(val);
			break;
		case T_PERM:
			print_perm(val);
			break;
		case T_MODE:
			print_mode(val);
			break;
		case T_SOCKADDR:
			print_sockaddr(val);
			break;
		case T_FLAGS:
			print_flags(val);
			break;
		case T_PROMISC:
			print_promiscuous(val);
			break;
		case T_CAPABILITY:
			print_capabilities(val);
			break;
		case T_SIGNAL:
			print_signals(val);
			break;
		case T_KEY:
			print_key(val);
			break;
		case T_LIST:
			print_list(val);
			break;
		case T_TTY_DATA:
			print_tty_data(val);
			break;
		default:
			printf("%s%c", val, comma ? ',' : ' ');
	}
}
示例#11
0
int main(int argc, char *argv[])
{
    if (!parseArgs(the_args, &argc, argv)
        || argc < 2 || show_help) {
        printUsage(argv[0], "DOCUMENT", the_args);
        exit(1);
    }

    if (show_text[0]) {
        if (!memcmp(show_text, "physical", 9)) {
            show_text_layout = poppler::page::physical_layout;
        } else if (!memcmp(show_text, "raw", 4)) {
            show_text_layout = poppler::page::raw_order_layout;
        } else {
            error(std::string("unrecognized text mode: '") + show_text + "'");
        }
    }

    std::string file_name(argv[1]);

    std::auto_ptr<poppler::document> doc(poppler::document::load_from_file(file_name));
    if (!doc.get()) {
        error("loading error");
    }
    if (doc->is_locked()) {
        error("encrypted document");
    }

    std::cout.setf(std::ios_base::boolalpha);

    if (show_all) {
        show_info = true;
        show_perm = true;
        show_metadata = true;
        show_toc = true;
        show_fonts = true;
        show_embedded_files = true;
        show_pages = true;
    }

    if (show_info) {
        print_info(doc.get());
    }
    if (show_perm) {
        print_perm(doc.get());
    }
    if (show_metadata) {
        print_metadata(doc.get());
    }
    if (show_toc) {
        std::auto_ptr<poppler::toc> doctoc(doc->create_toc());
        print_toc(doctoc.get());
    }
    if (show_fonts) {
        print_fonts(doc.get());
    }
    if (show_embedded_files) {
        print_embedded_files(doc.get());
    }
    if (show_pages) {
        const int pages = doc->pages();
        for (int i = 0; i < pages; ++i) {
            std::cout << "Page " << (i + 1) << "/" << pages << ":" << std::endl;
            std::auto_ptr<poppler::page> p(doc->create_page(i));
            print_page(p.get());
        }
    }
    if (show_text[0]) {
        const int pages = doc->pages();
        for (int i = 0; i < pages; ++i) {
            std::cout << "Page " << (i + 1) << "/" << pages << ":" << std::endl;
            std::auto_ptr<poppler::page> p(doc->create_page(i));
            print_page_text(p.get());
        }
    }

    return 0;
}