void wrd_init_path(void) { StringTableNode *p; delete_string_table(&path_list); for(p = default_path_list.head; p; p = p->next) wrd_add_path_one(p->string, strlen(p->string)); if(current_file_info) { if(strchr(current_file_info->filename, '#') != NULL) wrd_add_path_one(current_file_info->filename, strchr(current_file_info->filename, '#') - current_file_info->filename + 1); if(pathsep_strrchr(current_file_info->filename) != NULL) wrd_add_path_one(current_file_info->filename, pathsep_strrchr(current_file_info->filename) - current_file_info->filename + 1); } }
void free_wrd(void) { delete_string_table(&path_list); }
int main() { int ch, x, y; char fname[80]; FILE *fp; bool entering_metadata = false; char to_delete; char existing; initscr(); cbreak(); noecho(); nonl(); intrflush(stdscr, false); keypad(stdscr, true); /* Enable arrow keys. */ getmaxyx(stdscr, ROW, COL); move(0,0); start_color(); /* Yay colors! */ init_pair(1, COLOR_RED, COLOR_WHITE); // attron(COLOR_PAIR(1)); // printw("rows: %d, columns: %d\n", ROW, COL); char** contents = new_string_table(ROW, COL); char* blank_row = (char*)malloc(COL*sizeof(char)); for (int i=0; i<COL; i++) { blank_row[i] = ' '; } getyx(stdscr, y, x); while (true) { ch = getch(); switch (ch) { case KEY_LEFT: x -= 1; break; case KEY_RIGHT: x += 1; break; case KEY_UP: y -= 1; break; case KEY_DOWN: y += 1; break; case BACKSPACE: /* KEY_BACKSPACE wasn't working. */ --x; move(y, x); to_delete = inch(); attron(COLOR_PAIR(1)); addch(to_delete); attroff(COLOR_PAIR(1)); break; case KEY_DC: //attron(COLOR_PAIR(1)); addch('X'); //attroff(COLOR_PAIR(1)); break; case ESC: ch = getch(); switch (ch) { case ESC: /* Press ESC twice to exit. */ endwin(); free(blank_row); delete_string_table(contents, ROW); return 0; break; case 'w': move(ROW-1, 0); printw("Enter a file name (up to 80 characters): "); echo(); if (getnstr(fname, 80) == ERR) { perror("Something went wrong reading the file name you gave."); } noecho(); fp = fopen(fname, "w"); if (fp == NULL) { perror("Cannot open file"); } contents_to_file(contents, fp, ROW, COL); fclose(fp); move(ROW-1, 0); printw(blank_row); break; default: break; } break; default: existing = contents[y][x]; //printw("%d", (int)existing); if (existing == '\0') { addch(ch); ensureposition(&y, &x); contents[y][x] = ch; ++x; } //getyx(stdscr, y, x); break; } ensureposition(&y, &x); move(y, x); } }