~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to eat_right_char.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                eat_right_char.c
 
6
 
 
7
Purpose:
 
8
        Eat right character. Copy the command line to the history buffer.
 
9
 
 
10
Input:
 
11
        (1) Pointer to RuntimeS structure.
 
12
 
 
13
Output:
 
14
        (1) One character removed.
 
15
        (2) Return value.
 
16
 
 
17
Return value:
 
18
        (1) Positive on success.
 
19
        (2) Negative on failure.
 
20
 
 
21
========includes:============================================================*/
 
22
 
 
23
#include <stdio.h>
 
24
 
 
25
#include <string.h>
 
26
 
 
27
#include <X11/Xlib.h>
 
28
#include <X11/Xutil.h>
 
29
#include <X11/Xos.h>
 
30
#include <X11/Xatom.h>
 
31
 
 
32
#include "defines.h"
 
33
#include "typedefs.h"
 
34
 
 
35
/*======eat right character:=================================================*/
 
36
 
 
37
int EatRightChar_ (RuntimeS *runtimeSP)
 
38
{
 
39
int                     comm_length, old_comm_length, carriage_pos;
 
40
char                    stringA[COMMSTRINGSIZE];
 
41
char                    *currP;
 
42
 
 
43
/* Copy the command string length and carriage (keyboard cursor) position: */
 
44
comm_length = runtimeSP->command_length;
 
45
old_comm_length = comm_length;
 
46
carriage_pos = runtimeSP->carriage_position;
 
47
 
 
48
/* Check is there anything on the right side: */
 
49
if (carriage_pos >= comm_length) return -1;
 
50
 
 
51
/* Reduce the command length: */
 
52
comm_length--;
 
53
 
 
54
/* Copy the left part: */
 
55
strncpy (stringA, runtimeSP->curr_commandA, carriage_pos);
 
56
stringA[carriage_pos] = '\0';
 
57
 
 
58
/* Copy the right part, but skip the first character: */
 
59
strncat (stringA,
 
60
         runtimeSP->curr_commandA + carriage_pos + 1,
 
61
         old_comm_length - carriage_pos - 1);
 
62
 
 
63
/* Ensure the proper termination: */
 
64
stringA[comm_length] = '\0';
 
65
 
 
66
/* Copy the command string: */
 
67
strcpy (runtimeSP->curr_commandA, stringA);
 
68
 
 
69
/* Set the command length: */
 
70
runtimeSP->command_length = comm_length;
 
71
 
 
72
/* Copy the command string to the output buffer: */
 
73
currP = runtimeSP->commandsP + runtimeSP->curr_commandI * COMMSTRINGSIZE;
 
74
strcpy (currP, runtimeSP->curr_commandA);
 
75
 
 
76
/* Return positive value (success): */
 
77
return 1;
 
78
}
 
79
 
 
80
/*===========================================================================*/
 
81
 
 
82