PLplot: massage.c Source File

PLplot 5.10.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
massage.c
Go to the documentation of this file.
1 //
2 //## Copyright (C) 1998-2003 Joao Cardoso.
3 //##
4 //## This program is free software; you can redistribute it and/or modify it
5 //## under the terms of the GNU General Public License as published by the
6 //## Free Software Foundation; either version 2 of the License, or (at your
7 //## option) any later version.
8 //##
9 //## This program is distributed in the hope that it will be useful, but
10 //## WITHOUT ANY WARRANTY; without even the implied warranty of
11 //## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 //## General Public License for more details.
13 //##
14 //## This file is part of plplot_octave.
15 //
16
17 //
18 // Add online help to functions, parsing 'tmp_stub' and looking for
19 // function definitions; for each function found, scans directory
20 // 'plplot_octave_txt' for a file with the same basename as function
21 // and extension '.txt'; if found, incorporates it as the function
22 // online help, else, looks in 'plplot.doc' for a one-line description
23 // of the function and adds it. If not even found in 'plplot.doc', ask
24 // the user to write the docs! No free lunches!
25 //
26
27 #include "stdio.h"
28 #include "string.h"
29 #include "stdlib.h"
30 #include <sys/stat.h>
31 #include "errno.h"
32
33 int
34 main()
35 {
36 char *p1, *p2;
37 char doc[150][1024], b[1024], tok[80];
38 int item = 0, j;
39 FILE *fp, *fp1;
40 struct stat buf;
41
42 if ( ( fp = fopen( "plplot_octave_txt/plplot.doc", "r" ) ) == NULL )
43 {
44 perror( "plplot.doc not found:" );
45 exit( 1 );
46 }
47
48 while ( !feof( fp ) && fgets( b, sizeof ( b ), fp ) != NULL )
49 {
50 if ( strchr( b, '-' ) )
51 strcpy( doc[item++], b );
52 }
53 fclose( fp );
54
55 if ( ( fp = fopen( "tmp_stub", "r" ) ) == NULL )
56 {
57 perror( "tmp_stub not found:" );
58 exit( 1 );
59 }
60
61 while ( !feof( fp ) && fgets( b, sizeof ( b ), fp ) != NULL )
62 {
63 if ( ( p2 = strchr( b, '(' ) ) ) // function ... = ...(
64 {
65 p1 = p2;
66 while ( *p1-- != ' ' )
67 ;
68 p1 += 2;
69 if ( *( p1 + 1 ) == '_' ) // c_...
70 p1 += 2;
71 strncpy( tok, p1, p2 - p1 );
72 *( tok + (int) ( p2 - p1 ) ) = '\0';
73 printf( "%s", b );
74 if ( fgets( b, sizeof ( b ), fp ) == NULL )
75 {
76 fprintf( stderr, "Error reading line\n" );
77 return 1;
78 }
79 printf( "%s%%\n", b ); // % function ... = ...(
80
81 sprintf( b, "plplot_octave_txt/%s.txt", tok );
82 if ( stat( b, &buf ) && errno == ENOENT )
83 {
84 fprintf( stderr, "%s not found, trying plplot.doc... ", b );
85 strcat( tok, "\t" );
86 for ( j = 0; j < item; j++ )
87 {
88 if ( strncmp( doc[j], tok, strlen( tok ) ) == 0 )
89 {
90 printf( "%% %s", &doc[j][strlen( tok ) + 4] ); // strip func --
91 break;
92 }
93 }
94 if ( j == item )
95 {
96 fprintf( stderr, "%s not found\n", tok );
97 printf( "%% No online help available. Help me, write and submit the documentation, or at least write a one line descriptive text.\n" );
98 }
99 else
100 fprintf( stderr, "%s OK\n", tok );
101 }
102 else
103 {
104 printf( "%% Original PLplot call documentation:\n%%\n" );
105 fp1 = fopen( b, "r" );
106 while ( !feof( fp1 ) && fgets( b, sizeof ( b ), fp1 ) != NULL )
107 {
108 printf( "%% %s", b );
109 }
110 fclose( fp1 );
111 }
112 if ( fgets( b, sizeof ( b ), fp ) == NULL ) // % No doc...
113 {
114 fprintf( stderr, "Error reading line\n" );
115 return 1;
116 }
117 if ( fgets( b, sizeof ( b ), fp ) == NULL )
118 {
119 fprintf( stderr, "Error reading line\n" );
120 return 1;
121 }
122 printf( "%s", b ); // plplot_oct...
123 if ( fgets( b, sizeof ( b ), fp ) == NULL )
124 {
125 fprintf( stderr, "Error reading line\n" );
126 return 1;
127 }
128 printf( "%s\n", b ); // endfunction
129 }
130 }
131 fclose( fp );
132 exit( 0 );
133 }