Ejemplo n.º 1
0
void RotatedDC::DrawPreRotatedBitmap(const Bitmap& bitmap, const RealRect& rect) {
    RealPoint p_ext = tr(rect.position()) + boundingBoxCorner(rect.size());
    dc.DrawBitmap(bitmap, to_int(p_ext.x), to_int(p_ext.y), true);
}
Ejemplo n.º 2
0
void el_topo_static_operations( const ElTopoMesh* inputs,
                               const struct ElTopoGeneralOptions* general_options,
                               const struct ElTopoStaticOperationsOptions* options, 
                               struct ElTopoDefragInformation* defrag_info,  
                               struct ElTopoMesh* outputs )
{
    //
    // data wrangling
    //
    
    std::vector<Vec3d> vs;
    std::vector<double> masses;
    
    for ( int i = 0; i < inputs->num_vertices; ++i )
    {
        vs.push_back( Vec3d( inputs->vertex_locations[3*i], inputs->vertex_locations[3*i + 1], inputs->vertex_locations[3*i + 2] ) );
        masses.push_back( inputs->vertex_masses[i] );      
    }
    
    std::vector<Vec3st> ts;
    for ( int i = 0; i < inputs->num_triangles; ++i )
    {
        ts.push_back( Vec3st( inputs->triangles[3*i], inputs->triangles[3*i + 1], inputs->triangles[3*i + 2] ) );
    }
    
    
    // =================================================================================
    
    //
    // do the actual operations
    //
    
    // build a SurfTrack
    SurfTrackInitializationParameters construction_parameters;
    
    construction_parameters.m_proximity_epsilon = general_options->m_proximity_epsilon;
    
    construction_parameters.m_use_fraction = false;
    construction_parameters.m_min_edge_length = options->m_min_edge_length;
    construction_parameters.m_max_edge_length = options->m_max_edge_length;
    construction_parameters.m_max_volume_change = options->m_max_volume_change;   
    construction_parameters.m_min_triangle_angle = options->m_min_triangle_angle;
    construction_parameters.m_max_triangle_angle = options->m_max_triangle_angle;
    construction_parameters.m_use_curvature_when_splitting = options->m_use_curvature_when_splitting;
    construction_parameters.m_use_curvature_when_collapsing = options->m_use_curvature_when_collapsing;
    construction_parameters.m_min_curvature_multiplier = options->m_min_curvature_multiplier;
    construction_parameters.m_max_curvature_multiplier = options->m_max_curvature_multiplier;
    construction_parameters.m_allow_vertex_movement = options->m_allow_vertex_movement;
    construction_parameters.m_edge_flip_min_length_change = options->m_edge_flip_min_length_change;   
    construction_parameters.m_merge_proximity_epsilon = options->m_merge_proximity_epsilon;
    construction_parameters.m_collision_safety = general_options->m_collision_safety;
    construction_parameters.m_allow_topology_changes = options->m_allow_topology_changes;
    construction_parameters.m_perform_improvement = options->m_perform_improvement;
    construction_parameters.m_subdivision_scheme = (SubdivisionScheme*) options->m_subdivision_scheme;
    
    
    SurfTrack surface_tracker( vs, ts, masses, construction_parameters ); 
    
    surface_tracker.improve_mesh();
    
    // do merging
    surface_tracker.topology_changes();
    
    surface_tracker.defrag_mesh();
    
    
    // =================================================================================
    
    defrag_info->num_vertex_changes = to_int(surface_tracker.m_vertex_change_history.size());
    defrag_info->vertex_is_remove = (int*) malloc( defrag_info->num_vertex_changes * sizeof(int) );
    defrag_info->vertex_index = (int*) malloc( defrag_info->num_vertex_changes * sizeof(int) );
    defrag_info->split_edge = (int*) malloc( 2 * defrag_info->num_vertex_changes * sizeof(int) );
    
    for ( int i = 0; i < defrag_info->num_vertex_changes; ++i )
    {
        defrag_info->vertex_is_remove[i] = surface_tracker.m_vertex_change_history[i].m_is_remove ? 1 : 0;
        defrag_info->vertex_index[i] = to_int(surface_tracker.m_vertex_change_history[i].m_vertex_index);
        defrag_info->split_edge[2*i+0] = to_int(surface_tracker.m_vertex_change_history[i].m_split_edge[0]);
        defrag_info->split_edge[2*i+1] = to_int(surface_tracker.m_vertex_change_history[i].m_split_edge[1]);
    }
    
    defrag_info->num_triangle_changes = to_int(surface_tracker.m_triangle_change_history.size());
    defrag_info->triangle_is_remove = (int*) malloc( defrag_info->num_triangle_changes * sizeof(int) );
    defrag_info->triangle_index = (int*) malloc( defrag_info->num_triangle_changes * sizeof(int) );
    defrag_info->new_tri = (int*) malloc( 3 * defrag_info->num_triangle_changes * sizeof(int) );
    
    for ( int i = 0; i < defrag_info->num_triangle_changes; ++i )
    {
        defrag_info->triangle_is_remove[i] = surface_tracker.m_triangle_change_history[i].m_is_remove ? 1 : 0;
        defrag_info->triangle_index[i] = to_int(surface_tracker.m_triangle_change_history[i].m_triangle_index);
        defrag_info->new_tri[3*i+0] = to_int(surface_tracker.m_triangle_change_history[i].m_tri[0]);
        defrag_info->new_tri[3*i+1] = to_int(surface_tracker.m_triangle_change_history[i].m_tri[1]);
        defrag_info->new_tri[3*i+2] = to_int(surface_tracker.m_triangle_change_history[i].m_tri[2]);
    }
    
    
    defrag_info->defragged_triangle_map_size = to_int(surface_tracker.m_defragged_triangle_map.size());
    defrag_info->defragged_triangle_map = (int*) malloc( 2 * defrag_info->defragged_triangle_map_size * sizeof(int)  );
    
    for ( int i = 0; i < defrag_info->defragged_triangle_map_size; ++i )
    {
        defrag_info->defragged_triangle_map[2*i+0] = to_int(surface_tracker.m_defragged_triangle_map[i][0]);
        defrag_info->defragged_triangle_map[2*i+1] = to_int(surface_tracker.m_defragged_triangle_map[i][1]);
    }
    
    defrag_info->defragged_vertex_map_size = to_int(surface_tracker.m_defragged_vertex_map.size());
    defrag_info->defragged_vertex_map = (int*) malloc( 2 * defrag_info->defragged_vertex_map_size * sizeof(int) );
    
    for ( int i = 0; i < defrag_info->defragged_vertex_map_size; ++i )
    {
        defrag_info->defragged_vertex_map[2*i+0] = to_int(surface_tracker.m_defragged_vertex_map[i][0]);
        defrag_info->defragged_vertex_map[2*i+1] = to_int(surface_tracker.m_defragged_vertex_map[i][1]);
    }
    
    // =================================================================================
    
    //
    // data wrangling
    //
    
    outputs->num_vertices = to_int(surface_tracker.get_num_vertices());
    outputs->vertex_locations = (double*) malloc( 3 * (outputs->num_vertices) * sizeof(double) );
    outputs->vertex_masses = (double*) malloc( (outputs->num_vertices) * sizeof(double) );
    
    for ( int i = 0; i < outputs->num_vertices; ++i )
    {
        const Vec3d& pos = surface_tracker.get_position(i);
        outputs->vertex_locations[3*i + 0] = pos[0];
        outputs->vertex_locations[3*i + 1] = pos[1];  
        outputs->vertex_locations[3*i + 2] = pos[2];
        outputs->vertex_masses[i] = surface_tracker.m_masses[i];
    }
    
    outputs->num_triangles = to_int(surface_tracker.m_mesh.num_triangles());
    outputs->triangles = (int*) malloc( 3 * (outputs->num_triangles) * sizeof(int) );
    
    for ( int i = 0; i < outputs->num_triangles; ++i )
    {
        const Vec3st& curr_tri = surface_tracker.m_mesh.get_triangle(i); 
        outputs->triangles[3*i + 0] = to_int(curr_tri[0]);
        outputs->triangles[3*i + 1] = to_int(curr_tri[1]);
        outputs->triangles[3*i + 2] = to_int(curr_tri[2]);
    }
    
}
Ejemplo n.º 3
0
		operator int() const { return to_int(); }
Ejemplo n.º 4
0
//Convert To Char Function
char msl::to_char(const std::string& value)
{
	//Integers Will Work!
	return to_int(value);
}
Ejemplo n.º 5
0
Graph* read_lib_file(char *file_root, char *file_name) {
	strcat(file_root, file_name);
	ifstream ifs(file_root);

	if (ifs.fail()) {
		cout << "read lib file error" << endl;
		exit(1);
	}

	string name, comment, type;
	int dim = -1;

	regex re("^(\\S+)(\\s*):(\\s*)(.+)$");
	smatch match;

	while (1) {
		string line;
		getline(ifs, line);

		if (line == "NODE_COORD_SECTION") break;

		bool ok = regex_match(line, match, re);
		if (!ok) {
			cout << "No match line: " << line << endl;
			exit(1);
		}

		string pattern = match[1], str = match[4];

		if (pattern == "NAME") {
			name = str;
		} else if (pattern == "COMMENT") {
			comment = str;
		} else if (pattern == "DIMENSION") {
			dim = to_int(str);
		} else if (pattern == "EDGE_WEIGHT_TYPE") {
			if (str != "EUC_2D") {
				cout << "Cannot load this format: " << str << endl;
				exit(1);
			}
		} else {
			cout << "No match pattern: " << pattern << endl;
		}
	}

	if (dim < 0) {
		cout << "No dim error" << endl;
		exit(1);
	}

	Graph *g = new Graph(dim, name, comment, "EUC_2D");

	double x, y;
	int num;
	string line;
	for (int i=0; i<dim; i++) {
		getline(ifs, line);
		istringstream istr(line);
		istr >> num >> x >> y;

		g->add_node(x, y);
	}

	g->calc_distance();

	return g;
}
Ejemplo n.º 6
0
void build() {
    //build s[0];
    root->child[to_int(str[0])] = get_next(0, e, NULL, root, 0);
    //update s[j - 1, i - 1] to s[j, i - 1]
    //build s[j, i] from s[j, i - 1]
    //current is at s[j - 1, i - 1] (leaf node or the internal node)
    //for the s[ last_non + 1, i], current should be s[ last_non, i - 1]
    current = root->child[to_int(str[0])];
    //last_non is the last non extension in the s[ j - 1, i - 1]
    //remain_len is the left part in current node
    //base is the index in the str to start match
    int last_non = 0, remain_len = 0, base = 0;
    for(int i = 1; i <= len; ++i) {
        pre = NULL;
        current = root;
        base = last_non;
        remain_len = i - last_non;
        walk_down(&current, remain_len, base);
        for(int j = last_non + 1; j <= i; ++j) {
            //explict extentions for last_non + 1...i
            //update s[ j - 1, i - 1] to s[j, i - 1]
            if(current->leaf_index >= 0) {
                //now at the leaf, should go up to the internal node
                base = current->start;
                remain_len = edge_len(current);
                current = current->parent;
            }
            if(current == root) {
                base = j;
                remain_len = i - j;
            }
            else {
                current = current->suffix_link;
            }
            walk_down(&current, remain_len, base);
            if(pre != NULL) {
                pre->suffix_link = current;
            }
            if(remain_len == 0) {
                if(current->child[to_int(str[i])] == NULL) {
                    //rule 2
                    //puts("rule 2");
                    //printf("j %d, str[j] %c, current->leafindex %d current->start %d\n", j, str[j], current->leaf_index, current->start);
                    node *new_node = get_next(i, e, NULL, current, j);
                    current->child[to_int(str[i])] = new_node;
                    pre = NULL;
                    last_non = j;
                }
                else {
                    //rule 3
                    //puts("rule 3");
                    pre = NULL;
                    break;
                }
            }
            else {
                node *next = current->child[to_int(str[base])];
                //printf("remain_len %d\n", remain_len);
                if(str[next->start + remain_len] != str[i]) {
                    //rule 2
                    //puts("split rule 2");
                    int *middle_end = new int(next->start + remain_len - 1);
                    //printf("next->start %d middle_end %d\n", next->start, *middle_end);
                    node *new_middle = get_next(next->start, middle_end, NULL, current, -1);
                    current->child[to_int(str[base])] = new_middle;
                    next->start = (*middle_end) + 1;
                    node *new_leaf = get_next(i, e, NULL, new_middle, j);
                    new_middle->child[to_int(str[i])] = new_leaf;
                    new_middle->child[to_int(str[next->start])] = next;
                    //printf("new_middle start %d end %d leaf_index %d\n", new_middle->start, *(new_middle->end), new_middle->leaf_index);
                    last_non = j;
                    if(pre != NULL) {
                        pre->suffix_link = new_middle;
                    }
                    pre = new_middle;
                }
                else {
                    //rule 3
                    //puts("rule 3");
                    pre = NULL;
                    break;
                }
            }
        }
        //implict extentions for 0...last_non extensions
        (*e) = i;
    }
}
Ejemplo n.º 7
0
int cmd_get_datalink(struct libusb_device_handle* devh) {
	char dataptr[4];
	cmd_getter(devh, DOT11_GET_DATALINK, dataptr, 4);
	return to_int(dataptr);
}
Ejemplo n.º 8
0
inline bool to_int(string const & s, int & i, int base = 10) { return to_int(s.c_str(), i, base); }
Ejemplo n.º 9
0
/* Return value is only valid if the result should fit into an int.
   AUTHOR: David Harvey (2008-06-08) */
static CYTHON_INLINE int ZZ_to_int(const ZZ* x)
{
    return to_int(*x);
}
JNIEXPORT jobjectArray JNICALL Java_cn_edu_hitwh_dict_plugin_stardict_DictIndexReader_getDictIndex
  (JNIEnv * pEnv, jobject pThis, jstring jFileName, jint jWordCount, jint jIdxSize)
{
	char * fileName = (char*) pEnv->GetStringUTFChars(jFileName, JNI_FALSE);
	DICT_INFO *dict_info = new DICT_INFO;
	dict_info->wordcount = jWordCount;
	dict_info->idxfilesize = jIdxSize;
//
	jclass cls = pEnv->FindClass("cn/edu/hitwh/dict/plugin/stardict/DictIndex");
	load_jni_dict_index(pEnv);
	jobjectArray jDictIndexArray = pEnv->NewObjectArray(jWordCount,
			cls, NULL);
	FILE *fd = fopen(fileName, "rb");
	size_t nread;
	if (fd == NULL) {
		 __android_log_print(ANDROID_LOG_DEBUG, "SOS", "fd");
		 return NULL;
	 }
	 if (dict_info == NULL) {
		 __android_log_print(ANDROID_LOG_DEBUG, "SOS", "info");
		 return NULL;
	 }
	 unsigned char *buffer = (unsigned char *)malloc(sizeof(unsigned char) * (dict_info->idxfilesize));
	 nread = fread(buffer, dict_info->idxfilesize, 1, fd);
////
	 unsigned char *head, *tail;
	 head = tail = buffer;
	 int it = 0;
	 int total = 0;
	 for (; it < dict_info->idxfilesize; it++)
	 {
		 if (*head == '\0')
		 {
			 jstring word = pEnv->NewStringUTF((char*)tail);
			 jobject jDictIndex = pEnv->NewObject(jniDictIndex->cls,
			 jniDictIndex->ctorID, word, to_int(head + 1),
			 to_int(head + 5));
		//
			 pEnv->SetObjectArrayElement(jDictIndexArray, total, jDictIndex);
			 pEnv->DeleteLocalRef(jDictIndex);
			 pEnv->DeleteLocalRef(word);
		//
			 total++;
			 head += 9;
			 tail = head;
			 if (total == dict_info->wordcount)
			 {
				 break;
			 }
		 }else
		 {
			 head++;
			 continue;
		 }
	}
	head = tail = NULL;
	free(buffer);
	buffer = NULL;
	fclose(fd);
	fd = NULL;
	pEnv->DeleteLocalRef(jDictIndexArray);
	pEnv->ReleaseStringUTFChars(jFileName, fileName);
	return jDictIndexArray;
}
Ejemplo n.º 11
0
	inline operator wxPoint() const {
		return wxPoint(to_int(x), to_int(y));
	}
Ejemplo n.º 12
0
/*
 * The main function.
 */
int
main(int argc, char *argv[])
{
	const char *opt_string = "t:o:k:hf:l:c:s:";
	struct option const longopts[] = {
		{"interval", required_argument, NULL, 't'},
		{"output-log-file", required_argument, NULL, 'o'},
		{"kernel-log-level", required_argument, NULL, 'k'},
		{"help", no_argument, NULL, 'h'},
		{"feature", required_argument, NULL, 'f'},
		{"log-period", required_argument, NULL, 'l'},
		{"config", required_argument, NULL, 'c'},
		{"select", required_argument, NULL, 's'},
		{NULL, 0, NULL, 0}
	};

	int optc;
	int longind = 0;
	int running = 1;
	int unknown_option = FALSE;
	int refresh_interval = 5;
	int klog_level = 0;
	int log_interval = 0;
	long long last_logged = 0;
	char *token = NULL;
	int retval = 0;
	int gpipe;
	int err;
	uint64_t collect_end;
	uint64_t current_time;
	uint64_t delta_time;
	char logfile[PATH_MAX] = "";
	int select_id;
	int select_value;
	char *select_str;
	boolean_t no_dtrace_cleanup = B_TRUE;

	lt_gpipe_init();
	(void) signal(SIGINT, signal_handler);
	(void) signal(SIGTERM, signal_handler);

	/* Default global settings */
	g_config.lt_cfg_enable_filter = 0;
	g_config.lt_cfg_trace_sched = 0;
	g_config.lt_cfg_trace_syncobj = 1;
	g_config.lt_cfg_low_overhead_mode = 0;
	g_config.lt_cfg_trace_pid = 0;
	g_config.lt_cfg_trace_pgid = 0;
	/* dtrace snapshot every 1 second */
	g_config.lt_cfg_snap_interval = 1000;
#ifdef EMBED_CONFIGS
	g_config.lt_cfg_config_name = NULL;
#else
	g_config.lt_cfg_config_name = lt_strdup(DEFAULT_CONFIG_NAME);
#endif

	/* Parse command line arguments. */
	while ((optc = getopt_long(argc, argv, opt_string,
	    longopts, &longind)) != -1) {
		switch (optc) {
		case 'h':
			print_usage(argv[0], TRUE);
			goto end_none;
		case 't':
			if (to_int(optarg, &refresh_interval) != 0 ||
			    refresh_interval < 1 || refresh_interval > 60) {
				lt_display_error(
				    "Invalid refresh interval: %s\n", optarg);
				unknown_option = TRUE;
			} else if (check_opt_dup(LT_CMDOPT_INTERVAL,
			    refresh_interval)) {
				unknown_option = TRUE;
			}

			break;
		case 'k':
			if (to_int(optarg, &klog_level) != 0 ||
			    lt_klog_set_log_level(klog_level) != 0) {
				lt_display_error(
				    "Invalid log level: %s\n", optarg);
				unknown_option = TRUE;
			} else if (check_opt_dup(LT_CMDOPT_LOG_LEVEL,
			    refresh_interval)) {
				unknown_option = TRUE;
			}

			break;
		case 'o':
			if (check_opt_dup(LT_CMDOPT_LOG_FILE, optind)) {
				unknown_option = TRUE;
			} else if (strlen(optarg) >= sizeof (logfile)) {
				lt_display_error(
				    "Log file name is too long: %s\n",
				    optarg);
				unknown_option = TRUE;
			} else {
				(void) strncpy(logfile, optarg,
				    sizeof (logfile));
			}

			break;
		case 'f':
			for (token = strtok(optarg, ","); token != NULL;
			    token = strtok(NULL, ",")) {
				int v = TRUE;

				if (strncmp(token, "no", 2) == 0) {
					v = FALSE;
					token = &token[2];
				}

				if (CMPOPT(token, "filter") == 0) {
					if (check_opt_dup(LT_CMDOPT_F_FILTER,
					    v)) {
						unknown_option = TRUE;
					} else {
						g_config.lt_cfg_enable_filter
						    = v;
					}
				} else if (CMPOPT(token, "sched") == 0) {
					if (check_opt_dup(LT_CMDOPT_F_SCHED,
					    v)) {
						unknown_option = TRUE;
					} else {
						g_config.lt_cfg_trace_sched
						    = v;
					}
				} else if (CMPOPT(token, "sobj") == 0) {
					if (check_opt_dup(LT_CMDOPT_F_SOBJ,
					    v)) {
						unknown_option = TRUE;
					} else {
						g_config.lt_cfg_trace_syncobj
						    = v;
					}
				} else if (CMPOPT(token, "low") == 0) {
					if (check_opt_dup(LT_CMDOPT_F_LOW,
					    v)) {
						unknown_option = TRUE;
					} else {
						g_config.
						    lt_cfg_low_overhead_mode
						    = v;
					}
				} else {
					lt_display_error(
					    "Unknown feature: %s\n", token);
					unknown_option = TRUE;
				}
			}

			break;
		case 'l':
			if (to_int(optarg, &log_interval) != 0 ||
			    log_interval < 60) {
				lt_display_error(
				    "Invalid log interval: %s\n", optarg);
				unknown_option = TRUE;
			} else if (check_opt_dup(LT_CMDOPT_LOG_INTERVAL,
			    log_interval)) {
				unknown_option = TRUE;
			}

			break;
		case 'c':
			if (strlen(optarg) >= PATH_MAX) {
				lt_display_error(
				    "Configuration name is too long.\n");
				unknown_option = TRUE;
			} else if (check_opt_dup(LT_CMDOPT_CONFIG_FILE,
			    optind)) {
				unknown_option = TRUE;
			} else {
				g_config.lt_cfg_config_name =
				    lt_strdup(optarg);
			}

			break;
		case 's':
			if (strncmp(optarg, "pid=", 4) == 0) {
				select_id = 0;
				select_str = &optarg[4];
			} else if (strncmp(optarg, "pgid=", 5) == 0) {
				select_id = 1;
				select_str = &optarg[5];
			} else {
				lt_display_error(
				    "Invalid select option: %s\n", optarg);
				unknown_option = TRUE;
				break;
			}

			if (to_int(select_str, &select_value) != 0) {
				lt_display_error(
				    "Invalid select option: %s\n", optarg);
				unknown_option = TRUE;
				break;
			}

			if (select_value <= 0) {
				lt_display_error(
				    "Process/process group ID must be "
				    "greater than 0: %s\n", optarg);
				unknown_option = TRUE;
				break;
			}

			if (check_opt_dup(LT_CMDOPT_SELECT,
			    (((uint64_t)select_id) << 32) | select_value)) {
				unknown_option = TRUE;
				break;
			}

			if (select_id == 0) {
				g_config.lt_cfg_trace_pid = select_value;
			} else {
				g_config.lt_cfg_trace_pgid = select_value;
			}
			break;
		default:
			unknown_option = TRUE;
			break;
		}
	}

	if (!unknown_option && strlen(logfile) > 0) {
		err = lt_klog_set_log_file(logfile);

		if (err == -1) {
			lt_display_error("Log file name is too long: %s\n",
			    logfile);
			unknown_option = TRUE;
		} else if (err == -2) {
			lt_display_error("Cannot write to log file: %s\n",
			    logfile);
			unknown_option = TRUE;
		}
	}

	/* Throw error for invalid/junk arguments */
	if (optind  < argc) {
		int tmpind = optind;
		(void) fprintf(stderr, "Unknown option(s): ");

		while (tmpind < argc) {
			(void) fprintf(stderr, "%s ", argv[tmpind++]);
		}

		(void) fprintf(stderr, "\n");
		unknown_option = TRUE;
	}

	if (unknown_option) {
		print_usage(argv[0], FALSE);
		retval = 1;
		goto end_none;
	}

	(void) printf("%s\n%s\n", TITLE, COPYRIGHT);

	/*
	 * Initialization
	 */
	lt_klog_init();

	if (lt_table_init() != 0) {
		lt_display_error("Unable to load configuration table.\n");
		retval = 1;
		goto end_notable;
	}

	if (lt_dtrace_init() != 0) {
		lt_display_error("Unable to initialize dtrace.\n");
		retval = 1;
		goto end_nodtrace;
	}

	last_logged = lt_millisecond();

	(void) printf("Collecting data for %d seconds...\n",
	    refresh_interval);

	gpipe = lt_gpipe_readfd();
	collect_end = last_logged + refresh_interval * 1000;
	for (;;) {
		fd_set read_fd;
		struct timeval timeout;
		int tsleep = collect_end - lt_millisecond();

		if (tsleep <= 0) {
			break;
		}

		/*
		 * Interval when we call dtrace_status() and collect
		 * aggregated data.
		 */
		if (tsleep > g_config.lt_cfg_snap_interval) {
			tsleep = g_config.lt_cfg_snap_interval;
		}

		timeout.tv_sec = tsleep / 1000;
		timeout.tv_usec = (tsleep % 1000) * 1000;

		FD_ZERO(&read_fd);
		FD_SET(gpipe, &read_fd);

		if (select(gpipe + 1, &read_fd, NULL, NULL, &timeout) > 0) {
			goto end_ubreak;
		}

		(void) lt_dtrace_work(0);
	}

	lt_display_init();

	do {
		current_time = lt_millisecond();

		lt_stat_clear_all();
		(void) lt_dtrace_collect();

		delta_time = current_time;
		current_time = lt_millisecond();
		delta_time = current_time - delta_time;

		if (log_interval > 0 &&
		    current_time - last_logged > log_interval * 1000) {
			lt_klog_write();
			last_logged = current_time;
		}

		running = lt_display_loop(refresh_interval * 1000 -
		    delta_time);

		/*
		 * This is to avoid dynamic variable drop
		 * in DTrace.
		 */
		if (lt_drop_detected == B_TRUE) {
			if (lt_dtrace_deinit() != 0) {
				no_dtrace_cleanup = B_FALSE;
				retval = 1;
				break;
			}

			lt_drop_detected = B_FALSE;
			if (lt_dtrace_init() != 0) {
				retval = 1;
				break;
			}
		}
	} while (running != 0);

	lt_klog_write();

	/* Cleanup */
	lt_display_deinit();

end_ubreak:
	if (no_dtrace_cleanup == B_FALSE || lt_dtrace_deinit() != 0)
		retval = 1;

	lt_stat_free_all();

end_nodtrace:
	lt_table_deinit();

end_notable:
	lt_klog_deinit();

end_none:
	lt_gpipe_deinit();

	if (g_config.lt_cfg_config_name != NULL) {
		free(g_config.lt_cfg_config_name);
	}

	return (retval);
}
Ejemplo n.º 13
0
int Z_mod::coerce_to_int(ring_elem a) const
{
  return to_int(a.int_val);
}
Ejemplo n.º 14
0
void RotatedDC::DrawPreRotatedImage (const Image& image, const RealRect& rect, ImageCombine combine) {
    RealPoint p_ext = tr(rect.position()) + boundingBoxCorner(rect.size());
    draw_combine_image(dc, to_int(p_ext.x), to_int(p_ext.y), image, combine);
}
Ejemplo n.º 15
0
ring_elem Z_mod::eval(const RingMap *map, const ring_elem f, int) const
{
  int a = to_int(f);
  return map->get_ring()->from_long(a);
}
Ejemplo n.º 16
0
/** CANELVEN(dc): Proficiency in the elven language.
 *
 * The guard ?(CANELVEN(40): says \"I hate your guts\" in Elven.):(says something angrily, but you can't understand it).
 */
string canelven( object env, string sdc ) {
   int dc = to_int(sdc);
   if( !dc ) dc = 30;
   if( this_player()->cached_skill_check(600, object_name(env), "knowledge.lang.elven", dc) ) return "";
   return 0;
}
Ejemplo n.º 17
0
std::pair<bool, long> Z_mod::coerceToLongInteger(ring_elem a) const
{
  return std::pair<bool, long>(true, to_int(a.int_val));
}
Ejemplo n.º 18
0
				inline int get_int_data(std::string key, int def = 0) {
					return to_int(data[key], def);
				}
Ejemplo n.º 19
0
int cmd_get_timeout(struct libusb_device_handle* devh) {
	char dataptr[4];
	cmd_getter(devh, DOT11_GET_TIMEOUT, dataptr, 4);
	return to_int(dataptr);
}
Ejemplo n.º 20
0
 column::operator int() const
 {
     return to_int();
 }
Ejemplo n.º 21
0
int cmd_get_channel(struct libusb_device_handle* devh) {
	char dataptr[4];
	cmd_getter(devh, DOT11_GET_CHANNEL, dataptr, 4);
	return to_int(dataptr);
}
Ejemplo n.º 22
0
 operator bool() const         {
     return static_cast<bool>(to_int());
 }
Ejemplo n.º 23
0
	string *stack=allocate(0);
	if (v("stack")){
		stack=v("stack");
	}
	switch (a){
	case "push":
		stack=stack + ({ARGS(1)});
		vSet("stack", stack);
		castmsg(ME, "_notice_public_stack_add", "Eintrag #[_num] hinzugefuegt: "+stack[sizeof(stack)-1], (["_nick": "stack", "_num": sizeof(stack)]));
		break;
	case "get":
		if(sizeof(stack)>0){
			if(sizeof(args)==1){
				castmsg(ME, "_notice_public_stack", "Eintrag #[_num]: "+stack[sizeof(stack)-1], (["_nick": "stack", "_num": sizeof(stack)]));
			}else{
				args[1]=to_int(args[1]);
				if(sizeof(stack)>=args[1]){
					castmsg(ME, "_notice_public_stack", "Eintrag #[_num]: "+stack[(args[1])-1], (["_nick": "stack", "_num": args[1]]));
				}
			}
		}
		break;
	case "pop":
		if(sizeof(args)==1){
			if(sizeof(stack)>0){
				castmsg(ME, "_notice_public_stack_delete", "Eintrag #[_num] entfernt: "+stack[sizeof(stack)-1], (["_nick": "stack", "_num": sizeof(stack)]));
				stack=stack - ({stack[sizeof(stack)-1]});
				vSet("stack", stack);
			}
		}else{
			args[1]=to_int(args[1]);
Ejemplo n.º 24
0
Archivo: _drink.c Proyecto: ehershey/pd
int cmd_drink(string s) {
    object tp, vic;
    float per, per2;

    tp=this_player();
    if(!abil()) return 0;
    if(!s) return notify_fail("Syntax: <drink [victim]>\n");
    if(s=="stop") {
	if(!bl[tp]) {
	    write("You are not drinking anyones blood right now.\n");
	    return 1;
	}
	write("You decide to stop drinking "+bl[tp]->query_cap_name()+"'s blood.\n");
	bl[tp]->set_paralyzed(0);
	if(present("drink_ob", tp)) present("drink_ob", tp)->remove();
	map_delete(bl, tp);
	return 1;
    }
    if(bl && bl[tp]) {
	write("You are already drinking the blood of another.\n");
	return 1;
    }
    if(environment(tp)->query_property("no attack")) return notify_fail("You may not drink here.\n");
    if(tp->query_bp() >= tp->query_max_bp()) {
	write("There is no reason to drink blood.\n");
	return 1;
    }
    vic=present(s, environment(this_player()));
    if(!vic) {
	write("You do not see that here.\n");
	return 1;
    }
    if(!vic->ok_to_kill(vic)) {
	write("You may not drink blood from that.\n");
	return 1;
    }
    if(vic->is_corpse() || vic->id("remains")) {
	write("The blood in the corpse would not be satisfying.\n");
	return 1;
    }
    if(vic->query_race() == "vampire" || vic->is_undead()) {
	write("You may not drink the blood for a fellow undead.\n");
	return 1;
    }
    if( ( vic->query_level() < 20 || tp->query_level() < 20 ) && vic->is_player()) {
	write("You are too young to feast on that of the living player.");
	return 1;
    }
    if(!vic->is_living()) {
	write("You may not drink from the non-living.\n");
	return 1;
    }
    if(tp->query_arena() || vic->query_arena()) {
	write("You may not drain blood inside of the arena.\n");
	return 1;
    }
    per=percent(vic->query_hp(), vic->query_max_hp());
    if(tp->query_level() < 20 && per > 10) {
	write(vic->query_cap_name()+" isnt weak enough for you to drink their blood.\n");
	if(this_player()->query_name() == "whit") write("Percent: "+to_int(per)+" HP: "+vic->query_hp()+" Max HP: "+vic->query_max_hp()+".\n");
	return 1;
    }
    per=percent(vic->query_bp(), vic->query_max_bp());
    if(per < 10) {
	write(vic->query_cap_name()+" is too low on blood.\n");
	return 1;
    }
    if(per2=break_away(tp, vic)) {
	write("Your attempt to drink the blood from "+vic->query_cap_name()+" has failed!\n");
	if(per2==-1) {
	    message("", tp->query_cap_name()+" fails at the attempt to suck "
	      "your %^BOLD%^%^RED%^blood%^RESET%^.\n", vic);
	    vic->force_me("laugh at "+tp->query_name());
	}
	if(per2>90) {
	    message("", tp->query_cap_name()+" fails at the attempt to suck "
	      "your %^BOLD%^%^RED%^blood%^RESET%^.\n", vic);
	    vic->force_me("kill "+tp->query_name());
	}
	return 1;
    }
    write("You latch onto "+vic->query_cap_name()+"'s neck and begin to "
      "draw %^BOLD%^%^RED%^blood%^RESET%^.\n");
    tell_object(vic, this_player()->query_cap_name()+" grabs ahold of "
      "you and starts to suck your %^BOLD%^%^RED%^blood%^RESET%^.");
    message("", this_player()->query_cap_name()+" grabs ahold of "
      +vic->query_cap_name()+" and starts to suck "+vic->query_possessive()+" %^BOLD%^%^RED%^blood%^RESET%^.", 
      environment(tp), ({tp, vic}) );
Ejemplo n.º 25
0
int 
main (int argc, char* argv[])
{
  /*
   * Set verifyp to 1 if you want to turn on verification.
   */
  const int verifyp = DO_VERIFY;
  const int argc_min = 3;
  const int argc_max = 4;

  int gens_max = 0;
  char* inboard = NULL;
  char* outboard = NULL;
  char* checkboard = NULL;
  char* final_board = NULL;
  int nrows = 0;
  int ncols = 0;
  FILE* input = NULL;
  FILE* output = NULL;
  int err = 0;

  /* Parse command-line arguments */
  if (argc < argc_min || argc > argc_max)
    {
      fprintf (stderr, "*** Wrong number of command-line arguments; "
	       "got %d, need at least %d and no more than %d ***\n", 
	       argc - 1, argc_min - 1, argc_max - 1);
      print_usage (argv[0]);
      exit (EXIT_FAILURE);
    }
  
  err = to_int (&gens_max, argv[1]);
  if (err != 0)
    {
      fprintf (stderr, "*** <num_generations> argument \'%s\' "
	       "must be a nonnegative integer! ***\n", argv[1]);
      print_usage (argv[0]);
      exit (EXIT_FAILURE);
    }

  /* Open input and output files */ 
  input = fopen (argv[2], "r");
  if (input == NULL)
    {
      fprintf (stderr, "*** Failed to open input file \'%s\' for reading! ***\n", argv[2]);
      print_usage (argv[0]);
      exit (EXIT_FAILURE);
    }

  if (argc < argc_max || 0 == strcmp (argv[3], "-"))
    output = stdout;
  else
    {
      output = fopen (argv[3], "w");
      if (output == NULL)
	{
	  fprintf (stderr, "*** Failed to open output file \'%s\' for writing! ***\n", argv[3]);
	  print_usage (argv[0]);
	  exit (EXIT_FAILURE);
	}
    }

  /* Load the initial board state from the input file */
  inboard = load_board (input, &nrows, &ncols);
  fclose (input);

  /* Create a second board for ping-ponging */
  outboard = make_board (nrows, ncols);

  /* If we want to verify the result, then make a third board and copy
     the initial state into it */
  if (verifyp)
    {
      checkboard = make_board (nrows, ncols);
      copy_board (checkboard, inboard, nrows, ncols);
    }

  /* 
   * Evolve board gens_max ticks, and time the evolution.  You will
   * parallelize the game_of_life() function for this assignment.
   */
  copy_board (outboard, inboard, nrows, ncols);
  final_board = game_of_life (outboard, inboard, nrows, ncols, gens_max);

  /* Print (or save, depending on command-line argument <outfilename>)
     the final board */
  save_board (output, final_board, nrows, ncols);
  if (output != stdout && output != stderr)
    fclose (output);

  if (verifyp)
    {
      /* Make sure that outboard has the final state, so we can verify
	 it.  Since we ping-pong between inboard and outboard, it
	 could be either that inboard == final_board or that outboard
	 == final_board */
      copy_board (outboard, final_board, nrows, ncols);

      /* Ping-pong between checkboard (contains the initial state) and
	 inboard */
      final_board = sequential_game_of_life (inboard, checkboard, nrows, ncols, gens_max);

      if (boards_equalp (final_board, outboard, nrows, ncols))
	printf ("Verification successful\n");
      else
	{
	  fprintf (stderr, "*** Verification failed! ***\n");
	  exit (EXIT_FAILURE);
	}
    }

  /* Clean up */
  if (inboard != NULL)
    free (inboard);
  if (outboard != NULL)
    free (outboard);
  if (checkboard != NULL)
    free (checkboard);

  return 0;
}
Ejemplo n.º 26
0
void typecast_stringarray_to_int_matrix(const std::vector<std::string> &tokens,iMatrix *mat){
  int start=0;
  for (int i=0;i<mat->x;i++)
    for(int j=0;j<mat->y;j++)
      mat->matrix[i][j] = to_int( tokens.at(start++),0,3);
}
Ejemplo n.º 27
0
int main(int argc, char *argv[])
{
  bool static_init_ok = false;
  const char *action;
  int err = 0;

  self = os_program_name(argv[0]);

  if (argc <= 1)
  {
      usage();
      err = 1;
      goto done;
  }

  err = examsg_static_init(EXAMSG_STATIC_GET);
  if (err != 0)
  {
      fprintf(stderr, "examsg_static_init failed: %s (%d)\n", exa_error_msg(-err), err);
      goto done;
  }
  static_init_ok = true;

  mh = examsgInit(EXAMSG_TEST_ID);
  if (!mh)
  {
      fprintf(stderr, "examsgInit failed\n");
      goto done;
  }

  err = examsgAddMbox(mh, examsgOwner(mh), 3, EXAMSG_MSG_MAX);
  if (err != 0)
  {
      fprintf(stderr, "examsgAddMbox failed: %s (%d)\n", exa_error_msg(-err), err);
      goto done;
  }

  action = argv[1];
  if (strcmp(action, "is_fs_mounted") == 0)
  {
      int m;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      m = fsd_is_fs_mounted(mh, argv[2]);
      if (m < 0)
          err = m;
  }
  else if (strcmp(action, "is_mountpoint_used") == 0)
  {
      int u;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      u = fsd_is_mountpoint_used(mh, argv[2]);
      if (u < 0)
          err = u;
  }
  else if (strcmp(action, "prepare_gfs") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      COMPILE_TIME_ASSERT(sizeof("sfs") <= sizeof(fs.fstype));
      os_strlcpy(fs.fstype, "sfs", sizeof(fs.fstype));

      sz = os_strlcpy(fs.clustered.gfs.lock_protocol, argv[2],
                      sizeof(fs.clustered.gfs.lock_protocol));
      if (sz >= sizeof(fs.clustered.gfs.lock_protocol))
      {
          fprintf(stderr, "Invalid lock protocol: '%s' (too long)\n", argv[2]);
          goto done;
      }

      err = fsd_prepare(mh, &fs);
  }
  else if (strcmp(action, "mount") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 7)
      {
          usage();
          goto done;
      }

      sz = os_strlcpy(fs.fstype, argv[2], sizeof(fs.fstype));
      if (sz >= sizeof(fs.fstype))
      {
          fprintf(stderr, "Invalid fs type: '%s' (too long)\n", argv[2]);
          goto done;
      }

      sz = os_strlcpy(fs.mountpoint, argv[3], sizeof(fs.mountpoint));
      if (sz >= sizeof(fs.mountpoint))
      {
          fprintf(stderr, "Invalid mountpoint: '%s' (too long)\n", argv[3]);
          goto done;
      }

      sz = os_strlcpy(fs.devpath, argv[4], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[4]);
          goto done;
      }

      err = fsd_mount(mh, &fs, 1 , 0, argv[5], argv[6]);
  }
  else if (strcmp(action, "umount") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 6)
      {
          usage();
          goto done;
      }

      sz = os_strlcpy(fs.mountpoint, argv[2], sizeof(fs.mountpoint));
      if (sz >= sizeof(fs.mountpoint))
      {
          fprintf(stderr, "Invalid mountpoint: '%s' (too long)\n", argv[2]);
          goto done;
      }

      sz = os_strlcpy(fs.devpath, argv[3], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[3]);
          goto done;
      }

      err = fsd_umount(mh, &fs, argv[5], argv[6]);
  }
  else if (strcmp(action, "unload") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      sz = os_strlcpy(fs.fstype, argv[2], sizeof(fs.fstype));
      if (sz >= sizeof(fs.fstype))
      {
          fprintf(stderr, "Invalid fs type: '%s' (too long)\n", argv[2]);
          goto done;
      }

      err = fsd_unload(mh, &fs);
  }
  else if (strcmp(action, "create_local") == 0)
  {
      if (argc != 4)
      {
          usage();
          goto done;
      }

      err = fsd_fs_create_local(mh, argv[2], argv[3]);
  }
  else if (strcmp(action, "create_gfs") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 7)
      {
          usage();
          goto done;
      }

      COMPILE_TIME_ASSERT(sizeof("sfs") <= sizeof(fs.fstype))
      sz = os_strlcpy(fs.fstype, "sfs", sizeof(fs.fstype));

      sz = os_strlcpy(fs.devpath, argv[2], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[2]);
          goto done;
      }

      sz = os_strlcpy(fs.clustered.gfs.lock_protocol, argv[3],
                      sizeof(fs.clustered.gfs.lock_protocol));
      if (sz >= sizeof(fs.clustered.gfs.lock_protocol))
      {
          fprintf(stderr, "Invalid lock protocol: '%s' (too long)\n", argv[3]);
          goto done;
      }

      if (to_uint64(argv[4], &fs.sizeKB) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid size: '%s'\n", argv[4]);
          goto done;
      }

      sz = os_strlcpy(fs.clustered.gfs.uuid, argv[5], sizeof(fs.clustered.gfs.uuid));
      if (sz >= sizeof(fs.clustered.gfs.uuid))
      {
          fprintf(stderr, "Invalid GFS uuid: '%s' (too long)\n", argv[5]);
          goto done;
      }

      if (to_uint64(argv[6], &fs.clustered.gfs.nb_logs) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid number of logs: '%s'\n", argv[6]);
          goto done;
      }

      err = fsd_fs_create_gfs(mh, &fs);
  }
  else if (strcmp(action, "dfinfo") == 0)
  {
      struct fsd_capa buf;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      err = fsd_df(mh, argv[2], &buf);
      if (err == 0)
          printf("size=%"PRId64" bytes\n"
                 "used=%"PRId64" bytes\n"
                 "free=%"PRId64" bytes\n",
                 buf.size, buf.used, buf.free);
  }
  else if (strcmp(action, "resize") == 0)
  {
      uint64_t size_kb;

      if (argc != 6)
      {
          usage();
          goto done;
      }

      if (to_uint64(argv[5], &size_kb) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid new size: '%s'\n", argv[5]);
          goto done;
      }

      err = fsd_resize(mh, argv[2], argv[3], argv[4], size_kb);
  }
  else if (strcmp(action, "prepare_resize") == 0)
  {
      if (argc != 4)
      {
          usage();
          goto done;
      }

      err = fsd_prepare_resize(mh, argv[2], argv[3]);
  }
  else if (strcmp(action, "read_shm") == 0)
  {
      read_shm();
  }
  else if (strcmp(action, "add_logs") == 0)
  {
      fs_data_t fs;
      int num_logs, actual_num_logs;
      size_t sz;

      if (argc != 4)
      {
          usage();
          goto done;
      }

      COMPILE_TIME_ASSERT(sizeof("sfs") <= sizeof(fs.fstype));
      os_strlcpy(fs.fstype, "sfs", sizeof(fs.fstype));

      sz = os_strlcpy(fs.devpath, argv[2], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[2]);
          goto done;
      }

      if (to_int(argv[3], &num_logs) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid number of logs: '%s'\n", argv[3]);
          goto done;
      }

      actual_num_logs = fsd_set_gfs_logs(mh, &fs, num_logs);
      if (actual_num_logs < 0)
          err = actual_num_logs;
      else
      {
	  examsgDelMbox(mh, EXAMSG_TEST_ID);
	  printf("Number of logs after the operation: %d\n", actual_num_logs);
      }
  }
  else
      usage();

  if (err != 0)
      fprintf(stderr, "Action finished with error %d: %s\n", err,
              exa_error_msg(-err));

done:

  examsgDelMbox(mh, EXAMSG_TEST_ID);

  if (mh != NULL)
      examsgExit(mh);

  if (static_init_ok)
      examsg_static_clean(EXAMSG_STATIC_RELEASE);

  return err == 0 ? 0 : 1;
}
Ejemplo n.º 28
0
int main() {

	char buf[1024];

	int command_number;
	int result;

	CFileSystem test_system;

	do {
		scanf("%s", buf);
		command_number = get_command_number(buf);

		switch(command_number) {
			case (1): {
				scanf("%s", buf);
				int block_size = to_int(buf);

				result = test_system.set_block_size(block_size);
				break;
			}
			case (2): {
				scanf("%s", buf);
				int disk_size = to_int(buf);

				result = test_system.start_with_disk_size(disk_size);
				break;
			}
			case (3): {
				result = test_system.creatable();
				break;
			}
			case (4): {
				result = test_system.create_file();
				break;
			}
			case (5): {
				scanf("%s", buf);
				int file_key = to_int(buf);

				result = test_system.is_empty(file_key);
				break;
			}
			case (6): {
				scanf("%s", buf);
				int file_key = to_int(buf);
				read_file_str_to_buffer(buf);

				result = test_system.can_add_line(file_key, buf);
				break;
			}
			case (7): {
				scanf("%s", buf);
				int file_key = to_int(buf);
				read_file_str_to_buffer(buf);

				result = test_system.push_back_line(file_key, buf);
				break;
			}
			case (8): {
				scanf("%s", buf);
				int file_key = to_int(buf);
				scanf("%s", buf);
				char* ptr = to_ptr(buf);

				result = test_system.get_last_line(file_key);
				break;
			}
			case (9): {
				scanf("%s", buf);
				int file_key = to_int(buf);

				result = test_system.at_begin(file_key);
				break;
			}
			case (10): {
				scanf("%s", buf);
				int file_key = to_int(buf);

				result = test_system.at_end(file_key);
				break;
			}
			case (11): {
				scanf("%s", buf);
				int file_key = to_int(buf);

				result = test_system.set_cursor_to_begin(file_key);
				break;
			}
			case (12): {
				scanf("%s", buf);
				int file_key = to_int(buf);

				result = test_system.set_cursor_to_end(file_key);
				break;
			}
			case (13): {
				scanf("%s", buf);
				int file_key = to_int(buf);
				scanf("%s", buf);
				char* ptr = to_ptr(buf);

				result = test_system.read_forward(file_key);
				break;
			}
			case (14): {
				scanf("%s", buf);
				int file_key = to_int(buf);
				scanf("%s", buf);
				char* ptr = to_ptr(buf);

				result = test_system.read_backward(file_key);
				break;

				break;
			}
			case (15): {
				scanf("%s", buf);
				int file_key = to_int(buf);

				result = test_system.delete_file(file_key);
				break;
			}
			case (16): {
				result = test_system.end_work();
				goto exit_main_loop;
			}
			default: {
				std::cout << "Unknown command" << std::endl;
				goto exit_main_loop;
			}
		}

		std::cout.flush();

		//std::cout << "Command_number: " << command_number << std::endl;
		std::cout << result << std::endl;

	} while (*buf != '\0');
	exit_main_loop:

	return 0;
}
Ejemplo n.º 29
0
std::string fix(A value)
    {
    std::ostringstream os;
    os << std::fixed << to_int(value);
    return os.str();
    }
Ejemplo n.º 30
0
    CUTE_CHECK("pigsty->conf->next->field->index != kIpv4_tos", pigsty->conf->next->field->index == kIpv4_tos);
    CUTE_CHECK("pigsty->conf->next->next == NULL", pigsty->conf->next->next != NULL);
    CUTE_CHECK("pigsty->conf->next->next->field == NULL", pigsty->conf->next->next->field != NULL);
    CUTE_CHECK("pigsty->conf->next->next->field->index != kIpv4_src", pigsty->conf->next->next->field->index == kIpv4_src);
    CUTE_CHECK("pigsty->conf->next->next->next->field == NULL", pigsty->conf->next->next->next->field != NULL);
    CUTE_CHECK("pigsty->conf->next->next->next->field->index != kIpv4_dst", pigsty->conf->next->next->next->field->index == kIpv4_dst);
    CUTE_CHECK("pigsty->conf->next->next->next->next->field == NULL", pigsty->conf->next->next->next->next->field != NULL);
    CUTE_CHECK("pigsty->conf->next->next->next->next->field->index != kIpv4_protocol", pigsty->conf->next->next->next->next->field->index == kIpv4_protocol);
    CUTE_CHECK("pigsty->conf->next->next->next->next->next != NULL", pigsty->conf->next->next->next->next->next == NULL);
    remove("test.pigsty");
    del_pigsty_entry(pigsty);

CUTE_TEST_CASE_END

CUTE_TEST_CASE(to_int_tests)
    CUTE_CHECK("to_int() != 0", to_int(NULL) == 0);
    CUTE_CHECK("to_int() != 4", to_int("4") == 4);
    CUTE_CHECK("to_int() != 0xf", to_int("0xf") == 0xf);
    CUTE_CHECK("to_int() != 0x0f", to_int("0x0f") == 0xf);
    CUTE_CHECK("to_int() != 0xe0", to_int("0xe0") == 0xe0);
    CUTE_CHECK("to_int() == 0", to_int(NULL) == 0);
CUTE_TEST_CASE_END

CUTE_TEST_CASE(to_str_tests)
    char *retval = NULL;
    CUTE_CHECK("to_str() != NULL", to_str(NULL) == NULL);
    retval = to_str("\"\\n\\r\\t\"");
    CUTE_CHECK("to_str() != \"\\n\\r\\t\"", strcmp(retval, "\n\r\t") == 0);
    free(retval);
    retval = to_str("\"r\\nr\\nn\\ne\\n\"");
    CUTE_CHECK("to_str() != \"r\\nr\\nn\\ne\\n\"", strcmp(retval, "r\nr\nn\ne\n") == 0);