home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / text / tex / pastex / source / driver / util / amiga / showopt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-01  |  8.4 KB  |  356 lines

  1.  
  2.  
  3. #define TEX
  4.  
  5. #include <dos/dos.h>
  6.  
  7. #include <stdarg.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <stddef.h>
  11. #include <string.h>
  12.  
  13. #include <dos/dos.h>
  14. #include <libraries/dos.h>
  15. #include <dos/dosextens.h>
  16.  
  17. #include <clib/exec_protos.h>
  18. #include <clib/dos_protos.h>
  19.  
  20. #include <pragmas/exec_pragmas.h>
  21. #include <pragmas/dos_pragmas.h>
  22.  
  23. extern struct ExecBase        *SysBase;
  24. extern struct DosLibrary    *DOSBase;
  25.  
  26.  
  27. #include "GetOpt.h"
  28. #include "GetOpt.i"
  29.  
  30. #include "little_globals.h"
  31. #include "little_globals.i"
  32.  
  33. extern char *_ProgramName;
  34.  
  35. static void PrintHelp(struct Options opt[], short long_hlp);
  36.  
  37. static char ver[] = "$VER: ShowOpt 0.34 ("__DATE__")";
  38.  
  39.  
  40. /*==================================================================*/
  41.  
  42.  
  43. /* Nur zum Test... */
  44. char  g_Logname[STRSIZE]= "ShowOpt.log";    /* name of log file, if created            */
  45. int   g_logfile=0;            /* Are these messages going to a log file? */
  46. FILE *g_logfp=NULL;            /* log file pointer (for errors)           */
  47. float hoffset_in = 1.0;
  48. float voffset_in = 1.0;
  49. int resolution = 100;
  50. int hconvresolution, vconvresolution;
  51. char *PXLpath = "default";
  52. int fontmemsize;
  53. int FirstPage;
  54. int PreLoad;
  55. int Stats;
  56. int g_logging;
  57. int g_authors;
  58. char filename[STRSIZE];
  59. FILE *dvifp;
  60. char m_string[STRSIZE];
  61. char *g_progname;
  62.  
  63.  
  64. #if 0
  65. #define Message(str)        puts(str)
  66. void Fatal(int ex, char *str, int bla);
  67. void AbortRun(int ex);
  68. void *xmalloc(unsigned size);
  69. #endif
  70.  
  71. /* liefert den Pfad zum file, falls file=="" dann Pfad des akt. Verz. */
  72. void getdir(char *file, char *dir)
  73. {
  74.   BPTR lock, lock1;
  75.   char strh[108], *h;
  76.   struct FileInfoBlock *fib;
  77.   struct Process *pr;
  78.  
  79.   if (*file == '\0') {
  80.     pr = (struct Process *)FindTask(NULL);
  81.     if (pr->pr_CurrentDir == NULL) {
  82.       strcpy(dir,"SYS:");
  83.       return;
  84.     }
  85.     else {
  86.       lock = DupLock(pr->pr_CurrentDir);
  87.     }
  88.   }
  89.   else {
  90.     lock = Lock(file,ACCESS_READ);
  91.   }
  92.  
  93.   if (lock==(BPTR)NULL) {
  94.      sprintf(m_string,"can't find file \"%s\" to examine!",file);
  95.      Fatal(3,m_string,16);
  96.   }
  97.  
  98.   dir[0]='\0';
  99.  
  100.   fib = (struct FileInfoBlock *)xmalloc((unsigned)sizeof(struct FileInfoBlock));
  101.   if (Examine(lock,fib) == 0) {
  102.     Fatal(3,"can't examine file!",17);
  103.   }
  104.  
  105.   if (file[0] == '\0' || fib->fib_DirEntryType > 0 ) {    /* aktuelles Verz. oder Dir.*/
  106.      strcpy(dir, fib->fib_FileName);
  107.      strcat(dir,"/");
  108.   }
  109.   lock1 = ParentDir(lock);
  110.   UnLock((BPTR)lock);
  111.   lock = lock1;
  112.   while (lock!=(BPTR)NULL)
  113.    {
  114.     if (Examine(lock,fib)==0) {
  115.        Fatal(3,"can't examine file!",17);
  116.     }
  117.     else {
  118.        strcpy(strh,fib->fib_FileName);
  119.        strcat(strh,"/");
  120.        strcat(strh,dir);
  121.        strcpy(dir,strh);
  122.     }
  123.     lock1 = ParentDir(lock);
  124.     UnLock((BPTR)lock);
  125.     lock = lock1;
  126.    }
  127.   h = strchr(dir,'/');
  128.   if (h != NULL) {
  129.     h[0] = ':';
  130.   }
  131.   xfree((char *)fib);
  132. }
  133.  
  134. int is_dir(char *file)
  135. {
  136.   struct FileLock *lock;
  137.   struct FileInfoBlock *fib;
  138.   int is = FALSE;
  139.  
  140.   fib = (struct FileInfoBlock *)xmalloc((unsigned)sizeof(struct FileInfoBlock));
  141.   lock = (struct FileLock *)Lock(file,ACCESS_READ);
  142.  
  143.   if (lock!=NULL) {
  144.     if (Examine((BPTR)lock,fib)!=0) {
  145.       if (fib->fib_DirEntryType>0) {
  146.         is = TRUE;
  147.       }
  148.     }
  149.     UnLock((BPTR)lock);
  150.   }
  151.   xfree((char *)fib);
  152.   return (is);
  153. }
  154.  
  155. #if 0
  156. void AbortRun(int ex)
  157. {
  158.   Delay(200);
  159.   exit(ex);
  160. }
  161.  
  162. void *xmalloc(unsigned size)
  163. {
  164.   void *poi;
  165.  
  166.   if ((poi = malloc(size)) == NULL) {
  167.     Fatal(5,"no memory",111);
  168.   }
  169.   return poi;
  170. }
  171.  
  172. void Fatal(int ex, char *str, int bla)
  173. {
  174.   printf("Fatal: %s\n",str);
  175.   AbortRun(ex);
  176. }
  177. #endif
  178.  
  179. /*==================================================================*/
  180.  
  181.  
  182. static char *filenameptr;
  183. static long help;
  184. static long DebugStats;
  185. static long logging;
  186.  
  187.  
  188. START_PARAM(opt)
  189.   /* req?      key-name     abbrev  type         variable       help-txt */
  190.   NOREQ_PARAM ("HELP",      "?",    OPT_HELP,    &help,        "print help information", NULL)
  191.   NOREQ_PARAM ("DIRECTORY", "DIR",  OPT_STRING,  &PXLpath,    "additional dir for fontlibs/pk-files", NULL)
  192.   NOREQ_PARAM ("FONTMEM",   NULL,   OPT_LONG,    &fontmemsize,    "size of the fontmemory", NULL)
  193.   NOREQ_PARAM ("PAGE",      "P",    OPT_LONG,    &FirstPage,    "start at page", NULL)
  194.   NOREQ_PARAM ("HOFFSET",   "HOFF", OPT_TEX_DIM, &hoffset_in,    "horizontal offset",
  195.         "(unit out of: pt|cm|in|pc|dd|cc|bp|mm|mi|cp)")
  196.   NOREQ_PARAM ("VOFFSET",   "VOFF", OPT_TEX_DIM, &voffset_in,    "vertical offset",
  197.         "(unit out of: pt|cm|in|pc|dd|cc|bp|mm|mi|cp)")
  198.   NOREQ_PARAM ("PRELOAD",   NULL,   OPT_BOOLEAN, &PreLoad,    "preload all fonts", NULL)
  199.   NOREQ_PARAM ("RESOLUTION","RES",  OPT_LONG,    &resolution,    "starting resolution in DPI", NULL)
  200.   NOREQ_PARAM ("STATISTIC", "STAT", OPT_BOOLEAN, &Stats,    "more output to the logfile", NULL)
  201.   NOREQ_PARAM ("DEBUGSTAT", NULL,   OPT_BOOLEAN, &DebugStats,    "close logfile after every line", NULL)
  202.   NOREQ_PARAM ("LOGFILE",   "LOG",  OPT_BOOLEAN, &logging,    "create logfile (ShowDVI.log)", NULL)
  203.   HIDDEN_PARAM("PRINTAUTHOR", NULL, OPT_BOOLEAN, &g_authors,    "show author name", NULL)
  204.   NOREQ_PARAM (NULL,        NULL,   OPT_OPTIONSTRING, &filenameptr,"DVI-file", NULL)
  205. END_PARAM
  206.  
  207.  
  208. void DecodeArgs(int argc, char *argv[])
  209. {
  210.   BOOL error;
  211.  
  212.   if (argc == 0) {
  213.     g_progname = _ProgramName;
  214.   }
  215.   else {
  216.     g_progname = argv[0];
  217.   }
  218.  
  219.   /* Default-Werte */
  220.   fontmemsize = FONTMEMSIZE;
  221.  
  222.   /*----------------------------------------------------------*/
  223.   error = GetOpt(argc, argv, "ShowDVI", TRUE, opt);
  224.   /*----------------------------------------------------------*/
  225.  
  226.   if (error) {
  227.     PrintHelp(opt, FALSE);
  228.     AbortRun(5);    /* Programm Ende */
  229.   }
  230.   if (help) {
  231.     PrintHelp(opt, TRUE);
  232.     AbortRun(0);    /* Programm Ende */
  233.   }
  234.  
  235.   hconvresolution = vconvresolution = resolution;
  236.   if (DebugStats) {
  237.     Stats = 2;
  238.   }
  239.   if (!logging) {
  240.     g_logging = -1;
  241.   }
  242.  
  243.   if (filenameptr == NULL) {
  244.     /* das ist eigentlich unnoetig 'filenameptr' sollte immer != NULL sein */
  245.     getdir("",filename);
  246.   }
  247.   else {
  248.     strcpy(filename, filenameptr);
  249.   }
  250.  
  251.   { char dir[250];        /* lokale Definition wg. Stack */
  252.     char *ext, *ptr;
  253.  
  254.     if (!is_dir(filename)) {
  255.  
  256.       if ((ext = strrchr(filename, '.')) == NULL) {
  257.         strcat(filename, ".dvi");
  258.       }
  259.       else {
  260.         if (stricmp(ext, ".tex") == NULL) {
  261.           strcpy(ext, ".dvi");    /* Ueberschreibe das '.tex' */
  262.         }
  263.         else {
  264.           if (stricmp(ext, ".dvi") != NULL) {
  265.             strcat(filename, ".dvi");
  266.           }
  267.         }
  268.       }
  269.       dvifp = fopen(filename, "r");
  270.       if (dvifp != NULL) {
  271.         /* bastle nun den vollen Pfad */
  272.         getdir(filename, dir);
  273.         if ((ptr = strrchr(filename, '/')) == NULL) {
  274.           if ((ptr = strrchr(filename, ':')) == NULL) {
  275.             strcat(dir, filename);
  276.           }
  277.           else {
  278.             strcat(dir, ptr+1);
  279.           }
  280.         }
  281.         else {
  282.           strcat(dir, ptr+1);
  283.         }
  284.         strcpy(filename, dir);
  285.       }
  286.       else {
  287.         if (strrchr(filename, ':') == NULL) {
  288.           if (strrchr(filename, '/') == NULL) {
  289.             getdir("", dir);        /* nicht gefunden, aber ohne Pfad */
  290.             strcat(dir, filename);    /* haenge Pfad an. */
  291.             strcpy(filename, dir);
  292.           }
  293.         }
  294.         sprintf(m_string, "*** Can't find file '%s'!",filename);
  295.         Message(m_string);
  296.       }
  297.     }
  298.     else {        /* es ist ein Directory */
  299.       getdir(filename, dir);
  300.       strcpy(filename, dir);
  301.     }
  302.   }
  303.   
  304.   if (!opt[12].is_given) {
  305.     getdir("",filename);    /* kein Name angegeben => nimm das aktuelle Dir. */
  306.   }
  307. }
  308.  
  309.  
  310. static void PrintHelp(struct Options opt[], short long_hlp)
  311. {
  312.   char hlp[100];
  313.  
  314.   Message(NULL);
  315.   sprintf(m_string,"(c)Copyright 1990-91, (hes). All rights reserved. %s",__DATE__);
  316.   Message(m_string);
  317.  
  318.   sprintf(hlp, "usage: %s ", g_progname);
  319.   GetOptShortHelp(hlp, 73, opt);
  320.   
  321.   if (long_hlp) {
  322.     Message("");
  323.     GetOptHelp(opt);  
  324.   }
  325. }
  326.  
  327.  
  328. void main(int argc, char *argv[])
  329. {
  330.   char buf[100];
  331.  
  332.   DecodeArgs(argc, argv);
  333.   
  334.   printf("help:         '%d'\n", help);
  335.   printf("PXLpath:      '%s'\n", PXLpath);
  336.   printf("fontmemsize:  '%d'\n", fontmemsize);
  337.   printf("FirstPage:    '%d'\n", FirstPage);
  338.   printf("hoffset_in:   '%f'\n", hoffset_in);
  339.   printf("voffset_in:   '%f'\n", voffset_in);
  340.   printf("PreLoad:      '%d'\n", PreLoad);
  341.   printf("resolution:   '%d'\n", resolution);
  342.   printf("Stats:        '%d'\n", Stats);
  343.   printf("DebugStats:   '%d'\n", DebugStats);
  344.   printf("logging:      '%d'\n", logging);
  345.   printf("g_authors:    '%d'\n", g_authors);
  346.   printf("Filename:     '%s'\n", filename);
  347.  
  348.   getdir("",buf);
  349.   printf("\ngetdir(\"\",buf) = %s\n",buf);
  350.  
  351.   if (argc == 0) {
  352.     Delay(200);
  353.   }
  354.   printf(".\n");
  355. }
  356.