home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 517a.lha / FontManipulatorForDtp_v2 / source / remfont / remfont.c < prev    next >
C/C++ Source or Header  |  1991-06-09  |  5KB  |  210 lines

  1. /* Font remover.  File "remfont.c".
  2.  * (C) Adrian Aylward 1991
  3.  *
  4.  * You may freely copy, use, and modify this file.
  5.  *
  6.  * This program removes a font from memory - or rather, makes it no longer
  7.  * available to OpenFont, and ensures that it will be unloaded if and when
  8.  * the last of its acessors closes it.
  9.  *
  10.  * The program was tested using Lattice C V5.05.  It has various Lattice
  11.  * dependencies.
  12.  *
  13.  * This is version 1.0.
  14.  */
  15.  
  16. # include <dos.h>
  17. # include <exec/exec.h>
  18. # include <graphics/gfxbase.h>
  19. # include <graphics/text.h>
  20. # include <proto/dos.h>
  21. # include <proto/exec.h>
  22. # include <proto/graphics.h>
  23. # include <string.h>
  24. # include <stdio.h>
  25.  
  26. /* External data (initialised to zero) */
  27.  
  28. char *argfontname, *argpointsizes;
  29.  
  30. int optbold, optitalic, optunderlined, optextended;
  31.  
  32. int retcode;
  33.  
  34. int fontsize;
  35.  
  36. char namebuf[100];
  37.  
  38. int pointc, pointv[100];
  39.  
  40. struct TextAttr ftattr =
  41. {   NULL, 0, 0, 0 };
  42.  
  43. struct TextFont *ftextf;
  44.  
  45. /* Routines */
  46.  
  47. extern void stub(void);
  48. extern void chkabort(void);
  49.  
  50. /* Main program */
  51.  
  52. void main(int argc, char **argv)
  53. {   char *s;
  54.     int i, ch;
  55.  
  56.     /* Parse arguments.  No workbench startup */
  57.  
  58.     if (argc == 0) goto tidyexit;
  59.     argv++;
  60.     argc--;
  61.     if (argc == 0 || (argc == 1 && strcmp(*argv, "?") == 0)) goto query;
  62.  
  63.     while (argc)
  64.     {   s = *argv;
  65.         if (*s != '-') break;
  66.         argv++;
  67.         argc--;
  68.         if (strcmp(s, "--") == 0) break;
  69.         s++;
  70.         for (;;)
  71.         {   ch = *s++;
  72.             if (ch == 0) break;
  73.             switch (ch)
  74.             {   case 'B': case 'b':
  75.                     optbold = 1;
  76.                     continue;
  77.  
  78.                 case 'I': case 'i':
  79.                     optitalic = 1;
  80.                     continue;
  81.  
  82.                 case 'U': case 'u':
  83.                     optunderlined = 1;
  84.                     continue;
  85.  
  86.                 case 'X': case 'x':
  87.                     optextended = 1;
  88.                     continue;
  89.  
  90.                 default:
  91.                     fprintf(stderr, "remfont: unknown option \"-%c\"", ch);
  92.                     goto badusage;
  93.             }
  94.         }
  95.  
  96.         if (*s == '-' && *(s + 1) == 0) break;
  97.     }
  98.  
  99.     if (argc != 2) goto badargs;
  100.     argfontname = argv[0];
  101.     argpointsizes = argv[1];
  102.  
  103.     s = argpointsizes;
  104.     while (*s)
  105.     {   i = 0;
  106.         for (;;)
  107.         {   ch = *s;
  108.             if (ch == 0) break;
  109.             s++;
  110.             if (ch == ',') break;
  111.             if (ch >= '0' && ch <= '9')
  112.                 i = i * 10 + (ch - '0');
  113.             else
  114.                 goto badargs;
  115.         }
  116.         if (i != 0)
  117.         {   if (pointc == 100) goto badargs;
  118.             pointv[pointc++] = i;
  119.         }
  120.     }
  121.  
  122.     /* Build the font descriptor (TextAttr structure) */
  123.  
  124.     if (strlen(argfontname) >= 95) goto badargs;
  125.     strcpy(namebuf, argfontname);
  126.     strcat(namebuf, ".font");
  127.     ftattr.ta_Name = namebuf;
  128.  
  129.     if (optbold)       ftattr.ta_Style |= FSF_BOLD;
  130.     if (optitalic)     ftattr.ta_Style |= FSF_ITALIC;
  131.     if (optunderlined) ftattr.ta_Style |= FSF_UNDERLINED;
  132.     if (optextended)   ftattr.ta_Style |= FSF_EXTENDED;
  133.  
  134.     /* Try to open each of the fonts.  If we find EXACTLY what we want,
  135.      * then remove it and close it again */
  136.  
  137.     GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0);
  138.     if (GfxBase == NULL)
  139.     {   fprintf(stderr, "remfont: can't open graphics.libary\n");
  140.         goto errorexit;
  141.     }
  142.  
  143.     for (i = 0 ; i < pointc; i++)
  144.     {   ftattr.ta_YSize = pointv[i];
  145.         ftextf = OpenFont(&ftattr);
  146.         if (ftextf != NULL)
  147.         {   if (strcmp(ftextf->tf_Message.mn_Node.ln_Name,
  148.                            ftattr.ta_Name) == 0 &&
  149.                 ftextf->tf_YSize == ftattr.ta_YSize &&
  150.                 ftextf->tf_Style == ftattr.ta_Style)
  151.                 RemFont(ftextf);
  152.             CloseFont(ftextf);
  153.         }
  154.     }
  155.  
  156.     CloseLibrary((struct Library *) GfxBase);
  157.     goto tidyexit;
  158.  
  159.     /* Argument errors and usage query */
  160.  
  161. query:
  162.     fprintf(stderr, "Font remover.  RemFont version 1.0\n"
  163.                     "\n"
  164.                     "  Usage:\n"
  165.                     "\n"
  166.                     "    remfont -options font nn,nn,...\n"
  167.                     "\n"
  168.                     "      -b              Bold\n"
  169.                     "      -i              Italic\n"
  170.                     "      -u              Underlined\n"
  171.                     "      -x              Extended\n"
  172.                     "\n"
  173.                     "  For example:\n"
  174.                     "\n"
  175.                     "    remfont topaz 8,11\n"
  176.                     "\n"
  177.                     "  N.B. the font name is case sensitive\n");
  178.     goto tidyexit;
  179.  
  180. badargs:
  181.     fprintf(stderr, "remfont: arguments bad or value missing\n");
  182. badusage:
  183.     retcode = 20;
  184.     fprintf(stderr, ".  Usage:\n"
  185.                     "    remfont -options font nn,nn,...\n");
  186.     goto tidyexit;
  187.  
  188.     /* Tidy up and exit */
  189.  
  190. errorexit:
  191.     retcode = 20;
  192.  
  193. tidyexit:
  194.     exit(retcode);
  195. }
  196.  
  197. /* Dummy stub routine */
  198.  
  199. void stub(void)
  200. {   return;
  201. }
  202.  
  203. /* Dummy check abort routine */
  204.  
  205. void chkabort(void)
  206. {   return;
  207. }
  208.  
  209. /* End of file "remfont.c" */
  210.