PERS_ENUM_TYPE(Error) persdb_Add(mpl_bag_t *employee, uint16_t *number) { mpl_list_t *tmp; mpl_list_t *dblist = NULL; mpl_bag_t *employee_copy; uint16_t new_number = EMPLOYEE_NUMBER_BASE; uint16_t max_number = EMPLOYEE_NUMBER_UNDEFINED; int ret; PERS_ENUM_VAR_DECLARE_INIT(Error, error, success); if (PERS_GET_Employee_number(employee) != EMPLOYEE_NUMBER_UNDEFINED) { error = PERS_ENUM_VALUE(Error, parameter); *number = EMPLOYEE_NUMBER_UNDEFINED; goto finish; } dbfile = fopen(PERSDB_FILENAME, "r"); if (dbfile) { ret = mpl_file_read_params(dbfile, &dblist, PERSONNEL_PARAM_SET_ID); fclose(dbfile); if (ret) { error = PERS_ENUM_VALUE(Error, general); *number = EMPLOYEE_NUMBER_UNDEFINED; goto finish; } } MPL_LIST_FOR_EACH(dblist, tmp) { uint16_t tmpnum; mpl_bag_t *tmpempl = MPL_LIST_CONTAINER(tmp, mpl_param_element_t, list_entry)->value_p; tmpnum = PERS_GET_Employee_number(tmpempl); max_number = tmpnum > max_number ? tmpnum : max_number; }
static int readlines(void) { char *line; mpl_list_t *reqMsg = NULL; int quit = 0; mpl_list_t *tmp; completionStrings = calloc(maxStrings, sizeof(char *)); while((line = linenoise("PERS> ")) != NULL) { if (line[0] != '\0') { if (strcmp(line,"quit") && strncmp(line, "help ", 5)) { char *req; int ret = -1; req = formatCmdLine(line, "Req"); reqMsg = mpl_param_list_unpack_param_set(req, PERSONNEL_PARAM_SET_ID); if (!reqMsg) { printf("Protocol error\n"); ret = -1; } else if (checkCommand(reqMsg) == 0) { ret = pack_and_send(reqMsg); } mpl_param_list_destroy(&reqMsg); free(req); if (ret == 0) { fgets(buf, 1024, fi); printf("%s\n", buf); } } else if (!strncmp(line, "help ", 5)) { char *helptext; persfile_get_command_help(line, &helptext); if (helptext != NULL) { printf("%s", helptext); free(helptext); } else printf("No help\n"); } else { quit = 1; } linenoiseHistoryAdd(line); linenoiseHistorySave("history.txt"); /* Save every new entry */ free(line); while ((tmp = mpl_list_remove(&completionCallstack, NULL)) != NULL) { completion_callstack_entry_t *e; e = MPL_LIST_CONTAINER(tmp, completion_callstack_entry_t, list_entry); free(e); } } if (quit) break; } free(completionStrings); return 0; }
/** * pscc_obj_get - get ps connection control object **/ pscc_object_t *pscc_obj_get(int connid) { mpl_list_t *obj_p; pscc_object_t *res; MPL_LIST_FOR_EACH(objects_list, obj_p) { res = MPL_LIST_CONTAINER(obj_p, pscc_object_t, list_entry); if (res->connid == connid) return res; }