ok this is it. basically i read something from stdin, make a hash of it and store that hash + the name inside a node. if i insert "h" then i dont want to hash the "h" but instead just print the history of hashes.
Code:
int main(int argc, char** argv)
{
char in[ASAP_BUFSIZE];
printf("**ASAP SHELL**\n>");
hashnode_t head;
hashnode_t *current = &head;
while (TRUE){
in[0] = '\0'; //reset buffer
if (fgets(in, ASAP_BUFSIZE, stdin) == NULL){
continue;
}
int length = strlen(in);
in[length-1] = '\0'; //delete newline from input
if (length == ASAP_BUFSIZE - 1){
printf("damn: buffer too small\n>");
continue;
}
if (strcmp(in, CMD_HISTORY) == 0){
print_history(&head);
continue;
}
char *in_copy = (char *) malloc((length + 1)*sizeof(char));
strcpy(in_copy, in);
current->filename = in_copy;
sha1_from_file(in, current->md);
current->next = (hashnode_t *) malloc(sizeof(hashnode_t)); //create next element
printf("malloc\n");
current = current->next;
printf(">");
}
}