Changeset 313


Ignore:
Timestamp:
Jun 28, 2006, 11:36:18 PM (19 years ago)
Author:
root
Message:

rewrite_archiverbb2: include user comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/avv.c

    r304 r313  
    1616  14 Aug 05 SHL ArcReviewDlgProc: ensure signature allocated
    1717  29 May 06 SHL EditArchiverData: rework
     18  26 Jun 06 SHL rewrite_archiverbb2: include user comments
    1819
    1920***********************************************************************/
     
    177178}
    178179
    179 //=== rewrite_archiverbb2() rewrite archiver.bb2, prompt if arg NULL ===
     180//=== rewrite_archiverbb2() rewrite archiver.bb2, prompt if arg NULL, merge comments ===
    180181
    181182VOID rewrite_archiverbb2 (PSZ archiverbb2)
    182183{
    183   FILE        *fp;
    184   INT         counter = 0;
    185   ARC_TYPE    *info;
    186   CHAR        s[258];
    187   CHAR        *p;
     184  FILE      *fpNew;
     185  FILE      *fpOld = NULL;
     186  UINT      entry_num = 0;              // Definition counter
     187  UINT      input_line_num = 0;         // Input file line counter
     188  ARC_TYPE  *pat;
     189  CHAR      sz[258];
     190  CHAR      *psz;
     191  BOOL      needEntryNumber;
     192  BOOL      needReload = FALSE;         // Because line numbers changed
     193  time_t    t;
     194  struct tm *tm;
     195  CHAR      ch;
    188196
    189197  arcsigsmodified = FALSE;
     
    204212    archiverbb2 = GetPString(IDS_ARCHIVERBB2);
    205213  }
    206   p = strrchr(archiverbb2,'.');   /* save a backup */
    207   if (p && !stricmp(p,".BB2")) {
    208     strcpy(p,".BAK");
     214
     215  /* save a backup */
     216  psz = strrchr(archiverbb2,'.');
     217  if (psz && !stricmp(psz,".BB2")) {
     218    strcpy(psz,".BAK");
    209219    DosDelete(archiverbb2);
    210     strcpy(s,archiverbb2);
    211     strcpy(p,".BB2");
    212     DosMove(archiverbb2,s);
     220    strcpy(sz,archiverbb2);
     221    strcpy(psz,".BB2");
     222    DosMove(archiverbb2,sz);
     223    fpOld = fopen(sz,"r");              // OK for file not to exist
    213224  }
    214   fp = fopen(archiverbb2,"w");
    215   if (fp) {
    216     fprintf(fp,"%u\n",NUMLINES);
    217     fprintf(fp,
    218             ";\n; %s file written by FM/2 v%d.%02d\n;\n",
     225
     226  fpNew = fopen(archiverbb2,"w");
     227
     228  if (fpNew) {
     229
     230    fprintf(fpNew,"%u\n",LINES_PER_ARCSIG);
     231    t = time(NULL);
     232    tm = localtime(&t);
     233
     234    fprintf(fpNew,
     235            ";\n; %s file written by FM/2 v%d.%02d on %u/%u/%u %u:%02u:%02u\n;\n",
    219236            GetPString(IDS_ARCHIVERBB2),
    220             VERMAJOR,
    221             VERMINOR);
    222     fputs(GetPString(IDS_ARCHIVERBB2TEXT),fp);
    223     info = arcsighead;
    224     while(info) {
    225       fprintf(fp,
    226               GetPString(IDS_ENTRYCNTRTEXT),
    227               ++counter);
    228       if(info->id)
    229         fprintf(fp,
    230                 " (%s)\n;\n",
    231                 info->id);
    232       fprintf(fp,
     237            VERMAJOR, VERMINOR,
     238            tm -> tm_mon + 1, tm -> tm_mday, tm -> tm_year + 1900,
     239            tm -> tm_hour, tm -> tm_min, tm -> tm_sec);
     240    // Rewrite header if known
     241    if (fpOld && arcsigs_header_lines) {
     242      needReload = TRUE;
     243      while (input_line_num < arcsigs_header_lines) {
     244        psz = fgets(sz, sizeof(sz), fpOld);
     245        if (!psz)
     246          break;
     247        input_line_num++;
     248        if (input_line_num == 1)
     249          continue;             // Bypass sig count
     250        fputs(sz, fpNew);
     251      }
     252    }
     253    else {
     254      // Write default header
     255      fputs(GetPString(IDS_ARCHIVERBB2TEXT),fpNew);
     256    }
     257    pat = arcsighead;
     258    while (pat) {
     259      needEntryNumber = TRUE;
     260      // Rewrite per sig header comments if any exist
     261      if (fpOld && pat -> comment_line_num) {
     262        needReload = TRUE;              // fixme to optimize
     263        // Definitions reordered - need to rewind
     264        if (input_line_num > pat -> comment_line_num) {
     265          fseek(fpOld, 0, SEEK_SET);
     266          input_line_num = 0;
     267        }
     268        while (input_line_num + 1 < pat -> defn_line_num) {
     269          psz = fgets(sz, sizeof(sz), fpOld);
     270          if (!psz)
     271            break;                      // Unexpected EOF
     272          input_line_num++;
     273          if (input_line_num < pat -> comment_line_num)
     274            continue;
     275          if (needEntryNumber && strnicmp(sz, "; Entry #", 9) == 0) {
     276            // Rewrite entry count comment
     277            needEntryNumber = FALSE;
     278            for (psz = sz + 9; *psz == ' '; psz++)
     279              ; // Find non-blank
     280            for (; (ch = *psz) >= '0' && ch <= '9'; psz++)
     281              ; // Find end of entry#
     282            fprintf(fpNew,
     283                    GetPString(IDS_ENTRYCNTRTEXT),
     284                    ++entry_num);
     285            fputs(psz, fpNew);
     286          }
     287          else {
     288            fputs(sz, fpNew);
     289          }
     290        }
     291      }
     292
     293      if (needEntryNumber) {
     294        fputs(";\n", fpNew);
     295        fprintf(fpNew,
     296                GetPString(IDS_ENTRYCNTRTEXT),
     297                ++entry_num);
     298        if(pat->id)
     299          fprintf(fpNew, " (%s)", pat->id);
     300        fputs("\n;\n", fpNew);
     301      }
     302
     303      fprintf(fpNew,
    233304              "%s\n%s\n%ld\n%s\n",
    234               nonull(info->id),
    235               nonull(info->ext),
    236               info->file_offset,
    237               nonull(info->list));
    238       fprintf(fp,
     305              nonull(pat->id),
     306              nonull(pat->ext),
     307              pat->file_offset,
     308              nonull(pat->list));
     309      fprintf(fpNew,
    239310              "%s\n%s\n%s\n%s\n%s\n%s\n",
    240               nonull(info->extract),
    241               nonull(info->exwdirs),
    242               nonull(info->test),
    243               nonull(info->create),
    244               nonull(info->createwdirs),
    245               nonull(info->createrecurse));
    246       fprintf(fp,
     311              nonull(pat->extract),
     312              nonull(pat->exwdirs),
     313              nonull(pat->test),
     314              nonull(pat->create),
     315              nonull(pat->createwdirs),
     316              nonull(pat->createrecurse));
     317      fprintf(fpNew,
    247318              "%s\n%s\n%s\n",
    248               nonull(info->move),
    249               nonull(info->movewdirs),
    250               nonull(info->delete));
    251       fprintf(fp,
     319              nonull(pat->move),
     320              nonull(pat->movewdirs),
     321              nonull(pat->delete));
     322      fprintf(fpNew,
    252323              "%s\n%s\n%s\n%d\n%d\n%d,%d\n%d\n%d,%lu,%lu,%lu\n",
    253               fixup(info->signature,
    254                     s,
    255                     sizeof(s),
    256                     info->siglen),
    257               nonull(info->startlist),
    258               nonull(info->endlist),
    259               info->osizepos,
    260               info->nsizepos,
    261               info->fdpos,
    262               info->datetype,
    263               info->fdflds,
    264               info->fnpos,
    265               info->nameislast,
    266               info->nameisnext,
    267               info->nameisfirst);
    268       fprintf(fp,";\n");
    269       info = info->next;
     324              fixup(pat->signature,
     325                    sz,
     326                    sizeof(sz),
     327                    pat->siglen),
     328              nonull(pat->startlist),
     329              nonull(pat->endlist),
     330              pat->osizepos,
     331              pat->nsizepos,
     332              pat->fdpos,
     333              pat->datetype,
     334              pat->fdflds,
     335              pat->fnpos,
     336              pat->nameislast,
     337              pat->nameisnext,
     338              pat->nameisfirst);
     339      pat = pat->next;
     340    } // while more sigs
     341
     342    // Rewrite trailer comments if known
     343    if (fpOld && arcsigs_trailer_line_num) {
     344      for (;;) {
     345        psz = fgets(sz, sizeof(sz), fpOld);
     346        if (!psz)
     347          break;
     348        input_line_num++;
     349        if (input_line_num < arcsigs_trailer_line_num)
     350          continue;             // Bypass sig count
     351        fputs(sz, fpNew);
     352      }
    270353    }
    271     fclose(fp);
    272   }
     354
     355    fclose(fpNew);
     356
     357  } // if fpNew open OK
     358
     359  if (fpOld)
     360    fclose(fpOld);
     361
     362  if (needReload)
     363    load_archivers();                   // Resync commend line numbers
    273364}
    274365
     
    378469{
    379470  ARCDUMP       *admp;
    380   CHAR          s[256];
     471  CHAR          s[256];
    381472  SHORT         sSelect;
    382473
Note: See TracChangeset for help on using the changeset viewer.