void get_tetri(t_all *all) { DIR *dir_info; struct dirent *file_info; t_t_info *info; unsigned int nb; nb = 0; dir_info = opendir("tetriminos"); if (dir_info == NULL) exit(84); file_info = readdir(dir_info); file_info = readdir(dir_info); start_list(&all->list_tetri); while ((file_info = readdir(dir_info))) { info = malloc(sizeof(t_t_info)); get_tetrimino_data(file_info->d_name, info); make_top(&all->list_tetri, info, nb); free(info); nb++; } if (!all->list_tetri.first && !all->list_tetri.last) exit(84); }
void clear_list(){ column *p; column *q; for(p = select_attributes; p != NULL;){ q = p->next; free(p); p = q; } start_list(); }
/** @brief The main function * * @param argc the number of arguments passed to the main function * @param argv the arguments passed to the main function * @return the finishing status of the funcion */ int main(int argc, char *argv[]){ if(argc == 2){ start_list(); populate_list(argv[1]); print_list(); printf("The index of the middle cell is %d\n", recursive_middle_search(-1,-1)); return 0; } else if(argc != 1){ fprintf(stderr, "Bad argumet\n"); } printf("Usage:\n./main <list>\n"); return 1; }
// get the field location of a field in the message properties (if it exists, // else 0). static qd_field_location_t *qd_message_properties_field(qd_message_t *msg, qd_message_field_t field) { static const intptr_t offsets[] = { // position of the field's qd_field_location_t in the message content // object (intptr_t) &((qd_message_content_t *)0)->field_message_id, (intptr_t) &((qd_message_content_t *)0)->field_user_id, (intptr_t) &((qd_message_content_t *)0)->field_to, (intptr_t) &((qd_message_content_t *)0)->field_subject, (intptr_t) &((qd_message_content_t *)0)->field_reply_to, (intptr_t) &((qd_message_content_t *)0)->field_correlation_id }; // update table above if new fields need to be accessed: assert(QD_FIELD_MESSAGE_ID <= field && field <= QD_FIELD_CORRELATION_ID); qd_message_content_t *content = MSG_CONTENT(msg); if (!content->section_message_properties.parsed) { if (!qd_message_check(msg, QD_DEPTH_PROPERTIES) || !content->section_message_properties.parsed) return 0; } if (field == QD_FIELD_PROPERTIES) return &content->section_message_properties; const int index = field - QD_FIELD_MESSAGE_ID; qd_field_location_t *const location = (qd_field_location_t *)((char *)content + offsets[index]); if (location->parsed) return location; // requested field not parsed out. Need to parse out up to the requested field: qd_buffer_t *buffer = content->section_message_properties.buffer; unsigned char *cursor = qd_buffer_base(buffer) + content->section_message_properties.offset; advance(&cursor, &buffer, content->section_message_properties.hdr_length, 0, 0); if (index >= start_list(&cursor, &buffer)) return 0; // properties list too short int position = 0; while (position < index) { qd_field_location_t *f = (qd_field_location_t *)((char *)content + offsets[position]); if (f->parsed) advance(&cursor, &buffer, f->hdr_length + f->length, 0, 0); else // parse it out if (!traverse_field(&cursor, &buffer, f)) return 0; position++; } // all fields previous to the target have now been parsed and cursor/buffer // are in the correct position, parse out the field: if (traverse_field(&cursor, &buffer, location)) return location; return 0; }