/** * Function used to get an attribute value of a IupCells object * @param h handle to the IupCells object * @param attr attribute to be read * @return the attribute value */ static char* cells_getattrib(Ihandle *h, char *attr) { static char buffer[ 80 ]; TCells* obj = NULL; /* Getting cell struct pointer saved in iup handle */ obj = (TCells*) iupGetEnv(h, "_IUPCELLS_DATA"); if (obj == NULL) return iupCpiDefaultGetAttr(h, attr); /* Sequence of ifs, onde for each attribute */ if (iupStrEqual(attr, IUP_BOXED)) { if (obj->boxed == 0) return IUP_NO; else return IUP_YES; } else if (iupStrEqual(attr, IUP_CLIPPED)) { if (obj->clipped == 0) return IUP_NO; else return IUP_YES; } else if (iupStrEqual(attr, IUP_NO_COLOR)) { return (char*) cd_to_iup(obj->no_color); } else if (iupStrEqual(attr, IUP_IMAGE_CANVAS)) { return (char*) obj->cddbuffer; } else if (iupStrEqual(attr, IUP_CANVAS)) { return (char*) obj->cdcanvas; } else if (iupStrEqual(attr, IUP_FIRST_LINE)) { sprintf(buffer, "%d", get_first_line(obj)); return buffer; } else if (iupStrEqual(attr, IUP_FIRST_COL)) { sprintf(buffer, "%d", get_first_col(obj)); return buffer; } else if (iupStrEqual(attr, IUP_NON_SCROLLABLE_COLS)) { sprintf(buffer, "%d", obj->non_scrollable_cols); return buffer; } else if (iupStrEqual(attr, IUP_NON_SCROLLABLE_LINES)) { sprintf(buffer, "%d", obj->non_scrollable_lins); return buffer; } else if (strstr(attr, IUP_LIMITS)) { int xmin, xmax, ymin, ymax; int i, j; int read = sscanf(attr, "%[^:]:%d:%d", buffer, &i, &j); if (read != 3) return NULL; get_cell_limit(obj, i, j, &xmin, &xmax, &ymin, &ymax); sprintf(buffer, "%d:%d:%d:%d", xmin, xmax, ymin, ymax); return buffer; } /* default case: using default iup search in hash table */ else return iupCpiDefaultGetAttr(h, attr); }
void restart_prompt(int sig) { t_env *env; (void)sig; env = get_t_env(NULL); ft_putchar_fd('\n', get_fd(-1)); display_prompt(env); clear_line(get_first_line(env->le.line)); env->le.line = ft_memalloc(sizeof(t_line)); env->le.line->is_orig = 1; history(RES_ORI, NULL); env->le.pos_x = 4; }
/** * initializes a vector of write buffers with the HTTP message information * * @param write_buffers vector of write buffers to initialize * @param keep_alive true if the connection should be kept alive * @param using_chunks true if the payload content will be sent in chunks */ inline void prepare_buffers_for_send(write_buffers_t& write_buffers, const bool keep_alive, const bool using_chunks) { // update message headers prepare_headers_for_send(keep_alive, using_chunks); // add first message line write_buffers.push_back(boost::asio::buffer(get_first_line())); write_buffers.push_back(boost::asio::buffer(STRING_CRLF)); // append cookie headers (if any) append_cookie_headers(); // append HTTP headers append_headers(write_buffers); }
void print_repo(FILE *f, struct cgit_repo *repo) { fprintf(f, "repo.url=%s\n", repo->url); fprintf(f, "repo.name=%s\n", repo->name); fprintf(f, "repo.path=%s\n", repo->path); if (repo->owner) fprintf(f, "repo.owner=%s\n", repo->owner); if (repo->desc) { char *tmp = get_first_line(repo->desc); fprintf(f, "repo.desc=%s\n", tmp); free(tmp); } if (repo->readme) fprintf(f, "repo.readme=%s\n", repo->readme); if (repo->defbranch) fprintf(f, "repo.defbranch=%s\n", repo->defbranch); if (repo->module_link) fprintf(f, "repo.module-link=%s\n", repo->module_link); if (repo->section) fprintf(f, "repo.section=%s\n", repo->section); if (repo->clone_url) fprintf(f, "repo.clone-url=%s\n", repo->clone_url); fprintf(f, "repo.enable-commit-graph=%d\n", repo->enable_commit_graph); fprintf(f, "repo.enable-log-filecount=%d\n", repo->enable_log_filecount); fprintf(f, "repo.enable-log-linecount=%d\n", repo->enable_log_linecount); if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter) fprintf(f, "repo.about-filter=%s\n", repo->about_filter->cmd); if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter) fprintf(f, "repo.commit-filter=%s\n", repo->commit_filter->cmd); if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter) fprintf(f, "repo.source-filter=%s\n", repo->source_filter->cmd); if (repo->snapshots != ctx.cfg.snapshots) { char *tmp = build_snapshot_setting(repo->snapshots); fprintf(f, "repo.snapshots=%s\n", tmp); free(tmp); } if (repo->max_stats != ctx.cfg.max_stats) fprintf(f, "repo.max-stats=%s\n", cgit_find_stats_periodname(repo->max_stats)); fprintf(f, "\n"); }
t_list *set_first_line(t_list *list) { t_elem *tmp; tmp = list->head; while (tmp != NULL) { if (tmp->status == 0) { if (get_first_line(tmp) == -1) { tmp->status = 1; } } tmp = tmp->next; } return (list); }
/** * IUP canvas callback for mouse press/unpress. */ static int cells_scroll(Ihandle *h) { TScrollCb func = NULL; int value = IUP_DEFAULT; int fline = -999; int fcol = -999; /* Getting cell struct pointer saved in iup handle */ TCells* obj = (TCells*) iupGetEnv(h, "_IUPCELLS_DATA"); if (obj == NULL) return IUP_IGNORE; fline = get_first_line(obj); fcol = get_first_col(obj); /* Checking the existence of a scroll bar callback. If the application * has set one, it will be called now. If the application returns * IUP_DEFAULT, the cells will be repainted. */ func = (TScrollCb) IupGetCallback(h, "SCROLLING_CB"); if (func != NULL) value = (*func)(obj->self, fline, fcol); if (value == IUP_DEFAULT) repaint_all(obj); /* Returning the callback */ return value; }
static void amgtar_selfcheck( application_argument_t *argument) { if (argument->dle.disk) { char *qdisk = quote_string(argument->dle.disk); fprintf(stdout, "OK disk %s\n", qdisk); amfree(qdisk); } printf("OK amgtar version %s\n", VERSION); amgtar_build_exinclude(&argument->dle, 1, NULL, NULL, NULL, NULL); printf("OK amgtar\n"); if (gnutar_path) { if (check_file(gnutar_path, X_OK)) { char *gtar_version; GPtrArray *argv_ptr = g_ptr_array_new(); g_ptr_array_add(argv_ptr, gnutar_path); g_ptr_array_add(argv_ptr, "--version"); g_ptr_array_add(argv_ptr, NULL); gtar_version = get_first_line(argv_ptr); if (gtar_version) { char *gv; for (gv = gtar_version; *gv && !g_ascii_isdigit(*gv); gv++); printf("OK amgtar gtar-version %s\n", gv); } else { printf(_("ERROR [Can't get %s version]\n"), gnutar_path); } g_ptr_array_free(argv_ptr, TRUE); amfree(gtar_version); } } else { printf(_("ERROR [GNUTAR program not available]\n")); } if (gnutar_listdir && strlen(gnutar_listdir) == 0) gnutar_listdir = NULL; if (gnutar_listdir) { check_dir(gnutar_listdir, R_OK|W_OK); } else { printf(_("ERROR [No GNUTAR-LISTDIR]\n")); } set_root_privs(1); if (gnutar_directory) { check_dir(gnutar_directory, R_OK); } else if (argument->dle.device) { check_dir(argument->dle.device, R_OK); } if (argument->calcsize) { char *calcsize = g_strjoin(NULL, amlibexecdir, "/", "calcsize", NULL); check_file(calcsize, X_OK); check_suid(calcsize); amfree(calcsize); } set_root_privs(0); }
static void print_platform(void) { struct stat stat_buf; char *uname; char *distro = NULL; char *platform = NULL; char line[1025]; GPtrArray *argv_ptr; if (stat("/etc/lsb-release", &stat_buf) == 0) { FILE *release = fopen("/etc/lsb-release", "r"); distro = "Ubuntu"; if (release) { char *result; while ((result = fgets(line, 1024, release))) { if (strstr(line, "DESCRIPTION")) { platform = strchr(line, '='); if (platform) platform++; } } fclose(release); } } else if (stat("/etc/redhat-release", &stat_buf) == 0) { FILE *release = fopen("/etc/redhat-release", "r"); distro = "RPM"; if (release) { char *result; result = fgets(line, 1024, release); if (result) { platform = line; } fclose(release); } } else if (stat("/etc/debian_version", &stat_buf) == 0) { FILE *release = fopen("/etc/debian_version", "r"); distro = "Debian"; if (release) { char *result; result = fgets(line, 1024, release); if (result) { platform = line; } fclose(release); } } else { argv_ptr = g_ptr_array_new(); g_ptr_array_add(argv_ptr, UNAME_PATH); g_ptr_array_add(argv_ptr, "-s"); g_ptr_array_add(argv_ptr, NULL); uname = get_first_line(argv_ptr); if (uname) { if (strncmp(uname, "SunOS", 5) == 0) { FILE *release = fopen("/etc/release", "r"); distro = "Solaris"; if (release) { char *result; result = fgets(line, 1024, release); if (result) { platform = line; } } fclose(release); } amfree(uname); } g_ptr_array_free(argv_ptr, TRUE); } if (!distro) { distro = "Unknown"; } if (!platform) { platform = "Unknown"; } if (platform[strlen(platform) -1] == '\n') { platform[strlen(platform) -1] = '\0'; } g_fprintf(stdout, "OK distro %s\n", distro); g_fprintf(stdout, "OK platform %s\n", platform); }
int ff_text_pre_parser ( char *origin, FF_BUFSIZE_PTR fmt_buffer, PP_OBJECT_PTR pp_object ) { BOOLEAN called_untl = FALSE; /* called update_name_table_list */ int error = 0; int new_error = 0; char *current_sect_start; char *text_line; sect_types_t current_sect_type; /* type of the previous section */ sect_types_t sect_type; BOOLEAN first_section = TRUE; assert(fmt_buffer); text_line = get_first_line(fmt_buffer->buffer); first_section = TRUE; current_sect_start = NULL; current_sect_type = ZEROTH_SECT; sect_type = !LAST_SECT; /* MAIN LOOP that parses each line of format buffer */ while (sect_type != LAST_SECT) { char save_char; sect_type = get_section_type(text_line, current_sect_type); switch (sect_type) { case ZEROTH_SECT: case IN_SECT: break; case FMT_SECT: case INPUT_EQV_SECT: case OUTPUT_EQV_SECT: case BEGIN_CONSTANT_SECT: case BEGIN_NAME_EQUIV_SECT: case LAST_SECT: /* case ADD_YOUR_SECTION_TYPE_HERE: */ if (first_section) { first_section = FALSE; } else { FF_BUFSIZE bufsize; /* Process current (previous) section */ bufsize.buffer = current_sect_start; bufsize.bytes_used = bufsize.total_bytes = (FF_BSS_t)((char HUGE *)text_line - (char HUGE *)current_sect_start); save_char = *text_line; *text_line = STR_END; switch (current_sect_type) { case FMT_SECT: if (pp_object->ppo_type == PPO_FORMAT_LIST) { error = update_format_list(origin, &bufsize, pp_object->u.hf_list); new_error = error; } break; case INPUT_EQV_SECT: case OUTPUT_EQV_SECT: case BEGIN_CONSTANT_SECT: case BEGIN_NAME_EQUIV_SECT: if (pp_object->ppo_type == PPO_NT_LIST && SAME_IO_CONTEXT(current_sect_type, pp_object) ) { called_untl = TRUE; error = update_name_table_list(origin, &bufsize, pp_object->u.nt_list.hnt_list); new_error = error; } break; /* case ADD_YOUR_SECTION_TYPE_HERE: */ default: assert(!ERR_SWITCH_DEFAULT); return(err_push(ERR_SWITCH_DEFAULT, "%s, %s:%d", ROUTINE_NAME, os_path_return_name(__FILE__), __LINE__)); } /* switch on current section type */ if (new_error) break; *text_line = save_char; } /* (else) if first section */ current_sect_type = sect_type; current_sect_start = text_line; break; default: assert(!ERR_SWITCH_DEFAULT); return(err_push(ERR_SWITCH_DEFAULT, "%s, %s:%d", ROUTINE_NAME, os_path_return_name(__FILE__), __LINE__)); } /* switch on section type */ if (new_error) break; if (sect_type != LAST_SECT) text_line = get_next_line(text_line); } /* while not the last section */ if (pp_object->ppo_type == PPO_NT_LIST && called_untl == FALSE && !error) return(ERR_NO_NAME_TABLE); return(error); }
static int make_format ( char *origin, FF_BUFSIZE_PTR bufsize, FORMAT_HANDLE hformat ) { char *text_line = NULL; char *fmt_name; int error = 0; assert(hformat); assert(*hformat == NULL); *hformat = NULL; text_line = get_first_line(bufsize->buffer); if (!text_line) return(err_push(ERR_MISSING_TOKEN, "Expecting a newline")); else { FF_TYPES_t check_format_type; if (get_format_type_and_name(text_line, &check_format_type, &fmt_name)) { char *cp; char save_char = STR_END; cp = find_EOL(fmt_name); if (cp) { save_char = *cp; *cp = STR_END; } *hformat = ff_create_format(fmt_name, origin); if (!*hformat) return(ERR_MEM_LACK); (*hformat)->type = check_format_type; if (cp) *cp = save_char; if ((*hformat)->name[0] == '\"') (*hformat)->name[0] = ' '; cp = strrchr((*hformat)->name, '\"'); if (cp) *cp = ' '; os_str_trim_whitespace((*hformat)->name, (*hformat)->name); text_line = get_next_line(text_line); if (!text_line) return(err_push(ERR_VARIABLE_DESC, "Expecting a variable description")); } else { char *cp; char save_char = STR_END; cp = find_EOL(text_line); if (cp) { save_char = *cp; *cp = STR_END; } error = err_push(ERR_UNKNOWN_FORMAT_TYPE, text_line); if (cp) *cp = save_char; return(error); } } while (strlen(text_line)) { if (!is_comment_line(text_line) && strlen(text_line)) { error = add_to_variable_list(text_line, *hformat); if (error && error < ERR_WARNING_ONLY) return(error); } text_line = get_next_line(text_line); } if (IS_ARRAY(*hformat) && IS_RECORD_FORMAT(*hformat)) return(err_push(ERR_MAKE_FORM, "You cannot define a record format containing an array (%s)", (*hformat)->name)); if (!(*hformat)->variables) return(err_push(ERR_NO_VARIABLES, "%s", (*hformat)->name)); if (IS_ASCII(*hformat) && !IS_ARRAY(*hformat) && !IS_VARIED(*hformat)) error = append_EOL_to_format(*hformat); /* experimental */ if (IS_ARRAY(*hformat)) (*hformat)->length = 0; return(error); }