summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-05-26 14:43:48 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-05-26 14:43:48 +0000
commit6d28f2c186d0b1967b3f25e6933e4a509d59a9a0 (patch)
tree027aea1c01a4403819bfd3bf3ae977ffb1761c9c /perl_checker.src
parent006dcb333615841ec541648b81df1780d766b364 (diff)
downloadperl_checker-6d28f2c186d0b1967b3f25e6933e4a509d59a9a0.tar
perl_checker-6d28f2c186d0b1967b3f25e6933e4a509d59a9a0.tar.gz
perl_checker-6d28f2c186d0b1967b3f25e6933e4a509d59a9a0.tar.bz2
perl_checker-6d28f2c186d0b1967b3f25e6933e4a509d59a9a0.tar.xz
perl_checker-6d28f2c186d0b1967b3f25e6933e4a509d59a9a0.zip
handle use foo() and use foo ("x", "y")
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/parser.mly2
-rw-r--r--perl_checker.src/tree.ml10
2 files changed, 10 insertions, 2 deletions
diff --git a/perl_checker.src/parser.mly b/perl_checker.src/parser.mly
index ceb3c41..a2b3bc1 100644
--- a/perl_checker.src/parser.mly
+++ b/perl_checker.src/parser.mly
@@ -168,7 +168,7 @@ decl:
use:
| use_word listexpr semi_colon {sp_n($2); new_esp M_none (Use($1.any, $2.any.expr)) $1 $3}
-| use_revision RAW_IDENT_PAREN PAREN PAREN_END {new_esp M_none (Use(to_Ident $2, [])) $1 $2}
+| use_revision word_paren PAREN listexpr PAREN_END {sp_0($4); sp_0_or_cr($5); new_esp M_none (Use($2.any, $4.any.expr)) $1 $5}
use_word:
| use_revision word comma {new_esp M_none $2.any $1 $3}
diff --git a/perl_checker.src/tree.ml b/perl_checker.src/tree.ml
index f866e14..d576e57 100644
--- a/perl_checker.src/tree.ml
+++ b/perl_checker.src/tree.ml
@@ -77,11 +77,19 @@ let get_current_package t =
let from_qw_raw = function
| Call_op("qw", [ Raw_string(s, pos)], _) ->
List.map (fun symbol -> symbol, pos) (words s)
+ | String([s, List []], pos) -> [ s, pos ]
| String(_, pos) ->
warn_with_pos pos "not recognised yet" ;
[]
| Raw_string(s, pos) ->
[ s, pos ]
+ | List [] -> []
+ | List [ List l ] ->
+ List.map (function
+ | String([s, List []], pos)
+ | Raw_string(s, pos) -> s, pos
+ | Ident(_, _, pos) as ident -> string_of_Ident ident, pos
+ ) l
| _ -> internal_error "from_qw_raw"
let from_qw e =
@@ -177,7 +185,7 @@ let get_uses t =
| Use(Ident _ as pkg, _) when uses_external_package (string_of_Ident pkg) -> uses
| Use(Ident(_, _, pos) as ident, l) ->
let package = string_of_Ident ident in
- let para = if l = [] then None else Some(from_qw (List.hd l)) in
+ let para = if l = [] then None else Some(collect from_qw l) in
(package, (para, pos)) :: uses
| _ -> uses
) [] t
>180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
/*
 * Guillaume Cottenceau (gc@mandrakesoft.com)
 *
 * Copyright 2000 MandrakeSoft
 *
 * This software may be freely redistributed under the terms of the GNU
 * public license.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */


/*
 * Each different frontend must implement all functions defined in frontend.h
 */


#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <termios.h>

#include <probing.h>

#include "frontend.h"


void init_frontend(char * welcome_msg)
{
	printf(welcome_msg);
	printf("\n");
}


void finish_frontend(void)
{
}

static void get_any_response(void)
{
	unsigned char t;
	printf("\n\t(press <enter> to proceed)");
	fflush(stdout);
	read(0, &t, 1);
	fcntl(0, F_SETFL, O_NONBLOCK);
	while (read(0, &t, 1) > 0);
	fcntl(0, F_SETFL, 0);
}
	
static int get_int_response(void)
{
	char s[50];
	int j = 0;
	unsigned int i = 0; /* (0) tied to Cancel */
	fflush(stdout);
	read(0, &(s[i++]), 1);
	fcntl(0, F_SETFL, O_NONBLOCK);
	do {
		int v = s[i-1];
		if (v >= '0' && v <= '9')
			j = j*10 + (v - '0');
	} while (read(0, &(s[i++]), 1) > 0 && i < sizeof(s));
	fcntl(0, F_SETFL, 0);
	return j;
}

static char * get_string_response(char * initial_string)
{
	/* I won't use a scanf/%s since I also want the null string to be accepted -- also, I want the initial_string */
	char s[500];
	int i = 0;
	char buf[10];
	int b_index = 0;
	char b;

	struct termios t;

	memset(s, '\0', sizeof(s));

	if (initial_string) {
		printf(initial_string);
		strcpy(s, initial_string);
		i = strlen(s);
	}
	
	/* from ncurses/tinfo/lib_raw.c:(cbreak) */
	tcgetattr(0, &t);
	t.c_lflag &= ~ICANON;
	t.c_lflag |= ISIG;
	t.c_lflag &= ~ECHO;
	t.c_iflag &= ~ICRNL;
	t.c_cc[VMIN] = 1;
	t.c_cc[VTIME] = 0;
	tcsetattr(0, TCSADRAIN, &t);

	fflush(stdout);

	fcntl(0, F_SETFL, O_NONBLOCK);

	while (1) {
		if (read(0, &b, 1) > 0) {
			if (b_index == 1) {
				if (b == 91) {
					buf[b_index] = b;
					b_index++;
					continue;
				}
				else
					b_index = 0;
			}
			if (b_index == 2) {
				if (b == 67) {
					if (s[i] != '\0') {
						printf("\033[C");
						i++;
					}
				}
				if (b == 68) {
					if (i > 0) {
						printf("\033[D");
						i--;
					}
				}
				b_index = 0;
				continue;
			}
				
			if (b == 13)
				break;
			if (b == 127) {
				if (i > 0) {
					printf("\033[D");
					printf(" ");
					printf("\033[D");
					if (s[i] == '\0')
						s[i-1] = '\0';
					else
						s[i-1] = ' ';
					i--;
				}
			} else if (b == 27) {
				buf[b_index] = b;
				b_index++;
			} else {
				printf("%c", b);
				s[i] = b;
				i++;
			}
		}
	}

	t.c_lflag |= ICANON;
	t.c_lflag |= ECHO;
	t.c_iflag |= ICRNL; 
	tcsetattr(0, TCSADRAIN, &t);

	fcntl(0, F_SETFL, 0);

	printf("\n");
	return strdup(s);
}

static void blocking_msg(char *type, char *fmt, va_list ap)
{
	printf(type);
	vprintf(fmt, ap);
	get_any_response();
}

void verror_message(char *msg, va_list ap)
{
	probe_that_type(USB_CONTROLLERS, BUS_USB); // we'd need the keyboard for interactions so...
	blocking_msg("> Error! ", msg, ap);
}

void vinfo_message(char *msg, va_list ap)
{
	probe_that_type(USB_CONTROLLERS, BUS_USB); // we'd need the keyboard for interactions so...
	blocking_msg("> Notice: ", msg, ap);
}

void vwait_message(char *msg, va_list ap)
{
	printf("Please wait: ");
	vprintf(msg, ap);
	fflush(stdout);
}

void remove_wait_message(void)
{
	printf("\n");
}


static int size_progress;
static int actually_drawn;
#define PROGRESS_SIZE 45
void init_progression(char *msg, int size)
{
	int i;
	size_progress = size;
	printf("%s  ", msg);
	if (size) {
		actually_drawn = 0;
		for (i=0; i<PROGRESS_SIZE; i++)
			printf(".");
		printf("]\033[G%s [", msg);		/* only works on ANSI-compatibles */
		fflush(stdout);
	} else
		printf("\n");
}

void update_progression(int current_size)
{
	if (size_progress) {
		if (current_size > size_progress)
			current_size = size_progress;
		while ((int)((current_size*PROGRESS_SIZE)/size_progress) > actually_drawn) {
			printf("*");
			actually_drawn++;
		}
	} else
		printf("\033[GStatus: [%8d] bytes loaded...", current_size);
	
	fflush(stdout);
}

void end_progression(void)
{
	if (size_progress) {
		update_progression(size_progress);
		printf("]\n");
	} else
		printf(" done.\n");
}


enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_comments, char ** choice)
{
	int justify_number = 1;
	void print_choice_number(int i) {
		char tmp[500];
		snprintf(tmp, sizeof(tmp), "[%%%dd]", justify_number);
		printf(tmp, i);
	}
	char ** sav_elems = elems;
	int i = 1;
	int j = 0;

	probe_that_type(USB_CONTROLLERS, BUS_USB); // we'd need the keyboard for interactions so...

	while (elems && *elems) {
		elems++;
		i++;
	}
	if (i >= 10)
		justify_number = 2;

	elems = sav_elems;
	i = 1;

	printf("> %s\n", msg);
	print_choice_number(0);
	printf(" Cancel");

	while (elems && *elems) {
		if (elems_comments && *elems_comments) {
			printf("\n");
			print_choice_number(i);
			printf(" %s (%s)", *elems, *elems_comments);
			j = 0;
		} else {
			if (j == 0)
				printf("\n");
			print_choice_number(i);
			printf(" %-14s ", *elems);
			j++;
		}
		if (j == 4)
			j = 0;
		
		if (elems_comments)
			elems_comments++;
		i++;
		elems++;
	}

	printf("\n? "); 

	j = get_int_response();

	if (j == 0)
		return RETURN_BACK;

	if (j >= 1 && j <= i) {
		*choice = strdup(sav_elems[j-1]);
		return RETURN_OK;
	}

	return RETURN_ERROR;
}


enum return_type ask_from_list(char *msg, char ** elems, char ** choice)
{
	probe_that_type(USB_CONTROLLERS, BUS_USB); // we'd need the keyboard for interactions so...
	return ask_from_list_comments(msg, elems, NULL, choice);
}


enum return_type ask_yes_no(char *msg)
{
	int j;

	probe_that_type(USB_CONTROLLERS, BUS_USB); // we'd need the keyboard for interactions so...

	printf("> %s\n[0] Yes  [1] No  [2] Back\n? ", msg);

	j = get_int_response();

	if (j == 0)
		return RETURN_OK;
	else if (j == 2)
		return RETURN_BACK;
	else return RETURN_ERROR;
}


enum return_type ask_from_entries(char *msg, char ** questions, char *** answers, int entry_size UNUSED, void (*callback_func)(char ** strings) UNUSED)
{
	int j, i = 0;
	char ** already_answers = NULL;

	probe_that_type(USB_CONTROLLERS, BUS_USB); // we'd need the keyboard for interactions so...

	printf("> %s\n", msg);

	while (questions && *questions) {
		printf("(%c) %s\n", i + 'a', *questions);
		i++;
		questions++;
	}

	if (*answers == NULL)
		*answers = (char **) malloc(sizeof(char *) * i);
	else
		already_answers = *answers;

	while (1) {
		int r;
		for (j = 0 ; j < i ; j++) {
			printf("(%c) ? ", j + 'a');
			if (already_answers && *already_answers) {
				(*answers)[j] = get_string_response(*already_answers);
				already_answers++;
			} else
				(*answers)[j] = get_string_response(NULL);

		}
		printf("[0] Cancel  [1] Accept  [2] Re-enter answers\n? ");
		r = get_int_response();
		if (r == 0)
			return RETURN_BACK;
		if (r == 1)
			return RETURN_OK;
	}
}


void suspend_to_console(void) {}
void resume_from_suspend(void) {}