Advertisement
codemonkey

builtins/history.h

Oct 13th, 2011
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. #ifndef HISTORY
  2. #define HISTORY
  3.  
  4. /*
  5.  * ================ *
  6.  * === Includes === *
  7.  * ================ *
  8.  */
  9.  
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. /*
  15.  * =================== *
  16.  * === Definitions === *
  17.  * =================== *
  18.  */
  19.  
  20. #define BLOCKS 64
  21. #define BLOCK_SIZE 8
  22.  
  23. /*
  24.  * ==============
  25.  * === Macros ===
  26.  * ==============
  27.  */
  28.  
  29. // Shortcut for the number of commands in history
  30. #define h_len() h_meta_len
  31.  
  32. /*
  33.  * ===============
  34.  * === Typedef ===
  35.  * ===============
  36.  */
  37.  
  38. // A struct to represent the meta blocks of this command history management
  39. // module
  40. typedef struct h_metablock_str
  41. {
  42.     // Contains a pointer to the next block
  43.     struct h_metablock_str* next;
  44.  
  45.     // Contains the length of the command
  46.     int length;
  47.  
  48.     // Contains the indices of the data in the bitmap and data structure
  49.     int dataindex[15];
  50. } h_metablock;
  51.  
  52. /*
  53.  * =============== *
  54.  * === Globals === *
  55.  * =============== *
  56.  */
  57.  
  58. short h_bitmap[BLOCKS]; // This is the bitmap
  59. char h_data[BLOCKS][BLOCK_SIZE]; // This is the block of data
  60.  
  61. // h_meta is the pointer to the first meta-block
  62. h_metablock* h_meta = NULL;
  63. int h_meta_len = 0;
  64.  
  65. /*
  66.  * ================= *
  67.  * === Functions === *
  68.  * ================= *
  69.  */
  70.  
  71. /*
  72.  * Add the input params to input history
  73.  */
  74. void h_add(char** param);
  75.  
  76. /*
  77.  * Allocate space in the data blocks for the input amount of blocks
  78.  */
  79. int* h_allocate(int blocks);
  80.  
  81. /*
  82.  * Remove the oldest command in history
  83.  */
  84. void h_removeoldest();
  85.  
  86. /*
  87.  * Reconstructs and returns the string for the input meta block
  88.  */
  89. char* h_meta_getcmd(h_metablock* metablock);
  90.  
  91. /*
  92.  * Calls h_meta_getcmd on the nth newest command in history and returns the
  93.  * result
  94.  */
  95. char* h_cmd_index(int index);
  96.  
  97. /*
  98.  * Free all resources allocated by the history module
  99.  */
  100. void h_free();
  101.  
  102. #endif
  103.  
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement