⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bibtool.c

📁 bibtool 是一个简单的基于curses的编辑
💻 C
📖 第 1 页 / 共 4 页
字号:
      case '1' : field_name = "ADDRESS"; lfield_name="address"; break;      case '2' : field_name = "ANNOTE"; lfield_name="annote"; break;      case '3' : field_name = "AUTHOR"; lfield_name="author"; break;      case '4' : field_name = "BOOKTITLE"; lfield_name="booktitle";break;      case '5' : field_name = "CHAPTER"; lfield_name="chapter";break;      case '6' : field_name = "CROSSREF"; lfield_name="crossref";break;      case '7' : field_name = "EDITION"; lfield_name="edition";break;      case '8' : field_name = "EDITOR"; lfield_name="editor";break;      case '9' : field_name = "HOWPUBLISHED";lfield_name="howpublished";break;      case 'A' : field_name = "INSTITUTION";lfield_name="institution";break;      case 'B' : field_name = "JOURNAL";lfield_name="journal";break;      case 'C' : field_name = "KEY";lfield_name="key";break;      case 'D' : field_name = "MONTH";lfield_name="month";break;      case 'E' : field_name = "NOTE";lfield_name="note";break;      case 'F' : field_name = "NUMBER";lfield_name="number";break;      case 'G' : field_name = "ORGANIZATION";lfield_name="organization";break;      case 'H' : field_name = "PAGES"; lfield_name = "pages";break;      case 'I' : field_name = "PUBLISHER";lfield_name = "publisher";break;      case 'J' : field_name = "SCHOOL";lfield_name="school";break;      case 'K' : field_name = "SERIES";lfield_name="series";break;      case 'L' : field_name = "TITLE"; lfield_name="title"; break;      case 'M' : field_name = "TYPE"; lfield_name="type";break;      case 'N' : field_name = "VOLUME"; lfield_name="volume";break;      case 'O' : field_name = "YEAR";lfield_name = "year"; break;      default: return(0); break;    }   setup_screen();   move(4,5);   printw("%s %s %s","Enter data for",lfield_name,"and press return to finish");   move(5,5);   printw("%s","To delete the field, just press return");   move(7,1);   refresh();   nocbreak();   getstr(field_data);   fin = fopen(bibfile,"r");   if (fin == NULL) return(0);   fout = fopen("bibtool_tmp.out","w");   if (fout == NULL)    {      endwin();      perror("Couldn't open temp output file ");      exit(1);    }   while((fgets(str, 99, fin)) > 0)    {      if (strchr(str, '@') != NULL)       {         if (strchr(str,'{') != NULL)            key_name = (strchr(str,'{')+1);         else            key_name = (strchr(str,'(')+1);         /* This is a record */         if (strstr(key_name, entry_name) != NULL)          {            /* This is the right record */            fputs(str,fout);            if (strlen(field_data) > 0)               fprintf(fout,"  %s={%s},\n",field_name,field_data);            in_record = 1;            changed_field = 1;          }         else          {            fputs(str,fout);            in_record = 0;          }       }      else       {         /* Make sure we don't write the new field we've just replaced */         if (in_record == 1)          {            if (strstr(str,field_name) == NULL)             {               if (strstr(str,lfield_name) == NULL)                  fputs(str,fout);             }          }         else            fputs(str,fout);       }    }   fclose(fin);   fclose(fout);   strcpy(out_string, "cp ");   strcat(out_string, bibfile);   strcat(out_string, " bibfile.old");   system(out_string);   strcpy(out_string, "mv bibtool_tmp.out ");   strcat(out_string, bibfile);   system(out_string);   move(10,5);   if (changed_field == 1)      printw("%s","Change made - press a key");   else      printw("%s","No changes made - press a key");     refresh();   cbreak();   ch = getch();  }server_menu() {   /* For use in bibcursed */ }beautify() {   /* For use in bibcursed */ }search_file(int what) {   /* Search the file using the supplied option */   char search_term[100];   char *key_name;   char str[100], str2[100];   char ch;   char *search_type, *search_type2;   FILE *fin;   int print_pos = 6;   int entries_found = 0;   int author_found;   int total_entries = 0;   int every = 0;   setup_screen();   move(4,5);   printw("%s", "Please enter ");   switch(what)    {      case 1 : printw("%s","author surname "); search_type = "AUTHOR";                search_type2 = "author"; break;      case 2 : printw("%s","principle author surname "); search_type =               "AUTHOR"; search_type2 = "author"; break;      case 3 : printw("%s","surname of author to link to ");               search_type="AUTHOR"; search_type2 = "author"; break;      case 4 : printw("%s","title (or partial title) "); search_type = "TITLE";               search_type2 = "title"; break;      case 5 : printw("%s","conference or journal name "); search_type =                "JOURNAL"; search_type2 = "journal"; break;      case 6 : printw("%s","name of university or institution ");                search_type = "SCHOOL"; search_type2 = "school"; break;      case 7 : printw("%s","year "); search_type = "YEAR";                search_type2 = "year"; break;      case 8 : printw("%s","keyword "); search_type2 = "all"; every = 1; break;      case 9 : printw("%s","name of organisation ");               search_type = "ORGANIZATION"; search_type2="organization"; break;      default : printw("%s","nothing (error)\n"); search_menu(); break;    }   printf("for search : ");   refresh();   getstr(search_term);   setup_screen();   move(4,5);   printw("%s","Searching for ");   attron(A_BOLD);   printw("%s", search_term);   attroff(A_BOLD);   refresh();   fin = fopen(bibfile, "r");   if (fin == NULL)    {      perror("Cant open BibTeX file ");      exit(1);    }   while ((fgets(str, 99, fin)) > 0)    {      author_found = 0;      if (strchr(str, '@') != NULL)       {         if (strchr(str, '{') != NULL)          {            key_name = (strchr(str, '{') + 1);          }         else          {            key_name = (strchr(str, '(') + 1);          }         while (author_found == 0)          {            if (fgets(str2, 99, fin) == NULL) break;            if ((strstr(str2, search_type) != NULL) || (strstr(str2, search_type2)               != NULL) || every == 1)             {               if (strstr(str2, search_term) != NULL)                {                  move(print_pos,5);                  printw("%s", key_name);                  move(print_pos+1, 8);                  printw("%s", str2);                  print_pos = print_pos + 2;                  entries_found++;                  total_entries++;                  if (entries_found == 5)                   {                     move(print_pos+1,5);                     printw("%s","Press any key for more results");                     refresh();                     cbreak();                     ch = getch();                     entries_found = 0;                     print_pos = 6;                     clear();                     setup_screen();                   }                  refresh();                }               author_found = 1;             }          }       }    }   fclose(fin);   move(print_pos+1,5);   printw("%s %d %s","That's it -", total_entries, "match. Press any key");   refresh();   cbreak();   ch = getch(); }void add_bold(char letter) {   /* Add the supplied char in bold to the current position */   attron(A_BOLD);   addch(letter);   attroff(A_BOLD); }search_menu() {   /* Display the first search menu */   int ch, lch, type;   setup_screen();   move(4,5);   printw("Search by :");   move(6,8);   add_bold('A');   printw("uthor");   move(7,8);   add_bold('P');   printw("%s","rinciple author only");   move(8,8);   add_bold('L');   printw("%s","inked authors");   move(9,8);   add_bold('T');   printw("%s","itle");   move(10,8);   add_bold('J');   printw("%s","ournal or conference title");   move(11,8);   add_bold('U');   printw("%s","niversity or institution (for thesis)");   move(12,8);   add_bold('O');   printw("%s","rganisation (for proceedings etc)");   move(13,8);   add_bold('Y');   printw("%s","ear");   move(14,8);   add_bold('E');   printw("%s","verything (keyword for all fields)");   move(15,8);   add_bold('Q');   printw("%s","uit and return to main menu");   move(17,8);   printw("What now? ");   refresh();   cbreak();   ch = getch();   lch = tolower(ch);   switch(lch)    {      case 'a' : search_file(1); break;      case 'p' : search_file(2); break;      case 'l' : search_file(3); break;      case 't' : search_file(4); break;      case 'j' : search_file(5); break;      case 'u' : search_file(6); break;      case 'y' : search_file(7); break;      case 'e' : search_file(8); break;      case 'o' : search_file(9); break;      case 'q' : return(0); break;      default : menu(); break ;    } }quit_prog() {   endwin();   exit(0); }main(int argc, char *argv[]) {   int ch, i;   char str[100];   FILE *fin;   printf("Bibtool 1.7 (c)1999,2000 Dominic Tristram. GPL applies\n");   sleep(1);   if (argc != 2)    {      printf("%s requires a BibTeX file as its argument\n", argv[0]);      exit(1);    }   strcpy(bibfile, argv[1]);   fin = fopen(bibfile, "r");   if (fin == NULL)    {      printf("Can't open %s for reading\n", bibfile);      exit(1);    }   while ((fgets(str, 10, fin)) > 0)    {      if (str[0] == '@') rec_count++;    }   printf("There are %d BibTeX entries in %s\n", rec_count, argv[1]);   fclose(fin);   initscr();   while (1 != 0)      menu(); }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -