Skip to content

Instantly share code, notes, and snippets.

@chunkyguy
Created July 1, 2012 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chunkyguy/3027857 to your computer and use it in GitHub Desktop.
Save chunkyguy/3027857 to your computer and use it in GitHub Desktop.
Create ObjectiveC implementation file from interface file.
/*
Input:
- (void)viewWillDisappear:(BOOL)animated;
Output:
- (void)viewWillDisappear:(BOOL)animated{
[handler_ viewWillDisappear:animated];
}
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define L_MAX 1024
int strcpy_move(char *d, char *s){
strcpy(d, s);
return strlen(s);
}
void createImp(char *decl){
char out[L_MAX]; //out buffer
char *op = out; //pointer to put buffer
char *sl = decl; //pointer for second line content
char tmp[L_MAX]; //temp buffer
char *tp; //pointer to temp buffer
char ch;
char skip;
//start
while((*op++ = *decl++) != ';')
;
op--;
//mid
op += strcpy_move(op, "{\n");
//second line
while(*sl++ != '(')
;
for(tp = tmp; (*tp = *sl++) != ')'; tp++)
;
*tp = '\0';
if(strcmp(tmp,"void"))
op += strcpy_move(op, "return ");
op += strcpy_move(op, "[handler_ ");
skip = 0;
while((ch = *sl++) != ';'){
if(ch == '('){
skip = 1;
}else if(ch == ')'){
skip = 0;
continue;
}
if(!skip){
*op++ = ch;
}
}
op += strcpy_move(op, "];\n");
//end
op += strcpy_move(op, "}");
//print
printf("%s\n",out);
}
int main(){
char input[L_MAX];
char *lp = input;
while((*lp = getchar()) != EOF){
if(*lp == ';'){
*(++lp) = '\0';
createImp(input);
lp = input;
}else{
lp++;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment