home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DVIM72-Mac 1.9.6 / source / Parse_special.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-14  |  2.9 KB  |  133 lines  |  [TEXT/R*ch]

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "mac-specific.h"
  5. #include "Parse_special.h"
  6.  
  7. #define        MAX_KEYWORD        50
  8.  
  9. char    *Get_keyword( char *s, short *keytype )
  10. {
  11.     char    keyword[MAX_KEYWORD];
  12.     char    *key_ptr, *keyword_end_ptr;    
  13.  
  14.     key_ptr = keyword;
  15.     keyword_end_ptr = keyword + MAX_KEYWORD - 1;
  16.     while (*s == ' ') ++s; // scan past any blanks
  17.     while ( (*s != '=') && (*s != '\0') && (key_ptr < keyword_end_ptr) )
  18.     {
  19.         *key_ptr = *s;    // copy the keyword
  20.         ++s;
  21.         key_ptr++;
  22.     }
  23.     *key_ptr = '\0';
  24.     if (*s != '=')
  25.     {
  26.         *keytype = sp_nokeyword;
  27.         return s;
  28.     }
  29.     /*
  30.         At this point, we have a keyword and *s == '='.
  31.     */
  32.     s++;    // skip over the '='
  33.     /*
  34.         Now we have an alleged keyword. See if we recognize it.
  35.     */
  36.     if ( (strcmp(keyword, "pict") == 0) || (strcmp(keyword, "pictfile") == 0) )
  37.         *keytype = sp_pict;
  38.     else if ( (strcmp(keyword, "width") == 0) || (strcmp(keyword, "wd") == 0) )
  39.         *keytype = sp_width;
  40.     else if ( (strcmp(keyword, "height") == 0) || (strcmp(keyword, "ht") == 0) )
  41.         *keytype = sp_height;
  42.     else if ( (strcmp(keyword, "hscale") == 0) || (strcmp(keyword, "xscale") == 0) )
  43.         *keytype = sp_hscale;
  44.     else if ( (strcmp(keyword, "vscale") == 0) || (strcmp(keyword, "yscale") == 0) )
  45.         *keytype = sp_vscale;
  46.     else if ( strcmp(keyword, "scale") == 0)
  47.         *keytype = sp_scale;
  48.     else
  49.         *keytype = sp_nokeyword;
  50.     
  51.     return s;
  52. }
  53.  
  54.  
  55. char    *Get_filename( char *s, StringPtr filename )
  56. {
  57.     char    *file_ptr;
  58.     
  59.     while (*s == ' ') ++s; // scan past any blanks
  60.     file_ptr = (char *) filename;
  61.     if (*s == '"')    // quoted filename
  62.     {
  63.         ++s;    // move past the quote
  64.         while ( (*s != '"') && (*s != '\0') )
  65.         {
  66.             *file_ptr = *s;
  67.             ++s;
  68.             ++file_ptr;
  69.         }
  70.         if (*s == '"') ++s;
  71.     }
  72.     else    // file not quoted, just scan to blank or end
  73.     {
  74.         while ( (*s != ' ') && (*s != '\0') )
  75.         {
  76.             *file_ptr = *s;
  77.             ++s;
  78.             ++file_ptr;
  79.         }
  80.     }
  81.     *file_ptr = '\0';
  82.     CtoPstr( (char *) filename );
  83.     return s;
  84. }
  85.  
  86. void Get_scales( char *s, float *hscale, float *vscale,
  87.                     short ht, short wd )
  88. {
  89.     char    message[256];
  90.     short    keytype;
  91.     float    value;
  92.     Boolean height_set, width_set;
  93.     
  94.     *hscale = *vscale = 1;
  95.     height_set = width_set = false;
  96.     while (*s) // process the string until the end
  97.     {
  98.         /*
  99.             Look for a keyword.
  100.         */
  101.         s = Get_keyword( s, &keytype );
  102.         
  103.         /*
  104.             At this point, we have a recognized keyword.  We need to get
  105.             the value, either a decimal number or a filename.
  106.         */
  107.         while (*s == ' ') ++s; // scan past any blanks
  108.         sscanf( s, "%g", &value );
  109.         switch (keytype)
  110.         {
  111.             case sp_scale:
  112.                 *hscale = *vscale = value;
  113.                 break;
  114.             case sp_hscale:
  115.                 *hscale = value;
  116.                 break;
  117.             case sp_vscale:
  118.                 *vscale = value;
  119.                 break;
  120.             case sp_height:
  121.                 *vscale = value / ht;
  122.                 height_set = true;
  123.                 if (!width_set) *hscale = value / wd;
  124.                 break;
  125.             case sp_width:
  126.                 *hscale = value / wd;
  127.                 width_set = true;
  128.                 if (!height_set) *vscale = value / ht;
  129.                 break;
  130.         }
  131.         while ( (*s != '\0') && (*s != ' ') ) ++s; // skip over the number
  132.     }
  133. }