home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume43 / pform / part02 / p_utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-10  |  3.0 KB  |  114 lines

  1. static char version[] = VERSION;
  2. /*
  3. #
  4. #   pform version 1.0 - ascii to postscript converter 
  5. #   copyright 1994 - Steven Weintraub
  6. #
  7. #   This program is created and distribed by Steven Weintraub.  It is
  8. #   public domain code, and can be freely distributed without permission
  9. #   as long as this head is retained in all files it appears
  10. #
  11. */
  12. #include "pform.h"
  13.  
  14. /* This file has some utilities programs for pform.  These are :
  15.  
  16.    p_error      - output an error message, also te usage message if desired
  17.    p_directions - printout the -? output
  18.    casecmp      - case insenstive strcmp
  19.  
  20. */
  21.  
  22. /***************************************************************************/
  23. /* This routine prints out error messages.  It alsoprints a usage message if
  24.    requested, and exits if fatal */
  25.  
  26. void p_error(int fatal,int print_usage,char *format,...)
  27.   {
  28.   va_list   args;
  29.   char    **usage_ptr;
  30.  
  31.   if (!quiet)
  32.     {
  33.     fprintf(stderr,"%s : ",program);
  34.     if (line_number || dot_lines)
  35.       fprintf(stderr,"Line %d : ",line_number + dot_lines);
  36.     va_start(args,format);
  37.     vfprintf(stderr,format,args);
  38.     va_end(args);
  39.     putc('\n',stderr);
  40.     if (print_usage)
  41.       {
  42.       putc('\n',stderr);
  43.       fprintf(stderr,usage[0],program);
  44.       for (usage_ptr = usage + 1;*usage_ptr;usage_ptr++)
  45.         fprintf(stderr,"%s\n",*usage_ptr);
  46.       fprintf(stderr,"\nUse '%s -?' for more details\n",program);
  47.       }
  48.     }
  49.   if (fatal)
  50.     exit(1);
  51.   }
  52.  
  53. /* This routine prints the directions to the -? arguement.  It first prints
  54.    the usage - the the arguement info - etc. */
  55.  
  56. void p_directions(void)
  57.   {
  58.   int    count = 0;
  59.   char **font_ptr;
  60.   char **usage_ptr;
  61.  
  62.   printf("%s\n\n",version);
  63.   if (!quiet)
  64.     {
  65. /*  print off the first usage value */
  66.     printf(usage[0],program);
  67. /*  print off the rest of the usage string */
  68.     for (usage_ptr = usage + 1;*usage_ptr;usage_ptr++)
  69.       printf("%s\n",*usage_ptr);
  70.     printf("\n");
  71. /*  print the rest of the directions (stored behind the null in usage array) */
  72.     for (usage_ptr++;*usage_ptr;usage_ptr++)
  73.       printf("%s\n",*usage_ptr);
  74.     printf("\n");
  75. /* print off the defautls */
  76. #ifdef PRINTER
  77.     printf("Default output goes to the %s printer\n\n",PRINTER);
  78. #else
  79. #ifdef DEFAULT_PRINTER_COMMAND
  80.     printf("Default output goes to the default printer\n\n");
  81. #else
  82.     printf("Default output goes to standard output\n\n");
  83. #endif /* DEFAULT_PRINTER_COMMAND */
  84. #endif /* PRINTER */
  85. #ifdef BLANK_PAGE
  86.     printf("Default output prints a blank page\n\n");
  87. #else
  88.     printf("Default is output does not start with a blank page\n\n");
  89. #endif /* BLANK_PAGE */
  90. /*  printf off the font table */
  91.     printf("Valid fonts are :\n\n");
  92.     for (font_ptr = fonts;*font_ptr;font_ptr++)
  93.       {
  94.       printf("%-25s",*font_ptr);
  95.       if (++count == 3)
  96.         {
  97.         printf("\n");
  98.         count = 0;
  99.         }
  100.       }
  101.     }
  102.   printf("\n");
  103.   exit(1);
  104.   }
  105.  
  106. /* same as strcmp only case insensitive */
  107.  
  108. int casecmp(char *str1,char *str2)
  109.   {
  110.   for (;*str1 && *str2 && tolower(*str1) == tolower(*str2);str1++,str2++)
  111.     ;
  112.   return(*str1 - *str2);
  113.   }
  114.