/* urlencoded2sh * convert x-www-form-urlencoded data to sh style variable decls */ #include #include #include #include int main(int argc, char *argv[]) { int c; char tmp[3]; int mustclose = 0; tmp[2] = '\0'; while((c = fgetc(stdin)) != EOF) { if(c == '&') { fputc('\'', stdout); fputc('\n', stdout); mustclose = 0; continue; } if(c == '+') { c = ' '; } else if(c == '=') { fputc(c, stdout); c = '\''; mustclose = 1; } else if(c == '\'') { fputs("'\"'\"'", stdout); continue; } else if(c == '%') { /* Pick up 2 hex bytes for char */ c = '?'; if((c = fgetc(stdin)) != EOF) { tmp[0] = c; if((c = fgetc(stdin)) != EOF) { tmp[1] = c; c = (int) strtol(tmp, NULL, 16); } } if(c == '\'') { fputs("'\"'\"'", stdout); continue; } } else if(c == '\n') { /* skip newlines for now. They are nasty */ continue; } fputc(c, stdout); } if(mustclose) fputc('\'', stdout); fputc('\n', stdout); exit(0); }