int parse_config(char *cfgfname, const char *devfname) { int err = 0, fd; unsigned int chipsectionscnt, ctrlsectionscnt, i; struct rcfile *f; struct sim_chip *chips; struct sim_ctrl *ctrls; err = rc_open(cfgfname, "r", &f); if (err) { error("could not open configuration file (%s)", cfgfname); return (EX_NOINPUT); } /* First, try to configure simulator itself. */ if (configure_sim(devfname, f) != EX_OK) { rc_close(f); return (EINVAL); } debug("SIM CONFIGURED!\n"); /* Then create controllers' configs */ if (create_ctrls(f, &ctrls, &ctrlsectionscnt) != 0) { rc_close(f); return (ENXIO); } debug("CTRLS CONFIG READ!\n"); /* Then create chips' configs */ if (create_chips(f, &chips, &chipsectionscnt) != 0) { destroy_ctrls(ctrls); rc_close(f); return (ENXIO); } debug("CHIPS CONFIG READ!\n"); if (validate_ctrls(ctrls, ctrlsectionscnt) != 0) { destroy_ctrls(ctrls); destroy_chips(chips); rc_close(f); return (EX_SOFTWARE); } if (validate_chips(chips, chipsectionscnt, ctrls, ctrlsectionscnt) != 0) { destroy_ctrls(ctrls); destroy_chips(chips); rc_close(f); return (EX_SOFTWARE); } /* Open device */ fd = open(devfname, O_RDWR); if (fd == -1) { error("could not open simulator device file (%s)!", devfname); rc_close(f); destroy_chips(chips); destroy_ctrls(ctrls); return (EX_OSFILE); } debug("SIM CONFIG STARTED!\n"); /* At this stage, both ctrls' and chips' configs should be valid */ for (i = 0; i < ctrlsectionscnt; i++) { err = ioctl(fd, NANDSIM_CREATE_CTRL, &ctrls[i]); if (err) { if (err == EEXIST) error("Controller#%d already created\n", ctrls[i].num); else if (err == EINVAL) error("Incorrect controler number (%d)\n", ctrls[i].num); else error("Could not created controller#%d\n", ctrls[i].num); /* Errors during controller creation stops parsing */ close(fd); rc_close(f); destroy_ctrls(ctrls); destroy_chips(chips); return (ENXIO); } debug("CTRL#%d CONFIG STARTED!\n", i); } for (i = 0; i < chipsectionscnt; i++) { err = ioctl(fd, NANDSIM_CREATE_CHIP, &chips[i]); if (err) { if (err == EEXIST) error("Chip#%d for controller#%d already " "created\n", chips[i].num, chips[i].ctrl_num); else if (err == EINVAL) error("Incorrect chip number (%d:%d)\n", chips[i].num, chips[i].ctrl_num); else error("Could not create chip (%d:%d)\n", chips[i].num, chips[i].ctrl_num); error("Could not start chip#%d\n", i); destroy_chips(chips); destroy_ctrls(ctrls); close(fd); rc_close(f); return (ENXIO); } } debug("CHIPS CONFIG STARTED!\n"); close(fd); rc_close(f); destroy_chips(chips); destroy_ctrls(ctrls); return (0); }
static int ControlTestWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam) { static BITMAP folder; switch (message) { case MSG_CREATE: { create_ctrls (hWnd); hRightMenu = create_rightbutton_menu (); LoadBitmapFromFile (HDC_SCREEN, &folder, "./res/folder.bmp"); hChildWnd1 = CreateWindow (CTRL_GRID, "GRID", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | WS_BORDER, IDC_GRID, 20, 20, 350, 200, hWnd, 0); } break; case MSG_COMMAND: { int id = LOWORD (wParam); //int code = HIWORD (wParam); int nSel, col, row; char buffer[101]; GetWindowText (GetDlgItem(hWnd, IDC_EDIT), buffer, 100); nSel = atoi(buffer); switch (id) { case IDC_CTRL1: row = SendMessage(hChildWnd1, GRIDM_GETHEADHEIGHT, 0,0); sprintf(buffer, "%d", row); SetWindowText(GetDlgItem(hWnd, IDC_EDIT), buffer); break; case IDC_CTRL2: col = SendMessage(hChildWnd1, GRIDM_GETHEADWIDTH, 0,0); sprintf(buffer, "%d", col); SetWindowText(GetDlgItem(hWnd, IDC_EDIT), buffer); break; case IDC_CTRL3: col = SendMessage(hChildWnd1, GRIDM_GETCOLCOUNT, 0, 0); SendMessage(hChildWnd1, GRIDM_ADDCOL, (WPARAM)col, 0); break; case IDC_CTRL4: col = SendMessage(hChildWnd1, GRIDM_GETCOLCOUNT, 0, 0); SendMessage(hChildWnd1, GRIDM_DELCOL, (WPARAM)(col-1), 0); break; case IDC_CTRL6: break; case IDC_CTRL7: break; case IDC_CTRL8: break; case IDC_CTRL9: break; case IDM_FILE ... IDM_FILE+4: MessageBox (hMainWnd, "In Construction ...", "Sorry", MB_OK); break; } } break; case MSG_DESTROY: UnloadBitmap (&folder); DestroyMenu (hRightMenu); DestroyAllControls (hWnd); hMainWnd = HWND_INVALID; return 0; case MSG_CLOSE: DestroyMainWindow (hWnd); MainWindowCleanup (hWnd); return 0; } return DefaultMainWinProc (hWnd, message, wParam, lParam); }