示例#1
0
void
centerText(layer l, const char * t)
{
    int insertFrom = 0;
    int margin = 0, lines = 1, itr = 0;
    char * t2;
    char * tok;

    t2 = malloc(strlen(t) + 1);
    if (t2 != NULL)
        strcpy(t2, t);

    while (t2[itr] != 0)
        if (t2[itr++] == '\n')
            lines++;

    if (lines <= l->y)
        insertFrom = (l->y - lines) / 2;
    zeroOut(l->matrix, l->x, l->y);

    for (tok = strtok(t2, "\n"); tok != NULL; tok = strtok(NULL, "\n")){
        margin = l->x - strlen(tok);
        if (margin < 0)
            margin = 0;
        else
            margin /= 2;
        setText(l, margin, insertFrom++, tok);
    }
    free(t2);
}
示例#2
0
/* TODO: replace this with a space-aware, self-WRAPing function. */
layer
idxtext(layer l, int start, const char *s)
{
    int itr, aux;
    int x = LEFT_MARGIN, y = start;
    zeroOut(l->matrix, l->x, l->y);
    for (itr = 0; s[itr] != 0 && y < l->y; itr++){
        if (is_valid_char(s[itr])){
            if (x < l->x - RIGHT_MARGIN){
                l->matrix[y][x++] = s[itr];
            } else if (l->mode & LYR_AUTO_WRAP) {
                x = LEFT_MARGIN;
                y++;
                itr--;
            }
        } else if (s[itr] == '\n'){
            x = LEFT_MARGIN;
            y++;
        } else if (s[itr] == '\t'){
            aux = 4;
            while (aux--){
                if (x < l->x){
                    l->matrix[y][x++] = ' ';
                } else aux = 0;
            }
        }
    }
    return l;
}
void numberOut( int myNumber )
{
    for( int i = 128; i >= 1; i = i / 2)
    {
        if( myNumber & i )
            oneOut();
        else
            zeroOut();
    }
}
示例#4
0
文件: main.cpp 项目: chrzhang/abc
int main() {
    bool matrix[M][N];
    bool possibilities[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 0}; // p = 0.10
    srand(time(0));
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < N; ++j) {
            matrix[i][j] = possibilities[rand() % 10];
        }
    }
    printMatrix(matrix);
    std::cout << "Zero-ing out the matrix." << std::endl;
    zeroOut(matrix);
    printMatrix(matrix);
    return 0;
}
int main (void)
{
  // Declaring and initializing necessary variables.
  int a, b, c;
  a = b = c = 42;

  // Prints original values of a, b, c, before zeroOut()
  printf("A: %d B: %d C: %d\n", a, b, c);

  // Uses pointers to change all values to 0
  zeroOut(&a, &b, &c);

  // Ensures that all values are indeed 0.
  printf("A: %d B: %d C: %d\n", a, b, c);
  return 0;
}
示例#6
0
/**
 * @brief
 *
 * @param
 *
 * @return
 */
layer
vmenu(layer l, const char * txt, const char ** opts)
{
    int itr, x;
    /* get the text height + 2 lines*/
    int normalTextSize = strlen(txt) / l->x + 3;
    zeroOut(l->matrix, l->x, l->y);
    /* Get the number of options to show. */
    for (itr = 0; opts[itr] != NULL; itr++);
    if (LYR_NO_AUTO_RESIZE != (l->mode & LYR_NO_AUTO_RESIZE))
        l = resizeLayer(l, l->x, itr + normalTextSize + 1);
    idxtext(l, 1, txt);
    for (itr = 0; opts[itr] != NULL && itr + normalTextSize < l->y - 1; itr++){
        x = nlen(itr + 1) + 3;
        /* snprintf is not ANSI C (std89), it's ISO C (std99). Any
         * half-decent implementation has it. Anyway... */
        setNumber(l, 1, normalTextSize + itr, (unsigned int)(itr + 1));
        setText(l, x - 2, normalTextSize + itr, ")");
        setText(l, x, normalTextSize + itr, opts[itr]);
    }
    return l;
}
示例#7
0
/*-------------------------------------------------------------*/
void AzDmat::_reform(int new_row_num, int new_col_num, 
                     bool do_zeroOut) 
{
  const char *eyec = "AzDmat::_reform";  
  checkLock(eyec); 
  if (row_num == new_row_num && col_num == new_col_num) {
    if (do_zeroOut) zeroOut(); 
    return; 
  }
 
  _release(); 
  if (new_col_num < 0 || new_row_num < 0) {
    throw new AzException(eyec, "# columns or row must be non-negative"); 
  }
  col_num = new_col_num; 
  row_num = new_row_num; 
  a.alloc(&column, col_num, eyec, "column"); 
  dummy_zero.reform(row_num);   
  
  int cx; 
  for (cx = 0; cx < col_num; ++cx) {
    column[cx] = new AzDvect(this->row_num); 
  }
}
示例#8
0
/**
 * @brief
 *
 * @param
 *
 * @return
 */
void
clrscr(screen scr)
{
    zeroOut(scr->buffer, scr->x, scr->y);
}
示例#9
0
 inline void reform(int new_row_num) {
   _reform_noset(new_row_num); 
   zeroOut(); 
 }
示例#10
0
文件: main.c 项目: davestevens/DES
int main(int argv, char *argc[]) {
  unsigned int IIP[2];
  int i;
  FILE *fp;
  char *filename = NULL;
  int in[2];
  unsigned int K[2] = {0x13345779, 0x9bbcdff1}; /* default key value */
  unsigned int Keys[34];
  unsigned int decrypt = 0;
  unsigned int hexout = 1;

  for(i=1;i<argv;i++) {
    if(!strcmp(argc[i], "key")) {
      /* get the next two values */
      /* TODO */
      sscanf(argc[++i], "%u", &K[0]);
      sscanf(argc[++i], "%u", &K[1]);
    }
    else if(!strcmp(argc[i], "decrypt")) {
      decrypt = 1;
    }
    else if(!strcmp(argc[i], "dec")) {
      hexout = 0;
    }
    else {
      /* file name */
      filename = argc[i];
    }
  }

  zeroOut(Keys);
  initDES(K, Keys);

  /*  DES(input, Keys, IIP);
  printf("0x%08x", IIP[0]);
  printf("%08x\n", IIP[1]);*/

  /*DES(input2, Keys, IIP);
  printf("0x%08x", *(IIP));
  printf("%08x\n", *(IIP+1));*/

  if(filename == NULL) {
    for(i=0;i<16;i++) {
      DES(&input[i][0], Keys, IIP, decrypt);
      printf("0x%08x%08x\n", IIP[0], IIP[1]);
    }
  }
  else {
    if( (fp = fopen(filename, "r")) == NULL ) {
      printf("Could not open input file (%s)\n", filename);
      return -1;
    }

    while(!feof(fp)) {
      if(fscanf(fp, "%d", &in[0]) < 0) {
	break;
      }
      if(fscanf(fp, "%d", &in[1]) < 0) {
	break;
      }
      in[0] = ntohl(in[0]); /* flip endian */
      in[1] = ntohl(in[1]);
      DES((unsigned char *)&in[0], Keys, IIP, decrypt);
      if(hexout) {
	printf("0x%08x%08x\n", IIP[0], IIP[1]);
      }
      else {
	printf("%u\n%u\n", IIP[0], IIP[1]);
      }
    }
  }

  return 0;
}