static int get_target_name(void)
{
    int target_name = TARGET_NAME_OTHER;

    char hw_platform[]      = "/sys/devices/system/soc/soc0/hw_platform"; // "Liquid" or "Surf"
    char id[]               = "/sys/devices/system/soc/soc0/id"; //109
    char mdm[]              = "/dev/mdm"; // No such file or directory

    char line[LINE_LEN];

    read_a_line( hw_platform, line, LINE_LEN);
    if(( !memcmp(line, STR_LIQUID, STRLEN_LIQUID) && IS_STR_END(line[STRLEN_LIQUID]) ) ||
       ( !memcmp(line, STR_SURF,   STRLEN_SURF)   && IS_STR_END(line[STRLEN_SURF])   )
      ) {
        if (!read_a_line( mdm, line, LINE_LEN)) {
            target_name = TARGET_NAME_APQ8064_FUSION3;
        } else {
            read_a_line( id, line, LINE_LEN);
            if(!strncmp(line, "109", strlen("109")) || !strncmp(line, "153", strlen("153"))) {
                target_name = TARGET_NAME_APQ8064_STANDALONE;
            }
        }
    }
    return target_name;
}
Esempio n. 2
0
/********************************************************************** 
  ...
***********************************************************************/
const char *inf_token(struct inputfile *inf, enum inf_token_type type)
{
  const char *c;
  const char *name;
  get_token_fn_t func;
  
  assert_sanity(inf);
  assert(type>=INF_TOK_FIRST && type<INF_TOK_LAST);

  name = tok_tab[type].name ? tok_tab[type].name : "(unnamed)";
  func = tok_tab[type].func;
  
  if (!func) {
    freelog(LOG_ERROR, "token type %d (%s) not supported yet", type, name);
    c = NULL;
  } else {
    if (!have_line(inf))
      (void) read_a_line(inf);
    if (!have_line(inf)) {
      c = NULL;
    } else {
      c = func(inf);
    }
  }
  if (c && INF_DEBUG_FOUND) {
    freelog(LOG_DEBUG, "inputfile: found %s '%s'", name, inf->token.str);
  }
  return c;
}
void * AP_UART_USB_RX (void* lpParameter)
{
	char buf_cmd [BUF_SIZE] = {0};
	int len;
	
	LOGD(TAG "Enter AP_UART_USB_RX()\n");

	for (;;)
	{
		len = read_a_line(g_fd_uart, buf_cmd, BUF_SIZE);            
		if (len>0)
		{
			buf_cmd[len] = '\0';
        	LOGD(TAG "AP_UART_USB_RX Command: %s, Len: %d\n" ,buf_cmd, len);
			AT_Pre_Process (buf_cmd);
			#ifdef MTK_DT_SUPPORT
				
				if(g_mdFlag==1)
			send_at (g_fd_atcmd, buf_cmd);
				if(g_mdFlag==2)
					send_at (g_fd_atcmdmd2, buf_cmd);
			#else
			send_at (g_fd_atcmd, buf_cmd);
			#endif
		}
 	}

	//pthread_exit (NULL);
}
Esempio n. 4
0
char *read_cfg_line(FILE *cfg_fp)
{
    char *line = malloc(LEN);
    size_t sz;

    if(!line) return NULL;

    sz = LEN;

    if(read_a_line(&line, &sz, cfg_fp) == -1)
    {
        free(line);
        return NULL;
    }

    if(line[strlen(line)-1] == '\n')
        line[strlen(line)-1] = 0;

    return line;
}
Esempio n. 5
0
void
bfam_cl_create_context_on(const char *plat_name, const char *dev_name,
                          cl_uint idx, cl_context *ctx,
                          cl_command_queue *queue, int enable_profiling)
{
  char dev_sel_buf[MAX_NAME_LEN];
  char platform_sel_buf[MAX_NAME_LEN];

  // get number of platforms
  cl_uint plat_count;
  BFAM_CL_SAFE_CALL(clGetPlatformIDs(0, NULL, &plat_count));

  // allocate memory, get list of platform handles
  cl_platform_id *platforms =
    (cl_platform_id *) bfam_malloc(plat_count*sizeof(cl_platform_id));
  BFAM_CL_SAFE_CALL(clGetPlatformIDs(plat_count, platforms, NULL));

  // print menu, if requested
#ifndef BFAM_CL_HELPER_FORCE_INTERACTIVE
  if (plat_name == CHOOSE_INTERACTIVELY) // yes, we want exactly that pointer
#endif
  {
    puts("Choose platform:");
    for (cl_uint i = 0; i < plat_count; ++i)
    {
      char buf[MAX_NAME_LEN];
      BFAM_CL_SAFE_CALL(clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR,
            sizeof(buf), buf, NULL));
      printf("[%d] %s\n", i, buf);
    }

    printf("Enter choice: ");
    fflush(stdout);

    char *sel = read_a_line();
    if (!sel)
    {
      BFAM_ABORT("error reading line from stdin");
    }

    int sel_int = BFAM_MIN(BFAM_MAX(0, atoi(sel)), (int) plat_count-1);
    bfam_free(sel);

    BFAM_CL_SAFE_CALL(clGetPlatformInfo(platforms[sel_int], CL_PLATFORM_VENDOR,
          sizeof(platform_sel_buf), platform_sel_buf, NULL));
    plat_name = platform_sel_buf;
  }

  // iterate over platforms
  for (cl_uint i = 0; i < plat_count; ++i)
  {
    // get platform name
    char buf[MAX_NAME_LEN];
    BFAM_CL_SAFE_CALL(clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR,
          sizeof(buf), buf, NULL));

    // does it match?
    if (!plat_name || strstr(buf, plat_name))
    {
      // get number of devices in platform
      cl_uint dev_count;
      BFAM_CL_SAFE_CALL(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL,
            0, NULL, &dev_count));

      // allocate memory, get list of device handles in platform
      cl_device_id *devices =
        (cl_device_id *) bfam_malloc(dev_count*sizeof(cl_device_id));

      BFAM_CL_SAFE_CALL(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL,
            dev_count, devices, NULL));

      // {{{ print device menu, if requested
#ifndef BFAM_CL_HELPER_FORCE_INTERACTIVE
      if (dev_name == CHOOSE_INTERACTIVELY) // yes, we want exactly that pointer
#endif
      {
        puts("Choose device:");
        for (cl_uint j = 0; j < dev_count; ++j)
        {
          char buf[MAX_NAME_LEN];
          BFAM_CL_SAFE_CALL(clGetDeviceInfo(devices[j], CL_DEVICE_NAME,
                sizeof(buf), buf, NULL));
          printf("[%d] %s\n", j, buf);
        }

        printf("Enter choice: ");
        fflush(stdout);

        char *sel = read_a_line();
        if (!sel)
        {
          BFAM_ABORT("error reading line from stdin");
          abort(); /* Add this for the clang static analysis */
        }

        int int_sel = BFAM_MIN(BFAM_MAX(0, atoi(sel)), (int) dev_count-1);
        bfam_free(sel);

        BFAM_CL_SAFE_CALL(clGetDeviceInfo(devices[int_sel], CL_DEVICE_NAME,
              sizeof(dev_sel_buf), dev_sel_buf, NULL));
        dev_name = dev_sel_buf;
      }

      // }}}

      // iterate over devices
      for (cl_uint j = 0; j < dev_count; ++j)
      {
        // get device name
        char buf[MAX_NAME_LEN];
        BFAM_CL_SAFE_CALL(clGetDeviceInfo(devices[j], CL_DEVICE_NAME,
              sizeof(buf), buf, NULL));

        // does it match?
        if (!dev_name || strstr(buf, dev_name))
        {
          if (idx == 0)
          {
            cl_platform_id plat = platforms[i];
            cl_device_id dev = devices[j];

            bfam_free(devices);
            bfam_free(platforms);

            // create a context
            cl_context_properties cps[3] = {
              CL_CONTEXT_PLATFORM, (cl_context_properties) plat, 0 };

            cl_int status;
            *ctx = clCreateContext(
                cps, 1, &dev, NULL, NULL, &status);
            BFAM_CL_CHECK(status, "clCreateContext");

            // create a command queue
            cl_command_queue_properties qprops = 0;
            if (enable_profiling)
              qprops |= CL_QUEUE_PROFILING_ENABLE;

            *queue = clCreateCommandQueue(*ctx, dev, qprops, &status);
            BFAM_CL_CHECK(status, "clCreateCommandQueue");

            return;
          }
          else
            --idx;
        }
      }

      bfam_free(devices);
    }
  }

  bfam_free(platforms);

  BFAM_ABORT("create_context_on: specified device not found.");
}
unsigned int loc_get_target(void)
{
    if (gTarget != (unsigned int)-1)
        return gTarget;

    static const char hw_platform[]      = "/sys/devices/soc0/hw_platform";
    static const char id[]               = "/sys/devices/soc0/soc_id";
    static const char hw_platform_dep[]  =
        "/sys/devices/system/soc/soc0/hw_platform";
    static const char id_dep[]           = "/sys/devices/system/soc/soc0/id";
    static const char mdm[]              = "/dev/mdm"; // No such file or directory

    char rd_hw_platform[LINE_LEN];
    char rd_id[LINE_LEN];
    char rd_mdm[LINE_LEN];
    char baseband[LINE_LEN];

    if (is_qca1530()) {
        gTarget = TARGET_QCA1530;
        goto detected;
    }

    loc_get_target_baseband(baseband, sizeof(baseband));

    if (!access(hw_platform, F_OK)) {
        read_a_line(hw_platform, rd_hw_platform, LINE_LEN);
    } else {
        read_a_line(hw_platform_dep, rd_hw_platform, LINE_LEN);
    }
    if (!access(id, F_OK)) {
        read_a_line(id, rd_id, LINE_LEN);
    } else {
        read_a_line(id_dep, rd_id, LINE_LEN);
    }

    if( !memcmp(baseband, STR_APQ, LENGTH(STR_APQ)) ){
        if( !memcmp(rd_id, MPQ8064_ID_1, LENGTH(MPQ8064_ID_1))
            && IS_STR_END(rd_id[LENGTH(MPQ8064_ID_1)]) )
            gTarget = TARGET_MPQ;
        else
            gTarget = TARGET_APQ_SA;
    }
    else {
        if( (!memcmp(rd_hw_platform, STR_LIQUID, LENGTH(STR_LIQUID))
             && IS_STR_END(rd_hw_platform[LENGTH(STR_LIQUID)])) ||
            (!memcmp(rd_hw_platform, STR_SURF,   LENGTH(STR_SURF))
             && IS_STR_END(rd_hw_platform[LENGTH(STR_SURF)])) ||
            (!memcmp(rd_hw_platform, STR_MTP,   LENGTH(STR_MTP))
             && IS_STR_END(rd_hw_platform[LENGTH(STR_MTP)]))) {

            if (!read_a_line( mdm, rd_mdm, LINE_LEN))
                gTarget = TARGET_MDM;
        }
        else if( (!memcmp(rd_id, MSM8930_ID_1, LENGTH(MSM8930_ID_1))
                   && IS_STR_END(rd_id[LENGTH(MSM8930_ID_1)])) ||
                  (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2))
                   && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) )
             gTarget = TARGET_MSM_NO_SSC;
        else
             gTarget = TARGET_UNKNOWN;
    }

detected:
    LOC_LOGD("HAL: %s returned %d", __FUNCTION__, gTarget);
    return gTarget;
}
Esempio n. 7
0
void * AP_UART_USB_RX (void* lpParameter)
{
	char buf_cmd [BUF_SIZE] = {0};
	int len;
    int wr_len;
    char result[64] = {0};
	
	LOGD(TAG "Enter AP_UART_USB_RX()\n");
    cmd_handler_init ();

	for (;;)
	{
		len = read_a_line(g_fd_uart, buf_cmd, BUF_SIZE);            
		if (len>0)
		{
			buf_cmd[len] = '\0';
        	LOGD(TAG "AP_UART_USB_RX Command: %s, Len: %d\n" ,buf_cmd, len);
			AT_Pre_Process (buf_cmd);
            LOGD("buf_cmd:%s\n", buf_cmd);
#if 0
			#ifdef MTK_DT_SUPPORT
				
				if(g_mdFlag==1)
			send_at (g_fd_atcmd, buf_cmd);
				if(g_mdFlag==2)
					send_at (g_fd_atcmdmd2, buf_cmd);
			#else
				send_at (g_fd_atcmd, buf_cmd);
			#endif
#endif

            CMD_OWENR_ENUM owner = rmmi_cmd_processor(buf_cmd, result);
            LOGD(TAG "result:%s\n", result);
            if(owner == CMD_OWENR_AP)
            {
                wr_len = write_chars (g_fd_uart, result, strlen(result));
			    if (wr_len != strlen(result))
				LOGE(TAG "AP_CCCI_RX: wr_len != rd_len\n");
            }
            else
            {

			if(g_mdFlag == 1)
			{
				#if defined(MTK_EXTERNAL_MODEM_SLOT)
				if(!strcmp(MTK_EXTERNAL_MODEM_SLOT, "1"))
				{
					#ifndef EVDO_DT_SUPPORT
						send_at(g_fd_atcmdmd_dt, buf_cmd);
					#endif
				}
				else{

                    if(is_support_modem(1)){
						send_at(g_fd_atcmd, buf_cmd);

					}else if(is_support_modem(2)){
					    send_at(g_fd_atcmdmd2, buf_cmd);

                    }
				}
				#else
				

					if(is_support_modem(1)){
						send_at(g_fd_atcmd, buf_cmd);

                    }else if(is_support_modem(2)){
					    send_at(g_fd_atcmdmd2, buf_cmd);

                    }
				#endif
			}
		    else if(g_mdFlag == 2)
		    {
				#if defined(MTK_EXTERNAL_MODEM_SLOT)
				if(!strcmp(MTK_EXTERNAL_MODEM_SLOT, "2"))
				{
					#ifndef EVDO_DT_SUPPORT
						send_at(g_fd_atcmdmd_dt, buf_cmd);
					#endif
				}else{

					if(is_support_modem(1)){
						send_at(g_fd_atcmd, buf_cmd);

                    }else if(is_support_modem(2)){
					    send_at(g_fd_atcmdmd2, buf_cmd);

                    }
				}
				#else
				

					if(is_support_modem(1)){
						send_at(g_fd_atcmd, buf_cmd);

                    }else if(is_support_modem(2)){
					    send_at(g_fd_atcmdmd2, buf_cmd);

                    }
				#endif
			}
		}
 	}
 	}

	//pthread_exit (NULL);
}
Esempio n. 8
0
void create_context_on(const char *plat_name, const char*dev_name, cl_uint idx,
    cl_context *ctx, cl_command_queue *queue, int enable_profiling)
{
  char dev_sel_buf[MAX_NAME_LEN];
  char platform_sel_buf[MAX_NAME_LEN];

  // get number of platforms
  cl_uint plat_count;
  CALL_CL_GUARDED(clGetPlatformIDs, (0, NULL, &plat_count));

  // allocate memory, get list of platform handles
  cl_platform_id *platforms =
    (cl_platform_id *) malloc(plat_count*sizeof(cl_platform_id));
  CHECK_SYS_ERROR(!platforms, "allocating platform array");
  CALL_CL_GUARDED(clGetPlatformIDs, (plat_count, platforms, NULL));

  // print menu, if requested
#ifndef CL_HELPER_FORCE_INTERACTIVE
  if (plat_name == CHOOSE_INTERACTIVELY) // yes, we want exactly that pointer
#endif
  {
    puts("Choose platform:");
    for (cl_uint i = 0; i < plat_count; ++i)
    {
      char buf[MAX_NAME_LEN];
      CALL_CL_GUARDED(clGetPlatformInfo, (platforms[i], CL_PLATFORM_VENDOR,
            sizeof(buf), buf, NULL));
      printf("[%d] %s\n", i, buf);
    }

    printf("Enter choice: ");
    fflush(stdout);

    char *sel = read_a_line();
    if (!sel)
    {
      fprintf(stderr, "error reading line from stdin");
      abort();
    }

    int sel_int = MIN(MAX(0, atoi(sel)), (int) plat_count-1);
    free(sel);

    CALL_CL_GUARDED(clGetPlatformInfo, (platforms[sel_int], CL_PLATFORM_VENDOR,
          sizeof(platform_sel_buf), platform_sel_buf, NULL));
    plat_name = platform_sel_buf;
  }

  // iterate over platforms
  for (cl_uint i = 0; i < plat_count; ++i)
  {
    // get platform name
    char buf[MAX_NAME_LEN];
    CALL_CL_GUARDED(clGetPlatformInfo, (platforms[i], CL_PLATFORM_VENDOR,
          sizeof(buf), buf, NULL));

    // does it match?
    if (!plat_name || strstr(buf, plat_name))
    {
      // get number of devices in platform
      cl_uint dev_count;
      CALL_CL_GUARDED(clGetDeviceIDs, (platforms[i], CL_DEVICE_TYPE_ALL,
            0, NULL, &dev_count));

      // allocate memory, get list of device handles in platform
      cl_device_id *devices =
        (cl_device_id *) malloc(dev_count*sizeof(cl_device_id));
      CHECK_SYS_ERROR(!devices, "allocating device array");

      CALL_CL_GUARDED(clGetDeviceIDs, (platforms[i], CL_DEVICE_TYPE_ALL,
            dev_count, devices, NULL));

      // {{{ print device menu, if requested
#ifndef CL_HELPER_FORCE_INTERACTIVE
      if (dev_name == CHOOSE_INTERACTIVELY) // yes, we want exactly that pointer
#endif
      {
        puts("Choose device:");
        for (cl_uint j = 0; j < dev_count; ++j)
        {
          char buf[MAX_NAME_LEN];
          CALL_CL_GUARDED(clGetDeviceInfo, (devices[j], CL_DEVICE_NAME,
                sizeof(buf), buf, NULL));
          printf("[%d] %s\n", j, buf);
        }

        printf("Enter choice: ");
        fflush(stdout);

        char *sel = read_a_line();
        if (!sel)
        {
          fprintf(stderr, "error reading line from stdin");
          abort();
        }

        int int_sel = MIN(MAX(0, atoi(sel)), (int) dev_count-1);
        free(sel);

        CALL_CL_GUARDED(clGetDeviceInfo, (devices[int_sel], CL_DEVICE_NAME,
              sizeof(dev_sel_buf), dev_sel_buf, NULL));
        dev_name = dev_sel_buf;
      }

      // }}}

      // iterate over devices
      for (cl_uint j = 0; j < dev_count; ++j)
      {
        // get device name
        char buf[MAX_NAME_LEN];
        CALL_CL_GUARDED(clGetDeviceInfo, (devices[j], CL_DEVICE_NAME,
              sizeof(buf), buf, NULL));

        // does it match?
        if (!dev_name || strstr(buf, dev_name))
        {
          if (idx == 0)
          {
            cl_platform_id plat = platforms[i];
            cl_device_id dev = devices[j];

            free(devices);
            free(platforms);

            cl_int status;
            
            // create a context
#if OPENCL_SHARE_WITH_OPENGL
  #if __APPLE__
//              CGLContextObj kCGLContext = CGLGetCurrentContext();
//              CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
//              cl_context_properties cps[] = {
//                CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup,
//                CL_CONTEXT_PLATFORM, (cl_context_properties) plat, 0 };
//            
            
            CGLContextObj gl_context = CGLGetCurrentContext();
            CGLShareGroupObj share_group = CGLGetShareGroup(gl_context);
            
            cl_context_properties properties[] = {
              CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
              (cl_context_properties)share_group, 0
            };
            *ctx = clCreateContext(properties, 0, 0, 0, 0, 0);
            clGetGLContextInfoAPPLE(*ctx, gl_context,
                                    CL_CGL_DEVICE_FOR_CURRENT_VIRTUAL_SCREEN_APPLE, sizeof(dev),
                                    &dev, NULL);
            
            
            
  #elif WIN32
              cl_context_properties cps[] = {
                CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(), CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(), CL_CONTEXT_PLATFORM, (cl_context_properties) plat, 0};
            
            //Probably won't work because &dev should correspond to glContext
            *ctx = clCreateContext(cps, 1, &dev, NULL, NULL, &status);
            CHECK_CL_ERROR(status, "clCreateContext");
  #else
              // Linux
              cl_context_properties cps[] = {
                CL_GL_CONTEXT_KHR, ( cl_context_properties) glXGetCurrentContext(), CL_GLX_DISPLAY_KHR, (cl_context_properties) glXGetCurrentDisplay(), CL_CONTEXT_PLATFORM, (cl_context_properties) plat, 0 };
            //Probably won't work because &dev should correspond to glContext
            *ctx = clCreateContext(cps, 1, &dev, NULL, NULL, &status);
            CHECK_CL_ERROR(status, "clCreateContext");
#endif

#else
            // create a context
            cl_context_properties cps[3] = {
              CL_CONTEXT_PLATFORM, (cl_context_properties) plat, 0 };
            // create a command queue
            cl_command_queue_properties qprops = 0;
            if (enable_profiling)
              qprops |= CL_QUEUE_PROFILING_ENABLE;
            
            *queue = clCreateCommandQueue(*ctx, dev, qprops, &status);
            CHECK_CL_ERROR(status, "clCreateCommandQueue");
#endif
//            *ctx = clCreateContext(
//                                   cps, 1, &dev, NULL, NULL, &status);
//            CHECK_CL_ERROR(status, "clCreateContext");

//            // create a command queue
            cl_command_queue_properties qprops = 0;
            if (enable_profiling)
              qprops |= CL_QUEUE_PROFILING_ENABLE;

            *queue = clCreateCommandQueue(*ctx, dev, qprops, &status);
            CHECK_CL_ERROR(status, "clCreateCommandQueue");

            return;
          }
          else
            --idx;
        }
      }

      free(devices);
    }
  }

  free(platforms);

  fputs("create_context_on: specified device not found.\n", stderr);
  abort();
}
Esempio n. 9
0
/********************************************************************** 
  This one is more complicated; note that it may read in multiple lines.
***********************************************************************/
static const char *get_token_value(struct inputfile *inf)
{
  struct astring *partial;
  char *c, *start;
  char trailing;
  bool has_i18n_marking = FALSE;
  char border_character = '\"';
  
  assert(have_line(inf));

  c = inf->cur_line.str + inf->cur_line_pos;
  while(*c != '\0' && my_isspace(*c)) {
    c++;
  }
  if (*c == '\0')
    return NULL;

  if (*c == '-' || my_isdigit(*c)) {
    /* a number: */
    start = c++;
    while(*c != '\0' && my_isdigit(*c)) {
      c++;
    }
    /* check that the trailing stuff is ok: */
    if (!(*c == '\0' || *c == ',' || my_isspace(*c) || is_comment(*c))) {
      return NULL;
    }
    /* If its a comma, we don't want to obliterate it permanently,
     * so rememeber it: */
    trailing = *c;
    *c = '\0';
    
    inf->cur_line_pos = c - inf->cur_line.str;
    astr_minsize(&inf->token, strlen(start)+1);
    strcpy(inf->token.str, start);
    
    *c = trailing;
    return inf->token.str;
  }

  /* allow gettext marker: */
  if (*c == '_' && *(c+1) == '(') {
    has_i18n_marking = TRUE;
    c += 2;
    while(*c != '\0' && my_isspace(*c)) {
      c++;
    }
    if (*c == '\0')
      return NULL;
  }

  border_character = *c;

  if (border_character != '\"'
      && border_character != '\''
      && border_character != '$') {
    return NULL;
  }

  /* From here, we know we have a string, we just have to find the
     trailing (un-escaped) double-quote.  We read in extra lines if
     necessary to find it.  If we _don't_ find the end-of-string
     (that is, we come to end-of-file), we return NULL, but we
     leave the file in at_eof, and don't try to back-up to the
     current point.  (That would be more difficult, and probably
     not necessary: at that point we probably have a malformed
     string/file.)

     As we read extra lines, the string value from previous
     lines is placed in partial.
  */

  /* prepare for possibly multi-line string: */
  inf->string_start_line = inf->line_num;
  inf->in_string = TRUE;

  partial = &inf->partial;	/* abbreviation */
  astr_minsize(partial, 1);
  partial->str[0] = '\0';
  
  start = c++;			/* start includes the initial \", to
				   distinguish from a number */
  for(;;) {
    int pos;
    
    while(*c != '\0' && *c != border_character) {
      /* skip over escaped chars, including backslash-doublequote,
	 and backslash-backslash: */
      if (*c == '\\' && *(c+1) != '\0') {  
	c++;
      }
      c++;
    }

    if (*c == border_character) {
      /* Found end of string */
      break;
    }

    /* Accumulate to partial string and try more lines;
     * note partial->n must be _exactly_ the right size, so we
     * can strcpy instead of strcat-ing all the way to the end
     * each time. */
    pos = partial->n - 1;
    astr_minsize(partial, partial->n + c - start + 1);
    strcpy(partial->str + pos, start);
    strcpy(partial->str + partial->n - 2, "\n");
    
    if (!read_a_line(inf)) {
      /* shouldn't happen */
      inf_log(inf, LOG_ERROR, 
              "Bad return for multi-line string from read_a_line");
      return NULL;
    }
    c = start = inf->cur_line.str;
  }

  /* found end of string */
  *c = '\0';
  inf->cur_line_pos = c + 1 - inf->cur_line.str;
  astr_minsize(&inf->token, partial->n + strlen(start));
  strcpy(inf->token.str, partial->str);
  strcpy(inf->token.str + partial->n - 1, start);

  /* check gettext tag at end: */
  if (has_i18n_marking) {
    if (*++c == ')') {
      inf->cur_line_pos++;
    } else {
      inf_warn(inf, "Missing end of i18n string marking");
    }
  }
  inf->in_string = FALSE;
  return inf->token.str;
}
Esempio n. 10
0
/********************************************************************** 
  Read a new line into cur_line; also copy to copy_line.
  Increments line_num and cur_line_pos.
  Returns 0 if didn't read or other problem: treat as EOF.
  Strips newline from input.
***********************************************************************/
static bool read_a_line(struct inputfile *inf)
{
  struct astring *line;
  char *ret;
  int pos;
  
  assert_sanity(inf);

  if (inf->at_eof)
    return FALSE;
  
  /* abbreviation: */
  line = &inf->cur_line;
  
  /* minimum initial line length: */
  astr_minsize(line, 80);
  pos = 0;

  /* don't print "orig line" in warnings until we have it: */
  inf->copy_line.n = 0;
  
  /* Read until we get a full line:
   * At start of this loop, pos is index to trailing null
   * (or first position) in line.
   */
  for(;;) {
    ret = fz_fgets(line->str + pos, line->n_alloc - pos, inf->fp);
    
    if (!ret) {
      /* fgets failed */
      inf->at_eof = TRUE;
      if (inf->in_string) {
        /* Note: Don't allow multi-line strings to cross "include"
         * boundaries */
        inf_log(inf, LOG_ERROR, "Multi-line string went to end-of-file");
        return FALSE;
      }
      break;
    }
    
    pos += strlen(line->str + pos);
    line->n = pos + 1;
    
    if (line->str[pos-1] == '\n') {
      line->str[pos-1] = '\0';
      line->n--;
      break;
    }
    if (line->n != line->n_alloc) {
      freelog(LOG_VERBOSE, "inputfile: expect missing newline at EOF");
    }
    astr_minsize(line, line->n*2);
  }
  inf->line_num++;
  inf->cur_line_pos = 0;

  astr_minsize(&inf->copy_line, inf->cur_line.n + ((inf->cur_line.n == 0) ? 1 : 0));
  strcpy(inf->copy_line.str, inf->cur_line.str);

  if (check_include(inf)) {
    return read_a_line(inf);
  }

  if (inf->at_eof) {
    line->str[0] = '\0';
    line->n = 0;
    if (inf->included_from) {
      /* Pop the include, and get next line from file above instead. */
      struct inputfile *inc = inf->included_from;
      inf_close_partial(inf);
      *inf = *inc;    /* so the user pointer in still valid
                       * (and inf pointers in calling functions) */
      free(inc);
      return read_a_line(inf);
    }
    return FALSE;
  } else {
    return TRUE;
  }
}