示例#1
0
/**
 * reregister the Sipcc stack service, without downloading the config file
 *
 */
cc_return_t CCAPI_Service_reregister(int device_handle, const char *device_name,
                                     const char *cfg,
                                     int complete_config)
{
    CCAPP_ERROR("CCAPI_Service_reregister - initiate reregister \n");

    if (is_action_to_be_deferred(RE_REGISTER_ACTION) == TRUE) {
        return CC_SUCCESS;
    }
    if (pending_action_type != NO_ACTION) {
        CCAPP_ERROR("Reset/Restart is pending, reregister Ignored! \n");
        return CC_FAILURE;
    }

    if (is_empty_str((char*)cfg)) {
        CCAPP_ERROR("Reregister request with empty config.  Exiting.\n");
        return CC_FAILURE;
    }

    g_dev_hdl = device_handle;
    strncpy(g_dev_name, device_name, 64);
    strncpy(g_cfg_p, cfg, 256);
    CCAPP_DEBUG("CCAPI_Service_reregister - devce name [%s], cfg [%s] \n", g_dev_name, g_cfg_p);
    g_compl_cfg  = complete_config;

    registration_processEvent(EV_CC_RE_REGISTER);

    return (CC_SUCCESS);
}
示例#2
0
/**
 * parse_stream - Parse a text stream for cheats.
 * @list: list to add cheats to
 * @stream: stream to read cheats from
 * @return: 0: success, -1: error
 */
int parse_stream(gamelist_t *list, FILE *stream)
{
	parser_ctx_t ctx;
	char line[LINE_MAX + 1];
	int nl = 1;

	if (list == NULL || stream == NULL)
		return -1;

	init_parser(&ctx);

	while (fgets(line, sizeof(line), stream) != NULL) { /* Scanner */
		if (!is_empty_str(line)) {
			/* Screener */
			term_str(line, is_cmt_str);
			trim_str(line);

			/* Parser */
			if (strlen(line) > 0 && parse_line(line, nl, &ctx, list) < 0)
				return -1;
		}
		nl++;
	}

	return 0;
}
示例#3
0
// @pathprefix: 如果该值为NULL/pathprefix[0]=='\0', 在形成的路径前前加这一串
char* TreeView_FormPath(HWND hctl, HTREEITEM htvi, char *pathprefix)
{
	static char		path[_MAX_PATH];
	char			text[_MAX_PATH];
	HTREEITEM		htvip;
	TVITEMEX		tvi;

	path[0] = '\0';
	TreeView_GetItem1(hctl, htvi, &tvi, TVIF_TEXT, path);
	while ((htvip = TreeView_GetParent(hctl, htvi)) && (htvip != TVI_ROOT)) {
		TreeView_GetItem1(hctl, htvip, &tvi, TVIF_TEXT, text);
		if (path[0]) {
            strcpy(path, formatstr("%s\\%s", text, path));
		} else {
			strcpy(path, text);
		}
		htvi = htvip;
	}
	if (!is_empty_str(pathprefix)) {
		if (path[0]) {
			strcpy(path, formatstr("%s\\%s", pathprefix, path));
		} else {
			strcpy(path, pathprefix);
		}
	}

	return path;
}
示例#4
0
BOOL CCmdLineParser::ExpandExtNames(LPTSTR lpFilePath, LPCTSTR lpExtNames)
{
	BOOL bResult = FALSE;
	
	if ( get_path_type(lpFilePath) != 1 )
	{
		LPCTSTR lpFileName = get_file_name(lpFilePath);
 		LPTSTR lpExtName = (TCHAR*)_tcsrchr(lpFileName, _T('.'));
 		if ( lpExtName == NULL )
 		{
			lpExtName = lpFilePath + _tcslen(lpFilePath);
			*lpExtName++ = _T('.');
			*lpExtName = _T('\0');
			
			LPCTSTR lpFixExtName = lpExtNames;
			while ( !is_empty_str(lpFixExtName) )
			{
				size_t nFixExtNameLen = 0;
				
				LPTSTR lpNextFixExtName = (LPTSTR)_tcschr(lpFixExtName, _T(';'));
				if ( lpNextFixExtName != NULL )
				{
					nFixExtNameLen = lpNextFixExtName - lpFixExtName;
					lpNextFixExtName++;
				}
				else
				{
					nFixExtNameLen = _tcslen(lpFixExtName);
				}
				
				if ( lpExtName + nFixExtNameLen < lpFilePath + MAX_PATH )
				{
					_tcsncpy(lpExtName, lpFixExtName, nFixExtNameLen);
					lpExtName[nFixExtNameLen] = 0;

					if ( get_path_type(lpFilePath) == 1 )
					{
						bResult = TRUE;
						break;
					}
				}

				lpFixExtName = lpNextFixExtName;
			}
			
			if ( !bResult )
			{
				lpExtName[-1] = _T('\0');
			}
		}
	}
	else
	{
		bResult = TRUE;
	}

	return bResult;
}
示例#5
0
/* Receives an HTTP request from socket SOCKFD and decodes it into KVREQ.
 * Returns false if there is an error. */
bool kvrequest_receive(kvrequest_t *kvreq, int sockfd) {
  bool success = false;
  kvreq->type = EMPTY;

  http_request_t req;
  url_params_t params;
  zero_params(&params);

  success = http_request_receive(&req, sockfd);
  if (!success)
    goto error;
  success = url_decode(&params, req.path);
  if (!success)
    goto error;

  switch (req.method) {
  case GET: {
    kvreq->type = is_empty_str(params.key) ? INDEX : GETREQ;
    break;
  }
  case PUT: {
    if (is_empty_str(params.key) || is_empty_str(params.val))
      goto error;
    kvreq->type = PUTREQ;
    break;
  }
  case DELETE: {
    if (is_empty_str(params.key))
      goto error;
    kvreq->type = DELREQ;
    break;
  }
  case POST: {
    if (is_empty_str(params.path))
      goto error;
    if (!strcmp(params.path, REGISTER_PATH)) {
      if (is_empty_str(params.key) || is_empty_str(params.val))
        goto error;
      kvreq->type = REGISTER;
    } else if (!strcmp(params.path, COMMIT_PATH)) {
      kvreq->type = COMMIT;
    } else if (!strcmp(params.path, ABORT_PATH)) {
      kvreq->type = ABORT;
    }
    break;
  }
  default:
    goto error;
  }
  strcpy(kvreq->key, params.key);
  strcpy(kvreq->val, params.val);

  return true;

error:
  return false;
}
示例#6
0
void CCAPI_Start_response(int device_handle, const char *device_name, const char *sipUser, const char *sipPassword, const char *sipDomain) {
    static const char fname[] = "CCAPI_Start_response";

    if (is_empty_str((char*)sipUser) || is_empty_str((char*)sipDomain)) {
        CCAPP_ERROR(DEB_F_PREFIX" invalid registration details user=%s, domain=%s", DEB_F_PREFIX_ARGS(CC_API, fname), sipUser, sipDomain);
        return;
    }

    g_dev_hdl = device_handle;
    sstrncpy(g_dev_name, device_name, sizeof(g_dev_name));

    if (is_phone_registered() == FALSE) {

        if (parse_setup_properties(device_handle, device_name, sipUser, sipPassword, sipDomain)) {
            registration_processEvent(EV_CC_CONFIG_RECEIVED);
        }
        return;
    }

 }
示例#7
0
void CCmdLineParser::ExpandParam(LPCTSTR lpCmdEnd)
{
	if ( m_dwFlag & NEED_PARAM )
	{
		LPCTSTR lpParamBegin;

		lpParamBegin = lpCmdEnd;
		lpParamBegin = skip_blank(lpParamBegin);

		if ( !is_empty_str(lpParamBegin) )
		{
			size_t nParamLen = _tcslen(lpParamBegin);

			m_lpParam = new TCHAR[nParamLen + 2];
			_tcscpy(m_lpParam, lpParamBegin);
		}
	}
}
示例#8
0
Config* Config::load(const char *filename){
	FILE *fp = NULL;
	int lineno = 0;

	// PROB: 这里为什么会比较 stdout? 猜想是因为其他程序的输出是这个程序的输入?
	if(strcmp(filename, "stdout") == 0){
		fp = stdin;
	}else{
		fp = fopen(filename, "r");
		if(!fp){
			log_error("error opening file '%s': %s", filename, strerror(errno));
			return NULL;
		}
	}

	Config *root = new Config("root", "");
	Config *cfg = root;
	int last_indent = 0;
	char buf[CONFIG_MAX_LINE];
	while(fgets(buf, sizeof(buf), fp)){
		lineno++;

		buf[strlen(buf) - 1] = '\0'; /* 去除 '\n' */
		if(is_empty_str(buf)){
			continue;
		}

		/* 有效行以 \t* 开头 */
		int indent = strspn(buf, "\t");
		char *key = buf + indent;

		if(*key == '#'){
			cfg->add_child("#", key + 1, lineno);
			continue;
		}
		if(indent <= last_indent){
			for(int i = indent; i <= last_indent; i++)
				/* 第一个配置时, 此条件为真 */
				// NOTE: 如果是同一层的而且当前 cfg 不是 root, 就回到父 config
				if(cfg != root){
					cfg = cfg->parent;
				}
			}
		}else if(indent > last_indent + 1){
示例#9
0
BOOL CCmdLineParser::_DoParser(LPCTSTR lpCmdLine,
							  LPCTSTR lpCurDir, 
							  LPCTSTR lpEnvVars, 
							  LPCTSTR lpExtNames,
							  LPCTSTR lpParentPath
							  )
{
	BOOL	bResult = FALSE;
	LPCTSTR	lpCmdBegin = NULL;
	BOOL	bQuotation = FALSE;
	
	m_szCmd[0] = 0;

    if (m_lpParam != NULL)
    {
        delete[] m_lpParam;
        m_lpParam = NULL;
    }

	if ( is_empty_str(lpCmdLine) ) return FALSE;
	if ( is_empty_str(lpParentPath) ) lpParentPath = NULL;
	if ( is_empty_str(lpCurDir) ) lpCurDir = NULL;
	if ( is_empty_str(lpEnvVars) ) lpEnvVars = NULL;
	if ( is_empty_str(lpExtNames) ) lpExtNames = NULL;

	/*
	1、The directory from which the application loaded. 
	2、The current directory for the parent process. 
	3、The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
	Windows Me/98/95:  The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
	4、The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System. 
	5、The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. 
	6、The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function. 
	*/
	lpCmdBegin = lpCmdLine;
	if ( *lpCmdBegin == _T('\"') )
	{
		lpCmdBegin = skip_quotation(lpCmdBegin);
		bQuotation = TRUE;
	}

	if ( (m_dwFlag & DEF_EXT_NAME) && lpExtNames == NULL )
	{
		// 默认扩展名
		lpExtNames = _T("bat;cmd;exe;pif");
	}

	if ( _tcsnicmp(lpCmdBegin, _T("\\??\\"), 4) == 0 )
	{
		lpCmdBegin += 4;
	}

	if ( _tcsnicmp(lpCmdBegin, _T("file://"), 7) == 0 )
	{
		if ( lpCmdBegin[8] == _T(':') )
		{
			lpCmdBegin += 7;
		}
	}

	/*
		宏展开
	*/
	if ( *lpCmdBegin == _T('%') )
	{
		LPTSTR lpCmdBuff = ExpandMacro(lpCmdBegin);
		if ( lpCmdBuff != NULL )
		{
			bResult = ExpandAbsolute(lpCmdBuff, lpExtNames, bQuotation);

			delete lpCmdBuff;
			lpCmdBuff = NULL;
		}
		
		goto _Exit;
	}
	
	/*
		绝对路径展开
	*/
	if ( is_absolute_path(lpCmdBegin) )
	{
		bResult = ExpandAbsolute(lpCmdBegin, lpExtNames, bQuotation);
		goto _Exit;
	}

	/*
		相对路径转换
	*/
	if ( (lpCurDir != NULL) || (m_dwFlag & DEF_CUR_DIR) )
	{
		LPTSTR lpCmdBuff = ExpandRelative(lpCmdBegin, lpCurDir, bQuotation);
		if ( lpCmdBuff != NULL )
		{
			bResult = ExpandAbsolute(lpCmdBuff, lpExtNames, bQuotation);

			delete lpCmdBuff;
			lpCmdBuff = NULL;

			if ( bResult )
			{
				goto _Exit;
			}
		}
	}
	
	/*
		二次宏展开
	*/
	if ( m_dwFlag & DEF_ENV_VAR )
	{
		LPTSTR lpCmdBuff = ExpandMacro2(lpCmdBegin);
		if ( lpCmdBuff != NULL )
		{
			bResult = ExpandAbsolute(lpCmdBuff, lpExtNames, bQuotation);
			
			delete lpCmdBuff;
			lpCmdBuff = NULL;

			if ( bResult )
			{
				goto _Exit;
			}
		}
	}

	/*
		在父程序目录下查找
	*/
	if ( lpParentPath != NULL )
	{
		if ( MyGetLongPathName(lpParentPath, m_szCmd, MAX_PATH) != 0 )
		{
			LPTSTR lpFileName = (LPTSTR)get_file_name(m_szCmd);
			*lpFileName = 0;
			DWORD dwLen2 = (DWORD)_tcslen(m_szCmd);

			LPTSTR lpCmdBuff = new TCHAR[dwLen2 + _tcslen(lpCmdBegin) + 2];
			if ( lpCmdBuff != NULL )
			{
				_tcscpy(lpCmdBuff, m_szCmd);
				if ( lpCmdBuff[dwLen2 - 1] != _T('\\') )
				{
					lpCmdBuff[dwLen2++] = _T('\\');
				}
				_tcscpy(lpCmdBuff + dwLen2, lpCmdBegin);
				//MessageBox(0, lpCmdBuff, NULL, 0);

				bResult = ExpandAbsolute(lpCmdBuff, lpExtNames, bQuotation);
				
				delete lpCmdBuff;
				lpCmdBuff = NULL;

				if ( bResult )
				{
					goto _Exit;
				}
			}
		}
	}

	/*
	环境变量中查找
	*/
	if ( lpEnvVars != NULL || (m_dwFlag & DEF_ENV_VAR) )
	{
		LPCTSTR lpCmdEnd = NULL;

		if ( bQuotation )
		{
			lpCmdEnd = _tcschr(lpCmdBegin, _T('\"'));
			if ( lpCmdEnd == NULL )
			{
				goto _Exit;
			}
		}
		else
		{
			lpCmdEnd = skip_no_blank(lpCmdBegin);
		}

		if ( !fix_path_separator(m_szCmd, MAX_PATH, lpCmdBegin, lpCmdEnd - lpCmdBegin) )
		{
			goto _Exit;
		}

		if ( !is_relative_path(m_szCmd) )
		{
			bResult = ExpandEnvVars(m_szCmd, lpEnvVars, lpExtNames);
			if ( bResult )
			{
				ExpandParam(lpCmdEnd);
			}
		}
	}

_Exit:
	if ( !bResult )
	{
		m_szCmd[0] = 0;
	}

	return bResult;
}
示例#10
0
BOOL CCmdLineParser::ExpandEnvVars(LPTSTR lpFilePath, LPCTSTR lpEnvVars, LPCTSTR lpExtNames)
{
	TCHAR szTempBuff[MAX_PATH + 10];

	GetSystemDirectory(szTempBuff, MAX_PATH);
	append_file_name(szTempBuff, lpFilePath);
	if ( ExpandExtNames(szTempBuff, lpExtNames) )
	{
		MyGetLongPathName(szTempBuff, lpFilePath, MAX_PATH);
		return TRUE;
	}

	GetSystemWindowsDirectory(szTempBuff, MAX_PATH);
	append_file_name(szTempBuff, lpFilePath);
	if ( ExpandExtNames(szTempBuff, lpExtNames) )
	{
		MyGetLongPathName(szTempBuff, lpFilePath, MAX_PATH);
		return TRUE;
	}

	if ( (m_dwFlag & DEF_ENV_VAR) && lpEnvVars == NULL )
	{
		lpEnvVars = GetDefaultPathVar();
	}

	if ( lpEnvVars != NULL )
	{
		//
		// 展开环境变量
		//
		LPCTSTR lpVar = lpEnvVars;
		while ( !is_empty_str(lpVar)  )
		{
			size_t nVarLen;
			TCHAR c;

			while ( (c = *lpVar) != 0 )
			{
				if ( c != _T(';') && c != _T(' ') && c != _T('\t') )
				{
					break;
				}

				lpVar++;
			}

			if ( c == 0 )
			{
				break;
			}

			LPCTSTR lpNextVar = _tcschr(lpVar, _T(';'));
			if ( lpNextVar != NULL )
			{
				nVarLen = lpNextVar - lpVar;
				lpNextVar++;
			}
			else
			{
				nVarLen = _tcslen(lpVar);
			}

			if ( fix_path_separator(szTempBuff, MAX_PATH, lpVar, nVarLen) &&
				append_file_name(szTempBuff, lpFilePath) &&
				ExpandExtNames(szTempBuff, lpExtNames) )
			{
				MyGetLongPathName(szTempBuff, lpFilePath, MAX_PATH);
				return TRUE;
			}

			lpVar = lpNextVar;
		}
	}

	return FALSE;
}
示例#11
0
文件: menus.c 项目: aspacsa/vlp
void actions_dataentry_scr(const char *curr_path, const char *case_num) {
  const size_t n_fields = 4;
  const size_t starty = 6;
  const size_t startx = 25;
  FIELD *field[n_fields];
  FORM *my_form;
  Action_t record;
  int width[] = {  MAX_ACT_DATE - 1, MAX_ACT_TYPE, MAX_ACT_NOTE - 200 };
  int height[] = { 1, 1, 4 };
 
  for ( size_t i = 0; i < n_fields - 1; ++i )
    field[i] = new_field(height[i], width[i], starty + i * 2, startx, 0, 0);
  field[n_fields - 1] = NULL;

  set_field_back( field[0], A_UNDERLINE  );
  field_opts_off( field[0], O_AUTOSKIP   );
  set_field_back( field[1], A_UNDERLINE  );
  field_opts_off( field[1], O_AUTOSKIP   );
  set_field_back( field[2], A_UNDERLINE  );
  field_opts_off( field[2], O_AUTOSKIP   );
  field_opts_off( field[2], O_STATIC     );
  set_max_field(  field[2], MAX_ACT_NOTE );

  my_form = new_form(field);
  post_form(my_form);
  refresh();

  int note_count = MAX_ACT_NOTE;
  char note_msg[4];
  char date_str[MAX_ACT_DATE];
  get_curr_date( date_str );
  mvprintw( 0, 0,   curr_path );
  mvprintw( 4, 10,  "Case Number:   %s", case_num );
  mvprintw( 6, 10,  "Entry Date:    " );
  mvprintw( 8, 10,  "Type:          " );
  mvprintw( 10, 10, "Note:          " );
  mvprintw( 15, 77, "%d", note_count );
  mvprintw( 16, 10, "(F2) = Add | (ESC) = Previous Screen" );
  set_visible_fields( field, 1, 3 );
  size_t actions_count = actions_list( case_num );
  move( 6, 25 );
  set_field_buffer( field[0], 0, date_str );
  set_current_field( my_form, field[0] );

  record.id = 0;
  int ch;

  do {
 
    ch = getch();

    switch ( ch ) {
      case KEY_UP:
        form_driver(my_form, REQ_PREV_FIELD);
        form_driver(my_form, REQ_END_LINE);
        break;
      case KEY_LEFT:
        form_driver(my_form, REQ_LEFT_CHAR);
        break;
      case KEY_RIGHT:
        form_driver(my_form, REQ_RIGHT_CHAR);
        break;
      case KEY_BACKSPACE:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( curr_fld == field[2] ) {
            snprintf( note_msg, 4, "%d", ++note_count );
            display_msg( 15, 77, my_form, curr_fld, note_msg );
          }
        }
        form_driver(my_form, REQ_PREV_CHAR);
        form_driver(my_form, REQ_DEL_CHAR);
        break;
     case DEL:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( curr_fld == field[2] ) {
            snprintf( note_msg, 4, "%d", ++note_count );
            display_msg( 15, 77, my_form, curr_fld, note_msg );
          }
        }
        form_driver( my_form, REQ_DEL_CHAR );
        break;
      case ENTER:
        form_driver( my_form, REQ_NEXT_FIELD );
        form_driver( my_form, REQ_END_LINE );
        break;
      case KEY_F(1):
        {
          FIELD * curr_fld = current_field( my_form );

          if ( curr_fld == field[1] ) {
            if ( query_select_all_codes_from_action_types()  ) {
              clear_line(18, 10);
              mvprintw( 18, 10, db_get_error_msg() );
            } else {
              const Code_t const * code_ptr;
              size_t count = 0;
              
              mvprintw( 8, 75, "Type Options:" );
              while ( ( code_ptr = get_code_from_result() ) != NULL )      
                mvprintw( 9 + count++, 81, "[%d] %s", code_ptr->code, code_ptr->desc );
              free_code_result();

              int row, col;
              get_cursor_pos( curr_fld, &row, &col );
              move( row, col );
              set_current_field( my_form, curr_fld );
            }
          }
        }
        break;
      case KEY_F(2):
        {
          clear_line( 18, 10 );
          strncpy( record.case_num, case_num, MAX_CANUM );
          strncpy( record.entry_date, compress_str( field_buffer(field[0], 0) ), MAX_ACT_DATE );
          record.type = atoi( compress_str( field_buffer(field[1], 0) ) );
          strncpy( record.note, field_buffer(field[2], 0), MAX_ACT_NOTE );
          
          if ( is_empty_str( record.note, MAX_ACT_NOTE ) ) {
            mvprintw( 18, 10, "[!] Action must at least have a note." ); 
            move( 10, 25 );
            set_current_field( my_form, field[2] );
            break;
          }

          if ( query_add_action( &record ) ) {
            mvprintw( 18, 10, db_get_error_msg() );
          } else {
            clear_fields( field, 0, 2 );
            actions_count++;
            print_action( &record, actions_count );
            note_count = MAX_ACT_NOTE;
            mvprintw( 15, 77, "%d", note_count );
          }
          move( 6, 25 );
          set_current_field( my_form, field[0] );
        }
        break;
      default:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( ch == '\'' )
            break;
          if ( curr_fld == field[1] ) {
            if ( !isdigit( ch ) )
              break;
          } else if ( curr_fld == field[2] ) {
            snprintf( note_msg, 4, "%d", --note_count );
            display_msg( 15, 77, my_form, curr_fld, note_msg );
          }
        }
        form_driver( my_form, ch );
        break;
    }
  } while ( ch != ESC );

  unpost_form( my_form );
  free_form( my_form );
  for ( size_t i = 0; i < n_fields - 1; ++i )
    free_field( field[i] );
  return;
}
示例#12
0
文件: menus.c 项目: aspacsa/vlp
void summons_dataentry_scr(const char *curr_path, const char *case_num) {
  const size_t n_fields = 6;
  const size_t starty = 6;
  const size_t startx = 25;
  FIELD *field[n_fields];
  FORM *my_form;
  Summon_t record;
  int width[] = {  MAX_SUMM_NAME, MAX_SUMM_STATUS, MAX_SUMM_REASON,  
                   MAX_SUMM_CITY, MAX_SUMM_DATE
                };
 
  for ( size_t i = 0; i < n_fields - 1; ++i )
    field[i] = new_field(1, width[i], starty + i * 2, startx, 0, 0);
  field[n_fields - 1] = NULL;
  
  set_field_back( field[0], A_UNDERLINE );
  field_opts_off( field[0], O_AUTOSKIP  );
  set_field_back( field[1], A_UNDERLINE );
  field_opts_on(  field[1], O_BLANK     );
  field_opts_off( field[1], O_AUTOSKIP  );
  set_field_back( field[2], A_UNDERLINE );
  field_opts_off( field[2], O_AUTOSKIP  );
  field_opts_on(  field[2], O_BLANK     );
  set_field_back( field[3], A_UNDERLINE );
  field_opts_off( field[3], O_AUTOSKIP  );
  field_opts_on(  field[3], O_BLANK     );
  set_field_back( field[4], A_UNDERLINE );
  field_opts_off( field[4], O_AUTOSKIP  );

  my_form = new_form(field);
  post_form(my_form);
  refresh();
 
  mvprintw( 0, 0,   curr_path );
  mvprintw( 4, 10,  "Case Number:   %s", case_num );
  mvprintw( 6, 10,  "Person:        " );
  mvprintw( 8, 10,  "Status:        " );
  mvprintw( 10, 10, "Reason:        " );
  mvprintw( 12, 10, "City:          " );
  mvprintw( 14, 10, "Date Summoned: " );
  mvprintw( 16, 10, "(F1) = Options | (F2) = Update | (F3) = Delete | (F5) = List | (ESC) = Main Menu" );
  set_visible_fields( field, 1, 5 );
  move( 6, 25 );
  set_current_field( my_form, field[0] );
 
  record.id = 0;
  int ch;
  do {
    ch = getch();
   
    switch ( ch ) {
      case KEY_UP:
        form_driver(my_form, REQ_PREV_FIELD);
        form_driver(my_form, REQ_END_LINE);
        break;
      case KEY_LEFT:
        form_driver(my_form, REQ_LEFT_CHAR);
        break;
      case KEY_RIGHT:
        form_driver(my_form, REQ_RIGHT_CHAR);
        break;
      case KEY_BACKSPACE:
        form_driver(my_form, REQ_PREV_CHAR);
        form_driver(my_form, REQ_DEL_CHAR);
        break;
      case ENTER:
        form_driver( my_form, REQ_NEXT_FIELD );
        if ( current_field( my_form ) == field[0] )
          form_driver( my_form, REQ_END_LINE );
        break;
      case KEY_F(1):
        clear_lines( 20, 40 );
        {
          FIELD * curr_fld = current_field( my_form );
          size_t error = 0;
          size_t in_target_fld = 0;
          char fld_name[7];     

          if ( curr_fld == field[1] ) {
            error = query_select_all_codes_from_summon_status();
            in_target_fld = 1;
            strncpy( fld_name, "Status", 7 );
          } else if ( curr_fld == field[2] ) {
            error = query_select_all_codes_from_summon_reasons();
            in_target_fld = 1;
            strncpy( fld_name, "Reason", 7 );
          } else if ( curr_fld == field[3] ) {
            if ( query_select_all_codes_from_city_rates() ) {
              clear_line(20, 10);
              mvprintw( 20, 10, db_get_error_msg() );
              move( 12, 25 );
              set_current_field( my_form, curr_fld );
            } else {
              const SCode_t const * scode_ptr;
              size_t count = 0;
              size_t column = 10;

              mvprintw( 20, 5, "Cities:" );
              while ( ( scode_ptr = get_scode_from_result() ) != NULL ) {
                mvprintw( 21 + count++, column, "[%s] %s", scode_ptr->code, scode_ptr->name );
                if ( count == 30 ) {
                  column += 20;
                  count = 0;
                }
              }
              free_scode_result();
            }
          }
          if ( !error && in_target_fld ) {
            const Code_t const * code_ptr;
            size_t count = 0;

            mvprintw( 20, 5, "%s Options:", fld_name );
            while ( ( code_ptr = get_code_from_result() ) != NULL )          
              mvprintw( 21 + count++, 10, "[%d] %s", code_ptr->code, code_ptr->desc );
            free_code_result();
          }
          int row, col;
          get_cursor_pos( curr_fld, &row, &col );
          move( row, col );
          set_current_field( my_form, curr_fld );
        }
        break;
      case KEY_F(2):
        clear_lines( 20, 40 );

        char person_name[MAX_SUMM_NAME];
        strncpy( person_name, field_buffer(field[0], 0), MAX_SUMM_NAME );
         
        if ( is_empty_str( person_name, MAX_SUMM_NAME ) ) {
          mvprintw( 20, 10, "[!] Summon must at least have the person's name." ); 
          move( 6, 25 );
          set_current_field( my_form, field[0] );
          break;
        }
        strncpy( record.case_num, case_num, MAX_CANUM );
        strncpy( record.name, field_buffer(field[0], 0), MAX_SUMM_NAME );
        record.status = atoi( compress_str( field_buffer(field[1], 0) ) );
        record.reason = atoi( compress_str( field_buffer(field[2], 0) ) );
        strncpy( record.city_code, compress_str( field_buffer(field[3], 0) ), MAX_SUMM_CITY );
        strncpy( record.summon_date, compress_str( field_buffer(field[4], 0) ), MAX_SUMM_DATE );
        if ( query_update_summon( &record ) ) {
          mvprintw( 20, 10, db_get_error_msg() );
          move( 6, 25 );
          set_current_field( my_form, field[0] );
        } else {
          clear_fields( field, 0, 4 );
          mvprintw( 20, 10, "[!] Summon has been updated." );
          move( 6, 25 );
          set_current_field( my_form, field[0] );
          record.id = 0;
        }
        break;
      case KEY_F(3):
        clear_lines( 20, 40 );
        if ( record.id > 0 ) {
          mvprintw( 20, 10, "[?] Delete summon '%u' ? [Y/n]", record.id );
          int ch = toupper( getch() );
          if ( ch == 'Y' ) {
            if ( query_delete_summon( record.id ) ) {
              mvprintw( 20, 10, db_get_error_msg() );
            } else {
              clear_fields( field, 0, 4 );    
              mvprintw( 20, 10, "[!] Summon '%u' has been deleted.", record.id );
              move( 6, 25 );
              set_current_field( my_form, field[0] );
              record.id = 0;
            }
          }
        }
        break;
      case KEY_F(5):
        clear_lines( 20, 40 );
        if ( query_select_all_from_summons_for( case_num ) ) {
          mvprintw( 20, 10, db_get_error_msg() );
        } else {
          Summon_t *summ_ptr;
          Summon_t *summons[MAX_SUMM_SET];
          size_t count = 0;

          while ( ( summ_ptr = get_summon_from_result() ) != NULL ) {           
            summons[count] = summ_ptr;
            count++;
          }
          if ( count ) {
            size_t selection;
            char code_buff[4];

            summons_list_scr( summons, count, &selection );
            if ( selection > 0 ) {
              summ_ptr = summons[selection - 1];
              record.id = summ_ptr->id;
              set_field_buffer( field[0], 0, summ_ptr->name );
              snprintf( code_buff, 4, "%d", summ_ptr->status );
              set_field_buffer( field[1], 0, code_buff );
              snprintf( code_buff, 4, "%d", summ_ptr->reason );
              set_field_buffer( field[2], 0, code_buff );
              set_field_buffer( field[3], 0, summ_ptr->city_code );
               set_field_buffer( field[4], 0, summ_ptr->summon_date );
            }
            free_summon_result();
          } else {
            mvprintw( 20, 10, "[!] Case %s has no summons.", case_num );
          }
        }
        set_current_field( my_form, field[0] );
        move( 6, 25 );
        break;
      default:
        {
          FIELD * curr_fld = current_field( my_form );
          if ( ch == '\'' )
            break;

          if ( curr_fld == field[1] || curr_fld == field[2] ) {
            if ( !isdigit( ch ) )
              break;
          } else if ( curr_fld == field[3] ) {
            if ( !isalpha( ch ) )
              break;
            else
              ch = toupper( ch );
          }
          form_driver( my_form, ch );
          break;
        } 
    }
  } while ( ch != ESC );

  unpost_form( my_form );
  free_form( my_form );
  for ( size_t i = 0; i < n_fields - 1; ++i )
    free_field( field[i] );
  return;
}
示例#13
0
文件: note.c 项目: andrevmatos/conboy
void note_save(UserInterface *ui)
{
	time_t time_in_s;
	gchar* title;
	gchar* content;
	GtkTextIter iter, start, end;
	GtkTextMark *mark;
	gint cursor_position;
	AppData *app_data = app_data_get();
	GtkTextBuffer *buffer = ui->buffer;
	ConboyNote *note = ui->note;

	/* If note is empty, don't save */
	gtk_text_buffer_get_bounds(buffer, &start, &end);
	content = gtk_text_iter_get_text(&start, &end);
	if (is_empty_str(content)) {
		gtk_text_buffer_set_modified(buffer, FALSE);
		g_free(content);
		return;
	}
	g_free(content);

	/* If buffer is not dirty, don't save */
	if (!gtk_text_buffer_get_modified(buffer)) {
		return;
	}

	/* Get time */
	time_in_s = time(NULL);

	/* Get cursor position */
	mark = gtk_text_buffer_get_insert(buffer);
	gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
	cursor_position = gtk_text_iter_get_offset(&iter);

	/* Get title */
	title = note_extract_title_from_buffer(buffer);

	/* Check for duplicated title */
	ConboyNote *existing_note = conboy_note_store_find_by_title(app_data->note_store, title);
	if (existing_note && (existing_note != note)) {
		/* Save alternative title if title is already taken */
		int num = conboy_note_store_get_length(app_data->note_store) + 1;
		gchar new_title[100];
		g_sprintf(new_title, _("New Note %i"), num);
		g_free(title);
		title = g_strdup(new_title);
	}

	/* Set meta data */
	/* We don't change height, width, x and y because we don't use them */
	g_object_set(note,
			"title", title,
			"change-date", time_in_s,
			"metadata-change-date", time_in_s,
			"cursor-position", cursor_position,
			"open-on-startup", FALSE,
			NULL);

	g_free(title);

	if (note->create_date == 0) {
		g_object_set(note, "create-date", time_in_s, NULL);
	}
	if (note->height == 0) {
		g_object_set(note, "height", 300, NULL);
	}
	if (note->width == 0) {
		g_object_set(note, "width", 600, NULL);
	}
	if (note->x == 0) {
		g_object_set(note, "x", 1, NULL);
	}
	if (note->y == 0) {
		g_object_set(note, "y", 1, NULL);
	}

	/* Clear note content, then set it with fresh data from the text buffer */
	content = conboy_note_buffer_get_xml(CONBOY_NOTE_BUFFER(buffer));

	/** DEBUG **/
	if (!g_str_has_suffix(content, "</note-content>\n")) {
		g_printerr("WARN: Problem when saving:\n%s\n", content);
		g_free(content);
		content = NULL;

		/* Get XML again. See wheter is's ok now */
		content = conboy_note_buffer_get_xml(CONBOY_NOTE_BUFFER(buffer));
		if (!g_str_has_suffix(content, "</note-content>\n")) {
			g_printerr("ERROR: Second save NOT successful\n");
		} else {
			g_printerr("INFO: Second save successful\n");
		}

		gtk_text_buffer_set_modified(buffer, FALSE);
		return;
	}
	/****/

	g_object_set(note, "content", content, NULL);
	g_free(content);

	/* Save the complete note */
	conboy_storage_note_save(app_data->storage, note);

	/* If first save, add to list of all notes */
	if (!conboy_note_store_find(app_data->note_store, note)) {
		conboy_note_store_add(app_data->note_store, note, NULL);
	} else {
		conboy_note_store_note_changed(app_data->note_store, note);
	}

	gtk_text_buffer_set_modified(buffer, FALSE);
}
示例#14
0
文件: config.cpp 项目: 2php/ssdb
Config* Config::load(const char *filename){
	FILE *fp = NULL;
	int lineno = 0;

	if(strcmp(filename, "stdout") == 0){
		fp = stdin;
	}else{
		fp = fopen(filename, "r");
		if(!fp){
			log_error("error opening file '%s': %s", filename, strerror(errno));
			return NULL;
		}
	}

	Config *root = new Config("root", "");
	Config *cfg = root;
	int last_indent = 0;
	char buf[CONFIG_MAX_LINE];
	while(fgets(buf, sizeof(buf), fp)){
		lineno++;

		buf[strlen(buf) - 1] = '\0'; /* 去除 '\n' */
		if(is_empty_str(buf)){
			continue;
		}

		/* 有效行以 \t* 开头 */
		int indent = strspn(buf, "\t");
		char *key = buf + indent;

		if(*key == '#'){
			cfg->add_child("#", key + 1, lineno);
			continue;
		}
		if(indent <= last_indent){
			for(int i = indent; i <= last_indent; i++){
				/* 第一个配置时, 此条件为真 */
				if(cfg != root){
					cfg = cfg->parent;
				}
			}
		}else if(indent > last_indent + 1){
			log_error("invalid indent line(%d)", lineno);
			goto err;
		}
		
		if(isspace(*key)){
			log_error("invalid line(%d): unexpected whitespace char '%c'", lineno, *key);
			goto err;
		}

		char *val = key;
		/* 跳过键名 */
		while(*val && !is_kv_seperator(*val)){
			val++;
		}
		if(*val == '\0'){
			log_error("invalid line(%d): %s, expecting ':' or '='", lineno, *val);
			goto err;
		}else if(!is_kv_seperator(*val)){
			log_error("invalid line(%d): unexpected char '%c', expecting ':' or '='", lineno, *val);
			goto err;
		}
		*val++ = '\0';

		/* key 或者 value 的前后空白字符会被过滤 */
		key = trim(key);
		val = trim(val);

		cfg = cfg->add_child(key, val, lineno);
		if(cfg == NULL){
			goto err;
		}

		last_indent = indent;
	}
	if(ferror(fp)){
		log_error("error while reading file %s", filename);
		goto err;
	}
	fclose(fp);
	return root;
err:
	if(root){
		delete root;
	}
	if(fp && fp != stdin){
		fclose(fp);
	}
	return NULL;
}
示例#15
0
void get_code(const irept &location, std::string &dest)
{
  dest = "";

  const irep_idt &file = location.file();
  const irep_idt &line = location.line();

  if(file == "" || line == "")
    return;

  std::ifstream in(file.c_str());

  if(!in)
    return;

  int line_int = atoi(line.c_str());

  int line_start = line_int - 3, line_end = line_int + 3;

  if(line_start <= 1)
    line_start = 1;

  // skip line_start-1 lines

  for(int l = 0; l < line_start - 1; l++)
  {
    std::string tmp;
    std::getline(in, tmp);
  }

  // read till line_end

  std::list<linet> lines;

  for(int l = line_start; l <= line_end && in; l++)
  {
    lines.emplace_back();

    std::string &line = lines.back().text;
    std::getline(in, line);

    if(!line.empty() && line[line.size() - 1] == '\r')
      line.resize(line.size() - 1);

    lines.back().line_number = l;
  }

  // remove empty lines at the end and at the beginning

  for(std::list<linet>::iterator it = lines.begin(); it != lines.end();)
  {
    if(is_empty_str(it->text))
      it = lines.erase(it);
    else
      break;
  }

  for(std::list<linet>::iterator it = lines.end(); it != lines.begin();)
  {
    it--;

    if(is_empty_str(it->text))
      it = lines.erase(it);
    else
      break;
  }

  // strip space
  strip_space(lines);

  // build dest

  for(auto &line : lines)
  {
    std::string line_no = i2string(line.line_number);

    while(line_no.size() < 4)
      line_no = " " + line_no;

    std::string tmp = line_no + "  " + escape_latex(line.text, true);

    if(line.line_number == line_int)
      tmp = emphasize(tmp);

    dest += tmp + "\n";
  }
}