Esempio n. 1
0
int main(int argc, char *argv[])
{
    argc = process_options(argc, argv);
    load_prototypes(protos_file);

    generate_temp_file(tmp_preprocess_output);
    generate_temp_file(tmp_pandoc_output);
    d_cleanup = remove_temp_files;

    if (0 == strcmp(to_format, "man"))
        make_man_pages(argc, argv);
    else
        make_single_doc(argc, argv);

    d_cleanup();
    return 0;
}
Esempio n. 2
0
int
main(int argc,char **argv)
{
	ParseCtx* ctx;
	int i, j, ret = 0xbad;
	char* buf;

	banner();

	rl_completion_entry_function = generator;

	if(argv[1] && !strcmp(argv[1],"--prototype"))
		show_proto = 1;

	commands = malloc( sizeof(char*) * 4 );
	commands[command_index++] = strdup("quit");
	commands[command_index++] = strdup("help");
	commands[command_index++] = strdup("clear_ptr");
	commands[command_index++] = strdup("prototype");

	load_prototypes("./dynamic.xml");

	specialPointer = malloc( BUFSIZ );
	memset( specialPointer, 0, BUFSIZ );

	while((buf = readline(">> ")))
	{
		rl_bind_key('\t',rl_complete);

		if( !buf[0] || buf[0] == '\n' || buf[0] == '#' )
			continue;

		if(strstr(buf,"//"))
			*(char*)strstr(buf,"//") = 0;

		ctx = pcre_parse_string( buf );

		if( !ctx )
			continue;

		if(!strcmp( ctx->keyword, "clear_ptr" ))
			memset( specialPointer, 0, BUFSIZ );
		else if(!strcmp( ctx->keyword, "help" ))
			printf(
				"clear_ptr()\t-\tClear the specialPointer.\n"
				"prototype([char*])\t-\tShow all the prototypes.\n"
				"help()     \t-\tShow this help.\n"
				"quit()     \t-\tQuit program.\n"
				);
		else if(!strcmp( ctx->keyword, "prototype" )) {
			if(ctx->argc == 0 )
			{
				printf("===== PROTOTYPE STARTS HERE =====\n");
				for(i = 0;i < lib.sym_count;i++)
				{
					switch( lib.syms[i].proto.ret )
					{
						case Int:
							printf("int ");
							break;
						case Char:
							printf("char ");
							break;
						case Ptr:
							printf("void* ");
							break;
						case Str:
							printf("char* ");
							break;
						case Db:
							printf("double ");
							break;
						default:
							printf("void ");
							break;
					}

					if( !lib.syms[i].proto.type_count )
						printf("%s( );\n", lib.syms[i].name );
					else {
						printf("%s(", lib.syms[i].name );
	
						for(j = 0;j < lib.syms[i].proto.type_count;j++)
						{
							if(lib.syms[i].proto.types[j] == Integer)
								printf(" int" );
							else if(lib.syms[i].proto.types[j] == Pointer)
								printf(" void*" );
							else if(lib.syms[i].proto.types[j] == Double)
								printf(" double");

							if( (j+1) != lib.syms[i].proto.type_count )
								putchar(',');
							else
								printf(" );\n");
						}
					}
				}

				printf("===== PROTOTYPE ENDS HERE =====\n");
			} else {
				for(i = 0;i < lib.sym_count;i++)
				{
					if(!strcmp(lib.syms[i].name,ctx->args[0]))
					{
						switch( lib.syms[i].proto.ret )
						{
							case Int:
								printf("int ");
								break;
							case Char:
								printf("char ");
								break;
							case Ptr:
								printf("void* ");
								break;
							case Str:
								printf("char* ");
								break;
							case Db:
								printf("double ");
								break;
							default:
								printf("void ");
								break;
						}

						if( !lib.syms[i].proto.type_count )
							printf("%s( );\n", lib.syms[i].name );
						else {
							printf("%s(", lib.syms[i].name );
	
							for(j = 0;j < lib.syms[i].proto.type_count;j++)
							{
								if(lib.syms[i].proto.types[j] == Integer)
									printf(" int" );
								else if(lib.syms[i].proto.types[j] == Pointer)
									printf(" void*" );
								else if(lib.syms[i].proto.types[j] == Double)
									printf(" double");

								if( (j+1) != lib.syms[i].proto.type_count )
									putchar(',');
								else
									printf(" );\n");
							}
						}
					}
				}
			}
		} else if(!strcmp( ctx->keyword, "quit" )) {
			free( ctx->args );
			free( ctx );

			exit( 0 );
		}
		else {
			for(i = 0;i < lib.sym_count;i++)
			{
				if(!strcmp( lib.syms[i].name, ctx->keyword))
				{
					ret = dlcall( lib.syms[i].pointer, ctx->args, ctx->argc, lib.syms[i].proto );

					switch( lib.syms[i].proto.ret )
					{
						case Int:
							printf("[return: %d]\n", ret );
							break;
						case Ptr:
							printf("[return: %p]\n", (void*)ret );
							break;
						case Str:
							printf("[return: %s]\n", (char*)ret );
							break;
						case Char:
							printf("[return: \'%c\']\n", (char)ret );
							break;
						case Db:
							printf("[return: %lf]\n", (double)ret );
							break;
						default:
							printf("[return: %p]\n", (void*)ret );
							break;
					}

					break;
				}
			}

			if( ret == 0xbad )
				printf("Unknown command.\n");
		}

		add_history( buf );

		free( ctx->args );
		free( ctx );
		free( buf );
	}

	return 0;
}