int main() { const char *query_string = getenv("QUERY_STRING"); if (query_string == NULL) { generatepage("Internal error: invalid request"); return EXIT_SUCCESS; } if (NULL != validate_name_version(query_string)) { generatepage(validate_name_version(query_string)); return EXIT_SUCCESS; } char *data[MAX_RECORDS] = {0}; if (!readdata(data, MAX_RECORDS)) { generatepage("Failed to delete file, try again"); return EXIT_SUCCESS; } sortdata(data, MAX_RECORDS); char name[MAX_NAME_LEN] = {0}; strcpy(name, getname(query_string)); int index = -1; for (int i = 0; i < MAX_RECORDS && data[i]; i++) { if (strcmp(name, getname(data[i])) == 0) { index = i; break; } } if (index == -1) { generatepage("File not found"); return EXIT_SUCCESS; } FILE *f = fopen("data.txt", "wt"); if (f == NULL) { generatepage("Failed to delete file (access denied)"); return EXIT_SUCCESS; } int deleted = 0; for (int i = 0; i < MAX_RECORDS && data[i]; i++) { if (i != index) fprintf(f, "%s\n", data[i]); else deleted = 1; } fclose(f); generatepage(deleted ? "File deleted" : "Failed to delete file"); return EXIT_SUCCESS; }
void CMuleListCtrl::SortList() { if (!IsSorting() && (m_sort_func && GetColumnCount())) { m_isSorting = true; MuleSortData sortdata(m_sort_orders, m_sort_func); // In many cases control already has correct order, and sorting causes nasty flickering. // Make one pass through it to check if sorting is necessary at all. int nrItems = GetItemCount(); bool clean = true; long lastItemdata = 0; if (nrItems > 1) { lastItemdata = GetItemData(0); } for (int i = 1; i < nrItems; i++) { long nextItemdata = GetItemData(i); if (SortProc(lastItemdata, nextItemdata, (long int)&sortdata) > 0) { // ok - we need to sort clean = false; break; } lastItemdata = nextItemdata; } if (clean) { // no need to sort m_isSorting = false; return; } // Positions are likely to be invalid after sorting. ResetTTS(); // Store the current selected items ItemDataList selectedItems = GetSelectedItems(); // Store the focused item long pos = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED ); wxUIntPtr focused = (pos == -1) ? 0 : GetItemData(pos); SortItems(SortProc, (long int)&sortdata); // Re-select the selected items. for (unsigned i = 0; i < selectedItems.size(); ++i) { long it_pos = FindItem(-1, selectedItems[i]); if (it_pos != -1) { SetItemState(it_pos, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } } // Set focus on item if any was focused if (focused) { long it_pos = FindItem(-1, focused); if (it_pos != -1) { SetItemState(it_pos, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); } } m_isSorting = false; } }