File: eat_right_char.c

package info (click to toggle)
garlic 1.5-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,324 kB
  • ctags: 1,378
  • sloc: ansic: 50,306; makefile: 1,088
file content (82 lines) | stat: -rw-r--r-- 1,997 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

				eat_right_char.c

Purpose:
	Eat right character. Copy the command line to the history buffer.

Input:
	(1) Pointer to RuntimeS structure.

Output:
	(1) One character removed.
	(2) Return value.

Return value:
	(1) Positive on success.
	(2) Negative on failure.

========includes:============================================================*/

#include <stdio.h>

#include <string.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======eat right character:=================================================*/

int EatRightChar_ (RuntimeS *runtimeSP)
{
int			comm_length, old_comm_length, carriage_pos;
char			stringA[COMMSTRINGSIZE];
char			*currP;

/* Copy the command string length and carriage (keyboard cursor) position: */
comm_length = runtimeSP->command_length;
old_comm_length = comm_length;
carriage_pos = runtimeSP->carriage_position;

/* Check is there anything on the right side: */
if (carriage_pos >= comm_length) return -1;

/* Reduce the command length: */
comm_length--;

/* Copy the left part: */
strncpy (stringA, runtimeSP->curr_commandA, carriage_pos);
stringA[carriage_pos] = '\0';

/* Copy the right part, but skip the first character: */
strncat (stringA,
	 runtimeSP->curr_commandA + carriage_pos + 1,
	 old_comm_length - carriage_pos - 1);

/* Ensure the proper termination: */
stringA[comm_length] = '\0';

/* Copy the command string: */
strcpy (runtimeSP->curr_commandA, stringA);

/* Set the command length: */
runtimeSP->command_length = comm_length;

/* Copy the command string to the output buffer: */
currP = runtimeSP->commandsP + runtimeSP->next_commandI * COMMSTRINGSIZE;
strcpy (currP, runtimeSP->curr_commandA);

/* Return positive value (success): */
return 1;
}

/*===========================================================================*/