Sys.Signals module for a Variant type of signals (and a set_signal function that...
[ocaml.git] / win32caml / history.c
blob11397ac66aceed8185ba71ce8ffbacf324c02035
1 /***********************************************************************/
2 /* */
3 /* Objective Caml */
4 /* */
5 /* Jacob Navia, after Xavier Leroy */
6 /* */
7 /* Copyright 2001 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../LICENSE. */
11 /* */
12 /***********************************************************************/
14 /***********************************************************************/
15 /* Changes made by Chris Watford to enhance the source editor */
16 /* Began 14 Sept 2003 - watford@uiuc.edu */
17 /***********************************************************************/
19 #include "inria.h"
20 #include "history.h"
22 /*------------------------------------------------------------------------
23 Procedure: AddToHistory ID:2
24 Author: Chris Watford watford@uiuc.edu
25 Purpose: Adds an edit buffer to the history control
26 Input: Pointer to the edit buffer to add
27 Output:
28 Errors:
29 --------------------------------------------------------------------------
30 Edit History:
31 15 Sept 2003 - Chris Watford watford@uiuc.edu
32 - Complete rewrite
33 - Got it to add the edit buffer to the history
34 17 Sept 2003 - Chris Watford watford@uiuc.edu
35 - Added doubly link list support
36 ------------------------------------------------------------------------*/
37 void AddToHistory(EditBuffer *edBuf)
39 StatementHistory *newLine;
41 // sanity checks
42 if(edBuf == NULL)
44 return;
45 } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) {
46 // fix any possible errors that may come from this
47 edBuf->LineCount = 0;
48 edBuf->Lines = NULL;
49 return;
52 // setup newline and add as the front of the linked list
53 newLine = SafeMalloc(sizeof(StatementHistory));
54 newLine->Next = History;
55 newLine->Prev = NULL;
56 newLine->Statement = edBuf;
58 // setup back linking
59 if(History != NULL)
60 History->Prev = newLine;
62 // set the history up
63 History = newLine;
65 // search for the new history tail
66 for(HistoryTail = (HistoryTail != NULL ? HistoryTail : History); HistoryTail->Next != NULL; HistoryTail = HistoryTail->Next);
69 /*------------------------------------------------------------------------
70 Procedure: GetHistoryLine ID:2
71 Author: Chris Watford watford@uiuc.edu
72 Purpose: Returns an entry from the history table
73 Input: Index of the history entry to return
74 Output: The history entry as a single line
75 Errors:
76 --------------------------------------------------------------------------
77 Edit History:
78 15 Sept 2003 - Chris Watford watford@uiuc.edu
79 - Complete rewrite
80 17 Sept 2003 - Chris Watford watford@uiuc.edu
81 - Added doubly link list support
82 ------------------------------------------------------------------------*/
83 char *GetHistoryLine(int n)
85 StatementHistory *histentry = History;
86 int i;
88 // traverse linked list looking for member n
89 for (i = 0; ((i < n) && (histentry != NULL)); i++, histentry = histentry->Next);
91 // figure out what to return
92 if (histentry != NULL)
94 return editbuffer_getasline(histentry->Statement);
95 } else {
96 return "";