/** Kolorowanie słów. Słowa nie znajdujące się w słowniku - potencjalnie błędne - zostają oznaczone na czerwono. */ static void show_errors() { GtkTextIter start, end, text_end; int i, range; char *word; gunichar *wword; gtk_text_buffer_create_tag(editor_buf, "red_fg", "foreground", "red", "weight", PANGO_WEIGHT_BOLD, NULL); gtk_text_buffer_get_end_iter(editor_buf, &text_end); gtk_text_buffer_get_start_iter(editor_buf, &end); range = gtk_text_buffer_get_char_count(editor_buf); while (!gtk_text_iter_is_end(&end)) { gtk_text_iter_forward_word_end(&end); start = end; gtk_text_iter_backward_word_start(&start); word = gtk_text_iter_get_text(&start, &end); wword = g_utf8_to_ucs4_fast(word, -1, NULL); if (make_lowercase(wword)) { if (!dictionary_find(dict, wword)) gtk_text_buffer_apply_tag_by_name(editor_buf, "red_fg", &start, &end); } g_free(word); g_free(wword); } }
static void read_string( const char *line, int pos, char *value ) { if (sscanf( line+pos, "%s", value ) != 1) { parse_exit( line ); } make_lowercase( value ); }
/** * ファイルロード[拡張子自動判別] * @param filepath ファイルフルパス * @retval true 成功 * @retval false 失敗 */ bool Load(const char* filename) { bool result = false; m_image.Clear(); std::string path(filename); std::string::size_type pos = path.rfind('.'); if (pos != std::string::npos) { const std::string ext = make_lowercase(path.substr(pos+1)); if (ext == "png") { result = LoadPNG(path); } else if (ext == "jpg" || ext == "jpeg") { result = LoadJPG(path); } else if (ext == "tga") { result = LoadTGA(path); } else if (ext == "hdr") { result = LoadHDR(path); } else if (ext == "exr" || ext == "EXR") { result = LoadEXR(path); } } return result; }
void copy_prj_file( FILE *in_prj_file, FILE *out_prj_file ) // Copies input .prj file to output .prj file, and changes any "ZUNITS" line to "ZUNITS NO" { char line [MAXLINE+3]; // add 3 for possible "\r\n\0" terminators char keyword[MAXLINE+3]; char strval [MAXLINE+1]; int pos, pos2; int error = 0; // Read and write .prj files: while (fgets( line, MAXLINE+3, in_prj_file )) { pos = 0; if (sscanf( line, "%s %n", keyword, &pos ) > 0) { // write keyword and optional whitespace error = error || 0 > fprintf( out_prj_file, "%.*s", pos, line ); make_lowercase( keyword ); if (strcmp( keyword, "zunits" ) == 0) { if (sscanf( line+pos, "%s%n", strval, &pos2 ) > 0) { // check that entire value string was read if (line[pos+pos2] != '\0') { // skip input ZUNITS value and write "NO" instead pos += pos2; error = error || 0 > fprintf( out_prj_file, "NO" ); } } } } // write remainder of line read error = error || 0 > fprintf( out_prj_file, "%s", line+pos ); // make sure entire input line has been read and copy remainder of line while (!strchr( line, '\n' ) && fgets( line, MAXLINE+3, in_prj_file )) { error = error || 0 > fprintf( out_prj_file, "%s", line ); } } error = error || fflush( out_prj_file ); if (!feof( in_prj_file )) { error_exit( "Read error occurred on input .prj file." ); } if (error) { error_exit( "Write error occurred on output .prj file." ); } }
bool windy::is_Direction(string w)// makes the string lowercase in order to pass to the function that checks wind direction { string wordsToFind[8] = { "north", "south", "west", "east", "northeast", "northwest", "southwest", "southeast" }; string test = make_lowercase(w); bool answer; for (int i = 0; i < 8; i++) { if (test == wordsToFind[i]){ answer = true; break; } else{ answer = false; } } return answer; }
static int __devinit fsl_ssi_probe(struct platform_device *pdev, const struct of_device_id *match) { struct fsl_ssi_private *ssi_private; int ret = 0; struct device_attribute *dev_attr = NULL; struct device_node *np = pdev->dev.of_node; const char *p, *sprop; const uint32_t *iprop; struct resource res; char name[64]; /* SSIs that are not connected on the board should have a * status = "disabled" * property in their device tree nodes. */ if (!of_device_is_available(np)) return -ENODEV; /* Check for a codec-handle property. */ if (!of_get_property(np, "codec-handle", NULL)) { dev_err(&pdev->dev, "missing codec-handle property\n"); return -ENODEV; } /* We only support the SSI in "I2S Slave" mode */ sprop = of_get_property(np, "fsl,mode", NULL); if (!sprop || strcmp(sprop, "i2s-slave")) { dev_notice(&pdev->dev, "mode %s is unsupported\n", sprop); return -ENODEV; } /* The DAI name is the last part of the full name of the node. */ p = strrchr(np->full_name, '/') + 1; ssi_private = kzalloc(sizeof(struct fsl_ssi_private) + strlen(p), GFP_KERNEL); if (!ssi_private) { dev_err(&pdev->dev, "could not allocate DAI object\n"); return -ENOMEM; } strcpy(ssi_private->name, p); /* Initialize this copy of the CPU DAI driver structure */ memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_dai_template, sizeof(fsl_ssi_dai_template)); ssi_private->cpu_dai_drv.name = ssi_private->name; /* Get the addresses and IRQ */ ret = of_address_to_resource(np, 0, &res); if (ret) { dev_err(&pdev->dev, "could not determine device resources\n"); kfree(ssi_private); return ret; } ssi_private->ssi = ioremap(res.start, 1 + res.end - res.start); ssi_private->ssi_phys = res.start; ssi_private->irq = irq_of_parse_and_map(np, 0); /* Are the RX and the TX clocks locked? */ if (of_find_property(np, "fsl,ssi-asynchronous", NULL)) ssi_private->asynchronous = 1; else ssi_private->cpu_dai_drv.symmetric_rates = 1; /* Determine the FIFO depth. */ iprop = of_get_property(np, "fsl,fifo-depth", NULL); if (iprop) ssi_private->fifo_depth = *iprop; else /* Older 8610 DTs didn't have the fifo-depth property */ ssi_private->fifo_depth = 8; /* Initialize the the device_attribute structure */ dev_attr = &ssi_private->dev_attr; dev_attr->attr.name = "statistics"; dev_attr->attr.mode = S_IRUGO; dev_attr->show = fsl_sysfs_ssi_show; ret = device_create_file(&pdev->dev, dev_attr); if (ret) { dev_err(&pdev->dev, "could not create sysfs %s file\n", ssi_private->dev_attr.attr.name); goto error; } /* Register with ASoC */ dev_set_drvdata(&pdev->dev, ssi_private); ret = snd_soc_register_dai(&pdev->dev, &ssi_private->cpu_dai_drv); if (ret) { dev_err(&pdev->dev, "failed to register DAI: %d\n", ret); goto error; } /* Trigger the machine driver's probe function. The platform driver * name of the machine driver is taken from the /model property of the * device tree. We also pass the address of the CPU DAI driver * structure. */ sprop = of_get_property(of_find_node_by_path("/"), "model", NULL); /* Sometimes the model name has a "fsl," prefix, so we strip that. */ p = strrchr(sprop, ','); if (p) sprop = p + 1; snprintf(name, sizeof(name), "snd-soc-%s", sprop); make_lowercase(name); ssi_private->pdev = platform_device_register_data(&pdev->dev, name, 0, NULL, 0); if (IS_ERR(ssi_private->pdev)) { ret = PTR_ERR(ssi_private->pdev); dev_err(&pdev->dev, "failed to register platform: %d\n", ret); goto error; } return 0; error: snd_soc_unregister_dai(&pdev->dev); dev_set_drvdata(&pdev->dev, NULL); if (dev_attr) device_remove_file(&pdev->dev, dev_attr); irq_dispose_mapping(ssi_private->irq); iounmap(ssi_private->ssi); kfree(ssi_private); return ret; }
/** Sprawdzenie słowa, na którym aktualnie znajduje się kursor. Ewentualne dodanie do słownika. @param[in] item element menu. @param[in] data wskaźnik na wartość. */ static void WhatCheck (GtkMenuItem *item, gpointer data) { GtkWidget *dialog; GtkTextIter start, end; char *word; gunichar *wword; //load_dictionary_from_menu(&dict); // Znajdujemy pozycję kursora gtk_text_buffer_get_iter_at_mark(editor_buf, &start, gtk_text_buffer_get_insert(editor_buf)); // Jeśli nie wewnątrz słowa, kończymy if (!gtk_text_iter_inside_word(&start)) { dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Kursor musi być w środku słowa"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; } // Znajdujemy początek i koniec słowa, a potem samo słowo end = start; gtk_text_iter_backward_word_start(&start); gtk_text_iter_forward_word_end(&end); word = gtk_text_iter_get_text(&start, &end); // Zamieniamy na wide char (no prawie) wword = g_utf8_to_ucs4_fast(word, -1, NULL); if (!make_lowercase(wword)) { dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Podane słowo nie jest słowem słownikowym."); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } else { // Sprawdzamy if (dictionary_find(dict, (wchar_t *)wword)) { dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Wszystko w porządku,\nśpij spokojnie"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } else { // Czas korekty GtkWidget *vbox, *label, *combo; struct word_list hints; int i; wchar_t **words; dictionary_hints(dict, (wchar_t *)wword, &hints); words = (wchar_t **) word_list_get(&hints); dialog = gtk_dialog_new_with_buttons("Korekta", NULL, 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_ADD, GTK_RESPONSE_APPLY, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); // W treści dialogu dwa elementy vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); // Tekst label = gtk_label_new("Słowo nie znajduje się w słowniku. Wybierz \njedną z propozycji lub dodaj słowa do słownika."); gtk_widget_show(label); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 1); // Spuszczane menu combo = gtk_combo_box_text_new(); for (i = 0; i < word_list_size(&hints); i++) { // Combo box lubi mieć Gtk char *uword = g_ucs4_to_utf8((gunichar *)words[i], -1, NULL, NULL, NULL); // Dodajemy kolejny element gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), uword); g_free(uword); } gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 1); gtk_widget_show(combo); gint click = gtk_dialog_run(GTK_DIALOG(dialog)); if (click == GTK_RESPONSE_ACCEPT) { char *korekta = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo)); // Usuwamy stare gtk_text_buffer_delete(editor_buf, &start, &end); // Wstawiamy nowe gtk_text_buffer_insert(editor_buf, &start, korekta, -1); g_free(korekta); } // Proponujemy dodanie słowa do słownika else if (click == GTK_RESPONSE_APPLY) dictionary_insert(dict, wword); gtk_widget_destroy(dialog); } } g_free(word); g_free(wword); }
static void read_hdr_file( FILE *in_hdr_file, int *nrows, int *ncols, double *xmin, double *xmax, double *ymin, double *ymax, float *nodata, int *big_endian, int *skipbytes, int *rowpad, char **software ) { char line [MAXLINE+3]; // add 3 for possible "\r\n\0" terminators char keyword[MAXLINE+3]; char strval [MAXLINE+1]; int pos; char *ptr; int intval; float fltval; double dblval; double xdim = 0.0; double ydim = 0.0; double xcoord; double ycoord; int xcoord_type = 0; int ycoord_type = 0; int bandrow = 0; int totalrow = 0; // Read .hdr file: *big_endian = 0; // default is little-endian (LSBFIRST) *ncols = 0; *nrows = 0; *nodata = -3.40282347e+38; *skipbytes = 0; if (software) { *software = 0; } while (fgets( line, MAXLINE+3, in_hdr_file )) { // error here if line longer than MAXLINE characters? if (sscanf( line, "%s %n", keyword, &pos ) > 0) { make_lowercase( keyword ); if (strcmp( keyword, "ncols" ) == 0) { read_int( line, pos, ncols ); if (*ncols <= 0) { negative_exit( line, *ncols ); } } else if (strcmp( keyword, "nrows" ) == 0) { read_int( line, pos, nrows ); if (*nrows <= 0) { negative_exit( line, *nrows ); } } else if (strcmp( keyword, "xllcorner" ) == 0) { read_double( line, pos, &xcoord ); xcoord_type = 1; } else if (strcmp( keyword, "yllcorner" ) == 0) { read_double( line, pos, &ycoord ); ycoord_type = 1; } else if (strcmp( keyword, "xllcenter" ) == 0) { read_double( line, pos, &xcoord ); xcoord_type = 2; } else if (strcmp( keyword, "yllcenter" ) == 0) { read_double( line, pos, &ycoord ); ycoord_type = 2; } else if (strcmp( keyword, "ulxmap" ) == 0) { read_double( line, pos, &xcoord ); xcoord_type = 3; } else if (strcmp( keyword, "ulymap" ) == 0) { read_double( line, pos, &ycoord ); ycoord_type = 3; } else if (strcmp( keyword, "cellsize" ) == 0) { read_double( line, pos, &xdim ); ydim = xdim; if (xdim == 0.0) { bad_zero_exit( line ); } } else if (strcmp( keyword, "xdim" ) == 0) { read_double( line, pos, &xdim ); if (xdim == 0.0) { bad_zero_exit( line ); } } else if (strcmp( keyword, "ydim" ) == 0) { read_double( line, pos, &ydim ); if (ydim == 0.0) { bad_zero_exit( line ); } } else if (strcmp( keyword, "nodata_value" ) == 0) { read_float( line, pos, nodata ); } else if (strcmp( keyword, "nodata" ) == 0) { read_float( line, pos, nodata ); } else if (strcmp( keyword, "nbands" ) == 0) { read_int( line, pos, &intval ); if (intval != 1) { bad_value_exit( line, "1" ); } } else if (strcmp( keyword, "nbits" ) == 0) { read_int( line, pos, &intval ); if (intval == 8 || intval == 16 || intval != 32) { bad_value_exit( line, "32" ); } } else if (strcmp( keyword, "skipbytes" ) == 0) { read_int( line, pos, skipbytes ); if (*skipbytes < 0) { negative_exit( line, *skipbytes ); } } else if (strcmp( keyword, "bandrowbytes" ) == 0) { read_int( line, pos, &bandrow ); if (bandrow <= 0) { negative_exit( line, bandrow ); } } else if (strcmp( keyword, "totalrowbytes" ) == 0) { read_int( line, pos, &totalrow ); if (totalrow <= 0) { negative_exit( line, totalrow ); } } else if (strcmp( keyword, "bandgapbytes" ) == 0) { read_int( line, pos, &intval ); if (intval != 0) { bad_value_exit( line, "0" ); } } else if (strcmp( keyword, "min_value" ) == 0) { // MIN_VALUE ignored read_float( line, pos, &fltval ); } else if (strcmp( keyword, "max_value" ) == 0) { // MAX_VALUE ignored read_float( line, pos, &fltval ); } else if (strcmp( keyword, "byteorder" ) == 0) { read_string( line, pos, strval ); if (strcmp( strval, "lsbfirst" ) == 0) { *big_endian = 0; } else if (strcmp( strval, "i" ) == 0) { *big_endian = 0; } else if (strcmp( strval, "msbfirst" ) == 0) { *big_endian = 1; } else if (strcmp( strval, "m" ) == 0) { *big_endian = 1; } else { bad_value_exit( line, NULL ); } } else if (strcmp( keyword, "layout" ) == 0) { read_string( line, pos, strval ); if (strcmp( strval, "bip" ) == 0 || strcmp( strval, "bsq" ) == 0 || strcmp( strval, "bil" ) != 0) { bad_value_exit( line, "BIL" ); } } else if (strcmp( keyword, "numbertype" ) == 0) { read_string( line, pos, strval ); if (strcmp( strval, "1_byte_integer" ) == 0 || strcmp( strval, "byte" ) == 0) { bad_value_exit( line, NULL ); } else if (strcmp( strval, "2_byte_integer" ) == 0) { bad_value_exit( line, NULL ); } else if (strcmp( strval, "4_byte_float" ) != 0) { bad_value_exit( line, NULL ); } } else if (strcmp( keyword, "pixeltype" ) == 0) { read_string( line, pos, strval ); if (strcmp( strval, "signedint" ) == 0) { bad_value_exit( line, NULL ); } else if (strcmp( strval, "unsignedint" ) == 0) { bad_value_exit( line, NULL ); } else if (strcmp( strval, "float" ) != 0 && strcmp( strval, "floatingpoint" ) != 0) { bad_value_exit( line, NULL ); } } else if (strcmp( keyword, "offset" ) == 0) { // OFFSET ignored read_float( line, pos, &fltval ); } else if (strcmp( keyword, "scale" ) == 0) { // SCALE ignored read_float( line, pos, &fltval ); } else if (strcmp( keyword, "units" ) == 0) { // UNITS ignored read_string( line, pos, strval ); } else if (strcmp( keyword, "zunits" ) == 0) { // ZUNITS ignored read_string( line, pos, strval ); } else if (strcmp( keyword, "software" ) == 0) { if (software) { free( *software ); *software = (char *)malloc( strlen(line+pos) + 1 ); if (!*software) { error_exit( "Memory allocation error occurred while reading .hdr file." ); } strcpy( *software, line+pos ); ptr = strpbrk( *software, "\r\n" ); if (ptr) { *ptr = '\0'; } } } else { fprintf( stderr, "*** WARNING - " ); fprintf( stderr, "Input .hdr file contains unrecognized keyword at this line:\n" ); fprintf( stderr, "%s\n", line ); } } // make sure entire input line has been read // (and ignore remainder of line - can be used for comments) while (!strchr( line, '\n' ) && fgets( line, MAXLINE+3, in_hdr_file )) { } } if (!feof( in_hdr_file )) { error_exit( "Read error occurred on input .hdr file." ); } // Validate values read from .hdr file: if (*ncols == 0) { error_exit( "Input .hdr file does not specify NCOLS." ); } else if (*nrows == 0) { error_exit( "Input .hdr file does not specify NROWS." ); } if (bandrow && bandrow != 4 * (*ncols)) { prefix_error(); fprintf( stderr, "Input .hdr file contains unsupported value for BANDROWBYTES\n" ); fprintf( stderr, "(expected 4 x NCOLS).\n" ); exit( EXIT_FAILURE ); } bandrow = 4 * (*ncols); if (totalrow) { *rowpad = totalrow - bandrow; } else { *rowpad = 0; } if (*rowpad < 0) { prefix_error(); fprintf( stderr, "Input .hdr file contains bad value for TOTALROWBYTES\n" ); fprintf( stderr, "(expected at least 4 x NCOLS).\n" ); exit( EXIT_FAILURE ); } if (xdim == 0.0) { error_exit( "Input .hdr file does not specify CELLSIZE or XDIM." ); } if (ydim == 0.0) { error_exit( "Input .hdr file does not specify CELLSIZE or YDIM." ); } switch (xcoord_type) { case 1: // XLLCORNER *xmin = xcoord; *xmax = xcoord + xdim * (*ncols); break; case 2: case 3: // XLLCENTER or ULXMAP *xmin = xcoord - xdim * 0.5; *xmax = xcoord + xdim * (*ncols - 0.5); break; default: error_exit( "Input .hdr file does not specify XLLCORNER or XLLCENTER or ULXMAP." ); } switch (ycoord_type) { case 1: // YLLCORNER *ymin = ycoord; *ymax = ycoord + ydim * (*nrows); break; case 2: // YLLCENTER *ymin = ycoord - ydim * 0.5; *ymax = ycoord + ydim * (*nrows - 0.5); break; case 3: // ULYMAP *ymax = ycoord + ydim * 0.5; *ymin = ycoord - ydim * (*nrows - 0.5); break; default: error_exit( "Input .hdr file does not specify YLLCORNER or YLLCENTER or ULYMAP." ); } if (xdim < 0.0 ) { dblval = *xmin; *xmin = *xmax; *xmax = dblval; } if (ydim < 0.0 ) { dblval = *ymin; *ymin = *ymax; *ymax = dblval; } }
bool parse_http( std::string pdata, http_request *req ) { // printf("--------\nparse_http call with packet:\n%s\n-----------\n", pdata.c_str() ); std::string method, path, host, full_url, data; int http=1; int posf, pos, tam; // Find headers part ( before '\r\n' ): if( pos = pdata.find("\r\n\r\n",0) == std::string::npos ) return false; // packet has no http header part data = pdata.substr(0, pos+1); std::vector<std::string> strings = explode( "\r\n", pdata ); if( strings.size() < 2 ) return false; // too low strings // First string must me GET/POST/HEAD std::string line, tmp; line = strings.front(); posf = line.find(" ", 0); // first value before whitespace tmp = line.substr(0, posf); if( tmp == "GET" || tmp == "POST" || tmp == "HEAD" ) { // valid request beginning method = tmp; // find path pos = line.find(" ", posf+1); if( pos == std::string::npos ) return false; tmp = line.substr( posf+1, pos-(posf+1) ); if( tmp == "" ) return false; path = tmp; // http ver.: posf = line.find("\r", pos); if( pos == std::string::npos ) return false; tmp = line.substr(pos+1, posf); if( tmp == "HTTP/1.1" ) http = 1; else if ( tmp == "HTTP/1.0" ) http = 0; else return false; } else return false; // printf("%s","Got method and http version.\n"); // loop trough all other lines // for( std::string& str : strings ) { for( std::vector<std::string>::iterator it = strings.begin(); it != strings.end(); ++it ) { std::string str = *it; if( str.length() < 4 ) continue; posf = str.find(" ", 0); if( posf != std::string::npos ) { // string with spaces tmp = str.substr(0, posf); if( make_lowercase( tmp ) == "host:" ) { tmp = str.substr( posf+1 ); // any spaces more? if( tmp.find(" ", 0) != std::string::npos ) { return false; } host = tmp; // printf("host found: '%s'\n", host.c_str()); break; } } } // if http/1.1, path must begin with / if( http == 1 ) { if( path.substr(0,1) != "/" ) return false; full_url = host + path; } if( http == 0 ) { // address begins with slash? if( path.substr(0,1) == "/" ) { if( host != "" ) full_url = host+path; } else { // path contains full url if( path.substr(0,4) == "http" ) { tmp = path.substr(0, 7); // cut http:// full_url = tmp; // get domain info if( pos = tmp.find("/") != std::string::npos ) { host = path.substr(0, pos); // eg. http://www.ru/ } else { host = path; // eg. http://www.ru } } } } if( host == "" || path == "" || method == "" ) return false; else { req->host = host; req->full_url = full_url; req->method = method; return true; } }