• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

massage.c

Go to the documentation of this file.
00001 //
00002 //## Copyright (C) 1998-2003 Joao Cardoso.
00003 //##
00004 //## This program is free software; you can redistribute it and/or modify it
00005 //## under the terms of the GNU General Public License as published by the
00006 //## Free Software Foundation; either version 2 of the License, or (at your
00007 //## option) any later version.
00008 //##
00009 //## This program is distributed in the hope that it will be useful, but
00010 //## WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 //## General Public License for more details.
00013 //##
00014 //## This file is part of plplot_octave.
00015 //
00016 
00017 //
00018 // Add online help to functions, parsing 'tmp_stub' and looking for
00019 // function definitions; for each function found, scans directory
00020 // 'plplot_octave_txt' for a file with the same basename as function
00021 // and extension '.txt'; if found, incorporates it as the function
00022 // online help, else, looks in 'plplot.doc' for a one-line description
00023 // of the function and adds it. If not even found in 'plplot.doc', ask
00024 // the user to write the docs! No free lunches!
00025 //
00026 
00027 #include "stdio.h"
00028 #include "string.h"
00029 #include "stdlib.h"
00030 #include  <sys/stat.h>
00031 #include  "errno.h"
00032 
00033 int
00034 main()
00035 {
00036     char        *p1, *p2;
00037     char        doc[150][1024], b[1024], tok[80];
00038     int         item = 0, j;
00039     FILE        *fp, *fp1;
00040     struct stat buf;
00041 
00042     if ( ( fp = fopen( "plplot_octave_txt/plplot.doc", "r" ) ) == NULL )
00043     {
00044         perror( "plplot.doc not found:" );
00045         exit( 1 );
00046     }
00047 
00048     while ( !feof( fp ) && fgets( b, sizeof ( b ), fp ) != NULL )
00049     {
00050         if ( strchr( b, '-' ) )
00051             strcpy( doc[item++], b );
00052     }
00053     fclose( fp );
00054 
00055     if ( ( fp = fopen( "tmp_stub", "r" ) ) == NULL )
00056     {
00057         perror( "tmp_stub not found:" );
00058         exit( 1 );
00059     }
00060 
00061     while ( !feof( fp ) && fgets( b, sizeof ( b ), fp ) != NULL )
00062     {
00063         if ( ( p2 = strchr( b, '(' ) ) )   // function ... = ...(
00064         {
00065             p1 = p2;
00066             while ( *p1-- != ' ' )
00067                 ;
00068             p1 += 2;
00069             if ( *( p1 + 1 ) == '_' )           // c_...
00070                 p1 += 2;
00071             strncpy( tok, p1, p2 - p1 );
00072             *( tok + (int) ( p2 - p1 ) ) = '\0';
00073             printf( "%s", b );
00074             if ( fgets( b, sizeof ( b ), fp ) == NULL )
00075             {
00076                 fprintf( stderr, "Error reading line\n" );
00077                 return 1;
00078             }
00079             printf( "%s%%\n", b ); // % function ... = ...(
00080 
00081             sprintf( b, "plplot_octave_txt/%s.txt", tok );
00082             if ( stat( b, &buf ) && errno == ENOENT )
00083             {
00084                 fprintf( stderr, "%s not found, trying plplot.doc... ", b );
00085                 strcat( tok, "\t" );
00086                 for ( j = 0; j < item; j++ )
00087                 {
00088                     if ( strncmp( doc[j], tok, strlen( tok ) ) == 0 )
00089                     {
00090                         printf( "%% %s", &doc[j][strlen( tok ) + 4] ); // strip func --
00091                         break;
00092                     }
00093                 }
00094                 if ( j == item )
00095                 {
00096                     fprintf( stderr, "%s not found\n", tok );
00097                     printf( "%% No online help available. Help me, write and submit the documentation, or at least write a one line descriptive text.\n" );
00098                 }
00099                 else
00100                     fprintf( stderr, "%s OK\n", tok );
00101             }
00102             else
00103             {
00104                 printf( "%%   Original PLplot call documentation:\n%%\n" );
00105                 fp1 = fopen( b, "r" );
00106                 while ( !feof( fp1 ) && fgets( b, sizeof ( b ), fp1 ) != NULL )
00107                 {
00108                     printf( "%% %s", b );
00109                 }
00110                 fclose( fp1 );
00111             }
00112             if ( fgets( b, sizeof ( b ), fp ) == NULL ) // % No doc...
00113             {
00114                 fprintf( stderr, "Error reading line\n" );
00115                 return 1;
00116             }
00117             if ( fgets( b, sizeof ( b ), fp ) == NULL )
00118             {
00119                 fprintf( stderr, "Error reading line\n" );
00120                 return 1;
00121             }
00122             printf( "%s", b );  // plplot_oct...
00123             if ( fgets( b, sizeof ( b ), fp ) == NULL )
00124             {
00125                 fprintf( stderr, "Error reading line\n" );
00126                 return 1;
00127             }
00128             printf( "%s\n", b ); // endfunction
00129         }
00130     }
00131     fclose( fp );
00132     exit( 0 );
00133 }

Generated on Wed Oct 12 2011 20:42:21 for PLplot by  doxygen 1.7.1