示例#1
0
void CHudChapterTitle::LevelInit()
{
	char chapter_name[32];
	engine->GetChapterName(chapter_name, sizeof(chapter_name));
	m_wChapterName = g_pVGuiLocalize->Find(deblank(chapter_name));
	g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("HudChapterTitle");
}
示例#2
0
void	add_line_2_param(t_function **file, char *line, int test)
{
	t_tempo		*vars;

	vars = (t_tempo *)malloc(sizeof(t_tempo));
	vars->j = 0;
	vars->i = 0;
	g_nb_line++;
	vars->str2 = ft_strtrim(line);
	vars->str2 = deblank(vars->str2);
	vars->str2 = rem_com_if(vars->str2);
	while (vars->i < (int)ft_strlen(g_op_tab[test - 1].name) - 1)
		vars->i++;
	vars->i++;
	vars->name = ft_strsub(vars->str2, 0, vars->i);
	vars->j = vars->i + 1;
	while (vars->str2[vars->j] != SEPARATOR_CHAR && vars->str2[vars->j])
		vars->j++;
	test_no_params(&vars);
	vars->param1 = ft_strsub(vars->str2, vars->i, vars->j - vars->i);
	vars->i = vars->j + 1;
	while (vars->str2[vars->i] != '\0')
		vars->i++;
	vars->j++;
	vars->param2 = ft_strsub(vars->str2, vars->j, vars->i);
	make_line_2(file, vars);
	free(vars);
}
示例#3
0
文件: parser.c 项目: fourks/goaccess
/* process data based on a unique key, this includes the following
 * modules, VISITORS, BROWSERS, OS */
static void
process_unique_data (char *host, char *date, char *agent)
{
#ifdef HAVE_LIBGEOIP
  char city[CITY_LEN] = "";
  char continent[CONTINENT_LEN] = "";
  char country[COUNTRY_LEN] = "";
#endif

  char *a = NULL, *browser_key = NULL, *browser = NULL;
  char *os_key = NULL, *opsys = NULL;

  char visitor_key[UKEY_BUFFER];
  char os_type[OPESYS_TYPE_LEN], browser_type[BROWSER_TYPE_LEN];

  a = deblank (xstrdup (agent));
  snprintf (visitor_key, sizeof (visitor_key), "%s|%s|%s", host, date, a);
  (visitor_key)[sizeof (visitor_key) - 1] = '\0';
  free (a);

  /* Check if the unique visitor key exists, if not,
   * process hit as unique visitor. Includes, BROWSERS, OSs, VISITORS. */
  if (process_generic_data (ht_unique_visitors, visitor_key) == -1) {
    process_generic_data (ht_unique_vis, date);
    browser_key = xstrdup (agent);
    os_key = xstrdup (agent);

    /* extract browser & OS from agent  */
    browser = verify_browser (browser_key, browser_type);
    if (browser != NULL)
      process_browser (ht_browsers, browser, browser_type);

    opsys = verify_os (os_key, os_type);
    if (opsys != NULL)
      process_opesys (ht_os, opsys, os_type);

#ifdef HAVE_LIBGEOIP
    if (geo_location_data != NULL) {
      if (conf.geoip_city_data)
        geoip_get_city (host, city);

      geoip_get_country (host, country);
      geoip_get_continent (host, continent);
      process_geolocation (ht_countries, country, continent, city);
    }
#endif
  }

  if (browser != NULL)
    free (browser);
  if (browser_key != NULL)
    free (browser_key);
  if (os_key != NULL)
    free (os_key);
  if (opsys != NULL)
    free (opsys);
}
示例#4
0
char	is_command(char *line)
{
	if (!(line = ft_strtrim(line)))
		return (0);
	if (!(line = deblank(line)))
		return (0);
	if (is_command_start(line))
		return (1);
	return (0);
}
int
main(void)
{
	char string[] = "ab  cd e   f.g  hi";
	printf("%s\n", string);
	deblank(string);
	printf("%s\n", string);

	return EXIT_SUCCESS;
}
示例#6
0
int main()
{
    //char *str = ( char *)malloc( MAXSIZE * sizeof( char ));
    char str[MAXSIZE]="Hello   world";
    printf("size:%d\n",sizeof( *str ) );
    printf("before:%s\n", str );
    deblank( str );
    printf("after:%s\n", str );
    return EXIT_SUCCESS;
}
示例#7
0
void reportEncoderPosition() {
	char buf[60];
	char buf1[12];

	floatEncoder = encoder0Pos * (2.4 / 160.0);
	dtostrf(floatEncoder, 4, 2, buf1);
	sprintf(buf, "Encoder: %s", deblank(buf1));
	String message1 = String(buf);

	if (!message1.equals(lastPositionMessage)) {
		WebSocketsList &clients = server.getActiveWebSockets();
		for (int i = 0; i < clients.count(); i++) {
			clients[i].sendString(message1);
		}
	}

	//printf(" * zmtp_msg: ");
	//zmtp_msg_t *msg = zmtp_msg_from_const_data(0, "hello", 6);
	//zmtp_msg_destroy(&msg);

	//zmtp_msg_test (false);
	//zmtp_channel_test (false);

	/*


	 pb::Container container, got;


	 pb::Pin *pin;
	 pb::Value *value;

	 // type-tag the container:
	 container.set_type(pb::ContainerType::MT_HALUPDATE);
	 container.set_serial(56789);
	 container.set_rsvp(pb::ReplyType::NONE);


	 // add repeated submessage(s)
	 pin = container.add_pin();
	 pin->set_type(pb::ValueType::HAL_S32);
	 pin->set_name("foo.1.bar");
	 pin->set_hals32(4711);

	 value = container.add_value();
	 value->set_type(pb::ValueType::DOUBLE);
	 value->set_v_double(3.14159);

	 //std::string json = pb2json(container);
	 */

}
示例#8
0
int
main(void)
{
	char	input[MAX];

	if ((gets(input)) == NULL){
		printf("gets() error!\n");
		exit(EXIT_FAILURE);
	}
	printf("%s\n",input);
	deblank(input);
	printf("%s\n",input);
	return EXIT_SUCCESS;
}
示例#9
0
void	add_line_3_param(t_function **file, char *line, int test)
{
	t_tempo		*vars;

	vars = (t_tempo *)malloc(sizeof(t_tempo));
	vars->j = 0;
	vars->i = 0;
	g_nb_line++;
	vars->str2 = ft_strtrim(line);
	vars->str2 = deblank(vars->str2);
	vars->str2 = rem_com_if(vars->str2);
	cut_param_3(&vars, test);
	make_line_3(file, vars);
	free(vars);
}
示例#10
0
void onReceive(UdpConnection& connection, char *data, int size, IPAddress remoteIP, uint16_t remotePort)
{
	char buf[60];
	char buf1[12];

	sendToClients("UDP received");
	debugf("UDP Sever callback from %s:%d, %d bytes", remoteIP.toString().c_str(), remotePort, size);

	// We implement string mode server for example
	Serial.print(">\t");
	Serial.print(data);

	floatAnalog = atof(analogResult.c_str()) / 10.0;
	dtostrf(floatAnalog, 7, 4, buf1);
	sprintf(buf, "%s", deblank(buf1));
	String message = String(buf);

	udp.sendStringTo(remoteIP, udpServerPort, message);
}
示例#11
0
int SB_SA_Util_Op_Line::get_op_line(char *pa_arg[], int pv_max) {
    const char *WHERE = "SB_SA_Util_Op_Line::get_op_line";
    char        la_line[BUFSIZ];
    char       *lp_line;
    char        lv_char;
    int         lv_inx;

    lp_line = ip_file->get_file_line(la_line, BUFSIZ);
    if (lp_line != NULL)
        lp_line = SB_SA_Util_Op_Line::deblank(0, lp_line);
    if (lp_line == NULL)
        lv_inx = 0;
    else if (*lp_line == '#')
        lv_inx = 0;
    else {
        for (lv_inx = 0; lv_inx < pv_max; lv_inx++) {
            pa_arg[lv_inx] = lp_line;
            while (!isspace(*lp_line) && (*lp_line != ',') && *lp_line)
                lp_line++;
            if (pa_arg[lv_inx] == lp_line) {
                if (*lp_line == ',')
                    pa_arg[lv_inx] = NULL;
                else
                    break;
            }
            lv_char = *lp_line;
            *lp_line = '\0';
            if (!lv_char) {
                lv_inx++;
                break;
            }
            lp_line = deblank(1, lp_line);
        }
        if (lv_inx == 0) {
            SB_SA_Util_Error::error_printf(WHERE,
                                           "input line parse failed to acquire any arguments\n");
            SB_SA_util_assert_igt(lv_inx, 0);
        }
    }
    return lv_inx;
}
示例#12
0
void reportAnalogue() {
	char buf[60];
	char buf1[10];
	char data[4];

	/*
	 1 ... BROWN        ... 12V ... 24V +
	 2 ... WHITE        ... RXD
	 3 ... BLUE         ... GND
	 4...  BLACK        ... not used
	 5...  YELOW/GREEN  ... TXD
	 */

	floatAnalog = atof(analogResult.c_str()) / 10.0;
	dtostrf(floatAnalog, 7, 4, buf1);
	sprintf(buf, "Analogue: %s", deblank(buf1));
	String message = String(buf);

	if (!message.equals(lastPositionMessage)) {
		WebSocketsList &clients = server.getActiveWebSockets();
		for (int i = 0; i < clients.count(); i++) {
			clients[i].sendString(message);
		}
		lastPositionMessage = message;

		/*
		union u
		{
		    float f;
		    char s[sizeof(float)];
		};

		union u foo;
		foo.f = floatAnalog;
*/
		//udp.sendStringTo(IPAddress("192.168.1.19"), (uint16_t)1234, foo.s);
		udp.sendStringTo(IPAddress(udpServerIP), udpServerPort, analogResult);

		//Serial.printf("Analogue: %f", analogResult.c_str());
	}
}
示例#13
0
文件: parser.c 项目: fourks/goaccess
/* process a line from the log and store it accordingly */
static int
process_log (GLog * logger, char *line, int test)
{
  GLogItem *glog;
  char date[DATE_LEN];
  char *qmark = NULL, *req_key = NULL;
  int is404 = 0;

  if (valid_line (line)) {
    count_invalid (logger);
    return 0;
  }

  count_process (logger);
  glog = init_log_item (logger);
  /* parse a line of log, and fill structure with appropriate values */
  if (parse_format (glog, conf.log_format, conf.date_format, line)) {
    count_invalid (logger);
    goto cleanup;
  }

  /* must have the following fields */
  if (glog->host == NULL || glog->date == NULL || glog->req == NULL) {
    count_invalid (logger);
    goto cleanup;
  }
  /* agent will be null in cases where %u is not specified */
  if (glog->agent == NULL)
    glog->agent = alloc_string ("-");

  /* testing log only */
  if (test)
    goto cleanup;

  if (process_date (glog, date)) {
    count_invalid (logger);
    goto cleanup;
  }
  /* ignore host or crawlers */
  if (exclude_ip (logger, glog) == 0)
    goto cleanup;
  if (exclude_crawler (glog) == 0)
    goto cleanup;
  if (ignore_referer (glog->site))
    goto cleanup;

  /* is this a 404? */
  if (glog->status && !memcmp (glog->status, "404", 3))
    is404 = 1;
  /* treat 444 as 404? */
  else if (glog->status && !memcmp (glog->status, "444", 3) &&
           conf.code444_as_404)
    is404 = 1;
  /* check if we need to remove the request's query string */
  else if (conf.ignore_qstr) {
    if ((qmark = strchr (glog->req, '?')) != NULL) {
      if ((qmark - glog->req) > 0)
        *qmark = '\0';
    }
  }

  req_key = xstrdup (glog->req);
  /* include HTTP method/protocol to request */
  if (conf.append_method && glog->method) {
    glog->method = strtoupper (glog->method);
    append_method_to_request (&req_key, glog->method);
  }
  if (conf.append_protocol && glog->protocol) {
    glog->protocol = strtoupper (glog->protocol);
    append_protocol_to_request (&req_key, glog->protocol);
  }
  if ((conf.append_method) || (conf.append_protocol))
    req_key = deblank (req_key);

  unique_data (glog, date);
  /* process agents that are part of a host */
  if (conf.list_agents)
    process_host_agents (glog->host, glog->agent);
  /* process status codes */
  if (glog->status)
    process_generic_data (ht_status_code, glog->status);
  /* process 404s */
  if (is404)
    process_request (ht_not_found_requests, req_key, glog);
  /* process static files */
  else if (verify_static_content (glog->req))
    process_request (ht_requests_static, req_key, glog);
  /* process regular files */
  else
    process_request (ht_requests, req_key, glog);

  /* process referrers */
  process_referrers (glog->ref, glog->site);
  /* process hosts */
  process_generic_data (ht_hosts, glog->host);
  /* process bandwidth  */
  process_request_meta (ht_date_bw, date, glog->resp_size);
  process_request_meta (ht_file_bw, req_key, glog->resp_size);
  process_request_meta (ht_host_bw, glog->host, glog->resp_size);

  /* process time taken to serve the request, in microseconds */
  process_request_meta (ht_file_serve_usecs, req_key, glog->serve_time);
  process_request_meta (ht_host_serve_usecs, glog->host, glog->serve_time);

  logger->resp_size += glog->resp_size;
#ifdef TCB_BTREE
  process_request_meta (ht_general_stats, "bandwidth", glog->resp_size);
#endif

cleanup:
  free_logger (glog);
  if (req_key != NULL)
    free (req_key);

  return 0;
}
示例#14
0
/* process a line from the log and store it accordingly */
static int
process_log (GLog * logger, char *line, int test)
{
  GLogItem *glog;
  char buf[DATE_LEN];
  char *qmark = NULL, *req_key = NULL;
  int not_found = 0;            /* 404s */

  /* make compiler happy */
  memset (buf, 0, sizeof (buf));

  if ((line == NULL) || (*line == '\0')) {
    logger->invalid++;
    return 0;
  }

  /* ignore comments */
  if (*line == '#' || *line == '\n')
    return 0;

  if (parsing_spinner != NULL && parsing_spinner->state == SPN_RUN)
    pthread_mutex_lock (&parsing_spinner->mutex);

  logger->process++;

#ifdef TCB_BTREE
  process_generic_data (ht_general_stats, "total_requests");
#endif

  if (parsing_spinner != NULL && parsing_spinner->state == SPN_RUN)
    pthread_mutex_unlock (&parsing_spinner->mutex);

  glog = init_log_item (logger);
  if (parse_format (glog, conf.log_format, conf.date_format, line) == 1) {
    logger->invalid++;

#ifdef TCB_BTREE
    process_generic_data (ht_general_stats, "failed_requests");
#endif
    goto cleanup;
  }

  /* must have the following fields */
  if (glog->host == NULL || glog->date == NULL || glog->status == NULL ||
      glog->req == NULL) {
    logger->invalid++;
    goto cleanup;
  }

  if (test)
    goto cleanup;

  convert_date (buf, glog->date, conf.date_format, "%Y%m%d", DATE_LEN);
  if (buf == NULL)
    goto cleanup;

  /* ignore host */
  if (conf.ignore_ip_idx && ip_in_range (glog->host)) {
    logger->exclude_ip++;
#ifdef TCB_BTREE
    process_generic_data (ht_general_stats, "exclude_ip");
#endif
    goto cleanup;
  }
  /* ignore crawlers */
  if (conf.ignore_crawlers && is_crawler (glog->agent))
    goto cleanup;

  /* agent will be null in cases where %u is not specified */
  if (glog->agent == NULL)
    glog->agent = alloc_string ("-");
  /* process visitors, browsers, and OS */
  process_unique_data (glog->host, buf, glog->agent);

  /* process agents that are part of a host */
  if (conf.list_agents)
    process_host_agents (glog->host, glog->agent);

  /* is this a 404? */
  if (!memcmp (glog->status, "404", 3)) {
    not_found = 1;
  }
  /* treat 444 as 404? */
  else if (!memcmp (glog->status, "444", 3) && conf.code444_as_404) {
    not_found = 1;
  }
  /* check if we need to remove the request's query string */
  else if (conf.ignore_qstr) {
    if ((qmark = strchr (glog->req, '?')) != NULL) {
      if ((qmark - glog->req) > 0)
        *qmark = '\0';
    }
  }

  req_key = xstrdup (glog->req);
  /* include HTTP method/protocol to request */
  if (conf.append_method && glog->method) {
    str_to_upper (glog->method);
    append_method_to_request (&req_key, glog->method);
  }
  if (conf.append_protocol && glog->protocol) {
    str_to_upper (glog->protocol);
    append_protocol_to_request (&req_key, glog->protocol);
  }
  if ((conf.append_method) || (conf.append_protocol))
    req_key = deblank (req_key);

  /* process 404s */
  if (not_found)
    process_request (ht_not_found_requests, req_key, glog);
  /* process static files */
  else if (verify_static_content (glog->req))
    process_request (ht_requests_static, req_key, glog);
  /* process regular files */
  else
    process_request (ht_requests, req_key, glog);

  /* process referrers */
  process_referrers (glog->ref);
  /* process status codes */
  process_generic_data (ht_status_code, glog->status);
  /* process hosts */
  process_generic_data (ht_hosts, glog->host);
  /* process bandwidth  */
  process_request_meta (ht_date_bw, buf, glog->resp_size);
  process_request_meta (ht_file_bw, req_key, glog->resp_size);
  process_request_meta (ht_host_bw, glog->host, glog->resp_size);
  /* process time taken to serve the request, in microseconds */
  process_request_meta (ht_file_serve_usecs, req_key, glog->serve_time);
  process_request_meta (ht_host_serve_usecs, glog->host, glog->serve_time);
  logger->resp_size += glog->resp_size;
#ifdef TCB_BTREE
  process_request_meta (ht_general_stats, "bandwidth", glog->resp_size);
#endif

cleanup:
  free_logger (glog);
  if (req_key != NULL)
    free (req_key);

  return 0;
}
int main (){
	cl_platform_id clPlatform;
	cl_device_id clDevice;
	cl_context clContext;
	cl_command_queue clQueue;
	cl_program clProgram;
	int isMic=0;
	cl_uint numDevices;
	cl_platform_id platform;
	clGetPlatformIDs(1, &platform, NULL);
	cl_int err;
	err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
	//Check for MIC if GPU is not found
	if (err != CL_SUCCESS) {
		err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ACCELERATOR, 0, NULL, &numDevices);
		isMic = 1;
	}
	if (err != CL_SUCCESS) {
		fprintf(stderr, "[ERROR in OpenCLDriver::HI_get_num_devices()] Failed to get device IDs  for type \n");
	}
	
	
	cl_device_id devices[numDevices];
	clGetPlatformIDs(1, &clPlatform, NULL);
	if(isMic)
		clGetDeviceIDs(clPlatform, CL_DEVICE_TYPE_ACCELERATOR, numDevices, devices, NULL);
	else
		clGetDeviceIDs(clPlatform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
	
	for(int i=0; i< numDevices; i++) {
		clDevice = devices[i];
		
		FILE *fp;
		char *source_str;
		size_t source_size;
		char filename[] = "openarc_kernel.cl";
		fp = fopen(filename, "r");
		if (!fp) {
			fprintf(stderr, "[INFO: in OpenCL binary creation] Failed to read the kernel file %s, so skipping binary generation for OpenCL devices %d\n", filename, i);
			break;
		}
		source_str = (char*)malloc(MAX_SOURCE_SIZE);
		source_size = fread( source_str, 1, MAX_SOURCE_SIZE, fp);
		fclose( fp );

		cl_int err;
		clContext = clCreateContext( NULL, 1, &clDevice, NULL, NULL, &err);
		if(err != CL_SUCCESS) {
				fprintf(stderr, "[ERROR in OpenCL binary creation] failed to create OPENCL context with error %d (OPENCL GPU)\n", err);
		}

		clQueue = clCreateCommandQueue(clContext, clDevice, 0, &err);
		if(err != CL_SUCCESS) {
				fprintf(stderr, "[ERROR in OpenCL binary creation] failed to create OPENCL queue with error %d (OPENCL GPU)\n", err);
		}
		
		char cBuffer[1024];
		char *cBufferN;
		clGetDeviceInfo(clDevice, CL_DEVICE_NAME, sizeof(cBuffer), &cBuffer, NULL);
		cBufferN = deblank(cBuffer);
		
		std::string binaryName = std::string("openarc_kernel_") + cBufferN + std::string(".ptx");
		
		clProgram = clCreateProgramWithSource(clContext, 1, (const char **)&source_str, (const size_t *)&source_size, &err);
		if(err != CL_SUCCESS) {
				fprintf(stderr, "[ERROR in OpenCL binary creation] failed to create OPENCL program with error %d (OPENCL GPU)\n", err);
		}
		
		char *envVar;
		envVar = getenv("OPENARC_JITOPTION");
		err = clBuildProgram(clProgram, 1, &clDevice, envVar, NULL, NULL);
#if PRINT_LOG == 0
		if(err != CL_SUCCESS)
		{
				printf("[ERROR in OpenCL binary creation] Error in clBuildProgram, Line %u in file %s : %d!!!\n\n", __LINE__, __FILE__, err);
				if (err == CL_BUILD_PROGRAM_FAILURE)
				{
						// Determine the size of the log
						size_t log_size;
						clGetProgramBuildInfo(clProgram, clDevice, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);

						// Allocate memory for the log
						char *log = (char *) malloc(log_size);

						// Get the log
						clGetProgramBuildInfo(clProgram, clDevice, CL_PROGRAM_BUILD_LOG, log_size, log, NULL);

						// Print the log
						printf("%s\n", log);
				}
				exit(1);
		}
#else
		// Determine the size of the log
		size_t log_size;
		clGetProgramBuildInfo(clProgram, clDevice, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);

		// Allocate memory for the log
		char *log = (char *) malloc(log_size);

		// Get the log
		clGetProgramBuildInfo(clProgram, clDevice, CL_PROGRAM_BUILD_LOG, log_size, log, NULL);

		// Print the log
		printf("%s\n", log);
#endif
		
		
		size_t size;
		err = clGetProgramInfo( clProgram, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), &size, NULL );
		if(err != CL_SUCCESS) {
				fprintf(stderr, "[ERROR in OpenCL binary creation] failed to get OPENCL program info error %d (OPENCL GPU)\n", err);
		}

		unsigned char * binary = new unsigned char [size];
		
		//#ifdef NVIDIA_GPU
		//err = clGetProgramInfo( clProgram, CL_PROGRAM_BINARIES, size, &binary, NULL );
		//#else
		err = clGetProgramInfo(clProgram, CL_PROGRAM_BINARIES, sizeof(unsigned char *), &binary, NULL);
		//#endif
		
		if(err != CL_SUCCESS) {
				fprintf(stderr, "[ERROR in OpenCL binary creation] failed to dump OPENCL program binary error %d (OPENCL GPU)\n", err);
		}
		
		FILE * fpbin = fopen(binaryName.c_str(), "wb" );
		fwrite(binary, 1 , size, fpbin);
		fclose(fpbin);
		delete[] binary;
	}	
	
	#ifdef NVIDIA_GPU
	//Generate ptx files for .cu, only if nvcc is found on the system
	if (system("which nvcc")==0){
		CUresult err;
		int major, minor;
		CUdevice cuDevice;
		CUcontext cuContext;
		CUmodule cuModule;
		int numDevices;
		cudaGetDeviceCount(&numDevices);
		
		for(int i=0 ; i < numDevices; i++) {
			cuDeviceGet(&cuDevice, i);
			#if CUDA_VERSION >= 5000
			cuDeviceGetAttribute (&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, cuDevice);
			cuDeviceGetAttribute (&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, cuDevice);
			#else
				cuDeviceComputeCapability(&major, &minor, cuDevice);
			#endif

			std::stringstream ss;
			ss << major;
			ss << minor;
			std::string version = ss.str();
			std::string ptxName = std::string("openarc_kernel_") + version + std::string(".ptx");
			std::string command = std::string("nvcc $OPENARC_JITOPTION -arch=sm_") + version + std::string(" openarc_kernel.cu -ptx -o ") + ptxName;
			system(command.c_str());
		}
	}
	#endif

}
示例#16
0
/*
 * Get any character by its code.
 */
static int
gf_get_char (gf_font_t *font, gf_char_t *sym, unsigned char charcode)
{
	gf_locator_t *loc;
	unsigned char c, col_delta, row_delta;
	long lcode, back_pointer;

	loc = &font->char_loc [charcode];
	if (loc->char_pointer == -1)
		return 0;

	sym->font = font;
	sym->h_escapement = loc->h_escapement;
	sym->tfm_width = loc->tfm_width;

	if (fseek (font->input_file, loc->char_pointer, SEEK_SET) < 0) {
		fprintf (stderr, "%s: seek error\n", font->input_filename);
		return 0;
	}

	/* This reads the character starting from the current position
	 * (but some specials might come first).
	 */
	skip_specials (font);

	c = get_byte (font);
	switch (c) {
	case BOC:
		/* If the back pointer actually points somewhere,
		 * this character is a ``residue'', and the font
		 * is probably too big.
		 */
		lcode = (long) get_four (font);
		if (lcode < 0 || lcode > 255) {
			/* Someone is trying to use a font with character codes
			 * that are out of our range. */
			fprintf (stderr, "%s: invalid character code %ld (expected %d)\n",
				font->input_filename, lcode, charcode);
			return 0;
		}
		sym->charcode = lcode;

		back_pointer = (long) get_four (font);
		if (back_pointer != -1)
			fprintf (stderr, "%s: warning: character %u has a non-null back pointer (to %#lx)\n",
				font->input_filename, sym->charcode, back_pointer);

		sym->bbox_min_col = (long) get_four (font);
		sym->bbox_max_col = (long) get_four (font);
		sym->bbox_min_row = (long) get_four (font);
		sym->bbox_max_row = (long) get_four (font);
		break;

	case BOC1:
		sym->charcode = get_byte (font);

		col_delta = get_byte (font);
		sym->bbox_max_col = get_byte (font);
		sym->bbox_min_col = sym->bbox_max_col - col_delta;

		row_delta = get_byte (font);
		sym->bbox_max_row = get_byte (font);
		sym->bbox_min_row = sym->bbox_max_row - row_delta;
		break;

	case POST:
		return 0;

	default:
		fprintf (stderr, "%s: error reading character (found %u)\n",
			font->input_filename, c);
		return 0;
	}
	if (sym->charcode != charcode) {
		fprintf (stderr, "%s: warning: character code mismatch, %d != %d\n",
			font->input_filename, sym->charcode, charcode);
	}

	get_character_bitmap (sym);

	deblank (sym);
	return 1;
}