home *** CD-ROM | disk | FTP | other *** search
/ Crazy Collection 12 / CC-12_1.iso / update / doompack / data.a00 / LMPC280.ZIP / LMPC-2.8 / SRC / TOOLS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-23  |  3.2 KB  |  110 lines

  1. /****************************************************************************\
  2. ;                                                                            ;
  3. ;  tools.c  -  projekt LMP control center                                    ;
  4. ;  implementation                                                            ;
  5. ;                                                                            ;
  6. ;  general tool routines                                                     ;
  7. ;                                                                            ;
  8. ;  Uwe Girlich                                                               ;
  9. ;  Erika-von-Brockdorff-Strasse 2                                            ;
  10. ;  04159 Leipzig                                                             ;
  11. ;  Deutschland / Germany                                                     ;
  12. ;  E-mail: girlich@aix520.informatik.uni-leipzig.de                          ;
  13. ;                                                                            ;
  14. \****************************************************************************/
  15.  
  16.  
  17. #include <errno.h>
  18. #include <stdio.h>
  19. #include "tools.h"
  20.  
  21.  
  22. char *my_errlist[] = {
  23.             "too few arguments",
  24.             "too many arguments",
  25.             "read error",
  26.             "write error",
  27.             "wrong predefined game type",
  28.             "unknown game type",
  29.             "bad LMP file",
  30.             "bad version byte",
  31.             "unknown version byte",
  32.             "impossible version change",
  33.             "argument missing",
  34.             "too many action parameters",
  35.             "invalid option value",
  36.             "illegal option",
  37.             "missing input filename",
  38.             "missing output filename"
  39.                };
  40.  
  41.  
  42. void syserror(int errno, char* message)
  43. {
  44.   syswarning(errno, message);
  45.   exit(errno);
  46. }
  47.  
  48. void syswarning(int errno, char* message)
  49. {
  50.   if (0<errno && errno<sys_nerr)
  51.     fprintf(stderr,"lmpc: %s: %s\n", message, sys_errlist[errno]);
  52.   else
  53.     if (err_base<=errno && errno<LASTERR) 
  54.       fprintf(stderr,"lmpc: %s: %s\n", message, my_errlist[errno-err_base]);
  55.     else
  56.       fprintf(stderr,"lmpc: %s: errno=%d\n", message, errno);
  57. }
  58.  
  59. void syntaxerror(long linenumber, char *message)
  60. {
  61.   fprintf(stderr, "lmpc: Syntax error in line %ld. %s.\n", linenumber, message);
  62.   exit(1);
  63. }
  64.  
  65. void syntaxwarning(long linenumber, char *message)
  66. {
  67.   fprintf(stderr, "lmpc: Syntax warning in line %ld. %s.\n", linenumber, message);
  68. }
  69.  
  70. char *Time2String(double time, char *buf)
  71. {
  72.   int hour, min, secFull, sec100;
  73.   double sec;
  74.  
  75.   hour = time/3600;
  76.   min = (time -3600*hour)/60;
  77.   sec = time -3600*hour -60*min;
  78.   secFull = sec;
  79.   sec100 = (sec-secFull)*100;
  80.   if (hour!=0)
  81.     sprintf(buf, "%d:%02d:%02d.%02dh", hour, min, secFull, sec100);
  82.   else
  83.     if (min!=0)
  84.       sprintf(buf, "%d:%02d.%02dm", min, secFull, sec100);
  85.     else 
  86.       sprintf(buf, "%d.%02ds", secFull, sec100);
  87.   return buf;
  88. }
  89.  
  90. void copyopenfiles(FILE *f1, FILE *f2)
  91. {
  92.   int c;
  93.  
  94.   while ((c=fgetc(f1))!=EOF) fputc(c,f2);
  95. }
  96.  
  97. char *delspaces(char *a)
  98. {
  99.   while(strlen(a)>0 && (a[strlen(a)-1]==' '   || 
  100.             a[strlen(a)-1]=='\t'  || 
  101.             a[strlen(a)-1]=='\n'  ||
  102.             a[strlen(a)-1]=='\015'   )) 
  103.     a[strlen(a)-1]='\0';
  104.   while(strlen(a)>0 && (a[0]==' ' || a[0]=='\t')) 
  105.     a++;
  106.   return a;
  107. }
  108.  
  109. /*-- file end tools.c --------------------------------------------------------*/
  110.