| 3077 | * No /EXPORT is required for x64 |
| 3078 | */ |
| 3079 | extern "C" EXPORT char* STDCALL |
| 3080 | AStyleMain(const char* pSourceIn, // pointer to the source to be formatted |
| 3081 | const char* pOptions, // pointer to AStyle options, separated by \n |
| 3082 | fpError fpErrorHandler, // pointer to error handler function |
| 3083 | fpAlloc fpMemoryAlloc) // pointer to memory allocation function |
| 3084 | { |
| 3085 | if (fpErrorHandler == NULL) // cannot display a message if no error handler |
| 3086 | return NULL; |
| 3087 | |
| 3088 | if (pSourceIn == NULL) |
| 3089 | { |
| 3090 | fpErrorHandler(101, "No pointer to source input."); |
| 3091 | return NULL; |
| 3092 | } |
| 3093 | if (pOptions == NULL) |
| 3094 | { |
| 3095 | fpErrorHandler(102, "No pointer to AStyle options."); |
| 3096 | return NULL; |
| 3097 | } |
| 3098 | if (fpMemoryAlloc == NULL) |
| 3099 | { |
| 3100 | fpErrorHandler(103, "No pointer to memory allocation function."); |
| 3101 | return NULL; |
| 3102 | } |
| 3103 | |
| 3104 | ASFormatter formatter; |
| 3105 | ASOptions options(formatter); |
| 3106 | |
| 3107 | vector<string> optionsVector; |
| 3108 | istringstream opt(pOptions); |
| 3109 | |
| 3110 | options.importOptions(opt, optionsVector); |
| 3111 | |
| 3112 | bool ok = options.parseOptions(optionsVector, |
| 3113 | "Invalid Artistic Style options:"); |
| 3114 | |
| 3115 | if (!ok) |
| 3116 | fpErrorHandler(210, options.getOptionErrors().c_str()); |
| 3117 | |
| 3118 | istringstream in(pSourceIn); |
| 3119 | ASStreamIterator<istringstream> streamIterator(&in); |
| 3120 | ostringstream out; |
| 3121 | formatter.init(&streamIterator); |
| 3122 | |
| 3123 | while (formatter.hasMoreLines()) |
| 3124 | { |
| 3125 | out << formatter.nextLine(); |
| 3126 | if (formatter.hasMoreLines()) |
| 3127 | out << streamIterator.getOutputEOL(); |
| 3128 | else |
| 3129 | { |
| 3130 | // this can happen if the file if missing a closing bracket and break-blocks is requested |
| 3131 | if (formatter.getIsLineReady()) |
| 3132 | { |
| 3133 | out << streamIterator.getOutputEOL(); |
| 3134 | out << formatter.nextLine(); |
| 3135 | } |
| 3136 | } |
no test coverage detected