int valueEquals(Value *v1, Value *v2) { if (v1 == v2) return 1; if (v1->type != v2->type) return 0; switch (v1->type) { case INT_VALUE_TYPE: case ENV_VALUE_TYPE: case BUILTIN_FUN_VALUE_TYPE: case CLOSURE_VALUE_TYPE: return v1->data == v2->data; case LIST_VALUE_TYPE: { List *l1 = v1->data; List *l2 = v2->data; int len = listSize(l1); int i; if (len != listSize(l2)) return 0; for (i = 0; i < len; i++) if (!valueEquals(listGet(l1, i), listGet(l2, i))) return 0; return 1; } case STRING_VALUE_TYPE: return strcmp((char *)v1->data, (char *)v2->data) == 0; case NONE_VALUE_TYPE: return 1; // singleton, same type means equal default: error("unknown value type passed to valueEquals: %d\n", v1->type); } }
static int valueToStringInternal(Value *v, char *s, int n) { Node *t; int i; switch (v->type) { case BUILTIN_FUN_VALUE_TYPE: return mySnprintf(s, n, "<builtin-function@%p>", v->data); case NONE_VALUE_TYPE: return mySnprintf(s, n, "none"); case INT_VALUE_TYPE: return mySnprintf(s, n, "%d", v->data); case CLOSURE_VALUE_TYPE: { int len = 0; Node *f = ((Closure *)v->data)->f; len += mySnprintf(s + len, n - len, "fun %s(", getStrId((long)chld(f, 0)->data)); t = chld(f, 1); for (i = 0; i < chldNum(t); i++) { if (i) { len += mySnprintf(s + len, n - len, ", "); } len += mySnprintf(s + len, n - len, "%s", getStrId((long)chld(t, i)->data)); } len += mySnprintf(s + len, n - len, ")"); return len; } case LIST_VALUE_TYPE: { int len = 0; List *l = v->data; len += mySnprintf(s + len, n - len, "["); for (i = 0; i < listSize(l); i++) { if (i) { len += mySnprintf(s + len, n - len, ", "); } len += valueToStringInternal(listGet(l, i), s + len, n - len); } len += mySnprintf(s + len, n - len, "]"); return len; } case STRING_VALUE_TYPE: { return mySnprintf(s, n, "%s", v->data); } case ENV_VALUE_TYPE: { List *keys = envGetAllIds(v->data); int len = 0; len += mySnprintf(s, n, "env parent->%p { ", getEnvFromValue(v)->parent); int keyN = listSize(keys); for (i = 0; i < keyN; i++) { long key = (long)listGet(keys, i); len += mySnprintf(s + len, n - len, "%s->%p ", getStrId(key), envGet(v->data, key)); } len += mySnprintf(s + len, n - len, "}"); freeList(keys); return len; } default: error("cannot print unknown value type: %d at %p\n", v->type, v); } }
int valueCmp(Value *v1, Value *v2) { if (v1->type != v2->type) { return -1; // comparing different type } if (v1 == v2) { return 0; } switch (v1->type) { case LIST_VALUE_TYPE: { List *l1 = v1->data, *l2 = v2->data; int i, n1 = listSize(l1), n2 = listSize(l2); for (i = 0; i < n1 && i < n2; i++) { int res = valueCmp(listGet(l1, i), listGet(l2, i)); if (res) return res; } if (n1 == n2) return 0; else if (n1 < n2) return -1; else return 1; } case STRING_VALUE_TYPE: return strcmp(v1->data, v2->data); case CLOSURE_VALUE_TYPE: case ENV_VALUE_TYPE: case BUILTIN_FUN_VALUE_TYPE: case INT_VALUE_TYPE: return (long)(v1->data) - (long)(v2->data); case NONE_VALUE_TYPE: return 0; default: error("cannot compare unknown type: %d\n", v1->type); } }
static void assemble(pPdf417class p, pArrayList list) { int k; if (list->size == 0) return; p->cwPtr = 1; for (k = 0; k < list->size; ++k) { pListElement v = listGet(list, k); switch (v->type) { case 'T': if (k != 0) p->param->codewords[p->cwPtr++] = TEXT_MODE; textCompaction(p, v->start, v->end - v->start); break; case 'N': p->param->codewords[p->cwPtr++] = NUMERIC_MODE; numberCompaction(p, v->start, v->end - v->start); break; case 'B': p->param->codewords[p->cwPtr++] = (v->end - v->start) % 6 ? BYTE_MODE : BYTE_MODE_6; byteCompaction(p, v->start, v->end - v->start); break; } if (p->param->error) return; } }
// GLUT callback for rendering. // Draws all the control points in l, their connecting lines and the curve as specified by the user. // Ends by printing a description of the current curve to the screen. void display() { struct list * tmp = l; float x, y; float t; glClear(GL_COLOR_BUFFER_BIT); glColor3ub(127, 127, 127); glBegin(GL_LINE_STRIP); tmp = l; while (tmp) { glVertex2f(tmp->x, tmp->y); tmp = tmp->next; } glEnd(); glColor3ub(255, 0, 0); glBegin(GL_POINTS); tmp = l; while (tmp) { glVertex2f(tmp->x, tmp->y); tmp = tmp->next; } glEnd(); glColor3ub(0, 0, 0); glBegin(GL_LINE_STRIP); tmp = l; if (bezier) { while (tmp && listCount(tmp) > order) { for (t = 0.0f; t <= 1.0f; t+=0.01f) { computeNOrderBezierlf(order, tmp, t, &x, &y); glVertex2f(x, y); } tmp = listGet(tmp, order); } } else { for (t = knot[order]; t <= knot[count]; t+=0.01f) { computeNOrderBsplinelf(order + 1, l, t, knot, &x, &y); glVertex2f(x, y); } } glEnd(); printHelpglut(); glutSwapBuffers(); }
int listRemoveN(List root, int n) { List element = listGet(root, n); if (element == NULL) return 0; /* out-of-list exception */ listRemove(root, element); return 1; }
static void dumpList(pPdf417class p, pArrayList list) { int k; if (list->size == 0) return; for (k = 0; k < list->size; ++k) { pListElement v = listGet(list, k); printf("%c%.*s\n", v->type, v->end - v->start, p->param->text + v->start); } }
//取得子結點 void* node_get(list *mList, short value, struct node *tmp) { listStart(mList); while(listNext(mList)) { tmp = listGet(mList); if(tmp->no == value) return tmp; } return NULL; }
void save_help_olc(HELP_OLC *data) { // first, remove our old helpfile from disc LIST *kwds = parse_keywords(data->old_keywords); char *primary = listGet(kwds, 0); if(primary && *primary) remove_help(primary); deleteListWith(kwds, free); // now, add our new one add_help(data->keywords, bufferString(data->info), data->user_groups, data->related, TRUE); }
void stPrintBlocks(symtable *st, unsigned int n) { int i = listSize(st->blockList) - 1; while (i >= 0 && n > 0) { block *b = (block *) listGet(st->blockList, i); fprintf(stdout, "Block %d: %.*s\n", i, stringGetLength(b->name), stringGetBuffer(b->name)); bstPrint(b->symbols, bstPrintSymbol); i--; n--; } }
void conditional_parrern_base(struct node *fptree, struct header_table *htable, int *item_index, char *generate_string) { struct frequent_patterns *fp = malloc(sizeof(struct frequent_patterns)); struct frequent_patterns *fp_head = malloc(sizeof(struct frequent_patterns)); struct node *now_node = malloc(sizeof(struct node)); int ptr_index; fp_head = fp; fp->next = NULL; while(htable != NULL) { if(generate_string != "") printf("%s", generate_string); listStart(htable->cond); while(listNext(htable->cond)) { now_node = listGet(htable->cond); if(fp->next == NULL && fp->counter != 0) { struct frequent_patterns *new_fp = malloc(sizeof(struct frequent_patterns)); new_fp->ptr = malloc(sizeof(short) * MIN_SUPPORT_INDEX); new_fp->htable_value = htable->no; fp->next = new_fp; fp = new_fp; } else if(fp->next != NULL) { fp = fp->next; } fp->counter = now_node->counter; fp->htable_value = htable->no; ptr_index = 0; while(now_node->parent != NULL) { *(fp->ptr + ptr_index) = now_node->no; ptr_index++; now_node = now_node->parent; } fp->index = ptr_index; } struct header_table *sub_htable = malloc(sizeof(struct header_table)); struct node *sub_tree = malloc(sizeof(struct node)); sub_tree = create_sub_fptree(); //sub_tree = build_sub_tree(sub_tree, sub_htable, fp_head, htable->no, item_index); if(sub_tree->child != NULL) { conditional_parrern_base(sub_tree, sub_htable, item_index, myString_cat(generate_string, htable->no)); } htable = htable->prev; } }
int bedit_chooser(SOCKET_DATA *sock, BITVECTOR *vector, const char *option) { if(!isdigit(*option)) return MENU_CHOICE_INVALID; else { int choice = atoi(option); if(choice < 0 || choice >= bitvectorSize(vector)) return MENU_CHOICE_INVALID; else { LIST *bits = bitvectorListBits(vector); char *bit = listGet(bits, choice); bitToggle(vector, bit); deleteListWith(bits, free); return MENU_NOCHOICE; } } }
//深度優先搜尋法 void dfs(struct node *root) { struct node *current = malloc(sizeof(struct node)); current = root; //printf("%d ", current->no); if(root->child == NULL) { free(current); return; } listStart(root->child); while(listNext(current->child)) { node_tmp = listGet(current->child); dfs(node_tmp); } free(current); }
symbol *stLookup(symtable *st, string *name, unsigned int *level) { symbol *ret; //TODO: create iterator for lists? for (unsigned int i = listSize(st->blockList)-1; i >= 0; i--) { symbol *test = symbolCreate(name); ret = (symbol *) bstGet(((block *) listGet(st->blockList, i))->symbols, test); symbolDestroy(test); if (ret != NULL) { if (level != NULL) *level = i; return ret; } } return NULL; }
void listTest(void) { List *list; int i; list = createList(); printf("delete when list is empty\n"); listDelete(list, 0); printf("insert 0\n"); listInsert(list, 0, 0); listTraverse(list); printf("delect position:0\n"); listDelete(list, 0); listTraverse(list); printf("insert 5 element to list\n"); for(i = 0; i < 5; i++) { listInsert(list, 5 - i, 0); } listTraverse(list); printf("insert 55 to position 3\n"); listInsert(list, 55, 3); listTraverse(list); printf("delete first tree element\n"); for(i = 0; i < 3; i++) { listDelete(list, 0); } listTraverse(list); printf("delete position 1\n"); listDelete(list, 1); listTraverse(list); printf("get position 3\n"); printf("postion 3:%d\n", listGet(list, 3)); destroyList(list); }
void renderList(sLinkedList* list, sSdlWrapper* wrap) { Uint32 bg = makeColor(255, 50, 25, 175); Uint32 fg = makeColor(255, 75, 50, 200); if(listEmpty(list)) return; sListIterator* it = 0; listHead(list, &it); point* toDraw = 0; int x = 0; int y = 0; while(!listIteratorEnd(it)) { toDraw = (point*)listGet(it); pointGetPos(toDraw, &x, &y); drawBevel(wrap, x*25, y*25, 25, 25, bg, fg); listIteratorNext(it); } free(it); }
Value *valueAdd(Value *v1, Value *v2) { switch (v1->type) { case INT_VALUE_TYPE: switch (v2->type) { case INT_VALUE_TYPE: return newIntValue((long)v1->data + (long)v2->data); default: error("int can only add to int\n"); } case LIST_VALUE_TYPE: { List *res = listCopy(v1->data); int i; assert(v2->type == LIST_VALUE_TYPE); List *l = v2->data; for (i = 0; i < listSize(l); i++) { listPush(res, listGet(l, i)); } return newListValue(res); } case STRING_VALUE_TYPE: { if (v2->type == STRING_VALUE_TYPE) { char *s1 = (char *)v1->data, *s2 = (char *)v2->data; char *res = (char *)tlMalloc(strlen(s1) + strlen(s2) + 1); *res = 0; strcat(res, s1); strcat(res, s2); return newStringValue(res); } else { error("can only add string to string\n"); } } case CLOSURE_VALUE_TYPE: error("Closure value cannot add to anything\n"); case ENV_VALUE_TYPE: error("Environment value cannot add to anything\n"); default: error("unknown value type passed to valueAdd: %d\n", v1->type); } return 0; // never reach here }
void* queueFront(Queue queue) { if (!queueIsEmpty(queue)) return listGet(queue->queue, 0); }
List *listCopy(List *lst) { List *res = newList(); int i, len = lst->size; for (i = 0; i < len; i++) listPush(res, listGet(lst, i)); return res; }
static void breakString(pPdf417class p, pArrayList list) { char* text = p->param->text; int textLength = p->param->lenText; int lastP = 0; int startN = 0; int nd = 0; char c = 0; int k, ptrS, lastTxt, j, txt; pListElement v; pListElement vp; pListElement vn; list->size = 0; for (k = 0; k < textLength; ++k) { c = text[k]; if (c >= '0' && c <= '9') { if (nd == 0) startN = k; ++nd; continue; } if (nd >= 13) { if (lastP != startN) { c = text[lastP]; ptrS = lastP; lastTxt = (c >= ' ' && c < 127) || c == '\r' || c == '\n' || c == '\t'; for (j = lastP; j < startN; ++j) { c = text[j]; txt = (c >= ' ' && c < 127) || c == '\r' || c == '\n' || c == '\t'; if (txt != lastTxt) { listAdd(list, (char)(lastTxt ? 'T' : 'B'), lastP, j); lastP = j; lastTxt = txt; } } listAdd(list, (char)(lastTxt ? 'T' : 'B'), lastP, startN); } listAdd(list, 'N', startN, k); lastP = k; } nd = 0; } if (nd < 13) startN = textLength; if (lastP != startN) { c = text[lastP]; ptrS = lastP; lastTxt = (c >= ' ' && c < 127) || c == '\r' || c == '\n' || c == '\t'; for (j = lastP; j < startN; ++j) { c = text[j]; txt = (c >= ' ' && c < 127) || c == '\r' || c == '\n' || c == '\t'; if (txt != lastTxt) { listAdd(list, (char)(lastTxt ? 'T' : 'B'), lastP, j); lastP = j; lastTxt = txt; } } listAdd(list, (char)(lastTxt ? 'T' : 'B'), lastP, startN); } if (nd >= 13) listAdd(list, 'N', startN, textLength); //optimize //merge short binary for (k = 0; k < list->size; ++k) { v = listGet(list, k); vp = listGet(list, k - 1); vn = listGet(list, k + 1);; if (checkElementType(v, 'B') && getElementLength(v) == 1) { if (checkElementType(vp, 'T') && checkElementType(vn, 'T') && getElementLength(vp) + getElementLength(vn) >= 3) { vp->end = vn->end; listRemove(list, k); listRemove(list, k); k = -1; continue; } } } //merge text sections for (k = 0; k < list->size; ++k) { v = listGet(list, k); vp = listGet(list, k - 1); vn = listGet(list, k + 1);; if (checkElementType(v, 'T') && getElementLength(v) >= 5) { int redo = 0; if ((checkElementType(vp, 'B') && getElementLength(vp) == 1) || checkElementType(vp, 'T')) { redo = 1; v->start = vp->start; listRemove(list, k - 1); --k; } if ((checkElementType(vn, 'B') && getElementLength(vn) == 1) || checkElementType(vn, 'T')) { redo = 1; v->end = vn->end; listRemove(list, k + 1); } if (redo) { k = -1; continue; } } } //merge binary sections for (k = 0; k < list->size; ++k) { v = listGet(list, k); vp = listGet(list, k - 1); vn = listGet(list, k + 1);; if (checkElementType(v, 'B')) { int redo = 0; if ((checkElementType(vp, 'T') && getElementLength(vp) < 5) || checkElementType(vp, 'B')) { redo = 1; v->start = vp->start; listRemove(list, k - 1); --k; } if ((checkElementType(vn, 'T') && getElementLength(vn) < 5) || checkElementType(vn, 'B')) { redo = 1; v->end = vn->end; listRemove(list, k + 1); } if (redo) { k = -1; continue; } } } // check if all numbers if (list->size == 1 && (v = listGet(list, 0))->type == 'T' && getElementLength(v) >= 8) { for (k = v->start; k < v->end; ++k) { c = text[k]; if (c < '0' || c > '9') break; } if (k == v->end) v->type = 'N'; } }
never_inline s32 savedata_op( PPUThread& CPU, u32 operation, u32 version, vm::cptr<char> dirName, u32 errDialog, vm::ptr<CellSaveDataSetList> setList, vm::ptr<CellSaveDataSetBuf> setBuf, vm::ptr<CellSaveDataListCallback> funcList, vm::ptr<CellSaveDataFixedCallback> funcFixed, vm::ptr<CellSaveDataStatCallback> funcStat, vm::ptr<CellSaveDataFileCallback> funcFile, u32 container, u32 unknown, // 0, 2, 6 vm::ptr<void> userdata, u32 userId, vm::ptr<CellSaveDataDoneCallback> funcDone) { // TODO: check arguments // try to lock the mutex (not sure how it originally works; std::try_to_lock makes it non-blocking) std::unique_lock<std::mutex> lock(g_savedata_dialog->mutex, std::try_to_lock); if (!lock) { return CELL_SAVEDATA_ERROR_BUSY; } // path of the specified user (00000001 by default) const std::string base_dir = fmt::format("/dev_hdd0/home/%08d/savedata/", userId ? userId : 1u); vm::stackvar<CellSaveDataCBResult> result(CPU); result->userdata = userdata; // probably should be assigned only once (allows the callback to change it) SaveDataEntry save_entry; if (setList) { std::vector<SaveDataEntry> save_entries; vm::stackvar<CellSaveDataListGet> listGet(CPU); listGet->dirNum = 0; listGet->dirListNum = 0; listGet->dirList.set(setBuf->buf.addr()); memset(listGet->reserved, 0, sizeof(listGet->reserved)); const auto prefix_list = fmt::split(setList->dirNamePrefix.get_ptr(), { "|" }); for (const auto entry : vfsDir(base_dir)) { if (entry->flags & DirEntry_TypeFile) { continue; } for (const auto& prefix : prefix_list) { if (entry->name.substr(0, prefix.size()) == prefix) { // Count the amount of matches and the amount of listed directories if (listGet->dirListNum++ < setBuf->dirListMax) { listGet->dirNum++; // PSF parameters vfsFile f(base_dir + entry->name + "/PARAM.SFO"); const PSFLoader psf(f); if (!psf) { break; } SaveDataEntry save_entry2; save_entry2.dirName = psf.GetString("SAVEDATA_DIRECTORY"); save_entry2.listParam = psf.GetString("SAVEDATA_LIST_PARAM"); save_entry2.title = psf.GetString("TITLE"); save_entry2.subtitle = psf.GetString("SUB_TITLE"); save_entry2.details = psf.GetString("DETAIL"); save_entry2.size = 0; for (const auto entry2 : vfsDir(base_dir + entry->name)) { save_entry2.size += entry2->size; } save_entry2.atime = entry->access_time; save_entry2.mtime = entry->modify_time; save_entry2.ctime = entry->create_time; //save_entry2.iconBuf = NULL; // TODO: Here should be the PNG buffer //save_entry2.iconBufSize = 0; // TODO: Size of the PNG file save_entry2.isNew = false; save_entries.push_back(save_entry2); } break; } } } // Sort the entries { const u32 order = setList->sortOrder; const u32 type = setList->sortType; if (order > CELL_SAVEDATA_SORTORDER_ASCENT || type > CELL_SAVEDATA_SORTTYPE_SUBTITLE) { // error } std::sort(save_entries.begin(), save_entries.end(), [=](const SaveDataEntry& entry1, const SaveDataEntry& entry2) { if (order == CELL_SAVEDATA_SORTORDER_DESCENT && type == CELL_SAVEDATA_SORTTYPE_MODIFIEDTIME) { return entry1.mtime >= entry2.mtime; } if (order == CELL_SAVEDATA_SORTORDER_DESCENT && type == CELL_SAVEDATA_SORTTYPE_SUBTITLE) { return entry1.subtitle >= entry2.subtitle; } if (order == CELL_SAVEDATA_SORTORDER_ASCENT && type == CELL_SAVEDATA_SORTTYPE_MODIFIEDTIME) { return entry1.mtime < entry2.mtime; } if (order == CELL_SAVEDATA_SORTORDER_ASCENT && type == CELL_SAVEDATA_SORTTYPE_SUBTITLE) { return entry1.subtitle < entry2.subtitle; } return true; }); } // Fill the listGet->dirList array auto dir_list = listGet->dirList.get_ptr(); for (const auto& entry : save_entries) { auto& dir = *dir_list++; strcpy_trunc(dir.dirName, entry.dirName); strcpy_trunc(dir.listParam, entry.listParam); memset(dir.reserved, 0, sizeof(dir.reserved)); } s32 selected = -1; if (funcList) { vm::stackvar<CellSaveDataListSet> listSet(CPU); // List Callback funcList(CPU, result, listGet, listSet); if (result->result < 0) { return CELL_SAVEDATA_ERROR_CBRESULT; } // Clean save data list save_entries.erase(std::remove_if(save_entries.begin(), save_entries.end(), [&listSet](const SaveDataEntry& entry) -> bool { for (u32 i = 0; i < listSet->fixedListNum; i++) { if (entry.dirName == listSet->fixedList[i].dirName) { return false; } } return true; }), save_entries.end()); // Focus save data s32 focused = -1; switch (const u32 pos_type = listSet->focusPosition) { case CELL_SAVEDATA_FOCUSPOS_DIRNAME: { for (s32 i = 0; i < save_entries.size(); i++) { if (save_entries[i].dirName == listSet->focusDirName.get_ptr()) { focused = i; break; } } break; } case CELL_SAVEDATA_FOCUSPOS_LISTHEAD: { focused = save_entries.empty() ? -1 : 0; break; } case CELL_SAVEDATA_FOCUSPOS_LISTTAIL: { focused = save_entries.size() - 1; break; } case CELL_SAVEDATA_FOCUSPOS_LATEST: { s64 max = INT64_MIN; for (s32 i = 0; i < save_entries.size(); i++) { if (save_entries[i].mtime > max) { focused = i; max = save_entries[i].mtime; } } break; } case CELL_SAVEDATA_FOCUSPOS_OLDEST: { s64 min = INT64_MAX; for (s32 i = 0; i < save_entries.size(); i++) { if (save_entries[i].mtime < min) { focused = i; min = save_entries[i].mtime; } } break; } case CELL_SAVEDATA_FOCUSPOS_NEWDATA: { break; } default: { cellSysutil.Error("savedata_op(): unknown listSet->focusPosition (0x%x)", pos_type); return CELL_SAVEDATA_ERROR_PARAM; } } // Display Save Data List selected = g_savedata_dialog->ShowSaveDataList(save_entries, focused, listSet); if (selected == -1) { if (listSet->newData) { save_entry.dirName = listSet->newData->dirName.get_ptr(); } else { return CELL_OK; // ??? } } } if (funcFixed) { vm::stackvar<CellSaveDataFixedSet> fixedSet(CPU); // Fixed Callback funcFixed(CPU, result, listGet, fixedSet); if (result->result < 0) { return CELL_SAVEDATA_ERROR_CBRESULT; } for (s32 i = 0; i < save_entries.size(); i++) { if (save_entries[i].dirName == fixedSet->dirName.get_ptr()) { selected = i; break; } } if (selected == -1) { save_entry.dirName = fixedSet->dirName.get_ptr(); } } if (selected >= 0) { if (selected < save_entries.size()) { save_entry.dirName = std::move(save_entries[selected].dirName); } else { throw EXCEPTION("Invalid savedata selected"); } } } if (dirName) { save_entry.dirName = dirName.get_ptr(); } std::string dir_path = base_dir + save_entry.dirName + "/"; std::string sfo_path = dir_path + "PARAM.SFO"; PSFLoader psf; // Load PARAM.SFO { vfsFile f(sfo_path); psf.Load(f); } // Get save stats { vm::stackvar<CellSaveDataStatGet> statGet(CPU); vm::stackvar<CellSaveDataStatSet> statSet(CPU); std::string dir_local_path; Emu.GetVFS().GetDevice(dir_path, dir_local_path); fs::stat_t dir_info; if (!fs::stat(dir_local_path, dir_info)) { // error } statGet->hddFreeSizeKB = 40 * 1024 * 1024; // 40 GB statGet->isNewData = save_entry.isNew = !psf; statGet->dir.atime = save_entry.atime = dir_info.atime; statGet->dir.mtime = save_entry.mtime = dir_info.mtime; statGet->dir.ctime = save_entry.ctime = dir_info.ctime; strcpy_trunc(statGet->dir.dirName, save_entry.dirName); statGet->getParam.attribute = psf.GetInteger("ATTRIBUTE"); // ??? strcpy_trunc(statGet->getParam.title, save_entry.title = psf.GetString("TITLE")); strcpy_trunc(statGet->getParam.subTitle, save_entry.subtitle = psf.GetString("SUB_TITLE")); strcpy_trunc(statGet->getParam.detail, save_entry.details = psf.GetString("DETAIL")); strcpy_trunc(statGet->getParam.listParam, save_entry.listParam = psf.GetString("SAVEDATA_LIST_PARAM")); statGet->bind = 0; statGet->sizeKB = save_entry.size / 1024; statGet->sysSizeKB = 0; // This is the size of system files, but PARAM.SFO is very small and PARAM.PDF is not used statGet->fileNum = 0; statGet->fileList.set(setBuf->buf.addr()); statGet->fileListNum = 0; memset(statGet->reserved, 0, sizeof(statGet->reserved)); auto file_list = statGet->fileList.get_ptr(); for (const auto entry : vfsDir(dir_path)) { // only files, system files ignored, fileNum is limited by setBuf->fileListMax if (entry->flags & DirEntry_TypeFile && entry->name != "PARAM.SFO" && statGet->fileListNum++ < setBuf->fileListMax) { statGet->fileNum++; auto& file = *file_list++; if (entry->name == "ICON0.PNG") { file.fileType = CELL_SAVEDATA_FILETYPE_CONTENT_ICON0; } else if (entry->name == "ICON1.PAM") { file.fileType = CELL_SAVEDATA_FILETYPE_CONTENT_ICON1; } else if (entry->name == "PIC1.PNG") { file.fileType = CELL_SAVEDATA_FILETYPE_CONTENT_PIC1; } else if (entry->name == "SND0.AT3") { file.fileType = CELL_SAVEDATA_FILETYPE_CONTENT_SND0; } else if (psf.GetInteger("*" + entry->name)) // let's put the list of protected files in PARAM.SFO (int param = 1 if protected) { file.fileType = CELL_SAVEDATA_FILETYPE_SECUREFILE; } else { file.fileType = CELL_SAVEDATA_FILETYPE_NORMALFILE; } file.size = entry->size; file.atime = entry->access_time; file.mtime = entry->modify_time; file.ctime = entry->create_time; strcpy_trunc(file.fileName, entry->name); } } // Stat Callback funcStat(CPU, result, statGet, statSet); if (result->result < 0) { return CELL_SAVEDATA_ERROR_CBRESULT; } // Update PARAM.SFO if (statSet->setParam) { psf.Clear(); psf.SetString("ACCOUNT_ID", ""); // ??? psf.SetInteger("ATTRIBUTE", statSet->setParam->attribute); psf.SetString("CATEGORY", "SD"); // ??? psf.SetString("PARAMS", ""); // ??? psf.SetString("PARAMS2", ""); // ??? psf.SetInteger("PARENTAL_LEVEL", 0); // ??? psf.SetString("DETAIL", statSet->setParam->detail); psf.SetString("SAVEDATA_DIRECTORY", save_entry.dirName); psf.SetString("SAVEDATA_LIST_PARAM", statSet->setParam->listParam); psf.SetString("SUB_TITLE", statSet->setParam->subTitle); psf.SetString("TITLE", statSet->setParam->title); } switch (const u32 mode = statSet->reCreateMode & 0xffff) { case CELL_SAVEDATA_RECREATE_NO: case CELL_SAVEDATA_RECREATE_NO_NOBROKEN: { break; } case CELL_SAVEDATA_RECREATE_YES: case CELL_SAVEDATA_RECREATE_YES_RESET_OWNER: { // kill it with fire for (const auto entry : vfsDir(dir_path)) { if (entry->flags & DirEntry_TypeFile) { Emu.GetVFS().RemoveFile(dir_path + entry->name); } } break; } default: { cellSysutil.Error("savedata_op(): unknown statSet->reCreateMode (0x%x)", statSet->reCreateMode); return CELL_SAVEDATA_ERROR_PARAM; } } } // Create save directory if necessary if (psf && save_entry.isNew && !Emu.GetVFS().CreateDir(dir_path)) { // Let's ignore this error for now } // Enter the loop where the save files are read/created/deleted vm::stackvar<CellSaveDataFileGet> fileGet(CPU); vm::stackvar<CellSaveDataFileSet> fileSet(CPU); fileGet->excSize = 0; memset(fileGet->reserved, 0, sizeof(fileGet->reserved)); while (funcFile) { funcFile(CPU, result, fileGet, fileSet); if (result->result < 0) { return CELL_SAVEDATA_ERROR_CBRESULT; } if (result->result == CELL_SAVEDATA_CBRESULT_OK_LAST || result->result == CELL_SAVEDATA_CBRESULT_OK_LAST_NOCONFIRM) { break; } std::string file_path; switch (const u32 type = fileSet->fileType) { case CELL_SAVEDATA_FILETYPE_SECUREFILE: case CELL_SAVEDATA_FILETYPE_NORMALFILE: { file_path = fileSet->fileName.get_ptr(); break; } case CELL_SAVEDATA_FILETYPE_CONTENT_ICON0: { file_path = "ICON0.PNG"; break; } case CELL_SAVEDATA_FILETYPE_CONTENT_ICON1: { file_path = "ICON1.PAM"; break; } case CELL_SAVEDATA_FILETYPE_CONTENT_PIC1: { file_path = "PIC1.PNG"; break; } case CELL_SAVEDATA_FILETYPE_CONTENT_SND0: { file_path = "SND0.AT3"; break; } default: { cellSysutil.Error("savedata_op(): unknown fileSet->fileType (0x%x)", type); return CELL_SAVEDATA_ERROR_PARAM; } } psf.SetInteger("*" + file_path, fileSet->fileType == CELL_SAVEDATA_FILETYPE_SECUREFILE); std::string local_path; Emu.GetVFS().GetDevice(dir_path + file_path, local_path); switch (const u32 op = fileSet->fileOperation) { case CELL_SAVEDATA_FILEOP_READ: { fs::file file(local_path, o_read); file.seek(fileSet->fileOffset); fileGet->excSize = static_cast<u32>(file.read(fileSet->fileBuf.get_ptr(), std::min<u32>(fileSet->fileSize, fileSet->fileBufSize))); break; } case CELL_SAVEDATA_FILEOP_WRITE: { fs::file file(local_path, o_write | o_create); file.seek(fileSet->fileOffset); fileGet->excSize = static_cast<u32>(file.write(fileSet->fileBuf.get_ptr(), std::min<u32>(fileSet->fileSize, fileSet->fileBufSize))); file.trunc(file.seek(0, from_cur)); // truncate break; } case CELL_SAVEDATA_FILEOP_DELETE: { fs::remove_file(local_path); fileGet->excSize = 0; break; } case CELL_SAVEDATA_FILEOP_WRITE_NOTRUNC: { fs::file file(local_path, o_write | o_create); file.seek(fileSet->fileOffset); fileGet->excSize = static_cast<u32>(file.write(fileSet->fileBuf.get_ptr(), std::min<u32>(fileSet->fileSize, fileSet->fileBufSize))); break; } default: { cellSysutil.Error("savedata_op(): unknown fileSet->fileOperation (0x%x)", op); return CELL_SAVEDATA_ERROR_PARAM; } } } // Write PARAM.SFO if (psf) { vfsFile f(sfo_path, vfsWriteNew); psf.Save(f); } return CELL_OK; }
/* Loads the data from a case-file */ void loadDataFromFile(Firm * firm, Employee ** employees, char * filename) { /* Opens the filestream */ FILE * input = fopen(filename, "r"); /* Checks if the file exists */ if(!input) { perror("File not found: "); exit(EXIT_FAILURE); } char line[DATA_LINE_LENGTH] = { }; /* Allocates a startSting with enough memory for the size of the string which tells us where the different data starts in the case-file*/ char startString[START_STR_LLENGTH] = { }; /* The list of shifts */ Shift * shifts = NULL; /* The list of ranks */ Rank * ranks = NULL; /* The list of wishes */ Wish * wishes = NULL; /* The list of skills */ Skill * firmSkills = NULL; Skill * rankSkills = NULL; /* TEMP */ //Skill * tmpSkill; Rank * tmpRank; Shift * tmpShift; Wish * tmpWish; Employee * tmpEmployee; /* Declare counters and char arrays for different names */ int shiftCounter = 0, wishCounter = 0, employeeCounter = 0, rankCounter = 0; int skillCounter = 0, totalSkillCounter = 0; char skillName[MAX_SKILLNAME_LENGTH]; /* Name of a skill */ char rankName[RANK_NAME_SIZE]; /* Name of a rank */ /* Runs through the entire file one line at the time untill EndOfFile */ while(fscanf(input, " %[^\n]", line) != EOF) { sscanf(line, "%2s", startString); /* Adds shifts to the firm*/ if(shiftCounter) { /* Temprary shift to add the list of shifts */ tmpShift = (Shift *) calloc(1, sizeof(Shift)); sscanf(line, " - %1d %2d %2d %1d %2d %2d %d %1d %s \n", &(tmpShift->date.tmStart.tm_wday), &(tmpShift->date.tmStart.tm_hour), &(tmpShift->date.tmStart.tm_min), &(tmpShift->date.tmEnd.tm_wday), &(tmpShift->date.tmEnd.tm_hour), &(tmpShift->date.tmEnd.tm_min), &(tmpShift->extraPoints), &(tmpShift->priorityValue), skillName); tmpShift->length = calculateDatintervalLength(&(tmpShift->date)); tmpShift->requiredSkill = listGetByKey((void *) firmSkills, sizeof(Skill), skillName); listAdd((void**) &shifts, sizeof(Shift), tmpShift); shiftCounter--; } /* Adds shifts to the firm*/ if(skillCounter) { sscanf(line, " - %s \n", skillName); if(listGetByKey((void *) firmSkills, sizeof(Skill), skillName) == NULL ) { Skill * tmpSkill = (Skill *) calloc(1, sizeof(Skill)); strcpy(tmpSkill->name, skillName); tmpSkill->ID = totalSkillCounter; totalSkillCounter++; listAdd((void**) &firmSkills, sizeof(Skill), tmpSkill); } Skill * tmpSkill = (Skill *) calloc(1, sizeof(Skill)); strcpy(tmpSkill->name, skillName); tmpSkill->ID = listGetIndexByKey((void *) firmSkills, sizeof(Skill), skillName); listAdd((void**) &rankSkills, sizeof(Skill), tmpSkill); skillCounter--; if(!skillCounter) { /* Add the list of skills to a rank */ tmpRank = (Rank *) listGet((void*) ranks, sizeof(Rank), rankCounter - 1); tmpRank->skills = rankSkills; rankSkills = NULL; } } /* Adds wishes to the list of whishes */ if(wishCounter) { /* Temprary wish to add the list of wishes */ tmpWish = (Wish *) calloc(1, sizeof(Wish)); sscanf(line, " - %1d %2d %2d %1d %2d %2d %1d %1d \n", &(tmpWish->date.tmStart.tm_wday), &(tmpWish->date.tmStart.tm_hour), &(tmpWish->date.tmStart.tm_min), &(tmpWish->date.tmEnd.tm_wday), &(tmpWish->date.tmEnd.tm_hour), &(tmpWish->date.tmEnd.tm_min), &(tmpWish->priorityType), &(tmpWish->priorityValue)); tmpWish->length = calculateDatintervalLength(&(tmpWish->date)); listAdd((void**) &wishes, sizeof(Wish), tmpWish); wishCounter--; if(!wishCounter) { /* Add the list of wisehs to a employee */ tmpEmployee = (Employee *) listGet((void*) *employees, sizeof(Employee), employeeCounter - 1); tmpEmployee->wishes = wishes; wishes = NULL; } } /* Checks if the next data describes the Rank*/ if(!strcmp(startString, "@R")) { sscanf(line, " @R : %s %d : ", rankName, &skillCounter); tmpRank = (Rank *) calloc(1, sizeof(Rank)); strcpy(tmpRank->name, rankName); listAdd((void **) &ranks, sizeof(Rank), tmpRank); rankCounter++; } /* Checks if the next data describes the firm*/ else if(!strcmp(startString, "@F")) { sscanf(line, " @F : %s %d :", firm->firmName, &(firm->shiftCounter)); shiftCounter = firm->shiftCounter; firm->ranks = ranks; } /* Checks if the next data describes an employee*/ else if(!strcmp(startString, "@E")) { tmpEmployee = (Employee *) calloc(1, sizeof(Employee)); sscanf(line, "@E : %s %s %s %d %d :", tmpEmployee->firstName, tmpEmployee->lastName, rankName, &(tmpEmployee->points), &(tmpEmployee->wishCounter)); tmpEmployee->rank = listGetByKey((void *) firm->ranks, sizeof(Rank), rankName); tmpEmployee->ID = employeeCounter; wishCounter = tmpEmployee->wishCounter; listAdd((void**) employees, sizeof(Employee), tmpEmployee); employeeCounter++; } } firm->skills = firmSkills; firm->emptySchedule = shifts; /* Close the filestream */ fclose(input); }
void conditional_parrern_base(struct node *fptree, struct header_table *htable, int *item_counter,int *item_index, char *generate_string) { struct frequent_patterns *fp = malloc(sizeof(struct frequent_patterns)); struct frequent_patterns *fp_head = malloc(sizeof(struct frequent_patterns)); struct node *now_node = malloc(sizeof(struct node)); int ptr_index; fp_head = fp; if(generate_string != "") //printf("%s \n", generate_string); while(htable != NULL) { fp = fp_head; fp->next = NULL; fp->index = 0; listStart(htable->cond); while(listNext(htable->cond)) { now_node = listGet(htable->cond); if(fp->index == 0) { fp->ptr = malloc(sizeof(short) * MIN_SUPPORT_INDEX); } else { struct frequent_patterns *new_fp = malloc(sizeof(struct frequent_patterns)); new_fp->ptr = malloc(sizeof(short) * MIN_SUPPORT_INDEX); fp->next = new_fp; fp = new_fp; } fp->counter = now_node->counter; fp->htable_value = htable->no; ptr_index = 0; now_node = now_node->parent; while(now_node != NULL) { if( now_node->no == -1) break; *(fp->ptr + ptr_index) = now_node->no; ptr_index++; now_node = now_node->parent; } fp->index = ptr_index; } struct header_table *sub_htable = malloc(sizeof(struct header_table)); struct node *sub_tree = malloc(sizeof(struct node)); sub_tree = create_fptree(); sub_tree = build_sub_tree(sub_tree, sub_htable, fp_head, item_counter, item_index); //dfs(sub_tree); if(sub_tree->child != NULL) { int len = strlen(generate_string) + 4; char *str_ans = malloc(sizeof(char) * len); myString_cat(str_ans, generate_string, htable->no); while(sub_htable->next != NULL) sub_htable = sub_htable->next; conditional_parrern_base(sub_tree, sub_htable, item_counter, item_index, str_ans); dfs(sub_tree); }else if(htable->prev == NULL || listCount(htable->cond) > 0){ int len = strlen(generate_string) + 4; char *str_ans = malloc(sizeof(char) * len); myString_cat(str_ans, generate_string, htable->no); //printf("%s\n", str_ans); } htable = htable->prev; } while(htable != NULL) { header_head = htable; htable = htable->next; free(header_head); } }
void input_handler() { LIST_ITERATOR *sock_i = newListIterator(socket_list); SOCKET_DATA *sock = NULL; ITERATE_LIST(sock, sock_i) { // Close sockects we are unable to read from, or if we have no handler // to take in input if ((FD_ISSET(sock->control, &rFd) && !read_from_socket(sock)) || listSize(sock->input_handlers) == 0) { close_socket(sock, FALSE); continue; } /* Ok, check for a new command */ next_cmd_from_buffer(sock); // are we idling? if(!sock->cmd_read) sock->idle += 1.0 / PULSES_PER_SECOND; /* Is there a new command pending ? */ else if (sock->cmd_read) { sock->idle = 0.0; IH_PAIR *pair = listGet(sock->input_handlers, 0); if(pair->python == FALSE) { void (* handler)(SOCKET_DATA *, char *) = pair->handler; char *cmddup = strdup(bufferString(sock->next_command)); handler(sock, cmddup); free(cmddup); } else { PyObject *arglist = Py_BuildValue("Os", socketGetPyFormBorrowed(sock), bufferString(sock->next_command)); PyObject *retval = PyEval_CallObject(pair->handler, arglist); // check for an error: if(retval == NULL) log_pyerr("Error with a Python input handler"); // garbage collection Py_XDECREF(retval); Py_XDECREF(arglist); } // append our last command to the command history. History buffer is // 100 commands, so pop off the earliest command if we're going over listPut(sock->command_hist, strdup(bufferString(sock->next_command))); if(listSize(sock->command_hist) > 100) free(listRemoveNum(sock->command_hist, 100)); bufferClear(sock->next_command); // we save whether or not we read a command until our next call to // input_handler(), at which time it is reset to FALSE if we didn't read // sock->cmd_read = FALSE; } #ifdef MODULE_ALIAS // ACK!! this is so yucky, but I can't think of a better way to do it... // if this command was put in place by an alias, decrement the alias_queue // counter by one. This counter is in place mainly so aliases do not end // up calling eachother and making us get stuck in an infinite loop. if(sock->player) { int alias_queue = charGetAliasesQueued(sock->player); if(alias_queue > 0) charSetAliasesQueued(sock->player, --alias_queue); } #endif } deleteListIterator(sock_i); }