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

📄 bibtool.c

📁 bibtool 是一个简单的基于curses的编辑
💻 C
📖 第 1 页 / 共 4 页
字号:
               if (set_howpublished == 1)                  fprintf(fout,",\n  HOWPUBLISHED={%s}", howpublished);               if (set_month == 1)                  fprintf(fout,",\n  MONTH={%s}", month);               if (set_year == 1)                  fprintf(fout,",\n  YEAR={%s}", year);               if (set_annote == 1)                  fprintf(fout,",\n  ANNOTE={%s}",annote);               if (set_note == 1)                  fprintf(fout,",\n  NOTE={%s}", note);               fprintf(fout,"\n }\n\n");               written_new = 1;               rec_count++;             }          }       }      /* Write the input line to the output file */      fputs(str, fout);    }   if (entry_count == 0)    {      /* This is a bit of a hack. This function adds the new record when it	 comes accross a record that comes after it. If the new record comes	 after all the present ones, or the bibfile is empty, it won't	 work. This bit of code writes the new record at the end of the	 file if no other records were found */      switch (entry_type)       {         case '1' :            fprintf(fout, "@article{%s", entry_name); break;         case '2' :            fprintf(fout,"@book{%s", entry_name); break;         case '3' :            fprintf(fout,"@booklet{%s", entry_name); break;         case '4' :            fprintf(fout,"@inproceedings{%s", entry_name);            break;         case '5' :            fprintf(fout,"@inbook{%s", entry_name); break;         case '6' :            fprintf(fout,"@incollection{%s", entry_name); break;         case '7' :            fprintf(fout,"@manual{%s", entry_name); break;         case '8' :            fprintf(fout,"@mastersthesis{%s", entry_name); break;         case '9' :            fprintf(fout,"@misc{%s", entry_name); break;         case 'a' :            fprintf(fout,"@phdthesis{%s", entry_name); break;         case 'b' :            fprintf(fout,"@proceedings{%s", entry_name); break;         case 'c' :            fprintf(fout,"@techreport{%s", entry_name); break;         case 'd' :            fprintf(fout,"@unpublished{%s", entry_name); break;         default : break;       }      if (set_key == 1)         fprintf(fout,",\n  KEY={%s}", key);      if (set_crossref == 1)         fprintf(fout,",\n  CROSSREF={%s}", crossref);      if (set_author == 1)         fprintf(fout,",\n  AUTHOR={%s}",author);      if (set_title == 1)         fprintf(fout,",\n  TITLE={%s}",title);      if (set_booktitle == 1)         fprintf(fout,",\n  BOOKTITLE={%s}", booktitle);      if (set_journal == 1)         fprintf(fout,",\n  JOURNAL={%s}", journal);      if (set_series == 1)         fprintf(fout,",\n  SERIES={%s}", series);      if (set_edition == 1)         fprintf(fout,",\n  EDITION={%s}", edition);      if (set_volume == 1)         fprintf(fout,",\n  VOLUME={%s}", volume);      if (set_number == 1)         fprintf(fout,",\n  NUMBER={%s}", number);      if (set_type == 1)         fprintf(fout,",\n  TYPE={%s}", type);      if (set_chapter == 1)         fprintf(fout,",\n  CHAPTER={%s}", chapter);      if (set_pages == 1)         fprintf(fout,",\n  PAGES={%s}", pages);      if (set_editor == 1)         fprintf(fout,",\n  EDITOR={%s}", editor);      if (set_institution == 1)         fprintf(fout,",\n  INSTITUTION={%s}", institution);      if (set_organisation == 1)         fprintf(fout,",\n  ORGANIZATION={%s}", organisation);      if (set_school == 1)         fprintf(fout,",\n  SCHOOL={%s}", school);      if (set_publisher == 1)         fprintf(fout,",\n  PUBLISHER={%s}", publisher);      if (set_address == 1)         fprintf(fout,",\n  ADDRESS={%s}",address);      if (set_howpublished == 1)         fprintf(fout,",\n  HOWPUBLISHED={%s}", howpublished);      if (set_month == 1)         fprintf(fout,",\n  MONTH={%s}", month);      if (set_year == 1)         fprintf(fout,",\n  YEAR={%s}", year);      if (set_annote == 1)         fprintf(fout,",\n  ANNOTE={%s}",annote);      if (set_note == 1)         fprintf(fout,",\n  NOTE={%s}", note);      fprintf(fout,"\n }\n\n");      written_new = 3;      rec_count++;    }   fclose(fin);   fclose(fout);   /* Rename the original bibTeX file to bibfile.old */   strcpy(out_string, "cp ");   strcat(out_string, bibfile);   strcat(out_string, " bibfile.old");   system(out_string);   /* Rename the output from bibtool_tmp.out to the original filename */   strcpy(out_string, "mv bibtool_tmp.out ");   strcat(out_string, bibfile);   system(out_string);   /* Report on success or otherwise */   move(7,5);   switch(written_new)    {      case 0 : printw("%s","No new entry was written. Press any key"); break;      case 1 : printw("%s","New entry was successfully written. Press a key"); break;      case 2 : printw("%s","Entry name already exists - new entry not added. Press a key");               break;      case 3 : printw("%s","New entry was added to the end of the file. Press a key"); break;      default : break;    }   cbreak();   ch = getch(); }delete_entry() {   char entry_name[100], str[100], str2[100], out_string[100], ch;   char *key_name;   FILE *fin, *fout;   int record_found = 0, length, dont_output = 0, removed_something=0;   setup_screen();   move(4,5);   printw("%s","Enter the name of the entry to delete");   move(5,5);   refresh();   nocbreak();   getstr(entry_name);   fin = fopen(bibfile,"r");   fout = fopen("bibtool_tmp.out","w");   if (fout == NULL)    {      endwin();      perror("Could not open file for output ");      exit(1);    }   /* Add some advertising */   fprintf(fout,"%s\n","%%% Generated by Bibtool - Dominic Tristram UWA, 1999");   fprintf(fout,"%s\n","%%% Version $Id: bibtool.c,v 1.6 1999/10/14 18:26:26 dbt93 Exp $");   while((fgets(str, 99, fin)) > 0)    {      if (strchr(str, '@') != NULL)       {         strcpy(str2, str);         if (strchr(str2,'{') != NULL)            key_name = (strchr(str2,'{')+1);         else            key_name = (strchr(str2,'(')+1);         length = strlen(key_name);         *(key_name + (length-2)) = 0;         if (strcmp(key_name,entry_name) == 0)          {            /* Skip this entry */            dont_output = 1;            removed_something = 1;            rec_count--;            move(7,5);            printw("%s removed",key_name);          }         else          {            dont_output = 0;            fputs(str, fout);          }       }      else         if (dont_output == 0)          {            fputs(str, fout);          }    }   fclose(fin);   fclose(fout);   move(10,5);   if (removed_something == 0)    {      printw("%s","Record not found - nothing removed");      move(12,5);    }   printw("%s","Press any key");   cbreak();   refresh();   ch = getch();   if (removed_something == 1)    {      /* Only do all the renaming and moving if we deleted something */      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);    } }int field_menu(int priority, int field_set, char *fieldname) {   int ret_val = 0;   if (priority != 0)    {      if (priority == 1)       {         attron(A_BOLD);         printw("%s ", fieldname);         attroff(A_BOLD);       }      else printw("%s ", fieldname);      if (field_set == 1) addch('*');      ret_val = 1;    }   return(ret_val); }change_entry() {   char entry_name[100], str[100], ch, lch;   int record_found = 0, found_record = 0, print_pos = 6, record_count = 0;   FILE *fin;   setup_screen();   move(4,5);   printw("%s","Please enter the record name : ");   refresh();   nocbreak();   getstr(entry_name);   fin = fopen(bibfile, "r");   if (fin == NULL) return(1);   move(print_pos,1);   while ((fgets(str, 99, fin)) > 0)    {      if (strchr(str, '@') != NULL)       {         if (strstr(str,entry_name) != 0)          {            if (record_count > 0)             {               printw("%s","More than one match! Be more specific! Any key for next match");               refresh();               cbreak();               ch = getch();               setup_screen();               move(4,0);               refresh();             }            record_found = 1;            found_record = 1;            record_count++;          }         else            record_found = 0;       }      if (record_found == 1)       {         printw("%s",str);         print_pos++;       }    }   fclose(fin);   move(print_pos + 1, 5);   if (found_record == 0)    {       printw("%s","The record name was not found! ");      printw("%s","Press a key");      refresh();      cbreak();      ch = getch();      return(0);    }   if (record_count > 1)      printw("%s","You must give a unique ID to change a field - try again");   else      printw("%s","Press C to change a field or any other key to return to the menu");   refresh();   cbreak();   ch = getch();   lch = tolower(ch);   if (lch == 'c')      change_field(entry_name); }change_field(char *entry_name) {   char ch, lch;   char *field_name, *lfield_name, *key_name;   char field_data[200], str[200], out_string[100];   FILE *fin, *fout;   int in_record = 0, changed_field = 0;   setup_screen();   move(4,5);   printw("%s","Select a field to add/replace.");   move(5,5); printw("%s","Note that not all are valid for every entry type!");   move(6,5); printw("%s","If in doubt, don't add anything that isn't there already");   move(8,8);  printw("%s","1. Address          D. Month");   move(9,8);  printw("%s","2. Annote           E. Note");   move(10,8); printw("%s","3. Author           F. Number");   move(11,8); printw("%s","4. Booktitle        G. Organisation");   move(12,8); printw("%s","5. Chapter          H. Pages");   move(13,8); printw("%s","6. Crossref         I. Publisher");   move(14,8); printw("%s","7. Edition          J. School");   move(15,8); printw("%s","8. Editor           K. Series");   move(16,8); printw("%s","9. Howpublished     L. Title");   move(17,8); printw("%s","A. Institution      M. Type");   move(18,8); printw("%s","B. Journal          N. Volume");   move(19,8); printw("%s","C. Key              O. Year");   move(21,8);printw("%s","Make your choice or press q to quit");   refresh();   cbreak();   ch = getch();   lch = toupper(ch);   if (lch == 'q')      return(0);   switch(lch)    {

⌨️ 快捷键说明

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