int every_glob(t_tab *stock, glob_t *globuf) { int i; char *path; int ret; i = 0; path = NULL; if ((ret = glob("*", GLOB_MARK , NULL, globuf)) < 0) return (-1); while (stock && stock->path && stock->path[i]) { path = my_strslashcat(stock->path[i++], "*"); if ((ret = glob(my_strdup(path), GLOB_MARK | GLOB_ERR | GLOB_APPEND, NULL, globuf)) == -1) return (my_glob_return(globuf, path, -1)); } globuf->gl_pathc = epur_duplicates(globuf->gl_pathv); if (globuf->gl_pathc > 50) return (disclaimer(globuf, stock, NULL)); else aff_glob(globuf); prompt(stock); return (my_glob_return(globuf, path, 0)); }
int bin_completion(char **send, t_tab *stock , glob_t *globuf, t_comp *count) { char *path; int i; i = 0; if ((!(stock && stock->path && send)) || (!(path = my_strslashcat(my_strdup(stock->path[0]), my_strdup((*send)))) || (glob(my_strcat(my_strdup(path), "*"), GLOB_MARK, NULL, globuf) < 0))) return (-1); while (stock->path[++i] != NULL) { path = my_strslashcat(my_strdup(stock->path[i]), my_strdup((*send))); if ((glob(my_strcat(my_strdup(path), "*"), GLOB_ERR | GLOB_APPEND, NULL, globuf)) == -1) return (my_glob_return(globuf, path, -1)); } if (globuf->gl_pathc <= 0) return (my_glob_return(globuf, path, -1)); globuf->gl_pathc = epur_duplicates(globuf->gl_pathv); if (globuf->gl_pathc > 50) return (disclaimer(globuf, stock, send)); else aff_glob(globuf); prompt(stock); check_common_char(globuf->gl_pathv, send, *send, count); return (my_glob_return(globuf, path, 0)); }
kgeography::kgeography() : KMainWindow(), p_firstShow(true), p_mustShowResultsDialog(false) { p_map = 0; p_askWidget = 0; p_bigWidget = new QHBox(this); QVBox *p_leftWidget = new QVBox(p_bigWidget); p_currentMap = new QLabel(p_leftWidget); p_currentMap -> setAlignment(AlignCenter); p_consult = new KPushButton(i18n("&Browse Map"), p_leftWidget); QWhatsThis::add(p_consult, i18n("In this section left click on any part of the map to learn about the divisions" )); p_askMap = new KPushButton(i18n("&Click Division in Map..."), p_leftWidget); QWhatsThis::add(p_askMap, i18n("In this challenge you are given a division name on the left under the menu and you must find it on the map and click on it")); p_askCapitalDivisions = new KPushButton(i18n("Guess Division From Its &Capital..."), p_leftWidget); QWhatsThis::add(p_askCapitalDivisions, i18n("In this quiz you have to guess the division name given its capital")); p_askDivisionCapitals = new KPushButton(i18n("Guess Capital of &Division..."), p_leftWidget); QWhatsThis::add(p_askDivisionCapitals, i18n("In this quiz you have to guess the capital of a given division name")); p_askFlagDivisions = new KPushButton(i18n("&Guess Division From Its Flag..."), p_leftWidget); QWhatsThis::add(p_askFlagDivisions, i18n("In this quiz you have to guess the division name given its flag")); p_askDivisionFlags = new KPushButton(i18n("G&uess Flag of Division..."), p_leftWidget); QWhatsThis::add(p_askDivisionFlags, i18n("In this quiz you have to guess the flag of a division given its name")); p_underLeftWidget = new QVBox(p_leftWidget); p_underLeftWidget -> layout() -> setSpacing(KDialog::spacingHint()); p_underLeftWidget -> layout() -> setMargin(KDialog::marginHint()); p_leftWidget -> setStretchFactor(p_underLeftWidget, 1); setCentralWidget(p_bigWidget); connect(p_consult, SIGNAL(clicked()), this, SLOT(consult())); connect(p_askMap, SIGNAL(clicked()), this, SLOT(askMap())); connect(p_askCapitalDivisions, SIGNAL(clicked()), this, SLOT(askCapitalDivisions())); connect(p_askDivisionCapitals, SIGNAL(clicked()), this, SLOT(askDivisionCapitals())); connect(p_askFlagDivisions, SIGNAL(clicked()), this, SLOT(askFlagDivisions())); connect(p_askDivisionFlags, SIGNAL(clicked()), this, SLOT(askDivisionFlags())); KAction *a = KStdAction::open(this, SLOT(openMap()), actionCollection(), "openMap"); a -> setText(i18n("&Open Map...")); KStdAction::quit(this, SLOT(close()), actionCollection(), "quit"); p_zoom = new KToggleAction(i18n("&Zoom"), "viewmagfit", 0, 0, 0, actionCollection(), "zoom_select"); p_zoom -> setEnabled(false); p_zoomOriginal = new KAction(i18n("&Original Size"), "viewmag1", 0, 0, 0, actionCollection(), "zoom_original"); p_zoomOriginal -> setEnabled(false); p_move = new KToggleAction(i18n("&Move"), "move", 0, 0, 0, actionCollection(), "move"); p_move -> setEnabled(false); new KAction(i18n("Disclaimer"), 0, this, SLOT(disclaimer()), actionCollection(), "disclaimer"); setupGUI(Keys | ToolBar | Save | Create); show(); }
// here all is done int main(int argc, char *argv[]) { char *ptr; int i; int nType = HW_PCI; __u32 dwPort = 0; __u16 wIrq = 0; __u16 wBTR0BTR1 = 0; int nExtended = CAN_INIT_TYPE_ST; const char *szDevNode = DEFAULT_NODE; bool bDevNodeGiven = false; bool bTypeGiven = false; bool bDisplayOn = true; char txt[VERSIONSTRING_LEN]; errno = 0; current_release = CURRENT_RELEASE; disclaimer("receivetest"); init(); // decode command line arguments for (i = 1; i < argc; i++) { char c; ptr = argv[i]; while (*ptr == '-') ptr++; c = *ptr; ptr++; if (*ptr == '=') ptr++; switch(tolower(c)) { case 'f': szDevNode = ptr; bDevNodeGiven = true; break; case 'd': if (strcmp(ptr, "no") == 0) bDisplayOn = false; break; case 't': nType = getTypeOfInterface(ptr); if (!nType) { errno = EINVAL; printf("receivetest: unknown type of interface!\n"); goto error; } bTypeGiven = true; break; case 'p': dwPort = strtoul(ptr, NULL, 16); break; case 'i': wIrq = (__u16)strtoul(ptr, NULL, 10); break; case 'e': nExtended = CAN_INIT_TYPE_EX; break; case '?': case 'h': hlpMsg(); goto error; break; case 'b': wBTR0BTR1 = (__u16)strtoul(ptr, NULL, 16); break; default: errno = EINVAL; perror("receivetest: unknown command line argument!\n"); goto error; break; } } // simple command input check if (bDevNodeGiven && bTypeGiven) { errno = EINVAL; perror("receivetest: device node and type together is useless"); goto error; } // give some information back if (!bTypeGiven) { printf("receivetest: device node=\"%s\"\n", szDevNode); } else { printf("receivetest: type=%s", getNameOfInterface(nType)); switch (nType) { case HW_USB: case HW_USB_PRO: case HW_USB_FD: case HW_USB_PRO_FD: if (dwPort) printf(", %d. device\n", dwPort); else printf(", standard device\n"); break; default: if (dwPort) { if (nType == HW_PCI) printf(", %d. PCI device", dwPort); else printf(", port=0x%08x", dwPort); } else printf(", port=default"); if ((wIrq) && !(nType == HW_PCI)) printf(" irq=0x%04x\n", wIrq); else printf(", irq=default\n"); break; } } if (nExtended == CAN_INIT_TYPE_EX) printf(" Extended frames are accepted"); else printf(" Only standard frames are accepted"); if (wBTR0BTR1) printf(", init with BTR0BTR1=0x%04x\n", wBTR0BTR1); else printf(", init with 500 kbit/sec.\n"); /* open CAN port */ if ((bDevNodeGiven) || (!bDevNodeGiven && !bTypeGiven)) { h = LINUX_CAN_Open(szDevNode, O_RDWR); if (!h) { printf("receivetest: can't open %s\n", szDevNode); goto error; } } else { // please use what is appropriate // HW_DONGLE_SJA // HW_DONGLE_SJA_EPP // HW_ISA_SJA // HW_PCI h = CAN_Open(nType, dwPort, wIrq); if (!h) { printf("receivetest: can't open %s device.\n", getNameOfInterface(nType)); goto error; } } /* clear status */ // CAN_Status(h); // get version info errno = CAN_VersionInfo(h, txt); if (!errno) printf("receivetest: driver version = %s\n", txt); else { perror("receivetest: CAN_VersionInfo()"); goto error; } // init to a user defined bit rate if (wBTR0BTR1) { errno = CAN_Init(h, wBTR0BTR1, nExtended); if (errno) { perror("receivetest: CAN_Init()"); goto error; } } errno = read_loop(bDisplayOn); if (!errno) return 0; error: do_exit(errno); return errno; }
int main(int argc, char *argv[]) { char *ptr; int i; int nType = HW_PCI; __u32 dwPort = 0; __u16 wIrq = 0; __u16 wBTR0BTR1 = 0; __u32 dwMaxTimeInterval = 0, dwMaxLoop = 0; char *filename = NULL; const char *szDevNode = DEFAULT_NODE; bool bDevNodeGiven = false; bool bTypeGiven = false; parser MyParser; char txt[VERSIONSTRING_LEN]; errno = 0; current_release = CURRENT_RELEASE; disclaimer("transmitest"); init(); // decode command line arguments for (i = 1; i < argc; i++) { char c; ptr = argv[i]; if (*ptr == '-') { while (*ptr == '-') ptr++; c = *ptr; ptr++; if (*ptr == '=') ptr++; switch(tolower(c)) { case 'f': szDevNode = ptr; bDevNodeGiven = true; break; case 't': nType = getTypeOfInterface(ptr); if (!nType) { errno = EINVAL; printf("transmitest: unknown type of interface\n"); goto error; } bTypeGiven = true; break; case 'p': dwPort = strtoul(ptr, NULL, 16); break; case 'i': wIrq = (__u16)strtoul(ptr, NULL, 10); break; case 'e': nExtended = CAN_INIT_TYPE_EX; break; case '?': case 'h': hlpMsg(); goto error; break; case 'b': wBTR0BTR1 = (__u16)strtoul(ptr, NULL, 16); break; case 'r': dwMaxTimeInterval = strtoul(ptr, NULL, 10); break; case 'n': dwMaxLoop = strtoul(ptr, NULL, 10); break; default: errno = EINVAL; printf("transmitest: unknown command line argument\n"); goto error; break; } } else filename = ptr; } // test for filename if (filename == NULL) { errno = EINVAL; perror("transmitest: no filename given"); goto error; } // test device node and type if (bDevNodeGiven && bTypeGiven) { errno = EINVAL; perror("transmitest: device node and type together is useless"); goto error; } // give the filename to my parser MyParser.setFileName(filename); // tell some information to the user if (!bTypeGiven) { printf("transmitest: device node=\"%s\"\n", szDevNode); } else { printf("transmitest: type=%s", getNameOfInterface(nType)); if (nType == HW_USB) printf(", Serial Number=default, Device Number=%d\n", dwPort); else { if (dwPort) { if (nType == HW_PCI) printf(", %d. PCI device", dwPort); else printf(", port=0x%08x", dwPort); } else printf(", port=default"); if ((wIrq) && !(nType == HW_PCI)) printf(" irq=0x%04x\n", wIrq); else printf(", irq=default\n"); } } if (nExtended == CAN_INIT_TYPE_EX) printf(" Extended frames are sent"); else printf(" Only standard frames are sent"); if (wBTR0BTR1) printf(", init with BTR0BTR1=0x%04x\n", wBTR0BTR1); else printf(", init with 500 kbit/sec.\n"); printf(" Data will be read from \"%s\".\n", filename); if (dwMaxTimeInterval) printf(" Messages are send in random time intervalls with a max. gap time of %d msec.\n", dwMaxTimeInterval); /* get the list of data from parser */ List = MyParser.Messages(); if (!List) { errno = MyParser.nGetLastError(); perror("transmitest: error at file read"); goto error; } /* open CAN port */ if ((bDevNodeGiven) || (!bDevNodeGiven && !bTypeGiven)) { h = LINUX_CAN_Open(szDevNode, O_RDWR); if (!h) { printf("transmitest: can't open %s\n", szDevNode); goto error; } } else { // please use what is appropriate // HW_DONGLE_SJA // HW_DONGLE_SJA_EPP // HW_ISA_SJA // HW_PCI h = CAN_Open(nType, dwPort, wIrq); if (!h) { printf("transmitest: can't open %s device.\n", getNameOfInterface(nType)); goto error; } } /* clear status */ CAN_Status(h); // get version info errno = CAN_VersionInfo(h, txt); if (!errno) printf("transmitest: driver version = %s\n", txt); else { perror("transmitest: CAN_VersionInfo()"); goto error; } // init to a user defined bit rate if (wBTR0BTR1) { errno = CAN_Init(h, wBTR0BTR1, nExtended); if (errno) { perror("transmitest: CAN_Init()"); goto error; } } // enter in the write loop errno = write_loop(dwMaxTimeInterval, dwMaxLoop); if (!errno) return 0; error: do_exit(errno); return errno; }
// here all is done int main(int argc, char *argv[]) { char *ptr; int i; const char *szDeviceNode = DEFAULT_NODE; errno = 0; current_release = CURRENT_RELEASE; disclaimer("bitratetest"); // decode command line arguments for (i = 1; i < argc; i++) { char c; ptr = argv[i]; while (*ptr == '-') ptr++; c = *ptr; ptr++; if (*ptr == '=') ptr++; switch(tolower(c)) { case 'f': szDeviceNode = ptr; break; case '?': case 'h': hlpMsg(); my_private_exit(0); break; default: errno = EINVAL; perror("bitratetest: unknown command line argument"); my_private_exit(errno); break; } } // open the CAN port // please use what is appropriate // HW_DONGLE_SJA // HW_DONGLE_SJA_EPP // HW_ISA_SJA // HW_PCI h = LINUX_CAN_Open(szDeviceNode, O_RDWR); if (h) { char txt[VERSIONSTRING_LEN]; // get version info errno = CAN_VersionInfo(h, txt); if (!errno) printf("bitratetest: driver version = %s\n", txt); else { perror("bitratetest: CAN_VersionInfo()"); my_private_exit(errno); } printf("\n"); // calculate BTR0BTR1 from bitrates for (i = 1000000; i > 2500; i /= 2) { if (i == 62500) i = 100000; if (i == 6250) i = 10000; printf("bitratetest: %d bits/sec \t->BTR0BTR1=0x%04x\n", i + 1, LINUX_CAN_BTR0BTR1(h, i + 1)); printf(" %d bits/sec \t->BTR0BTR1=0x%04x\n", i , LINUX_CAN_BTR0BTR1(h, i)); printf(" %d bits/sec \t->BTR0BTR1=0x%04x\n", i - 1, LINUX_CAN_BTR0BTR1(h, i - 1)); }; printf("\n"); } else { errno = nGetLastError(); perror("bitratetest: CAN_Open()"); } my_private_exit(errno); return errno; }
/** Demo program using curses. * * This demo displays the text entered in a top windows that stretches * across the screen. The current prediction is displayed immediately * underneath the text window, at the leftmost position. * * The previous predictions are displayed in cronological order to the * right of the current prediction. * * Subsequent predictions shifted to the right, so that the current * prediction is always on the left hand side. * Context switches are marked in some way (either a vertical bar or a * box enclosing the other prediction boxes). * */ int main(int argc, char** argv) { parseCommandLineArgs(argc, argv); // magic starts here PresageCallback* callback = new PresageDemoCallback(buffer); Presage presage(callback, config); // configuration variable may be read and written programmatically if (suggestions.empty()) { suggestions = presage.config("Presage.Selector.SUGGESTIONS"); } else { presage.config("Presage.Selector.SUGGESTIONS", suggestions); } // curses initscr(); noecho(); cbreak(); keypad(stdscr, TRUE); clear(); refresh(); disclaimer(); // curses title window const int TITLE_WIN_HEIGHT = 6; const int TITLE_WIN_WIDTH = COLS; const int TITLE_WIN_BEGIN_Y = 0; const int TITLE_WIN_BEGIN_X = 0; WINDOW* title_win = newwin(TITLE_WIN_HEIGHT, TITLE_WIN_WIDTH, TITLE_WIN_BEGIN_Y, TITLE_WIN_BEGIN_X); draw_title_win(title_win); // curses context window const int CONTEXT_WIN_HEIGHT = 5; const int CONTEXT_WIN_WIDTH = COLS; const int CONTEXT_WIN_BEGIN_Y = TITLE_WIN_BEGIN_Y + TITLE_WIN_HEIGHT + 1; const int CONTEXT_WIN_BEGIN_X = 0; WINDOW* context_win = newwin(CONTEXT_WIN_HEIGHT, CONTEXT_WIN_WIDTH, CONTEXT_WIN_BEGIN_Y, CONTEXT_WIN_BEGIN_X); draw_context_win(context_win, std::string("")); // curses function keys window const int FUNCTION_WIN_HEIGHT = atoi(suggestions.c_str()) + 2; const int FUNCTION_WIN_WIDTH = 4; const int FUNCTION_WIN_BEGIN_Y = CONTEXT_WIN_BEGIN_Y + CONTEXT_WIN_HEIGHT + 1; const int FUNCTION_WIN_BEGIN_X = 0; WINDOW* function_win = newwin(FUNCTION_WIN_HEIGHT, FUNCTION_WIN_WIDTH, FUNCTION_WIN_BEGIN_Y, FUNCTION_WIN_BEGIN_X); draw_function_keys(function_win); mvprintw(LINES - 1, 0, "Press F12 to quit."); refresh(); std::vector<std::string> words; int c = ' '; do { size_t size = words.size(); if ((KEY_F0 < c) && (c <= KEY_F(size)) && (c - KEY_F0 <= size)) { // prediction was successful. user pressed the function // key corresponding to desired token. selecting // suggestion. std::string message = "Last selected word: " + words[c - KEY_F0 - 1]; mvprintw(LINES - 3, 0, message.c_str()); clrtoeol(); move(LINES, COLS); // update buffer with prediction completion buffer << presage.completion(words[c - KEY_F0 - 1]); // ask presage to predict next token words = presage.predict(); } else { // prediction unsuccessful. get next character from user // and elaborate a new prediction. buffer << static_cast<char>(c); words = presage.predict(); // refresh curses screen refresh(); } draw_context_win(context_win, presage.context()); draw_previous_suggestions(words, presage.context_change(), CONTEXT_WIN_BEGIN_Y + CONTEXT_WIN_HEIGHT + 1, FUNCTION_WIN_BEGIN_X + FUNCTION_WIN_WIDTH + 1 ); c = getch(); } while( c != KEY_F(12) ); delwin(title_win); delwin(context_win); delwin(function_win); endwin(); return 0; }