コード例 #1
0
ファイル: main.c プロジェクト: amendiola/sngrep
/**
 * @brief Main function logic
 *
 * Parse command line options and start running threads
 *
 * @note There are no params actually... if you supply one 
 *    param, I will assume we are running offline mode with
 *    a pcap file. Otherwise the args will be passed to ngrep
 *    without any type of validation.
 *
 */
int
main(int argc, char* argv[])
{

    int ret;
    //! ngrep thread attributes
    pthread_attr_t attr;
    //! ngrep running thread
    pthread_t exec_t;

    // Initialize configuration options
    init_options();

    // Parse arguments.. I mean..
    if (argc < 2) {
        // No arguments!
        usage(argv[0]);
        return 1;
    } else if (argc == 2) {
        // Show offline mode in ui
        set_option_value("running.mode", "Offline");
        set_option_value("running.file", argv[1]);

        // Assume Offline mode with pcap file
        if (load_from_file(argv[1]) != 0) {
            fprintf(stderr, "Error loading data from pcap file %s\n", argv[1]);
            return 1;
        }
    } else {
        // Show online mode in ui
        set_option_value("running.mode", "Online");

        // Assume online mode, launch ngrep in a thread
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
        if (pthread_create(&exec_t, &attr, (void *) online_capture, argv)) {
            fprintf(stderr, "Unable to create Exec Thread!\n");
            return 1;
        }
        pthread_attr_destroy(&attr);
    }

    // Initialize interface
    // This is a blocking call. Interface have user action loops.
    init_interface();
    // Leaving!
    return ret;
}
コード例 #2
0
ファイル: option.c プロジェクト: miconda/sngrep
int
read_options(const char *fname)
{
    FILE *fh;
    char line[1024], type[20], option[50], value[50];
    int id;

    if (!(fh = fopen(fname, "rt")))
        return -1;

    while (fgets(line, 1024, fh) != NULL) {
        // Check if this line is a commentary or empty line
        if (!strlen(line) || *line == '#')
            continue;

        // Get configuration option from setting line
        if (sscanf(line, "%s %s %[^\t\n]", type, option, value) == 3) {
            if (!strcasecmp(type, "set")) {
                if ((id = setting_id(option)) >= 0) {
                    setting_set_value(id, value);
                } else {
                    set_option_value(option, value);
                }
            } else if (!strcasecmp(type, "alias")) {
                set_alias_value(option, value);
            } else if (!strcasecmp(type, "bind")) {
                key_bind_action(key_action_id(option), key_from_str(value));
            } else if (!strcasecmp(type, "unbind")) {
                key_unbind_action(key_action_id(option), key_from_str(value));
            }
        }
    }
    fclose(fh);
    return 0;
}
コード例 #3
0
ファイル: os_win16.c プロジェクト: Raimondi/VimStarterKit_OLD
/*
 * GUI version of mch_init().
 */
    void
mch_init()
{
    extern int _fmode;


    /* Let critical errors result in a failure, not in a dialog box.  Required
     * for the timestamp test to work on removed floppies. */
    SetErrorMode(SEM_FAILCRITICALERRORS);

    _fmode = O_BINARY;		/* we do our own CR-LF translation */

    /* Specify window size.  Is there a place to get the default from? */
    Rows = 25;
    Columns = 80;


    set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0);

#ifdef FEAT_CLIPBOARD
    clip_init(TRUE);

    /*
     * Vim's own clipboard format recognises whether the text is char, line,
     * or rectangular block.  Only useful for copying between two Vims.
     * "VimClipboard" was used for previous versions, using the first
     * character to specify MCHAR, MLINE or MBLOCK.
     */
    clip_star.format = RegisterClipboardFormat("VimClipboard2");
    clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");
#endif
}
コード例 #4
0
ファイル: dropt.c プロジェクト: mm318/TiledEditor
/** parse_option_arg
  *
  *     Helper function to dropt_parse to deal with consuming possibly
  *     optional arguments.
  *
  * PARAMETERS:
  *     IN/OUT context : The dropt context.
  *     IN/OUT ps      : The current parse state.
  *
  * RETURNS:
  *     An error code.
  */
static dropt_error
parse_option_arg(dropt_context * context, parse_state * ps)
{
  dropt_error err;

  bool consumeNextArg = false;

  if (OPTION_TAKES_ARG(ps->option) && ps->optionArgument == NULL) {
    /* The option expects an argument, but none was specified with '='.
     * Try using the next item from the command-line.
     */
    if (ps->argsLeft > 0 && *(ps->argNext) != NULL) {
      consumeNextArg = true;
      ps->optionArgument = *(ps->argNext);
    } else if (!(ps->option->attr & dropt_attr_optional_val)) {
      err = dropt_error_insufficient_arguments;
      goto exit;
    }
  }

  /* Even for options that don't ask for arguments, always parse and
   * consume an argument that was specified with '='.
   */
  err = set_option_value(context, ps->option, ps->optionArgument);

  if (err != dropt_error_none
      && (ps->option->attr & dropt_attr_optional_val)
      && consumeNextArg
      && ps->optionArgument != NULL) {
    /* The option's handler didn't like the argument we fed it.  If the
     * argument was optional, try again without it.
     */
    consumeNextArg = false;
    ps->optionArgument = NULL;
    err = set_option_value(context, ps->option, NULL);
  }

exit:
  if (err == dropt_error_none && consumeNextArg) {
    ps->argNext++;
    ps->argsLeft--;
  }
  return err;
}
コード例 #5
0
/**
 * @brief For the selected option, selects the previous possible value in the list.
 */
void SelectionMenuOptions::set_option_previous_value() {

  int index = current_indices[cursor_position];
  index = (index + nb_values[cursor_position] - 1) % nb_values[cursor_position];
  set_option_value(index);
  menu->play_cursor_sound();

  left_arrow_sprite->restart_animation();
  right_arrow_sprite->restart_animation();
}
コード例 #6
0
ファイル: crypt.c プロジェクト: KarstenHopp/vim
/*
 * Ask the user for a crypt key.
 * When "store" is TRUE, the new key is stored in the 'key' option, and the
 * 'key' option value is returned: Don't free it.
 * When "store" is FALSE, the typed key is returned in allocated memory.
 * Returns NULL on failure.
 */
    char_u *
crypt_get_key(
    int		store,
    int		twice)	    /* Ask for the key twice. */
{
    char_u	*p1, *p2 = NULL;
    int		round;

    for (round = 0; ; ++round)
    {
	cmdline_star = TRUE;
	cmdline_row = msg_row;
	p1 = getcmdline_prompt(NUL, round == 0
		? (char_u *)_("Enter encryption key: ")
		: (char_u *)_("Enter same key again: "), 0, EXPAND_NOTHING,
		NULL);
	cmdline_star = FALSE;

	if (p1 == NULL)
	    break;

	if (round == twice)
	{
	    if (p2 != NULL && STRCMP(p1, p2) != 0)
	    {
		MSG(_("Keys don't match!"));
		crypt_free_key(p1);
		crypt_free_key(p2);
		p2 = NULL;
		round = -1;		/* do it again */
		continue;
	    }

	    if (store)
	    {
		set_option_value((char_u *)"key", 0L, p1, OPT_LOCAL);
		crypt_free_key(p1);
		p1 = curbuf->b_p_key;
	    }
	    break;
	}
	p2 = p1;
    }

    /* since the user typed this, no need to wait for return */
    if (msg_didout)
	msg_putchar('\n');
    need_wait_return = FALSE;
    msg_didout = FALSE;

    crypt_free_key(p2);
    return p1;
}
コード例 #7
0
ファイル: option.c プロジェクト: miconda/sngrep
int
init_options(int no_config)
{
    // Custom user conf file
    char *userconf = NULL;
    char *rcfile;
    char pwd[MAX_SETTING_LEN];

    // Defualt savepath is current directory
    if (getcwd(pwd, MAX_SETTING_LEN)) {
        setting_set_value(SETTING_SAVEPATH, pwd);
    }

    // Initialize settings
    setting_set_value(SETTING_FILTER_METHODS, "REGISTER,INVITE,SUBSCRIBE,NOTIFY,OPTIONS,PUBLISH,MESSAGE");

    // Add Call list column options
    set_option_value("cl.column0", "index");
    set_option_value("cl.column1", "method");
    set_option_value("cl.column2", "sipfrom");
    set_option_value("cl.column3", "sipto");
    set_option_value("cl.column4", "msgcnt");
    set_option_value("cl.column5", "src");
    set_option_value("cl.column6", "dst");
    set_option_value("cl.column7", "state");

	// Done if config file should not be read
	if(no_config) {
		return 0;
	}

    // Read options from configuration files
    read_options("/etc/sngreprc");
    read_options("/usr/local/etc/sngreprc");
    // Get user configuration
    if ((rcfile = getenv("SNGREPRC"))) {
        read_options(rcfile);
    } else if ((rcfile = getenv("HOME"))) {
        if ((userconf = sng_malloc(strlen(rcfile) + RCFILE_EXTRA_LEN))) {
            sprintf(userconf, "%s/.sngreprc", rcfile);
            read_options(userconf);
            sng_free(userconf);
        }
    }

    return 0;
}
コード例 #8
0
ファイル: workshop.c プロジェクト: KarstenHopp/vim
    void
workshop_init(void)
{
    char_u	 buf[64];
    int		 is_dirty = FALSE;
    int		 width, height;
    XtInputMask	 mask;

    /*
     * Turn on MenuBar, ToolBar, and Footer.
     */
    STRCPY(buf, p_go);
    if (vim_strchr(p_go, GO_MENUS) == NULL)
    {
	STRCAT(buf, "m");
	is_dirty = TRUE;
    }
    if (vim_strchr(p_go, GO_TOOLBAR) == NULL)
    {
	STRCAT(buf, "T");
	is_dirty = TRUE;
    }
    if (vim_strchr(p_go, GO_FOOTER) == NULL)
    {
	STRCAT(buf, "F");
	is_dirty = TRUE;
    }
    if (is_dirty)
	set_option_value((char_u *)"go", 0L, buf, 0);

    /*
     * Set size from workshop_get_width_height().
     */
    width = height = 0;
    if (workshop_get_width_height(&width, &height))
    {
	XtVaSetValues(vimShell,
		XmNwidth, width,
		XmNheight, height,
		NULL);
    }

    /*
     * Now read in the initial messages from eserve.
     */
    while ((mask = XtAppPending(app_context))
	    && (mask & XtIMAlternateInput) && !workshopInitDone)
	XtAppProcessEvent(app_context, (XtInputMask)XtIMAlternateInput);
}
コード例 #9
0
ファイル: workshop.c プロジェクト: UTSASRG/DoubleTake
    void
workshop_toolbar_end()
{
    char_u	buf[64];

#ifdef WSDEBUG_TRACE
    if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
    {
	wstrace("workshop_toolbar_end()\n");
    }
#endif

    /*
     * Turn on ToolBar.
     */
    STRCPY(buf, p_go);
    if (vim_strchr(p_go, 'T') == NULL)
    {
	STRCAT(buf, "T");
	set_option_value((char_u *)"go", 0L, buf, 0);
    }
    workshopInitDone = True;
}
コード例 #10
0
ファイル: popupmnu.c プロジェクト: applidium/Vim
/*
 * Set the index of the currently selected item.  The menu will scroll when
 * necessary.  When "n" is out of range don't scroll.
 * This may be repeated when the preview window is used:
 * "repeat" == 0: open preview window normally
 * "repeat" == 1: open preview window but don't set the size
 * "repeat" == 2: don't open preview window
 * Returns TRUE when the window was resized and the location of the popup menu
 * must be recomputed.
 */
    static int
pum_set_selected(int n, int repeat)
{
    int	    resized = FALSE;
    int	    context = pum_height / 2;

    pum_selected = n;

    if (pum_selected >= 0 && pum_selected < pum_size)
    {
	if (pum_first > pum_selected - 4)
	{
	    /* scroll down; when we did a jump it's probably a PageUp then
	     * scroll a whole page */
	    if (pum_first > pum_selected - 2)
	    {
		pum_first -= pum_height - 2;
		if (pum_first < 0)
		    pum_first = 0;
		else if (pum_first > pum_selected)
		    pum_first = pum_selected;
	    }
	    else
		pum_first = pum_selected;
	}
	else if (pum_first < pum_selected - pum_height + 5)
	{
	    /* scroll up; when we did a jump it's probably a PageDown then
	     * scroll a whole page */
	    if (pum_first < pum_selected - pum_height + 1 + 2)
	    {
		pum_first += pum_height - 2;
		if (pum_first < pum_selected - pum_height + 1)
		    pum_first = pum_selected - pum_height + 1;
	    }
	    else
		pum_first = pum_selected - pum_height + 1;
	}

	/* Give a few lines of context when possible. */
	if (context > 3)
	    context = 3;
	if (pum_height > 2)
	{
	    if (pum_first > pum_selected - context)
	    {
		/* scroll down */
		pum_first = pum_selected - context;
		if (pum_first < 0)
		    pum_first = 0;
	    }
	    else if (pum_first < pum_selected + context - pum_height + 1)
	    {
		/* scroll up */
		pum_first = pum_selected + context - pum_height + 1;
	    }
	}

#if defined(FEAT_QUICKFIX)
	/*
	 * Show extra info in the preview window if there is something and
	 * 'completeopt' contains "preview".
	 * Skip this when tried twice already.
	 * Skip this also when there is not much room.
	 * NOTE: Be very careful not to sync undo!
	 */
	if (pum_array[pum_selected].pum_info != NULL
		&& Rows > 10
		&& repeat <= 1
		&& vim_strchr(p_cot, 'p') != NULL)
	{
	    win_T	*curwin_save = curwin;
	    tabpage_T   *curtab_save = curtab;
	    int		res = OK;

	    /* Open a preview window.  3 lines by default.  Prefer
	     * 'previewheight' if set and smaller. */
	    g_do_tagpreview = 3;
	    if (p_pvh > 0 && p_pvh < g_do_tagpreview)
		g_do_tagpreview = p_pvh;
	    ++RedrawingDisabled;
	    /* Prevent undo sync here, if an autocommand syncs undo weird
	     * things can happen to the undo tree. */
	    ++no_u_sync;
	    resized = prepare_tagpreview(FALSE);
	    --no_u_sync;
	    --RedrawingDisabled;
	    g_do_tagpreview = 0;

	    if (curwin->w_p_pvw)
	    {
		if (!resized
			&& curbuf->b_nwindows == 1
			&& curbuf->b_fname == NULL
			&& curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f'
			&& curbuf->b_p_bh[0] == 'w')
		{
		    /* Already a "wipeout" buffer, make it empty. */
		    while (!BUFEMPTY())
			ml_delete((linenr_T)1, FALSE);
		}
		else
		{
		    /* Don't want to sync undo in the current buffer. */
		    ++no_u_sync;
		    res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL);
		    --no_u_sync;
		    if (res == OK)
		    {
			/* Edit a new, empty buffer. Set options for a "wipeout"
			 * buffer. */
			set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
			set_option_value((char_u *)"bt", 0L,
					       (char_u *)"nofile", OPT_LOCAL);
			set_option_value((char_u *)"bh", 0L,
						 (char_u *)"wipe", OPT_LOCAL);
			set_option_value((char_u *)"diff", 0L,
							     NULL, OPT_LOCAL);
		    }
		}
		if (res == OK)
		{
		    char_u	*p, *e;
		    linenr_T	lnum = 0;

		    for (p = pum_array[pum_selected].pum_info; *p != NUL; )
		    {
			e = vim_strchr(p, '\n');
			if (e == NULL)
			{
			    ml_append(lnum++, p, 0, FALSE);
			    break;
			}
			else
			{
			    *e = NUL;
			    ml_append(lnum++, p, (int)(e - p + 1), FALSE);
			    *e = '\n';
			    p = e + 1;
			}
		    }

		    /* Increase the height of the preview window to show the
		     * text, but no more than 'previewheight' lines. */
		    if (repeat == 0)
		    {
			if (lnum > p_pvh)
			    lnum = p_pvh;
			if (curwin->w_height < lnum)
			{
			    win_setheight((int)lnum);
			    resized = TRUE;
			}
		    }

		    curbuf->b_changed = 0;
		    curbuf->b_p_ma = FALSE;
		    curwin->w_cursor.lnum = 1;
		    curwin->w_cursor.col = 0;

		    if ((curwin != curwin_save && win_valid(curwin_save))
			    || (curtab != curtab_save
						&& valid_tabpage(curtab_save)))
		    {
			if (curtab != curtab_save && valid_tabpage(curtab_save))
			    goto_tabpage_tp(curtab_save, FALSE, FALSE);

			/* When the first completion is done and the preview
			 * window is not resized, skip the preview window's
			 * status line redrawing. */
			if (ins_compl_active() && !resized)
			    curwin->w_redr_status = FALSE;

			/* Return cursor to where we were */
			validate_cursor();
			redraw_later(SOME_VALID);

			/* When the preview window was resized we need to
			 * update the view on the buffer.  Only go back to
			 * the window when needed, otherwise it will always be
			 * redraw. */
			if (resized)
			{
			    ++no_u_sync;
			    win_enter(curwin_save, TRUE);
			    --no_u_sync;
			    update_topline();
			}

			/* Update the screen before drawing the popup menu.
			 * Enable updating the status lines. */
			pum_do_redraw = TRUE;
			update_screen(0);
			pum_do_redraw = FALSE;

			if (!resized && win_valid(curwin_save))
			{
			    ++no_u_sync;
			    win_enter(curwin_save, TRUE);
			    --no_u_sync;
			}

			/* May need to update the screen again when there are
			 * autocommands involved. */
			pum_do_redraw = TRUE;
			update_screen(0);
			pum_do_redraw = FALSE;
		    }
		}
	    }
	}
#endif
    }

    if (!resized)
	pum_redraw();

    return resized;
}
コード例 #11
0
/// Set the index of the currently selected item.  The menu will scroll when
/// necessary.  When "n" is out of range don't scroll.
/// This may be repeated when the preview window is used:
/// "repeat" == 0: open preview window normally
/// "repeat" == 1: open preview window but don't set the size
/// "repeat" == 2: don't open preview window
///
/// @param n
/// @param repeat
///
/// @returns TRUE when the window was resized and the location of the popup
/// menu must be recomputed.
static int pum_set_selected(int n, int repeat)
{
  int resized = FALSE;
  int context = pum_height / 2;

  pum_selected = n;

  if ((pum_selected >= 0) && (pum_selected < pum_size)) {
    if (pum_first > pum_selected - 4) {
      // scroll down; when we did a jump it's probably a PageUp then
      // scroll a whole page
      if (pum_first > pum_selected - 2) {
        pum_first -= pum_height - 2;
        if (pum_first < 0) {
          pum_first = 0;
        } else if (pum_first > pum_selected) {
          pum_first = pum_selected;
        }
      } else {
        pum_first = pum_selected;
      }
    } else if (pum_first < pum_selected - pum_height + 5) {
      // scroll up; when we did a jump it's probably a PageDown then
      // scroll a whole page
      if (pum_first < pum_selected - pum_height + 1 + 2) {
        pum_first += pum_height - 2;
        if (pum_first < pum_selected - pum_height + 1) {
          pum_first = pum_selected - pum_height + 1;
        }
      } else {
        pum_first = pum_selected - pum_height + 1;
      }
    }

    // Give a few lines of context when possible.
    if (context > 3) {
      context = 3;
    }

    if (pum_height > 2) {
      if (pum_first > pum_selected - context) {
        // scroll down
        pum_first = pum_selected - context;

        if (pum_first < 0) {
          pum_first = 0;
        }
      } else if (pum_first < pum_selected + context - pum_height + 1) {
        // scroll up
        pum_first = pum_selected + context - pum_height + 1;
      }
    }

    // Show extra info in the preview window if there is something and
    // 'completeopt' contains "preview".
    // Skip this when tried twice already.
    // Skip this also when there is not much room.
    // NOTE: Be very careful not to sync undo!
    if ((pum_array[pum_selected].pum_info != NULL)
        && (Rows > 10)
        && (repeat <= 1)
        && (vim_strchr(p_cot, 'p') != NULL)) {
      win_T *curwin_save = curwin;
      int res = OK;

      // Open a preview window.  3 lines by default.  Prefer
      // 'previewheight' if set and smaller.
      g_do_tagpreview = 3;

      if ((p_pvh > 0) && (p_pvh < g_do_tagpreview)) {
        g_do_tagpreview = p_pvh;
      }
      resized = prepare_tagpreview(false);
      g_do_tagpreview = 0;

      if (curwin->w_p_pvw) {
        if ((curbuf->b_fname == NULL)
            && (curbuf->b_p_bt[0] == 'n')
            && (curbuf->b_p_bt[2] == 'f')
            && (curbuf->b_p_bh[0] == 'w')) {
          // Already a "wipeout" buffer, make it empty.
          while (!bufempty()) {
            ml_delete((linenr_T)1, FALSE);
          }
        } else {
          // Don't want to sync undo in the current buffer.
          no_u_sync++;
          res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL);
          no_u_sync--;

          if (res == OK) {
            // Edit a new, empty buffer. Set options for a "wipeout"
            // buffer.
            set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
            set_option_value((char_u *)"bt", 0L,
                             (char_u *)"nofile", OPT_LOCAL);
            set_option_value((char_u *)"bh", 0L,
                             (char_u *)"wipe", OPT_LOCAL);
            set_option_value((char_u *)"diff", 0L,
                             NULL, OPT_LOCAL);
          }
        }

        if (res == OK) {
          char_u *p, *e;
          linenr_T lnum = 0;

          for (p = pum_array[pum_selected].pum_info; *p != NUL;) {
            e = vim_strchr(p, '\n');
            if (e == NULL) {
              ml_append(lnum++, p, 0, FALSE);
              break;
            } else {
              *e = NUL;
              ml_append(lnum++, p, (int)(e - p + 1), FALSE);
              *e = '\n';
              p = e + 1;
            }
          }

          // Increase the height of the preview window to show the
          // text, but no more than 'previewheight' lines.
          if (repeat == 0) {
            if (lnum > p_pvh) {
              lnum = p_pvh;
            }

            if (curwin->w_height < lnum) {
              win_setheight((int)lnum);
              resized = TRUE;
            }
          }

          curbuf->b_changed = 0;
          curbuf->b_p_ma = FALSE;
          curwin->w_cursor.lnum = 1;
          curwin->w_cursor.col = 0;

          if ((curwin != curwin_save) && win_valid(curwin_save)) {
            // Return cursor to where we were
            validate_cursor();
            redraw_later(SOME_VALID);

            // When the preview window was resized we need to
            // update the view on the buffer.  Only go back to
            // the window when needed, otherwise it will always be
            // redraw.
            if (resized) {
              win_enter(curwin_save, true);
              update_topline();
            }

            // Update the screen before drawing the popup menu.
            // Enable updating the status lines.
            pum_do_redraw = TRUE;
            update_screen(0);
            pum_do_redraw = FALSE;

            if (!resized && win_valid(curwin_save)) {
              win_enter(curwin_save, true);
            }

            // May need to update the screen again when there are
            // autocommands involved.
            pum_do_redraw = TRUE;
            update_screen(0);
            pum_do_redraw = FALSE;
          }
        }
      }
    }
  }

  if (!resized) {
    pum_redraw();
  }

  return resized;
}
コード例 #12
0
ファイル: boot_cfg.c プロジェクト: kisom/pmon
int menu_list_read(ExecId id, int fd, int flags)
{
	int j;//index for current menu item.
	char buf[1025];
	char buf_bak[1025];
	int buflen = 1024;
	int n = 0;
	char* cp = NULL;
	char option[OPTION_LEN] = {0};
	char value[VALUE_LEN] = {0};
	int in_menu = 0;
	char title [MENU_TITLE_BUF_LEN + 1];//Title of menu item, display on screen.
	
	for (j = 0; j < MAXARGS; j++)
	{
		memset (menu_items + j, 0, sizeof(menu_items[j]));
	//	memset (menu_items[j].title, 0, MENU_TITLE_BUF_LEN + 1 );
	}
	
	j = -1; //set to 0;
	n = 0;
	while (ReadLine(id, fd, buf, buflen) > 0)//Read a line.
	{
		memset(title,0, MENU_TITLE_BUF_LEN + 1 );
		n++;

		strcpy(buf_bak, buf);//Got a copy of buf.
		cp = trim(buf);//Trim space
		if (*cp == '\0' || *cp == '#')//If only a empty line,or comment line, drop it.
		{
			continue;
		}
		
		//Check data, looking for menu title.
		if( GetTitle (cp, title, MENU_TITLE_BUF_LEN ) == 0) 
		{
			j++;
			strncpy (menu_items[j].title, title, MENU_TITLE_BUF_LEN);//storage it.
			if(menu_items[j].kernel == NULL)
			{
				menu_items[j].kernel = malloc (VALUE_LEN + 1);
				menu_items[j].args = malloc (VALUE_LEN + 1);
				menu_items[j].initrd = malloc (VALUE_LEN + 1);
				menu_items[j].root = malloc (VALUE_LEN + 1);
				menu_items[j].recovery= malloc (VALUE_LEN + 1);
			}
			memset (menu_items[j].kernel, 0, VALUE_LEN + 1);
			memset (menu_items[j].args, 0, VALUE_LEN + 1);
			memset (menu_items[j].initrd, 0, VALUE_LEN + 1);
			memset (menu_items[j].root, 0, VALUE_LEN + 1);
			memset (menu_items[j].recovery, 0, VALUE_LEN + 1);
			in_menu = 1;
			continue;
		}

		cp = trim(buf_bak);
		if( in_menu )
		{	
			//Read all properties of current menu item.
			if( GetOption (cp,option,OPTION_LEN,value,VALUE_LEN) == 0 )
			{
				if( strcasecmp (option,"kernel") == 0 ) // got kernel property
				{
					if( menu_items[j].kernel != NULL && menu_items[j].kernel[0] == '\0') // we only sotr the firs kernel property, drop others.
						strncpy(menu_items[j].kernel,value,VALUE_LEN);
				}
				else if( strcasecmp (option,"args") == 0 )// got kernel arguments property.
				{
					if( menu_items[j].args != NULL && menu_items[j].args[0] == '\0')//same as the kernel property.
						strncpy(menu_items[j].args,value,VALUE_LEN);
				}
				else if( strcasecmp (option,"initrd") == 0 )// go initrd kernel arguments property, may be null.
				{
					if( menu_items[j].initrd!= NULL && menu_items[j].initrd[0] == '\0')// same as the kernel property.
						strncpy(menu_items[j].initrd,value,VALUE_LEN);
				}
				else if (strcasecmp(option, "root") == 0)
				{
					if (menu_items[j].root != NULL && menu_items[j].root[0] == '\0')
					{
						strncpy(menu_items[j].root, value, VALUE_LEN);
					}
				}
                else if (strcasecmp(option, "recovery") == 0)
                {
                    /*this is not recovery item,or recovery item not used*/
                    if (((bootcfg_flags & U_KEY_PRESSED) != U_KEY_PRESSED)
                        &&(value[0] == '0'))
                    {
                        free(menu_items[j].kernel);
                        free(menu_items[j].args);
                        free(menu_items[j].initrd);
                        free(menu_items[j].root);
                        free(menu_items[j].recovery);
		                memset (menu_items + j, 0, sizeof(menu_items[j]));
                        j--;
                    }
                }
				//drop other property.
			}
		}
		else // out of menu item.
		{
			//Check data, looking for global option.
			if( GetOption (cp,option,OPTION_LEN,value,VALUE_LEN) == 0 )
			{
				set_option_value(option, value);//storage it.
			}
		}
	}
	menus_num = j + 1;
	return menus_num > 0 ? 0 : -1;
}
コード例 #13
0
/**
 * @brief Loads the values from the configuration file into the menu.
 */
void SelectionMenuOptions::load_configuration() {
  
  // compute the list of languages and set the current one
  std::map<std::string, std::string> language_names = FileTools::get_languages();
  const std::string &current_language_code = Configuration::get_value("language", FileTools::get_default_language());
  nb_values[0] = language_names.size();
  all_values[0] = new std::string[nb_values[0]];
  language_codes = new std::string[nb_values[0]];
  std::map<std::string, std::string>::iterator it;
  int i = 0;
  for (it = language_names.begin(); it != language_names.end(); it++) {
    language_codes[i] = it->first;
    all_values[0][i] = it->second;

    if (language_codes[i] == current_language_code) {
      current_indices[0] = i;
      set_option_value(0, i);
    }
    i++;
  }

  // video mode
  nb_values[1] = VideoManager::NB_MODES;
  all_values[1] = new std::string[nb_values[1]];
  for (int i = 0; i < nb_values[1]; i++) {
    std::ostringstream oss;
    oss << "options.video_mode_" << i;
    all_values[1][i] = StringResource::get_string(oss.str());

    if (i == VideoManager::get_instance()->get_video_mode()) {
      current_indices[1] = i;
      set_option_value(1, i);
    }
  }

  // music volume
  int volume = Music::get_volume();
  if (volume % 10 != 0) {
    // make sure the volume is a multiple of 10
    volume = (volume + 5) / 10 * 10;
    Music::set_volume(volume);
  }
  nb_values[2] = 11;
  all_values[2] = new std::string[nb_values[2]];
  for (int i = 0; i < nb_values[2]; i++) {
    volume = i * 10;
    std::ostringstream oss;
    oss << volume << " %";
    all_values[2][i] = oss.str();

    if (volume == Music::get_volume()) {
      current_indices[2] = i;
      set_option_value(2, i);
    }
  }

  // sound volume
  volume = Sound::get_volume();
  if (volume % 10 != 0) {
    // make sure the volume is a multiple of 10
    volume = (volume + 5) / 10 * 10;
    Sound::set_volume(volume);
  }
  nb_values[3] = 11;
  all_values[3] = new std::string[nb_values[3]];
  for (int i = 0; i < nb_values[3]; i++) {
    volume = i * 10;
    std::ostringstream oss;
    oss << volume << " %";
    all_values[3][i] = oss.str();

    if (volume == Sound::get_volume()) {
      current_indices[3] = i;
      set_option_value(3, i);
    }
  }
}
コード例 #14
0
/**
 * @brief For the selected option, sets the value at the specified index.
 * @param index index of the value to set for the current option
 */
void SelectionMenuOptions::set_option_value(int index) {
  set_option_value(cursor_position, index);
}