void report_selected_products() { if (no_of_prods == 0) LE_send_msg(GL_INFO, "All products selected"); else { int i; char num_buf[50]; char* output_str=NULL; output_str = STR_copy(output_str, ""); for (i = 0; i < no_of_prods; i++) { if (i % 8 == 0) output_str = STR_cat(output_str, "Selected prods: "); sprintf(num_buf, "%d", selected_prods[i]); output_str = STR_cat(output_str, num_buf); if (i % 8 == 7) { LE_send_msg(GL_INFO, output_str); output_str = STR_copy(output_str, ""); } else { if (i < no_of_prods - 1) output_str = STR_cat(output_str, ","); } } if (no_of_prods % 8 != 0) LE_send_msg(GL_INFO, output_str); } }
static void Set_baseline_values () { char *id; int ret; DEAU_attr_t *at; DEAU_get_next_dea (NULL, NULL); ret = DEAU_get_next_dea (&id, &at); while (1) { if (ret == DEAU_DE_NOT_FOUND) break; if (ret < 0) { LE_send_msg (GL_ERROR, "DEAU_get_next_dea failed (%d)", ret); exit (1); } if (at->ats[DEAU_AT_BASELINE][0] == '\0' && at->ats[DEAU_AT_ID][0] != '@') { static char *vb = NULL, *idbuf = NULL; idbuf = STR_copy (idbuf, id); vb = STR_copy (vb, at->ats[DEAU_AT_VALUE]); ret = DEAU_update_attr (idbuf, DEAU_AT_BASELINE, vb); if (ret < 0) { LE_send_msg (GL_ERROR, "DEAU_update_attr (baseline) (%s) failed (%d)", id, ret); exit (1); } } ret = DEAU_get_next_dea (&id, &at); } return; }
/** Read the command line options @param(in) argc - number of arguments @param(in) argv - arguments **/ static int Read_options(int argc, char **argv) { int retval = 1; char* endstr; int input; opterr = 0; while ((input = getopt(argc,argv,"hoO:w:p:s:")) != -1) { switch(input) { case 'o': orpg_format=1; break; case 'O': output_dir = STR_copy(output_dir, optarg); break; case 'p': prod_select_file = STR_copy(prod_select_file, optarg); break; case 's': size_of_index = strtol(optarg, &endstr, 10); if (endstr == optarg) size_of_index = 500; break; case 'w': index_name = STR_copy(index_name, optarg); break; default: retval = 0; printf ("\n\tUsage:\t%s [options] -O output_dir\n",argv[0]); printf ("\n\tDescription:\n"); printf ("\n\t\tWrite ORPG selected ORPG products to files in\n"); printf ("\n\t\the specified output directory as they are generated.\n"); printf ("\n\tOptions:\n\n"); printf ("\t\t-h \t\tPrint usage information\n"); printf ("\t\t-o \t\tGenerate products in orpg format\n"); printf ("\t\t-O \t\tOutput directory\n"); printf ("\t\t-p select_file \tSpecify a product selection file\n"); printf ("\t\t\t\t\tthat allows extraction of specific products\n"); printf ("\t\t-s index_size \tSpecify the number of products\n"); printf ("\t\t \tmaintained by the index\n"); printf ("\t\t-w index_name \tGenerate a wdssII index file\n"); printf ("\t\t\t\t\tindex_name is the name of the wdssII index file\n"); return(retval); break ; } } if (output_dir == NULL) { printf("Error, -O option is required\n"); exit(1); } return(retval); }
static void fill_files(const char *root, bool recursive) { DIR *dir; char *path; struct dirent *dirent; char *file_name; const char *name; const char *file; struct stat info; const char *ext; path = STR_copy(root); dir = opendir(path); if (!dir) { fprintf(stderr, "gbc: cannot browse directory: %s\n", path); exit(1); } while ((dirent = readdir(dir)) != NULL) { file_name = dirent->d_name; if (*file_name == '.') continue; file = FILE_cat(path, file_name, NULL); if (stat(file, &info)) { fprintf(stderr, "gbc: warning: cannot stat file: %s\n", file); continue; } if (S_ISDIR(info.st_mode)) { if (recursive) fill_files(file, TRUE); } else { ext = FILE_get_ext(file); if ((strcmp(ext, "module") == 0) || (strcmp(ext, "class") == 0)) { *((char **)ARRAY_add(&_files)) = STR_copy(file); // Add the class to the list of classes name = FILE_get_basename(file_name); COMPILE_add_class(name, strlen(name)); } } } closedir(dir); STR_free(path); }
/*# Generate an xml string */ static int generate_xml_string(Prod_header* product, const char* file_name) { static char* xml_string = NULL; int rda_elev_indx; char text[100]; struct tm* time; char* desc = NULL; int i; int status; int lb_fd; float elevation; xml_string = STR_copy(xml_string, "<item>\n <time fractional=\"0.000000\"> "); sprintf(text, "%d", (int) product->elev_t); xml_string = STR_cat(xml_string, text); xml_string = STR_cat(xml_string, " </time>\n <params>NIDS FlatFile "); xml_string = STR_cat(xml_string, output_dir); xml_string = STR_cat(xml_string, " "); xml_string = STR_cat(xml_string, get_type_string(product)); xml_string = STR_cat(xml_string, " "); xml_string = STR_cat(xml_string, file_name); xml_string = STR_cat(xml_string, " </params>\n <selections> "); time = gmtime((const time_t*)&product->elev_t); sprintf(text, "%4.4d%2.2d%2.2d-%2.2d%2.2d%2.2d ", time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec); xml_string = STR_cat(xml_string, text); desc = STR_copy(desc, ORPGPAT_get_description(product->g.prod_id, STRIP_MNEMONIC)); for (i=0; (i < strlen(desc)); i++) { if (desc[i] == ' ') desc[i] = '_'; } xml_string = STR_cat(xml_string, desc); STR_free(desc); rda_elev_indx = ORPGVST_get_rda_index(product->g.elev_ind); elevation = ((float)ORPGVST_get_elevation(rda_elev_indx)) / 10; if (ORPGPAT_get_type(product->g.prod_id) == 0) elevation = 0.0; sprintf(text, " %2.2f </selections>\n</item>\n", elevation); xml_string = STR_cat(xml_string, text); lb_fd = get_index_lb(); if (lb_fd >= 0) { LE_send_msg(GL_INFO, "Writing xml string"); LE_send_wrapped_string(GL_INFO, xml_string, 150); status = LB_write(lb_fd, xml_string, strlen(xml_string) + 1, LB_ANY); if (status < 0) LE_send_msg(GL_INFO, "Error (%d) writing to index lb", status); } return(lb_fd); }
static char *Get_full_path (char *name) { char dir[MAX_NAME_SIZE], *b; if (name[0] == '/') return (STR_copy (NULL, name)); if (MISC_get_work_dir (dir, MAX_NAME_SIZE) <= 0) { LE_send_msg (GL_ERROR, "$WORK_DIR not found"); return (NULL); } b = STR_copy (NULL, dir); b = STR_cat (b, "/"); b = STR_cat (b, name); return (b); }
/*# Open/Create Index LB */ int get_index_lb() { static int lb_fd = -1; if (lb_fd < 0) { char* lb_name = NULL; lb_name = STR_copy(lb_name, output_dir); if (lb_name[strlen(lb_name) - 1] != '/') lb_name = STR_cat(lb_name, "/"); lb_name = STR_cat(lb_name, index_name); lb_fd = LB_open(lb_name, LB_READ | LB_WRITE, NULL); if (lb_fd < 0) { LB_attr attr; strcpy(attr.remark, "Index LB"); attr.mode = 0666; attr.msg_size = 0; attr.maxn_msgs = size_of_index; attr.types = LB_FILE; attr.tag_size = (30 << NRA_SIZE_SHIFT); lb_fd = LB_open(lb_name, LB_READ | LB_WRITE | LB_CREATE, &attr); if (lb_fd < 0) { LE_send_msg(GL_ERROR, "Error %d creating index lb %s", lb_fd, lb_name); } } } return(lb_fd); }
static void Reset () { Trans_bytes = Total_bytes = 0; Prev_time = Get_time (); Cancelled = 0; Operation = STR_copy (Operation, ""); Hide (); }
static void RefreshAppearance () { static char *operation_text = NULL; XmString label; Window window; window = XtWindow (Progress_widget); XSetForeground (display, Progress_gc, hci_get_read_color (WHITE)); XSetBackground (display, Progress_gc, hci_get_read_color (WHITE)); XFillRectangle (display, window, Progress_gc, 0, 0, PROGRESS_BAR_WIDTH, PROGRESS_BAR_HEIGHT); XSetForeground (display, Progress_gc, hci_get_read_color (BLACK)); XFillRectangle (display, window, Progress_gc, 0, 0, Bar_width, PROGRESS_BAR_HEIGHT); operation_text = STR_copy (operation_text, "Operation:\t"); operation_text = STR_cat (operation_text, Operation); label = XmStringCreateLocalized (operation_text); XtVaSetValues (Operation_label, XmNlabelString, label, NULL); XmStringFree (label); label = XmStringCreateLocalized (Transfer_op_label_str); XtVaSetValues (Transfer_op_label, XmNlabelString, label, NULL); XmStringFree (label); label = XmStringCreateLocalized (Transfer_rate_label_str); XtVaSetValues (Transfer_rate_label, XmNlabelString, label, NULL); XmStringFree (label); if( Visible ){ XmUpdateDisplay( Main_widget ); } }
static void Initialize () { char dir[IAD_NAME_SIZE]; int ret; ret = MISC_get_cfg_dir (dir, IAD_NAME_SIZE); if (ret < 0) { LE_send_msg (GL_ERROR, "MISC_get_cfg_dir failed (%d)", ret); exit (1); } Cfg_dea = STR_copy (Cfg_dea, dir); Cfg_dea = STR_cat (Cfg_dea, "/dea"); Cfg_dir = STR_copy (Cfg_dir, dir); if (ORPGMISC_is_operational () && strcmp (Type, "init") != 0) Operational = 1; }
int FE_get_eq_code (char **code) { int level, max, cnt; *code = STR_copy (*code, ""); cnt = 0; level = 0; max = 0; while (level <= max) { int i; for (i = 0; i < N_eqs; i++) { Eq_t *eq = Eqs + i; if (eq->level > max) max = eq->level; if (eq->level == level && (eq->id1->prop & P_USED)) { char b[256]; if (eq->cast != NULL) { sprintf (b, "%s /* %s */\n", eq->cast, eq->eq); *code = STR_cat (*code, b); cnt++; } else { sprintf (b, "/* TBD: equivalence %s */\n", eq->eq); *code = STR_cat (*code, b); cnt++; } } } level++; } return (cnt); }
static int Read_dea_files (char *suffix, char *dir_name) { DIR *dir; char *vb; struct dirent *dp; int de_cnt; dir = opendir (dir_name); if (dir == NULL) { if (errno == ENOENT) { LE_send_msg (GL_INFO, "dir %s not found\n", dir_name); return (0); } LE_send_msg (GL_ERROR, "opendir (%s) failed, errno %d\n", dir_name, errno); return (0); } vb = NULL; vb = STR_reset (vb, 128); de_cnt = 0; while ((dp = readdir (dir)) != NULL) { int ret; struct stat st; if (strcmp (dp->d_name, ".") == 0 || strcmp (dp->d_name, "..") == 0 || dp->d_name[strlen (dp->d_name) - 1] == '%') continue; vb = STR_copy (vb, dir_name); vb = STR_cat (vb, "/"); vb = STR_cat (vb, dp->d_name); ret = stat (vb, &st); if (ret < 0) continue; if (S_ISREG (st.st_mode)) { int ln, ls; if (suffix != NULL && ((ln = strlen (dp->d_name)) < (ls = strlen (suffix)) || strcmp (dp->d_name + (ln - ls), suffix) != 0)) continue; LE_send_msg (GL_INFO, "read DEA file %s\n", vb); ret = DEAU_use_attribute_file (vb, 0); if (ret < 0) { LE_send_msg (GL_ERROR, "DEAU_use_attribute_file (%s) failed (%d)\n", vb, ret); exit (1); } else de_cnt += ret; } } STR_free (vb); closedir (dir); return (de_cnt); }
void OC_prepare_for_restart (int argc, char **argv) { int i; Cmd = STR_copy (Cmd, ""); for (i = 0; i < argc; i++) { Cmd = STR_cat (Cmd, argv[i]); Cmd = STR_cat (Cmd, " "); } Cmd = STR_cat (Cmd, "&"); }
/* Generate the output file */ static int generate_output_file(const char* file_name, void* product, int product_len) { static char* complete_file_name = NULL; int len; FILE* file; int ret = 0; static char* mkdir_command = NULL; if (mkdir_command == NULL) { mkdir_command = STR_copy(mkdir_command, "mkdir -p "); mkdir_command = STR_cat(mkdir_command, output_dir); system(mkdir_command); } complete_file_name = STR_copy(complete_file_name, output_dir); len = strlen(complete_file_name); if ((len > 0) && (complete_file_name[len-1] != '/')) complete_file_name = STR_cat(complete_file_name, "/"); complete_file_name = STR_cat(complete_file_name, file_name); LE_send_msg(GL_INFO, "Open %s", complete_file_name); file = fopen(complete_file_name, "w"); if (file != NULL) { LE_send_msg(GL_INFO, "Write product, length = %d", product_len); errno = 0; ret = fwrite_retry(product, product_len, 1, file); if (ret == 0) { LE_send_msg(GL_ERROR, "Error %d writing file:", errno); LE_send_wrapped_string(GL_ERROR, complete_file_name, 150); } fclose(file); chmod(complete_file_name, 0666); } else { LE_send_msg(GL_ERROR, "Error %d opening file:", errno); LE_send_wrapped_string(GL_ERROR, complete_file_name, 150); } return(ret != 0); }
void UIPM_set_operation (const char* operation) { char *p; Operation = STR_copy (Operation, operation); p = Operation + strlen (Operation) - 1; /* remove trailing \n */ while (p >= Operation && *p == '\n') { *p = '\0'; p--; } Operate = 1; }
static int Search_resource_config () { char *line, *l; line = CS_THIS_LINE; while (1) { int cnt, i; char conf_name[MRPG_NAME_SIZE], name[MRPG_NAME_SIZE]; CS_control (CS_KEY_OPTIONAL); if (CS_entry (line, 0, MRPG_NAME_SIZE, conf_name) <= 0) break; if (strcmp (conf_name, "node_names") == 0 || strncmp (conf_name, "ras_", 4) == 0 || CS_level (CS_DOWN_LEVEL) < 0) { line = CS_NEXT_LINE; continue; } cnt = 0; l = CS_THIS_LINE; while (1) { if (CS_entry (l, 0, MRPG_NAME_SIZE, name) <= 0) { if (cnt > 0) { /* found the config */ CS_level (CS_UP_LEVEL); CS_entry (conf_name, 0, MRPG_NAME_SIZE, name); CS_level (CS_DOWN_LEVEL); LE_send_msg (GL_INFO, "Resource config %s selected", name); Res_name = STR_copy (Res_name, name); return (0); } break; } for (i = 0; i < N_nodes; i++) { if (strcmp (name, Nodes[i].node) == 0) break; } if (i >= N_nodes) { if (strcmp (name, "replicate") != 0 && strcmp (name, "multicast") != 0) break; } else if (!Nodes[i].is_connected) break; else cnt++; l = CS_NEXT_LINE; } CS_level (CS_UP_LEVEL); line = CS_NEXT_LINE; } return (-1); }
char *STR_cat (char *dest_str, const char *src_str) { int nb; if (dest_str == NULL || ((Str_hd_t *)(dest_str - sizeof (Str_hd_t)))->n_bytes == 0) return (STR_copy (dest_str, src_str)); nb = strlen (dest_str) + strlen (src_str) + 1; dest_str = Str_expand (dest_str, nb); strcat (dest_str, src_str); ((Str_hd_t *)(dest_str - sizeof (Str_hd_t)))->n_bytes = nb; return (dest_str); }
char *STR_gen (char *str, ...) { va_list args; char *p; int cnt; va_start (args, str); cnt = 0; while (1) { p = va_arg (args, char *); if (p == NULL) break; if (cnt == 0) str = STR_copy (str, p); else str = STR_cat (str, p); cnt++; } va_end (args); return (str); }
void UIPM_create (int cancel_type, int simulation_speed, int low_bandwidth, XtAppContext app_context, Widget parent) { if (low_bandwidth || simulation_speed > 0) { Cancel_type = cancel_type; Simulation_speed = simulation_speed; Low_bandwidth = low_bandwidth; Operation = STR_copy (Operation, ""); Trans_bytes = Total_bytes = 0; Cancelled = 0; Visible = 0; if (!Initialized) { display = XtDisplay (parent); App_context = app_context; Create (parent); Initialized = 1; } Reset (); Operate = 1; Listen (1); } }
static void Set_to_defaults (int force) { char site[128], *p; char *id, *lid; int ret; if ((p = ORPGMISC_get_site_name ("site")) == NULL) { LE_send_msg (GL_INFO, "Site name not available - default values not used"); return; } strncpy (site, p, 128); site [127] = '\0'; DEAU_get_next_dea (NULL, NULL); ret = DEAU_get_next_dea (&id, NULL); lid = NULL; while (1) { if (ret == DEAU_DE_NOT_FOUND) break; if (ret < 0) { LE_send_msg (GL_ERROR, "DEAU_get_next_dea failed (%d)", ret); exit (1); } lid = STR_copy (lid, id); ret = DEAU_use_default_values (lid, site, force); if (ret < 0 && ret != DEAU_DEFAULT_NOT_FOUND && ret != DEAU_DE_NOT_FOUND) { LE_send_msg (GL_ERROR, "DEAU_use_default_values failed (%d)", ret); exit (1); } ret = DEAU_get_next_dea (&id, NULL); } STR_free (lid); return; }
char *STR_create (const void *orig_str) { return (STR_copy (NULL, (char *)orig_str)); }
static int Read_options (int argc, char **argv) { extern char *optarg; /* used by getopt */ extern int optind; /* used by getopt */ int c; int err; /* error flag */ err = 0; while ((c = getopt (argc, argv, "n:r:c:p:t:sC:l:vh?")) != EOF) { switch (c) { char tok[256], *sep; case 'n': if (sscanf (optarg, "%d", &Max_static_msgs) != 1) err = 1; break; case 'p': if (sscanf (optarg, "%d", &Poll_ms) != 1) err = 1; break; case 'c': if (sscanf (optarg, "%d", &Server_port) != 1) err = 1; break; case 't': Byteswap_func = STR_copy (NULL, optarg); break; case 'l': Le_label = STR_copy (NULL, optarg); break; case 's': Static_rep_only = 1; break; case 'r': sep = "S,"; if (MISC_get_token (optarg, sep, 1, tok, 0) <= 0) sep = "S-"; if (MISC_get_token (optarg, sep, 1, tok, 256) > 0) { Lb_rep_pair *rep = Rep_list + N_reps; rep->dest_name = STR_copy (NULL, tok); MISC_get_token (optarg, sep, 0, tok, 256); rep->src_name = STR_copy (NULL, tok); if (MISC_get_token (optarg, sep, 2, tok, 256) > 0) rep->data_type = STR_copy (NULL, tok); else rep->data_type = NULL; rep->src = rep->dest = -1; rep->stype = 0; rep->ids = NULL; N_reps++; } else { MISC_log ("bad argument in -r option (%s)\n", optarg); err = 1; } break; case 'C': if (sscanf (optarg, "%d", &Comp_type) != 1) err = 1; if (Comp_type != MISC_GZIP && Comp_type != MISC_BZIP2) { MISC_log ("bad argument in -C option (%s)\n", optarg); err = 1; } break; case 'v': Verbose = 1; break; case 'h': case '?': err = 1; break; default: MISC_log ("Unexpected option (-%c)\n", c); err = 1; break; } } if (N_reps == 0 && err == 0) { MISC_log ("no replication path specified\n"); exit (0); } if (Static_rep_only && Max_static_msgs == 0) { MISC_log ("Number of static messages to replicate not specified\n"); exit (0); } if (err == 1) { /* Print usage message */ printf ("Usage: %s options\n", argv[0]); printf (" options: \n"); printf (" -r src_lb_name,dest_lb_name,type (Multiple -r options\n"); printf (" are fine. '-' can be used to replace ','. \"type\" is\n"); printf (" optional. It is the data type for byte swapping)\n"); printf (" -t lib_file:func_name (SMI lib name and function for byte\n"); printf (" swapping. func_name is optional with SMI_get_info assumed)\n"); printf (" -c server_port_number\n"); printf (" -n max_static_msg_number (maximum number of existing messages\n"); printf (" replicated. For DB, all existing messages are replicated\n"); printf (" if non-zero. The default is 0)\n"); printf (" -s (static, i.e. existing message, replication only)\n"); printf (" -p poll_ms (milli-seconds between each poll in dynamic\n"); printf (" replication. The default is 500 ms (.5 second))\n"); printf (" -C cmp_method (0 = gzip or 1 = bzip2. Multiple messages\n"); printf (" are read, packed and compressed on the reading side.\n"); printf (" Messages are then uncompressed, unpacked and written to the\n"); printf (" destination. Message queue LB only)\n"); printf (" -l LE_lable (sets LE message label. \"stderr\" directs to STDERR)\n"); printf (" -v (verbose mode)\n"); return (-1); } return (0); }
static void Create (Widget parent) { XGCValues gcv; Widget frame; Widget progress_row_column; HCI_Shell_init( &Main_widget, "Data Transfer Meter" ); Main_form = XtVaCreateWidget ("Main_form", xmFormWidgetClass, Main_widget, XmNmarginWidth, 5, XmNmarginHeight, 5, XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL, XmNbackground, hci_get_read_color (BACKGROUND_COLOR1), XmNforeground, hci_get_read_color (TEXT_FOREGROUND), NULL); frame = XtVaCreateManagedWidget ("frame_widget", xmFrameWidgetClass, Main_form, XmNshadowType, XmSHADOW_ETCHED_IN, XmNshadowThickness, 5, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbackground, hci_get_read_color (BACKGROUND_COLOR1), XmNforeground, hci_get_read_color (TEXT_FOREGROUND), NULL); progress_row_column = XtVaCreateWidget ("form", xmRowColumnWidgetClass, frame, XmNorientation, XmVERTICAL, XmNmarginWidth, 5, XmNmarginHeight, 5, XmNbackground, hci_get_read_color (BACKGROUND_COLOR1), XmNforeground, hci_get_read_color (TEXT_FOREGROUND), NULL); Operation_label = XtVaCreateManagedWidget (" ", xmLabelWidgetClass, progress_row_column, XmNbackground, hci_get_read_color (BACKGROUND_COLOR1), XmNforeground, hci_get_read_color (TEXT_FOREGROUND), XmNfontList, hci_get_fontlist (LIST), NULL); Progress_widget = XtVaCreateManagedWidget ("meter", xmDrawingAreaWidgetClass, progress_row_column, XmNwidth, PROGRESS_BAR_WIDTH, XmNheight, PROGRESS_BAR_HEIGHT, NULL); gcv.foreground = BlackPixelOfScreen (XtScreen (Progress_widget)); Progress_gc = XCreateGC (XtDisplay (Progress_widget), RootWindowOfScreen (XtScreen (Progress_widget)), GCForeground, &gcv); Transfer_op_label_str = STR_copy (Transfer_op_label_str, "No data received or sent"); Transfer_op_label = XtVaCreateManagedWidget ("bottom_label", xmLabelWidgetClass, progress_row_column, XmNbackground, hci_get_read_color (BACKGROUND_COLOR1), XmNforeground, hci_get_read_color (TEXT_FOREGROUND), XmNfontList, hci_get_fontlist (LIST), NULL); Transfer_rate_label = XtVaCreateManagedWidget ("Transfer_rate_label", xmLabelWidgetClass, progress_row_column, XmNbackground, hci_get_read_color (BACKGROUND_COLOR1), XmNforeground, hci_get_read_color (TEXT_FOREGROUND), XmNfontList, hci_get_fontlist (LIST), NULL); Transfer_rate_label_str = STR_copy (Transfer_rate_label_str, "Transferred 0 bytes in 0.0 seconds (0.0 K/s)"); XtManageChild (progress_row_column); /* Create cancel button as unmanaged */ Cancel_form = XtVaCreateWidget ("Cancel_form", xmFormWidgetClass, Main_form, XmNfractionBase, 3, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, progress_row_column, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNmarginWidth, 5, XmNmarginHeight, 5, XmNbackground, hci_get_read_color (BACKGROUND_COLOR1), XmNforeground, hci_get_read_color (TEXT_FOREGROUND), NULL); Cancel_button = XtVaCreateManagedWidget ("Cancel", xmPushButtonWidgetClass, Cancel_form, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 2, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNbackground, hci_get_read_color (BACKGROUND_COLOR1), XmNforeground, hci_get_read_color (TEXT_FOREGROUND), XmNfontList, hci_get_fontlist (LIST), NULL); XtAddCallback (Cancel_button, XmNactivateCallback, Cancel_button_cb, NULL); XtManageChild (Cancel_form); HCI_Shell_start( Main_widget, RESIZE_HCI ); }
int GDCF_install_file () { char *p, path[MAX_STR_SIZE], dest[MAX_STR_SIZE]; char new_name[MAX_STR_SIZE]; char buf[MAX_STR_SIZE * 2 + 128], tok[MAX_STR_SIZE]; int nt, is_gz, is_tar, len, path_levels; p = Install_path; if (p == NULL) { unlink (Out_fname); if (VERBOSE) printf ("Install not needed for this node and site\n"); return (0); } if (strlen (p) + 32 > MAX_STR_SIZE) GDCP_exception_exit ("Install file name (%s) too long\n", p); GDCM_strlcpy (path, p, MAX_STR_SIZE); is_gz = is_tar = 0; if (Link_path[0] == '\0' || !Is_link) { nt = MISC_get_token (path, "S.", 0, NULL, 0); if (nt > 1 && GDCM_stoken (path, "S.", nt - 1, tok, MAX_STR_SIZE) > 0) { if (strcmp (tok, "gz") == 0) { if (nt > 2 && GDCM_stoken (path, "S.", nt - 2, tok, MAX_STR_SIZE) > 0 && strcmp (tok, "tar") == 0) is_tar = 1; is_gz = 1; } else if (strcmp (tok, "tar") == 0) is_tar = 1; } } len = 0; if (is_gz) len += 3; if (is_tar) len += 4; path[strlen (path) - len] = '\0'; if (is_tar) { char tmp[MAX_STR_SIZE]; int i; if (rename (Out_fname, MISC_basename (path)) < 0) GDCP_exception_exit ("rename (%s %s) failed\n", Out_fname, MISC_basename (path)); strcpy (tmp, path); i = 0; while (path[i] != '\0') { if (path[i] == ':') path[i] = '_'; i++; } GDCM_strlcat (path, ".tar", MAX_STR_SIZE); GDCM_strlcpy (new_name, MISC_basename (path), MAX_STR_SIZE); sprintf (buf, "tar cf %s %s", new_name, MISC_basename (tmp)); if (Run_cmd (buf) != 0) exit (1); unlink (MISC_basename (tmp)); } else strcpy (new_name, Out_fname); if (path[0] == '/') { GDCM_strlcpy (dest, "root/", MAX_STR_SIZE); GDCM_strlcat (dest, path + 1, MAX_STR_SIZE); } else if (path[0] == '.' && path[1] == '/') { GDCM_strlcpy (dest, path + 2, MAX_STR_SIZE); } else { GDCM_strlcpy (dest, "user/", MAX_STR_SIZE); GDCM_strlcat (dest, path, MAX_STR_SIZE); } path_levels = MISC_get_token (path, "S/", 0, NULL, 0) - 1; GDCM_add_dir (Dest_dir, dest, MAX_STR_SIZE); if (MISC_mkdir (MISC_dirname (dest, buf, MAX_STR_SIZE))) GDCP_exception_exit ("MISC_mkdir (%s) failed\n", buf); if (Link_path[0] == '\0' || !Is_link) { if (rename (new_name, dest) < 0) GDCP_exception_exit ("Failed in installing (rename) (%s)\n", dest); } else { int i; char *name = NULL; name = STR_copy (name, ""); for (i = 0; i < path_levels; i++) name = STR_cat (name, "../"); name = STR_cat (name, Link_path); name = STR_cat (name, "/"); name = STR_cat (name, MISC_basename (dest)); unlink (dest); if (symlink (name, dest) < 0) GDCP_exception_exit ( "Failed in installing (symlink) link (%s)\n", dest); STR_free (name); name = NULL; if (!File_exist) { name = STR_gen (name, Shared_dir, "/", MISC_basename (dest), NULL); if (MISC_mkdir (MISC_dirname (name, buf, MAX_STR_SIZE))) GDCP_exception_exit ("MISC_mkdir (%s) failed\n", buf); if (rename (new_name, name) < 0) GDCP_exception_exit ( "Failed in installing shared (%s)\n", name); STR_free (name); } } if (is_gz) { sprintf (buf, "gzip -f %s", dest); if (Run_cmd (buf) != 0) exit (1); GDCM_strlcat (dest, ".gz", MAX_STR_SIZE); } printf ("Created %s\n", dest); return (1); }
static int OnTransferEvent (rmt_transfer_event_t *event) { static int rpc_started = 0; static double last_update_time = 0.0; char sprintf_str[200]; double new_time, rate; if (event->event != RMT_DATA_SENT && event->event != RMT_DATA_RECEIVED) return(0); if (Cancelled) return (Cancelled); new_time = Get_time (); Trans_bytes += event->no_of_segment_bytes; if (event->no_of_bytes == 0) { if (!rpc_started) { Total_bytes += event->total_no_of_bytes; rpc_started = 1; } } else rpc_started = 0; if (new_time - last_update_time < .2) { SleepForSimulation (event); return (Cancelled); } last_update_time = new_time; Show (); if (Total_bytes > 0.) Bar_width = Trans_bytes * PROGRESS_BAR_WIDTH / Total_bytes; else Bar_width = 0; if (Bar_width > PROGRESS_BAR_WIDTH) Bar_width = PROGRESS_BAR_WIDTH; if (new_time - Prev_time > 0.0) rate = ((double)Trans_bytes / 1024.0) / (new_time - Prev_time); else rate = 0.0; sprintf (sprintf_str, "Transferred %d bytes in %1.2f seconds (%1.2f K/s)", Trans_bytes, new_time - Prev_time, rate); Transfer_rate_label_str = STR_copy (Transfer_rate_label_str, sprintf_str); if (event->event == RMT_DATA_RECEIVED) sprintf (sprintf_str, "Receiving %d bytes - (%d of %d received)", event->no_of_segment_bytes, event->no_of_bytes, event->total_no_of_bytes); else sprintf (sprintf_str, "Sending %d bytes - (%d of %d sent)", event->no_of_segment_bytes, event->no_of_bytes, event->total_no_of_bytes); Transfer_op_label_str = STR_copy (Transfer_op_label_str, sprintf_str); RefreshAppearance (); /* Refresh the appearance */ if (Cancelled) { Hide (); return (Cancelled); } SleepForSimulation (event); return (Cancelled); }
parent_get(str, len, 1); } static void save_action(bool delete) { FILE *file; const char *path; char *name; const char *line; int len; path = FILE_cat(FILE_get_dir(COMP_project), ".action", NULL); mkdir(path, 0777); FILE_set_owner(path, COMP_project); name = STR_copy(FILE_set_ext(FILE_get_name(JOB->form), "action")); path = FILE_cat(FILE_get_dir(COMP_project), ".action", name, NULL); if (delete) { if (FILE_exist(path)) { if (JOB->verbose) printf("Deleting action file %s\n", path); FILE_unlink(path); } } else { if (JOB->verbose)
static void Init_dea_database () { char *db_name; int ret, de_cnt; struct stat st; char *path, *p; db_name = ORPGDA_lbname (ORPGDAT_ADAPT_DATA); if (db_name == NULL) { LE_send_msg (GL_ERROR, "ORPGDA_lbname (%d) failed", ORPGDAT_ADAPT_DATA); exit (1); } DEAU_LB_name (db_name); ret = DEAU_get_string_values ("RPG_DEA_DB_init_state", &p); if (ret > 0 && strcmp (p, "init completed") == 0) { LE_send_msg (GL_INFO, "DEA database exits - not initialized\n"); exit (0); } path = NULL; path = STR_copy (path, Cfg_dir); path = STR_cat (path, "/site_info.dea"); if (stat (path, &st) < 0) { LE_send_msg (GL_INFO, "site_info.dea not found in %s - Use existing data\n", Cfg_dir); exit (0); } STR_free (path); DEAU_special_suffix ("alg"); de_cnt = Read_dea_files (".dea", Cfg_dir); de_cnt += Read_dea_files (NULL, Cfg_dea); if (de_cnt == 0) { LE_send_msg (GL_INFO, "No data element found in %s and %s\n", Cfg_dir, Cfg_dea); exit (0); } else LE_send_msg (GL_INFO, "%d data elements found in %s and %s\n", de_cnt, Cfg_dir, Cfg_dea); LE_send_msg (GL_INFO, "Create a/c DB"); ret = DEAU_create_dea_db (); if (ret < 0) { LE_send_msg (GL_ERROR, "DEAU_create_dea_db failed (%d)\n", ret); exit (1); } LE_send_msg (GL_INFO, "Set uninitialized value to default"); Set_to_defaults (0); Correct_layer_levels (); LE_send_msg (GL_INFO, "Verify current and baseline values"); Verify_values (); LE_send_msg (GL_INFO, "Set uninitialized baseline values"); Set_baseline_values (); ret = DEAU_set_values ("RPG_DEA_DB_init_state", 1, "init completed", 1, 0); if (ret < 0) { LE_send_msg (GL_ERROR, "DEAU_set_values RPG_DEA_DB_init_state failed (%d)\n", ret); exit (1); } LE_send_msg (GL_INFO, "init_adapt_data completed - non-operational"); exit (0); }
static void Connectivity_cb (EN_id_t evtcd, char *msg, int msglen, void *arg) { char tok[256]; int n_hosts, err; static char *cr_msg = NULL; int i, ln_cnt, changed; time_t prev_lost_conn, cr_t; if (N_nodes <= 1) return; if (msglen <= 0) { LE_send_msg (GL_ERROR, "Unexpected EN_QUERY_HOSTS evt - no message"); return; } err = 0; if (MISC_get_token (msg, "", 0, tok, 256) > 0 && strcmp (tok, "Remote_hosts:") == 0 && MISC_get_token (msg, "Ci", 1, &n_hosts, 0) > 0 && n_hosts >= 0) { for (i = 0; i < n_hosts; i++) { int c, k; unsigned int ip; if (MISC_get_token (msg, "", 2 + i * 2, tok, 256) <= 0 || MISC_get_token (msg, "Ci", 3 + i * 2, &c, 0) <= 0) { err = 1; break; } ip = NET_get_ip_by_name (tok); for (k = 0; k < N_nodes; k++) { if (Nodes[k].ip == ip) { if (c == 1) Nodes[k].is_connected = 1; else Nodes[k].is_connected = 0; break; } } } } else err = 1; if (err) { if (msglen >= 150) msg[150] = '\0'; LE_send_msg (GL_ERROR, "Unexpected EN_QUERY_HOSTS evt (%s)", msg); return; } /* report lost conn nodes */ ln_cnt = changed = 0; /* lost node count */ cr_msg = STR_copy (cr_msg, ""); for (i = 0; i < N_nodes; i++) { Node_attribute_t *node = Nodes + i; if (!node->is_connected) { ln_cnt++; cr_msg = STR_cat (cr_msg, " "); cr_msg = STR_cat (cr_msg, Nodes[i].node); } if (node->is_connected != node->prev_connected) changed = 1; node->prev_connected = node->is_connected; } if (changed) { Need_publish_node_info = 1; if (ln_cnt > 0) LE_send_msg (GL_STATUS, "Lost Connectivity Node(s):%s", cr_msg); } prev_lost_conn = Lost_conn_time; if (ln_cnt > 0) Lost_conn_detected = 1; if (ln_cnt == 0) Lost_conn_time = 0; else if (Lost_conn_time == 0) Lost_conn_time = MISC_systime (NULL); if (Lost_conn_time > 0 && prev_lost_conn == 0) { /* report lost conn */ LE_send_msg (GL_STATUS, "RPG Node Connectivity Lost"); Node_connectivity_OK = 0; } if (Lost_conn_time == 0 && prev_lost_conn > 0) { /* report resume conn */ LE_send_msg (GL_STATUS, "RPG Node Connectivity Has Resumed"); if (!Restart_required) Node_connectivity_OK = 1; } if (Lost_conn_time > 0 && !Restart_required) { Restart_required = 1; LE_send_msg (GL_STATUS, "RPG Recovery Is Scheduled Due To Node Connectivity Lost"); } if (Lost_conn_time > 0) Restart_set_time = 0; else if (prev_lost_conn > 0 && Restart_required && (cr_t = MISC_systime (NULL)) > Restart_set_time) Restart_set_time = cr_t; }
static int Read_resource_config (char *rc_name) { char tmp[MRPG_NAME_SIZE], node_name[MRPG_NAME_SIZE]; vector_t ras; char *line; int i; CS_cfg_name (Ra_config_name); CS_control (CS_COMMENT | '#'); if (rc_name == NULL || strlen (rc_name) == 0) { if (Search_resource_config () < 0) { LE_send_msg (GL_ERROR, "no appropriate resource config found"); return (-1); } } else { Res_name = STR_copy (Res_name, rc_name); LE_send_msg (LE_VL2, " Using resource config %s", rc_name); if (CS_entry (rc_name, 0, MRPG_NAME_SIZE, tmp) <= 0) { LE_send_msg (GL_ERROR, "Resource config %s not found", rc_name); return (-1); } if (CS_level (CS_DOWN_LEVEL) < 0) { LE_send_msg (GL_INFO, "Empty resource config %s", rc_name); return (0); } } ras.type = VECTOR_STRING; ras.length = ras.buf_size = 0; line = CS_THIS_LINE; while (1) { Node_attribute_t *node; int ind; CS_control (CS_KEY_OPTIONAL); if (CS_entry (line, 0, MRPG_NAME_SIZE, node_name) <= 0) break; if (strcmp (node_name, "replicate") == 0 || strcmp (node_name, "multicast") == 0) { char buf[256]; CS_entry (CS_THIS_LINE, CS_FULL_LINE, 256, buf); if (Add_replication_spec (buf) < 0) return (-1); line = CS_NEXT_LINE; continue; } for (i = 0; i < N_nodes; i++) { if (strcmp (node_name, Nodes[i].node) == 0) break; } if (i >= N_nodes) { LE_send_msg (GL_ERROR, "node name %s not defined", node_name); return (-1); } node = Nodes + i; node->not_used = 0; ras.length = ras.buf_size = node->n_rass; ras.p = node->rass; ind = 1; while (1) { if (CS_entry (CS_THIS_LINE, ind, MRPG_NAME_SIZE, tmp) <= 0) break; if (strcmp (tmp, "ras_default") == 0) node->default_node = 1; else Append_element (&ras, tmp); ind++; } node->n_rass = ras.length; node->rass = ras.p; line = CS_NEXT_LINE; } CS_level (CS_TOP_LEVEL); for (i = 0; i < N_nodes; i++) { if (Read_ra_sections (Nodes + i) < 0) return (-1); } CS_cfg_name (""); return (0); }
static void get_arguments(int argc, char **argv) { const char *dir; int opt; #if HAVE_GETOPT_LONG int index = 0; #endif for(;;) { #if HAVE_GETOPT_LONG opt = getopt_long(argc, argv, "gxvaVhLwtpmser:", Long_options, &index); #else opt = getopt(argc, argv, "gxvaVhLwtpmser:"); #endif if (opt < 0) break; switch (opt) { case 'V': #ifdef TRUNK_VERSION printf(VERSION " r" TRUNK_VERSION "\n"); #else printf(VERSION "\n"); #endif exit(0); case 'g': main_debug = TRUE; break; case 'x': main_exec = TRUE; break; case 'v': main_verbose = TRUE; break; case 'a': main_compile_all = TRUE; break; case 't': main_trans = TRUE; break; case 'w': main_warnings = TRUE; break; case 'p': main_public = TRUE; break; case 'm': main_public_module = TRUE; break; case 's': main_swap = TRUE; break; //case 'c': // main_class_file = optarg; //: break; case 'r': if (COMP_root) { fprintf(stderr, "gbc: option '-r' already specified.\n"); exit(1); } COMP_root = STR_copy(optarg); break; case 'e': ERROR_translate = TRUE; break; case 1: main_no_old_read_syntax = TRUE; break; case 'L': printf( "\nGAMBAS Compiler version " VERSION " " __DATE__ " " __TIME__ "\n" COPYRIGHT ); exit(0); case 'h': case '?': printf( "\nCompile Gambas projects into architecture-independent bytecode.\n" "\nUsage: gbc" GAMBAS_VERSION_STRING " [options] [<project directory>]\n\n" "Options:" #if HAVE_GETOPT_LONG "\n" " -g --debug add debugging information\n" " -v --verbose verbose output\n" " -a --all compile all\n" " -w --warnings display warnings\n" " -t --translate output translation files\n" " -p --public-control form controls are public\n" " -m --public-module module symbols are public by default\n" " -s --swap swap endianness\n" " -r --root <directory> gives the gambas installation directory\n" " -e --translate-errors display translatable error messages\n" " -x --exec define the 'Exec' preprocessor constant\n" " -V --version display version\n" " -L --license display license\n" " -h --help display this help\n" #else " (no long options on this system)\n" " -g add debugging information\n" " -v verbose output\n" " -a compile all\n" " -w display warnings\n" " -t output translation files\n" " -p form controls are public\n" " -m module symbols are public by default\n" " -s swap endianness\n" " -r <directory> gives the gambas installation directory\n" " -e display translatable error messages\n" " -x define the 'Exec' preprocessor constant\n" " -V display version\n" " -L display license\n" " -h display this help\n" #endif "\n" ); exit(0); default: exit(1); } } if (optind < (argc - 1)) { fprintf(stderr, "gbc: too many arguments.\n"); exit(1); } /*COMP_project = STR_copy(FILE_cat(argv[optind], "Gambas", NULL));*/ if (optind < argc) FILE_chdir(argv[optind]); dir = FILE_get_current_dir(); if (!dir) { fprintf(stderr, "gbc: no current directory.\n"); exit(1); } COMP_project = STR_copy(FILE_cat(dir, ".project", NULL)); if (!FILE_exist(COMP_project)) { fprintf(stderr, "gbc: project file not found: %s\n", COMP_project); exit(1); } }