int merge_trees(struct merge_options *o, struct tree *head, struct tree *merge, struct tree *common, struct tree **result) { int code, clean; if (o->subtree_merge) { merge = shift_tree_object(head, merge); common = shift_tree_object(head, common); } if (sha_eq(common->object.sha1, merge->object.sha1)) { output(o, 0, "Already uptodate!"); *result = head; return 1; } code = git_merge_trees(o->call_depth, common, head, merge); if (code != 0) die("merging of trees %s and %s failed", sha1_to_hex(head->object.sha1), sha1_to_hex(merge->object.sha1)); if (unmerged_cache()) { struct string_list *entries, *re_head, *re_merge; int i; string_list_clear(&o->current_file_set, 1); string_list_clear(&o->current_directory_set, 1); get_files_dirs(o, head); get_files_dirs(o, merge); entries = get_unmerged(); re_head = get_renames(o, head, common, head, merge, entries); re_merge = get_renames(o, merge, common, head, merge, entries); clean = process_renames(o, re_head, re_merge); for (i = 0; i < entries->nr; i++) { const char *path = entries->items[i].string; struct stage_data *e = entries->items[i].util; if (!e->processed && !process_entry(o, path, e)) clean = 0; } string_list_clear(re_merge, 0); string_list_clear(re_head, 0); string_list_clear(entries, 1); } else clean = 1; if (o->call_depth) *result = write_tree_from_memory(o); return clean; }
int glob_windows(struct conf **confs) { struct strlist *ig; for(ig=get_strlist(confs[OPT_INCGLOB]); ig; ig=ig->next) if(process_entry(ig, confs)) return -1; return 0; }
void mysh(char **env) { t_envp envp; t_sh_token *token; t_glob_def def; if (!(init_def(&def))) return; msh_init_env(&envp, env); while (42) { token = parsed_entry(&def); if (token && token->up) process_entry(token, &envp); free_sh_token(token); } }
static int process_entry_ref(entry_ref_t *entry_ref, process_params_t *params) { char *data = NULL; int dsize = 0; entry_t *entry = NULL; char *xcap_uri; int res; /* DEBUG_LOG("processing entry-ref with ref \'%s\'\n", STR_OK(entry_ref->ref)); */ if (!entry_ref) return RES_OK; if (!entry_ref->ref) return RES_OK; if (add_uri_to_traversed(params, entry_ref->ref) != 0) { /* It is existing yet? */ ERROR_LOG("Duplicate URI in traversed set\n"); return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */ } /* XCAP query for the ref uri */ xcap_uri = relative2absolute_uri(params->xcap_root, entry_ref->ref); res = xcap_query(xcap_uri, params->xcap_params, &data, &dsize); if (res != 0) { ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap_uri ? xcap_uri: "???"); if (data) cds_free(data); if (xcap_uri) cds_free(xcap_uri); return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */ } if (xcap_uri) cds_free(xcap_uri); /* parse document as an entry element */ if (parse_entry_xml(data, dsize, &entry) != 0) { ERROR_LOG("Parsing problems!\n"); if (entry) free_entry(entry); if (data) cds_free(data); return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */ } if (data) cds_free(data); if (!entry) return RES_INTERNAL_ERR; /* ??? */ res = process_entry(entry, params); free_entry(entry); return res; }
static int process_unmerged_entries (struct merge_options *o, SeafDir *head, SeafDir *merge) { int clean = 1; if (unmerged_index(o->index)) { GList *entries, *p; g_hash_table_remove_all(o->current_file_set); g_hash_table_remove_all(o->current_directory_set); get_files_dirs(o, head); get_files_dirs(o, merge); entries = get_unmerged(o->index); /* We don't want to remove any existing file. */ /* make_room_for_directories_of_df_conflicts(o, entries); */ for (p = entries; p != NULL; p = p->next) { struct stage_data *e = p->data; if (!e->processed && !process_entry(o, e->path, e)) clean = 0; } for (p = entries; p != NULL; p = p->next) { struct stage_data *e = p->data; if (!e->processed && !process_df_entry(o, e->path, e)) clean = 0; } for (p = entries; p != NULL; p = p->next) { struct stage_data *e = p->data; if (!e->processed) { g_warning("Unprocessed path??? %s", e->path); return 0; } g_free(e->path); free(e); } g_list_free(entries); } return clean; }
/* * Process a notify list, either for notifying remote hosts after reboot * or for calling back (local) statd clients when the remote has notified * us of a crash. */ int process_notify_list(void) { notify_list *entry; time_t now; while ((entry = notify) != NULL && NL_WHEN(entry) < time(&now)) { if (process_entry(entry)) { NL_WHEN(entry) = time(NULL) + NOTIFY_TIMEOUT; nlist_remove(¬ify, entry); nlist_insert_timer(¬ify, entry); } else { xlog(L_ERROR, "%s: Can't callback %s (%d,%d), giving up", __func__, NL_MY_NAME(entry), NL_MY_PROG(entry), NL_MY_VERS(entry)); nlist_free(¬ify, entry); } } return 1; }
// Generate a `Process` object for the process associated with `pid`. If // process is not found, we return `None`; error is reserved for the case where // something went wrong. inline Result<Process> process(pid_t pid) { // Find process with pid. Result<PROCESSENTRY32> entry = process_entry(pid); if (entry.isError()) { return WindowsError(entry.error()); } else if (entry.isNone()) { return None(); } HANDLE process_handle = ::OpenProcess( PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, false, pid); if (process_handle == INVALID_HANDLE_VALUE) { return WindowsError("os::process: Call to `OpenProcess` failed"); } SharedHandle safe_process_handle(process_handle, ::CloseHandle); // Get Windows Working set size (Resident set size in linux). PROCESS_MEMORY_COUNTERS proc_mem_counters; BOOL get_process_memory_info = ::GetProcessMemoryInfo( safe_process_handle.get(), &proc_mem_counters, sizeof(proc_mem_counters)); if (!get_process_memory_info) { return WindowsError("os::process: Call to `GetProcessMemoryInfo` failed"); } // Get session Id. pid_t session_id; BOOL process_id_to_session_id = ::ProcessIdToSessionId(pid, &session_id); if (!process_id_to_session_id) { return WindowsError("os::process: Call to `ProcessIdToSessionId` failed"); } // Get Process CPU time. FILETIME create_filetime, exit_filetime, kernel_filetime, user_filetime; BOOL get_process_times = ::GetProcessTimes( safe_process_handle.get(), &create_filetime, &exit_filetime, &kernel_filetime, &user_filetime); if (!get_process_times) { return WindowsError("os::process: Call to `GetProcessTimes` failed"); } // Get utime and stime. ULARGE_INTEGER lKernelTime, lUserTime; // In 100 nanoseconds. lKernelTime.HighPart = kernel_filetime.dwHighDateTime; lKernelTime.LowPart = kernel_filetime.dwLowDateTime; lUserTime.HighPart = user_filetime.dwHighDateTime; lUserTime.LowPart = user_filetime.dwLowDateTime; Try<Duration> utime = Nanoseconds(lKernelTime.QuadPart * 100); Try<Duration> stime = Nanoseconds(lUserTime.QuadPart * 100); return Process( pid, entry.get().th32ParentProcessID, // Parent process id. 0, // Group id. session_id, Bytes(proc_mem_counters.WorkingSetSize), utime.isSome() ? utime.get() : Option<Duration>::none(), stime.isSome() ? stime.get() : Option<Duration>::none(), entry.get().szExeFile, // Executable filename. false); // Is not zombie process. }
ftw_dir (struct ftw_data *data, struct STAT *st, struct dir_data *old_dir) { struct dir_data dir; struct dirent64 *d; int previous_base = data->ftw.base; int result; char *startp; /* Open the stream for this directory. This might require that another stream has to be closed. */ result = open_dir_stream (old_dir == NULL ? NULL : &old_dir->streamfd, data, &dir); if (result != 0) { if (errno == EACCES) /* We cannot read the directory. Signal this with a special flag. */ result = (*data->func) (data->dirbuf, st, FTW_DNR, &data->ftw); return result; } /* First, report the directory (if not depth-first). */ if (!(data->flags & FTW_DEPTH)) { result = (*data->func) (data->dirbuf, st, FTW_D, &data->ftw); if (result != 0) { int save_err; fail: save_err = errno; __closedir (dir.stream); dir.streamfd = -1; __set_errno (save_err); if (data->actdir-- == 0) data->actdir = data->maxdir - 1; data->dirstreams[data->actdir] = NULL; return result; } } /* If necessary, change to this directory. */ if (data->flags & FTW_CHDIR) { if (__fchdir (__dirfd (dir.stream)) < 0) { result = -1; goto fail; } } /* Next, update the `struct FTW' information. */ ++data->ftw.level; startp = __rawmemchr (data->dirbuf, '\0'); /* There always must be a directory name. */ assert (startp != data->dirbuf); if (startp[-1] != '/') *startp++ = '/'; data->ftw.base = startp - data->dirbuf; while (dir.stream != NULL && (d = __readdir64 (dir.stream)) != NULL) { int d_type = DT_UNKNOWN; #ifdef _DIRENT_HAVE_D_TYPE d_type = d->d_type; #endif result = process_entry (data, &dir, d->d_name, NAMLEN (d), d_type); if (result != 0) break; } if (dir.stream != NULL) { /* The stream is still open. I.e., we did not need more descriptors. Simply close the stream now. */ int save_err = errno; assert (dir.content == NULL); __closedir (dir.stream); dir.streamfd = -1; __set_errno (save_err); if (data->actdir-- == 0) data->actdir = data->maxdir - 1; data->dirstreams[data->actdir] = NULL; } else { int save_err; char *runp = dir.content; while (result == 0 && *runp != '\0') { char *endp = strchr (runp, '\0'); // XXX Should store the d_type values as well?! result = process_entry (data, &dir, runp, endp - runp, DT_UNKNOWN); runp = endp + 1; } save_err = errno; free (dir.content); __set_errno (save_err); } if ((data->flags & FTW_ACTIONRETVAL) && result == FTW_SKIP_SIBLINGS) result = 0; /* Prepare the return, revert the `struct FTW' information. */ data->dirbuf[data->ftw.base - 1] = '\0'; --data->ftw.level; data->ftw.base = previous_base; /* Finally, if we process depth-first report the directory. */ if (result == 0 && (data->flags & FTW_DEPTH)) result = (*data->func) (data->dirbuf, st, FTW_DP, &data->ftw); if (old_dir && (data->flags & FTW_CHDIR) && (result == 0 || ((data->flags & FTW_ACTIONRETVAL) && (result != -1 && result != FTW_STOP)))) { /* Change back to the parent directory. */ int done = 0; if (old_dir->stream != NULL) if (__fchdir (__dirfd (old_dir->stream)) == 0) done = 1; if (!done) { if (data->ftw.base == 1) { if (__chdir ("/") < 0) result = -1; } else if (__chdir ("..") < 0) result = -1; } } return result; }
static process_content(FILE *f, FILE *output, FILE* outputHeader) { char token[MAX_START_NAME+1]; /* Must be big enough to hold a tag/attr start string */ char name[MAX_NAME+1]; char optional[MAX_LINE+1]; char *tag_code_page = ""; char *attr_code_page = ""; char processing_tag = 2; /* processing state: 1 = tag, 0 = attribute, 2 = init */ int n = 0; int use_strings = 1; for(;;) { if ((get_tuple(f, token, name, optional)) != 1) { break; } if (!strcmp(token, TAG_TABLE_HEADING)) { use_strings = strcmp(optional, NO_STRINGS); if (processing_tag == 1) { /* Process the current tag table */ print_token_table(output, outputHeader, TAG_NAME, "token", tag_code_page, n, use_strings); print_name_table(output, TAG_NAME, "name", tag_code_page, n, use_strings); cache_codepage(tag_codepages, tag_code_page, n); n = 0; } else if (processing_tag == 0) { /* Process the current attribute table */ print_token_table(output, outputHeader, ATTR_NAME, "token", attr_code_page, n, use_strings); print_name_table(output, ATTR_NAME, "name", attr_code_page, n, use_strings); cache_codepage(attr_codepages, attr_code_page, n); n = 0; } tag_code_page = strdup(name); processing_tag = 1; } else if (!strcmp(token, ATTR_TABLE_HEADING)) { use_strings = strcmp(optional, NO_STRINGS); if (processing_tag == 1) { /* Process the current tag table */ print_token_table(output, outputHeader, TAG_NAME, "token", tag_code_page, n, use_strings); print_name_table(output, TAG_NAME, "name", tag_code_page, n, use_strings); cache_codepage(tag_codepages, tag_code_page, n); n = 0; } else if (processing_tag == 0) { /* Process the current attribute table */ print_token_table(output, outputHeader, ATTR_NAME, "token", attr_code_page, n, use_strings); print_name_table(output, ATTR_NAME, "name", attr_code_page, n, use_strings); cache_codepage(attr_codepages, attr_code_page, n); n = 0; } attr_code_page = strdup(name); processing_tag = 0; } else { process_entry(n, token, name); n++; } } if (processing_tag == 2) { fprintf(stderr, "ERROR: Could not find tag or attribute table starts in file.\n" " Input file syntax has changed.\n" " See usage by executing this program with no arguments.\n"); exit_error(1); } /* * If anything is left, process it */ if (n > 0) { if (processing_tag == 1) { print_token_table(output, outputHeader, TAG_NAME, "token", tag_code_page, n, use_strings); print_name_table(output, TAG_NAME, "name", tag_code_page, n, use_strings); cache_codepage(tag_codepages, tag_code_page, n); } else if (processing_tag == 0) { print_token_table(output, outputHeader, ATTR_NAME, "token", attr_code_page, n, use_strings); print_name_table(output, ATTR_NAME, "name", attr_code_page, n, use_strings); cache_codepage(attr_codepages, attr_code_page, n); } } }
/*============================================================================= * This function processes a directory entry and all it's child nodes */ void process_directory(GMenuTreeDirectory *directory, gboolean isRoot) { int hasSeparator = 0; int hasMenu = 0; GMenuTreeItemType entryType; GSList *entryList = gmenu_tree_directory_get_contents (directory); GSList *l; if (option_do_not_use_categories == 00 && isRoot == 0 && g_slist_length(entryList) > 0) { hasMenu = 1; if (option_show_amount_of_entries == 1) { g_printf( "<menu id=\"xdg-menu-%s\" label=\"%s (%d)\">\n", gmenu_tree_directory_get_name(directory), gmenu_tree_directory_get_name(directory), g_slist_length(entryList)); } else { g_printf( "<menu id=\"xdg-menu-%s\" label=\"%s\">\n", gmenu_tree_directory_get_name(directory), gmenu_tree_directory_get_name(directory)); } } for (l = entryList; l; l = l->next) { GMenuTreeItem *item = l->data; entryType = gmenu_tree_item_get_type (GMENU_TREE_ITEM(item)); switch (entryType) { case GMENU_TREE_ITEM_DIRECTORY: if (hasSeparator) { process_separator(GMENU_TREE_SEPARATOR(item)); hasSeparator = 0; } process_directory(GMENU_TREE_DIRECTORY(item), 0); break; case GMENU_TREE_ITEM_ENTRY: if (hasSeparator) { process_separator(GMENU_TREE_SEPARATOR(item)); hasSeparator = 0; } process_entry(GMENU_TREE_ENTRY(item)); break; case GMENU_TREE_ITEM_SEPARATOR: hasSeparator = 1; break; } gmenu_tree_item_unref (item); } if (hasMenu == 1) { g_printf("</menu>\n"); } g_slist_free (entryList); }
/**************************************************************************** * process_layout_file * * Read CMOS layout information from file 'f' and add it to our internal * repository. ****************************************************************************/ static void process_layout_file(FILE * f) { compile_reg_expr(REG_EXTENDED | REG_NEWLINE, blank_or_comment_regex, &blank_or_comment_expr); compile_reg_expr(REG_EXTENDED | REG_NEWLINE, start_entries_regex, &start_entries_expr); compile_reg_expr(REG_EXTENDED | REG_NEWLINE, entries_line_regex, &entries_line_expr); compile_reg_expr(REG_EXTENDED | REG_NEWLINE, start_enums_regex, &start_enums_expr); compile_reg_expr(REG_EXTENDED | REG_NEWLINE, enums_line_regex, &enums_line_expr); compile_reg_expr(REG_EXTENDED | REG_NEWLINE, start_checksums_regex, &start_checksums_expr); compile_reg_expr(REG_EXTENDED | REG_NEWLINE, checksum_line_regex, &checksum_line_expr); line_num = 1; skip_past_start(f); /* Skip past all entries. We will process these later when we * make a second pass through the file. */ while (!process_entry(f, 1)) ; /* Process all enums, adding them to our internal repository as * we go. */ if (process_enum(f, 0)) { fprintf(stderr, "%s: Error: CMOS layout file contains no " "enumerations.\n", prog_name); exit(1); } while (!process_enum(f, 0)) ; /* Go back to start of file. */ line_num = 1; fseek(f, 0, SEEK_SET); skip_past_start(f); /* Process all entries, adding them to the repository as we go. * We must add the entries after the enums, even though they * appear in the layout file before the enums. This is because * the entries are sanity checked against the enums as they are * added. */ if (process_entry(f, 0)) { fprintf(stderr, "%s: Error: CMOS layout file contains no entries.\n", prog_name); exit(1); } while (!process_entry(f, 0)) ; /* Skip past all enums. They have already been processed. */ while (!process_enum(f, 1)) ; /* Process CMOS checksum info. */ process_checksum_info(f); /* See if there are any lines left to process. If so, verify * that they are all either blank lines or comments. */ skip_remaining_lines(f); regfree(&blank_or_comment_expr); regfree(&start_entries_expr); regfree(&entries_line_expr); regfree(&start_enums_expr); regfree(&enums_line_expr); regfree(&start_checksums_expr); regfree(&checksum_line_expr); }
int main(int argc,char **argv) { char buffer[1024*1024]; if (argc!=3) { fprintf(stderr,"usage: parsecountries ISO_3166-1.xml countries.h\n"); exit(-1); } FILE *f=fopen(argv[1],"r"); if (!f) { perror("Failed to open input file"); exit(-1); } FILE *of=fopen(argv[2],"w"); if (!of) { perror("Failed to open output file"); exit(-1); } fprintf(of, "struct country {\n" " char *country;\n" " char *iso3166_code;\n" "};\n" "\n" "struct country countries[]={\n"); int r=fread(buffer,1,1024*1024,f); fclose(f); char line[1024]; int len=0; int state=0; char country[1024]; char iso_code[1024]; int i; for(i=0;i<r;i++) { if ((buffer[i]=='\n')||(buffer[i]=='\r')) { line[len]=0; switch (state) { case 0: // Waiting for table row if (!strncmp(line,"|-",2)) state=1; break; case 1: // In table row, looking for country name if (sscanf(line,"| [[%[^]]]]",country)==1) state=2; else state=0; break; case 2: // Got country name, looking for data row if (sscanf(line,"| [[ISO 3166-1 alpha-2#%[^|]",iso_code)==1) { state=0; process_entry(of,country,iso_code); } state=0; break; } len=0; } else { if (len<1000) line[len++]=buffer[i]; } } fprintf(of, "{NULL,NULL}\n" "};\n"); fclose(of); fprintf(stderr, "Extracted %d countries from https://en.wikipedia.org/wiki/ISO_3166-1\n", count); return 0; }