
/*****************************************************
  ren.c

  This program allows one to rename the directory
  which contains the font data files.

  Copyright 1988 By Stephen Vermeulen

  This program may be freely redistributed so long as
  the Copyright messages remain intact and the program
  is distributed with the supplied documentation.

  syntax:

     ren thisfont.font path
******************************************************/

#include <stdio.h>

char newname[256], oldname[256];

main(argc, argv)
int argc;
char *argv[];
{
  FILE *font;
  long j, pos;
  short i, n;

  if (argc != 3)
  {
    printf("ren filename.font newpath\n");
    printf("Copyright 1988 By Stephen Vermeulen\n");
    printf("3635 Utah Dr. N.W.,  Calgary, Alberta, CANADA, T2N 4A6\n");
  }
  else
  {
    font = fopen(argv[1], "r+");
    if (font)
    {
      /********************************************
        now determine how many sizes this font has
      *********************************************/

      fread(&n, 2, 1, font);  /** throw away **/
      fread(&n, 2, 1, font);  /** number of sizes **/
      printf("Font %s has %d sizes\n", argv[1], n);
      for (i = 0; i < n; ++i)
      {
        /** for each size we rename it...
         **/

        fseek(font, 4L + 260L * i, 0);
        fread(oldname, 256, 1, font);
        printf("name was: %s ", oldname);
        for (j = 255; j > 0; --j)
          if (oldname[j] == '/') break;
        strcpy(newname, argv[2]);
        strcat(newname, oldname + j);
        fseek(font, 4L + 260L * i, 0);
        printf("now is: %s\n", newname);
        fwrite(newname, 256, 1, font);
      }
      fclose(font);
    }
  }
}

