Esempio n. 1
0
void fill_TABLES() {
    struct hash * looked_up;
    struct hash * row;
    struct parser_generator * parser_generator = new_parser_generator();
    append_to_list( parser_generator->TABLE, new_hash() );
    append_to_list( parser_generator->GOTO, new_hash() );
    add_initial_itemset( parser_generator );
    struct list * itemsets = parser_generator->itemsets;
    int i = 0;
    while ( i < parser_generator->itemsets->next_index ) {
        struct itemset * current_itemset = listlookup( itemsets, i );
        looked_up = listlookup( parser_generator->TABLE, i );
        if ( ! looked_up ) {
            row = new_hash();
            append_to_list( parser_generator->TABLE, row );
        }
        looked_up = listlookup( parser_generator->GOTO, i );
        if ( ! looked_up ) {
            row = new_hash();
            append_to_list( parser_generator->GOTO, row );
        }
        install_incomplete_transitions( i, current_itemset, parser_generator );
        install_complete_transitions( i, current_itemset, parser_generator );
        i++;
    }
    TABLE = parser_generator->TABLE;
    GOTO = parser_generator->GOTO;
    
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	struct list_node *my_list = NULL;

	add_item_to_front_of_list(&my_list, "Calvin", "Spaceman Spiff");
	add_item_to_front_of_list(&my_list, "Snoopy", "Red Baron");
	append_to_list(&my_list, "Marty McFly", "Calvin Klien");
	append_to_list(&my_list, "Clark Kent", "Superman");
	append_to_list(&my_list, "Bruce Wayne", "Batman");
	print_list(my_list);
	return 0;
}
Esempio n. 3
0
void push_operator_and_command(char* chunk,
                               char* pair,
                               command_t command_to_append, 
                               command_t operator_to_append,
                               command_stream* iterate_me) {

    command_to_append = malloc(sizeof(struct command));
    parse_chunk_to_command(chunk, command_to_append);
    append_to_list(command_to_append, iterate_me);
    chunk[0] = '\0';
    operator_to_append = malloc(sizeof(struct command));
    parse_pair_to_operator_command(pair, operator_to_append);
    append_to_list(operator_to_append, iterate_me);
}
Esempio n. 4
0
int main()
{
    printf("Testing lists...\n");
    List *list = (List *) create_list();
    assert(list != NULL);
    assert(list->data == NULL);
    assert(list->next == NULL);

    int w = 42;
    int x = 1;
    int y = 2;
    int z = 3;

    append_to_list(list, &x);
    assert(*(int *)(list->data) == 1);
    assert(list->next != NULL);

    append_to_list(list, &y);
    assert(*(int *)(list->next->data) == 2);
    assert(list->next->next != NULL);
    
    append_to_list(list, &z);
    assert(*(int *)(list->next->next->data) == 3);
    assert(list->next->next->next != NULL);

    assert(list->next->next->next->data == NULL);
    assert(list->next->next->next->next == NULL);


    list = (List *) push_to_list(list, &w);
    assert(*(int *)(list->data) == 42);
    assert(list->next != NULL);

    list = (List *) pop_from_list(list);
    assert(*(int *)(list->data) == 1);

    assert(list_length(list) == 3);
    assert(list_index(list, &y) == 1);
    assert(list_index(list, &w) == -1);
   
    list = remove_from_list(list, &x);
    assert(*(int *)(list->data) == 2);

    list = push_to_list(list, &x);
    list = remove_from_list(list, &y);
    assert(*(int *)(list->next->data) == 3);

    printf("List tests passed\n");
    return 0;
}
void list_keys_in_hash( struct hash * current, struct list * result, char * prefix ) {
    int siglen = strlen(current->sigstr);
    int prefixlen = strlen(prefix);
    char * path = malloc( ( prefixlen + siglen + 2 ) * sizeof(char) ); // Extra child char.
    strcpy( path, prefix );
    strcat( path, current->sigstr );
    path[ prefixlen + siglen + 1 ] = path[ prefixlen + siglen ] = '\0';
    char * chars_in_child = chars_in( current->child, 0, 0 );
    char child_char = '\0';
    struct hash * child_hash = NULL;
    int i = current->num_children;
    while ( i-- ) { // Recurse through all children.
        child_char = chars_in_child[i];
        if ( child_char == '\0' ) { // No keys to recurse through.
            continue;
        }
        path[ prefixlen + siglen ] = child_char; // Get the path prefix for this child.
        child_hash = charhashlookup( current->child, child_char )->data;
        list_keys_in_hash( child_hash, result, path );
    }

    // Decide if the path to this node needs to be included in the list of keys.
    if ( current->data ) {
        path[ prefixlen + siglen ] = '\0';
        append_to_list( result, (void *) path );
    }
    else {
        free(path);
    }
    free(chars_in_child);
    return;
}
Esempio n. 6
0
/**********************************************************
 * main: Prompts the user to enter an operation code,     *
 *       then calls a function to perform the requested   *
 *       action. Repeats until the user enters the        *
 *       command 'q'. Prints an error message if the user *
 *       enters an illegal code.                          *
 **********************************************************/
int main(void)
{
  char code;

  struct player *team_roster = NULL;  
  printf("Operation Code: a for appending to the roster, d for deleteing a player, f for finding a player"
	  ", p for printing the roster; q for quit.\n");
  for (;;) {
    printf("Enter operation code: ");
    scanf(" %c", &code);
    while (getchar() != '\n')   /* skips to end of line */
      ;
    switch (code) {
      case 'a': team_roster = append_to_list(team_roster);
		break;
      case 'f': find_player(team_roster);
                break;
      case 'p': printList(team_roster);
                break;
      case 'd': delete_from_list(team_roster);
		break; 
      case 'q': clearList(team_roster);
		printf("\n");
		return 0;
      default:  printf("Illegal code");
    }
    printf("\n");
  }
}
Esempio n. 7
0
int main(int argc, char **argv) {
    if (argc < 3) {
        printf("Provide an int followed by some characters (at least one)\n"
               "        as command-line arguments.\n");
        return EXIT_FAILURE;
    }
    const int length = argc - 2;
    int starting_point = strtol(argv[1], NULL, 10) % length;
    Node *list = NULL;
    for (int i = 2; i < argc; ++i)
        append_to_list(argv[i][0], &list);
    Node *list_copy = list;
    reverse_from(&list, starting_point);
    print_list(list);
    reverse_from(&list, starting_point);
    print_list(list);
    for (int i = 0; i < length; ++i) {
        if (list != list_copy) {
            printf("You cheated! Failed test.\n");
            break;
        }
        list = list->pt_to_next_node;
        list_copy = list_copy->pt_to_next_node;
    }
    return EXIT_SUCCESS;
}
Esempio n. 8
0
/*
 * Appends a value to the subordinate list.
 */
void to_sub_list(element_type value)
{
	list_type d;
	//仅仅往树添加系数的幅度值的大小,系数的符号已经编码
	d.x = abs(value);
	d.y = 0;
	append_to_list(d);
}
Esempio n. 9
0
void apriori(void)
{
  ItemSetNode *frequent[8] = {NULL};
  frequent[1] = get_frequent_one_itemsets();
  int i, j, k;
  for (i = 2; i < 8; i++)
  {
    frequent[i] = get_frequent_k_plus_one_itemsets(frequent[i - 1], frequent[1], i);
  }

  ItemSetNode *all_frequent = NULL, *l, *m;
  for (i = 1; i < 8; i++)
  {
    for (l = frequent[i]; l != NULL; l = l->next)
    {
      append_to_list(&all_frequent, l->data);
    }
  }
  printf("Frequent Itemsets: \n");
  print_list(all_frequent);

  for (l = all_frequent; l != NULL; l = l->next)
  {
    for (i = 0; i < 256; i++)
      permutations[i] = NULL;
    count = 0;

    char *tmp = malloc(sizeof(char) * (strlen(l->data->item_set) + 1));
    strcpy(tmp, l->data->item_set);
    
    permute(tmp, 0, strlen(tmp) - 1);
    for (i = 0; i < 256; i++)
    {
      if (permutations[i] != NULL)
      {
        for (j = 1; j < strlen(permutations[i]); j++)
        {
          char *LHS = malloc(sizeof(char) * (j + 1));
          strncpy(LHS, permutations[i], j);
          *(LHS + j) = '\0';
          char *total = permutations[i];
          int lhs_support, total_support;
          for (m = all_frequent; m != NULL; m = m->next)
          {
            if (strcmp(LHS, m->data->item_set) == 0)
              lhs_support = m->data->count;
            if (strcmp(total, m->data->item_set) == 0)
              total_support = m->data->count;
          }
          float conf = (float) total_support / lhs_support;
          if (conf >= MIN_CONF)
            printf("Rule: %s -> %s, Confidence: %f\n", LHS, j + permutations[i], conf);
        }
      }
    }

  }
}
Esempio n. 10
0
void insert_itemset_into_tree(TreeNode **root, ItemSet *item_set, int level, int k)
{
  if (*root == NULL)
  {
    *root = new_tree_node();
    (*root)->level = level;
    append_to_list(&((*root)->item_sets), item_set);
  }
  else if (get_size_of_list((*root)->item_sets) == MAX_NODE_SIZE && level < k)
  {
    ItemSetNode *tmp = NULL, *l;

    append_to_list(&tmp, (*root)->item_sets->data);
    append_to_list(&tmp, (*root)->item_sets->next->data);
    append_to_list(&tmp, item_set);

    (*root)->item_sets = NULL;
    (*root)->flag = 0;

    for (l = tmp; l != NULL; l = l->next)
    {
      if ((*(l->data->item_set + level)) % 3 == 0)
        insert_itemset_into_tree(&((*root)->left), l->data, 1 + level, k);
      else if ((*(l->data->item_set + level)) % 3 == 1)
        insert_itemset_into_tree(&((*root)->middle), l->data, 1 + level, k);
      else if ((*(l->data->item_set + level)) % 3 == 2)
        insert_itemset_into_tree(&((*root)->right), l->data, 1 + level, k);
    }
  }
  else if ((*root)->flag)
  {
    append_to_list(&((*root)->item_sets), item_set);
  }
  else
  {
    if ((*(item_set->item_set + level)) % 3 == 0)
      insert_itemset_into_tree(&((*root)->left), item_set, 1 + level, k);
    else if ((*(item_set->item_set + level)) % 3 == 1)
      insert_itemset_into_tree(&((*root)->middle), item_set, 1 + level, k);
    else if ((*(item_set->item_set + level)) % 3 == 2)
      insert_itemset_into_tree(&((*root)->right), item_set, 1 + level, k);
  }
}
Esempio n. 11
0
int main(int argc, char **argv) {
    char* array[4] = {"This ", "is ", "good ", "time "};
    List* list = init_list();
    for (int i = 0; i < 4; i++) {
        Node *node = create_node(array[i]);
        append_to_list(list, node);
    }
    print_list(list);
    return EXIT_SUCCESS;
}
Esempio n. 12
0
int main(int argc, char *argv[]) {
	printf("\n");
	/*
	 * testing the creation of lists and appending
	 */
	printf("%s\n\n", "Commands Test 1");
	LTICKET ref = create_list("Adewale");
	append_to_list(ref, "Olufemi");
	append_to_list(ref, "Nneka");
	append_to_list(ref, "Jacob");
	append_to_list(ref, "Adetola");
	append_to_list(ref, "Kemi");
	visit_nodes(ref);
	delete_list(ref);

	/*
	 * testing the head and tail removal as well as head insertion
	 */
	printf("%s\n\n", "Commands Test 2");
	LTICKET ref2 = create_list("Adewale");
	append_to_list(ref2, "Olufemi");
	append_to_list(ref2, "Nneka");
	append_to_list(ref2, "Jacob");
	append_to_list(ref2, "Adetola");
	append_to_list(ref2, "Kemi");
	visit_nodes(ref2);
	remove_head(ref2);
	visit_nodes(ref2);
	insert_head(ref2, "Chiamaka");
	visit_nodes(ref2);
	remove_tail(ref2);
	visit_nodes(ref2);
	delete_list(ref2);

	// int check = visit_nodes(ref);
	// if(LE_ISERROR(check))
	// 	printf("%s\n", le_errbuf);
	return 0;
}
Esempio n. 13
0
void add_initial_itemset( struct parser_generator * self ) {
    struct item * initial_item = new_item();
    char * initial_item_key = create_item_key( initial_item );
    struct itemset * initial_itemset = new_itemset();
    add_to_hash( initial_itemset->items, initial_item_key, (void *) initial_item );
    free( initial_item_key );
    char * initial_itemset_key = create_closure_key( initial_itemset );
    append_to_list( self->itemsets, (void *) initial_itemset );
    int initial_state = self->itemsets->next_index - 1;
    add_to_hash( self->itemsets_by_key, initial_itemset_key, (void *) (long int) initial_state );
    free( initial_itemset_key );
    return;
}
Esempio n. 14
0
static LRESULT CALLBACK PopupAlarmDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message) {
	case WM_COMMAND: // snooze
		if (HIWORD(wParam) == STN_CLICKED) { //It was a click on the Popup.
			ALARM *mpd = (ALARM *)CallService(MS_POPUP_GETPLUGINDATA, (WPARAM)hWnd, 0);

			if (mpd->flags & ALF_NOSNOOZE)
				return TRUE;

			// add snooze minutes to current time
			FILETIME ft;
			GetLocalTime(&mpd->time);
			SystemTimeToFileTime(&mpd->time, &ft);
			ULARGE_INTEGER uli;
			uli.LowPart = ft.dwLowDateTime;
			uli.HighPart = ft.dwHighDateTime;

			uli.QuadPart += mult.QuadPart * options.snooze_minutes;

			ft.dwHighDateTime = uli.HighPart;
			ft.dwLowDateTime = uli.LowPart;

			FileTimeToSystemTime(&ft, &mpd->time);

			mpd->occurrence = OC_ONCE;
			mpd->snoozer = true;
			mpd->flags = mpd->flags & ~(ALF_NOSTARTUP);

			mpd->id = next_alarm_id++;

			append_to_list(mpd);
		}

		PUDeletePopup(hWnd);
		return TRUE;

	case WM_CONTEXTMENU: 
		PUDeletePopup(hWnd);
		return TRUE;

	case UM_FREEPLUGINDATA: 
		ALARM *mpd = (ALARM *)CallService(MS_POPUP_GETPLUGINDATA, (WPARAM)hWnd, 0);
		if (mpd > 0) {
			free_alarm_data(mpd);
			delete mpd;
		}
		return TRUE;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}
Esempio n. 15
0
void install_incomplete_transition( int i, char * symbol, int destination, struct parser_generator * self ) {
    struct hash * table_row = listlookup( self->TABLE, i );
    struct hash * goto_row = listlookup( self->GOTO, i );
    struct list * trans_list;
    struct hash * looked_up;
    if ( ( (int *) hashlookup( IS_TERMINAL, symbol )->data ) == &TRUE ) {

        // Transitions on terminals go in TABLE.
        looked_up = hashlookup( table_row, symbol );
        if  ( ! looked_up ) {
            trans_list = new_list();
            add_to_hash( table_row, symbol, (void *) trans_list );
        }
        else {
            trans_list = looked_up->data;
        }
        struct transition * terminal_transition = new_transition();
        terminal_transition->action = "shift";
        terminal_transition->arg = destination;
        if ( ! strcmp( symbol, "end" ) ) {
            terminal_transition->action = "accept";
        }
        append_to_list( trans_list, (void *) terminal_transition );
    }
    else { // Transitions on nonterminals go in GOTO.
        looked_up = hashlookup( goto_row, symbol );
        if ( ! looked_up ) {
            trans_list = new_list();
            add_to_hash( goto_row, symbol, (void *) trans_list );
        }
        else {
            trans_list = looked_up->data;
        }
        append_to_list( trans_list, (void *) (long int) destination );
    }
}
Esempio n. 16
0
KDEF_SYSCALL(thread_fork, r)
{
  // example: thread_fork(stack, function, argument);
  process_stack stack = init_pstack();
  if(current->proc->flags & PROC_FLAG_DEBUG)
  {
    debug("[info]thread_fork(%x, %x, %x)\n", stack[0], stack[1], stack[2]);
  }
  thread_t *th = new_thread((void (*)(void))stack[1], 1);
  append_to_list(current->proc->threads, th->process_threads);
  th->proc = current->proc;
  uint32_t *stk = (uint32_t *)stack[0];
  *--stk = stack[2];
  *--stk = SIGNAL_RETURN_ADDRESS;
  th->r.useresp = th->r.ebp = (uint32_t)stk;
  r->eax = th->tid;
  return r;
}
Esempio n. 17
0
linked_list_node *prime_numbers_less_than(int n) {
  int cur = 3;
  linked_list_node * head = create_linked_list_node(2);

  while ((last_node(head))->data < n) {

    if (cur >= n) {
      break;
    } else if (!list_can_divide_num(head, cur)) {
      printf("%d\n", cur);
      append_to_list(head, cur);
    }

    cur ++;
  }

  return head;
}
Esempio n. 18
0
void get_leaves(TreeNode *root, ItemSetNode **list)
{
  if (root == NULL)
    return;

  ItemSetNode *l;

  for (l = root->item_sets; l != NULL; l = l->next)
  {
    if ((float)l->data->count / TXNS >= MIN_SUPPORT)
    {
      append_to_list(list, l->data);
    }
  }

  get_leaves(root->left,list);
  get_leaves(root->middle, list);
  get_leaves(root->right, list);
}
Esempio n. 19
0
INT_PTR AddAlarmService(WPARAM, LPARAM lParam)
{
	ALARMINFO *alarm_info = (ALARMINFO *)lParam;
	ALARM alarm = {0};
	alarm.action = alarm_info->action;
	alarm.flags = alarm_info->flags;
	alarm.id = next_alarm_id++;
	alarm.occurrence = alarm_info->occurrence;
	alarm.snoozer = alarm_info->snoozer;
	alarm.sound_num = alarm_info->sound_num;
	alarm.szCommand = mir_tstrdup(alarm_info->szCommand);
	alarm.szCommandParams = mir_tstrdup(alarm_info->szCommandParams);
	alarm.szDesc = mir_tstrdup(alarm_info->szDesc);
	alarm.szTitle = mir_tstrdup(alarm_info->szTitle);
	alarm.time = alarm_info->time;

	append_to_list(&alarm);
	return 0;
}
Esempio n. 20
0
void analyze_productions() {
    GSIZE = NUM_PRODUCTIONS;
    int i;
    int j;
    struct list * production;
    struct list * productions_for_symbol;
    char * symbol;
    if ( ! IS_TERMINAL ) {
        IS_TERMINAL = new_hash();
    }
    if ( ! PRODUCTIONS_FOR ) {
        PRODUCTIONS_FOR = new_hash();
    }
    for ( i = 0; i < NUM_PRODUCTIONS; i++ ) {
        production = GRAMMAR[i].production;
        if ( production->next_index > GSIZE ) {
            GSIZE = production->next_index;
        }
        for ( j = 0; j < production->next_index; j++ ) {
            symbol = listlookup( production, j );
            struct hash * looked_up = hashlookup( IS_TERMINAL, symbol );
            if ( ! looked_up ) { // Assume each new symbol is a terminal.
                add_to_hash( IS_TERMINAL, symbol, (void *) &TRUE );
            }
            if ( j == 0 ) { // Symbols on the left side of a productions are nonterminal.
                add_to_hash( IS_TERMINAL, symbol, (void *) &FALSE );
                looked_up = hashlookup( PRODUCTIONS_FOR, symbol );
                if ( ! looked_up ) {
                    productions_for_symbol = new_list();
                    add_to_hash( PRODUCTIONS_FOR, symbol, (void *) productions_for_symbol );
                }
                else {
                    productions_for_symbol = looked_up->data;
                }

                append_to_list( productions_for_symbol, (void *) (long int) i );
            }
        }
    }
}
Esempio n. 21
0
ItemSetNode *get_frequent_one_itemsets(void)
{
  const char* item[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y"};
  int count[25] = {0};

  FILE *fp = fopen(DATA_FILE, "r");

  char *line = NULL;
  int i;

  while ((line = read_line(fp)) != NULL && *line != '\0')
  {
    for (i = 0; i < 25; i++)
    {
      if (strstr(line, item[i]) != NULL)
      {
        count[i]++;
      }
    }
    free(line);
  }

  ItemSetNode *list = NULL;
  for (i = 0; i < 25; i++)
  {
    float support = (float) count[i] / TXNS;
    if (support >= MIN_SUPPORT)
    {
      char *tmp = malloc(sizeof(char) * 2);
      *tmp = *item[i];
      *(tmp + 1) = '\0';
      append_to_list(&list, new_item_set(tmp, count[i]));
    }
  }

  fclose(fp);

  return list;
}
Esempio n. 22
0
void install_incomplete_transitions( int i, struct itemset * current_itemset, struct parser_generator * self ) {
    struct list * itemsets = self->itemsets;
    struct hash * itemsets_by_key = self->itemsets_by_key;
    struct hash * ready_for = current_itemset->ready_for;

    // Prepare to loop through the keys of current_itemset->ready_for.
    struct list * key_list = new_list();
    list_keys_in_hash( ready_for, key_list, "" );
    int j;
    int k;
    for ( j = 0; j < key_list->next_index; j++ ) { // Loop ready-for symbols.
        char * symbol = listlookup( key_list, j );
        struct list * ready_for_symbol = hashlookup( ready_for, symbol )->data;
        struct itemset * proposed_itemset = new_itemset();
        for ( k = 0; k < ready_for_symbol->next_index; k++ ) { // Loop symbol items.
            struct item * ready_item = listlookup( ready_for_symbol, k );
            struct item * proposed_item = new_item();
            proposed_item->prod_num = ready_item->prod_num;
            proposed_item->dot = ready_item->dot + 1;
            char * proposed_item_key = create_item_key( proposed_item );
            add_to_hash( proposed_itemset->items, proposed_item_key, (void *) proposed_item );
            free( proposed_item_key ); // It's now in the hash.
        } // End symbol items loop.
        char * proposed_itemset_key = create_closure_key( proposed_itemset );
        struct hash * looked_up = hashlookup( itemsets_by_key, proposed_itemset_key );
        if ( ! looked_up ) {
            append_to_list( itemsets, (void *) proposed_itemset );
            int state_num = itemsets->next_index - 1;
            looked_up = add_to_hash( itemsets_by_key, proposed_itemset_key, (void *) (long int) state_num );
        }
        else {
            destroy_itemset( proposed_itemset );
        }
        int destination = (long int) looked_up->data;
        install_incomplete_transition( i, symbol, destination, self );
    } // End ready-for symbols loop.
    return;
}
Esempio n. 23
0
void install_complete_transitions( int i, struct itemset * current_itemset, struct parser_generator * self ) {
    struct list * table = self->TABLE;
    struct list * complete_items = current_itemset->complete;
    char * lhs;
    struct item * complete_item;
    struct list * complete_production;
    int j; int k;
    struct hash * table_row = listlookup( self->TABLE, i );
    for ( j = 0; j < complete_items->next_index; j++ ) {
        complete_item = listlookup( complete_items, j );
        int prod_num = complete_item->prod_num;
        complete_production = GRAMMAR[prod_num].production;
        lhs = listlookup( complete_production, 0 );

        // Loop all terminals which can follow this lhs.
        struct list * key_list = new_list();
        list_keys_in_hash( hashlookup( FOLLOW, lhs )->data, key_list, "" );
        for ( k = 0; k < key_list->next_index; k++ ) {
            struct list * trans_list;
            char * follower = listlookup( key_list, k );

            // Add a reduce transition on each follower token.
            struct hash * looked_up = hashlookup( table_row, follower );
            if ( ! looked_up ) {
                trans_list = new_list();
                add_to_hash( table_row, follower, (void *) trans_list );
            }
            else {
                trans_list = looked_up->data;
            }
            struct transition * reduce_transition = new_transition();
            reduce_transition->action = "reduce";
            reduce_transition->arg = prod_num;
            append_to_list( trans_list, reduce_transition );
        }
        destroy_key_list( key_list );
    }
}
Esempio n. 24
0
static int handle_line(char *line)
{
	int i, len = strlen(line);
	unsigned char *sha1;
	char *src, *origin;
	struct src_data *src_data;
	int pulling_head = 0;

	if (len < 43 || line[40] != '\t')
		return 1;

	if (!prefixcmp(line + 41, "not-for-merge"))
		return 0;

	if (line[41] != '\t')
		return 2;

	line[40] = 0;
	sha1 = xmalloc(20);
	i = get_sha1(line, sha1);
	line[40] = '\t';
	if (i)
		return 3;

	if (line[len - 1] == '\n')
		line[len - 1] = 0;
	line += 42;

	src = strstr(line, " of ");
	if (src) {
		*src = 0;
		src += 4;
		pulling_head = 0;
	} else {
		src = line;
		pulling_head = 1;
	}

	i = find_in_list(&srcs, src);
	if (i < 0) {
		i = srcs.nr;
		append_to_list(&srcs, xstrdup(src),
				xcalloc(1, sizeof(struct src_data)));
	}
	src_data = srcs.payload[i];

	if (pulling_head) {
		origin = xstrdup(src);
		src_data->head_status |= 1;
	} else if (!prefixcmp(line, "branch ")) {
		origin = xstrdup(line + 7);
		append_to_list(&src_data->branch, origin, NULL);
		src_data->head_status |= 2;
	} else if (!prefixcmp(line, "tag ")) {
		origin = line;
		append_to_list(&src_data->tag, xstrdup(origin + 4), NULL);
		src_data->head_status |= 2;
	} else if (!prefixcmp(line, "remote branch ")) {
		origin = xstrdup(line + 14);
		append_to_list(&src_data->r_branch, origin, NULL);
		src_data->head_status |= 2;
	} else {
		origin = xstrdup(src);
		append_to_list(&src_data->generic, xstrdup(line), NULL);
		src_data->head_status |= 2;
	}

	if (!strcmp(".", src) || !strcmp(src, origin)) {
		int len = strlen(origin);
		if (origin[0] == '\'' && origin[len - 1] == '\'') {
			origin = xmemdupz(origin + 1, len - 2);
		} else {
			origin = xstrdup(origin);
		}
	} else {
		char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5);
		sprintf(new_origin, "%s of %s", origin, src);
		origin = new_origin;
	}
	append_to_list(&origins, origin, sha1);
	return 0;
}
Esempio n. 25
0
static void shortlog(const char *name, unsigned char *sha1,
		struct commit *head, struct rev_info *rev, int limit)
{
	int i, count = 0;
	struct commit *commit;
	struct object *branch;
	struct list subjects = { NULL, NULL, 0, 0 };
	int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;

	branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
	if (!branch || branch->type != OBJ_COMMIT)
		return;

	setup_revisions(0, NULL, rev, NULL);
	rev->ignore_merges = 1;
	add_pending_object(rev, branch, name);
	add_pending_object(rev, &head->object, "^HEAD");
	head->object.flags |= UNINTERESTING;
	if (prepare_revision_walk(rev))
		die("revision walk setup failed");
	while ((commit = get_revision(rev)) != NULL) {
		char *oneline, *bol, *eol;

		/* ignore merges */
		if (commit->parents && commit->parents->next)
			continue;

		count++;
		if (subjects.nr > limit)
			continue;

		bol = strstr(commit->buffer, "\n\n");
		if (bol) {
			unsigned char c;
			do {
				c = *++bol;
			} while (isspace(c));
			if (!c)
				bol = NULL;
		}

		if (!bol) {
			append_to_list(&subjects, xstrdup(sha1_to_hex(
							commit->object.sha1)),
					NULL);
			continue;
		}

		eol = strchr(bol, '\n');
		if (eol) {
			oneline = xmemdupz(bol, eol - bol);
		} else {
			oneline = xstrdup(bol);
		}
		append_to_list(&subjects, oneline, NULL);
	}

	if (count > limit)
		printf("\n* %s: (%d commits)\n", name, count);
	else
		printf("\n* %s:\n", name);

	for (i = 0; i < subjects.nr; i++)
		if (i >= limit)
			printf("  ...\n");
		else
			printf("  %s\n", subjects.list[i]);

	clear_commit_marks((struct commit *)branch, flags);
	clear_commit_marks(head, flags);
	free_commit_list(rev->commits);
	rev->commits = NULL;
	rev->pending.nr = 0;

	free_list(&subjects);
}
Esempio n. 26
0
static void node_checkdirectory(struct imgtooltest_state *state, xml_data_node *node)
{
	imgtoolerr_t err = IMGTOOLERR_SUCCESS;
	imgtool_directory *imageenum;
	imgtool_dirent ent;
	char expected_listing[1024];
	char actual_listing[1024];
	int i/*, actual_count*/;
	int mismatch;
	xml_attribute_node *attr_node;
	xml_data_node *child_node;
	const char *filename;
	expected_dirent *entry;
	expected_dirent entries[256];
	int entry_count;

	if (!state->m_partition)
	{
		state->m_failed = 1;
		report_message(MSG_FAILURE, "Partition not loaded");
		return;
	}

	attr_node = xml_get_attribute(node, "path");
	filename = attr_node ? attr_node->value : "";

	memset(&entries, 0, sizeof(entries));
	entry_count = 0;

	for (child_node = xml_get_sibling(node->child, "entry"); child_node; child_node = xml_get_sibling(child_node->next, "entry"))
	{
		if (entry_count >= ARRAY_LENGTH(entries))
		{
			report_message(MSG_FAILURE, "Too many directory entries");
			return;
		}

		entry = &entries[entry_count++];

		attr_node = xml_get_attribute(child_node, "name");
		entry->filename = attr_node ? attr_node->value : NULL;

		attr_node = xml_get_attribute(child_node, "size");
		entry->size = attr_node ? atoi(attr_node->value) : -1;
	}

	/* build expected listing string */
	expected_listing[0] = '\0';
	for (i = 0; i < entry_count; i++)
	{
		append_to_list(expected_listing,
			ARRAY_LENGTH(expected_listing),
			entries[i].filename);
	}

	/* now enumerate though listing */
	//actual_count = 0;
	actual_listing[0] = '\0';
	mismatch = FALSE;

	memset(&ent, 0, sizeof(ent));

	err = imgtool_directory_open(state->m_partition, filename, &imageenum);
	if (err)
		goto done;

	i = 0;
	do
	{
		err = imgtool_directory_get_next(imageenum, &ent);
		if (err)
			goto done;

		if (!ent.eof)
		{
			append_to_list(actual_listing,
				ARRAY_LENGTH(actual_listing),
				ent.filename);

			if (i < entry_count && (strcmp(ent.filename, entries[i].filename)))
				mismatch = TRUE;
			i++;
		}
	}
	while(!ent.eof);

	if (i != entry_count)
		mismatch = TRUE;

	if (mismatch)
	{
		state->m_failed = 1;
		report_message(MSG_FAILURE, "File listing mismatch: {%s} expected {%s}",
			actual_listing, expected_listing);
		goto done;
	}

done:
	if (imageenum)
		imgtool_directory_close(imageenum);
	if (err)
	{
		state->m_failed = 1;
		report_imgtoolerr(err);
	}
}
Esempio n. 27
0
void pool_add(lky_mempool *pool, void *obj)
{
    struct poolnode *next = gen_node(obj);
    append_to_list(&(pool->head), &(pool->tail), next);
}
Esempio n. 28
0
List *split_into_simple_commands( char *cmd )
{
    List *command_list = NULL;

    int escaped = 0;
    int in_single_quote = 0;
    int in_double_quote = 0;
    int in_backwards_quote = 0;

    int start_index = 0;
    int current_index = 0;
    int cmd_length = strlen( cmd );
    char c;
    char prev_c;
    char next_c;

    //fprintf( stderr, "split_into_simple_commands(%s)\n", cmd );

    while ( current_index < cmd_length ) {
        /* It is sometimes easiest if we can look one character to the
           right or to the left of the current position, whilst not
           going off either end of the string. */

        c = cmd[ current_index ];

        if ( current_index > 0 ) {
            prev_c = cmd[ current_index - 1 ];
        } else {
            prev_c = '\0';
        }

        if ( (current_index + 1) < cmd_length ) {
            next_c = cmd[ current_index + 1 ];
        } else {
            next_c = '\0';
        }

        switch(c) {
        case '\\' :
            escaped = 1;
            current_index++;
            break;

        case '\'' :
            if ( escaped ) {
                escaped = 0;
                current_index++;
            } else {
                in_single_quote = !in_single_quote;
                current_index++;
            }
            break;

        case '\"' :
            if ( escaped ) {
                escaped = 0;
                current_index++;
            } else {
                in_double_quote = !in_double_quote;
                current_index++;
            }
            break;

        case '`' :
            if ( escaped ) {
                escaped = 0;
                current_index++;
            } else {
                in_backwards_quote = !in_backwards_quote;
                current_index++;
            }
            break;

        case '|' :
        case '&' :
        case '(' :
        case ')' :
        case ';' :
            escaped = 0;
            if (in_single_quote || in_double_quote || in_backwards_quote) {
                current_index++;
            } else {
                if ( ((c == '&') && (next_c == '&')) || 
                     ((c == '|') && (next_c == '|')) ||
                     ((c == '|') && (next_c == '&')) ) {
                    command_list = append_to_list( command_list, 
                                                   strndup( &(cmd[start_index]), current_index-start_index ) );
                    command_list = append_to_list( command_list, 
                                                   strndup( &(cmd[current_index]), 2 ) );
                    current_index += 2;
                    start_index = current_index;
                } else if ( (prev_c == '>') && (c == '&') ) { // ignore >& redirect                    
                    current_index++;
                } else {
                    command_list = append_to_list( command_list, 
                                                   strndup( &(cmd[start_index]), current_index-start_index ) );
                    command_list = append_to_list( command_list, 
                                                   strndup( &(cmd[current_index]), 1 ) );
                    current_index++;
                    start_index = current_index;
                }
            }
            break;

        case ' ' :
        case '\t' :
            /* If we see one or more spaces or tabs at the start of a
               (simple) command, then keep moving start_index forward,
               so that if we eventually find a command, we've already
               stepped over the white space. */

            if (start_index == current_index) {
                current_index++;
                start_index = current_index;
            } else {
                current_index++;
            }
            escaped = 0;
            break;

        default :
            escaped = 0;
            current_index++;
        }
    }

    if (start_index != current_index) {
        command_list = append_to_list( command_list, 
                                       strndup( &(cmd[start_index]), current_index-start_index ) );
    }

    //fprintf( stderr, "split_into_simple_commands returns\n" );
    //print_list( command_list );

    return command_list;
}
Esempio n. 29
0
INT_PTR CALLBACK DlgProcAlarm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch ( msg ) {
	case WM_INITDIALOG: 
		TranslateDialogDefault( hwndDlg );
		{
			Utils_RestoreWindowPositionNoSize(hwndDlg, 0, MODULE, "Notify");
			SetFocus(GetDlgItem(hwndDlg, IDC_SNOOZE));

			WindowData *wd = new WindowData;
			wd->moving = false;
			wd->alarm = 0;
			wd->win_num = win_num++;

			if (wd->win_num > 0) {
				RECT r;
				GetWindowRect(hwndDlg, &r);
				r.top += 20;
				r.left += 20;

				SetWindowPos(hwndDlg, 0, r.left, r.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
				Utils_SaveWindowPosition(hwndDlg, 0, MODULE, "Notify");
			}

			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)wd);

			// options
			SendMessage(hwndDlg, WMU_SETOPT, 0, 0);
		
			// fonts
			SendMessage(hwndDlg, WMU_SETFONTS, 0, 0);
		}
		return FALSE;

	case WMU_REFRESH:
		InvalidateRect(hwndDlg, 0, TRUE);
		return TRUE;

	case WM_CTLCOLORSTATIC:
		{
			HDC hdc = (HDC)wParam;
			HWND hwndCtrl = (HWND)lParam;

			if (hBackgroundBrush) {
				if (hTitleFont && GetDlgItem(hwndDlg, IDC_TITLE) == hwndCtrl)
					SetTextColor(hdc, title_font_colour);
				else if (hWindowFont)
					SetTextColor(hdc, window_font_colour);

				SetBkMode(hdc, TRANSPARENT);
				return (BOOL)hBackgroundBrush;
			}
		}
		break;
	case WM_CTLCOLORDLG:
		if (hBackgroundBrush)
			return (BOOL)hBackgroundBrush;
		break;
	case WMU_SETFONTS:
		// fonts
		if (hWindowFont)
			SendMessage(hwndDlg, WM_SETFONT, (WPARAM)hWindowFont, TRUE);
		if (hTitleFont)
			SendDlgItemMessage(hwndDlg, IDC_TITLE, WM_SETFONT, (WPARAM)hTitleFont, TRUE);

		if (hBackgroundBrush) {
			SetClassLong(hwndDlg, GCLP_HBRBACKGROUND, (LONG)hBackgroundBrush);
			InvalidateRect(hwndDlg, 0, TRUE);
		}
		return TRUE;

	case WMU_SETOPT:
		{
			Options *opt;
			if (lParam) opt = (Options *)lParam;
			else opt = &options;
			
			// round corners
			if (opt->aw_roundcorners) {
				HRGN hRgn1;
				RECT r;
				int v,h;
				int w=10;
				GetWindowRect(hwndDlg,&r);
				h=(r.right-r.left)>(w*2)?w:(r.right-r.left);
				v=(r.bottom-r.top)>(w*2)?w:(r.bottom-r.top);
				h=(h<v)?h:v;
				hRgn1=CreateRoundRectRgn(0,0,(r.right-r.left+1),(r.bottom-r.top+1),h,h);
				SetWindowRgn(hwndDlg,hRgn1,1);
			}
			else {
				HRGN hRgn1;
				RECT r;
				int v,h;
				int w=10;
				GetWindowRect(hwndDlg,&r);
				h=(r.right-r.left)>(w*2)?w:(r.right-r.left);
				v=(r.bottom-r.top)>(w*2)?w:(r.bottom-r.top);
				h=(h<v)?h:v;
				hRgn1=CreateRectRgn(0,0,(r.right-r.left+1),(r.bottom-r.top+1));
				SetWindowRgn(hwndDlg,hRgn1,1);
			}
			// transparency
		
#ifdef WS_EX_LAYERED 
			SetWindowLongPtr(hwndDlg, GWL_EXSTYLE, GetWindowLongPtr(hwndDlg, GWL_EXSTYLE) | WS_EX_LAYERED);
#endif
#ifdef LWA_ALPHA
			SetLayeredWindowAttributes(hwndDlg, RGB(0,0,0), (int)((100 - opt->aw_trans) / 100.0 * 255), LWA_ALPHA);
#endif
		}
		return TRUE;

	case WMU_SETALARM:
		{
			ALARM *data = (ALARM *)lParam;
			SetWindowText(hwndDlg, data->szTitle);
			HWND hw = GetDlgItem(hwndDlg, IDC_TITLE);
			SetWindowText(hw, data->szTitle);

			SetDlgItemText(hwndDlg, IDC_ED_DESC, data->szDesc);
			((WindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA))->alarm = data;

			if (data->action & AAF_SOUND && options.loop_sound) {
				if (data->sound_num <= 3)
					SetTimer(hwndDlg, ID_TIMER_SOUND, SOUND_REPEAT_PERIOD, 0);	
				else if (data->sound_num == 4) 
					SetTimer(hwndDlg, ID_TIMER_SOUND, SPEACH_REPEAT_PERIOD, 0);	
			}

			hw = GetDlgItem(hwndDlg, IDC_SNOOZE);
			EnableWindow(hw, !(data->flags & ALF_NOSNOOZE));
			ShowWindow(hw, (data->flags & ALF_NOSNOOZE) ? SW_HIDE : SW_SHOWNA);
		}
		return TRUE;

	case WMU_FAKEALARM:
		{
			SetWindowText(hwndDlg, TranslateT("Example alarm"));
			SetDlgItemText(hwndDlg, IDC_TITLE, TranslateT("Example alarm"));
			SetDlgItemText(hwndDlg, IDC_ED_DESC, TranslateT("Some example text. Example, example, example."));
		}
		return TRUE;

	case WM_TIMER: 
		if (wParam == ID_TIMER_SOUND) {
			WindowData *dw = (WindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			if (dw) {
				ALARM *data = dw->alarm;
				if (data && data->action & AAF_SOUND) {
					if (data->sound_num <= 3) {
						char buff[128];
						mir_snprintf(buff, SIZEOF(buff), "Triggered%d", data->sound_num);
						SkinPlaySound(buff);
					}
					else if (data->sound_num == 4) {
						if (data->szTitle != NULL && data->szTitle[0] != '\0') {
							if (ServiceExists("Speak/Say")) {
								CallService("Speak/Say", 0, (LPARAM)data->szTitle);
							}
						}
					}
				}
			}
		}
		return TRUE;

	case WM_MOVE:
		Utils_SaveWindowPosition(hwndDlg, 0, MODULE, "Notify");
		break;

	case WMU_ADDSNOOZER:
		{
			WindowData *wd = (WindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			if (wd) {
				ALARM *data = wd->alarm;

				if (data) {
					// add snooze minutes to current time
					FILETIME ft;
					GetLocalTime(&data->time);
					SystemTimeToFileTime(&data->time, &ft);
					ULARGE_INTEGER uli;
					uli.LowPart = ft.dwLowDateTime;
					uli.HighPart = ft.dwHighDateTime;

					// there are 10000000 100-nanosecond blocks in a second...
					uli.QuadPart += mult.QuadPart * (int)(wParam);

					ft.dwHighDateTime = uli.HighPart;
					ft.dwLowDateTime = uli.LowPart;

					FileTimeToSystemTime(&ft, &data->time);

					data->occurrence = OC_ONCE;
					data->snoozer = true;
					data->flags = data->flags & ~ALF_NOSTARTUP;

					data->id = next_alarm_id++;

					append_to_list(data);
				}
			}
		}
		return TRUE;

	case WM_COMMAND:
		if ( HIWORD( wParam ) == BN_CLICKED ) {
			switch( LOWORD( wParam )) {
			case IDCANCEL:  // no button - esc pressed
			case IDOK:		// space?
			case IDC_SNOOZE:
				SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)options.snooze_minutes, 0);
				//drop through
			case IDC_DISMISS:
				{
					WindowData *window_data = (WindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
					KillTimer(hwndDlg, ID_TIMER_SOUND);
					if (window_data) {
						if (window_data->alarm) {
							free_alarm_data(window_data->alarm);
							delete window_data->alarm;
						}
						delete window_data;
					}
					SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);

					win_num--;
					//EndDialog(hwndDlg, IDOK); // not modal!
					WindowList_Remove(hAlarmWindowList, hwndDlg);
					DestroyWindow(hwndDlg);
				}
				break;
			case IDC_SNOOZELIST:
				{
					POINT pt, pt_rel;
					GetCursorPos(&pt);				
					pt_rel = pt;
					ScreenToClient(hwndDlg,&pt_rel);

					HMENU hMenu = CreatePopupMenu();
					MENUITEMINFO mmi = {0};
					mmi.cbSize = sizeof(mmi);
					mmi.fMask = MIIM_ID | MIIM_STRING;

#define AddItem(x)							\
		mmi.wID++;							\
		mmi.dwTypeData = TranslateT(x);		\
		mmi.cch = ( UINT )mir_tstrlen(mmi.dwTypeData);	\
		InsertMenuItem(hMenu, mmi.wID, FALSE, &mmi);

					AddItem(LPGEN("5 mins"));
					AddItem(LPGEN("15 mins"));
					AddItem(LPGEN("30 mins"));
					AddItem(LPGEN("1 hour"));
					AddItem(LPGEN("1 day"));
					AddItem(LPGEN("1 week"));

					TPMPARAMS tpmp = {0};
					tpmp.cbSize	= sizeof(tpmp);
					LRESULT ret = (LRESULT)TrackPopupMenuEx(hMenu, TPM_RETURNCMD, pt.x, pt.y, hwndDlg, &tpmp);
					switch(ret) {
						case 0: DestroyMenu(hMenu); return 0; // dismis menu
						case 1: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)5, 0); break;
						case 2: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)15, 0); break;
						case 3: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)30, 0); break;
						case 4: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)60, 0); break;
						case 5: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)(60 * 24), 0); break;
						case 6: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)(60 * 24 * 7), 0); break;
					}

					DestroyMenu(hMenu);

					SendMessage(hwndDlg, WM_COMMAND, IDC_DISMISS, 0);
				}
				break;
			}
		}
		return TRUE;

	case WM_MOUSEMOVE:
		if (wParam & MK_LBUTTON) {
			SetCapture(hwndDlg);

			POINT newp;
			newp.x = (short)LOWORD(lParam);
			newp.y = (short)HIWORD(lParam);

			ClientToScreen(hwndDlg, &newp);

			WindowData *window_data = (WindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			if (!window_data->moving)
				window_data->moving = true;
			else {
				RECT r;
				GetWindowRect(hwndDlg, &r);
				
				SetWindowPos(hwndDlg, 0, r.left + (newp.x - window_data->p.x), r.top + (newp.y - window_data->p.y), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
			}
			window_data->p.x = newp.x;
			window_data->p.y = newp.y;			
		}
		else {
			ReleaseCapture();
			WindowData *window_data = (WindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			window_data->moving = false;
		}
		return TRUE;
	}

	return FALSE;
}
Esempio n. 30
0
void
MyString::append_to_list(MyString const &str,char const *delim /* ="," */) {
	append_to_list(str.Value(),delim);
}